From adabd647b1d0421f961b5cc3808128001facb9bd Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Fri, 11 Sep 2009 11:05:54 +0200 Subject: [PATCH 1/2] psd: use skb_header_pointer Do not rely on tcphdr being in the linear area. Signed-off-by: Florian Westphal --- extensions/xt_psd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extensions/xt_psd.c b/extensions/xt_psd.c index f12e5cf..23b5e91 100644 --- a/extensions/xt_psd.c +++ b/extensions/xt_psd.c @@ -102,8 +102,9 @@ 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; @@ -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; From 342ccf62b2b5dafe07dbd3d82be08803eb6a00a2 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Fri, 11 Sep 2009 11:05:55 +0200 Subject: [PATCH 2/2] psd: byteswap constant value instead htons(CONSTANT) is computed at compile time. reduces .text by 4 bytes on x86. Signed-off-by: Florian Westphal --- extensions/xt_psd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/xt_psd.c b/extensions/xt_psd.c index 23b5e91..605ed03 100644 --- a/extensions/xt_psd.c +++ b/extensions/xt_psd.c @@ -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; }