Skip to contentSkip to conversation

net: ip, diag -- Add diag interface for raw sockets

PATCH Superseded Cyrill Gorcunov 4 participants 10 messages Sep 9, 2016 – Sep 13, 2016

Subsystems (2)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ip, diag -- Add diag interface for raw sockets

In criu we are actively using diag interface to collect sockets present in the system when dumping applications. And while for unix, tcp, udp[lite], packet, netlink it works as expected, the raw sockets do not have. Thus add it.

CC David S. Miller <[email protected]>
CC Eric Dumazet <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Hideaki YOSHIFUJI <[email protected]>
CC Patrick McHardy <[email protected]>
CC Andrey Vagin <[email protected]>
CC Stephen Hemminger <[email protected]>

---

Take a look please, once time permit. Hopefully I didn't miss something obvious, tested as "ss -n -A raw" for modified iproute2 instance and c/r for trivial application which has raw sockets opened. A patch for ss tool is at https://goo.gl/VFQ93L
for the reference, will send it out then.

 include/net/raw.h   |    5 +
 include/net/rawv6.h |    5 +
 net/ipv4/Kconfig    |    8 ++
 net/ipv4/Makefile   |    1 
 net/ipv4/raw.c      |    6 +
 net/ipv4/raw_diag.c |  192 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv6/raw.c      |    6 +
 7 files changed, 219 insertions(+), 4 deletions(-)
include/net/raw.h +5 -0
Index: linux-ml.git/include/net/raw.h
===================================================================
@@ -23,6 +23,11 @@
 
 extern struct proto raw_prot;
 
+extern struct raw_hashinfo raw_v4_hashinfo;
+struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
+			     unsigned short num, __be32 raddr,
+			     __be32 laddr, int dif);
+
 void raw_icmp_error(struct sk_buff *, int, u32);
 int raw_local_deliver(struct sk_buff *, int);
 
include/net/rawv6.h +5 -0
Index: linux-ml.git/include/net/rawv6.h
===================================================================
@@ -3,6 +3,11 @@
 
 #include <net/protocol.h>
 
+extern struct raw_hashinfo raw_v6_hashinfo;
+struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
+			     unsigned short num, const struct in6_addr *loc_addr,
+			     const struct in6_addr *rmt_addr, int dif);
+
 void raw6_icmp_error(struct sk_buff *, int nexthdr,
 		u8 type, u8 code, int inner_offset, __be32);
 bool raw6_local_deliver(struct sk_buff *, int);
net/ipv4/Kconfig +8 -0
Index: linux-ml.git/net/ipv4/Kconfig
===================================================================
@@ -430,6 +430,14 @@ config INET_UDP_DIAG
 	  Support for UDP socket monitoring interface used by the ss tool.
 	  If unsure, say Y.
 
+config INET_RAW_DIAG
+	tristate "RAW: socket monitoring interface"
+	depends on INET_DIAG && (IPV6 || IPV6=n)
+	default n
+	---help---
+	  Support for RAW socket monitoring interface used by the ss tool.
+	  If unsure, say Y.
+
 config INET_DIAG_DESTROY
 	bool "INET: allow privileged process to administratively close sockets"
 	depends on INET_DIAG
net/ipv4/Makefile +1 -0
Index: linux-ml.git/net/ipv4/Makefile
===================================================================
@@ -40,6 +40,7 @@ obj-$(CONFIG_NETFILTER)	+= netfilter.o n
 obj-$(CONFIG_INET_DIAG) += inet_diag.o 
 obj-$(CONFIG_INET_TCP_DIAG) += tcp_diag.o
 obj-$(CONFIG_INET_UDP_DIAG) += udp_diag.o
+obj-$(CONFIG_INET_RAW_DIAG) += raw_diag.o
 obj-$(CONFIG_NET_TCPPROBE) += tcp_probe.o
 obj-$(CONFIG_TCP_CONG_BIC) += tcp_bic.o
 obj-$(CONFIG_TCP_CONG_CDG) += tcp_cdg.o
net/ipv4/raw.c +4 -2
Index: linux-ml.git/net/ipv4/raw.c
===================================================================
@@ -89,9 +89,10 @@ struct raw_frag_vec {
 	int hlen;
 };
 
-static struct raw_hashinfo raw_v4_hashinfo = {
+struct raw_hashinfo raw_v4_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock),
 };
+EXPORT_SYMBOL_GPL(raw_v4_hashinfo);
 
 int raw_hash_sk(struct sock *sk)
 {
@@ -120,7 +121,7 @@ void raw_unhash_sk(struct sock *sk)
 }
 EXPORT_SYMBOL_GPL(raw_unhash_sk);
 
-static struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
+struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
 		unsigned short num, __be32 raddr, __be32 laddr, int dif)
 {
 	sk_for_each_from(sk) {
@@ -136,6 +137,7 @@ static struct sock *__raw_v4_lookup(stru
 found:
 	return sk;
 }
+EXPORT_SYMBOL_GPL(__raw_v4_lookup);
 
 /*
  *	0 - deliver
net/ipv4/raw_diag.c new file +192 -0

192 lines not on this page · raw message

net/ipv6/raw.c +4 -2
Index: linux-ml.git/net/ipv6/raw.c
===================================================================
@@ -65,11 +65,12 @@
 
 #define	ICMPV6_HDRLEN	4	/* ICMPv6 header, RFC 4443 Section 2.1 */
 
-static struct raw_hashinfo raw_v6_hashinfo = {
+struct raw_hashinfo raw_v6_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
 };
+EXPORT_SYMBOL_GPL(raw_v6_hashinfo);
 
-static struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
+struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
 		unsigned short num, const struct in6_addr *loc_addr,
 		const struct in6_addr *rmt_addr, int dif)
 {
@@ -102,6 +103,7 @@ static struct sock *__raw_v6_lookup(stru
 found:
 	return sk;
 }
+EXPORT_SYMBOL_GPL(__raw_v6_lookup);
 
 /*
  *	0 - deliver
#1 lore raw

On Fri, 2016-09-09 at 21:26 +0300, Cyrill Gorcunov wrote:

...

Quoted 21 lines
net/ipv4/raw_diag.c new file +21 -0
+static int raw_diag_dump_one(struct sk_buff *in_skb,
+			     const struct nlmsghdr *nlh,
+			     const struct inet_diag_req_v2 *r)
+{
+	struct raw_hashinfo *hashinfo = raw_get_hashinfo(r);
+	struct net *net = sock_net(in_skb->sk);
+	struct sock *sk = NULL, *s;
+	int err = -ENOENT, slot;
+	struct sk_buff *rep;
+
+	if (IS_ERR(hashinfo))
+		return PTR_ERR(hashinfo);
+
+	read_lock(&hashinfo->lock);
+	for (slot = 0; slot < RAW_HTABLE_SIZE; slot++) {
+		sk_for_each(s, &hashinfo->ht[slot]) {
+			sk = raw_lookup(net, s, r);
+			if (sk)
+				break;
+		}
+	}

net/ipv4/raw_diag.c line 82

Quoted 10 lines
net/ipv4/raw_diag.c new file +10 -0
+	if (sk && !atomic_inc_not_zero(&sk->sk_refcnt))
+		sk = NULL;
+	read_unlock(&hashinfo->lock);
+	if (!sk)
+		return -ENOENT;
+
+	rep = nlmsg_new(sizeof(struct inet_diag_msg) +
+			sizeof(struct inet_diag_meminfo) + 64,
+			GFP_KERNEL);
+	if (!rep)

There is a missing sock_put(sk)

net/ipv4/raw_diag.c line 88

Quoted 6 lines
net/ipv4/raw_diag.c new file +6 -0
+		return -ENOMEM;
+
+	err = inet_sk_diag_fill(sk, NULL, rep, r,
+				sk_user_ns(NETLINK_CB(in_skb).sk),
+				NETLINK_CB(in_skb).portid,
+				nlh->nlmsg_seq, 0, nlh);

sock_put(sk);

Quoted 15 lines
net/ipv4/raw_diag.c new file +13 -0
+	if (err < 0) {
+		kfree_skb(rep);
 
 
+		return err;
+	}
+
+	err = netlink_unicast(net->diag_nlsk, rep,
+			      NETLINK_CB(in_skb).portid,
+			      MSG_DONTWAIT);
+	if (err > 0)
+		err = 0;
+	return err;
+}
+
#2 lore raw
Quoted 8 lines · Eric Dumazet

net/ipv4/raw_diag.c line 82

Quoted 5 lines
net/ipv4/raw_diag.c new file +5 -0
+
+	rep = nlmsg_new(sizeof(struct inet_diag_msg) +
+			sizeof(struct inet_diag_meminfo) + 64,
+			GFP_KERNEL);
+	if (!rep)

There is a missing sock_put(sk)

Quoted 8 lines

net/ipv4/raw_diag.c line 88

Quoted 6 lines
net/ipv4/raw_diag.c new file +6 -0
+		return -ENOMEM;
+
+	err = inet_sk_diag_fill(sk, NULL, rep, r,
+				sk_user_ns(NETLINK_CB(in_skb).sk),
+				NETLINK_CB(in_skb).portid,
+				nlh->nlmsg_seq, 0, nlh);

sock_put(sk);

Oh, missed. Thanks lot, Eric, will update!

#3 lore raw
In reply to Cyrill Gorcunov
Quoted 14 lines · Cyrill Gorcunov

In criu we are actively using diag interface to collect sockets present in the system when dumping applications. And while for unix, tcp, udp[lite], packet, netlink it works as expected, the raw sockets do not have. Thus add it.

CC David S. Miller <[email protected]>
CC Eric Dumazet <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Hideaki YOSHIFUJI <[email protected]>
CC Patrick McHardy <[email protected]>
CC Andrey Vagin <[email protected]>
CC Stephen Hemminger <[email protected]>
Quoted 1 line

---

Would you mind adding the destroy capability as well? The udp version should be close to what is needed for raw sockets. See udp_diag_destroy and udp_abort.

#4 lore raw
Quoted 17 lines · David Ahern
Quoted 14 lines · Cyrill Gorcunov

In criu we are actively using diag interface to collect sockets present in the system when dumping applications. And while for unix, tcp, udp[lite], packet, netlink it works as expected, the raw sockets do not have. Thus add it.

CC David S. Miller <[email protected]>
CC Eric Dumazet <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Hideaki YOSHIFUJI <[email protected]>
CC Patrick McHardy <[email protected]>
CC Andrey Vagin <[email protected]>
CC Stephen Hemminger <[email protected]>
Quoted 1 line

---

Quoted 2 lines

Would you mind adding the destroy capability as well? The udp version should be close to what is needed for raw sockets. See udp_diag_destroy and udp_abort.

Sure, will do.

#5 lore raw

PATCH v2 1/1 net: ip, diag -- Add diag interface for raw sockets

In reply to David Ahern
Quoted 4 lines · David Ahern

Would you mind adding the destroy capability as well? The udp version should be close to what is needed for raw sockets. See udp_diag_destroy and udp_abort.

Should be something like below. Didn't tested it yet so for review only. Will do testing at Monday.
---
From: Cyrill Gorcunov <[email protected]>
Subject: [PATCH v2] net: ip, diag -- Add diag interface for raw sockets

In criu we are actively using diag interface to collect sockets present in the system when dumping applications. And while for unix, tcp, udp[lite], packet, netlink it works as expected, the raw sockets do not have. Thus add it.

v2:
- add missing sock_put calls in raw_diag_dump_one (by eric.dumazet@)
- implement @destroy for diag requests (by dsa@)

CC David S. Miller <[email protected]>
CC Eric Dumazet <[email protected]>
CC David Ahern <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Hideaki YOSHIFUJI <[email protected]>
CC Patrick McHardy <[email protected]>
CC Andrey Vagin <[email protected]>
CC Stephen Hemminger <[email protected]>

---

Take a look please, once time permit. Hopefully I didn't miss something obvious, tested as "ss -n -A raw" for modified iproute2 instance and c/r for trivial application which has raw sockets opened. A patch for ss tool is at https://goo.gl/VFQ93L
for the reference, will send it out then.

 include/net/raw.h   |    5 +
 include/net/rawv6.h |    5 +
 net/ipv4/Kconfig    |    8 +
 net/ipv4/Makefile   |    1 
 net/ipv4/raw.c      |   22 ++++-
 net/ipv4/raw_diag.c |  219 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv6/raw.c      |    7 +
 7 files changed, 263 insertions(+), 4 deletions(-)
include/net/raw.h +5 -0
Index: linux-ml.git/include/net/raw.h
===================================================================
@@ -23,6 +23,11 @@
 
 extern struct proto raw_prot;
 
+extern struct raw_hashinfo raw_v4_hashinfo;
+struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
+			     unsigned short num, __be32 raddr,
+			     __be32 laddr, int dif);
+
 void raw_icmp_error(struct sk_buff *, int, u32);
 int raw_local_deliver(struct sk_buff *, int);
 
include/net/rawv6.h +5 -0
Index: linux-ml.git/include/net/rawv6.h
===================================================================
@@ -3,6 +3,11 @@
 
 #include <net/protocol.h>
 
+extern struct raw_hashinfo raw_v6_hashinfo;
+struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
+			     unsigned short num, const struct in6_addr *loc_addr,
+			     const struct in6_addr *rmt_addr, int dif);
+
 void raw6_icmp_error(struct sk_buff *, int nexthdr,
 		u8 type, u8 code, int inner_offset, __be32);
 bool raw6_local_deliver(struct sk_buff *, int);
net/ipv4/Kconfig +8 -0
Index: linux-ml.git/net/ipv4/Kconfig
===================================================================
@@ -430,6 +430,14 @@ config INET_UDP_DIAG
 	  Support for UDP socket monitoring interface used by the ss tool.
 	  If unsure, say Y.
 
+config INET_RAW_DIAG
+	tristate "RAW: socket monitoring interface"
+	depends on INET_DIAG && (IPV6 || IPV6=n)
+	default n
+	---help---
+	  Support for RAW socket monitoring interface used by the ss tool.
+	  If unsure, say Y.
+
 config INET_DIAG_DESTROY
 	bool "INET: allow privileged process to administratively close sockets"
 	depends on INET_DIAG
net/ipv4/Makefile +1 -0
Index: linux-ml.git/net/ipv4/Makefile
===================================================================
@@ -40,6 +40,7 @@ obj-$(CONFIG_NETFILTER)	+= netfilter.o n
 obj-$(CONFIG_INET_DIAG) += inet_diag.o 
 obj-$(CONFIG_INET_TCP_DIAG) += tcp_diag.o
 obj-$(CONFIG_INET_UDP_DIAG) += udp_diag.o
+obj-$(CONFIG_INET_RAW_DIAG) += raw_diag.o
 obj-$(CONFIG_NET_TCPPROBE) += tcp_probe.o
 obj-$(CONFIG_TCP_CONG_BIC) += tcp_bic.o
 obj-$(CONFIG_TCP_CONG_CDG) += tcp_cdg.o
net/ipv4/raw.c +20 -2
Index: linux-ml.git/net/ipv4/raw.c
===================================================================
@@ -89,9 +89,10 @@ struct raw_frag_vec {
 	int hlen;
 };
 
-static struct raw_hashinfo raw_v4_hashinfo = {
+struct raw_hashinfo raw_v4_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock),
 };
+EXPORT_SYMBOL_GPL(raw_v4_hashinfo);
 
 int raw_hash_sk(struct sock *sk)
 {
@@ -120,7 +121,7 @@ void raw_unhash_sk(struct sock *sk)
 }
 EXPORT_SYMBOL_GPL(raw_unhash_sk);
 
-static struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
+struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
 		unsigned short num, __be32 raddr, __be32 laddr, int dif)
 {
 	sk_for_each_from(sk) {
@@ -136,6 +137,7 @@ static struct sock *__raw_v4_lookup(stru
 found:
 	return sk;
 }
+EXPORT_SYMBOL_GPL(__raw_v4_lookup);
 
 /*
  *	0 - deliver
@@ -918,6 +920,21 @@ static int compat_raw_ioctl(struct sock
 }
 #endif
 
+int raw_abort(struct sock *sk, int err)
+{
+	lock_sock(sk);
+
+	sk->sk_err = err;
+	sk->sk_error_report(sk);
+	udp_disconnect(sk, 0);
+
+	release_sock(sk);
+
+	sock_put(sk);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(raw_abort);
+
 struct proto raw_prot = {
 	.name		   = "RAW",
 	.owner		   = THIS_MODULE,
@@ -943,6 +960,7 @@ struct proto raw_prot = {
 	.compat_getsockopt = compat_raw_getsockopt,
 	.compat_ioctl	   = compat_raw_ioctl,
 #endif
+	.diag_destroy	   = raw_abort,
 };
 
 #ifdef CONFIG_PROC_FS
net/ipv4/raw_diag.c new file +219 -0

219 lines not on this page · raw message

net/ipv6/raw.c +5 -2
Index: linux-ml.git/net/ipv6/raw.c
===================================================================
@@ -65,11 +65,12 @@
 
 #define	ICMPV6_HDRLEN	4	/* ICMPv6 header, RFC 4443 Section 2.1 */
 
-static struct raw_hashinfo raw_v6_hashinfo = {
+struct raw_hashinfo raw_v6_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
 };
+EXPORT_SYMBOL_GPL(raw_v6_hashinfo);
 
-static struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
+struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
 		unsigned short num, const struct in6_addr *loc_addr,
 		const struct in6_addr *rmt_addr, int dif)
 {
@@ -102,6 +103,7 @@ static struct sock *__raw_v6_lookup(stru
 found:
 	return sk;
 }
+EXPORT_SYMBOL_GPL(__raw_v6_lookup);
 
 /*
  *	0 - deliver
@@ -1252,6 +1254,7 @@ struct proto rawv6_prot = {
 	.compat_getsockopt = compat_rawv6_getsockopt,
 	.compat_ioctl	   = compat_rawv6_ioctl,
 #endif
+	.diag_destroy	   = raw_abort,
 };
 
 #ifdef CONFIG_PROC_FS
#6 lore raw
Quoted 8 lines · Cyrill Gorcunov
Quoted 4 lines · David Ahern

Would you mind adding the destroy capability as well? The udp version should be close to what is needed for raw sockets. See udp_diag_destroy and udp_abort.

Should be something like below. Didn't tested it yet so for review only. Will do testing at Monday.

doesn't compile:
- raw_abort needs to be in a header for ipv6, and
- inet_sk_diag_fill args have changed due to a recent commit

#7 lore raw

PATCH v3 1/1 net: ip, diag -- Add diag interface for raw sockets

Quoted 7 lines · David Ahern
Quoted 6 lines · Cyrill Gorcunov
Quoted 4 lines · David Ahern

Would you mind adding the destroy capability as well? The udp version should be close to what is needed for raw sockets. See udp_diag_destroy and udp_abort.

Quoted 6 lines
Quoted 2 lines

Should be something like below. Didn't tested it yet so for review only. Will do testing at Monday.

doesn't compile:
- raw_abort needs to be in a header for ipv6, and
- inet_sk_diag_fill args have changed due to a recent commit

Thanks for review, David. I updated against net-next.
---
From: Cyrill Gorcunov <[email protected]>
Subject: [PATCH v3] net: ip, diag -- Add diag interface for raw sockets

In criu we are actively using diag interface to collect sockets present in the system when dumping applications. And while for unix, tcp, udp[lite], packet, netlink it works as expected, the raw sockets do not have. Thus add it.

v2:
- add missing sock_put calls in raw_diag_dump_one (by eric.dumazet@)
- implement @destroy for diag requests (by dsa@)

v3:
- add export of raw_abort for IPv6 (by dsa@)
- pass net-admin flag into inet_sk_diag_fill due to changes in net-next branch (by dsa@)

CC David S. Miller <[email protected]>
CC Eric Dumazet <[email protected]>
CC David Ahern <[email protected]>
CC Alexey Kuznetsov <[email protected]>
CC James Morris <[email protected]>
CC Hideaki YOSHIFUJI <[email protected]>
CC Patrick McHardy <[email protected]>
CC Andrey Vagin <[email protected]>
CC Stephen Hemminger <[email protected]>

---

 include/net/raw.h   |    5 +
 include/net/rawv6.h |    7 +
 net/ipv4/Kconfig    |    8 +
 net/ipv4/Makefile   |    1 
 net/ipv4/raw.c      |   21 ++++
 net/ipv4/raw_diag.c |  226 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv6/raw.c      |    7 +
 7 files changed, 271 insertions(+), 4 deletions(-)
include/net/raw.h +5 -0
Index: linux-ml.git/include/net/raw.h
===================================================================
@@ -23,6 +23,11 @@
 
 extern struct proto raw_prot;
 
+extern struct raw_hashinfo raw_v4_hashinfo;
+struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
+			     unsigned short num, __be32 raddr,
+			     __be32 laddr, int dif);
+
 void raw_icmp_error(struct sk_buff *, int, u32);
 int raw_local_deliver(struct sk_buff *, int);
 
include/net/rawv6.h +7 -0
Index: linux-ml.git/include/net/rawv6.h
===================================================================
@@ -3,6 +3,13 @@
 
 #include <net/protocol.h>
 
+extern struct raw_hashinfo raw_v6_hashinfo;
+struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
+			     unsigned short num, const struct in6_addr *loc_addr,
+			     const struct in6_addr *rmt_addr, int dif);
+
+int raw_abort(struct sock *sk, int err);
+
 void raw6_icmp_error(struct sk_buff *, int nexthdr,
 		u8 type, u8 code, int inner_offset, __be32);
 bool raw6_local_deliver(struct sk_buff *, int);
net/ipv4/Kconfig +8 -0
Index: linux-ml.git/net/ipv4/Kconfig
===================================================================
@@ -430,6 +430,14 @@ config INET_UDP_DIAG
 	  Support for UDP socket monitoring interface used by the ss tool.
 	  If unsure, say Y.
 
+config INET_RAW_DIAG
+	tristate "RAW: socket monitoring interface"
+	depends on INET_DIAG && (IPV6 || IPV6=n)
+	default n
+	---help---
+	  Support for RAW socket monitoring interface used by the ss tool.
+	  If unsure, say Y.
+
 config INET_DIAG_DESTROY
 	bool "INET: allow privileged process to administratively close sockets"
 	depends on INET_DIAG
net/ipv4/Makefile +1 -0
Index: linux-ml.git/net/ipv4/Makefile
===================================================================
@@ -40,6 +40,7 @@ obj-$(CONFIG_NETFILTER)	+= netfilter.o n
 obj-$(CONFIG_INET_DIAG) += inet_diag.o 
 obj-$(CONFIG_INET_TCP_DIAG) += tcp_diag.o
 obj-$(CONFIG_INET_UDP_DIAG) += udp_diag.o
+obj-$(CONFIG_INET_RAW_DIAG) += raw_diag.o
 obj-$(CONFIG_NET_TCPPROBE) += tcp_probe.o
 obj-$(CONFIG_TCP_CONG_BIC) += tcp_bic.o
 obj-$(CONFIG_TCP_CONG_CDG) += tcp_cdg.o
net/ipv4/raw.c +19 -2
Index: linux-ml.git/net/ipv4/raw.c
===================================================================
@@ -89,9 +89,10 @@ struct raw_frag_vec {
 	int hlen;
 };
 
-static struct raw_hashinfo raw_v4_hashinfo = {
+struct raw_hashinfo raw_v4_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock),
 };
+EXPORT_SYMBOL_GPL(raw_v4_hashinfo);
 
 int raw_hash_sk(struct sock *sk)
 {
@@ -120,7 +121,7 @@ void raw_unhash_sk(struct sock *sk)
 }
 EXPORT_SYMBOL_GPL(raw_unhash_sk);
 
-static struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
+struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
 		unsigned short num, __be32 raddr, __be32 laddr, int dif)
 {
 	sk_for_each_from(sk) {
@@ -136,6 +137,7 @@ static struct sock *__raw_v4_lookup(stru
 found:
 	return sk;
 }
+EXPORT_SYMBOL_GPL(__raw_v4_lookup);
 
 /*
  *	0 - deliver
@@ -918,6 +920,20 @@ static int compat_raw_ioctl(struct sock
 }
 #endif
 
+int raw_abort(struct sock *sk, int err)
+{
+	lock_sock(sk);
+
+	sk->sk_err = err;
+	sk->sk_error_report(sk);
+	udp_disconnect(sk, 0);
+
+	release_sock(sk);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(raw_abort);
+
 struct proto raw_prot = {
 	.name		   = "RAW",
 	.owner		   = THIS_MODULE,
@@ -943,6 +959,7 @@ struct proto raw_prot = {
 	.compat_getsockopt = compat_raw_getsockopt,
 	.compat_ioctl	   = compat_raw_ioctl,
 #endif
+	.diag_destroy	   = raw_abort,
 };
 
 #ifdef CONFIG_PROC_FS
net/ipv4/raw_diag.c new file +226 -0

226 lines not on this page · raw message

net/ipv6/raw.c +5 -2
Index: linux-ml.git/net/ipv6/raw.c
===================================================================
@@ -65,11 +65,12 @@
 
 #define	ICMPV6_HDRLEN	4	/* ICMPv6 header, RFC 4443 Section 2.1 */
 
-static struct raw_hashinfo raw_v6_hashinfo = {
+struct raw_hashinfo raw_v6_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
 };
+EXPORT_SYMBOL_GPL(raw_v6_hashinfo);
 
-static struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
+struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
 		unsigned short num, const struct in6_addr *loc_addr,
 		const struct in6_addr *rmt_addr, int dif)
 {
@@ -102,6 +103,7 @@ static struct sock *__raw_v6_lookup(stru
 found:
 	return sk;
 }
+EXPORT_SYMBOL_GPL(__raw_v6_lookup);
 
 /*
  *	0 - deliver
@@ -1252,6 +1254,7 @@ struct proto rawv6_prot = {
 	.compat_getsockopt = compat_rawv6_getsockopt,
 	.compat_ioctl	   = compat_rawv6_ioctl,
 #endif
+	.diag_destroy	   = raw_abort,
 };
 
 #ifdef CONFIG_PROC_FS
maintainer
#8 lore raw

From: Cyrill Gorcunov <[email protected]>
Date: Sun, 11 Sep 2016 22:17:15 +0300

Quoted 8 lines · David Ahern
Quoted 7 lines · Cyrill Gorcunov
Quoted 6 lines · David Ahern
Quoted 4 lines

Would you mind adding the destroy capability as well? The udp version should be close to what is needed for raw sockets. See udp_diag_destroy and udp_abort.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Should be something like below. Didn't tested it yet so for review only. Will do testing at Monday.

doesn't compile:
- raw_abort needs to be in a header for ipv6, and
- inet_sk_diag_fill args have changed due to a recent commit

Thanks for review, David. I updated against net-next.

Please do not post new versions of patches as replies to existing discussions.

Instead, make fresh patch postings to the list.

Thanks.

#9 lore raw
Quoted 7 lines · David Miller
Quoted 2 lines

Thanks for review, David. I updated against net-next.

Please do not post new versions of patches as replies to existing discussions.

Instead, make fresh patch postings to the list.

Oh, will do. Sorry for inconvenience.