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.
routing: allow comments in iproute2 lookup tables #162
jantore/ifstate:rt-table-comments into master @ -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)
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?
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.
I just pushed an updated version with support for hex.
427e7572b3
6d05f73537
6d05f73537
20a5a101d1
@ -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+\#.*)?$')
The iproute2 implementation doesn't allow an upper X. So we should not accept it either to mimic the same behavior.
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...
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!
20a5a101d1
45f84f2e54
No due date set.
No dependencies set.
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?