diff options
author | Patrick McHardy <kaber@trash.net> | 2006-08-22 03:33:09 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-09-22 17:55:29 -0400 |
commit | da878c8e5aae3eeceeee7af8d52633d7bc125edf (patch) | |
tree | 27f67c9713e98919e5c38d6cc85a05e9485576e9 | |
parent | 1158ba27bec6d1a20999099a938908cf85f47640 (diff) |
[NETFILTER]: replace open coded checksum updates
Replace open coded checksum update by nf_csum_update calls and clean up
the surrounding code a bit.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/ipv4/netfilter/ipt_ECN.c | 22 | ||||
-rw-r--r-- | net/ipv4/netfilter/ipt_TOS.c | 22 | ||||
-rw-r--r-- | net/ipv4/netfilter/ipt_TTL.c | 9 |
3 files changed, 20 insertions, 33 deletions
diff --git a/net/ipv4/netfilter/ipt_ECN.c b/net/ipv4/netfilter/ipt_ECN.c index 35916c74fe4e..7e30e6d2b5da 100644 --- a/net/ipv4/netfilter/ipt_ECN.c +++ b/net/ipv4/netfilter/ipt_ECN.c | |||
@@ -27,22 +27,18 @@ MODULE_DESCRIPTION("iptables ECN modification module"); | |||
27 | static inline int | 27 | static inline int |
28 | set_ect_ip(struct sk_buff **pskb, const struct ipt_ECN_info *einfo) | 28 | set_ect_ip(struct sk_buff **pskb, const struct ipt_ECN_info *einfo) |
29 | { | 29 | { |
30 | if (((*pskb)->nh.iph->tos & IPT_ECN_IP_MASK) | 30 | struct iphdr *iph = (*pskb)->nh.iph; |
31 | != (einfo->ip_ect & IPT_ECN_IP_MASK)) { | 31 | u_int16_t oldtos; |
32 | u_int16_t diffs[2]; | ||
33 | 32 | ||
33 | if ((iph->tos & IPT_ECN_IP_MASK) != (einfo->ip_ect & IPT_ECN_IP_MASK)) { | ||
34 | if (!skb_make_writable(pskb, sizeof(struct iphdr))) | 34 | if (!skb_make_writable(pskb, sizeof(struct iphdr))) |
35 | return 0; | 35 | return 0; |
36 | 36 | iph = (*pskb)->nh.iph; | |
37 | diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF; | 37 | oldtos = iph->tos; |
38 | (*pskb)->nh.iph->tos &= ~IPT_ECN_IP_MASK; | 38 | iph->tos &= ~IPT_ECN_IP_MASK; |
39 | (*pskb)->nh.iph->tos |= (einfo->ip_ect & IPT_ECN_IP_MASK); | 39 | iph->tos |= (einfo->ip_ect & IPT_ECN_IP_MASK); |
40 | diffs[1] = htons((*pskb)->nh.iph->tos); | 40 | iph->check = nf_csum_update(oldtos ^ 0xFFFF, iph->tos, |
41 | (*pskb)->nh.iph->check | 41 | iph->check); |
42 | = csum_fold(csum_partial((char *)diffs, | ||
43 | sizeof(diffs), | ||
44 | (*pskb)->nh.iph->check | ||
45 | ^0xFFFF)); | ||
46 | } | 42 | } |
47 | return 1; | 43 | return 1; |
48 | } | 44 | } |
diff --git a/net/ipv4/netfilter/ipt_TOS.c b/net/ipv4/netfilter/ipt_TOS.c index 1c7a5ca399b3..52e9d705d48e 100644 --- a/net/ipv4/netfilter/ipt_TOS.c +++ b/net/ipv4/netfilter/ipt_TOS.c | |||
@@ -30,23 +30,17 @@ target(struct sk_buff **pskb, | |||
30 | void *userinfo) | 30 | void *userinfo) |
31 | { | 31 | { |
32 | const struct ipt_tos_target_info *tosinfo = targinfo; | 32 | const struct ipt_tos_target_info *tosinfo = targinfo; |
33 | struct iphdr *iph = (*pskb)->nh.iph; | ||
34 | u_int16_t oldtos; | ||
33 | 35 | ||
34 | if (((*pskb)->nh.iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) { | 36 | if ((iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) { |
35 | u_int16_t diffs[2]; | ||
36 | |||
37 | if (!skb_make_writable(pskb, sizeof(struct iphdr))) | 37 | if (!skb_make_writable(pskb, sizeof(struct iphdr))) |
38 | return NF_DROP; | 38 | return NF_DROP; |
39 | 39 | iph = (*pskb)->nh.iph; | |
40 | diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF; | 40 | oldtos = iph->tos; |
41 | (*pskb)->nh.iph->tos | 41 | iph->tos = (iph->tos & IPTOS_PREC_MASK) | tosinfo->tos; |
42 | = ((*pskb)->nh.iph->tos & IPTOS_PREC_MASK) | 42 | iph->check = nf_csum_update(oldtos ^ 0xFFFF, iph->tos, |
43 | | tosinfo->tos; | 43 | iph->check); |
44 | diffs[1] = htons((*pskb)->nh.iph->tos); | ||
45 | (*pskb)->nh.iph->check | ||
46 | = csum_fold(csum_partial((char *)diffs, | ||
47 | sizeof(diffs), | ||
48 | (*pskb)->nh.iph->check | ||
49 | ^0xFFFF)); | ||
50 | } | 44 | } |
51 | return IPT_CONTINUE; | 45 | return IPT_CONTINUE; |
52 | } | 46 | } |
diff --git a/net/ipv4/netfilter/ipt_TTL.c b/net/ipv4/netfilter/ipt_TTL.c index f48892ae0be5..2afb2a8aa8c5 100644 --- a/net/ipv4/netfilter/ipt_TTL.c +++ b/net/ipv4/netfilter/ipt_TTL.c | |||
@@ -27,7 +27,6 @@ ipt_ttl_target(struct sk_buff **pskb, | |||
27 | { | 27 | { |
28 | struct iphdr *iph; | 28 | struct iphdr *iph; |
29 | const struct ipt_TTL_info *info = targinfo; | 29 | const struct ipt_TTL_info *info = targinfo; |
30 | u_int16_t diffs[2]; | ||
31 | int new_ttl; | 30 | int new_ttl; |
32 | 31 | ||
33 | if (!skb_make_writable(pskb, (*pskb)->len)) | 32 | if (!skb_make_writable(pskb, (*pskb)->len)) |
@@ -55,12 +54,10 @@ ipt_ttl_target(struct sk_buff **pskb, | |||
55 | } | 54 | } |
56 | 55 | ||
57 | if (new_ttl != iph->ttl) { | 56 | if (new_ttl != iph->ttl) { |
58 | diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF; | 57 | iph->check = nf_csum_update((iph->ttl << 8) ^ 0xFFFF, |
58 | new_ttl << 8, | ||
59 | iph->check); | ||
59 | iph->ttl = new_ttl; | 60 | iph->ttl = new_ttl; |
60 | diffs[1] = htons(((unsigned)iph->ttl) << 8); | ||
61 | iph->check = csum_fold(csum_partial((char *)diffs, | ||
62 | sizeof(diffs), | ||
63 | iph->check^0xFFFF)); | ||
64 | } | 61 | } |
65 | 62 | ||
66 | return IPT_CONTINUE; | 63 | return IPT_CONTINUE; |