rdisc: rename to ndisc

We'll soon not only do the router discovery, but announce ourselves as a
reouter. "Neighbor discovery" sounds to be a more appropriate name for
the class than "Router discovery".
This commit is contained in:
Lubomir Rintel 2016-10-13 11:06:25 +00:00
parent aa71dbc6c4
commit 44fca246a7
20 changed files with 876 additions and 875 deletions

5
.gitignore vendored
View file

@ -247,8 +247,8 @@ test-*.trs
/src/dhcp-manager/tests/test-dhcp-utils
/src/dnsmasq-manager/tests/test-dnsmasq-utils
/src/nm-iface-helper
/src/rdisc/tests/test-rdisc-fake
/src/rdisc/tests/test-rdisc-linux
/src/ndisc/tests/test-ndisc-fake
/src/ndisc/tests/test-ndisc-linux
/src/settings/plugins/ibft/tests/test-ibft
/src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.[ch]
/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh
@ -289,3 +289,4 @@ test-*.trs
/src/devices/wifi/tests/test-wifi-ap-utils
/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils
/src/settings/plugins/ifnet/tests/check_ifnet
/src/rdisc/

View file

@ -900,7 +900,7 @@ src_cppflags = \
-I$(top_srcdir)/src/platform \
-I$(top_srcdir)/src/platform/wifi \
-I$(top_srcdir)/src/ppp-manager \
-I$(top_srcdir)/src/rdisc \
-I$(top_srcdir)/src/ndisc \
-I$(top_srcdir)/src/settings \
-I$(top_srcdir)/src/supplicant-manager \
-I$(top_srcdir)/src/vpn-manager \
@ -1142,11 +1142,11 @@ src_libNetworkManagerBase_la_SOURCES = \
src/platform/wifi/wifi-utils.c \
src/platform/wifi/wifi-utils.h \
\
src/rdisc/nm-lndp-rdisc.c \
src/rdisc/nm-lndp-rdisc.h \
src/rdisc/nm-rdisc.c \
src/rdisc/nm-rdisc.h \
src/rdisc/nm-rdisc-private.h \
src/ndisc/nm-lndp-ndisc.c \
src/ndisc/nm-lndp-ndisc.h \
src/ndisc/nm-ndisc.c \
src/ndisc/nm-ndisc.h \
src/ndisc/nm-ndisc-private.h \
\
src/nm-exported-object.c \
src/nm-exported-object.h \
@ -1381,8 +1381,8 @@ src_tests_cppflags_linux = $(src_tests_cppflags) -DSETUP=nm_linux_platform_setup
src_libNetworkManagerTest_la_CPPFLAGS = $(src_tests_cppflags)
src_libNetworkManagerTest_la_SOURCES = \
src/rdisc/nm-fake-rdisc.c \
src/rdisc/nm-fake-rdisc.h \
src/ndisc/nm-fake-ndisc.c \
src/ndisc/nm-fake-ndisc.h \
src/platform/nm-fake-platform.c \
src/platform/nm-fake-platform.h \
src/platform/tests/test-common.c \
@ -2613,26 +2613,26 @@ src_devices_tests_test_arping_LDADD = \
src/libNetworkManagerTest.la
###############################################################################
# src/rdisc/tests
# src/ndisc/tests
###############################################################################
src_rdisc_tests_ldflags = \
src_ndisc_tests_ldflags = \
$(CODE_COVERAGE_LDFLAGS)
src_rdisc_tests_ldadd = \
src_ndisc_tests_ldadd = \
src/libNetworkManagerTest.la \
$(GLIB_LIBS)
check_programs += src/rdisc/tests/test-rdisc-fake
check_programs_norun += src/rdisc/tests/test-rdisc-linux
check_programs += src/ndisc/tests/test-ndisc-fake
check_programs_norun += src/ndisc/tests/test-ndisc-linux
src_rdisc_tests_test_rdisc_linux_CPPFLAGS = $(src_tests_cppflags)
src_rdisc_tests_test_rdisc_linux_LDFLAGS = $(src_rdisc_tests_flags)
src_rdisc_tests_test_rdisc_linux_LDADD = $(src_rdisc_tests_ldadd)
src_ndisc_tests_test_ndisc_linux_CPPFLAGS = $(src_tests_cppflags)
src_ndisc_tests_test_ndisc_linux_LDFLAGS = $(src_ndisc_tests_flags)
src_ndisc_tests_test_ndisc_linux_LDADD = $(src_ndisc_tests_ldadd)
src_rdisc_tests_test_rdisc_fake_CPPFLAGS = $(src_tests_cppflags)
src_rdisc_tests_test_rdisc_fake_LDFLAGS = $(src_rdisc_tests_flags)
src_rdisc_tests_test_rdisc_fake_LDADD = $(src_rdisc_tests_ldadd)
src_ndisc_tests_test_ndisc_fake_CPPFLAGS = $(src_tests_cppflags)
src_ndisc_tests_test_ndisc_fake_LDFLAGS = $(src_ndisc_tests_flags)
src_ndisc_tests_test_ndisc_fake_LDADD = $(src_ndisc_tests_ldadd)
###############################################################################
# src/supplicant-manager/tests

View file

