igmp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Linux NET3: Internet Group Management Protocol [IGMP]
  4. *
  5. * Authors:
  6. * Alan Cox <[email protected]>
  7. *
  8. * Extended to talk the BSD extended IGMP protocol of mrouted 3.6
  9. */
  10. #ifndef _LINUX_IGMP_H
  11. #define _LINUX_IGMP_H
  12. #include <linux/skbuff.h>
  13. #include <linux/timer.h>
  14. #include <linux/in.h>
  15. #include <linux/ip.h>
  16. #include <linux/refcount.h>
  17. #include <uapi/linux/igmp.h>
  18. static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
  19. {
  20. return (struct igmphdr *)skb_transport_header(skb);
  21. }
  22. static inline struct igmpv3_report *
  23. igmpv3_report_hdr(const struct sk_buff *skb)
  24. {
  25. return (struct igmpv3_report *)skb_transport_header(skb);
  26. }
  27. static inline struct igmpv3_query *
  28. igmpv3_query_hdr(const struct sk_buff *skb)
  29. {
  30. return (struct igmpv3_query *)skb_transport_header(skb);
  31. }
  32. struct ip_sf_socklist {
  33. unsigned int sl_max;
  34. unsigned int sl_count;
  35. struct rcu_head rcu;
  36. __be32 sl_addr[];
  37. };
  38. #define IP_SFBLOCK 10 /* allocate this many at once */
  39. /* ip_mc_socklist is real list now. Speed is not argument;
  40. this list never used in fast path code
  41. */
  42. struct ip_mc_socklist {
  43. struct ip_mc_socklist __rcu *next_rcu;
  44. struct ip_mreqn multi;
  45. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  46. struct ip_sf_socklist __rcu *sflist;
  47. struct rcu_head rcu;
  48. };
  49. struct ip_sf_list {
  50. struct ip_sf_list *sf_next;
  51. unsigned long sf_count[2]; /* include/exclude counts */
  52. __be32 sf_inaddr;
  53. unsigned char sf_gsresp; /* include in g & s response? */
  54. unsigned char sf_oldin; /* change state */
  55. unsigned char sf_crcount; /* retrans. left to send */
  56. };
  57. struct ip_mc_list {
  58. struct in_device *interface;
  59. __be32 multiaddr;
  60. unsigned int sfmode;
  61. struct ip_sf_list *sources;
  62. struct ip_sf_list *tomb;
  63. unsigned long sfcount[2];
  64. union {
  65. struct ip_mc_list *next;
  66. struct ip_mc_list __rcu *next_rcu;
  67. };
  68. struct ip_mc_list __rcu *next_hash;
  69. struct timer_list timer;
  70. int users;
  71. refcount_t refcnt;
  72. spinlock_t lock;
  73. char tm_running;
  74. char reporter;
  75. char unsolicit_count;
  76. char loaded;
  77. unsigned char gsquery; /* check source marks? */
  78. unsigned char crcount;
  79. struct rcu_head rcu;
  80. };
  81. /* V3 exponential field decoding */
  82. #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
  83. #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
  84. ((value) < (thresh) ? (value) : \
  85. ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
  86. (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
  87. #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
  88. #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
  89. static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
  90. {
  91. if (skb_transport_offset(skb) + ip_transport_len(skb) < len)
  92. return 0;
  93. return pskb_may_pull(skb, len);
  94. }
  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. sockptr_t optval, sockptr_t optlen);
  107. extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
  108. sockptr_t optval, size_t offset);
  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, gfp_t gfp);
  118. static inline void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
  119. {
  120. return __ip_mc_dec_group(in_dev, addr, GFP_KERNEL);
  121. }
  122. extern void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
  123. gfp_t gfp);
  124. extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
  125. int ip_mc_check_igmp(struct sk_buff *skb);
  126. #endif