daemon_kern.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  3. * James Leu (jleu@mindspring.net).
  4. * Copyright (C) 2001 by various other people who didn't put their name here.
  5. * Licensed under the GPL.
  6. */
  7. #include "linux/kernel.h"
  8. #include "linux/init.h"
  9. #include "linux/netdevice.h"
  10. #include "linux/etherdevice.h"
  11. #include "net_kern.h"
  12. #include "net_user.h"
  13. #include "daemon.h"
  14. struct daemon_init {
  15. char *sock_type;
  16. char *ctl_sock;
  17. };
  18. static void daemon_init(struct net_device *dev, void *data)
  19. {
  20. struct uml_net_private *pri;
  21. struct daemon_data *dpri;
  22. struct daemon_init *init = data;
  23. pri = dev->priv;
  24. dpri = (struct daemon_data *) pri->user;
  25. dpri->sock_type = init->sock_type;
  26. dpri->ctl_sock = init->ctl_sock;
  27. dpri->fd = -1;
  28. dpri->control = -1;
  29. dpri->dev = dev;
  30. /* We will free this pointer. If it contains crap we're burned. */
  31. dpri->ctl_addr = NULL;
  32. dpri->data_addr = NULL;
  33. dpri->local_addr = NULL;
  34. printk("daemon backend (uml_switch version %d) - %s:%s",
  35. SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
  36. printk("\n");
  37. }
  38. static int daemon_read(int fd, struct sk_buff **skb,
  39. struct uml_net_private *lp)
  40. {
  41. *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
  42. if(*skb == NULL) return(-ENOMEM);
  43. return(net_recvfrom(fd, (*skb)->mac.raw,
  44. (*skb)->dev->mtu + ETH_HEADER_OTHER));
  45. }
  46. static int daemon_write(int fd, struct sk_buff **skb,
  47. struct uml_net_private *lp)
  48. {
  49. return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
  50. (struct daemon_data *) &lp->user));
  51. }
  52. static struct net_kern_info daemon_kern_info = {
  53. .init = daemon_init,
  54. .protocol = eth_protocol,
  55. .read = daemon_read,
  56. .write = daemon_write,
  57. };
  58. static int daemon_setup(char *str, char **mac_out, void *data)
  59. {
  60. struct daemon_init *init = data;
  61. char *remain;
  62. *init = ((struct daemon_init)
  63. { .sock_type = "unix",
  64. .ctl_sock = "/tmp/uml.ctl" });
  65. remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
  66. NULL);
  67. if(remain != NULL)
  68. printk(KERN_WARNING "daemon_setup : Ignoring data socket "
  69. "specification\n");
  70. return(1);
  71. }
  72. static struct transport daemon_transport = {
  73. .list = LIST_HEAD_INIT(daemon_transport.list),
  74. .name = "daemon",
  75. .setup = daemon_setup,
  76. .user = &daemon_user_info,
  77. .kern = &daemon_kern_info,
  78. .private_size = sizeof(struct daemon_data),
  79. .setup_size = sizeof(struct daemon_init),
  80. };
  81. static int register_daemon(void)
  82. {
  83. register_transport(&daemon_transport);
  84. return 0;
  85. }
  86. __initcall(register_daemon);