blob: 5566580811ce6f858a272ced6ab0b82510aec105 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_MROUTE_H
2#define __LINUX_MROUTE_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/in.h>
David S. Miller7c19a3d2008-08-29 14:37:23 -07005#include <linux/pim.h>
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +01006#include <linux/rhashtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <net/sock.h>
Yotam Gigi4d65b942017-09-27 08:23:13 +02008#include <net/fib_notifier.h>
David Howells607ca462012-10-13 10:46:48 +01009#include <uapi/linux/mroute.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080011#ifdef CONFIG_IP_MROUTE
12static inline int ip_mroute_opt(int opt)
13{
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010014 return opt >= MRT_BASE && opt <= MRT_MAX;
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080015}
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080016
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010017int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
18int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
19int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
20int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
21int ip_mr_init(void);
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090022#else
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010023static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
24 char __user *optval, unsigned int optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090025{
26 return -ENOPROTOOPT;
27}
28
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010029static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
30 char __user *optval, int __user *optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090031{
32 return -ENOPROTOOPT;
33}
34
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010035static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090036{
37 return -ENOIOCTLCMD;
38}
39
40static inline int ip_mr_init(void)
41{
42 return 0;
43}
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010044
45static inline int ip_mroute_opt(int opt)
46{
47 return 0;
48}
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090049#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080051struct vif_device {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 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 */
Al Viro114c7842006-09-27 18:39:29 -070058 __be32 local,remote; /* Addresses(remote for tunnels)*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 int link; /* Physical interface index */
60};
61
Yotam Gigi4d65b942017-09-27 08:23:13 +020062struct vif_entry_notifier_info {
63 struct fib_notifier_info info;
64 struct net_device *dev;
65 vifi_t vif_index;
66 unsigned short vif_flags;
67 u32 tb_id;
68};
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#define VIFF_STATIC 0x8000
71
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010072#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010073
74struct mr_table {
75 struct list_head list;
76 possible_net_t net;
77 u32 id;
78 struct sock __rcu *mroute_sk;
79 struct timer_list ipmr_expire_timer;
80 struct list_head mfc_unres_queue;
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010081 struct vif_device vif_table[MAXVIFS];
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010082 struct rhltable mfc_hash;
83 struct list_head mfc_cache_list;
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010084 int maxvif;
85 atomic_t cache_resolve_queue_len;
86 bool mroute_do_assert;
87 bool mroute_do_pim;
88 int mroute_reg_vif_num;
89};
90
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +010091/* mfc_flags:
92 * MFC_STATIC - the entry was added statically (not by a routing daemon)
Yotam Gigic7c0bbe2017-09-27 08:23:15 +020093 * MFC_OFFLOAD - the entry was offloaded to the hardware
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +010094 */
95enum {
96 MFC_STATIC = BIT(0),
Yotam Gigic7c0bbe2017-09-27 08:23:15 +020097 MFC_OFFLOAD = BIT(1),
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +010098};
99
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100100struct mfc_cache_cmp_arg {
101 __be32 mfc_mcastgrp;
102 __be32 mfc_origin;
103};
104
105/**
106 * struct mfc_cache - multicast routing entries
107 * @mnode: rhashtable list
108 * @mfc_mcastgrp: destination multicast group address
109 * @mfc_origin: source address
110 * @cmparg: used for rhashtable comparisons
111 * @mfc_parent: source interface (iif)
112 * @mfc_flags: entry flags
113 * @expires: unresolved entry expire time
114 * @unresolved: unresolved cached skbs
115 * @last_assert: time of last assert
116 * @minvif: minimum VIF id
117 * @maxvif: maximum VIF id
118 * @bytes: bytes that have passed for this entry
119 * @pkt: packets that have passed for this entry
120 * @wrong_if: number of wrong source interface hits
121 * @lastuse: time of last use of the group (traffic or update)
122 * @ttls: OIF TTL threshold array
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200123 * @refcount: reference count for this entry
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100124 * @list: global entry list
125 * @rcu: used for entry destruction
126 */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800127struct mfc_cache {
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100128 struct rhlist_head mnode;
129 union {
130 struct {
131 __be32 mfc_mcastgrp;
132 __be32 mfc_origin;
133 };
134 struct mfc_cache_cmp_arg cmparg;
135 };
136 vifi_t mfc_parent;
137 int mfc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 union {
140 struct {
141 unsigned long expires;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100142 struct sk_buff_head unresolved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } unres;
144 struct {
145 unsigned long last_assert;
146 int minvif;
147 int maxvif;
148 unsigned long bytes;
149 unsigned long pkt;
150 unsigned long wrong_if;
Nikolay Aleksandrov43b9e122016-07-14 19:28:27 +0300151 unsigned long lastuse;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100152 unsigned char ttls[MAXVIFS];
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200153 refcount_t refcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 } res;
155 } mfc_un;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100156 struct list_head list;
Eric Dumazeta8c94862010-10-01 16:15:08 +0000157 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158};
159
Yotam Gigi4d65b942017-09-27 08:23:13 +0200160struct mfc_entry_notifier_info {
161 struct fib_notifier_info info;
162 struct mfc_cache *mfc;
163 u32 tb_id;
164};
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166struct rtmsg;
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +0100167int ipmr_get_route(struct net *net, struct sk_buff *skb,
168 __be32 saddr, __be32 daddr,
David Ahern9f09eae2017-01-06 17:39:06 -0800169 struct rtmsg *rtm, u32 portid);
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200170
171#ifdef CONFIG_IP_MROUTE
172void ipmr_cache_free(struct mfc_cache *mfc_cache);
173#else
174static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
175{
176}
177#endif
178
179static inline void ipmr_cache_put(struct mfc_cache *c)
180{
181 if (refcount_dec_and_test(&c->mfc_un.res.refcount))
182 ipmr_cache_free(c);
183}
184static inline void ipmr_cache_hold(struct mfc_cache *c)
185{
186 refcount_inc(&c->mfc_un.res.refcount);
187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#endif