blob: 5396521a776ac48a8673f9528426a87215e36dc4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __LINUX_MROUTE_H
3#define __LINUX_MROUTE_H
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/in.h>
David S. Miller7c19a3d2008-08-29 14:37:23 -07006#include <linux/pim.h>
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +01007#include <linux/rhashtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <net/sock.h>
Yotam Gigi478e4c22017-09-27 08:23:16 +02009#include <net/fib_rules.h>
Yotam Gigi4d65b942017-09-27 08:23:13 +020010#include <net/fib_notifier.h>
David Howells607ca462012-10-13 10:46:48 +010011#include <uapi/linux/mroute.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080013#ifdef CONFIG_IP_MROUTE
14static inline int ip_mroute_opt(int opt)
15{
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010016 return opt >= MRT_BASE && opt <= MRT_MAX;
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080017}
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080018
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010019int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
20int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
21int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
22int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
23int ip_mr_init(void);
Yotam Gigi478e4c22017-09-27 08:23:16 +020024bool ipmr_rule_default(const struct fib_rule *rule);
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090025#else
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010026static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
27 char __user *optval, unsigned int optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090028{
29 return -ENOPROTOOPT;
30}
31
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010032static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
33 char __user *optval, int __user *optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090034{
35 return -ENOPROTOOPT;
36}
37
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010038static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090039{
40 return -ENOIOCTLCMD;
41}
42
43static inline int ip_mr_init(void)
44{
45 return 0;
46}
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010047
48static inline int ip_mroute_opt(int opt)
49{
50 return 0;
51}
Yotam Gigi478e4c22017-09-27 08:23:16 +020052
53static inline bool ipmr_rule_default(const struct fib_rule *rule)
54{
55 return true;
56}
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090057#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080059struct vif_device {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 struct net_device *dev; /* Device we are using */
Yotam Gigi5d8b3e62017-10-03 09:58:07 +020061 struct netdev_phys_item_id dev_parent_id; /* Device parent ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 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 */
Al Viro114c7842006-09-27 18:39:29 -070067 __be32 local,remote; /* Addresses(remote for tunnels)*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 int link; /* Physical interface index */
69};
70
Yotam Gigi4d65b942017-09-27 08:23:13 +020071struct 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define VIFF_STATIC 0x8000
80
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010081#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010082
83struct 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;
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010090 struct vif_device vif_table[MAXVIFS];
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010091 struct rhltable mfc_hash;
92 struct list_head mfc_cache_list;
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010093 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
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +0100100/* mfc_flags:
101 * MFC_STATIC - the entry was added statically (not by a routing daemon)
Yotam Gigic7c0bbe2017-09-27 08:23:15 +0200102 * MFC_OFFLOAD - the entry was offloaded to the hardware
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +0100103 */
104enum {
105 MFC_STATIC = BIT(0),
Yotam Gigic7c0bbe2017-09-27 08:23:15 +0200106 MFC_OFFLOAD = BIT(1),
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +0100107};
108
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100109struct 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
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200132 * @refcount: reference count for this entry
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100133 * @list: global entry list
134 * @rcu: used for entry destruction
135 */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800136struct mfc_cache {
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100137 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 union {
149 struct {
150 unsigned long expires;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100151 struct sk_buff_head unresolved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 } 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;
Nikolay Aleksandrov43b9e122016-07-14 19:28:27 +0300160 unsigned long lastuse;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100161 unsigned char ttls[MAXVIFS];
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200162 refcount_t refcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 } res;
164 } mfc_un;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100165 struct list_head list;
Eric Dumazeta8c94862010-10-01 16:15:08 +0000166 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167};
168
Yotam Gigi4d65b942017-09-27 08:23:13 +0200169struct mfc_entry_notifier_info {
170 struct fib_notifier_info info;
171 struct mfc_cache *mfc;
172 u32 tb_id;
173};
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175struct rtmsg;
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +0100176int ipmr_get_route(struct net *net, struct sk_buff *skb,
177 __be32 saddr, __be32 daddr,
David Ahern9f09eae2017-01-06 17:39:06 -0800178 struct rtmsg *rtm, u32 portid);
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200179
180#ifdef CONFIG_IP_MROUTE
181void ipmr_cache_free(struct mfc_cache *mfc_cache);
182#else
183static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
184{
185}
186#endif
187
188static 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}
193static inline void ipmr_cache_hold(struct mfc_cache *c)
194{
195 refcount_inc(&c->mfc_un.res.refcount);
196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif