15 #include <arpa/inet.h> 16 #include <netinet/ip.h> 17 #include <netinet/ip6.h> 19 #include <netinet/tcp.h> 21 #include <libnetfilter_queue/libnetfilter_queue.h> 22 #include <libnetfilter_queue/libnetfilter_queue_tcp.h> 23 #include <libnetfilter_queue/libnetfilter_queue_ipv4.h> 24 #include <libnetfilter_queue/libnetfilter_queue_ipv6.h> 25 #include <libnetfilter_queue/pktbuff.h> 45 if (pktb->transport_header == NULL)
49 if (pktb_tail(pktb) - pktb->transport_header <
sizeof(
struct tcphdr))
52 return (
struct tcphdr *)pktb->transport_header;
64 unsigned int len = tcph->doff * 4;
67 if (len <
sizeof(
struct tcphdr))
71 if (pktb->transport_header + len > pktb_tail(pktb))
74 return pktb->transport_header + len;
86 return pktb_tail(pktb) - pktb->transport_header - (tcph->doff * 4);
112 tcph->check = nfq_checksum_tcpudp_ipv4(iph, IPPROTO_TCP);
130 tcph->check = nfq_checksum_tcpudp_ipv6(ip6h, tcph, IPPROTO_TCP);
147 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words[3]) 164 #define TCP_RESERVED_BITS htonl(0x0F000000) 166 ret = snprintf(buf, size,
"SPT=%u DPT=%u SEQ=%u ACK=%u " 167 "WINDOW=%u RES=0x%02x ",
168 ntohs(tcph->source), ntohs(tcph->dest),
169 ntohl(tcph->seq), ntohl(tcph->ack_seq),
172 (ntohl(tcp_flag_word(tcph) & TCP_RESERVED_BITS) >> 22));
176 ret = snprintf(buf+len, size-len,
"URG ");
180 ret = snprintf(buf+len, size-len,
"ACK ");
184 ret = snprintf(buf+len, size-len,
"PSH ");
188 ret = snprintf(buf+len, size-len,
"RST ");
192 ret = snprintf(buf+len, size-len,
"SYN ");
196 ret = snprintf(buf+len, size-len,
"FIN ");
220 unsigned int match_offset,
unsigned int match_len,
221 const char *rep_buffer,
unsigned int rep_len)
226 iph = (
struct iphdr *)pktb->network_header;
227 tcph = (
struct tcphdr *)(pktb->network_header + iph->ihl*4);
230 match_offset, match_len, rep_buffer, rep_len))
255 unsigned int match_offset,
unsigned int match_len,
256 const char *rep_buffer,
unsigned int rep_len)
258 struct ip6_hdr *ip6h;
261 ip6h = (
struct ip6_hdr *)pktb->network_header;
262 tcph = (
struct tcphdr *)(pktb->transport_header);
267 pktb->transport_header - pktb->network_header +
269 match_offset, match_len, rep_buffer, rep_len))
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)
int nfq_tcp_mangle_ipv6(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)
int nfq_tcp_mangle_ipv4(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)
void nfq_tcp_compute_checksum_ipv4(struct tcphdr *tcph, struct iphdr *iph)
struct tcphdr * nfq_tcp_get_hdr(struct pkt_buff *pktb)
int nfq_tcp_snprintf(char *buf, size_t size, const struct tcphdr *tcph)
void nfq_tcp_compute_checksum_ipv6(struct tcphdr *tcph, struct ip6_hdr *ip6h)
unsigned int nfq_tcp_get_payload_len(struct tcphdr *tcph, struct pkt_buff *pktb)
void * nfq_tcp_get_payload(struct tcphdr *tcph, struct pkt_buff *pktb)
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)