Commit da878c8e authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

[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: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1158ba27
...@@ -27,22 +27,18 @@ MODULE_DESCRIPTION("iptables ECN modification module"); ...@@ -27,22 +27,18 @@ MODULE_DESCRIPTION("iptables ECN modification module");
static inline int static inline int
set_ect_ip(struct sk_buff **pskb, const struct ipt_ECN_info *einfo) set_ect_ip(struct sk_buff **pskb, const struct ipt_ECN_info *einfo)
{ {
if (((*pskb)->nh.iph->tos & IPT_ECN_IP_MASK) struct iphdr *iph = (*pskb)->nh.iph;
!= (einfo->ip_ect & IPT_ECN_IP_MASK)) { u_int16_t oldtos;
u_int16_t diffs[2];
if ((iph->tos & IPT_ECN_IP_MASK) != (einfo->ip_ect & IPT_ECN_IP_MASK)) {
if (!skb_make_writable(pskb, sizeof(struct iphdr))) if (!skb_make_writable(pskb, sizeof(struct iphdr)))
return 0; return 0;
iph = (*pskb)->nh.iph;
diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF; oldtos = iph->tos;
(*pskb)->nh.iph->tos &= ~IPT_ECN_IP_MASK; iph->tos &= ~IPT_ECN_IP_MASK;
(*pskb)->nh.iph->tos |= (einfo->ip_ect & IPT_ECN_IP_MASK); iph->tos |= (einfo->ip_ect & IPT_ECN_IP_MASK);
diffs[1] = htons((*pskb)->nh.iph->tos); iph->check = nf_csum_update(oldtos ^ 0xFFFF, iph->tos,
(*pskb)->nh.iph->check iph->check);
= csum_fold(csum_partial((char *)diffs,
sizeof(diffs),
(*pskb)->nh.iph->check
^0xFFFF));
} }
return 1; return 1;
} }
......
...@@ -30,23 +30,17 @@ target(struct sk_buff **pskb, ...@@ -30,23 +30,17 @@ target(struct sk_buff **pskb,
void *userinfo) void *userinfo)
{ {
const struct ipt_tos_target_info *tosinfo = targinfo; const struct ipt_tos_target_info *tosinfo = targinfo;
struct iphdr *iph = (*pskb)->nh.iph;
u_int16_t oldtos;
if (((*pskb)->nh.iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) { if ((iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) {
u_int16_t diffs[2];
if (!skb_make_writable(pskb, sizeof(struct iphdr))) if (!skb_make_writable(pskb, sizeof(struct iphdr)))
return NF_DROP; return NF_DROP;
iph = (*pskb)->nh.iph;
diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF; oldtos = iph->tos;
(*pskb)->nh.iph->tos iph->tos = (iph->tos & IPTOS_PREC_MASK) | tosinfo->tos;
= ((*pskb)->nh.iph->tos & IPTOS_PREC_MASK) iph->check = nf_csum_update(oldtos ^ 0xFFFF, iph->tos,
| tosinfo->tos; iph->check);
diffs[1] = htons((*pskb)->nh.iph->tos);
(*pskb)->nh.iph->check
= csum_fold(csum_partial((char *)diffs,
sizeof(diffs),
(*pskb)->nh.iph->check
^0xFFFF));
} }
return IPT_CONTINUE; return IPT_CONTINUE;
} }
......
...@@ -27,7 +27,6 @@ ipt_ttl_target(struct sk_buff **pskb, ...@@ -27,7 +27,6 @@ ipt_ttl_target(struct sk_buff **pskb,
{ {
struct iphdr *iph; struct iphdr *iph;
const struct ipt_TTL_info *info = targinfo; const struct ipt_TTL_info *info = targinfo;
u_int16_t diffs[2];
int new_ttl; int new_ttl;
if (!skb_make_writable(pskb, (*pskb)->len)) if (!skb_make_writable(pskb, (*pskb)->len))
...@@ -55,12 +54,10 @@ ipt_ttl_target(struct sk_buff **pskb, ...@@ -55,12 +54,10 @@ ipt_ttl_target(struct sk_buff **pskb,
} }
if (new_ttl != iph->ttl) { if (new_ttl != iph->ttl) {
diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF; iph->check = nf_csum_update((iph->ttl << 8) ^ 0xFFFF,
new_ttl << 8,
iph->check);
iph->ttl = new_ttl; iph->ttl = new_ttl;
diffs[1] = htons(((unsigned)iph->ttl) << 8);
iph->check = csum_fold(csum_partial((char *)diffs,
sizeof(diffs),
iph->check^0xFFFF));
} }
return IPT_CONTINUE; return IPT_CONTINUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment