macvtap.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. #include <linux/etherdevice.h>
  2. #include <linux/if_macvlan.h>
  3. #include <linux/if_vlan.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/nsproxy.h>
  6. #include <linux/compat.h>
  7. #include <linux/if_tun.h>
  8. #include <linux/module.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/cache.h>
  11. #include <linux/sched.h>
  12. #include <linux/types.h>
  13. #include <linux/slab.h>
  14. #include <linux/wait.h>
  15. #include <linux/cdev.h>
  16. #include <linux/idr.h>
  17. #include <linux/fs.h>
  18. #include <linux/uio.h>
  19. #include <net/ipv6.h>
  20. #include <net/net_namespace.h>
  21. #include <net/rtnetlink.h>
  22. #include <net/sock.h>
  23. #include <linux/virtio_net.h>
  24. /*
  25. * A macvtap queue is the central object of this driver, it connects
  26. * an open character device to a macvlan interface. There can be
  27. * multiple queues on one interface, which map back to queues
  28. * implemented in hardware on the underlying device.
  29. *
  30. * macvtap_proto is used to allocate queues through the sock allocation
  31. * mechanism.
  32. *
  33. */
  34. struct macvtap_queue {
  35. struct sock sk;
  36. struct socket sock;
  37. struct socket_wq wq;
  38. int vnet_hdr_sz;
  39. struct macvlan_dev __rcu *vlan;
  40. struct file *file;
  41. unsigned int flags;
  42. u16 queue_index;
  43. bool enabled;
  44. struct list_head next;
  45. };
  46. #define MACVTAP_FEATURES (IFF_VNET_HDR | IFF_MULTI_QUEUE)
  47. #define MACVTAP_VNET_LE 0x80000000
  48. static inline u16 macvtap16_to_cpu(struct macvtap_queue *q, __virtio16 val)
  49. {
  50. return __virtio16_to_cpu(q->flags & MACVTAP_VNET_LE, val);
  51. }
  52. static inline __virtio16 cpu_to_macvtap16(struct macvtap_queue *q, u16 val)
  53. {
  54. return __cpu_to_virtio16(q->flags & MACVTAP_VNET_LE, val);
  55. }
  56. static struct proto macvtap_proto = {
  57. .name = "macvtap",
  58. .owner = THIS_MODULE,
  59. .obj_size = sizeof (struct macvtap_queue),
  60. };
  61. /*
  62. * Variables for dealing with macvtaps device numbers.
  63. */
  64. static dev_t macvtap_major;
  65. #define MACVTAP_NUM_DEVS (1U << MINORBITS)
  66. static DEFINE_MUTEX(minor_lock);
  67. static DEFINE_IDR(minor_idr);
  68. #define GOODCOPY_LEN 128
  69. static struct class *macvtap_class;
  70. static struct cdev macvtap_cdev;
  71. static const struct proto_ops macvtap_socket_ops;
  72. #define TUN_OFFLOADS (NETIF_F_HW_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \
  73. NETIF_F_TSO6)
  74. #define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)
  75. #define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG)
  76. static struct macvlan_dev *macvtap_get_vlan_rcu(const struct net_device *dev)
  77. {
  78. return rcu_dereference(dev->rx_handler_data);
  79. }
  80. /*
  81. * RCU usage:
  82. * The macvtap_queue and the macvlan_dev are loosely coupled, the
  83. * pointers from one to the other can only be read while rcu_read_lock
  84. * or rtnl is held.
  85. *
  86. * Both the file and the macvlan_dev hold a reference on the macvtap_queue
  87. * through sock_hold(&q->sk). When the macvlan_dev goes away first,
  88. * q->vlan becomes inaccessible. When the files gets closed,
  89. * macvtap_get_queue() fails.
  90. *
  91. * There may still be references to the struct sock inside of the
  92. * queue from outbound SKBs, but these never reference back to the
  93. * file or the dev. The data structure is freed through __sk_free
  94. * when both our references and any pending SKBs are gone.
  95. */
  96. static int macvtap_enable_queue(struct net_device *dev, struct file *file,
  97. struct macvtap_queue *q)
  98. {
  99. struct macvlan_dev *vlan = netdev_priv(dev);
  100. int err = -EINVAL;
  101. ASSERT_RTNL();
  102. if (q->enabled)
  103. goto out;
  104. err = 0;
  105. rcu_assign_pointer(vlan->taps[vlan->numvtaps], q);
  106. q->queue_index = vlan->numvtaps;
  107. q->enabled = true;
  108. vlan->numvtaps++;
  109. out:
  110. return err;
  111. }
  112. /* Requires RTNL */
  113. static int macvtap_set_queue(struct net_device *dev, struct file *file,
  114. struct macvtap_queue *q)
  115. {
  116. struct macvlan_dev *vlan = netdev_priv(dev);
  117. if (vlan->numqueues == MAX_MACVTAP_QUEUES)
  118. return -EBUSY;
  119. rcu_assign_pointer(q->vlan, vlan);
  120. rcu_assign_pointer(vlan->taps[vlan->numvtaps], q);
  121. sock_hold(&q->sk);
  122. q->file = file;
  123. q->queue_index = vlan->numvtaps;
  124. q->enabled = true;
  125. file->private_data = q;
  126. list_add_tail(&q->next, &vlan->queue_list);
  127. vlan->numvtaps++;
  128. vlan->numqueues++;
  129. return 0;
  130. }
  131. static int macvtap_disable_queue(struct macvtap_queue *q)
  132. {
  133. struct macvlan_dev *vlan;
  134. struct macvtap_queue *nq;
  135. ASSERT_RTNL();
  136. if (!q->enabled)
  137. return -EINVAL;
  138. vlan = rtnl_dereference(q->vlan);
  139. if (vlan) {
  140. int index = q->queue_index;
  141. BUG_ON(index >= vlan->numvtaps);
  142. nq = rtnl_dereference(vlan->taps[vlan->numvtaps - 1]);
  143. nq->queue_index = index;
  144. rcu_assign_pointer(vlan->taps[index], nq);
  145. RCU_INIT_POINTER(vlan->taps[vlan->numvtaps - 1], NULL);
  146. q->enabled = false;
  147. vlan->numvtaps--;
  148. }
  149. return 0;
  150. }
  151. /*
  152. * The file owning the queue got closed, give up both
  153. * the reference that the files holds as well as the
  154. * one from the macvlan_dev if that still exists.
  155. *
  156. * Using the spinlock makes sure that we don't get
  157. * to the queue again after destroying it.
  158. */
  159. static void macvtap_put_queue(struct macvtap_queue *q)
  160. {
  161. struct macvlan_dev *vlan;
  162. rtnl_lock();
  163. vlan = rtnl_dereference(q->vlan);
  164. if (vlan) {
  165. if (q->enabled)
  166. BUG_ON(macvtap_disable_queue(q));
  167. vlan->numqueues--;
  168. RCU_INIT_POINTER(q->vlan, NULL);
  169. sock_put(&q->sk);
  170. list_del_init(&q->next);
  171. }
  172. rtnl_unlock();
  173. synchronize_rcu();
  174. sock_put(&q->sk);
  175. }
  176. /*
  177. * Select a queue based on the rxq of the device on which this packet
  178. * arrived. If the incoming device is not mq, calculate a flow hash
  179. * to select a queue. If all fails, find the first available queue.
  180. * Cache vlan->numvtaps since it can become zero during the execution
  181. * of this function.
  182. */
  183. static struct macvtap_queue *macvtap_get_queue(struct net_device *dev,
  184. struct sk_buff *skb)
  185. {
  186. struct macvlan_dev *vlan = netdev_priv(dev);
  187. struct macvtap_queue *tap = NULL;
  188. /* Access to taps array is protected by rcu, but access to numvtaps
  189. * isn't. Below we use it to lookup a queue, but treat it as a hint
  190. * and validate that the result isn't NULL - in case we are
  191. * racing against queue removal.
  192. */
  193. int numvtaps = ACCESS_ONCE(vlan->numvtaps);
  194. __u32 rxq;
  195. if (!numvtaps)
  196. goto out;
  197. /* Check if we can use flow to select a queue */
  198. rxq = skb_get_hash(skb);
  199. if (rxq) {
  200. tap = rcu_dereference(vlan->taps[rxq % numvtaps]);
  201. goto out;
  202. }
  203. if (likely(skb_rx_queue_recorded(skb))) {
  204. rxq = skb_get_rx_queue(skb);
  205. while (unlikely(rxq >= numvtaps))
  206. rxq -= numvtaps;
  207. tap = rcu_dereference(vlan->taps[rxq]);
  208. goto out;
  209. }
  210. tap = rcu_dereference(vlan->taps[0]);
  211. out:
  212. return tap;
  213. }
  214. /*
  215. * The net_device is going away, give up the reference
  216. * that it holds on all queues and safely set the pointer
  217. * from the queues to NULL.
  218. */
  219. static void macvtap_del_queues(struct net_device *dev)
  220. {
  221. struct macvlan_dev *vlan = netdev_priv(dev);
  222. struct macvtap_queue *q, *tmp, *qlist[MAX_MACVTAP_QUEUES];
  223. int i, j = 0;
  224. ASSERT_RTNL();
  225. list_for_each_entry_safe(q, tmp, &vlan->queue_list, next) {
  226. list_del_init(&q->next);
  227. qlist[j++] = q;
  228. RCU_INIT_POINTER(q->vlan, NULL);
  229. if (q->enabled)
  230. vlan->numvtaps--;
  231. vlan->numqueues--;
  232. }
  233. for (i = 0; i < vlan->numvtaps; i++)
  234. RCU_INIT_POINTER(vlan->taps[i], NULL);
  235. BUG_ON(vlan->numvtaps);
  236. BUG_ON(vlan->numqueues);
  237. /* guarantee that any future macvtap_set_queue will fail */
  238. vlan->numvtaps = MAX_MACVTAP_QUEUES;
  239. for (--j; j >= 0; j--)
  240. sock_put(&qlist[j]->sk);
  241. }
  242. static rx_handler_result_t macvtap_handle_frame(struct sk_buff **pskb)
  243. {
  244. struct sk_buff *skb = *pskb;
  245. struct net_device *dev = skb->dev;
  246. struct macvlan_dev *vlan;
  247. struct macvtap_queue *q;
  248. netdev_features_t features = TAP_FEATURES;
  249. vlan = macvtap_get_vlan_rcu(dev);
  250. if (!vlan)
  251. return RX_HANDLER_PASS;
  252. q = macvtap_get_queue(dev, skb);
  253. if (!q)
  254. return RX_HANDLER_PASS;
  255. if (skb_queue_len(&q->sk.sk_receive_queue) >= dev->tx_queue_len)
  256. goto drop;
  257. skb_push(skb, ETH_HLEN);
  258. /* Apply the forward feature mask so that we perform segmentation
  259. * according to users wishes. This only works if VNET_HDR is
  260. * enabled.
  261. */
  262. if (q->flags & IFF_VNET_HDR)
  263. features |= vlan->tap_features;
  264. if (netif_needs_gso(dev, skb, features)) {
  265. struct sk_buff *segs = __skb_gso_segment(skb, features, false);
  266. if (IS_ERR(segs))
  267. goto drop;
  268. if (!segs) {
  269. skb_queue_tail(&q->sk.sk_receive_queue, skb);
  270. goto wake_up;
  271. }
  272. kfree_skb(skb);
  273. while (segs) {
  274. struct sk_buff *nskb = segs->next;
  275. segs->next = NULL;
  276. skb_queue_tail(&q->sk.sk_receive_queue, segs);
  277. segs = nskb;
  278. }
  279. } else {
  280. /* If we receive a partial checksum and the tap side
  281. * doesn't support checksum offload, compute the checksum.
  282. * Note: it doesn't matter which checksum feature to
  283. * check, we either support them all or none.
  284. */
  285. if (skb->ip_summed == CHECKSUM_PARTIAL &&
  286. !(features & NETIF_F_ALL_CSUM) &&
  287. skb_checksum_help(skb))
  288. goto drop;
  289. skb_queue_tail(&q->sk.sk_receive_queue, skb);
  290. }
  291. wake_up:
  292. wake_up_interruptible_poll(sk_sleep(&q->sk), POLLIN | POLLRDNORM | POLLRDBAND);
  293. return RX_HANDLER_CONSUMED;
  294. drop:
  295. /* Count errors/drops only here, thus don't care about args. */
  296. macvlan_count_rx(vlan, 0, 0, 0);
  297. kfree_skb(skb);
  298. return RX_HANDLER_CONSUMED;
  299. }
  300. static int macvtap_get_minor(struct macvlan_dev *vlan)
  301. {
  302. int retval = -ENOMEM;
  303. mutex_lock(&minor_lock);
  304. retval = idr_alloc(&minor_idr, vlan, 1, MACVTAP_NUM_DEVS, GFP_KERNEL);
  305. if (retval >= 0) {
  306. vlan->minor = retval;
  307. } else if (retval == -ENOSPC) {
  308. printk(KERN_ERR "too many macvtap devices\n");
  309. retval = -EINVAL;
  310. }
  311. mutex_unlock(&minor_lock);
  312. return retval < 0 ? retval : 0;
  313. }
  314. static void macvtap_free_minor(struct macvlan_dev *vlan)
  315. {
  316. mutex_lock(&minor_lock);
  317. if (vlan->minor) {
  318. idr_remove(&minor_idr, vlan->minor);
  319. vlan->minor = 0;
  320. }
  321. mutex_unlock(&minor_lock);
  322. }
  323. static struct net_device *dev_get_by_macvtap_minor(int minor)
  324. {
  325. struct net_device *dev = NULL;
  326. struct macvlan_dev *vlan;
  327. mutex_lock(&minor_lock);
  328. vlan = idr_find(&minor_idr, minor);
  329. if (vlan) {
  330. dev = vlan->dev;
  331. dev_hold(dev);
  332. }
  333. mutex_unlock(&minor_lock);
  334. return dev;
  335. }
  336. static int macvtap_newlink(struct net *src_net,
  337. struct net_device *dev,
  338. struct nlattr *tb[],
  339. struct nlattr *data[])
  340. {
  341. struct macvlan_dev *vlan = netdev_priv(dev);
  342. int err;
  343. INIT_LIST_HEAD(&vlan->queue_list);
  344. /* Since macvlan supports all offloads by default, make
  345. * tap support all offloads also.
  346. */
  347. vlan->tap_features = TUN_OFFLOADS;
  348. err = netdev_rx_handler_register(dev, macvtap_handle_frame, vlan);
  349. if (err)
  350. return err;
  351. /* Don't put anything that may fail after macvlan_common_newlink
  352. * because we can't undo what it does.
  353. */
  354. return macvlan_common_newlink(src_net, dev, tb, data);
  355. }
  356. static void macvtap_dellink(struct net_device *dev,
  357. struct list_head *head)
  358. {
  359. netdev_rx_handler_unregister(dev);
  360. macvtap_del_queues(dev);
  361. macvlan_dellink(dev, head);
  362. }
  363. static void macvtap_setup(struct net_device *dev)
  364. {
  365. macvlan_common_setup(dev);
  366. dev->tx_queue_len = TUN_READQ_SIZE;
  367. }
  368. static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
  369. .kind = "macvtap",
  370. .setup = macvtap_setup,
  371. .newlink = macvtap_newlink,
  372. .dellink = macvtap_dellink,
  373. };
  374. static void macvtap_sock_write_space(struct sock *sk)
  375. {
  376. wait_queue_head_t *wqueue;
  377. if (!sock_writeable(sk) ||
  378. !test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags))
  379. return;
  380. wqueue = sk_sleep(sk);
  381. if (wqueue && waitqueue_active(wqueue))
  382. wake_up_interruptible_poll(wqueue, POLLOUT | POLLWRNORM | POLLWRBAND);
  383. }
  384. static void macvtap_sock_destruct(struct sock *sk)
  385. {
  386. skb_queue_purge(&sk->sk_receive_queue);
  387. }
  388. static int macvtap_open(struct inode *inode, struct file *file)
  389. {
  390. struct net *net = current->nsproxy->net_ns;
  391. struct net_device *dev;
  392. struct macvtap_queue *q;
  393. int err = -ENODEV;
  394. rtnl_lock();
  395. dev = dev_get_by_macvtap_minor(iminor(inode));
  396. if (!dev)
  397. goto out;
  398. err = -ENOMEM;
  399. q = (struct macvtap_queue *)sk_alloc(net, AF_UNSPEC, GFP_KERNEL,
  400. &macvtap_proto);
  401. if (!q)
  402. goto out;
  403. RCU_INIT_POINTER(q->sock.wq, &q->wq);
  404. init_waitqueue_head(&q->wq.wait);
  405. q->sock.type = SOCK_RAW;
  406. q->sock.state = SS_CONNECTED;
  407. q->sock.file = file;
  408. q->sock.ops = &macvtap_socket_ops;
  409. sock_init_data(&q->sock, &q->sk);
  410. q->sk.sk_write_space = macvtap_sock_write_space;
  411. q->sk.sk_destruct = macvtap_sock_destruct;
  412. q->flags = IFF_VNET_HDR | IFF_NO_PI | IFF_TAP;
  413. q->vnet_hdr_sz = sizeof(struct virtio_net_hdr);
  414. /*
  415. * so far only KVM virtio_net uses macvtap, enable zero copy between
  416. * guest kernel and host kernel when lower device supports zerocopy
  417. *
  418. * The macvlan supports zerocopy iff the lower device supports zero
  419. * copy so we don't have to look at the lower device directly.
  420. */
  421. if ((dev->features & NETIF_F_HIGHDMA) && (dev->features & NETIF_F_SG))
  422. sock_set_flag(&q->sk, SOCK_ZEROCOPY);
  423. err = macvtap_set_queue(dev, file, q);
  424. if (err)
  425. sock_put(&q->sk);
  426. out:
  427. if (dev)
  428. dev_put(dev);
  429. rtnl_unlock();
  430. return err;
  431. }
  432. static int macvtap_release(struct inode *inode, struct file *file)
  433. {
  434. struct macvtap_queue *q = file->private_data;
  435. macvtap_put_queue(q);
  436. return 0;
  437. }
  438. static unsigned int macvtap_poll(struct file *file, poll_table * wait)
  439. {
  440. struct macvtap_queue *q = file->private_data;
  441. unsigned int mask = POLLERR;
  442. if (!q)
  443. goto out;
  444. mask = 0;
  445. poll_wait(file, &q->wq.wait, wait);
  446. if (!skb_queue_empty(&q->sk.sk_receive_queue))
  447. mask |= POLLIN | POLLRDNORM;
  448. if (sock_writeable(&q->sk) ||
  449. (!test_and_set_bit(SOCK_ASYNC_NOSPACE, &q->sock.flags) &&
  450. sock_writeable(&q->sk)))
  451. mask |= POLLOUT | POLLWRNORM;
  452. out:
  453. return mask;
  454. }
  455. static inline struct sk_buff *macvtap_alloc_skb(struct sock *sk, size_t prepad,
  456. size_t len, size_t linear,
  457. int noblock, int *err)
  458. {
  459. struct sk_buff *skb;
  460. /* Under a page? Don't bother with paged skb. */
  461. if (prepad + len < PAGE_SIZE || !linear)
  462. linear = len;
  463. skb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,
  464. err, 0);
  465. if (!skb)
  466. return NULL;
  467. skb_reserve(skb, prepad);
  468. skb_put(skb, linear);
  469. skb->data_len = len - linear;
  470. skb->len += len - linear;
  471. return skb;
  472. }
  473. /*
  474. * macvtap_skb_from_vnet_hdr and macvtap_skb_to_vnet_hdr should
  475. * be shared with the tun/tap driver.
  476. */
  477. static int macvtap_skb_from_vnet_hdr(struct macvtap_queue *q,
  478. struct sk_buff *skb,
  479. struct virtio_net_hdr *vnet_hdr)
  480. {
  481. unsigned short gso_type = 0;
  482. if (vnet_hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
  483. switch (vnet_hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
  484. case VIRTIO_NET_HDR_GSO_TCPV4:
  485. gso_type = SKB_GSO_TCPV4;
  486. break;
  487. case VIRTIO_NET_HDR_GSO_TCPV6:
  488. gso_type = SKB_GSO_TCPV6;
  489. break;
  490. case VIRTIO_NET_HDR_GSO_UDP:
  491. pr_warn_once("macvtap: %s: using disabled UFO feature; please fix this program\n",
  492. current->comm);
  493. gso_type = SKB_GSO_UDP;
  494. if (skb->protocol == htons(ETH_P_IPV6))
  495. ipv6_proxy_select_ident(skb);
  496. break;
  497. default:
  498. return -EINVAL;
  499. }
  500. if (vnet_hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN)
  501. gso_type |= SKB_GSO_TCP_ECN;
  502. if (vnet_hdr->gso_size == 0)
  503. return -EINVAL;
  504. }
  505. if (vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
  506. if (!skb_partial_csum_set(skb, macvtap16_to_cpu(q, vnet_hdr->csum_start),
  507. macvtap16_to_cpu(q, vnet_hdr->csum_offset)))
  508. return -EINVAL;
  509. }
  510. if (vnet_hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
  511. skb_shinfo(skb)->gso_size = macvtap16_to_cpu(q, vnet_hdr->gso_size);
  512. skb_shinfo(skb)->gso_type = gso_type;
  513. /* Header must be checked, and gso_segs computed. */
  514. skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
  515. skb_shinfo(skb)->gso_segs = 0;
  516. }
  517. return 0;
  518. }
  519. static void macvtap_skb_to_vnet_hdr(struct macvtap_queue *q,
  520. const struct sk_buff *skb,
  521. struct virtio_net_hdr *vnet_hdr)
  522. {
  523. memset(vnet_hdr, 0, sizeof(*vnet_hdr));
  524. if (skb_is_gso(skb)) {
  525. struct skb_shared_info *sinfo = skb_shinfo(skb);
  526. /* This is a hint as to how much should be linear. */
  527. vnet_hdr->hdr_len = cpu_to_macvtap16(q, skb_headlen(skb));
  528. vnet_hdr->gso_size = cpu_to_macvtap16(q, sinfo->gso_size);
  529. if (sinfo->gso_type & SKB_GSO_TCPV4)
  530. vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
  531. else if (sinfo->gso_type & SKB_GSO_TCPV6)
  532. vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
  533. else
  534. BUG();
  535. if (sinfo->gso_type & SKB_GSO_TCP_ECN)
  536. vnet_hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN;
  537. } else
  538. vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
  539. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  540. vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
  541. if (vlan_tx_tag_present(skb))
  542. vnet_hdr->csum_start = cpu_to_macvtap16(q,
  543. skb_checksum_start_offset(skb) + VLAN_HLEN);
  544. else
  545. vnet_hdr->csum_start = cpu_to_macvtap16(q,
  546. skb_checksum_start_offset(skb));
  547. vnet_hdr->csum_offset = cpu_to_macvtap16(q, skb->csum_offset);
  548. } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
  549. vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
  550. } /* else everything is zero */
  551. }
  552. /* Get packet from user space buffer */
  553. static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
  554. struct iov_iter *from, int noblock)
  555. {
  556. int good_linear = SKB_MAX_HEAD(NET_IP_ALIGN);
  557. struct sk_buff *skb;
  558. struct macvlan_dev *vlan;
  559. unsigned long total_len = iov_iter_count(from);
  560. unsigned long len = total_len;
  561. int err;
  562. struct virtio_net_hdr vnet_hdr = { 0 };
  563. int vnet_hdr_len = 0;
  564. int copylen = 0;
  565. bool zerocopy = false;
  566. size_t linear;
  567. ssize_t n;
  568. if (q->flags & IFF_VNET_HDR) {
  569. vnet_hdr_len = q->vnet_hdr_sz;
  570. err = -EINVAL;
  571. if (len < vnet_hdr_len)
  572. goto err;
  573. len -= vnet_hdr_len;
  574. err = -EFAULT;
  575. n = copy_from_iter(&vnet_hdr, sizeof(vnet_hdr), from);
  576. if (n != sizeof(vnet_hdr))
  577. goto err;
  578. iov_iter_advance(from, vnet_hdr_len - sizeof(vnet_hdr));
  579. if ((vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
  580. macvtap16_to_cpu(q, vnet_hdr.csum_start) +
  581. macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2 >
  582. macvtap16_to_cpu(q, vnet_hdr.hdr_len))
  583. vnet_hdr.hdr_len = cpu_to_macvtap16(q,
  584. macvtap16_to_cpu(q, vnet_hdr.csum_start) +
  585. macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2);
  586. err = -EINVAL;
  587. if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > len)
  588. goto err;
  589. }
  590. err = -EINVAL;
  591. if (unlikely(len < ETH_HLEN))
  592. goto err;
  593. if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
  594. struct iov_iter i;
  595. copylen = vnet_hdr.hdr_len ?
  596. macvtap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN;
  597. if (copylen > good_linear)
  598. copylen = good_linear;
  599. linear = copylen;
  600. i = *from;
  601. iov_iter_advance(&i, copylen);
  602. if (iov_iter_npages(&i, INT_MAX) <= MAX_SKB_FRAGS)
  603. zerocopy = true;
  604. }
  605. if (!zerocopy) {
  606. copylen = len;
  607. if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > good_linear)
  608. linear = good_linear;
  609. else
  610. linear = macvtap16_to_cpu(q, vnet_hdr.hdr_len);
  611. }
  612. skb = macvtap_alloc_skb(&q->sk, NET_IP_ALIGN, copylen,
  613. linear, noblock, &err);
  614. if (!skb)
  615. goto err;
  616. if (zerocopy)
  617. err = zerocopy_sg_from_iter(skb, from);
  618. else {
  619. err = skb_copy_datagram_from_iter(skb, 0, from, len);
  620. if (!err && m && m->msg_control) {
  621. struct ubuf_info *uarg = m->msg_control;
  622. uarg->callback(uarg, false);
  623. }
  624. }
  625. if (err)
  626. goto err_kfree;
  627. skb_set_network_header(skb, ETH_HLEN);
  628. skb_reset_mac_header(skb);
  629. skb->protocol = eth_hdr(skb)->h_proto;
  630. if (vnet_hdr_len) {
  631. err = macvtap_skb_from_vnet_hdr(q, skb, &vnet_hdr);
  632. if (err)
  633. goto err_kfree;
  634. }
  635. skb_probe_transport_header(skb, ETH_HLEN);
  636. rcu_read_lock();
  637. vlan = rcu_dereference(q->vlan);
  638. /* copy skb_ubuf_info for callback when skb has no error */
  639. if (zerocopy) {
  640. skb_shinfo(skb)->destructor_arg = m->msg_control;
  641. skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
  642. skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
  643. }
  644. if (vlan) {
  645. skb->dev = vlan->dev;
  646. dev_queue_xmit(skb);
  647. } else {
  648. kfree_skb(skb);
  649. }
  650. rcu_read_unlock();
  651. return total_len;
  652. err_kfree:
  653. kfree_skb(skb);
  654. err:
  655. rcu_read_lock();
  656. vlan = rcu_dereference(q->vlan);
  657. if (vlan)
  658. this_cpu_inc(vlan->pcpu_stats->tx_dropped);
  659. rcu_read_unlock();
  660. return err;
  661. }
  662. static ssize_t macvtap_write_iter(struct kiocb *iocb, struct iov_iter *from)
  663. {
  664. struct file *file = iocb->ki_filp;
  665. struct macvtap_queue *q = file->private_data;
  666. return macvtap_get_user(q, NULL, from, file->f_flags & O_NONBLOCK);
  667. }
  668. /* Put packet to the user space buffer */
  669. static ssize_t macvtap_put_user(struct macvtap_queue *q,
  670. const struct sk_buff *skb,
  671. struct iov_iter *iter)
  672. {
  673. int ret;
  674. int vnet_hdr_len = 0;
  675. int vlan_offset = 0;
  676. int total;
  677. if (q->flags & IFF_VNET_HDR) {
  678. struct virtio_net_hdr vnet_hdr;
  679. vnet_hdr_len = q->vnet_hdr_sz;
  680. if (iov_iter_count(iter) < vnet_hdr_len)
  681. return -EINVAL;
  682. macvtap_skb_to_vnet_hdr(q, skb, &vnet_hdr);
  683. if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
  684. sizeof(vnet_hdr))
  685. return -EFAULT;
  686. iov_iter_advance(iter, vnet_hdr_len - sizeof(vnet_hdr));
  687. }
  688. total = vnet_hdr_len;
  689. total += skb->len;
  690. if (vlan_tx_tag_present(skb)) {
  691. struct {
  692. __be16 h_vlan_proto;
  693. __be16 h_vlan_TCI;
  694. } veth;
  695. veth.h_vlan_proto = skb->vlan_proto;
  696. veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb));
  697. vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
  698. total += VLAN_HLEN;
  699. ret = skb_copy_datagram_iter(skb, 0, iter, vlan_offset);
  700. if (ret || !iov_iter_count(iter))
  701. goto done;
  702. ret = copy_to_iter(&veth, sizeof(veth), iter);
  703. if (ret != sizeof(veth) || !iov_iter_count(iter))
  704. goto done;
  705. }
  706. ret = skb_copy_datagram_iter(skb, vlan_offset, iter,
  707. skb->len - vlan_offset);
  708. done:
  709. return ret ? ret : total;
  710. }
  711. static ssize_t macvtap_do_read(struct macvtap_queue *q,
  712. struct iov_iter *to,
  713. int noblock)
  714. {
  715. DEFINE_WAIT(wait);
  716. struct sk_buff *skb;
  717. ssize_t ret = 0;
  718. if (!iov_iter_count(to))
  719. return 0;
  720. while (1) {
  721. if (!noblock)
  722. prepare_to_wait(sk_sleep(&q->sk), &wait,
  723. TASK_INTERRUPTIBLE);
  724. /* Read frames from the queue */
  725. skb = skb_dequeue(&q->sk.sk_receive_queue);
  726. if (skb)
  727. break;
  728. if (noblock) {
  729. ret = -EAGAIN;
  730. break;
  731. }
  732. if (signal_pending(current)) {
  733. ret = -ERESTARTSYS;
  734. break;
  735. }
  736. /* Nothing to read, let's sleep */
  737. schedule();
  738. }
  739. if (skb) {
  740. ret = macvtap_put_user(q, skb, to);
  741. if (unlikely(ret < 0))
  742. kfree_skb(skb);
  743. else
  744. consume_skb(skb);
  745. }
  746. if (!noblock)
  747. finish_wait(sk_sleep(&q->sk), &wait);
  748. return ret;
  749. }
  750. static ssize_t macvtap_read_iter(struct kiocb *iocb, struct iov_iter *to)
  751. {
  752. struct file *file = iocb->ki_filp;
  753. struct macvtap_queue *q = file->private_data;
  754. ssize_t len = iov_iter_count(to), ret;
  755. ret = macvtap_do_read(q, to, file->f_flags & O_NONBLOCK);
  756. ret = min_t(ssize_t, ret, len);
  757. if (ret > 0)
  758. iocb->ki_pos = ret;
  759. return ret;
  760. }
  761. static struct macvlan_dev *macvtap_get_vlan(struct macvtap_queue *q)
  762. {
  763. struct macvlan_dev *vlan;
  764. ASSERT_RTNL();
  765. vlan = rtnl_dereference(q->vlan);
  766. if (vlan)
  767. dev_hold(vlan->dev);
  768. return vlan;
  769. }
  770. static void macvtap_put_vlan(struct macvlan_dev *vlan)
  771. {
  772. dev_put(vlan->dev);
  773. }
  774. static int macvtap_ioctl_set_queue(struct file *file, unsigned int flags)
  775. {
  776. struct macvtap_queue *q = file->private_data;
  777. struct macvlan_dev *vlan;
  778. int ret;
  779. vlan = macvtap_get_vlan(q);
  780. if (!vlan)
  781. return -EINVAL;
  782. if (flags & IFF_ATTACH_QUEUE)
  783. ret = macvtap_enable_queue(vlan->dev, file, q);
  784. else if (flags & IFF_DETACH_QUEUE)
  785. ret = macvtap_disable_queue(q);
  786. else
  787. ret = -EINVAL;
  788. macvtap_put_vlan(vlan);
  789. return ret;
  790. }
  791. static int set_offload(struct macvtap_queue *q, unsigned long arg)
  792. {
  793. struct macvlan_dev *vlan;
  794. netdev_features_t features;
  795. netdev_features_t feature_mask = 0;
  796. vlan = rtnl_dereference(q->vlan);
  797. if (!vlan)
  798. return -ENOLINK;
  799. features = vlan->dev->features;
  800. if (arg & TUN_F_CSUM) {
  801. feature_mask = NETIF_F_HW_CSUM;
  802. if (arg & (TUN_F_TSO4 | TUN_F_TSO6)) {
  803. if (arg & TUN_F_TSO_ECN)
  804. feature_mask |= NETIF_F_TSO_ECN;
  805. if (arg & TUN_F_TSO4)
  806. feature_mask |= NETIF_F_TSO;
  807. if (arg & TUN_F_TSO6)
  808. feature_mask |= NETIF_F_TSO6;
  809. }
  810. }
  811. /* tun/tap driver inverts the usage for TSO offloads, where
  812. * setting the TSO bit means that the userspace wants to
  813. * accept TSO frames and turning it off means that user space
  814. * does not support TSO.
  815. * For macvtap, we have to invert it to mean the same thing.
  816. * When user space turns off TSO, we turn off GSO/LRO so that
  817. * user-space will not receive TSO frames.
  818. */
  819. if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6))
  820. features |= RX_OFFLOADS;
  821. else
  822. features &= ~RX_OFFLOADS;
  823. /* tap_features are the same as features on tun/tap and
  824. * reflect user expectations.
  825. */
  826. vlan->tap_features = feature_mask;
  827. vlan->set_features = features;
  828. netdev_update_features(vlan->dev);
  829. return 0;
  830. }
  831. /*
  832. * provide compatibility with generic tun/tap interface
  833. */
  834. static long macvtap_ioctl(struct file *file, unsigned int cmd,
  835. unsigned long arg)
  836. {
  837. struct macvtap_queue *q = file->private_data;
  838. struct macvlan_dev *vlan;
  839. void __user *argp = (void __user *)arg;
  840. struct ifreq __user *ifr = argp;
  841. unsigned int __user *up = argp;
  842. unsigned short u;
  843. int __user *sp = argp;
  844. int s;
  845. int ret;
  846. switch (cmd) {
  847. case TUNSETIFF:
  848. /* ignore the name, just look at flags */
  849. if (get_user(u, &ifr->ifr_flags))
  850. return -EFAULT;
  851. ret = 0;
  852. if ((u & ~MACVTAP_FEATURES) != (IFF_NO_PI | IFF_TAP))
  853. ret = -EINVAL;
  854. else
  855. q->flags = (q->flags & ~MACVTAP_FEATURES) | u;
  856. return ret;
  857. case TUNGETIFF:
  858. rtnl_lock();
  859. vlan = macvtap_get_vlan(q);
  860. if (!vlan) {
  861. rtnl_unlock();
  862. return -ENOLINK;
  863. }
  864. ret = 0;
  865. u = q->flags;
  866. if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
  867. put_user(u, &ifr->ifr_flags))
  868. ret = -EFAULT;
  869. macvtap_put_vlan(vlan);
  870. rtnl_unlock();
  871. return ret;
  872. case TUNSETQUEUE:
  873. if (get_user(u, &ifr->ifr_flags))
  874. return -EFAULT;
  875. rtnl_lock();
  876. ret = macvtap_ioctl_set_queue(file, u);
  877. rtnl_unlock();
  878. return ret;
  879. case TUNGETFEATURES:
  880. if (put_user(IFF_TAP | IFF_NO_PI | MACVTAP_FEATURES, up))
  881. return -EFAULT;
  882. return 0;
  883. case TUNSETSNDBUF:
  884. if (get_user(u, up))
  885. return -EFAULT;
  886. q->sk.sk_sndbuf = u;
  887. return 0;
  888. case TUNGETVNETHDRSZ:
  889. s = q->vnet_hdr_sz;
  890. if (put_user(s, sp))
  891. return -EFAULT;
  892. return 0;
  893. case TUNSETVNETHDRSZ:
  894. if (get_user(s, sp))
  895. return -EFAULT;
  896. if (s < (int)sizeof(struct virtio_net_hdr))
  897. return -EINVAL;
  898. q->vnet_hdr_sz = s;
  899. return 0;
  900. case TUNGETVNETLE:
  901. s = !!(q->flags & MACVTAP_VNET_LE);
  902. if (put_user(s, sp))
  903. return -EFAULT;
  904. return 0;
  905. case TUNSETVNETLE:
  906. if (get_user(s, sp))
  907. return -EFAULT;
  908. if (s)
  909. q->flags |= MACVTAP_VNET_LE;
  910. else
  911. q->flags &= ~MACVTAP_VNET_LE;
  912. return 0;
  913. case TUNSETOFFLOAD:
  914. /* let the user check for future flags */
  915. if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 |
  916. TUN_F_TSO_ECN))
  917. return -EINVAL;
  918. rtnl_lock();
  919. ret = set_offload(q, arg);
  920. rtnl_unlock();
  921. return ret;
  922. default:
  923. return -EINVAL;
  924. }
  925. }
  926. #ifdef CONFIG_COMPAT
  927. static long macvtap_compat_ioctl(struct file *file, unsigned int cmd,
  928. unsigned long arg)
  929. {
  930. return macvtap_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
  931. }
  932. #endif
  933. static const struct file_operations macvtap_fops = {
  934. .owner = THIS_MODULE,
  935. .open = macvtap_open,
  936. .release = macvtap_release,
  937. .read = new_sync_read,
  938. .write = new_sync_write,
  939. .read_iter = macvtap_read_iter,
  940. .write_iter = macvtap_write_iter,
  941. .poll = macvtap_poll,
  942. .llseek = no_llseek,
  943. .unlocked_ioctl = macvtap_ioctl,
  944. #ifdef CONFIG_COMPAT
  945. .compat_ioctl = macvtap_compat_ioctl,
  946. #endif
  947. };
  948. static int macvtap_sendmsg(struct kiocb *iocb, struct socket *sock,
  949. struct msghdr *m, size_t total_len)
  950. {
  951. struct macvtap_queue *q = container_of(sock, struct macvtap_queue, sock);
  952. return macvtap_get_user(q, m, &m->msg_iter, m->msg_flags & MSG_DONTWAIT);
  953. }
  954. static int macvtap_recvmsg(struct kiocb *iocb, struct socket *sock,
  955. struct msghdr *m, size_t total_len,
  956. int flags)
  957. {
  958. struct macvtap_queue *q = container_of(sock, struct macvtap_queue, sock);
  959. int ret;
  960. if (flags & ~(MSG_DONTWAIT|MSG_TRUNC))
  961. return -EINVAL;
  962. ret = macvtap_do_read(q, &m->msg_iter, flags & MSG_DONTWAIT);
  963. if (ret > total_len) {
  964. m->msg_flags |= MSG_TRUNC;
  965. ret = flags & MSG_TRUNC ? ret : total_len;
  966. }
  967. return ret;
  968. }
  969. /* Ops structure to mimic raw sockets with tun */
  970. static const struct proto_ops macvtap_socket_ops = {
  971. .sendmsg = macvtap_sendmsg,
  972. .recvmsg = macvtap_recvmsg,
  973. };
  974. /* Get an underlying socket object from tun file. Returns error unless file is
  975. * attached to a device. The returned object works like a packet socket, it
  976. * can be used for sock_sendmsg/sock_recvmsg. The caller is responsible for
  977. * holding a reference to the file for as long as the socket is in use. */
  978. struct socket *macvtap_get_socket(struct file *file)
  979. {
  980. struct macvtap_queue *q;
  981. if (file->f_op != &macvtap_fops)
  982. return ERR_PTR(-EINVAL);
  983. q = file->private_data;
  984. if (!q)
  985. return ERR_PTR(-EBADFD);
  986. return &q->sock;
  987. }
  988. EXPORT_SYMBOL_GPL(macvtap_get_socket);
  989. static int macvtap_device_event(struct notifier_block *unused,
  990. unsigned long event, void *ptr)
  991. {
  992. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  993. struct macvlan_dev *vlan;
  994. struct device *classdev;
  995. dev_t devt;
  996. int err;
  997. if (dev->rtnl_link_ops != &macvtap_link_ops)
  998. return NOTIFY_DONE;
  999. vlan = netdev_priv(dev);
  1000. switch (event) {
  1001. case NETDEV_REGISTER:
  1002. /* Create the device node here after the network device has
  1003. * been registered but before register_netdevice has
  1004. * finished running.
  1005. */
  1006. err = macvtap_get_minor(vlan);
  1007. if (err)
  1008. return notifier_from_errno(err);
  1009. devt = MKDEV(MAJOR(macvtap_major), vlan->minor);
  1010. classdev = device_create(macvtap_class, &dev->dev, devt,
  1011. dev, "tap%d", dev->ifindex);
  1012. if (IS_ERR(classdev)) {
  1013. macvtap_free_minor(vlan);
  1014. return notifier_from_errno(PTR_ERR(classdev));
  1015. }
  1016. break;
  1017. case NETDEV_UNREGISTER:
  1018. devt = MKDEV(MAJOR(macvtap_major), vlan->minor);
  1019. device_destroy(macvtap_class, devt);
  1020. macvtap_free_minor(vlan);
  1021. break;
  1022. }
  1023. return NOTIFY_DONE;
  1024. }
  1025. static struct notifier_block macvtap_notifier_block __read_mostly = {
  1026. .notifier_call = macvtap_device_event,
  1027. };
  1028. static int macvtap_init(void)
  1029. {
  1030. int err;
  1031. err = alloc_chrdev_region(&macvtap_major, 0,
  1032. MACVTAP_NUM_DEVS, "macvtap");
  1033. if (err)
  1034. goto out1;
  1035. cdev_init(&macvtap_cdev, &macvtap_fops);
  1036. err = cdev_add(&macvtap_cdev, macvtap_major, MACVTAP_NUM_DEVS);
  1037. if (err)
  1038. goto out2;
  1039. macvtap_class = class_create(THIS_MODULE, "macvtap");
  1040. if (IS_ERR(macvtap_class)) {
  1041. err = PTR_ERR(macvtap_class);
  1042. goto out3;
  1043. }
  1044. err = register_netdevice_notifier(&macvtap_notifier_block);
  1045. if (err)
  1046. goto out4;
  1047. err = macvlan_link_register(&macvtap_link_ops);
  1048. if (err)
  1049. goto out5;
  1050. return 0;
  1051. out5:
  1052. unregister_netdevice_notifier(&macvtap_notifier_block);
  1053. out4:
  1054. class_unregister(macvtap_class);
  1055. out3:
  1056. cdev_del(&macvtap_cdev);
  1057. out2:
  1058. unregister_chrdev_region(macvtap_major, MACVTAP_NUM_DEVS);
  1059. out1:
  1060. return err;
  1061. }
  1062. module_init(macvtap_init);
  1063. static void macvtap_exit(void)
  1064. {
  1065. rtnl_link_unregister(&macvtap_link_ops);
  1066. unregister_netdevice_notifier(&macvtap_notifier_block);
  1067. class_unregister(macvtap_class);
  1068. cdev_del(&macvtap_cdev);
  1069. unregister_chrdev_region(macvtap_major, MACVTAP_NUM_DEVS);
  1070. }
  1071. module_exit(macvtap_exit);
  1072. MODULE_ALIAS_RTNL_LINK("macvtap");
  1073. MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
  1074. MODULE_LICENSE("GPL");