inet_diag.c (9a64e8e0ace51b309fdcff4b4754b3649250382a) inet_diag.c (d106352d9f527fe336749ad89de7e07e5af91a68)
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

--- 73 unchanged lines hidden (view full) ---

82 struct inet_diag_meminfo *minfo = NULL;
83 unsigned char *b = skb_tail_pointer(skb);
84 const struct inet_diag_handler *handler;
85 int ext = req->idiag_ext;
86
87 handler = inet_diag_table[req->sdiag_protocol];
88 BUG_ON(handler == NULL);
89
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

--- 73 unchanged lines hidden (view full) ---

82 struct inet_diag_meminfo *minfo = NULL;
83 unsigned char *b = skb_tail_pointer(skb);
84 const struct inet_diag_handler *handler;
85 int ext = req->idiag_ext;
86
87 handler = inet_diag_table[req->sdiag_protocol];
88 BUG_ON(handler == NULL);
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;
92
95 nlh->nlmsg_flags = nlmsg_flags;
96
93 r = NLMSG_DATA(nlh);
97 r = nlmsg_data(nlh);
94 BUG_ON(sk->sk_state == TCP_TIME_WAIT);
95
96 if (ext & (1 << (INET_DIAG_MEMINFO - 1)))
97 minfo = INET_DIAG_PUT(skb, INET_DIAG_MEMINFO, sizeof(*minfo));
98
99 r->idiag_family = sk->sk_family;
100 r->idiag_state = sk->sk_state;
101 r->idiag_timer = 0;

--- 79 unchanged lines hidden (view full) ---

181 icsk->icsk_ca_ops && icsk->icsk_ca_ops->get_info)
182 icsk->icsk_ca_ops->get_info(sk, ext, skb);
183
184out:
185 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
186 return skb->len;
187
188rtattr_failure:
98 BUG_ON(sk->sk_state == TCP_TIME_WAIT);
99
100 if (ext & (1 << (INET_DIAG_MEMINFO - 1)))
101 minfo = INET_DIAG_PUT(skb, INET_DIAG_MEMINFO, sizeof(*minfo));
102
103 r->idiag_family = sk->sk_family;
104 r->idiag_state = sk->sk_state;
105 r->idiag_timer = 0;

--- 79 unchanged lines hidden (view full) ---

185 icsk->icsk_ca_ops && icsk->icsk_ca_ops->get_info)
186 icsk->icsk_ca_ops->get_info(sk, ext, skb);
187
188out:
189 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
190 return skb->len;
191
192rtattr_failure:
189nlmsg_failure:
190 nlmsg_trim(skb, b);
191 return -EMSGSIZE;
192}
193EXPORT_SYMBOL_GPL(inet_sk_diag_fill);
194
195static int inet_csk_diag_fill(struct sock *sk,
196 struct sk_buff *skb, struct inet_diag_req_v2 *req,
197 u32 pid, u32 seq, u16 nlmsg_flags,

--- 6 unchanged lines hidden (view full) ---

204static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
205 struct sk_buff *skb, struct inet_diag_req_v2 *req,
206 u32 pid, u32 seq, u16 nlmsg_flags,
207 const struct nlmsghdr *unlh)
208{
209 long tmo;
210 struct inet_diag_msg *r;
211 const unsigned char *previous_tail = skb_tail_pointer(skb);
193 nlmsg_trim(skb, b);
194 return -EMSGSIZE;
195}
196EXPORT_SYMBOL_GPL(inet_sk_diag_fill);
197
198static int inet_csk_diag_fill(struct sock *sk,
199 struct sk_buff *skb, struct inet_diag_req_v2 *req,
200 u32 pid, u32 seq, u16 nlmsg_flags,

--- 6 unchanged lines hidden (view full) ---

207static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
208 struct sk_buff *skb, struct inet_diag_req_v2 *req,
209 u32 pid, u32 seq, u16 nlmsg_flags,
210 const struct nlmsghdr *unlh)
211{
212 long tmo;
213 struct inet_diag_msg *r;
214 const unsigned char *previous_tail = skb_tail_pointer(skb);
212 struct nlmsghdr *nlh = NLMSG_PUT(skb, pid, seq,
213 unlh->nlmsg_type, sizeof(*r));
215 struct nlmsghdr *nlh = nlmsg_put(skb, pid, seq,
216 unlh->nlmsg_type, sizeof(*r), 0);
214
217
215 r = NLMSG_DATA(nlh);
218 if (!nlh) {
219 nlmsg_trim(skb, previous_tail);
220 return -EMSGSIZE;
221 }
222
223 r = nlmsg_data(nlh);
216 BUG_ON(tw->tw_state != TCP_TIME_WAIT);
217
218 nlh->nlmsg_flags = nlmsg_flags;
219
220 tmo = tw->tw_ttd - jiffies;
221 if (tmo < 0)
222 tmo = 0;
223

--- 18 unchanged lines hidden (view full) ---

242 inet6_twsk((struct sock *)tw);
243
244 *(struct in6_addr *)r->id.idiag_src = tw6->tw_v6_rcv_saddr;
245 *(struct in6_addr *)r->id.idiag_dst = tw6->tw_v6_daddr;
246 }
247#endif
248 nlh->nlmsg_len = skb_tail_pointer(skb) - previous_tail;
249 return skb->len;
224 BUG_ON(tw->tw_state != TCP_TIME_WAIT);
225
226 nlh->nlmsg_flags = nlmsg_flags;
227
228 tmo = tw->tw_ttd - jiffies;
229 if (tmo < 0)
230 tmo = 0;
231

--- 18 unchanged lines hidden (view full) ---

250 inet6_twsk((struct sock *)tw);
251
252 *(struct in6_addr *)r->id.idiag_src = tw6->tw_v6_rcv_saddr;
253 *(struct in6_addr *)r->id.idiag_dst = tw6->tw_v6_daddr;
254 }
255#endif
256 nlh->nlmsg_len = skb_tail_pointer(skb) - previous_tail;
257 return skb->len;
250nlmsg_failure:
251 nlmsg_trim(skb, previous_tail);
252 return -EMSGSIZE;
253}
254
255static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
256 struct inet_diag_req_v2 *r, u32 pid, u32 seq, u16 nlmsg_flags,
257 const struct nlmsghdr *unlh)
258{
259 if (sk->sk_state == TCP_TIME_WAIT)
260 return inet_twsk_diag_fill((struct inet_timewait_sock *)sk,

--- 331 unchanged lines hidden (view full) ---

592{
593 const struct inet_request_sock *ireq = inet_rsk(req);
594 struct inet_sock *inet = inet_sk(sk);
595 unsigned char *b = skb_tail_pointer(skb);
596 struct inet_diag_msg *r;
597 struct nlmsghdr *nlh;
598 long tmo;
599
258}
259
260static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
261 struct inet_diag_req_v2 *r, u32 pid, u32 seq, u16 nlmsg_flags,
262 const struct nlmsghdr *unlh)
263{
264 if (sk->sk_state == TCP_TIME_WAIT)
265 return inet_twsk_diag_fill((struct inet_timewait_sock *)sk,

--- 331 unchanged lines hidden (view full) ---

597{
598 const struct inet_request_sock *ireq = inet_rsk(req);
599 struct inet_sock *inet = inet_sk(sk);
600 unsigned char *b = skb_tail_pointer(skb);
601 struct inet_diag_msg *r;
602 struct nlmsghdr *nlh;
603 long tmo;
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
604 r->idiag_family = sk->sk_family;
605 r->idiag_state = TCP_SYN_RECV;
606 r->idiag_timer = 1;
607 r->idiag_retrans = req->retrans;
608
609 r->id.idiag_if = sk->sk_bound_dev_if;
610 sock_diag_save_cookie(req, r->id.idiag_cookie);

--- 15 unchanged lines hidden (view full) ---

626 if (r->idiag_family == AF_INET6) {
627 *(struct in6_addr *)r->id.idiag_src = inet6_rsk(req)->loc_addr;
628 *(struct in6_addr *)r->id.idiag_dst = inet6_rsk(req)->rmt_addr;
629 }
630#endif
631 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
632
633 return skb->len;
612
613 r->idiag_family = sk->sk_family;
614 r->idiag_state = TCP_SYN_RECV;
615 r->idiag_timer = 1;
616 r->idiag_retrans = req->retrans;
617
618 r->id.idiag_if = sk->sk_bound_dev_if;
619 sock_diag_save_cookie(req, r->id.idiag_cookie);

--- 15 unchanged lines hidden (view full) ---

635 if (r->idiag_family == AF_INET6) {
636 *(struct in6_addr *)r->id.idiag_src = inet6_rsk(req)->loc_addr;
637 *(struct in6_addr *)r->id.idiag_dst = inet6_rsk(req)->rmt_addr;
638 }
639#endif
640 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
641
642 return skb->len;
634
635nlmsg_failure:
636 nlmsg_trim(skb, b);
637 return -1;
638}
639
640static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
641 struct netlink_callback *cb,
642 struct inet_diag_req_v2 *r,
643 const struct nlattr *bc)
644{
645 struct inet_diag_entry entry;

--- 241 unchanged lines hidden (view full) ---

887static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
888{
889 struct nlattr *bc = NULL;
890 int hdrlen = sizeof(struct inet_diag_req_v2);
891
892 if (nlmsg_attrlen(cb->nlh, hdrlen))
893 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
894
643}
644
645static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
646 struct netlink_callback *cb,
647 struct inet_diag_req_v2 *r,
648 const struct nlattr *bc)
649{
650 struct inet_diag_entry entry;

--- 241 unchanged lines hidden (view full) ---

892static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
893{
894 struct nlattr *bc = NULL;
895 int hdrlen = sizeof(struct inet_diag_req_v2);
896
897 if (nlmsg_attrlen(cb->nlh, hdrlen))
898 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
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}
897
898static inline int inet_diag_type2proto(int type)
899{
900 switch (type) {
901 case TCPDIAG_GETSOCK:
902 return IPPROTO_TCP;
903 case DCCPDIAG_GETSOCK:
904 return IPPROTO_DCCP;
905 default:
906 return 0;
907 }
908}
909
910static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb)
911{
901}
902
903static inline int inet_diag_type2proto(int type)
904{
905 switch (type) {
906 case TCPDIAG_GETSOCK:
907 return IPPROTO_TCP;
908 case DCCPDIAG_GETSOCK:
909 return IPPROTO_DCCP;
910 default:
911 return 0;
912 }
913}
914
915static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb)
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;
914 struct nlattr *bc = NULL;
915 int hdrlen = sizeof(struct inet_diag_req);
916
917 req.sdiag_family = AF_UNSPEC; /* compatibility */
918 req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
919 req.idiag_ext = rc->idiag_ext;
920 req.idiag_states = rc->idiag_states;
921 req.id = rc->id;
922
923 if (nlmsg_attrlen(cb->nlh, hdrlen))
924 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
925
926 return __inet_diag_dump(skb, cb, &req, bc);
927}
928
929static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
930 const struct nlmsghdr *nlh)
931{
918 struct inet_diag_req_v2 req;
919 struct nlattr *bc = NULL;
920 int hdrlen = sizeof(struct inet_diag_req);
921
922 req.sdiag_family = AF_UNSPEC; /* compatibility */
923 req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
924 req.idiag_ext = rc->idiag_ext;
925 req.idiag_states = rc->idiag_states;
926 req.id = rc->id;
927
928 if (nlmsg_attrlen(cb->nlh, hdrlen))
929 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
930
931 return __inet_diag_dump(skb, cb, &req, bc);
932}
933
934static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
935 const struct nlmsghdr *nlh)
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;
934
935 req.sdiag_family = rc->idiag_family;
936 req.sdiag_protocol = inet_diag_type2proto(nlh->nlmsg_type);
937 req.idiag_ext = rc->idiag_ext;
938 req.idiag_states = rc->idiag_states;
939 req.id = rc->id;
940

--- 50 unchanged lines hidden (view full) ---

991 {
992 struct netlink_dump_control c = {
993 .dump = inet_diag_dump,
994 };
995 return netlink_dump_start(sock_diag_nlsk, skb, h, &c);
996 }
997 }
998
938 struct inet_diag_req_v2 req;
939
940 req.sdiag_family = rc->idiag_family;
941 req.sdiag_protocol = inet_diag_type2proto(nlh->nlmsg_type);
942 req.idiag_ext = rc->idiag_ext;
943 req.idiag_states = rc->idiag_states;
944 req.id = rc->id;
945

--- 50 unchanged lines hidden (view full) ---

996 {
997 struct netlink_dump_control c = {
998 .dump = inet_diag_dump,
999 };
1000 return netlink_dump_start(sock_diag_nlsk, skb, h, &c);
1001 }
1002 }
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}
1001
1002static const struct sock_diag_handler inet_diag_handler = {
1003 .family = AF_INET,
1004 .dump = inet_diag_handler_dump,
1005};
1006
1007static const struct sock_diag_handler inet6_diag_handler = {

--- 79 unchanged lines hidden ---
1005}
1006
1007static const struct sock_diag_handler inet_diag_handler = {
1008 .family = AF_INET,
1009 .dump = inet_diag_handler_dump,
1010};
1011
1012static const struct sock_diag_handler inet6_diag_handler = {

--- 79 unchanged lines hidden ---