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