Skip to contentSkip to conversation

Introducing socket mark socket option

PATCH Patrick McHardy 2 participants 2 messages Jan 22, 2008 – Jan 23, 2008 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 12010124971855-git-send-email-

#1 lore raw
Quoted 4 lines · [email protected] wrote:

From: Laszlo Attila Toth <[email protected]>

If netfilter is enabled, a userspace program may wish to set the mark for each packets its send instead of using the MARK target.

Looks reasonable, but please CC netdev and linux-arch.

Quoted 13 lines
include/net/route.h +1 -0
index 5847e6f..70792e3 100644
@@ -27,6 +27,7 @@
 #include <net/dst.h>
 #include <net/inetpeer.h>
 #include <net/flow.h>
+#include <net/sock.h>
 #include <linux/in_route.h>
 #include <linux/rtnetlink.h>
 #include <linux/route.h>

include/net/route.h static inline int ip_route_connect(struct rtable **rp, __be32 dst, · line 154

Quoted 6 lines
include/net/route.h +3 -0
@@ -148,9 +149,13 @@ static inline int ip_route_connect(struct rtable **rp, __be32 dst,
 				   int flags)
 {
 	struct flowi fl = { .oif = oif,
+#ifdef CONFIG_NETFILTER
+			 .mark = sk->sk_mark,
+#endif

Formatting is slightly inconsistent, but more importantly the mark doesn't depend on CONFIG_NETFILTER anymore.

Quoted 13 lines
include/net/route.h +2 -1
 			    .nl_u = { .ip4_u = { .daddr = dst,
 						 .saddr = src,
-						 .tos   = tos } },
+						 .tos   = tos,
+                            } },
 			    .proto = protocol,
 			    .uli_u = { .ports =
 				       { .sport = sport,
include/net/sock.h +0 -0
index 9023244..8e88a0e 100644

include/net/sock.h struct sock { · line 257

Quoted 6 lines
include/net/sock.h +3 -0
@@ -252,6 +252,9 @@ struct sock {
 	long			sk_rcvtimeo;
 	long			sk_sndtimeo;
 	struct sk_filter      	*sk_filter;
+#ifdef CONFIG_NETFILTER
+	__u32			sk_mark;
+#endif

Please find a spot that doesn't add holes on 64 bit.

Quoted 1 line
include/net/sock.h +0 -0
 	void			*sk_protinfo;
#2 lore raw
Quoted 5 lines · Patrick McHardy
Quoted 5 lines
include/net/sock.h +0 -0
index 9023244..8e88a0e 100644
@@ -252,6 +252,9 @@ struct sock {
Quoted 9 lines

include/net/sock.h struct sock { · line 257

Quoted 6 lines
include/net/sock.h +3 -0
     long            sk_rcvtimeo;
     long            sk_sndtimeo;
     struct sk_filter          *sk_filter;
+#ifdef CONFIG_NETFILTER
+    __u32            sk_mark;
+#endif

Please find a spot that doesn't add holes on 64 bit.

It adds if I insert the member before the function pointers. If I add it at the end of struct sock, it is ugly but there is no hole. Pahole's output:

/* --- cacheline 8 boundary (512 bytes) --- */
void (*sk_destruct)(struct sock *); /*
512 8 */

        __u32                      sk_mark;              /*   520     4 */

        /* size: 528, cachelines: 9 */
        /* padding: 4 */
        /* paddings: 4, sum paddings: 16 */
        /* last cacheline: 16 bytes */
};      /* definitions: 80 */

I'd prefer the following:

include/net/sock.h +2 -0
index 9023244..67de401 100644
@@ -262,6 +262,8 @@ struct sock {
        __u32                   sk_sndmsg_off;
        int                     sk_write_pending;
        void                    *sk_security;
+       __u32                   sk_mark;
+       /* XXX 4 bytes hole on 64 bit */
        void                    (*sk_state_change)(struct sock *sk);
        void                    (*sk_data_ready)(struct sock *sk, int 
bytes);
        void                    (*sk_write_space)(struct sock *sk);

--
Attila