inet_diag.c (37f352b5e3e89337f7a9a3a90250b5dde3c5f40d) | inet_diag.c (f13c95f0e255e6d21762259875295cc212e6bc32) |
---|---|
1/* 2 * inet_diag.c Module for monitoring INET transport protocols sockets. 3 * 4 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version --- 36 unchanged lines hidden (view full) --- 45 u16 userlocks; 46}; 47 48static struct sock *sdiagnl; 49 50#define INET_DIAG_PUT(skb, attrtype, attrlen) \ 51 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen)) 52 | 1/* 2 * inet_diag.c Module for monitoring INET transport protocols sockets. 3 * 4 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version --- 36 unchanged lines hidden (view full) --- 45 u16 userlocks; 46}; 47 48static struct sock *sdiagnl; 49 50#define INET_DIAG_PUT(skb, attrtype, attrlen) \ 51 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen)) 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); 54 | 65static DEFINE_MUTEX(inet_diag_table_mutex); 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 61 mutex_lock(&inet_diag_table_mutex); | 72 73 mutex_lock(&inet_diag_table_mutex); |
62 if (!inet_diag_table[type]) | 74 if (!inet_diag_table[proto]) |
63 return ERR_PTR(-ENOENT); 64 | 75 return ERR_PTR(-ENOENT); 76 |
65 return inet_diag_table[type]; | 77 return inet_diag_table[proto]; |
66} 67 68static inline void inet_diag_unlock_handler( 69 const struct inet_diag_handler *handler) 70{ 71 mutex_unlock(&inet_diag_table_mutex); 72} 73 --- 6 unchanged lines hidden (view full) --- 80 const struct inet_connection_sock *icsk = inet_csk(sk); 81 struct inet_diag_msg *r; 82 struct nlmsghdr *nlh; 83 void *info = NULL; 84 struct inet_diag_meminfo *minfo = NULL; 85 unsigned char *b = skb_tail_pointer(skb); 86 const struct inet_diag_handler *handler; 87 | 78} 79 80static inline void inet_diag_unlock_handler( 81 const struct inet_diag_handler *handler) 82{ 83 mutex_unlock(&inet_diag_table_mutex); 84} 85 --- 6 unchanged lines hidden (view full) --- 92 const struct inet_connection_sock *icsk = inet_csk(sk); 93 struct inet_diag_msg *r; 94 struct nlmsghdr *nlh; 95 void *info = NULL; 96 struct inet_diag_meminfo *minfo = NULL; 97 unsigned char *b = skb_tail_pointer(skb); 98 const struct inet_diag_handler *handler; 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); 90 91 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r)); 92 nlh->nlmsg_flags = nlmsg_flags; 93 94 r = NLMSG_DATA(nlh); 95 BUG_ON(sk->sk_state == TCP_TIME_WAIT); 96 --- 155 unchanged lines hidden (view full) --- 252{ 253 int err; 254 struct sock *sk; 255 struct inet_diag_req *req = NLMSG_DATA(nlh); 256 struct sk_buff *rep; 257 struct inet_hashinfo *hashinfo; 258 const struct inet_diag_handler *handler; 259 | 101 BUG_ON(handler == NULL); 102 103 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r)); 104 nlh->nlmsg_flags = nlmsg_flags; 105 106 r = NLMSG_DATA(nlh); 107 BUG_ON(sk->sk_state == TCP_TIME_WAIT); 108 --- 155 unchanged lines hidden (view full) --- 264{ 265 int err; 266 struct sock *sk; 267 struct inet_diag_req *req = NLMSG_DATA(nlh); 268 struct sk_buff *rep; 269 struct inet_hashinfo *hashinfo; 270 const struct inet_diag_handler *handler; 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)) { 262 err = PTR_ERR(handler); 263 goto unlock; 264 } 265 266 hashinfo = handler->idiag_hashinfo; 267 err = -EINVAL; 268 --- 433 unchanged lines hidden (view full) --- 702 struct inet_diag_req *r = NLMSG_DATA(cb->nlh); 703 const struct inet_diag_handler *handler; 704 struct inet_hashinfo *hashinfo; 705 const struct nlattr *bc = NULL; 706 707 if (nlmsg_attrlen(cb->nlh, sizeof(struct inet_diag_req))) 708 bc = nlmsg_find_attr(cb->nlh, sizeof(*r), INET_DIAG_REQ_BYTECODE); 709 | 273 if (IS_ERR(handler)) { 274 err = PTR_ERR(handler); 275 goto unlock; 276 } 277 278 hashinfo = handler->idiag_hashinfo; 279 err = -EINVAL; 280 --- 433 unchanged lines hidden (view full) --- 714 struct inet_diag_req *r = NLMSG_DATA(cb->nlh); 715 const struct inet_diag_handler *handler; 716 struct inet_hashinfo *hashinfo; 717 const struct nlattr *bc = NULL; 718 719 if (nlmsg_attrlen(cb->nlh, sizeof(struct inet_diag_req))) 720 bc = nlmsg_find_attr(cb->nlh, sizeof(*r), INET_DIAG_REQ_BYTECODE); 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)) 712 goto unlock; 713 714 hashinfo = handler->idiag_hashinfo; 715 716 s_i = cb->args[1]; 717 s_num = num = cb->args[2]; 718 --- 183 unchanged lines hidden (view full) --- 902 mutex_unlock(&sock_diag_mutex); 903} 904 905int inet_diag_register(const struct inet_diag_handler *h) 906{ 907 const __u16 type = h->idiag_type; 908 int err = -EINVAL; 909 | 723 if (IS_ERR(handler)) 724 goto unlock; 725 726 hashinfo = handler->idiag_hashinfo; 727 728 s_i = cb->args[1]; 729 s_num = num = cb->args[2]; 730 --- 183 unchanged lines hidden (view full) --- 914 mutex_unlock(&sock_diag_mutex); 915} 916 917int inet_diag_register(const struct inet_diag_handler *h) 918{ 919 const __u16 type = h->idiag_type; 920 int err = -EINVAL; 921 |
910 if (type >= INET_DIAG_GETSOCK_MAX) | 922 if (type >= IPPROTO_MAX) |
911 goto out; 912 913 mutex_lock(&inet_diag_table_mutex); 914 err = -EEXIST; 915 if (inet_diag_table[type] == NULL) { 916 inet_diag_table[type] = h; 917 err = 0; 918 } 919 mutex_unlock(&inet_diag_table_mutex); 920out: 921 return err; 922} 923EXPORT_SYMBOL_GPL(inet_diag_register); 924 925void inet_diag_unregister(const struct inet_diag_handler *h) 926{ 927 const __u16 type = h->idiag_type; 928 | 923 goto out; 924 925 mutex_lock(&inet_diag_table_mutex); 926 err = -EEXIST; 927 if (inet_diag_table[type] == NULL) { 928 inet_diag_table[type] = h; 929 err = 0; 930 } 931 mutex_unlock(&inet_diag_table_mutex); 932out: 933 return err; 934} 935EXPORT_SYMBOL_GPL(inet_diag_register); 936 937void inet_diag_unregister(const struct inet_diag_handler *h) 938{ 939 const __u16 type = h->idiag_type; 940 |
929 if (type >= INET_DIAG_GETSOCK_MAX) | 941 if (type >= IPPROTO_MAX) |
930 return; 931 932 mutex_lock(&inet_diag_table_mutex); 933 inet_diag_table[type] = NULL; 934 mutex_unlock(&inet_diag_table_mutex); 935} 936EXPORT_SYMBOL_GPL(inet_diag_unregister); 937 938static int __init inet_diag_init(void) 939{ | 942 return; 943 944 mutex_lock(&inet_diag_table_mutex); 945 inet_diag_table[type] = NULL; 946 mutex_unlock(&inet_diag_table_mutex); 947} 948EXPORT_SYMBOL_GPL(inet_diag_unregister); 949 950static int __init inet_diag_init(void) 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 *)); 942 int err = -ENOMEM; 943 944 inet_diag_table = kzalloc(inet_diag_table_size, GFP_KERNEL); 945 if (!inet_diag_table) 946 goto out; 947 948 sdiagnl = netlink_kernel_create(&init_net, NETLINK_SOCK_DIAG, 0, --- 21 unchanged lines hidden --- | 953 sizeof(struct inet_diag_handler *)); 954 int err = -ENOMEM; 955 956 inet_diag_table = kzalloc(inet_diag_table_size, GFP_KERNEL); 957 if (!inet_diag_table) 958 goto out; 959 960 sdiagnl = netlink_kernel_create(&init_net, NETLINK_SOCK_DIAG, 0, --- 21 unchanged lines hidden --- |