15 #include <arpa/inet.h>
16 #include <netinet/ip6.h>
18 #include <libnetfilter_queue/libnetfilter_queue.h>
19 #include <libnetfilter_queue/libnetfilter_queue_ipv6.h>
20 #include <libnetfilter_queue/pktbuff.h>
39 unsigned int pktlen = pktb->tail - pktb->network_header;
42 if (pktlen <
sizeof(
struct ip6_hdr))
45 ip6h = (
struct ip6_hdr *)pktb->network_header;
48 if (ip6h->ip6_flow != 0x60)
67 uint8_t nexthdr = ip6h->ip6_nxt;
68 uint8_t *cur = (uint8_t *)ip6h +
sizeof(
struct ip6_hdr);
70 while (nexthdr != target) {
71 struct ip6_ext *ip6_ext;
75 if (nexthdr == IPPROTO_NONE) {
80 if (pktb->tail - cur <
sizeof(
struct ip6_ext)) {
84 ip6_ext = (
struct ip6_ext *)cur;
86 if (nexthdr == IPPROTO_FRAGMENT) {
90 if (pktb->tail - cur <
sizeof(
struct ip6_frag)) {
95 frag_off = (uint16_t *)cur +
96 offsetof(
struct ip6_frag, ip6f_offlg);
99 if (htons(*frag_off & ~0x7)) {
106 hdrlen =
sizeof(
struct ip6_frag);
107 }
else if (nexthdr == IPPROTO_AH)
108 hdrlen = (ip6_ext->ip6e_len + 2) << 2;
110 hdrlen = ip6_ext->ip6e_len;
112 nexthdr = ip6_ext->ip6e_nxt;
115 pktb->transport_header = cur;
130 char src[INET6_ADDRSTRLEN];
131 char dst[INET6_ADDRSTRLEN];
133 inet_ntop(AF_INET6, &ip6h->ip6_src, src, INET6_ADDRSTRLEN);
134 inet_ntop(AF_INET6, &ip6h->ip6_dst, dst, INET6_ADDRSTRLEN);
136 ret = snprintf(buf, size,
"SRC=%s DST=%s LEN=%Zu TC=0x%X "
137 "HOPLIMIT=%u FLOWLBL=%u ",
139 ntohs(ip6h->ip6_plen) +
sizeof(
struct ip6_hdr),
140 (ip6h->ip6_flow & 0x0ff00000) >> 20,
142 (ip6h->ip6_flow & 0x000fffff));
struct ip6_hdr * nfq_ip6_get_hdr(struct pkt_buff *pktb)
int nfq_ip6_snprintf(char *buf, size_t size, const struct ip6_hdr *ip6h)
int nfq_ip6_set_transport_header(struct pkt_buff *pktb, struct ip6_hdr *ip6h, uint8_t target)