Skip to content

Commit eea68e2

Browse files
xemuldavem330
authored andcommitted
packet: Report socket mclist info via diag module
The info is reported as an array of packet_diag_mclist structures. Each includes not only the directly configured values (index, type, etc), but also the "count". Signed-off-by: Pavel Emelyanov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8a360be commit eea68e2

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

include/linux/packet_diag.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct packet_diag_req {
1313
};
1414

1515
#define PACKET_SHOW_INFO 0x00000001 /* Basic packet_sk information */
16+
#define PACKET_SHOW_MCLIST 0x00000002 /* A set of packet_diag_mclist-s */
1617

1718
struct packet_diag_msg {
1819
__u8 pdiag_family;
@@ -25,6 +26,7 @@ struct packet_diag_msg {
2526

2627
enum {
2728
PACKET_DIAG_INFO,
29+
PACKET_DIAG_MCLIST,
2830

2931
PACKET_DIAG_MAX,
3032
};
@@ -44,4 +46,12 @@ struct packet_diag_info {
4446
#define PDI_LOSS 0x10
4547
};
4648

49+
struct packet_diag_mclist {
50+
__u32 pdmc_index;
51+
__u32 pdmc_count;
52+
__u16 pdmc_type;
53+
__u16 pdmc_alen;
54+
__u8 pdmc_addr[MAX_ADDR_LEN];
55+
};
56+
4757
#endif

net/packet/diag.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <linux/module.h>
22
#include <linux/sock_diag.h>
33
#include <linux/net.h>
4+
#include <linux/netdevice.h>
45
#include <linux/packet_diag.h>
56
#include <net/net_namespace.h>
67
#include <net/sock.h>
@@ -32,6 +33,40 @@ static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb)
3233
return nla_put(nlskb, PACKET_DIAG_INFO, sizeof(pinfo), &pinfo);
3334
}
3435

36+
static int pdiag_put_mclist(const struct packet_sock *po, struct sk_buff *nlskb)
37+
{
38+
struct nlattr *mca;
39+
struct packet_mclist *ml;
40+
41+
mca = nla_nest_start(nlskb, PACKET_DIAG_MCLIST);
42+
if (!mca)
43+
return -EMSGSIZE;
44+
45+
rtnl_lock();
46+
for (ml = po->mclist; ml; ml = ml->next) {
47+
struct packet_diag_mclist *dml;
48+
49+
dml = nla_reserve_nohdr(nlskb, sizeof(*dml));
50+
if (!dml) {
51+
rtnl_unlock();
52+
nla_nest_cancel(nlskb, mca);
53+
return -EMSGSIZE;
54+
}
55+
56+
dml->pdmc_index = ml->ifindex;
57+
dml->pdmc_type = ml->type;
58+
dml->pdmc_alen = ml->alen;
59+
dml->pdmc_count = ml->count;
60+
BUILD_BUG_ON(sizeof(dml->pdmc_addr) != sizeof(ml->addr));
61+
memcpy(dml->pdmc_addr, ml->addr, sizeof(ml->addr));
62+
}
63+
64+
rtnl_unlock();
65+
nla_nest_end(nlskb, mca);
66+
67+
return 0;
68+
}
69+
3570
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct packet_diag_req *req,
3671
u32 pid, u32 seq, u32 flags, int sk_ino)
3772
{
@@ -54,6 +89,10 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct packet_diag
5489
pdiag_put_info(po, skb))
5590
goto out_nlmsg_trim;
5691

92+
if ((req->pdiag_show & PACKET_SHOW_MCLIST) &&
93+
pdiag_put_mclist(po, skb))
94+
goto out_nlmsg_trim;
95+
5796
return nlmsg_end(skb, nlh);
5897

5998
out_nlmsg_trim:

0 commit comments

Comments
 (0)