blob: faa6586a57838554cf02402d6659691f17bd458f [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Linux NET3: Internet Group Management Protocol [IGMP]
4 *
5 * Authors:
Alan Cox113aa832008-10-13 19:01:08 -07006 * Alan Cox <alan@lxorguk.ukuu.org.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * Extended to talk the BSD extended IGMP protocol of mrouted 3.6
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#ifndef _LINUX_IGMP_H
11#define _LINUX_IGMP_H
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/skbuff.h>
Al Virod7fe0f22006-12-03 23:15:30 -050014#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/in.h>
Linus Lüssingba5ea6142019-01-21 07:26:25 +010016#include <linux/ip.h>
Reshetova, Elena8851ab52017-06-30 13:08:02 +030017#include <linux/refcount.h>
David Howells607ca462012-10-13 10:46:48 +010018#include <uapi/linux/igmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Joe Perchescc32e052008-03-23 22:05:44 -070020static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
21{
22 return (struct igmphdr *)skb_transport_header(skb);
23}
24
25static inline struct igmpv3_report *
26 igmpv3_report_hdr(const struct sk_buff *skb)
27{
28 return (struct igmpv3_report *)skb_transport_header(skb);
29}
30
31static 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
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080037struct ip_sf_socklist {
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 unsigned int sl_max;
39 unsigned int sl_count;
Flavio Leitnerc85bb412010-02-02 07:32:29 -080040 struct rcu_head rcu;
Gustavo A. R. Silva0ead3362020-03-23 17:59:00 -050041 __be32 sl_addr[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070042};
43
44#define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
Al Viro63007722006-09-27 18:31:32 -070045 (count) * sizeof(__be32))
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#define IP_SFBLOCK 10 /* allocate this many at once */
48
49/* ip_mc_socklist is real list now. Speed is not argument;
50 this list never used in fast path code
51 */
52
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080053struct ip_mc_socklist {
Eric Dumazet1d7138d2010-11-12 05:46:50 +000054 struct ip_mc_socklist __rcu *next_rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 struct ip_mreqn multi;
56 unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
Eric Dumazet1d7138d2010-11-12 05:46:50 +000057 struct ip_sf_socklist __rcu *sflist;
Flavio Leitnerc85bb412010-02-02 07:32:29 -080058 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080061struct ip_sf_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 struct ip_sf_list *sf_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned long sf_count[2]; /* include/exclude counts */
Eric Dumazet0db355d2019-05-22 15:00:25 -070064 __be32 sf_inaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 unsigned char sf_gsresp; /* include in g & s response? */
66 unsigned char sf_oldin; /* change state */
67 unsigned char sf_crcount; /* retrans. left to send */
68};
69
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080070struct ip_mc_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 struct in_device *interface;
Alexey Dobriyan338fcf92006-06-05 21:04:39 -070072 __be32 multiaddr;
Eric Dumazet1d7138d2010-11-12 05:46:50 +000073 unsigned int sfmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 struct ip_sf_list *sources;
75 struct ip_sf_list *tomb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 unsigned long sfcount[2];
Eric Dumazet1d7138d2010-11-12 05:46:50 +000077 union {
78 struct ip_mc_list *next;
79 struct ip_mc_list __rcu *next_rcu;
80 };
Eric Dumazete9897072013-06-07 08:48:57 -070081 struct ip_mc_list __rcu *next_hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 struct timer_list timer;
83 int users;
Reshetova, Elena8851ab52017-06-30 13:08:02 +030084 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 spinlock_t lock;
86 char tm_running;
87 char reporter;
88 char unsolicit_count;
89 char loaded;
90 unsigned char gsquery; /* check source marks? */
91 unsigned char crcount;
Eric Dumazet1d7138d2010-11-12 05:46:50 +000092 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
95/* V3 exponential field decoding */
96#define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
97#define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
98 ((value) < (thresh) ? (value) : \
David L Stevensfb47ddb2006-11-19 10:38:39 -080099 ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
101
102#define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
103#define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
104
Linus Lüssingba5ea6142019-01-21 07:26:25 +0100105static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
106{
107 if (skb_transport_offset(skb) + ip_transport_len(skb) < len)
Eric Dumazet083b78a92019-03-09 14:43:38 -0800108 return 0;
Linus Lüssingba5ea6142019-01-21 07:26:25 +0100109
110 return pskb_may_pull(skb, len);
111}
112
Alexander Duyck2094acb2015-09-28 11:10:31 -0700113extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern int igmp_rcv(struct sk_buff *);
115extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
Hangbin Liu6e2059b2018-07-10 22:41:26 +0800116extern int ip_mc_join_group_ssm(struct sock *sk, struct ip_mreqn *imr,
117 unsigned int mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
119extern void ip_mc_drop_socket(struct sock *sk);
120extern int ip_mc_source(int add, int omode, struct sock *sk,
121 struct ip_mreq_source *mreqs, int ifindex);
122extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
123extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
124 struct ip_msfilter __user *optval, int __user *optlen);
125extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
126 struct group_filter __user *optval, int __user *optlen);
David Ahern60d9b032017-08-07 08:44:19 -0700127extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt,
128 int dif, int sdif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129extern void ip_mc_init_dev(struct in_device *);
130extern void ip_mc_destroy_dev(struct in_device *);
131extern void ip_mc_up(struct in_device *);
132extern void ip_mc_down(struct in_device *);
Moni Shoua75c78502009-09-15 02:37:40 -0700133extern void ip_mc_unmap(struct in_device *);
134extern void ip_mc_remap(struct in_device *);
Florian Fainelli9fb20802019-02-01 20:20:52 -0800135extern void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp);
136static inline void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
137{
138 return __ip_mc_dec_group(in_dev, addr, GFP_KERNEL);
139}
140extern void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
141 gfp_t gfp);
Al Viro8f935bb2006-09-27 18:30:07 -0700142extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
Linus Lüssingba5ea6142019-01-21 07:26:25 +0100143int ip_mc_check_igmp(struct sk_buff *skb);
Jay Vosburgha816c7c2007-02-28 17:03:37 -0800144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif