netfilter: nfnetlink_queue: unbreak SCTP traffic
Subsystems (3)
Pablo Neira Ayuso
maintainerPATCH v4 1/2 netfilter: nfnetlink_queue: unbreak SCTP traffic
From: Antonio Ojea <[email protected]>
when packet is enqueued with nfqueue and GSO is enabled, checksum calculation has to take into account the protocol, as SCTP uses a 32 bits CRC checksum.
Enter skb_gso_segment() path in case of SCTP GSO packets because skb_zerocopy() does not support for GSO_BY_FRAGS.
Signed-off-by Antonio Ojea <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v4: - missing EXPORT_SYMBOL
- enter skb_gso_segment() with SCTP GSO packets.
net/core/dev.c | 1 + net/netfilter/nfnetlink_queue.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
net/core/dev.c +1 -0
@@ -3384,6 +3384,7 @@ int skb_crc32c_csum_help(struct sk_buff *skb) out:return ret; } +EXPORT_SYMBOL (skb_crc32c_csum_help);__be16 skb_network_protocol (struct sk_buff *skb,int *depth) {
net/netfilter/nfnetlink_queue.c +10 -2
@@ -540,6 +540,14 @@ static int nfqnl_put_bridge(struct nf_queue_entry *entry, struct sk_buff *skb)return -1 ; } +static int nf_queue_checksum_help (struct sk_buff *entskb) +{ +if (skb_csum_is_sctp (entskb)) +return skb_crc32c_csum_help (entskb); + +return skb_checksum_help (entskb); +} +static struct sk_buff * nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, struct nf_queue_entry *entry,
@@ -602,7 +610,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,case NFQNL_COPY_PACKET :if (!(queue->flags &NFQA_CFG_F_GSO ) && entskb->ip_summed ==CHECKSUM_PARTIAL && -skb_checksum_help (entskb)) +nf_queue_checksum_help (entskb))return NULL ; data_len =READ_ONCE (queue->copy_range);
@@ -983,7 +991,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)break ; } -if ((queue->flags &NFQA_CFG_F_GSO ) || !skb_is_gso (skb)) +if (!skb_is_gso (skb) || ((queue->flags &NFQA_CFG_F_GSO ) && !skb_is_gso_sctp (skb)))return __nfqnl_enqueue_packet (net, queue, entry);nf_bridge_adjust_skb_data (skb);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v4 2/2 selftests: net: netfilter: nft_queue.sh: sctp coverage
From: Antonio Ojea <[email protected]>
Test that nfqueue with and without GSO process SCTP packets correctly.
Signed-off-by Antonio Ojea <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v4: - use ss -S to detect listener socket reliably.
- add test to cover SCTP GSO from output path.
.../selftests/net/netfilter/nft_queue.sh | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+)
tools/testing/selftests/net/netfilter/nft_queue.sh +76 -0
@@ -25,6 +25,9 @@ cleanup() } checktool "nft --version" "test without nft tool" +checktool "socat -h" "run test without socat" + +modprobe -q sctp trap cleanup EXIT
@@ -375,6 +378,77 @@ EOF wait 2>/dev/null } +sctp_listener_ready() +{ + ss -S -N "$1" -lnt -o "sport = :12345" | grep -q 12345 +} + +test_sctp_forward() +{ + ip netns exec "$nsrouter" nft -f /dev/stdin <<EOF +table inet sctpq { + chain forward { + type filter hook forward priority 0; policy accept; + sctp dport 12345 queue num 10 + } +} +EOF + ip netns exec "$nsrouter" ./nf_queue -q 10 -G -t "$timeout" & + local nfqpid=$! + + timeout 60 ip netns exec "$ns2" socat -u SCTP-LISTEN:12345 STDOUT > "$TMPFILE1" & + local rpid=$! + + busywait "$BUSYWAIT_TIMEOUT" sctp_listener_ready "$ns2" + + ip netns exec "$ns1" socat -u STDIN SCTP:10.0.2.99:12345 <"$TMPINPUT" >/dev/null + + if ! ip netns exec "$nsrouter" nft delete table inet sctpq; then + echo "FAIL: Could not delete sctpq table" + exit 1 + fi + + if ! diff -u "$TMPINPUT" "$TMPFILE1" ; then + echo "FAIL: lost packets?!" 1>&2 + return + fi + + wait "$rpid" && echo "PASS: sctp and nfqueue in forward chain" +} + +test_sctp_output() +{ + ip netns exec "$ns1" nft -f /dev/stdin <<EOF +table inet sctpq { + chain output { + type filter hook output priority 0; policy accept; + sctp dport 12345 queue num 11 + } +} +EOF + ip netns exec "$ns1" ./nf_queue -q 11 -t "$timeout" & + local nfqpid=$! + + timeout 60 ip netns exec "$ns2" socat -u SCTP-LISTEN:12345 STDOUT > "$TMPFILE1" & + local rpid=$! + + busywait "$BUSYWAIT_TIMEOUT" sctp_listener_ready "$ns2" + + ip netns exec "$ns1" socat -u STDIN SCTP:10.0.2.99:12345 <"$TMPINPUT" >/dev/null + + if ! ip netns exec "$ns1" nft delete table inet sctpq; then + echo "FAIL: Could not delete sctpq table" + exit 1 + fi + + if ! diff -u "$TMPINPUT" "$TMPFILE1" ; then + echo "FAIL: lost packets?!" 1>&2 + return + fi + + wait "$rpid" && echo "PASS: sctp and nfqueue in output chain with GSO" +} + ip netns exec "$nsrouter" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
@@ -413,5 +487,7 @@ test_tcp_localhost test_tcp_localhost_connectclose test_tcp_localhost_requeue test_icmp_vrf +test_sctp_forward +test_sctp_output exit $ret
Signature · 1 line
2.30.2