vde_kern.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
  3. * Licensed under the GPL.
  4. *
  5. * Transport usage:
  6. * ethN=vde,<vde_switch>,<mac addr>,<port>,<group>,<mode>,<description>
  7. *
  8. */
  9. #include "linux/init.h"
  10. #include <linux/netdevice.h>
  11. #include "net_kern.h"
  12. #include "net_user.h"
  13. #include "vde.h"
  14. static void vde_init(struct net_device *dev, void *data)
  15. {
  16. struct vde_init *init = data;
  17. struct uml_net_private *pri;
  18. struct vde_data *vpri;
  19. pri = netdev_priv(dev);
  20. vpri = (struct vde_data *) pri->user;
  21. vpri->vde_switch = init->vde_switch;
  22. vpri->descr = init->descr ? init->descr : "UML vde_transport";
  23. vpri->args = NULL;
  24. vpri->conn = NULL;
  25. vpri->dev = dev;
  26. printk("vde backend - %s, ", vpri->vde_switch ?
  27. vpri->vde_switch : "(default socket)");
  28. vde_init_libstuff(vpri, init);
  29. printk("\n");
  30. }
  31. static int vde_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  32. {
  33. struct vde_data *pri = (struct vde_data *) &lp->user;
  34. if (pri->conn != NULL)
  35. return vde_user_read(pri->conn, skb_mac_header(skb),
  36. skb->dev->mtu + ETH_HEADER_OTHER);
  37. printk(KERN_ERR "vde_read - we have no VDECONN to read from");
  38. return -EBADF;
  39. }
  40. static int vde_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  41. {
  42. struct vde_data *pri = (struct vde_data *) &lp->user;
  43. if (pri->conn != NULL)
  44. return vde_user_write((void *)pri->conn, skb->data,
  45. skb->len);
  46. printk(KERN_ERR "vde_write - we have no VDECONN to write to");
  47. return -EBADF;
  48. }
  49. static const struct net_kern_info vde_kern_info = {
  50. .init = vde_init,
  51. .protocol = eth_protocol,
  52. .read = vde_read,
  53. .write = vde_write,
  54. };
  55. static int vde_setup(char *str, char **mac_out, void *data)
  56. {
  57. struct vde_init *init = data;
  58. char *remain, *port_str = NULL, *mode_str = NULL, *last;
  59. *init = ((struct vde_init)
  60. { .vde_switch = NULL,
  61. .descr = NULL,
  62. .port = 0,
  63. .group = NULL,
  64. .mode = 0 });
  65. remain = split_if_spec(str, &init->vde_switch, mac_out, &port_str,
  66. &init->group, &mode_str, &init->descr, NULL);
  67. if (remain != NULL)
  68. printk(KERN_WARNING "vde_setup - Ignoring extra data :"
  69. "'%s'\n", remain);
  70. if (port_str != NULL) {
  71. init->port = simple_strtoul(port_str, &last, 10);
  72. if ((*last != '\0') || (last == port_str)) {
  73. printk(KERN_ERR "vde_setup - Bad port : '%s'\n",
  74. port_str);
  75. return 0;
  76. }
  77. }
  78. if (mode_str != NULL) {
  79. init->mode = simple_strtoul(mode_str, &last, 8);
  80. if ((*last != '\0') || (last == mode_str)) {
  81. printk(KERN_ERR "vde_setup - Bad mode : '%s'\n",
  82. mode_str);
  83. return 0;
  84. }
  85. }
  86. printk(KERN_INFO "Configured vde device: %s\n", init->vde_switch ?
  87. init->vde_switch : "(default socket)");
  88. return 1;
  89. }
  90. static struct transport vde_transport = {
  91. .list = LIST_HEAD_INIT(vde_transport.list),
  92. .name = "vde",
  93. .setup = vde_setup,
  94. .user = &vde_user_info,
  95. .kern = &vde_kern_info,
  96. .private_size = sizeof(struct vde_data),
  97. .setup_size = sizeof(struct vde_init),
  98. };
  99. static int register_vde(void)
  100. {
  101. register_transport(&vde_transport);
  102. return 0;
  103. }
  104. late_initcall(register_vde);