Skip to content

Commit 77589ce

Browse files
ebiedermdavem330
authored andcommitted
ipv4: Cache net in ip_build_and_send_pkt and ip_queue_xmit
Compute net and store it in a variable in the functions ip_build_and_send_pkt and ip_queue_xmit so that it does not need to be recomputed next time it is needed. Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f859b0f commit 77589ce

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

net/ipv4/ip_output.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
139139
{
140140
struct inet_sock *inet = inet_sk(sk);
141141
struct rtable *rt = skb_rtable(skb);
142+
struct net *net = sock_net(sk);
142143
struct iphdr *iph;
143144

144145
/* Build the IP header. */
@@ -157,7 +158,7 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
157158
iph->id = 0;
158159
} else {
159160
iph->frag_off = 0;
160-
__ip_select_ident(sock_net(sk), iph, 1);
161+
__ip_select_ident(net, iph, 1);
161162
}
162163

163164
if (opt && opt->opt.optlen) {
@@ -382,6 +383,7 @@ static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4)
382383
int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
383384
{
384385
struct inet_sock *inet = inet_sk(sk);
386+
struct net *net = sock_net(sk);
385387
struct ip_options_rcu *inet_opt;
386388
struct flowi4 *fl4;
387389
struct rtable *rt;
@@ -412,7 +414,7 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
412414
* keep trying until route appears or the connection times
413415
* itself out.
414416
*/
415-
rt = ip_route_output_ports(sock_net(sk), fl4, sk,
417+
rt = ip_route_output_ports(net, fl4, sk,
416418
daddr, inet->inet_saddr,
417419
inet->inet_dport,
418420
inet->inet_sport,
@@ -449,7 +451,7 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
449451
ip_options_build(skb, &inet_opt->opt, inet->inet_daddr, rt, 0);
450452
}
451453

452-
ip_select_ident_segs(sock_net(sk), skb, sk,
454+
ip_select_ident_segs(net, skb, sk,
453455
skb_shinfo(skb)->gso_segs ?: 1);
454456

455457
/* TODO : should we use skb->sk here instead of sk ? */
@@ -462,7 +464,7 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
462464

463465
no_route:
464466
rcu_read_unlock();
465-
IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
467+
IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
466468
kfree_skb(skb);
467469
return -EHOSTUNREACH;
468470
}

0 commit comments

Comments
 (0)