Skip to contentSkip to conversation

ipv4: ip_forward: perform skb->pkt_type check at the beginning

PATCH Superseded Denis Kirjanov 3 participants 3 messages Feb 12, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: ip_forward: perform skb->pkt_type check at the beginning

Packets which have L2 address different from ours should be already filtered before entering into ip_forward().

Perform that check at the beginning to avoid processing such packets.

---
 net/ipv4/ip_forward.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/ip_forward.c +4 -3
index e9f1217..1a07056 100644
@@ -59,6 +59,10 @@ int ip_forward(struct sk_buff *skb)
 	struct rtable *rt;	/* Route we use */
 	struct ip_options *opt	= &(IPCB(skb)->opt);
 
+    /* that should never happen */
+    if (skb->pkt_type != PACKET_HOST)
+        goto drop;
+
 	if (skb_warn_if_lro(skb))
 		goto drop;
 
@@ -68,9 +72,6 @@ int ip_forward(struct sk_buff *skb)
 	if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb))
 		return NET_RX_SUCCESS;
 
-	if (skb->pkt_type != PACKET_HOST)
-		goto drop;
-
 	skb_forward_csum(skb);
 
 	/*
Signature · 1 line
1.8.3.2
#1 lore raw

Hello.

Quoted 15 lines · Denis Kirjanov

Packets which have L2 address different from ours should be already filtered before entering into ip_forward().

Perform that check at the beginning to avoid processing such packets.

---
  net/ipv4/ip_forward.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/ip_forward.c +0 -0
index e9f1217..1a07056 100644

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 65

Quoted 7 lines
net/ipv4/ip_forward.c +4 -0
@@ -59,6 +59,10 @@ int ip_forward(struct sk_buff *skb)
  	struct rtable *rt;	/* Route we use */
  	struct ip_options *opt	= &(IPCB(skb)->opt);
 
+    /* that should never happen */
+    if (skb->pkt_type != PACKET_HOST)
+        goto drop;
+

Please indent the code with tabs, not spaces.

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 73

Quoted 10 lines
net/ipv4/ip_forward.c +0 -3
  	if (skb_warn_if_lro(skb))
  		goto drop;
 
@@ -68,9 +72,6 @@ int ip_forward(struct sk_buff *skb)
  	if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb))
  		return NET_RX_SUCCESS;
 
-	if (skb->pkt_type != PACKET_HOST)
-		goto drop;
-

Like it was here.

WBR, Sergei

maintainer
#2 lore raw
In reply to Denis Kirjanov

From: Denis Kirjanov <[email protected]>
Date: Wed, 12 Feb 2014 12:10:32 +0400

net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 65

Quoted 4 lines
net/ipv4/ip_forward.c +4 -0
+    /* that should never happen */
+    if (skb->pkt_type != PACKET_HOST)
+        goto drop;
+

At a minimum, this is not formatted properly. You are using spaces instead of TAB characters.