Skip to contentSkip to conversation

payload mangling support

RFC PATCH Superseded Patrick McHardy 4 participants 10 messages Nov 9, 2015 – Nov 23, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover payload mangling support

The following patch adds support for payload mangling. It supports updating all fields except those included in pseudo headers since it only supports a single checksum update operation. So it can not be used for stateless NAT.

Checksum updates currently only support internet checksums and assume the mangled data is actually covered by the checksum. Userspace only allows use for these protocols.

So the main questions is basically, do we want to support stateless NAT? The downside is that we have to add protocol specific checksumming functions.

Patrick McHardy (1):
netfilter: nft_payload: add packet mangling support

 include/net/netfilter/nf_tables_core.h   |   1 +
 include/uapi/linux/netfilter/nf_tables.h |   4 ++
 net/netfilter/nft_payload.c              | 116 +++++++++++++++++++++++++++++--
 3 files changed, 115 insertions(+), 6 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

RFC PATCH 1/1 netfilter: nft_payload: add packet mangling support

Add support for mangling packet payload. Checksum for the specified base header is updated automatically, however no double updates (for pseudo headers) are supported, meaning no stateless NAT is supported.

---
 include/net/netfilter/nf_tables_core.h   |   1 +
 include/uapi/linux/netfilter/nf_tables.h |   4 ++
 net/netfilter/nft_payload.c              | 116 +++++++++++++++++++++++++++++--
 3 files changed, 115 insertions(+), 6 deletions(-)
include/net/netfilter/nf_tables_core.h +1 -0
index c6f400c..6d7a793 100644
@@ -45,6 +45,7 @@ struct nft_payload {
 	u8			offset;
 	u8			len;
 	enum nft_registers	dreg:8;
+	u8			csum_offset;
 };
 
 extern const struct nft_expr_ops nft_payload_fast_ops;
