blob: 10028f208efb63de5994d52d63f271c929fcb2c6 [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>
David Howells607ca462012-10-13 10:46:48 +01008#include <uapi/linux/mroute.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080010#ifdef CONFIG_IP_MROUTE
11static inline int ip_mroute_opt(int opt)
12{
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010013 return opt >= MRT_BASE && opt <= MRT_MAX;
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080014}
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080015
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010016int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
17int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
18int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
19int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
20int ip_mr_init(void);
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090021#else
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010022static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
23 char __user *optval, unsigned int optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090024{
25 return -ENOPROTOOPT;
26}
27
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010028static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
29 char __user *optval, int __user *optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090030{
31 return -ENOPROTOOPT;
32}
33
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010034static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090035{
36 return -ENOIOCTLCMD;
37}
38
39static inline int ip_mr_init(void)
40{
41 return 0;
42}
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010043
44static inline int ip_mroute_opt(int opt)
45{
46 return 0;
47}
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090048#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080050struct vif_device {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 struct net_device *dev; /* Device we are using */
52 unsigned long bytes_in,bytes_out;
53 unsigned long pkt_in,pkt_out; /* Statistics */
54 unsigned long rate_limit; /* Traffic shaping (NI) */
55 unsigned char threshold; /* TTL threshold */
56 unsigned short flags; /* Control flags */
Al Viro114c7842006-09-27 18:39:29 -070057 __be32 local,remote; /* Addresses(remote for tunnels)*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 int link; /* Physical interface index */
59};
60
61#define VIFF_STATIC 0x8000
62
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010063#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010064
65struct mr_table {
66 struct list_head list;
67 possible_net_t net;
68 u32 id;
69 struct sock __rcu *mroute_sk;
70 struct timer_list ipmr_expire_timer;
71 struct list_head mfc_unres_queue;
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010072 struct vif_device vif_table[MAXVIFS];
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010073 struct rhltable mfc_hash;
74 struct list_head mfc_cache_list;
Nikolay Aleksandrov5ea1f132015-11-26 15:23:47 +010075 int maxvif;
76 atomic_t cache_resolve_queue_len;
77 bool mroute_do_assert;
78 bool mroute_do_pim;
79 int mroute_reg_vif_num;
80};
81
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +010082/* mfc_flags:
83 * MFC_STATIC - the entry was added statically (not by a routing daemon)
84 */
85enum {
86 MFC_STATIC = BIT(0),
87};
88
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010089struct mfc_cache_cmp_arg {
90 __be32 mfc_mcastgrp;
91 __be32 mfc_origin;
92};
93
94/**
95 * struct mfc_cache - multicast routing entries
96 * @mnode: rhashtable list
97 * @mfc_mcastgrp: destination multicast group address
98 * @mfc_origin: source address
99 * @cmparg: used for rhashtable comparisons
100 * @mfc_parent: source interface (iif)
101 * @mfc_flags: entry flags
102 * @expires: unresolved entry expire time
103 * @unresolved: unresolved cached skbs
104 * @last_assert: time of last assert
105 * @minvif: minimum VIF id
106 * @maxvif: maximum VIF id
107 * @bytes: bytes that have passed for this entry
108 * @pkt: packets that have passed for this entry
109 * @wrong_if: number of wrong source interface hits
110 * @lastuse: time of last use of the group (traffic or update)
111 * @ttls: OIF TTL threshold array
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200112 * @refcount: reference count for this entry
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100113 * @list: global entry list
114 * @rcu: used for entry destruction
115 */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800116struct mfc_cache {
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100117 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 union {
129 struct {
130 unsigned long expires;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100131 struct sk_buff_head unresolved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 } 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;
Nikolay Aleksandrov43b9e122016-07-14 19:28:27 +0300140 unsigned long lastuse;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100141 unsigned char ttls[MAXVIFS];
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200142 refcount_t refcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } res;
144 } mfc_un;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100145 struct list_head list;
Eric Dumazeta8c94862010-10-01 16:15:08 +0000146 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149struct rtmsg;
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +0100150int ipmr_get_route(struct net *net, struct sk_buff *skb,
151 __be32 saddr, __be32 daddr,
David Ahern9f09eae2017-01-06 17:39:06 -0800152 struct rtmsg *rtm, u32 portid);
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200153
154#ifdef CONFIG_IP_MROUTE
155void ipmr_cache_free(struct mfc_cache *mfc_cache);
156#else
157static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
158{
159}
160#endif
161
162static inline void ipmr_cache_put(struct mfc_cache *c)
163{
164 if (refcount_dec_and_test(&c->mfc_un.res.refcount))
165 ipmr_cache_free(c);
166}
167static inline void ipmr_cache_hold(struct mfc_cache *c)
168{
169 refcount_inc(&c->mfc_un.res.refcount);
170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#endif