Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux NET3: Internet Group Management Protocol [IGMP] |
| 3 | * |
| 4 | * Authors: |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 5 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #ifndef _LINUX_IGMP_H |
| 16 | #define _LINUX_IGMP_H |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/skbuff.h> |
Al Viro | d7fe0f2 | 2006-12-03 23:15:30 -0500 | [diff] [blame] | 19 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/in.h> |
Linus Lüssing | ba5ea614 | 2019-01-21 07:26:25 +0100 | [diff] [blame] | 21 | #include <linux/ip.h> |
Reshetova, Elena | 8851ab5 | 2017-06-30 13:08:02 +0300 | [diff] [blame] | 22 | #include <linux/refcount.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 23 | #include <uapi/linux/igmp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Joe Perches | cc32e05 | 2008-03-23 22:05:44 -0700 | [diff] [blame] | 25 | static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb) |
| 26 | { |
| 27 | return (struct igmphdr *)skb_transport_header(skb); |
| 28 | } |
| 29 | |
| 30 | static inline struct igmpv3_report * |
| 31 | igmpv3_report_hdr(const struct sk_buff *skb) |
| 32 | { |
| 33 | return (struct igmpv3_report *)skb_transport_header(skb); |
| 34 | } |
| 35 | |
| 36 | static inline struct igmpv3_query * |
| 37 | igmpv3_query_hdr(const struct sk_buff *skb) |
| 38 | { |
| 39 | return (struct igmpv3_query *)skb_transport_header(skb); |
| 40 | } |
| 41 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 42 | struct ip_sf_socklist { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | unsigned int sl_max; |
| 44 | unsigned int sl_count; |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 45 | struct rcu_head rcu; |
Al Viro | ea4d9e7 | 2006-09-27 18:30:52 -0700 | [diff] [blame] | 46 | __be32 sl_addr[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | #define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \ |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 50 | (count) * sizeof(__be32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #define IP_SFBLOCK 10 /* allocate this many at once */ |
| 53 | |
| 54 | /* ip_mc_socklist is real list now. Speed is not argument; |
| 55 | this list never used in fast path code |
| 56 | */ |
| 57 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 58 | struct ip_mc_socklist { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 59 | struct ip_mc_socklist __rcu *next_rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct ip_mreqn multi; |
| 61 | unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */ |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 62 | struct ip_sf_socklist __rcu *sflist; |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 63 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 66 | struct ip_sf_list { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | struct ip_sf_list *sf_next; |
Al Viro | ea4d9e7 | 2006-09-27 18:30:52 -0700 | [diff] [blame] | 68 | __be32 sf_inaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | unsigned long sf_count[2]; /* include/exclude counts */ |
| 70 | unsigned char sf_gsresp; /* include in g & s response? */ |
| 71 | unsigned char sf_oldin; /* change state */ |
| 72 | unsigned char sf_crcount; /* retrans. left to send */ |
| 73 | }; |
| 74 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 75 | struct ip_mc_list { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | struct in_device *interface; |
Alexey Dobriyan | 338fcf9 | 2006-06-05 21:04:39 -0700 | [diff] [blame] | 77 | __be32 multiaddr; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 78 | unsigned int sfmode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | struct ip_sf_list *sources; |
| 80 | struct ip_sf_list *tomb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | unsigned long sfcount[2]; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 82 | union { |
| 83 | struct ip_mc_list *next; |
| 84 | struct ip_mc_list __rcu *next_rcu; |
| 85 | }; |
Eric Dumazet | e989707 | 2013-06-07 08:48:57 -0700 | [diff] [blame] | 86 | struct ip_mc_list __rcu *next_hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | struct timer_list timer; |
| 88 | int users; |
Reshetova, Elena | 8851ab5 | 2017-06-30 13:08:02 +0300 | [diff] [blame] | 89 | refcount_t refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | spinlock_t lock; |
| 91 | char tm_running; |
| 92 | char reporter; |
| 93 | char unsolicit_count; |
| 94 | char loaded; |
| 95 | unsigned char gsquery; /* check source marks? */ |
| 96 | unsigned char crcount; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 97 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /* V3 exponential field decoding */ |
| 101 | #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value)) |
| 102 | #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \ |
| 103 | ((value) < (thresh) ? (value) : \ |
David L Stevens | fb47ddb | 2006-11-19 10:38:39 -0800 | [diff] [blame] | 104 | ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp)))) |
| 106 | |
| 107 | #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value) |
| 108 | #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value) |
| 109 | |
Linus Lüssing | ba5ea614 | 2019-01-21 07:26:25 +0100 | [diff] [blame] | 110 | static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len) |
| 111 | { |
| 112 | if (skb_transport_offset(skb) + ip_transport_len(skb) < len) |
| 113 | return -EINVAL; |
| 114 | |
| 115 | return pskb_may_pull(skb, len); |
| 116 | } |
| 117 | |
Alexander Duyck | 2094acb | 2015-09-28 11:10:31 -0700 | [diff] [blame] | 118 | extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | extern int igmp_rcv(struct sk_buff *); |
| 120 | extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr); |
Hangbin Liu | 6e2059b | 2018-07-10 22:41:26 +0800 | [diff] [blame] | 121 | extern int ip_mc_join_group_ssm(struct sock *sk, struct ip_mreqn *imr, |
| 122 | unsigned int mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr); |
| 124 | extern void ip_mc_drop_socket(struct sock *sk); |
| 125 | extern int ip_mc_source(int add, int omode, struct sock *sk, |
| 126 | struct ip_mreq_source *mreqs, int ifindex); |
| 127 | extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex); |
| 128 | extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, |
| 129 | struct ip_msfilter __user *optval, int __user *optlen); |
| 130 | extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf, |
| 131 | struct group_filter __user *optval, int __user *optlen); |
David Ahern | 60d9b03 | 2017-08-07 08:44:19 -0700 | [diff] [blame] | 132 | extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt, |
| 133 | int dif, int sdif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | extern void ip_mc_init_dev(struct in_device *); |
| 135 | extern void ip_mc_destroy_dev(struct in_device *); |
| 136 | extern void ip_mc_up(struct in_device *); |
| 137 | extern void ip_mc_down(struct in_device *); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 138 | extern void ip_mc_unmap(struct in_device *); |
| 139 | extern void ip_mc_remap(struct in_device *); |
Florian Fainelli | 9fb2080 | 2019-02-01 20:20:52 -0800 | [diff] [blame] | 140 | extern void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp); |
| 141 | static inline void ip_mc_dec_group(struct in_device *in_dev, __be32 addr) |
| 142 | { |
| 143 | return __ip_mc_dec_group(in_dev, addr, GFP_KERNEL); |
| 144 | } |
| 145 | extern void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr, |
| 146 | gfp_t gfp); |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 147 | extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr); |
Linus Lüssing | ba5ea614 | 2019-01-21 07:26:25 +0100 | [diff] [blame] | 148 | int ip_mc_check_igmp(struct sk_buff *skb); |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | #endif |