Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9500d7b authored by Florian Westphal's avatar Florian Westphal Committed by Steffen Klassert
Browse files

xfrm: store xfrm_mode directly, not its address



This structure is now only 4 bytes, so its more efficient
to cache a copy rather than its address.

No significant size difference in allmodconfig vmlinux.

With non-modular kernel that has all XFRM options enabled, this
series reduces vmlinux image size by ~11kb. All xfrm_mode
indirections are gone and all modes are built-in.

before (ipsec-next master):
    text      data      bss         dec   filename
21071494   7233140 11104324    39408958   vmlinux.master

after this series:
21066448   7226772 11104324    39397544   vmlinux.patched

With allmodconfig kernel, the size increase is only 362 bytes,
even all the xfrm config options removed in this series are
modular.

before:
    text      data     bss      dec   filename
15731286   6936912 4046908 26715106   vmlinux.master

after this series:
15731492   6937068  4046908  26715468 vmlinux

Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Reviewed-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
parent 4c145dce
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -132,6 +132,17 @@ struct xfrm_state_offload {
	u8			flags;
};

struct xfrm_mode {
	u8 encap;
	u8 family;
	u8 flags;
};

/* Flags for xfrm_mode. */
enum {
	XFRM_MODE_FLAG_TUNNEL = 1,
};

/* Full description of state of transformer. */
struct xfrm_state {
	possible_net_t		xs_net;
@@ -234,9 +245,9 @@ struct xfrm_state {
	/* Reference to data common to all the instances of this
	 * transformer. */
	const struct xfrm_type	*type;
	const struct xfrm_mode	*inner_mode;
	const struct xfrm_mode	*inner_mode_iaf;
	const struct xfrm_mode	*outer_mode;
	struct xfrm_mode	inner_mode;
	struct xfrm_mode	inner_mode_iaf;
	struct xfrm_mode	outer_mode;

	const struct xfrm_type_offload	*type_offload;

@@ -421,17 +432,6 @@ struct xfrm_type_offload {
int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
int xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);

struct xfrm_mode {
	u8 encap;
	u8 family;
	u8 flags;
};

/* Flags for xfrm_mode. */
enum {
	XFRM_MODE_FLAG_TUNNEL = 1,
};

static inline int xfrm_af2proto(unsigned int family)
{
	switch(family) {
@@ -448,9 +448,9 @@ static inline const struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, i
{
	if ((ipproto == IPPROTO_IPIP && x->props.family == AF_INET) ||
	    (ipproto == IPPROTO_IPV6 && x->props.family == AF_INET6))
		return x->inner_mode;
		return &x->inner_mode;
	else
		return x->inner_mode_iaf;
		return &x->inner_mode_iaf;
}

struct xfrm_tmpl {
@@ -1990,7 +1990,7 @@ static inline int xfrm_tunnel_check(struct sk_buff *skb, struct xfrm_state *x,
			tunnel = true;
		break;
	}
	if (tunnel && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL))
	if (tunnel && !(x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL))
		return -EINVAL;

	return 0;
+1 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
						    struct sk_buff *skb,
						    netdev_features_t features)
{
	switch (x->outer_mode->encap) {
	switch (x->outer_mode.encap) {
	case XFRM_MODE_TUNNEL:
		return xfrm4_tunnel_gso_segment(x, skb, features);
	case XFRM_MODE_TRANSPORT:
+1 −1
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)

	x = xfrm_input_state(skb);

	inner_mode = x->inner_mode;
	inner_mode = &x->inner_mode;

	if (x->sel.family == AF_UNSPEC) {
		inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
#endif

	rcu_read_lock();
	afinfo = xfrm_state_afinfo_get_rcu(x->outer_mode->family);
	afinfo = xfrm_state_afinfo_get_rcu(x->outer_mode.family);
	if (likely(afinfo))
		ret = afinfo->output_finish(sk, skb);
	else
+1 −1
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ static struct sk_buff *xfrm6_outer_mode_gso_segment(struct xfrm_state *x,
						    struct sk_buff *skb,
						    netdev_features_t features)
{
	switch (x->outer_mode->encap) {
	switch (x->outer_mode.encap) {
	case XFRM_MODE_TUNNEL:
		return xfrm6_tunnel_gso_segment(x, skb, features);
	case XFRM_MODE_TRANSPORT:
Loading