Introducing socket mark socket option
Subsystems (4)
PATCH RESEND 1/1 Introducing socket mark socket option
If netfilter is enabled, a userspace program may wish to set the mark for each packets its send instead of using the MARK target.
Signed-off-by Laszlo Attila Toth <[email protected]>
--- include/asm-alpha/socket.h | 2 ++ include/asm-arm/socket.h | 2 ++ include/asm-avr32/socket.h | 2 ++ include/asm-blackfin/socket.h | 3 +++ include/asm-cris/socket.h | 2 ++ include/asm-frv/socket.h | 2 ++ include/asm-h8300/socket.h | 2 ++ include/asm-ia64/socket.h | 4 +++- include/asm-m32r/socket.h | 2 ++ include/asm-m68k/socket.h | 2 ++ include/asm-mips/socket.h | 2 ++ include/asm-parisc/socket.h | 2 ++ include/asm-powerpc/socket.h | 2 ++ include/asm-s390/socket.h | 2 ++ include/asm-sh/socket.h | 2 ++ include/asm-sparc/socket.h | 2 ++ include/asm-sparc64/socket.h | 1 + include/asm-v850/socket.h | 2 ++ include/asm-x86/socket.h | 2 ++ include/asm-xtensa/socket.h | 2 ++ include/net/route.h | 7 ++++++- include/net/sock.h | 3 +++ net/core/sock.c | 14 ++++++++++++++ net/ipv4/icmp.c | 8 ++++++-- net/ipv4/ip_output.c | 9 +++++++++ net/ipv4/raw.c | 6 ++++++ 26 files changed, 85 insertions(+), 4 deletions(-)
include/asm-alpha/socket.h +2 -0
@@ -60,4 +60,6 @@#define SO_SECURITY_ENCRYPTION_TRANSPORT 20#define SO_SECURITY_ENCRYPTION_NETWORK 21 +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-arm/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-avr32/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* __ASM_AVR32_SOCKET_H */
include/asm-blackfin/socket.h +3 -0
@@ -50,4 +50,7 @@#define SO_PASSSEC 34#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS + +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-cris/socket.h +2 -0
@@ -54,6 +54,8 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-frv/socket.h +2 -0
@@ -52,5 +52,7 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-h8300/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-ia64/socket.h +3 -1
@@ -56,9 +56,11 @@#define SO_ACCEPTCONN 30 -#define SO_PEERSEC 31 +#define SO_PEERSEC 31#define SO_PASSSEC 34#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_IA64_SOCKET_H */
include/asm-m32r/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_M32R_SOCKET_H */
include/asm-m68k/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-mips/socket.h +2 -0
@@ -73,6 +73,8 @@ To add: #define SO_REUSEPORT 0x0200 /* Allow local address and port reuse. */#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#ifdef __KERNEL__/** sock_type - Socket types
include/asm-parisc/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_PEERSEC 0x401d#define SO_PASSSEC 0x401e +#define SO_MARK 0x401f +#endif /* _ASM_SOCKET_H */
include/asm-powerpc/socket.h +2 -0
@@ -59,4 +59,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_POWERPC_SOCKET_H */
include/asm-s390/socket.h +2 -0
@@ -60,4 +60,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-sh/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* __ASM_SH_SOCKET_H */
include/asm-sparc/socket.h +2 -0
@@ -52,6 +52,8 @@#define SO_TIMESTAMPNS 0x0021#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 0x0022 +/* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 0x5001#define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002
include/asm-sparc64/socket.h +1 -0
@@ -57,4 +57,5 @@#define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002#define SO_SECURITY_ENCRYPTION_NETWORK 0x5004 +#define SO_MARK 0x0022#endif /* _ASM_SOCKET_H */
include/asm-v850/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* __V850_SOCKET_H__ */
include/asm-x86/socket.h +2 -0
@@ -52,4 +52,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _ASM_SOCKET_H */
include/asm-xtensa/socket.h +2 -0
@@ -63,4 +63,6 @@#define SO_TIMESTAMPNS 35#define SCM_TIMESTAMPNS SO_TIMESTAMPNS +#define SO_MARK 36 +#endif /* _XTENSA_SOCKET_H */
include/net/route.h +6 -1
@@ -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>
@@ -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 .nl_u = { .ip4_u = { .daddr = dst, .saddr = src, - .tos = tos } }, + .tos = tos, + } }, .proto = protocol, .uli_u = { .ports = { .sport = sport,
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 void *sk_protinfo;struct timer_list sk_timer;ktime_t sk_stamp;
net/core/sock.c +14 -0
@@ -667,6 +667,15 @@ set_rcvbuf:else clear_bit (SOCK_PASSSEC , &sock->flags);break ; +case SO_MARK : +if (!capable (CAP_NET_ADMIN )) + ret = -EPERM ; +else { +#ifdef CONFIG_NETFILTER + sk->sk_mark = val; +#endif + } +break ;/* We implement the SO_SNDLOWAT etc to not be settable (1003.1g 5.3) */
@@ -836,6 +845,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,case SO_PEERSEC :return security_socket_getpeersec_stream (sock, optval, optlen, len); +case SO_MARK : +#ifdef CONFIG_NETFILTER + v.val = sk->sk_mark; +#endif +break ;default :return -ENOPROTOOPT ; }
net/ipv4/icmp.c +6 -2
@@ -401,8 +401,12 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)struct flowi fl = { .nl_u = { .ip4_u = { .daddr = daddr, .saddr = rt->rt_spec_dst, - .tos =RT_TOS (ip_hdr (skb)->tos) } }, - .proto =IPPROTO_ICMP }; + .tos =RT_TOS (ip_hdr (skb)->tos) + } }, +#ifdef CONFIG_NETFILTER + .mark = sk->sk_mark, +#endif + .proto =IPPROTO_ICMP };security_skb_classify_flow (skb, &fl);if (ip_route_output_key (&rt, &fl)) goto out_unlock;
net/ipv4/ip_output.c +9 -0
@@ -168,6 +168,9 @@ int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk, } skb->priority = sk->sk_priority; +#ifdef CONFIG_NETFILTER + skb->mark = sk->sk_mark; +#endif /* Send it out. */ return ip_local_out (skb);
@@ -385,6 +388,9 @@ packet_routed: (skb_shinfo(skb)->gso_segs ?: 1) - 1); skb->priority = sk->sk_priority; +#ifdef CONFIG_NETFILTER + skb->mark = sk->sk_mark; +#endif return ip_local_out (skb);
@@ -1282,6 +1288,9 @@ int ip_push_pending_frames(struct sock *sk) iph->daddr = rt->rt_dst; skb->priority = sk->sk_priority; +#ifdef CONFIG_NETFILTER + skb->mark = sk->sk_mark; +#endif skb->dst =dst_clone (&rt->u.dst);if (iph->protocol ==IPPROTO_ICMP )
net/ipv4/raw.c +6 -0
@@ -352,6 +352,9 @@ static int raw_send_hdrinc(struct sock *sk, void *from, size_t length,skb_reserve (skb, hh_len); skb->priority = sk->sk_priority; +#ifdef CONFIG_NETFILTER + skb->mark = sk->sk_mark; +#endif skb->dst =dst_clone (&rt->u.dst);skb_reset_network_header (skb);
@@ -544,6 +547,9 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, {struct flowi fl = { .oif = ipc.oif, +#ifdef CONFIG_NETFILTER + .mark = sk->sk_mark, +#endif .nl_u = { .ip4_u = { .daddr = daddr, .saddr = saddr,
Signature · 1 line
1.5.2.5
Quoted 4 lines · Laszlo Attila Toth
If netfilter is enabled, a userspace program may wish to set the mark for each packets its send instead of using the MARK target.
For systems where conntrack and xtables is not loaded, I presume? Sounds reasonable.
Jan Engelhardt írta:
Quoted 7 lines · Laszlo Attila Toth
Quoted 3 lines
If netfilter is enabled, a userspace program may wish to set the mark for each packets its send instead of using the MARK target.
For systems where conntrack and xtables is not loaded, I presume? Sounds reasonable.
For this... yes, but mainly in junction with the mark match and mark based routing.
Signature · 5 lines
Panther - To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html