1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Linux NET3: Internet Group Management Protocol [IGMP]
6 * Alan Cox <alan@lxorguk.ukuu.org.uk>
8 * Extended to talk the BSD extended IGMP protocol of mrouted 3.6
13 #include <linux/skbuff.h>
14 #include <linux/timer.h>
17 #include <linux/refcount.h>
18 #include <linux/sockptr.h>
19 #include <uapi/linux/igmp.h>
21 static inline struct igmphdr
*igmp_hdr(const struct sk_buff
*skb
)
23 return (struct igmphdr
*)skb_transport_header(skb
);
26 static inline struct igmpv3_report
*
27 igmpv3_report_hdr(const struct sk_buff
*skb
)
29 return (struct igmpv3_report
*)skb_transport_header(skb
);
32 static inline struct igmpv3_query
*
33 igmpv3_query_hdr(const struct sk_buff
*skb
)
35 return (struct igmpv3_query
*)skb_transport_header(skb
);
38 struct ip_sf_socklist
{
40 unsigned int sl_count
;
42 __be32 sl_addr
[] __counted_by(sl_max
);
45 #define IP_SFBLOCK 10 /* allocate this many at once */
47 /* ip_mc_socklist is real list now. Speed is not argument;
48 this list never used in fast path code
51 struct ip_mc_socklist
{
52 struct ip_mc_socklist __rcu
*next_rcu
;
53 struct ip_mreqn multi
;
54 unsigned int sfmode
; /* MCAST_{INCLUDE,EXCLUDE} */
55 struct ip_sf_socklist __rcu
*sflist
;
60 struct ip_sf_list
*sf_next
;
61 unsigned long sf_count
[2]; /* include/exclude counts */
63 unsigned char sf_gsresp
; /* include in g & s response? */
64 unsigned char sf_oldin
; /* change state */
65 unsigned char sf_crcount
; /* retrans. left to send */
69 struct in_device
*interface
;
72 struct ip_sf_list
*sources
;
73 struct ip_sf_list
*tomb
;
74 unsigned long sfcount
[2];
76 struct ip_mc_list
*next
;
77 struct ip_mc_list __rcu
*next_rcu
;
79 struct ip_mc_list __rcu
*next_hash
;
80 struct timer_list timer
;
88 unsigned char gsquery
; /* check source marks? */
89 unsigned char crcount
;
93 /* V3 exponential field decoding */
94 #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
95 #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
96 ((value) < (thresh) ? (value) : \
97 ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
98 (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
100 #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
101 #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
103 static inline int ip_mc_may_pull(struct sk_buff
*skb
, unsigned int len
)
105 if (skb_transport_offset(skb
) + ip_transport_len(skb
) < len
)
108 return pskb_may_pull(skb
, len
);
111 extern int ip_check_mc_rcu(struct in_device
*dev
, __be32 mc_addr
, __be32 src_addr
, u8 proto
);
112 extern int igmp_rcv(struct sk_buff
*);
113 extern int ip_mc_join_group(struct sock
*sk
, struct ip_mreqn
*imr
);
114 extern int ip_mc_join_group_ssm(struct sock
*sk
, struct ip_mreqn
*imr
,
116 extern int ip_mc_leave_group(struct sock
*sk
, struct ip_mreqn
*imr
);
117 extern void ip_mc_drop_socket(struct sock
*sk
);
118 extern int ip_mc_source(int add
, int omode
, struct sock
*sk
,
119 struct ip_mreq_source
*mreqs
, int ifindex
);
120 extern int ip_mc_msfilter(struct sock
*sk
, struct ip_msfilter
*msf
,int ifindex
);
121 extern int ip_mc_msfget(struct sock
*sk
, struct ip_msfilter
*msf
,
122 sockptr_t optval
, sockptr_t optlen
);
123 extern int ip_mc_gsfget(struct sock
*sk
, struct group_filter
*gsf
,
124 sockptr_t optval
, size_t offset
);
125 extern int ip_mc_sf_allow(const struct sock
*sk
, __be32 local
, __be32 rmt
,
127 extern void ip_mc_init_dev(struct in_device
*);
128 extern void ip_mc_destroy_dev(struct in_device
*);
129 extern void ip_mc_up(struct in_device
*);
130 extern void ip_mc_down(struct in_device
*);
131 extern void ip_mc_unmap(struct in_device
*);
132 extern void ip_mc_remap(struct in_device
*);
133 extern void __ip_mc_dec_group(struct in_device
*in_dev
, __be32 addr
, gfp_t gfp
);
134 static inline void ip_mc_dec_group(struct in_device
*in_dev
, __be32 addr
)
136 return __ip_mc_dec_group(in_dev
, addr
, GFP_KERNEL
);
138 extern void __ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
,
140 extern void ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
);
141 int ip_mc_check_igmp(struct sk_buff
*skb
);