14 #include <arpa/inet.h> 15 #include <netinet/ip.h> 16 #include <netinet/ip6.h> 18 #include <netinet/udp.h> 20 #include <libnetfilter_queue/libnetfilter_queue.h> 21 #include <libnetfilter_queue/libnetfilter_queue_udp.h> 22 #include <libnetfilter_queue/libnetfilter_queue_ipv4.h> 23 #include <libnetfilter_queue/libnetfilter_queue_ipv6.h> 24 #include <libnetfilter_queue/pktbuff.h> 45 if (pktb->transport_header == NULL)
49 if (pktb_tail(pktb) - pktb->transport_header <
sizeof(
struct udphdr))
52 return (
struct udphdr *)pktb->transport_header;
64 uint16_t len = ntohs(udph->len);
67 if (len <
sizeof(
struct udphdr))
71 if (pktb->transport_header + len > pktb_tail(pktb))
74 return pktb->transport_header +
sizeof(
struct udphdr);
86 return pktb_tail(pktb) - pktb->transport_header -
sizeof(
struct udphdr);
112 udph->check = nfq_checksum_tcpudp_ipv4(iph, IPPROTO_UDP);
130 udph->check = nfq_checksum_tcpudp_ipv6(ip6h, udph, IPPROTO_UDP);
151 unsigned int match_offset,
unsigned int match_len,
152 const char *rep_buffer,
unsigned int rep_len)
157 iph = (
struct iphdr *)pktb->network_header;
158 udph = (
struct udphdr *)(pktb->network_header + iph->ihl*4);
160 udph->len = htons(ntohs(udph->len) + rep_len - match_len);
163 match_offset, match_len, rep_buffer, rep_len))
185 unsigned int match_offset,
unsigned int match_len,
186 const char *rep_buffer,
unsigned int rep_len)
188 struct ip6_hdr *ip6h;
191 ip6h = (
struct ip6_hdr *)pktb->network_header;
192 udph = (
struct udphdr *)(pktb->transport_header);
196 udph->len = htons(ntohs(udph->len) + rep_len - match_len);
199 pktb->transport_header - pktb->network_header +
200 sizeof(
struct udphdr),
201 match_offset, match_len, rep_buffer, rep_len))
222 return snprintf(buf, size,
"SPT=%u DPT=%u ",
223 htons(udph->source), htons(udph->dest));
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)
void nfq_udp_compute_checksum_ipv4(struct udphdr *udph, struct iphdr *iph)
unsigned int nfq_udp_get_payload_len(struct udphdr *udph, struct pkt_buff *pktb)
int nfq_udp_snprintf(char *buf, size_t size, const struct udphdr *udph)
void nfq_udp_compute_checksum_ipv6(struct udphdr *udph, struct ip6_hdr *ip6h)
int nfq_udp_mangle_ipv6(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)
int nfq_udp_mangle_ipv4(struct pkt_buff *pktb, unsigned int match_offset, unsigned int match_len, const char *rep_buffer, unsigned int rep_len)
void * nfq_udp_get_payload(struct udphdr *udph, struct pkt_buff *pktb)
struct udphdr * nfq_udp_get_hdr(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)