tuntap_kern.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL
  4. */
  5. #include <linux/netdevice.h>
  6. #include <linux/init.h>
  7. #include <linux/skbuff.h>
  8. #include <asm/errno.h>
  9. #include "net_kern.h"
  10. #include "tuntap.h"
  11. struct tuntap_init {
  12. char *dev_name;
  13. char *gate_addr;
  14. };
  15. static void tuntap_init(struct net_device *dev, void *data)
  16. {
  17. struct uml_net_private *pri;
  18. struct tuntap_data *tpri;
  19. struct tuntap_init *init = data;
  20. pri = netdev_priv(dev);
  21. tpri = (struct tuntap_data *) pri->user;
  22. tpri->dev_name = init->dev_name;
  23. tpri->fixed_config = (init->dev_name != NULL);
  24. tpri->gate_addr = init->gate_addr;
  25. tpri->fd = -1;
  26. tpri->dev = dev;
  27. printk(KERN_INFO "TUN/TAP backend - ");
  28. if (tpri->gate_addr != NULL)
  29. printk(KERN_CONT "IP = %s", tpri->gate_addr);
  30. printk(KERN_CONT "\n");
  31. }
  32. static int tuntap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  33. {
  34. return net_read(fd, skb_mac_header(skb),
  35. skb->dev->mtu + ETH_HEADER_OTHER);
  36. }
  37. static int tuntap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  38. {
  39. return net_write(fd, skb->data, skb->len);
  40. }
  41. const struct net_kern_info tuntap_kern_info = {
  42. .init = tuntap_init,
  43. .protocol = eth_protocol,
  44. .read = tuntap_read,
  45. .write = tuntap_write,
  46. };
  47. int tuntap_setup(char *str, char **mac_out, void *data)
  48. {
  49. struct tuntap_init *init = data;
  50. *init = ((struct tuntap_init)
  51. { .dev_name = NULL,
  52. .gate_addr = NULL });
  53. if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
  54. &init->gate_addr))
  55. return 0;
  56. return 1;
  57. }
  58. static struct transport tuntap_transport = {
  59. .list = LIST_HEAD_INIT(tuntap_transport.list),
  60. .name = "tuntap",
  61. .setup = tuntap_setup,
  62. .user = &tuntap_user_info,
  63. .kern = &tuntap_kern_info,
  64. .private_size = sizeof(struct tuntap_data),
  65. .setup_size = sizeof(struct tuntap_init),
  66. };
  67. static int register_tuntap(void)
  68. {
  69. register_transport(&tuntap_transport);
  70. return 0;
  71. }
  72. late_initcall(register_tuntap);