netfilter: bridge: add queuing to userspace for AF_
Subsystems (3)
v2 cover netfilter: bridge: add queuing to userspace for AF_
From: stephane <[email protected]>
This series of patches intends to add support for queuing to userspace for the AF_BRIDGE family:
-patch 1 just adds and registers the relevant structures: basic queuing
is enabled
-patch 2 passed VLAN and L2 header as netlink attribute, to and back
from userspace.
stephane (2):
netfilter: bridge: add nf_afinfo to enable queuing to userspace
netfilter: bridge: pass L2 header and VLAN as netlink attributes in
queues to userspace
include/uapi/linux/netfilter/nfnetlink_queue.h | 7 ++ net/bridge/netfilter/nf_tables_bridge.c | 47 ++++++++- net/netfilter/nfnetlink_queue.c | 130 ++++++++++++++++++++++++- 3 files changed, 177 insertions(+), 7 deletions(-)
Signature · 1 line
2.1.4
PATCH v2 1/2 netfilter: bridge: add nf_afinfo to enable queuing to userspace
From: stephane <[email protected]>
This just adds and registers a nf_afinfo for the ethernet bridge, which enables queuing to userspace for the AF_BRIDGE family. No checksum computation is done.
--- net/bridge/netfilter/nf_tables_bridge.c | 47 +++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-)
net/bridge/netfilter/nf_tables_bridge.c +45 -2
@@ -162,15 +162,57 @@ static const struct nf_chain_type filter_bridge = { (1 << NF_BR_POST_ROUTING), }; +static void nf_br_saveroute (const struct sk_buff *skb, +struct nf_queue_entry *entry) +{ +} + +static int nf_br_reroute (struct net *net,struct sk_buff *skb, +const struct nf_queue_entry *entry) +{ +return 0 ; +} + +static __sum16 nf_br_checksum (struct sk_buff *skb,unsigned int hook, +unsigned int dataoff,u_int8_t protocol) +{ +return 0 ; +} + +static __sum16 nf_br_checksum_partial (struct sk_buff *skb,unsigned int hook, +unsigned int dataoff,unsigned int len, +u_int8_t protocol) +{ +return 0 ; +} + +static int nf_br_route (struct net *net,struct dst_entry **dst, +struct flowi *fl,bool strict__always_unused ) +{ +return 0 ; +} + +static const struct nf_afinfo nf_br_afinfo = { + .family =AF_BRIDGE , + .checksum = nf_br_checksum, + .checksum_partial = nf_br_checksum_partial, + .route = nf_br_route, + .saveroute = nf_br_saveroute, + .reroute = nf_br_reroute, + .route_key_size =0 , +}; +static int __init nf_tables_bridge_init (void ) {int ret; +nf_register_afinfo (&nf_br_afinfo);nft_register_chain_type (&filter_bridge); ret =register_pernet_subsys (&nf_tables_bridge_net_ops); -if (ret <0 ) +if (ret <0 ) {nft_unregister_chain_type (&filter_bridge); - +nf_unregister_afinfo (&nf_br_afinfo); + }return ret; }
@@ -178,6 +220,7 @@ static void __exit nf_tables_bridge_exit(void) {unregister_pernet_subsys (&nf_tables_bridge_net_ops);nft_unregister_chain_type (&filter_bridge); +nf_unregister_afinfo (&nf_br_afinfo); }module_init (nf_tables_bridge_init);
Signature · 1 line
2.1.4
Florian Westphal
maintainerRe: [PATCH nf-next v2 1/2] netfilter: bridge: add nf_afinfo to enable queuing to userspace
Quoted 5 lines · [email protected] <[email protected]> wrote:
From: stephane <[email protected]>
This just adds and registers a
nf_afinfofor the ethernet bridge, which enables queuing to userspace for theAF_BRIDGEfamily. No checksum computation is done.
I think that using empty stub functions is ok for now,
we can add checksum manipulation or mac header save/restore later on.
PATCH v2 2/2 netfilter: bridge: pass L2 header and VLAN as netlink attributes in queues to userspace
In reply to [email protected]From: stephane <[email protected]>
-this creates 2 netlink attribute NLQA_VLAN and NLQA_L2HDR -these are filled up for the PF_BRIDGE family on the way to userspace, and
used on the way back to modify the original skb accordingly
--- include/uapi/linux/netfilter/nfnetlink_queue.h | 7 ++ net/netfilter/nfnetlink_queue.c | 130 ++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 5 deletions(-)
include/uapi/linux/netfilter/nfnetlink_queue.h +7 -0
@@ -30,6 +30,11 @@ struct nfqnl_msg_packet_timestamp {__aligned_be64 usec; }; +struct nfqnl_msg_vlan { +__be16 proto; +__u16 tci; +} __attribute__ ((packed)); +enum nfqnl_attr_type {NFQA_UNSPEC ,NFQA_PACKET_HDR ,
@@ -50,6 +55,8 @@ enum nfqnl_attr_type {NFQA_UID ,/* __u32 sk uid */ NFQA_GID ,/* __u32 sk gid */ NFQA_SECCTX ,/* security context string */ +NFQA_VLAN ,/* packet vlan info */ +NFQA_L2HDR ,/* full L2 header */ __NFQA_MAX };
net/netfilter/nfnetlink_queue.c +125 -5
170 lines not on this page · raw message
Signature · 1 line
2.1.4
Florian Westphal
maintainerRe: [PATCH nf-next v2 2/2] netfilter: bridge: pass L2 header and VLAN as netlink attributes in queues to userspace
Review
Quoted 5 lines · [email protected] <[email protected]> wrote:
From: stephane <[email protected]>
(quoted diff) +0
-2-this creates 2 netlink attribute NLQA_VLAN and NLQA_L2HDR -these are filled up for the PF_BRIDGE family on the way to userspace, and used on the way back to modify the original skb accordingly
Looks good, some comments below.
Quoted 4 lines
net/netfilter/nfnetlink_queue.c +0
-0@@ -295,6 +295,59 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata)return seclen; }
net/netfilter/nfnetlink_queue.c static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) · line 307
Quoted 10 lines
net/netfilter/nfnetlink_queue.c +10
-0+static u32 nfqnl_get_bridge_nla_len (struct nf_queue_entry *entry) +{ +u32 nlalen =0 ; + +struct sk_buff *entskb = entry->skb; + +if (skb_vlan_tag_present (entskb)) + nlalen +=nla_total_size (sizeof (struct nfqnl_msg_vlan )); + + if (entry->state.in && entskb->dev &&
I don't think the state.in and entskb->dev tests are needed.
net/netfilter/nfnetlink_queue.c static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) · line 330
Quoted 8 lines
net/netfilter/nfnetlink_queue.c +7
-0+static int nfqnl_put_bridge_nla (struct nf_queue_entry *entry, +struct sk_buff *skb) +{ +struct sk_buff *entskb = entry->skb; + +if (entry->state.in && entskb->dev && + (entskb->mac_header < entskb->network_header)) {
I'd suggest:
if (!skb_mac_header_was_set(entskb))
return 0;
Another idea is to move the if (entry->state.pf == PF_BRIDGE) check to this function to avoid increasing nfqnl_build_packet_message() size too much.
net/netfilter/nfnetlink_queue.c static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) · line 336
Quoted 5 lines
net/netfilter/nfnetlink_queue.c +4
-0+int len = (int )(entskb->network_header - entskb->mac_header); +if (skb_tailroom (skb) < +NLA_ALIGN ((sizeof (struct nlattr ) + len))) + goto nla_put_failure;
[..]
I'd suggest
return nla_put(skb, NFQA_L2HDR, len, skb_mac_header(entskb), len);
net/netfilter/nfnetlink_queue.c static int nfqnl_recv_verdict(struct net *net, struct sock *ctnl, · line 1187
Quoted 13 lines
net/netfilter/nfnetlink_queue.c +9
-2if (nfqa[NFQA_PAYLOAD ]) { -u16 payload_len =nla_len (nfqa[NFQA_PAYLOAD ]); -int diff = payload_len - entry->skb->len; +int payload_len =nla_len (nfqa[NFQA_PAYLOAD ]); +unsigned char *payload =nla_data (nfqa[NFQA_PAYLOAD ]); +int mac_header_len =0 ; +int diff =0 ; + +if (entry->state.pf ==PF_BRIDGE ) + mac_header_len =nfqnl_push_l2hdr (&payload, + &payload_len, + entry, nfqa);
Is there a reason why NFQA_L2HDR depends on NFQA_PAYLOAD presence? I'd handle NFQA_L2HDR independently, after NFQA_PAYLOAD.
The replace procedure could look like this:
mac_header_len = entskb->mac_header - entskb->network_header;
if (mac_header_len != nla_len(nfqa[NFQA_L2HDR]))
/* err */
memcpy(entskb->mac_header, nla_data(nfqa[NFQA_L2HDR], mac_header_len);
Yes, this doesn't allow increase/change of l2 header. But I think we should not allow it for the time being.
We can always be more permissive later, possibly while adding checks that there is a valid l2 eth header and that nothing will go wrong with e.g. segmentation or fragmentation of skb on tx side.
You also might want to split this patch into two, one that adds the 'passive' features to make nfqueue work for logging, another one to add the NFQA_L2HDR and VLAN manipulation.
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next v2 2/2] netfilter: bridge: pass L2 header and VLAN as netlink attributes in queues to userspace
In reply to [email protected]Quoted 17 lines · On Thu, Feb 11, 2016 at 03:53:16PM +0100, [email protected] wrote:
From: stephane <[email protected]>
(quoted diff) +0
-2-this creates 2 netlink attribute NLQA_VLAN and NLQA_L2HDR -these are filled up for the PF_BRIDGE family on the way to userspace, and used on the way back to modify the original skb accordinglySigned-off-by Stephane Bryant <[email protected]>--- include/uapi/linux/netfilter/nfnetlink_queue.h | 7 ++ net/netfilter/nfnetlink_queue.c | 130 ++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 5 deletions(-)include/uapi/linux/netfilter/nfnetlink_queue.h +0
-0
include/uapi/linux/netfilter/nfnetlink_queue.h struct nfqnl_msg_packet_timestamp { · line 36
Quoted 7 lines
include/uapi/linux/netfilter/nfnetlink_queue.h +4
-0@@ -30,6 +30,11 @@ struct nfqnl_msg_packet_timestamp {__aligned_be64 usec; }; +struct nfqnl_msg_vlan { +__be16 proto; +__u16 tci; +} __attribute__ ((packed));
I'd rather use nested attributes instead of passing structures through netlink.
I'm aware we're using structure in the existing code, that decision was made long time ago and we cannot change it. But as I said for new code I'd rather see nested attributes. See nla_nest_start and nla_nest_end.
Thanks.