]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - net/ipv4/esp4_offload.c
Merge tag 'devprop-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[mirror_ubuntu-focal-kernel.git] / net / ipv4 / esp4_offload.c
CommitLineData
7785bba2
SK
1/*
2 * IPV4 GSO/GRO offload support
3 * Linux INET implementation
4 *
5 * Copyright (C) 2016 secunet Security Networks AG
6 * Author: Steffen Klassert <steffen.klassert@secunet.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * ESP GRO support
13 */
14
15#include <linux/skbuff.h>
16#include <linux/init.h>
17#include <net/protocol.h>
18#include <crypto/aead.h>
19#include <crypto/authenc.h>
20#include <linux/err.h>
21#include <linux/module.h>
22#include <net/ip.h>
23#include <net/xfrm.h>
24#include <net/esp.h>
25#include <linux/scatterlist.h>
26#include <linux/kernel.h>
27#include <linux/slab.h>
28#include <linux/spinlock.h>
29#include <net/udp.h>
30
31static struct sk_buff **esp4_gro_receive(struct sk_buff **head,
32 struct sk_buff *skb)
33{
34 int offset = skb_gro_offset(skb);
35 struct xfrm_offload *xo;
36 struct xfrm_state *x;
37 __be32 seq;
38 __be32 spi;
39 int err;
40
41 skb_pull(skb, offset);
42
43 if ((err = xfrm_parse_spi(skb, IPPROTO_ESP, &spi, &seq)) != 0)
44 goto out;
45
46 err = secpath_set(skb);
47 if (err)
48 goto out;
49
50 if (skb->sp->len == XFRM_MAX_DEPTH)
51 goto out;
52
53 x = xfrm_state_lookup(dev_net(skb->dev), skb->mark,
54 (xfrm_address_t *)&ip_hdr(skb)->daddr,
55 spi, IPPROTO_ESP, AF_INET);
56 if (!x)
57 goto out;
58
59 skb->sp->xvec[skb->sp->len++] = x;
60 skb->sp->olen++;
61
62 xo = xfrm_offload(skb);
63 if (!xo) {
64 xfrm_state_put(x);
65 goto out;
66 }
67 xo->flags |= XFRM_GRO;
68
69 XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = NULL;
70 XFRM_SPI_SKB_CB(skb)->family = AF_INET;
71 XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
72 XFRM_SPI_SKB_CB(skb)->seq = seq;
73
74 /* We don't need to handle errors from xfrm_input, it does all
75 * the error handling and frees the resources on error. */
76 xfrm_input(skb, IPPROTO_ESP, spi, -2);
77
78 return ERR_PTR(-EINPROGRESS);
79out:
80 skb_push(skb, offset);
81 NAPI_GRO_CB(skb)->same_flow = 0;
82 NAPI_GRO_CB(skb)->flush = 1;
83
84 return NULL;
85}
86
87static const struct net_offload esp4_offload = {
88 .callbacks = {
89 .gro_receive = esp4_gro_receive,
90 },
91};
92
93static int __init esp4_offload_init(void)
94{
95 return inet_add_offload(&esp4_offload, IPPROTO_ESP);
96}
97
98static void __exit esp4_offload_exit(void)
99{
100 inet_del_offload(&esp4_offload, IPPROTO_ESP);
101}
102
103module_init(esp4_offload_init);
104module_exit(esp4_offload_exit);
105MODULE_LICENSE("GPL");
106MODULE_AUTHOR("Steffen Klassert <steffen.klassert@secunet.com>");