diff options
Diffstat (limited to 'src/nm-ip4-config.c')
| -rw-r--r-- | src/nm-ip4-config.c | 233 |
1 files changed, 123 insertions, 110 deletions
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 7b422359..1486edcc 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -27,34 +27,57 @@ #include <arpa/inet.h> #include "nm-utils.h" -#include "nm-platform.h" -#include "nm-platform-utils.h" +#include "platform/nm-platform.h" +#include "platform/nm-platform-utils.h" #include "NetworkManagerUtils.h" #include "nm-route-manager.h" #include "nm-core-internal.h" -#include "nmdbus-ip4-config.h" +#include "introspection/org.freedesktop.NetworkManager.IP4Config.h" + +/*****************************************************************************/ + +/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ +G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32)); +G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF); + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, + PROP_IFINDEX, + PROP_ADDRESS_DATA, + PROP_ADDRESSES, + PROP_ROUTE_DATA, + PROP_ROUTES, + PROP_GATEWAY, + PROP_NAMESERVERS, + PROP_DOMAINS, + PROP_SEARCHES, + PROP_DNS_OPTIONS, + PROP_WINS_SERVERS, + PROP_DNS_PRIORITY, +); typedef struct { - gboolean never_default; + bool never_default:1; + bool metered:1; + bool has_gateway:1; guint32 gateway; - gboolean has_gateway; + guint32 mss; + guint32 mtu; + int ifindex; + NMIPConfigSource mtu_source; + gint dns_priority; + gint64 route_metric; GArray *addresses; GArray *routes; GArray *nameservers; GPtrArray *domains; GPtrArray *searches; GPtrArray *dns_options; - guint32 mss; GArray *nis; char *nis_domain; GArray *wins; - guint32 mtu; - NMIPConfigSource mtu_source; - int ifindex; - gint64 route_metric; - gboolean metered; - gint dns_priority; GVariant *address_data_variant; GVariant *addresses_variant; } NMIP4ConfigPrivate; @@ -72,33 +95,7 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT) #define NM_IP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP4Config, NM_IS_IP4_CONFIG) -/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ -G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32)); -G_STATIC_ASSERT (G_MAXUINT >= 0xFFFFFFFF); - -NM_GOBJECT_PROPERTIES_DEFINE (NMIP4Config, - PROP_IFINDEX, - PROP_ADDRESS_DATA, - PROP_ADDRESSES, - PROP_ROUTE_DATA, - PROP_ROUTES, - PROP_GATEWAY, - PROP_NAMESERVERS, - PROP_DOMAINS, - PROP_SEARCHES, - PROP_DNS_OPTIONS, - PROP_WINS_SERVERS, - PROP_DNS_PRIORITY, -); - -NMIP4Config * -nm_ip4_config_new (int ifindex) -{ - g_return_val_if_fail (ifindex >= -1, NULL); - return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, - NM_IP4_CONFIG_IFINDEX, ifindex, - NULL); -} +/*****************************************************************************/ int nm_ip4_config_get_ifindex (const NMIP4Config *config) @@ -106,7 +103,7 @@ nm_ip4_config_get_ifindex (const NMIP4Config *config) return NM_IP4_CONFIG_GET_PRIVATE (config)->ifindex; } -/******************************************************************/ +/*****************************************************************************/ static gboolean _ipv4_is_zeronet (in_addr_t network) @@ -115,7 +112,7 @@ _ipv4_is_zeronet (in_addr_t network) return (network & htonl(0xff000000)) == htonl(0x00000000); } -/******************************************************************/ +/*****************************************************************************/ /** * nm_ip4_config_capture_resolv_conf(): @@ -640,7 +637,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config) return NM_SETTING (s_ip4); } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFlags merge_flags) @@ -705,9 +702,11 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFl nm_ip4_config_set_mss (dst, nm_ip4_config_get_mss (src)); /* MTU */ - if (nm_ip4_config_get_mtu (src)) - nm_ip4_config_set_mtu (dst, nm_ip4_config_get_mtu (src), - nm_ip4_config_get_mtu_source (src)); + if ( src_priv->mtu_source > dst_priv->mtu_source + || ( src_priv->mtu_source == dst_priv->mtu_source + && ( (!dst_priv->mtu && src_priv->mtu) + || (dst_priv->mtu && src_priv->mtu < dst_priv->mtu)))) + nm_ip4_config_set_mtu (dst, src_priv->mtu, src_priv->mtu_source); /* NIS */ if (!NM_FLAGS_HAS (merge_flags, NM_IP_CONFIG_MERGE_NO_DNS)) { @@ -735,7 +734,7 @@ nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFl g_object_thaw_notify (G_OBJECT (dst)); } -/*******************************************************************************/ +/*****************************************************************************/ static int _addresses_get_index (const NMIP4Config *self, const NMPlatformIP4Address *addr) @@ -858,7 +857,7 @@ _wins_get_index (const NMIP4Config *self, guint32 wins_server) return -1; } -/*******************************************************************************/ +/*****************************************************************************/ /** * nm_ip4_config_subtract: @@ -935,7 +934,8 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src) nm_ip4_config_set_mss (dst, 0); /* MTU */ - if (nm_ip4_config_get_mtu (src) == nm_ip4_config_get_mtu (dst)) + if ( nm_ip4_config_get_mtu (src) == nm_ip4_config_get_mtu (dst) + && nm_ip4_config_get_mtu_source (src) == nm_ip4_config_get_mtu_source (dst)) nm_ip4_config_set_mtu (dst, 0, NM_IP_CONFIG_SOURCE_UNKNOWN); /* NIS */ @@ -1255,7 +1255,8 @@ nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relev } /* mtu */ - if (src_priv->mtu != dst_priv->mtu) { + if ( src_priv->mtu != dst_priv->mtu + || src_priv->mtu_source != dst_priv->mtu_source) { nm_ip4_config_set_mtu (dst, src_priv->mtu, src_priv->mtu_source); has_minor_changes = TRUE; } @@ -1332,7 +1333,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail) g_message (" dnspri: %d", nm_ip4_config_get_dns_priority (config)); g_message (" mss: %"G_GUINT32_FORMAT, nm_ip4_config_get_mss (config)); - g_message (" mtu: %"G_GUINT32_FORMAT, nm_ip4_config_get_mtu (config)); + g_message (" mtu: %"G_GUINT32_FORMAT" (source: %d)", nm_ip4_config_get_mtu (config), (int) nm_ip4_config_get_mtu_source (config)); /* NIS */ for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++) { @@ -1378,14 +1379,14 @@ nm_ip4_config_destination_is_direct (const NMIP4Config *config, guint32 network, return FALSE; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_set_never_default (NMIP4Config *config, gboolean never_default) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - priv->never_default = !!never_default; + priv->never_default = never_default; } gboolean @@ -1454,7 +1455,7 @@ nm_ip4_config_get_route_metric (const NMIP4Config *config) return priv->route_metric; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_addresses (NMIP4Config *config) @@ -1558,7 +1559,7 @@ nm_ip4_config_address_exists (const NMIP4Config *config, return _addresses_get_index (config, needle) >= 0; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_routes (NMIP4Config *config) @@ -1673,7 +1674,7 @@ nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host return best_route; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_nameservers (NMIP4Config *config) @@ -1729,7 +1730,7 @@ nm_ip4_config_get_nameserver (const NMIP4Config *config, guint i) return g_array_index (priv->nameservers, guint32, i); } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_domains (NMIP4Config *config) @@ -1786,7 +1787,7 @@ nm_ip4_config_get_domain (const NMIP4Config *config, guint i) return g_ptr_array_index (priv->domains, i); } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_searches (NMIP4Config *config) @@ -1858,7 +1859,7 @@ nm_ip4_config_get_search (const NMIP4Config *config, guint i) return g_ptr_array_index (priv->searches, i); } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_dns_options (NMIP4Config *config) @@ -1915,7 +1916,7 @@ nm_ip4_config_get_dns_option (const NMIP4Config *config, guint i) return g_ptr_array_index (priv->dns_options, i); } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_set_dns_priority (NMIP4Config *config, gint priority) @@ -1936,7 +1937,7 @@ nm_ip4_config_get_dns_priority (const NMIP4Config *config) return priv->dns_priority; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_set_mss (NMIP4Config *config, guint32 mss) @@ -1954,7 +1955,7 @@ nm_ip4_config_get_mss (const NMIP4Config *config) return priv->mss; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_nis_servers (NMIP4Config *config) @@ -2020,7 +2021,7 @@ nm_ip4_config_get_nis_domain (const NMIP4Config *config) return priv->nis_domain; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_reset_wins (NMIP4Config *config) @@ -2076,18 +2077,18 @@ nm_ip4_config_get_wins (const NMIP4Config *config, guint i) return g_array_index (priv->wins, guint32, i); } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu, NMIPConfigSource source) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - if (source > priv->mtu_source) { - priv->mtu = mtu; - priv->mtu_source = source; - } else if (source == priv->mtu_source && (!priv->mtu || priv->mtu > mtu)) - priv->mtu = mtu; + if (!mtu) + source = NM_IP_CONFIG_SOURCE_UNKNOWN; + + priv->mtu = mtu; + priv->mtu_source = source; } guint32 @@ -2106,14 +2107,14 @@ nm_ip4_config_get_mtu_source (const NMIP4Config *config) return priv->mtu_source; } -/******************************************************************/ +/*****************************************************************************/ void nm_ip4_config_set_metered (NMIP4Config *config, gboolean metered) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - priv->metered = !!metered; + priv->metered = metered; } gboolean @@ -2124,7 +2125,7 @@ nm_ip4_config_get_metered (const NMIP4Config *config) return priv->metered; } -/******************************************************************/ +/*****************************************************************************/ static inline void hash_u32 (GChecksum *sum, guint32 n) @@ -2231,44 +2232,7 @@ nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b) return equal; } -/******************************************************************/ - -static void -nm_ip4_config_init (NMIP4Config *config) -{ - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); - - priv->addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address)); - priv->routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route)); - priv->nameservers = g_array_new (FALSE, FALSE, sizeof (guint32)); - priv->domains = g_ptr_array_new_with_free_func (g_free); - priv->searches = g_ptr_array_new_with_free_func (g_free); - priv->dns_options = g_ptr_array_new_with_free_func (g_free); - priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32)); - priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32)); - priv->route_metric = -1; -} - -static void -finalize (GObject *object) -{ - NMIP4Config *self = NM_IP4_CONFIG (object); - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); - - nm_clear_g_variant (&priv->address_data_variant); - nm_clear_g_variant (&priv->addresses_variant); - g_array_unref (priv->addresses); - g_array_unref (priv->routes); - g_array_unref (priv->nameservers); - g_ptr_array_unref (priv->domains); - g_ptr_array_unref (priv->searches); - g_ptr_array_unref (priv->dns_options); - g_array_unref (priv->nis); - g_free (priv->nis_domain); - g_array_unref (priv->wins); - - G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); -} +/*****************************************************************************/ static void get_property (GObject *object, guint prop_id, @@ -2459,6 +2423,7 @@ set_property (GObject *object, switch (prop_id) { case PROP_IFINDEX: + /* construct-only */ priv->ifindex = g_value_get_int (value); break; default: @@ -2467,13 +2432,61 @@ set_property (GObject *object, } } +/*****************************************************************************/ + +static void +nm_ip4_config_init (NMIP4Config *config) +{ + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); + + priv->addresses = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Address)); + priv->routes = g_array_new (FALSE, FALSE, sizeof (NMPlatformIP4Route)); + priv->nameservers = g_array_new (FALSE, FALSE, sizeof (guint32)); + priv->domains = g_ptr_array_new_with_free_func (g_free); + priv->searches = g_ptr_array_new_with_free_func (g_free); + priv->dns_options = g_ptr_array_new_with_free_func (g_free); + priv->nis = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->wins = g_array_new (FALSE, TRUE, sizeof (guint32)); + priv->route_metric = -1; +} + +NMIP4Config * +nm_ip4_config_new (int ifindex) +{ + g_return_val_if_fail (ifindex >= -1, NULL); + return (NMIP4Config *) g_object_new (NM_TYPE_IP4_CONFIG, + NM_IP4_CONFIG_IFINDEX, ifindex, + NULL); +} + +static void +finalize (GObject *object) +{ + NMIP4Config *self = NM_IP4_CONFIG (object); + NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); + + nm_clear_g_variant (&priv->address_data_variant); + nm_clear_g_variant (&priv->addresses_variant); + g_array_unref (priv->addresses); + g_array_unref (priv->routes); + g_array_unref (priv->nameservers); + g_ptr_array_unref (priv->domains); + g_ptr_array_unref (priv->searches); + g_ptr_array_unref (priv->dns_options); + g_array_unref (priv->nis); + g_free (priv->nis_domain); + g_array_unref (priv->wins); + + G_OBJECT_CLASS (nm_ip4_config_parent_class)->finalize (object); +} + static void nm_ip4_config_class_init (NMIP4ConfigClass *config_class) { GObjectClass *object_class = G_OBJECT_CLASS (config_class); NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class); - exported_object_class->export_path = NM_DBUS_PATH "/IP4Config/%u"; + exported_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP4Config"); object_class->get_property = get_property; object_class->set_property = set_property; |