1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_MROUTE6_H
3 #define __LINUX_MROUTE6_H
4
5
6 #include <linux/pim.h>
7 #include <linux/skbuff.h> /* for struct sk_buff_head */
8 #include <net/net_namespace.h>
9 #include <uapi/linux/mroute6.h>
10 #include <linux/mroute_base.h>
11 #include <linux/sockptr.h>
12 #include <net/fib_rules.h>
13
14 #ifdef CONFIG_IPV6_MROUTE
ip6_mroute_opt(int opt)15 static inline int ip6_mroute_opt(int opt)
16 {
17 return (opt >= MRT6_BASE) && (opt <= MRT6_MAX);
18 }
19 #else
ip6_mroute_opt(int opt)20 static inline int ip6_mroute_opt(int opt)
21 {
22 return 0;
23 }
24 #endif
25
26 struct sock;
27
28 #ifdef CONFIG_IPV6_MROUTE
29 extern int ip6_mroute_setsockopt(struct sock *, int, sockptr_t, unsigned int);
30 extern int ip6_mroute_getsockopt(struct sock *, int, sockptr_t, sockptr_t);
31 extern int ip6_mr_input(struct sk_buff *skb);
32 extern int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
33 extern int ip6_mr_init(void);
34 extern int ip6_mr_output(struct net *net, struct sock *sk, struct sk_buff *skb);
35 extern void ip6_mr_cleanup(void);
36 int ip6mr_ioctl(struct sock *sk, int cmd, void *arg);
37 #else
ip6_mroute_setsockopt(struct sock * sock,int optname,sockptr_t optval,unsigned int optlen)38 static inline int ip6_mroute_setsockopt(struct sock *sock, int optname,
39 sockptr_t optval, unsigned int optlen)
40 {
41 return -ENOPROTOOPT;
42 }
43
44 static inline
ip6_mroute_getsockopt(struct sock * sock,int optname,sockptr_t optval,sockptr_t optlen)45 int ip6_mroute_getsockopt(struct sock *sock,
46 int optname, sockptr_t optval, sockptr_t optlen)
47 {
48 return -ENOPROTOOPT;
49 }
50
51 static inline
ip6mr_ioctl(struct sock * sk,int cmd,void * arg)52 int ip6mr_ioctl(struct sock *sk, int cmd, void *arg)
53 {
54 return -ENOIOCTLCMD;
55 }
56
ip6_mr_init(void)57 static inline int ip6_mr_init(void)
58 {
59 return 0;
60 }
61
62 static inline int
ip6_mr_output(struct net * net,struct sock * sk,struct sk_buff * skb)63 ip6_mr_output(struct net *net, struct sock *sk, struct sk_buff *skb)
64 {
65 return ip6_output(net, sk, skb);
66 }
67
ip6_mr_cleanup(void)68 static inline void ip6_mr_cleanup(void)
69 {
70 return;
71 }
72 #endif
73
74 #ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
75 bool ip6mr_rule_default(const struct fib_rule *rule);
76 #else
ip6mr_rule_default(const struct fib_rule * rule)77 static inline bool ip6mr_rule_default(const struct fib_rule *rule)
78 {
79 return true;
80 }
81 #endif
82
83 #define VIFF_STATIC 0x8000
84
85 struct mfc6_cache_cmp_arg {
86 struct in6_addr mf6c_mcastgrp;
87 struct in6_addr mf6c_origin;
88 };
89
90 struct mfc6_cache {
91 struct mr_mfc _c;
92 union {
93 struct {
94 struct in6_addr mf6c_mcastgrp;
95 struct in6_addr mf6c_origin;
96 };
97 struct mfc6_cache_cmp_arg cmparg;
98 };
99 };
100
101 #define MFC_ASSERT_THRESH (3*HZ) /* Maximal freq. of asserts */
102
103 struct rtmsg;
104 extern int ip6mr_get_route(struct net *net, struct sk_buff *skb,
105 struct rtmsg *rtm, u32 portid);
106
107 #ifdef CONFIG_IPV6_MROUTE
108 bool mroute6_is_socket(struct net *net, struct sk_buff *skb);
109 extern int ip6mr_sk_done(struct sock *sk);
ip6mr_sk_ioctl(struct sock * sk,unsigned int cmd,void __user * arg)110 static inline int ip6mr_sk_ioctl(struct sock *sk, unsigned int cmd,
111 void __user *arg)
112 {
113 switch (cmd) {
114 /* These userspace buffers will be consumed by ip6mr_ioctl() */
115 case SIOCGETMIFCNT_IN6: {
116 struct sioc_mif_req6 buffer;
117
118 return sock_ioctl_inout(sk, cmd, arg, &buffer,
119 sizeof(buffer));
120 }
121 case SIOCGETSGCNT_IN6: {
122 struct sioc_sg_req6 buffer;
123
124 return sock_ioctl_inout(sk, cmd, arg, &buffer,
125 sizeof(buffer));
126 }
127 }
128
129 return 1;
130 }
131 #else
mroute6_is_socket(struct net * net,struct sk_buff * skb)132 static inline bool mroute6_is_socket(struct net *net, struct sk_buff *skb)
133 {
134 return false;
135 }
ip6mr_sk_done(struct sock * sk)136 static inline int ip6mr_sk_done(struct sock *sk)
137 {
138 return 0;
139 }
140
ip6mr_sk_ioctl(struct sock * sk,unsigned int cmd,void __user * arg)141 static inline int ip6mr_sk_ioctl(struct sock *sk, unsigned int cmd,
142 void __user *arg)
143 {
144 return 1;
145 }
146 #endif
147 #endif
148