mcast_kern.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * user-mode-linux networking multicast transport
  3. * Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
  4. *
  5. * based on the existing uml-networking code, which is
  6. * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  7. * James Leu (jleu@mindspring.net).
  8. * Copyright (C) 2001 by various other people who didn't put their name here.
  9. *
  10. * Licensed under the GPL.
  11. */
  12. #include "linux/kernel.h"
  13. #include "linux/init.h"
  14. #include "linux/netdevice.h"
  15. #include "linux/etherdevice.h"
  16. #include "linux/in.h"
  17. #include "linux/inet.h"
  18. #include "net_kern.h"
  19. #include "net_user.h"
  20. #include "mcast.h"
  21. struct mcast_init {
  22. char *addr;
  23. int port;
  24. int ttl;
  25. };
  26. void mcast_init(struct net_device *dev, void *data)
  27. {
  28. struct uml_net_private *pri;
  29. struct mcast_data *dpri;
  30. struct mcast_init *init = data;
  31. pri = dev->priv;
  32. dpri = (struct mcast_data *) pri->user;
  33. dpri->addr = init->addr;
  34. dpri->port = init->port;
  35. dpri->ttl = init->ttl;
  36. dpri->dev = dev;
  37. printk("mcast backend ");
  38. printk("multicast adddress: %s:%u, TTL:%u ",
  39. dpri->addr, dpri->port, dpri->ttl);
  40. printk("\n");
  41. }
  42. static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
  43. {
  44. *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
  45. if(*skb == NULL) return(-ENOMEM);
  46. return(net_recvfrom(fd, (*skb)->mac.raw,
  47. (*skb)->dev->mtu + ETH_HEADER_OTHER));
  48. }
  49. static int mcast_write(int fd, struct sk_buff **skb,
  50. struct uml_net_private *lp)
  51. {
  52. return mcast_user_write(fd, (*skb)->data, (*skb)->len,
  53. (struct mcast_data *) &lp->user);
  54. }
  55. static struct net_kern_info mcast_kern_info = {
  56. .init = mcast_init,
  57. .protocol = eth_protocol,
  58. .read = mcast_read,
  59. .write = mcast_write,
  60. };
  61. int mcast_setup(char *str, char **mac_out, void *data)
  62. {
  63. struct mcast_init *init = data;
  64. char *port_str = NULL, *ttl_str = NULL, *remain;
  65. char *last;
  66. *init = ((struct mcast_init)
  67. { .addr = "239.192.168.1",
  68. .port = 1102,
  69. .ttl = 1 });
  70. remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str,
  71. NULL);
  72. if(remain != NULL){
  73. printk(KERN_ERR "mcast_setup - Extra garbage on "
  74. "specification : '%s'\n", remain);
  75. return(0);
  76. }
  77. if(port_str != NULL){
  78. init->port = simple_strtoul(port_str, &last, 10);
  79. if((*last != '\0') || (last == port_str)){
  80. printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
  81. port_str);
  82. return(0);
  83. }
  84. }
  85. if(ttl_str != NULL){
  86. init->ttl = simple_strtoul(ttl_str, &last, 10);
  87. if((*last != '\0') || (last == ttl_str)){
  88. printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
  89. ttl_str);
  90. return(0);
  91. }
  92. }
  93. printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
  94. init->port, init->ttl);
  95. return(1);
  96. }
  97. static struct transport mcast_transport = {
  98. .list = LIST_HEAD_INIT(mcast_transport.list),
  99. .name = "mcast",
  100. .setup = mcast_setup,
  101. .user = &mcast_user_info,
  102. .kern = &mcast_kern_info,
  103. .private_size = sizeof(struct mcast_data),
  104. .setup_size = sizeof(struct mcast_init),
  105. };
  106. static int register_mcast(void)
  107. {
  108. register_transport(&mcast_transport);
  109. return(1);
  110. }
  111. __initcall(register_mcast);
  112. /*
  113. * Overrides for Emacs so that we follow Linus's tabbing style.
  114. * Emacs will notice this stuff at the end of the file and automatically
  115. * adjust the settings for this buffer only. This must remain at the end
  116. * of the file.
  117. * ---------------------------------------------------------------------------
  118. * Local variables:
  119. * c-file-style: "linux"
  120. * End:
  121. */