daemon_kern.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <net_kern.h>
  11. #include "daemon.h"
  12. struct daemon_init {
  13. char *sock_type;
  14. char *ctl_sock;
  15. };
  16. static void daemon_init(struct net_device *dev, void *data)
  17. {
  18. struct uml_net_private *pri;
  19. struct daemon_data *dpri;
  20. struct daemon_init *init = data;
  21. pri = netdev_priv(dev);
  22. dpri = (struct daemon_data *) pri->user;
  23. dpri->sock_type = init->sock_type;
  24. dpri->ctl_sock = init->ctl_sock;
  25. dpri->fd = -1;
  26. dpri->control = -1;
  27. dpri->dev = dev;
  28. /* We will free this pointer. If it contains crap we're burned. */
  29. dpri->ctl_addr = NULL;
  30. dpri->data_addr = NULL;
  31. dpri->local_addr = NULL;
  32. printk("daemon backend (uml_switch version %d) - %s:%s",
  33. SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
  34. printk("\n");
  35. }
  36. static int daemon_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  37. {
  38. return net_recvfrom(fd, skb_mac_header(skb),
  39. skb->dev->mtu + ETH_HEADER_OTHER);
  40. }
  41. static int daemon_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
  42. {
  43. return daemon_user_write(fd, skb->data, skb->len,
  44. (struct daemon_data *) &lp->user);
  45. }
  46. static const struct net_kern_info daemon_kern_info = {
  47. .init = daemon_init,
  48. .protocol = eth_protocol,
  49. .read = daemon_read,
  50. .write = daemon_write,
  51. };
  52. static int daemon_setup(char *str, char **mac_out, void *data)
  53. {
  54. struct daemon_init *init = data;
  55. char *remain;
  56. *init = ((struct daemon_init)
  57. { .sock_type = "unix",
  58. .ctl_sock = "/tmp/uml.ctl" });
  59. remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
  60. NULL);
  61. if (remain != NULL)
  62. printk(KERN_WARNING "daemon_setup : Ignoring data socket "
  63. "specification\n");
  64. return 1;
  65. }
  66. static struct transport daemon_transport = {
  67. .list = LIST_HEAD_INIT(daemon_transport.list),
  68. .name = "daemon",
  69. .setup = daemon_setup,
  70. .user = &daemon_user_info,
  71. .kern = &daemon_kern_info,
  72. .private_size = sizeof(struct daemon_data),
  73. .setup_size = sizeof(struct daemon_init),
  74. };
  75. static int register_daemon(void)
  76. {
  77. register_transport(&daemon_transport);
  78. return 0;
  79. }
  80. late_initcall(register_daemon);