Merge pull request #20865 from keszybz/meson-net-naming-definitions

Allow defining new naming scheme entries as configuration time
This commit is contained in:
Yu Watanabe
2021-09-29 12:29:14 +09:00
committed by GitHub
6 changed files with 78 additions and 9 deletions
+17 -7
View File
@@ -5,6 +5,13 @@
#include "proc-cmdline.h"
#include "string-util.h"
#ifdef _DEFAULT_NET_NAMING_SCHEME_TEST
/* The primary purpose of this check is to verify that _DEFAULT_NET_NAMING_SCHEME_TEST
* is a valid identifier. If an invalid name is given during configuration, this will
* fail with a name error. */
assert_cc(_DEFAULT_NET_NAMING_SCHEME_TEST >= 0);
#endif
static const NamingScheme naming_schemes[] = {
{ "v238", NAMING_V238 },
{ "v239", NAMING_V239 },
@@ -15,19 +22,22 @@ static const NamingScheme naming_schemes[] = {
{ "v247", NAMING_V247 },
{ "v249", NAMING_V249 },
/* … add more schemes here, as the logic to name devices is updated … */
/* also remember to update the list of options in meson_options.txt */
EXTRA_NET_NAMING_MAP
};
static const NamingScheme* naming_scheme_from_name(const char *name) {
size_t i;
const NamingScheme* naming_scheme_from_name(const char *name) {
/* "latest" may either be defined explicitly by the extra map, in which case we we will find it in
* the table like any other name. After iterating through the table, we check for "latest" again,
* which means that if not mapped explicitly, it maps to the last defined entry, whatever that is. */
for (size_t i = 0; i < ELEMENTSOF(naming_schemes); i++)
if (streq(naming_schemes[i].name, name))
return naming_schemes + i;
if (streq(name, "latest"))
return naming_schemes + ELEMENTSOF(naming_schemes) - 1;
for (i = 0; i < ELEMENTSOF(naming_schemes); i++)
if (streq(naming_schemes[i].name, name))
return naming_schemes + i;
return NULL;
}
+3
View File
@@ -46,6 +46,8 @@ typedef enum NamingSchemeFlags {
NAMING_V247 = NAMING_V245 | NAMING_BRIDGE_NO_SLOT,
NAMING_V249 = NAMING_V247 | NAMING_SLOT_FUNCTION_ID | NAMING_16BIT_INDEX | NAMING_REPLACE_STRICTLY,
EXTRA_NET_NAMING_SCHEMES
_NAMING_SCHEME_FLAGS_INVALID = -EINVAL,
} NamingSchemeFlags;
@@ -54,6 +56,7 @@ typedef struct NamingScheme {
NamingSchemeFlags flags;
} NamingScheme;
const NamingScheme* naming_scheme_from_name(const char *name);
const NamingScheme* naming_scheme(void);
static inline bool naming_scheme_has(NamingSchemeFlags flags) {