aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2012-08-16 01:34:22 -0400
committerDavid S. Miller <davem@davemloft.net>2012-08-20 05:23:14 -0400
commit16f01365fa01150bf3606fe702a80a03ec87953a (patch)
tree07695d8703bb3b25a97b5ec3a80b5701daeb111d
parent5ef5d6c569f80cf716d75fa88e9b5ee72f0986b2 (diff)
packet: Report rings cfg via diag engine
One extension bit may result in two nlattrs -- one per ring type. If some ring type is not configured, then the respective nlatts will be empty. The structure reported contains the data, that is given to the corresponding ring setup socket option. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/packet_diag.h13
-rw-r--r--net/packet/diag.c48
2 files changed, 60 insertions, 1 deletions
diff --git a/include/linux/packet_diag.h b/include/linux/packet_diag.h
index ea2e8923bd7e..34ade828979b 100644
--- a/include/linux/packet_diag.h
+++ b/include/linux/packet_diag.h
@@ -14,6 +14,7 @@ struct packet_diag_req {
14 14
15#define PACKET_SHOW_INFO 0x00000001 /* Basic packet_sk information */ 15#define PACKET_SHOW_INFO 0x00000001 /* Basic packet_sk information */
16#define PACKET_SHOW_MCLIST 0x00000002 /* A set of packet_diag_mclist-s */ 16#define PACKET_SHOW_MCLIST 0x00000002 /* A set of packet_diag_mclist-s */
17#define PACKET_SHOW_RING_CFG 0x00000004 /* Rings configuration parameters */
17 18
18struct packet_diag_msg { 19struct packet_diag_msg {
19 __u8 pdiag_family; 20 __u8 pdiag_family;
@@ -27,6 +28,8 @@ struct packet_diag_msg {
27enum { 28enum {
28 PACKET_DIAG_INFO, 29 PACKET_DIAG_INFO,
29 PACKET_DIAG_MCLIST, 30 PACKET_DIAG_MCLIST,
31 PACKET_DIAG_RX_RING,
32 PACKET_DIAG_TX_RING,
30 33
31 PACKET_DIAG_MAX, 34 PACKET_DIAG_MAX,
32}; 35};
@@ -54,4 +57,14 @@ struct packet_diag_mclist {
54 __u8 pdmc_addr[MAX_ADDR_LEN]; 57 __u8 pdmc_addr[MAX_ADDR_LEN];
55}; 58};
56 59
60struct packet_diag_ring {
61 __u32 pdr_block_size;
62 __u32 pdr_block_nr;
63 __u32 pdr_frame_size;
64 __u32 pdr_frame_nr;
65 __u32 pdr_retire_tmo;
66 __u32 pdr_sizeof_priv;
67 __u32 pdr_features;
68};
69
57#endif 70#endif
diff --git a/net/packet/diag.c b/net/packet/diag.c
index 3dda4ecb9a46..e3975e4d458c 100644
--- a/net/packet/diag.c
+++ b/net/packet/diag.c
@@ -67,12 +67,54 @@ static int pdiag_put_mclist(const struct packet_sock *po, struct sk_buff *nlskb)
67 return 0; 67 return 0;
68} 68}
69 69
70static int pdiag_put_ring(struct packet_ring_buffer *ring, int ver, int nl_type,
71 struct sk_buff *nlskb)
72{
73 struct packet_diag_ring pdr;
74
75 if (!ring->pg_vec || ((ver > TPACKET_V2) &&
76 (nl_type == PACKET_DIAG_TX_RING)))
77 return 0;
78
79 pdr.pdr_block_size = ring->pg_vec_pages << PAGE_SHIFT;
80 pdr.pdr_block_nr = ring->pg_vec_len;
81 pdr.pdr_frame_size = ring->frame_size;
82 pdr.pdr_frame_nr = ring->frame_max + 1;
83
84 if (ver > TPACKET_V2) {
85 pdr.pdr_retire_tmo = ring->prb_bdqc.retire_blk_tov;
86 pdr.pdr_sizeof_priv = ring->prb_bdqc.blk_sizeof_priv;
87 pdr.pdr_features = ring->prb_bdqc.feature_req_word;
88 } else {
89 pdr.pdr_retire_tmo = 0;
90 pdr.pdr_sizeof_priv = 0;
91 pdr.pdr_features = 0;
92 }
93
94 return nla_put(nlskb, nl_type, sizeof(pdr), &pdr);
95}
96
97static int pdiag_put_rings_cfg(struct packet_sock *po, struct sk_buff *skb)
98{
99 int ret;
100
101 mutex_lock(&po->pg_vec_lock);
102 ret = pdiag_put_ring(&po->rx_ring, po->tp_version,
103 PACKET_DIAG_RX_RING, skb);
104 if (!ret)
105 ret = pdiag_put_ring(&po->tx_ring, po->tp_version,
106 PACKET_DIAG_TX_RING, skb);
107 mutex_unlock(&po->pg_vec_lock);
108
109 return ret;
110}
111
70static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct packet_diag_req *req, 112static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct packet_diag_req *req,
71 u32 pid, u32 seq, u32 flags, int sk_ino) 113 u32 pid, u32 seq, u32 flags, int sk_ino)
72{ 114{
73 struct nlmsghdr *nlh; 115 struct nlmsghdr *nlh;
74 struct packet_diag_msg *rp; 116 struct packet_diag_msg *rp;
75 const struct packet_sock *po = pkt_sk(sk); 117 struct packet_sock *po = pkt_sk(sk);
76 118
77 nlh = nlmsg_put(skb, pid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rp), flags); 119 nlh = nlmsg_put(skb, pid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rp), flags);
78 if (!nlh) 120 if (!nlh)
@@ -93,6 +135,10 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct packet_diag
93 pdiag_put_mclist(po, skb)) 135 pdiag_put_mclist(po, skb))
94 goto out_nlmsg_trim; 136 goto out_nlmsg_trim;
95 137
138 if ((req->pdiag_show & PACKET_SHOW_RING_CFG) &&
139 pdiag_put_rings_cfg(po, skb))
140 goto out_nlmsg_trim;
141
96 return nlmsg_end(skb, nlh); 142 return nlmsg_end(skb, nlh);
97 143
98out_nlmsg_trim: 144out_nlmsg_trim: