hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/net/ipv4/tunnel4.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* tunnel4.c: Generic IP tunnel transformer.
23 *
34 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
....@@ -109,6 +110,33 @@
109110 return 0;
110111 }
111112
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
+
112140 #if IS_ENABLED(CONFIG_IPV6)
113141 static int tunnel64_rcv(struct sk_buff *skb)
114142 {
....@@ -149,34 +177,40 @@
149177 }
150178 #endif
151179
152
-static void tunnel4_err(struct sk_buff *skb, u32 info)
180
+static int tunnel4_err(struct sk_buff *skb, u32 info)
153181 {
154182 struct xfrm_tunnel *handler;
155183
156184 for_each_tunnel_rcu(tunnel4_handlers, handler)
157185 if (!handler->err_handler(skb, info))
158
- break;
186
+ return 0;
187
+
188
+ return -ENOENT;
159189 }
160190
161191 #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)
163193 {
164194 struct xfrm_tunnel *handler;
165195
166196 for_each_tunnel_rcu(tunnel64_handlers, handler)
167197 if (!handler->err_handler(skb, info))
168
- break;
198
+ return 0;
199
+
200
+ return -ENOENT;
169201 }
170202 #endif
171203
172204 #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)
174206 {
175207 struct xfrm_tunnel *handler;
176208
177209 for_each_tunnel_rcu(tunnelmpls4_handlers, handler)
178210 if (!handler->err_handler(skb, info))
179
- break;
211
+ return 0;
212
+
213
+ return -ENOENT;
180214 }
181215 #endif
182216
....@@ -224,6 +258,18 @@
224258 goto err;
225259 }
226260 #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
227273 return 0;
228274
229275 err:
....@@ -233,6 +279,10 @@
233279
234280 static void __exit tunnel4_fini(void)
235281 {
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
236286 #if IS_ENABLED(CONFIG_MPLS)
237287 if (inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS))
238288 pr_err("tunnelmpls4 close: can't remove protocol\n");