diff options
author | David S. Miller <davem@davemloft.net> | 2012-06-27 00:28:54 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-06-27 00:28:54 -0400 |
commit | d106352d9f527fe336749ad89de7e07e5af91a68 (patch) | |
tree | 25cf181cffa863b3c0c0ee985ec1ece01aefbbd9 /net/ipv4/inet_diag.c | |
parent | 77ca4ed566cdef855bc63d0f4cf4d034182d5ebd (diff) |
inet_diag: Move away from NLMSG_PUT().
And use nlmsg_data() while we're here too, and remove useless
casts.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/inet_diag.c')
-rw-r--r-- | net/ipv4/inet_diag.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c index 46d1e7199a8c..27640e734cfd 100644 --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c | |||
@@ -87,10 +87,14 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, | |||
87 | handler = inet_diag_table[req->sdiag_protocol]; | 87 | handler = inet_diag_table[req->sdiag_protocol]; |
88 | BUG_ON(handler == NULL); | 88 | BUG_ON(handler == NULL); |
89 | 89 | ||
90 | nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r)); | 90 | nlh = nlmsg_put(skb, pid, seq, unlh->nlmsg_type, sizeof(*r), 0); |
91 | if (!nlh) { | ||
92 | nlmsg_trim(skb, b); | ||
93 | return -EMSGSIZE; | ||
94 | } | ||
91 | nlh->nlmsg_flags = nlmsg_flags; | 95 | nlh->nlmsg_flags = nlmsg_flags; |
92 | 96 | ||
93 | r = NLMSG_DATA(nlh); | 97 | r = nlmsg_data(nlh); |
94 | BUG_ON(sk->sk_state == TCP_TIME_WAIT); | 98 | BUG_ON(sk->sk_state == TCP_TIME_WAIT); |
95 | 99 | ||
96 | if (ext & (1 << (INET_DIAG_MEMINFO - 1))) | 100 | if (ext & (1 << (INET_DIAG_MEMINFO - 1))) |
@@ -186,7 +190,6 @@ out: | |||
186 | return skb->len; | 190 | return skb->len; |
187 | 191 | ||
188 | rtattr_failure: | 192 | rtattr_failure: |
189 | nlmsg_failure: | ||
190 | nlmsg_trim(skb, b); | 193 | nlmsg_trim(skb, b); |
191 | return -EMSGSIZE; | 194 | return -EMSGSIZE; |
192 | } | 195 | } |
@@ -209,10 +212,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw, | |||
209 | long tmo; | 212 | long tmo; |
210 | struct inet_diag_msg *r; | 213 | struct inet_diag_msg *r; |
211 | const unsigned char *previous_tail = skb_tail_pointer(skb); | 214 | const unsigned char *previous_tail = skb_tail_pointer(skb); |
212 | struct nlmsghdr *nlh = NLMSG_PUT(skb, pid, seq, | 215 | struct nlmsghdr *nlh = nlmsg_put(skb, pid, seq, |
213 | unlh->nlmsg_type, sizeof(*r)); | 216 | unlh->nlmsg_type, sizeof(*r), 0); |
217 | |||
218 | if (!nlh) { | ||
219 | nlmsg_trim(skb, previous_tail); | ||
220 | return -EMSGSIZE; | ||
221 | } | ||
214 | 222 | ||
215 | r = NLMSG_DATA(nlh); | 223 | r = nlmsg_data(nlh); |
216 | BUG_ON(tw->tw_state != TCP_TIME_WAIT); | 224 | BUG_ON(tw->tw_state != TCP_TIME_WAIT); |
217 | 225 | ||
218 | nlh->nlmsg_flags = nlmsg_flags; | 226 | nlh->nlmsg_flags = nlmsg_flags; |
@@ -247,9 +255,6 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw, | |||
247 | #endif | 255 | #endif |
248 | nlh->nlmsg_len = skb_tail_pointer(skb) - previous_tail; | 256 | nlh->nlmsg_len = skb_tail_pointer(skb) - previous_tail; |
249 | return skb->len; | 257 | return skb->len; |
250 | nlmsg_failure: | ||
251 | nlmsg_trim(skb, previous_tail); | ||
252 | return -EMSGSIZE; | ||
253 | } | 258 | } |
254 | 259 | ||
255 | static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, | 260 | static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, |
@@ -597,9 +602,13 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk, | |||
597 | struct nlmsghdr *nlh; | 602 | struct nlmsghdr *nlh; |
598 | long tmo; | 603 | long tmo; |
599 | 604 | ||
600 | nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r)); | 605 | nlh = nlmsg_put(skb, pid, seq, unlh->nlmsg_type, sizeof(*r), 0); |
606 | if (!nlh) { | ||
607 | nlmsg_trim(skb, b); | ||
608 | return -1; | ||
609 | } | ||
601 | nlh->nlmsg_flags = NLM_F_MULTI; | 610 | nlh->nlmsg_flags = NLM_F_MULTI; |
602 | r = NLMSG_DATA(nlh); | 611 | r = nlmsg_data(nlh); |
603 | 612 | ||
604 | r->idiag_family = sk->sk_family; | 613 | r->idiag_family = sk->sk_family; |
605 | r->idiag_state = TCP_SYN_RECV; | 614 | r->idiag_state = TCP_SYN_RECV; |
@@ -631,10 +640,6 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk, | |||
631 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; | 640 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; |
632 | 641 | ||
633 | return skb->len; | 642 | return skb->len; |
634 | |||
635 | nlmsg_failure: | ||
636 | nlmsg_trim(skb, b); | ||
637 | return -1; | ||
638 | } | 643 | } |
639 | 644 | ||
640 | static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk, | 645 | static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk, |
@@ -892,7 +897,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
892 | if (nlmsg_attrlen(cb->nlh, hdrlen)) | 897 | if (nlmsg_attrlen(cb->nlh, hdrlen)) |
893 | bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE); | 898 | bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE); |
894 | 899 | ||
895 | return __inet_diag_dump(skb, cb, (struct inet_diag_req_v2 *)NLMSG_DATA(cb->nlh), bc); | 900 | return __inet_diag_dump(skb, cb, nlmsg_data(cb->nlh), bc); |
896 | } | 901 | } |
897 | 902 | ||
898 | static inline int inet_diag_type2proto(int type) | 903 | static inline int inet_diag_type2proto(int type) |
@@ -909,7 +914,7 @@ static inline int inet_diag_type2proto(int type) | |||
909 | 914 | ||
910 | static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb) | 915 | static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb) |
911 | { | 916 | { |
912 | struct inet_diag_req *rc = NLMSG_DATA(cb->nlh); | 917 | struct inet_diag_req *rc = nlmsg_data(cb->nlh); |
913 | struct inet_diag_req_v2 req; | 918 | struct inet_diag_req_v2 req; |
914 | struct nlattr *bc = NULL; | 919 | struct nlattr *bc = NULL; |
915 | int hdrlen = sizeof(struct inet_diag_req); | 920 | int hdrlen = sizeof(struct inet_diag_req); |
@@ -929,7 +934,7 @@ static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *c | |||
929 | static int inet_diag_get_exact_compat(struct sk_buff *in_skb, | 934 | static int inet_diag_get_exact_compat(struct sk_buff *in_skb, |
930 | const struct nlmsghdr *nlh) | 935 | const struct nlmsghdr *nlh) |
931 | { | 936 | { |
932 | struct inet_diag_req *rc = NLMSG_DATA(nlh); | 937 | struct inet_diag_req *rc = nlmsg_data(nlh); |
933 | struct inet_diag_req_v2 req; | 938 | struct inet_diag_req_v2 req; |
934 | 939 | ||
935 | req.sdiag_family = rc->idiag_family; | 940 | req.sdiag_family = rc->idiag_family; |
@@ -996,7 +1001,7 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) | |||
996 | } | 1001 | } |
997 | } | 1002 | } |
998 | 1003 | ||
999 | return inet_diag_get_exact(skb, h, (struct inet_diag_req_v2 *)NLMSG_DATA(h)); | 1004 | return inet_diag_get_exact(skb, h, nlmsg_data(h)); |
1000 | } | 1005 | } |
1001 | 1006 | ||
1002 | static const struct sock_diag_handler inet_diag_handler = { | 1007 | static const struct sock_diag_handler inet_diag_handler = { |