From 535a79f002c95b9d37ebded4f34c3b225c4c738d Mon Sep 17 00:00:00 2001 From: Duncan Roe Date: Fri, 20 Dec 2019 16:53:48 +1100 Subject: src: add mangle functions for IPv6, IPv6/TCP and IPv6/UDP Signed-off-by: Duncan Roe Signed-off-by: Pablo Neira Ayuso --- src/extra/udp.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/extra/udp.c') diff --git a/src/extra/udp.c b/src/extra/udp.c index 34dbf2a..9eee1c7 100644 --- a/src/extra/udp.c +++ b/src/extra/udp.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "internal.h" @@ -159,6 +160,44 @@ int nfq_udp_mangle_ipv4(struct pkt_buff *pktb, return 1; } +/** + * nfq_udp_mangle_ipv6 - Mangle UDP/IPv6 packet buffer + * \param pktb: Pointer to network packet buffer + * \param match_offset: Offset from start of UDP data of content that you want + * to mangle + * \param match_len: Length of the existing content you want to mangle + * \param rep_buffer: Pointer to data you want to use to replace current content + * \param rep_len: Length of data you want to use to replace current content + * \returns 1 for success and 0 for failure. See pktb_mangle() for failure case + * \note This function updates the IPv6 and UDP lengths and recalculates the UDP + * checksum for you. + */ +EXPORT_SYMBOL +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) +{ + struct ip6_hdr *ip6h; + struct udphdr *udph; + + ip6h = (struct ip6_hdr *)pktb->network_header; + udph = (struct udphdr *)(pktb->transport_header); + if (!udph) + return 0; + + udph->len = htons(ntohs(udph->len) + rep_len - match_len); + + if (!nfq_ip6_mangle(pktb, + pktb->transport_header - pktb->network_header + + sizeof(struct udphdr), + match_offset, match_len, rep_buffer, rep_len)) + return 0; + + nfq_udp_compute_checksum_ipv6(udph, ip6h); + + return 1; +} + /** * nfq_pkt_snprintf_udp_hdr - print udp header into one buffer in a humnan * readable way -- cgit v1.2.3