Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netlink/diag: report flags for netlink sockets

cb_running is reported in /proc/self/net/netlink and it is reported by
the ss tool, when it gets information from the proc files.

sock_diag is a new interface which is used instead of proc files, so it
looks reasonable that this interface has to report no less information
about sockets than proc files.

We use these flags to dump and restore netlink sockets.

Signed-off-by: Andrei Vagin <avagin@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Andrey Vagin and committed by
David S. Miller
457c79e5 c8004600

+43 -8
-8
net/netlink/af_netlink.c
··· 78 78 /* state bits */ 79 79 #define NETLINK_S_CONGESTED 0x0 80 80 81 - /* flags */ 82 - #define NETLINK_F_KERNEL_SOCKET 0x1 83 - #define NETLINK_F_RECV_PKTINFO 0x2 84 - #define NETLINK_F_BROADCAST_SEND_ERROR 0x4 85 - #define NETLINK_F_RECV_NO_ENOBUFS 0x8 86 - #define NETLINK_F_LISTEN_ALL_NSID 0x10 87 - #define NETLINK_F_CAP_ACK 0x20 88 - 89 81 static inline int netlink_is_kernel(struct sock *sk) 90 82 { 91 83 return nlk_sk(sk)->flags & NETLINK_F_KERNEL_SOCKET;
+8
net/netlink/af_netlink.h
··· 6 6 #include <linux/workqueue.h> 7 7 #include <net/sock.h> 8 8 9 + /* flags */ 10 + #define NETLINK_F_KERNEL_SOCKET 0x1 11 + #define NETLINK_F_RECV_PKTINFO 0x2 12 + #define NETLINK_F_BROADCAST_SEND_ERROR 0x4 13 + #define NETLINK_F_RECV_NO_ENOBUFS 0x8 14 + #define NETLINK_F_LISTEN_ALL_NSID 0x10 15 + #define NETLINK_F_CAP_ACK 0x20 16 + 9 17 #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8) 10 18 #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long)) 11 19
+25
net/netlink/diag.c
··· 19 19 nlk->groups); 20 20 } 21 21 22 + static int sk_diag_put_flags(struct sock *sk, struct sk_buff *skb) 23 + { 24 + struct netlink_sock *nlk = nlk_sk(sk); 25 + u32 flags = 0; 26 + 27 + if (nlk->cb_running) 28 + flags |= NDIAG_FLAG_CB_RUNNING; 29 + if (nlk->flags & NETLINK_F_RECV_PKTINFO) 30 + flags |= NDIAG_FLAG_PKTINFO; 31 + if (nlk->flags & NETLINK_F_BROADCAST_SEND_ERROR) 32 + flags |= NDIAG_FLAG_BROADCAST_ERROR; 33 + if (nlk->flags & NETLINK_F_RECV_NO_ENOBUFS) 34 + flags |= NDIAG_FLAG_NO_ENOBUFS; 35 + if (nlk->flags & NETLINK_F_LISTEN_ALL_NSID) 36 + flags |= NDIAG_FLAG_LISTEN_ALL_NSID; 37 + if (nlk->flags & NETLINK_F_CAP_ACK) 38 + flags |= NDIAG_FLAG_CAP_ACK; 39 + 40 + return nla_put_u32(skb, NETLINK_DIAG_FLAGS, flags); 41 + } 42 + 22 43 static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, 23 44 struct netlink_diag_req *req, 24 45 u32 portid, u32 seq, u32 flags, int sk_ino) ··· 71 50 72 51 if ((req->ndiag_show & NDIAG_SHOW_MEMINFO) && 73 52 sock_diag_put_meminfo(sk, skb, NETLINK_DIAG_MEMINFO)) 53 + goto out_nlmsg_trim; 54 + 55 + if ((req->ndiag_show & NDIAG_SHOW_FLAGS) && 56 + sk_diag_put_flags(sk, skb)) 74 57 goto out_nlmsg_trim; 75 58 76 59 nlmsg_end(skb, nlh);