Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __LINUX_MROUTE_H |
3 | #define __LINUX_MROUTE_H | |
4 | ||
1da177e4 | 5 | #include <linux/in.h> |
7c19a3d2 | 6 | #include <linux/pim.h> |
478e4c2f | 7 | #include <net/fib_rules.h> |
4d65b948 | 8 | #include <net/fib_notifier.h> |
607ca46e | 9 | #include <uapi/linux/mroute.h> |
6853f21f | 10 | #include <linux/mroute_base.h> |
1da177e4 | 11 | |
6a9fb947 PE |
12 | #ifdef CONFIG_IP_MROUTE |
13 | static inline int ip_mroute_opt(int opt) | |
14 | { | |
520191bb | 15 | return opt >= MRT_BASE && opt <= MRT_MAX; |
6a9fb947 | 16 | } |
6a9fb947 | 17 | |
520191bb NA |
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); | |
478e4c2f | 23 | bool ipmr_rule_default(const struct fib_rule *rule); |
e0835f8f | 24 | #else |
520191bb NA |
25 | static inline int ip_mroute_setsockopt(struct sock *sock, int optname, |
26 | char __user *optval, unsigned int optlen) | |
e0835f8f YH |
27 | { |
28 | return -ENOPROTOOPT; | |
29 | } | |
30 | ||
520191bb NA |
31 | static inline int ip_mroute_getsockopt(struct sock *sock, int optname, |
32 | char __user *optval, int __user *optlen) | |
e0835f8f YH |
33 | { |
34 | return -ENOPROTOOPT; | |
35 | } | |
36 | ||
520191bb | 37 | static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) |
e0835f8f YH |
38 | { |
39 | return -ENOIOCTLCMD; | |
40 | } | |
41 | ||
42 | static inline int ip_mr_init(void) | |
43 | { | |
44 | return 0; | |
45 | } | |
520191bb NA |
46 | |
47 | static inline int ip_mroute_opt(int opt) | |
48 | { | |
49 | return 0; | |
50 | } | |
478e4c2f YG |
51 | |
52 | static inline bool ipmr_rule_default(const struct fib_rule *rule) | |
53 | { | |
54 | return true; | |
55 | } | |
e0835f8f | 56 | #endif |
1da177e4 | 57 | |
4d65b948 YG |
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 | ||
1da177e4 LT |
66 | #define VIFF_STATIC 0x8000 |
67 | ||
06bd6c03 NA |
68 | /* mfc_flags: |
69 | * MFC_STATIC - the entry was added statically (not by a routing daemon) | |
c7c0bbea | 70 | * MFC_OFFLOAD - the entry was offloaded to the hardware |
06bd6c03 NA |
71 | */ |
72 | enum { | |
73 | MFC_STATIC = BIT(0), | |
c7c0bbea | 74 | MFC_OFFLOAD = BIT(1), |
06bd6c03 NA |
75 | }; |
76 | ||
8fb472c0 NA |
77 | struct mfc_cache_cmp_arg { |
78 | __be32 mfc_mcastgrp; | |
79 | __be32 mfc_origin; | |
80 | }; | |
81 | ||
82 | /** | |
83 | * struct mfc_cache - multicast routing entries | |
84 | * @mnode: rhashtable list | |
85 | * @mfc_mcastgrp: destination multicast group address | |
86 | * @mfc_origin: source address | |
87 | * @cmparg: used for rhashtable comparisons | |
88 | * @mfc_parent: source interface (iif) | |
89 | * @mfc_flags: entry flags | |
90 | * @expires: unresolved entry expire time | |
91 | * @unresolved: unresolved cached skbs | |
92 | * @last_assert: time of last assert | |
93 | * @minvif: minimum VIF id | |
94 | * @maxvif: maximum VIF id | |
95 | * @bytes: bytes that have passed for this entry | |
96 | * @pkt: packets that have passed for this entry | |
97 | * @wrong_if: number of wrong source interface hits | |
98 | * @lastuse: time of last use of the group (traffic or update) | |
99 | * @ttls: OIF TTL threshold array | |
310ebbba | 100 | * @refcount: reference count for this entry |
8fb472c0 NA |
101 | * @list: global entry list |
102 | * @rcu: used for entry destruction | |
103 | */ | |
d94d9fee | 104 | struct mfc_cache { |
8fb472c0 NA |
105 | struct rhlist_head mnode; |
106 | union { | |
107 | struct { | |
108 | __be32 mfc_mcastgrp; | |
109 | __be32 mfc_origin; | |
110 | }; | |
111 | struct mfc_cache_cmp_arg cmparg; | |
112 | }; | |
113 | vifi_t mfc_parent; | |
114 | int mfc_flags; | |
1da177e4 LT |
115 | |
116 | union { | |
117 | struct { | |
118 | unsigned long expires; | |
8fb472c0 | 119 | struct sk_buff_head unresolved; |
1da177e4 LT |
120 | } unres; |
121 | struct { | |
122 | unsigned long last_assert; | |
123 | int minvif; | |
124 | int maxvif; | |
125 | unsigned long bytes; | |
126 | unsigned long pkt; | |
127 | unsigned long wrong_if; | |
43b9e127 | 128 | unsigned long lastuse; |
8fb472c0 | 129 | unsigned char ttls[MAXVIFS]; |
310ebbba | 130 | refcount_t refcount; |
1da177e4 LT |
131 | } res; |
132 | } mfc_un; | |
8fb472c0 | 133 | struct list_head list; |
a8c9486b | 134 | struct rcu_head rcu; |
1da177e4 LT |
135 | }; |
136 | ||
4d65b948 YG |
137 | struct mfc_entry_notifier_info { |
138 | struct fib_notifier_info info; | |
139 | struct mfc_cache *mfc; | |
140 | u32 tb_id; | |
141 | }; | |
142 | ||
1da177e4 | 143 | struct rtmsg; |
520191bb NA |
144 | int ipmr_get_route(struct net *net, struct sk_buff *skb, |
145 | __be32 saddr, __be32 daddr, | |
9f09eaea | 146 | struct rtmsg *rtm, u32 portid); |
310ebbba YG |
147 | |
148 | #ifdef CONFIG_IP_MROUTE | |
149 | void ipmr_cache_free(struct mfc_cache *mfc_cache); | |
150 | #else | |
151 | static inline void ipmr_cache_free(struct mfc_cache *mfc_cache) | |
152 | { | |
153 | } | |
154 | #endif | |
155 | ||
156 | static inline void ipmr_cache_put(struct mfc_cache *c) | |
157 | { | |
158 | if (refcount_dec_and_test(&c->mfc_un.res.refcount)) | |
159 | ipmr_cache_free(c); | |
160 | } | |
161 | static inline void ipmr_cache_hold(struct mfc_cache *c) | |
162 | { | |
163 | refcount_inc(&c->mfc_un.res.refcount); | |
164 | } | |
165 | ||
1da177e4 | 166 | #endif |