slip_kern.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL.
  4. */
  5. #include <linux/if_arp.h>
  6. #include <linux/init.h>
  7. #include <linux/netdevice.h>
  8. #include "net_kern.h"
  9. #include "slip.h"
  10. struct slip_init {
  11. char *gate_addr;
  12. };
  13. static void slip_init(struct net_device *dev, void *data)
  14. {
  15. struct uml_net_private *private;
  16. struct slip_data *spri;
  17. struct slip_init *init = data;
  18. private = netdev_priv(dev);
  19. spri = (struct slip_data *) private->user;
  20. memset(spri->name, 0, sizeof(spri->name));
  21. spri->addr = NULL;
  22. spri->gate_addr = init->gate_addr;
  23. spri->slave = -1;
  24. spri->dev = dev;
  25. slip_proto_init(&spri->slip);
  26. dev->hard_header_len = 0;
  27. dev->header_ops = NULL;
  28. dev->addr_len = 0;
  29. dev->type = ARPHRD_SLIP;
  30. dev->tx_queue_len = 256;
  31. dev->flags = IFF_NOARP;
  32. printk("SLIP backend - SLIP IP = %s\n", spri->gate_addr);
  33. }
  34. static unsigned short slip_protocol(struct sk_buff *skbuff)
  35. {
  36. return htons(ETH_P_IP);
  37. }
  38. static int slip_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  39. {
  40. return slip_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
  41. (struct slip_data *) &lp->user);
  42. }
  43. static int slip_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  44. {
  45. return slip_user_write(fd, skb->data, skb->len,
  46. (struct slip_data *) &lp->user);
  47. }
  48. static const struct net_kern_info slip_kern_info = {
  49. .init = slip_init,
  50. .protocol = slip_protocol,
  51. .read = slip_read,
  52. .write = slip_write,
  53. };
  54. static int slip_setup(char *str, char **mac_out, void *data)
  55. {
  56. struct slip_init *init = data;
  57. *init = ((struct slip_init) { .gate_addr = NULL });
  58. if (str[0] != '\0')
  59. init->gate_addr = str;
  60. return 1;
  61. }
  62. static struct transport slip_transport = {
  63. .list = LIST_HEAD_INIT(slip_transport.list),
  64. .name = "slip",
  65. .setup = slip_setup,
  66. .user = &slip_user_info,
  67. .kern = &slip_kern_info,
  68. .private_size = sizeof(struct slip_data),
  69. .setup_size = sizeof(struct slip_init),
  70. };
  71. static int register_slip(void)
  72. {
  73. register_transport(&slip_transport);
  74. return 0;
  75. }
  76. late_initcall(register_slip);