@@ -110,6 +110,7 @@ struct cf_mod {
110110 void (* xor )(struct can_frame * cf , struct cgw_csum_xor * xor );
111111 void (* crc8 )(struct can_frame * cf , struct cgw_csum_crc8 * crc8 );
112112 } csumfunc ;
113+ u32 uid ;
113114};
114115
115116
@@ -548,6 +549,11 @@ static int cgw_put_job(struct sk_buff *skb, struct cgw_job *gwj, int type,
548549 goto cancel ;
549550 }
550551
552+ if (gwj -> mod .uid ) {
553+ if (nla_put_u32 (skb , CGW_MOD_UID , gwj -> mod .uid ) < 0 )
554+ goto cancel ;
555+ }
556+
551557 if (gwj -> mod .csumfunc .crc8 ) {
552558 if (nla_put (skb , CGW_CS_CRC8 , CGW_CS_CRC8_LEN ,
553559 & gwj -> mod .csum .crc8 ) < 0 )
@@ -619,6 +625,7 @@ static const struct nla_policy cgw_policy[CGW_MAX+1] = {
619625 [CGW_DST_IF ] = { .type = NLA_U32 },
620626 [CGW_FILTER ] = { .len = sizeof (struct can_filter ) },
621627 [CGW_LIM_HOPS ] = { .type = NLA_U8 },
628+ [CGW_MOD_UID ] = { .type = NLA_U32 },
622629};
623630
624631/* check for common and gwtype specific attributes */
@@ -761,6 +768,10 @@ static int cgw_parse_attr(struct nlmsghdr *nlh, struct cf_mod *mod,
761768 else
762769 mod -> csumfunc .xor = cgw_csum_xor_neg ;
763770 }
771+
772+ if (tb [CGW_MOD_UID ]) {
773+ nla_memcpy (& mod -> uid , tb [CGW_MOD_UID ], sizeof (u32 ));
774+ }
764775 }
765776
766777 if (gwtype == CGW_TYPE_CAN_CAN ) {
@@ -802,6 +813,8 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
802813{
803814 struct rtcanmsg * r ;
804815 struct cgw_job * gwj ;
816+ struct cf_mod mod ;
817+ struct can_can_gw ccgw ;
805818 u8 limhops = 0 ;
806819 int err = 0 ;
807820
@@ -819,6 +832,36 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
819832 if (r -> gwtype != CGW_TYPE_CAN_CAN )
820833 return - EINVAL ;
821834
835+ err = cgw_parse_attr (nlh , & mod , CGW_TYPE_CAN_CAN , & ccgw , & limhops );
836+ if (err < 0 )
837+ return err ;
838+
839+ if (mod .uid ) {
840+
841+ ASSERT_RTNL ();
842+
843+ /* check for updating an existing job with identical uid */
844+ hlist_for_each_entry (gwj , & cgw_list , list ) {
845+
846+ if (gwj -> mod .uid != mod .uid )
847+ continue ;
848+
849+ /* interfaces & filters must be identical */
850+ if (memcmp (& gwj -> ccgw , & ccgw , sizeof (ccgw )))
851+ return - EINVAL ;
852+
853+ /* update modifications with disabled softirq & quit */
854+ local_bh_disable ();
855+ memcpy (& gwj -> mod , & mod , sizeof (mod ));
856+ local_bh_enable ();
857+ return 0 ;
858+ }
859+ }
860+
861+ /* ifindex == 0 is not allowed for job creation */
862+ if (!ccgw .src_idx || !ccgw .dst_idx )
863+ return - ENODEV ;
864+
822865 gwj = kmem_cache_alloc (cgw_cache , GFP_KERNEL );
823866 if (!gwj )
824867 return - ENOMEM ;
@@ -828,18 +871,14 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
828871 gwj -> deleted_frames = 0 ;
829872 gwj -> flags = r -> flags ;
830873 gwj -> gwtype = r -> gwtype ;
874+ gwj -> limit_hops = limhops ;
831875
832- err = cgw_parse_attr (nlh , & gwj -> mod , CGW_TYPE_CAN_CAN , & gwj -> ccgw ,
833- & limhops );
834- if (err < 0 )
835- goto out ;
876+ /* insert already parsed information */
877+ memcpy (& gwj -> mod , & mod , sizeof (mod ));
878+ memcpy (& gwj -> ccgw , & ccgw , sizeof (ccgw ));
836879
837880 err = - ENODEV ;
838881
839- /* ifindex == 0 is not allowed for job creation */
840- if (!gwj -> ccgw .src_idx || !gwj -> ccgw .dst_idx )
841- goto out ;
842-
843882 gwj -> src .dev = __dev_get_by_index (& init_net , gwj -> ccgw .src_idx );
844883
845884 if (!gwj -> src .dev )
@@ -856,8 +895,6 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
856895 if (gwj -> dst .dev -> type != ARPHRD_CAN )
857896 goto out ;
858897
859- gwj -> limit_hops = limhops ;
860-
861898 ASSERT_RTNL ();
862899
863900 err = cgw_register_filter (gwj );
@@ -931,8 +968,15 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
931968 if (gwj -> limit_hops != limhops )
932969 continue ;
933970
934- if (memcmp (& gwj -> mod , & mod , sizeof (mod )))
935- continue ;
971+ /* we have a match when uid is enabled and identical */
972+ if (gwj -> mod .uid || mod .uid ) {
973+ if (gwj -> mod .uid != mod .uid )
974+ continue ;
975+ } else {
976+ /* no uid => check for identical modifications */
977+ if (memcmp (& gwj -> mod , & mod , sizeof (mod )))
978+ continue ;
979+ }
936980
937981 /* if (r->gwtype == CGW_TYPE_CAN_CAN) - is made sure here */
938982 if (memcmp (& gwj -> ccgw , & ccgw , sizeof (ccgw )))
0 commit comments