Try to shrink down bool bug code

This commit is contained in:
Nico Schottelius 2019-03-06 19:33:24 +01:00
commit a25da0f0df
2 changed files with 340 additions and 1 deletions

View file

@ -204,7 +204,69 @@ multicast address of the target address."
**** DONE Make switch answer icmp6 echo request for
**** TODO Make switch answer icmp echo request for
**** TODO Introduce mixed mode: switch: icmp6 echo reply, controller: NDP
***** TODO try 1: reply seen, but checksum is incorrect
***** DONE try 1: reply seen, but checksum is incorrect
***** TODO try 2: analysing tagya checksumming code
static uint16_t ip6_checksum(struct ip6 *ip6, uint32_t data_len, uint8_t proto)
{
uint32_t sum = 0;
uint16_t *p;
int i;
for (i = 0, p = ip6->src.s6_addr16; i < 16; ++i)
sum += *p++;
sum += htonl(data_len) >> 16;
sum += htonl(data_len) & 0xffff;
sum += htons(proto);
while (sum > 0xffff)
sum = (sum & 0xffff) + (sum >> 16);
return ~sum;
}
static uint16_t convert_cksum(struct ip6 *ip6, struct ip4 *ip4)
{
uint32_t sum = 0;
uint16_t *p;
int i;
sum += ~ip4->src.s_addr >> 16;
sum += ~ip4->src.s_addr & 0xffff;
sum += ~ip4->dest.s_addr >> 16;
sum += ~ip4->dest.s_addr & 0xffff;
for (i = 0, p = ip6->src.s6_addr16; i < 16; ++i)
sum += *p++;
while (sum > 0xffff)
sum = (sum & 0xffff) + (sum >> 16);
return sum;
}
...
static int xlate_payload_4to6(struct pkt *p, struct ip6 *ip6)
{
uint16_t *tck;
uint16_t cksum;
if (p->ip4->flags_offset & htons(IP4_F_MASK))
return 0;
switch (p->data_proto) {
case 1:
cksum = ip6_checksum(ip6, htons(p->ip4->length) -
p->header_len, 58);
cksum = ones_add(p->icmp->cksum, cksum);
if (p->icmp->type == 8) {
p->icmp->type = 128;
p->icmp->cksum = ones_add(cksum, ~(128 - 8));
} else {
p->icmp->type = 129;
p->icmp->cksum = ones_add(cksum, ~(129 - 0));
}
return 0;
**** DONE Add default route for v6 hosts
p4@ubuntu:~/master-thesis$ mx h1 ip -6 r
sudo: unable to resolve host ubuntu