Patchwork [11/14] netlink: add RX/TX-ring support to netlink diag

login
register
mail settings
Submitter Patrick McHardy
Date April 17, 2013, 4:47 p.m.
Message ID <1366217229-22705-12-git-send-email-kaber@trash.net>
Download mbox | patch
Permalink /patch/237307/
State Awaiting Upstream
Headers show

Comments

Patrick McHardy - April 17, 2013, 4:47 p.m.
Based on AF_PACKET.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 include/uapi/linux/netlink_diag.h | 10 ++++++++++
 net/netlink/diag.c                | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
Christoph Paasch - April 23, 2013, 6:28 p.m.
Hello,

On Wednesday 17 April 2013 18:47:06 Patrick McHardy wrote:
> +       mutex_lock(&nlk->pg_vec_lock);
> +       ret = sk_diag_put_ring(&nlk->rx_ring, NETLINK_DIAG_RX_RING, nlskb);
> +       if (!ret)
> +               ret = sk_diag_put_ring(&nlk->tx_ring, NETLINK_DIAG_TX_RING,
> +                                      nlskb);
> +       mutex_unlock(&nlk->pg_vec_lock);

this produces a build-error, if CONFIG_NETLINK_MMAP=n:

/home/cpaasch/builder/net-next/net/netlink/diag.c: In function 
‘sk_diag_put_rings_cfg’:
/home/cpaasch/builder/net-next/net/netlink/diag.c:28: error: ‘struct 
netlink_sock’ has no member named ‘pg_vec_lock’
/home/cpaasch/builder/net-next/net/netlink/diag.c:29: error: ‘struct 
netlink_sock’ has no member named ‘rx_ring’


Should the #ifdef CONFIG_NETLINK_MMAP in struct netlink_sock be removed?


Cheers,
Christoph
David Miller - April 23, 2013, 7:23 p.m.
From: Christoph Paasch <christoph.paasch@uclouvain.be>
Date: Tue, 23 Apr 2013 20:28:35 +0200

> Hello,
> 
> On Wednesday 17 April 2013 18:47:06 Patrick McHardy wrote:
>> +       mutex_lock(&nlk->pg_vec_lock);
>> +       ret = sk_diag_put_ring(&nlk->rx_ring, NETLINK_DIAG_RX_RING, nlskb);
>> +       if (!ret)
>> +               ret = sk_diag_put_ring(&nlk->tx_ring, NETLINK_DIAG_TX_RING,
>> +                                      nlskb);
>> +       mutex_unlock(&nlk->pg_vec_lock);
> 
> this produces a build-error, if CONFIG_NETLINK_MMAP=n:

See:

	http://marc.info/?l=linux-netdev&m=136674481328037&w=2
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christoph Paasch - April 23, 2013, 7:43 p.m.
On Tuesday 23 April 2013 15:23:39 David Miller wrote:
> > On Wednesday 17 April 2013 18:47:06 Patrick McHardy wrote:
> >> +       mutex_lock(&nlk->pg_vec_lock);
> >> +       ret = sk_diag_put_ring(&nlk->rx_ring, NETLINK_DIAG_RX_RING,
> >> nlskb);
> >> +       if (!ret)
> >> +               ret = sk_diag_put_ring(&nlk->tx_ring,
> >> NETLINK_DIAG_TX_RING,
> >> +                                      nlskb);
> >> +       mutex_unlock(&nlk->pg_vec_lock);
> >
> > 
> >
> > this produces a build-error, if CONFIG_NETLINK_MMAP=n:
> See:
> 
>         http://marc.info/?l=linux-netdev&m=136674481328037&w=2

Ok, I see. He was slightly quicker than me :)

Patch

diff --git a/include/uapi/linux/netlink_diag.h b/include/uapi/linux/netlink_diag.h
index 88009a3..4e31db4 100644
--- a/include/uapi/linux/netlink_diag.h
+++ b/include/uapi/linux/netlink_diag.h
@@ -25,9 +25,18 @@  struct netlink_diag_msg {
 	__u32	ndiag_cookie[2];
 };
 
+struct netlink_diag_ring {
+	__u32	ndr_block_size;
+	__u32	ndr_block_nr;
+	__u32	ndr_frame_size;
+	__u32	ndr_frame_nr;
+};
+
 enum {
 	NETLINK_DIAG_MEMINFO,
 	NETLINK_DIAG_GROUPS,
+	NETLINK_DIAG_RX_RING,
+	NETLINK_DIAG_TX_RING,
 
 	__NETLINK_DIAG_MAX,
 };
@@ -38,5 +47,6 @@  enum {
 
 #define NDIAG_SHOW_MEMINFO	0x00000001 /* show memory info of a socket */
 #define NDIAG_SHOW_GROUPS	0x00000002 /* show groups of a netlink socket */
+#define NDIAG_SHOW_RING_CFG	0x00000004 /* show ring configuration */
 
 #endif
diff --git a/net/netlink/diag.c b/net/netlink/diag.c
index 5ffb1d1..4e4aa47 100644
--- a/net/netlink/diag.c
+++ b/net/netlink/diag.c
@@ -7,6 +7,34 @@ 
 
 #include "af_netlink.h"
 
+static int sk_diag_put_ring(struct netlink_ring *ring, int nl_type,
+			    struct sk_buff *nlskb)
+{
+	struct netlink_diag_ring ndr;
+
+	ndr.ndr_block_size = ring->pg_vec_pages << PAGE_SHIFT;
+	ndr.ndr_block_nr   = ring->pg_vec_len;
+	ndr.ndr_frame_size = ring->frame_size;
+	ndr.ndr_frame_nr   = ring->frame_max + 1;
+
+	return nla_put(nlskb, nl_type, sizeof(ndr), &ndr);
+}
+
+static int sk_diag_put_rings_cfg(struct sock *sk, struct sk_buff *nlskb)
+{
+	struct netlink_sock *nlk = nlk_sk(sk);
+	int ret;
+
+	mutex_lock(&nlk->pg_vec_lock);
+	ret = sk_diag_put_ring(&nlk->rx_ring, NETLINK_DIAG_RX_RING, nlskb);
+	if (!ret)
+		ret = sk_diag_put_ring(&nlk->tx_ring, NETLINK_DIAG_TX_RING,
+				       nlskb);
+	mutex_unlock(&nlk->pg_vec_lock);
+
+	return ret;
+}
+
 static int sk_diag_dump_groups(struct sock *sk, struct sk_buff *nlskb)
 {
 	struct netlink_sock *nlk = nlk_sk(sk);
@@ -51,6 +79,10 @@  static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
 	    sock_diag_put_meminfo(sk, skb, NETLINK_DIAG_MEMINFO))
 		goto out_nlmsg_trim;
 
+	if ((req->ndiag_show & NDIAG_SHOW_RING_CFG) &&
+	    sk_diag_put_rings_cfg(sk, skb))
+		goto out_nlmsg_trim;
+
 	return nlmsg_end(skb, nlh);
 
 out_nlmsg_trim: