mbox series

[iproute2-next,0/3] Change parse_one_of(), parse_on_off() to strcmp()

Message ID cover.1700061513.git.petrm@nvidia.com (mailing list archive)
Headers show
Series Change parse_one_of(), parse_on_off() to strcmp() | expand

Message

Petr Machata Nov. 15, 2023, 3:31 p.m. UTC
Library functions parse_one_of() and parse_on_off() were added about three
years ago to unify all the disparate reimplementations of the same basic
idea. It used the matches() function to determine whether a string under
consideration corresponds to one of the patterns. This reflected many,
though not all cases of on/off parsing at the time.

This decision has some odd consequences. In particular, "o" can be used as
a shorthand for "off", which is not obvious, because "o" is the prefix of
both. By sheer luck, the end result actually makes some sense: "on" means
on, anything else either means off or errors out. Similar issues are in
principle also possible for parse_one_of() uses, though currently this does
not come up.

Ideally parse_on_off() would accept the strings "on" and "off" and no
others, likewise for parse_one_of().

Hence this patchset, which renames the existing functions to
parse_one_of_deprecated() and parse_on_off_deprecated(), respectively,
and introduces the new functions in their place, parse_one_of() and
parse_on_off(), which use strcmp() under the hood.

Petr Machata (3):
  lib: utils: Switch matches() to returning int again
  lib: utils: Generalize code of parse_one_of(), parse_on_off()
  lib: utils: Add parse_one_of_deprecated(), parse_on_off_deprecated()

 bridge/link.c            | 48 ++++++++++++++++++++++++++--------------
 bridge/vlan.c            |  4 ++--
 dcb/dcb_ets.c            |  6 +++--
 dcb/dcb_pfc.c            |  5 +++--
 include/utils.h          |  6 ++++-
 ip/iplink.c              | 15 ++++++++-----
 ip/iplink_bridge_slave.c |  2 +-
 ip/ipmacsec.c            | 27 +++++++++++++---------
 ip/ipstats.c             |  3 ++-
 lib/utils.c              | 44 ++++++++++++++++++++++++++++--------
 10 files changed, 109 insertions(+), 51 deletions(-)