calculate checksum for all outgoing packets new

git.mgm/mediaproxy-ng/2.0
Richard Fuchs 15 years ago
parent aad7abbfa4
commit a17a138fc7

@ -964,22 +964,14 @@ err:
static int send_proxy_packet(struct sk_buff *skb, u_int32_t sip, u_int16_t sport, u_int32_t dip, u_int16_t dport, unsigned char tos) { static int send_proxy_packet(struct sk_buff *skb, u_int32_t sip, u_int16_t sport, u_int32_t dip, u_int16_t dport, unsigned char tos) {
long sum;
struct iphdr *ih; struct iphdr *ih;
struct udphdr *uh; struct udphdr *uh;
int datalen;
ih = ip_hdr(skb); ih = ip_hdr(skb);
uh = udp_hdr(skb); uh = udp_hdr(skb);
sum = uh->check; datalen = ntohs(uh->len);
if (sum) {
sum += ((u_int16_t *) &ih->saddr)[0];
sum += ((u_int16_t *) &ih->saddr)[1];
sum += ((u_int16_t *) &ih->daddr)[0];
sum += ((u_int16_t *) &ih->daddr)[1];
sum += uh->source;
sum += uh->dest;
}
ih->saddr = sip; ih->saddr = sip;
ih->daddr = dip; ih->daddr = dip;
@ -987,32 +979,19 @@ static int send_proxy_packet(struct sk_buff *skb, u_int32_t sip, u_int16_t sport
uh->source = htons(sport); uh->source = htons(sport);
uh->dest = htons(dport); uh->dest = htons(dport);
if (sum) { uh->check = 0;
sum -= ((u_int16_t *) &ih->saddr)[0]; skb->csum_start = skb_transport_header(skb) - skb->head;
sum -= ((u_int16_t *) &ih->saddr)[1]; skb->csum_offset = offsetof(struct udphdr, check);
sum -= ((u_int16_t *) &ih->daddr)[0]; uh->check = csum_tcpudp_magic(sip, dip, datalen, IPPROTO_UDP, csum_partial(uh, datalen, 0));
sum -= ((u_int16_t *) &ih->daddr)[1]; if (uh->check == 0)
sum -= uh->source; uh->check = CSUM_MANGLED_0;
sum -= uh->dest;
if (sum < 0) {
sum = -sum;
sum = (sum >> 16) + (sum & 0xffff);
sum += sum >> 16;
uh->check = ~sum;
}
else {
sum = (sum >> 16) + (sum & 0xffff);
sum += sum >> 16;
uh->check = sum;
}
}
__ip_select_ident(ih, skb_dst(skb), 0); __ip_select_ident(ih, skb_dst(skb), 0);
if (ip_route_me_harder(skb, RTN_LOCAL)) if (ip_route_me_harder(skb, RTN_LOCAL))
goto drop; goto drop;
skb->ip_summed = CHECKSUM_NONE;
__ip_select_ident(ih, skb_dst(skb), 0); __ip_select_ident(ih, skb_dst(skb), 0);
ip_local_out(skb); ip_local_out(skb);

Loading…
Cancel
Save