diff mbox series

[net-next,2/2] ipv6: replace ip_hdr() with skb->data for optimization

Message ID 1528200262-11834-2-git-send-email-laoar.shao@gmail.com
State Rejected, archived
Delegated to: David Miller
Headers show
Series [net-next,1/2] ipv4: replace ip_hdr() with skb->data for optimization | expand

Commit Message

Yafang Shao June 5, 2018, 12:04 p.m. UTC
In ipv6 receive path, when ip header hasn't been pulled yet, ip_hdr()
and skb->data are pointing to the same byte.

In ipv6 output path, when ip header is just pushed, ip_hdr() and skb->data
are pointing to the same byte.

As ip_hdr() is more expensive than using skb->data, so replace ip_hdr()
with skb->data in these situations for optimization.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 net/ipv6/ip6_input.c  | 4 ++--
 net/ipv6/ip6_output.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index f08d344..2ff4fe8 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -113,7 +113,7 @@  int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
 	if (unlikely(!pskb_may_pull(skb, sizeof(*hdr))))
 		goto err;
 
-	hdr = ipv6_hdr(skb);
+	hdr = (const struct ipv6hdr *)skb->data;
 
 	if (hdr->version != 6)
 		goto err;
@@ -189,7 +189,7 @@  int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
 			__IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
 			goto drop;
 		}
-		hdr = ipv6_hdr(skb);
+		hdr = (const struct ipv6hdr *)skb->data;
 	}
 
 	if (hdr->nexthdr == NEXTHDR_HOP) {
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 021e5ae..8bb3bc1 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -235,7 +235,7 @@  int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
 
 	skb_push(skb, sizeof(struct ipv6hdr));
 	skb_reset_network_header(skb);
-	hdr = ipv6_hdr(skb);
+	hdr = (struct ipv6hdr *)skb->data;
 
 	/*
 	 *	Fill in the IPv6 header
@@ -1659,7 +1659,7 @@  struct sk_buff *__ip6_make_skb(struct sock *sk,
 
 	skb_push(skb, sizeof(struct ipv6hdr));
 	skb_reset_network_header(skb);
-	hdr = ipv6_hdr(skb);
+	hdr = (struct ipv6hdr *)skb->data;
 
 	ip6_flow_hdr(hdr, v6_cork->tclass,
 		     ip6_make_flowlabel(net, skb, fl6->flowlabel,