igmp.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Linux NET3: Internet Group Management Protocol [IGMP]
  3. *
  4. * Authors:
  5. * Alan Cox <alan@lxorguk.ukuu.org.uk>
  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 <linux/types.h>
  18. #include <asm/byteorder.h>
  19. /*
  20. * IGMP protocol structures
  21. */
  22. /*
  23. * Header in on cable format
  24. */
  25. struct igmphdr {
  26. __u8 type;
  27. __u8 code; /* For newer IGMP */
  28. __sum16 csum;
  29. __be32 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. __be16 grec_nsrcs;
  42. __be32 grec_mca;
  43. __be32 grec_src[0];
  44. };
  45. struct igmpv3_report {
  46. __u8 type;
  47. __u8 resv1;
  48. __be16 csum;
  49. __be16 resv2;
  50. __be16 ngrec;
  51. struct igmpv3_grec grec[0];
  52. };
  53. struct igmpv3_query {
  54. __u8 type;
  55. __u8 code;
  56. __be16 csum;
  57. __be32 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. __be16 nsrcs;
  71. __be32 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 0x12 */
  79. #define IGMP_HOST_LEAVE_MESSAGE 0x17
  80. #define IGMPV3_HOST_MEMBERSHIP_REPORT 0x22 /* V3 version of 0x12 */
  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/timer.h>
  110. #include <linux/in.h>
  111. static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
  112. {
  113. return (struct igmphdr *)skb_transport_header(skb);
  114. }
  115. static inline struct igmpv3_report *
  116. igmpv3_report_hdr(const struct sk_buff *skb)
  117. {
  118. return (struct igmpv3_report *)skb_transport_header(skb);
  119. }
  120. static inline struct igmpv3_query *
  121. igmpv3_query_hdr(const struct sk_buff *skb)
  122. {
  123. return (struct igmpv3_query *)skb_transport_header(skb);
  124. }
  125. extern int sysctl_igmp_max_memberships;
  126. extern int sysctl_igmp_max_msf;
  127. struct ip_sf_socklist {
  128. unsigned int sl_max;
  129. unsigned int sl_count;
  130. struct rcu_head rcu;
  131. __be32 sl_addr[0];
  132. };
  133. #define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
  134. (count) * sizeof(__be32))
  135. #define IP_SFBLOCK 10 /* allocate this many at once */
  136. /* ip_mc_socklist is real list now. Speed is not argument;
  137. this list never used in fast path code
  138. */
  139. struct ip_mc_socklist {
  140. struct ip_mc_socklist __rcu *next_rcu;
  141. struct ip_mreqn multi;
  142. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  143. struct ip_sf_socklist __rcu *sflist;
  144. struct rcu_head rcu;
  145. };
  146. struct ip_sf_list {
  147. struct ip_sf_list *sf_next;
  148. __be32 sf_inaddr;
  149. unsigned long sf_count[2]; /* include/exclude counts */
  150. unsigned char sf_gsresp; /* include in g & s response? */
  151. unsigned char sf_oldin; /* change state */
  152. unsigned char sf_crcount; /* retrans. left to send */
  153. };
  154. struct ip_mc_list {
  155. struct in_device *interface;
  156. __be32 multiaddr;
  157. unsigned int sfmode;
  158. struct ip_sf_list *sources;
  159. struct ip_sf_list *tomb;
  160. unsigned long sfcount[2];
  161. union {
  162. struct ip_mc_list *next;
  163. struct ip_mc_list __rcu *next_rcu;
  164. };
  165. struct timer_list timer;
  166. int users;
  167. atomic_t refcnt;
  168. spinlock_t lock;
  169. char tm_running;
  170. char reporter;
  171. char unsolicit_count;
  172. char loaded;
  173. unsigned char gsquery; /* check source marks? */
  174. unsigned char crcount;
  175. struct rcu_head rcu;
  176. };
  177. /* V3 exponential field decoding */
  178. #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
  179. #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
  180. ((value) < (thresh) ? (value) : \
  181. ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
  182. (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
  183. #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
  184. #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
  185. extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u16 proto);
  186. extern int igmp_rcv(struct sk_buff *);
  187. extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
  188. extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
  189. extern void ip_mc_drop_socket(struct sock *sk);
  190. extern int ip_mc_source(int add, int omode, struct sock *sk,
  191. struct ip_mreq_source *mreqs, int ifindex);
  192. extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
  193. extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
  194. struct ip_msfilter __user *optval, int __user *optlen);
  195. extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
  196. struct group_filter __user *optval, int __user *optlen);
  197. extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt, int dif);
  198. extern void ip_mc_init_dev(struct in_device *);
  199. extern void ip_mc_destroy_dev(struct in_device *);
  200. extern void ip_mc_up(struct in_device *);
  201. extern void ip_mc_down(struct in_device *);
  202. extern void ip_mc_unmap(struct in_device *);
  203. extern void ip_mc_remap(struct in_device *);
  204. extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);
  205. extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
  206. extern void ip_mc_rejoin_groups(struct in_device *in_dev);
  207. #endif
  208. #endif