core: cleanup type of route metric to ensure guint32

Kernel, netlink an NMPlatformRoute treat route metrics as
uint32. Fix several places to use the exact type.

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-08-28 17:25:36 +02:00
parent 36d99dbed5
commit 52ddd72bde
13 changed files with 59 additions and 64 deletions

View File

@@ -42,7 +42,7 @@ typedef struct {
GByteArray * hwaddr;
gboolean ipv6;
char * uuid;
guint priority;
guint32 priority;
guint32 timeout;
GByteArray * duid;
@@ -885,7 +885,7 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
g_object_class_install_property
(object_class, PROP_PRIORITY,
g_param_spec_uint (NM_DHCP_CLIENT_PRIORITY, "", "",
0, G_MAXUINT, 0,
0, G_MAXUINT32, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));

View File

@@ -359,7 +359,7 @@ client_start (NMDhcpManager *self,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
guint priority,
guint32 priority,
gboolean ipv6,
const char *dhcp_client_id,
guint32 timeout,
@@ -433,7 +433,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
guint priority,
guint32 priority,
gboolean send_hostname,
const char *dhcp_hostname,
const char *dhcp_client_id,
@@ -458,7 +458,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
guint priority,
guint32 priority,
gboolean send_hostname,
const char *dhcp_hostname,
guint32 timeout,

View File

@@ -56,7 +56,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
guint priority,
guint32 priority,
gboolean send_hostname,
const char *dhcp_hostname,
const char *dhcp_client_id,
@@ -68,7 +68,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
int ifindex,
const GByteArray *hwaddr,
const char *uuid,
guint priority,
guint32 priority,
gboolean send_hostname,
const char *dhcp_hostname,
guint32 timeout,

View File

@@ -34,7 +34,7 @@
static gboolean
ip4_process_dhcpcd_rfc3442_routes (const char *str,
guint priority,
guint32 priority,
NMIP4Config *ip4_config,
guint32 *gwaddr)
{
@@ -161,7 +161,7 @@ error:
static gboolean
ip4_process_dhclient_rfc3442_routes (const char *str,
guint priority,
guint32 priority,
NMIP4Config *ip4_config,
guint32 *gwaddr)
{
@@ -209,7 +209,7 @@ out:
static gboolean
ip4_process_classless_routes (GHashTable *options,
guint priority,
guint32 priority,
NMIP4Config *ip4_config,
guint32 *gwaddr)
{
@@ -272,7 +272,7 @@ ip4_process_classless_routes (GHashTable *options,
}
static void
process_classful_routes (GHashTable *options, guint priority, NMIP4Config *ip4_config)
process_classful_routes (GHashTable *options, guint32 priority, NMIP4Config *ip4_config)
{
const char *str;
char **searches, **s;
@@ -374,7 +374,7 @@ ip4_add_domain_search (gpointer data, gpointer user_data)
NMIP4Config *
nm_dhcp_utils_ip4_config_from_options (const char *iface,
GHashTable *options,
guint priority)
guint32 priority)
{
NMIP4Config *ip4_config = NULL;
guint32 tmp_addr;
@@ -591,7 +591,7 @@ ip6_add_domain_search (gpointer data, gpointer user_data)
NMIP6Config *
nm_dhcp_utils_ip6_config_from_options (const char *iface,
GHashTable *options,
guint priority,
guint32 priority,
gboolean info_only)
{
NMIP6Config *ip6_config = NULL;

View File

@@ -302,7 +302,7 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex)
}
void
nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, int default_route_metric)
nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric)
{
guint naddresses, nroutes, nnameservers, nsearches;
int i;

View File

@@ -65,7 +65,7 @@ const char * nm_ip4_config_get_dbus_path (const NMIP4Config *config);
/* Integration with nm-platform and nm-setting */
NMIP4Config *nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf);
gboolean nm_ip4_config_commit (const NMIP4Config *config, int ifindex);
void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, int default_route_metric);
void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config);
/* Utility functions */

View File

@@ -407,7 +407,7 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex)
}
void
nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, int default_route_metric)
nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, guint32 default_route_metric)
{
guint naddresses, nroutes, nnameservers, nsearches;
const char *gateway_str;

View File

@@ -65,7 +65,7 @@ const char * nm_ip6_config_get_dbus_path (const NMIP6Config *config);
/* Integration with nm-platform and nm-setting */
NMIP6Config *nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary);
gboolean nm_ip6_config_commit (const NMIP6Config *config, int ifindex);
void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, int default_route_metric);
void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip6_config_create_setting (const NMIP6Config *config);
/* Utility functions */

View File

