Skip to contentSkip to conversation

bridge: export nft_reject_ip*hdr_validate functions

PATCH Superseded Alvaro Neira Ayuso 2 participants 3 messages Nov 14, 2014 – Nov 20, 2014

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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
new file mode 100644
index 0000000..511fb79
@@ -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
#1 lore raw

PATCH 2/2 bridge: set the pktinfo for IPv4/IPv6 traffic

This patch sets the pktinfo for IPv4/IPv6 traffic. Therefore, we can check the meta l4proto for IPv4/IPv6 traffic in bridge, before we don't have enough information to do it.

---
 net/bridge/netfilter/nf_tables_bridge.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/bridge/netfilter/nf_tables_bridge.c +16 -1
index d468c19..0a0f0ca 100644
@@ -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)
 {
@@ -71,8 +73,21 @@ 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):
+		if (!nft_bridge_iphdr_validate(skb))
+			break;
+		nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
+		return nft_do_chain(&pkt, ops);
+	case htons(ETH_P_IPV6):
+		if (!nft_bridge_ip6hdr_validate(skb))
+			break;
+		if (nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
+			break;
+		return nft_do_chain(&pkt, ops);
+	}
 
+	nft_set_pktinfo(&pkt, ops, skb, in, out);
 	return nft_do_chain(&pkt, ops);
 }
 
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH nf 2/2] bridge: set the pktinfo for IPv4/IPv6 traffic

Quoted 23 lines · Alvaro Neira Ayuso

This patch sets the pktinfo for IPv4/IPv6 traffic. Therefore, we can check the meta l4proto for IPv4/IPv6 traffic in bridge, before we don't have enough information to do it.

---
 net/bridge/netfilter/nf_tables_bridge.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/bridge/netfilter/nf_tables_bridge.c +2 -0
index d468c19..0a0f0ca 100644
@@ -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)
 {

net/bridge/netfilter/nf_tables_bridge.c nft_do_chain_bridge(const struct nf_hook_ops *ops, · line 81

Quoted 10 lines
net/bridge/netfilter/nf_tables_bridge.c +6 -1
@@ -71,8 +73,21 @@ 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):
+		if (!nft_bridge_iphdr_validate(skb))
+			break;
+		nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
+		return nft_do_chain(&pkt, ops);

Please, clean up this, add this function:

static inline void nft_bridge_set_pktinfo_ipv4(...)

{
        if (nft_bridge_iphdr_validate(skb))
                nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
        else
                nft_set_pktinfo(&pkt, ops)
}

And use it.

net/bridge/netfilter/nf_tables_bridge.c nft_do_chain_bridge(const struct nf_hook_ops *ops, · line 87

Quoted 6 lines
net/bridge/netfilter/nf_tables_bridge.c +6 -0
+	case htons(ETH_P_IPV6):
+		if (!nft_bridge_ip6hdr_validate(skb))
+			break;
+		if (nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
+			break;
+		return nft_do_chain(&pkt, ops);

static inline void nft_bridge_set_pktinfo_ipv4(...) {

#if IS_ENABLED(CONFIG_IPV6)
        if (!nft_bridge_ip6hdr_validate(skb) ||
            nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
                nft_set_pktinfo(&pkt, ops);

#endif
}

And use it. The #if is needed because nft_set_pktinfo_ipv6 calls ipv6_find_hdr() which may not be available if CONFIG_IPV6 is set.

Then, don't forget to:

        return nft_do_chain(&pkt, ops);

so we only have one single out output path in this function.