License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* xfrm_input.c
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* YOSHIFUJI Hideaki @USAGI
|
|
|
|
* Split up af-specific portion
|
2007-02-09 22:25:29 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2017-12-15 13:40:44 +08:00
|
|
|
#include <linux/bottom_half.h>
|
2018-02-25 02:21:38 +08:00
|
|
|
#include <linux/cache.h>
|
2017-12-15 13:40:44 +08:00
|
|
|
#include <linux/interrupt.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
2007-11-14 13:44:23 +08:00
|
|
|
#include <linux/netdevice.h>
|
2017-12-15 13:40:44 +08:00
|
|
|
#include <linux/percpu.h>
|
2007-11-14 13:44:23 +08:00
|
|
|
#include <net/dst.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/ip.h>
|
|
|
|
#include <net/xfrm.h>
|
2015-05-27 22:16:49 +08:00
|
|
|
#include <net/ip_tunnels.h>
|
|
|
|
#include <net/ip6_tunnel.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-03-30 04:16:28 +08:00
|
|
|
#include "xfrm_inout.h"
|
|
|
|
|
2017-12-15 13:40:44 +08:00
|
|
|
struct xfrm_trans_tasklet {
|
|
|
|
struct tasklet_struct tasklet;
|
|
|
|
struct sk_buff_head queue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xfrm_trans_cb {
|
2018-03-19 14:15:39 +08:00
|
|
|
union {
|
|
|
|
struct inet_skb_parm h4;
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
struct inet6_skb_parm h6;
|
|
|
|
#endif
|
|
|
|
} header;
|
2017-12-15 13:40:44 +08:00
|
|
|
int (*finish)(struct net *net, struct sock *sk, struct sk_buff *skb);
|
2019-11-25 21:48:58 +08:00
|
|
|
struct net *net;
|
2017-12-15 13:40:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define XFRM_TRANS_SKB_CB(__skb) ((struct xfrm_trans_cb *)&((__skb)->cb[0]))
|
|
|
|
|
2014-03-14 14:28:07 +08:00
|
|
|
static DEFINE_SPINLOCK(xfrm_input_afinfo_lock);
|
2020-07-06 20:01:29 +08:00
|
|
|
static struct xfrm_input_afinfo const __rcu *xfrm_input_afinfo[2][AF_INET6 + 1];
|
2014-03-14 14:28:07 +08:00
|
|
|
|
2017-01-30 13:45:43 +08:00
|
|
|
static struct gro_cells gro_cells;
|
|
|
|
static struct net_device xfrm_napi_dev;
|
|
|
|
|
2017-12-15 13:40:44 +08:00
|
|
|
static DEFINE_PER_CPU(struct xfrm_trans_tasklet, xfrm_trans_tasklet);
|
|
|
|
|
2017-02-07 21:52:30 +08:00
|
|
|
int xfrm_input_register_afinfo(const struct xfrm_input_afinfo *afinfo)
|
2014-03-14 14:28:07 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2020-07-06 20:01:29 +08:00
|
|
|
if (WARN_ON(afinfo->family > AF_INET6))
|
2014-03-14 14:28:07 +08:00
|
|
|
return -EAFNOSUPPORT;
|
2017-02-07 21:52:30 +08:00
|
|
|
|
2014-03-14 14:28:07 +08:00
|
|
|
spin_lock_bh(&xfrm_input_afinfo_lock);
|
2020-07-06 20:01:29 +08:00
|
|
|
if (unlikely(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family]))
|
2015-04-23 11:06:53 +08:00
|
|
|
err = -EEXIST;
|
2014-03-14 14:28:07 +08:00
|
|
|
else
|
2020-07-06 20:01:29 +08:00
|
|
|
rcu_assign_pointer(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family], afinfo);
|
2014-03-14 14:28:07 +08:00
|
|
|
spin_unlock_bh(&xfrm_input_afinfo_lock);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xfrm_input_register_afinfo);
|
|
|
|
|
2017-02-07 21:52:30 +08:00
|
|
|
int xfrm_input_unregister_afinfo(const struct xfrm_input_afinfo *afinfo)
|
2014-03-14 14:28:07 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
spin_lock_bh(&xfrm_input_afinfo_lock);
|
2020-07-06 20:01:29 +08:00
|
|
|
if (likely(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family])) {
|
|
|
|
if (unlikely(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family] != afinfo))
|
2014-03-14 14:28:07 +08:00
|
|
|
err = -EINVAL;
|
|
|
|
else
|
2020-07-06 20:01:29 +08:00
|
|
|
RCU_INIT_POINTER(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family], NULL);
|
2014-03-14 14:28:07 +08:00
|
|
|
}
|
|
|
|
spin_unlock_bh(&xfrm_input_afinfo_lock);
|
|
|
|
synchronize_rcu();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xfrm_input_unregister_afinfo);
|
|
|
|
|
2020-07-06 20:01:29 +08:00
|
|
|
static const struct xfrm_input_afinfo *xfrm_input_get_afinfo(u8 family, bool is_ipip)
|
2014-03-14 14:28:07 +08:00
|
|
|
{
|
2017-02-07 21:52:30 +08:00
|
|
|
const struct xfrm_input_afinfo *afinfo;
|
2014-03-14 14:28:07 +08:00
|
|
|
|
2020-07-06 20:01:29 +08:00
|
|
|
if (WARN_ON_ONCE(family > AF_INET6))
|
2014-03-14 14:28:07 +08:00
|
|
|
return NULL;
|
2017-02-07 21:52:30 +08:00
|
|
|
|
2014-03-14 14:28:07 +08:00
|
|
|
rcu_read_lock();
|
2020-07-06 20:01:29 +08:00
|
|
|
afinfo = rcu_dereference(xfrm_input_afinfo[is_ipip][family]);
|
2014-03-14 14:28:07 +08:00
|
|
|
if (unlikely(!afinfo))
|
|
|
|
rcu_read_unlock();
|
|
|
|
return afinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xfrm_rcv_cb(struct sk_buff *skb, unsigned int family, u8 protocol,
|
|
|
|
int err)
|
|
|
|
{
|
2020-07-06 20:01:29 +08:00
|
|
|
bool is_ipip = (protocol == IPPROTO_IPIP || protocol == IPPROTO_IPV6);
|
|
|
|
const struct xfrm_input_afinfo *afinfo;
|
2014-03-14 14:28:07 +08:00
|
|
|
int ret;
|
|
|
|
|
2020-07-06 20:01:29 +08:00
|
|
|
afinfo = xfrm_input_get_afinfo(family, is_ipip);
|
2014-03-14 14:28:07 +08:00
|
|
|
if (!afinfo)
|
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
|
|
|
|
ret = afinfo->callback(skb, protocol, err);
|
2017-02-07 21:52:30 +08:00
|
|
|
rcu_read_unlock();
|
2014-03-14 14:28:07 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-19 00:15:27 +08:00
|
|
|
struct sec_path *secpath_set(struct sk_buff *skb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-19 00:15:27 +08:00
|
|
|
struct sec_path *sp, *tmp = skb_ext_find(skb, SKB_EXT_SEC_PATH);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-12-19 00:15:27 +08:00
|
|
|
sp = skb_ext_add(skb, SKB_EXT_SEC_PATH);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sp)
|
|
|
|
return NULL;
|
|
|
|
|
2018-12-19 00:15:27 +08:00
|
|
|
if (tmp) /* reused existing one (was COW'd if needed) */
|
|
|
|
return sp;
|
2017-02-15 16:39:54 +08:00
|
|
|
|
2018-12-19 00:15:27 +08:00
|
|
|
/* allocated new secpath */
|
2018-10-07 10:22:42 +08:00
|
|
|
memset(sp->ovec, 0, sizeof(sp->ovec));
|
2018-12-19 00:15:27 +08:00
|
|
|
sp->olen = 0;
|
|
|
|
sp->len = 0;
|
2018-12-19 00:15:18 +08:00
|
|
|
|
|
|
|
return sp;
|
2017-02-15 16:39:24 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(secpath_set);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Fetch spi and seq from ipsec header */
|
|
|
|
|
2006-09-28 09:47:59 +08:00
|
|
|
int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int offset, offset_seq;
|
2007-10-18 12:30:34 +08:00
|
|
|
int hlen;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (nexthdr) {
|
|
|
|
case IPPROTO_AH:
|
2007-10-18 12:30:34 +08:00
|
|
|
hlen = sizeof(struct ip_auth_hdr);
|
2005-04-17 06:20:36 +08:00
|
|
|
offset = offsetof(struct ip_auth_hdr, spi);
|
|
|
|
offset_seq = offsetof(struct ip_auth_hdr, seq_no);
|
|
|
|
break;
|
|
|
|
case IPPROTO_ESP:
|
2007-10-18 12:30:34 +08:00
|
|
|
hlen = sizeof(struct ip_esp_hdr);
|
2005-04-17 06:20:36 +08:00
|
|
|
offset = offsetof(struct ip_esp_hdr, spi);
|
|
|
|
offset_seq = offsetof(struct ip_esp_hdr, seq_no);
|
|
|
|
break;
|
|
|
|
case IPPROTO_COMP:
|
|
|
|
if (!pskb_may_pull(skb, sizeof(struct ip_comp_hdr)))
|
|
|
|
return -EINVAL;
|
2013-12-24 09:43:47 +08:00
|
|
|
*spi = htonl(ntohs(*(__be16 *)(skb_transport_header(skb) + 2)));
|
2005-04-17 06:20:36 +08:00
|
|
|
*seq = 0;
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-10-18 12:30:34 +08:00
|
|
|
if (!pskb_may_pull(skb, hlen))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-12-24 09:43:47 +08:00
|
|
|
*spi = *(__be32 *)(skb_transport_header(skb) + offset);
|
|
|
|
*seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-02-15 16:39:49 +08:00
|
|
|
EXPORT_SYMBOL(xfrm_parse_spi);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-03-30 04:16:28 +08:00
|
|
|
static int xfrm4_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct iphdr *iph;
|
|
|
|
int optlen = 0;
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
|
|
|
if (unlikely(XFRM_MODE_SKB_CB(skb)->protocol == IPPROTO_BEETPH)) {
|
|
|
|
struct ip_beet_phdr *ph;
|
|
|
|
int phlen;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(*ph)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ph = (struct ip_beet_phdr *)skb->data;
|
|
|
|
|
|
|
|
phlen = sizeof(*ph) + ph->padlen;
|
|
|
|
optlen = ph->hdrlen * 8 + (IPV4_BEET_PHMAXLEN - phlen);
|
|
|
|
if (optlen < 0 || optlen & 3 || optlen > 250)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
XFRM_MODE_SKB_CB(skb)->protocol = ph->nexthdr;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, phlen))
|
|
|
|
goto out;
|
|
|
|
__skb_pull(skb, phlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_push(skb, sizeof(*iph));
|
|
|
|
skb_reset_network_header(skb);
|
|
|
|
skb_mac_header_rebuild(skb);
|
|
|
|
|
|
|
|
xfrm4_beet_make_header(skb);
|
|
|
|
|
|
|
|
iph = ip_hdr(skb);
|
|
|
|
|
|
|
|
iph->ihl += optlen / 4;
|
|
|
|
iph->tot_len = htons(skb->len);
|
|
|
|
iph->daddr = x->sel.daddr.a4;
|
|
|
|
iph->saddr = x->sel.saddr.a4;
|
|
|
|
iph->check = 0;
|
|
|
|
iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
|
|
|
|
err = 0;
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipip_ecn_decapsulate(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct iphdr *inner_iph = ipip_hdr(skb);
|
|
|
|
|
|
|
|
if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
|
|
|
|
IP_ECN_set_ce(inner_iph);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xfrm4_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
|
|
|
if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPIP)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = skb_unclone(skb, GFP_ATOMIC);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (x->props.flags & XFRM_STATE_DECAP_DSCP)
|
|
|
|
ipv4_copy_dscp(XFRM_MODE_SKB_CB(skb)->tos, ipip_hdr(skb));
|
|
|
|
if (!(x->props.flags & XFRM_STATE_NOECN))
|
|
|
|
ipip_ecn_decapsulate(skb);
|
|
|
|
|
|
|
|
skb_reset_network_header(skb);
|
|
|
|
skb_mac_header_rebuild(skb);
|
|
|
|
if (skb->mac_len)
|
|
|
|
eth_hdr(skb)->h_proto = skb->protocol;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipip6_ecn_decapsulate(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ipv6hdr *inner_iph = ipipv6_hdr(skb);
|
|
|
|
|
|
|
|
if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
|
|
|
|
IP6_ECN_set_ce(skb, inner_iph);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xfrm6_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
|
|
|
if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPV6)
|
|
|
|
goto out;
|
|
|
|
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = skb_unclone(skb, GFP_ATOMIC);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (x->props.flags & XFRM_STATE_DECAP_DSCP)
|
|
|
|
ipv6_copy_dscp(ipv6_get_dsfield(ipv6_hdr(skb)),
|
|
|
|
ipipv6_hdr(skb));
|
|
|
|
if (!(x->props.flags & XFRM_STATE_NOECN))
|
|
|
|
ipip6_ecn_decapsulate(skb);
|
|
|
|
|
|
|
|
skb_reset_network_header(skb);
|
|
|
|
skb_mac_header_rebuild(skb);
|
|
|
|
if (skb->mac_len)
|
|
|
|
eth_hdr(skb)->h_proto = skb->protocol;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xfrm6_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ipv6hdr *ip6h;
|
|
|
|
int size = sizeof(struct ipv6hdr);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = skb_cow_head(skb, size + skb->mac_len);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
__skb_push(skb, size);
|
|
|
|
skb_reset_network_header(skb);
|
|
|
|
skb_mac_header_rebuild(skb);
|
|
|
|
|
|
|
|
xfrm6_beet_make_header(skb);
|
|
|
|
|
|
|
|
ip6h = ipv6_hdr(skb);
|
|
|
|
ip6h->payload_len = htons(skb->len - size);
|
|
|
|
ip6h->daddr = x->sel.daddr.in6;
|
|
|
|
ip6h->saddr = x->sel.saddr.in6;
|
|
|
|
err = 0;
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove encapsulation header.
|
|
|
|
*
|
|
|
|
* The IP header will be moved over the top of the encapsulation
|
|
|
|
* header.
|
|
|
|
*
|
|
|
|
* On entry, the transport header shall point to where the IP header
|
|
|
|
* should be and the network header shall be set to where the IP
|
|
|
|
* header currently is. skb->data shall point to the start of the
|
|
|
|
* payload.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
xfrm_inner_mode_encap_remove(struct xfrm_state *x,
|
|
|
|
const struct xfrm_mode *inner_mode,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
switch (inner_mode->encap) {
|
|
|
|
case XFRM_MODE_BEET:
|
|
|
|
if (inner_mode->family == AF_INET)
|
|
|
|
return xfrm4_remove_beet_encap(x, skb);
|
|
|
|
if (inner_mode->family == AF_INET6)
|
|
|
|
return xfrm6_remove_beet_encap(x, skb);
|
|
|
|
break;
|
|
|
|
case XFRM_MODE_TUNNEL:
|
|
|
|
if (inner_mode->family == AF_INET)
|
|
|
|
return xfrm4_remove_tunnel_encap(x, skb);
|
|
|
|
if (inner_mode->family == AF_INET6)
|
|
|
|
return xfrm6_remove_tunnel_encap(x, skb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2019-03-30 04:16:24 +08:00
|
|
|
static int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb)
|
2007-11-14 13:41:28 +08:00
|
|
|
{
|
2019-03-30 04:16:32 +08:00
|
|
|
const struct xfrm_mode *inner_mode = &x->inner_mode;
|
2007-11-14 13:41:28 +08:00
|
|
|
|
2020-05-04 16:06:04 +08:00
|
|
|
switch (x->outer_mode.family) {
|
|
|
|
case AF_INET:
|
|
|
|
xfrm4_extract_header(skb);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
xfrm6_extract_header(skb);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
}
|
2007-11-14 13:41:28 +08:00
|
|
|
|
2008-03-25 05:51:51 +08:00
|
|
|
if (x->sel.family == AF_UNSPEC) {
|
|
|
|
inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
|
2019-05-03 23:46:18 +08:00
|
|
|
if (!inner_mode)
|
2008-03-25 05:51:51 +08:00
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
}
|
|
|
|
|
2019-05-03 23:46:18 +08:00
|
|
|
switch (inner_mode->family) {
|
|
|
|
case AF_INET:
|
|
|
|
skb->protocol = htons(ETH_P_IP);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
skb->protocol = htons(ETH_P_IPV6);
|
2019-06-12 16:30:58 +08:00
|
|
|
break;
|
2019-05-03 23:46:18 +08:00
|
|
|
default:
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
break;
|
2019-03-30 04:16:30 +08:00
|
|
|
}
|
|
|
|
|
2019-03-30 04:16:28 +08:00
|
|
|
return xfrm_inner_mode_encap_remove(x, inner_mode, skb);
|
2007-11-14 13:41:28 +08:00
|
|
|
}
|
2019-03-30 04:16:24 +08:00
|
|
|
|
|
|
|
/* Remove encapsulation header.
|
|
|
|
*
|
|
|
|
* The IP header will be moved over the top of the encapsulation header.
|
|
|
|
*
|
|
|
|
* On entry, skb_transport_header() shall point to where the IP header
|
|
|
|
* should be and skb_network_header() shall be set to where the IP header
|
|
|
|
* currently is. skb->data shall point to the start of the payload.
|
|
|
|
*/
|
|
|
|
static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int ihl = skb->data - skb_transport_header(skb);
|
|
|
|
|
|
|
|
if (skb->transport_header != skb->network_header) {
|
|
|
|
memmove(skb_transport_header(skb),
|
|
|
|
skb_network_header(skb), ihl);
|
|
|
|
skb->network_header = skb->transport_header;
|
|
|
|
}
|
|
|
|
ip_hdr(skb)->tot_len = htons(skb->len + ihl);
|
|
|
|
skb_reset_transport_header(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xfrm6_transport_input(struct xfrm_state *x, struct sk_buff *skb)
|
|
|
|
{
|
2019-03-30 04:16:31 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2019-03-30 04:16:24 +08:00
|
|
|
int ihl = skb->data - skb_transport_header(skb);
|
|
|
|
|
|
|
|
if (skb->transport_header != skb->network_header) {
|
|
|
|
memmove(skb_transport_header(skb),
|
|
|
|
skb_network_header(skb), ihl);
|
|
|
|
skb->network_header = skb->transport_header;
|
|
|
|
}
|
|
|
|
ipv6_hdr(skb)->payload_len = htons(skb->len + ihl -
|
|
|
|
sizeof(struct ipv6hdr));
|
|
|
|
skb_reset_transport_header(skb);
|
|
|
|
return 0;
|
|
|
|
#else
|
2019-03-30 04:16:31 +08:00
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return -EAFNOSUPPORT;
|
2019-03-30 04:16:24 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xfrm_inner_mode_input(struct xfrm_state *x,
|
|
|
|
const struct xfrm_mode *inner_mode,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
switch (inner_mode->encap) {
|
|
|
|
case XFRM_MODE_BEET:
|
|
|
|
case XFRM_MODE_TUNNEL:
|
|
|
|
return xfrm_prepare_input(x, skb);
|
|
|
|
case XFRM_MODE_TRANSPORT:
|
|
|
|
if (inner_mode->family == AF_INET)
|
|
|
|
return xfrm4_transport_input(x, skb);
|
|
|
|
if (inner_mode->family == AF_INET6)
|
|
|
|
return xfrm6_transport_input(x, skb);
|
|
|
|
break;
|
|
|
|
case XFRM_MODE_ROUTEOPTIMIZATION:
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2007-11-14 13:41:28 +08:00
|
|
|
|
2007-11-14 13:44:23 +08:00
|
|
|
int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
|
|
|
|
{
|
2019-03-30 04:16:30 +08:00
|
|
|
const struct xfrm_state_afinfo *afinfo;
|
2008-11-26 09:37:56 +08:00
|
|
|
struct net *net = dev_net(skb->dev);
|
2019-03-30 04:16:31 +08:00
|
|
|
const struct xfrm_mode *inner_mode;
|
2007-11-14 13:44:23 +08:00
|
|
|
int err;
|
|
|
|
__be32 seq;
|
2011-03-08 08:09:51 +08:00
|
|
|
__be32 seq_hi;
|
2014-02-21 15:41:08 +08:00
|
|
|
struct xfrm_state *x = NULL;
|
2007-11-20 10:50:17 +08:00
|
|
|
xfrm_address_t *daddr;
|
2015-05-27 22:16:49 +08:00
|
|
|
u32 mark = skb->mark;
|
2017-11-29 01:55:40 +08:00
|
|
|
unsigned int family = AF_UNSPEC;
|
2007-11-14 13:44:23 +08:00
|
|
|
int decaps = 0;
|
2007-11-20 10:50:17 +08:00
|
|
|
int async = 0;
|
2017-02-15 16:40:00 +08:00
|
|
|
bool xfrm_gro = false;
|
2017-04-14 16:06:10 +08:00
|
|
|
bool crypto_done = false;
|
|
|
|
struct xfrm_offload *xo = xfrm_offload(skb);
|
2018-12-19 00:15:18 +08:00
|
|
|
struct sec_path *sp;
|
2007-11-20 10:50:17 +08:00
|
|
|
|
|
|
|
if (encap_type < 0) {
|
2007-12-11 17:53:43 +08:00
|
|
|
x = xfrm_input_state(skb);
|
2017-11-29 01:55:40 +08:00
|
|
|
|
|
|
|
if (unlikely(x->km.state != XFRM_STATE_VALID)) {
|
|
|
|
if (x->km.state == XFRM_STATE_ACQ)
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMACQUIREERROR);
|
|
|
|
else
|
|
|
|
XFRM_INC_STATS(net,
|
|
|
|
LINUX_MIB_XFRMINSTATEINVALID);
|
2019-11-12 07:05:46 +08:00
|
|
|
|
|
|
|
if (encap_type == -1)
|
|
|
|
dev_put(skb->dev);
|
2017-11-29 01:55:40 +08:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2019-03-30 04:16:32 +08:00
|
|
|
family = x->outer_mode.family;
|
2017-02-15 16:40:00 +08:00
|
|
|
|
|
|
|
/* An encap_type of -1 indicates async resumption. */
|
|
|
|
if (encap_type == -1) {
|
|
|
|
async = 1;
|
|
|
|
seq = XFRM_SKB_CB(skb)->seq.input.low;
|
|
|
|
goto resume;
|
|
|
|
}
|
2017-04-14 16:07:49 +08:00
|
|
|
|
2017-02-15 16:40:00 +08:00
|
|
|
/* encap_type < -1 indicates a GRO call. */
|
|
|
|
encap_type = 0;
|
|
|
|
seq = XFRM_SPI_SKB_CB(skb)->seq;
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2017-04-14 16:07:49 +08:00
|
|
|
if (xo && (xo->flags & CRYPTO_DONE)) {
|
|
|
|
crypto_done = true;
|
|
|
|
family = XFRM_SPI_SKB_CB(skb)->family;
|
|
|
|
|
|
|
|
if (!(xo->status & CRYPTO_SUCCESS)) {
|
|
|
|
if (xo->status &
|
|
|
|
(CRYPTO_TRANSPORT_AH_AUTH_FAILED |
|
|
|
|
CRYPTO_TRANSPORT_ESP_AUTH_FAILED |
|
|
|
|
CRYPTO_TUNNEL_AH_AUTH_FAILED |
|
|
|
|
CRYPTO_TUNNEL_ESP_AUTH_FAILED)) {
|
|
|
|
|
|
|
|
xfrm_audit_state_icvfail(x, skb,
|
|
|
|
x->type->proto);
|
|
|
|
x->stats.integrity_failed++;
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEPROTOERROR);
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2017-08-30 16:30:39 +08:00
|
|
|
if (xo->status & CRYPTO_INVALID_PROTOCOL) {
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEPROTOERROR);
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2017-04-14 16:07:49 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
|
2017-04-14 16:06:10 +08:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2017-04-14 16:07:49 +08:00
|
|
|
if ((err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0) {
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
|
|
|
|
goto drop;
|
|
|
|
}
|
2017-04-14 16:06:10 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 16:40:00 +08:00
|
|
|
goto lock;
|
2007-11-20 10:50:17 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2014-02-21 15:41:08 +08:00
|
|
|
family = XFRM_SPI_SKB_CB(skb)->family;
|
|
|
|
|
2015-05-27 22:16:49 +08:00
|
|
|
/* if tunnel is present override skb->mark value with tunnel i_key */
|
2016-08-10 18:54:57 +08:00
|
|
|
switch (family) {
|
|
|
|
case AF_INET:
|
|
|
|
if (XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4)
|
2015-05-27 22:16:49 +08:00
|
|
|
mark = be32_to_cpu(XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4->parms.i_key);
|
2016-08-10 18:54:57 +08:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
if (XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6)
|
2015-05-27 22:16:49 +08:00
|
|
|
mark = be32_to_cpu(XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6->parms.i_key);
|
2016-08-10 18:54:57 +08:00
|
|
|
break;
|
2015-05-27 22:16:49 +08:00
|
|
|
}
|
|
|
|
|
2018-12-19 00:15:18 +08:00
|
|
|
sp = secpath_set(skb);
|
|
|
|
if (!sp) {
|
2017-02-15 16:39:24 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
|
|
|
|
goto drop;
|
2007-11-14 13:44:55 +08:00
|
|
|
}
|
|
|
|
|
2007-11-14 13:44:23 +08:00
|
|
|
seq = 0;
|
2007-12-21 12:43:36 +08:00
|
|
|
if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0) {
|
2018-06-12 20:07:12 +08:00
|
|
|
secpath_reset(skb);
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2017-11-02 03:30:49 +08:00
|
|
|
daddr = (xfrm_address_t *)(skb_network_header(skb) +
|
|
|
|
XFRM_SPI_SKB_CB(skb)->daddroff);
|
2007-11-14 13:44:23 +08:00
|
|
|
do {
|
2018-12-19 00:15:20 +08:00
|
|
|
sp = skb_sec_path(skb);
|
|
|
|
|
|
|
|
if (sp->len == XFRM_MAX_DEPTH) {
|
2018-06-12 20:07:12 +08:00
|
|
|
secpath_reset(skb);
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2015-05-27 22:16:49 +08:00
|
|
|
x = xfrm_state_lookup(net, mark, daddr, spi, nexthdr, family);
|
2007-12-21 12:43:36 +08:00
|
|
|
if (x == NULL) {
|
2018-06-12 20:07:12 +08:00
|
|
|
secpath_reset(skb);
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINNOSTATES);
|
2007-12-22 06:58:11 +08:00
|
|
|
xfrm_audit_state_notfound(skb, family, spi, seq);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2018-06-12 18:44:26 +08:00
|
|
|
skb->mark = xfrm_smark_get(skb->mark, x);
|
|
|
|
|
2018-12-19 00:15:20 +08:00
|
|
|
sp->xvec[sp->len++] = x;
|
2007-11-14 13:44:55 +08:00
|
|
|
|
2018-11-22 14:26:24 +08:00
|
|
|
skb_dst_force(skb);
|
|
|
|
if (!skb_dst(skb)) {
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2017-02-15 16:40:00 +08:00
|
|
|
lock:
|
2007-11-14 13:44:23 +08:00
|
|
|
spin_lock(&x->lock);
|
2013-06-06 10:15:54 +08:00
|
|
|
|
2007-12-21 12:43:36 +08:00
|
|
|
if (unlikely(x->km.state != XFRM_STATE_VALID)) {
|
2015-04-24 16:49:31 +08:00
|
|
|
if (x->km.state == XFRM_STATE_ACQ)
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMACQUIREERROR);
|
|
|
|
else
|
|
|
|
XFRM_INC_STATS(net,
|
|
|
|
LINUX_MIB_XFRMINSTATEINVALID);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop_unlock;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2008-12-19 11:23:56 +08:00
|
|
|
if ((x->encap ? x->encap->encap_type : 0) != encap_type) {
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMISMATCH);
|
|
|
|
goto drop_unlock;
|
|
|
|
}
|
|
|
|
|
2011-03-29 03:45:52 +08:00
|
|
|
if (x->repl->check(x, skb, seq)) {
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop_unlock;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2007-12-21 12:43:36 +08:00
|
|
|
if (xfrm_state_check_expire(x)) {
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEEXPIRED);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop_unlock;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2007-11-14 13:45:58 +08:00
|
|
|
spin_unlock(&x->lock);
|
|
|
|
|
2015-04-02 15:58:24 +08:00
|
|
|
if (xfrm_tunnel_check(skb, x, family)) {
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2011-03-08 08:09:51 +08:00
|
|
|
seq_hi = htonl(xfrm_replay_seqhi(x, seq));
|
|
|
|
|
2011-03-08 08:06:31 +08:00
|
|
|
XFRM_SKB_CB(skb)->seq.input.low = seq;
|
2011-03-08 08:09:51 +08:00
|
|
|
XFRM_SKB_CB(skb)->seq.input.hi = seq_hi;
|
2007-11-20 10:50:17 +08:00
|
|
|
|
2016-03-24 12:39:50 +08:00
|
|
|
dev_hold(skb->dev);
|
2011-03-16 05:08:28 +08:00
|
|
|
|
2017-04-14 16:06:10 +08:00
|
|
|
if (crypto_done)
|
|
|
|
nexthdr = x->type_offload->input_tail(x, skb);
|
|
|
|
else
|
|
|
|
nexthdr = x->type->input(x, skb);
|
2007-11-14 13:45:58 +08:00
|
|
|
|
2007-11-20 10:50:17 +08:00
|
|
|
if (nexthdr == -EINPROGRESS)
|
|
|
|
return 0;
|
|
|
|
resume:
|
2016-03-24 12:39:50 +08:00
|
|
|
dev_put(skb->dev);
|
|
|
|
|
2007-11-14 13:45:58 +08:00
|
|
|
spin_lock(&x->lock);
|
2020-04-10 17:06:01 +08:00
|
|
|
if (nexthdr < 0) {
|
2007-12-31 13:10:30 +08:00
|
|
|
if (nexthdr == -EBADMSG) {
|
|
|
|
xfrm_audit_state_icvfail(x, skb,
|
|
|
|
x->type->proto);
|
2007-12-17 07:55:02 +08:00
|
|
|
x->stats.integrity_failed++;
|
2007-12-31 13:10:30 +08:00
|
|
|
}
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEPROTOERROR);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop_unlock;
|
2007-12-17 07:55:02 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
|
|
|
/* only the first xfrm gets the encap type */
|
|
|
|
encap_type = 0;
|
|
|
|
|
2012-09-04 08:03:29 +08:00
|
|
|
if (async && x->repl->recheck(x, skb, seq)) {
|
2011-09-21 07:38:58 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR);
|
|
|
|
goto drop_unlock;
|
|
|
|
}
|
|
|
|
|
2011-03-08 08:08:32 +08:00
|
|
|
x->repl->advance(x, seq);
|
2007-11-14 13:44:23 +08:00
|
|
|
|
|
|
|
x->curlft.bytes += skb->len;
|
|
|
|
x->curlft.packets++;
|
|
|
|
|
|
|
|
spin_unlock(&x->lock);
|
|
|
|
|
2007-11-20 10:47:58 +08:00
|
|
|
XFRM_MODE_SKB_CB(skb)->protocol = nexthdr;
|
|
|
|
|
2019-03-30 04:16:32 +08:00
|
|
|
inner_mode = &x->inner_mode;
|
2008-03-25 05:51:51 +08:00
|
|
|
|
|
|
|
if (x->sel.family == AF_UNSPEC) {
|
|
|
|
inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
|
2015-10-23 13:52:58 +08:00
|
|
|
if (inner_mode == NULL) {
|
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
|
2008-03-25 05:51:51 +08:00
|
|
|
goto drop;
|
2015-10-23 13:52:58 +08:00
|
|
|
}
|
2008-03-25 05:51:51 +08:00
|
|
|
}
|
|
|
|
|
2019-03-30 04:16:24 +08:00
|
|
|
if (xfrm_inner_mode_input(x, inner_mode, skb)) {
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2007-11-14 13:44:23 +08:00
|
|
|
|
2019-03-30 04:16:32 +08:00
|
|
|
if (x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL) {
|
2007-11-14 13:44:23 +08:00
|
|
|
decaps = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-20 10:50:17 +08:00
|
|
|
/*
|
|
|
|
* We need the inner address. However, we only get here for
|
|
|
|
* transport mode so the outer address is identical.
|
|
|
|
*/
|
|
|
|
daddr = &x->id.daddr;
|
2019-03-30 04:16:32 +08:00
|
|
|
family = x->outer_mode.family;
|
2007-11-20 10:50:17 +08:00
|
|
|
|
2007-11-14 13:44:23 +08:00
|
|
|
err = xfrm_parse_spi(skb, nexthdr, &spi, &seq);
|
2007-12-21 12:43:36 +08:00
|
|
|
if (err < 0) {
|
2008-11-26 09:59:52 +08:00
|
|
|
XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
|
2007-11-14 13:44:23 +08:00
|
|
|
goto drop;
|
2007-12-21 12:43:36 +08:00
|
|
|
}
|
2018-09-03 19:36:53 +08:00
|
|
|
crypto_done = false;
|
2007-11-14 13:44:23 +08:00
|
|
|
} while (!err);
|
|
|
|
|
2014-02-21 15:41:08 +08:00
|
|
|
err = xfrm_rcv_cb(skb, family, x->type->proto, 0);
|
|
|
|
if (err)
|
|
|
|
goto drop;
|
|
|
|
|
2019-09-30 02:54:03 +08:00
|
|
|
nf_reset_ct(skb);
|
2007-11-14 13:44:23 +08:00
|
|
|
|
|
|
|
if (decaps) {
|
2018-12-19 00:15:20 +08:00
|
|
|
sp = skb_sec_path(skb);
|
|
|
|
if (sp)
|
|
|
|
sp->olen = 0;
|
2009-06-02 13:19:30 +08:00
|
|
|
skb_dst_drop(skb);
|
2017-01-30 13:45:43 +08:00
|
|
|
gro_cells_receive(&gro_cells, skb);
|
2007-11-14 13:44:23 +08:00
|
|
|
return 0;
|
|
|
|
} else {
|
2017-02-15 16:40:00 +08:00
|
|
|
xo = xfrm_offload(skb);
|
|
|
|
if (xo)
|
|
|
|
xfrm_gro = xo->flags & XFRM_GRO;
|
|
|
|
|
2019-03-30 04:16:30 +08:00
|
|
|
err = -EAFNOSUPPORT;
|
|
|
|
rcu_read_lock();
|
2019-03-30 04:16:32 +08:00
|
|
|
afinfo = xfrm_state_afinfo_get_rcu(x->inner_mode.family);
|
2019-03-30 04:16:30 +08:00
|
|
|
if (likely(afinfo))
|
|
|
|
err = afinfo->transport_finish(skb, xfrm_gro || async);
|
|
|
|
rcu_read_unlock();
|
2017-02-15 16:40:00 +08:00
|
|
|
if (xfrm_gro) {
|
2018-12-19 00:15:20 +08:00
|
|
|
sp = skb_sec_path(skb);
|
|
|
|
if (sp)
|
|
|
|
sp->olen = 0;
|
2017-02-15 16:40:00 +08:00
|
|
|
skb_dst_drop(skb);
|
|
|
|
gro_cells_receive(&gro_cells, skb);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2007-11-14 13:44:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
drop_unlock:
|
|
|
|
spin_unlock(&x->lock);
|
|
|
|
drop:
|
2014-02-21 15:41:08 +08:00
|
|
|
xfrm_rcv_cb(skb, family, x && x->type ? x->type->proto : nexthdr, -1);
|
2007-11-14 13:44:23 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xfrm_input);
|
|
|
|
|
2007-11-20 10:50:17 +08:00
|
|
|
int xfrm_input_resume(struct sk_buff *skb, int nexthdr)
|
|
|
|
{
|
|
|
|
return xfrm_input(skb, nexthdr, 0, -1);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xfrm_input_resume);
|
|
|
|
|
2017-12-15 13:40:44 +08:00
|
|
|
static void xfrm_trans_reinject(unsigned long data)
|
|
|
|
{
|
|
|
|
struct xfrm_trans_tasklet *trans = (void *)data;
|
|
|
|
struct sk_buff_head queue;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
__skb_queue_head_init(&queue);
|
|
|
|
skb_queue_splice_init(&trans->queue, &queue);
|
|
|
|
|
|
|
|
while ((skb = __skb_dequeue(&queue)))
|
2019-11-25 21:48:58 +08:00
|
|
|
XFRM_TRANS_SKB_CB(skb)->finish(XFRM_TRANS_SKB_CB(skb)->net,
|
|
|
|
NULL, skb);
|
2017-12-15 13:40:44 +08:00
|
|
|
}
|
|
|
|
|
2019-11-25 21:48:58 +08:00
|
|
|
int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb,
|
|
|
|
int (*finish)(struct net *, struct sock *,
|
|
|
|
struct sk_buff *))
|
2017-12-15 13:40:44 +08:00
|
|
|
{
|
|
|
|
struct xfrm_trans_tasklet *trans;
|
|
|
|
|
|
|
|
trans = this_cpu_ptr(&xfrm_trans_tasklet);
|
|
|
|
|
|
|
|
if (skb_queue_len(&trans->queue) >= netdev_max_backlog)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2019-11-25 21:48:58 +08:00
|
|
|
BUILD_BUG_ON(sizeof(struct xfrm_trans_cb) > sizeof(skb->cb));
|
|
|
|
|
2017-12-15 13:40:44 +08:00
|
|
|
XFRM_TRANS_SKB_CB(skb)->finish = finish;
|
2019-11-25 21:48:58 +08:00
|
|
|
XFRM_TRANS_SKB_CB(skb)->net = net;
|
2018-01-04 19:25:07 +08:00
|
|
|
__skb_queue_tail(&trans->queue, skb);
|
2017-12-15 13:40:44 +08:00
|
|
|
tasklet_schedule(&trans->tasklet);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-25 21:48:58 +08:00
|
|
|
EXPORT_SYMBOL(xfrm_trans_queue_net);
|
|
|
|
|
|
|
|
int xfrm_trans_queue(struct sk_buff *skb,
|
|
|
|
int (*finish)(struct net *, struct sock *,
|
|
|
|
struct sk_buff *))
|
|
|
|
{
|
|
|
|
return xfrm_trans_queue_net(dev_net(skb->dev), skb, finish);
|
|
|
|
}
|
2017-12-15 13:40:44 +08:00
|
|
|
EXPORT_SYMBOL(xfrm_trans_queue);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void __init xfrm_input_init(void)
|
|
|
|
{
|
2017-01-30 13:45:43 +08:00
|
|
|
int err;
|
2017-12-15 13:40:44 +08:00
|
|
|
int i;
|
2017-01-30 13:45:43 +08:00
|
|
|
|
|
|
|
init_dummy_netdev(&xfrm_napi_dev);
|
|
|
|
err = gro_cells_init(&gro_cells, &xfrm_napi_dev);
|
|
|
|
if (err)
|
|
|
|
gro_cells.cells = NULL;
|
|
|
|
|
2017-12-15 13:40:44 +08:00
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
struct xfrm_trans_tasklet *trans;
|
|
|
|
|
|
|
|
trans = &per_cpu(xfrm_trans_tasklet, i);
|
|
|
|
__skb_queue_head_init(&trans->queue);
|
|
|
|
tasklet_init(&trans->tasklet, xfrm_trans_reinject,
|
|
|
|
(unsigned long)trans);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|