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) - pktb->network_header;
42 if (pktlen <
sizeof(
struct ip6_hdr))
45 ip6h = (
struct ip6_hdr *)pktb->network_header;
48 if ((*(uint8_t *)ip6h & 0xf0) != 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(pktb) - cur <
sizeof(
struct ip6_ext)) {
84 ip6_ext = (
struct ip6_ext *)cur;
86 if (nexthdr == IPPROTO_FRAGMENT) {
90 if (pktb_tail(pktb) - 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;
132 unsigned int match_offset,
unsigned int match_len,
133 const char *rep_buffer,
unsigned int rep_len)
135 struct ip6_hdr *ip6h = (
struct ip6_hdr *)pktb->network_header;
137 if (!
pktb_mangle(pktb, dataoff, match_offset, match_len, rep_buffer,
143 htons(pktb_tail(pktb) - pktb->network_header -
sizeof *ip6h);
161 char src[INET6_ADDRSTRLEN];
162 char dst[INET6_ADDRSTRLEN];
164 inet_ntop(AF_INET6, &ip6h->ip6_src, src, INET6_ADDRSTRLEN);
165 inet_ntop(AF_INET6, &ip6h->ip6_dst, dst, INET6_ADDRSTRLEN);
167 ret = snprintf(buf, size,
"SRC=%s DST=%s LEN=%zu TC=0x%X " 168 "HOPLIMIT=%u FLOWLBL=%u ",
170 ntohs(ip6h->ip6_plen) +
sizeof(
struct ip6_hdr),
171 (ip6h->ip6_flow & 0x0ff00000) >> 20,
173 (ip6h->ip6_flow & 0x000fffff));
int nfq_ip6_mangle(struct pkt_buff *pktb, unsigned int dataoff, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)
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)
int pktb_mangle(struct pkt_buff *pktb, int dataoff, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)