netfilter: nf_log: do not assume ethernet header in netdev family
authorLiping Zhang <zlpnobody@gmail.com>
Mon, 14 Nov 2016 14:39:25 +0000 (22:39 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 4 Dec 2016 19:45:33 +0000 (20:45 +0100)
In netdev family, we will handle non ethernet packets, so using
eth_hdr(skb)->h_proto is incorrect.

Meanwhile, we can use socket(AF_PACKET...) to sending packets, so
skb->protocol is not always set in bridge family.

Add an extra parameter into nf_log_l2packet to solve this issue.

Fixes: 1fddf4bad0ac ("netfilter: nf_log: add packet logging for netdev family")
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_log.h
net/bridge/netfilter/nf_log_bridge.c
net/netfilter/nf_log_common.c
net/netfilter/nf_log_netdev.c

index a559aa41253cee6680ee7f626df523af287ae08d..450f87f95415824586a1dae0bbfdcef467e6dc7a 100644 (file)
@@ -109,7 +109,9 @@ void nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
                               const struct net_device *out,
                               const struct nf_loginfo *loginfo,
                               const char *prefix);
-void nf_log_l2packet(struct net *net, u_int8_t pf, unsigned int hooknum,
+void nf_log_l2packet(struct net *net, u_int8_t pf,
+                    __be16 protocol,
+                    unsigned int hooknum,
                     const struct sk_buff *skb,
                     const struct net_device *in,
                     const struct net_device *out,
index c197b1f844eee9896b20e790df7dce4fbfeb4ea6..bd2b3c78f59bddd92425974d5731fba3e962e4d5 100644 (file)
@@ -24,7 +24,8 @@ static void nf_log_bridge_packet(struct net *net, u_int8_t pf,
                                 const struct nf_loginfo *loginfo,
                                 const char *prefix)
 {
-       nf_log_l2packet(net, pf, hooknum, skb, in, out, loginfo, prefix);
+       nf_log_l2packet(net, pf, eth_hdr(skb)->h_proto, hooknum, skb,
+                       in, out, loginfo, prefix);
 }
 
 static struct nf_logger nf_bridge_logger __read_mostly = {
index ed9b80815fa0b5ca5eea8b807fe59a8432839711..dc61399e30beb8a40e76dc81bde0f63f39740486 100644 (file)
@@ -177,6 +177,7 @@ EXPORT_SYMBOL_GPL(nf_log_dump_packet_common);
 
 /* bridge and netdev logging families share this code. */
 void nf_log_l2packet(struct net *net, u_int8_t pf,
+                    __be16 protocol,
                     unsigned int hooknum,
                     const struct sk_buff *skb,
                     const struct net_device *in,
@@ -184,7 +185,7 @@ void nf_log_l2packet(struct net *net, u_int8_t pf,
                     const struct nf_loginfo *loginfo,
                     const char *prefix)
 {
-       switch (eth_hdr(skb)->h_proto) {
+       switch (protocol) {
        case htons(ETH_P_IP):
                nf_log_packet(net, NFPROTO_IPV4, hooknum, skb, in, out,
                              loginfo, "%s", prefix);
index 1f645949f3d8de97472cdc8da435d4ec19022f0e..350eb147754d886f25d2aad19dab7fde157e1ddb 100644 (file)
@@ -23,7 +23,8 @@ static void nf_log_netdev_packet(struct net *net, u_int8_t pf,
                                 const struct nf_loginfo *loginfo,
                                 const char *prefix)
 {
-       nf_log_l2packet(net, pf, hooknum, skb, in, out, loginfo, prefix);
+       nf_log_l2packet(net, pf, skb->protocol, hooknum, skb, in, out,
+                       loginfo, prefix);
 }
 
 static struct nf_logger nf_netdev_logger __read_mostly = {