include/uapi/linux/netfilter/nf_tables.h +4 -0
index d8c8a7c..56e1706 100644
@@ -604,6 +604,8 @@ enum nft_payload_bases {
  * @NFTA_PAYLOAD_BASE: payload base (NLA_U32: nft_payload_bases)
  * @NFTA_PAYLOAD_OFFSET: payload offset relative to base (NLA_U32)
  * @NFTA_PAYLOAD_LEN: payload length (NLA_U32)
+ * @NFTA_PAYLOAD_SREG: source register to load data from (NLA_U32: nft_registers)
+ * @NFTA_PAYLOAD_CSUM_OFFSET: checksum offset relative to base (NLA_U32)
  */
 enum nft_payload_attributes {
 	NFTA_PAYLOAD_UNSPEC,
@@ -611,6 +613,8 @@ enum nft_payload_attributes {
 	NFTA_PAYLOAD_BASE,
 	NFTA_PAYLOAD_OFFSET,
 	NFTA_PAYLOAD_LEN,
+	NFTA_PAYLOAD_SREG,
+	NFTA_PAYLOAD_CSUM_OFFSET,
 	__NFTA_PAYLOAD_MAX
 };
 #define NFTA_PAYLOAD_MAX	(__NFTA_PAYLOAD_MAX - 1)
net/netfilter/nft_payload.c +110 -6

140 lines not on this page · raw message

Signature · 1 line
2.5.0
#2 lore raw

Re: [RFC PATCH nf-next 1/1] netfilter: nft_payload: add packet mangling support

Quoted 3 lines · Patrick McHardy

Add support for mangling packet payload. Checksum for the specified base header is updated automatically, however no double updates (for pseudo headers) are supported, meaning no stateless NAT is supported.

Patrick, if you have no concerns, I'll pass this to David in the next batch.

Thanks.

#3 lore raw

Re: [RFC PATCH nf-next 1/1] netfilter: nft_payload: add packet mangling support

Quoted 7 lines · Pablo Neira Ayuso
Quoted 3 lines · Patrick McHardy

Add support for mangling packet payload. Checksum for the specified base header is updated automatically, however no double updates (for pseudo headers) are supported, meaning no stateless NAT is supported.

Patrick, if you have no concerns, I'll pass this to David in the next batch.

It needs a minor fix to work with link layer headers. I'll try to get it ready tonight.

#4 lore raw
In reply to Patrick McHardy
Quoted 9 lines · Patrick McHardy

The following patch adds support for payload mangling. It supports updating all fields except those included in pseudo headers since it only supports a single checksum update operation. So it can not be used for stateless NAT.

Checksum updates currently only support internet checksums and assume the mangled data is actually covered by the checksum. Userspace only allows use for these protocols.

So the main questions is basically, do we want to support stateless NAT?

Some people ask for that sort of thing every now and then, so it depends on whether you want to please them. On the upside, they only seem to request L3 address editing and L3addrs-inside-ICMP(v6), so the amount of protocol handlers needed is small.

#5 lore raw
Quoted 11 lines · Jan Engelhardt
Quoted 8 lines · Patrick McHardy

The following patch adds support for payload mangling. It supports updating all fields except those included in pseudo headers since it only supports a single checksum update operation. So it can not be used for stateless NAT.

Checksum updates currently only support internet checksums and assume the mangled data is actually covered by the checksum. Userspace only allows use for these protocols.

Quoted 6 lines
Quoted 1 line

So the main questions is basically, do we want to support stateless NAT?

Some people ask for that sort of thing every now and then, so it depends on whether you want to please them. On the upside, they only seem to request L3 address editing and L3addrs-inside-ICMP(v6), so the amount of protocol handlers needed is small.

Yeah, but the l3 addresses are embedded in the protocol specific pseudo
header: There are basically two possibilities:

* add a paremeterized pseudo header update function to the payload expression. Requires one rule per protocol so we can set the required parameters.

* add automatic magic header updates, requires to add protocol knowledge of all protocols which are using this.

I'm not against supporting this per se, but I tend to go in the direction of waiting for people that need this and describe their use cases. I don't see any problem in adding either way later on.

maintainer
#6 lore raw
In reply to Patrick McHardy
Quoted 2 lines · Patrick McHardy

So the main questions is basically, do we want to support stateless NAT? The downside is that we have to add protocol specific checksumming functions.

For now i'm only be interested in mangling MAC addresses for nft bridge to provide ebtables snat/dnat/redirect equivalents.

#7 lore raw
Quoted 6 lines · Florian Westphal
Quoted 2 lines · Patrick McHardy

So the main questions is basically, do we want to support stateless NAT? The downside is that we have to add protocol specific checksumming functions.

For now i'm only be interested in mangling MAC addresses for nft bridge to provide ebtables snat/dnat/redirect equivalents.

I have not tested that, it probably needs some minor adjustments to skip checksum updates for NFT_PAYLOAD_LL_HEADER, but other than that, this will obviously work.

maintainer
#8 lore raw
Quoted 11 lines · Patrick McHardy
Quoted 6 lines · Florian Westphal
Quoted 2 lines · Patrick McHardy

So the main questions is basically, do we want to support stateless NAT? The downside is that we have to add protocol specific checksumming functions.

For now i'm only be interested in mangling MAC addresses for nft bridge to provide ebtables snat/dnat/redirect equivalents.

I have not tested that, it probably needs some minor adjustments to skip checksum updates for NFT_PAYLOAD_LL_HEADER, but other than that, this will obviously work.

For redirect we also need to alter skb->pkttype to PACKET_HOST.

I can take care of this later if needed, I'd just need advice on how to add this (meta statement?).

#9 lore raw
Quoted 9 lines · Florian Westphal
Quoted 8 lines · Patrick McHardy
Quoted 6 lines · Florian Westphal
Quoted 2 lines · Patrick McHardy

So the main questions is basically, do we want to support stateless NAT? The downside is that we have to add protocol specific checksumming functions.

For now i'm only be interested in mangling MAC addresses for nft bridge to provide ebtables snat/dnat/redirect equivalents.

Quoted 8 lines
Quoted 3 lines

I have not tested that, it probably needs some minor adjustments to skip checksum updates for NFT_PAYLOAD_LL_HEADER, but other than that, this will obviously work.

For redirect we also need to alter skb->pkttype to PACKET_HOST.

I can take care of this later if needed, I'd just need advice on how to add this (meta statement?).

Good point. I guess that would be the proper solution, I don't think we want to try to figure out whether an address is local in the payload module.