002-bigendian_wrong_checksum.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --- a/nat64.c
  2. +++ b/nat64.c
  3. @@ -19,6 +19,11 @@
  4. extern struct config *gcfg;
  5. +static uint16_t checksum_extend_byte(uint8_t b)
  6. +{
  7. + return htons(b << 8);
  8. +}
  9. +
  10. static uint16_t ip_checksum(void *d, int c)
  11. {
  12. uint32_t sum = 0xffff;
  13. @@ -30,7 +35,7 @@ static uint16_t ip_checksum(void *d, int
  14. }
  15. if (c)
  16. - sum += htons(*((uint8_t *)p) << 8);
  17. + sum += checksum_extend_byte(*((uint8_t *)p));
  18. while (sum > 0xffff)
  19. sum = (sum & 0xffff) + (sum >> 16);
  20. @@ -180,10 +185,12 @@ static int xlate_payload_4to6(struct pkt
  21. cksum = ones_add(p->icmp->cksum, cksum);
  22. if (p->icmp->type == 8) {
  23. p->icmp->type = 128;
  24. - p->icmp->cksum = ones_add(cksum, ~(128 - 8));
  25. + p->icmp->cksum = ones_add(cksum,
  26. + ~checksum_extend_byte(128 - 8));
  27. } else {
  28. p->icmp->type = 129;
  29. - p->icmp->cksum = ones_add(cksum, ~(129 - 0));
  30. + p->icmp->cksum = ones_add(cksum,
  31. + ~checksum_extend_byte(129 - 0));
  32. }
  33. return 0;
  34. case 17:
  35. @@ -668,10 +675,12 @@ static int xlate_payload_6to4(struct pkt
  36. cksum = ones_add(p->icmp->cksum, cksum);
  37. if (p->icmp->type == 128) {
  38. p->icmp->type = 8;
  39. - p->icmp->cksum = ones_add(cksum, 128 - 8);
  40. + p->icmp->cksum = ones_add(cksum,
  41. + checksum_extend_byte(128 - 8));
  42. } else {
  43. p->icmp->type = 0;
  44. - p->icmp->cksum = ones_add(cksum, 129 - 0);
  45. + p->icmp->cksum = ones_add(cksum,
  46. + checksum_extend_byte(129 - 0));
  47. }
  48. return 0;
  49. case 17: