@@ -69,7 +69,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
6969{
7070 struct tcf_common * p ;
7171 int err = 0 , index = -1 ,i = 0 , s_i = 0 , n_i = 0 ;
72- struct nlattr * r ;
72+ struct nlattr * nest ;
7373
7474 read_lock_bh (hinfo -> lock );
7575
@@ -84,15 +84,17 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
8484 continue ;
8585 a -> priv = p ;
8686 a -> order = n_i ;
87- r = (struct nlattr * )skb_tail_pointer (skb );
88- NLA_PUT (skb , a -> order , 0 , NULL );
87+
88+ nest = nla_nest_start (skb , a -> order );
89+ if (nest == NULL )
90+ goto nla_put_failure ;
8991 err = tcf_action_dump_1 (skb , a , 0 , 0 );
9092 if (err < 0 ) {
9193 index -- ;
92- nlmsg_trim (skb , r );
94+ nlmsg_trim (skb , nest );
9395 goto done ;
9496 }
95- r -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) r ;
97+ nla_nest_end (skb , nest ) ;
9698 n_i ++ ;
9799 if (n_i >= TCA_ACT_MAX_PRIO )
98100 goto done ;
@@ -105,19 +107,20 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
105107 return n_i ;
106108
107109nla_put_failure :
108- nlmsg_trim (skb , r );
110+ nla_nest_cancel (skb , nest );
109111 goto done ;
110112}
111113
112114static int tcf_del_walker (struct sk_buff * skb , struct tc_action * a ,
113115 struct tcf_hashinfo * hinfo )
114116{
115117 struct tcf_common * p , * s_p ;
116- struct nlattr * r ;
118+ struct nlattr * nest ;
117119 int i = 0 , n_i = 0 ;
118120
119- r = (struct nlattr * )skb_tail_pointer (skb );
120- NLA_PUT (skb , a -> order , 0 , NULL );
121+ nest = nla_nest_start (skb , a -> order );
122+ if (nest == NULL )
123+ goto nla_put_failure ;
121124 NLA_PUT (skb , TCA_KIND , IFNAMSIZ , a -> ops -> kind );
122125 for (i = 0 ; i < (hinfo -> hmask + 1 ); i ++ ) {
123126 p = hinfo -> htab [tcf_hash (i , hinfo -> hmask )];
@@ -131,11 +134,11 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a,
131134 }
132135 }
133136 NLA_PUT (skb , TCA_FCNT , 4 , & n_i );
134- r -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) r ;
137+ nla_nest_end (skb , nest ) ;
135138
136139 return n_i ;
137140nla_put_failure :
138- nlmsg_trim (skb , r );
141+ nla_nest_cancel (skb , nest );
139142 return - EINVAL ;
140143}
141144
@@ -415,18 +418,19 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
415418{
416419 int err = - EINVAL ;
417420 unsigned char * b = skb_tail_pointer (skb );
418- struct nlattr * r ;
421+ struct nlattr * nest ;
419422
420423 if (a -> ops == NULL || a -> ops -> dump == NULL )
421424 return err ;
422425
423426 NLA_PUT (skb , TCA_KIND , IFNAMSIZ , a -> ops -> kind );
424427 if (tcf_action_copy_stats (skb , a , 0 ))
425428 goto nla_put_failure ;
426- r = (struct nlattr * )skb_tail_pointer (skb );
427- NLA_PUT (skb , TCA_OPTIONS , 0 , NULL );
429+ nest = nla_nest_start (skb , TCA_OPTIONS );
430+ if (nest == NULL )
431+ goto nla_put_failure ;
428432 if ((err = tcf_action_dump_old (skb , a , bind , ref )) > 0 ) {
429- r -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) r ;
433+ nla_nest_end (skb , nest ) ;
430434 return err ;
431435 }
432436
@@ -441,25 +445,25 @@ tcf_action_dump(struct sk_buff *skb, struct tc_action *act, int bind, int ref)
441445{
442446 struct tc_action * a ;
443447 int err = - EINVAL ;
444- unsigned char * b = skb_tail_pointer (skb );
445- struct nlattr * r ;
448+ struct nlattr * nest ;
446449
447450 while ((a = act ) != NULL ) {
448- r = (struct nlattr * )skb_tail_pointer (skb );
449451 act = a -> next ;
450- NLA_PUT (skb , a -> order , 0 , NULL );
452+ nest = nla_nest_start (skb , a -> order );
453+ if (nest == NULL )
454+ goto nla_put_failure ;
451455 err = tcf_action_dump_1 (skb , a , bind , ref );
452456 if (err < 0 )
453457 goto errout ;
454- r -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) r ;
458+ nla_nest_end (skb , nest ) ;
455459 }
456460
457461 return 0 ;
458462
459463nla_put_failure :
460464 err = - EINVAL ;
461465errout :
462- nlmsg_trim (skb , b );
466+ nla_nest_cancel (skb , nest );
463467 return err ;
464468}
465469
@@ -627,7 +631,7 @@ tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 pid, u32 seq,
627631 struct tcamsg * t ;
628632 struct nlmsghdr * nlh ;
629633 unsigned char * b = skb_tail_pointer (skb );
630- struct nlattr * x ;
634+ struct nlattr * nest ;
631635
632636 nlh = NLMSG_NEW (skb , pid , seq , event , sizeof (* t ), flags );
633637
@@ -636,13 +640,14 @@ tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 pid, u32 seq,
636640 t -> tca__pad1 = 0 ;
637641 t -> tca__pad2 = 0 ;
638642
639- x = (struct nlattr * )skb_tail_pointer (skb );
640- NLA_PUT (skb , TCA_ACT_TAB , 0 , NULL );
643+ nest = nla_nest_start (skb , TCA_ACT_TAB );
644+ if (nest == NULL )
645+ goto nla_put_failure ;
641646
642647 if (tcf_action_dump (skb , a , bind , ref ) < 0 )
643648 goto nla_put_failure ;
644649
645- x -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) x ;
650+ nla_nest_end (skb , nest ) ;
646651
647652 nlh -> nlmsg_len = skb_tail_pointer (skb ) - b ;
648653 return skb -> len ;
@@ -743,7 +748,7 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
743748 struct nlmsghdr * nlh ;
744749 struct tcamsg * t ;
745750 struct netlink_callback dcb ;
746- struct nlattr * x ;
751+ struct nlattr * nest ;
747752 struct nlattr * tb [TCA_ACT_MAX + 1 ];
748753 struct nlattr * kind ;
749754 struct tc_action * a = create_a (0 );
@@ -779,14 +784,15 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
779784 t -> tca__pad1 = 0 ;
780785 t -> tca__pad2 = 0 ;
781786
782- x = (struct nlattr * )skb_tail_pointer (skb );
783- NLA_PUT (skb , TCA_ACT_TAB , 0 , NULL );
787+ nest = nla_nest_start (skb , TCA_ACT_TAB );
788+ if (nest == NULL )
789+ goto nla_put_failure ;
784790
785791 err = a -> ops -> walk (skb , & dcb , RTM_DELACTION , a );
786792 if (err < 0 )
787793 goto nla_put_failure ;
788794
789- x -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) x ;
795+ nla_nest_end (skb , nest ) ;
790796
791797 nlh -> nlmsg_len = skb_tail_pointer (skb ) - b ;
792798 nlh -> nlmsg_flags |= NLM_F_ROOT ;
@@ -875,7 +881,7 @@ static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
875881 struct tcamsg * t ;
876882 struct nlmsghdr * nlh ;
877883 struct sk_buff * skb ;
878- struct nlattr * x ;
884+ struct nlattr * nest ;
879885 unsigned char * b ;
880886 int err = 0 ;
881887
@@ -891,13 +897,14 @@ static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
891897 t -> tca__pad1 = 0 ;
892898 t -> tca__pad2 = 0 ;
893899
894- x = (struct nlattr * )skb_tail_pointer (skb );
895- NLA_PUT (skb , TCA_ACT_TAB , 0 , NULL );
900+ nest = nla_nest_start (skb , TCA_ACT_TAB );
901+ if (nest == NULL )
902+ goto nla_put_failure ;
896903
897904 if (tcf_action_dump (skb , a , 0 , 0 ) < 0 )
898905 goto nla_put_failure ;
899906
900- x -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) x ;
907+ nla_nest_end (skb , nest ) ;
901908
902909 nlh -> nlmsg_len = skb_tail_pointer (skb ) - b ;
903910 NETLINK_CB (skb ).dst_group = RTNLGRP_TC ;
@@ -1025,7 +1032,7 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
10251032 struct net * net = skb -> sk -> sk_net ;
10261033 struct nlmsghdr * nlh ;
10271034 unsigned char * b = skb_tail_pointer (skb );
1028- struct nlattr * x ;
1035+ struct nlattr * nest ;
10291036 struct tc_action_ops * a_o ;
10301037 struct tc_action a ;
10311038 int ret = 0 ;
@@ -1060,18 +1067,19 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
10601067 t -> tca__pad1 = 0 ;
10611068 t -> tca__pad2 = 0 ;
10621069
1063- x = (struct nlattr * )skb_tail_pointer (skb );
1064- NLA_PUT (skb , TCA_ACT_TAB , 0 , NULL );
1070+ nest = nla_nest_start (skb , TCA_ACT_TAB );
1071+ if (nest == NULL )
1072+ goto nla_put_failure ;
10651073
10661074 ret = a_o -> walk (skb , cb , RTM_GETACTION , & a );
10671075 if (ret < 0 )
10681076 goto nla_put_failure ;
10691077
10701078 if (ret > 0 ) {
1071- x -> nla_len = skb_tail_pointer (skb ) - ( u8 * ) x ;
1079+ nla_nest_end (skb , nest ) ;
10721080 ret = skb -> len ;
10731081 } else
1074- nlmsg_trim (skb , x );
1082+ nla_nest_cancel (skb , nest );
10751083
10761084 nlh -> nlmsg_len = skb_tail_pointer (skb ) - b ;
10771085 if (NETLINK_CB (cb -> skb ).pid && ret )
0 commit comments