Skip to contentSkip to conversation

RFC: libnetfilter_queue: nfq_udp_get_payload_len() gives wrong answer

PATCH Applied Duncan Roe 2 participants 4 messages Dec 8, 2019 – Dec 11, 2019 netfilter

lore
Share & tools
lore

Duncan Roe

author
#0 lore raw

nfq_udp_get_payload() correctly returns a pointer to the first data byte in a UDP message, e.g. to "A" in the message "ASD\n".

BUT nfq_udp_get_payload_len() returns 12 for the length of the above message, i.e. combined lengths of payload and UDP header.

I plan to do an update of the documentation in src/extra/udp.c so I can document this behaviour then.

OR

Should I change the behaviour of nfq_udp_get_payload_len() to what one would expect? (e.g. return 4 in the example above)

OR

Should there be a new function, say nfq_udp_get_payload_len2(), to give the expected answer?

AND, should the new or updated function guard against returning a -ve result? (which, being unsigned, would become a large +ve result)

Any opinions?

Cheers ... Duncan.

#1 lore raw

On Sun, Dec 08, 2019 at 02:49:30PM +1100, Duncan Roe wrote:
[...]

Quoted 2 lines

Should I change the behaviour of nfq_udp_get_payload_len() to what one would expect? (e.g. return 4 in the example above)

This option, just fix it, please.

Thanks.

author
#2 lore raw

PATCH 1/1 src: Fix value returned by nfq_udp_get_payload_len()

Updated:

src/extra/udp.c: Remember to subtract the UDP header length

---
 src/extra/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/extra/udp.c +1 -1
index fed23e2..eb301f2 100644
@@ -78,7 +78,7 @@ void *nfq_udp_get_payload(struct udphdr *udph, struct pkt_buff *pktb)
 EXPORT_SYMBOL
 unsigned int nfq_udp_get_payload_len(struct udphdr *udph, struct pkt_buff *pktb)
 {
-	return pktb->tail - pktb->transport_header;
+	return pktb->tail - pktb->transport_header - sizeof(struct udphdr);
 }
 
 /**
Signature · 1 line
2.14.5
maintainer Applied
#3 lore raw

Re: [PATCH libnetfilter_queue] src: Fix value returned by nfq_udp_get_payload_len()

Applied, thanks.