bridge: export nft_reject_ip*hdr_validate functions
Subsystems (3)
PATCH v4 1/2 bridge: export nft_reject_ip*hdr_validate functions
This patch exports the functions nft_reject_iphdr_validate and nft_reject_ip6hdr_validate to use it in follow up patches. These functions check if the ethernet header is correct.
---
[no changes in v4]
include/net/netfilter/nf_tables_bridge.h | 7 ++++ net/bridge/netfilter/nf_tables_bridge.c | 48 +++++++++++++++++++++++++++ net/bridge/netfilter/nft_reject_bridge.c | 52 +++--------------------------- 3 files changed, 60 insertions(+), 47 deletions(-) create mode 100644 include/net/netfilter/nf_tables_bridge.h
include/net/netfilter/nf_tables_bridge.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _NET_NF_TABLES_BRIDGE_H +#define _NET_NF_TABLES_BRIDGE_H + +int nft_bridge_iphdr_validate (struct sk_buff *skb); +int nft_bridge_ip6hdr_validate (struct sk_buff *skb); + +#endif /* _NET_NF_TABLES_BRIDGE_H */
net/bridge/netfilter/nf_tables_bridge.c +48 -0
54 lines not on this page · raw message
net/bridge/netfilter/nft_reject_bridge.c +5 -47
94 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v4 2/2 bridge: set the pktinfo for IPv4/IPv6 traffic
This patch adds the missing bits to allow to match per meta l4proto from the bridge. Example:
nft add rule bridge filter input ether type {ip, ip6} meta l4proto udp counter
---
[changes in v4]
* refactor the code in two functions nft_bridge_set_pktinfo_ipv*
net/bridge/netfilter/nf_tables_bridge.c | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
net/bridge/netfilter/nf_tables_bridge.c +41 -1
@@ -16,6 +16,8 @@#include <net/netfilter/nf_tables_bridge.h> #include <linux/ip.h> #include <linux/ipv6.h> +#include <net/netfilter/nf_tables_ipv4.h> +#include <net/netfilter/nf_tables_ipv6.h> int nft_bridge_iphdr_validate (struct sk_buff *skb) {
@@ -62,6 +64,34 @@ int nft_bridge_ip6hdr_validate(struct sk_buff *skb) }EXPORT_SYMBOL_GPL (nft_bridge_ip6hdr_validate); +static inline int nft_bridge_set_pktinfo_ipv4 (struct nft_pktinfo *pkt, +const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out) +{ +if (!nft_bridge_iphdr_validate (skb)) +nft_set_pktinfo (pkt, ops, skb, in, out); +else +nft_set_pktinfo_ipv4 (pkt, ops, skb, in, out); + +return 0 ; +} + +static inline int nft_bridge_set_pktinfo_ipv6 (struct nft_pktinfo *pkt, +const struct nf_hook_ops *ops, +struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out) +{ +#if IS_ENABLED (CONFIG_IPV6 ) +if (nft_bridge_ip6hdr_validate (skb) && +nft_set_pktinfo_ipv6 (pkt, ops, skb, in, out) ==0 ) +return 1 ; +#endif +return 0 ; +} + static unsigned int nft_do_chain_bridge(const struct nf_hook_ops *ops, struct sk_buff *skb,
@@ -71,7 +101,17 @@ nft_do_chain_bridge(const struct nf_hook_ops *ops, {struct nft_pktinfo pkt; -nft_set_pktinfo (&pkt, ops, skb, in, out); +switch (eth_hdr (skb)->h_proto) { +case htons (ETH_P_IP ): +nft_bridge_set_pktinfo_ipv4 (&pkt, ops, skb, in, out); +break ; +case htons (ETH_P_IPV6 ): +if (nft_bridge_set_pktinfo_ipv6 (&pkt, ops, skb, in, out) >0 ) +break ; +default : +nft_set_pktinfo (&pkt, ops, skb, in, out); +break ; + }return nft_do_chain (&pkt, ops); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerRe: [PATCH nf 2/2 v4] bridge: set the pktinfo for IPv4/IPv6 traffic
Quoted 4 lines · Alvaro Neira Ayuso
This patch adds the missing bits to allow to match per meta l4proto from the bridge. Example:
nft add rule bridge filter input ether type {ip, ip6} meta l4proto udp counter
Applied with changes, please see the nf-next tree.
Thanks.
Quoted 3 lines · Alvaro Neira Ayuso
This patch exports the functions
nft_reject_iphdr_validateandnft_reject_ip6hdr_validateto use it in follow up patches. These functions check if the ethernet header is correct.
Applied, thanks.