GNU Linux-libre 4.14.251-gnu1
[releases.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 <uapi/linux/mroute.h>
10
11 #ifdef CONFIG_IP_MROUTE
12 static inline int ip_mroute_opt(int opt)
13 {
14         return opt >= MRT_BASE && opt <= MRT_MAX;
15 }
16
17 int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
18 int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
19 int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
20 int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
21 int ip_mr_init(void);
22 #else
23 static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
24                                        char __user *optval, unsigned int optlen)
25 {
26         return -ENOPROTOOPT;
27 }
28
29 static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
30                                        char __user *optval, int __user *optlen)
31 {
32         return -ENOPROTOOPT;
33 }
34
35 static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
36 {
37         return -ENOIOCTLCMD;
38 }
39
40 static inline int ip_mr_init(void)
41 {
42         return 0;
43 }
44
45 static inline int ip_mroute_opt(int opt)
46 {
47         return 0;
48 }
49 #endif
50
51 struct vif_device {
52         struct net_device       *dev;                   /* Device we are using */
53         unsigned long   bytes_in,bytes_out;
54         unsigned long   pkt_in,pkt_out;         /* Statistics                   */
55         unsigned long   rate_limit;             /* Traffic shaping (NI)         */
56         unsigned char   threshold;              /* TTL threshold                */
57         unsigned short  flags;                  /* Control flags                */
58         __be32          local,remote;           /* Addresses(remote for tunnels)*/
59         int             link;                   /* Physical interface index     */
60 };
61
62 #define VIFF_STATIC 0x8000
63
64 #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
65
66 struct mr_table {
67         struct list_head        list;
68         possible_net_t          net;
69         u32                     id;
70         struct sock __rcu       *mroute_sk;
71         struct timer_list       ipmr_expire_timer;
72         struct list_head        mfc_unres_queue;
73         struct vif_device       vif_table[MAXVIFS];
74         struct rhltable         mfc_hash;
75         struct list_head        mfc_cache_list;
76         int                     maxvif;
77         atomic_t                cache_resolve_queue_len;
78         bool                    mroute_do_assert;
79         bool                    mroute_do_pim;
80         int                     mroute_reg_vif_num;
81 };
82
83 /* mfc_flags:
84  * MFC_STATIC - the entry was added statically (not by a routing daemon)
85  */
86 enum {
87         MFC_STATIC = BIT(0),
88 };
89
90 struct mfc_cache_cmp_arg {
91         __be32 mfc_mcastgrp;
92         __be32 mfc_origin;
93 };
94
95 /**
96  * struct mfc_cache - multicast routing entries
97  * @mnode: rhashtable list
98  * @mfc_mcastgrp: destination multicast group address
99  * @mfc_origin: source address
100  * @cmparg: used for rhashtable comparisons
101  * @mfc_parent: source interface (iif)
102  * @mfc_flags: entry flags
103  * @expires: unresolved entry expire time
104  * @unresolved: unresolved cached skbs
105  * @last_assert: time of last assert
106  * @minvif: minimum VIF id
107  * @maxvif: maximum VIF id
108  * @bytes: bytes that have passed for this entry
109  * @pkt: packets that have passed for this entry
110  * @wrong_if: number of wrong source interface hits
111  * @lastuse: time of last use of the group (traffic or update)
112  * @ttls: OIF TTL threshold array
113  * @list: global entry list
114  * @rcu: used for entry destruction
115  */
116 struct mfc_cache {
117         struct rhlist_head mnode;
118         union {
119                 struct {
120                         __be32 mfc_mcastgrp;
121                         __be32 mfc_origin;
122                 };
123                 struct mfc_cache_cmp_arg cmparg;
124         };
125         vifi_t mfc_parent;
126         int mfc_flags;
127
128         union {
129                 struct {
130                         unsigned long expires;
131                         struct sk_buff_head unresolved;
132                 } unres;
133                 struct {
134                         unsigned long last_assert;
135                         int minvif;
136                         int maxvif;
137                         unsigned long bytes;
138                         unsigned long pkt;
139                         unsigned long wrong_if;
140                         unsigned long lastuse;
141                         unsigned char ttls[MAXVIFS];
142                 } res;
143         } mfc_un;
144         struct list_head list;
145         struct rcu_head rcu;
146 };
147
148 struct rtmsg;
149 int ipmr_get_route(struct net *net, struct sk_buff *skb,
150                    __be32 saddr, __be32 daddr,
151                    struct rtmsg *rtm, u32 portid);
152 #endif