aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2011-12-06 03:05:24 -0500
committerDavid S. Miller <davem@davemloft.net>2011-12-06 13:58:01 -0500
commitf13c95f0e255e6d21762259875295cc212e6bc32 (patch)
treead60d56913b6be75b8735632af675a47f996c76d /net
parent37f352b5e3e89337f7a9a3a90250b5dde3c5f40d (diff)
inet_diag: Switch from _GETSOCK to IPPROTO_ numbers
Sorry, but the vger didn't let this message go to the list. Re-sending it with less spam-filter-prone subject. When dumping the AF_INET/AF_INET6 sockets user will also specify the protocol, so prepare the protocol diag handlers to work with IPPROTO_ constants. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/dccp/diag.c4
-rw-r--r--net/ipv4/inet_diag.c34
-rw-r--r--net/ipv4/tcp_diag.c4
3 files changed, 27 insertions, 15 deletions
diff --git a/net/dccp/diag.c b/net/dccp/diag.c
index d92ba7d1c351..424dcd8415d7 100644
--- a/net/dccp/diag.c
+++ b/net/dccp/diag.c
@@ -51,7 +51,7 @@ static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
51static const struct inet_diag_handler dccp_diag_handler = { 51static const struct inet_diag_handler dccp_diag_handler = {
52 .idiag_hashinfo = &dccp_hashinfo, 52 .idiag_hashinfo = &dccp_hashinfo,
53 .idiag_get_info = dccp_diag_get_info, 53 .idiag_get_info = dccp_diag_get_info,
54 .idiag_type = DCCPDIAG_GETSOCK, 54 .idiag_type = IPPROTO_DCCP,
55 .idiag_info_size = sizeof(struct tcp_info), 55 .idiag_info_size = sizeof(struct tcp_info),
56}; 56};
57 57
@@ -71,4 +71,4 @@ module_exit(dccp_diag_fini);
71MODULE_LICENSE("GPL"); 71MODULE_LICENSE("GPL");
72MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>"); 72MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>");
73MODULE_DESCRIPTION("DCCP inet_diag handler"); 73MODULE_DESCRIPTION("DCCP inet_diag handler");
74MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, DCCPDIAG_GETSOCK); 74MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 33);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 7aad6ad24dda..58caecc343b1 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -50,19 +50,31 @@ static struct sock *sdiagnl;
50#define INET_DIAG_PUT(skb, attrtype, attrlen) \ 50#define INET_DIAG_PUT(skb, attrtype, attrlen) \
51 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen)) 51 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
52 52
53static inline int inet_diag_type2proto(int type)
54{
55 switch (type) {
56 case TCPDIAG_GETSOCK:
57 return IPPROTO_TCP;
58 case DCCPDIAG_GETSOCK:
59 return IPPROTO_DCCP;
60 default:
61 return 0;
62 }
63}
64
53static DEFINE_MUTEX(inet_diag_table_mutex); 65static DEFINE_MUTEX(inet_diag_table_mutex);
54 66
55static const struct inet_diag_handler *inet_diag_lock_handler(int type) 67static const struct inet_diag_handler *inet_diag_lock_handler(int proto)
56{ 68{
57 if (!inet_diag_table[type]) 69 if (!inet_diag_table[proto])
58 request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK, 70 request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
59 NETLINK_SOCK_DIAG, type); 71 NETLINK_SOCK_DIAG, proto);
60 72
61 mutex_lock(&inet_diag_table_mutex); 73 mutex_lock(&inet_diag_table_mutex);
62 if (!inet_diag_table[type]) 74 if (!inet_diag_table[proto])
63 return ERR_PTR(-ENOENT); 75 return ERR_PTR(-ENOENT);
64 76
65 return inet_diag_table[type]; 77 return inet_diag_table[proto];
66} 78}
67 79
68static inline void inet_diag_unlock_handler( 80static inline void inet_diag_unlock_handler(
@@ -85,7 +97,7 @@ static int inet_csk_diag_fill(struct sock *sk,
85 unsigned char *b = skb_tail_pointer(skb); 97 unsigned char *b = skb_tail_pointer(skb);
86 const struct inet_diag_handler *handler; 98 const struct inet_diag_handler *handler;
87 99
88 handler = inet_diag_table[unlh->nlmsg_type]; 100 handler = inet_diag_table[inet_diag_type2proto(unlh->nlmsg_type)];
89 BUG_ON(handler == NULL); 101 BUG_ON(handler == NULL);
90 102
91 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r)); 103 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
@@ -257,7 +269,7 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
257 struct inet_hashinfo *hashinfo; 269 struct inet_hashinfo *hashinfo;
258 const struct inet_diag_handler *handler; 270 const struct inet_diag_handler *handler;
259 271
260 handler = inet_diag_lock_handler(nlh->nlmsg_type); 272 handler = inet_diag_lock_handler(inet_diag_type2proto(nlh->nlmsg_type));
261 if (IS_ERR(handler)) { 273 if (IS_ERR(handler)) {
262 err = PTR_ERR(handler); 274 err = PTR_ERR(handler);
263 goto unlock; 275 goto unlock;
@@ -707,7 +719,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
707 if (nlmsg_attrlen(cb->nlh, sizeof(struct inet_diag_req))) 719 if (nlmsg_attrlen(cb->nlh, sizeof(struct inet_diag_req)))
708 bc = nlmsg_find_attr(cb->nlh, sizeof(*r), INET_DIAG_REQ_BYTECODE); 720 bc = nlmsg_find_attr(cb->nlh, sizeof(*r), INET_DIAG_REQ_BYTECODE);
709 721
710 handler = inet_diag_lock_handler(cb->nlh->nlmsg_type); 722 handler = inet_diag_lock_handler(inet_diag_type2proto(cb->nlh->nlmsg_type));
711 if (IS_ERR(handler)) 723 if (IS_ERR(handler))
712 goto unlock; 724 goto unlock;
713 725
@@ -907,7 +919,7 @@ int inet_diag_register(const struct inet_diag_handler *h)
907 const __u16 type = h->idiag_type; 919 const __u16 type = h->idiag_type;
908 int err = -EINVAL; 920 int err = -EINVAL;
909 921
910 if (type >= INET_DIAG_GETSOCK_MAX) 922 if (type >= IPPROTO_MAX)
911 goto out; 923 goto out;
912 924
913 mutex_lock(&inet_diag_table_mutex); 925 mutex_lock(&inet_diag_table_mutex);
@@ -926,7 +938,7 @@ void inet_diag_unregister(const struct inet_diag_handler *h)
926{ 938{
927 const __u16 type = h->idiag_type; 939 const __u16 type = h->idiag_type;
928 940
929 if (type >= INET_DIAG_GETSOCK_MAX) 941 if (type >= IPPROTO_MAX)
930 return; 942 return;
931 943
932 mutex_lock(&inet_diag_table_mutex); 944 mutex_lock(&inet_diag_table_mutex);
@@ -937,7 +949,7 @@ EXPORT_SYMBOL_GPL(inet_diag_unregister);
937 949
938static int __init inet_diag_init(void) 950static int __init inet_diag_init(void)
939{ 951{
940 const int inet_diag_table_size = (INET_DIAG_GETSOCK_MAX * 952 const int inet_diag_table_size = (IPPROTO_MAX *
941 sizeof(struct inet_diag_handler *)); 953 sizeof(struct inet_diag_handler *));
942 int err = -ENOMEM; 954 int err = -ENOMEM;
943 955
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index 9e276b868ce8..981497795d49 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -37,7 +37,7 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
37static const struct inet_diag_handler tcp_diag_handler = { 37static const struct inet_diag_handler tcp_diag_handler = {
38 .idiag_hashinfo = &tcp_hashinfo, 38 .idiag_hashinfo = &tcp_hashinfo,
39 .idiag_get_info = tcp_diag_get_info, 39 .idiag_get_info = tcp_diag_get_info,
40 .idiag_type = TCPDIAG_GETSOCK, 40 .idiag_type = IPPROTO_TCP,
41 .idiag_info_size = sizeof(struct tcp_info), 41 .idiag_info_size = sizeof(struct tcp_info),
42}; 42};
43 43
@@ -54,4 +54,4 @@ static void __exit tcp_diag_exit(void)
54module_init(tcp_diag_init); 54module_init(tcp_diag_init);
55module_exit(tcp_diag_exit); 55module_exit(tcp_diag_exit);
56MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
57MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, TCPDIAG_GETSOCK); 57MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 6);