igmp.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Linux NET3: Internet Group Management Protocol [IGMP]
  3. *
  4. * Authors:
  5. * Alan Cox <Alan.Cox@linux.org>
  6. *
  7. * Extended to talk the BSD extended IGMP protocol of mrouted 3.6
  8. *
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. #ifndef _LINUX_IGMP_H
  16. #define _LINUX_IGMP_H
  17. #include <asm/byteorder.h>
  18. /*
  19. * IGMP protocol structures
  20. */
  21. /*
  22. * Header in on cable format
  23. */
  24. struct igmphdr
  25. {
  26. __u8 type;
  27. __u8 code; /* For newer IGMP */
  28. __u16 csum;
  29. __u32 group;
  30. };
  31. /* V3 group record types [grec_type] */
  32. #define IGMPV3_MODE_IS_INCLUDE 1
  33. #define IGMPV3_MODE_IS_EXCLUDE 2
  34. #define IGMPV3_CHANGE_TO_INCLUDE 3
  35. #define IGMPV3_CHANGE_TO_EXCLUDE 4
  36. #define IGMPV3_ALLOW_NEW_SOURCES 5
  37. #define IGMPV3_BLOCK_OLD_SOURCES 6
  38. struct igmpv3_grec {
  39. __u8 grec_type;
  40. __u8 grec_auxwords;
  41. __u16 grec_nsrcs;
  42. __u32 grec_mca;
  43. __u32 grec_src[0];
  44. };
  45. struct igmpv3_report {
  46. __u8 type;
  47. __u8 resv1;
  48. __u16 csum;
  49. __u16 resv2;
  50. __u16 ngrec;
  51. struct igmpv3_grec grec[0];
  52. };
  53. struct igmpv3_query {
  54. __u8 type;
  55. __u8 code;
  56. __u16 csum;
  57. __u32 group;
  58. #if defined(__LITTLE_ENDIAN_BITFIELD)
  59. __u8 qrv:3,
  60. suppress:1,
  61. resv:4;
  62. #elif defined(__BIG_ENDIAN_BITFIELD)
  63. __u8 resv:4,
  64. suppress:1,
  65. qrv:3;
  66. #else
  67. #error "Please fix <asm/byteorder.h>"
  68. #endif
  69. __u8 qqic;
  70. __u16 nsrcs;
  71. __u32 srcs[0];
  72. };
  73. #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
  74. #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
  75. #define IGMP_DVMRP 0x13 /* DVMRP routing */
  76. #define IGMP_PIM 0x14 /* PIM routing */
  77. #define IGMP_TRACE 0x15
  78. #define IGMPV2_HOST_MEMBERSHIP_REPORT 0x16 /* V2 version of 0x11 */
  79. #define IGMP_HOST_LEAVE_MESSAGE 0x17
  80. #define IGMPV3_HOST_MEMBERSHIP_REPORT 0x22 /* V3 version of 0x11 */
  81. #define IGMP_MTRACE_RESP 0x1e
  82. #define IGMP_MTRACE 0x1f
  83. /*
  84. * Use the BSD names for these for compatibility
  85. */
  86. #define IGMP_DELAYING_MEMBER 0x01
  87. #define IGMP_IDLE_MEMBER 0x02
  88. #define IGMP_LAZY_MEMBER 0x03
  89. #define IGMP_SLEEPING_MEMBER 0x04
  90. #define IGMP_AWAKENING_MEMBER 0x05
  91. #define IGMP_MINLEN 8
  92. #define IGMP_MAX_HOST_REPORT_DELAY 10 /* max delay for response to */
  93. /* query (in seconds) */
  94. #define IGMP_TIMER_SCALE 10 /* denotes that the igmphdr->timer field */
  95. /* specifies time in 10th of seconds */
  96. #define IGMP_AGE_THRESHOLD 400 /* If this host don't hear any IGMP V1 */
  97. /* message in this period of time, */
  98. /* revert to IGMP v2 router. */
  99. #define IGMP_ALL_HOSTS htonl(0xE0000001L)
  100. #define IGMP_ALL_ROUTER htonl(0xE0000002L)
  101. #define IGMPV3_ALL_MCR htonl(0xE0000016L)
  102. #define IGMP_LOCAL_GROUP htonl(0xE0000000L)
  103. #define IGMP_LOCAL_GROUP_MASK htonl(0xFFFFFF00L)
  104. /*
  105. * struct for keeping the multicast list in
  106. */
  107. #ifdef __KERNEL__
  108. #include <linux/skbuff.h>
  109. #include <linux/in.h>
  110. struct ip_sf_socklist
  111. {
  112. unsigned int sl_max;
  113. unsigned int sl_count;
  114. __u32 sl_addr[0];
  115. };
  116. #define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
  117. (count) * sizeof(__u32))
  118. #define IP_SFBLOCK 10 /* allocate this many at once */
  119. /* ip_mc_socklist is real list now. Speed is not argument;
  120. this list never used in fast path code
  121. */
  122. struct ip_mc_socklist
  123. {
  124. struct ip_mc_socklist *next;
  125. int count;
  126. struct ip_mreqn multi;
  127. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  128. struct ip_sf_socklist *sflist;
  129. };
  130. struct ip_sf_list
  131. {
  132. struct ip_sf_list *sf_next;
  133. __u32 sf_inaddr;
  134. unsigned long sf_count[2]; /* include/exclude counts */
  135. unsigned char sf_gsresp; /* include in g & s response? */
  136. unsigned char sf_oldin; /* change state */
  137. unsigned char sf_crcount; /* retrans. left to send */
  138. };
  139. struct ip_mc_list
  140. {
  141. struct in_device *interface;
  142. unsigned long multiaddr;
  143. struct ip_sf_list *sources;
  144. struct ip_sf_list *tomb;
  145. unsigned int sfmode;
  146. unsigned long sfcount[2];
  147. struct ip_mc_list *next;
  148. struct timer_list timer;
  149. int users;
  150. atomic_t refcnt;
  151. spinlock_t lock;
  152. char tm_running;
  153. char reporter;
  154. char unsolicit_count;
  155. char loaded;
  156. unsigned char gsquery; /* check source marks? */
  157. unsigned char crcount;
  158. };
  159. /* V3 exponential field decoding */
  160. #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
  161. #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
  162. ((value) < (thresh) ? (value) : \
  163. ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant+nbexp))) << \
  164. (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
  165. #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
  166. #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
  167. extern int ip_check_mc(struct in_device *dev, u32 mc_addr, u32 src_addr, u16 proto);
  168. extern int igmp_rcv(struct sk_buff *);
  169. extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
  170. extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
  171. extern void ip_mc_drop_socket(struct sock *sk);
  172. extern int ip_mc_source(int add, int omode, struct sock *sk,
  173. struct ip_mreq_source *mreqs, int ifindex);
  174. extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
  175. extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
  176. struct ip_msfilter __user *optval, int __user *optlen);
  177. extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
  178. struct group_filter __user *optval, int __user *optlen);
  179. extern int ip_mc_sf_allow(struct sock *sk, u32 local, u32 rmt, int dif);
  180. extern void ip_mr_init(void);
  181. extern void ip_mc_init_dev(struct in_device *);
  182. extern void ip_mc_destroy_dev(struct in_device *);
  183. extern void ip_mc_up(struct in_device *);
  184. extern void ip_mc_down(struct in_device *);
  185. extern void ip_mc_dec_group(struct in_device *in_dev, u32 addr);
  186. extern void ip_mc_inc_group(struct in_device *in_dev, u32 addr);
  187. #endif
  188. #endif