slirp_kern.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <linux/string.h>
  9. #include <net_kern.h>
  10. #include <net_user.h>
  11. #include "slirp.h"
  12. struct slirp_init {
  13. struct arg_list_dummy_wrapper argw; /* XXX should be simpler... */
  14. };
  15. void slirp_init(struct net_device *dev, void *data)
  16. {
  17. struct uml_net_private *private;
  18. struct slirp_data *spri;
  19. struct slirp_init *init = data;
  20. int i;
  21. private = netdev_priv(dev);
  22. spri = (struct slirp_data *) private->user;
  23. spri->argw = init->argw;
  24. spri->pid = -1;
  25. spri->slave = -1;
  26. spri->dev = dev;
  27. slip_proto_init(&spri->slip);
  28. dev->hard_header_len = 0;
  29. dev->header_ops = NULL;
  30. dev->addr_len = 0;
  31. dev->type = ARPHRD_SLIP;
  32. dev->tx_queue_len = 256;
  33. dev->flags = IFF_NOARP;
  34. printk("SLIRP backend - command line:");
  35. for (i = 0; spri->argw.argv[i] != NULL; i++)
  36. printk(" '%s'",spri->argw.argv[i]);
  37. printk("\n");
  38. }
  39. static unsigned short slirp_protocol(struct sk_buff *skbuff)
  40. {
  41. return htons(ETH_P_IP);
  42. }
  43. static int slirp_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  44. {
  45. return slirp_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
  46. (struct slirp_data *) &lp->user);
  47. }
  48. static int slirp_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  49. {
  50. return slirp_user_write(fd, skb->data, skb->len,
  51. (struct slirp_data *) &lp->user);
  52. }
  53. const struct net_kern_info slirp_kern_info = {
  54. .init = slirp_init,
  55. .protocol = slirp_protocol,
  56. .read = slirp_read,
  57. .write = slirp_write,
  58. };
  59. static int slirp_setup(char *str, char **mac_out, void *data)
  60. {
  61. struct slirp_init *init = data;
  62. int i=0;
  63. *init = ((struct slirp_init) { .argw = { { "slirp", NULL } } });
  64. str = split_if_spec(str, mac_out, NULL);
  65. if (str == NULL) /* no command line given after MAC addr */
  66. return 1;
  67. do {
  68. if (i >= SLIRP_MAX_ARGS - 1) {
  69. printk(KERN_WARNING "slirp_setup: truncating slirp "
  70. "arguments\n");
  71. break;
  72. }
  73. init->argw.argv[i++] = str;
  74. while(*str && *str!=',') {
  75. if (*str == '_')
  76. *str=' ';
  77. str++;
  78. }
  79. if (*str != ',')
  80. break;
  81. *str++ = '\0';
  82. } while (1);
  83. init->argw.argv[i] = NULL;
  84. return 1;
  85. }
  86. static struct transport slirp_transport = {
  87. .list = LIST_HEAD_INIT(slirp_transport.list),
  88. .name = "slirp",
  89. .setup = slirp_setup,
  90. .user = &slirp_user_info,
  91. .kern = &slirp_kern_info,
  92. .private_size = sizeof(struct slirp_data),
  93. .setup_size = sizeof(struct slirp_init),
  94. };
  95. static int register_slirp(void)
  96. {
  97. register_transport(&slirp_transport);
  98. return 0;
  99. }
  100. late_initcall(register_slirp);