Skip to contentSkip to conversation

xt_psd: use skb_header_pointer

PATCH In review Florian Westphal 2 participants 3 messages Sep 11, 2009 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/2 xt_psd: use skb_header_pointer

From: Florian Westphal <[email protected]>

Don't rely on tcphdr being in the linear area.

---
 extensions/xt_psd.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
extensions/xt_psd.c +7 -4
index f12e5cf..b3de7e2 100644
@@ -102,11 +102,12 @@ static inline int hashfunc(struct in_addr addr)
 static bool
 xt_psd_match(const struct sk_buff *pskb, const struct xt_match_param *match)
 {
-	struct iphdr *iph;
-	struct tcphdr *tcph;
+	const struct iphdr *iph;
+	const struct tcphdr *tcph;
+	struct tcphdr _tcph;
 	struct in_addr addr;
 	u_int16_t src_port,dest_port;
-  	u_int8_t tcp_flags, proto;
+	u_int8_t tcp_flags, proto;
 	unsigned long now;
 	struct host *curr, *last, **head;
 	int hash, index, count;
@@ -134,7 +135,9 @@ xt_psd_match(const struct sk_buff *pskb, const struct xt_match_param *match)
 
 	addr.s_addr = iph->saddr;
 
-	tcph = (void *)iph + ip_hdrlen(pskb);
+	tcph = skb_header_pointer(pskb, match->thoff, sizeof(_tcph), &_tcph);
+	if (tcph == NULL)
+		return false;
 
 	/* Yep, it's dirty */
 	src_port = tcph->source;
Signature · 1 line
1.6.3.3
author maintainer
#1 lore raw

PATCH 2/2 xt_psd: byteswap constant value instead

From: Florian Westphal <[email protected]>

htons(CONSTANT) is computed at compile time.
reduces .text by 4 bytes on x86.

---
 extensions/xt_psd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
extensions/xt_psd.c +1 -1
index b3de7e2..03e81e2 100644
@@ -118,7 +118,7 @@ xt_psd_match(const struct sk_buff *pskb, const struct xt_match_param *match)
 	iph = ip_hdr(pskb);
 
 	/* Sanity check */
-	if (ntohs(iph->frag_off) & IP_OFFSET) {
+	if (iph->frag_off & htons(IP_OFFSET)) {
 		pr_debug("sanity check failed\n");
 		return false;
 	}
Signature · 1 line
1.6.3.3