diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-11-30 14:00:53 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-12-01 13:28:54 -0500 |
commit | 84f9307c5da84a7c8513e7607dc8427d2cbd63e3 (patch) | |
tree | f34fb0525284d97e2b10870afd8e021cc45ef44c | |
parent | 898f73585bbe4bdbb471636ecdede071f7473e51 (diff) |
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.
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 a09447749e2d..9192d690b562 100644 --- a/include/net/flow.h +++ b/include/net/flow.h | |||
@@ -59,8 +59,11 @@ struct flowi4 { | |||
59 | #define flowi4_proto __fl_common.flowic_proto | 59 | #define flowi4_proto __fl_common.flowic_proto |
60 | #define flowi4_flags __fl_common.flowic_flags | 60 | #define flowi4_flags __fl_common.flowic_flags |
61 | #define flowi4_secid __fl_common.flowic_secid | 61 | #define flowi4_secid __fl_common.flowic_secid |
62 | __be32 daddr; | 62 | |
63 | /* (saddr,daddr) must be grouped, same order as in IP header */ | ||
63 | __be32 saddr; | 64 | __be32 saddr; |
65 | __be32 daddr; | ||
66 | |||
64 | union flowi_uli uli; | 67 | union flowi_uli uli; |
65 | #define fl4_sport uli.ports.sport | 68 | #define fl4_sport uli.ports.sport |
66 | #define fl4_dport uli.ports.dport | 69 | #define fl4_dport uli.ports.dport |
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 0bc95f3977d2..0d5e5672f3d1 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c | |||
@@ -319,6 +319,20 @@ int ip_output(struct sk_buff *skb) | |||
319 | !(IPCB(skb)->flags & IPSKB_REROUTED)); | 319 | !(IPCB(skb)->flags & IPSKB_REROUTED)); |
320 | } | 320 | } |
321 | 321 | ||
322 | /* | ||
323 | * copy saddr and daddr, possibly using 64bit load/stores | ||
324 | * Equivalent to : | ||
325 | * iph->saddr = fl4->saddr; | ||
326 | * iph->daddr = fl4->daddr; | ||
327 | */ | ||
328 | static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4) | ||
329 | { | ||
330 | BUILD_BUG_ON(offsetof(typeof(*fl4), daddr) != | ||
331 | offsetof(typeof(*fl4), saddr) + sizeof(fl4->saddr)); | ||
332 | memcpy(&iph->saddr, &fl4->saddr, | ||
333 | sizeof(fl4->saddr) + sizeof(fl4->daddr)); | ||
334 | } | ||
335 | |||
322 | int ip_queue_xmit(struct sk_buff *skb, struct flowi *fl) | 336 | int ip_queue_xmit(struct sk_buff *skb, struct flowi *fl) |
323 | { | 337 | { |
324 | struct sock *sk = skb->sk; | 338 | struct sock *sk = skb->sk; |
@@ -381,8 +395,8 @@ packet_routed: | |||
381 | iph->frag_off = 0; | 395 | iph->frag_off = 0; |
382 | iph->ttl = ip_select_ttl(inet, &rt->dst); | 396 | iph->ttl = ip_select_ttl(inet, &rt->dst); |
383 | iph->protocol = sk->sk_protocol; | 397 | iph->protocol = sk->sk_protocol; |
384 | iph->saddr = fl4->saddr; | 398 | ip_copy_addrs(iph, fl4); |
385 | iph->daddr = fl4->daddr; | 399 | |
386 | /* Transport layer set skb->h.foo itself. */ | 400 | /* Transport layer set skb->h.foo itself. */ |
387 | 401 | ||
388 | if (inet_opt && inet_opt->opt.optlen) { | 402 | if (inet_opt && inet_opt->opt.optlen) { |
@@ -1337,8 +1351,7 @@ struct sk_buff *__ip_make_skb(struct sock *sk, | |||
1337 | ip_select_ident(iph, &rt->dst, sk); | 1351 | ip_select_ident(iph, &rt->dst, sk); |
1338 | iph->ttl = ttl; | 1352 | iph->ttl = ttl; |
1339 | iph->protocol = sk->sk_protocol; | 1353 | iph->protocol = sk->sk_protocol; |
1340 | iph->saddr = fl4->saddr; | 1354 | ip_copy_addrs(iph, fl4); |
1341 | iph->daddr = fl4->daddr; | ||
1342 | 1355 | ||
1343 | if (opt) { | 1356 | if (opt) { |
1344 | iph->ihl += opt->optlen>>2; | 1357 | iph->ihl += opt->optlen>>2; |