.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* xfrm4_protocol.c - Generic xfrm protocol multiplexer. |
---|
2 | 3 | * |
---|
3 | 4 | * Copyright (C) 2013 secunet Security Networks AG |
---|
.. | .. |
---|
7 | 8 | * |
---|
8 | 9 | * Based on: |
---|
9 | 10 | * 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. |
---|
15 | 11 | */ |
---|
16 | 12 | |
---|
17 | 13 | #include <linux/init.h> |
---|
.. | .. |
---|
46 | 42 | handler != NULL; \ |
---|
47 | 43 | handler = rcu_dereference(handler->next)) \ |
---|
48 | 44 | |
---|
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) |
---|
50 | 46 | { |
---|
51 | 47 | int ret; |
---|
52 | 48 | struct xfrm4_protocol *handler; |
---|
.. | .. |
---|
61 | 57 | |
---|
62 | 58 | return 0; |
---|
63 | 59 | } |
---|
64 | | -EXPORT_SYMBOL(xfrm4_rcv_cb); |
---|
65 | 60 | |
---|
66 | 61 | int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, |
---|
67 | 62 | int encap_type) |
---|
.. | .. |
---|
77 | 72 | if (!head) |
---|
78 | 73 | goto out; |
---|
79 | 74 | |
---|
| 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 | + |
---|
80 | 83 | for_each_protocol_rcu(*head, handler) |
---|
81 | 84 | if ((ret = handler->input_handler(skb, nexthdr, spi, encap_type)) != -EINVAL) |
---|
82 | 85 | return ret; |
---|
.. | .. |
---|
84 | 87 | out: |
---|
85 | 88 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); |
---|
86 | 89 | |
---|
| 90 | +drop: |
---|
87 | 91 | kfree_skb(skb); |
---|
88 | 92 | return 0; |
---|
89 | 93 | } |
---|
.. | .. |
---|
106 | 110 | return 0; |
---|
107 | 111 | } |
---|
108 | 112 | |
---|
109 | | -static void xfrm4_esp_err(struct sk_buff *skb, u32 info) |
---|
| 113 | +static int xfrm4_esp_err(struct sk_buff *skb, u32 info) |
---|
110 | 114 | { |
---|
111 | 115 | struct xfrm4_protocol *handler; |
---|
112 | 116 | |
---|
113 | 117 | for_each_protocol_rcu(esp4_handlers, handler) |
---|
114 | 118 | if (!handler->err_handler(skb, info)) |
---|
115 | | - break; |
---|
| 119 | + return 0; |
---|
| 120 | + |
---|
| 121 | + return -ENOENT; |
---|
116 | 122 | } |
---|
117 | 123 | |
---|
118 | 124 | static int xfrm4_ah_rcv(struct sk_buff *skb) |
---|
.. | .. |
---|
132 | 138 | return 0; |
---|
133 | 139 | } |
---|
134 | 140 | |
---|
135 | | -static void xfrm4_ah_err(struct sk_buff *skb, u32 info) |
---|
| 141 | +static int xfrm4_ah_err(struct sk_buff *skb, u32 info) |
---|
136 | 142 | { |
---|
137 | 143 | struct xfrm4_protocol *handler; |
---|
138 | 144 | |
---|
139 | 145 | for_each_protocol_rcu(ah4_handlers, handler) |
---|
140 | 146 | if (!handler->err_handler(skb, info)) |
---|
141 | | - break; |
---|
| 147 | + return 0; |
---|
| 148 | + |
---|
| 149 | + return -ENOENT; |
---|
142 | 150 | } |
---|
143 | 151 | |
---|
144 | 152 | static int xfrm4_ipcomp_rcv(struct sk_buff *skb) |
---|
.. | .. |
---|
158 | 166 | return 0; |
---|
159 | 167 | } |
---|
160 | 168 | |
---|
161 | | -static void xfrm4_ipcomp_err(struct sk_buff *skb, u32 info) |
---|
| 169 | +static int xfrm4_ipcomp_err(struct sk_buff *skb, u32 info) |
---|
162 | 170 | { |
---|
163 | 171 | struct xfrm4_protocol *handler; |
---|
164 | 172 | |
---|
165 | 173 | for_each_protocol_rcu(ipcomp4_handlers, handler) |
---|
166 | 174 | if (!handler->err_handler(skb, info)) |
---|
167 | | - break; |
---|
| 175 | + return 0; |
---|
| 176 | + |
---|
| 177 | + return -ENOENT; |
---|
168 | 178 | } |
---|
169 | 179 | |
---|
170 | 180 | static const struct net_protocol esp4_protocol = { |
---|
.. | .. |
---|
297 | 307 | { |
---|
298 | 308 | xfrm_input_register_afinfo(&xfrm4_input_afinfo); |
---|
299 | 309 | } |
---|
300 | | -EXPORT_SYMBOL(xfrm4_protocol_init); |
---|