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/pktbuff.h>
45 if (pktb->transport_header == NULL)
49 if (pktb->tail - pktb->transport_header <
sizeof(
struct tcphdr))
52 return (
struct tcphdr *)pktb->transport_header;
63 unsigned int len = tcph->doff * 4;
66 if (len <
sizeof(
struct tcphdr))
70 if (pktb->transport_header + len > pktb->tail)
73 return pktb->transport_header + len;
85 return pktb->tail - pktb->transport_header;
99 tcph->check = nfq_checksum_tcpudp_ipv4(iph);
113 tcph->check = nfq_checksum_tcpudp_ipv6(ip6h, tcph);
127 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words[3])
141 #define TCP_RESERVED_BITS htonl(0x0F000000)
143 ret = snprintf(buf, size,
"SPT=%u DPT=%u SEQ=%u ACK=%u "
144 "WINDOW=%u RES=0x%02x ",
145 ntohs(tcph->source), ntohs(tcph->dest),
146 ntohl(tcph->seq), ntohl(tcph->ack_seq),
149 (ntohl(tcp_flag_word(tcph) & TCP_RESERVED_BITS) >> 22));
153 ret = snprintf(buf+len, size-len,
"URG ");
157 ret = snprintf(buf+len, size-len,
"ACK ");
161 ret = snprintf(buf+len, size-len,
"PSH ");
165 ret = snprintf(buf+len, size-len,
"RST ");
169 ret = snprintf(buf+len, size-len,
"SYN ");
173 ret = snprintf(buf+len, size-len,
"FIN ");
194 unsigned int match_offset,
unsigned int match_len,
195 const char *rep_buffer,
unsigned int rep_len)
200 iph = (
struct iphdr *)pkt->network_header;
201 tcph = (
struct tcphdr *)(pkt->network_header + iph->ihl*4);
204 match_offset, match_len, rep_buffer, rep_len))
void nfq_tcp_compute_checksum_ipv6(struct tcphdr *tcph, struct ip6_hdr *ip6h)
void nfq_tcp_compute_checksum_ipv4(struct tcphdr *tcph, struct iphdr *iph)
int nfq_tcp_mangle_ipv4(struct pkt_buff *pkt, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)
struct tcphdr * nfq_tcp_get_hdr(struct pkt_buff *pktb)
int nfq_tcp_snprintf(char *buf, size_t size, const struct tcphdr *tcph)
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)
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)