]> git.proxmox.com Git - mirror_iproute2.git/commit - lib/utils.c
lib: Generalize parse_mapping()
authorPetr Machata <me@pmachata.org>
Sat, 2 Jan 2021 00:03:36 +0000 (01:03 +0100)
committerDavid Ahern <dsahern@kernel.org>
Mon, 18 Jan 2021 04:09:29 +0000 (04:09 +0000)
commitc13216f7a66ae470c19c450e5e5d1f44bbbb3dba
tree7e6c5410eb26878f5e7fdec841337354e573fcb1
parentbf244ee6773486892e3223972afa07f5ab3b66bb
lib: Generalize parse_mapping()

The function parse_mapping() assumes the key is a number, with a single
configurable exception, which is using "all" to mean "all possible keys".
If a caller wishes to use symbolic names instead of numbers, they cannot
reuse this function.

To facilitate reuse in these situations, convert parse_mapping() into a
helper, parse_mapping_gen(), which instead of an allow-all boolean takes a
generic key-parsing callback. Rewrite parse_mapping() in terms of this
newly-added helper and add a pair of key parsers, one for just numbers,
another for numbers and the keyword "all". Publish the latter as well.

Signed-off-by: Petr Machata <me@pmachata.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/utils.h
lib/utils.c