Skip to content

Commit 0d9826b

Browse files
committed
netfilter: nf_log: missing vlan offload tag and proto
Dump vlan tag and proto for the usual vlan offload case if the NF_LOG_MACDECODE flag is set on. Without this information the logging is misleading as there is no reference to the VLAN header. [12716.993704] test: IN=veth0 OUT= MACSRC=86:6c:92:ea:d6:73 MACDST=0e:3b:eb:86:73:76 VPROTO=8100 VID=10 MACPROTO=0800 SRC=192.168.10.2 DST=172.217.168.163 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=2548 DF PROTO=TCP SPT=55848 DPT=80 WINDOW=501 RES=0x00 ACK FIN URGP=0 [12721.157643] test: IN=veth0 OUT= MACSRC=86:6c:92:ea:d6:73 MACDST=0e:3b:eb:86:73:76 VPROTO=8100 VID=10 MACPROTO=0806 ARP HTYPE=1 PTYPE=0x0800 OPCODE=2 MACSRC=86:6c:92:ea:d6:73 IPSRC=192.168.10.2 MACDST=0e:3b:eb:86:73:76 IPDST=192.168.10.1 Fixes: 83e96d4 ("netfilter: log: split family specific code to nf_log_{ip,ip6,common}.c files") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 98a381a commit 0d9826b

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

include/net/netfilter/nf_log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ int nf_log_dump_tcp_header(struct nf_log_buf *m, const struct sk_buff *skb,
108108
unsigned int logflags);
109109
void nf_log_dump_sk_uid_gid(struct net *net, struct nf_log_buf *m,
110110
struct sock *sk);
111+
void nf_log_dump_vlan(struct nf_log_buf *m, const struct sk_buff *skb);
111112
void nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
112113
unsigned int hooknum, const struct sk_buff *skb,
113114
const struct net_device *in,

net/ipv4/netfilter/nf_log_arp.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,31 @@ static void dump_arp_packet(struct nf_log_buf *m,
4343
const struct nf_loginfo *info,
4444
const struct sk_buff *skb, unsigned int nhoff)
4545
{
46-
const struct arphdr *ah;
47-
struct arphdr _arph;
4846
const struct arppayload *ap;
4947
struct arppayload _arpp;
48+
const struct arphdr *ah;
49+
unsigned int logflags;
50+
struct arphdr _arph;
5051

5152
ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
5253
if (ah == NULL) {
5354
nf_log_buf_add(m, "TRUNCATED");
5455
return;
5556
}
57+
58+
if (info->type == NF_LOG_TYPE_LOG)
59+
logflags = info->u.log.logflags;
60+
else
61+
logflags = NF_LOG_DEFAULT_MASK;
62+
63+
if (logflags & NF_LOG_MACDECODE) {
64+
nf_log_buf_add(m, "MACSRC=%pM MACDST=%pM ",
65+
eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest);
66+
nf_log_dump_vlan(m, skb);
67+
nf_log_buf_add(m, "MACPROTO=%04x ",
68+
ntohs(eth_hdr(skb)->h_proto));
69+
}
70+
5671
nf_log_buf_add(m, "ARP HTYPE=%d PTYPE=0x%04x OPCODE=%d",
5772
ntohs(ah->ar_hrd), ntohs(ah->ar_pro), ntohs(ah->ar_op));
5873

net/ipv4/netfilter/nf_log_ipv4.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,10 @@ static void dump_ipv4_mac_header(struct nf_log_buf *m,
284284

285285
switch (dev->type) {
286286
case ARPHRD_ETHER:
287-
nf_log_buf_add(m, "MACSRC=%pM MACDST=%pM MACPROTO=%04x ",
288-
eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
287+
nf_log_buf_add(m, "MACSRC=%pM MACDST=%pM ",
288+
eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest);
289+
nf_log_dump_vlan(m, skb);
290+
nf_log_buf_add(m, "MACPROTO=%04x ",
289291
ntohs(eth_hdr(skb)->h_proto));
290292
return;
291293
default:

net/ipv6/netfilter/nf_log_ipv6.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,11 @@ static void dump_ipv6_mac_header(struct nf_log_buf *m,
297297

298298
switch (dev->type) {
299299
case ARPHRD_ETHER:
300-
nf_log_buf_add(m, "MACSRC=%pM MACDST=%pM MACPROTO=%04x ",
301-
eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest,
302-
ntohs(eth_hdr(skb)->h_proto));
300+
nf_log_buf_add(m, "MACSRC=%pM MACDST=%pM ",
301+
eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest);
302+
nf_log_dump_vlan(m, skb);
303+
nf_log_buf_add(m, "MACPROTO=%04x ",
304+
ntohs(eth_hdr(skb)->h_proto));
303305
return;
304306
default:
305307
break;

net/netfilter/nf_log_common.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
171171
}
172172
EXPORT_SYMBOL_GPL(nf_log_dump_packet_common);
173173

174+
void nf_log_dump_vlan(struct nf_log_buf *m, const struct sk_buff *skb)
175+
{
176+
u16 vid;
177+
178+
if (!skb_vlan_tag_present(skb))
179+
return;
180+
181+
vid = skb_vlan_tag_get(skb);
182+
nf_log_buf_add(m, "VPROTO=%04x VID=%u ", ntohs(skb->vlan_proto), vid);
183+
}
184+
EXPORT_SYMBOL_GPL(nf_log_dump_vlan);
185+
174186
/* bridge and netdev logging families share this code. */
175187
void nf_log_l2packet(struct net *net, u_int8_t pf,
176188
__be16 protocol,

0 commit comments

Comments
 (0)