Skip to content

Commit 8a360be

Browse files
xemuldavem330
authored andcommitted
packet: Report more packet sk info via diag module
This reports in one rtattr message all the other scalar values, that can be set on a packet socket with setsockopt. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 96ec632 commit 8a360be

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎include/linux/packet_diag.h‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct packet_diag_req {
1212
__u32 pdiag_cookie[2];
1313
};
1414

15+
#define PACKET_SHOW_INFO 0x00000001 /* Basic packet_sk information */
16+
1517
struct packet_diag_msg {
1618
__u8 pdiag_family;
1719
__u8 pdiag_type;
@@ -21,4 +23,25 @@ struct packet_diag_msg {
2123
__u32 pdiag_cookie[2];
2224
};
2325

26+
enum {
27+
PACKET_DIAG_INFO,
28+
29+
PACKET_DIAG_MAX,
30+
};
31+
32+
struct packet_diag_info {
33+
__u32 pdi_index;
34+
__u32 pdi_version;
35+
__u32 pdi_reserve;
36+
__u32 pdi_copy_thresh;
37+
__u32 pdi_tstamp;
38+
__u32 pdi_flags;
39+
40+
#define PDI_RUNNING 0x1
41+
#define PDI_AUXDATA 0x2
42+
#define PDI_ORIGDEV 0x4
43+
#define PDI_VNETHDR 0x8
44+
#define PDI_LOSS 0x10
45+
};
46+
2447
#endif

‎net/packet/diag.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@
77

88
#include "internal.h"
99

10+
static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb)
11+
{
12+
struct packet_diag_info pinfo;
13+
14+
pinfo.pdi_index = po->ifindex;
15+
pinfo.pdi_version = po->tp_version;
16+
pinfo.pdi_reserve = po->tp_reserve;
17+
pinfo.pdi_copy_thresh = po->copy_thresh;
18+
pinfo.pdi_tstamp = po->tp_tstamp;
19+
20+
pinfo.pdi_flags = 0;
21+
if (po->running)
22+
pinfo.pdi_flags |= PDI_RUNNING;
23+
if (po->auxdata)
24+
pinfo.pdi_flags |= PDI_AUXDATA;
25+
if (po->origdev)
26+
pinfo.pdi_flags |= PDI_ORIGDEV;
27+
if (po->has_vnet_hdr)
28+
pinfo.pdi_flags |= PDI_VNETHDR;
29+
if (po->tp_loss)
30+
pinfo.pdi_flags |= PDI_LOSS;
31+
32+
return nla_put(nlskb, PACKET_DIAG_INFO, sizeof(pinfo), &pinfo);
33+
}
34+
1035
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct packet_diag_req *req,
1136
u32 pid, u32 seq, u32 flags, int sk_ino)
1237
{
@@ -25,7 +50,15 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct packet_diag
2550
rp->pdiag_ino = sk_ino;
2651
sock_diag_save_cookie(sk, rp->pdiag_cookie);
2752

53+
if ((req->pdiag_show & PACKET_SHOW_INFO) &&
54+
pdiag_put_info(po, skb))
55+
goto out_nlmsg_trim;
56+
2857
return nlmsg_end(skb, nlh);
58+
59+
out_nlmsg_trim:
60+
nlmsg_cancel(skb, nlh);
61+
return -EMSGSIZE;
2962
}
3063

3164
static int packet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)

0 commit comments

Comments
 (0)