@@ -1043,7 +1043,7 @@ ip6_route_get_all (NMPlatform *platform, int ifindex, gboolean include_default)
static gboolean
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
int metric, int mss)
guint32 metric, guint32 mss)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
NMPlatformIP4Route route;
@@ -1083,7 +1083,7 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
int metric, int mss)
guint32 metric, guint32 mss)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
NMPlatformIP6Route route;
@@ -1121,7 +1121,7 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
}
static NMPlatformIP4Route *
ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
int i;
@@ -1140,7 +1140,7 @@ ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, int plen, i
}
static NMPlatformIP6Route *
ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
int i;
@@ -1159,7 +1159,7 @@ ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, int p
}
static gboolean
ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
NMPlatformIP4Route *route = ip4_route_get (platform, ifindex, network, plen, metric);
NMPlatformIP4Route deleted_route;
@@ -1174,7 +1174,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen
}
static gboolean
ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
NMPlatformIP6Route *route = ip6_route_get (platform, ifindex, network, plen, metric);
NMPlatformIP6Route deleted_route;
@@ -1189,13 +1189,13 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
}
static gboolean
ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
return !!ip4_route_get (platform, ifindex, network, plen, metric);
}
static gboolean
ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
return !!ip6_route_get (platform, ifindex, network, plen, metric);
}

View File

@@ -3711,7 +3711,7 @@ clear_host_address (int family, const void *network, int plen, void *dst)
static struct nl_object *
build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
gconstpointer network, int plen, gconstpointer gateway,
int metric, int mss)
guint32 metric, guint32 mss)
{
guint32 network_clean[4];
struct rtnl_route *rtnlroute;
@@ -3752,7 +3752,7 @@ build_rtnl_route (int family, int ifindex, NMIPConfigSource source,
static gboolean
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
int metric, int mss)
guint32 metric, guint32 mss)
{
return add_object (platform, build_rtnl_route (AF_INET, ifindex, source, &network, plen, &gateway, metric, mss));
}
@@ -3760,13 +3760,13 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
int metric, int mss)
guint32 metric, guint32 mss)
{
return add_object (platform, build_rtnl_route (AF_INET6, ifindex, source, &network, plen, &gateway, metric, mss));
}
static struct rtnl_route *
route_search_cache (struct nl_cache *cache, int family, int ifindex, const void *network, int plen, int metric)
route_search_cache (struct nl_cache *cache, int family, int ifindex, const void *network, int plen, guint32 metric)
{
guint32 network_clean[4], dst_clean[4];
struct nl_object *object;
@@ -3815,7 +3815,7 @@ refresh_route (NMPlatform *platform, int family, int ifindex, const void *networ
}
static gboolean
ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
in_addr_t gateway = 0;
struct rtnl_route *cached_object;
@@ -3875,7 +3875,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen
}
static gboolean
ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
struct in6_addr gateway = IN6ADDR_ANY_INIT;
@@ -3884,7 +3884,7 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
}
static gboolean
ip_route_exists (NMPlatform *platform, int family, int ifindex, gpointer network, int plen, int metric)
ip_route_exists (NMPlatform *platform, int family, int ifindex, gpointer network, int plen, guint32 metric)
{
auto_nl_object struct nl_object *object = build_rtnl_route (family, ifindex,
NM_IP_CONFIG_SOURCE_UNKNOWN,
@@ -3898,13 +3898,13 @@ ip_route_exists (NMPlatform *platform, int family, int ifindex, gpointer network
}
static gboolean
ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, int metric)
ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen, guint32 metric)
{
return ip_route_exists (platform, AF_INET, ifindex, &network, plen, metric);
}
static gboolean
ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, int metric)
ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
{
return ip_route_exists (platform, AF_INET6, ifindex, &network, plen, metric);
}

View File

