.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* tunnel4.c: Generic IP tunnel transformer. |
---|
2 | 3 | * |
---|
3 | 4 | * Copyright (C) 2003 David S. Miller (davem@redhat.com) |
---|
.. | .. |
---|
109 | 110 | return 0; |
---|
110 | 111 | } |
---|
111 | 112 | |
---|
| 113 | +#if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL) |
---|
| 114 | +static int tunnel4_rcv_cb(struct sk_buff *skb, u8 proto, int err) |
---|
| 115 | +{ |
---|
| 116 | + struct xfrm_tunnel __rcu *head; |
---|
| 117 | + struct xfrm_tunnel *handler; |
---|
| 118 | + int ret; |
---|
| 119 | + |
---|
| 120 | + head = (proto == IPPROTO_IPIP) ? tunnel4_handlers : tunnel64_handlers; |
---|
| 121 | + |
---|
| 122 | + for_each_tunnel_rcu(head, handler) { |
---|
| 123 | + if (handler->cb_handler) { |
---|
| 124 | + ret = handler->cb_handler(skb, err); |
---|
| 125 | + if (ret <= 0) |
---|
| 126 | + return ret; |
---|
| 127 | + } |
---|
| 128 | + } |
---|
| 129 | + |
---|
| 130 | + return 0; |
---|
| 131 | +} |
---|
| 132 | + |
---|
| 133 | +static const struct xfrm_input_afinfo tunnel4_input_afinfo = { |
---|
| 134 | + .family = AF_INET, |
---|
| 135 | + .is_ipip = true, |
---|
| 136 | + .callback = tunnel4_rcv_cb, |
---|
| 137 | +}; |
---|
| 138 | +#endif |
---|
| 139 | + |
---|
112 | 140 | #if IS_ENABLED(CONFIG_IPV6) |
---|
113 | 141 | static int tunnel64_rcv(struct sk_buff *skb) |
---|
114 | 142 | { |
---|
.. | .. |
---|
149 | 177 | } |
---|
150 | 178 | #endif |
---|
151 | 179 | |
---|
152 | | -static void tunnel4_err(struct sk_buff *skb, u32 info) |
---|
| 180 | +static int tunnel4_err(struct sk_buff *skb, u32 info) |
---|
153 | 181 | { |
---|
154 | 182 | struct xfrm_tunnel *handler; |
---|
155 | 183 | |
---|
156 | 184 | for_each_tunnel_rcu(tunnel4_handlers, handler) |
---|
157 | 185 | if (!handler->err_handler(skb, info)) |
---|
158 | | - break; |
---|
| 186 | + return 0; |
---|
| 187 | + |
---|
| 188 | + return -ENOENT; |
---|
159 | 189 | } |
---|
160 | 190 | |
---|
161 | 191 | #if IS_ENABLED(CONFIG_IPV6) |
---|
162 | | -static void tunnel64_err(struct sk_buff *skb, u32 info) |
---|
| 192 | +static int tunnel64_err(struct sk_buff *skb, u32 info) |
---|
163 | 193 | { |
---|
164 | 194 | struct xfrm_tunnel *handler; |
---|
165 | 195 | |
---|
166 | 196 | for_each_tunnel_rcu(tunnel64_handlers, handler) |
---|
167 | 197 | if (!handler->err_handler(skb, info)) |
---|
168 | | - break; |
---|
| 198 | + return 0; |
---|
| 199 | + |
---|
| 200 | + return -ENOENT; |
---|
169 | 201 | } |
---|
170 | 202 | #endif |
---|
171 | 203 | |
---|
172 | 204 | #if IS_ENABLED(CONFIG_MPLS) |
---|
173 | | -static void tunnelmpls4_err(struct sk_buff *skb, u32 info) |
---|
| 205 | +static int tunnelmpls4_err(struct sk_buff *skb, u32 info) |
---|
174 | 206 | { |
---|
175 | 207 | struct xfrm_tunnel *handler; |
---|
176 | 208 | |
---|
177 | 209 | for_each_tunnel_rcu(tunnelmpls4_handlers, handler) |
---|
178 | 210 | if (!handler->err_handler(skb, info)) |
---|
179 | | - break; |
---|
| 211 | + return 0; |
---|
| 212 | + |
---|
| 213 | + return -ENOENT; |
---|
180 | 214 | } |
---|
181 | 215 | #endif |
---|
182 | 216 | |
---|
.. | .. |
---|
224 | 258 | goto err; |
---|
225 | 259 | } |
---|
226 | 260 | #endif |
---|
| 261 | +#if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL) |
---|
| 262 | + if (xfrm_input_register_afinfo(&tunnel4_input_afinfo)) { |
---|
| 263 | + inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP); |
---|
| 264 | +#if IS_ENABLED(CONFIG_IPV6) |
---|
| 265 | + inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6); |
---|
| 266 | +#endif |
---|
| 267 | +#if IS_ENABLED(CONFIG_MPLS) |
---|
| 268 | + inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS); |
---|
| 269 | +#endif |
---|
| 270 | + goto err; |
---|
| 271 | + } |
---|
| 272 | +#endif |
---|
227 | 273 | return 0; |
---|
228 | 274 | |
---|
229 | 275 | err: |
---|
.. | .. |
---|
233 | 279 | |
---|
234 | 280 | static void __exit tunnel4_fini(void) |
---|
235 | 281 | { |
---|
| 282 | +#if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL) |
---|
| 283 | + if (xfrm_input_unregister_afinfo(&tunnel4_input_afinfo)) |
---|
| 284 | + pr_err("tunnel4 close: can't remove input afinfo\n"); |
---|
| 285 | +#endif |
---|
236 | 286 | #if IS_ENABLED(CONFIG_MPLS) |
---|
237 | 287 | if (inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS)) |
---|
238 | 288 | pr_err("tunnelmpls4 close: can't remove protocol\n"); |
---|