igmp.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Linux NET3: Internet Group Management Protocol [IGMP]
  4. *
  5. * Authors:
  6. * Alan Cox <alan@lxorguk.ukuu.org.uk>
  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_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
  39. (count) * sizeof(__be32))
  40. #define IP_SFBLOCK 10 /* allocate this many at once */
  41. /* ip_mc_socklist is real list now. Speed is not argument;
  42. this list never used in fast path code
  43. */
  44. struct ip_mc_socklist {
  45. struct ip_mc_socklist __rcu *next_rcu;
  46. struct ip_mreqn multi;
  47. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  48. struct ip_sf_socklist __rcu *sflist;
  49. struct rcu_head rcu;
  50. };
  51. struct ip_sf_list {
  52. struct ip_sf_list *sf_next;
  53. unsigned long sf_count[2]; /* include/exclude counts */
  54. __be32 sf_inaddr;
  55. unsigned char sf_gsresp; /* include in g & s response? */
  56. unsigned char sf_oldin; /* change state */
  57. unsigned char sf_crcount; /* retrans. left to send */
  58. };
  59. struct ip_mc_list {
  60. struct in_device *interface;
  61. __be32 multiaddr;
  62. unsigned int sfmode;
  63. struct ip_sf_list *sources;
  64. struct ip_sf_list *tomb;
  65. unsigned long sfcount[2];
  66. union {
  67. struct ip_mc_list *next;
  68. struct ip_mc_list __rcu *next_rcu;
  69. };
  70. struct ip_mc_list __rcu *next_hash;
  71. struct timer_list timer;
  72. int users;
  73. refcount_t refcnt;
  74. spinlock_t lock;
  75. char tm_running;
  76. char reporter;
  77. char unsolicit_count;
  78. char loaded;
  79. unsigned char gsquery; /* check source marks? */
  80. unsigned char crcount;
  81. struct rcu_head rcu;
  82. };
  83. /* V3 exponential field decoding */
  84. #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
  85. #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
  86. ((value) < (thresh) ? (value) : \
  87. ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
  88. (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
  89. #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
  90. #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
  91. static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
  92. {
  93. if (skb_transport_offset(skb) + ip_transport_len(skb) < len)
  94. return 0;
  95. return pskb_may_pull(skb, len);
  96. }
  97. extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
  98. extern int igmp_rcv(struct sk_buff *);
  99. extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
  100. extern int ip_mc_join_group_ssm(struct sock *sk, struct ip_mreqn *imr,
  101. unsigned int mode);
  102. extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
  103. extern void ip_mc_drop_socket(struct sock *sk);
  104. extern int ip_mc_source(int add, int omode, struct sock *sk,
  105. struct ip_mreq_source *mreqs, int ifindex);
  106. extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
  107. extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
  108. struct ip_msfilter __user *optval, int __user *optlen);
  109. extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
  110. struct sockaddr_storage __user *p);
  111. extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt,
  112. int dif, int sdif);
  113. extern void ip_mc_init_dev(struct in_device *);
  114. extern void ip_mc_destroy_dev(struct in_device *);
  115. extern void ip_mc_up(struct in_device *);
  116. extern void ip_mc_down(struct in_device *);
  117. extern void ip_mc_unmap(struct in_device *);
  118. extern void ip_mc_remap(struct in_device *);
  119. extern void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp);
  120. static inline void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
  121. {
  122. return __ip_mc_dec_group(in_dev, addr, GFP_KERNEL);
  123. }
  124. extern void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
  125. gfp_t gfp);
  126. extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
  127. int ip_mc_check_igmp(struct sk_buff *skb);
  128. #endif