Git Product home page Git Product logo

Comments (6)

stapelberg avatar stapelberg commented on May 4, 2024 1

It’s implemented now :).

That said, if I understand https://wiki.nftables.org/wiki-nftables/index.php/Performing_Network_Address_Translation_(NAT)#Redirect correctly, you could have used a dnat rule to the same effect.

from nftables.

sbezverk avatar sbezverk commented on May 4, 2024

@stapelberg Any chance you could walk me through with comments test you added? I want to make sure I get the logic of building expr right:

		Exprs: []expr.Any{
			// [ meta load l4proto => reg 1 ]
			&expr.Meta{Key: expr.MetaKeyL4PROTO, Register: 1},
			// [ cmp eq reg 1 0x00000006 ]
			&expr.Cmp{
				Op:       expr.CmpOpEq,
				Register: 1,
				Data:     []byte{unix.IPPROTO_TCP},
			},

The rule will be applied to TCP traffic ^^^

 			// [ payload load 2b @ transport header + 2 => reg 1 ]
			&expr.Payload{
				DestRegister: 1,
				Base:         expr.PayloadBaseTransportHeader,
				Offset:       2, // TODO
				Len:          2, // TODO
			},
			// [ cmp eq reg 1 0x00001600 ]
			&expr.Cmp{
				Op:       expr.CmpOpEq,
				Register: 1,
				Data:     []byte{0x00, 0x16},
			},

Could you please explain ^^^, does it have something to do with specifying source port?

 			// [ immediate reg 1 0x0000ae08 ]
			&expr.Immediate{
				Register: 1,
				Data:     binaryutil.BigEndian.PutUint16(2222),
			},

expr.Immediate why it is used here, I suspect this is the way you load redirect to port

 			// [ redir proto_min reg 1 ]
			&expr.Redir{
				RegisterProtoMin: 1,
			},
		},

from nftables.

stapelberg avatar stapelberg commented on May 4, 2024

Could you please explain ^^^, does it have something to do with specifying source port?

Yeah, I probably should have just used BigEndian.PutUint16(22) for clarity.

The whole expression is taken from nft --debug all add rule nat prerouting tcp dport 22 redirect to 2222

from nftables.

sbezverk avatar sbezverk commented on May 4, 2024

@stapelberg great, --debug looks very useful! thanks a lot..

from nftables.

sbezverk avatar sbezverk commented on May 4, 2024

@stapelberg Appreciate you could comment how to implement this immediate expression:

[ immediate reg 0 jump -> chain_2 ]

it seems data actually consists out of 2 parts, jump command (I suspect, the code is ff fd) and chain name.

from nftables.

stapelberg avatar stapelberg commented on May 4, 2024

I’d need to look at that in more detail. Can you open a separate issue including an nft command I can use to test?

from nftables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.