aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2011-12-06 02:59:52 -0500
committerDavid S. Miller <davem@davemloft.net>2011-12-06 13:58:02 -0500
commit8ef874bfc7296fa206eea2ad1e8a426f576bf6f6 (patch)
tree1746f3acd306c55bff845a56e783ec6f1bd6fc6e /net/ipv4
parenta029fe26b67f815eddd432d9e702b9f2edbc2535 (diff)
sock_diag: Move the sock_ code to net/core/
This patch moves the sock_ code from inet_diag.c to generic sock_diag.c file and provides necessary request_module-s calls and a pointer on inet_diag_compat dumping routine. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/inet_diag.c105
1 files changed, 6 insertions, 99 deletions
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 515dc7b6dae..b56b7ba8bee 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -46,8 +46,6 @@ struct inet_diag_entry {
46 u16 userlocks; 46 u16 userlocks;
47}; 47};
48 48
49static struct sock *sdiagnl;
50
51#define INET_DIAG_PUT(skb, attrtype, attrlen) \ 49#define INET_DIAG_PUT(skb, attrtype, attrlen) \
52 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen)) 50 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
53 51
@@ -314,7 +312,7 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
314 kfree_skb(rep); 312 kfree_skb(rep);
315 goto out; 313 goto out;
316 } 314 }
317 err = netlink_unicast(sdiagnl, rep, NETLINK_CB(in_skb).pid, 315 err = netlink_unicast(sock_diag_nlsk, rep, NETLINK_CB(in_skb).pid,
318 MSG_DONTWAIT); 316 MSG_DONTWAIT);
319 if (err > 0) 317 if (err > 0)
320 err = 0; 318 err = 0;
@@ -931,7 +929,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
931 return -EINVAL; 929 return -EINVAL;
932 } 930 }
933 931
934 return netlink_dump_start(sdiagnl, skb, nlh, 932 return netlink_dump_start(sock_diag_nlsk, skb, nlh,
935 inet_diag_dump_compat, NULL, 0); 933 inet_diag_dump_compat, NULL, 0);
936 } 934 }
937 935
@@ -956,7 +954,7 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
956 return -EINVAL; 954 return -EINVAL;
957 } 955 }
958 956
959 return netlink_dump_start(sdiagnl, skb, h, 957 return netlink_dump_start(sock_diag_nlsk, skb, h,
960 inet_diag_dump, NULL, 0); 958 inet_diag_dump, NULL, 0);
961 } 959 }
962 960
@@ -973,91 +971,6 @@ static struct sock_diag_handler inet6_diag_handler = {
973 .dump = inet_diag_handler_dump, 971 .dump = inet_diag_handler_dump,
974}; 972};
975 973
976static struct sock_diag_handler *sock_diag_handlers[AF_MAX];
977static DEFINE_MUTEX(sock_diag_table_mutex);
978
979int sock_diag_register(struct sock_diag_handler *hndl)
980{
981 int err = 0;
982
983 if (hndl->family > AF_MAX)
984 return -EINVAL;
985
986 mutex_lock(&sock_diag_table_mutex);
987 if (sock_diag_handlers[hndl->family])
988 err = -EBUSY;
989 else
990 sock_diag_handlers[hndl->family] = hndl;
991 mutex_unlock(&sock_diag_table_mutex);
992
993 return err;
994}
995
996void sock_diag_unregister(struct sock_diag_handler *hnld)
997{
998 int family = hnld->family;
999
1000 if (family > AF_MAX)
1001 return;
1002
1003 mutex_lock(&sock_diag_table_mutex);
1004 BUG_ON(sock_diag_handlers[family] != hnld);
1005 sock_diag_handlers[family] = NULL;
1006 mutex_unlock(&sock_diag_table_mutex);
1007}
1008
1009static inline struct sock_diag_handler *sock_diag_lock_handler(int family)
1010{
1011 mutex_lock(&sock_diag_table_mutex);
1012 return sock_diag_handlers[family];
1013}
1014
1015static inline void sock_diag_unlock_handler(struct sock_diag_handler *h)
1016{
1017 mutex_unlock(&sock_diag_table_mutex);
1018}
1019
1020static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1021{
1022 int err;
1023 struct sock_diag_req *req = NLMSG_DATA(nlh);
1024 struct sock_diag_handler *hndl;
1025
1026 if (nlmsg_len(nlh) < sizeof(*req))
1027 return -EINVAL;
1028
1029 hndl = sock_diag_lock_handler(req->sdiag_family);
1030 if (hndl == NULL)
1031 err = -ENOENT;
1032 else
1033 err = hndl->dump(skb, nlh);
1034 sock_diag_unlock_handler(hndl);
1035
1036 return err;
1037}
1038
1039static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1040{
1041 switch (nlh->nlmsg_type) {
1042 case TCPDIAG_GETSOCK:
1043 case DCCPDIAG_GETSOCK:
1044 return inet_diag_rcv_msg_compat(skb, nlh);
1045 case SOCK_DIAG_BY_FAMILY:
1046 return __sock_diag_rcv_msg(skb, nlh);
1047 default:
1048 return -EINVAL;
1049 }
1050}
1051
1052static DEFINE_MUTEX(sock_diag_mutex);
1053
1054static void sock_diag_rcv(struct sk_buff *skb)
1055{
1056 mutex_lock(&sock_diag_mutex);
1057 netlink_rcv_skb(skb, &sock_diag_rcv_msg);
1058 mutex_unlock(&sock_diag_mutex);
1059}
1060
1061int inet_diag_register(const struct inet_diag_handler *h) 974int inet_diag_register(const struct inet_diag_handler *h)
1062{ 975{
1063 const __u16 type = h->idiag_type; 976 const __u16 type = h->idiag_type;
@@ -1101,11 +1014,6 @@ static int __init inet_diag_init(void)
1101 if (!inet_diag_table) 1014 if (!inet_diag_table)
1102 goto out; 1015 goto out;
1103 1016
1104 sdiagnl = netlink_kernel_create(&init_net, NETLINK_SOCK_DIAG, 0,
1105 sock_diag_rcv, NULL, THIS_MODULE);
1106 if (sdiagnl == NULL)
1107 goto out_free_table;
1108
1109 err = sock_diag_register(&inet_diag_handler); 1017 err = sock_diag_register(&inet_diag_handler);
1110 if (err) 1018 if (err)
1111 goto out_free_nl; 1019 goto out_free_nl;
@@ -1114,14 +1022,13 @@ static int __init inet_diag_init(void)
1114 if (err) 1022 if (err)
1115 goto out_free_inet; 1023 goto out_free_inet;
1116 1024
1025 sock_diag_register_inet_compat(inet_diag_rcv_msg_compat);
1117out: 1026out:
1118 return err; 1027 return err;
1119 1028
1120out_free_inet: 1029out_free_inet:
1121 sock_diag_unregister(&inet_diag_handler); 1030 sock_diag_unregister(&inet_diag_handler);
1122out_free_nl: 1031out_free_nl:
1123 netlink_kernel_release(sdiagnl);
1124out_free_table:
1125 kfree(inet_diag_table); 1032 kfree(inet_diag_table);
1126 goto out; 1033 goto out;
1127} 1034}
@@ -1130,11 +1037,11 @@ static void __exit inet_diag_exit(void)
1130{ 1037{
1131 sock_diag_unregister(&inet6_diag_handler); 1038 sock_diag_unregister(&inet6_diag_handler);
1132 sock_diag_unregister(&inet_diag_handler); 1039 sock_diag_unregister(&inet_diag_handler);
1133 netlink_kernel_release(sdiagnl); 1040 sock_diag_unregister_inet_compat(inet_diag_rcv_msg_compat);
1134 kfree(inet_diag_table); 1041 kfree(inet_diag_table);
1135} 1042}
1136 1043
1137module_init(inet_diag_init); 1044module_init(inet_diag_init);
1138module_exit(inet_diag_exit); 1045module_exit(inet_diag_exit);
1139MODULE_LICENSE("GPL"); 1046MODULE_LICENSE("GPL");
1140MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_SOCK_DIAG); 1047MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 0);