netfilter: ipt_LOG/ip6t_LOG: add option to print decoded MAC header
Subsystems (2)
commit 49923434ad6b90532bdea297a1bc70ae048f3450
Author: Patrick McHardy <[email protected]> Date: Wed Jun 23 18:10:03 2010 +0200
netfilter: ipt_LOG/ip6t_LOG: add option to print decoded MAC header
The LOG targets print the entire MAC header as one long string, which is not readable very well:
IN=eth0 OUT= MAC=00:15:f2:24:91:f8:00:1b:24:dc:61:e6:08:00 ...
Add an option to decode known header formats (currently just ARPHRD_ETHER devices) in their individual fields:
IN=eth0 OUT= MACSRC=00:1b:24:dc:61:e6 MACDST=00:15:f2:24:91:f8 MACPROTO=0800 ... IN=eth0 OUT= MACSRC=00:1b:24:dc:61:e6 MACDST=00:15:f2:24:91:f8 MACPROTO=86dd ...
The option needs to be explicitly enabled by userspace to avoid breaking existing parsers.
include/linux/netfilter_ipv4/ipt_LOG.h +2 -1
@@ -7,7 +7,8 @@#define IPT_LOG_IPOPT 0x04/* Log IP options */ #define IPT_LOG_UID 0x08/* Log UID owning local socket */ #define IPT_LOG_NFLOG 0x10/* Unsupported, don't reuse */ -#define IPT_LOG_MASK 0x1f +#define IPT_LOG_MACDECODE 0x20/* Decode MAC header */ +#define IPT_LOG_MASK 0x2fstruct ipt_log_info {unsigned char level;
include/linux/netfilter_ipv6/ip6t_LOG.h +2 -1
@@ -7,7 +7,8 @@#define IP6T_LOG_IPOPT 0x04/* Log IP options */ #define IP6T_LOG_UID 0x08/* Log UID owning local socket */ #define IP6T_LOG_NFLOG 0x10/* Unsupported, don't use */ -#define IP6T_LOG_MASK 0x1f +#define IP6T_LOG_MACDECODE 0x20/* Decode MAC header */ +#define IP6T_LOG_MASK 0x2fstruct ip6t_log_info {unsigned char level;
net/ipv4/netfilter/ipt_LOG.c +40 -14
72 lines not on this page · raw message
net/ipv6/netfilter/ip6t_LOG.c +52 -28
93 lines not on this page · raw message
net/ipv4/netfilter/ipt_LOG.c static void dump_packet(const struct nf_loginfo *info, · line 383
Quoted 5 lines · Patrick McHardy
net/ipv4/netfilter/ipt_LOG.c +5
-0+switch (dev->type) { +case ARPHRD_ETHER : +printk ("MACSRC=%pM MACDST=%pM MACPROTO=%.4x " , +eth_hdr (skb)->h_source,eth_hdr (skb)->h_dest, +ntohs (eth_hdr (skb)->h_proto));
Why not just the standard %04x? [Same applies to v6]
net/ipv4/netfilter/ipt_LOG.c static void dump_packet(const struct nf_loginfo *info, · line 398
Quoted 9 lines
net/ipv4/netfilter/ipt_LOG.c +9
-0+printk ("MAC=" ); +if (dev->hard_header_len && + skb->mac_header != skb->network_header) { +const unsigned char *p =skb_mac_header (skb); +unsigned int i; + +for (i =0 ; i < dev->hard_header_len; i++, p++) +printk ("%02x%c" , *p, + i == dev->hard_header_len -1 ?' ' :':' );
if (dev->hard_header_len > 0)
printk("%02x", *p++);
for (i = 1; i < dev->hard_header_len; ++i)
printk(":%02x", *p++);I like better for getting rid of the comparison inside the loop.
Review
Quoted 1 line
(quoted diff) +1
-0+ /* MAC logging for input chain only. */
"input path".
Quoted 4 lines
(quoted diff) +2
-0+ if (in && !out) + dump_mac_header(loginfo, skb);dump_packet(loginfo, skb, 0);
# ipv6
net/ipv6/netfilter/ip6t_LOG.c static void dump_packet(const struct nf_loginfo *info, · line 408
Quoted 10 lines
printk("\n");net/ipv6/netfilter/ip6t_LOG.c +9
-0+if (dev->hard_header_len && + skb->mac_header != skb->network_header) { +const unsigned char *p =skb_mac_header (skb); +unsigned int len = dev->hard_header_len; +unsigned int i; + +if (dev->type ==ARPHRD_SIT && + (p -=ETH_HLEN ) < skb->head) + p =NULL ;
What is the purpose of this? If the device is a sit, there is no guarantee that there's any ethernet header in the skb.
Quoted 12 lines · Jan Engelhardt
net/ipv4/netfilter/ipt_LOG.c static void dump_packet(const struct nf_loginfo *info, · line 383
Quoted 6 lines · Patrick McHardy
net/ipv4/netfilter/ipt_LOG.c +5
-0+switch (dev->type) { +case ARPHRD_ETHER : +printk ("MACSRC=%pM MACDST=%pM MACPROTO=%.4x " , +eth_hdr (skb)->h_source,eth_hdr (skb)->h_dest, +ntohs (eth_hdr (skb)->h_proto));Why not just the standard %04x? [Same applies to v6]
I guess that would be more consistent with the existing printks.
Quoted 16 lines
net/ipv4/netfilter/ipt_LOG.c static void dump_packet(const struct nf_loginfo *info, · line 398
Quoted 10 lines
net/ipv4/netfilter/ipt_LOG.c +9
-0+printk ("MAC=" ); +if (dev->hard_header_len && + skb->mac_header != skb->network_header) { +const unsigned char *p =skb_mac_header (skb); +unsigned int i; + +for (i =0 ; i < dev->hard_header_len; i++, p++) +printk ("%02x%c" , *p, + i == dev->hard_header_len -1 ?' ' :':' );if (dev->hard_header_len > 0) printk("%02x", *p++); for (i = 1; i < dev->hard_header_len; ++i) printk(":%02x", *p++);
Quoted 2 lines
I like better for getting rid of the comparison inside the loop.
Looks fine, I'll change that in a seperate patch.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ /* MAC logging for input chain only. */"input path".
Correct.
Quoted 8 lines
Quoted 5 lines
(quoted diff) +2
-0+ if (in && !out) + dump_mac_header(loginfo, skb);dump_packet(loginfo, skb, 0);# ipv6
Quoted 15 lines
net/ipv6/netfilter/ip6t_LOG.c static void dump_packet(const struct nf_loginfo *info, · line 408
Quoted 11 lines
printk("\n");net/ipv6/netfilter/ip6t_LOG.c +9
-0+if (dev->hard_header_len && + skb->mac_header != skb->network_header) { +const unsigned char *p =skb_mac_header (skb); +unsigned int len = dev->hard_header_len; +unsigned int i; + +if (dev->type ==ARPHRD_SIT && + (p -=ETH_HLEN ) < skb->head) + p =NULL ;What is the purpose of this? If the device is a sit, there is no guarantee that there's any ethernet header in the skb.
Correct, that's what the test is determining. This is all existing code that has just been moved around.