6
24
Fork
You've already forked ifstate
13

routing: allow comments in iproute2 lookup tables #162

Merged
liske merged 1 commit from jantore/ifstate:rt-table-comments into master 2026年03月10日 21:57:19 +01:00
Contributor
Copy link

iproute2 allows comments in rt_tables and similar lookup tables (see
lib/rt_names.c in iproute2). This commit extends the regular
expression that parses table entries to match this behavior.

iproute2 allows comments in rt_tables and similar lookup tables (see lib/rt_names.c in iproute2). This commit extends the regular expression that parses table entries to match this behavior.
@ -217,3 +217,3 @@
def _parse(self, fp):
for line in fp:
m = re.search(r'^(\d+)\s+(\S+)$', line)
m = re.search(r'^(\d+)\s+(\S+)(?:\s+\#.*)?$', line)
Owner
Copy link

The reference is lib/rt_names.c#L49-L52, isn't it?

Thanks for bringing this up! IMHO ifstate should also support hex notation.

Do you like to extend this PR to add hex notation support?

The reference is [lib/rt_names.c#L49-L52](https://github.com/iproute2/iproute2/blob/b7d23e62224ff3c18611c962c76a937b1ce29191/lib/rt_names.c#L49-L52), isn't it? Thanks for bringing this up! IMHO ifstate should also support hex notation. Do you like to extend this PR to add hex notation support?
Author
Contributor
Copy link

Yep, that's the correct reference. I took the easy way out and hoped you wouldn't notice the hexadecimals. ;-)

I can certainly add support for that as well. Will have a look as soon as I have a moment; shouldn't be too long.

Yep, that's the correct reference. I took the easy way out and hoped you wouldn't notice the hexadecimals. ;-) I can certainly add support for that as well. Will have a look as soon as I have a moment; shouldn't be too long.
Author
Contributor
Copy link

I just pushed an updated version with support for hex.

I just pushed an updated version with support for hex.
liske marked this conversation as resolved
liske added this to the 2.2.5 milestone 2026年03月09日 17:40:39 +01:00
jantore changed title from (削除) routing: allow comments in iproute2 lookup tables (削除ここまで) to WIP: routing: allow comments in iproute2 lookup tables 2026年03月09日 18:29:56 +01:00
jantore force-pushed rt-table-comments from 427e7572b3
Some checks are pending
pull request build test / build (pull_request) Blocked by required conditions
to 6d05f73537
Some checks are pending
pull request build test / build (pull_request) Blocked by required conditions
2026年03月10日 08:44:57 +01:00
Compare
jantore changed title from (削除) WIP: routing: allow comments in iproute2 lookup tables (削除ここまで) to routing: allow comments in iproute2 lookup tables 2026年03月10日 08:50:54 +01:00
jantore force-pushed rt-table-comments from 6d05f73537
Some checks are pending
pull request build test / build (pull_request) Blocked by required conditions
to 20a5a101d1
Some checks are pending
pull request build test / build (pull_request) Blocked by required conditions
2026年03月10日 08:51:50 +01:00
Compare
@ -215,11 +215,22 @@ class RTLookup():
pass
def _parse(self, fp):
pattern = re.compile(r'^(?:0[xX](?P<hex>[\da-fA-F]+)|(?P<decimal>\d+))\s+(?P<name>\S+)(?:\s+\#.*)?$')
Owner
Copy link

The iproute2 implementation doesn't allow an upper X. So we should not accept it either to mimic the same behavior.

The iproute2 implementation doesn't allow an upper `X`. So we should not accept it either to mimic the same behavior.
Author
Contributor
Copy link

Good catch. I was looking at the man page of sscanf() and it didn't quite sink in that this was a classic case of 0x0x. I've fixed the regex.

sscanf() will still allow lots of formats that [\da-fA-F]+ won't catch, though. Let's hope no one expects 0x-0xffffffeb to work...

Good catch. I was looking at the man page of `sscanf()` and it didn't quite sink in that this was a classic case of `0x0x`. I've fixed the regex. `sscanf()` will still allow lots of formats that `[\da-fA-F]+` won't catch, though. Let's hope no one expects `0x-0xffffffeb` to work...
Owner
Copy link

I'm still irritated that there is not scanf-like implementation available in the python core libs. 😒

IMHO it is OK that we do not support such edge cases. Thanks for your work, again!

I'm still irritated that there is not scanf-like implementation available in the python core libs. 😒 IMHO it is OK that we do not support such edge cases. Thanks for your work, again!
liske marked this conversation as resolved
jantore force-pushed rt-table-comments from 20a5a101d1
Some checks are pending
pull request build test / build (pull_request) Blocked by required conditions
to 45f84f2e54
Some checks failed
pull request build test / build (pull_request) Has been cancelled
2026年03月10日 15:21:40 +01:00
Compare
Some checks failed
pull request build test / build (pull_request) Has been cancelled
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
bug
Something isn't working
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
more info
Further details are required, the problem may not yet be reproducible, yet
question
Further information is requested
TBD
To be discussed
wontfix
This will not be worked on
AI slop
Burning out
bug
Something is not working
contribution welcome
Contributions are very welcome, get started here
duplicate
This issue or pull request already exists
enhancement
New feature
good first issue
Interested in contributing? Get started here.
help wanted
Need some help
invalid
Something is wrong
question
More information is needed
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
routerkit/ifstate!162
Reference in a new issue
routerkit/ifstate
No description provided.
Delete branch "jantore/ifstate:rt-table-comments"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?