diff options
author | Pavel Emelyanov <xemul@parallels.com> | 2011-12-09 01:23:18 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-12-09 14:14:08 -0500 |
commit | 1942c518ca017f376b267a7c5e78c15d37202442 (patch) | |
tree | 9ead5443adf15f2264240c928ff2514349fdcade | |
parent | 3c4d05c8056724aff3abc20650807dd828fded54 (diff) |
inet_diag: Generalize inet_diag dump and get_exact calls
Introduce two callbacks in inet_diag_handler -- one for dumping all
sockets (with filters) and the other one for dumping a single sk.
Replace direct calls to icsk handlers with indirect calls to callbacks
provided by handlers.
Make existing TCP and DCCP handlers use provided helpers for icsk-s.
The UDP diag module will provide its own.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/inet_diag.h | 18 | ||||
-rw-r--r-- | net/dccp/diag.c | 15 | ||||
-rw-r--r-- | net/ipv4/inet_diag.c | 11 | ||||
-rw-r--r-- | net/ipv4/tcp_diag.c | 15 |
4 files changed, 51 insertions, 8 deletions
diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h index eaf5865c9e8a..78972a149dff 100644 --- a/include/linux/inet_diag.h +++ b/include/linux/inet_diag.h | |||
@@ -138,9 +138,18 @@ struct inet_hashinfo; | |||
138 | struct nlattr; | 138 | struct nlattr; |
139 | struct nlmsghdr; | 139 | struct nlmsghdr; |
140 | struct sk_buff; | 140 | struct sk_buff; |
141 | struct netlink_callback; | ||
141 | 142 | ||
142 | struct inet_diag_handler { | 143 | struct inet_diag_handler { |
143 | struct inet_hashinfo *idiag_hashinfo; | 144 | void (*dump)(struct sk_buff *skb, |
145 | struct netlink_callback *cb, | ||
146 | struct inet_diag_req *r, | ||
147 | struct nlattr *bc); | ||
148 | |||
149 | int (*dump_one)(struct sk_buff *in_skb, | ||
150 | const struct nlmsghdr *nlh, | ||
151 | struct inet_diag_req *req); | ||
152 | |||
144 | void (*idiag_get_info)(struct sock *sk, | 153 | void (*idiag_get_info)(struct sock *sk, |
145 | struct inet_diag_msg *r, | 154 | struct inet_diag_msg *r, |
146 | void *info); | 155 | void *info); |
@@ -152,6 +161,13 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, | |||
152 | struct sk_buff *skb, struct inet_diag_req *req, | 161 | struct sk_buff *skb, struct inet_diag_req *req, |
153 | u32 pid, u32 seq, u16 nlmsg_flags, | 162 | u32 pid, u32 seq, u16 nlmsg_flags, |
154 | const struct nlmsghdr *unlh); | 163 | const struct nlmsghdr *unlh); |
164 | void inet_diag_dump_icsk(struct inet_hashinfo *h, struct sk_buff *skb, | ||
165 | struct netlink_callback *cb, struct inet_diag_req *r, | ||
166 | struct nlattr *bc); | ||
167 | int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, | ||
168 | struct sk_buff *in_skb, const struct nlmsghdr *nlh, | ||
169 | struct inet_diag_req *req); | ||
170 | |||
155 | int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk); | 171 | int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk); |
156 | int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req); | 172 | int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req); |
157 | 173 | ||
diff --git a/net/dccp/diag.c b/net/dccp/diag.c index 9343f52db284..e29214d193d6 100644 --- a/net/dccp/diag.c +++ b/net/dccp/diag.c | |||
@@ -48,8 +48,21 @@ static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r, | |||
48 | dccp_get_info(sk, _info); | 48 | dccp_get_info(sk, _info); |
49 | } | 49 | } |
50 | 50 | ||
51 | static void dccp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, | ||
52 | struct inet_diag_req *r, struct nlattr *bc) | ||
53 | { | ||
54 | inet_diag_dump_icsk(&dccp_hashinfo, skb, cb, r, bc); | ||
55 | } | ||
56 | |||
57 | static int dccp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh, | ||
58 | struct inet_diag_req *req) | ||
59 | { | ||
60 | return inet_diag_dump_one_icsk(&dccp_hashinfo, in_skb, nlh, req); | ||
61 | } | ||
62 | |||
51 | static const struct inet_diag_handler dccp_diag_handler = { | 63 | static const struct inet_diag_handler dccp_diag_handler = { |
52 | .idiag_hashinfo = &dccp_hashinfo, | 64 | .dump = dccp_diag_dump, |
65 | .dump_one = dccp_diag_dump_one, | ||
53 | .idiag_get_info = dccp_diag_get_info, | 66 | .idiag_get_info = dccp_diag_get_info, |
54 | .idiag_type = IPPROTO_DCCP, | 67 | .idiag_type = IPPROTO_DCCP, |
55 | }; | 68 | }; |
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c index dc8611e3e66f..9b3e0b179cd2 100644 --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c | |||
@@ -273,7 +273,7 @@ int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req) | |||
273 | } | 273 | } |
274 | EXPORT_SYMBOL_GPL(inet_diag_check_cookie); | 274 | EXPORT_SYMBOL_GPL(inet_diag_check_cookie); |
275 | 275 | ||
276 | static int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_skb, | 276 | int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_skb, |
277 | const struct nlmsghdr *nlh, struct inet_diag_req *req) | 277 | const struct nlmsghdr *nlh, struct inet_diag_req *req) |
278 | { | 278 | { |
279 | int err; | 279 | int err; |
@@ -339,6 +339,7 @@ out: | |||
339 | out_nosk: | 339 | out_nosk: |
340 | return err; | 340 | return err; |
341 | } | 341 | } |
342 | EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk); | ||
342 | 343 | ||
343 | static int inet_diag_get_exact(struct sk_buff *in_skb, | 344 | static int inet_diag_get_exact(struct sk_buff *in_skb, |
344 | const struct nlmsghdr *nlh, | 345 | const struct nlmsghdr *nlh, |
@@ -351,8 +352,7 @@ static int inet_diag_get_exact(struct sk_buff *in_skb, | |||
351 | if (IS_ERR(handler)) | 352 | if (IS_ERR(handler)) |
352 | err = PTR_ERR(handler); | 353 | err = PTR_ERR(handler); |
353 | else | 354 | else |
354 | err = inet_diag_dump_one_icsk(handler->idiag_hashinfo, | 355 | err = handler->dump_one(in_skb, nlh, req); |
355 | in_skb, nlh, req); | ||
356 | inet_diag_unlock_handler(handler); | 356 | inet_diag_unlock_handler(handler); |
357 | 357 | ||
358 | return err; | 358 | return err; |
@@ -731,7 +731,7 @@ out: | |||
731 | return err; | 731 | return err; |
732 | } | 732 | } |
733 | 733 | ||
734 | static void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb, | 734 | void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb, |
735 | struct netlink_callback *cb, struct inet_diag_req *r, struct nlattr *bc) | 735 | struct netlink_callback *cb, struct inet_diag_req *r, struct nlattr *bc) |
736 | { | 736 | { |
737 | int i, num; | 737 | int i, num; |
@@ -880,6 +880,7 @@ done: | |||
880 | out: | 880 | out: |
881 | ; | 881 | ; |
882 | } | 882 | } |
883 | EXPORT_SYMBOL_GPL(inet_diag_dump_icsk); | ||
883 | 884 | ||
884 | static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, | 885 | static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, |
885 | struct inet_diag_req *r, struct nlattr *bc) | 886 | struct inet_diag_req *r, struct nlattr *bc) |
@@ -888,7 +889,7 @@ static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, | |||
888 | 889 | ||
889 | handler = inet_diag_lock_handler(r->sdiag_protocol); | 890 | handler = inet_diag_lock_handler(r->sdiag_protocol); |
890 | if (!IS_ERR(handler)) | 891 | if (!IS_ERR(handler)) |
891 | inet_diag_dump_icsk(handler->idiag_hashinfo, skb, cb, r, bc); | 892 | handler->dump(skb, cb, r, bc); |
892 | inet_diag_unlock_handler(handler); | 893 | inet_diag_unlock_handler(handler); |
893 | 894 | ||
894 | return skb->len; | 895 | return skb->len; |
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c index 42e6bec7bd3e..6334b1f71f2d 100644 --- a/net/ipv4/tcp_diag.c +++ b/net/ipv4/tcp_diag.c | |||
@@ -34,8 +34,21 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r, | |||
34 | tcp_get_info(sk, info); | 34 | tcp_get_info(sk, info); |
35 | } | 35 | } |
36 | 36 | ||
37 | static void tcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, | ||
38 | struct inet_diag_req *r, struct nlattr *bc) | ||
39 | { | ||
40 | inet_diag_dump_icsk(&tcp_hashinfo, skb, cb, r, bc); | ||
41 | } | ||
42 | |||
43 | static int tcp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh, | ||
44 | struct inet_diag_req *req) | ||
45 | { | ||
46 | return inet_diag_dump_one_icsk(&tcp_hashinfo, in_skb, nlh, req); | ||
47 | } | ||
48 | |||
37 | static const struct inet_diag_handler tcp_diag_handler = { | 49 | static const struct inet_diag_handler tcp_diag_handler = { |
38 | .idiag_hashinfo = &tcp_hashinfo, | 50 | .dump = tcp_diag_dump, |
51 | .dump_one = tcp_diag_dump_one, | ||
39 | .idiag_get_info = tcp_diag_get_info, | 52 | .idiag_get_info = tcp_diag_get_info, |
40 | .idiag_type = IPPROTO_TCP, | 53 | .idiag_type = IPPROTO_TCP, |
41 | }; | 54 | }; |