1
0
Fork 0
mirror of https://passt.top/passt synced 2025-08-14 10:53:13 +02:00

passt: Add IPv6 and NDP support, further fixes for IPv4 CT

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2020-07-21 10:48:24 +02:00
commit d02e059ddc
10 changed files with 640 additions and 79 deletions

39
util.c
View file

@ -7,8 +7,11 @@
*
*/
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <linux/ipv6.h>
#include <arpa/inet.h>
/**
* csum_fold() - Fold long sum for IP and TCP checksum
@ -46,3 +49,39 @@ uint16_t csum_ip4(void *buf, size_t len)
return ~csum_fold(sum);
}
unsigned char *ipv6_l4hdr(struct ipv6hdr *ip6h, uint8_t *proto)
{
int offset, len, hdrlen;
struct ipv6_opt_hdr *o;
uint8_t nh;
len = ntohs(ip6h->payload_len);
offset = 0;
while (offset < len) {
if (!offset) {
nh = ip6h->nexthdr;
hdrlen = sizeof(struct ipv6hdr);
} else {
nh = o->nexthdr;
hdrlen = (o->hdrlen + 1) * 8;
}
if (nh == 59)
return NULL;
if (nh == 0 || nh == 43 || nh == 44 || nh == 50 ||
nh == 51 || nh == 60 || nh == 135 || nh == 139 ||
nh == 140 || nh == 253 || nh == 254) {
offset += hdrlen;
o = (struct ipv6_opt_hdr *)(unsigned char *)ip6h +
offset;
} else {
*proto = nh;
return (unsigned char *)(ip6h + 1) + offset;
}
}
return NULL;
}