hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/ipv4/xfrm4_protocol.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* xfrm4_protocol.c - Generic xfrm protocol multiplexer.
23 *
34 * Copyright (C) 2013 secunet Security Networks AG
....@@ -7,11 +8,6 @@
78 *
89 * Based on:
910 * net/ipv4/tunnel4.c
10
- *
11
- * This program is free software; you can redistribute it and/or
12
- * modify it under the terms of the GNU General Public License
13
- * as published by the Free Software Foundation; either version
14
- * 2 of the License, or (at your option) any later version.
1511 */
1612
1713 #include <linux/init.h>
....@@ -46,7 +42,7 @@
4642 handler != NULL; \
4743 handler = rcu_dereference(handler->next)) \
4844
49
-int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
45
+static int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
5046 {
5147 int ret;
5248 struct xfrm4_protocol *handler;
....@@ -61,7 +57,6 @@
6157
6258 return 0;
6359 }
64
-EXPORT_SYMBOL(xfrm4_rcv_cb);
6560
6661 int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
6762 int encap_type)
....@@ -77,6 +72,14 @@
7772 if (!head)
7873 goto out;
7974
75
+ if (!skb_dst(skb)) {
76
+ const struct iphdr *iph = ip_hdr(skb);
77
+
78
+ if (ip_route_input_noref(skb, iph->daddr, iph->saddr,
79
+ iph->tos, skb->dev))
80
+ goto drop;
81
+ }
82
+
8083 for_each_protocol_rcu(*head, handler)
8184 if ((ret = handler->input_handler(skb, nexthdr, spi, encap_type)) != -EINVAL)
8285 return ret;
....@@ -84,6 +87,7 @@
8487 out:
8588 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
8689
90
+drop:
8791 kfree_skb(skb);
8892 return 0;
8993 }
....@@ -106,13 +110,15 @@
106110 return 0;
107111 }
108112
109
-static void xfrm4_esp_err(struct sk_buff *skb, u32 info)
113
+static int xfrm4_esp_err(struct sk_buff *skb, u32 info)
110114 {
111115 struct xfrm4_protocol *handler;
112116
113117 for_each_protocol_rcu(esp4_handlers, handler)
114118 if (!handler->err_handler(skb, info))
115
- break;
119
+ return 0;
120
+
121
+ return -ENOENT;
116122 }
117123
118124 static int xfrm4_ah_rcv(struct sk_buff *skb)
....@@ -132,13 +138,15 @@
132138 return 0;
133139 }
134140
135
-static void xfrm4_ah_err(struct sk_buff *skb, u32 info)
141
+static int xfrm4_ah_err(struct sk_buff *skb, u32 info)
136142 {
137143 struct xfrm4_protocol *handler;
138144
139145 for_each_protocol_rcu(ah4_handlers, handler)
140146 if (!handler->err_handler(skb, info))
141
- break;
147
+ return 0;
148
+
149
+ return -ENOENT;
142150 }
143151
144152 static int xfrm4_ipcomp_rcv(struct sk_buff *skb)
....@@ -158,13 +166,15 @@
158166 return 0;
159167 }
160168
161
-static void xfrm4_ipcomp_err(struct sk_buff *skb, u32 info)
169
+static int xfrm4_ipcomp_err(struct sk_buff *skb, u32 info)
162170 {
163171 struct xfrm4_protocol *handler;
164172
165173 for_each_protocol_rcu(ipcomp4_handlers, handler)
166174 if (!handler->err_handler(skb, info))
167
- break;
175
+ return 0;
176
+
177
+ return -ENOENT;
168178 }
169179
170180 static const struct net_protocol esp4_protocol = {
....@@ -297,4 +307,3 @@
297307 {
298308 xfrm_input_register_afinfo(&xfrm4_input_afinfo);
299309 }
300
-EXPORT_SYMBOL(xfrm4_protocol_init);