netfilter: payload mangling
Subsystems (2)
PATCH v2 1/1 netfilter: payload mangling
Following is the latest version of the payload mangling patch. Changes to the last version are:
* Make checksum updates optional, required for some protocols
* Fix mangling headers before skb->data. Previously skb_make_writable() would fail due to negative lengths.
* Add new struct for set operation to avoid bloating the regular payload struct
The patch has been tested with headers on all header bases.
The last remaining question is how to react to failure. For data loading expressions we simply NFT_BREAK, which is reasonable since they're used in match like constructs.
For statements that are actions on the packet, I'd say we should drop the packet if the action fails. However we don't do this so far anywhere else, so I wanted to bring it up first since it might also be relevant for other actions, "ct" comes to mind.
Patrick McHardy (1):
netfilter: nft_payload: add packet mangling support
include/net/netfilter/nf_tables_core.h | 9 +++ include/uapi/linux/netfilter/nf_tables.h | 17 ++++ net/netfilter/nft_payload.c | 135 +++++++++++++++++++++++++++++-- 3 files changed, 155 insertions(+), 6 deletions(-)
Signature · 1 line
2.5.0
PATCH v2 1/1 netfilter: nft_payload: add packet mangling support
Add support for mangling packet payload. Checksum for the specified base header is updated automatically if requested, however no updates for any kind of pseudo headers are supported, meaning no stateless NAT is supported.
For checksum updates different checksumming methods can be specified. The currently supported methods are NONE for no checksum updates, and INET for internet type checksums.
--- include/net/netfilter/nf_tables_core.h | 9 +++ include/uapi/linux/netfilter/nf_tables.h | 17 ++++ net/netfilter/nft_payload.c | 135 +++++++++++++++++++++++++++++-- 3 files changed, 155 insertions(+), 6 deletions(-)
include/net/netfilter/nf_tables_core.h +9 -0
@@ -47,6 +47,15 @@ struct nft_payload { enum nft_registers dreg:8; }; +struct nft_payload_set { +enum nft_payload_bases base:8 ; +u8 offset; +u8 len; +enum nft_registers sreg:8 ; +u8 csum_type; +u8 csum_offset; +}; +extern const struct nft_expr_ops nft_payload_fast_ops;int nft_payload_module_init (void );
include/uapi/linux/netfilter/nf_tables.h +17 -0
@@ -598,12 +598,26 @@ enum nft_payload_bases { };/** +* enum nft_payload_csum_types - nf_tables payload expression checksum types +* +* @NFT_PAYLOAD_CSUM_NONE: no checksumming +* @NFT_PAYLOAD_CSUM_INET: internet checksum (RFC 791) +*/ +enum nft_payload_csum_types { +NFT_PAYLOAD_CSUM_NONE , +NFT_PAYLOAD_CSUM_INET , +}; + +/** * enum nft_payload_attributes - nf_tables payload expression netlink attributes * * @NFTA_PAYLOAD_DREG: destination register to load data into (NLA_U32: nft_registers) * @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_TYPE: checksum type (NLA_U32) +* @NFTA_PAYLOAD_CSUM_OFFSET: checksum offset relative to base (NLA_U32) */ enum nft_payload_attributes {NFTA_PAYLOAD_UNSPEC ,
@@ -611,6 +625,9 @@ enum nft_payload_attributes {NFTA_PAYLOAD_BASE ,NFTA_PAYLOAD_OFFSET ,NFTA_PAYLOAD_LEN , +NFTA_PAYLOAD_SREG , +NFTA_PAYLOAD_CSUM_TYPE , +NFTA_PAYLOAD_CSUM_OFFSET , __NFTA_PAYLOAD_MAX };#define NFTA_PAYLOAD_MAX (__NFTA_PAYLOAD_MAX - 1)
net/netfilter/nft_payload.c +129 -6
159 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [PATCH v2] netfilter: nft_payload: add packet mangling support
Quoted 7 lines · Patrick McHardy
Add support for mangling packet payload. Checksum for the specified base header is updated automatically if requested, however no updates for any kind of pseudo headers are supported, meaning no stateless NAT is supported.
For checksum updates different checksumming methods can be specified. The currently supported methods are NONE for no checksum updates, and INET for internet type checksums.
Applied, thanks Patrick!