1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_MROUTE_H
3 #define __LINUX_MROUTE_H
4 
5 #include <linux/in.h>
6 #include <linux/pim.h>
7 #include <net/fib_rules.h>
8 #include <net/fib_notifier.h>
9 #include <uapi/linux/mroute.h>
10 #include <linux/mroute_base.h>
11 #include <linux/sockptr.h>
12 
13 #ifdef CONFIG_IP_MROUTE
ip_mroute_opt(int opt)14 static inline int ip_mroute_opt(int opt)
15 {
16 	return opt >= MRT_BASE && opt <= MRT_MAX;
17 }
18 
19 int ip_mroute_setsockopt(struct sock *, int, sockptr_t, unsigned int);
20 int ip_mroute_getsockopt(struct sock *, int, sockptr_t, sockptr_t);
21 int ipmr_ioctl(struct sock *sk, int cmd, void *arg);
22 int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
23 int ip_mr_init(void);
24 bool ipmr_rule_default(const struct fib_rule *rule);
25 int ipmr_sk_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
26 #else
ip_mroute_setsockopt(struct sock * sock,int optname,sockptr_t optval,unsigned int optlen)27 static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
28 				       sockptr_t optval, unsigned int optlen)
29 {
30 	return -ENOPROTOOPT;
31 }
32 
ip_mroute_getsockopt(struct sock * sk,int optname,sockptr_t optval,sockptr_t optlen)33 static inline int ip_mroute_getsockopt(struct sock *sk, int optname,
34 				       sockptr_t optval, sockptr_t optlen)
35 {
36 	return -ENOPROTOOPT;
37 }
38 
ipmr_ioctl(struct sock * sk,int cmd,void * arg)39 static inline int ipmr_ioctl(struct sock *sk, int cmd, void *arg)
40 {
41 	return -ENOIOCTLCMD;
42 }
43 
ip_mr_init(void)44 static inline int ip_mr_init(void)
45 {
46 	return 0;
47 }
48 
ip_mroute_opt(int opt)49 static inline int ip_mroute_opt(int opt)
50 {
51 	return 0;
52 }
53 
ipmr_rule_default(const struct fib_rule * rule)54 static inline bool ipmr_rule_default(const struct fib_rule *rule)
55 {
56 	return true;
57 }
58 
ipmr_sk_ioctl(struct sock * sk,unsigned int cmd,void __user * arg)59 static inline int ipmr_sk_ioctl(struct sock *sk, unsigned int cmd,
60 				void __user *arg)
61 {
62 	return 1;
63 }
64 #endif
65 
66 #define VIFF_STATIC 0x8000
67 
68 struct mfc_cache_cmp_arg {
69 	__be32 mfc_mcastgrp;
70 	__be32 mfc_origin;
71 };
72 
73 /**
74  * struct mfc_cache - multicast routing entries
75  * @_c: Common multicast routing information; has to be first [for casting]
76  * @mfc_mcastgrp: destination multicast group address
77  * @mfc_origin: source address
78  * @cmparg: used for rhashtable comparisons
79  */
80 struct mfc_cache {
81 	struct mr_mfc _c;
82 	union {
83 		struct {
84 			__be32 mfc_mcastgrp;
85 			__be32 mfc_origin;
86 		};
87 		struct mfc_cache_cmp_arg cmparg;
88 	};
89 };
90 
91 struct rtmsg;
92 int ipmr_get_route(struct net *net, struct sk_buff *skb,
93 		   __be32 saddr, __be32 daddr,
94 		   struct rtmsg *rtm, u32 portid);
95 #endif
96