Skip to content

Commit

Permalink
net: ipv4: avoid repeated calls to ip_skb_dst_mtu helper
Browse files Browse the repository at this point in the history
ip_skb_dst_mtu is small inline helper, but its called in several places.

before: 17061      44       0   17105    42d1 net/ipv4/ip_output.o
after:  16805      44       0   16849    41d1 net/ipv4/ip_output.o

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Florian Westphal authored and David S. Miller committed May 27, 2015
1 parent 8c0ce77 commit c5501eb
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ int sysctl_ip_default_ttl __read_mostly = IPDEFTTL;
EXPORT_SYMBOL(sysctl_ip_default_ttl);

static int ip_fragment(struct sock *sk, struct sk_buff *skb,
unsigned int mtu,
int (*output)(struct sock *, struct sk_buff *));

/* Generate a checksum for an outgoing IP datagram. */
Expand Down Expand Up @@ -219,15 +220,16 @@ static inline int ip_finish_output2(struct sock *sk, struct sk_buff *skb)
return -EINVAL;
}

static int ip_finish_output_gso(struct sock *sk, struct sk_buff *skb)
static int ip_finish_output_gso(struct sock *sk, struct sk_buff *skb,
unsigned int mtu)
{
netdev_features_t features;
struct sk_buff *segs;
int ret = 0;

/* common case: locally created skb or seglen is <= mtu */
if (((IPCB(skb)->flags & IPSKB_FORWARDED) == 0) ||
skb_gso_network_seglen(skb) <= ip_skb_dst_mtu(skb))
skb_gso_network_seglen(skb) <= mtu)
return ip_finish_output2(sk, skb);

/* Slowpath - GSO segment length is exceeding the dst MTU.
Expand All @@ -251,7 +253,7 @@ static int ip_finish_output_gso(struct sock *sk, struct sk_buff *skb)
int err;

segs->next = NULL;
err = ip_fragment(sk, segs, ip_finish_output2);
err = ip_fragment(sk, segs, mtu, ip_finish_output2);

if (err && ret == 0)
ret = err;
Expand All @@ -263,18 +265,21 @@ static int ip_finish_output_gso(struct sock *sk, struct sk_buff *skb)

static int ip_finish_output(struct sock *sk, struct sk_buff *skb)
{
unsigned int mtu;

#if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM)
/* Policy lookup after SNAT yielded a new policy */
if (skb_dst(skb)->xfrm) {
IPCB(skb)->flags |= IPSKB_REROUTED;
return dst_output_sk(sk, skb);
}
#endif
mtu = ip_skb_dst_mtu(skb);
if (skb_is_gso(skb))
return ip_finish_output_gso(sk, skb);
return ip_finish_output_gso(sk, skb, mtu);

if (skb->len > ip_skb_dst_mtu(skb))
return ip_fragment(sk, skb, ip_finish_output2);
if (skb->len > mtu)
return ip_fragment(sk, skb, mtu, ip_finish_output2);

return ip_finish_output2(sk, skb);
}
Expand Down Expand Up @@ -482,10 +487,10 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)
}

static int ip_fragment(struct sock *sk, struct sk_buff *skb,
unsigned int mtu,
int (*output)(struct sock *, struct sk_buff *))
{
struct iphdr *iph = ip_hdr(skb);
unsigned int mtu = ip_skb_dst_mtu(skb);

if (unlikely(((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) ||
(IPCB(skb)->frag_max_size &&
Expand Down

0 comments on commit c5501eb

Please sign in to comment.