Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef __LINUX_MROUTE_H |
| 3 | #define __LINUX_MROUTE_H |
| 4 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/in.h> |
David S. Miller | 7c19a3d | 2008-08-29 14:37:23 -0700 | [diff] [blame] | 6 | #include <linux/pim.h> |
Yotam Gigi | 478e4c2 | 2017-09-27 08:23:16 +0200 | [diff] [blame] | 7 | #include <net/fib_rules.h> |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 8 | #include <net/fib_notifier.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 9 | #include <uapi/linux/mroute.h> |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 10 | #include <linux/mroute_base.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 12 | #ifdef CONFIG_IP_MROUTE |
| 13 | static inline int ip_mroute_opt(int opt) |
| 14 | { |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 15 | return opt >= MRT_BASE && opt <= MRT_MAX; |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 16 | } |
Pavel Emelyanov | 6a9fb94 | 2007-11-05 21:32:31 -0800 | [diff] [blame] | 17 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 18 | int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int); |
| 19 | int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *); |
| 20 | int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg); |
| 21 | int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg); |
| 22 | int ip_mr_init(void); |
Yotam Gigi | 478e4c2 | 2017-09-27 08:23:16 +0200 | [diff] [blame] | 23 | bool ipmr_rule_default(const struct fib_rule *rule); |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 24 | #else |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 25 | static inline int ip_mroute_setsockopt(struct sock *sock, int optname, |
| 26 | char __user *optval, unsigned int optlen) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 27 | { |
| 28 | return -ENOPROTOOPT; |
| 29 | } |
| 30 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 31 | static inline int ip_mroute_getsockopt(struct sock *sock, int optname, |
| 32 | char __user *optval, int __user *optlen) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 33 | { |
| 34 | return -ENOPROTOOPT; |
| 35 | } |
| 36 | |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 37 | static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 38 | { |
| 39 | return -ENOIOCTLCMD; |
| 40 | } |
| 41 | |
| 42 | static inline int ip_mr_init(void) |
| 43 | { |
| 44 | return 0; |
| 45 | } |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 46 | |
| 47 | static inline int ip_mroute_opt(int opt) |
| 48 | { |
| 49 | return 0; |
| 50 | } |
Yotam Gigi | 478e4c2 | 2017-09-27 08:23:16 +0200 | [diff] [blame] | 51 | |
| 52 | static inline bool ipmr_rule_default(const struct fib_rule *rule) |
| 53 | { |
| 54 | return true; |
| 55 | } |
YOSHIFUJI Hideaki | e0835f8 | 2008-07-03 16:51:22 +0900 | [diff] [blame] | 56 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 58 | struct 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define VIFF_STATIC 0x8000 |
| 67 | |
Nikolay Aleksandrov | 06bd6c0 | 2015-11-26 15:23:45 +0100 | [diff] [blame] | 68 | /* mfc_flags: |
| 69 | * MFC_STATIC - the entry was added statically (not by a routing daemon) |
Yotam Gigi | c7c0bbe | 2017-09-27 08:23:15 +0200 | [diff] [blame] | 70 | * MFC_OFFLOAD - the entry was offloaded to the hardware |
Nikolay Aleksandrov | 06bd6c0 | 2015-11-26 15:23:45 +0100 | [diff] [blame] | 71 | */ |
| 72 | enum { |
| 73 | MFC_STATIC = BIT(0), |
Yotam Gigi | c7c0bbe | 2017-09-27 08:23:15 +0200 | [diff] [blame] | 74 | MFC_OFFLOAD = BIT(1), |
Nikolay Aleksandrov | 06bd6c0 | 2015-11-26 15:23:45 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 77 | struct mfc_cache_cmp_arg { |
| 78 | __be32 mfc_mcastgrp; |
| 79 | __be32 mfc_origin; |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * struct mfc_cache - multicast routing entries |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame^] | 84 | * @_c: Common multicast routing information; has to be first [for casting] |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 85 | * @mfc_mcastgrp: destination multicast group address |
| 86 | * @mfc_origin: source address |
| 87 | * @cmparg: used for rhashtable comparisons |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 88 | */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 89 | struct mfc_cache { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame^] | 90 | struct mr_mfc _c; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 91 | union { |
| 92 | struct { |
| 93 | __be32 mfc_mcastgrp; |
| 94 | __be32 mfc_origin; |
| 95 | }; |
| 96 | struct mfc_cache_cmp_arg cmparg; |
| 97 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 100 | struct mfc_entry_notifier_info { |
| 101 | struct fib_notifier_info info; |
| 102 | struct mfc_cache *mfc; |
| 103 | u32 tb_id; |
| 104 | }; |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | struct rtmsg; |
Nikolay Aleksandrov | 520191b | 2015-11-26 15:23:46 +0100 | [diff] [blame] | 107 | int ipmr_get_route(struct net *net, struct sk_buff *skb, |
| 108 | __be32 saddr, __be32 daddr, |
David Ahern | 9f09eae | 2017-01-06 17:39:06 -0800 | [diff] [blame] | 109 | struct rtmsg *rtm, u32 portid); |
Yotam Gigi | 310ebbb | 2017-09-27 08:23:12 +0200 | [diff] [blame] | 110 | |
| 111 | #ifdef CONFIG_IP_MROUTE |
| 112 | void ipmr_cache_free(struct mfc_cache *mfc_cache); |
| 113 | #else |
| 114 | static inline void ipmr_cache_free(struct mfc_cache *mfc_cache) |
| 115 | { |
| 116 | } |
| 117 | #endif |
| 118 | |
| 119 | static inline void ipmr_cache_put(struct mfc_cache *c) |
| 120 | { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame^] | 121 | if (refcount_dec_and_test(&c->_c.mfc_un.res.refcount)) |
Yotam Gigi | 310ebbb | 2017-09-27 08:23:12 +0200 | [diff] [blame] | 122 | ipmr_cache_free(c); |
| 123 | } |
| 124 | static inline void ipmr_cache_hold(struct mfc_cache *c) |
| 125 | { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame^] | 126 | refcount_inc(&c->_c.mfc_un.res.refcount); |
Yotam Gigi | 310ebbb | 2017-09-27 08:23:12 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | #endif |