diff options
author | Dan Williams <dcbw@redhat.com> | 2012-05-29 22:24:51 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-06-12 09:37:26 -0500 |
commit | 90fb53de4cf0a57094a747dc7544484588026f7b (patch) | |
tree | 1ac568495cfd8a249df9748097860acb2a435ecd /src | |
parent | 9966ac45fa80fec89d58a5b607377c75e6aa8f6d (diff) | |
download | NetworkManager-90fb53de4cf0a57094a747dc7544484588026f7b.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/nm-ip4-config.c | 62 | ||||
-rw-r--r-- | src/nm-ip4-config.h | 2 | ||||
-rw-r--r-- | src/nm-ip6-config.c | 59 | ||||
-rw-r--r-- | src/nm-ip6-config.h | 2 |
4 files changed, 125 insertions, 0 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 9a3528491d..d00d40979d 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -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) { diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 2d27acff03..6b86bc4779 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -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 */ diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 2fab486383..e1600e43fd 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -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) { diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index bc87430cfc..db08e9b4e6 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -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 */ |