platform: expose nmp_utils_ip_config_source_to/from_rtprot()

Will be used also from the tests.
This commit is contained in:
Thomas Haller
2016-04-10 12:01:51 +02:00
parent af55476bf1
commit 198baca830
3 changed files with 50 additions and 41 deletions

View File

@@ -290,45 +290,6 @@ _support_user_ipv6ll_detect (struct nlattr **tb)
* Various utilities * Various utilities
******************************************************************/ ******************************************************************/
static guint
_nm_ip_config_source_to_rtprot (NMIPConfigSource source)
{
switch (source) {
case NM_IP_CONFIG_SOURCE_UNKNOWN:
return RTPROT_UNSPEC;
case NM_IP_CONFIG_SOURCE_KERNEL:
case NM_IP_CONFIG_SOURCE_RTPROT_KERNEL:
return RTPROT_KERNEL;
case NM_IP_CONFIG_SOURCE_DHCP:
return RTPROT_DHCP;
case NM_IP_CONFIG_SOURCE_RDISC:
return RTPROT_RA;
default:
return RTPROT_STATIC;
}
}
static NMIPConfigSource
_nm_ip_config_source_from_rtprot (guint rtprot)
{
switch (rtprot) {
case RTPROT_UNSPEC:
return NM_IP_CONFIG_SOURCE_UNKNOWN;
case RTPROT_KERNEL:
return NM_IP_CONFIG_SOURCE_RTPROT_KERNEL;
case RTPROT_REDIRECT:
return NM_IP_CONFIG_SOURCE_KERNEL;
case RTPROT_RA:
return NM_IP_CONFIG_SOURCE_RDISC;
case RTPROT_DHCP:
return NM_IP_CONFIG_SOURCE_DHCP;
default:
return NM_IP_CONFIG_SOURCE_USER;
}
}
static void static void
clear_host_address (int family, const void *network, guint8 plen, void *dst) clear_host_address (int family, const void *network, guint8 plen, void *dst)
{ {
@@ -1911,7 +1872,7 @@ _new_from_nl_route (struct nlmsghdr *nlh, gboolean id_only)
* */ * */
obj->ip_route.source = _NM_IP_CONFIG_SOURCE_RTM_F_CLONED; obj->ip_route.source = _NM_IP_CONFIG_SOURCE_RTM_F_CLONED;
} else } else
obj->ip_route.source = _nm_ip_config_source_from_rtprot (rtm->rtm_protocol); obj->ip_route.source = nmp_utils_ip_config_source_from_rtprot (rtm->rtm_protocol);
obj_result = obj; obj_result = obj;
obj = NULL; obj = NULL;
@@ -2271,7 +2232,7 @@ _nl_msg_new_route (int nlmsg_type,
.rtm_family = family, .rtm_family = family,
.rtm_tos = 0, .rtm_tos = 0,
.rtm_table = RT_TABLE_MAIN, /* omit setting RTA_TABLE attribute */ .rtm_table = RT_TABLE_MAIN, /* omit setting RTA_TABLE attribute */
.rtm_protocol = _nm_ip_config_source_to_rtprot (source), .rtm_protocol = nmp_utils_ip_config_source_to_rtprot (source),
.rtm_scope = scope, .rtm_scope = scope,
.rtm_type = RTN_UNICAST, .rtm_type = RTN_UNICAST,
.rtm_flags = 0, .rtm_flags = 0,

View File

@@ -30,6 +30,7 @@
#include <linux/sockios.h> #include <linux/sockios.h>
#include <linux/mii.h> #include <linux/mii.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/rtnetlink.h>
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-setting-wired.h" #include "nm-setting-wired.h"
@@ -412,6 +413,10 @@ out:
return g_intern_string (driver); return g_intern_string (driver);
} }
/******************************************************************************
* utils
*****************************************************************************/
gboolean gboolean
nmp_utils_device_exists (const char *name) nmp_utils_device_exists (const char *name)
{ {
@@ -427,3 +432,43 @@ nmp_utils_device_exists (const char *name)
nm_utils_ifname_cpy (&sysdir[NM_STRLEN (SYS_CLASS_NET)], name); nm_utils_ifname_cpy (&sysdir[NM_STRLEN (SYS_CLASS_NET)], name);
return g_file_test (sysdir, G_FILE_TEST_EXISTS); return g_file_test (sysdir, G_FILE_TEST_EXISTS);
} }
guint
nmp_utils_ip_config_source_to_rtprot (NMIPConfigSource source)
{
switch (source) {
case NM_IP_CONFIG_SOURCE_UNKNOWN:
return RTPROT_UNSPEC;
case NM_IP_CONFIG_SOURCE_KERNEL:
case NM_IP_CONFIG_SOURCE_RTPROT_KERNEL:
return RTPROT_KERNEL;
case NM_IP_CONFIG_SOURCE_DHCP:
return RTPROT_DHCP;
case NM_IP_CONFIG_SOURCE_RDISC:
return RTPROT_RA;
default:
return RTPROT_STATIC;
}
}
NMIPConfigSource
nmp_utils_ip_config_source_from_rtprot (guint rtprot)
{
switch (rtprot) {
case RTPROT_UNSPEC:
return NM_IP_CONFIG_SOURCE_UNKNOWN;
case RTPROT_KERNEL:
return NM_IP_CONFIG_SOURCE_RTPROT_KERNEL;
case RTPROT_REDIRECT:
return NM_IP_CONFIG_SOURCE_KERNEL;
case RTPROT_RA:
return NM_IP_CONFIG_SOURCE_RDISC;
case RTPROT_DHCP:
return NM_IP_CONFIG_SOURCE_DHCP;
default:
return NM_IP_CONFIG_SOURCE_USER;
}
}

View File

@@ -54,4 +54,7 @@ const char *nmp_utils_udev_get_driver (GUdevDevice *device);
gboolean nmp_utils_device_exists (const char *name); gboolean nmp_utils_device_exists (const char *name);
guint nmp_utils_ip_config_source_to_rtprot (NMIPConfigSource source);
NMIPConfigSource nmp_utils_ip_config_source_from_rtprot (guint rtprot);
#endif /* __NM_PLATFORM_UTILS_H__ */ #endif /* __NM_PLATFORM_UTILS_H__ */