src: doc: Final polish for current round
PATCH 1/1 src: doc: Final polish for current round
- 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)
--- src/extra/ipv4.c | 52 ++++++++++++++++++++++++++++++++++------------------ src/extra/tcp.c | 46 +++++++++++++++++++++++++++++++++++++--------- src/extra/udp.c | 20 ++++++++++++++------ src/nlmsg.c | 4 +--- 4 files changed, 86 insertions(+), 36 deletions(-)
src/extra/ipv4.c +34 -18
@@ -26,11 +26,15 @@*/ /** -* nfq_ip_get_hdr - get IPv4 header +* nfq_ip_get_hdr - get the IPv4 header * \param pktb: Pointer to user-space network packet buffer +* \returns validated pointer to the IPv4 header or NULL if IP is malformed or +* not version 4 * -* This funcion returns NULL if the IPv4 is malformed or the protocol version -* is not 4. On success, it returns a valid pointer to the IPv4 header. +* Many programs will not need to call this function. A possible use is to +* determine the layer 4 protocol. The validation is that the buffer is big +* enough for the declared lengths in the header, i.e. an extra check for packet +* truncation. */ EXPORT_SYMBOL struct iphdr *nfq_ip_get_hdr(struct pkt_buff *pktb)
@@ -56,13 +60,14 @@ struct iphdr *nfq_ip_get_hdr(struct pkt_buff *pktb) }/** -* nfq_ip_set_transport_header - set transport header +* nfq_ip_set_transport_header - set the \b transport_header field in \b pktb * \param pktb: Pointer to user-space network packet buffer * \param iph: Pointer to the IPv4 header -* -* Sets the \b transport_header field in \b pktb -* -* Level 4 helper functions need this to be set. +* \returns 0 on success or -1 if a minimal validation check fails +* \note +* Most programs should call __nfq_ip_set_transport_header__ as soon as +* possible, since most layer 4 helper functions assume the +* \b transport_header field is valid. */ EXPORT_SYMBOL int nfq_ip_set_transport_header(struct pkt_buff *pktb, struct iphdr *iph)
@@ -77,12 +82,21 @@ int nfq_ip_set_transport_header(struct pkt_buff *pktb, struct iphdr *iph)return 0 ; } +/** +* \defgroup ip_internals Internal IP functions +* +* Most user-space programs will never need these. +* +* @{ +*/ +/** * nfq_ip_set_checksum - set IPv4 checksum * \param iph: Pointer to the IPv4 header -* -* \note Call to this function if you modified the IPv4 header to update the -* checksum. +* \note +* nfq_ip_mangle() invokes this function. +* As long as developers always use the appropriate mangler for the layer being +* mangled, there is no need to call __nfq_ip_set_checksum__. */ EXPORT_SYMBOL void nfq_ip_set_checksum(struct iphdr *iph)
@@ -93,17 +107,21 @@ void nfq_ip_set_checksum(struct iphdr *iph) iph->check =nfq_checksum (0 , (uint16_t *)iph, iph_len); } +/** +* @} +*/ +/** * nfq_ip_mangle - mangle IPv4 packet buffer * \param pktb: Pointer to user-space network packet buffer -* \param dataoff: Offset to layer 4 header +* \param dataoff: Offset to layer 4 header, or zero to mangle IP header * \param match_offset: Offset to 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 IPv4 length and recalculates the IPv4 -* checksum (if necessary) +* \note This function updates the IPv4 length if necessary and recalculates the +* IPv4 checksum. */ EXPORT_SYMBOL int nfq_ip_mangle(struct pkt_buff *pktb, unsigned int dataoff,
@@ -128,10 +146,8 @@ int nfq_ip_mangle(struct pkt_buff *pktb, unsigned int dataoff,* \param buf: Pointer to buffer that will be used to print the header * \param size: Size of the buffer (or remaining room in it) * \param iph: Pointer to a valid IPv4 header -* -* This function returns the number of bytes written (excluding the -* string-terminating NUL) *assuming sufficient room in the buffer*. -* Read the snprintf manpage for more information about this strange behaviour. +* \returns same as snprintf +* \sa **snprintf**(3) */ EXPORT_SYMBOL int nfq_ip_snprintf(char *buf, size_t size, const struct iphdr *iph)
src/extra/tcp.c +37 -9
99 lines not on this page · raw message
src/extra/udp.c +14 -6
@@ -34,7 +34,10 @@* nfq_udp_get_hdr - get the UDP header. * \param pktb: Pointer to userspace network packet buffer * -* \returns Pointer to the UDP header, or NULL if no valid UDP header is found. +* \returns validated pointer to the UDP header or NULL if the UDP header was +* not set or if a minimal length check fails. +* \note You have to call nfq_ip_set_transport_header() or +* nfq_ip6_set_transport_header() first to set the UDP header. */ EXPORT_SYMBOL struct udphdr *nfq_udp_get_hdr(struct pkt_buff *pktb)
@@ -84,7 +87,7 @@ unsigned int nfq_udp_get_payload_len(struct udphdr *udph, struct pkt_buff *pktb) }/** -* \defgroup internals Internal functions +* \defgroup udp_internals Internal UDP functions * * Most user-space programs will never need these. *
@@ -109,14 +112,15 @@ void nfq_udp_compute_checksum_ipv4(struct udphdr *udph, struct iphdr *iph) udph->check =nfq_checksum_tcpudp_ipv4 (iph,IPPROTO_UDP ); } -/** -* @} -*/ -/** * nfq_udp_compute_checksum_ipv6 - sets up the UDP checksum in a UDP/IPv6 packet * \param udph: pointer to the UDP header * \param ip6h: pointer to the IPv6 header +* \note +* nfq_udp_mangle_ipv6() invokes this function. +* As long as developers always use __nfq_udp_mangle_ipv6__ when changing the +* content of a UDP message, there is no need to call +* __nfq_udp_compute_checksum_ipv6__. */ EXPORT_SYMBOL void nfq_udp_compute_checksum_ipv6(struct udphdr *udph, struct ip6_hdr *ip6h)
@@ -126,6 +130,10 @@ void nfq_udp_compute_checksum_ipv6(struct udphdr *udph, struct ip6_hdr *ip6h) udph->check =nfq_checksum_tcpudp_ipv6 (ip6h, udph,IPPROTO_UDP ); } +/** +* @} +*/ +/** * nfq_udp_mangle_ipv4 - Mangle UDP/IPv4 packet buffer * \param pktb: Pointer to network packet buffer
src/nlmsg.c +1 -3
@@ -263,9 +263,7 @@ static int nfq_pkt_parse_attr_cb(const struct nlattr *attr, void *data)* nfq_nlmsg_parse - set packet attributes from netlink message * \param nlh netlink message that you want to read. * \param attr pointer to array of attributes to set. -* -* This function returns MNL_CB_ERROR if any error occurs, or MNL_CB_OK on -* success. +* \returns MNL_CB_OK on success or MNL_CB_ERROR if any error occurs. */ EXPORT_SYMBOL int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr)
Signature · 1 line
2.14.5
Quoted 10 lines · Duncan Roe
- 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 fornfq_tcp_get_hdr(no other mismatches noticed, but there may be some)
- Add warnings regarding changing length of tcp packet
- Make group names unique withinlibnetfilter_queue(else man pages would be overwritten)
Applied, thanks.