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>
38 unsigned int pktlen = pktb->tail - pktb->network_header;
41 if (pktlen <
sizeof(
struct iphdr))
44 iph = (
struct iphdr *)pktb->network_header;
47 if (iph->version != 4)
51 if (ntohs(iph->tot_len) > pktlen)
65 int doff = iph->ihl * 4;
68 if ((
int)pktb->len - doff <= 0)
71 pktb->transport_header = pktb->network_header + doff;
85 uint32_t iph_len = iph->ihl * 4;
88 iph->check = nfq_checksum(0, (uint16_t *)iph, iph_len);
104 unsigned int match_offset,
unsigned int match_len,
105 const char *rep_buffer,
unsigned int rep_len)
107 struct iphdr *iph = (
struct iphdr *) pkt->network_header;
109 if (!pktb_mangle(pkt, dataoff, match_offset, match_len,
110 rep_buffer, rep_len))
114 iph->tot_len = htons(pkt->len);
134 struct in_addr src = { iph->saddr };
135 struct in_addr dst = { iph->daddr };
137 char src_str[INET_ADDRSTRLEN];
138 char dst_str[INET_ADDRSTRLEN];
140 ret = snprintf(buf, size,
"SRC=%s DST=%s LEN=%u TOS=0x%X "
141 "PREC=0x%X TTL=%u ID=%u PROTO=%u ",
142 inet_ntop(AF_INET, &src, src_str, INET_ADDRSTRLEN),
143 inet_ntop(AF_INET, &dst, dst_str, INET_ADDRSTRLEN),
144 ntohs(iph->tot_len), IPTOS_TOS(iph->tos),
145 IPTOS_PREC(iph->tos), iph->ttl, ntohs(iph->id),
void nfq_ip_set_checksum(struct iphdr *iph)
int nfq_ip_set_transport_header(struct pkt_buff *pktb, struct iphdr *iph)
struct iphdr * nfq_ip_get_hdr(struct pkt_buff *pktb)
int nfq_ip_mangle(struct pkt_buff *pkt, unsigned int dataoff, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)
int nfq_ip_snprintf(char *buf, size_t size, const struct iphdr *iph)