diff options
author | Thomas Haller <thaller@redhat.com> | 2021-03-03 21:46:05 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-03-05 11:09:14 +0100 |
commit | ec22551ce9b59efe5437a5d440c331e5d74bd622 (patch) | |
tree | 2c11079232209742642232f6ac780690f610025b | |
parent | 2ab87642f6ba2a4d24dd079242a1e1330b70b7bd (diff) | |
download | NetworkManager-ec22551ce9b59efe5437a5d440c331e5d74bd622.tar.gz |
glib-aux: move NMUtilsIPv6IfaceId struct to libnm-glib-aux
-rw-r--r-- | src/core/nm-core-utils.c | 83 | ||||
-rw-r--r-- | src/core/nm-core-utils.h | 43 | ||||
-rw-r--r-- | src/core/nm-types.h | 3 | ||||
-rw-r--r-- | src/libnm-core-impl/nm-utils.c | 23 | ||||
-rw-r--r-- | src/libnm-core-intern/nm-core-internal.h | 2 | ||||
-rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.c | 106 | ||||
-rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.h | 45 |
7 files changed, 151 insertions, 154 deletions
diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index 14f2adc4cd..3f4d5db27d 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -3376,89 +3376,6 @@ nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, /*****************************************************************************/ -/** - * nm_utils_ipv6_addr_set_interface_identifier: - * @addr: output token encoded as %in6_addr - * @iid: %NMUtilsIPv6IfaceId interface identifier - * - * Converts the %NMUtilsIPv6IfaceId to an %in6_addr (suitable for use - * with Linux platform). This only copies the lower 8 bytes, ignoring - * the /64 network prefix which is expected to be all-zero for a valid - * token. - */ -void -nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr *addr, const NMUtilsIPv6IfaceId iid) -{ - memcpy(addr->s6_addr + 8, &iid.id_u8, 8); -} - -/** - * nm_utils_ipv6_interface_identifier_get_from_addr: - * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token - * @addr: token encoded as %in6_addr - * - * Converts the %in6_addr encoded token (as used by Linux platform) to - * the interface identifier. - */ -void -nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, - const struct in6_addr *addr) -{ - memcpy(iid, addr->s6_addr + 8, 8); -} - -/** - * nm_utils_ipv6_interface_identifier_get_from_token: - * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token - * @token: token encoded as string - * - * Converts the %in6_addr encoded token (as used in ip6 settings) to - * the interface identifier. - * - * Returns: %TRUE if the @token is a valid token, %FALSE otherwise - */ -gboolean -nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, const char *token) -{ - struct in6_addr i6_token; - - g_return_val_if_fail(token, FALSE); - - if (!inet_pton(AF_INET6, token, &i6_token)) - return FALSE; - - if (!_nm_utils_inet6_is_token(&i6_token)) - return FALSE; - - nm_utils_ipv6_interface_identifier_get_from_addr(iid, &i6_token); - return TRUE; -} - -/** - * nm_utils_inet6_interface_identifier_to_token: - * @iid: %NMUtilsIPv6IfaceId interface identifier - * @buf: the destination buffer of at least %NM_UTILS_INET_ADDRSTRLEN - * bytes. - * - * Converts the interface identifier to a string token. - * - * Returns: the input buffer filled with the id as string. - */ -const char * -nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, - char buf[static INET6_ADDRSTRLEN]) -{ - struct in6_addr i6_token = {.s6_addr = { - 0, - }}; - - nm_assert(buf); - nm_utils_ipv6_addr_set_interface_identifier(&i6_token, iid); - return _nm_utils_inet6_ntop(&i6_token, buf); -} - -/*****************************************************************************/ - char * nm_utils_stable_id_random(void) { diff --git a/src/core/nm-core-utils.h b/src/core/nm-core-utils.h index 9591e9b08d..8f4bf786b6 100644 --- a/src/core/nm-core-utils.h +++ b/src/core/nm-core-utils.h @@ -342,49 +342,6 @@ nm_utils_arp_type_get_hwaddr_relevant_part(int arp_type, const guint8 **hwaddr, /*****************************************************************************/ -/* IPv6 Interface Identifier helpers */ - -/** - * NMUtilsIPv6IfaceId: - * @id: convenience member for validity checking; never use directly - * @id_u8: the 64-bit Interface Identifier - * - * Holds a 64-bit IPv6 Interface Identifier. The IID is a sequence of bytes - * and should not normally be treated as a %guint64, but this is done for - * convenience of validity checking and initialization. - */ -struct _NMUtilsIPv6IfaceId { - union { - guint64 id; - guint8 id_u8[8]; - }; -}; - -#define NM_UTILS_IPV6_IFACE_ID_INIT \ - { \ - { \ - .id = 0 \ - } \ - } - -void nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr * addr, - const NMUtilsIPv6IfaceId iid); - -void nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, - const struct in6_addr *addr); - -gboolean nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, - const char * token); - -const char *nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, - char buf[static INET6_ADDRSTRLEN]); - -gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, - const guint8 * hwaddr, - guint len, - guint dev_id, - NMUtilsIPv6IfaceId *out_iid); - typedef enum { /* The stable type. Note that this value is encoded in the * generated addresses, thus the numbers MUST not change. diff --git a/src/core/nm-types.h b/src/core/nm-types.h index 882de865e5..b0454d4df4 100644 --- a/src/core/nm-types.h +++ b/src/core/nm-types.h @@ -182,9 +182,6 @@ typedef struct _NMSecretAgent NMSecretAgent; typedef struct _NMSettings NMSettings; typedef struct _NMSettingsConnection NMSettingsConnection; -/* utils */ -typedef struct _NMUtilsIPv6IfaceId NMUtilsIPv6IfaceId; - #define NM_SETTING_CONNECTION_MDNS_UNKNOWN ((NMSettingConnectionMdns) -42) #endif /* NM_TYPES_H */ diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 4a85e89acc..61e380e010 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -4786,29 +4786,6 @@ nm_utils_ipaddr_valid(int family, const char *ip) } /** - * nm_utils_iinet6_is_token: - * @in6addr: the AF_INET6 address structure - * - * Checks if only the bottom 64bits of the address are set. - * - * Return value: %TRUE or %FALSE - */ -gboolean -_nm_utils_inet6_is_token(const struct in6_addr *in6addr) -{ - if (in6addr->s6_addr[0] || in6addr->s6_addr[1] || in6addr->s6_addr[2] || in6addr->s6_addr[3] - || in6addr->s6_addr[4] || in6addr->s6_addr[5] || in6addr->s6_addr[6] || in6addr->s6_addr[7]) - return FALSE; - - if (in6addr->s6_addr[8] || in6addr->s6_addr[9] || in6addr->s6_addr[10] || in6addr->s6_addr[11] - || in6addr->s6_addr[12] || in6addr->s6_addr[13] || in6addr->s6_addr[14] - || in6addr->s6_addr[15]) - return TRUE; - - return FALSE; -} - -/** * _nm_utils_dhcp_duid_valid: * @duid: the candidate DUID * diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 6721a35913..0a91c78eeb 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -631,8 +631,6 @@ gboolean _nm_setting_bond_option_supported(const char *option, NMBondMode mode); NMSettingBluetooth *_nm_connection_get_setting_bluetooth_for_nap(NMConnection *connection); -gboolean _nm_utils_inet6_is_token(const struct in6_addr *in6addr); - /*****************************************************************************/ NMTeamLinkWatcher *_nm_team_link_watcher_ref(NMTeamLinkWatcher *watcher); diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index ec3d1259e5..bec6bbf67b 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -105,6 +105,112 @@ G_STATIC_ASSERT(ETH_ALEN == 6); /*****************************************************************************/ +/** + * nm_utils_inet6_is_token: + * @in6addr: the AF_INET6 address structure + * + * Checks if only the bottom 64bits of the address are set. + * + * Return value: %TRUE or %FALSE + */ +gboolean +_nm_utils_inet6_is_token(const struct in6_addr *in6addr) +{ + if (in6addr->s6_addr[0] || in6addr->s6_addr[1] || in6addr->s6_addr[2] || in6addr->s6_addr[3] + || in6addr->s6_addr[4] || in6addr->s6_addr[5] || in6addr->s6_addr[6] || in6addr->s6_addr[7]) + return FALSE; + + if (in6addr->s6_addr[8] || in6addr->s6_addr[9] || in6addr->s6_addr[10] || in6addr->s6_addr[11] + || in6addr->s6_addr[12] || in6addr->s6_addr[13] || in6addr->s6_addr[14] + || in6addr->s6_addr[15]) + return TRUE; + + return FALSE; +} + +/** + * nm_utils_ipv6_addr_set_interface_identifier: + * @addr: output token encoded as %in6_addr + * @iid: %NMUtilsIPv6IfaceId interface identifier + * + * Converts the %NMUtilsIPv6IfaceId to an %in6_addr (suitable for use + * with Linux platform). This only copies the lower 8 bytes, ignoring + * the /64 network prefix which is expected to be all-zero for a valid + * token. + */ +void +nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr *addr, const NMUtilsIPv6IfaceId iid) +{ + memcpy(addr->s6_addr + 8, &iid.id_u8, 8); +} + +/** + * nm_utils_ipv6_interface_identifier_get_from_addr: + * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token + * @addr: token encoded as %in6_addr + * + * Converts the %in6_addr encoded token (as used by Linux platform) to + * the interface identifier. + */ +void +nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, + const struct in6_addr *addr) +{ + memcpy(iid, addr->s6_addr + 8, 8); +} + +/** + * nm_utils_ipv6_interface_identifier_get_from_token: + * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token + * @token: token encoded as string + * + * Converts the %in6_addr encoded token (as used in ip6 settings) to + * the interface identifier. + * + * Returns: %TRUE if the @token is a valid token, %FALSE otherwise + */ +gboolean +nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, const char *token) +{ + struct in6_addr i6_token; + + g_return_val_if_fail(token, FALSE); + + if (!inet_pton(AF_INET6, token, &i6_token)) + return FALSE; + + if (!_nm_utils_inet6_is_token(&i6_token)) + return FALSE; + + nm_utils_ipv6_interface_identifier_get_from_addr(iid, &i6_token); + return TRUE; +} + +/** + * nm_utils_inet6_interface_identifier_to_token: + * @iid: %NMUtilsIPv6IfaceId interface identifier + * @buf: the destination buffer of at least %NM_UTILS_INET_ADDRSTRLEN + * bytes. + * + * Converts the interface identifier to a string token. + * + * Returns: the input buffer filled with the id as string. + */ +const char * +nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, + char buf[static INET6_ADDRSTRLEN]) +{ + struct in6_addr i6_token = {.s6_addr = { + 0, + }}; + + nm_assert(buf); + nm_utils_ipv6_addr_set_interface_identifier(&i6_token, iid); + return _nm_utils_inet6_ntop(&i6_token, buf); +} + +/*****************************************************************************/ + pid_t nm_utils_gettid(void) { diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 48a2b50e2d..37f1402259 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -174,6 +174,8 @@ nm_link_type_supports_slaves(NMLinkType link_type) /*****************************************************************************/ +gboolean _nm_utils_inet6_is_token(const struct in6_addr *in6addr); + typedef struct { guint8 ether_addr_octet[6 /*ETH_ALEN*/]; } NMEtherAddr; @@ -308,6 +310,49 @@ nm_utils_ether_addr_equal(const struct ether_addr *a1, const struct ether_addr * /*****************************************************************************/ +/** + * NMUtilsIPv6IfaceId: + * @id: convenience member for validity checking; never use directly + * @id_u8: the 64-bit Interface Identifier + * + * Holds a 64-bit IPv6 Interface Identifier. The IID is a sequence of bytes + * and should not normally be treated as a %guint64, but this is done for + * convenience of validity checking and initialization. + */ +typedef struct _NMUtilsIPv6IfaceId { + union { + guint64 id; + guint8 id_u8[8]; + }; +} NMUtilsIPv6IfaceId; + +#define NM_UTILS_IPV6_IFACE_ID_INIT \ + { \ + { \ + .id = 0 \ + } \ + } + +void nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr * addr, + const NMUtilsIPv6IfaceId iid); + +void nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, + const struct in6_addr *addr); + +gboolean nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, + const char * token); + +const char *nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, + char buf[static INET6_ADDRSTRLEN]); + +gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, + const guint8 * hwaddr, + guint len, + guint dev_id, + NMUtilsIPv6IfaceId *out_iid); + +/*****************************************************************************/ + #define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN static inline const char * |