mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-04 04:04:19 +00:00
xfrm: remove xmit indirection from xfrm_mode
There are only two versions (tunnel and transport). The ip/ipv6 versions are only differ in sizeof(iphdr) vs ipv6hdr. Place this in the core and use x->outer_mode->encap type to call the correct adjustment helper. Before: text data bss dec filename 157303116937008
4046908 26714227 vmlinux After: 157304286937008
4046908 26714344 vmlinux (about 117 byte increase) v2: use family from x->outer_mode, not inner Signed-off-by: Florian Westphal <fw@strlen.de> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
This commit is contained in:
parent
0c620e97b3
commit
303c5fab12
@ -454,11 +454,6 @@ struct xfrm_mode {
|
|||||||
*/
|
*/
|
||||||
struct sk_buff *(*gso_segment)(struct xfrm_state *x, struct sk_buff *skb, netdev_features_t features);
|
struct sk_buff *(*gso_segment)(struct xfrm_state *x, struct sk_buff *skb, netdev_features_t features);
|
||||||
|
|
||||||
/*
|
|
||||||
* Adjust pointers into the packet when IPsec is done at layer2.
|
|
||||||
*/
|
|
||||||
void (*xmit)(struct xfrm_state *x, struct sk_buff *skb);
|
|
||||||
|
|
||||||
struct xfrm_state_afinfo *afinfo;
|
struct xfrm_state_afinfo *afinfo;
|
||||||
struct module *owner;
|
struct module *owner;
|
||||||
u8 encap;
|
u8 encap;
|
||||||
|
@ -30,22 +30,8 @@ static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
|
|||||||
return segs;
|
return segs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xfrm4_transport_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
|
||||||
{
|
|
||||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
|
||||||
|
|
||||||
skb_reset_mac_len(skb);
|
|
||||||
pskb_pull(skb, skb->mac_len + sizeof(struct iphdr) + x->props.header_len);
|
|
||||||
|
|
||||||
if (xo->flags & XFRM_GSO_SEGMENT) {
|
|
||||||
skb_reset_transport_header(skb);
|
|
||||||
skb->transport_header -= x->props.header_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct xfrm_mode xfrm4_transport_mode = {
|
static struct xfrm_mode xfrm4_transport_mode = {
|
||||||
.gso_segment = xfrm4_transport_gso_segment,
|
.gso_segment = xfrm4_transport_gso_segment,
|
||||||
.xmit = xfrm4_transport_xmit,
|
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.encap = XFRM_MODE_TRANSPORT,
|
.encap = XFRM_MODE_TRANSPORT,
|
||||||
.family = AF_INET,
|
.family = AF_INET,
|
||||||
|
@ -109,23 +109,10 @@ static struct sk_buff *xfrm4_mode_tunnel_gso_segment(struct xfrm_state *x,
|
|||||||
return skb_mac_gso_segment(skb, features);
|
return skb_mac_gso_segment(skb, features);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xfrm4_mode_tunnel_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
|
||||||
{
|
|
||||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
|
||||||
|
|
||||||
if (xo->flags & XFRM_GSO_SEGMENT)
|
|
||||||
skb->transport_header = skb->network_header +
|
|
||||||
sizeof(struct iphdr);
|
|
||||||
|
|
||||||
skb_reset_mac_len(skb);
|
|
||||||
pskb_pull(skb, skb->mac_len + x->props.header_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct xfrm_mode xfrm4_tunnel_mode = {
|
static struct xfrm_mode xfrm4_tunnel_mode = {
|
||||||
.input2 = xfrm4_mode_tunnel_input,
|
.input2 = xfrm4_mode_tunnel_input,
|
||||||
.output2 = xfrm4_mode_tunnel_output,
|
.output2 = xfrm4_mode_tunnel_output,
|
||||||
.gso_segment = xfrm4_mode_tunnel_gso_segment,
|
.gso_segment = xfrm4_mode_tunnel_gso_segment,
|
||||||
.xmit = xfrm4_mode_tunnel_xmit,
|
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.encap = XFRM_MODE_TUNNEL,
|
.encap = XFRM_MODE_TUNNEL,
|
||||||
.flags = XFRM_MODE_FLAG_TUNNEL,
|
.flags = XFRM_MODE_FLAG_TUNNEL,
|
||||||
|
@ -31,22 +31,8 @@ static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
|
|||||||
return segs;
|
return segs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xfrm6_transport_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
|
||||||
{
|
|
||||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
|
||||||
|
|
||||||
skb_reset_mac_len(skb);
|
|
||||||
pskb_pull(skb, skb->mac_len + sizeof(struct ipv6hdr) + x->props.header_len);
|
|
||||||
|
|
||||||
if (xo->flags & XFRM_GSO_SEGMENT) {
|
|
||||||
skb_reset_transport_header(skb);
|
|
||||||
skb->transport_header -= x->props.header_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct xfrm_mode xfrm6_transport_mode = {
|
static struct xfrm_mode xfrm6_transport_mode = {
|
||||||
.gso_segment = xfrm4_transport_gso_segment,
|
.gso_segment = xfrm4_transport_gso_segment,
|
||||||
.xmit = xfrm6_transport_xmit,
|
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.encap = XFRM_MODE_TRANSPORT,
|
.encap = XFRM_MODE_TRANSPORT,
|
||||||
.family = AF_INET6,
|
.family = AF_INET6,
|
||||||
|
@ -109,22 +109,10 @@ static struct sk_buff *xfrm6_mode_tunnel_gso_segment(struct xfrm_state *x,
|
|||||||
return skb_mac_gso_segment(skb, features);
|
return skb_mac_gso_segment(skb, features);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xfrm6_mode_tunnel_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
|
||||||
{
|
|
||||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
|
||||||
|
|
||||||
if (xo->flags & XFRM_GSO_SEGMENT)
|
|
||||||
skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
|
|
||||||
|
|
||||||
skb_reset_mac_len(skb);
|
|
||||||
pskb_pull(skb, skb->mac_len + x->props.header_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct xfrm_mode xfrm6_tunnel_mode = {
|
static struct xfrm_mode xfrm6_tunnel_mode = {
|
||||||
.input2 = xfrm6_mode_tunnel_input,
|
.input2 = xfrm6_mode_tunnel_input,
|
||||||
.output2 = xfrm6_mode_tunnel_output,
|
.output2 = xfrm6_mode_tunnel_output,
|
||||||
.gso_segment = xfrm6_mode_tunnel_gso_segment,
|
.gso_segment = xfrm6_mode_tunnel_gso_segment,
|
||||||
.xmit = xfrm6_mode_tunnel_xmit,
|
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.encap = XFRM_MODE_TUNNEL,
|
.encap = XFRM_MODE_TUNNEL,
|
||||||
.flags = XFRM_MODE_FLAG_TUNNEL,
|
.flags = XFRM_MODE_FLAG_TUNNEL,
|
||||||
|
@ -23,6 +23,60 @@
|
|||||||
#include <linux/notifier.h>
|
#include <linux/notifier.h>
|
||||||
|
|
||||||
#ifdef CONFIG_XFRM_OFFLOAD
|
#ifdef CONFIG_XFRM_OFFLOAD
|
||||||
|
static void __xfrm_transport_prep(struct xfrm_state *x, struct sk_buff *skb,
|
||||||
|
unsigned int hsize)
|
||||||
|
{
|
||||||
|
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||||
|
|
||||||
|
skb_reset_mac_len(skb);
|
||||||
|
pskb_pull(skb, skb->mac_len + hsize + x->props.header_len);
|
||||||
|
|
||||||
|
if (xo->flags & XFRM_GSO_SEGMENT) {
|
||||||
|
skb_reset_transport_header(skb);
|
||||||
|
skb->transport_header -= x->props.header_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __xfrm_mode_tunnel_prep(struct xfrm_state *x, struct sk_buff *skb,
|
||||||
|
unsigned int hsize)
|
||||||
|
|
||||||
|
{
|
||||||
|
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||||
|
|
||||||
|
if (xo->flags & XFRM_GSO_SEGMENT)
|
||||||
|
skb->transport_header = skb->network_header + hsize;
|
||||||
|
|
||||||
|
skb_reset_mac_len(skb);
|
||||||
|
pskb_pull(skb, skb->mac_len + x->props.header_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adjust pointers into the packet when IPsec is done at layer2 */
|
||||||
|
static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
|
||||||
|
{
|
||||||
|
switch (x->outer_mode->encap) {
|
||||||
|
case XFRM_MODE_TUNNEL:
|
||||||
|
if (x->outer_mode->family == AF_INET)
|
||||||
|
return __xfrm_mode_tunnel_prep(x, skb,
|
||||||
|
sizeof(struct iphdr));
|
||||||
|
if (x->outer_mode->family == AF_INET6)
|
||||||
|
return __xfrm_mode_tunnel_prep(x, skb,
|
||||||
|
sizeof(struct ipv6hdr));
|
||||||
|
break;
|
||||||
|
case XFRM_MODE_TRANSPORT:
|
||||||
|
if (x->outer_mode->family == AF_INET)
|
||||||
|
return __xfrm_transport_prep(x, skb,
|
||||||
|
sizeof(struct iphdr));
|
||||||
|
if (x->outer_mode->family == AF_INET6)
|
||||||
|
return __xfrm_transport_prep(x, skb,
|
||||||
|
sizeof(struct ipv6hdr));
|
||||||
|
break;
|
||||||
|
case XFRM_MODE_ROUTEOPTIMIZATION:
|
||||||
|
case XFRM_MODE_IN_TRIGGER:
|
||||||
|
case XFRM_MODE_BEET:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features, bool *again)
|
struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features, bool *again)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -79,7 +133,7 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featur
|
|||||||
|
|
||||||
if (!skb->next) {
|
if (!skb->next) {
|
||||||
esp_features |= skb->dev->gso_partial_features;
|
esp_features |= skb->dev->gso_partial_features;
|
||||||
x->outer_mode->xmit(x, skb);
|
xfrm_outer_mode_prep(x, skb);
|
||||||
|
|
||||||
xo->flags |= XFRM_DEV_RESUME;
|
xo->flags |= XFRM_DEV_RESUME;
|
||||||
|
|
||||||
@ -109,7 +163,7 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featur
|
|||||||
xo = xfrm_offload(skb2);
|
xo = xfrm_offload(skb2);
|
||||||
xo->flags |= XFRM_DEV_RESUME;
|
xo->flags |= XFRM_DEV_RESUME;
|
||||||
|
|
||||||
x->outer_mode->xmit(x, skb2);
|
xfrm_outer_mode_prep(x, skb2);
|
||||||
|
|
||||||
err = x->type_offload->xmit(x, skb2, esp_features);
|
err = x->type_offload->xmit(x, skb2, esp_features);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user