Skip to content

allow s/dnat to map to both addr and port

Florian Westphal netfilter-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6tests: add initial nat map testtests/shell/testcases/maps/dumps/nat_addr_port.nft tests/shell/testcases/maps/nat_addr_port+96 -00 replies
2/6evaluate: process concat expressions when used as mapped-to exprsrc/evaluate.c+4 -00 replies
3/6netlink: handle concatenations on set elements mappingssrc/netlink.c+7 -00 replies
4/6evaluate: add two new helperssrc/evaluate.c+32 -290 replies
5/6src: allow nat maps containing both ip(6) address and portinclude/statement.h src/evaluate.c src/netlink_delinearize.c +1 more+123 -10 replies
6/6tests: nat: add and use maps with both address and servicetests/shell/testcases/maps/dumps/nat_addr_port.nft tests/shell/testcases/maps/nat_addr_port+160 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH nft 0/6] allow s/dnat to map to both addr and port

Right now its not possible to use a map with snat/dnat to alter both address and port at the same time.

This series teaches nft to accept this:

	map y4 {
		type ipv4_addr : ipv4_addr . inet_service
		elements = { 192.168.7.2 : 10.1.1.1 . 4242 }
	}

meta l4proto tcp meta nfproto ipv4 dnat ip to ip saddr map @y4

i.e., it allows:
1. A mapping that contains a concatenated expression.
2. nat expression will peek into set type and detect when
the mapping is of 'addr + port' type.
Linearization will compute the register that contains the port part of the mapping.
3. Delinarization will figure out when this trick was used by looking at the length of the mapping: 64 == ipv4addr+service, 160 == ipv6addr+service.

What does not work:
Anonymous mappings, i.e.
meta l4proto tcp meta nfproto ipv4 dnat ip to ip saddr map { 1.2.3.4 : 1.2.3.5 . 53, ..

doesn't work. When evaluating "1.2.3.4", this is still a symbol and unlike with named sets, nft doesn't have a properly declared set type.

This is similar to the 'maps-on-LHS-side' issue.
Phil suggested to allow this:
... to ip saddr map { type ipv4_addr : ipv4_addr . inet_service; 1.2.3.4 : 1.2.3.5 . 53, ..

i.e. re-use the declarative syntax from map code.

Another related issue:
"typeof" doesn't work with concatenations so far.

I don't know when I will have time to look into this more. I have incomplete patches for concat typeof (udata) support and a patch to extend the grammar for the proposed { type ... in anon sets (doesn't cause grammar problems).

I will continue to work on it but don't know yet when I will do so, so I am sending the finished patches I have at this time.