diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-11-30 19:00:53 +0000 |
---|---|---|
committer | Ziyan <jaraidaniel@gmail.com> | 2016-03-11 15:57:04 +0100 |
commit | 921edcf001b259f8d61b9507a22f39af786c2f8e (patch) | |
tree | 7f6b1abcaed50654877faad3bd99f46470b65d8c | |
parent | 80607610d928c21da5b4ba3d8fded38f8ed80e9f (diff) | |
download | kernel_samsung_espresso10-921edcf001b259f8d61b9507a22f39af786c2f8e.zip kernel_samsung_espresso10-921edcf001b259f8d61b9507a22f39af786c2f8e.tar.gz kernel_samsung_espresso10-921edcf001b259f8d61b9507a22f39af786c2f8e.tar.bz2 |
ipv4: use a 64bit load/store in output path
gcc compiler is smart enough to use a single load/store if we
memcpy(dptr, sptr, 8) on x86_64, regardless of
CONFIG_CC_OPTIMIZE_FOR_SIZE
In IP header, daddr immediately follows saddr, this wont change in the
future. We only need to make sure our flowi4 (saddr,daddr) fields wont
break the rule.
Change-Id: Iad9c8fd9121ec84c2599b013badaebba92db7c39
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/flow.h | 5 | ||||
-rw-r--r-- | net/ipv4/ip_output.c | 21 |
2 files changed, 21 insertions, 5 deletions
diff --git a/include/net/flow.h b/include/net/flow.h index e37cfda..3a4e76e 100644 --- a/include/net/flow.h +++ b/include/net/flow.h @@ -59,8 +59,11 @@ struct flowi4 { #define flowi4_proto __fl_common.flowic_proto #define flowi4_flags __fl_common.flowic_flags #define flowi4_secid __fl_common.flowic_secid - __be32 daddr; + + /* (saddr,daddr) must be grouped, same order as in IP header */ __be32 saddr; + __be32 daddr; + union flowi_uli uli; #define fl4_sport uli.ports.sport #define fl4_dport uli.ports.dport diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 63e38cc..04444e2 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -326,6 +326,20 @@ int ip_output(struct sk_buff *skb) !(IPCB(skb)->flags & IPSKB_REROUTED)); } +/* + * copy saddr and daddr, possibly using 64bit load/stores + * Equivalent to : + * iph->saddr = fl4->saddr; + * iph->daddr = fl4->daddr; + */ +static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4) +{ + BUILD_BUG_ON(offsetof(typeof(*fl4), daddr) != + offsetof(typeof(*fl4), saddr) + sizeof(fl4->saddr)); + memcpy(&iph->saddr, &fl4->saddr, + sizeof(fl4->saddr) + sizeof(fl4->daddr)); +} + int ip_queue_xmit(struct sk_buff *skb, struct flowi *fl) { struct sock *sk = skb->sk; @@ -388,8 +402,8 @@ packet_routed: iph->frag_off = 0; iph->ttl = ip_select_ttl(inet, &rt->dst); iph->protocol = sk->sk_protocol; - iph->saddr = fl4->saddr; - iph->daddr = fl4->daddr; + ip_copy_addrs(iph, fl4); + /* Transport layer set skb->h.foo itself. */ if (inet_opt && inet_opt->opt.optlen) { @@ -1343,8 +1357,7 @@ struct sk_buff *__ip_make_skb(struct sock *sk, ip_select_ident(skb, &rt->dst, sk); iph->ttl = ttl; iph->protocol = sk->sk_protocol; - iph->saddr = fl4->saddr; - iph->daddr = fl4->daddr; + ip_copy_addrs(iph, fl4); if (opt) { iph->ihl += opt->optlen>>2; |