mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 00:30:09 +01:00
glib-aux: move NMUtilsIPv6IfaceId struct to libnm-glib-aux
This commit is contained in:
parent
2ab87642f6
commit
ec22551ce9
7 changed files with 151 additions and 154 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -4785,29 +4785,6 @@ nm_utils_ipaddr_valid(int family, const char *ip)
|
|||
return nm_utils_ipaddr_is_valid(family, 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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue