Skip to contentSkip to conversation

netfilter: xt_socket: add XT_SOCKET_RESTORESKMARK flag

PATCH In review Harout Hedeshian 2 participants 3 messages Jun 16, 2015

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

PATCH 1/1 netfilter: xt_socket: add XT_SOCKET_RESTORESKMARK flag

xt_socket is useful for matching sockets with IP_TRANSPARENT and taking some action on the matching packets. However, it lacks the ability to match only a small subset of transparent sockets.

Suppose there are 2 applications, each with its own set of transparent sockets. The first application wants all matching packets dropped, while the second application wants them forwarded somewhere else.

Add the ability to retore the skb->mark from the sk_mark. The mark is only restored if a matching socket is found and the transparent / nowildcard conditions are satisfied.

Now the 2 hypothetical applications can differentiate their sockets based on a mark value set with SO_MARK.

iptables -t mangle -I PREROUTING -m socket --transparent \
--restore-skmark -j action
iptables -t mangle -I PREROUTING -m socket --transparent \
--restore-skmark -j action
iptables -t mangle -A action -m mark --mark 10 -j action2 iptables -t mangle -A action -m mark --mark 11 -j action3

---
 include/uapi/linux/netfilter/xt_socket.h |  8 +++++
 net/netfilter/xt_socket.c                | 59 ++++++++++++++++++++++++++++----
 2 files changed, 61 insertions(+), 6 deletions(-)
include/uapi/linux/netfilter/xt_socket.h +8 -0
index 6315e2a..87644f8 100644
@@ -6,6 +6,7 @@
 enum {
 	XT_SOCKET_TRANSPARENT = 1 << 0,
 	XT_SOCKET_NOWILDCARD = 1 << 1,
+	XT_SOCKET_RESTORESKMARK = 1 << 2,
 };
 
 struct xt_socket_mtinfo1 {
@@ -18,4 +19,11 @@ struct xt_socket_mtinfo2 {
 };
 #define XT_SOCKET_FLAGS_V2 (XT_SOCKET_TRANSPARENT | XT_SOCKET_NOWILDCARD)
 
+struct xt_socket_mtinfo3 {
+	__u8 flags;
+};
+#define XT_SOCKET_FLAGS_V3 (XT_SOCKET_TRANSPARENT \
+			   | XT_SOCKET_NOWILDCARD \
+			   | XT_SOCKET_RESTORESKMARK)
+
 #endif /* _XT_SOCKET_H */
net/netfilter/xt_socket.c +53 -6

127 lines not on this page · raw message

Signature · 2 lines
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
#1 lore raw
Quoted 23 lines

-----Original Message-----
From: [email protected] [mailto:netfilter-devel- [email protected]] On Behalf Of Harout Hedeshian
Sent: Monday, June 15, 2015 6:41 PM
To: [email protected]
Cc: Lorenzo Colitti; Harout Hedeshian
Subject: [PATCH nf-next] netfilter: xt_socket: add XT_SOCKET_RESTORESKMARK flag

xt_socket is useful for matching sockets with IP_TRANSPARENT and taking some action on the matching packets. However, it lacks the ability to match only a small subset of transparent sockets.

Suppose there are 2 applications, each with its own set of transparent sockets. The first application wants all matching packets dropped, while the second application wants them forwarded somewhere else.

Add the ability to retore the skb->mark from the sk_mark. The mark is only restored if a matching socket is found and the transparent / nowildcard conditions are satisfied.

Quoted 7 lines

Now the 2 hypothetical applications can differentiate their sockets based on a mark value set with SO_MARK.

iptables -t mangle -I PREROUTING -m socket --transparent \
--restore-skmark -j action
iptables -t mangle -I PREROUTING -m socket --transparent \
--restore-skmark -j action

Oops, redundant command in the commit message. I'll submit a v2 if we are happy with the rest of the patch.

Quoted 3 lines

iptables -t mangle -A action -m mark --mark 10 -j action2 iptables -t mangle -A action -m mark --mark 11 -j action3

#2 lore raw

On Tue, Jun 16, 2015 at 07:38:44AM -0600, Harout Hedeshian wrote:
[...]

Quoted 10 lines
Quoted 7 lines

Now the 2 hypothetical applications can differentiate their sockets based on a mark value set with SO_MARK.

iptables -t mangle -I PREROUTING -m socket --transparent \
--restore-skmark -j action
iptables -t mangle -I PREROUTING -m socket --transparent \
--restore-skmark -j action

Oops, redundant command in the commit message. I'll submit a v2 if we are happy with the rest of the patch.

Never mind, I'll mangle this myself here before applying it.

Quoted 2 lines
Quoted 2 lines

iptables -t mangle -A action -m mark --mark 10 -j action2 iptables -t mangle -A action -m mark --mark 11 -j action3