@@ -1861,14 +1861,12 @@ nm_platform_ip6_route_get_all (int ifindex, gboolean include_default)
gboolean
nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
in_addr_t network, int plen,
in_addr_t gateway, int metric, int mss)
in_addr_t gateway, guint32 metric, guint32 mss)
{
reset_error ();
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (0 <= plen && plen <= 32, FALSE);
g_return_val_if_fail (metric >= 0, FALSE);
g_return_val_if_fail (mss >= 0, FALSE);
g_return_val_if_fail (klass->ip4_route_add, FALSE);
if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
@@ -1890,12 +1888,10 @@ nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
gboolean
nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
int metric, int mss)
guint32 metric, guint32 mss)
{
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (0 <= plen && plen <= 128, FALSE);
g_return_val_if_fail (metric >= 0, FALSE);
g_return_val_if_fail (mss >= 0, FALSE);
g_return_val_if_fail (klass->ip6_route_add, FALSE);
if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
@@ -1915,7 +1911,7 @@ nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source,
}
gboolean
nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, int metric)
nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, guint32 metric)
{
char str_dev[TO_STRING_DEV_BUF_SIZE];
@@ -1924,14 +1920,14 @@ nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, int metr
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (klass->ip4_route_delete, FALSE);
debug ("route: deleting IPv4 route %s/%d, metric=%d, ifindex %d%s",
debug ("route: deleting IPv4 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
nm_utils_inet4_ntop (network, NULL), plen, metric, ifindex,
_to_string_dev (ifindex, str_dev, sizeof (str_dev)));
return klass->ip4_route_delete (platform, ifindex, network, plen, metric);
}
gboolean
nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, int metric)
nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, guint32 metric)
{
char str_dev[TO_STRING_DEV_BUF_SIZE];
@@ -1940,14 +1936,14 @@ nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, in
g_return_val_if_fail (platform, FALSE);
g_return_val_if_fail (klass->ip6_route_delete, FALSE);
debug ("route: deleting IPv6 route %s/%d, metric=%d, ifindex %d%s",
debug ("route: deleting IPv6 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
nm_utils_inet6_ntop (&network, NULL), plen, metric, ifindex,
_to_string_dev (ifindex, str_dev, sizeof (str_dev)));
return klass->ip6_route_delete (platform, ifindex, network, plen, metric);
}
gboolean
nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, int metric)
nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, guint32 metric)
{
reset_error ();
@@ -1958,7 +1954,7 @@ nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, int metr
}
gboolean
nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, int metric)
nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, guint32 metric)
{
reset_error ();
@@ -2428,7 +2424,7 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route)
_to_string_dev (route->ifindex, str_dev, sizeof (str_dev));
g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %u mss %u src %s",
g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %"G_GUINT32_FORMAT" mss %"G_GUINT32_FORMAT" src %s",
s_network, route->plen, s_gateway,
str_dev,
route->metric, route->mss,
@@ -2461,7 +2457,7 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
_to_string_dev (route->ifindex, str_dev, sizeof (str_dev));
g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %u mss %u src %s",
g_snprintf (to_string_buffer, sizeof (to_string_buffer), "%s/%d via %s%s metric %"G_GUINT32_FORMAT" mss %"G_GUINT32_FORMAT" src %s",
s_network, route->plen, s_gateway,
str_dev,
route->metric, route->mss,

View File

@@ -180,8 +180,8 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_
__NMPlatformObject_COMMON; \
NMIPConfigSource source; \
int plen; \
guint metric; \
guint mss; \
guint32 metric; \
guint32 mss; \
;
typedef struct {
@@ -399,14 +399,14 @@ typedef struct {
GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex, gboolean include_default);
gboolean (*ip4_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
int prio, int mss);
guint32 metric, guint32 mss);
gboolean (*ip6_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
int prio, int mss);
gboolean (*ip4_route_delete) (NMPlatform *, int ifindex, in_addr_t network, int plen, int metric);
gboolean (*ip6_route_delete) (NMPlatform *, int ifindex, struct in6_addr network, int plen, int metric);
gboolean (*ip4_route_exists) (NMPlatform *, int ifindex, in_addr_t network, int plen, int metric);
gboolean (*ip6_route_exists) (NMPlatform *, int ifindex, struct in6_addr network, int plen, int metric);
guint32 metric, guint32 mss);
gboolean (*ip4_route_delete) (NMPlatform *, int ifindex, in_addr_t network, int plen, guint32 metric);
gboolean (*ip6_route_delete) (NMPlatform *, int ifindex, struct in6_addr network, int plen, guint32 metric);
gboolean (*ip4_route_exists) (NMPlatform *, int ifindex, in_addr_t network, int plen, guint32 metric);
gboolean (*ip6_route_exists) (NMPlatform *, int ifindex, struct in6_addr network, int plen, guint32 metric);
gboolean (*check_support_kernel_extended_ifa_flags) (NMPlatform *);
gboolean (*check_support_user_ipv6ll) (NMPlatform *);
@@ -544,17 +544,16 @@ gboolean nm_platform_address_flush (int ifindex);
GArray *nm_platform_ip4_route_get_all (int ifindex, gboolean include_default);
GArray *nm_platform_ip6_route_get_all (int ifindex, gboolean include_default);
gboolean nm_platform_route_set_metric (int ifindex, int metric);
gboolean nm_platform_ip4_route_add (int ifindex, NMIPConfigSource source,
in_addr_t network, int plen, in_addr_t gateway,
int metric, int mss);
guint32 metric, guint32 mss);
gboolean nm_platform_ip6_route_add (int ifindex, NMIPConfigSource source,
struct in6_addr network, int plen, struct in6_addr gateway,
int metric, int mss);
gboolean nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, int metric);
gboolean nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, int metric);
gboolean nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, int metric);
gboolean nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, int metric);
guint32 metric, guint32 mss);
gboolean nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, guint32 metric);
gboolean nm_platform_ip6_route_delete (int ifindex, struct in6_addr network, int plen, guint32 metric);
gboolean nm_platform_ip4_route_exists (int ifindex, in_addr_t network, int plen, guint32 metric);
gboolean nm_platform_ip6_route_exists (int ifindex, struct in6_addr network, int plen, guint32 metric);
gboolean nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes);
gboolean nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes);
gboolean nm_platform_route_flush (int ifindex);

View File

@@ -1104,7 +1104,7 @@ nm_vpn_connection_config_get (DBusGProxy *proxy,
g_clear_object (&priv->ip6_config);
}
static guint
static guint32
vpn_routing_metric (NMVpnConnection *connection)
{
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);