blob: 05926dcf5d175f1fcfd50dd8e0ea05fd69a7197a [file] [log] [blame]
Herbert Xu406ef772007-10-08 17:16:30 -07001/*
2 * xfrm_output.c - Common IPsec encapsulation code.
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/errno.h>
13#include <linux/module.h>
14#include <linux/netdevice.h>
Herbert Xu862b82c2007-11-13 21:43:11 -080015#include <linux/netfilter.h>
Herbert Xu406ef772007-10-08 17:16:30 -070016#include <linux/skbuff.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Herbert Xu406ef772007-10-08 17:16:30 -070018#include <linux/spinlock.h>
Herbert Xu406ef772007-10-08 17:16:30 -070019#include <net/dst.h>
20#include <net/xfrm.h>
21
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -050022static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb);
Florian Westphal0c620e92019-03-29 21:16:25 +010023static int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb);
Herbert Xuc6581a42007-11-13 21:43:43 -080024
Steffen Klassert26b20722012-03-21 23:32:39 +000025static int xfrm_skb_check_space(struct sk_buff *skb)
Herbert Xu83815de2007-10-08 17:25:08 -070026{
Eric Dumazetadf30902009-06-02 05:19:30 +000027 struct dst_entry *dst = skb_dst(skb);
Herbert Xu550ade82007-11-13 21:33:01 -080028 int nhead = dst->header_len + LL_RESERVED_SPACE(dst->dev)
Herbert Xu83815de2007-10-08 17:25:08 -070029 - skb_headroom(skb);
Johannes Bergf5184d22008-05-12 20:48:31 -070030 int ntail = dst->dev->needed_tailroom - skb_tailroom(skb);
Herbert Xu83815de2007-10-08 17:25:08 -070031
Herbert Xud01dbeb2008-09-30 02:03:19 -070032 if (nhead <= 0) {
33 if (ntail <= 0)
34 return 0;
35 nhead = 0;
36 } else if (ntail < 0)
37 ntail = 0;
Herbert Xu83815de2007-10-08 17:25:08 -070038
Herbert Xud01dbeb2008-09-30 02:03:19 -070039 return pskb_expand_head(skb, nhead, ntail, GFP_ATOMIC);
Herbert Xu83815de2007-10-08 17:25:08 -070040}
41
Ying Xue9449c3c2015-05-12 18:29:44 +080042/* Children define the path of the packet through the
43 * Linux networking. Thus, destinations are stackable.
44 */
45
46static struct dst_entry *skb_dst_pop(struct sk_buff *skb)
47{
David Millerb92cf4a2017-11-28 15:40:22 -050048 struct dst_entry *child = dst_clone(xfrm_dst_child(skb_dst(skb)));
Ying Xue9449c3c2015-05-12 18:29:44 +080049
50 skb_dst_drop(skb);
51 return child;
52}
53
Florian Westphal0c620e92019-03-29 21:16:25 +010054/* Add encapsulation header.
55 *
56 * The IP header will be moved forward to make space for the encapsulation
57 * header.
58 */
59static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
60{
61#if IS_ENABLED(CONFIG_INET_XFRM_MODE_TRANSPORT)
62 struct iphdr *iph = ip_hdr(skb);
63 int ihl = iph->ihl * 4;
64
65 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
66
67 skb_set_network_header(skb, -x->props.header_len);
68 skb->mac_header = skb->network_header +
69 offsetof(struct iphdr, protocol);
70 skb->transport_header = skb->network_header + ihl;
71 __skb_pull(skb, ihl);
72 memmove(skb_network_header(skb), iph, ihl);
73 return 0;
74#else
75 WARN_ON_ONCE(1);
76 return -EOPNOTSUPP;
77#endif
78}
79
80/* Add encapsulation header.
81 *
82 * The IP header and mutable extension headers will be moved forward to make
83 * space for the encapsulation header.
84 */
85static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
86{
87#if IS_ENABLED(CONFIG_INET6_XFRM_MODE_TRANSPORT)
88 struct ipv6hdr *iph;
89 u8 *prevhdr;
90 int hdr_len;
91
92 iph = ipv6_hdr(skb);
93 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
94
95 hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
96 if (hdr_len < 0)
97 return hdr_len;
98 skb_set_mac_header(skb,
99 (prevhdr - x->props.header_len) - skb->data);
100 skb_set_network_header(skb, -x->props.header_len);
101 skb->transport_header = skb->network_header + hdr_len;
102 __skb_pull(skb, hdr_len);
103 memmove(ipv6_hdr(skb), iph, hdr_len);
104 return 0;
105#else
106 WARN_ON_ONCE(1);
107 return -EOPNOTSUPP;
108#endif
109}
110
111/* Add route optimization header space.
112 *
113 * The IP header and mutable extension headers will be moved forward to make
114 * space for the route optimization header.
115 */
116static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
117{
118#if IS_ENABLED(CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION)
119 struct ipv6hdr *iph;
120 u8 *prevhdr;
121 int hdr_len;
122
123 iph = ipv6_hdr(skb);
124
125 hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
126 if (hdr_len < 0)
127 return hdr_len;
128 skb_set_mac_header(skb,
129 (prevhdr - x->props.header_len) - skb->data);
130 skb_set_network_header(skb, -x->props.header_len);
131 skb->transport_header = skb->network_header + hdr_len;
132 __skb_pull(skb, hdr_len);
133 memmove(ipv6_hdr(skb), iph, hdr_len);
134
135 x->lastused = ktime_get_real_seconds();
136
137 return 0;
138#else
139 WARN_ON_ONCE(1);
140 return -EOPNOTSUPP;
141#endif
142}
143
144static int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
145{
146 int err;
147
148 err = xfrm_inner_extract_output(x, skb);
149 if (err)
150 return err;
151
152 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
153 skb->protocol = htons(ETH_P_IP);
154
155 return x->outer_mode->output2(x, skb);
156}
157
158static int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
159{
160#if IS_ENABLED(CONFIG_IPV6)
161 int err;
162
163 err = xfrm_inner_extract_output(x, skb);
164 if (err)
165 return err;
166
167 skb->ignore_df = 1;
168 skb->protocol = htons(ETH_P_IPV6);
169
170 return x->outer_mode->output2(x, skb);
171#else
172 WARN_ON_ONCE(1);
173 return -EOPNOTSUPP;
174#endif
175}
176
177static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
178{
179 switch (x->outer_mode->encap) {
180 case XFRM_MODE_BEET:
181 case XFRM_MODE_TUNNEL:
182 if (x->outer_mode->family == AF_INET)
183 return xfrm4_prepare_output(x, skb);
184 if (x->outer_mode->family == AF_INET6)
185 return xfrm6_prepare_output(x, skb);
186 break;
187 case XFRM_MODE_TRANSPORT:
188 if (x->outer_mode->family == AF_INET)
189 return xfrm4_transport_output(x, skb);
190 if (x->outer_mode->family == AF_INET6)
191 return xfrm6_transport_output(x, skb);
192 break;
193 case XFRM_MODE_ROUTEOPTIMIZATION:
194 if (x->outer_mode->family == AF_INET6)
195 return xfrm6_ro_output(x, skb);
196 WARN_ON_ONCE(1);
197 break;
198 default:
199 WARN_ON_ONCE(1);
200 break;
201 }
202
203 return -EOPNOTSUPP;
204}
205
206#if IS_ENABLED(CONFIG_NET_PKTGEN)
207int pktgen_xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
208{
209 return xfrm_outer_mode_output(x, skb);
210}
211EXPORT_SYMBOL_GPL(pktgen_xfrm_outer_mode_output);
212#endif
213
Herbert Xuc6581a42007-11-13 21:43:43 -0800214static int xfrm_output_one(struct sk_buff *skb, int err)
Herbert Xu406ef772007-10-08 17:16:30 -0700215{
Eric Dumazetadf30902009-06-02 05:19:30 +0000216 struct dst_entry *dst = skb_dst(skb);
Herbert Xu406ef772007-10-08 17:16:30 -0700217 struct xfrm_state *x = dst->xfrm;
Alexey Dobriyana6483b72008-11-25 17:38:20 -0800218 struct net *net = xs_net(x);
Herbert Xu406ef772007-10-08 17:16:30 -0700219
Herbert Xuc6581a42007-11-13 21:43:43 -0800220 if (err <= 0)
221 goto resume;
Herbert Xu406ef772007-10-08 17:16:30 -0700222
223 do {
Steffen Klassert26b20722012-03-21 23:32:39 +0000224 err = xfrm_skb_check_space(skb);
Masahide NAKAMURAb15c4bc2007-12-24 16:00:09 -0800225 if (err) {
Alexey Dobriyan59c99402008-11-25 17:59:52 -0800226 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
Herbert Xu910ef702007-12-18 22:14:25 -0800227 goto error_nolock;
Masahide NAKAMURAb15c4bc2007-12-24 16:00:09 -0800228 }
Herbert Xu910ef702007-12-18 22:14:25 -0800229
Steffen Klassert9b42c1f2018-06-12 12:44:26 +0200230 skb->mark = xfrm_smark_get(skb->mark, x);
Lorenzo Colitti077fbac2017-08-11 02:11:33 +0900231
Florian Westphal0c620e92019-03-29 21:16:25 +0100232 err = xfrm_outer_mode_output(x, skb);
Masahide NAKAMURAb15c4bc2007-12-24 16:00:09 -0800233 if (err) {
Alexey Dobriyan59c99402008-11-25 17:59:52 -0800234 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR);
Herbert Xu910ef702007-12-18 22:14:25 -0800235 goto error_nolock;
Masahide NAKAMURAb15c4bc2007-12-24 16:00:09 -0800236 }
Herbert Xua2deb6d22007-11-13 21:39:38 -0800237
Herbert Xu406ef772007-10-08 17:16:30 -0700238 spin_lock_bh(&x->lock);
Li RongQingbb65a9c2012-12-28 16:06:28 +0800239
240 if (unlikely(x->km.state != XFRM_STATE_VALID)) {
241 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEINVALID);
Timo Teräs497574c2013-05-22 01:40:47 +0000242 err = -EINVAL;
Li RongQingfa8599d2013-02-01 13:17:16 +0800243 goto error;
Li RongQingbb65a9c2012-12-28 16:06:28 +0800244 }
245
Herbert Xu910ef702007-12-18 22:14:25 -0800246 err = xfrm_state_check_expire(x);
Masahide NAKAMURAb15c4bc2007-12-24 16:00:09 -0800247 if (err) {
Alexey Dobriyan59c99402008-11-25 17:59:52 -0800248 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEEXPIRED);
Herbert Xu406ef772007-10-08 17:16:30 -0700249 goto error;
Masahide NAKAMURAb15c4bc2007-12-24 16:00:09 -0800250 }
Herbert Xu406ef772007-10-08 17:16:30 -0700251
Steffen Klassert9fdc4882011-03-08 00:08:32 +0000252 err = x->repl->overflow(x, skb);
253 if (err) {
254 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATESEQERROR);
255 goto error;
Herbert Xu436a0a42007-10-08 17:25:53 -0700256 }
257
Herbert Xu406ef772007-10-08 17:16:30 -0700258 x->curlft.bytes += skb->len;
259 x->curlft.packets++;
260
Herbert Xu406ef772007-10-08 17:16:30 -0700261 spin_unlock_bh(&x->lock);
262
Steffen Klassert3bc07322011-03-15 21:08:28 +0000263 skb_dst_force(skb);
Steffen Klassert9e143792018-09-11 10:31:15 +0200264 if (!skb_dst(skb)) {
265 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
Wei Yongjun533555e2018-10-27 06:12:06 +0000266 err = -EHOSTUNREACH;
Steffen Klassert9e143792018-09-11 10:31:15 +0200267 goto error_nolock;
268 }
Steffen Klassert3bc07322011-03-15 21:08:28 +0000269
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200270 if (xfrm_offload(skb)) {
271 x->type_offload->encap(x, skb);
272 } else {
Steffen Klassert73b9fc42017-10-30 10:04:04 +0100273 /* Inner headers are invalid now. */
274 skb->encapsulation = 0;
275
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200276 err = x->type->output(x, skb);
277 if (err == -EINPROGRESS)
278 goto out;
279 }
Herbert Xuc6581a42007-11-13 21:43:43 -0800280
281resume:
Masahide NAKAMURA0aa64772007-12-20 20:43:36 -0800282 if (err) {
Alexey Dobriyan59c99402008-11-25 17:59:52 -0800283 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEPROTOERROR);
Herbert Xub7c6538c2007-10-09 13:33:35 -0700284 goto error_nolock;
Masahide NAKAMURA0aa64772007-12-20 20:43:36 -0800285 }
Herbert Xub7c6538c2007-10-09 13:33:35 -0700286
Steffen Klassert8764ab22010-06-04 01:57:38 +0000287 dst = skb_dst_pop(skb);
Eric Dumazetadf30902009-06-02 05:19:30 +0000288 if (!dst) {
Alexey Dobriyan59c99402008-11-25 17:59:52 -0800289 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
Herbert Xu406ef772007-10-08 17:16:30 -0700290 err = -EHOSTUNREACH;
291 goto error_nolock;
292 }
Steffen Klasserte4334302011-03-15 21:09:32 +0000293 skb_dst_set(skb, dst);
Herbert Xu406ef772007-10-08 17:16:30 -0700294 x = dst->xfrm;
Herbert Xu13996372007-10-17 21:35:51 -0700295 } while (x && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL));
Herbert Xu406ef772007-10-08 17:16:30 -0700296
Jean Sacrenebd46872013-06-01 16:23:15 +0000297 return 0;
Herbert Xu406ef772007-10-08 17:16:30 -0700298
Herbert Xu406ef772007-10-08 17:16:30 -0700299error:
300 spin_unlock_bh(&x->lock);
Herbert Xu862b82c2007-11-13 21:43:11 -0800301error_nolock:
302 kfree_skb(skb);
Jean Sacrenebd46872013-06-01 16:23:15 +0000303out:
304 return err;
Herbert Xu862b82c2007-11-13 21:43:11 -0800305}
306
Herbert Xuc6581a42007-11-13 21:43:43 -0800307int xfrm_output_resume(struct sk_buff *skb, int err)
Herbert Xu862b82c2007-11-13 21:43:11 -0800308{
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500309 struct net *net = xs_net(skb_dst(skb)->xfrm);
Eric W. Biedermanbe10de02015-09-17 17:21:31 -0500310
Herbert Xuc6581a42007-11-13 21:43:43 -0800311 while (likely((err = xfrm_output_one(skb, err)) == 0)) {
Herbert Xu862b82c2007-11-13 21:43:11 -0800312 nf_reset(skb);
313
Eric W. Biedermancf91a992015-10-07 16:48:45 -0500314 err = skb_dst(skb)->ops->local_out(net, skb->sk, skb);
Herbert Xu862b82c2007-11-13 21:43:11 -0800315 if (unlikely(err != 1))
Herbert Xuc6581a42007-11-13 21:43:43 -0800316 goto out;
Herbert Xu862b82c2007-11-13 21:43:11 -0800317
Eric Dumazetadf30902009-06-02 05:19:30 +0000318 if (!skb_dst(skb)->xfrm)
Eric W. Biederman13206b62015-10-07 16:48:35 -0500319 return dst_output(net, skb->sk, skb);
Herbert Xu862b82c2007-11-13 21:43:11 -0800320
Eric Dumazetadf30902009-06-02 05:19:30 +0000321 err = nf_hook(skb_dst(skb)->ops->family,
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500322 NF_INET_POST_ROUTING, net, skb->sk, skb,
Eric Dumazetadf30902009-06-02 05:19:30 +0000323 NULL, skb_dst(skb)->dev, xfrm_output2);
Herbert Xu862b82c2007-11-13 21:43:11 -0800324 if (unlikely(err != 1))
Herbert Xuc6581a42007-11-13 21:43:43 -0800325 goto out;
Herbert Xu862b82c2007-11-13 21:43:11 -0800326 }
327
Herbert Xuc6581a42007-11-13 21:43:43 -0800328 if (err == -EINPROGRESS)
329 err = 0;
330
331out:
Herbert Xu862b82c2007-11-13 21:43:11 -0800332 return err;
333}
Herbert Xuc6581a42007-11-13 21:43:43 -0800334EXPORT_SYMBOL_GPL(xfrm_output_resume);
Herbert Xu862b82c2007-11-13 21:43:11 -0800335
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500336static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb)
Herbert Xuc6581a42007-11-13 21:43:43 -0800337{
338 return xfrm_output_resume(skb, 1);
339}
340
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500341static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skb)
Herbert Xu862b82c2007-11-13 21:43:11 -0800342{
343 struct sk_buff *segs;
344
Konstantin Khlebnikov9207f9d2016-01-08 15:21:46 +0300345 BUILD_BUG_ON(sizeof(*IPCB(skb)) > SKB_SGO_CB_OFFSET);
346 BUILD_BUG_ON(sizeof(*IP6CB(skb)) > SKB_SGO_CB_OFFSET);
Herbert Xu862b82c2007-11-13 21:43:11 -0800347 segs = skb_gso_segment(skb, 0);
348 kfree_skb(skb);
Hirofumi Nakagawa801678c2008-04-29 01:03:09 -0700349 if (IS_ERR(segs))
Herbert Xu862b82c2007-11-13 21:43:11 -0800350 return PTR_ERR(segs);
Florian Westphal330966e2014-10-20 13:49:17 +0200351 if (segs == NULL)
352 return -EINVAL;
Herbert Xu862b82c2007-11-13 21:43:11 -0800353
354 do {
355 struct sk_buff *nskb = segs->next;
356 int err;
357
David S. Millera8305bf2018-07-29 20:42:53 -0700358 skb_mark_not_on_list(segs);
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500359 err = xfrm_output2(net, sk, segs);
Herbert Xu862b82c2007-11-13 21:43:11 -0800360
361 if (unlikely(err)) {
Florian Westphal46cfd722014-09-10 01:08:46 +0200362 kfree_skb_list(nskb);
Herbert Xu862b82c2007-11-13 21:43:11 -0800363 return err;
364 }
365
366 segs = nskb;
367 } while (segs);
368
369 return 0;
Herbert Xu406ef772007-10-08 17:16:30 -0700370}
Herbert Xuc6581a42007-11-13 21:43:43 -0800371
David Miller7026b1d2015-04-05 22:19:04 -0400372int xfrm_output(struct sock *sk, struct sk_buff *skb)
Herbert Xuc6581a42007-11-13 21:43:43 -0800373{
Eric Dumazetadf30902009-06-02 05:19:30 +0000374 struct net *net = dev_net(skb_dst(skb)->dev);
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200375 struct xfrm_state *x = skb_dst(skb)->xfrm;
Herbert Xuc6581a42007-11-13 21:43:43 -0800376 int err;
377
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200378 secpath_reset(skb);
379
380 if (xfrm_dev_offload_ok(skb, x)) {
381 struct sec_path *sp;
382
Florian Westphala84e3f52018-12-18 17:15:26 +0100383 sp = secpath_set(skb);
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200384 if (!sp) {
385 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
386 kfree_skb(skb);
387 return -ENOMEM;
388 }
Ilan Tayarif1bd7d62017-04-14 10:07:39 +0200389 skb->encapsulation = 1;
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200390
391 sp->olen++;
Florian Westphala84e3f52018-12-18 17:15:26 +0100392 sp->xvec[sp->len++] = x;
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200393 xfrm_state_hold(x);
394
395 if (skb_is_gso(skb)) {
396 skb_shinfo(skb)->gso_type |= SKB_GSO_ESP;
397
398 return xfrm_output2(net, sk, skb);
399 }
400
401 if (x->xso.dev && x->xso.dev->features & NETIF_F_HW_ESP_TX_CSUM)
402 goto out;
403 }
404
Herbert Xuc6581a42007-11-13 21:43:43 -0800405 if (skb_is_gso(skb))
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500406 return xfrm_output_gso(net, sk, skb);
Herbert Xuc6581a42007-11-13 21:43:43 -0800407
408 if (skb->ip_summed == CHECKSUM_PARTIAL) {
409 err = skb_checksum_help(skb);
410 if (err) {
Alexey Dobriyan59c99402008-11-25 17:59:52 -0800411 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
Herbert Xuc6581a42007-11-13 21:43:43 -0800412 kfree_skb(skb);
413 return err;
414 }
415 }
416
Steffen Klassertd77e38e2017-04-14 10:06:10 +0200417out:
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500418 return xfrm_output2(net, sk, skb);
Herbert Xuc6581a42007-11-13 21:43:43 -0800419}
Fabian Frederickfc680862014-05-12 19:54:34 +0200420EXPORT_SYMBOL_GPL(xfrm_output);
Kazunori MIYAZAWAdf9dcb42008-03-24 14:51:51 -0700421
Florian Westphal0c620e92019-03-29 21:16:25 +0100422static int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)
Kazunori MIYAZAWAdf9dcb42008-03-24 14:51:51 -0700423{
424 struct xfrm_mode *inner_mode;
425 if (x->sel.family == AF_UNSPEC)
426 inner_mode = xfrm_ip2inner_mode(x,
Eric Dumazetadf30902009-06-02 05:19:30 +0000427 xfrm_af2proto(skb_dst(skb)->ops->family));
Kazunori MIYAZAWAdf9dcb42008-03-24 14:51:51 -0700428 else
429 inner_mode = x->inner_mode;
430
431 if (inner_mode == NULL)
432 return -EAFNOSUPPORT;
433 return inner_mode->afinfo->extract_output(x, skb);
434}
435
Hannes Frederic Sowa628e3412013-08-14 13:05:23 +0200436void xfrm_local_error(struct sk_buff *skb, int mtu)
437{
Hannes Frederic Sowa844d4872013-08-18 13:47:01 +0200438 unsigned int proto;
Hannes Frederic Sowa628e3412013-08-14 13:05:23 +0200439 struct xfrm_state_afinfo *afinfo;
440
Hannes Frederic Sowa844d4872013-08-18 13:47:01 +0200441 if (skb->protocol == htons(ETH_P_IP))
442 proto = AF_INET;
443 else if (skb->protocol == htons(ETH_P_IPV6))
444 proto = AF_INET6;
445 else
446 return;
447
448 afinfo = xfrm_state_get_afinfo(proto);
Taehee Yoo46c0ef62018-03-16 11:35:51 +0900449 if (afinfo) {
Florian Westphalaf5d27c2017-01-09 14:20:47 +0100450 afinfo->local_error(skb, mtu);
Taehee Yoo46c0ef62018-03-16 11:35:51 +0900451 rcu_read_unlock();
452 }
Hannes Frederic Sowa628e3412013-08-14 13:05:23 +0200453}
Hannes Frederic Sowa628e3412013-08-14 13:05:23 +0200454EXPORT_SYMBOL_GPL(xfrm_local_error);