1b863ceb7SPatrick McHardy /* 2b863ceb7SPatrick McHardy * Copyright (c) 2007 Patrick McHardy <kaber@trash.net> 3b863ceb7SPatrick McHardy * 4b863ceb7SPatrick McHardy * This program is free software; you can redistribute it and/or 5b863ceb7SPatrick McHardy * modify it under the terms of the GNU General Public License as 6b863ceb7SPatrick McHardy * published by the Free Software Foundation; either version 2 of 7b863ceb7SPatrick McHardy * the License, or (at your option) any later version. 8b863ceb7SPatrick McHardy * 9b863ceb7SPatrick McHardy * The code this is based on carried the following copyright notice: 10b863ceb7SPatrick McHardy * --- 11b863ceb7SPatrick McHardy * (C) Copyright 2001-2006 12b863ceb7SPatrick McHardy * Alex Zeffertt, Cambridge Broadband Ltd, ajz@cambridgebroadband.com 13b863ceb7SPatrick McHardy * Re-worked by Ben Greear <greearb@candelatech.com> 14b863ceb7SPatrick McHardy * --- 15b863ceb7SPatrick McHardy */ 16b863ceb7SPatrick McHardy #include <linux/kernel.h> 17b863ceb7SPatrick McHardy #include <linux/types.h> 18b863ceb7SPatrick McHardy #include <linux/module.h> 19b863ceb7SPatrick McHardy #include <linux/init.h> 20b863ceb7SPatrick McHardy #include <linux/errno.h> 21b863ceb7SPatrick McHardy #include <linux/slab.h> 22b863ceb7SPatrick McHardy #include <linux/string.h> 2382524746SFranck Bui-Huu #include <linux/rculist.h> 24b863ceb7SPatrick McHardy #include <linux/notifier.h> 25b863ceb7SPatrick McHardy #include <linux/netdevice.h> 26b863ceb7SPatrick McHardy #include <linux/etherdevice.h> 27b863ceb7SPatrick McHardy #include <linux/ethtool.h> 28b863ceb7SPatrick McHardy #include <linux/if_arp.h> 2987002b03SJiri Pirko #include <linux/if_vlan.h> 30b863ceb7SPatrick McHardy #include <linux/if_link.h> 31b863ceb7SPatrick McHardy #include <linux/if_macvlan.h> 32cd431e73SEric Dumazet #include <linux/hash.h> 33b863ceb7SPatrick McHardy #include <net/rtnetlink.h> 34618e1b74SArnd Bergmann #include <net/xfrm.h> 35b863ceb7SPatrick McHardy 36b863ceb7SPatrick McHardy #define MACVLAN_HASH_SIZE (1 << BITS_PER_BYTE) 37b863ceb7SPatrick McHardy 38b863ceb7SPatrick McHardy struct macvlan_port { 39b863ceb7SPatrick McHardy struct net_device *dev; 40b863ceb7SPatrick McHardy struct hlist_head vlan_hash[MACVLAN_HASH_SIZE]; 41b863ceb7SPatrick McHardy struct list_head vlans; 428b37ef0aSJiri Pirko struct rcu_head rcu; 43eb06acdcSSridhar Samudrala bool passthru; 44d5cd9244SEric W. Biederman int count; 45b863ceb7SPatrick McHardy }; 46b863ceb7SPatrick McHardy 47d5cd9244SEric W. Biederman static void macvlan_port_destroy(struct net_device *dev); 48d5cd9244SEric W. Biederman 49e052f7e6SEric Dumazet static struct macvlan_port *macvlan_port_get_rcu(const struct net_device *dev) 50e052f7e6SEric Dumazet { 51e052f7e6SEric Dumazet return rcu_dereference(dev->rx_handler_data); 52e052f7e6SEric Dumazet } 53e052f7e6SEric Dumazet 54e052f7e6SEric Dumazet static struct macvlan_port *macvlan_port_get_rtnl(const struct net_device *dev) 55e052f7e6SEric Dumazet { 56e052f7e6SEric Dumazet return rtnl_dereference(dev->rx_handler_data); 57e052f7e6SEric Dumazet } 58e052f7e6SEric Dumazet 59a35e2c1bSJiri Pirko #define macvlan_port_exists(dev) (dev->priv_flags & IFF_MACVLAN_PORT) 60a35e2c1bSJiri Pirko 61b863ceb7SPatrick McHardy static struct macvlan_dev *macvlan_hash_lookup(const struct macvlan_port *port, 62b863ceb7SPatrick McHardy const unsigned char *addr) 63b863ceb7SPatrick McHardy { 64b863ceb7SPatrick McHardy struct macvlan_dev *vlan; 65b863ceb7SPatrick McHardy 66b67bfe0dSSasha Levin hlist_for_each_entry_rcu(vlan, &port->vlan_hash[addr[5]], hlist) { 67a6700db1SJoe Perches if (ether_addr_equal_64bits(vlan->dev->dev_addr, addr)) 68b863ceb7SPatrick McHardy return vlan; 69b863ceb7SPatrick McHardy } 70b863ceb7SPatrick McHardy return NULL; 71b863ceb7SPatrick McHardy } 72b863ceb7SPatrick McHardy 73f9ac30f0SEric Biederman static void macvlan_hash_add(struct macvlan_dev *vlan) 74f9ac30f0SEric Biederman { 75f9ac30f0SEric Biederman struct macvlan_port *port = vlan->port; 76f9ac30f0SEric Biederman const unsigned char *addr = vlan->dev->dev_addr; 77f9ac30f0SEric Biederman 78f9ac30f0SEric Biederman hlist_add_head_rcu(&vlan->hlist, &port->vlan_hash[addr[5]]); 79f9ac30f0SEric Biederman } 80f9ac30f0SEric Biederman 81449f4544SEric Dumazet static void macvlan_hash_del(struct macvlan_dev *vlan, bool sync) 82f9ac30f0SEric Biederman { 83f9ac30f0SEric Biederman hlist_del_rcu(&vlan->hlist); 84449f4544SEric Dumazet if (sync) 85f9ac30f0SEric Biederman synchronize_rcu(); 86f9ac30f0SEric Biederman } 87f9ac30f0SEric Biederman 88f9ac30f0SEric Biederman static void macvlan_hash_change_addr(struct macvlan_dev *vlan, 89f9ac30f0SEric Biederman const unsigned char *addr) 90f9ac30f0SEric Biederman { 91449f4544SEric Dumazet macvlan_hash_del(vlan, true); 92f9ac30f0SEric Biederman /* Now that we are unhashed it is safe to change the device 93f9ac30f0SEric Biederman * address without confusing packet delivery. 94f9ac30f0SEric Biederman */ 95f9ac30f0SEric Biederman memcpy(vlan->dev->dev_addr, addr, ETH_ALEN); 96f9ac30f0SEric Biederman macvlan_hash_add(vlan); 97f9ac30f0SEric Biederman } 98f9ac30f0SEric Biederman 99f9ac30f0SEric Biederman static int macvlan_addr_busy(const struct macvlan_port *port, 100f9ac30f0SEric Biederman const unsigned char *addr) 101f9ac30f0SEric Biederman { 102f9ac30f0SEric Biederman /* Test to see if the specified multicast address is 103f9ac30f0SEric Biederman * currently in use by the underlying device or 104f9ac30f0SEric Biederman * another macvlan. 105f9ac30f0SEric Biederman */ 106a6700db1SJoe Perches if (ether_addr_equal_64bits(port->dev->dev_addr, addr)) 107f9ac30f0SEric Biederman return 1; 108f9ac30f0SEric Biederman 109f9ac30f0SEric Biederman if (macvlan_hash_lookup(port, addr)) 110f9ac30f0SEric Biederman return 1; 111f9ac30f0SEric Biederman 112f9ac30f0SEric Biederman return 0; 113f9ac30f0SEric Biederman } 114f9ac30f0SEric Biederman 115a1e514c5SArnd Bergmann 116fc0663d6SArnd Bergmann static int macvlan_broadcast_one(struct sk_buff *skb, 117fc0663d6SArnd Bergmann const struct macvlan_dev *vlan, 118618e1b74SArnd Bergmann const struct ethhdr *eth, bool local) 119a1e514c5SArnd Bergmann { 120fc0663d6SArnd Bergmann struct net_device *dev = vlan->dev; 121a1e514c5SArnd Bergmann 122618e1b74SArnd Bergmann if (local) 1232f6a1b66SVlad Yasevich return dev_forward_skb(dev, skb); 124618e1b74SArnd Bergmann 125a1e514c5SArnd Bergmann skb->dev = dev; 126a6700db1SJoe Perches if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast)) 127a1e514c5SArnd Bergmann skb->pkt_type = PACKET_BROADCAST; 128a1e514c5SArnd Bergmann else 129a1e514c5SArnd Bergmann skb->pkt_type = PACKET_MULTICAST; 130a1e514c5SArnd Bergmann 1312f6a1b66SVlad Yasevich return netif_rx(skb); 132a1e514c5SArnd Bergmann } 133a1e514c5SArnd Bergmann 1343807ff58SEric Dumazet static u32 macvlan_hash_mix(const struct macvlan_dev *vlan) 1353807ff58SEric Dumazet { 1363807ff58SEric Dumazet return (u32)(((unsigned long)vlan) >> L1_CACHE_SHIFT); 1373807ff58SEric Dumazet } 1383807ff58SEric Dumazet 1393807ff58SEric Dumazet 1403807ff58SEric Dumazet static unsigned int mc_hash(const struct macvlan_dev *vlan, 1413807ff58SEric Dumazet const unsigned char *addr) 142cd431e73SEric Dumazet { 143cd431e73SEric Dumazet u32 val = __get_unaligned_cpu32(addr + 2); 144cd431e73SEric Dumazet 1453807ff58SEric Dumazet val ^= macvlan_hash_mix(vlan); 146cd431e73SEric Dumazet return hash_32(val, MACVLAN_MC_FILTER_BITS); 147cd431e73SEric Dumazet } 148cd431e73SEric Dumazet 149b863ceb7SPatrick McHardy static void macvlan_broadcast(struct sk_buff *skb, 150618e1b74SArnd Bergmann const struct macvlan_port *port, 151618e1b74SArnd Bergmann struct net_device *src, 152618e1b74SArnd Bergmann enum macvlan_mode mode) 153b863ceb7SPatrick McHardy { 154b863ceb7SPatrick McHardy const struct ethhdr *eth = eth_hdr(skb); 155b863ceb7SPatrick McHardy const struct macvlan_dev *vlan; 156b863ceb7SPatrick McHardy struct sk_buff *nskb; 157b863ceb7SPatrick McHardy unsigned int i; 158a1e514c5SArnd Bergmann int err; 1593807ff58SEric Dumazet unsigned int hash; 160b863ceb7SPatrick McHardy 161efbbced3SPatrick McHardy if (skb->protocol == htons(ETH_P_PAUSE)) 162efbbced3SPatrick McHardy return; 163efbbced3SPatrick McHardy 164b863ceb7SPatrick McHardy for (i = 0; i < MACVLAN_HASH_SIZE; i++) { 165b67bfe0dSSasha Levin hlist_for_each_entry_rcu(vlan, &port->vlan_hash[i], hlist) { 166618e1b74SArnd Bergmann if (vlan->dev == src || !(vlan->mode & mode)) 167618e1b74SArnd Bergmann continue; 168618e1b74SArnd Bergmann 1693807ff58SEric Dumazet hash = mc_hash(vlan, eth->h_dest); 170cd431e73SEric Dumazet if (!test_bit(hash, vlan->mc_filter)) 171cd431e73SEric Dumazet continue; 172de9e8f3fSHerbert Xu 173de9e8f3fSHerbert Xu err = NET_RX_DROP; 174b863ceb7SPatrick McHardy nskb = skb_clone(skb, GFP_ATOMIC); 175de9e8f3fSHerbert Xu if (likely(nskb)) 176de9e8f3fSHerbert Xu err = macvlan_broadcast_one( 177de9e8f3fSHerbert Xu nskb, vlan, eth, 178618e1b74SArnd Bergmann mode == MACVLAN_MODE_BRIDGE); 179a1e514c5SArnd Bergmann macvlan_count_rx(vlan, skb->len + ETH_HLEN, 180a1e514c5SArnd Bergmann err == NET_RX_SUCCESS, 1); 181b863ceb7SPatrick McHardy } 182b863ceb7SPatrick McHardy } 183b863ceb7SPatrick McHardy } 184b863ceb7SPatrick McHardy 185b863ceb7SPatrick McHardy /* called under rcu_read_lock() from netif_receive_skb */ 1868a4eb573SJiri Pirko static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) 187b863ceb7SPatrick McHardy { 188ab95bfe0SJiri Pirko struct macvlan_port *port; 1898a4eb573SJiri Pirko struct sk_buff *skb = *pskb; 190b863ceb7SPatrick McHardy const struct ethhdr *eth = eth_hdr(skb); 191b863ceb7SPatrick McHardy const struct macvlan_dev *vlan; 192618e1b74SArnd Bergmann const struct macvlan_dev *src; 193b863ceb7SPatrick McHardy struct net_device *dev; 194ba01877fSSridhar Samudrala unsigned int len = 0; 195ba01877fSSridhar Samudrala int ret = NET_RX_DROP; 196b863ceb7SPatrick McHardy 197a35e2c1bSJiri Pirko port = macvlan_port_get_rcu(skb->dev); 198b863ceb7SPatrick McHardy if (is_multicast_ether_addr(eth->h_dest)) { 199bc416d97SEric Dumazet skb = ip_check_defrag(skb, IP_DEFRAG_MACVLAN); 200bc416d97SEric Dumazet if (!skb) 201bc416d97SEric Dumazet return RX_HANDLER_CONSUMED; 2024ec7ac12SEric Dumazet eth = eth_hdr(skb); 203618e1b74SArnd Bergmann src = macvlan_hash_lookup(port, eth->h_source); 204618e1b74SArnd Bergmann if (!src) 205618e1b74SArnd Bergmann /* frame comes from an external address */ 206618e1b74SArnd Bergmann macvlan_broadcast(skb, port, NULL, 207618e1b74SArnd Bergmann MACVLAN_MODE_PRIVATE | 208618e1b74SArnd Bergmann MACVLAN_MODE_VEPA | 209eb06acdcSSridhar Samudrala MACVLAN_MODE_PASSTHRU| 210618e1b74SArnd Bergmann MACVLAN_MODE_BRIDGE); 211618e1b74SArnd Bergmann else if (src->mode == MACVLAN_MODE_VEPA) 212618e1b74SArnd Bergmann /* flood to everyone except source */ 213618e1b74SArnd Bergmann macvlan_broadcast(skb, port, src->dev, 214618e1b74SArnd Bergmann MACVLAN_MODE_VEPA | 215618e1b74SArnd Bergmann MACVLAN_MODE_BRIDGE); 216618e1b74SArnd Bergmann else if (src->mode == MACVLAN_MODE_BRIDGE) 217618e1b74SArnd Bergmann /* 218618e1b74SArnd Bergmann * flood only to VEPA ports, bridge ports 219618e1b74SArnd Bergmann * already saw the frame on the way out. 220618e1b74SArnd Bergmann */ 221618e1b74SArnd Bergmann macvlan_broadcast(skb, port, src->dev, 222618e1b74SArnd Bergmann MACVLAN_MODE_VEPA); 223729e72a1Sstephen hemminger else { 224729e72a1Sstephen hemminger /* forward to original port. */ 225729e72a1Sstephen hemminger vlan = src; 226729e72a1Sstephen hemminger ret = macvlan_broadcast_one(skb, vlan, eth, 0); 227729e72a1Sstephen hemminger goto out; 228729e72a1Sstephen hemminger } 229729e72a1Sstephen hemminger 2308a4eb573SJiri Pirko return RX_HANDLER_PASS; 231b863ceb7SPatrick McHardy } 232b863ceb7SPatrick McHardy 233eb06acdcSSridhar Samudrala if (port->passthru) 234233c7df0SJiri Pirko vlan = list_first_or_null_rcu(&port->vlans, 235233c7df0SJiri Pirko struct macvlan_dev, list); 236eb06acdcSSridhar Samudrala else 237b863ceb7SPatrick McHardy vlan = macvlan_hash_lookup(port, eth->h_dest); 238b863ceb7SPatrick McHardy if (vlan == NULL) 2398a4eb573SJiri Pirko return RX_HANDLER_PASS; 240b863ceb7SPatrick McHardy 241b863ceb7SPatrick McHardy dev = vlan->dev; 242b863ceb7SPatrick McHardy if (unlikely(!(dev->flags & IFF_UP))) { 243b863ceb7SPatrick McHardy kfree_skb(skb); 2448a4eb573SJiri Pirko return RX_HANDLER_CONSUMED; 245b863ceb7SPatrick McHardy } 246a1e514c5SArnd Bergmann len = skb->len + ETH_HLEN; 247b863ceb7SPatrick McHardy skb = skb_share_check(skb, GFP_ATOMIC); 248a1e514c5SArnd Bergmann if (!skb) 249ba01877fSSridhar Samudrala goto out; 250b863ceb7SPatrick McHardy 251b863ceb7SPatrick McHardy skb->dev = dev; 252b863ceb7SPatrick McHardy skb->pkt_type = PACKET_HOST; 253b863ceb7SPatrick McHardy 2542f6a1b66SVlad Yasevich ret = netif_rx(skb); 255ba01877fSSridhar Samudrala 256ba01877fSSridhar Samudrala out: 257ba01877fSSridhar Samudrala macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0); 2588a4eb573SJiri Pirko return RX_HANDLER_CONSUMED; 259b863ceb7SPatrick McHardy } 260b863ceb7SPatrick McHardy 261618e1b74SArnd Bergmann static int macvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev) 262618e1b74SArnd Bergmann { 263618e1b74SArnd Bergmann const struct macvlan_dev *vlan = netdev_priv(dev); 264618e1b74SArnd Bergmann const struct macvlan_port *port = vlan->port; 265618e1b74SArnd Bergmann const struct macvlan_dev *dest; 26612a2856bSDaniel Lezcano __u8 ip_summed = skb->ip_summed; 267618e1b74SArnd Bergmann 268618e1b74SArnd Bergmann if (vlan->mode == MACVLAN_MODE_BRIDGE) { 269618e1b74SArnd Bergmann const struct ethhdr *eth = (void *)skb->data; 27012a2856bSDaniel Lezcano skb->ip_summed = CHECKSUM_UNNECESSARY; 271618e1b74SArnd Bergmann 272618e1b74SArnd Bergmann /* send to other bridge ports directly */ 273618e1b74SArnd Bergmann if (is_multicast_ether_addr(eth->h_dest)) { 274618e1b74SArnd Bergmann macvlan_broadcast(skb, port, dev, MACVLAN_MODE_BRIDGE); 275618e1b74SArnd Bergmann goto xmit_world; 276618e1b74SArnd Bergmann } 277618e1b74SArnd Bergmann 278618e1b74SArnd Bergmann dest = macvlan_hash_lookup(port, eth->h_dest); 279618e1b74SArnd Bergmann if (dest && dest->mode == MACVLAN_MODE_BRIDGE) { 280a37dd333SDavid Ward /* send to lowerdev first for its network taps */ 281cb2d0f3eSDavid Ward dev_forward_skb(vlan->lowerdev, skb); 282618e1b74SArnd Bergmann 283618e1b74SArnd Bergmann return NET_XMIT_SUCCESS; 284618e1b74SArnd Bergmann } 285618e1b74SArnd Bergmann } 286618e1b74SArnd Bergmann 287618e1b74SArnd Bergmann xmit_world: 28812a2856bSDaniel Lezcano skb->ip_summed = ip_summed; 28959b9997bSDavid S. Miller skb->dev = vlan->lowerdev; 290618e1b74SArnd Bergmann return dev_queue_xmit(skb); 291618e1b74SArnd Bergmann } 292618e1b74SArnd Bergmann 293*0db901bdSstephen hemminger static netdev_tx_t macvlan_start_xmit(struct sk_buff *skb, 294424efe9cSStephen Hemminger struct net_device *dev) 295b863ceb7SPatrick McHardy { 296b863ceb7SPatrick McHardy unsigned int len = skb->len; 297b863ceb7SPatrick McHardy int ret; 2988ffab51bSEric Dumazet const struct macvlan_dev *vlan = netdev_priv(dev); 299b863ceb7SPatrick McHardy 300a6cc0cfaSJohn Fastabend if (vlan->fwd_priv) { 301a6cc0cfaSJohn Fastabend skb->dev = vlan->lowerdev; 302a6cc0cfaSJohn Fastabend ret = dev_hard_start_xmit(skb, skb->dev, NULL, vlan->fwd_priv); 303a6cc0cfaSJohn Fastabend } else { 304618e1b74SArnd Bergmann ret = macvlan_queue_xmit(skb, dev); 305a6cc0cfaSJohn Fastabend } 306a6cc0cfaSJohn Fastabend 3072d6c9ffcSEric Dumazet if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) { 3088ffab51bSEric Dumazet struct macvlan_pcpu_stats *pcpu_stats; 3092c114553SEric Dumazet 3108ffab51bSEric Dumazet pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); 3118ffab51bSEric Dumazet u64_stats_update_begin(&pcpu_stats->syncp); 3128ffab51bSEric Dumazet pcpu_stats->tx_packets++; 3138ffab51bSEric Dumazet pcpu_stats->tx_bytes += len; 3148ffab51bSEric Dumazet u64_stats_update_end(&pcpu_stats->syncp); 3158ffab51bSEric Dumazet } else { 3168ffab51bSEric Dumazet this_cpu_inc(vlan->pcpu_stats->tx_dropped); 3178ffab51bSEric Dumazet } 318cbbef5e1SPatrick McHardy return ret; 319b863ceb7SPatrick McHardy } 320b863ceb7SPatrick McHardy 321b863ceb7SPatrick McHardy static int macvlan_hard_header(struct sk_buff *skb, struct net_device *dev, 3223b04dddeSStephen Hemminger unsigned short type, const void *daddr, 3233b04dddeSStephen Hemminger const void *saddr, unsigned len) 324b863ceb7SPatrick McHardy { 325b863ceb7SPatrick McHardy const struct macvlan_dev *vlan = netdev_priv(dev); 326b863ceb7SPatrick McHardy struct net_device *lowerdev = vlan->lowerdev; 327b863ceb7SPatrick McHardy 3280c4e8581SStephen Hemminger return dev_hard_header(skb, lowerdev, type, daddr, 329b863ceb7SPatrick McHardy saddr ? : dev->dev_addr, len); 330b863ceb7SPatrick McHardy } 331b863ceb7SPatrick McHardy 3323b04dddeSStephen Hemminger static const struct header_ops macvlan_hard_header_ops = { 3333b04dddeSStephen Hemminger .create = macvlan_hard_header, 3343b04dddeSStephen Hemminger .rebuild = eth_rebuild_header, 3353b04dddeSStephen Hemminger .parse = eth_header_parse, 3363b04dddeSStephen Hemminger .cache = eth_header_cache, 3373b04dddeSStephen Hemminger .cache_update = eth_header_cache_update, 3383b04dddeSStephen Hemminger }; 3393b04dddeSStephen Hemminger 340b863ceb7SPatrick McHardy static int macvlan_open(struct net_device *dev) 341b863ceb7SPatrick McHardy { 342b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 343b863ceb7SPatrick McHardy struct net_device *lowerdev = vlan->lowerdev; 344b863ceb7SPatrick McHardy int err; 345b863ceb7SPatrick McHardy 346eb06acdcSSridhar Samudrala if (vlan->port->passthru) { 34778738141SMichael S. Tsirkin if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) { 34878738141SMichael S. Tsirkin err = dev_set_promiscuity(lowerdev, 1); 34978738141SMichael S. Tsirkin if (err < 0) 35078738141SMichael S. Tsirkin goto out; 35178738141SMichael S. Tsirkin } 352eb06acdcSSridhar Samudrala goto hash_add; 353eb06acdcSSridhar Samudrala } 354eb06acdcSSridhar Samudrala 355a6cc0cfaSJohn Fastabend if (lowerdev->features & NETIF_F_HW_L2FW_DOFFLOAD) { 356a6cc0cfaSJohn Fastabend vlan->fwd_priv = 357a6cc0cfaSJohn Fastabend lowerdev->netdev_ops->ndo_dfwd_add_station(lowerdev, dev); 358a6cc0cfaSJohn Fastabend 359a6cc0cfaSJohn Fastabend /* If we get a NULL pointer back, or if we get an error 360a6cc0cfaSJohn Fastabend * then we should just fall through to the non accelerated path 361a6cc0cfaSJohn Fastabend */ 362a6cc0cfaSJohn Fastabend if (IS_ERR_OR_NULL(vlan->fwd_priv)) { 363a6cc0cfaSJohn Fastabend vlan->fwd_priv = NULL; 364a6cc0cfaSJohn Fastabend } else { 365a6cc0cfaSJohn Fastabend dev->features &= ~NETIF_F_LLTX; 366a6cc0cfaSJohn Fastabend return 0; 367a6cc0cfaSJohn Fastabend } 368a6cc0cfaSJohn Fastabend } 369a6cc0cfaSJohn Fastabend 370f9ac30f0SEric Biederman err = -EBUSY; 371f9ac30f0SEric Biederman if (macvlan_addr_busy(vlan->port, dev->dev_addr)) 372f9ac30f0SEric Biederman goto out; 373f9ac30f0SEric Biederman 374a748ee24SJiri Pirko err = dev_uc_add(lowerdev, dev->dev_addr); 375b863ceb7SPatrick McHardy if (err < 0) 376b89fb7daSWang Chen goto out; 377b89fb7daSWang Chen if (dev->flags & IFF_ALLMULTI) { 378b89fb7daSWang Chen err = dev_set_allmulti(lowerdev, 1); 379b89fb7daSWang Chen if (err < 0) 380b89fb7daSWang Chen goto del_unicast; 381b89fb7daSWang Chen } 382eb06acdcSSridhar Samudrala 383eb06acdcSSridhar Samudrala hash_add: 384f9ac30f0SEric Biederman macvlan_hash_add(vlan); 385b863ceb7SPatrick McHardy return 0; 386b89fb7daSWang Chen 387b89fb7daSWang Chen del_unicast: 388a748ee24SJiri Pirko dev_uc_del(lowerdev, dev->dev_addr); 389b89fb7daSWang Chen out: 390a6cc0cfaSJohn Fastabend if (vlan->fwd_priv) { 391a6cc0cfaSJohn Fastabend lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev, 392a6cc0cfaSJohn Fastabend vlan->fwd_priv); 393a6cc0cfaSJohn Fastabend vlan->fwd_priv = NULL; 394a6cc0cfaSJohn Fastabend } 395b89fb7daSWang Chen return err; 396b863ceb7SPatrick McHardy } 397b863ceb7SPatrick McHardy 398b863ceb7SPatrick McHardy static int macvlan_stop(struct net_device *dev) 399b863ceb7SPatrick McHardy { 400b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 401b863ceb7SPatrick McHardy struct net_device *lowerdev = vlan->lowerdev; 402b863ceb7SPatrick McHardy 403a6cc0cfaSJohn Fastabend if (vlan->fwd_priv) { 404a6cc0cfaSJohn Fastabend lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev, 405a6cc0cfaSJohn Fastabend vlan->fwd_priv); 406a6cc0cfaSJohn Fastabend vlan->fwd_priv = NULL; 407a6cc0cfaSJohn Fastabend return 0; 408a6cc0cfaSJohn Fastabend } 409a6cc0cfaSJohn Fastabend 410df8ef8f3SJohn Fastabend dev_uc_unsync(lowerdev, dev); 411df8ef8f3SJohn Fastabend dev_mc_unsync(lowerdev, dev); 412df8ef8f3SJohn Fastabend 413eb06acdcSSridhar Samudrala if (vlan->port->passthru) { 414df8ef8f3SJohn Fastabend if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) 415eb06acdcSSridhar Samudrala dev_set_promiscuity(lowerdev, -1); 416eb06acdcSSridhar Samudrala goto hash_del; 417eb06acdcSSridhar Samudrala } 418eb06acdcSSridhar Samudrala 419b863ceb7SPatrick McHardy if (dev->flags & IFF_ALLMULTI) 420b863ceb7SPatrick McHardy dev_set_allmulti(lowerdev, -1); 421b863ceb7SPatrick McHardy 422a748ee24SJiri Pirko dev_uc_del(lowerdev, dev->dev_addr); 423b863ceb7SPatrick McHardy 424eb06acdcSSridhar Samudrala hash_del: 425449f4544SEric Dumazet macvlan_hash_del(vlan, !dev->dismantle); 426b863ceb7SPatrick McHardy return 0; 427b863ceb7SPatrick McHardy } 428b863ceb7SPatrick McHardy 429ad5d20a6SPatrick McHardy static int macvlan_set_mac_address(struct net_device *dev, void *p) 430ad5d20a6SPatrick McHardy { 431ad5d20a6SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 432ad5d20a6SPatrick McHardy struct net_device *lowerdev = vlan->lowerdev; 433ad5d20a6SPatrick McHardy struct sockaddr *addr = p; 434ad5d20a6SPatrick McHardy int err; 435ad5d20a6SPatrick McHardy 436ad5d20a6SPatrick McHardy if (!is_valid_ether_addr(addr->sa_data)) 437ad5d20a6SPatrick McHardy return -EADDRNOTAVAIL; 438ad5d20a6SPatrick McHardy 439f9ac30f0SEric Biederman if (!(dev->flags & IFF_UP)) { 440f9ac30f0SEric Biederman /* Just copy in the new address */ 441f9ac30f0SEric Biederman memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); 442f9ac30f0SEric Biederman } else { 443f9ac30f0SEric Biederman /* Rehash and update the device filters */ 444f9ac30f0SEric Biederman if (macvlan_addr_busy(vlan->port, addr->sa_data)) 445f9ac30f0SEric Biederman return -EBUSY; 446ad5d20a6SPatrick McHardy 447a748ee24SJiri Pirko err = dev_uc_add(lowerdev, addr->sa_data); 448ccffad25SJiri Pirko if (err) 449ad5d20a6SPatrick McHardy return err; 450f9ac30f0SEric Biederman 451a748ee24SJiri Pirko dev_uc_del(lowerdev, dev->dev_addr); 452ad5d20a6SPatrick McHardy 453f9ac30f0SEric Biederman macvlan_hash_change_addr(vlan, addr->sa_data); 454f9ac30f0SEric Biederman } 455ad5d20a6SPatrick McHardy return 0; 456ad5d20a6SPatrick McHardy } 457ad5d20a6SPatrick McHardy 458b863ceb7SPatrick McHardy static void macvlan_change_rx_flags(struct net_device *dev, int change) 459b863ceb7SPatrick McHardy { 460b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 461b863ceb7SPatrick McHardy struct net_device *lowerdev = vlan->lowerdev; 462b863ceb7SPatrick McHardy 463b863ceb7SPatrick McHardy if (change & IFF_ALLMULTI) 464b863ceb7SPatrick McHardy dev_set_allmulti(lowerdev, dev->flags & IFF_ALLMULTI ? 1 : -1); 465b863ceb7SPatrick McHardy } 466b863ceb7SPatrick McHardy 467df8ef8f3SJohn Fastabend static void macvlan_set_mac_lists(struct net_device *dev) 468b863ceb7SPatrick McHardy { 469b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 470b863ceb7SPatrick McHardy 471cd431e73SEric Dumazet if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { 472cd431e73SEric Dumazet bitmap_fill(vlan->mc_filter, MACVLAN_MC_FILTER_SZ); 473cd431e73SEric Dumazet } else { 474cd431e73SEric Dumazet struct netdev_hw_addr *ha; 475cd431e73SEric Dumazet DECLARE_BITMAP(filter, MACVLAN_MC_FILTER_SZ); 476cd431e73SEric Dumazet 477cd431e73SEric Dumazet bitmap_zero(filter, MACVLAN_MC_FILTER_SZ); 478cd431e73SEric Dumazet netdev_for_each_mc_addr(ha, dev) { 4793807ff58SEric Dumazet __set_bit(mc_hash(vlan, ha->addr), filter); 480cd431e73SEric Dumazet } 481d5270430SEric Dumazet 4823807ff58SEric Dumazet __set_bit(mc_hash(vlan, dev->broadcast), filter); 483d5270430SEric Dumazet 484cd431e73SEric Dumazet bitmap_copy(vlan->mc_filter, filter, MACVLAN_MC_FILTER_SZ); 485cd431e73SEric Dumazet } 486df8ef8f3SJohn Fastabend dev_uc_sync(vlan->lowerdev, dev); 487b863ceb7SPatrick McHardy dev_mc_sync(vlan->lowerdev, dev); 488b863ceb7SPatrick McHardy } 489b863ceb7SPatrick McHardy 490b863ceb7SPatrick McHardy static int macvlan_change_mtu(struct net_device *dev, int new_mtu) 491b863ceb7SPatrick McHardy { 492b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 493b863ceb7SPatrick McHardy 494b863ceb7SPatrick McHardy if (new_mtu < 68 || vlan->lowerdev->mtu < new_mtu) 495b863ceb7SPatrick McHardy return -EINVAL; 496b863ceb7SPatrick McHardy dev->mtu = new_mtu; 497b863ceb7SPatrick McHardy return 0; 498b863ceb7SPatrick McHardy } 499b863ceb7SPatrick McHardy 500b863ceb7SPatrick McHardy /* 501b863ceb7SPatrick McHardy * macvlan network devices have devices nesting below it and are a special 502b863ceb7SPatrick McHardy * "super class" of normal network devices; split their locks off into a 503b863ceb7SPatrick McHardy * separate class since they always nest. 504b863ceb7SPatrick McHardy */ 505b863ceb7SPatrick McHardy static struct lock_class_key macvlan_netdev_xmit_lock_key; 506cf508b12SDavid S. Miller static struct lock_class_key macvlan_netdev_addr_lock_key; 507b863ceb7SPatrick McHardy 508b863ceb7SPatrick McHardy #define MACVLAN_FEATURES \ 509b863ceb7SPatrick McHardy (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \ 510b863ceb7SPatrick McHardy NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \ 5118d13e670SJohn Fastabend NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_GRO | NETIF_F_RXCSUM | \ 51228d2b136SPatrick McHardy NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER) 513b863ceb7SPatrick McHardy 514b863ceb7SPatrick McHardy #define MACVLAN_STATE_MASK \ 515b863ceb7SPatrick McHardy ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT)) 516b863ceb7SPatrick McHardy 517e8a0464cSDavid S. Miller static void macvlan_set_lockdep_class_one(struct net_device *dev, 518e8a0464cSDavid S. Miller struct netdev_queue *txq, 519e8a0464cSDavid S. Miller void *_unused) 520c773e847SDavid S. Miller { 521c773e847SDavid S. Miller lockdep_set_class(&txq->_xmit_lock, 522c773e847SDavid S. Miller &macvlan_netdev_xmit_lock_key); 523c773e847SDavid S. Miller } 524c773e847SDavid S. Miller 525c773e847SDavid S. Miller static void macvlan_set_lockdep_class(struct net_device *dev) 526c773e847SDavid S. Miller { 527cf508b12SDavid S. Miller lockdep_set_class(&dev->addr_list_lock, 528cf508b12SDavid S. Miller &macvlan_netdev_addr_lock_key); 529e8a0464cSDavid S. Miller netdev_for_each_tx_queue(dev, macvlan_set_lockdep_class_one, NULL); 530c773e847SDavid S. Miller } 531c773e847SDavid S. Miller 532b863ceb7SPatrick McHardy static int macvlan_init(struct net_device *dev) 533b863ceb7SPatrick McHardy { 534b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 535b863ceb7SPatrick McHardy const struct net_device *lowerdev = vlan->lowerdev; 536827da44cSJohn Stultz int i; 537b863ceb7SPatrick McHardy 538b863ceb7SPatrick McHardy dev->state = (dev->state & ~MACVLAN_STATE_MASK) | 539b863ceb7SPatrick McHardy (lowerdev->state & MACVLAN_STATE_MASK); 540b863ceb7SPatrick McHardy dev->features = lowerdev->features & MACVLAN_FEATURES; 5418ffab51bSEric Dumazet dev->features |= NETIF_F_LLTX; 5428c2acc53SPatrick McHardy dev->gso_max_size = lowerdev->gso_max_size; 543b863ceb7SPatrick McHardy dev->iflink = lowerdev->ifindex; 544ef5c8996Ssg.tweak@gmail.com dev->hard_header_len = lowerdev->hard_header_len; 545b863ceb7SPatrick McHardy 546c773e847SDavid S. Miller macvlan_set_lockdep_class(dev); 547c773e847SDavid S. Miller 5488ffab51bSEric Dumazet vlan->pcpu_stats = alloc_percpu(struct macvlan_pcpu_stats); 5498ffab51bSEric Dumazet if (!vlan->pcpu_stats) 550fccaf710SEric Dumazet return -ENOMEM; 551fccaf710SEric Dumazet 552827da44cSJohn Stultz for_each_possible_cpu(i) { 553827da44cSJohn Stultz struct macvlan_pcpu_stats *mvlstats; 554827da44cSJohn Stultz mvlstats = per_cpu_ptr(vlan->pcpu_stats, i); 555827da44cSJohn Stultz u64_stats_init(&mvlstats->syncp); 556827da44cSJohn Stultz } 557827da44cSJohn Stultz 558b863ceb7SPatrick McHardy return 0; 559b863ceb7SPatrick McHardy } 560b863ceb7SPatrick McHardy 561fccaf710SEric Dumazet static void macvlan_uninit(struct net_device *dev) 562fccaf710SEric Dumazet { 563fccaf710SEric Dumazet struct macvlan_dev *vlan = netdev_priv(dev); 564d5cd9244SEric W. Biederman struct macvlan_port *port = vlan->port; 565fccaf710SEric Dumazet 5668ffab51bSEric Dumazet free_percpu(vlan->pcpu_stats); 567d5cd9244SEric W. Biederman 568d5cd9244SEric W. Biederman port->count -= 1; 569d5cd9244SEric W. Biederman if (!port->count) 570d5cd9244SEric W. Biederman macvlan_port_destroy(port->dev); 571fccaf710SEric Dumazet } 572fccaf710SEric Dumazet 57328172739SEric Dumazet static struct rtnl_link_stats64 *macvlan_dev_get_stats64(struct net_device *dev, 57428172739SEric Dumazet struct rtnl_link_stats64 *stats) 575fccaf710SEric Dumazet { 576fccaf710SEric Dumazet struct macvlan_dev *vlan = netdev_priv(dev); 577fccaf710SEric Dumazet 5788ffab51bSEric Dumazet if (vlan->pcpu_stats) { 5798ffab51bSEric Dumazet struct macvlan_pcpu_stats *p; 5808ffab51bSEric Dumazet u64 rx_packets, rx_bytes, rx_multicast, tx_packets, tx_bytes; 5818ffab51bSEric Dumazet u32 rx_errors = 0, tx_dropped = 0; 582bc66154eSEric Dumazet unsigned int start; 583fccaf710SEric Dumazet int i; 584fccaf710SEric Dumazet 585fccaf710SEric Dumazet for_each_possible_cpu(i) { 5868ffab51bSEric Dumazet p = per_cpu_ptr(vlan->pcpu_stats, i); 587bc66154eSEric Dumazet do { 588bc66154eSEric Dumazet start = u64_stats_fetch_begin_bh(&p->syncp); 589bc66154eSEric Dumazet rx_packets = p->rx_packets; 590bc66154eSEric Dumazet rx_bytes = p->rx_bytes; 591bc66154eSEric Dumazet rx_multicast = p->rx_multicast; 5928ffab51bSEric Dumazet tx_packets = p->tx_packets; 5938ffab51bSEric Dumazet tx_bytes = p->tx_bytes; 594bc66154eSEric Dumazet } while (u64_stats_fetch_retry_bh(&p->syncp, start)); 5958ffab51bSEric Dumazet 5968ffab51bSEric Dumazet stats->rx_packets += rx_packets; 5978ffab51bSEric Dumazet stats->rx_bytes += rx_bytes; 5988ffab51bSEric Dumazet stats->multicast += rx_multicast; 5998ffab51bSEric Dumazet stats->tx_packets += tx_packets; 6008ffab51bSEric Dumazet stats->tx_bytes += tx_bytes; 6018ffab51bSEric Dumazet /* rx_errors & tx_dropped are u32, updated 6028ffab51bSEric Dumazet * without syncp protection. 6038ffab51bSEric Dumazet */ 6048ffab51bSEric Dumazet rx_errors += p->rx_errors; 6058ffab51bSEric Dumazet tx_dropped += p->tx_dropped; 606fccaf710SEric Dumazet } 6078ffab51bSEric Dumazet stats->rx_errors = rx_errors; 6088ffab51bSEric Dumazet stats->rx_dropped = rx_errors; 6098ffab51bSEric Dumazet stats->tx_dropped = tx_dropped; 610fccaf710SEric Dumazet } 611fccaf710SEric Dumazet return stats; 612fccaf710SEric Dumazet } 613fccaf710SEric Dumazet 6148e586137SJiri Pirko static int macvlan_vlan_rx_add_vid(struct net_device *dev, 61580d5c368SPatrick McHardy __be16 proto, u16 vid) 6168d13e670SJohn Fastabend { 6178d13e670SJohn Fastabend struct macvlan_dev *vlan = netdev_priv(dev); 6188d13e670SJohn Fastabend struct net_device *lowerdev = vlan->lowerdev; 6198d13e670SJohn Fastabend 62080d5c368SPatrick McHardy return vlan_vid_add(lowerdev, proto, vid); 6218d13e670SJohn Fastabend } 6228d13e670SJohn Fastabend 6238e586137SJiri Pirko static int macvlan_vlan_rx_kill_vid(struct net_device *dev, 62480d5c368SPatrick McHardy __be16 proto, u16 vid) 6258d13e670SJohn Fastabend { 6268d13e670SJohn Fastabend struct macvlan_dev *vlan = netdev_priv(dev); 6278d13e670SJohn Fastabend struct net_device *lowerdev = vlan->lowerdev; 6288d13e670SJohn Fastabend 62980d5c368SPatrick McHardy vlan_vid_del(lowerdev, proto, vid); 6308e586137SJiri Pirko return 0; 6318d13e670SJohn Fastabend } 6328d13e670SJohn Fastabend 633edc7d573Sstephen hemminger static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], 634df8ef8f3SJohn Fastabend struct net_device *dev, 6356b6e2725Sstephen hemminger const unsigned char *addr, 636df8ef8f3SJohn Fastabend u16 flags) 637df8ef8f3SJohn Fastabend { 638df8ef8f3SJohn Fastabend struct macvlan_dev *vlan = netdev_priv(dev); 639df8ef8f3SJohn Fastabend int err = -EINVAL; 640df8ef8f3SJohn Fastabend 641df8ef8f3SJohn Fastabend if (!vlan->port->passthru) 642df8ef8f3SJohn Fastabend return -EOPNOTSUPP; 643df8ef8f3SJohn Fastabend 644ab2cfbb2SThomas Richter if (flags & NLM_F_REPLACE) 645ab2cfbb2SThomas Richter return -EOPNOTSUPP; 646ab2cfbb2SThomas Richter 647df8ef8f3SJohn Fastabend if (is_unicast_ether_addr(addr)) 648df8ef8f3SJohn Fastabend err = dev_uc_add_excl(dev, addr); 649df8ef8f3SJohn Fastabend else if (is_multicast_ether_addr(addr)) 650df8ef8f3SJohn Fastabend err = dev_mc_add_excl(dev, addr); 651df8ef8f3SJohn Fastabend 652df8ef8f3SJohn Fastabend return err; 653df8ef8f3SJohn Fastabend } 654df8ef8f3SJohn Fastabend 6551690be63SVlad Yasevich static int macvlan_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], 656df8ef8f3SJohn Fastabend struct net_device *dev, 6576b6e2725Sstephen hemminger const unsigned char *addr) 658df8ef8f3SJohn Fastabend { 659df8ef8f3SJohn Fastabend struct macvlan_dev *vlan = netdev_priv(dev); 660df8ef8f3SJohn Fastabend int err = -EINVAL; 661df8ef8f3SJohn Fastabend 662df8ef8f3SJohn Fastabend if (!vlan->port->passthru) 663df8ef8f3SJohn Fastabend return -EOPNOTSUPP; 664df8ef8f3SJohn Fastabend 665df8ef8f3SJohn Fastabend if (is_unicast_ether_addr(addr)) 666df8ef8f3SJohn Fastabend err = dev_uc_del(dev, addr); 667df8ef8f3SJohn Fastabend else if (is_multicast_ether_addr(addr)) 668df8ef8f3SJohn Fastabend err = dev_mc_del(dev, addr); 669df8ef8f3SJohn Fastabend 670df8ef8f3SJohn Fastabend return err; 671df8ef8f3SJohn Fastabend } 672df8ef8f3SJohn Fastabend 673b863ceb7SPatrick McHardy static void macvlan_ethtool_get_drvinfo(struct net_device *dev, 674b863ceb7SPatrick McHardy struct ethtool_drvinfo *drvinfo) 675b863ceb7SPatrick McHardy { 6767826d43fSJiri Pirko strlcpy(drvinfo->driver, "macvlan", sizeof(drvinfo->driver)); 6777826d43fSJiri Pirko strlcpy(drvinfo->version, "0.1", sizeof(drvinfo->version)); 678b863ceb7SPatrick McHardy } 679b863ceb7SPatrick McHardy 6809edb8bb6SStephen Hemminger static int macvlan_ethtool_get_settings(struct net_device *dev, 6819edb8bb6SStephen Hemminger struct ethtool_cmd *cmd) 6829edb8bb6SStephen Hemminger { 6839edb8bb6SStephen Hemminger const struct macvlan_dev *vlan = netdev_priv(dev); 6844bc71cb9SJiri Pirko 6854bc71cb9SJiri Pirko return __ethtool_get_settings(vlan->lowerdev, cmd); 6869edb8bb6SStephen Hemminger } 6879edb8bb6SStephen Hemminger 6882be5c767SVlad Yasevich static netdev_features_t macvlan_fix_features(struct net_device *dev, 6892be5c767SVlad Yasevich netdev_features_t features) 6902be5c767SVlad Yasevich { 6912be5c767SVlad Yasevich struct macvlan_dev *vlan = netdev_priv(dev); 6922be5c767SVlad Yasevich 6932be5c767SVlad Yasevich return features & (vlan->set_features | ~MACVLAN_FEATURES); 6942be5c767SVlad Yasevich } 6952be5c767SVlad Yasevich 696b863ceb7SPatrick McHardy static const struct ethtool_ops macvlan_ethtool_ops = { 697b863ceb7SPatrick McHardy .get_link = ethtool_op_get_link, 6989edb8bb6SStephen Hemminger .get_settings = macvlan_ethtool_get_settings, 699b863ceb7SPatrick McHardy .get_drvinfo = macvlan_ethtool_get_drvinfo, 700b863ceb7SPatrick McHardy }; 701b863ceb7SPatrick McHardy 70254a30c97SStephen Hemminger static const struct net_device_ops macvlan_netdev_ops = { 70354a30c97SStephen Hemminger .ndo_init = macvlan_init, 704fccaf710SEric Dumazet .ndo_uninit = macvlan_uninit, 70554a30c97SStephen Hemminger .ndo_open = macvlan_open, 70654a30c97SStephen Hemminger .ndo_stop = macvlan_stop, 70700829823SStephen Hemminger .ndo_start_xmit = macvlan_start_xmit, 70854a30c97SStephen Hemminger .ndo_change_mtu = macvlan_change_mtu, 7092be5c767SVlad Yasevich .ndo_fix_features = macvlan_fix_features, 71054a30c97SStephen Hemminger .ndo_change_rx_flags = macvlan_change_rx_flags, 71154a30c97SStephen Hemminger .ndo_set_mac_address = macvlan_set_mac_address, 712df8ef8f3SJohn Fastabend .ndo_set_rx_mode = macvlan_set_mac_lists, 713bc66154eSEric Dumazet .ndo_get_stats64 = macvlan_dev_get_stats64, 71454a30c97SStephen Hemminger .ndo_validate_addr = eth_validate_addr, 7158d13e670SJohn Fastabend .ndo_vlan_rx_add_vid = macvlan_vlan_rx_add_vid, 7168d13e670SJohn Fastabend .ndo_vlan_rx_kill_vid = macvlan_vlan_rx_kill_vid, 717df8ef8f3SJohn Fastabend .ndo_fdb_add = macvlan_fdb_add, 718df8ef8f3SJohn Fastabend .ndo_fdb_del = macvlan_fdb_del, 719df8ef8f3SJohn Fastabend .ndo_fdb_dump = ndo_dflt_fdb_dump, 72054a30c97SStephen Hemminger }; 72154a30c97SStephen Hemminger 7228a35747aSHerbert Xu void macvlan_common_setup(struct net_device *dev) 723b863ceb7SPatrick McHardy { 724b863ceb7SPatrick McHardy ether_setup(dev); 725b863ceb7SPatrick McHardy 726550fd08cSNeil Horman dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING); 72787ab7f6fSVlad Yasevich dev->priv_flags |= IFF_UNICAST_FLT; 72854a30c97SStephen Hemminger dev->netdev_ops = &macvlan_netdev_ops; 729b863ceb7SPatrick McHardy dev->destructor = free_netdev; 73071740129SLutz Jaenicke dev->header_ops = &macvlan_hard_header_ops; 731b863ceb7SPatrick McHardy dev->ethtool_ops = &macvlan_ethtool_ops; 7328a35747aSHerbert Xu } 7338a35747aSHerbert Xu EXPORT_SYMBOL_GPL(macvlan_common_setup); 7348a35747aSHerbert Xu 7358a35747aSHerbert Xu static void macvlan_setup(struct net_device *dev) 7368a35747aSHerbert Xu { 7378a35747aSHerbert Xu macvlan_common_setup(dev); 738b863ceb7SPatrick McHardy dev->tx_queue_len = 0; 739b863ceb7SPatrick McHardy } 740b863ceb7SPatrick McHardy 741b863ceb7SPatrick McHardy static int macvlan_port_create(struct net_device *dev) 742b863ceb7SPatrick McHardy { 743b863ceb7SPatrick McHardy struct macvlan_port *port; 744b863ceb7SPatrick McHardy unsigned int i; 745ab95bfe0SJiri Pirko int err; 746b863ceb7SPatrick McHardy 747b863ceb7SPatrick McHardy if (dev->type != ARPHRD_ETHER || dev->flags & IFF_LOOPBACK) 748b863ceb7SPatrick McHardy return -EINVAL; 749b863ceb7SPatrick McHardy 750b863ceb7SPatrick McHardy port = kzalloc(sizeof(*port), GFP_KERNEL); 751b863ceb7SPatrick McHardy if (port == NULL) 752b863ceb7SPatrick McHardy return -ENOMEM; 753b863ceb7SPatrick McHardy 754eb06acdcSSridhar Samudrala port->passthru = false; 755b863ceb7SPatrick McHardy port->dev = dev; 756b863ceb7SPatrick McHardy INIT_LIST_HEAD(&port->vlans); 757b863ceb7SPatrick McHardy for (i = 0; i < MACVLAN_HASH_SIZE; i++) 758b863ceb7SPatrick McHardy INIT_HLIST_HEAD(&port->vlan_hash[i]); 759ab95bfe0SJiri Pirko 760a35e2c1bSJiri Pirko err = netdev_rx_handler_register(dev, macvlan_handle_frame, port); 761a35e2c1bSJiri Pirko if (err) 762ab95bfe0SJiri Pirko kfree(port); 763d9351561SEric Dumazet else 764a35e2c1bSJiri Pirko dev->priv_flags |= IFF_MACVLAN_PORT; 765ab95bfe0SJiri Pirko return err; 766b863ceb7SPatrick McHardy } 767b863ceb7SPatrick McHardy 768b863ceb7SPatrick McHardy static void macvlan_port_destroy(struct net_device *dev) 769b863ceb7SPatrick McHardy { 770e052f7e6SEric Dumazet struct macvlan_port *port = macvlan_port_get_rtnl(dev); 771b863ceb7SPatrick McHardy 772a35e2c1bSJiri Pirko dev->priv_flags &= ~IFF_MACVLAN_PORT; 773ab95bfe0SJiri Pirko netdev_rx_handler_unregister(dev); 7746e070aecSLai Jiangshan kfree_rcu(port, rcu); 775b863ceb7SPatrick McHardy } 776b863ceb7SPatrick McHardy 777b863ceb7SPatrick McHardy static int macvlan_validate(struct nlattr *tb[], struct nlattr *data[]) 778b863ceb7SPatrick McHardy { 779b863ceb7SPatrick McHardy if (tb[IFLA_ADDRESS]) { 780b863ceb7SPatrick McHardy if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) 781b863ceb7SPatrick McHardy return -EINVAL; 782b863ceb7SPatrick McHardy if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) 783b863ceb7SPatrick McHardy return -EADDRNOTAVAIL; 784b863ceb7SPatrick McHardy } 78527c0b1a8SArnd Bergmann 78615127478SMichael S. Tsirkin if (data && data[IFLA_MACVLAN_FLAGS] && 78715127478SMichael S. Tsirkin nla_get_u16(data[IFLA_MACVLAN_FLAGS]) & ~MACVLAN_FLAG_NOPROMISC) 78815127478SMichael S. Tsirkin return -EINVAL; 78915127478SMichael S. Tsirkin 79027c0b1a8SArnd Bergmann if (data && data[IFLA_MACVLAN_MODE]) { 79127c0b1a8SArnd Bergmann switch (nla_get_u32(data[IFLA_MACVLAN_MODE])) { 79227c0b1a8SArnd Bergmann case MACVLAN_MODE_PRIVATE: 79327c0b1a8SArnd Bergmann case MACVLAN_MODE_VEPA: 79427c0b1a8SArnd Bergmann case MACVLAN_MODE_BRIDGE: 795eb06acdcSSridhar Samudrala case MACVLAN_MODE_PASSTHRU: 79627c0b1a8SArnd Bergmann break; 79727c0b1a8SArnd Bergmann default: 79827c0b1a8SArnd Bergmann return -EINVAL; 79927c0b1a8SArnd Bergmann } 80027c0b1a8SArnd Bergmann } 801b863ceb7SPatrick McHardy return 0; 802b863ceb7SPatrick McHardy } 803b863ceb7SPatrick McHardy 804fc0663d6SArnd Bergmann int macvlan_common_newlink(struct net *src_net, struct net_device *dev, 8052f6a1b66SVlad Yasevich struct nlattr *tb[], struct nlattr *data[]) 806b863ceb7SPatrick McHardy { 807b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 808b863ceb7SPatrick McHardy struct macvlan_port *port; 809b863ceb7SPatrick McHardy struct net_device *lowerdev; 810b863ceb7SPatrick McHardy int err; 811b863ceb7SPatrick McHardy 812b863ceb7SPatrick McHardy if (!tb[IFLA_LINK]) 813b863ceb7SPatrick McHardy return -EINVAL; 814b863ceb7SPatrick McHardy 81581adee47SEric W. Biederman lowerdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); 816b863ceb7SPatrick McHardy if (lowerdev == NULL) 817b863ceb7SPatrick McHardy return -ENODEV; 818b863ceb7SPatrick McHardy 819d70f2cf5SKevin Wallace /* When creating macvlans or macvtaps on top of other macvlans - use 820b0832a29SEric Biederman * the real device as the lowerdev. 821a6ca5f1dSPatrick McHardy */ 822d70f2cf5SKevin Wallace if (netif_is_macvlan(lowerdev)) 823d70f2cf5SKevin Wallace lowerdev = macvlan_dev_real_dev(lowerdev); 824a6ca5f1dSPatrick McHardy 825b863ceb7SPatrick McHardy if (!tb[IFLA_MTU]) 826b863ceb7SPatrick McHardy dev->mtu = lowerdev->mtu; 827b863ceb7SPatrick McHardy else if (dev->mtu > lowerdev->mtu) 828b863ceb7SPatrick McHardy return -EINVAL; 829b863ceb7SPatrick McHardy 830b863ceb7SPatrick McHardy if (!tb[IFLA_ADDRESS]) 8317ce5d222SDanny Kukawka eth_hw_addr_random(dev); 832b863ceb7SPatrick McHardy 833a35e2c1bSJiri Pirko if (!macvlan_port_exists(lowerdev)) { 834b863ceb7SPatrick McHardy err = macvlan_port_create(lowerdev); 835b863ceb7SPatrick McHardy if (err < 0) 836b863ceb7SPatrick McHardy return err; 837b863ceb7SPatrick McHardy } 838e052f7e6SEric Dumazet port = macvlan_port_get_rtnl(lowerdev); 839b863ceb7SPatrick McHardy 840eb06acdcSSridhar Samudrala /* Only 1 macvlan device can be created in passthru mode */ 841eb06acdcSSridhar Samudrala if (port->passthru) 842eb06acdcSSridhar Samudrala return -EINVAL; 843eb06acdcSSridhar Samudrala 844b863ceb7SPatrick McHardy vlan->lowerdev = lowerdev; 845b863ceb7SPatrick McHardy vlan->dev = dev; 846b863ceb7SPatrick McHardy vlan->port = port; 8472be5c767SVlad Yasevich vlan->set_features = MACVLAN_FEATURES; 848b863ceb7SPatrick McHardy 84927c0b1a8SArnd Bergmann vlan->mode = MACVLAN_MODE_VEPA; 85027c0b1a8SArnd Bergmann if (data && data[IFLA_MACVLAN_MODE]) 85127c0b1a8SArnd Bergmann vlan->mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); 85227c0b1a8SArnd Bergmann 853df8ef8f3SJohn Fastabend if (data && data[IFLA_MACVLAN_FLAGS]) 854df8ef8f3SJohn Fastabend vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); 855df8ef8f3SJohn Fastabend 856eb06acdcSSridhar Samudrala if (vlan->mode == MACVLAN_MODE_PASSTHRU) { 857d5cd9244SEric W. Biederman if (port->count) 858eb06acdcSSridhar Samudrala return -EINVAL; 859eb06acdcSSridhar Samudrala port->passthru = true; 8608b98604eSBjørn Mork eth_hw_addr_inherit(dev, lowerdev); 861eb06acdcSSridhar Samudrala } 862eb06acdcSSridhar Samudrala 86347d4ab91SJohn Fastabend port->count += 1; 86447d4ab91SJohn Fastabend err = register_netdevice(dev); 86547d4ab91SJohn Fastabend if (err < 0) 86647d4ab91SJohn Fastabend goto destroy_port; 86747d4ab91SJohn Fastabend 868a6cc0cfaSJohn Fastabend dev->priv_flags |= IFF_MACVLAN; 8697cd43db7SJiri Pirko err = netdev_upper_dev_link(lowerdev, dev); 8707cd43db7SJiri Pirko if (err) 8717cd43db7SJiri Pirko goto destroy_port; 8727cd43db7SJiri Pirko 873b863ceb7SPatrick McHardy 874233c7df0SJiri Pirko list_add_tail_rcu(&vlan->list, &port->vlans); 875fc4a7489SPatrick Mullaney netif_stacked_transfer_operstate(lowerdev, dev); 876f16d3d57SJiri Pirko 877b863ceb7SPatrick McHardy return 0; 878f16d3d57SJiri Pirko 879f16d3d57SJiri Pirko destroy_port: 880d5cd9244SEric W. Biederman port->count -= 1; 881d5cd9244SEric W. Biederman if (!port->count) 882f16d3d57SJiri Pirko macvlan_port_destroy(lowerdev); 883f16d3d57SJiri Pirko 884f16d3d57SJiri Pirko return err; 885b863ceb7SPatrick McHardy } 886fc0663d6SArnd Bergmann EXPORT_SYMBOL_GPL(macvlan_common_newlink); 887b863ceb7SPatrick McHardy 888fc0663d6SArnd Bergmann static int macvlan_newlink(struct net *src_net, struct net_device *dev, 889fc0663d6SArnd Bergmann struct nlattr *tb[], struct nlattr *data[]) 890fc0663d6SArnd Bergmann { 8912f6a1b66SVlad Yasevich return macvlan_common_newlink(src_net, dev, tb, data); 892fc0663d6SArnd Bergmann } 893fc0663d6SArnd Bergmann 894fc0663d6SArnd Bergmann void macvlan_dellink(struct net_device *dev, struct list_head *head) 895b863ceb7SPatrick McHardy { 896b863ceb7SPatrick McHardy struct macvlan_dev *vlan = netdev_priv(dev); 897b863ceb7SPatrick McHardy 898233c7df0SJiri Pirko list_del_rcu(&vlan->list); 89923289a37SEric Dumazet unregister_netdevice_queue(dev, head); 9007cd43db7SJiri Pirko netdev_upper_dev_unlink(vlan->lowerdev, dev); 901b863ceb7SPatrick McHardy } 902fc0663d6SArnd Bergmann EXPORT_SYMBOL_GPL(macvlan_dellink); 903b863ceb7SPatrick McHardy 90427c0b1a8SArnd Bergmann static int macvlan_changelink(struct net_device *dev, 90527c0b1a8SArnd Bergmann struct nlattr *tb[], struct nlattr *data[]) 90627c0b1a8SArnd Bergmann { 90727c0b1a8SArnd Bergmann struct macvlan_dev *vlan = netdev_priv(dev); 908266e8347SMichael S. Tsirkin enum macvlan_mode mode; 909266e8347SMichael S. Tsirkin bool set_mode = false; 910266e8347SMichael S. Tsirkin 911266e8347SMichael S. Tsirkin /* Validate mode, but don't set yet: setting flags may fail. */ 912266e8347SMichael S. Tsirkin if (data && data[IFLA_MACVLAN_MODE]) { 913266e8347SMichael S. Tsirkin set_mode = true; 914266e8347SMichael S. Tsirkin mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); 915266e8347SMichael S. Tsirkin /* Passthrough mode can't be set or cleared dynamically */ 916266e8347SMichael S. Tsirkin if ((mode == MACVLAN_MODE_PASSTHRU) != 917266e8347SMichael S. Tsirkin (vlan->mode == MACVLAN_MODE_PASSTHRU)) 918266e8347SMichael S. Tsirkin return -EINVAL; 919266e8347SMichael S. Tsirkin } 92099ffc3e7SMichael S. Tsirkin 921df8ef8f3SJohn Fastabend if (data && data[IFLA_MACVLAN_FLAGS]) { 922df8ef8f3SJohn Fastabend __u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); 923df8ef8f3SJohn Fastabend bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC; 92499ffc3e7SMichael S. Tsirkin if (vlan->port->passthru && promisc) { 92599ffc3e7SMichael S. Tsirkin int err; 926df8ef8f3SJohn Fastabend 92799ffc3e7SMichael S. Tsirkin if (flags & MACVLAN_FLAG_NOPROMISC) 92899ffc3e7SMichael S. Tsirkin err = dev_set_promiscuity(vlan->lowerdev, -1); 92999ffc3e7SMichael S. Tsirkin else 93099ffc3e7SMichael S. Tsirkin err = dev_set_promiscuity(vlan->lowerdev, 1); 93199ffc3e7SMichael S. Tsirkin if (err < 0) 93299ffc3e7SMichael S. Tsirkin return err; 93399ffc3e7SMichael S. Tsirkin } 934df8ef8f3SJohn Fastabend vlan->flags = flags; 935df8ef8f3SJohn Fastabend } 936266e8347SMichael S. Tsirkin if (set_mode) 937266e8347SMichael S. Tsirkin vlan->mode = mode; 93827c0b1a8SArnd Bergmann return 0; 93927c0b1a8SArnd Bergmann } 94027c0b1a8SArnd Bergmann 94127c0b1a8SArnd Bergmann static size_t macvlan_get_size(const struct net_device *dev) 94227c0b1a8SArnd Bergmann { 94301fe944fSEric Dumazet return (0 94401fe944fSEric Dumazet + nla_total_size(4) /* IFLA_MACVLAN_MODE */ 94501fe944fSEric Dumazet + nla_total_size(2) /* IFLA_MACVLAN_FLAGS */ 94601fe944fSEric Dumazet ); 94727c0b1a8SArnd Bergmann } 94827c0b1a8SArnd Bergmann 94927c0b1a8SArnd Bergmann static int macvlan_fill_info(struct sk_buff *skb, 95027c0b1a8SArnd Bergmann const struct net_device *dev) 95127c0b1a8SArnd Bergmann { 95227c0b1a8SArnd Bergmann struct macvlan_dev *vlan = netdev_priv(dev); 95327c0b1a8SArnd Bergmann 954ead9a76cSDavid S. Miller if (nla_put_u32(skb, IFLA_MACVLAN_MODE, vlan->mode)) 955ead9a76cSDavid S. Miller goto nla_put_failure; 956df8ef8f3SJohn Fastabend if (nla_put_u16(skb, IFLA_MACVLAN_FLAGS, vlan->flags)) 957df8ef8f3SJohn Fastabend goto nla_put_failure; 95827c0b1a8SArnd Bergmann return 0; 95927c0b1a8SArnd Bergmann 96027c0b1a8SArnd Bergmann nla_put_failure: 96127c0b1a8SArnd Bergmann return -EMSGSIZE; 96227c0b1a8SArnd Bergmann } 96327c0b1a8SArnd Bergmann 96427c0b1a8SArnd Bergmann static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = { 96527c0b1a8SArnd Bergmann [IFLA_MACVLAN_MODE] = { .type = NLA_U32 }, 966df8ef8f3SJohn Fastabend [IFLA_MACVLAN_FLAGS] = { .type = NLA_U16 }, 96727c0b1a8SArnd Bergmann }; 96827c0b1a8SArnd Bergmann 969fc0663d6SArnd Bergmann int macvlan_link_register(struct rtnl_link_ops *ops) 970fc0663d6SArnd Bergmann { 971fc0663d6SArnd Bergmann /* common fields */ 972fc0663d6SArnd Bergmann ops->priv_size = sizeof(struct macvlan_dev); 973fc0663d6SArnd Bergmann ops->validate = macvlan_validate; 974fc0663d6SArnd Bergmann ops->maxtype = IFLA_MACVLAN_MAX; 975fc0663d6SArnd Bergmann ops->policy = macvlan_policy; 976fc0663d6SArnd Bergmann ops->changelink = macvlan_changelink; 977fc0663d6SArnd Bergmann ops->get_size = macvlan_get_size; 978fc0663d6SArnd Bergmann ops->fill_info = macvlan_fill_info; 979fc0663d6SArnd Bergmann 980fc0663d6SArnd Bergmann return rtnl_link_register(ops); 981fc0663d6SArnd Bergmann }; 982fc0663d6SArnd Bergmann EXPORT_SYMBOL_GPL(macvlan_link_register); 983fc0663d6SArnd Bergmann 984fc0663d6SArnd Bergmann static struct rtnl_link_ops macvlan_link_ops = { 985b863ceb7SPatrick McHardy .kind = "macvlan", 9868a35747aSHerbert Xu .setup = macvlan_setup, 987b863ceb7SPatrick McHardy .newlink = macvlan_newlink, 988b863ceb7SPatrick McHardy .dellink = macvlan_dellink, 989b863ceb7SPatrick McHardy }; 990b863ceb7SPatrick McHardy 991b863ceb7SPatrick McHardy static int macvlan_device_event(struct notifier_block *unused, 992b863ceb7SPatrick McHardy unsigned long event, void *ptr) 993b863ceb7SPatrick McHardy { 994351638e7SJiri Pirko struct net_device *dev = netdev_notifier_info_to_dev(ptr); 995b863ceb7SPatrick McHardy struct macvlan_dev *vlan, *next; 996b863ceb7SPatrick McHardy struct macvlan_port *port; 997226bd341SEric Dumazet LIST_HEAD(list_kill); 998b863ceb7SPatrick McHardy 999a35e2c1bSJiri Pirko if (!macvlan_port_exists(dev)) 1000b863ceb7SPatrick McHardy return NOTIFY_DONE; 1001b863ceb7SPatrick McHardy 1002e052f7e6SEric Dumazet port = macvlan_port_get_rtnl(dev); 1003a35e2c1bSJiri Pirko 1004b863ceb7SPatrick McHardy switch (event) { 1005b863ceb7SPatrick McHardy case NETDEV_CHANGE: 1006b863ceb7SPatrick McHardy list_for_each_entry(vlan, &port->vlans, list) 1007fc4a7489SPatrick Mullaney netif_stacked_transfer_operstate(vlan->lowerdev, 1008fc4a7489SPatrick Mullaney vlan->dev); 1009b863ceb7SPatrick McHardy break; 1010b863ceb7SPatrick McHardy case NETDEV_FEAT_CHANGE: 1011b863ceb7SPatrick McHardy list_for_each_entry(vlan, &port->vlans, list) { 1012b863ceb7SPatrick McHardy vlan->dev->features = dev->features & MACVLAN_FEATURES; 10138c2acc53SPatrick McHardy vlan->dev->gso_max_size = dev->gso_max_size; 1014b863ceb7SPatrick McHardy netdev_features_change(vlan->dev); 1015b863ceb7SPatrick McHardy } 1016b863ceb7SPatrick McHardy break; 1017b863ceb7SPatrick McHardy case NETDEV_UNREGISTER: 10183b27e105SDavid Lamparter /* twiddle thumbs on netns device moves */ 10193b27e105SDavid Lamparter if (dev->reg_state != NETREG_UNREGISTERING) 10203b27e105SDavid Lamparter break; 10213b27e105SDavid Lamparter 1022b863ceb7SPatrick McHardy list_for_each_entry_safe(vlan, next, &port->vlans, list) 1023226bd341SEric Dumazet vlan->dev->rtnl_link_ops->dellink(vlan->dev, &list_kill); 1024226bd341SEric Dumazet unregister_netdevice_many(&list_kill); 1025226bd341SEric Dumazet list_del(&list_kill); 1026b863ceb7SPatrick McHardy break; 10271c01fe14SJiri Pirko case NETDEV_PRE_TYPE_CHANGE: 10281c01fe14SJiri Pirko /* Forbid underlaying device to change its type. */ 10291c01fe14SJiri Pirko return NOTIFY_BAD; 1030b863ceb7SPatrick McHardy } 1031b863ceb7SPatrick McHardy return NOTIFY_DONE; 1032b863ceb7SPatrick McHardy } 1033b863ceb7SPatrick McHardy 1034b863ceb7SPatrick McHardy static struct notifier_block macvlan_notifier_block __read_mostly = { 1035b863ceb7SPatrick McHardy .notifier_call = macvlan_device_event, 1036b863ceb7SPatrick McHardy }; 1037b863ceb7SPatrick McHardy 1038b863ceb7SPatrick McHardy static int __init macvlan_init_module(void) 1039b863ceb7SPatrick McHardy { 1040b863ceb7SPatrick McHardy int err; 1041b863ceb7SPatrick McHardy 1042b863ceb7SPatrick McHardy register_netdevice_notifier(&macvlan_notifier_block); 1043b863ceb7SPatrick McHardy 1044fc0663d6SArnd Bergmann err = macvlan_link_register(&macvlan_link_ops); 1045b863ceb7SPatrick McHardy if (err < 0) 1046b863ceb7SPatrick McHardy goto err1; 1047b863ceb7SPatrick McHardy return 0; 1048b863ceb7SPatrick McHardy err1: 1049b863ceb7SPatrick McHardy unregister_netdevice_notifier(&macvlan_notifier_block); 1050b863ceb7SPatrick McHardy return err; 1051b863ceb7SPatrick McHardy } 1052b863ceb7SPatrick McHardy 1053b863ceb7SPatrick McHardy static void __exit macvlan_cleanup_module(void) 1054b863ceb7SPatrick McHardy { 1055b863ceb7SPatrick McHardy rtnl_link_unregister(&macvlan_link_ops); 1056b863ceb7SPatrick McHardy unregister_netdevice_notifier(&macvlan_notifier_block); 1057b863ceb7SPatrick McHardy } 1058b863ceb7SPatrick McHardy 1059b863ceb7SPatrick McHardy module_init(macvlan_init_module); 1060b863ceb7SPatrick McHardy module_exit(macvlan_cleanup_module); 1061b863ceb7SPatrick McHardy 1062b863ceb7SPatrick McHardy MODULE_LICENSE("GPL"); 1063b863ceb7SPatrick McHardy MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); 1064b863ceb7SPatrick McHardy MODULE_DESCRIPTION("Driver for MAC address based VLANs"); 1065b863ceb7SPatrick McHardy MODULE_ALIAS_RTNL_LINK("macvlan"); 1066