summaryrefslogtreecommitdiffstats
path: root/src/extra
Commit message (Collapse)AuthorAgeFilesLines
* src: Fix IPv6 Fragment Header processingDuncan Roe2023-10-081-3/+3
| | | | | | | | | | | 2 items: 1. frag_off (Fragment Offset pointer) overshot by 2 bytes because of adding offsetof() to it *after* it had been cast to uint16_t *. 2. Need to mask off LS 3 bits of ip6f_offlg *after* call to htons. Fixes: a0c885ae5a79 ("add pkt_buff and protocol helper functions") Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: add alternative API to set up packet bufferPablo Neira Ayuso2023-08-201-5/+58
| | | | | | | | | | | | | | | | pktb_setup_raw() is a new function to initialise a new struct pkt_buff. It takes the memory area to be used to store pkt_buff structure and the data. Data is attached to the packet buffer (not copied), ie. the packet buffer data points to the provided data pointer. pktb_head_size() is a new function to return the amount of memory to reserve for a new struct pkt_buff. Extend documentation pon pktb_alloc(). Mostly original patch from Duncan Roe <duncan_roe@optusnet.com.au>. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Insert SYNOPSIS sections for man pagesDuncan Roe2021-08-156-7/+110
| | | | | | | | | | | | In order to work with the post-processing logic in doxygen/Makefile.am, SYNOPSIS sections must be inserted at the end of the module description (text after \defgroup or \addtogroup) (becomes Detailed Description in the man page). Also a few minor updates including rename module uselessfns to do_not_use. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* include: deprecate libnetfilter_queue/linux_nfnetlink_queue.hPablo Neira Ayuso2021-08-115-0/+5
| | | | | | Emit a warning to notify users that this file is deprecated. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* pktbuff: add __pktb_setup()Pablo Neira Ayuso2021-05-271-22/+33
| | | | | | Add private helper function to set up the pkt_buff object. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: fix IPv6 header handlingEtan Kissling2021-02-191-2/+13
| | | | | | | | This corrects issues in IPv6 header handling that sometimes resulted in an endless loop. Signed-off-by: Etan Kissling <etan_kissling@apple.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: add pkt_buff function for ICMPEtan Kissling2021-02-091-0/+48
| | | | | | | | Add support for processing ICMP packets using pkt_buff, similar to existing library support for TCP and UDP. Signed-off-by: Etan Kissling <etan_kissling@apple.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Fix doxygen warningDuncan Roe2020-09-301-4/+0
| | | | | | | | | src/extra/checksum.c had a stray group close sequence at the end. (Spotted after sending doxygen o/p to /dev/null) Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* Simplify struct pkt_buff: remove tailDuncan Roe2020-01-295-17/+13
| | | | | | | | | | In struct pkt_buff, we only ever needed any 2 of len, data and tail. This has caused bugs in the past, e.g. commit 8a4316f31. Delete tail, and where the value of pktb->tail was required, use new pktb_tail() function. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Simplify struct pkt_buff: remove headDuncan Roe2020-01-181-3/+2
| | | | | | | | head and data always had the same value. head was in the minority, so replace with data where it was used. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Fix indenting weirdness is pktbuff.c w/out changing indentDuncan Roe2020-01-161-4/+3
| | | | | | | | | In pktb_alloc, declare struct ethhdr *ethhdr at function start, thus avoiding cute braces on case AF_BRIDGE. This costs nothing and generates less code. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Fix value returned by nfq_tcp_get_payload_len()Duncan Roe2020-01-101-1/+1
| | | | | | | Remember to subtract the TCP header length. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Final polish for current roundDuncan Roe2020-01-103-33/+85
| | | | | | | | | | | | | | | | - Ensure all functions that return something have a \returns - Demote more checksum functions to their own groups (reduces number of functions on main pages) - Clarify wording where appropriate - Add \sa (see also) where appropriate - Fix documented function name for nfq_tcp_get_hdr (no other mismatches noticed, but there may be some) - Add warnings regarding changing length of tcp packet - Make group names unique within libnetfilter_queue (else man pages would be overwritten) Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Always use pktb as formal arg of type struct pkt_buffDuncan Roe2020-01-032-11/+11
| | | | | | | | | | | All remaining instances of pkt refer to something other than a pkt_buff. In the prototype for nfq_nlmsg_parse, pkt is changed to attr. Inconsistent whitespace in headers has been left for another day. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Florian Westphal <fw@strlen.de>
* src: checksum.c: remove redundant 0xFFFF mask of uint16_tDuncan Roe2020-01-031-2/+2
| | | | | Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Florian Westphal <fw@strlen.de>
* src: doc: tcp.c: fix remaining doxygen warningsDuncan Roe2019-12-301-4/+4
| | | | | Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: pktb_mangle has signed offset arg so can mangle MAC header with -ve oneDuncan Roe2019-12-301-3/+5
| | | | | | | | | - Update prototype - Update doxygen documentation - Update declaration Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: add mangle functions for IPv6, IPv6/TCP and IPv6/UDPDuncan Roe2019-12-303-0/+108
| | | | | Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: more IPv6 checksum fixesDuncan Roe2019-12-301-5/+5
| | | | | | | | | | | - Fix calculation of header length - Upgrade calculation of payload length: Allow for extra headers before the UDP header. - Delete "sum += ... s6_addr16[i] >> 16" lines, since uint16_t >> 16 == 0 - Use upgraded payload length in pseudo-header Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Eliminate doxygen warnings from udp.cDuncan Roe2019-12-161-20/+30
| | | | | | | | | | | | | | | - Make it clear that packet buffer is the user-space one - Use \returns for all return values - Make function names in doc agree with prototypes - Make number and names of params in doc agree with prototypes - Divide functions into a hierarchy: top-level: Functions all programs that modify data will use (nfq_udp_snprintf is optional) 2nd-level: Rarely-used (except internally) functions - Add see-also snprintf Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: udp.c: rename 1 more formal pkt arg to pktbDuncan Roe2019-12-161-4/+4
| | | | | Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Fix value returned by nfq_udp_get_payload_len()Duncan Roe2019-12-111-1/+1
| | | | | | | Remember to subtract the UDP header length. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* Minor tweak to pktb_len function descriptionDuncan Roe2019-12-071-1/+1
| | | | | Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Major re-work of user packet buffer documentationDuncan Roe2019-12-071-37/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Divide functions into a hierarchy: top-level: Functions all programs that modify data will use 2nd-level: Rarely-used functions 3rd-level: Functions not to use (should have been declared static) Only the top-level functions appear on the "User-space network packet buffer" page, which looks a lot less daunting than it used to. Parameter descriptions all match prototypes All non-void functions have a "Returns" paragraph Code change: pktb_alloc: set errno to EPROTONOSUPPORT before doing error return because protocol is not supported Detailed other updates (top-level) pktb_alloc: - Add "Errors" para - Add "See also" para pktb_data, pktb_len: Add "appropriate use" line pktb_mangle: Add warning to use a different function unless mangling MAC hddr pktb_mangled: Add usage hint line Detailed other updates (2nd-level) pktb_mac_header: Point out only for AF_BRIDGE pktb_tailroom: Point out no dynamic expansion pktb_transport_header: Add note that programmer must code to set this Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Fix test for IPv6 headerDuncan Roe2019-12-071-1/+1
| | | | | | | | | | | | Updated: src/extra/ipv6.c: Only test the first 4 bits of the putative IPv6 header to be 6, since all the other bits are up for grabs. (I have seen nonzero Flow Control on the local interface and RFC2474 & RFC3168 document Traffic Class use). Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Fix IPv4 checksum calculation in AF_BRIDGE packet bufferDuncan Roe2019-11-211-1/+1
| | | | | | | | | | | | Updated: src/extra/pktbuff.c: If pktb was created in family AF_BRIDGE, then pktb->len will include the bytes in the network header. So set the IPv4 length to "tail - network_header" rather than len Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Make sure pktb_alloc() works for IPv6 over AF_BRIDGEDuncan Roe2019-11-161-0/+1
| | | | | | | | | | | | | | | | At least on the local interface, the MAC header of an IPv6 packet specifies IPv6 protocol (rather than IP). This surprised me, since the first octet of the IP datagram is the IP version, but I guess it's an efficiency thing. Without this patch, pktb_alloc() returns NULL when an IPv6 packet is encountered. Updated: src/extra/pktbuff.c: - Treat ETH_P_IPV6 the same as ETH_P_IP. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Make sure pktb_alloc() works for AF_INET6 since we document that it doesDuncan Roe2019-11-121-0/+1
| | | | | | | | | | | | | Without this patch, AF_INET6 pktb_alloc() creates a pktb with NULL network_header. But in src/extra/ipv6.c, nfq_ip6_get_hdr() assumes that pktb->network_header is valid. Updated: src/extra/pktbuff.c: Treat AF_INET6 the same as AF_INET. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: pktb_trim() was not updating tail after updating lenDuncan Roe2019-11-121-0/+1
| | | | | | | | | | | skb->tail is used in many places, so it's important to keep it up to date. Updated: src/extra/pktbuff.c: Fix pktb_trim() Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Eliminate doxygen warnings from ipv{4,6}.cDuncan Roe2019-11-042-33/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Updated: src/extra/ipv4.c: - Rename pkt formal arg of nfq_ip_mangle to pktb (to match all other struct pkt_buff args) - Make it clear that packet buffer is the user-space one - Sentence-case all parameter descriptions - Fix \param 3 of nfq_pkt_snprintf_ip to match prototype - Revised description of nfq_pkt_snprintf_ip for English usage, but left the "strange behaviour" bit at the end. (I know kernel developers hate snprintf: the purpose of the return code was not a blanket buffer overrun check but rather an amount to subtract from the size argument to the next snprintf call. It was therefore a bit of a screw-up to have snprintf take an unsigned size_t argument so the -ve size looks like a huge +ve one and snprintf keeps writing :( The programmer needs to use a signed type for size and explicitly test it for still being +ve before every snprintf call; with ssize_t, snprintf could have done nothing and returned zero with a -ve size so the programmer only needs to check right at the end. Ah well...) src/extra/ipv6.c: - Use \returns for all return values - Fix \param 3 of nfq_ip6_snprintf to match prototype - Sentence-case all parameter descriptions - Change IPv4 to IPv6 in a comment Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* checksum: Fix TCP/UDP checksum computation on big endian archesAlin Nastac2019-10-091-2/+8
| | | | | | | | On big endian arches UDP/TCP checksum is incorrectly computed when payload length is odd. Signed-off-by: Alin Nastac <alin.nastac@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Minor fixDuncan Roe2019-10-081-1/+1
| | | | | | | | | | The documentation generally uses OSI layer numbering, where TCP (i.e. Transport) is layer 4 so that IP is layer 3. Bring pktb_mangle documentation into line with this. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Fix invalid conversion specifierDuncan Roe2019-10-081-1/+1
| | | | | | | | | Clang (but not gcc) warned about this. Gcc (but not clang) used to warn that nfq_set_verdict_mark is deprecated, but this has stopped since re-defining EXPORT_SYMBOL. Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Enable clang buildDuncan Roe2019-10-085-61/+53
| | | | | | | | | | | | | | | | Modify the definition and use of EXPORT_SYMBOL as was done for libmnl in commit 444d6dc9. Additionally, avoid generating long (>80ch) lines when inserting EXPORT_SYMBOL. Finally, re-align multi-line parameter blocks with opening parenthesis. [ I have mangled the original patch to not split the function definition and its return value. --pablo ] Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: doc: Miscellaneous updatesDuncan Roe2019-10-083-16/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (These updates only cover functions used in a recent project) src/extra/ipv4.c: - nfq_ip_set_transport_header(): Add explanatory notes - nfq_ip_mangle() - Advise that there is a return code - Note that IPv4 length is updated as well as checksum src/extra/pktbuff.c: - pktb_alloc(): Minor rewording (English usage) - pktb_mangle(): Document src/extra/udp.c: - nfq_udp_get_hdr(): Fix params - nfq_udp_get_payload(): Fix params - nfq_udp_get_payload_len(): Fix params - nfq_udp_mangle_ipv4(): Rewrite documentation src/nlmsg.c: - nfq_nlmsg_verdict_put(): Document - nfq_nlmsg_cfg_put_cmd(): - Change name (was: nfq_nlmsg_cfg_build_request) - Fix params - Delete function return documentation (void fn) - nfq_nlmsg_cfg_put_params(); Document (params only) - nfq_nlmsg_cfg_put_qmaxlen(): Document (params only) - nfq_nlmsg_parse: - Change name (was: nfq_pkt_parse) - Fix params Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Update UDP header length field after manglingDuncan Roe2019-10-061-0/+2
| | | | | | | | | | One would expect nfq_udp_mangle_ipv4() to take care of the length field in the UDP header but it did not. With this patch, it does. This patch is very unlikely to adversely affect any existing userspace software (that did its own length adjustment), because UDP checksumming was broken. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* checksum: Fix UDP checksum calculationPablo Neira Ayuso2019-09-303-8/+9
| | | | | | | | | | The level 4 protocol is part of the UDP and TCP calculations. nfq_checksum_tcpudp_ipv4() was using IPPROTO_TCP in this calculation, which gave the wrong answer for UDP. Based on patch from Alin Nastac, and patch description from Duncan Roe. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* Revert "src: Declare the define visibility attribute together"Pablo Neira Ayuso2017-04-145-36/+72
| | | | | | | | This reverts commit 58cb0668dc15c78cd3af9eeaedf29386e86ecac1. Prepare a new patch to keep this update consistent with libmnl. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: Declare the define visibility attribute togetherKhem Raj2017-04-145-72/+36
| | | | | | | | | clang ignores the visibility attribute if its not defined before the definition. As a result these symbols become hidden and consumers of this library fail to link due to these missing symbols. Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* extra: Define _GNU_SOURCE to get members of tcphdr&ucphdrFelix Janda2015-05-292-0/+2
| | | | | | | | | The source uses linux names for members of tcphdr. For example "source" instead of "th_sport", ... musl libc's headers need _GNU_SOURCE defined in order to expose these. Signed-off-by: Felix Janda <felix.janda@posteo.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* extra: tcp: insufficient sanitization in nfq_tcp_get_payload()Pablo Neira Ayuso2014-06-301-3/+7
| | | | | | | Similar to 7335cbe ("extra: fix wrong implementation in nfq_udp_get_payload"). Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* extra: fix wrong implementation in nfq_udp_get_payloadTing-Wei Lan2014-06-301-4/+8
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* extra: use inet_ntop instead of inet_ntoaTing-Wei Lan2014-06-301-1/+5
| | | | | | | | The result of inet_ntoa() will be overwritten by the next call to inet_ntoa(), so using it twice in the same snprintf() call causes wrong result. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: extra: add prefix nfq_ to internal checksum functionsPablo Neira Ayuso2013-08-134-10/+10
| | | | | | | | These functions are internal and they belong to the libnetfilter_queue scope, so let's add the corresponding nfq_ prefix. Suggested-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* build: avoid symbol namespace pollutionFlorian Westphal2013-08-131-0/+12
| | | | | | | | | | | | | | | As of f40eabb01 (add pkt_buff and protocol helper functions) libnetfilter_queue accidentally exports the internal function named 'checksum'. This is a bit too generic and may cause crashes with applications that worked fine before. This patch makes the functions checksum, checksum_tcpudp_ipv4 and checksum_tcpudp_ipv6 local by building with fvis-hidden and adding EXPORTs for the legacy api calls and the ones that seem to have missing EXPORT tags (mainly pktbuff api). Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: update doxygen documentation for new API for libmnlPablo Neira Ayuso2012-08-204-4/+83
| | | | | | This patch updates the doxygen documentation for the new API. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* pktbuff: fix pktb_push, _pull and _put functionPablo Neira Ayuso2012-08-201-2/+5
| | | | | | Fix wrong arithmetics and missing pktb->len update Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* extra: pktbuff: pktb_expand_tail return 0 if there is no room in the tailPablo Neira Ayuso2012-08-201-3/+9
| | | | | | | | | | | | pktb_expand_tail returns 0 if there is no room for the mangling. Note that we don't support dynamic reallocation, instead the caller is responsible for allocating the extra room via pktb_alloc according to the maximum amount of bytes it needs for the mangling. Since pkt_buff layout is not exposed, we can change this in the future if we prefer dynamic reallocation. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* add mangle functions for IPv4/TCP and IPv4/UDPPablo Neira Ayuso2012-08-066-4/+135
| | | | Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* add pkt_buff and protocol helper functionsPablo Neira Ayuso2012-08-066-0/+798
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>