Repository navigation
v1.61.0: port-match-never-matches (warning) and port-option-repeated (error) - #89
Merged
Merged
Conversation
…(error)
Two constraints on the same port side with nothing in common make a rule that
loads and never matches: `-p tcp --dport 443 -m multiport --dports 80,8080`,
two multiport lists, two `-m tcp --dport` matches, a range next to a disjoint
list, the sport pair, and nft `tcp dport 443 tcp dport { 22, 80 }`. Measured
with real SYNs on both iptables backends and nft: 34 variants, linter and
kernel agree on all 34. On the nf_tables backend two tcp matches stay dead in
the kernel while iptables-nft-save prints only the last port, and restoring
that dump makes the rule live.
The same side twice in one tcp/udp match does not load at all ("Only one
`--destination-port' allowed", rc 2): that is port-option-repeated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two new linter smells for port matches that cannot hold together.
port-match-never-matches(warning). A packet has one destination port and one source port, and every match on a rule must hold at once. Two constraints on the same side with no port in common make a rule that loads (rc 0) and never matches. Covered: a stray--dportin front of a multiport list, two multiport lists, two-m tcp --dportmatches, a range next to a disjoint list, the--sport/--sportspair, udp, ip6tables, and nfttcp dport 443 tcp dport { 22, 80 }(alsoth dport, ranges, sets).port-option-repeated(error). The same side twice in one tcp/udp match (--dport 9100 --dport 9256) is refused with *Only one--destination-port' allowed* (or--source-port'`), rc 2, on both backends. The file loads nothing.Measured first (debian:13, iptables 1.8.11 nf_tables and legacy, nftables 1.1.3, real loads, real SYNs)
--dport 80+--dports 22,80,1000:2000+22,1500,--dport 22+20:30). So did what is deliberately not judged: multiport--ports(either side,--dport 443 --ports 22,80matched sport 22 and 80),--dportvs--sport, negations and port names.-m tcp --dport 22 -m tcp --dport 80(and implicit + explicit) stays in the kernel astcp dport 22 tcp dport 80(0 packets).iptables-nft-saveprints only-m tcp --dport 80, and restoring that dump makes the rule live (1 packet after the round trip). Legacy keeps both in its dump. The finding says so when it applies.:1023is saved as0:1023and handled. ip6tables measured on nf_tables only: the legacy ip6 table is not available on this kernel, so it is not claimed.How
iptPortConstraintsreuses the option-binding model ofmultiport-one-option(#84) and keeps the values;portSpecIntervals+intersectIntervalssit on the existingportIntervals. A rule that does not load is never also called dead: a repeat inside a tcp/udp match goes toport-option-repeated, and a second list inside a multiport staysmultiport-one-option. Sample iptables (--dport twice — won't load — + a port list that never matches) trips both.Checks
npm test382/382 (was 377),npm run lintclean.linter.jsthe 4 new tests and 2 guardians fail (376/382).🤖 Generated with Claude Code