Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  Linux NET3: Internet Group Management Protocol  [IGMP]
0004  *
0005  *  Authors:
0006  *      Alan Cox <alan@lxorguk.ukuu.org.uk>
0007  *
0008  *  Extended to talk the BSD extended IGMP protocol of mrouted 3.6
0009  */
0010 #ifndef _LINUX_IGMP_H
0011 #define _LINUX_IGMP_H
0012 
0013 #include <linux/skbuff.h>
0014 #include <linux/timer.h>
0015 #include <linux/in.h>
0016 #include <linux/ip.h>
0017 #include <linux/refcount.h>
0018 #include <uapi/linux/igmp.h>
0019 
0020 static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb)
0021 {
0022     return (struct igmphdr *)skb_transport_header(skb);
0023 }
0024 
0025 static inline struct igmpv3_report *
0026             igmpv3_report_hdr(const struct sk_buff *skb)
0027 {
0028     return (struct igmpv3_report *)skb_transport_header(skb);
0029 }
0030 
0031 static inline struct igmpv3_query *
0032             igmpv3_query_hdr(const struct sk_buff *skb)
0033 {
0034     return (struct igmpv3_query *)skb_transport_header(skb);
0035 }
0036 
0037 struct ip_sf_socklist {
0038     unsigned int        sl_max;
0039     unsigned int        sl_count;
0040     struct rcu_head     rcu;
0041     __be32          sl_addr[];
0042 };
0043 
0044 #define IP_SFBLOCK  10  /* allocate this many at once */
0045 
0046 /* ip_mc_socklist is real list now. Speed is not argument;
0047    this list never used in fast path code
0048  */
0049 
0050 struct ip_mc_socklist {
0051     struct ip_mc_socklist __rcu *next_rcu;
0052     struct ip_mreqn     multi;
0053     unsigned int        sfmode;     /* MCAST_{INCLUDE,EXCLUDE} */
0054     struct ip_sf_socklist __rcu *sflist;
0055     struct rcu_head     rcu;
0056 };
0057 
0058 struct ip_sf_list {
0059     struct ip_sf_list   *sf_next;
0060     unsigned long       sf_count[2];    /* include/exclude counts */
0061     __be32          sf_inaddr;
0062     unsigned char       sf_gsresp;  /* include in g & s response? */
0063     unsigned char       sf_oldin;   /* change state */
0064     unsigned char       sf_crcount; /* retrans. left to send */
0065 };
0066 
0067 struct ip_mc_list {
0068     struct in_device    *interface;
0069     __be32          multiaddr;
0070     unsigned int        sfmode;
0071     struct ip_sf_list   *sources;
0072     struct ip_sf_list   *tomb;
0073     unsigned long       sfcount[2];
0074     union {
0075         struct ip_mc_list *next;
0076         struct ip_mc_list __rcu *next_rcu;
0077     };
0078     struct ip_mc_list __rcu *next_hash;
0079     struct timer_list   timer;
0080     int         users;
0081     refcount_t      refcnt;
0082     spinlock_t      lock;
0083     char            tm_running;
0084     char            reporter;
0085     char            unsolicit_count;
0086     char            loaded;
0087     unsigned char       gsquery;    /* check source marks? */
0088     unsigned char       crcount;
0089     struct rcu_head     rcu;
0090 };
0091 
0092 /* V3 exponential field decoding */
0093 #define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
0094 #define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
0095     ((value) < (thresh) ? (value) : \
0096         ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
0097          (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
0098 
0099 #define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
0100 #define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
0101 
0102 static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
0103 {
0104     if (skb_transport_offset(skb) + ip_transport_len(skb) < len)
0105         return 0;
0106 
0107     return pskb_may_pull(skb, len);
0108 }
0109 
0110 extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u8 proto);
0111 extern int igmp_rcv(struct sk_buff *);
0112 extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
0113 extern int ip_mc_join_group_ssm(struct sock *sk, struct ip_mreqn *imr,
0114                 unsigned int mode);
0115 extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
0116 extern void ip_mc_drop_socket(struct sock *sk);
0117 extern int ip_mc_source(int add, int omode, struct sock *sk,
0118         struct ip_mreq_source *mreqs, int ifindex);
0119 extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);
0120 extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
0121         struct ip_msfilter __user *optval, int __user *optlen);
0122 extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
0123             struct sockaddr_storage __user *p);
0124 extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt,
0125               int dif, int sdif);
0126 extern void ip_mc_init_dev(struct in_device *);
0127 extern void ip_mc_destroy_dev(struct in_device *);
0128 extern void ip_mc_up(struct in_device *);
0129 extern void ip_mc_down(struct in_device *);
0130 extern void ip_mc_unmap(struct in_device *);
0131 extern void ip_mc_remap(struct in_device *);
0132 extern void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp);
0133 static inline void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
0134 {
0135     return __ip_mc_dec_group(in_dev, addr, GFP_KERNEL);
0136 }
0137 extern void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
0138                   gfp_t gfp);
0139 extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
0140 int ip_mc_check_igmp(struct sk_buff *skb);
0141 
0142 #endif