mcast_kern.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. int n;
  67. *init = ((struct mcast_init)
  68. { .addr = "239.192.168.1",
  69. .port = 1102,
  70. .ttl = 1 });
  71. remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str,
  72. NULL);
  73. if(remain != NULL){
  74. printk(KERN_ERR "mcast_setup - Extra garbage on "
  75. "specification : '%s'\n", remain);
  76. return(0);
  77. }
  78. if(port_str != NULL){
  79. n = simple_strtoul(port_str, &last, 10);
  80. if((*last != '\0') || (last == port_str)){
  81. printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
  82. port_str);
  83. return(0);
  84. }
  85. init->port = htons(n);
  86. }
  87. if(ttl_str != NULL){
  88. init->ttl = simple_strtoul(ttl_str, &last, 10);
  89. if((*last != '\0') || (last == ttl_str)){
  90. printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
  91. ttl_str);
  92. return(0);
  93. }
  94. }
  95. printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
  96. init->port, init->ttl);
  97. return(1);
  98. }
  99. static struct transport mcast_transport = {
  100. .list = LIST_HEAD_INIT(mcast_transport.list),
  101. .name = "mcast",
  102. .setup = mcast_setup,
  103. .user = &mcast_user_info,
  104. .kern = &mcast_kern_info,
  105. .private_size = sizeof(struct mcast_data),
  106. .setup_size = sizeof(struct mcast_init),
  107. };
  108. static int register_mcast(void)
  109. {
  110. register_transport(&mcast_transport);
  111. return(1);
  112. }
  113. __initcall(register_mcast);
  114. /*
  115. * Overrides for Emacs so that we follow Linus's tabbing style.
  116. * Emacs will notice this stuff at the end of the file and automatically
  117. * adjust the settings for this buffer only. This must remain at the end
  118. * of the file.
  119. * ---------------------------------------------------------------------------
  120. * Local variables:
  121. * c-file-style: "linux"
  122. * End:
  123. */