ethertap_kern.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  3. * James Leu (jleu@mindspring.net).
  4. * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  5. * Copyright (C) 2001 by various other people who didn't put their name here.
  6. * Licensed under the GPL.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/netdevice.h>
  10. #include "etap.h"
  11. #include <net_kern.h>
  12. struct ethertap_init {
  13. char *dev_name;
  14. char *gate_addr;
  15. };
  16. static void etap_init(struct net_device *dev, void *data)
  17. {
  18. struct uml_net_private *pri;
  19. struct ethertap_data *epri;
  20. struct ethertap_init *init = data;
  21. pri = netdev_priv(dev);
  22. epri = (struct ethertap_data *) pri->user;
  23. epri->dev_name = init->dev_name;
  24. epri->gate_addr = init->gate_addr;
  25. epri->data_fd = -1;
  26. epri->control_fd = -1;
  27. epri->dev = dev;
  28. printk(KERN_INFO "ethertap backend - %s", epri->dev_name);
  29. if (epri->gate_addr != NULL)
  30. printk(KERN_CONT ", IP = %s", epri->gate_addr);
  31. printk(KERN_CONT "\n");
  32. }
  33. static int etap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  34. {
  35. int len;
  36. len = net_recvfrom(fd, skb_mac_header(skb),
  37. skb->dev->mtu + 2 + ETH_HEADER_ETHERTAP);
  38. if (len <= 0)
  39. return(len);
  40. skb_pull(skb, 2);
  41. len -= 2;
  42. return len;
  43. }
  44. static int etap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  45. {
  46. skb_push(skb, 2);
  47. return net_send(fd, skb->data, skb->len);
  48. }
  49. const struct net_kern_info ethertap_kern_info = {
  50. .init = etap_init,
  51. .protocol = eth_protocol,
  52. .read = etap_read,
  53. .write = etap_write,
  54. };
  55. int ethertap_setup(char *str, char **mac_out, void *data)
  56. {
  57. struct ethertap_init *init = data;
  58. *init = ((struct ethertap_init)
  59. { .dev_name = NULL,
  60. .gate_addr = NULL });
  61. if (tap_setup_common(str, "ethertap", &init->dev_name, mac_out,
  62. &init->gate_addr))
  63. return 0;
  64. if (init->dev_name == NULL) {
  65. printk(KERN_ERR "ethertap_setup : Missing tap device name\n");
  66. return 0;
  67. }
  68. return 1;
  69. }
  70. static struct transport ethertap_transport = {
  71. .list = LIST_HEAD_INIT(ethertap_transport.list),
  72. .name = "ethertap",
  73. .setup = ethertap_setup,
  74. .user = &ethertap_user_info,
  75. .kern = &ethertap_kern_info,
  76. .private_size = sizeof(struct ethertap_data),
  77. .setup_size = sizeof(struct ethertap_init),
  78. };
  79. static int register_ethertap(void)
  80. {
  81. register_transport(&ethertap_transport);
  82. return 0;
  83. }
  84. late_initcall(register_ethertap);