blob: 97caf1821de8ceebe6016b134ae291d802fcb78d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Linux NET3: Internet Group Management Protocol [IGMP]
3 *
4 * Authors:
Alan Cox113aa832008-10-13 19:01:08 -07005 * Alan Cox <alan@lxorguk.ukuu.org.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#ifndef _LINUX_IGMP_H
16#define _LINUX_IGMP_H
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/skbuff.h>
Al Virod7fe0f22006-12-03 23:15:30 -050019#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/in.h>
Reshetova, Elena8851ab52017-06-30 13:08:02 +030021#include <linux/refcount.h>
David Howells607ca462012-10-13 10:46:48 +010022#include <uapi/linux/igmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Joe Perchescc32e052008-03-23 22:05:44 -070024static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
25{
26 return (struct igmphdr *)skb_transport_header(skb);
27}
28
29static inline struct igmpv3_report *
30 igmpv3_report_hdr(const struct sk_buff *skb)
31{
32 return (struct igmpv3_report *)skb_transport_header(skb);
33}
34
35static inline struct igmpv3_query *
36 igmpv3_query_hdr(const struct sk_buff *skb)
37{
38 return (struct igmpv3_query *)skb_transport_header(skb);
39}
40
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080041struct ip_sf_socklist {
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 unsigned int sl_max;
43 unsigned int sl_count;
Flavio Leitnerc85bb412010-02-02 07:32:29 -080044 struct rcu_head rcu;
Al Viroea4d9e72006-09-27 18:30:52 -070045 __be32 sl_addr[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
48#define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
Al Viro63007722006-09-27 18:31:32 -070049 (count) * sizeof(__be32))
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define IP_SFBLOCK 10 /* allocate this many at once */
52
53/* ip_mc_socklist is real list now. Speed is not argument;
54 this list never used in fast path code
55 */
56
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080057struct ip_mc_socklist {
Eric Dumazet1d7138d2010-11-12 05:46:50 +000058 struct ip_mc_socklist __rcu *next_rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 struct ip_mreqn multi;
60 unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
Eric Dumazet1d7138d2010-11-12 05:46:50 +000061 struct ip_sf_socklist __rcu *sflist;
Flavio Leitnerc85bb412010-02-02 07:32:29 -080062 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080065struct ip_sf_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 struct ip_sf_list *sf_next;
Al Viroea4d9e72006-09-27 18:30:52 -070067 __be32 sf_inaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 unsigned long sf_count[2]; /* include/exclude counts */
69 unsigned char sf_gsresp; /* include in g & s response? */
70 unsigned char sf_oldin; /* change state */
71 unsigned char sf_crcount; /* retrans. left to send */
72};
73
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080074struct ip_mc_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 struct in_device *interface;
Alexey Dobriyan338fcf92006-06-05 21:04:39 -070076 __be32 multiaddr;
Eric Dumazet1d7138d2010-11-12 05:46:50 +000077 unsigned int sfmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 struct ip_sf_list *sources;
79 struct ip_sf_list *tomb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 unsigned long sfcount[2];
Eric Dumazet1d7138d2010-11-12 05:46:50 +000081 union {
82 struct ip_mc_list *next;
83 struct ip_mc_list __rcu *next_rcu;
84 };
Eric Dumazete9897072013-06-07 08:48:57 -070085 struct ip_mc_list __rcu *next_hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 struct timer_list timer;
87 int users;
Reshetova, Elena8851ab52017-06-30 13:08:02 +030088 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 spinlock_t lock;
90 char tm_running;
91 char reporter;
92 char unsolicit_count;
93 char loaded;
94 unsigned char gsquery; /* check source marks? */
95 unsigned char crcount;
Eric Dumazet1d7138d2010-11-12 05:46:50 +000096 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99/* V3 exponential field decoding */
100#define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
101#define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
102 ((value) < (thresh) ? (value) : \
David L Stevensfb47ddb2006-11-19 10:38:39 -0800103 ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
105
106#define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
107#define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
108
Alexander Duyck2094acb2015-09-28 11:10:31 -0700109extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110extern int igmp_rcv(struct sk_buff *);
111extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
112extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
113extern void ip_mc_drop_socket(struct sock *sk);
114extern int ip_mc_source(int add, int omode, struct sock *sk,
115 struct ip_mreq_source *mreqs, int ifindex);
116extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
117extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
118 struct ip_msfilter __user *optval, int __user *optlen);
119extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
120 struct group_filter __user *optval, int __user *optlen);
Al Viroc0cda062006-09-27 18:31:10 -0700121extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt, int dif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122extern void ip_mc_init_dev(struct in_device *);
123extern void ip_mc_destroy_dev(struct in_device *);
124extern void ip_mc_up(struct in_device *);
125extern void ip_mc_down(struct in_device *);
Moni Shoua75c78502009-09-15 02:37:40 -0700126extern void ip_mc_unmap(struct in_device *);
127extern void ip_mc_remap(struct in_device *);
Al Viro8f935bb2006-09-27 18:30:07 -0700128extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);
129extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
Linus Lüssing9afd85c2015-05-02 14:01:07 +0200130int ip_mc_check_igmp(struct sk_buff *skb, struct sk_buff **skb_trimmed);
Jay Vosburgha816c7c2007-02-28 17:03:37 -0800131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif