mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 12:50:33 +01:00
core: add hashing to IP config objects
We'll use this later to determine whether sets of IPxConfig objects have actually changed without comparing them all at once.
This commit is contained in:
parent
9966ac45fa
commit
90fb53de4c
4 changed files with 125 additions and 0 deletions
|
|
@ -813,6 +813,68 @@ nm_ip4_config_diff (NMIP4Config *a, NMIP4Config *b)
|
|||
return flags;
|
||||
}
|
||||
|
||||
static inline void
|
||||
hash_u32 (GChecksum *sum, guint32 n)
|
||||
{
|
||||
g_checksum_update (sum, (const guint8 *) &n, sizeof (n));
|
||||
}
|
||||
|
||||
void
|
||||
nm_ip4_config_hash (NMIP4Config *config, GChecksum *sum, gboolean dns_only)
|
||||
{
|
||||
guint32 i, n;
|
||||
const char *s;
|
||||
|
||||
g_return_if_fail (config != NULL);
|
||||
g_return_if_fail (sum != NULL);
|
||||
|
||||
if (dns_only == FALSE) {
|
||||
for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++) {
|
||||
NMIP4Address *a = nm_ip4_config_get_address (config, i);
|
||||
|
||||
hash_u32 (sum, nm_ip4_address_get_address (a));
|
||||
hash_u32 (sum, nm_ip4_address_get_prefix (a));
|
||||
hash_u32 (sum, nm_ip4_address_get_gateway (a));
|
||||
}
|
||||
|
||||
for (i = 0; i < nm_ip4_config_get_num_routes (config); i++) {
|
||||
NMIP4Route *r = nm_ip4_config_get_route (config, i);
|
||||
|
||||
hash_u32 (sum, nm_ip4_route_get_dest (r));
|
||||
hash_u32 (sum, nm_ip4_route_get_prefix (r));
|
||||
hash_u32 (sum, nm_ip4_route_get_next_hop (r));
|
||||
hash_u32 (sum, nm_ip4_route_get_metric (r));
|
||||
}
|
||||
|
||||
n = nm_ip4_config_get_ptp_address (config);
|
||||
if (n)
|
||||
hash_u32 (sum, n);
|
||||
|
||||
for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++)
|
||||
hash_u32 (sum, nm_ip4_config_get_nis_server (config, i));
|
||||
|
||||
s = nm_ip4_config_get_nis_domain (config);
|
||||
if (s)
|
||||
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
||||
}
|
||||
|
||||
for (i = 0; i < nm_ip4_config_get_num_nameservers (config); i++)
|
||||
hash_u32 (sum, nm_ip4_config_get_nameserver (config, i));
|
||||
|
||||
for (i = 0; i < nm_ip4_config_get_num_wins (config); i++)
|
||||
hash_u32 (sum, nm_ip4_config_get_wins (config, i));
|
||||
|
||||
for (i = 0; i < nm_ip4_config_get_num_domains (config); i++) {
|
||||
s = nm_ip4_config_get_domain (config, i);
|
||||
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
||||
}
|
||||
|
||||
for (i = 0; i < nm_ip4_config_get_num_searches (config); i++) {
|
||||
s = nm_ip4_config_get_search (config, i);
|
||||
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_ip4_config_init (NMIP4Config *config)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -139,4 +139,6 @@ typedef enum {
|
|||
/* Returns a bitfield representing how the two IP4 configs differ */
|
||||
NMIP4ConfigCompareFlags nm_ip4_config_diff (NMIP4Config *a, NMIP4Config *b);
|
||||
|
||||
void nm_ip4_config_hash (NMIP4Config *config, GChecksum *sum, gboolean dns_only);
|
||||
|
||||
#endif /* NM_IP4_CONFIG_H */
|
||||
|
|
|
|||
|
|
@ -677,6 +677,65 @@ nm_ip6_config_diff (NMIP6Config *a, NMIP6Config *b)
|
|||
return flags;
|
||||
}
|
||||
|
||||
static inline void
|
||||
hash_u32 (GChecksum *sum, guint32 n)
|
||||
{
|
||||
g_checksum_update (sum, (const guint8 *) &n, sizeof (n));
|
||||
}
|
||||
|
||||
static inline void
|
||||
hash_in6addr (GChecksum *sum, const struct in6_addr *a)
|
||||
{
|
||||
g_checksum_update (sum, (const guint8 *) a, sizeof (*a));
|
||||
}
|
||||
|
||||
void
|
||||
nm_ip6_config_hash (NMIP6Config *config, GChecksum *sum, gboolean dns_only)
|
||||
{
|
||||
guint32 i;
|
||||
const struct in6_addr *in6a;
|
||||
const char *s;
|
||||
|
||||
g_return_if_fail (config != NULL);
|
||||
g_return_if_fail (sum != NULL);
|
||||
|
||||
if (dns_only == FALSE) {
|
||||
for (i = 0; i < nm_ip6_config_get_num_addresses (config); i++) {
|
||||
NMIP6Address *a = nm_ip6_config_get_address (config, i);
|
||||
|
||||
hash_in6addr (sum, nm_ip6_address_get_address (a));
|
||||
hash_u32 (sum, nm_ip6_address_get_prefix (a));
|
||||
hash_in6addr (sum, nm_ip6_address_get_gateway (a));
|
||||
}
|
||||
|
||||
for (i = 0; i < nm_ip6_config_get_num_routes (config); i++) {
|
||||
NMIP6Route *r = nm_ip6_config_get_route (config, i);
|
||||
|
||||
hash_in6addr (sum, nm_ip6_route_get_dest (r));
|
||||
hash_u32 (sum, nm_ip6_route_get_prefix (r));
|
||||
hash_in6addr (sum, nm_ip6_route_get_next_hop (r));
|
||||
hash_u32 (sum, nm_ip6_route_get_metric (r));
|
||||
}
|
||||
|
||||
in6a = nm_ip6_config_get_ptp_address (config);
|
||||
if (in6a)
|
||||
hash_in6addr (sum, in6a);
|
||||
}
|
||||
|
||||
for (i = 0; i < nm_ip6_config_get_num_nameservers (config); i++)
|
||||
hash_in6addr (sum, nm_ip6_config_get_nameserver (config, i));
|
||||
|
||||
for (i = 0; i < nm_ip6_config_get_num_domains (config); i++) {
|
||||
s = nm_ip6_config_get_domain (config, i);
|
||||
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
||||
}
|
||||
|
||||
for (i = 0; i < nm_ip6_config_get_num_searches (config); i++) {
|
||||
s = nm_ip6_config_get_search (config, i);
|
||||
g_checksum_update (sum, (const guint8 *) s, strlen (s));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_ip6_config_init (NMIP6Config *config)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -120,4 +120,6 @@ typedef enum {
|
|||
/* Returns a bitfield representing how the two IP6 configs differ */
|
||||
NMIP6ConfigCompareFlags nm_ip6_config_diff (NMIP6Config *a, NMIP6Config *b);
|
||||
|
||||
void nm_ip6_config_hash (NMIP6Config *config, GChecksum *sum, gboolean dns_only);
|
||||
|
||||
#endif /* NM_IP6_CONFIG_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue