@@ -157,11 +157,9 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
157
157
EXPORT_SYMBOL_GPL (inet_diag_msg_attrs_fill );
158
158
159
159
int inet_sk_diag_fill (struct sock * sk , struct inet_connection_sock * icsk ,
160
- struct sk_buff * skb , const struct inet_diag_req_v2 * req ,
161
- struct user_namespace * user_ns ,
162
- u32 portid , u32 seq , u16 nlmsg_flags ,
163
- const struct nlmsghdr * unlh ,
164
- bool net_admin )
160
+ struct sk_buff * skb , struct netlink_callback * cb ,
161
+ const struct inet_diag_req_v2 * req ,
162
+ u16 nlmsg_flags , bool net_admin )
165
163
{
166
164
const struct tcp_congestion_ops * ca_ops ;
167
165
const struct inet_diag_handler * handler ;
@@ -174,8 +172,8 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
174
172
handler = inet_diag_table [req -> sdiag_protocol ];
175
173
BUG_ON (!handler );
176
174
177
- nlh = nlmsg_put (skb , portid , seq , unlh -> nlmsg_type , sizeof ( * r ) ,
178
- nlmsg_flags );
175
+ nlh = nlmsg_put (skb , NETLINK_CB ( cb -> skb ). portid , cb -> nlh -> nlmsg_seq ,
176
+ cb -> nlh -> nlmsg_type , sizeof ( * r ), nlmsg_flags );
179
177
if (!nlh )
180
178
return - EMSGSIZE ;
181
179
@@ -187,7 +185,9 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
187
185
r -> idiag_timer = 0 ;
188
186
r -> idiag_retrans = 0 ;
189
187
190
- if (inet_diag_msg_attrs_fill (sk , skb , r , ext , user_ns , net_admin ))
188
+ if (inet_diag_msg_attrs_fill (sk , skb , r , ext ,
189
+ sk_user_ns (NETLINK_CB (cb -> skb ).sk ),
190
+ net_admin ))
191
191
goto errout ;
192
192
193
193
if (ext & (1 << (INET_DIAG_MEMINFO - 1 ))) {
@@ -312,30 +312,19 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
312
312
}
313
313
EXPORT_SYMBOL_GPL (inet_sk_diag_fill );
314
314
315
- static int inet_csk_diag_fill (struct sock * sk ,
316
- struct sk_buff * skb ,
317
- const struct inet_diag_req_v2 * req ,
318
- struct user_namespace * user_ns ,
319
- u32 portid , u32 seq , u16 nlmsg_flags ,
320
- const struct nlmsghdr * unlh ,
321
- bool net_admin )
322
- {
323
- return inet_sk_diag_fill (sk , inet_csk (sk ), skb , req , user_ns ,
324
- portid , seq , nlmsg_flags , unlh , net_admin );
325
- }
326
-
327
315
static int inet_twsk_diag_fill (struct sock * sk ,
328
316
struct sk_buff * skb ,
329
- u32 portid , u32 seq , u16 nlmsg_flags ,
330
- const struct nlmsghdr * unlh )
317
+ struct netlink_callback * cb ,
318
+ u16 nlmsg_flags )
331
319
{
332
320
struct inet_timewait_sock * tw = inet_twsk (sk );
333
321
struct inet_diag_msg * r ;
334
322
struct nlmsghdr * nlh ;
335
323
long tmo ;
336
324
337
- nlh = nlmsg_put (skb , portid , seq , unlh -> nlmsg_type , sizeof (* r ),
338
- nlmsg_flags );
325
+ nlh = nlmsg_put (skb , NETLINK_CB (cb -> skb ).portid ,
326
+ cb -> nlh -> nlmsg_seq , cb -> nlh -> nlmsg_type ,
327
+ sizeof (* r ), nlmsg_flags );
339
328
if (!nlh )
340
329
return - EMSGSIZE ;
341
330
@@ -359,16 +348,16 @@ static int inet_twsk_diag_fill(struct sock *sk,
359
348
}
360
349
361
350
static int inet_req_diag_fill (struct sock * sk , struct sk_buff * skb ,
362
- u32 portid , u32 seq , u16 nlmsg_flags ,
363
- const struct nlmsghdr * unlh , bool net_admin )
351
+ struct netlink_callback * cb ,
352
+ u16 nlmsg_flags , bool net_admin )
364
353
{
365
354
struct request_sock * reqsk = inet_reqsk (sk );
366
355
struct inet_diag_msg * r ;
367
356
struct nlmsghdr * nlh ;
368
357
long tmo ;
369
358
370
- nlh = nlmsg_put (skb , portid , seq , unlh -> nlmsg_type , sizeof ( * r ) ,
371
- nlmsg_flags );
359
+ nlh = nlmsg_put (skb , NETLINK_CB ( cb -> skb ). portid , cb -> nlh -> nlmsg_seq ,
360
+ cb -> nlh -> nlmsg_type , sizeof ( * r ), nlmsg_flags );
372
361
if (!nlh )
373
362
return - EMSGSIZE ;
374
363
@@ -397,21 +386,18 @@ static int inet_req_diag_fill(struct sock *sk, struct sk_buff *skb,
397
386
}
398
387
399
388
static int sk_diag_fill (struct sock * sk , struct sk_buff * skb ,
389
+ struct netlink_callback * cb ,
400
390
const struct inet_diag_req_v2 * r ,
401
- struct user_namespace * user_ns ,
402
- u32 portid , u32 seq , u16 nlmsg_flags ,
403
- const struct nlmsghdr * unlh , bool net_admin )
391
+ u16 nlmsg_flags , bool net_admin )
404
392
{
405
393
if (sk -> sk_state == TCP_TIME_WAIT )
406
- return inet_twsk_diag_fill (sk , skb , portid , seq ,
407
- nlmsg_flags , unlh );
394
+ return inet_twsk_diag_fill (sk , skb , cb , nlmsg_flags );
408
395
409
396
if (sk -> sk_state == TCP_NEW_SYN_RECV )
410
- return inet_req_diag_fill (sk , skb , portid , seq ,
411
- nlmsg_flags , unlh , net_admin );
397
+ return inet_req_diag_fill (sk , skb , cb , nlmsg_flags , net_admin );
412
398
413
- return inet_csk_diag_fill (sk , skb , r , user_ns , portid , seq ,
414
- nlmsg_flags , unlh , net_admin );
399
+ return inet_sk_diag_fill (sk , inet_csk ( sk ), skb , cb , r , nlmsg_flags ,
400
+ net_admin );
415
401
}
416
402
417
403
struct sock * inet_diag_find_one_icsk (struct net * net ,
@@ -459,10 +445,10 @@ struct sock *inet_diag_find_one_icsk(struct net *net,
459
445
EXPORT_SYMBOL_GPL (inet_diag_find_one_icsk );
460
446
461
447
int inet_diag_dump_one_icsk (struct inet_hashinfo * hashinfo ,
462
- struct sk_buff * in_skb ,
463
- const struct nlmsghdr * nlh ,
448
+ struct netlink_callback * cb ,
464
449
const struct inet_diag_req_v2 * req )
465
450
{
451
+ struct sk_buff * in_skb = cb -> skb ;
466
452
bool net_admin = netlink_net_capable (in_skb , CAP_NET_ADMIN );
467
453
struct net * net = sock_net (in_skb -> sk );
468
454
struct sk_buff * rep ;
@@ -479,10 +465,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
479
465
goto out ;
480
466
}
481
467
482
- err = sk_diag_fill (sk , rep , req ,
483
- sk_user_ns (NETLINK_CB (in_skb ).sk ),
484
- NETLINK_CB (in_skb ).portid ,
485
- nlh -> nlmsg_seq , 0 , nlh , net_admin );
468
+ err = sk_diag_fill (sk , rep , cb , req , 0 , net_admin );
486
469
if (err < 0 ) {
487
470
WARN_ON (err == - EMSGSIZE );
488
471
nlmsg_free (rep );
@@ -509,14 +492,19 @@ static int inet_diag_cmd_exact(int cmd, struct sk_buff *in_skb,
509
492
int err ;
510
493
511
494
handler = inet_diag_lock_handler (req -> sdiag_protocol );
512
- if (IS_ERR (handler ))
495
+ if (IS_ERR (handler )) {
513
496
err = PTR_ERR (handler );
514
- else if (cmd == SOCK_DIAG_BY_FAMILY )
515
- err = handler -> dump_one (in_skb , nlh , req );
516
- else if (cmd == SOCK_DESTROY && handler -> destroy )
497
+ } else if (cmd == SOCK_DIAG_BY_FAMILY ) {
498
+ struct netlink_callback cb = {
499
+ .nlh = nlh ,
500
+ .skb = in_skb ,
501
+ };
502
+ err = handler -> dump_one (& cb , req );
503
+ } else if (cmd == SOCK_DESTROY && handler -> destroy ) {
517
504
err = handler -> destroy (in_skb , req );
518
- else
505
+ } else {
519
506
err = - EOPNOTSUPP ;
507
+ }
520
508
inet_diag_unlock_handler (handler );
521
509
522
510
return err ;
@@ -847,23 +835,6 @@ static int inet_diag_bc_audit(const struct nlattr *attr,
847
835
return len == 0 ? 0 : - EINVAL ;
848
836
}
849
837
850
- static int inet_csk_diag_dump (struct sock * sk ,
851
- struct sk_buff * skb ,
852
- struct netlink_callback * cb ,
853
- const struct inet_diag_req_v2 * r ,
854
- const struct nlattr * bc ,
855
- bool net_admin )
856
- {
857
- if (!inet_diag_bc_sk (bc , sk ))
858
- return 0 ;
859
-
860
- return inet_csk_diag_fill (sk , skb , r ,
861
- sk_user_ns (NETLINK_CB (cb -> skb ).sk ),
862
- NETLINK_CB (cb -> skb ).portid ,
863
- cb -> nlh -> nlmsg_seq , NLM_F_MULTI , cb -> nlh ,
864
- net_admin );
865
- }
866
-
867
838
static void twsk_build_assert (void )
868
839
{
869
840
BUILD_BUG_ON (offsetof(struct inet_timewait_sock , tw_family ) !=
@@ -935,8 +906,12 @@ void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb,
935
906
r -> id .idiag_sport )
936
907
goto next_listen ;
937
908
938
- if (inet_csk_diag_dump (sk , skb , cb , r ,
939
- bc , net_admin ) < 0 ) {
909
+ if (!inet_diag_bc_sk (bc , sk ))
910
+ goto next_listen ;
911
+
912
+ if (inet_sk_diag_fill (sk , inet_csk (sk ), skb ,
913
+ cb , r , NLM_F_MULTI ,
914
+ net_admin ) < 0 ) {
940
915
spin_unlock (& ilb -> lock );
941
916
goto done ;
942
917
}
@@ -1014,11 +989,8 @@ void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb,
1014
989
res = 0 ;
1015
990
for (idx = 0 ; idx < accum ; idx ++ ) {
1016
991
if (res >= 0 ) {
1017
- res = sk_diag_fill (sk_arr [idx ], skb , r ,
1018
- sk_user_ns (NETLINK_CB (cb -> skb ).sk ),
1019
- NETLINK_CB (cb -> skb ).portid ,
1020
- cb -> nlh -> nlmsg_seq , NLM_F_MULTI ,
1021
- cb -> nlh , net_admin );
992
+ res = sk_diag_fill (sk_arr [idx ], skb , cb , r ,
993
+ NLM_F_MULTI , net_admin );
1022
994
if (res < 0 )
1023
995
num = num_arr [idx ];
1024
996
}
0 commit comments