Merge remote-tracking branches 'asoc/fix/compress', 'asoc/fix/core', 'asoc/fix/dapm...
[linux-2.6-microblaze.git] / include / linux / mroute.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_MROUTE_H
3 #define __LINUX_MROUTE_H
4
5 #include <linux/in.h>
6 #include <linux/pim.h>
7 #include <linux/rhashtable.h>
8 #include <net/sock.h>
9 #include <net/fib_rules.h>
10 #include <net/fib_notifier.h>
11 #include <uapi/linux/mroute.h>
12
13 #ifdef CONFIG_IP_MROUTE
14 static inline int ip_mroute_opt(int opt)
15 {
16         return opt >= MRT_BASE && opt <= MRT_MAX;
17 }
18
19 int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
20 int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
21 int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
22 int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
23 int ip_mr_init(void);
24 bool ipmr_rule_default(const struct fib_rule *rule);
25 #else
26 static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
27                                        char __user *optval, unsigned int optlen)
28 {
29         return -ENOPROTOOPT;
30 }
31
32 static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
33                                        char __user *optval, int __user *optlen)
34 {
35         return -ENOPROTOOPT;
36 }
37
38 static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
39 {
40         return -ENOIOCTLCMD;
41 }
42
43 static inline int ip_mr_init(void)
44 {
45         return 0;
46 }
47
48 static inline int ip_mroute_opt(int opt)
49 {
50         return 0;
51 }
52
53 static inline bool ipmr_rule_default(const struct fib_rule *rule)
54 {
55         return true;
56 }
57 #endif
58
59 struct vif_device {
60         struct net_device       *dev;                   /* Device we are using */
61         struct netdev_phys_item_id dev_parent_id;       /* Device parent ID    */
62         unsigned long   bytes_in,bytes_out;
63         unsigned long   pkt_in,pkt_out;         /* Statistics                   */
64         unsigned long   rate_limit;             /* Traffic shaping (NI)         */
65         unsigned char   threshold;              /* TTL threshold                */
66         unsigned short  flags;                  /* Control flags                */
67         __be32          local,remote;           /* Addresses(remote for tunnels)*/
68         int             link;                   /* Physical interface index     */
69 };
70
71 struct vif_entry_notifier_info {
72         struct fib_notifier_info info;
73         struct net_device *dev;
74         vifi_t vif_index;
75         unsigned short vif_flags;
76         u32 tb_id;
77 };
78
79 #define VIFF_STATIC 0x8000
80
81 #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
82
83 struct mr_table {
84         struct list_head        list;
85         possible_net_t          net;
86         u32                     id;
87         struct sock __rcu       *mroute_sk;
88         struct timer_list       ipmr_expire_timer;
89         struct list_head        mfc_unres_queue;
90         struct vif_device       vif_table[MAXVIFS];
91         struct rhltable         mfc_hash;
92         struct list_head        mfc_cache_list;
93         int                     maxvif;
94         atomic_t                cache_resolve_queue_len;
95         bool                    mroute_do_assert;
96         bool                    mroute_do_pim;
97         int                     mroute_reg_vif_num;
98 };
99
100 /* mfc_flags:
101  * MFC_STATIC - the entry was added statically (not by a routing daemon)
102  * MFC_OFFLOAD - the entry was offloaded to the hardware
103  */
104 enum {
105         MFC_STATIC = BIT(0),
106         MFC_OFFLOAD = BIT(1),
107 };
108
109 struct mfc_cache_cmp_arg {
110         __be32 mfc_mcastgrp;
111         __be32 mfc_origin;
112 };
113
114 /**
115  * struct mfc_cache - multicast routing entries
116  * @mnode: rhashtable list
117  * @mfc_mcastgrp: destination multicast group address
118  * @mfc_origin: source address
119  * @cmparg: used for rhashtable comparisons
120  * @mfc_parent: source interface (iif)
121  * @mfc_flags: entry flags
122  * @expires: unresolved entry expire time
123  * @unresolved: unresolved cached skbs
124  * @last_assert: time of last assert
125  * @minvif: minimum VIF id
126  * @maxvif: maximum VIF id
127  * @bytes: bytes that have passed for this entry
128  * @pkt: packets that have passed for this entry
129  * @wrong_if: number of wrong source interface hits
130  * @lastuse: time of last use of the group (traffic or update)
131  * @ttls: OIF TTL threshold array
132  * @refcount: reference count for this entry
133  * @list: global entry list
134  * @rcu: used for entry destruction
135  */
136 struct mfc_cache {
137         struct rhlist_head mnode;
138         union {
139                 struct {
140                         __be32 mfc_mcastgrp;
141                         __be32 mfc_origin;
142                 };
143                 struct mfc_cache_cmp_arg cmparg;
144         };
145         vifi_t mfc_parent;
146         int mfc_flags;
147
148         union {
149                 struct {
150                         unsigned long expires;
151                         struct sk_buff_head unresolved;
152                 } unres;
153                 struct {
154                         unsigned long last_assert;
155                         int minvif;
156                         int maxvif;
157                         unsigned long bytes;
158                         unsigned long pkt;
159                         unsigned long wrong_if;
160                         unsigned long lastuse;
161                         unsigned char ttls[MAXVIFS];
162                         refcount_t refcount;
163                 } res;
164         } mfc_un;
165         struct list_head list;
166         struct rcu_head rcu;
167 };
168
169 struct mfc_entry_notifier_info {
170         struct fib_notifier_info info;
171         struct mfc_cache *mfc;
172         u32 tb_id;
173 };
174
175 struct rtmsg;
176 int ipmr_get_route(struct net *net, struct sk_buff *skb,
177                    __be32 saddr, __be32 daddr,
178                    struct rtmsg *rtm, u32 portid);
179
180 #ifdef CONFIG_IP_MROUTE
181 void ipmr_cache_free(struct mfc_cache *mfc_cache);
182 #else
183 static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
184 {
185 }
186 #endif
187
188 static inline void ipmr_cache_put(struct mfc_cache *c)
189 {
190         if (refcount_dec_and_test(&c->mfc_un.res.refcount))
191                 ipmr_cache_free(c);
192 }
193 static inline void ipmr_cache_hold(struct mfc_cache *c)
194 {
195         refcount_inc(&c->mfc_un.res.refcount);
196 }
197
198 #endif