@@ -270,6 +270,7 @@ struct macsec_dev {
270270 struct pcpu_secy_stats __percpu * stats ;
271271 struct list_head secys ;
272272 struct gro_cells gro_cells ;
273+ unsigned int nest_level ;
273274};
274275
275276/**
@@ -2699,6 +2700,8 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
26992700
27002701#define MACSEC_FEATURES \
27012702 (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
2703+ static struct lock_class_key macsec_netdev_addr_lock_key ;
2704+
27022705static int macsec_dev_init (struct net_device * dev )
27032706{
27042707 struct macsec_dev * macsec = macsec_priv (dev );
@@ -2910,6 +2913,13 @@ static int macsec_get_iflink(const struct net_device *dev)
29102913 return macsec_priv (dev )-> real_dev -> ifindex ;
29112914}
29122915
2916+
2917+ static int macsec_get_nest_level (struct net_device * dev )
2918+ {
2919+ return macsec_priv (dev )-> nest_level ;
2920+ }
2921+
2922+
29132923static const struct net_device_ops macsec_netdev_ops = {
29142924 .ndo_init = macsec_dev_init ,
29152925 .ndo_uninit = macsec_dev_uninit ,
@@ -2923,6 +2933,7 @@ static const struct net_device_ops macsec_netdev_ops = {
29232933 .ndo_start_xmit = macsec_start_xmit ,
29242934 .ndo_get_stats64 = macsec_get_stats64 ,
29252935 .ndo_get_iflink = macsec_get_iflink ,
2936+ .ndo_get_lock_subclass = macsec_get_nest_level ,
29262937};
29272938
29282939static const struct device_type macsec_type = {
@@ -3050,10 +3061,12 @@ static void macsec_del_dev(struct macsec_dev *macsec)
30503061static void macsec_common_dellink (struct net_device * dev , struct list_head * head )
30513062{
30523063 struct macsec_dev * macsec = macsec_priv (dev );
3064+ struct net_device * real_dev = macsec -> real_dev ;
30533065
30543066 unregister_netdevice_queue (dev , head );
30553067 list_del_rcu (& macsec -> secys );
30563068 macsec_del_dev (macsec );
3069+ netdev_upper_dev_unlink (real_dev , dev );
30573070
30583071 macsec_generation ++ ;
30593072}
@@ -3188,6 +3201,16 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
31883201
31893202 dev_hold (real_dev );
31903203
3204+ macsec -> nest_level = dev_get_nest_level (real_dev , netif_is_macsec ) + 1 ;
3205+ netdev_lockdep_set_classes (dev );
3206+ lockdep_set_class_and_subclass (& dev -> addr_list_lock ,
3207+ & macsec_netdev_addr_lock_key ,
3208+ macsec_get_nest_level (dev ));
3209+
3210+ err = netdev_upper_dev_link (real_dev , dev );
3211+ if (err < 0 )
3212+ goto unregister ;
3213+
31913214 /* need to be already registered so that ->init has run and
31923215 * the MAC addr is set
31933216 */
@@ -3200,12 +3223,12 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
32003223
32013224 if (rx_handler && sci_exists (real_dev , sci )) {
32023225 err = - EBUSY ;
3203- goto unregister ;
3226+ goto unlink ;
32043227 }
32053228
32063229 err = macsec_add_dev (dev , sci , icv_len );
32073230 if (err )
3208- goto unregister ;
3231+ goto unlink ;
32093232
32103233 if (data )
32113234 macsec_changelink_common (dev , data );
@@ -3220,6 +3243,8 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
32203243
32213244del_dev :
32223245 macsec_del_dev (macsec );
3246+ unlink :
3247+ netdev_upper_dev_unlink (real_dev , dev );
32233248unregister :
32243249 unregister_netdevice (dev );
32253250 return err ;
0 commit comments