daemon_kern.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. 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. printk("daemon backend (uml_switch version %d) - %s:%s",
  31. SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
  32. printk("\n");
  33. }
  34. static int daemon_read(int fd, struct sk_buff **skb,
  35. struct uml_net_private *lp)
  36. {
  37. *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
  38. if(*skb == NULL) return(-ENOMEM);
  39. return(net_recvfrom(fd, (*skb)->mac.raw,
  40. (*skb)->dev->mtu + ETH_HEADER_OTHER));
  41. }
  42. static int daemon_write(int fd, struct sk_buff **skb,
  43. struct uml_net_private *lp)
  44. {
  45. return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
  46. (struct daemon_data *) &lp->user));
  47. }
  48. static struct net_kern_info daemon_kern_info = {
  49. .init = daemon_init,
  50. .protocol = eth_protocol,
  51. .read = daemon_read,
  52. .write = daemon_write,
  53. };
  54. int daemon_setup(char *str, char **mac_out, void *data)
  55. {
  56. struct daemon_init *init = data;
  57. char *remain;
  58. *init = ((struct daemon_init)
  59. { .sock_type = "unix",
  60. .ctl_sock = "/tmp/uml.ctl" });
  61. remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
  62. NULL);
  63. if(remain != NULL)
  64. printk(KERN_WARNING "daemon_setup : Ignoring data socket "
  65. "specification\n");
  66. return(1);
  67. }
  68. static struct transport daemon_transport = {
  69. .list = LIST_HEAD_INIT(daemon_transport.list),
  70. .name = "daemon",
  71. .setup = daemon_setup,
  72. .user = &daemon_user_info,
  73. .kern = &daemon_kern_info,
  74. .private_size = sizeof(struct daemon_data),
  75. .setup_size = sizeof(struct daemon_init),
  76. };
  77. static int register_daemon(void)
  78. {
  79. register_transport(&daemon_transport);
  80. return(1);
  81. }
  82. __initcall(register_daemon);
  83. /*
  84. * Overrides for Emacs so that we follow Linus's tabbing style.
  85. * Emacs will notice this stuff at the end of the file and automatically
  86. * adjust the settings for this buffer only. This must remain at the end
  87. * of the file.
  88. * ---------------------------------------------------------------------------
  89. * Local variables:
  90. * c-file-style: "linux"
  91. * End:
  92. */