@ -40,8 +40,8 @@
#include "NetworkManagerUtils.h"
#include "nm-manager.h"
#include "nm-platform.h"
#include "nm-rdisc.h"
#include "nm-lndp-rdisc.h"
#include "nm-ndisc.h"
#include "nm-lndp-ndisc.h"
#include "nm-dhcp-manager.h"
#include "nm-act-request.h"
#include "nm-proxy-config.h"
@ -373,10 +373,10 @@ typedef struct _NMDevicePrivate {
guint32 ip6_mtu;
NMIP6Config * dad6_ip6_config;
NMRDisc * rdisc;
gulong rdisc_changed_id;
gulong rdisc_timeout_id;
NMSettingIP6ConfigPrivacy rdisc_use_tempaddr;
NMNDisc * ndisc;
gulong ndisc_changed_id;
gulong ndisc_timeout_id;
NMSettingIP6ConfigPrivacy ndisc_use_tempaddr;
/* IP6 config from autoconf */
NMIP6Config * ac_ip6_config;
@ -387,7 +387,7 @@ typedef struct _NMDevicePrivate {
struct {
NMDhcpClient * client;
NMRDiscDHCPLevel mode;
NMNDiscDHCPLevel mode;
gulong state_sigid;
NMDhcp6Config * config;
/* IP6 config from DHCP */
@ -1626,7 +1626,7 @@ nm_device_update_dynamic_ip_setup (NMDevice *self)
return;
}
}
if (priv->rdisc) {
if (priv->ndisc) {
/* FIXME: todo */
}
if (priv->dnsmasq_manager) {
@ -1896,10 +1896,10 @@ device_link_changed (NMDevice *self)
nm_device_emit_recheck_auto_activate (self);
}
if (priv->rdisc && info.inet6_token.id) {
if (nm_rdisc_set_iid (priv->rdisc, info.inet6_token)) {
if (priv->ndisc && info.inet6_token.id) {
if (nm_ndisc_set_iid (priv->ndisc, info.inet6_token)) {
_LOGD (LOGD_DEVICE, "IPv6 tokenized identifier present on device %s", priv->iface);
nm_rdisc_start (priv->rdisc);
nm_ndisc_start (priv->ndisc);
}
}
@ -5428,7 +5428,7 @@ dhcp6_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
priv->dhcp6.mode = NM_RDISC_DHCP_LEVEL_NONE;
priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_NONE;
g_clear_object (&priv->dhcp6.ip6_config);
g_clear_pointer (&priv->dhcp6.event_id, g_free);
nm_clear_g_source (&priv->dhcp6.restart_id);
@ -5635,7 +5635,7 @@ END_ADD_DEFAULT_ROUTE:
}
nm_ip6_config_addresses_sort (composite,
priv->rdisc ? priv->rdisc_use_tempaddr : NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
priv->ndisc ? priv->ndisc_use_tempaddr : NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
/* Allow setting MTU etc */
if (commit) {
@ -5755,7 +5755,7 @@ dhcp6_fail (NMDevice *self, gboolean timeout)
dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
if (priv->dhcp6.mode == NM_RDISC_DHCP_LEVEL_MANAGED) {
if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED) {
/* Don't fail if there are static addresses configured on
* the device, instead retry after some time.
*/
@ -5801,7 +5801,7 @@ dhcp6_timeout (NMDevice *self, NMDhcpClient *client)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
if (priv->dhcp6.mode == NM_RDISC_DHCP_LEVEL_MANAGED)
if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED)
dhcp6_fail (self, TRUE);
else {
/* not a hard failure; just live with the RA info */
@ -5878,7 +5878,7 @@ dhcp6_state_changed (NMDhcpClient *client,
* may exit right after getting a response from the server. That's
* normal. In that case we just ignore the exit.
*/
if (priv->dhcp6.mode == NM_RDISC_DHCP_LEVEL_OTHERCONF)
if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF)
break;
/* Otherwise, fall through */
case NM_DHCP_STATE_FAIL:
@ -5925,7 +5925,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
nm_setting_ip_config_get_dhcp_hostname (s_ip6),
priv->dhcp_timeout,
priv->dhcp_anycast_address,
(priv->dhcp6.mode == NM_RDISC_DHCP_LEVEL_OTHERCONF) ? TRUE : FALSE,
(priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF) ? TRUE : FALSE,
nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6)));
if (tmp)
g_byte_array_free (tmp, TRUE);
@ -6234,9 +6234,9 @@ nm_device_ipv6_set_mtu (NMDevice *self, guint32 mtu)
}
static void
rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_int, NMDevice *self)
ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, NMDevice *self)
{
NMRDiscConfigMap changed = changed_int;
NMNDiscConfigMap changed = changed_int;
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
int i;
int system_support;
@ -6252,8 +6252,8 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
if (system_support)
ifa_flags = IFA_F_NOPREFIXROUTE;
if ( priv->rdisc_use_tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR
|| priv->rdisc_use_tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)
if ( priv->ndisc_use_tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR
|| priv->ndisc_use_tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)
{
/* without system_support, this flag will be ignored. Still set it, doesn't seem to do any harm. */
ifa_flags |= IFA_F_MANAGETEMPADDR;
@ -6264,25 +6264,25 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
if (!priv->ac_ip6_config)
priv->ac_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
if (changed & NM_RDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in router discovery cache. */
if (changed & NM_NDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in neighbor discovery cache. */
if (rdata->gateways_n)
nm_ip6_config_set_gateway (priv->ac_ip6_config, &rdata->gateways[0].address);
else
nm_ip6_config_set_gateway (priv->ac_ip6_config, NULL);
}
if (changed & NM_RDISC_CONFIG_ADDRESSES) {
/* Rebuild address list from router discovery cache. */
if (changed & NM_NDISC_CONFIG_ADDRESSES) {
/* Rebuild address list from neighbor discovery cache. */
nm_ip6_config_reset_addresses (priv->ac_ip6_config);
/* rdisc->addresses contains at most max_addresses entries.
/* ndisc->addresses contains at most max_addresses entries.
* This is different from what the kernel does, which
* also counts static and temporary addresses when checking
* max_addresses.
**/
for (i = 0; i < rdata->addresses_n; i++) {
const NMRDiscAddress *discovered_address = &rdata->addresses[i];
const NMNDiscAddress *discovered_address = &rdata->addresses[i];
NMPlatformIP6Address address;
memset (&address, 0, sizeof (address));
@ -6293,24 +6293,24 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
address.preferred = discovered_address->preferred;
if (address.preferred > address.lifetime)
address.preferred = address.lifetime;
address.addr_source = NM_IP_CONFIG_SOURCE_RDISC;
address.addr_source = NM_IP_CONFIG_SOURCE_NDISC;
address.n_ifa_flags = ifa_flags;
nm_ip6_config_add_address (priv->ac_ip6_config, &address);
}
}
if (changed & NM_RDISC_CONFIG_ROUTES) {
/* Rebuild route list from router discovery cache. */
if (changed & NM_NDISC_CONFIG_ROUTES) {
/* Rebuild route list from neighbor discovery cache. */
nm_ip6_config_reset_routes (priv->ac_ip6_config);
for (i = 0; i < rdata->routes_n; i++) {
const NMRDiscRoute *discovered_route = &rdata->routes[i];
const NMNDiscRoute *discovered_route = &rdata->routes[i];
const NMPlatformIP6Route route = {
.network = discovered_route->network,
.plen = discovered_route->plen,
.gateway = discovered_route->gateway,
.rt_source = NM_IP_CONFIG_SOURCE_RDISC,
.rt_source = NM_IP_CONFIG_SOURCE_NDISC,
.metric = nm_device_get_ip6_route_metric (self),
};
@ -6318,34 +6318,34 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
}
}
if (changed & NM_RDISC_CONFIG_DNS_SERVERS) {
/* Rebuild DNS server list from router discovery cache. */
if (changed & NM_NDISC_CONFIG_DNS_SERVERS) {
/* Rebuild DNS server list from neighbor discovery cache. */
nm_ip6_config_reset_nameservers (priv->ac_ip6_config);
for (i = 0; i < rdata->dns_servers_n; i++)
nm_ip6_config_add_nameserver (priv->ac_ip6_config, &rdata->dns_servers[i].address);
}
if (changed & NM_RDISC_CONFIG_DNS_DOMAINS) {
/* Rebuild domain list from router discovery cache. */
if (changed & NM_NDISC_CONFIG_DNS_DOMAINS) {
/* Rebuild domain list from neighbor discovery cache. */
nm_ip6_config_reset_domains (priv->ac_ip6_config);
for (i = 0; i < rdata->dns_domains_n; i++)
nm_ip6_config_add_domain (priv->ac_ip6_config, rdata->dns_domains[i].domain);
}
if (changed & NM_RDISC_CONFIG_DHCP_LEVEL) {
if (changed & NM_NDISC_CONFIG_DHCP_LEVEL) {
dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, TRUE);
priv->dhcp6.mode = rdata->dhcp_level;
if (priv->dhcp6.mode != NM_RDISC_DHCP_LEVEL_NONE) {
if (priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE) {
NMDeviceStateReason reason;
_LOGD (LOGD_DEVICE | LOGD_DHCP6,
"Activation: Stage 3 of 5 (IP Configure Start) starting DHCPv6"
" as requested by IPv6 router...");
if (!dhcp6_start (self, FALSE, &reason)) {
if (priv->dhcp6.mode == NM_RDISC_DHCP_LEVEL_MANAGED) {
if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED) {
nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
return;
}
@ -6353,17 +6353,17 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
}
}
if (changed & NM_RDISC_CONFIG_HOP_LIMIT)
if (changed & NM_NDISC_CONFIG_HOP_LIMIT)
nm_platform_sysctl_set_ip6_hop_limit_safe (NM_PLATFORM_GET, nm_device_get_ip_iface (self), rdata->hop_limit);
if (changed & NM_RDISC_CONFIG_MTU)
if (changed & NM_NDISC_CONFIG_MTU)
priv->ip6_mtu = rdata->mtu;
nm_device_activate_schedule_ip6_config_result (self);
}
static void
rdisc_ra_timeout (NMRDisc *rdisc, NMDevice *self)
ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
@ -6393,13 +6393,13 @@ addrconf6_start_with_link_ready (NMDevice *self)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMUtilsIPv6IfaceId iid;
g_assert (priv->rdisc);
g_assert (priv->ndisc);
if (nm_device_get_ip_iface_identifier (self, &iid, FALSE)) {
_LOGD (LOGD_IP6, "addrconf6: using the device EUI-64 identifier");
nm_rdisc_set_iid (priv->rdisc, iid);
nm_ndisc_set_iid (priv->ndisc, iid);
} else {
/* Don't abort the addrconf at this point -- if rdisc needs the iid
/* Don't abort the addrconf at this point -- if ndisc needs the iid
* it will notice this itself. */
_LOGI (LOGD_IP6, "addrconf6: no interface identifier; IPv6 adddress creation may fail");
}
@ -6413,16 +6413,16 @@ addrconf6_start_with_link_ready (NMDevice *self)
nm_device_ipv6_sysctl_set (self, "accept_ra_pinfo", "0");
nm_device_ipv6_sysctl_set (self, "accept_ra_rtr_pref", "0");
priv->rdisc_changed_id = g_signal_connect (priv->rdisc,
NM_RDISC_CONFIG_CHANGED,
G_CALLBACK (rdisc_config_changed),
priv->ndisc_changed_id = g_signal_connect (priv->ndisc,
NM_NDISC_CONFIG_CHANGED,
G_CALLBACK (ndisc_config_changed),
self);
priv->rdisc_timeout_id = g_signal_connect (priv->rdisc,
NM_RDISC_RA_TIMEOUT,
G_CALLBACK (rdisc_ra_timeout),
priv->ndisc_timeout_id = g_signal_connect (priv->ndisc,
NM_NDISC_RA_TIMEOUT,
G_CALLBACK (ndisc_ra_timeout),
self);
nm_rdisc_start (priv->rdisc);
nm_ndisc_start (priv->ndisc);
return TRUE;
}
@ -6451,7 +6451,7 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr)
stable_id = _get_stable_id (connection, &stable_type);
if (stable_id) {
priv->rdisc = nm_lndp_rdisc_new (NM_PLATFORM_GET,
priv->ndisc = nm_lndp_ndisc_new (NM_PLATFORM_GET,
nm_device_get_ip_ifindex (self),
nm_device_get_ip_iface (self),
stable_type,
@ -6459,13 +6459,13 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr)
nm_setting_ip6_config_get_addr_gen_mode (s_ip6),
&error);
}
if (!priv->rdisc) {
_LOGE (LOGD_IP6, "addrconf6: failed to start router discovery: %s", error->message);
if (!priv->ndisc) {
_LOGE (LOGD_IP6, "addrconf6: failed to start neighbor discovery: %s", error->message);
g_error_free (error);
return FALSE;
}
priv->rdisc_use_tempaddr = use_tempaddr;
priv->ndisc_use_tempaddr = use_tempaddr;
if ( NM_IN_SET (use_tempaddr, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)
&& !nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET)) {
@ -6483,7 +6483,7 @@ addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr)
return TRUE;
}
/* success; already have the LL address; kick off router discovery */
/* success; already have the LL address; kick off neighbor discovery */
g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS);
return addrconf6_start_with_link_ready (self);
}
@ -6493,13 +6493,13 @@ addrconf6_cleanup (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
nm_clear_g_signal_handler (priv->rdisc, &priv->rdisc_changed_id);
nm_clear_g_signal_handler (priv->rdisc, &priv->rdisc_timeout_id);
nm_clear_g_signal_handler (priv->ndisc, &priv->ndisc_changed_id);
nm_clear_g_signal_handler (priv->ndisc, &priv->ndisc_timeout_id);
nm_device_remove_pending_action (self, PENDING_ACTION_AUTOCONF6, FALSE);
g_clear_object (&priv->ac_ip6_config);
g_clear_object (&priv->rdisc);
g_clear_object (&priv->ndisc);
}
/*****************************************************************************/
@ -6714,7 +6714,7 @@ act_stage3_ip6_config_start (NMDevice *self,
}
}
priv->dhcp6.mode = NM_RDISC_DHCP_LEVEL_NONE;
priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_NONE;
priv->dhcp6.num_tries_left = DHCP_NUM_TRIES_MAX;
method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
@ -6763,7 +6763,7 @@ act_stage3_ip6_config_start (NMDevice *self,
} else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) {
ret = linklocal6_start (self);
} else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
priv->dhcp6.mode = NM_RDISC_DHCP_LEVEL_MANAGED;
priv->dhcp6.mode = NM_NDISC_DHCP_LEVEL_MANAGED;
if (!dhcp6_start (self, TRUE, reason)) {
/* IPv6 might be disabled; allow IPv4 to proceed */
ret = NM_ACT_STAGE_RETURN_IP_FAIL;
@ -7482,7 +7482,7 @@ activate_stage5_ip6_config_commit (NMDevice *self)
}
if (ip6_config_merge_and_apply (self, TRUE, &reason)) {
if ( priv->dhcp6.mode != NM_RDISC_DHCP_LEVEL_NONE
if ( priv->dhcp6.mode != NM_NDISC_DHCP_LEVEL_NONE
&& priv->ip6_state == IP_CONF) {
if (priv->dhcp6.ip6_config) {
/* If IPv6 wasn't the first IP to complete, and DHCP was used,
@ -9635,8 +9635,8 @@ queued_ip6_config_change (gpointer user_data)
if (IN6_IS_ADDR_LINKLOCAL (&addr->address))
need_ipv6ll = TRUE;
else if (priv->rdisc)
nm_rdisc_dad_failed (priv->rdisc, &addr->address);
else if (priv->ndisc)
nm_ndisc_dad_failed (priv->ndisc, &addr->address);
}
/* If no IPv6 link-local address exists but other addresses do then we
@ -11047,7 +11047,7 @@ nm_device_spawn_iface_helper (NMDevice *self)
g_ptr_array_add (argv, g_strdup ("--slaac-required"));
g_ptr_array_add (argv, g_strdup ("--slaac-tempaddr"));
g_ptr_array_add (argv, g_strdup_printf ("%d", priv->rdisc_use_tempaddr));
g_ptr_array_add (argv, g_strdup_printf ("%d", priv->ndisc_use_tempaddr));
if (nm_device_get_ip_iface_identifier (self, &iid, FALSE)) {
g_ptr_array_add (argv, g_strdup ("--iid"));

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-fake-rdisc.c - Fake implementation of router discovery
/* nm-fake-ndisc.c - Fake implementation of neighbor discovery
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,14 +20,14 @@
#include "nm-default.h"
#include "nm-fake-rdisc.h"
#include "nm-fake-ndisc.h"
#include <string.h>
#include <arpa/inet.h>
#include "nm-rdisc-private.h"
#include "nm-ndisc-private.h"
#define _NMLOG_PREFIX_NAME "rdisc-fake"
#define _NMLOG_PREFIX_NAME "ndisc-fake"
/*****************************************************************************/
@ -35,7 +35,7 @@ typedef struct {
guint id;
guint when;
NMRDiscDHCPLevel dhcp_level;
NMNDiscDHCPLevel dhcp_level;
GArray *gateways;
GArray *prefixes;
GArray *dns_servers;
@ -51,7 +51,7 @@ typedef struct {
guint32 timestamp;
guint32 lifetime;
guint32 preferred;
NMRDiscPreference preference;
NMNDiscPreference preference;
} FakePrefix;
/*****************************************************************************/
@ -65,20 +65,20 @@ static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
guint receive_ra_id;
GSList *ras;
} NMFakeRDiscPrivate;
} NMFakeNDiscPrivate;
struct _NMFakeRRDisc {
NMRDisc parent;
NMFakeRDiscPrivate _priv;
struct _NMFakeRNDisc {
NMNDisc parent;
NMFakeNDiscPrivate _priv;
};
struct _NMFakeRRDiscClass {
NMRDiscClass parent;
struct _NMFakeRNDiscClass {
NMNDiscClass parent;
};
G_DEFINE_TYPE (NMFakeRDisc, nm_fake_rdisc, NM_TYPE_RDISC)
G_DEFINE_TYPE (NMFakeNDisc, nm_fake_ndisc, NM_TYPE_NDISC)
#define NM_FAKE_RDISC_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMFakeRDisc, NM_IS_FAKE_RDISC)
#define NM_FAKE_NDISC_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMFakeNDisc, NM_IS_FAKE_NDISC)
/*****************************************************************************/
@ -97,7 +97,7 @@ fake_ra_free (gpointer data)
static void
ra_dns_domain_free (gpointer data)
{
g_free (((NMRDiscDNSDomain *)(data))->domain);
g_free (((NMNDiscDNSDomain *)(data))->domain);
}
static FakeRa *
@ -113,13 +113,13 @@ find_ra (GSList *ras, guint id)
}
guint
nm_fake_rdisc_add_ra (NMFakeRDisc *self,
nm_fake_ndisc_add_ra (NMFakeNDisc *self,
guint seconds_after_previous,
NMRDiscDHCPLevel dhcp_level,
NMNDiscDHCPLevel dhcp_level,
int hop_limit,
guint32 mtu)
{
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE (self);
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (self);
static guint counter = 1;
FakeRa *ra;
@ -129,10 +129,10 @@ nm_fake_rdisc_add_ra (NMFakeRDisc *self,
ra->dhcp_level = dhcp_level;
ra->hop_limit = hop_limit;
ra->mtu = mtu;
ra->gateways = g_array_new (FALSE, FALSE, sizeof (NMRDiscGateway));
ra->gateways = g_array_new (FALSE, FALSE, sizeof (NMNDiscGateway));
ra->prefixes = g_array_new (FALSE, FALSE, sizeof (FakePrefix));
ra->dns_servers = g_array_new (FALSE, FALSE, sizeof (NMRDiscDNSServer));
ra->dns_domains = g_array_new (FALSE, FALSE, sizeof (NMRDiscDNSDomain));
ra->dns_servers = g_array_new (FALSE, FALSE, sizeof (NMNDiscDNSServer));
ra->dns_domains = g_array_new (FALSE, FALSE, sizeof (NMNDiscDNSDomain));
g_array_set_clear_func (ra->dns_domains, ra_dns_domain_free);
priv->ras = g_slist_append (priv->ras, ra);
@ -140,20 +140,20 @@ nm_fake_rdisc_add_ra (NMFakeRDisc *self,
}
void
nm_fake_rdisc_add_gateway (NMFakeRDisc *self,
nm_fake_ndisc_add_gateway (NMFakeNDisc *self,
guint ra_id,
const char *addr,
guint32 timestamp,
guint32 lifetime,
NMRDiscPreference preference)
NMNDiscPreference preference)
{
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE (self);
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (self);
FakeRa *ra = find_ra (priv->ras, ra_id);
NMRDiscGateway *gw;
NMNDiscGateway *gw;
g_assert (ra);
g_array_set_size (ra->gateways, ra->gateways->len + 1);
gw = &g_array_index (ra->gateways, NMRDiscGateway, ra->gateways->len - 1);
gw = &g_array_index (ra->gateways, NMNDiscGateway, ra->gateways->len - 1);
g_assert (inet_pton (AF_INET6, addr, &gw->address) == 1);
gw->timestamp = timestamp;
gw->lifetime = lifetime;
@ -161,7 +161,7 @@ nm_fake_rdisc_add_gateway (NMFakeRDisc *self,
}
void
nm_fake_rdisc_add_prefix (NMFakeRDisc *self,
nm_fake_ndisc_add_prefix (NMFakeNDisc *self,
guint ra_id,
const char *network,
guint plen,
@ -169,9 +169,9 @@ nm_fake_rdisc_add_prefix (NMFakeRDisc *self,
guint32 timestamp,
guint32 lifetime,
guint32 preferred,
NMRDiscPreference preference)
NMNDiscPreference preference)
{
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE (self);
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (self);
FakeRa *ra = find_ra (priv->ras, ra_id);
FakePrefix *prefix;
@ -189,70 +189,70 @@ nm_fake_rdisc_add_prefix (NMFakeRDisc *self,
}
void
nm_fake_rdisc_add_dns_server (NMFakeRDisc *self,
nm_fake_ndisc_add_dns_server (NMFakeNDisc *self,
guint ra_id,
const char *address,
guint32 timestamp,
guint32 lifetime)
{
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE (self);
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (self);
FakeRa *ra = find_ra (priv->ras, ra_id);
NMRDiscDNSServer *dns;
NMNDiscDNSServer *dns;
g_assert (ra);
g_array_set_size (ra->dns_servers, ra->dns_servers->len + 1);
dns = &g_array_index (ra->dns_servers, NMRDiscDNSServer, ra->dns_servers->len - 1);
dns = &g_array_index (ra->dns_servers, NMNDiscDNSServer, ra->dns_servers->len - 1);
g_assert (inet_pton (AF_INET6, address, &dns->address) == 1);
dns->timestamp = timestamp;
dns->lifetime = lifetime;
}
void
nm_fake_rdisc_add_dns_domain (NMFakeRDisc *self,
nm_fake_ndisc_add_dns_domain (NMFakeNDisc *self,
guint ra_id,
const char *domain,
guint32 timestamp,
guint32 lifetime)
{
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE (self);
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (self);
FakeRa *ra = find_ra (priv->ras, ra_id);
NMRDiscDNSDomain *dns;
NMNDiscDNSDomain *dns;
g_assert (ra);
g_array_set_size (ra->dns_domains, ra->dns_domains->len + 1);
dns = &g_array_index (ra->dns_domains, NMRDiscDNSDomain, ra->dns_domains->len - 1);
dns = &g_array_index (ra->dns_domains, NMNDiscDNSDomain, ra->dns_domains->len - 1);
dns->domain = g_strdup (domain);
dns->timestamp = timestamp;
dns->lifetime = lifetime;
}
gboolean
nm_fake_rdisc_done (NMFakeRDisc *self)
nm_fake_ndisc_done (NMFakeNDisc *self)
{
return !NM_FAKE_RDISC_GET_PRIVATE (self)->ras;
return !NM_FAKE_NDISC_GET_PRIVATE (self)->ras;
}
/*****************************************************************************/
static gboolean
send_rs (NMRDisc *rdisc, GError **error)
send_rs (NMNDisc *ndisc, GError **error)
{
g_signal_emit (rdisc, signals[RS_SENT], 0);
g_signal_emit (ndisc, signals[RS_SENT], 0);
return TRUE;
}
static gboolean
receive_ra (gpointer user_data)
{
NMFakeRDisc *self = user_data;
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE (self);
NMRDisc *rdisc = NM_RDISC (self);
NMRDiscDataInternal *rdata = rdisc->rdata;
NMFakeNDisc *self = user_data;
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE (self);
NMNDisc *ndisc = NM_NDISC (self);
NMNDiscDataInternal *rdata = ndisc->rdata;
FakeRa *ra = priv->ras->data;
NMRDiscConfigMap changed = 0;
NMNDiscConfigMap changed = 0;
guint32 now = nm_utils_get_monotonic_timestamp_s ();
guint i;
NMRDiscDHCPLevel dhcp_level;
NMNDiscDHCPLevel dhcp_level;
priv->receive_ra_id = 0;
@ -261,19 +261,19 @@ receive_ra (gpointer user_data)
if (rdata->public.dhcp_level != dhcp_level) {
rdata->public.dhcp_level = dhcp_level;
changed |= NM_RDISC_CONFIG_DHCP_LEVEL;
changed |= NM_NDISC_CONFIG_DHCP_LEVEL;
}
for (i = 0; i < ra->gateways->len; i++) {
NMRDiscGateway *item = &g_array_index (ra->gateways, NMRDiscGateway, i);
NMNDiscGateway *item = &g_array_index (ra->gateways, NMNDiscGateway, i);
if (nm_rdisc_add_gateway (rdisc, item))
changed |= NM_RDISC_CONFIG_GATEWAYS;
if (nm_ndisc_add_gateway (ndisc, item))
changed |= NM_NDISC_CONFIG_GATEWAYS;
}
for (i = 0; i < ra->prefixes->len; i++) {
FakePrefix *item = &g_array_index (ra->prefixes, FakePrefix, i);
NMRDiscRoute route = {
NMNDiscRoute route = {
.network = item->network,
.plen = item->plen,
.gateway = item->gateway,
@ -284,11 +284,11 @@ receive_ra (gpointer user_data)
g_assert (route.plen > 0 && route.plen <= 128);
if (nm_rdisc_add_route (rdisc, &route))
changed |= NM_RDISC_CONFIG_ROUTES;
if (nm_ndisc_add_route (ndisc, &route))
changed |= NM_NDISC_CONFIG_ROUTES;
if (item->plen == 64) {
NMRDiscAddress address = {
NMNDiscAddress address = {
.address = item->network,
.timestamp = item->timestamp,
.lifetime = item->lifetime,
@ -296,39 +296,39 @@ receive_ra (gpointer user_data)
.dad_counter = 0,
};
if (nm_rdisc_complete_and_add_address (rdisc, &address))
changed |= NM_RDISC_CONFIG_ADDRESSES;
if (nm_ndisc_complete_and_add_address (ndisc, &address))
changed |= NM_NDISC_CONFIG_ADDRESSES;
}
}
for (i = 0; i < ra->dns_servers->len; i++) {
NMRDiscDNSServer *item = &g_array_index (ra->dns_servers, NMRDiscDNSServer, i);
NMNDiscDNSServer *item = &g_array_index (ra->dns_servers, NMNDiscDNSServer, i);
if (nm_rdisc_add_dns_server (rdisc, item))
changed |= NM_RDISC_CONFIG_DNS_SERVERS;
if (nm_ndisc_add_dns_server (ndisc, item))
changed |= NM_NDISC_CONFIG_DNS_SERVERS;
}
for (i = 0; i < ra->dns_domains->len; i++) {
NMRDiscDNSDomain *item = &g_array_index (ra->dns_domains, NMRDiscDNSDomain, i);
NMNDiscDNSDomain *item = &g_array_index (ra->dns_domains, NMNDiscDNSDomain, i);
if (nm_rdisc_add_dns_domain (rdisc, item))
changed |= NM_RDISC_CONFIG_DNS_DOMAINS;
if (nm_ndisc_add_dns_domain (ndisc, item))
changed |= NM_NDISC_CONFIG_DNS_DOMAINS;
}
if (rdata->public.mtu != ra->mtu) {
rdata->public.mtu = ra->mtu;
changed |= NM_RDISC_CONFIG_MTU;
changed |= NM_NDISC_CONFIG_MTU;
}
if (rdata->public.hop_limit != ra->hop_limit) {
rdata->public.hop_limit = ra->hop_limit;
changed |= NM_RDISC_CONFIG_HOP_LIMIT;
changed |= NM_NDISC_CONFIG_HOP_LIMIT;
}
priv->ras = g_slist_remove (priv->ras, priv->ras->data);
fake_ra_free (ra);
nm_rdisc_ra_received (NM_RDISC (self), now, changed);
nm_ndisc_ra_received (NM_NDISC (self), now, changed);
/* Schedule next RA */
if (priv->ras) {
@ -340,9 +340,9 @@ receive_ra (gpointer user_data)
}
static void
start (NMRDisc *rdisc)
start (NMNDisc *ndisc)
{
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE ((NMFakeRDisc *) rdisc);
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE ((NMFakeNDisc *) ndisc);
FakeRa *ra;
/* Queue up the first fake RA */
@ -350,58 +350,58 @@ start (NMRDisc *rdisc)
ra = priv->ras->data;
g_assert (!priv->receive_ra_id);
priv->receive_ra_id = g_timeout_add_seconds (ra->when, receive_ra, rdisc);
priv->receive_ra_id = g_timeout_add_seconds (ra->when, receive_ra, ndisc);
}
void
nm_fake_rdisc_emit_new_ras (NMFakeRDisc *self)
nm_fake_ndisc_emit_new_ras (NMFakeNDisc *self)
{
if (!NM_FAKE_RDISC_GET_PRIVATE (self)->receive_ra_id)
start (NM_RDISC (self));
if (!NM_FAKE_NDISC_GET_PRIVATE (self)->receive_ra_id)
start (NM_NDISC (self));
}
/*****************************************************************************/
static void
nm_fake_rdisc_init (NMFakeRDisc *fake_rdisc)
nm_fake_ndisc_init (NMFakeNDisc *fake_ndisc)
{
}
NMRDisc *
nm_fake_rdisc_new (int ifindex, const char *ifname)
NMNDisc *
nm_fake_ndisc_new (int ifindex, const char *ifname)
{
return g_object_new (NM_TYPE_FAKE_RDISC,
NM_RDISC_IFINDEX, ifindex,
NM_RDISC_IFNAME, ifname,
return g_object_new (NM_TYPE_FAKE_NDISC,
NM_NDISC_IFINDEX, ifindex,
NM_NDISC_IFNAME, ifname,
NULL);
}
static void
dispose (GObject *object)
{
NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE ((NMFakeRDisc *) object);
NMFakeNDiscPrivate *priv = NM_FAKE_NDISC_GET_PRIVATE ((NMFakeNDisc *) object);
nm_clear_g_source (&priv->receive_ra_id);
g_slist_free_full (priv->ras, fake_ra_free);
priv->ras = NULL;
G_OBJECT_CLASS (nm_fake_rdisc_parent_class)->dispose (object);
G_OBJECT_CLASS (nm_fake_ndisc_parent_class)->dispose (object);
}
static void
nm_fake_rdisc_class_init (NMFakeRDiscClass *klass)
nm_fake_ndisc_class_init (NMFakeNDiscClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMRDiscClass *rdisc_class = NM_RDISC_CLASS (klass);
NMNDiscClass *ndisc_class = NM_NDISC_CLASS (klass);
object_class->dispose = dispose;
rdisc_class->start = start;
rdisc_class->send_rs = send_rs;
ndisc_class->start = start;
ndisc_class->send_rs = send_rs;
signals[RS_SENT] =
g_signal_new (NM_FAKE_RDISC_RS_SENT,
g_signal_new (NM_FAKE_NDISC_RS_SENT,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-fake-rdisc.h - Fake implementation of router discovery
/* nm-fake-ndisc.h - Fake implementation of neighbor discovery
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,41 +18,41 @@
* Copyright (C) 2013 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_FAKE_RDISC_H__
#define __NETWORKMANAGER_FAKE_RDISC_H__
#ifndef __NETWORKMANAGER_FAKE_NDISC_H__
#define __NETWORKMANAGER_FAKE_NDISC_H__
#include "nm-rdisc.h"
#include "nm-ndisc.h"
#define NM_TYPE_FAKE_RDISC (nm_fake_rdisc_get_type ())
#define NM_FAKE_RDISC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_FAKE_RDISC, NMFakeRDisc))
#define NM_FAKE_RDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_FAKE_RDISC, NMFakeRDiscClass))
#define NM_IS_FAKE_RDISC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_FAKE_RDISC))
#define NM_IS_FAKE_RDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_FAKE_RDISC))
#define NM_FAKE_RDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_FAKE_RDISC, NMFakeRDiscClass))
#define NM_TYPE_FAKE_NDISC (nm_fake_ndisc_get_type ())
#define NM_FAKE_NDISC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_FAKE_NDISC, NMFakeNDisc))
#define NM_FAKE_NDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_FAKE_NDISC, NMFakeNDiscClass))
#define NM_IS_FAKE_NDISC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_FAKE_NDISC))
#define NM_IS_FAKE_NDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_FAKE_NDISC))
#define NM_FAKE_NDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_FAKE_NDISC, NMFakeNDiscClass))
#define NM_FAKE_RDISC_RS_SENT "rs-sent"
#define NM_FAKE_NDISC_RS_SENT "rs-sent"
typedef struct _NMFakeRRDisc NMFakeRDisc;
typedef struct _NMFakeRRDiscClass NMFakeRDiscClass;
typedef struct _NMFakeRNDisc NMFakeNDisc;
typedef struct _NMFakeRNDiscClass NMFakeNDiscClass;
GType nm_fake_rdisc_get_type (void);
GType nm_fake_ndisc_get_type (void);
NMRDisc *nm_fake_rdisc_new (int ifindex, const char *ifname);
NMNDisc *nm_fake_ndisc_new (int ifindex, const char *ifname);
guint nm_fake_rdisc_add_ra (NMFakeRDisc *self,
guint nm_fake_ndisc_add_ra (NMFakeNDisc *self,
guint seconds,
NMRDiscDHCPLevel dhcp_level,
NMNDiscDHCPLevel dhcp_level,
int hop_limit,
guint32 mtu);
void nm_fake_rdisc_add_gateway (NMFakeRDisc *self,
void nm_fake_ndisc_add_gateway (NMFakeNDisc *self,
guint ra_id,
const char *addr,
guint32 timestamp,
guint32 lifetime,
NMRDiscPreference preference);
NMNDiscPreference preference);
void nm_fake_rdisc_add_prefix (NMFakeRDisc *self,
void nm_fake_ndisc_add_prefix (NMFakeNDisc *self,
guint ra_id,
const char *network,
guint plen,
@ -60,22 +60,22 @@ void nm_fake_rdisc_add_prefix (NMFakeRDisc *self,
guint32 timestamp,
guint32 lifetime,
guint32 preferred,
NMRDiscPreference preference);
NMNDiscPreference preference);
void nm_fake_rdisc_add_dns_server (NMFakeRDisc *self,
void nm_fake_ndisc_add_dns_server (NMFakeNDisc *self,
guint ra_id,
const char *address,
guint32 timestamp,
guint32 lifetime);
void nm_fake_rdisc_add_dns_domain (NMFakeRDisc *self,
void nm_fake_ndisc_add_dns_domain (NMFakeNDisc *self,
guint ra_id,
const char *domain,
guint32 timestamp,
guint32 lifetime);
void nm_fake_rdisc_emit_new_ras (NMFakeRDisc *self);
void nm_fake_ndisc_emit_new_ras (NMFakeNDisc *self);
gboolean nm_fake_rdisc_done (NMFakeRDisc *self);
gboolean nm_fake_ndisc_done (NMFakeNDisc *self);
#endif /* __NETWORKMANAGER_FAKE_RDISC_H__ */
#endif /* __NETWORKMANAGER_FAKE_NDISC_H__ */

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-lndp-rdisc.c - Router discovery implementation using libndp
/* nm-lndp-ndisc.c - Router discovery implementation using libndp
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@
#include "nm-default.h"
#include "nm-lndp-rdisc.h"
#include "nm-lndp-ndisc.h"
#include <string.h>
#include <arpa/inet.h>
@ -28,12 +28,12 @@
#include <stdarg.h>
#include <ndp.h>
#include "nm-rdisc-private.h"
#include "nm-ndisc-private.h"
#include "NetworkManagerUtils.h"
#include "nm-platform.h"
#include "nmp-netns.h"
#define _NMLOG_PREFIX_NAME "rdisc-lndp"
#define _NMLOG_PREFIX_NAME "ndisc-lndp"
/*****************************************************************************/
@ -43,31 +43,31 @@ typedef struct {
GIOChannel *event_channel;
guint event_id;
guint ra_timeout_id; /* first RA timeout */
} NMLndpRDiscPrivate;
} NMLndpNDiscPrivate;
/*****************************************************************************/
struct _NMLndpRDisc {
NMRDisc parent;
NMLndpRDiscPrivate _priv;
struct _NMLndpNDisc {
NMNDisc parent;
NMLndpNDiscPrivate _priv;
};
struct _NMLndpRDiscClass {
NMRDiscClass parent;
struct _NMLndpNDiscClass {
NMNDiscClass parent;
};
/*****************************************************************************/
G_DEFINE_TYPE (NMLndpRDisc, nm_lndp_rdisc, NM_TYPE_RDISC)
G_DEFINE_TYPE (NMLndpNDisc, nm_lndp_ndisc, NM_TYPE_NDISC)
#define NM_LNDP_RDISC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMLndpRDisc, NM_IS_LNDP_RDISC)
#define NM_LNDP_NDISC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMLndpNDisc, NM_IS_LNDP_NDISC)
/*****************************************************************************/
static gboolean
send_rs (NMRDisc *rdisc, GError **error)
send_rs (NMNDisc *ndisc, GError **error)
{
NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc);
NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc);
struct ndp_msg *msg;
int errsv;
@ -78,7 +78,7 @@ send_rs (NMRDisc *rdisc, GError **error)
"cannot create router solicitation");
return FALSE;
}
ndp_msg_ifindex_set (msg, nm_rdisc_get_ifindex (rdisc));
ndp_msg_ifindex_set (msg, nm_ndisc_get_ifindex (ndisc));
errsv = ndp_msg_send (priv->ndp, msg);
ndp_msg_destroy (msg);
@ -93,19 +93,19 @@ send_rs (NMRDisc *rdisc, GError **error)
return TRUE;
}
_NM_UTILS_LOOKUP_DEFINE (static, translate_preference, enum ndp_route_preference, NMRDiscPreference,
NM_UTILS_LOOKUP_DEFAULT (NM_RDISC_PREFERENCE_INVALID),
NM_UTILS_LOOKUP_ITEM (NDP_ROUTE_PREF_LOW, NM_RDISC_PREFERENCE_LOW),
NM_UTILS_LOOKUP_ITEM (NDP_ROUTE_PREF_MEDIUM, NM_RDISC_PREFERENCE_MEDIUM),
NM_UTILS_LOOKUP_ITEM (NDP_ROUTE_PREF_HIGH, NM_RDISC_PREFERENCE_HIGH),
_NM_UTILS_LOOKUP_DEFINE (static, translate_preference, enum ndp_route_preference, NMNDiscPreference,
NM_UTILS_LOOKUP_DEFAULT (NM_NDISC_PREFERENCE_INVALID),
NM_UTILS_LOOKUP_ITEM (NDP_ROUTE_PREF_LOW, NM_NDISC_PREFERENCE_LOW),
NM_UTILS_LOOKUP_ITEM (NDP_ROUTE_PREF_MEDIUM, NM_NDISC_PREFERENCE_MEDIUM),
NM_UTILS_LOOKUP_ITEM (NDP_ROUTE_PREF_HIGH, NM_NDISC_PREFERENCE_HIGH),
);
static int
receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
{
NMRDisc *rdisc = (NMRDisc *) user_data;
NMRDiscDataInternal *rdata = rdisc->rdata;
NMRDiscConfigMap changed = 0;
NMNDisc *ndisc = (NMNDisc *) user_data;
NMNDiscDataInternal *rdata = ndisc->rdata;
NMNDiscConfigMap changed = 0;
struct ndp_msgra *msgra = ndp_msgra (msg);
struct in6_addr gateway_addr;
guint32 now = nm_utils_get_monotonic_timestamp_s ();
@ -132,24 +132,24 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
* rewrite the flag with every inbound RA.
*/
{
NMRDiscDHCPLevel dhcp_level;
NMNDiscDHCPLevel dhcp_level;
if (ndp_msgra_flag_managed (msgra))
dhcp_level = NM_RDISC_DHCP_LEVEL_MANAGED;
dhcp_level = NM_NDISC_DHCP_LEVEL_MANAGED;
else if (ndp_msgra_flag_other (msgra))
dhcp_level = NM_RDISC_DHCP_LEVEL_OTHERCONF;
dhcp_level = NM_NDISC_DHCP_LEVEL_OTHERCONF;
else
dhcp_level = NM_RDISC_DHCP_LEVEL_NONE;
dhcp_level = NM_NDISC_DHCP_LEVEL_NONE;
/* when receiving multiple RA (possibly from different routers),
* let's keep the "most managed" level. */
G_STATIC_ASSERT_EXPR (NM_RDISC_DHCP_LEVEL_MANAGED > NM_RDISC_DHCP_LEVEL_OTHERCONF);
G_STATIC_ASSERT_EXPR (NM_RDISC_DHCP_LEVEL_OTHERCONF > NM_RDISC_DHCP_LEVEL_NONE);
G_STATIC_ASSERT_EXPR (NM_NDISC_DHCP_LEVEL_MANAGED > NM_NDISC_DHCP_LEVEL_OTHERCONF);
G_STATIC_ASSERT_EXPR (NM_NDISC_DHCP_LEVEL_OTHERCONF > NM_NDISC_DHCP_LEVEL_NONE);
dhcp_level = MAX (dhcp_level, rdata->public.dhcp_level);
if (dhcp_level != rdata->public.dhcp_level) {
rdata->public.dhcp_level = dhcp_level;
changed |= NM_RDISC_CONFIG_DHCP_LEVEL;
changed |= NM_NDISC_CONFIG_DHCP_LEVEL;
}
}
@ -161,15 +161,15 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
*/
gateway_addr = *ndp_msg_addrto (msg);
{
NMRDiscGateway gateway = {
NMNDiscGateway gateway = {
.address = gateway_addr,
.timestamp = now,
.lifetime = ndp_msgra_router_lifetime (msgra),
.preference = translate_preference (ndp_msgra_route_preference (msgra)),
};
if (nm_rdisc_add_gateway (rdisc, &gateway))
changed |= NM_RDISC_CONFIG_GATEWAYS;
if (nm_ndisc_add_gateway (ndisc, &gateway))
changed |= NM_NDISC_CONFIG_GATEWAYS;
}
/* Addresses & Routes */
@ -185,21 +185,21 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
nm_utils_ip6_address_clear_host_address (&r_network, ndp_msg_opt_prefix (msg, offset), r_plen);
if (ndp_msg_opt_prefix_flag_on_link (msg, offset)) {
NMRDiscRoute route = {
NMNDiscRoute route = {
.network = r_network,
.plen = r_plen,
.timestamp = now,
.lifetime = ndp_msg_opt_prefix_valid_time (msg, offset),
};
if (nm_rdisc_add_route (rdisc, &route))
changed |= NM_RDISC_CONFIG_ROUTES;
if (nm_ndisc_add_route (ndisc, &route))
changed |= NM_NDISC_CONFIG_ROUTES;
}
/* Address */
if ( r_plen == 64
&& ndp_msg_opt_prefix_flag_auto_addr_conf (msg, offset)) {
NMRDiscAddress address = {
NMNDiscAddress address = {
.address = r_network,
.timestamp = now,
.lifetime = ndp_msg_opt_prefix_valid_time (msg, offset),
@ -208,12 +208,12 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
if (address.preferred > address.lifetime)
address.preferred = address.lifetime;
if (nm_rdisc_complete_and_add_address (rdisc, &address))
changed |= NM_RDISC_CONFIG_ADDRESSES;
if (nm_ndisc_complete_and_add_address (ndisc, &address))
changed |= NM_NDISC_CONFIG_ADDRESSES;
}
}
ndp_msg_opt_for_each_offset(offset, msg, NDP_MSG_OPT_ROUTE) {
NMRDiscRoute route = {
NMNDiscRoute route = {
.gateway = gateway_addr,
.plen = ndp_msg_opt_route_prefix_len (msg, offset),
.timestamp = now,
@ -226,8 +226,8 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
/* Routers through this particular gateway */
nm_utils_ip6_address_clear_host_address (&route.network, ndp_msg_opt_route_prefix (msg, offset), route.plen);
if (nm_rdisc_add_route (rdisc, &route))
changed |= NM_RDISC_CONFIG_ROUTES;
if (nm_ndisc_add_route (ndisc, &route))
changed |= NM_NDISC_CONFIG_ROUTES;
}
/* DNS information */
@ -236,7 +236,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
int addr_index;
ndp_msg_opt_rdnss_for_each_addr (addr, addr_index, msg, offset) {
NMRDiscDNSServer dns_server = {
NMNDiscDNSServer dns_server = {
.address = *addr,
.timestamp = now,
.lifetime = ndp_msg_opt_rdnss_lifetime (msg, offset),
@ -249,8 +249,8 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
*/
if (dns_server.lifetime && dns_server.lifetime < 7200)
dns_server.lifetime = 7200;
if (nm_rdisc_add_dns_server (rdisc, &dns_server))
changed |= NM_RDISC_CONFIG_DNS_SERVERS;
if (nm_ndisc_add_dns_server (ndisc, &dns_server))
changed |= NM_NDISC_CONFIG_DNS_SERVERS;
}
}
ndp_msg_opt_for_each_offset(offset, msg, NDP_MSG_OPT_DNSSL) {
@ -258,7 +258,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
int domain_index;
ndp_msg_opt_dnssl_for_each_domain (domain, domain_index, msg, offset) {
NMRDiscDNSDomain dns_domain = {
NMNDiscDNSDomain dns_domain = {
.domain = domain,
.timestamp = now,
.lifetime = ndp_msg_opt_rdnss_lifetime (msg, offset),
@ -271,15 +271,15 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
*/
if (dns_domain.lifetime && dns_domain.lifetime < 7200)
dns_domain.lifetime = 7200;
if (nm_rdisc_add_dns_domain (rdisc, &dns_domain))
changed |= NM_RDISC_CONFIG_DNS_DOMAINS;
if (nm_ndisc_add_dns_domain (ndisc, &dns_domain))
changed |= NM_NDISC_CONFIG_DNS_DOMAINS;
}
}
hop_limit = ndp_msgra_curhoplimit (msgra);
if (rdata->public.hop_limit != hop_limit) {
rdata->public.hop_limit = hop_limit;
changed |= NM_RDISC_CONFIG_HOP_LIMIT;
changed |= NM_NDISC_CONFIG_HOP_LIMIT;
}
/* MTU */
@ -288,7 +288,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
if (mtu >= 1280) {
if (rdata->public.mtu != mtu) {
rdata->public.mtu = mtu;
changed |= NM_RDISC_CONFIG_MTU;
changed |= NM_NDISC_CONFIG_MTU;
}
} else {
/* All sorts of bad things would happen if we accepted this.
@ -299,19 +299,19 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
}
}
nm_rdisc_ra_received (rdisc, now, changed);
nm_ndisc_ra_received (ndisc, now, changed);
return 0;
}
static gboolean
event_ready (GIOChannel *source, GIOCondition condition, NMRDisc *rdisc)
event_ready (GIOChannel *source, GIOCondition condition, NMNDisc *ndisc)
{
nm_auto_pop_netns NMPNetns *netns = NULL;
NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc);
NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc);
_LOGD ("processing libndp events");
if (!nm_rdisc_netns_push (rdisc, &netns))
if (!nm_ndisc_netns_push (ndisc, &netns))
return G_SOURCE_CONTINUE;
ndp_callall_eventfd_handler (priv->ndp);
@ -319,18 +319,18 @@ event_ready (GIOChannel *source, GIOCondition condition, NMRDisc *rdisc)
}
static void
start (NMRDisc *rdisc)
start (NMNDisc *ndisc)
{
NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc);
NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc);
int fd = ndp_get_eventfd (priv->ndp);
priv->event_channel = g_io_channel_unix_new (fd);
priv->event_id = g_io_add_watch (priv->event_channel, G_IO_IN, (GIOFunc) event_ready, rdisc);
priv->event_id = g_io_add_watch (priv->event_channel, G_IO_IN, (GIOFunc) event_ready, ndisc);
/* Flush any pending messages to avoid using obsolete information */
event_ready (priv->event_channel, 0, rdisc);
event_ready (priv->event_channel, 0, ndisc);
ndp_msgrcv_handler_register (priv->ndp, receive_ra, NDP_MSG_RA, nm_rdisc_get_ifindex (rdisc), rdisc);
ndp_msgrcv_handler_register (priv->ndp, receive_ra, NDP_MSG_RA, nm_ndisc_get_ifindex (ndisc), ndisc);
}
/*****************************************************************************/
@ -347,12 +347,12 @@ ipv6_sysctl_get (NMPlatform *platform, const char *ifname, const char *property,
}
static void
nm_lndp_rdisc_init (NMLndpRDisc *lndp_rdisc)
nm_lndp_ndisc_init (NMLndpNDisc *lndp_ndisc)
{
}
NMRDisc *
nm_lndp_rdisc_new (NMPlatform *platform,
NMNDisc *
nm_lndp_ndisc_new (NMPlatform *platform,
int ifindex,
const char *ifname,
NMUtilsStableType stable_type,
@ -361,8 +361,8 @@ nm_lndp_rdisc_new (NMPlatform *platform,
GError **error)
{
nm_auto_pop_netns NMPNetns *netns = NULL;
NMRDisc *rdisc;
NMLndpRDiscPrivate *priv;
NMNDisc *ndisc;
NMLndpNDiscPrivate *priv;
int errsv;
g_return_val_if_fail (NM_IS_PLATFORM (platform), NULL);
@ -371,25 +371,25 @@ nm_lndp_rdisc_new (NMPlatform *platform,
if (!nm_platform_netns_push (platform, &netns))
return NULL;
rdisc = g_object_new (NM_TYPE_LNDP_RDISC,
NM_RDISC_PLATFORM, platform,
NM_RDISC_STABLE_TYPE, (int) stable_type,
NM_RDISC_IFINDEX, ifindex,
NM_RDISC_IFNAME, ifname,
NM_RDISC_NETWORK_ID, network_id,
NM_RDISC_ADDR_GEN_MODE, (int) addr_gen_mode,
NM_RDISC_MAX_ADDRESSES, ipv6_sysctl_get (platform, ifname,
ndisc = g_object_new (NM_TYPE_LNDP_NDISC,
NM_NDISC_PLATFORM, platform,
NM_NDISC_STABLE_TYPE, (int) stable_type,
NM_NDISC_IFINDEX, ifindex,
NM_NDISC_IFNAME, ifname,
NM_NDISC_NETWORK_ID, network_id,
NM_NDISC_ADDR_GEN_MODE, (int) addr_gen_mode,
NM_NDISC_MAX_ADDRESSES, ipv6_sysctl_get (platform, ifname,
"max_addresses",
0, G_MAXINT32, NM_RDISC_MAX_ADDRESSES_DEFAULT),
NM_RDISC_ROUTER_SOLICITATIONS, ipv6_sysctl_get (platform, ifname,
0, G_MAXINT32, NM_NDISC_MAX_ADDRESSES_DEFAULT),
NM_NDISC_ROUTER_SOLICITATIONS, ipv6_sysctl_get (platform, ifname,
"router_solicitations",
1, G_MAXINT32, NM_RDISC_ROUTER_SOLICITATIONS_DEFAULT),
NM_RDISC_ROUTER_SOLICITATION_INTERVAL, ipv6_sysctl_get (platform, ifname,
1, G_MAXINT32, NM_NDISC_ROUTER_SOLICITATIONS_DEFAULT),
NM_NDISC_ROUTER_SOLICITATION_INTERVAL, ipv6_sysctl_get (platform, ifname,
"router_solicitation_interval",
1, G_MAXINT32, NM_RDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT),
1, G_MAXINT32, NM_NDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT),
NULL);
priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc);
priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc);
errsv = ndp_open (&priv->ndp);
@ -398,37 +398,37 @@ nm_lndp_rdisc_new (NMPlatform *platform,
g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN,
"failure creating libndp socket: %s (%d)",
g_strerror (errsv), errsv);
g_object_unref (rdisc);
g_object_unref (ndisc);
return NULL;
}
return rdisc;
return ndisc;
}
static void
dispose (GObject *object)
{
NMRDisc *rdisc = (NMRDisc *) object;
NMLndpRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE ((NMLndpRDisc *) rdisc);
NMNDisc *ndisc = (NMNDisc *) object;
NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc);
nm_clear_g_source (&priv->event_id);
g_clear_pointer (&priv->event_channel, g_io_channel_unref);
if (priv->ndp) {
ndp_msgrcv_handler_unregister (priv->ndp, receive_ra, NDP_MSG_RA, nm_rdisc_get_ifindex (rdisc), rdisc);
ndp_msgrcv_handler_unregister (priv->ndp, receive_ra, NDP_MSG_RA, nm_ndisc_get_ifindex (ndisc), ndisc);
ndp_close (priv->ndp);
priv->ndp = NULL;
}
G_OBJECT_CLASS (nm_lndp_rdisc_parent_class)->dispose (object);
G_OBJECT_CLASS (nm_lndp_ndisc_parent_class)->dispose (object);
}
static void
nm_lndp_rdisc_class_init (NMLndpRDiscClass *klass)
nm_lndp_ndisc_class_init (NMLndpNDiscClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMRDiscClass *rdisc_class = NM_RDISC_CLASS (klass);
NMNDiscClass *ndisc_class = NM_NDISC_CLASS (klass);
object_class->dispose = dispose;
rdisc_class->start = start;
rdisc_class->send_rs = send_rs;
ndisc_class->start = start;
ndisc_class->send_rs = send_rs;
}

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-lndp-rdisc.h - Implementation of router discovery using libndp
/* nm-lndp-ndisc.h - Implementation of neighbor discovery using libndp
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,25 +18,25 @@
* Copyright (C) 2013 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_LNDP_RDISC_H__
#define __NETWORKMANAGER_LNDP_RDISC_H__
#ifndef __NETWORKMANAGER_LNDP_NDISC_H__
#define __NETWORKMANAGER_LNDP_NDISC_H__
#include "nm-rdisc.h"
#include "nm-ndisc.h"
#include "nm-core-utils.h"
#define NM_TYPE_LNDP_RDISC (nm_lndp_rdisc_get_type ())
#define NM_LNDP_RDISC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_LNDP_RDISC, NMLndpRDisc))
#define NM_LNDP_RDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_LNDP_RDISC, NMLndpRDiscClass))
#define NM_IS_LNDP_RDISC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_LNDP_RDISC))
#define NM_IS_LNDP_RDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_LNDP_RDISC))
#define NM_LNDP_RDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_LNDP_RDISC, NMLndpRDiscClass))
#define NM_TYPE_LNDP_NDISC (nm_lndp_ndisc_get_type ())
#define NM_LNDP_NDISC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_LNDP_NDISC, NMLndpNDisc))
#define NM_LNDP_NDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_LNDP_NDISC, NMLndpNDiscClass))
#define NM_IS_LNDP_NDISC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_LNDP_NDISC))
#define NM_IS_LNDP_NDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_LNDP_NDISC))
#define NM_LNDP_NDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_LNDP_NDISC, NMLndpNDiscClass))
typedef struct _NMLndpRDisc NMLndpRDisc;
typedef struct _NMLndpRDiscClass NMLndpRDiscClass;
typedef struct _NMLndpNDisc NMLndpNDisc;
typedef struct _NMLndpNDiscClass NMLndpNDiscClass;
GType nm_lndp_rdisc_get_type (void);
GType nm_lndp_ndisc_get_type (void);
NMRDisc *nm_lndp_rdisc_new (NMPlatform *platform,
NMNDisc *nm_lndp_ndisc_new (NMPlatform *platform,
int ifindex,
const char *ifname,
NMUtilsStableType stable_type,
@ -44,4 +44,4 @@ NMRDisc *nm_lndp_rdisc_new (NMPlatform *platform,
NMSettingIP6ConfigAddrGenMode addr_gen_mode,
GError **error);
#endif /* __NETWORKMANAGER_LNDP_RDISC_H__ */
#endif /* __NETWORKMANAGER_LNDP_NDISC_H__ */

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-rdisc.h - Perform IPv6 router discovery
/* nm-ndisc.h - Perform IPv6 neighbor discovery
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,15 +18,15 @@
* Copyright 2015 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_RDISC_PRIVATE_H__
#define __NETWORKMANAGER_RDISC_PRIVATE_H__
#ifndef __NETWORKMANAGER_NDISC_PRIVATE_H__
#define __NETWORKMANAGER_NDISC_PRIVATE_H__
#include "nm-rdisc.h"
#include "nm-ndisc.h"
/* Functions only used by rdisc implementations */
/* Functions only used by ndisc implementations */
struct _NMRDiscDataInternal {
NMRDiscData public;
struct _NMNDiscDataInternal {
NMNDiscData public;
GArray *gateways;
GArray *addresses;
GArray *routes;
@ -34,20 +34,20 @@ struct _NMRDiscDataInternal {
GArray *dns_domains;
};
typedef struct _NMRDiscDataInternal NMRDiscDataInternal;
typedef struct _NMNDiscDataInternal NMNDiscDataInternal;
void nm_rdisc_ra_received (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed);
void nm_ndisc_ra_received (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap changed);
gboolean nm_rdisc_add_gateway (NMRDisc *rdisc, const NMRDiscGateway *new);
gboolean nm_rdisc_complete_and_add_address (NMRDisc *rdisc, NMRDiscAddress *new);
gboolean nm_rdisc_add_route (NMRDisc *rdisc, const NMRDiscRoute *new);
gboolean nm_rdisc_add_dns_server (NMRDisc *rdisc, const NMRDiscDNSServer *new);
gboolean nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *new);
gboolean nm_ndisc_add_gateway (NMNDisc *ndisc, const NMNDiscGateway *new);
gboolean nm_ndisc_complete_and_add_address (NMNDisc *ndisc, NMNDiscAddress *new);
gboolean nm_ndisc_add_route (NMNDisc *ndisc, const NMNDiscRoute *new);
gboolean nm_ndisc_add_dns_server (NMNDisc *ndisc, const NMNDiscDNSServer *new);
gboolean nm_ndisc_add_dns_domain (NMNDisc *ndisc, const NMNDiscDNSDomain *new);
/*****************************************************************************/
#define _NMLOG_DOMAIN LOGD_IP6
#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, rdisc, __VA_ARGS__)
#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, ndisc, __VA_ARGS__)
#define _LOG(level, domain, self, ...) \
G_STMT_START { \
@ -55,14 +55,14 @@ gboolean nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDoma
const NMLogDomain __domain = (domain); \
\
if (nm_logging_enabled (__level, __domain)) { \
NMRDisc *const __self = (self); \
NMNDisc *const __self = (self); \
char __prefix[64]; \
\
_nm_log (__level, __domain, 0, \
"%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
(__self \
? ({ \
const char *__ifname = nm_rdisc_get_ifname (__self); \
const char *__ifname = nm_ndisc_get_ifname (__self); \
nm_sprintf_buf (__prefix, "%s[%p,%s%s%s]", \
_NMLOG_PREFIX_NAME, __self, \
NM_PRINT_FMT_QUOTE_STRING (__ifname)); \
@ -74,4 +74,4 @@ gboolean nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDoma
/*****************************************************************************/
#endif /* __NETWORKMANAGER_RDISC_PRIVATE_H__ */
#endif /* __NETWORKMANAGER_NDISC_PRIVATE_H__ */

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-rdisc.c - Perform IPv6 router discovery
/* nm-ndisc.c - Perform IPv6 neighbor discovery
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@
#include "nm-default.h"
#include "nm-rdisc.h"
#include "nm-ndisc.h"
#include <stdlib.h>
#include <arpa/inet.h>
@ -28,18 +28,18 @@
#include "nm-setting-ip6-config.h"
#include "nm-rdisc-private.h"
#include "nm-ndisc-private.h"
#include "nm-utils.h"
#include "nm-platform.h"
#include "nmp-netns.h"
#define _NMLOG_PREFIX_NAME "rdisc"
#define _NMLOG_PREFIX_NAME "ndisc"
/*****************************************************************************/
struct _NMRDiscPrivate {
struct _NMNDiscPrivate {
/* this *must* be the first field. */
NMRDiscDataInternal rdata;
NMNDiscDataInternal rdata;
gint32 solicitations_left;
guint send_rs_id;
@ -63,7 +63,7 @@ struct _NMRDiscPrivate {
NMPNetns *netns;
};
typedef struct _NMRDiscPrivate NMRDiscPrivate;
typedef struct _NMNDiscPrivate NMNDiscPrivate;
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_PLATFORM,
@ -85,32 +85,32 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (NMRDisc, nm_rdisc, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMNDisc, nm_ndisc, G_TYPE_OBJECT)
#define NM_RDISC_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMRDisc, NM_IS_RDISC)
#define NM_NDISC_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMNDisc, NM_IS_NDISC)
/*****************************************************************************/
static void _config_changed_log (NMRDisc *rdisc, NMRDiscConfigMap changed);
static void _config_changed_log (NMNDisc *ndisc, NMNDiscConfigMap changed);
/*****************************************************************************/
NMPNetns *
nm_rdisc_netns_get (NMRDisc *self)
nm_ndisc_netns_get (NMNDisc *self)
{
g_return_val_if_fail (NM_IS_RDISC (self), NULL);
g_return_val_if_fail (NM_IS_NDISC (self), NULL);
return NM_RDISC_GET_PRIVATE (self)->netns;
return NM_NDISC_GET_PRIVATE (self)->netns;
}
gboolean
nm_rdisc_netns_push (NMRDisc *self, NMPNetns **netns)
nm_ndisc_netns_push (NMNDisc *self, NMPNetns **netns)
{
NMRDiscPrivate *priv;
NMNDiscPrivate *priv;
g_return_val_if_fail (NM_IS_RDISC (self), FALSE);
g_return_val_if_fail (NM_IS_NDISC (self), FALSE);
priv = NM_RDISC_GET_PRIVATE (self);
priv = NM_NDISC_GET_PRIVATE (self);
if ( priv->netns
&& !nmp_netns_push (priv->netns)) {
NM_SET_OUT (netns, NULL);
@ -124,25 +124,25 @@ nm_rdisc_netns_push (NMRDisc *self, NMPNetns **netns)
/*****************************************************************************/
int
nm_rdisc_get_ifindex (NMRDisc *self)
nm_ndisc_get_ifindex (NMNDisc *self)
{
g_return_val_if_fail (NM_IS_RDISC (self), 0);
g_return_val_if_fail (NM_IS_NDISC (self), 0);
return NM_RDISC_GET_PRIVATE (self)->ifindex;
return NM_NDISC_GET_PRIVATE (self)->ifindex;
}
const char *
nm_rdisc_get_ifname (NMRDisc *self)
nm_ndisc_get_ifname (NMNDisc *self)
{
g_return_val_if_fail (NM_IS_RDISC (self), NULL);
g_return_val_if_fail (NM_IS_NDISC (self), NULL);
return NM_RDISC_GET_PRIVATE (self)->ifname;
return NM_NDISC_GET_PRIVATE (self)->ifname;
}
/*****************************************************************************/
static const NMRDiscData *
_data_complete (NMRDiscDataInternal *data)
static const NMNDiscData *
_data_complete (NMNDiscDataInternal *data)
{
#define _SET(data, field) \
G_STMT_START { \
@ -161,24 +161,24 @@ _data_complete (NMRDiscDataInternal *data)
}
static void
_emit_config_change (NMRDisc *self, NMRDiscConfigMap changed)
_emit_config_change (NMNDisc *self, NMNDiscConfigMap changed)
{
_config_changed_log (self, changed);
g_signal_emit (self, signals[CONFIG_CHANGED], 0,
_data_complete (&NM_RDISC_GET_PRIVATE (self)->rdata),
_data_complete (&NM_NDISC_GET_PRIVATE (self)->rdata),
(guint) changed);
}
/*****************************************************************************/
gboolean
nm_rdisc_add_gateway (NMRDisc *rdisc, const NMRDiscGateway *new)
nm_ndisc_add_gateway (NMNDisc *ndisc, const NMNDiscGateway *new)
{
NMRDiscDataInternal *rdata = &NM_RDISC_GET_PRIVATE(rdisc)->rdata;
NMNDiscDataInternal *rdata = &NM_NDISC_GET_PRIVATE(ndisc)->rdata;
int i, insert_idx = -1;
for (i = 0; i < rdata->gateways->len; i++) {
NMRDiscGateway *item = &g_array_index (rdata->gateways, NMRDiscGateway, i);
NMNDiscGateway *item = &g_array_index (rdata->gateways, NMNDiscGateway, i);
if (IN6_ARE_ADDR_EQUAL (&item->address, &new->address)) {
if (new->lifetime == 0) {
@ -207,8 +207,8 @@ nm_rdisc_add_gateway (NMRDisc *rdisc, const NMRDiscGateway *new)
/**
* complete_address:
* @rdisc: the #NMRDisc
* @addr: the #NMRDiscAddress
* @ndisc: the #NMNDisc
* @addr: the #NMNDiscAddress
*
* Adds the host part to the address that has network part set.
* If the address already has a host part, add a different host part
@ -220,14 +220,14 @@ nm_rdisc_add_gateway (NMRDisc *rdisc, const NMRDiscGateway *new)
* Returns: %TRUE if the address could be completed, %FALSE otherwise.
**/
static gboolean
complete_address (NMRDisc *rdisc, NMRDiscAddress *addr)
complete_address (NMNDisc *ndisc, NMNDiscAddress *addr)
{
NMRDiscPrivate *priv;
NMNDiscPrivate *priv;
GError *error = NULL;
g_return_val_if_fail (NM_IS_RDISC (rdisc), FALSE);
g_return_val_if_fail (NM_IS_NDISC (ndisc), FALSE);
priv = NM_RDISC_GET_PRIVATE (rdisc);
priv = NM_NDISC_GET_PRIVATE (ndisc);
if (priv->addr_gen_mode == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) {
if (!nm_utils_ipv6_addr_set_stable_privacy (priv->stable_type,
&addr->address,
@ -260,20 +260,20 @@ complete_address (NMRDisc *rdisc, NMRDiscAddress *addr)
}
gboolean
nm_rdisc_complete_and_add_address (NMRDisc *rdisc, NMRDiscAddress *new)
nm_ndisc_complete_and_add_address (NMNDisc *ndisc, NMNDiscAddress *new)
{
NMRDiscPrivate *priv;
NMRDiscDataInternal *rdata;
NMNDiscPrivate *priv;
NMNDiscDataInternal *rdata;
int i;
if (!complete_address (rdisc, new))
if (!complete_address (ndisc, new))
return FALSE;
priv = NM_RDISC_GET_PRIVATE (rdisc);
priv = NM_NDISC_GET_PRIVATE (ndisc);
rdata = &priv->rdata;
for (i = 0; i < rdata->addresses->len; i++) {
NMRDiscAddress *item = &g_array_index (rdata->addresses, NMRDiscAddress, i);
NMNDiscAddress *item = &g_array_index (rdata->addresses, NMNDiscAddress, i);
if (IN6_ARE_ADDR_EQUAL (&item->address, &new->address)) {
gboolean changed;
@ -303,28 +303,28 @@ nm_rdisc_complete_and_add_address (NMRDisc *rdisc, NMRDiscAddress *new)
}
gboolean
nm_rdisc_add_route (NMRDisc *rdisc, const NMRDiscRoute *new)
nm_ndisc_add_route (NMNDisc *ndisc, const NMNDiscRoute *new)
{
NMRDiscPrivate *priv;
NMRDiscDataInternal *rdata;
NMNDiscPrivate *priv;
NMNDiscDataInternal *rdata;
int i, insert_idx = -1;
if (new->plen == 0 || new->plen > 128) {
/* Only expect non-default routes. The router has no idea what the
* local configuration or user preferences are, so sending routes
* with a prefix length of 0 must be ignored by NMRDisc.
* with a prefix length of 0 must be ignored by NMNDisc.
*
* Also, upper layers also don't expect that NMRDisc exposes routes
* Also, upper layers also don't expect that NMNDisc exposes routes
* with a plen or zero or larger then 128.
*/
g_return_val_if_reached (FALSE);
}
priv = NM_RDISC_GET_PRIVATE (rdisc);
priv = NM_NDISC_GET_PRIVATE (ndisc);
rdata = &priv->rdata;
for (i = 0; i < rdata->routes->len; i++) {
NMRDiscRoute *item = &g_array_index (rdata->routes, NMRDiscRoute, i);
NMNDiscRoute *item = &g_array_index (rdata->routes, NMNDiscRoute, i);
if (IN6_ARE_ADDR_EQUAL (&item->network, &new->network) && item->plen == new->plen) {
if (new->lifetime == 0) {
@ -352,17 +352,17 @@ nm_rdisc_add_route (NMRDisc *rdisc, const NMRDiscRoute *new)
}
gboolean
nm_rdisc_add_dns_server (NMRDisc *rdisc, const NMRDiscDNSServer *new)
nm_ndisc_add_dns_server (NMNDisc *ndisc, const NMNDiscDNSServer *new)
{
NMRDiscPrivate *priv;
NMRDiscDataInternal *rdata;
NMNDiscPrivate *priv;
NMNDiscDataInternal *rdata;
int i;
priv = NM_RDISC_GET_PRIVATE (rdisc);
priv = NM_NDISC_GET_PRIVATE (ndisc);
rdata = &priv->rdata;
for (i = 0; i < rdata->dns_servers->len; i++) {
NMRDiscDNSServer *item = &g_array_index (rdata->dns_servers, NMRDiscDNSServer, i);
NMNDiscDNSServer *item = &g_array_index (rdata->dns_servers, NMNDiscDNSServer, i);
if (IN6_ARE_ADDR_EQUAL (&item->address, &new->address)) {
if (new->lifetime == 0) {
@ -384,18 +384,18 @@ nm_rdisc_add_dns_server (NMRDisc *rdisc, const NMRDiscDNSServer *new)
/* Copies new->domain if 'new' is added to the dns_domains list */
gboolean
nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *new)
nm_ndisc_add_dns_domain (NMNDisc *ndisc, const NMNDiscDNSDomain *new)
{
NMRDiscPrivate *priv;
NMRDiscDataInternal *rdata;
NMRDiscDNSDomain *item;
NMNDiscPrivate *priv;
NMNDiscDataInternal *rdata;
NMNDiscDNSDomain *item;
int i;
priv = NM_RDISC_GET_PRIVATE (rdisc);
priv = NM_NDISC_GET_PRIVATE (ndisc);
rdata = &priv->rdata;
for (i = 0; i < rdata->dns_domains->len; i++) {
item = &g_array_index (rdata->dns_domains, NMRDiscDNSDomain, i);
item = &g_array_index (rdata->dns_domains, NMNDiscDNSDomain, i);
if (!g_strcmp0 (item->domain, new->domain)) {
gboolean changed;
@ -417,7 +417,7 @@ nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *new)
if (new->lifetime) {
g_array_insert_val (rdata->dns_domains, i, *new);
item = &g_array_index (rdata->dns_domains, NMRDiscDNSDomain, i);
item = &g_array_index (rdata->dns_domains, NMNDiscDNSDomain, i);
item->domain = g_strdup (new->domain);
}
return !!new->lifetime;
@ -426,8 +426,8 @@ nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *new)
/*****************************************************************************/
/**
* nm_rdisc_set_iid:
* @rdisc: the #NMRDisc
* nm_ndisc_set_iid:
* @ndisc: the #NMNDisc
* @iid: the new interface ID
*
* Sets the "Modified EUI-64" interface ID to be used when generating
@ -445,14 +445,14 @@ nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *new)
* Returns: %TRUE if addresses need to be regenerated, %FALSE otherwise.
**/
gboolean
nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid)
nm_ndisc_set_iid (NMNDisc *ndisc, const NMUtilsIPv6IfaceId iid)
{
NMRDiscPrivate *priv;
NMRDiscDataInternal *rdata;
NMNDiscPrivate *priv;
NMNDiscDataInternal *rdata;
g_return_val_if_fail (NM_IS_RDISC (rdisc), FALSE);
g_return_val_if_fail (NM_IS_NDISC (ndisc), FALSE);
priv = NM_RDISC_GET_PRIVATE (rdisc);
priv = NM_NDISC_GET_PRIVATE (ndisc);
rdata = &priv->rdata;
if (priv->iid.id != iid.id) {
@ -464,7 +464,7 @@ nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid)
if (rdata->addresses->len) {
_LOGD ("IPv6 interface identifier changed, flushing addresses");
g_array_remove_range (rdata->addresses, 0, rdata->addresses->len);
_emit_config_change (rdisc, NM_RDISC_CONFIG_ADDRESSES);
_emit_config_change (ndisc, NM_NDISC_CONFIG_ADDRESSES);
}
return TRUE;
}
@ -473,19 +473,19 @@ nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid)
}
static gboolean
send_rs_timeout (NMRDisc *rdisc)
send_rs_timeout (NMNDisc *ndisc)
{
nm_auto_pop_netns NMPNetns *netns = NULL;
NMRDiscClass *klass = NM_RDISC_GET_CLASS (rdisc);
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
NMNDiscClass *klass = NM_NDISC_GET_CLASS (ndisc);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
GError *error = NULL;
priv->send_rs_id = 0;
if (!nm_rdisc_netns_push (rdisc, &netns))
if (!nm_ndisc_netns_push (ndisc, &netns))
return G_SOURCE_REMOVE;
if (klass->send_rs (rdisc, &error)) {
if (klass->send_rs (ndisc, &error)) {
_LOGD ("router solicitation sent");
priv->solicitations_left--;
g_clear_pointer (&priv->last_send_rs_error, g_free);
@ -507,7 +507,7 @@ send_rs_timeout (NMRDisc *rdisc)
_LOGD ("scheduling router solicitation retry in %d seconds.",
(int) priv->router_solicitation_interval);
priv->send_rs_id = g_timeout_add_seconds (priv->router_solicitation_interval,
(GSourceFunc) send_rs_timeout, rdisc);
(GSourceFunc) send_rs_timeout, ndisc);
} else {
_LOGD ("did not receive a router advertisement after %d solicitations.",
(int) priv->router_solicitations);
@ -517,9 +517,9 @@ send_rs_timeout (NMRDisc *rdisc)
}
static void
solicit (NMRDisc *rdisc)
solicit (NMNDisc *ndisc)
{
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
gint64 next, now;
if (priv->send_rs_id)
@ -533,100 +533,100 @@ solicit (NMRDisc *rdisc)
next = CLAMP (next, 0, G_MAXINT32);
_LOGD ("scheduling explicit router solicitation request in %" G_GINT64_FORMAT " seconds.",
next);
priv->send_rs_id = g_timeout_add_seconds ((guint32) next, (GSourceFunc) send_rs_timeout, rdisc);
priv->send_rs_id = g_timeout_add_seconds ((guint32) next, (GSourceFunc) send_rs_timeout, ndisc);
}
static gboolean
rdisc_ra_timeout_cb (gpointer user_data)
ndisc_ra_timeout_cb (gpointer user_data)
{
NMRDisc *rdisc = NM_RDISC (user_data);
NMNDisc *ndisc = NM_NDISC (user_data);
NM_RDISC_GET_PRIVATE (rdisc)->ra_timeout_id = 0;
g_signal_emit (rdisc, signals[RA_TIMEOUT], 0);
NM_NDISC_GET_PRIVATE (ndisc)->ra_timeout_id = 0;
g_signal_emit (ndisc, signals[RA_TIMEOUT], 0);
return G_SOURCE_REMOVE;
}
void
nm_rdisc_start (NMRDisc *rdisc)
nm_ndisc_start (NMNDisc *ndisc)
{
nm_auto_pop_netns NMPNetns *netns = NULL;
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
NMRDiscClass *klass = NM_RDISC_GET_CLASS (rdisc);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
NMNDiscClass *klass = NM_NDISC_GET_CLASS (ndisc);
gint64 ra_wait_secs;
g_assert (klass->start);
_LOGD ("starting router discovery: %d", priv->ifindex);
_LOGD ("starting neighbor discovery: %d", priv->ifindex);
if (!nm_rdisc_netns_push (rdisc, &netns))
if (!nm_ndisc_netns_push (ndisc, &netns))
return;
nm_clear_g_source (&priv->ra_timeout_id);
ra_wait_secs = (((gint64) priv->router_solicitations) * priv->router_solicitation_interval) + 1;
ra_wait_secs = CLAMP (ra_wait_secs, 30, 120);
priv->ra_timeout_id = g_timeout_add_seconds (ra_wait_secs, rdisc_ra_timeout_cb, rdisc);
priv->ra_timeout_id = g_timeout_add_seconds (ra_wait_secs, ndisc_ra_timeout_cb, ndisc);
_LOGD ("scheduling RA timeout in %d seconds", (int) ra_wait_secs);
if (klass->start)
klass->start (rdisc);
klass->start (ndisc);
solicit (rdisc);
solicit (ndisc);
}
void
nm_rdisc_dad_failed (NMRDisc *rdisc, struct in6_addr *address)
nm_ndisc_dad_failed (NMNDisc *ndisc, struct in6_addr *address)
{
NMRDiscDataInternal *rdata;
NMNDiscDataInternal *rdata;
int i;
gboolean changed = FALSE;
rdata = &NM_RDISC_GET_PRIVATE (rdisc)->rdata;
rdata = &NM_NDISC_GET_PRIVATE (ndisc)->rdata;
for (i = 0; i < rdata->addresses->len; i++) {
NMRDiscAddress *item = &g_array_index (rdata->addresses, NMRDiscAddress, i);
NMNDiscAddress *item = &g_array_index (rdata->addresses, NMNDiscAddress, i);
if (!IN6_ARE_ADDR_EQUAL (&item->address, address))
continue;
_LOGD ("DAD failed for discovered address %s", nm_utils_inet6_ntop (address, NULL));
if (!complete_address (rdisc, item))
if (!complete_address (ndisc, item))
g_array_remove_index (rdata->addresses, i--);
changed = TRUE;
}
if (changed)
_emit_config_change (rdisc, NM_RDISC_CONFIG_ADDRESSES);
_emit_config_change (ndisc, NM_NDISC_CONFIG_ADDRESSES);
}
#define CONFIG_MAP_MAX_STR 7
static void
config_map_to_string (NMRDiscConfigMap map, char *p)
config_map_to_string (NMNDiscConfigMap map, char *p)
{
if (map & NM_RDISC_CONFIG_DHCP_LEVEL)
if (map & NM_NDISC_CONFIG_DHCP_LEVEL)
*p++ = 'd';
if (map & NM_RDISC_CONFIG_GATEWAYS)
if (map & NM_NDISC_CONFIG_GATEWAYS)
*p++ = 'G';
if (map & NM_RDISC_CONFIG_ADDRESSES)
if (map & NM_NDISC_CONFIG_ADDRESSES)
*p++ = 'A';
if (map & NM_RDISC_CONFIG_ROUTES)
if (map & NM_NDISC_CONFIG_ROUTES)
*p++ = 'R';
if (map & NM_RDISC_CONFIG_DNS_SERVERS)
if (map & NM_NDISC_CONFIG_DNS_SERVERS)
*p++ = 'S';
if (map & NM_RDISC_CONFIG_DNS_DOMAINS)
if (map & NM_NDISC_CONFIG_DNS_DOMAINS)
*p++ = 'D';
*p = '\0';
}
static const char *
dhcp_level_to_string (NMRDiscDHCPLevel dhcp_level)
dhcp_level_to_string (NMNDiscDHCPLevel dhcp_level)
{
switch (dhcp_level) {
case NM_RDISC_DHCP_LEVEL_NONE:
case NM_NDISC_DHCP_LEVEL_NONE:
return "none";
case NM_RDISC_DHCP_LEVEL_OTHERCONF:
case NM_NDISC_DHCP_LEVEL_OTHERCONF:
return "otherconf";
case NM_RDISC_DHCP_LEVEL_MANAGED:
case NM_NDISC_DHCP_LEVEL_MANAGED:
return "managed";
default:
return "INVALID";
@ -636,10 +636,10 @@ dhcp_level_to_string (NMRDiscDHCPLevel dhcp_level)
#define expiry(item) (item->timestamp + item->lifetime)
static void
_config_changed_log (NMRDisc *rdisc, NMRDiscConfigMap changed)
_config_changed_log (NMNDisc *ndisc, NMNDiscConfigMap changed)
{
NMRDiscPrivate *priv;
NMRDiscDataInternal *rdata;
NMNDiscPrivate *priv;
NMNDiscDataInternal *rdata;
int i;
char changedstr[CONFIG_MAP_MAX_STR];
char addrstr[INET6_ADDRSTRLEN];
@ -647,26 +647,26 @@ _config_changed_log (NMRDisc *rdisc, NMRDiscConfigMap changed)
if (!_LOGD_ENABLED ())
return;
priv = NM_RDISC_GET_PRIVATE (rdisc);
priv = NM_NDISC_GET_PRIVATE (ndisc);
rdata = &priv->rdata;
config_map_to_string (changed, changedstr);
_LOGD ("router discovery configuration changed [%s]:", changedstr);
_LOGD ("neighbor discovery configuration changed [%s]:", changedstr);
_LOGD (" dhcp-level %s", dhcp_level_to_string (priv->rdata.public.dhcp_level));
for (i = 0; i < rdata->gateways->len; i++) {
NMRDiscGateway *gateway = &g_array_index (rdata->gateways, NMRDiscGateway, i);
NMNDiscGateway *gateway = &g_array_index (rdata->gateways, NMNDiscGateway, i);
inet_ntop (AF_INET6, &gateway->address, addrstr, sizeof (addrstr));
_LOGD (" gateway %s pref %d exp %u", addrstr, gateway->preference, expiry (gateway));
}
for (i = 0; i < rdata->addresses->len; i++) {
NMRDiscAddress *address = &g_array_index (rdata->addresses, NMRDiscAddress, i);
NMNDiscAddress *address = &g_array_index (rdata->addresses, NMNDiscAddress, i);
inet_ntop (AF_INET6, &address->address, addrstr, sizeof (addrstr));
_LOGD (" address %s exp %u", addrstr, expiry (address));
}
for (i = 0; i < rdata->routes->len; i++) {
NMRDiscRoute *route = &g_array_index (rdata->routes, NMRDiscRoute, i);
NMNDiscRoute *route = &g_array_index (rdata->routes, NMNDiscRoute, i);
inet_ntop (AF_INET6, &route->network, addrstr, sizeof (addrstr));
_LOGD (" route %s/%d via %s pref %d exp %u", addrstr, (int) route->plen,
@ -674,28 +674,28 @@ _config_changed_log (NMRDisc *rdisc, NMRDiscConfigMap changed)
expiry (route));
}
for (i = 0; i < rdata->dns_servers->len; i++) {
NMRDiscDNSServer *dns_server = &g_array_index (rdata->dns_servers, NMRDiscDNSServer, i);
NMNDiscDNSServer *dns_server = &g_array_index (rdata->dns_servers, NMNDiscDNSServer, i);
inet_ntop (AF_INET6, &dns_server->address, addrstr, sizeof (addrstr));
_LOGD (" dns_server %s exp %u", addrstr, expiry (dns_server));
}
for (i = 0; i < rdata->dns_domains->len; i++) {
NMRDiscDNSDomain *dns_domain = &g_array_index (rdata->dns_domains, NMRDiscDNSDomain, i);
NMNDiscDNSDomain *dns_domain = &g_array_index (rdata->dns_domains, NMNDiscDNSDomain, i);
_LOGD (" dns_domain %s exp %u", dns_domain->domain, expiry (dns_domain));
}
}
static void
clean_gateways (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32 *nextevent)
clean_gateways (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap *changed, guint32 *nextevent)
{
NMRDiscDataInternal *rdata;
NMNDiscDataInternal *rdata;
guint i;
rdata = &NM_RDISC_GET_PRIVATE (rdisc)->rdata;
rdata = &NM_NDISC_GET_PRIVATE (ndisc)->rdata;
for (i = 0; i < rdata->gateways->len; i++) {
NMRDiscGateway *item = &g_array_index (rdata->gateways, NMRDiscGateway, i);
NMNDiscGateway *item = &g_array_index (rdata->gateways, NMNDiscGateway, i);
guint64 expiry = (guint64) item->timestamp + item->lifetime;
if (item->lifetime == G_MAXUINT32)
@ -703,22 +703,22 @@ clean_gateways (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32
if (now >= expiry) {
g_array_remove_index (rdata->gateways, i--);
*changed |= NM_RDISC_CONFIG_GATEWAYS;
*changed |= NM_NDISC_CONFIG_GATEWAYS;
} else if (*nextevent > expiry)
*nextevent = expiry;
}
}
static void
clean_addresses (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32 *nextevent)
clean_addresses (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap *changed, guint32 *nextevent)
{
NMRDiscDataInternal *rdata;
NMNDiscDataInternal *rdata;
guint i;
rdata = &NM_RDISC_GET_PRIVATE (rdisc)->rdata;
rdata = &NM_NDISC_GET_PRIVATE (ndisc)->rdata;
for (i = 0; i < rdata->addresses->len; i++) {
NMRDiscAddress *item = &g_array_index (rdata->addresses, NMRDiscAddress, i);
NMNDiscAddress *item = &g_array_index (rdata->addresses, NMNDiscAddress, i);
guint64 expiry = (guint64) item->timestamp + item->lifetime;
if (item->lifetime == G_MAXUINT32)
@ -726,22 +726,22 @@ clean_addresses (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32
if (now >= expiry) {
g_array_remove_index (rdata->addresses, i--);
*changed |= NM_RDISC_CONFIG_ADDRESSES;
*changed |= NM_NDISC_CONFIG_ADDRESSES;
} else if (*nextevent > expiry)
*nextevent = expiry;
}
}
static void
clean_routes (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32 *nextevent)
clean_routes (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap *changed, guint32 *nextevent)
{
NMRDiscDataInternal *rdata;
NMNDiscDataInternal *rdata;
guint i;
rdata = &NM_RDISC_GET_PRIVATE (rdisc)->rdata;
rdata = &NM_NDISC_GET_PRIVATE (ndisc)->rdata;
for (i = 0; i < rdata->routes->len; i++) {
NMRDiscRoute *item = &g_array_index (rdata->routes, NMRDiscRoute, i);
NMNDiscRoute *item = &g_array_index (rdata->routes, NMNDiscRoute, i);
guint64 expiry = (guint64) item->timestamp + item->lifetime;
if (item->lifetime == G_MAXUINT32)
@ -749,22 +749,22 @@ clean_routes (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32 *n
if (now >= expiry) {
g_array_remove_index (rdata->routes, i--);
*changed |= NM_RDISC_CONFIG_ROUTES;
*changed |= NM_NDISC_CONFIG_ROUTES;
} else if (*nextevent > expiry)
*nextevent = expiry;
}
}
static void
clean_dns_servers (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32 *nextevent)
clean_dns_servers (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap *changed, guint32 *nextevent)
{
NMRDiscDataInternal *rdata;
NMNDiscDataInternal *rdata;
guint i;
rdata = &NM_RDISC_GET_PRIVATE (rdisc)->rdata;
rdata = &NM_NDISC_GET_PRIVATE (ndisc)->rdata;
for (i = 0; i < rdata->dns_servers->len; i++) {
NMRDiscDNSServer *item = &g_array_index (rdata->dns_servers, NMRDiscDNSServer, i);
NMNDiscDNSServer *item = &g_array_index (rdata->dns_servers, NMNDiscDNSServer, i);
guint64 expiry = (guint64) item->timestamp + item->lifetime;
guint64 refresh = (guint64) item->timestamp + item->lifetime / 2;
@ -773,24 +773,24 @@ clean_dns_servers (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint
if (now >= expiry) {
g_array_remove_index (rdata->dns_servers, i--);
*changed |= NM_RDISC_CONFIG_DNS_SERVERS;
*changed |= NM_NDISC_CONFIG_DNS_SERVERS;
} else if (now >= refresh)
solicit (rdisc);
solicit (ndisc);
else if (*nextevent > refresh)
*nextevent = refresh;
}
}
static void
clean_dns_domains (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint32 *nextevent)
clean_dns_domains (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap *changed, guint32 *nextevent)
{
NMRDiscDataInternal *rdata;
NMNDiscDataInternal *rdata;
guint i;
rdata = &NM_RDISC_GET_PRIVATE (rdisc)->rdata;
rdata = &NM_NDISC_GET_PRIVATE (ndisc)->rdata;
for (i = 0; i < rdata->dns_domains->len; i++) {
NMRDiscDNSDomain *item = &g_array_index (rdata->dns_domains, NMRDiscDNSDomain, i);
NMNDiscDNSDomain *item = &g_array_index (rdata->dns_domains, NMNDiscDNSDomain, i);
guint64 expiry = (guint64) item->timestamp + item->lifetime;
guint64 refresh = (guint64) item->timestamp + item->lifetime / 2;
@ -799,9 +799,9 @@ clean_dns_domains (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint
if (now >= expiry) {
g_array_remove_index (rdata->dns_domains, i--);
*changed |= NM_RDISC_CONFIG_DNS_DOMAINS;
*changed |= NM_NDISC_CONFIG_DNS_DOMAINS;
} else if (now >= refresh)
solicit (rdisc);
solicit (ndisc);
else if (*nextevent > refresh)
*nextevent = refresh;
}
@ -810,51 +810,51 @@ clean_dns_domains (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap *changed, guint
static gboolean timeout_cb (gpointer user_data);
static void
check_timestamps (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed)
check_timestamps (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap changed)
{
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
/* Use a magic date in the distant future (~68 years) */
guint32 never = G_MAXINT32;
guint32 nextevent = never;
nm_clear_g_source (&priv->timeout_id);
clean_gateways (rdisc, now, &changed, &nextevent);
clean_addresses (rdisc, now, &changed, &nextevent);
clean_routes (rdisc, now, &changed, &nextevent);
clean_dns_servers (rdisc, now, &changed, &nextevent);
clean_dns_domains (rdisc, now, &changed, &nextevent);
clean_gateways (ndisc, now, &changed, &nextevent);
clean_addresses (ndisc, now, &changed, &nextevent);
clean_routes (ndisc, now, &changed, &nextevent);
clean_dns_servers (ndisc, now, &changed, &nextevent);
clean_dns_domains (ndisc, now, &changed, &nextevent);
if (changed)
_emit_config_change (rdisc, changed);
_emit_config_change (ndisc, changed);
if (nextevent != never) {
g_return_if_fail (nextevent > now);
_LOGD ("scheduling next now/lifetime check: %u seconds",
nextevent - now);
priv->timeout_id = g_timeout_add_seconds (nextevent - now, timeout_cb, rdisc);
priv->timeout_id = g_timeout_add_seconds (nextevent - now, timeout_cb, ndisc);
}
}
static gboolean
timeout_cb (gpointer user_data)
{
NMRDisc *self = user_data;
NMNDisc *self = user_data;
NM_RDISC_GET_PRIVATE (self)->timeout_id = 0;
NM_NDISC_GET_PRIVATE (self)->timeout_id = 0;
check_timestamps (self, nm_utils_get_monotonic_timestamp_s (), 0);
return G_SOURCE_REMOVE;
}
void
nm_rdisc_ra_received (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed)
nm_ndisc_ra_received (NMNDisc *ndisc, guint32 now, NMNDiscConfigMap changed)
{
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
nm_clear_g_source (&priv->ra_timeout_id);
nm_clear_g_source (&priv->send_rs_id);
g_clear_pointer (&priv->last_send_rs_error, g_free);
check_timestamps (rdisc, now, changed);
check_timestamps (ndisc, now, changed);
}
/*****************************************************************************/
@ -862,15 +862,15 @@ nm_rdisc_ra_received (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed)
static void
dns_domain_free (gpointer data)
{
g_free (((NMRDiscDNSDomain *)(data))->domain);
g_free (((NMNDiscDNSDomain *)(data))->domain);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMRDisc *self = NM_RDISC (object);
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (self);
NMNDisc *self = NM_NDISC (object);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (self);
switch (prop_id) {
case PROP_PLATFORM:
@ -928,21 +928,21 @@ set_property (GObject *object, guint prop_id,
}
static void
nm_rdisc_init (NMRDisc *rdisc)
nm_ndisc_init (NMNDisc *ndisc)
{
NMRDiscPrivate *priv;
NMRDiscDataInternal *rdata;
NMNDiscPrivate *priv;
NMNDiscDataInternal *rdata;
priv = G_TYPE_INSTANCE_GET_PRIVATE (rdisc, NM_TYPE_RDISC, NMRDiscPrivate);
rdisc->_priv = priv;
priv = G_TYPE_INSTANCE_GET_PRIVATE (ndisc, NM_TYPE_NDISC, NMNDiscPrivate);
ndisc->_priv = priv;
rdata = &priv->rdata;
rdata->gateways = g_array_new (FALSE, FALSE, sizeof (NMRDiscGateway));
rdata->addresses = g_array_new (FALSE, FALSE, sizeof (NMRDiscAddress));
rdata->routes = g_array_new (FALSE, FALSE, sizeof (NMRDiscRoute));
rdata->dns_servers = g_array_new (FALSE, FALSE, sizeof (NMRDiscDNSServer));
rdata->dns_domains = g_array_new (FALSE, FALSE, sizeof (NMRDiscDNSDomain));
rdata->gateways = g_array_new (FALSE, FALSE, sizeof (NMNDiscGateway));
rdata->addresses = g_array_new (FALSE, FALSE, sizeof (NMNDiscAddress));
rdata->routes = g_array_new (FALSE, FALSE, sizeof (NMNDiscRoute));
rdata->dns_servers = g_array_new (FALSE, FALSE, sizeof (NMNDiscDNSServer));
rdata->dns_domains = g_array_new (FALSE, FALSE, sizeof (NMNDiscDNSDomain));
g_array_set_clear_func (rdata->dns_domains, dns_domain_free);
priv->rdata.public.hop_limit = 64;
@ -955,8 +955,8 @@ nm_rdisc_init (NMRDisc *rdisc)
static void
dispose (GObject *object)
{
NMRDisc *rdisc = NM_RDISC (object);
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
NMNDisc *ndisc = NM_NDISC (object);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
nm_clear_g_source (&priv->ra_timeout_id);
nm_clear_g_source (&priv->send_rs_id);
@ -964,15 +964,15 @@ dispose (GObject *object)
nm_clear_g_source (&priv->timeout_id);
G_OBJECT_CLASS (nm_rdisc_parent_class)->dispose (object);
G_OBJECT_CLASS (nm_ndisc_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMRDisc *rdisc = NM_RDISC (object);
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
NMRDiscDataInternal *rdata = &priv->rdata;
NMNDisc *ndisc = NM_NDISC (object);
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
NMNDiscDataInternal *rdata = &priv->rdata;
g_free (priv->ifname);
g_free (priv->network_id);
@ -986,85 +986,85 @@ finalize (GObject *object)
g_clear_object (&priv->netns);
g_clear_object (&priv->platform);
G_OBJECT_CLASS (nm_rdisc_parent_class)->finalize (object);
G_OBJECT_CLASS (nm_ndisc_parent_class)->finalize (object);
}
static void
nm_rdisc_class_init (NMRDiscClass *klass)
nm_ndisc_class_init (NMNDiscClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMRDiscPrivate));
g_type_class_add_private (klass, sizeof (NMNDiscPrivate));
object_class->set_property = set_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
obj_properties[PROP_PLATFORM] =
g_param_spec_object (NM_RDISC_PLATFORM, "", "",
g_param_spec_object (NM_NDISC_PLATFORM, "", "",
NM_TYPE_PLATFORM,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_IFINDEX] =
g_param_spec_int (NM_RDISC_IFINDEX, "", "",
g_param_spec_int (NM_NDISC_IFINDEX, "", "",
0, G_MAXINT, 0,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_IFNAME] =
g_param_spec_string (NM_RDISC_IFNAME, "", "",
g_param_spec_string (NM_NDISC_IFNAME, "", "",
NULL,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_STABLE_TYPE] =
g_param_spec_int (NM_RDISC_STABLE_TYPE, "", "",
g_param_spec_int (NM_NDISC_STABLE_TYPE, "", "",
NM_UTILS_STABLE_TYPE_UUID, NM_UTILS_STABLE_TYPE_STABLE_ID, NM_UTILS_STABLE_TYPE_UUID,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_NETWORK_ID] =
g_param_spec_string (NM_RDISC_NETWORK_ID, "", "",
g_param_spec_string (NM_NDISC_NETWORK_ID, "", "",
NULL,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDR_GEN_MODE] =
g_param_spec_int (NM_RDISC_ADDR_GEN_MODE, "", "",
g_param_spec_int (NM_NDISC_ADDR_GEN_MODE, "", "",
NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY, NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_MAX_ADDRESSES] =
g_param_spec_int (NM_RDISC_MAX_ADDRESSES, "", "",
0, G_MAXINT32, NM_RDISC_MAX_ADDRESSES_DEFAULT,
g_param_spec_int (NM_NDISC_MAX_ADDRESSES, "", "",
0, G_MAXINT32, NM_NDISC_MAX_ADDRESSES_DEFAULT,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTER_SOLICITATIONS] =
g_param_spec_int (NM_RDISC_ROUTER_SOLICITATIONS, "", "",
1, G_MAXINT32, NM_RDISC_ROUTER_SOLICITATIONS_DEFAULT,
g_param_spec_int (NM_NDISC_ROUTER_SOLICITATIONS, "", "",
1, G_MAXINT32, NM_NDISC_ROUTER_SOLICITATIONS_DEFAULT,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ROUTER_SOLICITATION_INTERVAL] =
g_param_spec_int (NM_RDISC_ROUTER_SOLICITATION_INTERVAL, "", "",
1, G_MAXINT32, NM_RDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT,
g_param_spec_int (NM_NDISC_ROUTER_SOLICITATION_INTERVAL, "", "",
1, G_MAXINT32, NM_NDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
signals[CONFIG_CHANGED] =
g_signal_new (NM_RDISC_CONFIG_CHANGED,
g_signal_new (NM_NDISC_CONFIG_CHANGED,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_UINT);
signals[RA_TIMEOUT] =
g_signal_new (NM_RDISC_RA_TIMEOUT,
g_signal_new (NM_NDISC_RA_TIMEOUT,
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
0,

170
src/ndisc/nm-ndisc.h Normal file
View file

@ -0,0 +1,170 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-ndisc.h - Perform IPv6 neighbor discovery
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2013 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_NDISC_H__
#define __NETWORKMANAGER_NDISC_H__
#include <stdlib.h>
#include <netinet/in.h>
#include "nm-setting-ip6-config.h"
#include "NetworkManagerUtils.h"
#define NM_TYPE_NDISC (nm_ndisc_get_type ())
#define NM_NDISC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_NDISC, NMNDisc))
#define NM_NDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_NDISC, NMNDiscClass))
#define NM_IS_NDISC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_NDISC))
#define NM_IS_NDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_NDISC))
#define NM_NDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_NDISC, NMNDiscClass))
#define NM_NDISC_PLATFORM "platform"
#define NM_NDISC_IFINDEX "ifindex"
#define NM_NDISC_IFNAME "ifname"
#define NM_NDISC_NETWORK_ID "network-id"
#define NM_NDISC_ADDR_GEN_MODE "addr-gen-mode"
#define NM_NDISC_STABLE_TYPE "stable-type"
#define NM_NDISC_MAX_ADDRESSES "max-addresses"
#define NM_NDISC_ROUTER_SOLICITATIONS "router-solicitations"
#define NM_NDISC_ROUTER_SOLICITATION_INTERVAL "router-solicitation-interval"
#define NM_NDISC_CONFIG_CHANGED "config-changed"
#define NM_NDISC_RA_TIMEOUT "ra-timeout"
typedef enum {
NM_NDISC_DHCP_LEVEL_UNKNOWN,
NM_NDISC_DHCP_LEVEL_NONE,
NM_NDISC_DHCP_LEVEL_OTHERCONF,
NM_NDISC_DHCP_LEVEL_MANAGED
} NMNDiscDHCPLevel;
typedef enum {
NM_NDISC_PREFERENCE_INVALID,
NM_NDISC_PREFERENCE_LOW,
NM_NDISC_PREFERENCE_MEDIUM,
NM_NDISC_PREFERENCE_HIGH
} NMNDiscPreference;
typedef struct {
struct in6_addr address;
guint32 timestamp;
guint32 lifetime;
NMNDiscPreference preference;
} NMNDiscGateway;
typedef struct {
struct in6_addr address;
guint8 dad_counter;
guint32 timestamp;
guint32 lifetime;
guint32 preferred;
} NMNDiscAddress;
typedef struct {
struct in6_addr network;
guint8 plen;
struct in6_addr gateway;
guint32 timestamp;
guint32 lifetime;
NMNDiscPreference preference;
} NMNDiscRoute;
typedef struct {
struct in6_addr address;
guint32 timestamp;
guint32 lifetime;
} NMNDiscDNSServer;
typedef struct {
char *domain;
guint32 timestamp;
guint32 lifetime;
} NMNDiscDNSDomain;
typedef enum {
NM_NDISC_CONFIG_DHCP_LEVEL = 1 << 0,
NM_NDISC_CONFIG_GATEWAYS = 1 << 1,
NM_NDISC_CONFIG_ADDRESSES = 1 << 2,
NM_NDISC_CONFIG_ROUTES = 1 << 3,
NM_NDISC_CONFIG_DNS_SERVERS = 1 << 4,
NM_NDISC_CONFIG_DNS_DOMAINS = 1 << 5,
NM_NDISC_CONFIG_HOP_LIMIT = 1 << 6,
NM_NDISC_CONFIG_MTU = 1 << 7,
} NMNDiscConfigMap;
#define NM_NDISC_MAX_ADDRESSES_DEFAULT 16
#define NM_NDISC_ROUTER_SOLICITATIONS_DEFAULT 3
#define NM_NDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT 4
struct _NMNDiscPrivate;
struct _NMNDiscDataInternal;
typedef struct {
NMNDiscDHCPLevel dhcp_level;
guint32 mtu;
int hop_limit;
guint gateways_n;
guint addresses_n;
guint routes_n;
guint dns_servers_n;
guint dns_domains_n;
const NMNDiscGateway *gateways;
const NMNDiscAddress *addresses;
const NMNDiscRoute *routes;
const NMNDiscDNSServer *dns_servers;
const NMNDiscDNSDomain *dns_domains;
} NMNDiscData;
/**
* NMNDisc:
*
* Interface-specific structure that handles incoming router advertisements,
* caches advertised items and removes them when they are obsolete.
*/
typedef struct {
GObject parent;
union {
struct _NMNDiscPrivate *_priv;
struct _NMNDiscDataInternal *rdata;
};
} NMNDisc;
typedef struct {
GObjectClass parent;
void (*start) (NMNDisc *ndisc);
gboolean (*send_rs) (NMNDisc *ndisc, GError **error);
} NMNDiscClass;
GType nm_ndisc_get_type (void);
int nm_ndisc_get_ifindex (NMNDisc *self);
const char *nm_ndisc_get_ifname (NMNDisc *self);
gboolean nm_ndisc_set_iid (NMNDisc *ndisc, const NMUtilsIPv6IfaceId iid);
void nm_ndisc_start (NMNDisc *ndisc);
void nm_ndisc_dad_failed (NMNDisc *ndisc, struct in6_addr *address);
NMPlatform *nm_ndisc_get_platform (NMNDisc *self);
NMPNetns *nm_ndisc_netns_get (NMNDisc *self);
gboolean nm_ndisc_netns_push (NMNDisc *self, NMPNetns **netns);
#endif /* __NETWORKMANAGER_NDISC_H__ */

1
src/ndisc/tests/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/ndisc

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* rdisc.c - test program
/* ndisc.c - test program
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,32 +23,32 @@
#include <string.h>
#include <syslog.h>
#include "nm-rdisc.h"
#include "nm-fake-rdisc.h"
#include "nm-ndisc.h"
#include "nm-fake-ndisc.h"
#include "nm-fake-platform.h"
#include "nm-test-utils-core.h"
static NMFakeRDisc *
rdisc_new (void)
static NMFakeNDisc *
ndisc_new (void)
{
NMRDisc *rdisc;
NMNDisc *ndisc;
const int ifindex = 1;
const char *ifname = nm_platform_link_get_name (NM_PLATFORM_GET, ifindex);
NMUtilsIPv6IfaceId iid = { };
rdisc = nm_fake_rdisc_new (ifindex, ifname);
ndisc = nm_fake_ndisc_new (ifindex, ifname);
iid.id_u8[7] = 1;
nm_rdisc_set_iid (rdisc, iid);
g_assert (rdisc);
return NM_FAKE_RDISC (rdisc);
nm_ndisc_set_iid (ndisc, iid);
g_assert (ndisc);
return NM_FAKE_NDISC (ndisc);
}
static void
match_gateway (const NMRDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt, NMRDiscPreference pref)
match_gateway (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt, NMNDiscPreference pref)
{
const NMRDiscGateway *gw;
const NMNDiscGateway *gw;
char buf[INET6_ADDRSTRLEN];
g_assert (rdata);
@ -64,9 +64,9 @@ match_gateway (const NMRDiscData *rdata, guint idx, const char *addr, guint32 ts
}
static void
match_address (const NMRDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt, guint32 preferred)
match_address (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt, guint32 preferred)
{
const NMRDiscAddress *a;
const NMNDiscAddress *a;
char buf[INET6_ADDRSTRLEN];
g_assert (rdata);
@ -82,9 +82,9 @@ match_address (const NMRDiscData *rdata, guint idx, const char *addr, guint32 ts
}
static void
match_route (const NMRDiscData *rdata, guint idx, const char *nw, int plen, const char *gw, guint32 ts, guint32 lt, NMRDiscPreference pref)
match_route (const NMNDiscData *rdata, guint idx, const char *nw, int plen, const char *gw, guint32 ts, guint32 lt, NMNDiscPreference pref)
{
const NMRDiscRoute *route;
const NMNDiscRoute *route;
char buf[INET6_ADDRSTRLEN];
g_assert (rdata);
@ -103,9 +103,9 @@ match_route (const NMRDiscData *rdata, guint idx, const char *nw, int plen, cons
}
static void
match_dns_server (const NMRDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt)
match_dns_server (const NMNDiscData *rdata, guint idx, const char *addr, guint32 ts, guint32 lt)
{
const NMRDiscDNSServer *dns;
const NMNDiscDNSServer *dns;
char buf[INET6_ADDRSTRLEN];
g_assert (rdata);
@ -120,9 +120,9 @@ match_dns_server (const NMRDiscData *rdata, guint idx, const char *addr, guint32
}
static void
match_dns_domain (const NMRDiscData *rdata, guint idx, const char *domain, guint32 ts, guint32 lt)
match_dns_domain (const NMNDiscData *rdata, guint idx, const char *domain, guint32 ts, guint32 lt)
{
const NMRDiscDNSDomain *dns;
const NMNDiscDNSDomain *dns;
g_assert (rdata);
g_assert_cmpint (idx, <, rdata->dns_domains_n);
@ -145,26 +145,26 @@ typedef struct {
} TestData;
static void
test_simple_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_int, TestData *data)
test_simple_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data)
{
NMRDiscConfigMap changed = changed_int;
NMNDiscConfigMap changed = changed_int;
g_assert_cmpint (changed, ==, NM_RDISC_CONFIG_DHCP_LEVEL |
NM_RDISC_CONFIG_GATEWAYS |
NM_RDISC_CONFIG_ADDRESSES |
NM_RDISC_CONFIG_ROUTES |
NM_RDISC_CONFIG_DNS_SERVERS |
NM_RDISC_CONFIG_DNS_DOMAINS |
NM_RDISC_CONFIG_HOP_LIMIT |
NM_RDISC_CONFIG_MTU);
g_assert_cmpint (rdata->dhcp_level, ==, NM_RDISC_DHCP_LEVEL_OTHERCONF);
match_gateway (rdata, 0, "fe80::1", data->timestamp1, 10, NM_RDISC_PREFERENCE_MEDIUM);
g_assert_cmpint (changed, ==, NM_NDISC_CONFIG_DHCP_LEVEL |
NM_NDISC_CONFIG_GATEWAYS |
NM_NDISC_CONFIG_ADDRESSES |
NM_NDISC_CONFIG_ROUTES |
NM_NDISC_CONFIG_DNS_SERVERS |
NM_NDISC_CONFIG_DNS_DOMAINS |
NM_NDISC_CONFIG_HOP_LIMIT |
NM_NDISC_CONFIG_MTU);
g_assert_cmpint (rdata->dhcp_level, ==, NM_NDISC_DHCP_LEVEL_OTHERCONF);
match_gateway (rdata, 0, "fe80::1", data->timestamp1, 10, NM_NDISC_PREFERENCE_MEDIUM);
match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1, 10, 10);
match_route (rdata, 0, "2001:db8:a:a::", 64, "fe80::1", data->timestamp1, 10, 10);
match_dns_server (rdata, 0, "2001:db8:c:c::1", data->timestamp1, 10);
match_dns_domain (rdata, 0, "foobar.com", data->timestamp1, 10);
g_assert (nm_fake_rdisc_done (NM_FAKE_RDISC (rdisc)));
g_assert (nm_fake_ndisc_done (NM_FAKE_NDISC (ndisc)));
data->counter++;
g_main_loop_quit (data->loop);
}
@ -172,67 +172,67 @@ test_simple_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_int
static void
test_simple (void)
{
NMFakeRDisc *rdisc = rdisc_new ();
NMFakeNDisc *ndisc = ndisc_new ();
guint32 now = nm_utils_get_monotonic_timestamp_s ();
TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now };
guint id;
id = nm_fake_rdisc_add_ra (rdisc, 1, NM_RDISC_DHCP_LEVEL_OTHERCONF, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 1, NM_NDISC_DHCP_LEVEL_OTHERCONF, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::1", now, 10, NM_RDISC_PREFERENCE_MEDIUM);
nm_fake_rdisc_add_prefix (rdisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 10);
nm_fake_rdisc_add_dns_server (rdisc, id, "2001:db8:c:c::1", now, 10);
nm_fake_rdisc_add_dns_domain (rdisc, id, "foobar.com", now, 10);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::1", now, 10, NM_NDISC_PREFERENCE_MEDIUM);
nm_fake_ndisc_add_prefix (ndisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 10);
nm_fake_ndisc_add_dns_server (ndisc, id, "2001:db8:c:c::1", now, 10);
nm_fake_ndisc_add_dns_domain (ndisc, id, "foobar.com", now, 10);
g_signal_connect (rdisc,
NM_RDISC_CONFIG_CHANGED,
g_signal_connect (ndisc,
NM_NDISC_CONFIG_CHANGED,
G_CALLBACK (test_simple_changed),
&data);
nm_rdisc_start (NM_RDISC (rdisc));
nm_ndisc_start (NM_NDISC (ndisc));
g_main_loop_run (data.loop);
g_assert_cmpint (data.counter, ==, 1);
g_object_unref (rdisc);
g_object_unref (ndisc);
g_main_loop_unref (data.loop);
}
static void
test_everything_rs_sent (NMRDisc *rdisc, TestData *data)
test_everything_rs_sent (NMNDisc *ndisc, TestData *data)
{
g_assert_cmpint (data->rs_counter, ==, 0);
data->rs_counter++;
}
static void
test_everything_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_int, TestData *data)
test_everything_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data)
{
NMRDiscConfigMap changed = changed_int;
NMNDiscConfigMap changed = changed_int;
if (data->counter == 0) {
g_assert_cmpint (data->rs_counter, ==, 1);
g_assert_cmpint (changed, ==, NM_RDISC_CONFIG_DHCP_LEVEL |
NM_RDISC_CONFIG_GATEWAYS |
NM_RDISC_CONFIG_ADDRESSES |
NM_RDISC_CONFIG_ROUTES |
NM_RDISC_CONFIG_DNS_SERVERS |
NM_RDISC_CONFIG_DNS_DOMAINS |
NM_RDISC_CONFIG_HOP_LIMIT |
NM_RDISC_CONFIG_MTU);
match_gateway (rdata, 0, "fe80::1", data->timestamp1, 10, NM_RDISC_PREFERENCE_MEDIUM);
g_assert_cmpint (changed, ==, NM_NDISC_CONFIG_DHCP_LEVEL |
NM_NDISC_CONFIG_GATEWAYS |
NM_NDISC_CONFIG_ADDRESSES |
NM_NDISC_CONFIG_ROUTES |
NM_NDISC_CONFIG_DNS_SERVERS |
NM_NDISC_CONFIG_DNS_DOMAINS |
NM_NDISC_CONFIG_HOP_LIMIT |
NM_NDISC_CONFIG_MTU);
match_gateway (rdata, 0, "fe80::1", data->timestamp1, 10, NM_NDISC_PREFERENCE_MEDIUM);
match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1, 10, 10);
match_route (rdata, 0, "2001:db8:a:a::", 64, "fe80::1", data->timestamp1, 10, 10);
match_dns_server (rdata, 0, "2001:db8:c:c::1", data->timestamp1, 10);
match_dns_domain (rdata, 0, "foobar.com", data->timestamp1, 10);
} else if (data->counter == 1) {
g_assert_cmpint (changed, ==, NM_RDISC_CONFIG_GATEWAYS |
NM_RDISC_CONFIG_ADDRESSES |
NM_RDISC_CONFIG_ROUTES |
NM_RDISC_CONFIG_DNS_SERVERS |
NM_RDISC_CONFIG_DNS_DOMAINS);
g_assert_cmpint (changed, ==, NM_NDISC_CONFIG_GATEWAYS |
NM_NDISC_CONFIG_ADDRESSES |
NM_NDISC_CONFIG_ROUTES |
NM_NDISC_CONFIG_DNS_SERVERS |
NM_NDISC_CONFIG_DNS_DOMAINS);
g_assert_cmpint (rdata->gateways_n, ==, 1);
match_gateway (rdata, 0, "fe80::2", data->timestamp1, 10, NM_RDISC_PREFERENCE_MEDIUM);
match_gateway (rdata, 0, "fe80::2", data->timestamp1, 10, NM_NDISC_PREFERENCE_MEDIUM);
g_assert_cmpint (rdata->addresses_n, ==, 1);
match_address (rdata, 0, "2001:db8:a:b::1", data->timestamp1, 10, 10);
g_assert_cmpint (rdata->routes_n, ==, 1);
@ -242,7 +242,7 @@ test_everything_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed
g_assert_cmpint (rdata->dns_domains_n, ==, 1);
match_dns_domain (rdata, 0, "foobar2.com", data->timestamp1, 10);
g_assert (nm_fake_rdisc_done (NM_FAKE_RDISC (rdisc)));
g_assert (nm_fake_ndisc_done (NM_FAKE_NDISC (ndisc)));
g_main_loop_quit (data->loop);
} else
g_assert_not_reached ();
@ -253,62 +253,62 @@ test_everything_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed
static void
test_everything (void)
{
NMFakeRDisc *rdisc = rdisc_new ();
NMFakeNDisc *ndisc = ndisc_new ();
guint32 now = nm_utils_get_monotonic_timestamp_s ();
TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now };
guint id;
id = nm_fake_rdisc_add_ra (rdisc, 1, NM_RDISC_DHCP_LEVEL_NONE, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 1, NM_NDISC_DHCP_LEVEL_NONE, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::1", now, 10, NM_RDISC_PREFERENCE_MEDIUM);
nm_fake_rdisc_add_prefix (rdisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 10);
nm_fake_rdisc_add_dns_server (rdisc, id, "2001:db8:c:c::1", now, 10);
nm_fake_rdisc_add_dns_domain (rdisc, id, "foobar.com", now, 10);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::1", now, 10, NM_NDISC_PREFERENCE_MEDIUM);
nm_fake_ndisc_add_prefix (ndisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 10);
nm_fake_ndisc_add_dns_server (ndisc, id, "2001:db8:c:c::1", now, 10);
nm_fake_ndisc_add_dns_domain (ndisc, id, "foobar.com", now, 10);
/* expire everything from the first RA in the second */
id = nm_fake_rdisc_add_ra (rdisc, 1, NM_RDISC_DHCP_LEVEL_NONE, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 1, NM_NDISC_DHCP_LEVEL_NONE, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::1", now, 0, NM_RDISC_PREFERENCE_MEDIUM);
nm_fake_rdisc_add_prefix (rdisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 0, 0, 0);
nm_fake_rdisc_add_dns_server (rdisc, id, "2001:db8:c:c::1", now, 0);
nm_fake_rdisc_add_dns_domain (rdisc, id, "foobar.com", now, 0);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::1", now, 0, NM_NDISC_PREFERENCE_MEDIUM);
nm_fake_ndisc_add_prefix (ndisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 0, 0, 0);
nm_fake_ndisc_add_dns_server (ndisc, id, "2001:db8:c:c::1", now, 0);
nm_fake_ndisc_add_dns_domain (ndisc, id, "foobar.com", now, 0);
/* and add some new stuff */
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::2", now, 10, NM_RDISC_PREFERENCE_MEDIUM);
nm_fake_rdisc_add_prefix (rdisc, id, "2001:db8:a:b::", 64, "fe80::2", now, 10, 10, 10);
nm_fake_rdisc_add_dns_server (rdisc, id, "2001:db8:c:c::2", now, 10);
nm_fake_rdisc_add_dns_domain (rdisc, id, "foobar2.com", now, 10);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::2", now, 10, NM_NDISC_PREFERENCE_MEDIUM);
nm_fake_ndisc_add_prefix (ndisc, id, "2001:db8:a:b::", 64, "fe80::2", now, 10, 10, 10);
nm_fake_ndisc_add_dns_server (ndisc, id, "2001:db8:c:c::2", now, 10);
nm_fake_ndisc_add_dns_domain (ndisc, id, "foobar2.com", now, 10);
g_signal_connect (rdisc,
NM_RDISC_CONFIG_CHANGED,
g_signal_connect (ndisc,
NM_NDISC_CONFIG_CHANGED,
G_CALLBACK (test_everything_changed),
&data);
g_signal_connect (rdisc,
NM_FAKE_RDISC_RS_SENT,
g_signal_connect (ndisc,
NM_FAKE_NDISC_RS_SENT,
G_CALLBACK (test_everything_rs_sent),
&data);
nm_rdisc_start (NM_RDISC (rdisc));
nm_ndisc_start (NM_NDISC (ndisc));
g_main_loop_run (data.loop);
g_assert_cmpint (data.counter, ==, 2);
g_assert_cmpint (data.rs_counter, ==, 1);
g_object_unref (rdisc);
g_object_unref (ndisc);
g_main_loop_unref (data.loop);
}
static void
test_preference_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_int, TestData *data)
test_preference_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data)
{
NMRDiscConfigMap changed = changed_int;
NMNDiscConfigMap changed = changed_int;
if (data->counter == 1) {
g_assert_cmpint (changed, ==, NM_RDISC_CONFIG_GATEWAYS |
NM_RDISC_CONFIG_ADDRESSES |
NM_RDISC_CONFIG_ROUTES);
g_assert_cmpint (changed, ==, NM_NDISC_CONFIG_GATEWAYS |
NM_NDISC_CONFIG_ADDRESSES |
NM_NDISC_CONFIG_ROUTES);
g_assert_cmpint (rdata->gateways_n, ==, 2);
match_gateway (rdata, 0, "fe80::2", data->timestamp1 + 1, 10, NM_RDISC_PREFERENCE_MEDIUM);
match_gateway (rdata, 1, "fe80::1", data->timestamp1, 10, NM_RDISC_PREFERENCE_LOW);
match_gateway (rdata, 0, "fe80::2", data->timestamp1 + 1, 10, NM_NDISC_PREFERENCE_MEDIUM);
match_gateway (rdata, 1, "fe80::1", data->timestamp1, 10, NM_NDISC_PREFERENCE_LOW);
g_assert_cmpint (rdata->addresses_n, ==, 2);
match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1, 10, 10);
match_address (rdata, 1, "2001:db8:a:b::1", data->timestamp1 + 1, 10, 10);
@ -316,13 +316,13 @@ test_preference_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed
match_route (rdata, 0, "2001:db8:a:b::", 64, "fe80::2", data->timestamp1 + 1, 10, 10);
match_route (rdata, 1, "2001:db8:a:a::", 64, "fe80::1", data->timestamp1, 10, 5);
} else if (data->counter == 2) {
g_assert_cmpint (changed, ==, NM_RDISC_CONFIG_GATEWAYS |
NM_RDISC_CONFIG_ADDRESSES |
NM_RDISC_CONFIG_ROUTES);
g_assert_cmpint (changed, ==, NM_NDISC_CONFIG_GATEWAYS |
NM_NDISC_CONFIG_ADDRESSES |
NM_NDISC_CONFIG_ROUTES);
g_assert_cmpint (rdata->gateways_n, ==, 2);
match_gateway (rdata, 0, "fe80::1", data->timestamp1 + 2, 10, NM_RDISC_PREFERENCE_HIGH);
match_gateway (rdata, 1, "fe80::2", data->timestamp1 + 1, 10, NM_RDISC_PREFERENCE_MEDIUM);
match_gateway (rdata, 0, "fe80::1", data->timestamp1 + 2, 10, NM_NDISC_PREFERENCE_HIGH);
match_gateway (rdata, 1, "fe80::2", data->timestamp1 + 1, 10, NM_NDISC_PREFERENCE_MEDIUM);
g_assert_cmpint (rdata->addresses_n, ==, 2);
match_address (rdata, 0, "2001:db8:a:a::1", data->timestamp1 + 2, 10, 10);
match_address (rdata, 1, "2001:db8:a:b::1", data->timestamp1 + 1, 10, 10);
@ -330,7 +330,7 @@ test_preference_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed
match_route (rdata, 0, "2001:db8:a:a::", 64, "fe80::1", data->timestamp1 + 2, 10, 15);
match_route (rdata, 1, "2001:db8:a:b::", 64, "fe80::2", data->timestamp1 + 1, 10, 10);
g_assert (nm_fake_rdisc_done (NM_FAKE_RDISC (rdisc)));
g_assert (nm_fake_ndisc_done (NM_FAKE_NDISC (ndisc)));
g_main_loop_quit (data->loop);
}
@ -340,7 +340,7 @@ test_preference_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed
static void
test_preference (void)
{
NMFakeRDisc *rdisc = rdisc_new ();
NMFakeNDisc *ndisc = ndisc_new ();
guint32 now = nm_utils_get_monotonic_timestamp_s ();
TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now };
guint id;
@ -350,36 +350,36 @@ test_preference (void)
* not get duplicates in the gateway list.
*/
id = nm_fake_rdisc_add_ra (rdisc, 1, NM_RDISC_DHCP_LEVEL_NONE, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 1, NM_NDISC_DHCP_LEVEL_NONE, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::1", now, 10, NM_RDISC_PREFERENCE_LOW);
nm_fake_rdisc_add_prefix (rdisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 5);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::1", now, 10, NM_NDISC_PREFERENCE_LOW);
nm_fake_ndisc_add_prefix (ndisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 5);
id = nm_fake_rdisc_add_ra (rdisc, 1, NM_RDISC_DHCP_LEVEL_NONE, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 1, NM_NDISC_DHCP_LEVEL_NONE, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::2", ++now, 10, NM_RDISC_PREFERENCE_MEDIUM);
nm_fake_rdisc_add_prefix (rdisc, id, "2001:db8:a:b::", 64, "fe80::2", now, 10, 10, 10);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::2", ++now, 10, NM_NDISC_PREFERENCE_MEDIUM);
nm_fake_ndisc_add_prefix (ndisc, id, "2001:db8:a:b::", 64, "fe80::2", now, 10, 10, 10);
id = nm_fake_rdisc_add_ra (rdisc, 1, NM_RDISC_DHCP_LEVEL_NONE, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 1, NM_NDISC_DHCP_LEVEL_NONE, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::1", ++now, 10, NM_RDISC_PREFERENCE_HIGH);
nm_fake_rdisc_add_prefix (rdisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 15);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::1", ++now, 10, NM_NDISC_PREFERENCE_HIGH);
nm_fake_ndisc_add_prefix (ndisc, id, "2001:db8:a:a::", 64, "fe80::1", now, 10, 10, 15);
g_signal_connect (rdisc,
NM_RDISC_CONFIG_CHANGED,
g_signal_connect (ndisc,
NM_NDISC_CONFIG_CHANGED,
G_CALLBACK (test_preference_changed),
&data);
nm_rdisc_start (NM_RDISC (rdisc));
nm_ndisc_start (NM_NDISC (ndisc));
g_main_loop_run (data.loop);
g_assert_cmpint (data.counter, ==, 3);
g_object_unref (rdisc);
g_object_unref (ndisc);
g_main_loop_unref (data.loop);
}
static void
test_dns_solicit_loop_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_int, TestData *data)
test_dns_solicit_loop_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, TestData *data)
{
data->counter++;
}
@ -393,7 +393,7 @@ success_timeout (TestData *data)
}
static void
test_dns_solicit_loop_rs_sent (NMFakeRDisc *rdisc, TestData *data)
test_dns_solicit_loop_rs_sent (NMFakeNDisc *ndisc, TestData *data)
{
guint32 now = nm_utils_get_monotonic_timestamp_s ();
guint id;
@ -409,11 +409,11 @@ test_dns_solicit_loop_rs_sent (NMFakeRDisc *rdisc, TestData *data)
* DNS servers reaching 1/2 lifetime, emit a new RA without the DNS
* servers again.
*/
id = nm_fake_rdisc_add_ra (rdisc, 0, NM_RDISC_DHCP_LEVEL_NONE, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 0, NM_NDISC_DHCP_LEVEL_NONE, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::1", now, 10, NM_RDISC_PREFERENCE_MEDIUM);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::1", now, 10, NM_NDISC_PREFERENCE_MEDIUM);
nm_fake_rdisc_emit_new_ras (rdisc);
nm_fake_ndisc_emit_new_ras (ndisc);
} else if (data->rs_counter >= 6) {
/* Fail if we've sent too many solicitations in the past 4 seconds */
g_assert_cmpint (now - data->first_solicit, >, 4);
@ -426,7 +426,7 @@ test_dns_solicit_loop_rs_sent (NMFakeRDisc *rdisc, TestData *data)
static void
test_dns_solicit_loop (void)
{
NMFakeRDisc *rdisc = rdisc_new ();
NMFakeNDisc *ndisc = ndisc_new ();
guint32 now = nm_utils_get_monotonic_timestamp_s ();
TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now, 0 };
guint id;
@ -438,25 +438,25 @@ test_dns_solicit_loop (void)
* first.
*/
id = nm_fake_rdisc_add_ra (rdisc, 1, NM_RDISC_DHCP_LEVEL_NONE, 4, 1500);
id = nm_fake_ndisc_add_ra (ndisc, 1, NM_NDISC_DHCP_LEVEL_NONE, 4, 1500);
g_assert (id);
nm_fake_rdisc_add_gateway (rdisc, id, "fe80::1", now, 10, NM_RDISC_PREFERENCE_LOW);
nm_fake_rdisc_add_dns_server (rdisc, id, "2001:db8:c:c::1", now, 6);
nm_fake_ndisc_add_gateway (ndisc, id, "fe80::1", now, 10, NM_NDISC_PREFERENCE_LOW);
nm_fake_ndisc_add_dns_server (ndisc, id, "2001:db8:c:c::1", now, 6);
g_signal_connect (rdisc,
NM_RDISC_CONFIG_CHANGED,
g_signal_connect (ndisc,
NM_NDISC_CONFIG_CHANGED,
G_CALLBACK (test_dns_solicit_loop_changed),
&data);
g_signal_connect (rdisc,
NM_FAKE_RDISC_RS_SENT,
g_signal_connect (ndisc,
NM_FAKE_NDISC_RS_SENT,
G_CALLBACK (test_dns_solicit_loop_rs_sent),
&data);
nm_rdisc_start (NM_RDISC (rdisc));
nm_ndisc_start (NM_NDISC (ndisc));
g_main_loop_run (data.loop);
g_assert_cmpint (data.counter, ==, 3);
g_object_unref (rdisc);
g_object_unref (ndisc);
g_main_loop_unref (data.loop);
}
@ -468,16 +468,16 @@ main (int argc, char **argv)
nmtst_init_with_logging (&argc, &argv, NULL, "DEFAULT");
if (nmtst_test_quick ()) {
g_print ("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", g_get_prgname () ?: "test-rdisc-fake");
g_print ("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", g_get_prgname () ?: "test-ndisc-fake");
return g_test_run ();
}
nm_fake_platform_setup ();
g_test_add_func ("/rdisc/simple", test_simple);
g_test_add_func ("/rdisc/everything-changed", test_everything);
g_test_add_func ("/rdisc/preference-changed", test_preference);
g_test_add_func ("/rdisc/dns-solicit-loop", test_dns_solicit_loop);
g_test_add_func ("/ndisc/simple", test_simple);
g_test_add_func ("/ndisc/everything-changed", test_everything);
g_test_add_func ("/ndisc/preference-changed", test_preference);
g_test_add_func ("/ndisc/dns-solicit-loop", test_dns_solicit_loop);
return g_test_run ();
}

View file

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* rdisc.c - test program
/* ndisc.c - test program
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,8 +23,8 @@
#include <string.h>
#include <syslog.h>
#include "nm-rdisc.h"
#include "nm-lndp-rdisc.h"
#include "nm-ndisc.h"
#include "nm-lndp-ndisc.h"
#include "nm-linux-platform.h"
@ -36,7 +36,7 @@ int
main (int argc, char **argv)
{
GMainLoop *loop;
NMRDisc *rdisc;
NMNDisc *ndisc;
int ifindex = 1;
const char *ifname;
NMUtilsIPv6IfaceId iid = { };
@ -61,25 +61,25 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
rdisc = nm_lndp_rdisc_new (NM_PLATFORM_GET,
ndisc = nm_lndp_ndisc_new (NM_PLATFORM_GET,
ifindex,
ifname,
NM_UTILS_STABLE_TYPE_UUID,
"8ce666e8-d34d-4fb1-b858-f15a7al28086",
NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64,
&error);
if (!rdisc) {
g_print ("Failed to create NMRDisc instance: %s\n", error->message);
if (!ndisc) {
g_print ("Failed to create NMNDisc instance: %s\n", error->message);
g_error_free (error);
return EXIT_FAILURE;
}
iid.id_u8[7] = 1;
nm_rdisc_set_iid (rdisc, iid);
nm_rdisc_start (rdisc);
nm_ndisc_set_iid (ndisc, iid);
nm_ndisc_start (ndisc);
g_main_loop_run (loop);
g_clear_object (&rdisc);
g_clear_object (&ndisc);
return EXIT_SUCCESS;
}

View file

@ -40,8 +40,8 @@ extern unsigned int if_nametoindex (const char *__ifname);
#include "NetworkManagerUtils.h"
#include "nm-linux-platform.h"
#include "nm-dhcp-manager.h"
#include "nm-rdisc.h"
#include "nm-lndp-rdisc.h"
#include "nm-ndisc.h"
#include "nm-lndp-ndisc.h"
#include "nm-utils.h"
#include "nm-setting-ip6-config.h"
#include "systemd/nm-sd.h"
@ -146,10 +146,10 @@ dhcp4_state_changed (NMDhcpClient *client,
}
static void
rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_int, gpointer user_data)
ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_int, gpointer user_data)
{
NMRDiscConfigMap changed = changed_int;
static NMIP6Config *rdisc_config = NULL;
NMNDiscConfigMap changed = changed_int;
static NMIP6Config *ndisc_config = NULL;
NMIP6Config *existing;
static int system_support = -1;
guint32 ifa_flags = 0x00;
@ -176,30 +176,30 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
}
existing = nm_ip6_config_capture (gl.ifindex, FALSE, global_opt.tempaddr);
if (rdisc_config)
nm_ip6_config_subtract (existing, rdisc_config);
if (ndisc_config)
nm_ip6_config_subtract (existing, ndisc_config);
else
rdisc_config = nm_ip6_config_new (gl.ifindex);
ndisc_config = nm_ip6_config_new (gl.ifindex);
if (changed & NM_RDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in router discovery cache. */
if (changed & NM_NDISC_CONFIG_GATEWAYS) {
/* Use the first gateway as ordered in neighbor discovery cache. */
if (rdata->gateways_n)
nm_ip6_config_set_gateway (rdisc_config, &rdata->gateways[0].address);
nm_ip6_config_set_gateway (ndisc_config, &rdata->gateways[0].address);
else
nm_ip6_config_set_gateway (rdisc_config, NULL);
nm_ip6_config_set_gateway (ndisc_config, NULL);
}
if (changed & NM_RDISC_CONFIG_ADDRESSES) {
/* Rebuild address list from router discovery cache. */
nm_ip6_config_reset_addresses (rdisc_config);
if (changed & NM_NDISC_CONFIG_ADDRESSES) {
/* Rebuild address list from neighbor discovery cache. */
nm_ip6_config_reset_addresses (ndisc_config);
/* rdisc->addresses contains at most max_addresses entries.
/* ndisc->addresses contains at most max_addresses entries.
* This is different from what the kernel does, which
* also counts static and temporary addresses when checking
* max_addresses.
**/
for (i = 0; i < rdata->addresses_n; i++) {
const NMRDiscAddress *discovered_address = &rdata->addresses[i];
const NMNDiscAddress *discovered_address = &rdata->addresses[i];
NMPlatformIP6Address address;
memset (&address, 0, sizeof (address));
@ -210,52 +210,52 @@ rdisc_config_changed (NMRDisc *rdisc, const NMRDiscData *rdata, guint changed_in
address.preferred = discovered_address->preferred;
if (address.preferred > address.lifetime)
address.preferred = address.lifetime;
address.addr_source = NM_IP_CONFIG_SOURCE_RDISC;
address.addr_source = NM_IP_CONFIG_SOURCE_NDISC;
address.n_ifa_flags = ifa_flags;
nm_ip6_config_add_address (rdisc_config, &address);
nm_ip6_config_add_address (ndisc_config, &address);
}
}
if (changed & NM_RDISC_CONFIG_ROUTES) {
/* Rebuild route list from router discovery cache. */
nm_ip6_config_reset_routes (rdisc_config);
if (changed & NM_NDISC_CONFIG_ROUTES) {
/* Rebuild route list from neighbor discovery cache. */
nm_ip6_config_reset_routes (ndisc_config);
for (i = 0; i < rdata->routes_n; i++) {
const NMRDiscRoute *discovered_route = &rdata->routes[i];
const NMNDiscRoute *discovered_route = &rdata->routes[i];
const NMPlatformIP6Route route = {
.network = discovered_route->network,
.plen = discovered_route->plen,
.gateway = discovered_route->gateway,
.rt_source = NM_IP_CONFIG_SOURCE_RDISC,
.rt_source = NM_IP_CONFIG_SOURCE_NDISC,
.metric = global_opt.priority_v6,
};
nm_ip6_config_add_route (rdisc_config, &route);
nm_ip6_config_add_route (ndisc_config, &route);
}
}
if (changed & NM_RDISC_CONFIG_DHCP_LEVEL) {
if (changed & NM_NDISC_CONFIG_DHCP_LEVEL) {
/* Unsupported until systemd DHCPv6 is ready */
}
if (changed & NM_RDISC_CONFIG_HOP_LIMIT)
if (changed & NM_NDISC_CONFIG_HOP_LIMIT)
nm_platform_sysctl_set_ip6_hop_limit_safe (NM_PLATFORM_GET, global_opt.ifname, rdata->hop_limit);
if (changed & NM_RDISC_CONFIG_MTU) {
if (changed & NM_NDISC_CONFIG_MTU) {
char val[16];
g_snprintf (val, sizeof (val), "%d", rdata->mtu);
nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "mtu"), val);
}
nm_ip6_config_merge (existing, rdisc_config, NM_IP_CONFIG_MERGE_DEFAULT);
nm_ip6_config_merge (existing, ndisc_config, NM_IP_CONFIG_MERGE_DEFAULT);
if (!nm_ip6_config_commit (existing, gl.ifindex, TRUE))
_LOGW (LOGD_IP6, "failed to apply IPv6 config");
}
static void
rdisc_ra_timeout (NMRDisc *rdisc, gpointer user_data)
ndisc_ra_timeout (NMNDisc *ndisc, gpointer user_data)
{
if (global_opt.slaac_required) {
_LOGW (LOGD_IP6, "IPv6 timed out or failed, quitting...");
@ -337,13 +337,13 @@ ip6_address_changed (NMPlatform *platform,
int iface,
NMPlatformIP6Address *addr,
int change_type_i,
NMRDisc *rdisc)
NMNDisc *ndisc)
{
const NMPlatformSignalChangeType change_type = change_type_i;
if ( (change_type == NM_PLATFORM_SIGNAL_CHANGED && addr->n_ifa_flags & IFA_F_DADFAILED)
|| (change_type == NM_PLATFORM_SIGNAL_REMOVED && addr->n_ifa_flags & IFA_F_TENTATIVE))
nm_rdisc_dad_failed (rdisc, &addr->address);
nm_ndisc_dad_failed (ndisc, &addr->address);
}
int
@ -354,7 +354,7 @@ main (int argc, char *argv[])
gboolean wrote_pidfile = FALSE;
gs_free char *pidfile = NULL;
gs_unref_object NMDhcpClient *dhcp4_client = NULL;
gs_unref_object NMRDisc *rdisc = NULL;
gs_unref_object NMNDisc *ndisc = NULL;
GByteArray *hwaddr = NULL;
size_t hwaddr_len = 0;
gconstpointer tmp;
@ -502,13 +502,13 @@ main (int argc, char *argv[])
stable_type = (global_opt.stable_id[0] - '0');
stable_id = &global_opt.stable_id[2];
}
rdisc = nm_lndp_rdisc_new (NM_PLATFORM_GET, gl.ifindex, global_opt.ifname,
ndisc = nm_lndp_ndisc_new (NM_PLATFORM_GET, gl.ifindex, global_opt.ifname,
stable_type, stable_id,
global_opt.addr_gen_mode, NULL);
g_assert (rdisc);
g_assert (ndisc);
if (iid)
nm_rdisc_set_iid (rdisc, *iid);
nm_ndisc_set_iid (ndisc, *iid);
nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra"), "1");
nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_defrtr"), "0");
@ -518,16 +518,16 @@ main (int argc, char *argv[])
g_signal_connect (NM_PLATFORM_GET,
NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED,
G_CALLBACK (ip6_address_changed),
rdisc);
g_signal_connect (rdisc,
NM_RDISC_CONFIG_CHANGED,
G_CALLBACK (rdisc_config_changed),
ndisc);
g_signal_connect (ndisc,
NM_NDISC_CONFIG_CHANGED,
G_CALLBACK (ndisc_config_changed),
NULL);
g_signal_connect (rdisc,
NM_RDISC_RA_TIMEOUT,
G_CALLBACK (rdisc_ra_timeout),
g_signal_connect (ndisc,
NM_NDISC_RA_TIMEOUT,
G_CALLBACK (ndisc_ra_timeout),
NULL);
nm_rdisc_start (rdisc);
nm_ndisc_start (ndisc);
}
sd_id = nm_sd_event_attach_default ();

View file

@ -79,7 +79,7 @@ typedef enum {
NM_IP_CONFIG_SOURCE_WWAN,
NM_IP_CONFIG_SOURCE_VPN,
NM_IP_CONFIG_SOURCE_DHCP,
NM_IP_CONFIG_SOURCE_RDISC,
NM_IP_CONFIG_SOURCE_NDISC,
NM_IP_CONFIG_SOURCE_USER,
} NMIPConfigSource;

View file

@ -469,7 +469,7 @@ nmp_utils_ip_config_source_coerce_to_rtprot (NMIPConfigSource source)
return RTPROT_KERNEL;
case NM_IP_CONFIG_SOURCE_DHCP:
return RTPROT_DHCP;
case NM_IP_CONFIG_SOURCE_RDISC:
case NM_IP_CONFIG_SOURCE_NDISC:
return RTPROT_RA;
default:
@ -501,7 +501,7 @@ nmp_utils_ip_config_source_coerce_from_rtprot (NMIPConfigSource source)
return NM_IP_CONFIG_SOURCE_KERNEL;
case NM_IP_CONFIG_SOURCE_RTPROT_RA:
return NM_IP_CONFIG_SOURCE_RDISC;
return NM_IP_CONFIG_SOURCE_NDISC;
case NM_IP_CONFIG_SOURCE_RTPROT_DHCP:
return NM_IP_CONFIG_SOURCE_DHCP;
@ -538,7 +538,7 @@ nmp_utils_ip_config_source_to_string (NMIPConfigSource source, char *buf, gsize
case NM_IP_CONFIG_SOURCE_WWAN: s = "wwan"; break;
case NM_IP_CONFIG_SOURCE_VPN: s = "vpn"; break;
case NM_IP_CONFIG_SOURCE_DHCP: s = "dhcp"; break;
case NM_IP_CONFIG_SOURCE_RDISC: s = "rdisc"; break;
case NM_IP_CONFIG_SOURCE_NDISC: s = "ndisc"; break;
case NM_IP_CONFIG_SOURCE_USER: s = "user"; break;
default:
break;

View file

@ -1,170 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-rdisc.h - Perform IPv6 router discovery
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2013 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_RDISC_H__
#define __NETWORKMANAGER_RDISC_H__
#include <stdlib.h>
#include <netinet/in.h>
#include "nm-setting-ip6-config.h"
#include "NetworkManagerUtils.h"
#define NM_TYPE_RDISC (nm_rdisc_get_type ())
#define NM_RDISC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_RDISC, NMRDisc))
#define NM_RDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_RDISC, NMRDiscClass))
#define NM_IS_RDISC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_RDISC))
#define NM_IS_RDISC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_RDISC))
#define NM_RDISC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_RDISC, NMRDiscClass))
#define NM_RDISC_PLATFORM "platform"
#define NM_RDISC_IFINDEX "ifindex"
#define NM_RDISC_IFNAME "ifname"
#define NM_RDISC_NETWORK_ID "network-id"
#define NM_RDISC_ADDR_GEN_MODE "addr-gen-mode"
#define NM_RDISC_STABLE_TYPE "stable-type"
#define NM_RDISC_MAX_ADDRESSES "max-addresses"
#define NM_RDISC_ROUTER_SOLICITATIONS "router-solicitations"
#define NM_RDISC_ROUTER_SOLICITATION_INTERVAL "router-solicitation-interval"
#define NM_RDISC_CONFIG_CHANGED "config-changed"
#define NM_RDISC_RA_TIMEOUT "ra-timeout"
typedef enum {
NM_RDISC_DHCP_LEVEL_UNKNOWN,
NM_RDISC_DHCP_LEVEL_NONE,
NM_RDISC_DHCP_LEVEL_OTHERCONF,
NM_RDISC_DHCP_LEVEL_MANAGED
} NMRDiscDHCPLevel;
typedef enum {
NM_RDISC_PREFERENCE_INVALID,
NM_RDISC_PREFERENCE_LOW,
NM_RDISC_PREFERENCE_MEDIUM,
NM_RDISC_PREFERENCE_HIGH
} NMRDiscPreference;
typedef struct {
struct in6_addr address;
guint32 timestamp;
guint32 lifetime;
NMRDiscPreference preference;
} NMRDiscGateway;
typedef struct {
struct in6_addr address;
guint8 dad_counter;
guint32 timestamp;
guint32 lifetime;
guint32 preferred;
} NMRDiscAddress;
typedef struct {
struct in6_addr network;
guint8 plen;
struct in6_addr gateway;
guint32 timestamp;
guint32 lifetime;
NMRDiscPreference preference;
} NMRDiscRoute;
typedef struct {
struct in6_addr address;
guint32 timestamp;
guint32 lifetime;
} NMRDiscDNSServer;
typedef struct {
char *domain;
guint32 timestamp;
guint32 lifetime;
} NMRDiscDNSDomain;
typedef enum {
NM_RDISC_CONFIG_DHCP_LEVEL = 1 << 0,
NM_RDISC_CONFIG_GATEWAYS = 1 << 1,
NM_RDISC_CONFIG_ADDRESSES = 1 << 2,
NM_RDISC_CONFIG_ROUTES = 1 << 3,
NM_RDISC_CONFIG_DNS_SERVERS = 1 << 4,
NM_RDISC_CONFIG_DNS_DOMAINS = 1 << 5,
NM_RDISC_CONFIG_HOP_LIMIT = 1 << 6,
NM_RDISC_CONFIG_MTU = 1 << 7,
} NMRDiscConfigMap;
#define NM_RDISC_MAX_ADDRESSES_DEFAULT 16
#define NM_RDISC_ROUTER_SOLICITATIONS_DEFAULT 3
#define NM_RDISC_ROUTER_SOLICITATION_INTERVAL_DEFAULT 4
struct _NMRDiscPrivate;
struct _NMRDiscDataInternal;
typedef struct {
NMRDiscDHCPLevel dhcp_level;
guint32 mtu;
int hop_limit;
guint gateways_n;
guint addresses_n;
guint routes_n;
guint dns_servers_n;
guint dns_domains_n;
const NMRDiscGateway *gateways;
const NMRDiscAddress *addresses;
const NMRDiscRoute *routes;
const NMRDiscDNSServer *dns_servers;
const NMRDiscDNSDomain *dns_domains;
} NMRDiscData;
/**
* NMRDisc:
*
* Interface-specific structure that handles incoming router advertisements,
* caches advertised items and removes them when they are obsolete.
*/
typedef struct {
GObject parent;
union {
struct _NMRDiscPrivate *_priv;
struct _NMRDiscDataInternal *rdata;
};
} NMRDisc;
typedef struct {
GObjectClass parent;
void (*start) (NMRDisc *rdisc);
gboolean (*send_rs) (NMRDisc *rdisc, GError **error);
} NMRDiscClass;
GType nm_rdisc_get_type (void);
int nm_rdisc_get_ifindex (NMRDisc *self);
const char *nm_rdisc_get_ifname (NMRDisc *self);
gboolean nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid);
void nm_rdisc_start (NMRDisc *rdisc);
void nm_rdisc_dad_failed (NMRDisc *rdisc, struct in6_addr *address);
NMPlatform *nm_rdisc_get_platform (NMRDisc *self);
NMPNetns *nm_rdisc_netns_get (NMRDisc *self);
gboolean nm_rdisc_netns_push (NMRDisc *self, NMPNetns **netns);
#endif /* __NETWORKMANAGER_RDISC_H__ */

View file

@ -1 +0,0 @@
/rdisc

View file

@ -29,7 +29,7 @@
#include "nm-test-utils-core.h"
/* Reference implementation for nm_utils_ip6_address_clear_host_address.
* Taken originally from set_address_masked(), src/rdisc/nm-lndp-rdisc.c
* Taken originally from set_address_masked(), src/ndisc/nm-lndp-ndisc.c
**/
static void
ip6_address_clear_host_address_reference (struct in6_addr *dst, struct in6_addr *src, guint8 plen)

View file

@ -288,7 +288,7 @@ test_nm_ip6_config_addresses_sort (void)
nm_ip6_config_reset_addresses (config);
ADDR_ADD("2607:f0d0:1002:51::4", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0);
ADDR_ADD("2607:f0d0:1002:51::5", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0);
ADDR_ADD("2607:f0d0:1002:51::6", NULL, 64, 0, NM_IP_CONFIG_SOURCE_RDISC, 0, 0, 0, IFA_F_MANAGETEMPADDR);
ADDR_ADD("2607:f0d0:1002:51::6", NULL, 64, 0, NM_IP_CONFIG_SOURCE_NDISC, 0, 0, 0, IFA_F_MANAGETEMPADDR);
ADDR_ADD("2607:f0d0:1002:51::3", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, IFA_F_SECONDARY);
ADDR_ADD("2607:f0d0:1002:51::8", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, IFA_F_SECONDARY);
ADDR_ADD("2607:f0d0:1002:51::0", NULL, 64, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, IFA_F_SECONDARY);
@ -307,7 +307,7 @@ test_nm_ip6_config_addresses_sort (void)
ADDR_ADD("2607:f0d0:1002:51::5", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, 0);
ADDR_ADD("2607:f0d0:1002:51::8", NULL, 64, 0, NM_IP_CONFIG_SOURCE_USER, 0, 0, 0, IFA_F_SECONDARY);
ADDR_ADD("2607:f0d0:1002:51::0", NULL, 64, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, IFA_F_SECONDARY);
ADDR_ADD("2607:f0d0:1002:51::6", NULL, 64, 0, NM_IP_CONFIG_SOURCE_RDISC, 0, 0, 0, IFA_F_MANAGETEMPADDR);
ADDR_ADD("2607:f0d0:1002:51::6", NULL, 64, 0, NM_IP_CONFIG_SOURCE_NDISC, 0, 0, 0, IFA_F_MANAGETEMPADDR);
ADDR_ADD("fec0::1", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0);
ADDR_ADD("fe80::208:74ff:feda:625c", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0);
ADDR_ADD("fe80::208:74ff:feda:625d", NULL, 128, 0, NM_IP_CONFIG_SOURCE_KERNEL, 0, 0, 0, 0);