blob: 63b36e6c72a03b6d73f093b93fef1ff28dc2717d [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>
Yotam Gigi478e4c22017-09-27 08:23:16 +02007#include <net/fib_rules.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>
Yuval Mintz6853f212018-02-28 23:29:29 +020010#include <linux/mroute_base.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080012#ifdef CONFIG_IP_MROUTE
13static inline int ip_mroute_opt(int opt)
14{
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010015 return opt >= MRT_BASE && opt <= MRT_MAX;
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080016}
Pavel Emelyanov6a9fb942007-11-05 21:32:31 -080017
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010018int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
19int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
20int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
21int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
22int ip_mr_init(void);
Yotam Gigi478e4c22017-09-27 08:23:16 +020023bool ipmr_rule_default(const struct fib_rule *rule);
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090024#else
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010025static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
26 char __user *optval, unsigned int optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090027{
28 return -ENOPROTOOPT;
29}
30
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010031static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
32 char __user *optval, int __user *optlen)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090033{
34 return -ENOPROTOOPT;
35}
36
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010037static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090038{
39 return -ENOIOCTLCMD;
40}
41
42static inline int ip_mr_init(void)
43{
44 return 0;
45}
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +010046
47static inline int ip_mroute_opt(int opt)
48{
49 return 0;
50}
Yotam Gigi478e4c22017-09-27 08:23:16 +020051
52static inline bool ipmr_rule_default(const struct fib_rule *rule)
53{
54 return true;
55}
YOSHIFUJI Hideakie0835f82008-07-03 16:51:22 +090056#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Yotam Gigi4d65b942017-09-27 08:23:13 +020058struct vif_entry_notifier_info {
59 struct fib_notifier_info info;
60 struct net_device *dev;
61 vifi_t vif_index;
62 unsigned short vif_flags;
63 u32 tb_id;
64};
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define VIFF_STATIC 0x8000
67
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +010068/* mfc_flags:
69 * MFC_STATIC - the entry was added statically (not by a routing daemon)
Yotam Gigic7c0bbe2017-09-27 08:23:15 +020070 * MFC_OFFLOAD - the entry was offloaded to the hardware
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +010071 */
72enum {
73 MFC_STATIC = BIT(0),
Yotam Gigic7c0bbe2017-09-27 08:23:15 +020074 MFC_OFFLOAD = BIT(1),
Nikolay Aleksandrov06bd6c02015-11-26 15:23:45 +010075};
76
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010077struct mfc_cache_cmp_arg {
78 __be32 mfc_mcastgrp;
79 __be32 mfc_origin;
80};
81
82/**
83 * struct mfc_cache - multicast routing entries
Yuval Mintz494fff52018-02-28 23:29:34 +020084 * @_c: Common multicast routing information; has to be first [for casting]
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010085 * @mfc_mcastgrp: destination multicast group address
86 * @mfc_origin: source address
87 * @cmparg: used for rhashtable comparisons
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010088 */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080089struct mfc_cache {
Yuval Mintz494fff52018-02-28 23:29:34 +020090 struct mr_mfc _c;
Nikolay Aleksandrov8fb472c2017-01-12 15:53:33 +010091 union {
92 struct {
93 __be32 mfc_mcastgrp;
94 __be32 mfc_origin;
95 };
96 struct mfc_cache_cmp_arg cmparg;
97 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
Yotam Gigi4d65b942017-09-27 08:23:13 +0200100struct mfc_entry_notifier_info {
101 struct fib_notifier_info info;
102 struct mfc_cache *mfc;
103 u32 tb_id;
104};
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106struct rtmsg;
Nikolay Aleksandrov520191b2015-11-26 15:23:46 +0100107int ipmr_get_route(struct net *net, struct sk_buff *skb,
108 __be32 saddr, __be32 daddr,
David Ahern9f09eae2017-01-06 17:39:06 -0800109 struct rtmsg *rtm, u32 portid);
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200110
111#ifdef CONFIG_IP_MROUTE
112void ipmr_cache_free(struct mfc_cache *mfc_cache);
113#else
114static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
115{
116}
117#endif
118
119static inline void ipmr_cache_put(struct mfc_cache *c)
120{
Yuval Mintz494fff52018-02-28 23:29:34 +0200121 if (refcount_dec_and_test(&c->_c.mfc_un.res.refcount))
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200122 ipmr_cache_free(c);
123}
124static inline void ipmr_cache_hold(struct mfc_cache *c)
125{
Yuval Mintz494fff52018-02-28 23:29:34 +0200126 refcount_inc(&c->_c.mfc_un.res.refcount);
Yotam Gigi310ebbb2017-09-27 08:23:12 +0200127}
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#endif