macvtap.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  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. /* Neighbour code has some assumptions on HH_DATA_MOD alignment */
  550. #define MACVTAP_RESERVE HH_DATA_OFF(ETH_HLEN)
  551. /* Get packet from user space buffer */
  552. static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
  553. struct iov_iter *from, int noblock)
  554. {
  555. int good_linear = SKB_MAX_HEAD(MACVTAP_RESERVE);
  556. struct sk_buff *skb;
  557. struct macvlan_dev *vlan;
  558. unsigned long total_len = iov_iter_count(from);
  559. unsigned long len = total_len;
  560. int err;
  561. struct virtio_net_hdr vnet_hdr = { 0 };
  562. int vnet_hdr_len = 0;
  563. int copylen = 0;
  564. bool zerocopy = false;
  565. size_t linear;
  566. ssize_t n;
  567. if (q->flags & IFF_VNET_HDR) {
  568. vnet_hdr_len = q->vnet_hdr_sz;
  569. err = -EINVAL;
  570. if (len < vnet_hdr_len)
  571. goto err;
  572. len -= vnet_hdr_len;
  573. err = -EFAULT;
  574. n = copy_from_iter(&vnet_hdr, sizeof(vnet_hdr), from);
  575. if (n != sizeof(vnet_hdr))
  576. goto err;
  577. iov_iter_advance(from, vnet_hdr_len - sizeof(vnet_hdr));
  578. if ((vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
  579. macvtap16_to_cpu(q, vnet_hdr.csum_start) +
  580. macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2 >
  581. macvtap16_to_cpu(q, vnet_hdr.hdr_len))
  582. vnet_hdr.hdr_len = cpu_to_macvtap16(q,
  583. macvtap16_to_cpu(q, vnet_hdr.csum_start) +
  584. macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2);
  585. err = -EINVAL;
  586. if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > len)
  587. goto err;
  588. }
  589. err = -EINVAL;
  590. if (unlikely(len < ETH_HLEN))
  591. goto err;
  592. if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
  593. struct iov_iter i;
  594. copylen = vnet_hdr.hdr_len ?
  595. macvtap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN;
  596. if (copylen > good_linear)
  597. copylen = good_linear;
  598. linear = copylen;
  599. i = *from;
  600. iov_iter_advance(&i, copylen);
  601. if (iov_iter_npages(&i, INT_MAX) <= MAX_SKB_FRAGS)
  602. zerocopy = true;
  603. }
  604. if (!zerocopy) {
  605. copylen = len;
  606. if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > good_linear)
  607. linear = good_linear;
  608. else
  609. linear = macvtap16_to_cpu(q, vnet_hdr.hdr_len);
  610. }
  611. skb = macvtap_alloc_skb(&q->sk, MACVTAP_RESERVE, copylen,
  612. linear, noblock, &err);
  613. if (!skb)
  614. goto err;
  615. if (zerocopy)
  616. err = zerocopy_sg_from_iter(skb, from);
  617. else {
  618. err = skb_copy_datagram_from_iter(skb, 0, from, len);
  619. if (!err && m && m->msg_control) {
  620. struct ubuf_info *uarg = m->msg_control;
  621. uarg->callback(uarg, false);
  622. }
  623. }
  624. if (err)
  625. goto err_kfree;
  626. skb_set_network_header(skb, ETH_HLEN);
  627. skb_reset_mac_header(skb);
  628. skb->protocol = eth_hdr(skb)->h_proto;
  629. if (vnet_hdr_len) {
  630. err = macvtap_skb_from_vnet_hdr(q, skb, &vnet_hdr);
  631. if (err)
  632. goto err_kfree;
  633. }
  634. skb_probe_transport_header(skb, ETH_HLEN);
  635. rcu_read_lock();
  636. vlan = rcu_dereference(q->vlan);
  637. /* copy skb_ubuf_info for callback when skb has no error */
  638. if (zerocopy) {
  639. skb_shinfo(skb)->destructor_arg = m->msg_control;
  640. skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
  641. skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
  642. }
  643. if (vlan) {
  644. skb->dev = vlan->dev;
  645. dev_queue_xmit(skb);
  646. } else {
  647. kfree_skb(skb);
  648. }
  649. rcu_read_unlock();
  650. return total_len;
  651. err_kfree:
  652. kfree_skb(skb);
  653. err:
  654. rcu_read_lock();
  655. vlan = rcu_dereference(q->vlan);
  656. if (vlan)
  657. this_cpu_inc(vlan->pcpu_stats->tx_dropped);
  658. rcu_read_unlock();
  659. return err;
  660. }
  661. static ssize_t macvtap_write_iter(struct kiocb *iocb, struct iov_iter *from)
  662. {
  663. struct file *file = iocb->ki_filp;
  664. struct macvtap_queue *q = file->private_data;
  665. return macvtap_get_user(q, NULL, from, file->f_flags & O_NONBLOCK);
  666. }
  667. /* Put packet to the user space buffer */
  668. static ssize_t macvtap_put_user(struct macvtap_queue *q,
  669. const struct sk_buff *skb,
  670. struct iov_iter *iter)
  671. {
  672. int ret;
  673. int vnet_hdr_len = 0;
  674. int vlan_offset = 0;
  675. int total;
  676. if (q->flags & IFF_VNET_HDR) {
  677. struct virtio_net_hdr vnet_hdr;
  678. vnet_hdr_len = q->vnet_hdr_sz;
  679. if (iov_iter_count(iter) < vnet_hdr_len)
  680. return -EINVAL;
  681. macvtap_skb_to_vnet_hdr(q, skb, &vnet_hdr);
  682. if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
  683. sizeof(vnet_hdr))
  684. return -EFAULT;
  685. iov_iter_advance(iter, vnet_hdr_len - sizeof(vnet_hdr));
  686. }
  687. total = vnet_hdr_len;
  688. total += skb->len;
  689. if (skb_vlan_tag_present(skb)) {
  690. struct {
  691. __be16 h_vlan_proto;
  692. __be16 h_vlan_TCI;
  693. } veth;
  694. veth.h_vlan_proto = skb->vlan_proto;
  695. veth.h_vlan_TCI = htons(skb_vlan_tag_get(skb));
  696. vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
  697. total += VLAN_HLEN;
  698. ret = skb_copy_datagram_iter(skb, 0, iter, vlan_offset);
  699. if (ret || !iov_iter_count(iter))
  700. goto done;
  701. ret = copy_to_iter(&veth, sizeof(veth), iter);
  702. if (ret != sizeof(veth) || !iov_iter_count(iter))
  703. goto done;
  704. }
  705. ret = skb_copy_datagram_iter(skb, vlan_offset, iter,
  706. skb->len - vlan_offset);
  707. done:
  708. return ret ? ret : total;
  709. }
  710. static ssize_t macvtap_do_read(struct macvtap_queue *q,
  711. struct iov_iter *to,
  712. int noblock)
  713. {
  714. DEFINE_WAIT(wait);
  715. struct sk_buff *skb;
  716. ssize_t ret = 0;
  717. if (!iov_iter_count(to))
  718. return 0;
  719. while (1) {
  720. if (!noblock)
  721. prepare_to_wait(sk_sleep(&q->sk), &wait,
  722. TASK_INTERRUPTIBLE);
  723. /* Read frames from the queue */
  724. skb = skb_dequeue(&q->sk.sk_receive_queue);
  725. if (skb)
  726. break;
  727. if (noblock) {
  728. ret = -EAGAIN;
  729. break;
  730. }
  731. if (signal_pending(current)) {
  732. ret = -ERESTARTSYS;
  733. break;
  734. }
  735. /* Nothing to read, let's sleep */
  736. schedule();
  737. }
  738. if (skb) {
  739. ret = macvtap_put_user(q, skb, to);
  740. if (unlikely(ret < 0))
  741. kfree_skb(skb);
  742. else
  743. consume_skb(skb);
  744. }
  745. if (!noblock)
  746. finish_wait(sk_sleep(&q->sk), &wait);
  747. return ret;
  748. }
  749. static ssize_t macvtap_read_iter(struct kiocb *iocb, struct iov_iter *to)
  750. {
  751. struct file *file = iocb->ki_filp;
  752. struct macvtap_queue *q = file->private_data;
  753. ssize_t len = iov_iter_count(to), ret;
  754. ret = macvtap_do_read(q, to, file->f_flags & O_NONBLOCK);
  755. ret = min_t(ssize_t, ret, len);
  756. if (ret > 0)
  757. iocb->ki_pos = ret;
  758. return ret;
  759. }
  760. static struct macvlan_dev *macvtap_get_vlan(struct macvtap_queue *q)
  761. {
  762. struct macvlan_dev *vlan;
  763. ASSERT_RTNL();
  764. vlan = rtnl_dereference(q->vlan);
  765. if (vlan)
  766. dev_hold(vlan->dev);
  767. return vlan;
  768. }
  769. static void macvtap_put_vlan(struct macvlan_dev *vlan)
  770. {
  771. dev_put(vlan->dev);
  772. }
  773. static int macvtap_ioctl_set_queue(struct file *file, unsigned int flags)
  774. {
  775. struct macvtap_queue *q = file->private_data;
  776. struct macvlan_dev *vlan;
  777. int ret;
  778. vlan = macvtap_get_vlan(q);
  779. if (!vlan)
  780. return -EINVAL;
  781. if (flags & IFF_ATTACH_QUEUE)
  782. ret = macvtap_enable_queue(vlan->dev, file, q);
  783. else if (flags & IFF_DETACH_QUEUE)
  784. ret = macvtap_disable_queue(q);
  785. else
  786. ret = -EINVAL;
  787. macvtap_put_vlan(vlan);
  788. return ret;
  789. }
  790. static int set_offload(struct macvtap_queue *q, unsigned long arg)
  791. {
  792. struct macvlan_dev *vlan;
  793. netdev_features_t features;
  794. netdev_features_t feature_mask = 0;
  795. vlan = rtnl_dereference(q->vlan);
  796. if (!vlan)
  797. return -ENOLINK;
  798. features = vlan->dev->features;
  799. if (arg & TUN_F_CSUM) {
  800. feature_mask = NETIF_F_HW_CSUM;
  801. if (arg & (TUN_F_TSO4 | TUN_F_TSO6)) {
  802. if (arg & TUN_F_TSO_ECN)
  803. feature_mask |= NETIF_F_TSO_ECN;
  804. if (arg & TUN_F_TSO4)
  805. feature_mask |= NETIF_F_TSO;
  806. if (arg & TUN_F_TSO6)
  807. feature_mask |= NETIF_F_TSO6;
  808. }
  809. if (arg & TUN_F_UFO)
  810. feature_mask |= NETIF_F_UFO;
  811. }
  812. /* tun/tap driver inverts the usage for TSO offloads, where
  813. * setting the TSO bit means that the userspace wants to
  814. * accept TSO frames and turning it off means that user space
  815. * does not support TSO.
  816. * For macvtap, we have to invert it to mean the same thing.
  817. * When user space turns off TSO, we turn off GSO/LRO so that
  818. * user-space will not receive TSO frames.
  819. */
  820. if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_UFO))
  821. features |= RX_OFFLOADS;
  822. else
  823. features &= ~RX_OFFLOADS;
  824. /* tap_features are the same as features on tun/tap and
  825. * reflect user expectations.
  826. */
  827. vlan->tap_features = feature_mask;
  828. vlan->set_features = features;
  829. netdev_update_features(vlan->dev);
  830. return 0;
  831. }
  832. /*
  833. * provide compatibility with generic tun/tap interface
  834. */
  835. static long macvtap_ioctl(struct file *file, unsigned int cmd,
  836. unsigned long arg)
  837. {
  838. struct macvtap_queue *q = file->private_data;
  839. struct macvlan_dev *vlan;
  840. void __user *argp = (void __user *)arg;
  841. struct ifreq __user *ifr = argp;
  842. unsigned int __user *up = argp;
  843. unsigned short u;
  844. int __user *sp = argp;
  845. int s;
  846. int ret;
  847. switch (cmd) {
  848. case TUNSETIFF:
  849. /* ignore the name, just look at flags */
  850. if (get_user(u, &ifr->ifr_flags))
  851. return -EFAULT;
  852. ret = 0;
  853. if ((u & ~MACVTAP_FEATURES) != (IFF_NO_PI | IFF_TAP))
  854. ret = -EINVAL;
  855. else
  856. q->flags = (q->flags & ~MACVTAP_FEATURES) | u;
  857. return ret;
  858. case TUNGETIFF:
  859. rtnl_lock();
  860. vlan = macvtap_get_vlan(q);
  861. if (!vlan) {
  862. rtnl_unlock();
  863. return -ENOLINK;
  864. }
  865. ret = 0;
  866. u = q->flags;
  867. if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
  868. put_user(u, &ifr->ifr_flags))
  869. ret = -EFAULT;
  870. macvtap_put_vlan(vlan);
  871. rtnl_unlock();
  872. return ret;
  873. case TUNSETQUEUE:
  874. if (get_user(u, &ifr->ifr_flags))
  875. return -EFAULT;
  876. rtnl_lock();
  877. ret = macvtap_ioctl_set_queue(file, u);
  878. rtnl_unlock();
  879. return ret;
  880. case TUNGETFEATURES:
  881. if (put_user(IFF_TAP | IFF_NO_PI | MACVTAP_FEATURES, up))
  882. return -EFAULT;
  883. return 0;
  884. case TUNSETSNDBUF:
  885. if (get_user(u, up))
  886. return -EFAULT;
  887. q->sk.sk_sndbuf = u;
  888. return 0;
  889. case TUNGETVNETHDRSZ:
  890. s = q->vnet_hdr_sz;
  891. if (put_user(s, sp))
  892. return -EFAULT;
  893. return 0;
  894. case TUNSETVNETHDRSZ:
  895. if (get_user(s, sp))
  896. return -EFAULT;
  897. if (s < (int)sizeof(struct virtio_net_hdr))
  898. return -EINVAL;
  899. q->vnet_hdr_sz = s;
  900. return 0;
  901. case TUNGETVNETLE:
  902. s = !!(q->flags & MACVTAP_VNET_LE);
  903. if (put_user(s, sp))
  904. return -EFAULT;
  905. return 0;
  906. case TUNSETVNETLE:
  907. if (get_user(s, sp))
  908. return -EFAULT;
  909. if (s)
  910. q->flags |= MACVTAP_VNET_LE;
  911. else
  912. q->flags &= ~MACVTAP_VNET_LE;
  913. return 0;
  914. case TUNSETOFFLOAD:
  915. /* let the user check for future flags */
  916. if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 |
  917. TUN_F_TSO_ECN | TUN_F_UFO))
  918. return -EINVAL;
  919. rtnl_lock();
  920. ret = set_offload(q, arg);
  921. rtnl_unlock();
  922. return ret;
  923. default:
  924. return -EINVAL;
  925. }
  926. }
  927. #ifdef CONFIG_COMPAT
  928. static long macvtap_compat_ioctl(struct file *file, unsigned int cmd,
  929. unsigned long arg)
  930. {
  931. return macvtap_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
  932. }
  933. #endif
  934. static const struct file_operations macvtap_fops = {
  935. .owner = THIS_MODULE,
  936. .open = macvtap_open,
  937. .release = macvtap_release,
  938. .read = new_sync_read,
  939. .write = new_sync_write,
  940. .read_iter = macvtap_read_iter,
  941. .write_iter = macvtap_write_iter,
  942. .poll = macvtap_poll,
  943. .llseek = no_llseek,
  944. .unlocked_ioctl = macvtap_ioctl,
  945. #ifdef CONFIG_COMPAT
  946. .compat_ioctl = macvtap_compat_ioctl,
  947. #endif
  948. };
  949. static int macvtap_sendmsg(struct socket *sock, struct msghdr *m,
  950. size_t total_len)
  951. {
  952. struct macvtap_queue *q = container_of(sock, struct macvtap_queue, sock);
  953. return macvtap_get_user(q, m, &m->msg_iter, m->msg_flags & MSG_DONTWAIT);
  954. }
  955. static int macvtap_recvmsg(struct socket *sock, struct msghdr *m,
  956. size_t total_len, 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");