igmp.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/skbuff.h>
  18. #include <linux/timer.h>
  19. #include <linux/in.h>
  20. #include <linux/refcount.h>
  21. #include <uapi/linux/igmp.h>
  22. static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
  23. {
  24. return (struct igmphdr *)skb_transport_header(skb);
  25. }
  26. static inline struct igmpv3_report *
  27. igmpv3_report_hdr(const struct sk_buff *skb)
  28. {
  29. return (struct igmpv3_report *)skb_transport_header(skb);
  30. }
  31. static inline struct igmpv3_query *
  32. igmpv3_query_hdr(const struct sk_buff *skb)
  33. {
  34. return (struct igmpv3_query *)skb_transport_header(skb);
  35. }
  36. struct ip_sf_socklist {
  37. unsigned int sl_max;
  38. unsigned int sl_count;
  39. struct rcu_head rcu;
  40. __be32 sl_addr[0];
  41. };
  42. #define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
  43. (count) * sizeof(__be32))
  44. #define IP_SFBLOCK 10 /* allocate this many at once */
  45. /* ip_mc_socklist is real list now. Speed is not argument;
  46. this list never used in fast path code
  47. */
  48. struct ip_mc_socklist {
  49. struct ip_mc_socklist __rcu *next_rcu;
  50. struct ip_mreqn multi;
  51. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  52. struct ip_sf_socklist __rcu *sflist;
  53. struct rcu_head rcu;
  54. };
  55. struct ip_sf_list {
  56. struct ip_sf_list *sf_next;
  57. __be32 sf_inaddr;
  58. unsigned long sf_count[2]; /* include/exclude counts */
  59. unsigned char sf_gsresp; /* include in g & s response? */
  60. unsigned char sf_oldin; /* change state */
  61. unsigned char sf_crcount; /* retrans. left to send */
  62. };
  63. struct ip_mc_list {
  64. struct in_device *interface;
  65. __be32 multiaddr;
  66. unsigned int sfmode;
  67. struct ip_sf_list *sources;
  68. struct ip_sf_list *tomb;
  69. unsigned long sfcount[2];
  70. union {
  71. struct ip_mc_list *next;
  72. struct ip_mc_list __rcu *next_rcu;
  73. };
  74. struct ip_mc_list __rcu *next_hash;
  75. struct timer_list timer;
  76. int users;
  77. refcount_t refcnt;
  78. spinlock_t lock;
  79. char tm_running;
  80. char reporter;
  81. char unsolicit_count;
  82. char loaded;
  83. unsigned char gsquery; /* check source marks? */
  84. unsigned char crcount;
  85. struct rcu_head rcu;
  86. };
  87. /* V3 exponential field decoding */
  88. #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
  89. #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
  90. ((value) < (thresh) ? (value) : \
  91. ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
  92. (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
  93. #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
  94. #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
  95. extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
  96. extern int igmp_rcv(struct sk_buff *);
  97. extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
  98. extern int ip_mc_join_group_ssm(struct sock *sk, struct ip_mreqn *imr,
  99. unsigned int mode);
  100. extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
  101. extern void ip_mc_drop_socket(struct sock *sk);
  102. extern int ip_mc_source(int add, int omode, struct sock *sk,
  103. struct ip_mreq_source *mreqs, int ifindex);
  104. extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
  105. extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
  106. struct ip_msfilter __user *optval, int __user *optlen);
  107. extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
  108. struct group_filter __user *optval, int __user *optlen);
  109. extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt,
  110. int dif, int sdif);
  111. extern void ip_mc_init_dev(struct in_device *);
  112. extern void ip_mc_destroy_dev(struct in_device *);
  113. extern void ip_mc_up(struct in_device *);
  114. extern void ip_mc_down(struct in_device *);
  115. extern void ip_mc_unmap(struct in_device *);
  116. extern void ip_mc_remap(struct in_device *);
  117. extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);
  118. extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
  119. int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed);
  120. #endif