blob: d7f63339ef0b48e7321954ea2fd083d3da2478d6 [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
112 * @list: global entry list
113 * @rcu: used for entry destruction
114 */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800115struct mfc_cache {
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100116 struct rhlist_head mnode;
117 union {
118 struct {
119 __be32 mfc_mcastgrp;
120 __be32 mfc_origin;
121 };
122 struct mfc_cache_cmp_arg cmparg;
123 };
124 vifi_t mfc_parent;
125 int mfc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 union {
128 struct {
129 unsigned long expires;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100130 struct sk_buff_head unresolved;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 } unres;
132 struct {
133 unsigned long last_assert;
134 int minvif;
135 int maxvif;
136 unsigned long bytes;
137 unsigned long pkt;
138 unsigned long wrong_if;
Nikolay Aleksandrov43b9e122016-07-14 19:28:27 +0300139 unsigned long lastuse;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100140 unsigned char ttls[MAXVIFS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 } res;
142 } mfc_un;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +0100143 struct list_head list;
Eric Dumazeta8c94862010-10-01 16:15:08 +0000144 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147struct rtmsg;
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +0100148int ipmr_get_route(struct net *net, struct sk_buff *skb,
149 __be32 saddr, __be32 daddr,
David Ahern9f09eae2017-01-06 17:39:06 -0800150 struct rtmsg *rtm, u32 portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif