macvlan.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 2007 Patrick McHardy <kaber@trash.net>
  4. *
  5. * The code this is based on carried the following copyright notice:
  6. * ---
  7. * (C) Copyright 2001-2006
  8. * Alex Zeffertt, Cambridge Broadband Ltd, ajz@cambridgebroadband.com
  9. * Re-worked by Ben Greear <greearb@candelatech.com>
  10. * ---
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/slab.h>
  18. #include <linux/string.h>
  19. #include <linux/rculist.h>
  20. #include <linux/notifier.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/net_tstamp.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/if_arp.h>
  26. #include <linux/if_vlan.h>
  27. #include <linux/if_link.h>
  28. #include <linux/if_macvlan.h>
  29. #include <linux/hash.h>
  30. #include <linux/workqueue.h>
  31. #include <net/rtnetlink.h>
  32. #include <net/xfrm.h>
  33. #include <linux/netpoll.h>
  34. #include <linux/phy.h>
  35. #define MACVLAN_HASH_BITS 8
  36. #define MACVLAN_HASH_SIZE (1<<MACVLAN_HASH_BITS)
  37. #define MACVLAN_BC_QUEUE_LEN 1000
  38. #define MACVLAN_F_PASSTHRU 1
  39. #define MACVLAN_F_ADDRCHANGE 2
  40. struct macvlan_port {
  41. struct net_device *dev;
  42. struct hlist_head vlan_hash[MACVLAN_HASH_SIZE];
  43. struct list_head vlans;
  44. struct sk_buff_head bc_queue;
  45. struct work_struct bc_work;
  46. u32 flags;
  47. int count;
  48. struct hlist_head vlan_source_hash[MACVLAN_HASH_SIZE];
  49. DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
  50. unsigned char perm_addr[ETH_ALEN];
  51. };
  52. struct macvlan_source_entry {
  53. struct hlist_node hlist;
  54. struct macvlan_dev *vlan;
  55. unsigned char addr[6+2] __aligned(sizeof(u16));
  56. struct rcu_head rcu;
  57. };
  58. struct macvlan_skb_cb {
  59. const struct macvlan_dev *src;
  60. };
  61. #define MACVLAN_SKB_CB(__skb) ((struct macvlan_skb_cb *)&((__skb)->cb[0]))
  62. static void macvlan_port_destroy(struct net_device *dev);
  63. static inline bool macvlan_passthru(const struct macvlan_port *port)
  64. {
  65. return port->flags & MACVLAN_F_PASSTHRU;
  66. }
  67. static inline void macvlan_set_passthru(struct macvlan_port *port)
  68. {
  69. port->flags |= MACVLAN_F_PASSTHRU;
  70. }
  71. static inline bool macvlan_addr_change(const struct macvlan_port *port)
  72. {
  73. return port->flags & MACVLAN_F_ADDRCHANGE;
  74. }
  75. static inline void macvlan_set_addr_change(struct macvlan_port *port)
  76. {
  77. port->flags |= MACVLAN_F_ADDRCHANGE;
  78. }
  79. static inline void macvlan_clear_addr_change(struct macvlan_port *port)
  80. {
  81. port->flags &= ~MACVLAN_F_ADDRCHANGE;
  82. }
  83. /* Hash Ethernet address */
  84. static u32 macvlan_eth_hash(const unsigned char *addr)
  85. {
  86. u64 value = get_unaligned((u64 *)addr);
  87. /* only want 6 bytes */
  88. #ifdef __BIG_ENDIAN
  89. value >>= 16;
  90. #else
  91. value <<= 16;
  92. #endif
  93. return hash_64(value, MACVLAN_HASH_BITS);
  94. }
  95. static struct macvlan_port *macvlan_port_get_rcu(const struct net_device *dev)
  96. {
  97. return rcu_dereference(dev->rx_handler_data);
  98. }
  99. static struct macvlan_port *macvlan_port_get_rtnl(const struct net_device *dev)
  100. {
  101. return rtnl_dereference(dev->rx_handler_data);
  102. }
  103. static struct macvlan_dev *macvlan_hash_lookup(const struct macvlan_port *port,
  104. const unsigned char *addr)
  105. {
  106. struct macvlan_dev *vlan;
  107. u32 idx = macvlan_eth_hash(addr);
  108. hlist_for_each_entry_rcu(vlan, &port->vlan_hash[idx], hlist) {
  109. if (ether_addr_equal_64bits(vlan->dev->dev_addr, addr))
  110. return vlan;
  111. }
  112. return NULL;
  113. }
  114. static struct macvlan_source_entry *macvlan_hash_lookup_source(
  115. const struct macvlan_dev *vlan,
  116. const unsigned char *addr)
  117. {
  118. struct macvlan_source_entry *entry;
  119. u32 idx = macvlan_eth_hash(addr);
  120. struct hlist_head *h = &vlan->port->vlan_source_hash[idx];
  121. hlist_for_each_entry_rcu(entry, h, hlist) {
  122. if (ether_addr_equal_64bits(entry->addr, addr) &&
  123. entry->vlan == vlan)
  124. return entry;
  125. }
  126. return NULL;
  127. }
  128. static int macvlan_hash_add_source(struct macvlan_dev *vlan,
  129. const unsigned char *addr)
  130. {
  131. struct macvlan_port *port = vlan->port;
  132. struct macvlan_source_entry *entry;
  133. struct hlist_head *h;
  134. entry = macvlan_hash_lookup_source(vlan, addr);
  135. if (entry)
  136. return 0;
  137. entry = kmalloc(sizeof(*entry), GFP_KERNEL);
  138. if (!entry)
  139. return -ENOMEM;
  140. ether_addr_copy(entry->addr, addr);
  141. entry->vlan = vlan;
  142. h = &port->vlan_source_hash[macvlan_eth_hash(addr)];
  143. hlist_add_head_rcu(&entry->hlist, h);
  144. vlan->macaddr_count++;
  145. return 0;
  146. }
  147. static void macvlan_hash_add(struct macvlan_dev *vlan)
  148. {
  149. struct macvlan_port *port = vlan->port;
  150. const unsigned char *addr = vlan->dev->dev_addr;
  151. u32 idx = macvlan_eth_hash(addr);
  152. hlist_add_head_rcu(&vlan->hlist, &port->vlan_hash[idx]);
  153. }
  154. static void macvlan_hash_del_source(struct macvlan_source_entry *entry)
  155. {
  156. hlist_del_rcu(&entry->hlist);
  157. kfree_rcu(entry, rcu);
  158. }
  159. static void macvlan_hash_del(struct macvlan_dev *vlan, bool sync)
  160. {
  161. hlist_del_rcu(&vlan->hlist);
  162. if (sync)
  163. synchronize_rcu();
  164. }
  165. static void macvlan_hash_change_addr(struct macvlan_dev *vlan,
  166. const unsigned char *addr)
  167. {
  168. macvlan_hash_del(vlan, true);
  169. /* Now that we are unhashed it is safe to change the device
  170. * address without confusing packet delivery.
  171. */
  172. memcpy(vlan->dev->dev_addr, addr, ETH_ALEN);
  173. macvlan_hash_add(vlan);
  174. }
  175. static bool macvlan_addr_busy(const struct macvlan_port *port,
  176. const unsigned char *addr)
  177. {
  178. /* Test to see if the specified address is
  179. * currently in use by the underlying device or
  180. * another macvlan.
  181. */
  182. if (!macvlan_passthru(port) && !macvlan_addr_change(port) &&
  183. ether_addr_equal_64bits(port->dev->dev_addr, addr))
  184. return true;
  185. if (macvlan_hash_lookup(port, addr))
  186. return true;
  187. return false;
  188. }
  189. static int macvlan_broadcast_one(struct sk_buff *skb,
  190. const struct macvlan_dev *vlan,
  191. const struct ethhdr *eth, bool local)
  192. {
  193. struct net_device *dev = vlan->dev;
  194. if (local)
  195. return __dev_forward_skb(dev, skb);
  196. skb->dev = dev;
  197. if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
  198. skb->pkt_type = PACKET_BROADCAST;
  199. else
  200. skb->pkt_type = PACKET_MULTICAST;
  201. return 0;
  202. }
  203. static u32 macvlan_hash_mix(const struct macvlan_dev *vlan)
  204. {
  205. return (u32)(((unsigned long)vlan) >> L1_CACHE_SHIFT);
  206. }
  207. static unsigned int mc_hash(const struct macvlan_dev *vlan,
  208. const unsigned char *addr)
  209. {
  210. u32 val = __get_unaligned_cpu32(addr + 2);
  211. val ^= macvlan_hash_mix(vlan);
  212. return hash_32(val, MACVLAN_MC_FILTER_BITS);
  213. }
  214. static void macvlan_broadcast(struct sk_buff *skb,
  215. const struct macvlan_port *port,
  216. struct net_device *src,
  217. enum macvlan_mode mode)
  218. {
  219. const struct ethhdr *eth = eth_hdr(skb);
  220. const struct macvlan_dev *vlan;
  221. struct sk_buff *nskb;
  222. unsigned int i;
  223. int err;
  224. unsigned int hash;
  225. if (skb->protocol == htons(ETH_P_PAUSE))
  226. return;
  227. for (i = 0; i < MACVLAN_HASH_SIZE; i++) {
  228. hlist_for_each_entry_rcu(vlan, &port->vlan_hash[i], hlist) {
  229. if (vlan->dev == src || !(vlan->mode & mode))
  230. continue;
  231. hash = mc_hash(vlan, eth->h_dest);
  232. if (!test_bit(hash, vlan->mc_filter))
  233. continue;
  234. err = NET_RX_DROP;
  235. nskb = skb_clone(skb, GFP_ATOMIC);
  236. if (likely(nskb))
  237. err = macvlan_broadcast_one(
  238. nskb, vlan, eth,
  239. mode == MACVLAN_MODE_BRIDGE) ?:
  240. netif_rx_ni(nskb);
  241. macvlan_count_rx(vlan, skb->len + ETH_HLEN,
  242. err == NET_RX_SUCCESS, true);
  243. }
  244. }
  245. }
  246. static void macvlan_process_broadcast(struct work_struct *w)
  247. {
  248. struct macvlan_port *port = container_of(w, struct macvlan_port,
  249. bc_work);
  250. struct sk_buff *skb;
  251. struct sk_buff_head list;
  252. __skb_queue_head_init(&list);
  253. spin_lock_bh(&port->bc_queue.lock);
  254. skb_queue_splice_tail_init(&port->bc_queue, &list);
  255. spin_unlock_bh(&port->bc_queue.lock);
  256. while ((skb = __skb_dequeue(&list))) {
  257. const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src;
  258. rcu_read_lock();
  259. if (!src)
  260. /* frame comes from an external address */
  261. macvlan_broadcast(skb, port, NULL,
  262. MACVLAN_MODE_PRIVATE |
  263. MACVLAN_MODE_VEPA |
  264. MACVLAN_MODE_PASSTHRU|
  265. MACVLAN_MODE_BRIDGE);
  266. else if (src->mode == MACVLAN_MODE_VEPA)
  267. /* flood to everyone except source */
  268. macvlan_broadcast(skb, port, src->dev,
  269. MACVLAN_MODE_VEPA |
  270. MACVLAN_MODE_BRIDGE);
  271. else
  272. /*
  273. * flood only to VEPA ports, bridge ports
  274. * already saw the frame on the way out.
  275. */
  276. macvlan_broadcast(skb, port, src->dev,
  277. MACVLAN_MODE_VEPA);
  278. rcu_read_unlock();
  279. if (src)
  280. dev_put(src->dev);
  281. consume_skb(skb);
  282. cond_resched();
  283. }
  284. }
  285. static void macvlan_broadcast_enqueue(struct macvlan_port *port,
  286. const struct macvlan_dev *src,
  287. struct sk_buff *skb)
  288. {
  289. struct sk_buff *nskb;
  290. int err = -ENOMEM;
  291. nskb = skb_clone(skb, GFP_ATOMIC);
  292. if (!nskb)
  293. goto err;
  294. MACVLAN_SKB_CB(nskb)->src = src;
  295. spin_lock(&port->bc_queue.lock);
  296. if (skb_queue_len(&port->bc_queue) < MACVLAN_BC_QUEUE_LEN) {
  297. if (src)
  298. dev_hold(src->dev);
  299. __skb_queue_tail(&port->bc_queue, nskb);
  300. err = 0;
  301. }
  302. spin_unlock(&port->bc_queue.lock);
  303. schedule_work(&port->bc_work);
  304. if (err)
  305. goto free_nskb;
  306. return;
  307. free_nskb:
  308. kfree_skb(nskb);
  309. err:
  310. atomic_long_inc(&skb->dev->rx_dropped);
  311. }
  312. static void macvlan_flush_sources(struct macvlan_port *port,
  313. struct macvlan_dev *vlan)
  314. {
  315. int i;
  316. for (i = 0; i < MACVLAN_HASH_SIZE; i++) {
  317. struct hlist_node *h, *n;
  318. hlist_for_each_safe(h, n, &port->vlan_source_hash[i]) {
  319. struct macvlan_source_entry *entry;
  320. entry = hlist_entry(h, struct macvlan_source_entry,
  321. hlist);
  322. if (entry->vlan == vlan)
  323. macvlan_hash_del_source(entry);
  324. }
  325. }
  326. vlan->macaddr_count = 0;
  327. }
  328. static void macvlan_forward_source_one(struct sk_buff *skb,
  329. struct macvlan_dev *vlan)
  330. {
  331. struct sk_buff *nskb;
  332. struct net_device *dev;
  333. int len;
  334. int ret;
  335. dev = vlan->dev;
  336. if (unlikely(!(dev->flags & IFF_UP)))
  337. return;
  338. nskb = skb_clone(skb, GFP_ATOMIC);
  339. if (!nskb)
  340. return;
  341. len = nskb->len + ETH_HLEN;
  342. nskb->dev = dev;
  343. if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, dev->dev_addr))
  344. nskb->pkt_type = PACKET_HOST;
  345. ret = netif_rx(nskb);
  346. macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, false);
  347. }
  348. static void macvlan_forward_source(struct sk_buff *skb,
  349. struct macvlan_port *port,
  350. const unsigned char *addr)
  351. {
  352. struct macvlan_source_entry *entry;
  353. u32 idx = macvlan_eth_hash(addr);
  354. struct hlist_head *h = &port->vlan_source_hash[idx];
  355. hlist_for_each_entry_rcu(entry, h, hlist) {
  356. if (ether_addr_equal_64bits(entry->addr, addr))
  357. macvlan_forward_source_one(skb, entry->vlan);
  358. }
  359. }
  360. /* called under rcu_read_lock() from netif_receive_skb */
  361. static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
  362. {
  363. struct macvlan_port *port;
  364. struct sk_buff *skb = *pskb;
  365. const struct ethhdr *eth = eth_hdr(skb);
  366. const struct macvlan_dev *vlan;
  367. const struct macvlan_dev *src;
  368. struct net_device *dev;
  369. unsigned int len = 0;
  370. int ret;
  371. rx_handler_result_t handle_res;
  372. /* Packets from dev_loopback_xmit() do not have L2 header, bail out */
  373. if (unlikely(skb->pkt_type == PACKET_LOOPBACK))
  374. return RX_HANDLER_PASS;
  375. port = macvlan_port_get_rcu(skb->dev);
  376. if (is_multicast_ether_addr(eth->h_dest)) {
  377. unsigned int hash;
  378. skb = ip_check_defrag(dev_net(skb->dev), skb, IP_DEFRAG_MACVLAN);
  379. if (!skb)
  380. return RX_HANDLER_CONSUMED;
  381. *pskb = skb;
  382. eth = eth_hdr(skb);
  383. macvlan_forward_source(skb, port, eth->h_source);
  384. src = macvlan_hash_lookup(port, eth->h_source);
  385. if (src && src->mode != MACVLAN_MODE_VEPA &&
  386. src->mode != MACVLAN_MODE_BRIDGE) {
  387. /* forward to original port. */
  388. vlan = src;
  389. ret = macvlan_broadcast_one(skb, vlan, eth, 0) ?:
  390. netif_rx(skb);
  391. handle_res = RX_HANDLER_CONSUMED;
  392. goto out;
  393. }
  394. hash = mc_hash(NULL, eth->h_dest);
  395. if (test_bit(hash, port->mc_filter))
  396. macvlan_broadcast_enqueue(port, src, skb);
  397. return RX_HANDLER_PASS;
  398. }
  399. macvlan_forward_source(skb, port, eth->h_source);
  400. if (macvlan_passthru(port))
  401. vlan = list_first_or_null_rcu(&port->vlans,
  402. struct macvlan_dev, list);
  403. else
  404. vlan = macvlan_hash_lookup(port, eth->h_dest);
  405. if (!vlan || vlan->mode == MACVLAN_MODE_SOURCE)
  406. return RX_HANDLER_PASS;
  407. dev = vlan->dev;
  408. if (unlikely(!(dev->flags & IFF_UP))) {
  409. kfree_skb(skb);
  410. return RX_HANDLER_CONSUMED;
  411. }
  412. len = skb->len + ETH_HLEN;
  413. skb = skb_share_check(skb, GFP_ATOMIC);
  414. if (!skb) {
  415. ret = NET_RX_DROP;
  416. handle_res = RX_HANDLER_CONSUMED;
  417. goto out;
  418. }
  419. *pskb = skb;
  420. skb->dev = dev;
  421. skb->pkt_type = PACKET_HOST;
  422. ret = NET_RX_SUCCESS;
  423. handle_res = RX_HANDLER_ANOTHER;
  424. out:
  425. macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, false);
  426. return handle_res;
  427. }
  428. static int macvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev)
  429. {
  430. const struct macvlan_dev *vlan = netdev_priv(dev);
  431. const struct macvlan_port *port = vlan->port;
  432. const struct macvlan_dev *dest;
  433. if (vlan->mode == MACVLAN_MODE_BRIDGE) {
  434. const struct ethhdr *eth = skb_eth_hdr(skb);
  435. /* send to other bridge ports directly */
  436. if (is_multicast_ether_addr(eth->h_dest)) {
  437. skb_reset_mac_header(skb);
  438. macvlan_broadcast(skb, port, dev, MACVLAN_MODE_BRIDGE);
  439. goto xmit_world;
  440. }
  441. dest = macvlan_hash_lookup(port, eth->h_dest);
  442. if (dest && dest->mode == MACVLAN_MODE_BRIDGE) {
  443. /* send to lowerdev first for its network taps */
  444. dev_forward_skb(vlan->lowerdev, skb);
  445. return NET_XMIT_SUCCESS;
  446. }
  447. }
  448. xmit_world:
  449. skb->dev = vlan->lowerdev;
  450. return dev_queue_xmit_accel(skb,
  451. netdev_get_sb_channel(dev) ? dev : NULL);
  452. }
  453. static inline netdev_tx_t macvlan_netpoll_send_skb(struct macvlan_dev *vlan, struct sk_buff *skb)
  454. {
  455. #ifdef CONFIG_NET_POLL_CONTROLLER
  456. if (vlan->netpoll)
  457. netpoll_send_skb(vlan->netpoll, skb);
  458. #else
  459. BUG();
  460. #endif
  461. return NETDEV_TX_OK;
  462. }
  463. static netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
  464. struct net_device *dev)
  465. {
  466. struct macvlan_dev *vlan = netdev_priv(dev);
  467. unsigned int len = skb->len;
  468. int ret;
  469. if (unlikely(netpoll_tx_running(dev)))
  470. return macvlan_netpoll_send_skb(vlan, skb);
  471. ret = macvlan_queue_xmit(skb, dev);
  472. if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) {
  473. struct vlan_pcpu_stats *pcpu_stats;
  474. pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
  475. u64_stats_update_begin(&pcpu_stats->syncp);
  476. pcpu_stats->tx_packets++;
  477. pcpu_stats->tx_bytes += len;
  478. u64_stats_update_end(&pcpu_stats->syncp);
  479. } else {
  480. this_cpu_inc(vlan->pcpu_stats->tx_dropped);
  481. }
  482. return ret;
  483. }
  484. static int macvlan_hard_header(struct sk_buff *skb, struct net_device *dev,
  485. unsigned short type, const void *daddr,
  486. const void *saddr, unsigned len)
  487. {
  488. const struct macvlan_dev *vlan = netdev_priv(dev);
  489. struct net_device *lowerdev = vlan->lowerdev;
  490. return dev_hard_header(skb, lowerdev, type, daddr,
  491. saddr ? : dev->dev_addr, len);
  492. }
  493. static const struct header_ops macvlan_hard_header_ops = {
  494. .create = macvlan_hard_header,
  495. .parse = eth_header_parse,
  496. .cache = eth_header_cache,
  497. .cache_update = eth_header_cache_update,
  498. };
  499. static int macvlan_open(struct net_device *dev)
  500. {
  501. struct macvlan_dev *vlan = netdev_priv(dev);
  502. struct net_device *lowerdev = vlan->lowerdev;
  503. int err;
  504. if (macvlan_passthru(vlan->port)) {
  505. if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) {
  506. err = dev_set_promiscuity(lowerdev, 1);
  507. if (err < 0)
  508. goto out;
  509. }
  510. goto hash_add;
  511. }
  512. err = -EADDRINUSE;
  513. if (macvlan_addr_busy(vlan->port, dev->dev_addr))
  514. goto out;
  515. /* Attempt to populate accel_priv which is used to offload the L2
  516. * forwarding requests for unicast packets.
  517. */
  518. if (lowerdev->features & NETIF_F_HW_L2FW_DOFFLOAD)
  519. vlan->accel_priv =
  520. lowerdev->netdev_ops->ndo_dfwd_add_station(lowerdev, dev);
  521. /* If earlier attempt to offload failed, or accel_priv is not
  522. * populated we must add the unicast address to the lower device.
  523. */
  524. if (IS_ERR_OR_NULL(vlan->accel_priv)) {
  525. vlan->accel_priv = NULL;
  526. err = dev_uc_add(lowerdev, dev->dev_addr);
  527. if (err < 0)
  528. goto out;
  529. }
  530. if (dev->flags & IFF_ALLMULTI) {
  531. err = dev_set_allmulti(lowerdev, 1);
  532. if (err < 0)
  533. goto del_unicast;
  534. }
  535. if (dev->flags & IFF_PROMISC) {
  536. err = dev_set_promiscuity(lowerdev, 1);
  537. if (err < 0)
  538. goto clear_multi;
  539. }
  540. hash_add:
  541. macvlan_hash_add(vlan);
  542. return 0;
  543. clear_multi:
  544. if (dev->flags & IFF_ALLMULTI)
  545. dev_set_allmulti(lowerdev, -1);
  546. del_unicast:
  547. if (vlan->accel_priv) {
  548. lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev,
  549. vlan->accel_priv);
  550. vlan->accel_priv = NULL;
  551. } else {
  552. dev_uc_del(lowerdev, dev->dev_addr);
  553. }
  554. out:
  555. return err;
  556. }
  557. static int macvlan_stop(struct net_device *dev)
  558. {
  559. struct macvlan_dev *vlan = netdev_priv(dev);
  560. struct net_device *lowerdev = vlan->lowerdev;
  561. if (vlan->accel_priv) {
  562. lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev,
  563. vlan->accel_priv);
  564. vlan->accel_priv = NULL;
  565. }
  566. dev_uc_unsync(lowerdev, dev);
  567. dev_mc_unsync(lowerdev, dev);
  568. if (macvlan_passthru(vlan->port)) {
  569. if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC))
  570. dev_set_promiscuity(lowerdev, -1);
  571. goto hash_del;
  572. }
  573. if (dev->flags & IFF_ALLMULTI)
  574. dev_set_allmulti(lowerdev, -1);
  575. if (dev->flags & IFF_PROMISC)
  576. dev_set_promiscuity(lowerdev, -1);
  577. dev_uc_del(lowerdev, dev->dev_addr);
  578. hash_del:
  579. macvlan_hash_del(vlan, !dev->dismantle);
  580. return 0;
  581. }
  582. static int macvlan_sync_address(struct net_device *dev, unsigned char *addr)
  583. {
  584. struct macvlan_dev *vlan = netdev_priv(dev);
  585. struct net_device *lowerdev = vlan->lowerdev;
  586. struct macvlan_port *port = vlan->port;
  587. int err;
  588. if (!(dev->flags & IFF_UP)) {
  589. /* Just copy in the new address */
  590. ether_addr_copy(dev->dev_addr, addr);
  591. } else {
  592. /* Rehash and update the device filters */
  593. if (macvlan_addr_busy(vlan->port, addr))
  594. return -EADDRINUSE;
  595. if (!macvlan_passthru(port)) {
  596. err = dev_uc_add(lowerdev, addr);
  597. if (err)
  598. return err;
  599. dev_uc_del(lowerdev, dev->dev_addr);
  600. }
  601. macvlan_hash_change_addr(vlan, addr);
  602. }
  603. if (macvlan_passthru(port) && !macvlan_addr_change(port)) {
  604. /* Since addr_change isn't set, we are here due to lower
  605. * device change. Save the lower-dev address so we can
  606. * restore it later.
  607. */
  608. ether_addr_copy(vlan->port->perm_addr,
  609. lowerdev->dev_addr);
  610. }
  611. macvlan_clear_addr_change(port);
  612. return 0;
  613. }
  614. static int macvlan_set_mac_address(struct net_device *dev, void *p)
  615. {
  616. struct macvlan_dev *vlan = netdev_priv(dev);
  617. struct sockaddr *addr = p;
  618. if (!is_valid_ether_addr(addr->sa_data))
  619. return -EADDRNOTAVAIL;
  620. /* If the addresses are the same, this is a no-op */
  621. if (ether_addr_equal(dev->dev_addr, addr->sa_data))
  622. return 0;
  623. if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
  624. macvlan_set_addr_change(vlan->port);
  625. return dev_set_mac_address(vlan->lowerdev, addr, NULL);
  626. }
  627. if (macvlan_addr_busy(vlan->port, addr->sa_data))
  628. return -EADDRINUSE;
  629. return macvlan_sync_address(dev, addr->sa_data);
  630. }
  631. static void macvlan_change_rx_flags(struct net_device *dev, int change)
  632. {
  633. struct macvlan_dev *vlan = netdev_priv(dev);
  634. struct net_device *lowerdev = vlan->lowerdev;
  635. if (dev->flags & IFF_UP) {
  636. if (change & IFF_ALLMULTI)
  637. dev_set_allmulti(lowerdev, dev->flags & IFF_ALLMULTI ? 1 : -1);
  638. if (change & IFF_PROMISC)
  639. dev_set_promiscuity(lowerdev,
  640. dev->flags & IFF_PROMISC ? 1 : -1);
  641. }
  642. }
  643. static void macvlan_compute_filter(unsigned long *mc_filter,
  644. struct net_device *dev,
  645. struct macvlan_dev *vlan)
  646. {
  647. if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
  648. bitmap_fill(mc_filter, MACVLAN_MC_FILTER_SZ);
  649. } else {
  650. struct netdev_hw_addr *ha;
  651. DECLARE_BITMAP(filter, MACVLAN_MC_FILTER_SZ);
  652. bitmap_zero(filter, MACVLAN_MC_FILTER_SZ);
  653. netdev_for_each_mc_addr(ha, dev) {
  654. __set_bit(mc_hash(vlan, ha->addr), filter);
  655. }
  656. __set_bit(mc_hash(vlan, dev->broadcast), filter);
  657. bitmap_copy(mc_filter, filter, MACVLAN_MC_FILTER_SZ);
  658. }
  659. }
  660. static void macvlan_set_mac_lists(struct net_device *dev)
  661. {
  662. struct macvlan_dev *vlan = netdev_priv(dev);
  663. macvlan_compute_filter(vlan->mc_filter, dev, vlan);
  664. dev_uc_sync(vlan->lowerdev, dev);
  665. dev_mc_sync(vlan->lowerdev, dev);
  666. /* This is slightly inaccurate as we're including the subscription
  667. * list of vlan->lowerdev too.
  668. *
  669. * Bug alert: This only works if everyone has the same broadcast
  670. * address as lowerdev. As soon as someone changes theirs this
  671. * will break.
  672. *
  673. * However, this is already broken as when you change your broadcast
  674. * address we don't get called.
  675. *
  676. * The solution is to maintain a list of broadcast addresses like
  677. * we do for uc/mc, if you care.
  678. */
  679. macvlan_compute_filter(vlan->port->mc_filter, vlan->lowerdev, NULL);
  680. }
  681. static int macvlan_change_mtu(struct net_device *dev, int new_mtu)
  682. {
  683. struct macvlan_dev *vlan = netdev_priv(dev);
  684. if (vlan->lowerdev->mtu < new_mtu)
  685. return -EINVAL;
  686. dev->mtu = new_mtu;
  687. return 0;
  688. }
  689. static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  690. {
  691. struct net_device *real_dev = macvlan_dev_real_dev(dev);
  692. const struct net_device_ops *ops = real_dev->netdev_ops;
  693. struct ifreq ifrr;
  694. int err = -EOPNOTSUPP;
  695. strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
  696. ifrr.ifr_ifru = ifr->ifr_ifru;
  697. switch (cmd) {
  698. case SIOCSHWTSTAMP:
  699. if (!net_eq(dev_net(dev), &init_net))
  700. break;
  701. /* fall through */
  702. case SIOCGHWTSTAMP:
  703. if (netif_device_present(real_dev) && ops->ndo_do_ioctl)
  704. err = ops->ndo_do_ioctl(real_dev, &ifrr, cmd);
  705. break;
  706. }
  707. if (!err)
  708. ifr->ifr_ifru = ifrr.ifr_ifru;
  709. return err;
  710. }
  711. /*
  712. * macvlan network devices have devices nesting below it and are a special
  713. * "super class" of normal network devices; split their locks off into a
  714. * separate class since they always nest.
  715. */
  716. #define ALWAYS_ON_OFFLOADS \
  717. (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE | \
  718. NETIF_F_GSO_ROBUST | NETIF_F_GSO_ENCAP_ALL)
  719. #define ALWAYS_ON_FEATURES (ALWAYS_ON_OFFLOADS | NETIF_F_LLTX)
  720. #define MACVLAN_FEATURES \
  721. (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
  722. NETIF_F_GSO | NETIF_F_TSO | NETIF_F_LRO | \
  723. NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_GRO | NETIF_F_RXCSUM | \
  724. NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER)
  725. #define MACVLAN_STATE_MASK \
  726. ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT))
  727. static int macvlan_init(struct net_device *dev)
  728. {
  729. struct macvlan_dev *vlan = netdev_priv(dev);
  730. const struct net_device *lowerdev = vlan->lowerdev;
  731. struct macvlan_port *port = vlan->port;
  732. dev->state = (dev->state & ~MACVLAN_STATE_MASK) |
  733. (lowerdev->state & MACVLAN_STATE_MASK);
  734. dev->features = lowerdev->features & MACVLAN_FEATURES;
  735. dev->features |= ALWAYS_ON_FEATURES;
  736. dev->hw_features |= NETIF_F_LRO;
  737. dev->vlan_features = lowerdev->vlan_features & MACVLAN_FEATURES;
  738. dev->vlan_features |= ALWAYS_ON_OFFLOADS;
  739. dev->hw_enc_features |= dev->features;
  740. dev->gso_max_size = lowerdev->gso_max_size;
  741. dev->gso_max_segs = lowerdev->gso_max_segs;
  742. dev->hard_header_len = lowerdev->hard_header_len;
  743. vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
  744. if (!vlan->pcpu_stats)
  745. return -ENOMEM;
  746. port->count += 1;
  747. return 0;
  748. }
  749. static void macvlan_uninit(struct net_device *dev)
  750. {
  751. struct macvlan_dev *vlan = netdev_priv(dev);
  752. struct macvlan_port *port = vlan->port;
  753. free_percpu(vlan->pcpu_stats);
  754. macvlan_flush_sources(port, vlan);
  755. port->count -= 1;
  756. if (!port->count)
  757. macvlan_port_destroy(port->dev);
  758. }
  759. static void macvlan_dev_get_stats64(struct net_device *dev,
  760. struct rtnl_link_stats64 *stats)
  761. {
  762. struct macvlan_dev *vlan = netdev_priv(dev);
  763. if (vlan->pcpu_stats) {
  764. struct vlan_pcpu_stats *p;
  765. u64 rx_packets, rx_bytes, rx_multicast, tx_packets, tx_bytes;
  766. u32 rx_errors = 0, tx_dropped = 0;
  767. unsigned int start;
  768. int i;
  769. for_each_possible_cpu(i) {
  770. p = per_cpu_ptr(vlan->pcpu_stats, i);
  771. do {
  772. start = u64_stats_fetch_begin_irq(&p->syncp);
  773. rx_packets = p->rx_packets;
  774. rx_bytes = p->rx_bytes;
  775. rx_multicast = p->rx_multicast;
  776. tx_packets = p->tx_packets;
  777. tx_bytes = p->tx_bytes;
  778. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  779. stats->rx_packets += rx_packets;
  780. stats->rx_bytes += rx_bytes;
  781. stats->multicast += rx_multicast;
  782. stats->tx_packets += tx_packets;
  783. stats->tx_bytes += tx_bytes;
  784. /* rx_errors & tx_dropped are u32, updated
  785. * without syncp protection.
  786. */
  787. rx_errors += p->rx_errors;
  788. tx_dropped += p->tx_dropped;
  789. }
  790. stats->rx_errors = rx_errors;
  791. stats->rx_dropped = rx_errors;
  792. stats->tx_dropped = tx_dropped;
  793. }
  794. }
  795. static int macvlan_vlan_rx_add_vid(struct net_device *dev,
  796. __be16 proto, u16 vid)
  797. {
  798. struct macvlan_dev *vlan = netdev_priv(dev);
  799. struct net_device *lowerdev = vlan->lowerdev;
  800. return vlan_vid_add(lowerdev, proto, vid);
  801. }
  802. static int macvlan_vlan_rx_kill_vid(struct net_device *dev,
  803. __be16 proto, u16 vid)
  804. {
  805. struct macvlan_dev *vlan = netdev_priv(dev);
  806. struct net_device *lowerdev = vlan->lowerdev;
  807. vlan_vid_del(lowerdev, proto, vid);
  808. return 0;
  809. }
  810. static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  811. struct net_device *dev,
  812. const unsigned char *addr, u16 vid,
  813. u16 flags,
  814. struct netlink_ext_ack *extack)
  815. {
  816. struct macvlan_dev *vlan = netdev_priv(dev);
  817. int err = -EINVAL;
  818. /* Support unicast filter only on passthru devices.
  819. * Multicast filter should be allowed on all devices.
  820. */
  821. if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr))
  822. return -EOPNOTSUPP;
  823. if (flags & NLM_F_REPLACE)
  824. return -EOPNOTSUPP;
  825. if (is_unicast_ether_addr(addr))
  826. err = dev_uc_add_excl(dev, addr);
  827. else if (is_multicast_ether_addr(addr))
  828. err = dev_mc_add_excl(dev, addr);
  829. return err;
  830. }
  831. static int macvlan_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  832. struct net_device *dev,
  833. const unsigned char *addr, u16 vid)
  834. {
  835. struct macvlan_dev *vlan = netdev_priv(dev);
  836. int err = -EINVAL;
  837. /* Support unicast filter only on passthru devices.
  838. * Multicast filter should be allowed on all devices.
  839. */
  840. if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr))
  841. return -EOPNOTSUPP;
  842. if (is_unicast_ether_addr(addr))
  843. err = dev_uc_del(dev, addr);
  844. else if (is_multicast_ether_addr(addr))
  845. err = dev_mc_del(dev, addr);
  846. return err;
  847. }
  848. static void macvlan_ethtool_get_drvinfo(struct net_device *dev,
  849. struct ethtool_drvinfo *drvinfo)
  850. {
  851. strlcpy(drvinfo->driver, "macvlan", sizeof(drvinfo->driver));
  852. strlcpy(drvinfo->version, "0.1", sizeof(drvinfo->version));
  853. }
  854. static int macvlan_ethtool_get_link_ksettings(struct net_device *dev,
  855. struct ethtool_link_ksettings *cmd)
  856. {
  857. const struct macvlan_dev *vlan = netdev_priv(dev);
  858. return __ethtool_get_link_ksettings(vlan->lowerdev, cmd);
  859. }
  860. static int macvlan_ethtool_get_ts_info(struct net_device *dev,
  861. struct ethtool_ts_info *info)
  862. {
  863. struct net_device *real_dev = macvlan_dev_real_dev(dev);
  864. const struct ethtool_ops *ops = real_dev->ethtool_ops;
  865. struct phy_device *phydev = real_dev->phydev;
  866. if (phydev && phydev->drv && phydev->drv->ts_info) {
  867. return phydev->drv->ts_info(phydev, info);
  868. } else if (ops->get_ts_info) {
  869. return ops->get_ts_info(real_dev, info);
  870. } else {
  871. info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
  872. SOF_TIMESTAMPING_SOFTWARE;
  873. info->phc_index = -1;
  874. }
  875. return 0;
  876. }
  877. static netdev_features_t macvlan_fix_features(struct net_device *dev,
  878. netdev_features_t features)
  879. {
  880. struct macvlan_dev *vlan = netdev_priv(dev);
  881. netdev_features_t lowerdev_features = vlan->lowerdev->features;
  882. netdev_features_t mask;
  883. features |= NETIF_F_ALL_FOR_ALL;
  884. features &= (vlan->set_features | ~MACVLAN_FEATURES);
  885. mask = features;
  886. lowerdev_features &= (features | ~NETIF_F_LRO);
  887. features = netdev_increment_features(lowerdev_features, features, mask);
  888. features |= ALWAYS_ON_FEATURES;
  889. features &= (ALWAYS_ON_FEATURES | MACVLAN_FEATURES);
  890. return features;
  891. }
  892. #ifdef CONFIG_NET_POLL_CONTROLLER
  893. static void macvlan_dev_poll_controller(struct net_device *dev)
  894. {
  895. return;
  896. }
  897. static int macvlan_dev_netpoll_setup(struct net_device *dev, struct netpoll_info *npinfo)
  898. {
  899. struct macvlan_dev *vlan = netdev_priv(dev);
  900. struct net_device *real_dev = vlan->lowerdev;
  901. struct netpoll *netpoll;
  902. int err = 0;
  903. netpoll = kzalloc(sizeof(*netpoll), GFP_KERNEL);
  904. err = -ENOMEM;
  905. if (!netpoll)
  906. goto out;
  907. err = __netpoll_setup(netpoll, real_dev);
  908. if (err) {
  909. kfree(netpoll);
  910. goto out;
  911. }
  912. vlan->netpoll = netpoll;
  913. out:
  914. return err;
  915. }
  916. static void macvlan_dev_netpoll_cleanup(struct net_device *dev)
  917. {
  918. struct macvlan_dev *vlan = netdev_priv(dev);
  919. struct netpoll *netpoll = vlan->netpoll;
  920. if (!netpoll)
  921. return;
  922. vlan->netpoll = NULL;
  923. __netpoll_free(netpoll);
  924. }
  925. #endif /* CONFIG_NET_POLL_CONTROLLER */
  926. static int macvlan_dev_get_iflink(const struct net_device *dev)
  927. {
  928. struct macvlan_dev *vlan = netdev_priv(dev);
  929. return vlan->lowerdev->ifindex;
  930. }
  931. static const struct ethtool_ops macvlan_ethtool_ops = {
  932. .get_link = ethtool_op_get_link,
  933. .get_link_ksettings = macvlan_ethtool_get_link_ksettings,
  934. .get_drvinfo = macvlan_ethtool_get_drvinfo,
  935. .get_ts_info = macvlan_ethtool_get_ts_info,
  936. };
  937. static const struct net_device_ops macvlan_netdev_ops = {
  938. .ndo_init = macvlan_init,
  939. .ndo_uninit = macvlan_uninit,
  940. .ndo_open = macvlan_open,
  941. .ndo_stop = macvlan_stop,
  942. .ndo_start_xmit = macvlan_start_xmit,
  943. .ndo_change_mtu = macvlan_change_mtu,
  944. .ndo_do_ioctl = macvlan_do_ioctl,
  945. .ndo_fix_features = macvlan_fix_features,
  946. .ndo_change_rx_flags = macvlan_change_rx_flags,
  947. .ndo_set_mac_address = macvlan_set_mac_address,
  948. .ndo_set_rx_mode = macvlan_set_mac_lists,
  949. .ndo_get_stats64 = macvlan_dev_get_stats64,
  950. .ndo_validate_addr = eth_validate_addr,
  951. .ndo_vlan_rx_add_vid = macvlan_vlan_rx_add_vid,
  952. .ndo_vlan_rx_kill_vid = macvlan_vlan_rx_kill_vid,
  953. .ndo_fdb_add = macvlan_fdb_add,
  954. .ndo_fdb_del = macvlan_fdb_del,
  955. .ndo_fdb_dump = ndo_dflt_fdb_dump,
  956. #ifdef CONFIG_NET_POLL_CONTROLLER
  957. .ndo_poll_controller = macvlan_dev_poll_controller,
  958. .ndo_netpoll_setup = macvlan_dev_netpoll_setup,
  959. .ndo_netpoll_cleanup = macvlan_dev_netpoll_cleanup,
  960. #endif
  961. .ndo_get_iflink = macvlan_dev_get_iflink,
  962. .ndo_features_check = passthru_features_check,
  963. .ndo_change_proto_down = dev_change_proto_down_generic,
  964. };
  965. void macvlan_common_setup(struct net_device *dev)
  966. {
  967. ether_setup(dev);
  968. dev->min_mtu = 0;
  969. dev->max_mtu = ETH_MAX_MTU;
  970. dev->priv_flags &= ~IFF_TX_SKB_SHARING;
  971. netif_keep_dst(dev);
  972. dev->priv_flags |= IFF_UNICAST_FLT;
  973. dev->netdev_ops = &macvlan_netdev_ops;
  974. dev->needs_free_netdev = true;
  975. dev->header_ops = &macvlan_hard_header_ops;
  976. dev->ethtool_ops = &macvlan_ethtool_ops;
  977. }
  978. EXPORT_SYMBOL_GPL(macvlan_common_setup);
  979. static void macvlan_setup(struct net_device *dev)
  980. {
  981. macvlan_common_setup(dev);
  982. dev->priv_flags |= IFF_NO_QUEUE;
  983. }
  984. static int macvlan_port_create(struct net_device *dev)
  985. {
  986. struct macvlan_port *port;
  987. unsigned int i;
  988. int err;
  989. if (dev->type != ARPHRD_ETHER || dev->flags & IFF_LOOPBACK)
  990. return -EINVAL;
  991. if (netdev_is_rx_handler_busy(dev))
  992. return -EBUSY;
  993. port = kzalloc(sizeof(*port), GFP_KERNEL);
  994. if (port == NULL)
  995. return -ENOMEM;
  996. port->dev = dev;
  997. ether_addr_copy(port->perm_addr, dev->dev_addr);
  998. INIT_LIST_HEAD(&port->vlans);
  999. for (i = 0; i < MACVLAN_HASH_SIZE; i++)
  1000. INIT_HLIST_HEAD(&port->vlan_hash[i]);
  1001. for (i = 0; i < MACVLAN_HASH_SIZE; i++)
  1002. INIT_HLIST_HEAD(&port->vlan_source_hash[i]);
  1003. skb_queue_head_init(&port->bc_queue);
  1004. INIT_WORK(&port->bc_work, macvlan_process_broadcast);
  1005. err = netdev_rx_handler_register(dev, macvlan_handle_frame, port);
  1006. if (err)
  1007. kfree(port);
  1008. else
  1009. dev->priv_flags |= IFF_MACVLAN_PORT;
  1010. return err;
  1011. }
  1012. static void macvlan_port_destroy(struct net_device *dev)
  1013. {
  1014. struct macvlan_port *port = macvlan_port_get_rtnl(dev);
  1015. struct sk_buff *skb;
  1016. dev->priv_flags &= ~IFF_MACVLAN_PORT;
  1017. netdev_rx_handler_unregister(dev);
  1018. /* After this point, no packet can schedule bc_work anymore,
  1019. * but we need to cancel it and purge left skbs if any.
  1020. */
  1021. cancel_work_sync(&port->bc_work);
  1022. while ((skb = __skb_dequeue(&port->bc_queue))) {
  1023. const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src;
  1024. if (src)
  1025. dev_put(src->dev);
  1026. kfree_skb(skb);
  1027. }
  1028. /* If the lower device address has been changed by passthru
  1029. * macvlan, put it back.
  1030. */
  1031. if (macvlan_passthru(port) &&
  1032. !ether_addr_equal(port->dev->dev_addr, port->perm_addr)) {
  1033. struct sockaddr sa;
  1034. sa.sa_family = port->dev->type;
  1035. memcpy(&sa.sa_data, port->perm_addr, port->dev->addr_len);
  1036. dev_set_mac_address(port->dev, &sa, NULL);
  1037. }
  1038. kfree(port);
  1039. }
  1040. static int macvlan_validate(struct nlattr *tb[], struct nlattr *data[],
  1041. struct netlink_ext_ack *extack)
  1042. {
  1043. struct nlattr *nla, *head;
  1044. int rem, len;
  1045. if (tb[IFLA_ADDRESS]) {
  1046. if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
  1047. return -EINVAL;
  1048. if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
  1049. return -EADDRNOTAVAIL;
  1050. }
  1051. if (!data)
  1052. return 0;
  1053. if (data[IFLA_MACVLAN_FLAGS] &&
  1054. nla_get_u16(data[IFLA_MACVLAN_FLAGS]) & ~MACVLAN_FLAG_NOPROMISC)
  1055. return -EINVAL;
  1056. if (data[IFLA_MACVLAN_MODE]) {
  1057. switch (nla_get_u32(data[IFLA_MACVLAN_MODE])) {
  1058. case MACVLAN_MODE_PRIVATE:
  1059. case MACVLAN_MODE_VEPA:
  1060. case MACVLAN_MODE_BRIDGE:
  1061. case MACVLAN_MODE_PASSTHRU:
  1062. case MACVLAN_MODE_SOURCE:
  1063. break;
  1064. default:
  1065. return -EINVAL;
  1066. }
  1067. }
  1068. if (data[IFLA_MACVLAN_MACADDR_MODE]) {
  1069. switch (nla_get_u32(data[IFLA_MACVLAN_MACADDR_MODE])) {
  1070. case MACVLAN_MACADDR_ADD:
  1071. case MACVLAN_MACADDR_DEL:
  1072. case MACVLAN_MACADDR_FLUSH:
  1073. case MACVLAN_MACADDR_SET:
  1074. break;
  1075. default:
  1076. return -EINVAL;
  1077. }
  1078. }
  1079. if (data[IFLA_MACVLAN_MACADDR]) {
  1080. if (nla_len(data[IFLA_MACVLAN_MACADDR]) != ETH_ALEN)
  1081. return -EINVAL;
  1082. if (!is_valid_ether_addr(nla_data(data[IFLA_MACVLAN_MACADDR])))
  1083. return -EADDRNOTAVAIL;
  1084. }
  1085. if (data[IFLA_MACVLAN_MACADDR_DATA]) {
  1086. head = nla_data(data[IFLA_MACVLAN_MACADDR_DATA]);
  1087. len = nla_len(data[IFLA_MACVLAN_MACADDR_DATA]);
  1088. nla_for_each_attr(nla, head, len, rem) {
  1089. if (nla_type(nla) != IFLA_MACVLAN_MACADDR ||
  1090. nla_len(nla) != ETH_ALEN)
  1091. return -EINVAL;
  1092. if (!is_valid_ether_addr(nla_data(nla)))
  1093. return -EADDRNOTAVAIL;
  1094. }
  1095. }
  1096. if (data[IFLA_MACVLAN_MACADDR_COUNT])
  1097. return -EINVAL;
  1098. return 0;
  1099. }
  1100. /**
  1101. * reconfigure list of remote source mac address
  1102. * (only for macvlan devices in source mode)
  1103. * Note regarding alignment: all netlink data is aligned to 4 Byte, which
  1104. * suffices for both ether_addr_copy and ether_addr_equal_64bits usage.
  1105. */
  1106. static int macvlan_changelink_sources(struct macvlan_dev *vlan, u32 mode,
  1107. struct nlattr *data[])
  1108. {
  1109. char *addr = NULL;
  1110. int ret, rem, len;
  1111. struct nlattr *nla, *head;
  1112. struct macvlan_source_entry *entry;
  1113. if (data[IFLA_MACVLAN_MACADDR])
  1114. addr = nla_data(data[IFLA_MACVLAN_MACADDR]);
  1115. if (mode == MACVLAN_MACADDR_ADD) {
  1116. if (!addr)
  1117. return -EINVAL;
  1118. return macvlan_hash_add_source(vlan, addr);
  1119. } else if (mode == MACVLAN_MACADDR_DEL) {
  1120. if (!addr)
  1121. return -EINVAL;
  1122. entry = macvlan_hash_lookup_source(vlan, addr);
  1123. if (entry) {
  1124. macvlan_hash_del_source(entry);
  1125. vlan->macaddr_count--;
  1126. }
  1127. } else if (mode == MACVLAN_MACADDR_FLUSH) {
  1128. macvlan_flush_sources(vlan->port, vlan);
  1129. } else if (mode == MACVLAN_MACADDR_SET) {
  1130. macvlan_flush_sources(vlan->port, vlan);
  1131. if (addr) {
  1132. ret = macvlan_hash_add_source(vlan, addr);
  1133. if (ret)
  1134. return ret;
  1135. }
  1136. if (!data || !data[IFLA_MACVLAN_MACADDR_DATA])
  1137. return 0;
  1138. head = nla_data(data[IFLA_MACVLAN_MACADDR_DATA]);
  1139. len = nla_len(data[IFLA_MACVLAN_MACADDR_DATA]);
  1140. nla_for_each_attr(nla, head, len, rem) {
  1141. addr = nla_data(nla);
  1142. ret = macvlan_hash_add_source(vlan, addr);
  1143. if (ret)
  1144. return ret;
  1145. }
  1146. } else {
  1147. return -EINVAL;
  1148. }
  1149. return 0;
  1150. }
  1151. int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
  1152. struct nlattr *tb[], struct nlattr *data[],
  1153. struct netlink_ext_ack *extack)
  1154. {
  1155. struct macvlan_dev *vlan = netdev_priv(dev);
  1156. struct macvlan_port *port;
  1157. struct net_device *lowerdev;
  1158. int err;
  1159. int macmode;
  1160. bool create = false;
  1161. if (!tb[IFLA_LINK])
  1162. return -EINVAL;
  1163. lowerdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
  1164. if (lowerdev == NULL)
  1165. return -ENODEV;
  1166. /* When creating macvlans or macvtaps on top of other macvlans - use
  1167. * the real device as the lowerdev.
  1168. */
  1169. if (netif_is_macvlan(lowerdev))
  1170. lowerdev = macvlan_dev_real_dev(lowerdev);
  1171. if (!tb[IFLA_MTU])
  1172. dev->mtu = lowerdev->mtu;
  1173. else if (dev->mtu > lowerdev->mtu)
  1174. return -EINVAL;
  1175. /* MTU range: 68 - lowerdev->max_mtu */
  1176. dev->min_mtu = ETH_MIN_MTU;
  1177. dev->max_mtu = lowerdev->max_mtu;
  1178. if (!tb[IFLA_ADDRESS])
  1179. eth_hw_addr_random(dev);
  1180. if (!netif_is_macvlan_port(lowerdev)) {
  1181. err = macvlan_port_create(lowerdev);
  1182. if (err < 0)
  1183. return err;
  1184. create = true;
  1185. }
  1186. port = macvlan_port_get_rtnl(lowerdev);
  1187. /* Only 1 macvlan device can be created in passthru mode */
  1188. if (macvlan_passthru(port)) {
  1189. /* The macvlan port must be not created this time,
  1190. * still goto destroy_macvlan_port for readability.
  1191. */
  1192. err = -EINVAL;
  1193. goto destroy_macvlan_port;
  1194. }
  1195. vlan->lowerdev = lowerdev;
  1196. vlan->dev = dev;
  1197. vlan->port = port;
  1198. vlan->set_features = MACVLAN_FEATURES;
  1199. vlan->mode = MACVLAN_MODE_VEPA;
  1200. if (data && data[IFLA_MACVLAN_MODE])
  1201. vlan->mode = nla_get_u32(data[IFLA_MACVLAN_MODE]);
  1202. if (data && data[IFLA_MACVLAN_FLAGS])
  1203. vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
  1204. if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
  1205. if (port->count) {
  1206. err = -EINVAL;
  1207. goto destroy_macvlan_port;
  1208. }
  1209. macvlan_set_passthru(port);
  1210. eth_hw_addr_inherit(dev, lowerdev);
  1211. }
  1212. if (data && data[IFLA_MACVLAN_MACADDR_MODE]) {
  1213. if (vlan->mode != MACVLAN_MODE_SOURCE) {
  1214. err = -EINVAL;
  1215. goto destroy_macvlan_port;
  1216. }
  1217. macmode = nla_get_u32(data[IFLA_MACVLAN_MACADDR_MODE]);
  1218. err = macvlan_changelink_sources(vlan, macmode, data);
  1219. if (err)
  1220. goto destroy_macvlan_port;
  1221. }
  1222. err = register_netdevice(dev);
  1223. if (err < 0)
  1224. goto destroy_macvlan_port;
  1225. dev->priv_flags |= IFF_MACVLAN;
  1226. err = netdev_upper_dev_link(lowerdev, dev, extack);
  1227. if (err)
  1228. goto unregister_netdev;
  1229. list_add_tail_rcu(&vlan->list, &port->vlans);
  1230. netif_stacked_transfer_operstate(lowerdev, dev);
  1231. linkwatch_fire_event(dev);
  1232. return 0;
  1233. unregister_netdev:
  1234. /* macvlan_uninit would free the macvlan port */
  1235. unregister_netdevice(dev);
  1236. return err;
  1237. destroy_macvlan_port:
  1238. /* the macvlan port may be freed by macvlan_uninit when fail to register.
  1239. * so we destroy the macvlan port only when it's valid.
  1240. */
  1241. if (create && macvlan_port_get_rtnl(lowerdev))
  1242. macvlan_port_destroy(port->dev);
  1243. return err;
  1244. }
  1245. EXPORT_SYMBOL_GPL(macvlan_common_newlink);
  1246. static int macvlan_newlink(struct net *src_net, struct net_device *dev,
  1247. struct nlattr *tb[], struct nlattr *data[],
  1248. struct netlink_ext_ack *extack)
  1249. {
  1250. return macvlan_common_newlink(src_net, dev, tb, data, extack);
  1251. }
  1252. void macvlan_dellink(struct net_device *dev, struct list_head *head)
  1253. {
  1254. struct macvlan_dev *vlan = netdev_priv(dev);
  1255. if (vlan->mode == MACVLAN_MODE_SOURCE)
  1256. macvlan_flush_sources(vlan->port, vlan);
  1257. list_del_rcu(&vlan->list);
  1258. unregister_netdevice_queue(dev, head);
  1259. netdev_upper_dev_unlink(vlan->lowerdev, dev);
  1260. }
  1261. EXPORT_SYMBOL_GPL(macvlan_dellink);
  1262. static int macvlan_changelink(struct net_device *dev,
  1263. struct nlattr *tb[], struct nlattr *data[],
  1264. struct netlink_ext_ack *extack)
  1265. {
  1266. struct macvlan_dev *vlan = netdev_priv(dev);
  1267. enum macvlan_mode mode;
  1268. bool set_mode = false;
  1269. enum macvlan_macaddr_mode macmode;
  1270. int ret;
  1271. /* Validate mode, but don't set yet: setting flags may fail. */
  1272. if (data && data[IFLA_MACVLAN_MODE]) {
  1273. set_mode = true;
  1274. mode = nla_get_u32(data[IFLA_MACVLAN_MODE]);
  1275. /* Passthrough mode can't be set or cleared dynamically */
  1276. if ((mode == MACVLAN_MODE_PASSTHRU) !=
  1277. (vlan->mode == MACVLAN_MODE_PASSTHRU))
  1278. return -EINVAL;
  1279. if (vlan->mode == MACVLAN_MODE_SOURCE &&
  1280. vlan->mode != mode)
  1281. macvlan_flush_sources(vlan->port, vlan);
  1282. }
  1283. if (data && data[IFLA_MACVLAN_FLAGS]) {
  1284. __u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
  1285. bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC;
  1286. if (macvlan_passthru(vlan->port) && promisc) {
  1287. int err;
  1288. if (flags & MACVLAN_FLAG_NOPROMISC)
  1289. err = dev_set_promiscuity(vlan->lowerdev, -1);
  1290. else
  1291. err = dev_set_promiscuity(vlan->lowerdev, 1);
  1292. if (err < 0)
  1293. return err;
  1294. }
  1295. vlan->flags = flags;
  1296. }
  1297. if (set_mode)
  1298. vlan->mode = mode;
  1299. if (data && data[IFLA_MACVLAN_MACADDR_MODE]) {
  1300. if (vlan->mode != MACVLAN_MODE_SOURCE)
  1301. return -EINVAL;
  1302. macmode = nla_get_u32(data[IFLA_MACVLAN_MACADDR_MODE]);
  1303. ret = macvlan_changelink_sources(vlan, macmode, data);
  1304. if (ret)
  1305. return ret;
  1306. }
  1307. return 0;
  1308. }
  1309. static size_t macvlan_get_size_mac(const struct macvlan_dev *vlan)
  1310. {
  1311. if (vlan->macaddr_count == 0)
  1312. return 0;
  1313. return nla_total_size(0) /* IFLA_MACVLAN_MACADDR_DATA */
  1314. + vlan->macaddr_count * nla_total_size(sizeof(u8) * ETH_ALEN);
  1315. }
  1316. static size_t macvlan_get_size(const struct net_device *dev)
  1317. {
  1318. struct macvlan_dev *vlan = netdev_priv(dev);
  1319. return (0
  1320. + nla_total_size(4) /* IFLA_MACVLAN_MODE */
  1321. + nla_total_size(2) /* IFLA_MACVLAN_FLAGS */
  1322. + nla_total_size(4) /* IFLA_MACVLAN_MACADDR_COUNT */
  1323. + macvlan_get_size_mac(vlan) /* IFLA_MACVLAN_MACADDR */
  1324. );
  1325. }
  1326. static int macvlan_fill_info_macaddr(struct sk_buff *skb,
  1327. const struct macvlan_dev *vlan,
  1328. const int i)
  1329. {
  1330. struct hlist_head *h = &vlan->port->vlan_source_hash[i];
  1331. struct macvlan_source_entry *entry;
  1332. hlist_for_each_entry_rcu(entry, h, hlist) {
  1333. if (entry->vlan != vlan)
  1334. continue;
  1335. if (nla_put(skb, IFLA_MACVLAN_MACADDR, ETH_ALEN, entry->addr))
  1336. return 1;
  1337. }
  1338. return 0;
  1339. }
  1340. static int macvlan_fill_info(struct sk_buff *skb,
  1341. const struct net_device *dev)
  1342. {
  1343. struct macvlan_dev *vlan = netdev_priv(dev);
  1344. int i;
  1345. struct nlattr *nest;
  1346. if (nla_put_u32(skb, IFLA_MACVLAN_MODE, vlan->mode))
  1347. goto nla_put_failure;
  1348. if (nla_put_u16(skb, IFLA_MACVLAN_FLAGS, vlan->flags))
  1349. goto nla_put_failure;
  1350. if (nla_put_u32(skb, IFLA_MACVLAN_MACADDR_COUNT, vlan->macaddr_count))
  1351. goto nla_put_failure;
  1352. if (vlan->macaddr_count > 0) {
  1353. nest = nla_nest_start_noflag(skb, IFLA_MACVLAN_MACADDR_DATA);
  1354. if (nest == NULL)
  1355. goto nla_put_failure;
  1356. for (i = 0; i < MACVLAN_HASH_SIZE; i++) {
  1357. if (macvlan_fill_info_macaddr(skb, vlan, i))
  1358. goto nla_put_failure;
  1359. }
  1360. nla_nest_end(skb, nest);
  1361. }
  1362. return 0;
  1363. nla_put_failure:
  1364. return -EMSGSIZE;
  1365. }
  1366. static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
  1367. [IFLA_MACVLAN_MODE] = { .type = NLA_U32 },
  1368. [IFLA_MACVLAN_FLAGS] = { .type = NLA_U16 },
  1369. [IFLA_MACVLAN_MACADDR_MODE] = { .type = NLA_U32 },
  1370. [IFLA_MACVLAN_MACADDR] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
  1371. [IFLA_MACVLAN_MACADDR_DATA] = { .type = NLA_NESTED },
  1372. [IFLA_MACVLAN_MACADDR_COUNT] = { .type = NLA_U32 },
  1373. };
  1374. int macvlan_link_register(struct rtnl_link_ops *ops)
  1375. {
  1376. /* common fields */
  1377. ops->validate = macvlan_validate;
  1378. ops->maxtype = IFLA_MACVLAN_MAX;
  1379. ops->policy = macvlan_policy;
  1380. ops->changelink = macvlan_changelink;
  1381. ops->get_size = macvlan_get_size;
  1382. ops->fill_info = macvlan_fill_info;
  1383. return rtnl_link_register(ops);
  1384. };
  1385. EXPORT_SYMBOL_GPL(macvlan_link_register);
  1386. static struct net *macvlan_get_link_net(const struct net_device *dev)
  1387. {
  1388. return dev_net(macvlan_dev_real_dev(dev));
  1389. }
  1390. static struct rtnl_link_ops macvlan_link_ops = {
  1391. .kind = "macvlan",
  1392. .setup = macvlan_setup,
  1393. .newlink = macvlan_newlink,
  1394. .dellink = macvlan_dellink,
  1395. .get_link_net = macvlan_get_link_net,
  1396. .priv_size = sizeof(struct macvlan_dev),
  1397. };
  1398. static int macvlan_device_event(struct notifier_block *unused,
  1399. unsigned long event, void *ptr)
  1400. {
  1401. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  1402. struct macvlan_dev *vlan, *next;
  1403. struct macvlan_port *port;
  1404. LIST_HEAD(list_kill);
  1405. if (!netif_is_macvlan_port(dev))
  1406. return NOTIFY_DONE;
  1407. port = macvlan_port_get_rtnl(dev);
  1408. switch (event) {
  1409. case NETDEV_UP:
  1410. case NETDEV_DOWN:
  1411. case NETDEV_CHANGE:
  1412. list_for_each_entry(vlan, &port->vlans, list)
  1413. netif_stacked_transfer_operstate(vlan->lowerdev,
  1414. vlan->dev);
  1415. break;
  1416. case NETDEV_FEAT_CHANGE:
  1417. list_for_each_entry(vlan, &port->vlans, list) {
  1418. vlan->dev->gso_max_size = dev->gso_max_size;
  1419. vlan->dev->gso_max_segs = dev->gso_max_segs;
  1420. netdev_update_features(vlan->dev);
  1421. }
  1422. break;
  1423. case NETDEV_CHANGEMTU:
  1424. list_for_each_entry(vlan, &port->vlans, list) {
  1425. if (vlan->dev->mtu <= dev->mtu)
  1426. continue;
  1427. dev_set_mtu(vlan->dev, dev->mtu);
  1428. }
  1429. break;
  1430. case NETDEV_CHANGEADDR:
  1431. if (!macvlan_passthru(port))
  1432. return NOTIFY_DONE;
  1433. vlan = list_first_entry_or_null(&port->vlans,
  1434. struct macvlan_dev,
  1435. list);
  1436. if (vlan && macvlan_sync_address(vlan->dev, dev->dev_addr))
  1437. return NOTIFY_BAD;
  1438. break;
  1439. case NETDEV_UNREGISTER:
  1440. /* twiddle thumbs on netns device moves */
  1441. if (dev->reg_state != NETREG_UNREGISTERING)
  1442. break;
  1443. list_for_each_entry_safe(vlan, next, &port->vlans, list)
  1444. vlan->dev->rtnl_link_ops->dellink(vlan->dev, &list_kill);
  1445. unregister_netdevice_many(&list_kill);
  1446. break;
  1447. case NETDEV_PRE_TYPE_CHANGE:
  1448. /* Forbid underlaying device to change its type. */
  1449. return NOTIFY_BAD;
  1450. case NETDEV_NOTIFY_PEERS:
  1451. case NETDEV_BONDING_FAILOVER:
  1452. case NETDEV_RESEND_IGMP:
  1453. /* Propagate to all vlans */
  1454. list_for_each_entry(vlan, &port->vlans, list)
  1455. call_netdevice_notifiers(event, vlan->dev);
  1456. }
  1457. return NOTIFY_DONE;
  1458. }
  1459. static struct notifier_block macvlan_notifier_block __read_mostly = {
  1460. .notifier_call = macvlan_device_event,
  1461. };
  1462. static int __init macvlan_init_module(void)
  1463. {
  1464. int err;
  1465. register_netdevice_notifier(&macvlan_notifier_block);
  1466. err = macvlan_link_register(&macvlan_link_ops);
  1467. if (err < 0)
  1468. goto err1;
  1469. return 0;
  1470. err1:
  1471. unregister_netdevice_notifier(&macvlan_notifier_block);
  1472. return err;
  1473. }
  1474. static void __exit macvlan_cleanup_module(void)
  1475. {
  1476. rtnl_link_unregister(&macvlan_link_ops);
  1477. unregister_netdevice_notifier(&macvlan_notifier_block);
  1478. }
  1479. module_init(macvlan_init_module);
  1480. module_exit(macvlan_cleanup_module);
  1481. MODULE_LICENSE("GPL");
  1482. MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
  1483. MODULE_DESCRIPTION("Driver for MAC address based VLANs");
  1484. MODULE_ALIAS_RTNL_LINK("macvlan");