Skip to content

Commit 1de7083

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: remove output2 indirection from xfrm_mode
similar to previous patch: no external module dependencies, so we can avoid the indirection by placing this in the core. This change removes the last indirection from xfrm_mode and the xfrm4|6_mode_{beet,tunnel}.c modules contain (almost) no code anymore. Before: text data bss dec hex filename 3957 136 0 4093 ffd net/xfrm/xfrm_output.o 587 44 0 631 277 net/ipv4/xfrm4_mode_beet.o 649 32 0 681 2a9 net/ipv4/xfrm4_mode_tunnel.o 625 44 0 669 29d net/ipv6/xfrm6_mode_beet.o 599 32 0 631 277 net/ipv6/xfrm6_mode_tunnel.o After: text data bss dec hex filename 5359 184 0 5543 15a7 net/xfrm/xfrm_output.o 171 24 0 195 c3 net/ipv4/xfrm4_mode_beet.o 171 24 0 195 c3 net/ipv4/xfrm4_mode_tunnel.o 172 24 0 196 c4 net/ipv6/xfrm6_mode_beet.o 172 24 0 196 c4 net/ipv6/xfrm6_mode_tunnel.o v2: fold the *encap_add functions into xfrm*_prepare_output preserve (move) output2 comment (Sabrina) use x->outer_mode->encap, not inner fix a build breakage on ppc (kbuild robot) Signed-off-by: Florian Westphal <fw@strlen.de> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent b3284df commit 1de7083

File tree

6 files changed

+207
-224
lines changed

6 files changed

+207
-224
lines changed

include/net/xfrm.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -423,19 +423,6 @@ int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned sh
423423
int xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
424424

425425
struct xfrm_mode {
426-
/*
427-
* Add encapsulation header.
428-
*
429-
* On exit, the transport header will be set to the start of the
430-
* encapsulation header to be filled in by x->type->output and
431-
* the mac header will be set to the nextheader (protocol for
432-
* IPv4) field of the extension header directly preceding the
433-
* encapsulation header, or in its absence, that of the top IP
434-
* header. The value of the network header will always point
435-
* to the top IP header while skb->data will point to the payload.
436-
*/
437-
int (*output2)(struct xfrm_state *x,struct sk_buff *skb);
438-
439426
struct xfrm_state_afinfo *afinfo;
440427
struct module *owner;
441428
u8 encap;

net/ipv4/xfrm4_mode_beet.c

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -17,71 +17,8 @@
1717
#include <net/ip.h>
1818
#include <net/xfrm.h>
1919

20-
static void xfrm4_beet_make_header(struct sk_buff *skb)
21-
{
22-
struct iphdr *iph = ip_hdr(skb);
23-
24-
iph->ihl = 5;
25-
iph->version = 4;
26-
27-
iph->protocol = XFRM_MODE_SKB_CB(skb)->protocol;
28-
iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
29-
30-
iph->id = XFRM_MODE_SKB_CB(skb)->id;
31-
iph->frag_off = XFRM_MODE_SKB_CB(skb)->frag_off;
32-
iph->ttl = XFRM_MODE_SKB_CB(skb)->ttl;
33-
}
34-
35-
/* Add encapsulation header.
36-
*
37-
* The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
38-
*/
39-
static int xfrm4_beet_output(struct xfrm_state *x, struct sk_buff *skb)
40-
{
41-
struct ip_beet_phdr *ph;
42-
struct iphdr *top_iph;
43-
int hdrlen, optlen;
44-
45-
hdrlen = 0;
46-
optlen = XFRM_MODE_SKB_CB(skb)->optlen;
47-
if (unlikely(optlen))
48-
hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4);
49-
50-
skb_set_network_header(skb, -x->props.header_len -
51-
hdrlen + (XFRM_MODE_SKB_CB(skb)->ihl - sizeof(*top_iph)));
52-
if (x->sel.family != AF_INET6)
53-
skb->network_header += IPV4_BEET_PHMAXLEN;
54-
skb->mac_header = skb->network_header +
55-
offsetof(struct iphdr, protocol);
56-
skb->transport_header = skb->network_header + sizeof(*top_iph);
57-
58-
xfrm4_beet_make_header(skb);
59-
60-
ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdrlen);
61-
62-
top_iph = ip_hdr(skb);
63-
64-
if (unlikely(optlen)) {
65-
BUG_ON(optlen < 0);
66-
67-
ph->padlen = 4 - (optlen & 4);
68-
ph->hdrlen = optlen / 8;
69-
ph->nexthdr = top_iph->protocol;
70-
if (ph->padlen)
71-
memset(ph + 1, IPOPT_NOP, ph->padlen);
72-
73-
top_iph->protocol = IPPROTO_BEETPH;
74-
top_iph->ihl = sizeof(struct iphdr) / 4;
75-
}
76-
77-
top_iph->saddr = x->props.saddr.a4;
78-
top_iph->daddr = x->id.daddr.a4;
79-
80-
return 0;
81-
}
8220

