Skip to content

ENT-14276: Refactor Addr lib - #6485

Open
victormlg wants to merge 22 commits into
cfengine:masterfrom
victormlg:addr_lib
Open

victormlg wants to merge 22 commits into
cfengine:masterfrom
victormlg:addr_lib

Conversation

@victormlg

Copy link
Copy Markdown
Contributor

No description provided.

@victormlg victormlg changed the title ENT-14276_ Refactor Addr lib ENT-14276: Refactor Addr lib Nov 9, 2026
Comment thread cf-serverd/server_access.c Fixed
Comment thread cf-serverd/server_access.c Fixed
Comment thread libcfnet/addr_lib.c Fixed
Comment thread libcfnet/addr_lib.c Fixed
Comment thread libcfnet/addr_lib.c Fixed
Comment thread libcfnet/addr_lib.c Fixed
Comment thread libcfnet/addr_lib.c Fixed
Comment thread libcfnet/addr_lib.c Fixed
Comment thread libcfnet/addr_lib.c Fixed
@victormlg
victormlg marked this pull request as ready for review November 9, 2026 16:17

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate each bug fix into their own commits with a changelog.

Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread cf-serverd/server_access.c Resolved
victormlg and others added 7 commits November 16, 2026 10:32
Covers the current behaviour, before refactoring them.

Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FuzzySetMatch() now returns -1 instead of the strncmp() result when a
prefix does not match. All callers only compare the result to 0.

Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FuzzySetMatch() now determines the notation of the pattern (prefix, CIDR
or range) and calls the matching helper.

Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread libcfnet/addr_lib.c Outdated
(address[len] == '\0' || address[len] == '.');
}

static bool MatchIPv4CIDR(const char *pattern, const char *address)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left off reviewing here in commit 47d645e

@craigcomstock craigcomstock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments, but looks good to me!

Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot's of great improvements. And it's much more digestible with smaller commits. Great work! 🚀

I'm a little bit uncertain if these functions should spam the error log. A normal use case could be to check is something is an IP address. In that case, I don't want to see a bunch of errors spammed to the logs if it's not. It would make me think that something is wrong. And also it would probably spam the system log. Maybe LOG_LEVEL_VERBOSE would be better option here?

I think the change log entries can also be phrased a bit better.

Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
Comment thread libcfnet/addr_lib.c Resolved
@larsewi larsewi added the cherry-pick? Fixes which may need to be cherry-picked to LTS branches label Nov 17, 2026
victormlg and others added 9 commits November 17, 2026 15:01
It now splits host and port first and determines the address type
afterwards, instead of doing both in each branch.

Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was never defined.

Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Groups without a range, e.g. "fe80", were parsed as decimal, so
"fe80:1-3:0:0:0:0:0:1" matched "fe81:2:0:0:0:0:0:1".

Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"2001:10-20:0:0:0:0:0:1" did not match "2001:10:0:0:0:0:0:1".

Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Neither in the pattern nor in the address, so "2001:db8:1-5::1" never
matched "2001:db8:3::1". Invalid groups are now rejected too.

Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ctet

When an octet failed to parse, the value of the previous octet was
compared instead, so "10.x.0.1-50" matched "10.10.0.25".

Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…re now rejected

The address was never validated, so an uninitialized address was
compared, and e.g. "bogus/0" matched every address.

Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ranges

FuzzyMatchParse() always returned true. It now uses the same parsers as
FuzzySetMatch(), including for CIDR patterns.

Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FuzzyHostMatch() read before the start of its buffer when the host name
was empty or only digits. Only visible with ASan/valgrind.

Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@victormlg
victormlg force-pushed the addr_lib branch 2 times, most recently from d32863c to b864e94 Compare November 18, 2026 07:53
@victormlg
victormlg requested a review from larsewi November 18, 2026 09:07

@larsewi larsewi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need some more context here in the change log. These are policy functions right? Maybe mention which ones. It's better to do this proper now, then the release manager having to figure this out. Sorry I did not mention this before.

Otherwise looks great!

victormlg and others added 6 commits November 18, 2026 11:56
… digit

It contained the host name, e.g. "1password.com", instead of its IP
address. ParseHostPort() now uses inet_pton() to detect IPv4.

Changelog: Title
Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There is nothing fuzzy about them. IPRangeMatch() and HostRangeMatch()
now return true on match, like StringMatch(), instead of 0.

Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The acl argument is always dereferenced.

Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… level

E.g. isipinsubnet("10.0.0.0/8", "not-an-ip-address") logged an error.
The same applies to IP lists in cf-serverd, e.g. admit_ips and allowconnects.

Changelog: Commit
Ticket: ENT-14276
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@larsewi

larsewi commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@cf-bottom Jenkins please :)

@cf-bottom

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick? Fixes which may need to be cherry-picked to LTS branches

Development

Successfully merging this pull request may close these issues.

5 participants