Skip to contentSkip to conversation

netfilter: nfnetlink_log:add support for VLAN information

PATCH Applied Michael Braun 3 participants 3 messages Aug 20, 2019 – Aug 26, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 netfilter: nfnetlink_log:add support for VLAN information

Currently, there is no vlan information (e.g. when used with a vlan aware bridge) passed to userspache, HWHEADER will contain an 08 00 (ip) suffix even for tagged ip packets.

Therefore, add an extra netlink attribute that passes the vlan information to userspace similarly to 15824ab29f for nfqueue.

--
v2: mirror nfqueue behaviour
v3: remove dep on CONFIG_BRIDGE_NETFILTER, allow NFPROTO_NETDEV, fix size calc

---
 include/uapi/linux/netfilter/nfnetlink_log.h | 11 ++++
 net/netfilter/nf_log_common.c                |  2 +
 net/netfilter/nfnetlink_log.c                | 57 ++++++++++++++++++++
 3 files changed, 70 insertions(+)
include/uapi/linux/netfilter/nfnetlink_log.h +11 -0
index 20983cb195a0..45c8d3b027e0 100644
@@ -33,6 +33,15 @@ struct nfulnl_msg_packet_timestamp {
 	__aligned_be64	usec;
 };
 
+enum nfulnl_vlan_attr {
+	NFULA_VLAN_UNSPEC,
+	NFULA_VLAN_PROTO,		/* __be16 skb vlan_proto */
+	NFULA_VLAN_TCI,			/* __be16 skb htons(vlan_tci) */
+	__NFULA_VLAN_MAX,
+};
+
+#define NFULA_VLAN_MAX (__NFULA_VLAN_MAX + 1)
+
 enum nfulnl_attr_type {
 	NFULA_UNSPEC,
 	NFULA_PACKET_HDR,
@@ -54,6 +63,8 @@ enum nfulnl_attr_type {
 	NFULA_HWLEN,			/* hardware header length */
 	NFULA_CT,                       /* nf_conntrack_netlink.h */
 	NFULA_CT_INFO,                  /* enum ip_conntrack_info */
+	NFULA_VLAN,			/* nested attribute: packet vlan info */
+	NFULA_L2HDR,			/* full L2 header */
 
 	__NFULA_MAX
 };
net/netfilter/nf_log_common.c +2 -0
index ae5628ddbe6d..c127bcc119d8 100644
@@ -167,6 +167,8 @@ nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
 	physoutdev = nf_bridge_get_physoutdev(skb);
 	if (physoutdev && out != physoutdev)
 		nf_log_buf_add(m, "PHYSOUT=%s ", physoutdev->name);
+	if (skb_vlan_tag_present(skb))
+		nf_log_buf_add(m, "VLAN=%d ", skb_vlan_tag_get_id(skb));
 #endif
 }
 EXPORT_SYMBOL_GPL(nf_log_dump_packet_common);
net/netfilter/nfnetlink_log.c +57 -0

75 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Michael Braun

Currently, there is no vlan information (e.g. when used with a vlan aware bridge) passed to userspache, HWHEADER will contain an 08 00 (ip) suffix even for tagged ip packets.

Quoted 8 lines

Therefore, add an extra netlink attribute that passes the vlan information to userspace similarly to 15824ab29f for nfqueue.

--
v2: mirror nfqueue behaviour
v3: remove dep on CONFIG_BRIDGE_NETFILTER, allow NFPROTO_NETDEV, fix size calc

Looks good, thanks for addressing all the comments.

maintainer Applied
#2 lore raw
In reply to Michael Braun
Quoted 6 lines · Michael Braun

Currently, there is no vlan information (e.g. when used with a vlan aware bridge) passed to userspache, HWHEADER will contain an 08 00 (ip) suffix even for tagged ip packets.

Therefore, add an extra netlink attribute that passes the vlan information to userspace similarly to 15824ab29f for nfqueue.

Applied, with one minor glitch.

[...]

net/netfilter/nf_log_common.c nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf, · line 174

Quoted 13 lines
net/netfilter/nf_log_common.c +2 -0
index ae5628ddbe6d..c127bcc119d8 100644
@@ -167,6 +167,8 @@ nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
 	physoutdev = nf_bridge_get_physoutdev(skb);
 	if (physoutdev && out != physoutdev)
 		nf_log_buf_add(m, "PHYSOUT=%s ", physoutdev->name);
+	if (skb_vlan_tag_present(skb))
+		nf_log_buf_add(m, "VLAN=%d ", skb_vlan_tag_get_id(skb));
 #endif
 }
 EXPORT_SYMBOL_GPL(nf_log_dump_packet_common);

I have kept this chunk behind. I think exposing the VPROTO would be useful too. Just send a separated patch for this for review, thanks.