diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-12-14 11:26:44 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-12-16 01:55:37 +0900 |
commit | ff516b4341eb869b450ab0c0e0d7fd0bd555e99f (patch) | |
tree | a7d750131b2c8e5d995014cd3b6aac7aa3014e27 | |
parent | eb3e86ae2c62570d0a138ef15a120f1be183f192 (diff) | |
download | systemd-ff516b4341eb869b450ab0c0e0d7fd0bd555e99f.tar.gz |
udev: move NamePolicy to netif-naming-scheme.[ch]
-rw-r--r-- | src/shared/netif-naming-scheme.c | 23 | ||||
-rw-r--r-- | src/shared/netif-naming-scheme.h | 18 | ||||
-rw-r--r-- | src/udev/net/link-config.c | 21 | ||||
-rw-r--r-- | src/udev/net/link-config.h | 19 |
4 files changed, 42 insertions, 39 deletions
diff --git a/src/shared/netif-naming-scheme.c b/src/shared/netif-naming-scheme.c index 8d03e0e5e7..245466c4cb 100644 --- a/src/shared/netif-naming-scheme.c +++ b/src/shared/netif-naming-scheme.c @@ -4,6 +4,7 @@ #include "netif-naming-scheme.h" #include "proc-cmdline.h" #include "string-util.h" +#include "string-table.h" #ifdef _DEFAULT_NET_NAMING_SCHEME_TEST /* The primary purpose of this check is to verify that _DEFAULT_NET_NAMING_SCHEME_TEST @@ -80,3 +81,25 @@ const NamingScheme* naming_scheme(void) { return cache; } + +static const char* const name_policy_table[_NAMEPOLICY_MAX] = { + [NAMEPOLICY_KERNEL] = "kernel", + [NAMEPOLICY_KEEP] = "keep", + [NAMEPOLICY_DATABASE] = "database", + [NAMEPOLICY_ONBOARD] = "onboard", + [NAMEPOLICY_SLOT] = "slot", + [NAMEPOLICY_PATH] = "path", + [NAMEPOLICY_MAC] = "mac", +}; + +DEFINE_STRING_TABLE_LOOKUP(name_policy, NamePolicy); + +static const char* const alternative_names_policy_table[_NAMEPOLICY_MAX] = { + [NAMEPOLICY_DATABASE] = "database", + [NAMEPOLICY_ONBOARD] = "onboard", + [NAMEPOLICY_SLOT] = "slot", + [NAMEPOLICY_PATH] = "path", + [NAMEPOLICY_MAC] = "mac", +}; + +DEFINE_STRING_TABLE_LOOKUP(alternative_names_policy, NamePolicy); diff --git a/src/shared/netif-naming-scheme.h b/src/shared/netif-naming-scheme.h index 11ce6e62ee..16b304ce10 100644 --- a/src/shared/netif-naming-scheme.h +++ b/src/shared/netif-naming-scheme.h @@ -64,3 +64,21 @@ const NamingScheme* naming_scheme(void); static inline bool naming_scheme_has(NamingSchemeFlags flags) { return FLAGS_SET(naming_scheme()->flags, flags); } + +typedef enum NamePolicy { + NAMEPOLICY_KERNEL, + NAMEPOLICY_KEEP, + NAMEPOLICY_DATABASE, + NAMEPOLICY_ONBOARD, + NAMEPOLICY_SLOT, + NAMEPOLICY_PATH, + NAMEPOLICY_MAC, + _NAMEPOLICY_MAX, + _NAMEPOLICY_INVALID = -EINVAL, +} NamePolicy; + +const char *name_policy_to_string(NamePolicy p) _const_; +NamePolicy name_policy_from_string(const char *p) _pure_; + +const char *alternative_names_policy_to_string(NamePolicy p) _const_; +NamePolicy alternative_names_policy_from_string(const char *p) _pure_; diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 880de0baf5..05f0f2e0a6 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -22,7 +22,6 @@ #include "log-link.h" #include "memory-util.h" #include "net-condition.h" -#include "netif-naming-scheme.h" #include "netif-util.h" #include "netlink-util.h" #include "parse-util.h" @@ -1032,30 +1031,10 @@ DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT( MAC_ADDRESS_POLICY_NONE, "Failed to parse MAC address policy"); -static const char* const name_policy_table[_NAMEPOLICY_MAX] = { - [NAMEPOLICY_KERNEL] = "kernel", - [NAMEPOLICY_KEEP] = "keep", - [NAMEPOLICY_DATABASE] = "database", - [NAMEPOLICY_ONBOARD] = "onboard", - [NAMEPOLICY_SLOT] = "slot", - [NAMEPOLICY_PATH] = "path", - [NAMEPOLICY_MAC] = "mac", -}; - -DEFINE_STRING_TABLE_LOOKUP(name_policy, NamePolicy); DEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy, _NAMEPOLICY_INVALID, "Failed to parse interface name policy"); -static const char* const alternative_names_policy_table[_NAMEPOLICY_MAX] = { - [NAMEPOLICY_DATABASE] = "database", - [NAMEPOLICY_ONBOARD] = "onboard", - [NAMEPOLICY_SLOT] = "slot", - [NAMEPOLICY_PATH] = "path", - [NAMEPOLICY_MAC] = "mac", -}; - -DEFINE_STRING_TABLE_LOOKUP(alternative_names_policy, NamePolicy); DEFINE_CONFIG_PARSE_ENUMV(config_parse_alternative_names_policy, alternative_names_policy, NamePolicy, _NAMEPOLICY_INVALID, "Failed to parse alternative names policy"); diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h index 092a6fa808..3b2cd69620 100644 --- a/src/udev/net/link-config.h +++ b/src/udev/net/link-config.h @@ -9,6 +9,7 @@ #include "ethtool-util.h" #include "list.h" #include "net-condition.h" +#include "netif-naming-scheme.h" typedef struct LinkConfigContext LinkConfigContext; typedef struct LinkConfig LinkConfig; @@ -21,18 +22,6 @@ typedef enum MACAddressPolicy { _MAC_ADDRESS_POLICY_INVALID = -EINVAL, } MACAddressPolicy; -typedef enum NamePolicy { - NAMEPOLICY_KERNEL, - NAMEPOLICY_KEEP, - NAMEPOLICY_DATABASE, - NAMEPOLICY_ONBOARD, - NAMEPOLICY_SLOT, - NAMEPOLICY_PATH, - NAMEPOLICY_MAC, - _NAMEPOLICY_MAX, - _NAMEPOLICY_INVALID = -EINVAL, -} NamePolicy; - typedef struct Link { int ifindex; const char *ifname; @@ -105,12 +94,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free); int link_get_config(LinkConfigContext *ctx, Link *link); int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link); -const char *name_policy_to_string(NamePolicy p) _const_; -NamePolicy name_policy_from_string(const char *p) _pure_; - -const char *alternative_names_policy_to_string(NamePolicy p) _const_; -NamePolicy alternative_names_policy_from_string(const char *p) _pure_; - const char *mac_address_policy_to_string(MACAddressPolicy p) _const_; MACAddressPolicy mac_address_policy_from_string(const char *p) _pure_; |