blob: f47550d75f85fddd53186c92f0e1383c8f693b90 [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>
David Howells607ca462012-10-13 10:46:48 +010021#include <uapi/linux/igmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Joe Perchescc32e052008-03-23 22:05:44 -070023static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
24{
25 return (struct igmphdr *)skb_transport_header(skb);
26}
27
28static inline struct igmpv3_report *
29 igmpv3_report_hdr(const struct sk_buff *skb)
30{
31 return (struct igmpv3_report *)skb_transport_header(skb);
32}
33
34static inline struct igmpv3_query *
35 igmpv3_query_hdr(const struct sk_buff *skb)
36{
37 return (struct igmpv3_query *)skb_transport_header(skb);
38}
39
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030040extern int sysctl_igmp_max_memberships;
41extern int sysctl_igmp_max_msf;
42
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080043struct ip_sf_socklist {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 unsigned int sl_max;
45 unsigned int sl_count;
Flavio Leitnerc85bb412010-02-02 07:32:29 -080046 struct rcu_head rcu;
Al Viroea4d9e72006-09-27 18:30:52 -070047 __be32 sl_addr[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070048};
49
50#define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
Al Viro63007722006-09-27 18:31:32 -070051 (count) * sizeof(__be32))
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#define IP_SFBLOCK 10 /* allocate this many at once */
54
55/* ip_mc_socklist is real list now. Speed is not argument;
56 this list never used in fast path code
57 */
58
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080059struct ip_mc_socklist {
Eric Dumazet1d7138d2010-11-12 05:46:50 +000060 struct ip_mc_socklist __rcu *next_rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 struct ip_mreqn multi;
62 unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
Eric Dumazet1d7138d2010-11-12 05:46:50 +000063 struct ip_sf_socklist __rcu *sflist;
Flavio Leitnerc85bb412010-02-02 07:32:29 -080064 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080067struct ip_sf_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 struct ip_sf_list *sf_next;
Al Viroea4d9e72006-09-27 18:30:52 -070069 __be32 sf_inaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 unsigned long sf_count[2]; /* include/exclude counts */
71 unsigned char sf_gsresp; /* include in g & s response? */
72 unsigned char sf_oldin; /* change state */
73 unsigned char sf_crcount; /* retrans. left to send */
74};
75
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080076struct ip_mc_list {
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 struct in_device *interface;
Alexey Dobriyan338fcf92006-06-05 21:04:39 -070078 __be32 multiaddr;
Eric Dumazet1d7138d2010-11-12 05:46:50 +000079 unsigned int sfmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 struct ip_sf_list *sources;
81 struct ip_sf_list *tomb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 unsigned long sfcount[2];
Eric Dumazet1d7138d2010-11-12 05:46:50 +000083 union {
84 struct ip_mc_list *next;
85 struct ip_mc_list __rcu *next_rcu;
86 };
Eric Dumazete9897072013-06-07 08:48:57 -070087 struct ip_mc_list __rcu *next_hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 struct timer_list timer;
89 int users;
90 atomic_t refcnt;
91 spinlock_t lock;
92 char tm_running;
93 char reporter;
94 char unsolicit_count;
95 char loaded;
96 unsigned char gsquery; /* check source marks? */
97 unsigned char crcount;
Eric Dumazet1d7138d2010-11-12 05:46:50 +000098 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
101/* V3 exponential field decoding */
102#define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
103#define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
104 ((value) < (thresh) ? (value) : \
David L Stevensfb47ddb2006-11-19 10:38:39 -0800105 ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
107
108#define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
109#define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
110
David S. Millerdbdd9a52011-03-10 16:34:38 -0800111extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u16 proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112extern int igmp_rcv(struct sk_buff *);
113extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
114extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
115extern void ip_mc_drop_socket(struct sock *sk);
116extern int ip_mc_source(int add, int omode, struct sock *sk,
117 struct ip_mreq_source *mreqs, int ifindex);
118extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
119extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
120 struct ip_msfilter __user *optval, int __user *optlen);
121extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
122 struct group_filter __user *optval, int __user *optlen);
Al Viroc0cda062006-09-27 18:31:10 -0700123extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt, int dif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124extern void ip_mc_init_dev(struct in_device *);
125extern void ip_mc_destroy_dev(struct in_device *);
126extern void ip_mc_up(struct in_device *);
127extern void ip_mc_down(struct in_device *);
Moni Shoua75c78502009-09-15 02:37:40 -0700128extern void ip_mc_unmap(struct in_device *);
129extern void ip_mc_remap(struct in_device *);
Al Viro8f935bb2006-09-27 18:30:07 -0700130extern void ip_mc_dec_group(struct in_device *in_dev, __be32 addr);
131extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
Jay Vosburgha816c7c2007-02-28 17:03:37 -0800132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#endif