14 #include <arpa/inet.h> 15 #include <netinet/ip.h> 17 #include <libnetfilter_queue/libnetfilter_queue.h> 18 #include <libnetfilter_queue/libnetfilter_queue_ipv4.h> 19 #include <libnetfilter_queue/pktbuff.h> 43 unsigned int pktlen = pktb_tail(pktb) - pktb->network_header;
46 if (pktlen <
sizeof(
struct iphdr))
49 iph = (
struct iphdr *)pktb->network_header;
52 if (iph->version != 4)
56 if (ntohs(iph->tot_len) > pktlen)
75 int doff = iph->ihl * 4;
78 if ((
int)pktb->len - doff <= 0)
81 pktb->transport_header = pktb->network_header + doff;
104 uint32_t iph_len = iph->ihl * 4;
107 iph->check = nfq_checksum(0, (uint16_t *)iph, iph_len);
128 unsigned int match_offset,
unsigned int match_len,
129 const char *rep_buffer,
unsigned int rep_len)
131 struct iphdr *iph = (
struct iphdr *) pktb->network_header;
133 if (!
pktb_mangle(pktb, dataoff, match_offset, match_len, rep_buffer,
138 iph->tot_len = htons(pktb_tail(pktb) - pktb->network_header);
156 struct in_addr src = { iph->saddr };
157 struct in_addr dst = { iph->daddr };
159 char src_str[INET_ADDRSTRLEN];
160 char dst_str[INET_ADDRSTRLEN];
162 ret = snprintf(buf, size,
"SRC=%s DST=%s LEN=%u TOS=0x%X " 163 "PREC=0x%X TTL=%u ID=%u PROTO=%u ",
164 inet_ntop(AF_INET, &src, src_str, INET_ADDRSTRLEN),
165 inet_ntop(AF_INET, &dst, dst_str, INET_ADDRSTRLEN),
166 ntohs(iph->tot_len), IPTOS_TOS(iph->tos),
167 IPTOS_PREC(iph->tos), iph->ttl, ntohs(iph->id),
int nfq_ip_set_transport_header(struct pkt_buff *pktb, struct iphdr *iph)
struct iphdr * nfq_ip_get_hdr(struct pkt_buff *pktb)
void nfq_ip_set_checksum(struct iphdr *iph)
int nfq_ip_snprintf(char *buf, size_t size, const struct iphdr *iph)
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)
int nfq_ip_mangle(struct pkt_buff *pktb, unsigned int dataoff, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)