8321
static struct xfrm_mode xfrm4_beet_mode = {
84-
.output2 = xfrm4_beet_output,
8522
.owner = THIS_MODULE,
8623
.encap = XFRM_MODE_BEET,
8724
.flags = XFRM_MODE_FLAG_TUNNEL,

net/ipv4/xfrm4_mode_tunnel.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,7 @@
1515
#include <net/ip.h>
1616
#include <net/xfrm.h>
1717

18-
/* Add encapsulation header.
19-
*
20-
* The top IP header will be constructed per RFC 2401.
21-
*/
22-
static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
23-
{
24-
struct dst_entry *dst = skb_dst(skb);
25-
struct iphdr *top_iph;
26-
int flags;
27-
28-
skb_set_inner_network_header(skb, skb_network_offset(skb));
29-
skb_set_inner_transport_header(skb, skb_transport_offset(skb));
30-
31-
skb_set_network_header(skb, -x->props.header_len);
32-
skb->mac_header = skb->network_header +
33-
offsetof(struct iphdr, protocol);
34-
skb->transport_header = skb->network_header + sizeof(*top_iph);
35-
top_iph = ip_hdr(skb);
36-
37-
top_iph->ihl = 5;
38-
top_iph->version = 4;
39-
40-
top_iph->protocol = xfrm_af2proto(skb_dst(skb)->ops->family);
41-
42-
/* DS disclosing depends on XFRM_SA_XFLAG_DONT_ENCAP_DSCP */
43-
if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
44-
top_iph->tos = 0;
45-
else
46-
top_iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
47-
top_iph->tos = INET_ECN_encapsulate(top_iph->tos,
48-
XFRM_MODE_SKB_CB(skb)->tos);
49-
50-
flags = x->props.flags;
51-
if (flags & XFRM_STATE_NOECN)
52-
IP_ECN_clear(top_iph);
53-
54-
top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
55-
0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
56-
57-
top_iph->ttl = ip4_dst_hoplimit(xfrm_dst_child(dst));
58-
59-
top_iph->saddr = x->props.saddr.a4;
60-
top_iph->daddr = x->id.daddr.a4;
61-
ip_select_ident(dev_net(dst->dev), skb, NULL);
62-
63-
return 0;
64-
}
65-
6618
static struct xfrm_mode xfrm4_tunnel_mode = {
67-
.output2 = xfrm4_mode_tunnel_output,
6819
.owner = THIS_MODULE,
6920
.encap = XFRM_MODE_TUNNEL,
7021
.flags = XFRM_MODE_FLAG_TUNNEL,

net/ipv6/xfrm6_mode_beet.c

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,65 +19,7 @@
1919
#include <net/ipv6.h>
2020
#include <net/xfrm.h>
2121

22-
static void xfrm6_beet_make_header(struct sk_buff *skb)
23-
{
24-
struct ipv6hdr *iph = ipv6_hdr(skb);
25-
26-
iph->version = 6;
27-
28-
memcpy(iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
29-
sizeof(iph->flow_lbl));
30-
iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol;
31-
32-
ipv6_change_dsfield(iph, 0, XFRM_MODE_SKB_CB(skb)->tos);
33-
iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl;
34-
}
35-
36-
/* Add encapsulation header.
37-
*
38-
* The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
39-
*/
40-
static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
41-
{
42-
struct ipv6hdr *top_iph;
43-
struct ip_beet_phdr *ph;
44-
int optlen, hdr_len;
45-
46-
hdr_len = 0;
47-
optlen = XFRM_MODE_SKB_CB(skb)->optlen;
48-
if (unlikely(optlen))
49-
hdr_len += IPV4_BEET_PHMAXLEN - (optlen & 4);
50-
51-
skb_set_network_header(skb, -x->props.header_len - hdr_len);
52-
if (x->sel.family != AF_INET6)
53-
skb->network_header += IPV4_BEET_PHMAXLEN;
54-
skb->mac_header = skb->network_header +
55-
offsetof(struct ipv6hdr, nexthdr);
56-
skb->transport_header = skb->network_header + sizeof(*top_iph);
57-
ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdr_len);
58-
59-
xfrm6_beet_make_header(skb);
60-
61-
top_iph = ipv6_hdr(skb);
62-
if (unlikely(optlen)) {
63-
64-
BUG_ON(optlen < 0);
65-
66-
ph->padlen = 4 - (optlen & 4);
67-
ph->hdrlen = optlen / 8;
68-
ph->nexthdr = top_iph->nexthdr;
69-
if (ph->padlen)
70-
memset(ph + 1, IPOPT_NOP, ph->padlen);
71-
72-
top_iph->nexthdr = IPPROTO_BEETPH;
73-
}
74-
75-
top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
76-
top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
77-
return 0;
78-
}
7922
static struct xfrm_mode xfrm6_beet_mode = {
80-
.output2 = xfrm6_beet_output,
8123
.owner = THIS_MODULE,
8224
.encap = XFRM_MODE_BEET,
8325
.flags = XFRM_MODE_FLAG_TUNNEL,

net/ipv6/xfrm6_mode_tunnel.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,7 @@
2222
*
2323
* The top IP header will be constructed per RFC 2401.
2424
*/
25-
static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
26-
{
27-
struct dst_entry *dst = skb_dst(skb);
28-
struct ipv6hdr *top_iph;
29-
int dsfield;
30-
31-
skb_set_inner_network_header(skb, skb_network_offset(skb));
32-
skb_set_inner_transport_header(skb, skb_transport_offset(skb));
33-
34-
skb_set_network_header(skb, -x->props.header_len);
35-
skb->mac_header = skb->network_header +
36-
offsetof(struct ipv6hdr, nexthdr);
37-
skb->transport_header = skb->network_header + sizeof(*top_iph);
38-
top_iph = ipv6_hdr(skb);
39-
40-
top_iph->version = 6;
41-
42-
memcpy(top_iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
43-
sizeof(top_iph->flow_lbl));
44-
top_iph->nexthdr = xfrm_af2proto(skb_dst(skb)->ops->family);
45-
46-
if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
47-
dsfield = 0;
48-
else
49-
dsfield = XFRM_MODE_SKB_CB(skb)->tos;
50-
dsfield = INET_ECN_encapsulate(dsfield, XFRM_MODE_SKB_CB(skb)->tos);
51-
if (x->props.flags & XFRM_STATE_NOECN)
52-
dsfield &= ~INET_ECN_MASK;
53-
ipv6_change_dsfield(top_iph, 0, dsfield);
54-
top_iph->hop_limit = ip6_dst_hoplimit(xfrm_dst_child(dst));
55-
top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
56-
top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
57-
return 0;
58-
}
59-
6025
static struct xfrm_mode xfrm6_tunnel_mode = {
61-
.output2 = xfrm6_mode_tunnel_output,
6226
.owner = THIS_MODULE,
6327
.encap = XFRM_MODE_TUNNEL,
6428
.flags = XFRM_MODE_FLAG_TUNNEL,

0 commit comments

Comments
 (0)