core: merge branch 'th/dedup-multi-v2-bgo785004'

https://bugzilla.gnome.org/show_bug.cgi?id=785004
This commit is contained in:
Thomas Haller 2017-07-25 06:44:34 +02:00
commit 394ed959f4
38 changed files with 2658 additions and 1920 deletions

View file

@ -414,6 +414,7 @@ libnm_core_lib_h_pub_real = \
libnm_core_lib_h_pub_mkenums = \
libnm-core/nm-core-enum-types.h
libnm_core_lib_h_priv = \
shared/nm-utils/c-list-util.h \
shared/nm-utils/nm-dedup-multi.h \
shared/nm-utils/nm-enum-utils.h \
shared/nm-utils/nm-shared-utils.h \
@ -429,6 +430,7 @@ libnm_core_lib_h_priv = \
libnm-core/nm-setting-private.h \
libnm-core/nm-utils-private.h
libnm_core_lib_c_real = \
shared/nm-utils/c-list-util.c \
shared/nm-utils/nm-dedup-multi.c \
shared/nm-utils/nm-enum-utils.c \
shared/nm-utils/nm-shared-utils.c \
@ -4437,6 +4439,8 @@ EXTRA_DIST += \
shared/nm-test-libnm-utils.h \
shared/nm-test-utils-impl.c \
shared/nm-utils/c-list.h \
shared/nm-utils/c-list-util.c \
shared/nm-utils/c-list-util.h \
shared/nm-utils/gsystem-local-alloc.h \
shared/nm-utils/nm-glib.h \
shared/nm-utils/nm-obj.h \

View file

@ -25,6 +25,8 @@
#include <string.h>
#include "nm-utils/c-list-util.h"
#include "nm-utils.h"
#include "nm-setting-private.h"
#include "nm-utils.h"
@ -76,6 +78,103 @@ G_STATIC_ASSERT (sizeof (bool) <= sizeof (int));
/*****************************************************************************/
typedef struct {
int val;
int idx;
CList lst;
} CListSort;
static int
_c_list_sort_cmp (const CList *lst_a, const CList *lst_b, const void *user_data)
{
const CListSort *a, *b;
g_assert (lst_a);
g_assert (lst_b);
g_assert (lst_a != lst_b);
a = c_list_entry (lst_a, CListSort, lst);
b = c_list_entry (lst_b, CListSort, lst);
if (a->val < b->val)
return -1;
if (a->val > b->val)
return 1;
return 0;
}
static void
test_c_list_sort (void)
{
guint i, n_list, repeat, headless;
CList head, *iter, *iter_prev, *lst;
CListSort elements[30];
const CListSort *el_prev;
c_list_init (&head);
c_list_sort (&head, _c_list_sort_cmp, NULL);
g_assert (c_list_length (&head) == 0);
g_assert (c_list_is_empty (&head));
for (repeat = 0; repeat < 10; repeat++) {
for (n_list = 1; n_list < G_N_ELEMENTS (elements); n_list++) {
for (headless = 0; headless < 2; headless++) {
c_list_init (&head);
for (i = 0; i < n_list; i++) {
CListSort *el;
el = &elements[i];
el->val = nmtst_get_rand_int () % (2*n_list);
el->idx = i;
c_list_link_tail (&head, &el->lst);
}
if (headless) {
lst = head.next;
c_list_unlink (&head);
lst = c_list_sort_headless (lst, _c_list_sort_cmp, NULL);
g_assert (lst);
g_assert (lst->next);
g_assert (lst->prev);
g_assert (c_list_length (lst) == n_list - 1);
iter_prev = lst->prev;
for (iter = lst; iter != lst; iter = iter->next) {
g_assert (iter);
g_assert (iter->next);
g_assert (iter->prev == iter_prev);
}
c_list_link_before (lst, &head);
} else {
c_list_sort (&head, _c_list_sort_cmp, NULL);
}
g_assert (!c_list_is_empty (&head));
g_assert (c_list_length (&head) == n_list);
el_prev = NULL;
c_list_for_each (iter, &head) {
CListSort *el;
el = c_list_entry (iter, CListSort, lst);
g_assert (el->idx >= 0 && el->idx < n_list);
g_assert (el == &elements[el->idx]);
if (el_prev) {
g_assert (el_prev->val <= el->val);
if (el_prev->val == el->val)
g_assert (el_prev->idx < el->idx);
g_assert (iter->prev == &el_prev->lst);
g_assert (el_prev->lst.next == iter);
}
el_prev = el;
}
g_assert (head.prev == &el_prev->lst);
}
}
}
}
/*****************************************************************************/
typedef struct {
NMDedupMultiObj parent;
guint val;
@ -6078,6 +6177,7 @@ int main (int argc, char **argv)
{
nmtst_init (&argc, &argv, TRUE);
g_test_add_func ("/core/general/test_c_list_sort", test_c_list_sort);
g_test_add_func ("/core/general/test_dedup_multi", test_dedup_multi);
g_test_add_func ("/core/general/test_utils_str_utf8safe", test_utils_str_utf8safe);
g_test_add_func ("/core/general/test_nm_in_set", test_nm_in_set);

View file

@ -0,0 +1,165 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2017 Red Hat, Inc.
*/
#include "c-list-util.h"
/*****************************************************************************/
/**
* c_list_relink:
* @lst: the head list entry
*
* Takes an invalid list, that has undefined prev pointers.
* Only the next pointers are valid, and the tail's next
* pointer points to %NULL instead of the head.
*
* c_list_relink() fixes the list by updating all prev pointers
* and close the circular linking by pointing the tails' next
* pointer to @lst.
*
* The use of this function is to do a bulk update, that lets the
* list degredate by not updating the prev pointers. At the end,
* the list can be fixed by c_list_relink().
*/
void
c_list_relink (CList *lst)
{
CList *ls, *ls_prev;
ls_prev = lst;
ls = lst->next;
do {
ls->prev = ls_prev;
ls_prev = ls;
ls = ls->next;
} while (ls);
ls_prev->next = lst;
lst->prev = ls_prev;
}
/*****************************************************************************/
static CList *
_c_list_sort (CList *ls,
CListSortCmp cmp,
const void *user_data)
{
CList *ls1, *ls2;
CList head;
if (!ls->next)
return ls;
/* split list in two halfs @ls1 and @ls2. */
ls1 = ls;
ls2 = ls;
ls = ls->next;
while (ls) {
ls = ls->next;
if (!ls)
break;
ls = ls->next;
ls2 = ls2->next;
}
ls = ls2;
ls2 = ls->next;
ls->next = NULL;
/* recurse */
ls1 = _c_list_sort (ls1, cmp, user_data);
if (!ls2)
return ls1;
ls2 = _c_list_sort (ls2, cmp, user_data);
/* merge */
ls = &head;
for (;;) {
/* while invoking the @cmp function, the list
* elements are not properly linked. Don't try to access
* their next/prev pointers. */
if (cmp (ls1, ls2, user_data) <= 0) {
ls->next = ls1;
ls = ls1;
ls1 = ls1->next;
if (!ls1)
break;
} else {
ls->next = ls2;
ls = ls2;
ls2 = ls2->next;
if (!ls2)
break;
}
}
ls->next = ls1 ?: ls2;
return head.next;
}
/**
* c_list_sort_headless:
* @lst: the list.
* @cmp: compare function for sorting. While comparing two
* CList elements, their next/prev pointers are in undefined
* state.
* @user_data: user data for @cmp.
*
* Sorts the list @lst according to @cmp. Contrary to
* c_list_sort(), @lst is not the list head but a
* valid entry as well. This function returns the new
* list head.
*/
CList *
c_list_sort_headless (CList *lst,
CListSortCmp cmp,
const void *user_data)
{
if (!c_list_is_empty (lst)) {
lst->prev->next = NULL;
lst = _c_list_sort (lst, cmp, user_data);
c_list_relink (lst);
}
return lst;
}
/**
* c_list_sort:
* @head: the list head.
* @cmp: compare function for sorting. While comparing two
* CList elements, their next/prev pointers are in undefined
* state.
* @user_data: user data for @cmp.
*
* Sorts the list @head according to @cmp.
*/
void
c_list_sort (CList *head,
CListSortCmp cmp,
const void *user_data)
{
if ( !c_list_is_empty (head)
&& head->next->next != head) {
head->prev->next = NULL;
head->next = _c_list_sort (head->next, cmp, user_data);
c_list_relink (head);
}
}

View file

@ -0,0 +1,43 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2017 Red Hat, Inc.
*/
#ifndef __C_LIST_UTIL_H__
#define __C_LIST_UTIL_H__
#include "c-list.h"
/*****************************************************************************/
void c_list_relink (CList *lst);
typedef int (*CListSortCmp) (const CList *a,
const CList *b,
const void *user_data);
CList *c_list_sort_headless (CList *lst,
CListSortCmp cmp,
const void *user_data);
void c_list_sort (CList *head,
CListSortCmp cmp,
const void *user_data);
#endif /* __C_LIST_UTIL_H__ */

View file

@ -927,21 +927,60 @@ nm_dedup_multi_obj_clone (const NMDedupMultiObj *obj)
return o;
}
gconstpointer *
nm_dedup_multi_objs_to_array_head (const NMDedupMultiHeadEntry *head_entry,
NMDedupMultiFcnSelectPredicate predicate,
gpointer user_data,
guint *out_len)
{
gconstpointer *result;
CList *iter;
guint i;
if (!head_entry) {
NM_SET_OUT (out_len, 0);
return NULL;
}
result = g_new (gconstpointer, head_entry->len + 1);
i = 0;
c_list_for_each (iter, &head_entry->lst_entries_head) {
const NMDedupMultiObj *obj = c_list_entry (iter, NMDedupMultiEntry, lst_entries)->obj;
if ( !predicate
|| predicate (obj, user_data)) {
nm_assert (i < head_entry->len);
result[i++] = obj;
}
}
if (i == 0) {
g_free (result);
NM_SET_OUT (out_len, 0);
return NULL;
}
nm_assert (i <= head_entry->len);
NM_SET_OUT (out_len, i);
result[i++] = NULL;
return result;
}
GPtrArray *
nm_dedup_multi_objs_to_ptr_array_head (const NMDedupMultiHeadEntry *head_entry,
NMDedupMultiFcnSelectPredicate predicate,
gpointer user_data)
{
GPtrArray *result;
NMDedupMultiIter iter;
CList *iter;
if (!head_entry)
return NULL;
result = g_ptr_array_new_full (head_entry->len,
(GDestroyNotify) nm_dedup_multi_obj_unref);
nm_dedup_multi_iter_for_each (&iter, head_entry) {
const NMDedupMultiObj *obj = iter.current->obj;
c_list_for_each (iter, &head_entry->lst_entries_head) {
const NMDedupMultiObj *obj = c_list_entry (iter, NMDedupMultiEntry, lst_entries)->obj;
if ( !predicate
|| predicate (obj, user_data))

View file

@ -23,7 +23,7 @@
#define __NM_DEDUP_MULTI_H__
#include "nm-obj.h"
#include "c-list.h"
#include "c-list-util.h"
/*****************************************************************************/
@ -302,9 +302,9 @@ guint nm_dedup_multi_index_dirty_remove_idx (NMDedupMultiIndex *self,
/*****************************************************************************/
typedef struct _NMDedupMultiIter {
const NMDedupMultiHeadEntry *head;
const CList *_head;
const CList *_next;
const NMDedupMultiEntry *current;
const NMDedupMultiEntry *next;
} NMDedupMultiIter;
static inline void
@ -312,11 +312,14 @@ nm_dedup_multi_iter_init (NMDedupMultiIter *iter, const NMDedupMultiHeadEntry *h
{
g_return_if_fail (iter);
iter->head = head;
if (head && !c_list_is_empty (&head->lst_entries_head)) {
iter->_head = &head->lst_entries_head;
iter->_next = head->lst_entries_head.next;
} else {
iter->_head = NULL;
iter->_next = NULL;
}
iter->current = NULL;
iter->next = head && !c_list_is_empty (&head->lst_entries_head)
? c_list_entry (head->lst_entries_head.next, NMDedupMultiEntry, lst_entries)
: NULL;
}
static inline gboolean
@ -324,42 +327,19 @@ nm_dedup_multi_iter_next (NMDedupMultiIter *iter)
{
g_return_val_if_fail (iter, FALSE);
if (!iter->next)
if (!iter->_next)
return FALSE;
/* we always look ahead for the @next. This way, the user
/* we always look ahead for the next. This way, the user
* may delete the current entry (but no other entries). */
iter->current = iter->next;
if (iter->next->lst_entries.next == &iter->head->lst_entries_head)
iter->next = NULL;
iter->current = c_list_entry (iter->_next, NMDedupMultiEntry, lst_entries);
if (iter->_next->next == iter->_head)
iter->_next = NULL;
else
iter->next = c_list_entry (iter->next->lst_entries.next, NMDedupMultiEntry, lst_entries);
iter->_next = iter->_next->next;
return TRUE;
}
static inline void
nm_dedup_multi_iter_rewind (NMDedupMultiIter *iter)
{
/* rewind the iterator.
*
* In principle, you can always delete the current entry.
* However, if you delete *all* current entries, the list
* head becomes invalid too and rewinding will crash.
*
* So, either
* - don't modify the list
* - if you modify it:
* - only delete the current entry, don't delete other entries.
* - you may add more entries, however that may make iteration
* confusing.
* - you may rewind the iterator, but only if not all
* entires were deleted.
*
* Use with care. */
g_return_if_fail (iter);
nm_dedup_multi_iter_init (iter, iter->head);
}
#define nm_dedup_multi_iter_for_each(iter, head_entry) \
for (nm_dedup_multi_iter_init ((iter), (head_entry)); \
nm_dedup_multi_iter_next ((iter)); \
@ -370,10 +350,27 @@ nm_dedup_multi_iter_rewind (NMDedupMultiIter *iter)
typedef gboolean (*NMDedupMultiFcnSelectPredicate) (/* const NMDedupMultiObj * */ gconstpointer obj,
gpointer user_data);
gconstpointer *nm_dedup_multi_objs_to_array_head (const NMDedupMultiHeadEntry *head_entry,
NMDedupMultiFcnSelectPredicate predicate,
gpointer user_data,
guint *out_len);
GPtrArray *nm_dedup_multi_objs_to_ptr_array_head (const NMDedupMultiHeadEntry *head_entry,
NMDedupMultiFcnSelectPredicate predicate,
gpointer user_data);
static inline void
nm_dedup_multi_head_entry_sort (const NMDedupMultiHeadEntry *head_entry,
CListSortCmp cmp,
gconstpointer user_data)
{
if (head_entry) {
/* the head entry can be sorted directly without messing up the
* index to which it belongs. Of course, this does mess up any
* NMDedupMultiIter instances. */
c_list_sort ((CList *) &head_entry->lst_entries_head, cmp, user_data);
}
}
/*****************************************************************************/
#endif /* __NM_DEDUP_MULTI_H__ */

View file

@ -2454,16 +2454,19 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self)
gint32 now;
GArray *addresses, *dns_servers, *dns_domains;
guint len, i;
const NMDedupMultiHeadEntry *head_entry;
NMDedupMultiIter ipconf_iter;
if (nm_ndisc_get_node_type (ndisc) != NM_NDISC_NODE_TYPE_ROUTER)
return;
now = nm_utils_get_monotonic_timestamp_s ();
len = nm_ip6_config_get_num_addresses (priv->ip6_config);
addresses = g_array_sized_new (FALSE, TRUE, sizeof (NMNDiscAddress), len);
for (i = 0; i < len; i++) {
const NMPlatformIP6Address *addr = nm_ip6_config_get_address (priv->ip6_config, i);
head_entry = nm_ip6_config_lookup_addresses (priv->ip6_config);
addresses = g_array_sized_new (FALSE, TRUE, sizeof (NMNDiscAddress),
head_entry ? head_entry->len : 0);
nm_dedup_multi_iter_for_each (&ipconf_iter, head_entry) {
const NMPlatformIP6Address *addr = NMP_OBJECT_CAST_IP6_ADDRESS (ipconf_iter.current->obj);
NMNDiscAddress *ndisc_addr;
if (IN6_IS_ADDR_LINKLOCAL (&addr->address))
@ -5095,17 +5098,17 @@ arping_manager_probe_terminated (NMArpingManager *arping_manager, ArpingData *da
{
NMDevice *self;
NMDevicePrivate *priv;
NMDedupMultiIter ipconf_iter;
const NMPlatformIP4Address *address;
gboolean result, success = TRUE;
int i, j;
int i;
g_assert (data);
self = data->device;
priv = NM_DEVICE_GET_PRIVATE (self);
for (i = 0; data->configs && data->configs[i]; i++) {
for (j = 0; j < nm_ip4_config_get_num_addresses (data->configs[i]); j++) {
address = nm_ip4_config_get_address (data->configs[i], j);
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, data->configs[i], &address) {
result = nm_arping_manager_check_address (arping_manager, address->address);
success &= result;
@ -5139,13 +5142,14 @@ ipv4_dad_start (NMDevice *self, NMIP4Config **configs, ArpingCallback cb)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMArpingManager *arping_manager;
const NMPlatformIP4Address *address;
NMDedupMultiIter ipconf_iter;
ArpingData *data;
guint timeout;
gboolean ret, addr_found;
const guint8 *hw_addr;
size_t hw_addr_len = 0;
GError *error = NULL;
guint i, j;
guint i;
g_return_if_fail (NM_IS_DEVICE (self));
g_return_if_fail (configs);
@ -5191,10 +5195,8 @@ ipv4_dad_start (NMDevice *self, NMIP4Config **configs, ArpingCallback cb)
data->device = self;
for (i = 0; configs[i]; i++) {
for (j = 0; j < nm_ip4_config_get_num_addresses (configs[i]); j++) {
address = nm_ip4_config_get_address (configs[i], j);
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, configs[i], &address)
nm_arping_manager_add_address (arping_manager, address->address);
}
}
g_signal_connect_data (arping_manager, NM_ARPING_MANAGER_PROBE_TERMINATED,
@ -6618,7 +6620,6 @@ dhcp6_state_changed (NMDhcpClient *client,
{
NMDevice *self = NM_DEVICE (user_data);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
guint i;
g_return_if_fail (nm_dhcp_client_get_ipv6 (client) == TRUE);
g_return_if_fail (!ip6_config || NM_IS_IP6_CONFIG (ip6_config));
@ -6635,10 +6636,11 @@ dhcp6_state_changed (NMDhcpClient *client,
&& event_id
&& priv->dhcp6.event_id
&& !strcmp (event_id, priv->dhcp6.event_id)) {
for (i = 0; i < nm_ip6_config_get_num_addresses (ip6_config); i++) {
nm_ip6_config_add_address (priv->dhcp6.ip6_config,
nm_ip6_config_get_address (ip6_config, i));
}
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Address *a;
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6_config, &a)
nm_ip6_config_add_address (priv->dhcp6.ip6_config, a);
} else {
g_clear_object (&priv->dhcp6.ip6_config);
g_clear_pointer (&priv->dhcp6.event_id, g_free);
@ -6978,7 +6980,6 @@ check_and_add_ipv6ll_addr (NMDevice *self)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
int ip_ifindex = nm_device_get_ip_ifindex (self);
struct in6_addr lladdr;
guint i, n;
NMConnection *connection;
NMSettingIP6Config *s_ip6 = NULL;
GError *error = NULL;
@ -6987,11 +6988,10 @@ check_and_add_ipv6ll_addr (NMDevice *self)
return;
if (priv->ip6_config) {
n = nm_ip6_config_get_num_addresses (priv->ip6_config);
for (i = 0; i < n; i++) {
const NMPlatformIP6Address *addr;
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Address *addr;
addr = nm_ip6_config_get_address (priv->ip6_config, i);
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, priv->ip6_config, &addr) {
if ( IN6_IS_ADDR_LINKLOCAL (&addr->address)
&& !(addr->n_ifa_flags & IFA_F_DADFAILED)) {
/* Already have an LL address, nothing to do */
@ -8292,15 +8292,15 @@ start_sharing (NMDevice *self, NMIP4Config *config)
char str_addr[INET_ADDRSTRLEN + 1];
char str_mask[INET_ADDRSTRLEN + 1];
guint32 netmask, network;
const NMPlatformIP4Address *ip4_addr;
const NMPlatformIP4Address *ip4_addr = NULL;
const char *ip_iface;
g_return_val_if_fail (config != NULL, FALSE);
ip_iface = nm_device_get_ip_iface (self);
ip4_addr = nm_ip4_config_get_address (config, 0);
if (!ip4_addr || !ip4_addr->address)
ip4_addr = nm_ip4_config_get_first_address (config);
if (ip4_addr || !ip4_addr->address)
return FALSE;
netmask = nm_utils_ip4_prefix_to_netmask (ip4_addr->plen);
@ -8513,7 +8513,8 @@ dad6_get_pending_addresses (NMDevice *self)
priv->wwan_ip6_config };
const NMPlatformIP6Address *addr, *pl_addr;
NMIP6Config *dad6_config = NULL;
guint i, j, num;
NMDedupMultiIter ipconf_iter;
guint i;
int ifindex;
ifindex = nm_device_get_ip_ifindex (self);
@ -8524,9 +8525,8 @@ dad6_get_pending_addresses (NMDevice *self)
*/
for (i = 0; i < G_N_ELEMENTS (confs); i++) {
if (confs[i]) {
num = nm_ip6_config_get_num_addresses (confs[i]);
for (j = 0; j < num; j++) {
addr = nm_ip6_config_get_address (confs[i], j);
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, confs[i], &addr) {
pl_addr = nm_platform_ip6_address_get (nm_device_get_platform (self),
ifindex,
addr->address);
@ -8738,16 +8738,15 @@ static void
_update_ip4_address (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
guint32 addr;
const NMPlatformIP4Address *address;
g_return_if_fail (NM_IS_DEVICE (self));
if ( priv->ip4_config
&& ip_config_valid (priv->state)
&& nm_ip4_config_get_num_addresses (priv->ip4_config)) {
addr = nm_ip4_config_get_address (priv->ip4_config, 0)->address;
if (addr != priv->ip4_address) {
priv->ip4_address = addr;
&& (address = nm_ip4_config_get_first_address (priv->ip4_config))) {
if (address->address != priv->ip4_address) {
priv->ip4_address = address->address;
_notify (self, PROP_IP4_ADDRESS);
}
}
@ -10598,7 +10597,7 @@ find_ip4_lease_config (NMDevice *self,
nm_device_get_ip4_route_metric (self));
for (liter = leases; liter && !found; liter = liter->next) {
NMIP4Config *lease_config = liter->data;
const NMPlatformIP4Address *address = nm_ip4_config_get_address (lease_config, 0);
const NMPlatformIP4Address *address = nm_ip4_config_get_first_address (lease_config);
guint32 gateway = nm_ip4_config_get_gateway (lease_config);
g_assert (address);
@ -10624,23 +10623,24 @@ capture_lease_config (NMDevice *self,
NMSettingsConnection *const*connections;
guint i;
gboolean dhcp_used = FALSE;
NMDedupMultiIter ipconf_iter;
/* Ensure at least one address on the device has a non-infinite lifetime,
* otherwise DHCP cannot possibly be active on the device right now.
*/
if (ext_ip4_config && out_ip4_config) {
for (i = 0; i < nm_ip4_config_get_num_addresses (ext_ip4_config); i++) {
const NMPlatformIP4Address *addr = nm_ip4_config_get_address (ext_ip4_config, i);
const NMPlatformIP4Address *addr;
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ext_ip4_config, &addr) {
if (addr->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) {
dhcp_used = TRUE;
break;
}
}
} else if (ext_ip6_config && out_ip6_config) {
for (i = 0; i < nm_ip6_config_get_num_addresses (ext_ip6_config); i++) {
const NMPlatformIP6Address *addr = nm_ip6_config_get_address (ext_ip6_config, i);
const NMPlatformIP6Address *addr;
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ext_ip6_config, &addr) {
if (addr->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) {
dhcp_used = TRUE;
break;
@ -12227,15 +12227,13 @@ static char *
find_dhcp4_address (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
guint i, n;
const NMPlatformIP4Address *a;
NMDedupMultiIter ipconf_iter;
if (!priv->ip4_config)
return NULL;
n = nm_ip4_config_get_num_addresses (priv->ip4_config);
for (i = 0; i < n; i++) {
const NMPlatformIP4Address *a = nm_ip4_config_get_address (priv->ip4_config, i);
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, priv->ip4_config, &a) {
if (a->addr_source == NM_IP_CONFIG_SOURCE_DHCP)
return g_strdup (nm_utils_inet4_ntop (a->address, NULL));
}

View file

@ -682,7 +682,7 @@ nm_modem_ip4_pre_commit (NMModem *modem,
*/
if ( priv->ip4_method == NM_MODEM_IP_METHOD_STATIC
|| priv->ip4_method == NM_MODEM_IP_METHOD_AUTO) {
const NMPlatformIP4Address *address = nm_ip4_config_get_address (config, 0);
const NMPlatformIP4Address *address = nm_ip4_config_get_first_address (config);
g_assert (address);
if (address->plen == 32)
@ -698,7 +698,8 @@ nm_modem_emit_ip6_config_result (NMModem *self,
GError *error)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
guint i, num;
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Address *addr;
gboolean do_slaac = TRUE;
if (error) {
@ -710,11 +711,7 @@ nm_modem_emit_ip6_config_result (NMModem *self,
/* If the IPv6 configuration only included a Link-Local address, then
* we have to run SLAAC to get the full IPv6 configuration.
*/
num = nm_ip6_config_get_num_addresses (config);
g_assert (num > 0);
for (i = 0; i < num; i++) {
const NMPlatformIP6Address * addr = nm_ip6_config_get_address (config, i);
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, config, &addr) {
if (IN6_IS_ADDR_LINKLOCAL (&addr->address)) {
if (!priv->iid.id)
priv->iid.id = ((guint64 *)(&addr->address.s6_addr))[1];

View file

@ -344,12 +344,13 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
if (sd_dhcp_route_get_destination (routes[i], &a) < 0)
continue;
route.network = a.s_addr;
if ( sd_dhcp_route_get_destination_prefix_length (routes[i], &plen) < 0
|| plen > 32)
continue;
route.plen = plen;
route.network = nm_utils_ip4_address_clear_host_address (a.s_addr, plen);
if (sd_dhcp_route_get_gateway (routes[i], &a) < 0)
continue;

View file

@ -86,7 +86,7 @@ ip4_process_dhcpcd_rfc3442_routes (const char *iface,
} else {
_LOG2I (LOGD_DHCP4, iface, " classless static route %s/%d gw %s", *r, rt_cidr, *(r + 1));
memset (&route, 0, sizeof (route));
route.network = rt_addr;
route.network = nm_utils_ip4_address_clear_host_address (rt_addr, rt_cidr);
route.plen = rt_cidr;
route.gateway = rt_route;
route.rt_source = NM_IP_CONFIG_SOURCE_DHCP;
@ -144,8 +144,7 @@ process_dhclient_rfc3442_route (const char **octets,
goto error;
}
g_free (str_addr);
tmp_addr &= nm_utils_ip4_prefix_to_netmask ((guint32) tmp);
route->network = tmp_addr;
route->network = nm_utils_ip4_address_clear_host_address (tmp_addr, tmp);
}
/* Handle next hop */
@ -327,6 +326,8 @@ process_classful_routes (const char *iface,
route.rt_source = NM_IP_CONFIG_SOURCE_DHCP;
route.metric = priority;
route.network = nm_utils_ip4_address_clear_host_address (route.network, route.plen);
nm_ip4_config_add_route (ip4_config, &route);
_LOG2I (LOGD_DHCP, iface, " static route %s",
nm_platform_ip4_route_to_string (&route, NULL, 0));

View file

@ -37,6 +37,8 @@
#define DEBUG 1
static const int IFINDEX = 5;
static void
test_config (const char *orig,
const char *expected,
@ -910,7 +912,7 @@ test_read_lease_ip4_config_basic (void)
/* Date from before the least expiration */
now = g_date_time_new_utc (2013, 11, 1, 19, 55, 32);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", -1, contents, FALSE, now);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", IFINDEX, contents, FALSE, now);
g_assert_cmpint (g_slist_length (leases), ==, 2);
/* IP4Config #1 */
@ -920,7 +922,7 @@ test_read_lease_ip4_config_basic (void)
/* Address */
g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1);
expected_addr = nmtst_inet4_from_string ("192.168.1.180");
addr = nm_ip4_config_get_address (config, 0);
addr = _nmtst_nm_ip4_config_get_address (config, 0);
g_assert_cmpint (addr->address, ==, expected_addr);
g_assert_cmpint (addr->peer_address, ==, expected_addr);
g_assert_cmpint (addr->plen, ==, 24);
@ -943,7 +945,7 @@ test_read_lease_ip4_config_basic (void)
/* Address */
g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1);
expected_addr = nmtst_inet4_from_string ("10.77.52.141");
addr = nm_ip4_config_get_address (config, 0);
addr = _nmtst_nm_ip4_config_get_address (config, 0);
g_assert_cmpint (addr->address, ==, expected_addr);
g_assert_cmpint (addr->peer_address, ==, expected_addr);
g_assert_cmpint (addr->plen, ==, 8);
@ -985,7 +987,7 @@ test_read_lease_ip4_config_expired (void)
/* Date from *after* the lease expiration */
now = g_date_time_new_utc (2013, 12, 1, 19, 55, 32);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", -1, contents, FALSE, now);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", IFINDEX, contents, FALSE, now);
g_assert (leases == NULL);
g_date_time_unref (now);
@ -1008,7 +1010,7 @@ test_read_lease_ip4_config_expect_failure (gconstpointer user_data)
/* Date from before the least expiration */
now = g_date_time_new_utc (2013, 11, 1, 1, 1, 1);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", -1, contents, FALSE, now);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, "wlan0", IFINDEX, contents, FALSE, now);
g_assert (leases == NULL);
g_date_time_unref (now);

View file

@ -105,7 +105,7 @@ test_generic_options (void)
/* IP4 address */
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
address = nm_ip4_config_get_address (ip4_config, 0);
address = _nmtst_nm_ip4_config_get_address (ip4_config, 0);
g_assert (inet_pton (AF_INET, expected_addr, &tmp) > 0);
g_assert (address->address == tmp);
g_assert (address->peer_address == tmp);
@ -175,7 +175,7 @@ test_wins_options (void)
/* IP4 address */
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
address = nm_ip4_config_get_address (ip4_config, 0);
address = _nmtst_nm_ip4_config_get_address (ip4_config, 0);
g_assert (address);
g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 2);
g_assert (inet_pton (AF_INET, expected_wins1, &tmp) > 0);
@ -624,7 +624,7 @@ test_ip4_missing_prefix (const char *ip, guint32 expected_prefix)
ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
address = nm_ip4_config_get_address (ip4_config, 0);
address = _nmtst_nm_ip4_config_get_address (ip4_config, 0);
g_assert (address);
g_assert_cmpint (address->plen, ==, expected_prefix);
@ -668,7 +668,7 @@ test_ip4_prefix_classless (void)
ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
address = nm_ip4_config_get_address (ip4_config, 0);
address = _nmtst_nm_ip4_config_get_address (ip4_config, 0);
g_assert (address);
g_assert_cmpint (address->plen, ==, 22);

View file

@ -80,21 +80,18 @@ get_ip4_rdns_domains (NMIP4Config *ip4)
{
char **strv;
GPtrArray *domains = NULL;
guint i;
NMDedupMultiIter ipconf_iter;
const NMPlatformIP4Address *address;
const NMPlatformIP4Route *route;
g_return_val_if_fail (ip4 != NULL, NULL);
domains = g_ptr_array_sized_new (5);
for (i = 0; i < nm_ip4_config_get_num_addresses (ip4); i++) {
const NMPlatformIP4Address *address = nm_ip4_config_get_address (ip4, i);
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &address)
nm_utils_get_reverse_dns_domains_ip4 (address->address, address->plen, domains);
}
nm_ip4_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &route)
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &route)
nm_utils_get_reverse_dns_domains_ip4 (route->network, route->plen, domains);
/* Terminating NULL so we can use g_strfreev() to free it */
@ -111,21 +108,18 @@ get_ip6_rdns_domains (NMIP6Config *ip6)
{
char **strv;
GPtrArray *domains = NULL;
guint i;
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Address *address;
const NMPlatformIP6Route *route;
g_return_val_if_fail (ip6 != NULL, NULL);
domains = g_ptr_array_sized_new (5);
for (i = 0; i < nm_ip6_config_get_num_addresses (ip6); i++) {
const NMPlatformIP6Address *address = nm_ip6_config_get_address (ip6, i);
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &address)
nm_utils_get_reverse_dns_domains_ip6 (&address->address, address->plen, domains);
}
nm_ip6_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &route)
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &route)
nm_utils_get_reverse_dns_domains_ip6 (&route->network, route->plen, domains);
/* Terminating NULL so we can use g_strfreev() to free it */

View file

@ -162,7 +162,7 @@ create_dm_cmd_line (const char *iface,
const NMPlatformIP4Address *listen_address;
guint i, n;
listen_address = nm_ip4_config_get_address (ip4_config, 0);
listen_address = nm_ip4_config_get_first_address (ip4_config);
g_return_val_if_fail (listen_address, NULL);
dm_binary = nm_utils_find_helper ("dnsmasq", DNSMASQ_PATH, error);

View file

@ -287,15 +287,17 @@ nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen)
* @plen: prefix length of network
*
* Note: this function is self assignment safe, to update @src inplace, set both
* @dst and @src to the same destination.
* @dst and @src to the same destination or set @src NULL.
*/
const struct in6_addr *
nm_utils_ip6_address_clear_host_address (struct in6_addr *dst, const struct in6_addr *src, guint8 plen)
{
g_return_val_if_fail (plen <= 128, NULL);
g_return_val_if_fail (src, NULL);
g_return_val_if_fail (dst, NULL);
if (!src)
src = dst;
if (plen < 128) {
guint nbytes = plen / 8;
guint nbits = plen % 8;

View file

@ -371,7 +371,7 @@ _platform_route_sync_flush (const VTableIP *vtable, NMDefaultRouteManager *self,
*/
if ( !entry
&& (has_ifindex_synced || ifindex_to_flush == route->ifindex)) {
vtable->vt->route_delete_default (priv->platform, route->ifindex, route->metric);
nm_platform_ip_route_delete (priv->platform, NMP_OBJECT_UP_CAST (route));
changed = TRUE;
}
}

View file

@ -114,6 +114,7 @@ dump_ip4_to_props (NMIP4Config *ip4, GVariantBuilder *builder)
{
GVariantBuilder int_builder;
NMDedupMultiIter ipconf_iter;
gboolean first;
guint n, i;
const NMPlatformIP4Address *addr;
const NMPlatformIP4Route *route;
@ -121,15 +122,15 @@ dump_ip4_to_props (NMIP4Config *ip4, GVariantBuilder *builder)
/* Addresses */
g_variant_builder_init (&int_builder, G_VARIANT_TYPE ("aau"));
n = nm_ip4_config_get_num_addresses (ip4);
for (i = 0; i < n; i++) {
addr = nm_ip4_config_get_address (ip4, i);
first = TRUE;
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &addr) {
array[0] = addr->address;
array[1] = addr->plen;
array[2] = (i == 0) ? nm_ip4_config_get_gateway (ip4) : 0;
array[2] = first ? nm_ip4_config_get_gateway (ip4) : 0;
g_variant_builder_add (&int_builder, "@au",
g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
array, 3, sizeof (guint32)));
first = FALSE;
}
g_variant_builder_add (builder, "{sv}",
"addresses",
@ -164,7 +165,7 @@ dump_ip4_to_props (NMIP4Config *ip4, GVariantBuilder *builder)
/* Static routes */
g_variant_builder_init (&int_builder, G_VARIANT_TYPE ("aau"));
nm_ip4_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &route) {
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &route) {
array[0] = route->network;
array[1] = route->plen;
array[2] = route->gateway;
@ -184,24 +185,26 @@ dump_ip6_to_props (NMIP6Config *ip6, GVariantBuilder *builder)
GVariantBuilder int_builder;
NMDedupMultiIter ipconf_iter;
guint n, i;
gboolean first;
const NMPlatformIP6Address *addr;
const struct in6_addr *gw_bytes;
const NMPlatformIP6Route *route;
GVariant *ip, *gw;
/* Addresses */
g_variant_builder_init (&int_builder, G_VARIANT_TYPE ("a(ayuay)"));
n = nm_ip6_config_get_num_addresses (ip6);
for (i = 0; i < n; i++) {
addr = nm_ip6_config_get_address (ip6, i);
gw_bytes = nm_ip6_config_get_gateway (ip6);
first = TRUE;
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &addr) {
ip = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
&addr->address,
sizeof (struct in6_addr), 1);
gw = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
(i == 0 && gw_bytes) ? gw_bytes : &in6addr_any,
first
? (nm_ip6_config_get_gateway (ip6) ?: &in6addr_any)
: &in6addr_any,
sizeof (struct in6_addr), 1);
g_variant_builder_add (&int_builder, "(@ayu@ay)", ip, addr->plen, gw);
first = FALSE;
}
g_variant_builder_add (builder, "{sv}",
"addresses",
@ -231,7 +234,7 @@ dump_ip6_to_props (NMIP6Config *ip6, GVariantBuilder *builder)
/* Static routes */
g_variant_builder_init (&int_builder, G_VARIANT_TYPE ("a(ayuayu)"));
nm_ip6_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &route) {
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &route) {
ip = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
&route->network,
sizeof (struct in6_addr), 1);

File diff suppressed because it is too large Load diff

View file

@ -25,6 +25,7 @@
#include "nm-setting-ip4-config.h"
#include "nm-utils/nm-dedup-multi.h"
#include "platform/nmp-object.h"
/*****************************************************************************/
@ -35,19 +36,64 @@ typedef struct {
void nm_ip_config_dedup_multi_idx_type_init (NMIPConfigDedupMultiIdxType *idx_type, NMPObjectType obj_type);
void nm_ip4_config_iter_ip4_route_init (NMDedupMultiIter *iter, const NMIP4Config *self);
gboolean nm_ip4_config_iter_ip4_route_next (NMDedupMultiIter *iter, const NMPlatformIP4Route **out_route);
/*****************************************************************************/
#define nm_ip4_config_iter_ip4_route_for_each(iter, self, route) \
for (nm_ip4_config_iter_ip4_route_init ((iter), (self)); \
nm_ip4_config_iter_ip4_route_next ((iter), (route)); \
)
void nm_ip_config_iter_ip4_address_init (NMDedupMultiIter *iter, const NMIP4Config *self);
void nm_ip_config_iter_ip4_route_init (NMDedupMultiIter *iter, const NMIP4Config *self);
static inline gboolean
nm_ip_config_iter_ip4_address_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP4Address **out_address)
{
gboolean has_next;
g_return_val_if_fail (out_address, FALSE);
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (has_next)
*out_address = NMP_OBJECT_CAST_IP4_ADDRESS (ipconf_iter->current->obj);
return has_next;
}
static inline gboolean
nm_ip_config_iter_ip4_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP4Route **out_route)
{
gboolean has_next;
g_return_val_if_fail (out_route, FALSE);
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (has_next)
*out_route = NMP_OBJECT_CAST_IP4_ROUTE (ipconf_iter->current->obj);
return has_next;
}
#define nm_ip_config_iter_ip4_address_for_each(iter, self, address) \
for (*(address) = NULL, nm_ip_config_iter_ip4_address_init ((iter), (self)); \
nm_ip_config_iter_ip4_address_next ((iter), (address)); \
)
#define nm_ip_config_iter_ip4_route_for_each(iter, self, route) \
for (*(route) = NULL, nm_ip_config_iter_ip4_route_init ((iter), (self)); \
nm_ip_config_iter_ip4_route_next ((iter), (route)); \
)
/*****************************************************************************/
gboolean nm_ip_config_obj_id_equal_ip4_address (const NMPlatformIP4Address *a,
const NMPlatformIP4Address *b);
gboolean nm_ip_config_obj_id_equal_ip6_address (const NMPlatformIP6Address *a,
const NMPlatformIP6Address *b);
gboolean nm_ip_config_obj_id_equal_ip4_route (const NMPlatformIP4Route *r_a,
const NMPlatformIP4Route *r_b);
gboolean nm_ip_config_obj_id_equal_ip6_route (const NMPlatformIP6Route *r_a,
const NMPlatformIP6Route *r_b);
gboolean _nm_ip_config_add_obj (NMDedupMultiIndex *multi_idx,
NMIPConfigDedupMultiIdxType *idx_type,
int ifindex,
const NMPObject *obj_new,
const NMPlatformObject *pl_new);
/*****************************************************************************/
#define NM_TYPE_IP4_CONFIG (nm_ip4_config_get_type ())
@ -84,99 +130,102 @@ GType nm_ip4_config_get_type (void);
NMIP4Config * nm_ip4_config_new (NMDedupMultiIndex *multi_idx,
int ifindex);
int nm_ip4_config_get_ifindex (const NMIP4Config *config);
int nm_ip4_config_get_ifindex (const NMIP4Config *self);
NMDedupMultiIndex *nm_ip4_config_get_multi_idx (const NMIP4Config *self);
NMIP4Config *nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf);
gboolean nm_ip4_config_commit (const NMIP4Config *config, NMPlatform *platform, NMRouteManager *route_manager, int ifindex, gboolean routes_full_sync, gint64 default_route_metric);
void nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip4_config_create_setting (const NMIP4Config *config);
gboolean nm_ip4_config_commit (const NMIP4Config *self, NMPlatform *platform, NMRouteManager *route_manager, int ifindex, gboolean routes_full_sync, gint64 default_route_metric);
void nm_ip4_config_merge_setting (NMIP4Config *self, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip4_config_create_setting (const NMIP4Config *self);
void nm_ip4_config_merge (NMIP4Config *dst, const NMIP4Config *src, NMIPConfigMergeFlags merge_flags);
void nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src);
void nm_ip4_config_intersect (NMIP4Config *dst, const NMIP4Config *src);
gboolean nm_ip4_config_replace (NMIP4Config *dst, const NMIP4Config *src, gboolean *relevant_changes);
gboolean nm_ip4_config_destination_is_direct (const NMIP4Config *config, guint32 dest, guint8 plen);
void nm_ip4_config_dump (const NMIP4Config *config, const char *detail);
gboolean nm_ip4_config_destination_is_direct (const NMIP4Config *self, guint32 dest, guint8 plen);
void nm_ip4_config_dump (const NMIP4Config *self, const char *detail);
void nm_ip4_config_set_never_default (NMIP4Config *config, gboolean never_default);
gboolean nm_ip4_config_get_never_default (const NMIP4Config *config);
void nm_ip4_config_set_gateway (NMIP4Config *config, guint32 gateway);
void nm_ip4_config_unset_gateway (NMIP4Config *config);
gboolean nm_ip4_config_has_gateway (const NMIP4Config *config);
guint32 nm_ip4_config_get_gateway (const NMIP4Config *config);
gint64 nm_ip4_config_get_route_metric (const NMIP4Config *config);
void nm_ip4_config_set_never_default (NMIP4Config *self, gboolean never_default);
gboolean nm_ip4_config_get_never_default (const NMIP4Config *self);
void nm_ip4_config_set_gateway (NMIP4Config *self, guint32 gateway);
void nm_ip4_config_unset_gateway (NMIP4Config *self);
gboolean nm_ip4_config_has_gateway (const NMIP4Config *self);
guint32 nm_ip4_config_get_gateway (const NMIP4Config *self);
gint64 nm_ip4_config_get_route_metric (const NMIP4Config *self);
void nm_ip4_config_reset_addresses (NMIP4Config *config);
void nm_ip4_config_add_address (NMIP4Config *config, const NMPlatformIP4Address *address);
void nm_ip4_config_del_address (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_addresses (const NMIP4Config *config);
const NMPlatformIP4Address *nm_ip4_config_get_address (const NMIP4Config *config, guint i);
gboolean nm_ip4_config_address_exists (const NMIP4Config *config, const NMPlatformIP4Address *address);
const NMDedupMultiHeadEntry *nm_ip4_config_lookup_addresses (const NMIP4Config *self);
void nm_ip4_config_reset_addresses (NMIP4Config *self);
void nm_ip4_config_add_address (NMIP4Config *self, const NMPlatformIP4Address *address);
void _nmtst_nm_ip4_config_del_address (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_addresses (const NMIP4Config *self);
const NMPlatformIP4Address *nm_ip4_config_get_first_address (const NMIP4Config *self);
const NMPlatformIP4Address *_nmtst_nm_ip4_config_get_address (const NMIP4Config *self, guint i);
gboolean nm_ip4_config_address_exists (const NMIP4Config *self, const NMPlatformIP4Address *address);
void nm_ip4_config_reset_routes (NMIP4Config *config);
void nm_ip4_config_add_route (NMIP4Config *config, const NMPlatformIP4Route *route);
void _nmtst_nm_ip4_config_del_route (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_routes (const NMIP4Config *config);
const NMPlatformIP4Route *_nmtst_nm_ip4_config_get_route (const NMIP4Config *config, guint i);
const NMDedupMultiHeadEntry *nm_ip4_config_lookup_routes (const NMIP4Config *self);
void nm_ip4_config_reset_routes (NMIP4Config *self);
void nm_ip4_config_add_route (NMIP4Config *self, const NMPlatformIP4Route *route);
void _nmtst_nm_ip4_config_del_route (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_routes (const NMIP4Config *self);
const NMPlatformIP4Route *_nmtst_nm_ip4_config_get_route (const NMIP4Config *self, guint i);
const NMPlatformIP4Route *nm_ip4_config_get_direct_route_for_host (const NMIP4Config *config, guint32 host);
const NMPlatformIP4Route *nm_ip4_config_get_direct_route_for_host (const NMIP4Config *self, guint32 host);
void nm_ip4_config_reset_nameservers (NMIP4Config *config);
void nm_ip4_config_add_nameserver (NMIP4Config *config, guint32 nameserver);
void nm_ip4_config_del_nameserver (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_nameservers (const NMIP4Config *config);
guint32 nm_ip4_config_get_nameserver (const NMIP4Config *config, guint i);
void nm_ip4_config_reset_nameservers (NMIP4Config *self);
void nm_ip4_config_add_nameserver (NMIP4Config *self, guint32 nameserver);
void nm_ip4_config_del_nameserver (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_nameservers (const NMIP4Config *self);
guint32 nm_ip4_config_get_nameserver (const NMIP4Config *self, guint i);
void nm_ip4_config_reset_domains (NMIP4Config *config);
void nm_ip4_config_add_domain (NMIP4Config *config, const char *domain);
void nm_ip4_config_del_domain (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_domains (const NMIP4Config *config);
const char * nm_ip4_config_get_domain (const NMIP4Config *config, guint i);
void nm_ip4_config_reset_domains (NMIP4Config *self);
void nm_ip4_config_add_domain (NMIP4Config *self, const char *domain);
void nm_ip4_config_del_domain (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_domains (const NMIP4Config *self);
const char * nm_ip4_config_get_domain (const NMIP4Config *self, guint i);
void nm_ip4_config_reset_searches (NMIP4Config *config);
void nm_ip4_config_add_search (NMIP4Config *config, const char *search);
void nm_ip4_config_del_search (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_searches (const NMIP4Config *config);
const char * nm_ip4_config_get_search (const NMIP4Config *config, guint i);
void nm_ip4_config_reset_searches (NMIP4Config *self);
void nm_ip4_config_add_search (NMIP4Config *self, const char *search);
void nm_ip4_config_del_search (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_searches (const NMIP4Config *self);
const char * nm_ip4_config_get_search (const NMIP4Config *self, guint i);
void nm_ip4_config_reset_dns_options (NMIP4Config *config);
void nm_ip4_config_add_dns_option (NMIP4Config *config, const char *option);
void nm_ip4_config_del_dns_option (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_dns_options (const NMIP4Config *config);
const char * nm_ip4_config_get_dns_option (const NMIP4Config *config, guint i);
void nm_ip4_config_reset_dns_options (NMIP4Config *self);
void nm_ip4_config_add_dns_option (NMIP4Config *self, const char *option);
void nm_ip4_config_del_dns_option (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_dns_options (const NMIP4Config *self);
const char * nm_ip4_config_get_dns_option (const NMIP4Config *self, guint i);
void nm_ip4_config_set_dns_priority (NMIP4Config *config, gint priority);
gint nm_ip4_config_get_dns_priority (const NMIP4Config *config);
void nm_ip4_config_set_dns_priority (NMIP4Config *self, gint priority);
gint nm_ip4_config_get_dns_priority (const NMIP4Config *self);
void nm_ip4_config_set_mss (NMIP4Config *config, guint32 mss);
guint32 nm_ip4_config_get_mss (const NMIP4Config *config);
void nm_ip4_config_set_mss (NMIP4Config *self, guint32 mss);
guint32 nm_ip4_config_get_mss (const NMIP4Config *self);
void nm_ip4_config_reset_nis_servers (NMIP4Config *config);
void nm_ip4_config_add_nis_server (NMIP4Config *config, guint32 nis);
void nm_ip4_config_del_nis_server (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_nis_servers (const NMIP4Config *config);
guint32 nm_ip4_config_get_nis_server (const NMIP4Config *config, guint i);
void nm_ip4_config_set_nis_domain (NMIP4Config *config, const char *domain);
const char * nm_ip4_config_get_nis_domain (const NMIP4Config *config);
void nm_ip4_config_reset_nis_servers (NMIP4Config *self);
void nm_ip4_config_add_nis_server (NMIP4Config *self, guint32 nis);
void nm_ip4_config_del_nis_server (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_nis_servers (const NMIP4Config *self);
guint32 nm_ip4_config_get_nis_server (const NMIP4Config *self, guint i);
void nm_ip4_config_set_nis_domain (NMIP4Config *self, const char *domain);
const char * nm_ip4_config_get_nis_domain (const NMIP4Config *self);
void nm_ip4_config_reset_wins (NMIP4Config *config);
void nm_ip4_config_add_wins (NMIP4Config *config, guint32 wins);
void nm_ip4_config_del_wins (NMIP4Config *config, guint i);
guint nm_ip4_config_get_num_wins (const NMIP4Config *config);
guint32 nm_ip4_config_get_wins (const NMIP4Config *config, guint i);
void nm_ip4_config_reset_wins (NMIP4Config *self);
void nm_ip4_config_add_wins (NMIP4Config *self, guint32 wins);
void nm_ip4_config_del_wins (NMIP4Config *self, guint i);
guint nm_ip4_config_get_num_wins (const NMIP4Config *self);
guint32 nm_ip4_config_get_wins (const NMIP4Config *self, guint i);
void nm_ip4_config_set_mtu (NMIP4Config *config, guint32 mtu, NMIPConfigSource source);
guint32 nm_ip4_config_get_mtu (const NMIP4Config *config);
NMIPConfigSource nm_ip4_config_get_mtu_source (const NMIP4Config *config);
void nm_ip4_config_set_mtu (NMIP4Config *self, guint32 mtu, NMIPConfigSource source);
guint32 nm_ip4_config_get_mtu (const NMIP4Config *self);
NMIPConfigSource nm_ip4_config_get_mtu_source (const NMIP4Config *self);
void nm_ip4_config_set_metered (NMIP4Config *config, gboolean metered);
gboolean nm_ip4_config_get_metered (const NMIP4Config *config);
void nm_ip4_config_set_metered (NMIP4Config *self, gboolean metered);
gboolean nm_ip4_config_get_metered (const NMIP4Config *self);
void nm_ip4_config_hash (const NMIP4Config *config, GChecksum *sum, gboolean dns_only);
void nm_ip4_config_hash (const NMIP4Config *self, GChecksum *sum, gboolean dns_only);
gboolean nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b);
/*****************************************************************************/

File diff suppressed because it is too large Load diff

View file

@ -27,15 +27,47 @@
#include "nm-setting-ip6-config.h"
#include "nm-utils/nm-dedup-multi.h"
#include "platform/nmp-object.h"
/*****************************************************************************/
void nm_ip6_config_iter_ip6_route_init (NMDedupMultiIter *iter, const NMIP6Config *self);
gboolean nm_ip6_config_iter_ip6_route_next (NMDedupMultiIter *iter, const NMPlatformIP6Route **out_route);
void nm_ip_config_iter_ip6_address_init (NMDedupMultiIter *iter, const NMIP6Config *self);
void nm_ip_config_iter_ip6_route_init (NMDedupMultiIter *iter, const NMIP6Config *self);
#define nm_ip6_config_iter_ip6_route_for_each(iter, self, route) \
for (nm_ip6_config_iter_ip6_route_init ((iter), (self)); \
nm_ip6_config_iter_ip6_route_next ((iter), (route)); \
static inline gboolean
nm_ip_config_iter_ip6_address_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP6Address **out_address)
{
gboolean has_next;
g_return_val_if_fail (out_address, FALSE);
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (has_next)
*out_address = NMP_OBJECT_CAST_IP6_ADDRESS (ipconf_iter->current->obj);
return has_next;
}
static inline gboolean
nm_ip_config_iter_ip6_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatformIP6Route **out_route)
{
gboolean has_next;
g_return_val_if_fail (out_route, FALSE);
has_next = nm_dedup_multi_iter_next (ipconf_iter);
if (has_next)
*out_route = NMP_OBJECT_CAST_IP6_ROUTE (ipconf_iter->current->obj);
return has_next;
}
#define nm_ip_config_iter_ip6_address_for_each(iter, self, address) \
for (*(address) = NULL, nm_ip_config_iter_ip6_address_init ((iter), (self)); \
nm_ip_config_iter_ip6_address_next ((iter), (address)); \
)
#define nm_ip_config_iter_ip6_route_for_each(iter, self, route) \
for (*(route) = NULL, nm_ip_config_iter_ip6_route_init ((iter), (self)); \
nm_ip_config_iter_ip6_route_next ((iter), (route)); \
)
/*****************************************************************************/
@ -73,89 +105,94 @@ GType nm_ip6_config_get_type (void);
NMIP6Config * nm_ip6_config_new (struct _NMDedupMultiIndex *multi_idx, int ifindex);
NMIP6Config * nm_ip6_config_new_cloned (const NMIP6Config *src);
int nm_ip6_config_get_ifindex (const NMIP6Config *config);
int nm_ip6_config_get_ifindex (const NMIP6Config *self);
struct _NMDedupMultiIndex *nm_ip6_config_get_multi_idx (const NMIP6Config *self);
NMIP6Config *nm_ip6_config_capture (struct _NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex,
gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary);
gboolean nm_ip6_config_commit (const NMIP6Config *config,
gboolean nm_ip6_config_commit (const NMIP6Config *self,
NMPlatform *platform,
NMRouteManager *route_manager,
int ifindex,
gboolean routes_full_sync);
void nm_ip6_config_merge_setting (NMIP6Config *config, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip6_config_create_setting (const NMIP6Config *config);
void nm_ip6_config_merge_setting (NMIP6Config *self, NMSettingIPConfig *setting, guint32 default_route_metric);
NMSetting *nm_ip6_config_create_setting (const NMIP6Config *self);
void nm_ip6_config_merge (NMIP6Config *dst, const NMIP6Config *src, NMIPConfigMergeFlags merge_flags);
void nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src);
void nm_ip6_config_intersect (NMIP6Config *dst, const NMIP6Config *src);
gboolean nm_ip6_config_replace (NMIP6Config *dst, const NMIP6Config *src, gboolean *relevant_changes);
int nm_ip6_config_destination_is_direct (const NMIP6Config *config, const struct in6_addr *dest, guint8 plen);
void nm_ip6_config_dump (const NMIP6Config *config, const char *detail);
int nm_ip6_config_destination_is_direct (const NMIP6Config *self, const struct in6_addr *dest, guint8 plen);
void nm_ip6_config_dump (const NMIP6Config *self, const char *detail);
void nm_ip6_config_set_never_default (NMIP6Config *config, gboolean never_default);
gboolean nm_ip6_config_get_never_default (const NMIP6Config *config);
void nm_ip6_config_set_gateway (NMIP6Config *config, const struct in6_addr *);
const struct in6_addr *nm_ip6_config_get_gateway (const NMIP6Config *config);
gint64 nm_ip6_config_get_route_metric (const NMIP6Config *config);
void nm_ip6_config_set_never_default (NMIP6Config *self, gboolean never_default);
gboolean nm_ip6_config_get_never_default (const NMIP6Config *self);
void nm_ip6_config_set_gateway (NMIP6Config *self, const struct in6_addr *);
const struct in6_addr *nm_ip6_config_get_gateway (const NMIP6Config *self);
gint64 nm_ip6_config_get_route_metric (const NMIP6Config *self);
void nm_ip6_config_reset_addresses (NMIP6Config *config);
void nm_ip6_config_add_address (NMIP6Config *config, const NMPlatformIP6Address *address);
void nm_ip6_config_del_address (NMIP6Config *config, guint i);
guint nm_ip6_config_get_num_addresses (const NMIP6Config *config);
const NMPlatformIP6Address *nm_ip6_config_get_address (const NMIP6Config *config, guint i);
const NMPlatformIP6Address *nm_ip6_config_get_address_first_nontentative (const NMIP6Config *config, gboolean linklocal);
gboolean nm_ip6_config_address_exists (const NMIP6Config *config, const NMPlatformIP6Address *address);
gboolean nm_ip6_config_addresses_sort (NMIP6Config *config);
const NMDedupMultiHeadEntry *nm_ip6_config_lookup_addresses (const NMIP6Config *self);
void nm_ip6_config_reset_addresses (NMIP6Config *self);
void nm_ip6_config_add_address (NMIP6Config *self, const NMPlatformIP6Address *address);
void _nmtst_nm_ip6_config_del_address (NMIP6Config *self, guint i);
guint nm_ip6_config_get_num_addresses (const NMIP6Config *self);
const NMPlatformIP6Address *nm_ip6_config_get_first_address (const NMIP6Config *self);
const NMPlatformIP6Address *_nmtst_nm_ip6_config_get_address (const NMIP6Config *self, guint i);
const NMPlatformIP6Address *nm_ip6_config_get_address_first_nontentative (const NMIP6Config *self, gboolean linklocal);
gboolean nm_ip6_config_address_exists (const NMIP6Config *self, const NMPlatformIP6Address *address);
const NMPlatformIP6Address *nm_ip6_config_lookup_address (const NMIP6Config *self,
const struct in6_addr *addr);
gboolean _nmtst_nm_ip6_config_addresses_sort (NMIP6Config *self);
gboolean nm_ip6_config_has_any_dad_pending (const NMIP6Config *self,
const NMIP6Config *candidates);
void nm_ip6_config_reset_routes (NMIP6Config *config);
void nm_ip6_config_add_route (NMIP6Config *config, const NMPlatformIP6Route *route);
void _nmtst_ip6_config_del_route (NMIP6Config *config, guint i);
guint nm_ip6_config_get_num_routes (const NMIP6Config *config);
const NMPlatformIP6Route *_nmtst_ip6_config_get_route (const NMIP6Config *config, guint i);
const NMDedupMultiHeadEntry *nm_ip6_config_lookup_routes (const NMIP6Config *self);
void nm_ip6_config_reset_routes (NMIP6Config *self);
void nm_ip6_config_add_route (NMIP6Config *self, const NMPlatformIP6Route *route);
void _nmtst_ip6_config_del_route (NMIP6Config *self, guint i);
guint nm_ip6_config_get_num_routes (const NMIP6Config *self);
const NMPlatformIP6Route *_nmtst_ip6_config_get_route (const NMIP6Config *self, guint i);
const NMPlatformIP6Route *nm_ip6_config_get_direct_route_for_host (const NMIP6Config *config, const struct in6_addr *host);
const NMPlatformIP6Address *nm_ip6_config_get_subnet_for_host (const NMIP6Config *config, const struct in6_addr *host);
const NMPlatformIP6Route *nm_ip6_config_get_direct_route_for_host (const NMIP6Config *self, const struct in6_addr *host);
const NMPlatformIP6Address *nm_ip6_config_get_subnet_for_host (const NMIP6Config *self, const struct in6_addr *host);
void nm_ip6_config_reset_nameservers (NMIP6Config *config);
void nm_ip6_config_add_nameserver (NMIP6Config *config, const struct in6_addr *nameserver);
void nm_ip6_config_del_nameserver (NMIP6Config *config, guint i);
guint nm_ip6_config_get_num_nameservers (const NMIP6Config *config);
const struct in6_addr *nm_ip6_config_get_nameserver (const NMIP6Config *config, guint i);
void nm_ip6_config_reset_nameservers (NMIP6Config *self);
void nm_ip6_config_add_nameserver (NMIP6Config *self, const struct in6_addr *nameserver);
void nm_ip6_config_del_nameserver (NMIP6Config *self, guint i);
guint nm_ip6_config_get_num_nameservers (const NMIP6Config *self);
const struct in6_addr *nm_ip6_config_get_nameserver (const NMIP6Config *self, guint i);
void nm_ip6_config_reset_domains (NMIP6Config *config);
void nm_ip6_config_add_domain (NMIP6Config *config, const char *domain);
void nm_ip6_config_del_domain (NMIP6Config *config, guint i);
guint nm_ip6_config_get_num_domains (const NMIP6Config *config);
const char * nm_ip6_config_get_domain (const NMIP6Config *config, guint i);
void nm_ip6_config_reset_domains (NMIP6Config *self);
void nm_ip6_config_add_domain (NMIP6Config *self, const char *domain);
void nm_ip6_config_del_domain (NMIP6Config *self, guint i);
guint nm_ip6_config_get_num_domains (const NMIP6Config *self);
const char * nm_ip6_config_get_domain (const NMIP6Config *self, guint i);
void nm_ip6_config_reset_searches (NMIP6Config *config);
void nm_ip6_config_add_search (NMIP6Config *config, const char *search);
void nm_ip6_config_del_search (NMIP6Config *config, guint i);
guint nm_ip6_config_get_num_searches (const NMIP6Config *config);
const char * nm_ip6_config_get_search (const NMIP6Config *config, guint i);
void nm_ip6_config_reset_searches (NMIP6Config *self);
void nm_ip6_config_add_search (NMIP6Config *self, const char *search);
void nm_ip6_config_del_search (NMIP6Config *self, guint i);
guint nm_ip6_config_get_num_searches (const NMIP6Config *self);
const char * nm_ip6_config_get_search (const NMIP6Config *self, guint i);
void nm_ip6_config_reset_dns_options (NMIP6Config *config);
void nm_ip6_config_add_dns_option (NMIP6Config *config, const char *option);
void nm_ip6_config_del_dns_option (NMIP6Config *config, guint i);
guint nm_ip6_config_get_num_dns_options (const NMIP6Config *config);
const char * nm_ip6_config_get_dns_option (const NMIP6Config *config, guint i);
void nm_ip6_config_reset_dns_options (NMIP6Config *self);
void nm_ip6_config_add_dns_option (NMIP6Config *self, const char *option);
void nm_ip6_config_del_dns_option (NMIP6Config *self, guint i);
guint nm_ip6_config_get_num_dns_options (const NMIP6Config *self);
const char * nm_ip6_config_get_dns_option (const NMIP6Config *self, guint i);
void nm_ip6_config_set_dns_priority (NMIP6Config *config, gint priority);
gint nm_ip6_config_get_dns_priority (const NMIP6Config *config);
void nm_ip6_config_set_dns_priority (NMIP6Config *self, gint priority);
gint nm_ip6_config_get_dns_priority (const NMIP6Config *self);
void nm_ip6_config_set_mss (NMIP6Config *config, guint32 mss);
guint32 nm_ip6_config_get_mss (const NMIP6Config *config);
void nm_ip6_config_set_mss (NMIP6Config *self, guint32 mss);
guint32 nm_ip6_config_get_mss (const NMIP6Config *self);
void nm_ip6_config_hash (const NMIP6Config *config, GChecksum *sum, gboolean dns_only);
void nm_ip6_config_hash (const NMIP6Config *self, GChecksum *sum, gboolean dns_only);
gboolean nm_ip6_config_equal (const NMIP6Config *a, const NMIP6Config *b);
void nm_ip6_config_set_privacy (NMIP6Config *config, NMSettingIP6ConfigPrivacy privacy);
void nm_ip6_config_set_privacy (NMIP6Config *self, NMSettingIP6ConfigPrivacy privacy);
/*****************************************************************************/
/* Testing-only functions */

View file

@ -170,6 +170,7 @@ get_ip4_domains (GPtrArray *domains, NMIP4Config *ip4)
{
NMDedupMultiIter ipconf_iter;
char *cidr;
const NMPlatformIP4Address *address;
const NMPlatformIP4Route *routes;
guint i;
@ -182,16 +183,15 @@ get_ip4_domains (GPtrArray *domains, NMIP4Config *ip4)
g_ptr_array_add (domains, g_strdup (nm_ip4_config_get_domain (ip4, i)));
/* Add addresses and routes in CIDR form */
for (i = 0; i < nm_ip4_config_get_num_addresses (ip4); i++) {
const NMPlatformIP4Address *address = nm_ip4_config_get_address (ip4, i);
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &address) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet4_ntop (address->address, NULL),
address->plen);
g_ptr_array_add (domains, cidr);
}
nm_ip4_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &routes) {
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &routes) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet4_ntop (routes->network, NULL),
routes->plen);
@ -204,6 +204,7 @@ get_ip6_domains (GPtrArray *domains, NMIP6Config *ip6)
{
NMDedupMultiIter ipconf_iter;
char *cidr;
const NMPlatformIP6Address *address;
const NMPlatformIP6Route *routes;
guint i;
@ -216,16 +217,14 @@ get_ip6_domains (GPtrArray *domains, NMIP6Config *ip6)
g_ptr_array_add (domains, g_strdup (nm_ip6_config_get_domain (ip6, i)));
/* Add addresses and routes in CIDR form */
for (i = 0; i < nm_ip6_config_get_num_addresses (ip6); i++) {
const NMPlatformIP6Address *address = nm_ip6_config_get_address (ip6, i);
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &address) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet6_ntop (&address->address, NULL),
address->plen);
g_ptr_array_add (domains, cidr);
}
nm_ip6_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &routes) {
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &routes) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet6_ntop (&routes->network, NULL),
routes->plen);

View file

@ -605,6 +605,8 @@ update_system_hostname (NMPolicy *self, NMDevice *best4, NMDevice *best6, const
NMIP4Config *ip4_config;
NMIP6Config *ip6_config;
gboolean external_hostname = FALSE;
const NMPlatformIP4Address *addr4;
const NMPlatformIP6Address *addr6;
g_return_if_fail (self != NULL);
@ -746,17 +748,13 @@ update_system_hostname (NMPolicy *self, NMDevice *best4, NMDevice *best6, const
ip4_config = best4 ? nm_device_get_ip4_config (best4) : NULL;
ip6_config = best6 ? nm_device_get_ip6_config (best6) : NULL;
if (ip4_config && nm_ip4_config_get_num_addresses (ip4_config) > 0) {
const NMPlatformIP4Address *addr4;
addr4 = nm_ip4_config_get_address (ip4_config, 0);
if ( ip4_config
&& (addr4 = nm_ip4_config_get_first_address (ip4_config))) {
g_clear_object (&priv->lookup.addr);
priv->lookup.addr = g_inet_address_new_from_bytes ((guint8 *) &addr4->address,
G_SOCKET_FAMILY_IPV4);
} else if (ip6_config && nm_ip6_config_get_num_addresses (ip6_config) > 0) {
const NMPlatformIP6Address *addr6;
addr6 = nm_ip6_config_get_address (ip6_config, 0);
} else if ( ip6_config
&& (addr6 = nm_ip6_config_get_first_address (ip6_config))) {
g_clear_object (&priv->lookup.addr);
priv->lookup.addr = g_inet_address_new_from_bytes ((guint8 *) &addr6->address,
G_SOCKET_FAMILY_IPV6);

View file

@ -33,7 +33,7 @@
* up, we delete it. */
#define IP4_DEVICE_ROUTES_WAIT_TIME_NS (NM_UTILS_NS_PER_SECOND / 2)
#define IP4_DEVICE_ROUTES_GC_INTERVAL_SEC (IP4_DEVICE_ROUTES_WAIT_TIME_NS * 2)
#define IP4_DEVICE_ROUTES_GC_INTERVAL_MSEC ((IP4_DEVICE_ROUTES_WAIT_TIME_NS / 1000000) * 3)
/*****************************************************************************/
@ -58,7 +58,8 @@ typedef struct {
NMRouteManager *self;
gint64 scheduled_at_ns;
guint idle_id;
NMPObject *obj;
const NMPObject *obj;
const NMPObject *obj_cached;
} IP4DeviceRoutePurgeEntry;
/*****************************************************************************/
@ -490,8 +491,10 @@ _get_next_plat_route (const RouteIndex *index, gboolean start_at_zero, guint *cu
++*cur_idx;
/* get next route from the platform index. */
if (*cur_idx < index->len)
if (*cur_idx < index->len) {
nm_assert (NMP_OBJECT_UP_CAST (index->entries[*cur_idx]));
return index->entries[*cur_idx];
}
*cur_idx = index->len;
return NULL;
}
@ -649,7 +652,8 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const
* in platform. Delete it. */
_LOGt (vtable->vt->addr_family, "%3d: platform rt-rm #%u - %s", ifindex, i_plat_routes,
vtable->vt->route_to_string (cur_plat_route, NULL, 0));
vtable->vt->route_delete (priv->platform, ifindex, cur_plat_route);
nm_assert (ifindex == cur_plat_route->rx.ifindex);
nm_platform_ip_route_delete (priv->platform, NMP_OBJECT_UP_CAST (cur_plat_route));
}
}
}
@ -796,7 +800,7 @@ next:
while (cur_plat_route) {
int route_dest_cmp_result = 0;
g_assert (cur_plat_route->rx.ifindex == ifindex);
nm_assert (cur_plat_route->rx.ifindex == ifindex);
_LOGt (vtable->vt->addr_family, "%3d: platform rt #%u - %s", ifindex, i_plat_routes, vtable->vt->route_to_string (cur_plat_route, NULL, 0));
@ -816,8 +820,10 @@ next:
/* if @cur_ipx_route is not equal to @plat_route, the route must be deleted. */
if ( !cur_ipx_route
|| route_dest_cmp_result != 0
|| *p_effective_metric != cur_plat_route->rx.metric)
vtable->vt->route_delete (priv->platform, ifindex, cur_plat_route);
|| *p_effective_metric != cur_plat_route->rx.metric) {
nm_assert (ifindex == cur_plat_route->rx.ifindex);
nm_platform_ip_route_delete (priv->platform, NMP_OBJECT_UP_CAST (cur_plat_route));
}
cur_plat_route = _get_next_plat_route (plat_routes_idx, FALSE, &i_plat_routes);
}
@ -1074,6 +1080,7 @@ _ip4_device_routes_purge_entry_create (NMRouteManager *self, const NMPlatformIP4
entry->scheduled_at_ns = now_ns;
entry->idle_id = 0;
entry->obj = nmp_object_new (NMP_OBJECT_TYPE_IP4_ROUTE, (NMPlatformObject *) route);
entry->obj_cached = NULL;
return entry;
}
@ -1081,6 +1088,7 @@ static void
_ip4_device_routes_purge_entry_free (IP4DeviceRoutePurgeEntry *entry)
{
nmp_object_unref (entry->obj);
nmp_object_unref (entry->obj_cached);
nm_clear_g_source (&entry->idle_id);
g_slice_free (IP4DeviceRoutePurgeEntry, entry);
}
@ -1100,13 +1108,9 @@ _ip4_device_routes_idle_cb (IP4DeviceRoutePurgeEntry *entry)
return G_SOURCE_REMOVE;
}
_LOGt (vtable_v4.vt->addr_family, "device-route: delete %s", nmp_object_to_string (entry->obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
_LOGt (vtable_v4.vt->addr_family, "device-route: delete %s", nmp_object_to_string (entry->obj_cached, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
nm_platform_ip4_route_delete (priv->platform,
entry->obj->ip4_route.ifindex,
entry->obj->ip4_route.network,
entry->obj->ip4_route.plen,
entry->obj->ip4_route.metric);
nm_platform_ip_route_delete (priv->platform, entry->obj_cached);
g_hash_table_remove (priv->ip4_device_routes.entries, entry->obj);
_ip4_device_routes_cancel (self);
@ -1123,12 +1127,9 @@ _ip4_device_routes_ip4_route_changed (NMPlatform *platform,
{
const NMPlatformSignalChangeType change_type = change_type_i;
NMRouteManagerPrivate *priv;
NMPObject obj_needle;
const NMPObject *obj;
IP4DeviceRoutePurgeEntry *entry;
if (change_type == NM_PLATFORM_SIGNAL_REMOVED)
return;
if ( route->rt_source != NM_IP_CONFIG_SOURCE_RTPROT_KERNEL
|| route->metric != 0) {
/* we don't have an automatically created device route at hand. Bail out early. */
@ -1137,8 +1138,9 @@ _ip4_device_routes_ip4_route_changed (NMPlatform *platform,
priv = NM_ROUTE_MANAGER_GET_PRIVATE (self);
entry = g_hash_table_lookup (priv->ip4_device_routes.entries,
nmp_object_stackinit (&obj_needle, NMP_OBJECT_TYPE_IP4_ROUTE, (NMPlatformObject *) route));
obj = NMP_OBJECT_UP_CAST (route);
entry = g_hash_table_lookup (priv->ip4_device_routes.entries, obj);
if (!entry)
return;
@ -1149,6 +1151,15 @@ _ip4_device_routes_ip4_route_changed (NMPlatform *platform,
return;
}
entry->obj_cached = nmp_object_unref (entry->obj_cached);
if (change_type == NM_PLATFORM_SIGNAL_REMOVED) {
if (nm_clear_g_source (&entry->idle_id))
_LOGt (vtable_v4.vt->addr_family, "device-route: unschedule %s", nmp_object_to_string (entry->obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
return;
}
entry->obj_cached = nmp_object_ref (obj);
if (entry->idle_id == 0) {
_LOGt (vtable_v4.vt->addr_family, "device-route: schedule %s", nmp_object_to_string (entry->obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
entry->idle_id = g_idle_add ((GSourceFunc) _ip4_device_routes_idle_cb, entry);
@ -1227,7 +1238,7 @@ nm_route_manager_ip4_route_register_device_route_purge_list (NMRouteManager *sel
}
if (priv->ip4_device_routes.gc_id == 0) {
g_signal_connect (priv->platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (_ip4_device_routes_ip4_route_changed), self);
priv->ip4_device_routes.gc_id = g_timeout_add (IP4_DEVICE_ROUTES_GC_INTERVAL_SEC, (GSourceFunc) _ip4_device_routes_gc, self);
priv->ip4_device_routes.gc_id = g_timeout_add (IP4_DEVICE_ROUTES_GC_INTERVAL_MSEC, (GSourceFunc) _ip4_device_routes_gc, self);
}
}

View file

@ -110,6 +110,7 @@ NM_IS_IP_CONFIG_SOURCE_RTPROT (NMIPConfigSource source)
/* platform */
typedef struct _NMPlatform NMPlatform;
typedef struct _NMPlatformObject NMPlatformObject;
typedef struct _NMPlatformIP4Address NMPlatformIP4Address;
typedef struct _NMPlatformIP4Route NMPlatformIP4Route;
typedef struct _NMPlatformIP6Address NMPlatformIP6Address;

View file

@ -106,9 +106,7 @@ static gboolean ipx_address_delete (NMPlatform *platform,
static gboolean ipx_route_delete (NMPlatform *platform,
int addr_family,
int ifindex,
gconstpointer network,
const guint8 *plen,
const guint32 *metric);
const NMPObject *obj);
static gboolean ip6_address_add (NMPlatform *platform,
int ifindex,
@ -401,8 +399,8 @@ link_delete (NMPlatform *platform, int ifindex)
/* Remove addresses and routes which belong to the deleted interface */
ipx_address_delete (platform, AF_INET, ifindex, NULL, NULL, NULL);
ipx_address_delete (platform, AF_INET6, ifindex, NULL, NULL, NULL);
ipx_route_delete (platform, AF_INET, ifindex, NULL, NULL, NULL);
ipx_route_delete (platform, AF_INET6, ifindex, NULL, NULL, NULL);
ipx_route_delete (platform, AF_INET, ifindex, NULL);
ipx_route_delete (platform, AF_INET6, ifindex, NULL);
nm_platform_cache_update_emit_signal (platform,
cache_op,
@ -1115,42 +1113,54 @@ static gboolean
ipx_route_delete (NMPlatform *platform,
int addr_family,
int ifindex,
gconstpointer network,
const guint8 *plen,
const guint32 *metric)
const NMPObject *obj)
{
gs_unref_ptrarray GPtrArray *objs = g_ptr_array_new_with_free_func ((GDestroyNotify) nmp_object_unref);
NMDedupMultiIter iter;
const NMPObject *o = NULL;
guint i;
NMPObjectType obj_type;
g_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6));
if (addr_family == AF_UNSPEC) {
g_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE,
NMP_OBJECT_TYPE_IP6_ROUTE));
g_assert (ifindex == -1);
ifindex = obj->object.ifindex;
obj_type = NMP_OBJECT_GET_TYPE (obj);
} else {
g_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6));
g_assert (!obj);
g_assert (ifindex > 0);
obj_type = addr_family == AF_INET
? NMP_OBJECT_TYPE_IP4_ROUTE
: NMP_OBJECT_TYPE_IP6_ROUTE;
}
nmp_cache_iter_for_each (&iter,
nm_platform_lookup_addrroute (platform,
addr_family == AF_INET
? NMP_OBJECT_TYPE_IP4_ROUTE
: NMP_OBJECT_TYPE_IP6_ROUTE,
0),
obj_type,
ifindex),
&o) {
const NMPObject *obj_old = NULL;
if (addr_family == AF_INET) {
const NMPlatformIP4Route *route = NMP_OBJECT_CAST_IP4_ROUTE (o);
if (obj) {
if (obj_type == NMP_OBJECT_TYPE_IP4_ROUTE) {
const NMPlatformIP4Route *route = NMP_OBJECT_CAST_IP4_ROUTE (o);
const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE (obj);
if ( route->ifindex != ifindex
|| (network && route->network != *((guint32 *) network))
|| (plen && route->plen != *plen)
|| (metric && route->metric != *metric))
continue;
} else {
const NMPlatformIP6Route *route = NMP_OBJECT_CAST_IP6_ROUTE (o);
if ( route->network != r->network
|| route->plen != r->plen
|| route->metric != r->metric)
continue;
} else {
const NMPlatformIP6Route *route = NMP_OBJECT_CAST_IP6_ROUTE (o);
const NMPlatformIP6Route *r = NMP_OBJECT_CAST_IP6_ROUTE (obj);
if ( route->ifindex != ifindex
|| (network && !IN6_ARE_ADDR_EQUAL (&route->network, network))
|| (plen && route->plen != *plen)
|| (metric && route->metric != *metric))
continue;
if ( !IN6_ARE_ADDR_EQUAL (&route->network, &r->network)
|| route->plen != r->plen
|| route->metric != r->metric)
continue;
}
}
if (nmp_cache_remove (nm_platform_get_cache (platform),
@ -1172,16 +1182,13 @@ ipx_route_delete (NMPlatform *platform,
}
static gboolean
ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
ip_route_delete (NMPlatform *platform, const NMPObject *obj)
{
return ipx_route_delete (platform, AF_INET, ifindex, &network, &plen, &metric);
}
g_assert (NM_IS_FAKE_PLATFORM (platform));
g_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE,
NMP_OBJECT_TYPE_IP6_ROUTE));
static gboolean
ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, guint8 plen, guint32 metric)
{
metric = nm_utils_ip6_route_metric_normalize (metric);
return ipx_route_delete (platform, AF_INET6, ifindex, &network, &plen, &metric);
return ipx_route_delete (platform, AF_UNSPEC, -1, obj);
}
static gboolean
@ -1391,6 +1398,5 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->ip4_route_add = ip4_route_add;
platform_class->ip6_route_add = ip6_route_add;
platform_class->ip4_route_delete = ip4_route_delete;
platform_class->ip6_route_delete = ip6_route_delete;
platform_class->ip_route_delete = ip_route_delete;
}

View file

@ -2418,19 +2418,14 @@ nla_put_failure:
static struct nl_msg *
_nl_msg_new_route (int nlmsg_type,
int nlmsg_flags,
int family,
int ifindex,
const NMPObject *obj,
NMIPConfigSource source,
unsigned char scope,
gconstpointer network,
guint8 plen,
gconstpointer gateway,
guint32 metric,
guint32 mss,
gconstpointer pref_src,
gconstpointer src,
guint8 src_plen,
guint8 tos,
guint32 window,
guint32 cwnd,
guint32 initcwnd,
@ -2439,23 +2434,24 @@ _nl_msg_new_route (int nlmsg_type,
guint32 lock)
{
struct nl_msg *msg;
const NMPClass *klass = NMP_OBJECT_GET_CLASS (obj);
gboolean is_v4 = klass->addr_family == AF_INET;
struct rtmsg rtmsg = {
.rtm_family = family,
.rtm_tos = tos,
.rtm_family = klass->addr_family,
.rtm_tos = obj->ip_route.tos,
.rtm_table = RT_TABLE_MAIN, /* omit setting RTA_TABLE attribute */
.rtm_protocol = nmp_utils_ip_config_source_coerce_to_rtprot (source),
.rtm_scope = scope,
.rtm_type = RTN_UNICAST,
.rtm_flags = 0,
.rtm_dst_len = plen,
.rtm_dst_len = obj->ip_route.plen,
.rtm_src_len = src ? src_plen : 0,
};
gsize addr_len;
nm_assert (NM_IN_SET (family, AF_INET, AF_INET6));
nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE));
nm_assert (NM_IN_SET (nlmsg_type, RTM_NEWROUTE, RTM_DELROUTE));
nm_assert (network);
msg = nlmsg_alloc_simple (nlmsg_type, nlmsg_flags);
if (!msg)
@ -2464,14 +2460,19 @@ _nl_msg_new_route (int nlmsg_type,
if (nlmsg_append (msg, &rtmsg, sizeof (rtmsg), NLMSG_ALIGNTO) < 0)
goto nla_put_failure;
addr_len = family == AF_INET ? sizeof (in_addr_t) : sizeof (struct in6_addr);
addr_len = is_v4
? sizeof (in_addr_t)
: sizeof (struct in6_addr);
NLA_PUT (msg, RTA_DST, addr_len, network);
NLA_PUT (msg, RTA_DST, addr_len,
is_v4
? (gconstpointer) &obj->ip4_route.network
: (gconstpointer) &obj->ip6_route.network);
if (src)
NLA_PUT (msg, RTA_SRC, addr_len, src);
NLA_PUT_U32 (msg, RTA_PRIORITY, metric);
NLA_PUT_U32 (msg, RTA_PRIORITY, obj->ip_route.metric);
if (pref_src)
NLA_PUT (msg, RTA_PREFSRC, addr_len, pref_src);
@ -2505,7 +2506,7 @@ _nl_msg_new_route (int nlmsg_type,
if ( gateway
&& memcmp (gateway, &nm_ip_addr_zero, addr_len) != 0)
NLA_PUT (msg, RTA_GATEWAY, addr_len, gateway);
NLA_PUT_U32 (msg, RTA_OIF, ifindex);
NLA_PUT_U32 (msg, RTA_OIF, obj->ip_route.ifindex);
return msg;
@ -4032,7 +4033,7 @@ out:
/* such an object still exists in the cache. To be sure, refetch it (and
* hope it's gone) */
do_request_one_type (platform, NMP_OBJECT_GET_TYPE (obj_id));
return !!nmp_cache_lookup_obj (cache, obj_id);
return !nmp_cache_lookup_obj (cache, obj_id);
}
static WaitForNlResponseResult
@ -5688,86 +5689,78 @@ ip_route_get_lock_flag (NMPlatformIPRoute *route)
static gboolean
ip4_route_add (NMPlatform *platform, const NMPlatformIP4Route *route)
{
NMPObject obj_id;
NMPObject obj;
NMPlatformIP4Route *r;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
in_addr_t network;
network = nm_utils_ip4_address_clear_host_address (route->network, route->plen);
nmp_object_stackinit (&obj, NMP_OBJECT_TYPE_IP4_ROUTE, (const NMPlatformObject *) route);
r = NMP_OBJECT_CAST_IP4_ROUTE (&obj);
r->network = nm_utils_ip4_address_clear_host_address (r->network, r->plen);
/* FIXME: take the scope from route into account */
nlmsg = _nl_msg_new_route (RTM_NEWROUTE,
NLM_F_CREATE | NLM_F_REPLACE,
AF_INET,
route->ifindex,
&obj,
route->rt_source,
route->gateway ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK,
&network,
route->plen,
&route->gateway,
route->metric,
route->mss,
route->pref_src ? &route->pref_src : NULL,
NULL,
0,
route->tos,
route->window,
route->cwnd,
route->initcwnd,
route->initrwnd,
route->mtu,
ip_route_get_lock_flag ((NMPlatformIPRoute *) route));
nmp_object_stackinit_id_ip4_route (&obj_id, route->ifindex, network, route->plen, route->metric);
return do_add_addrroute (platform, &obj_id, nlmsg);
return do_add_addrroute (platform, &obj, nlmsg);
}
static gboolean
ip6_route_add (NMPlatform *platform, const NMPlatformIP6Route *route)
{
NMPObject obj_id;
NMPObject obj;
NMPlatformIP6Route *r;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct in6_addr network;
nm_utils_ip6_address_clear_host_address (&network, &route->network, route->plen);
nmp_object_stackinit (&obj, NMP_OBJECT_TYPE_IP6_ROUTE, (const NMPlatformObject *) route);
r = NMP_OBJECT_CAST_IP6_ROUTE (&obj);
nm_utils_ip6_address_clear_host_address (&r->network, &r->network, r->plen);
/* FIXME: take the scope from route into account */
nlmsg = _nl_msg_new_route (RTM_NEWROUTE,
NLM_F_CREATE | NLM_F_REPLACE,
AF_INET6,
route->ifindex,
&obj,
route->rt_source,
IN6_IS_ADDR_UNSPECIFIED (&route->gateway) ? RT_SCOPE_LINK : RT_SCOPE_UNIVERSE,
&network,
route->plen,
&route->gateway,
route->metric,
route->mss,
!IN6_IS_ADDR_UNSPECIFIED (&route->pref_src) ? &route->pref_src : NULL,
!IN6_IS_ADDR_UNSPECIFIED (&route->src) ? &route->src : NULL,
route->src_plen,
route->tos,
route->window,
route->cwnd,
route->initcwnd,
route->initrwnd,
route->mtu,
ip_route_get_lock_flag ((NMPlatformIPRoute *) route));
nmp_object_stackinit_id_ip6_route (&obj_id, route->ifindex, &network, route->plen, route->metric);
return do_add_addrroute (platform, &obj_id, nlmsg);
return do_add_addrroute (platform, &obj, nlmsg);
}
static gboolean
ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
ip_route_delete (NMPlatform *platform,
const NMPObject *obj)
{
nm_auto_nmpobj const NMPObject *obj_keep_alive = NULL;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
NMPObject obj_id;
network = nm_utils_ip4_address_clear_host_address (network, plen);
nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE,
NMP_OBJECT_TYPE_IP6_ROUTE));
nmp_object_stackinit_id_ip4_route (&obj_id, ifindex, network, plen, metric);
if (!NMP_OBJECT_IS_STACKINIT (obj))
obj_keep_alive = nmp_object_ref (obj);
if (metric == 0) {
if ( NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_IP4_ROUTE
&& obj->ip_route.metric == 0) {
NMPCache *cache = nm_platform_get_cache (platform);
/* Deleting an IPv4 route with metric 0 does not only delete an exectly matching route.
@ -5776,9 +5769,12 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 p
*
* Instead, make sure that we have the most recent state and process all
* delayed actions (including re-reading data from netlink). */
/* FIXME: later, we only want to pass in here @obj instances that originate
* from the cache, and where we know that the route with metric 0 exists. */
delayed_action_handle_all (platform, TRUE);
if (!nmp_cache_lookup_obj (cache, &obj_id)) {
if (!nmp_cache_lookup_obj (cache, obj)) {
/* hmm... we are about to delete an IP4 route with metric 0. We must only
* send the delete request if such a route really exists. Above we refreshed
* the platform cache, still no such route exists.
@ -5786,32 +5782,23 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 p
* Be extra careful and reload the routes. We must be sure that such a
* route doesn't exists, because when we add an IPv4 address, we immediately
* afterwards try to delete the kernel-added device route with metric 0.
* It might be, that we didn't yet get the notification about that route.
*
* FIXME: once our ip4_address_add() is sure that upon return we have
* the latest state from in the platform cache, we might save this
* additional expensive cache-resync. */
* It might be, that we didn't yet get the notification about that route. */
do_request_one_type (platform, NMP_OBJECT_TYPE_IP4_ROUTE);
if (!nmp_cache_lookup_obj (cache, &obj_id))
if (!nmp_cache_lookup_obj (cache, obj))
return TRUE;
}
}
nlmsg = _nl_msg_new_route (RTM_DELROUTE,
0,
AF_INET,
ifindex,
obj,
NM_IP_CONFIG_SOURCE_UNKNOWN,
RT_SCOPE_NOWHERE,
&network,
plen,
NULL,
metric,
0,
NULL,
NULL,
0,
NULL,
NULL,
0,
0,
0,
@ -5821,47 +5808,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 p
0);
if (!nlmsg)
return FALSE;
return do_delete_object (platform, &obj_id, nlmsg);
}
static gboolean
ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, guint8 plen, guint32 metric)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
NMPObject obj_id;
metric = nm_utils_ip6_route_metric_normalize (metric);
nm_utils_ip6_address_clear_host_address (&network, &network, plen);
nlmsg = _nl_msg_new_route (RTM_DELROUTE,
0,
AF_INET6,
ifindex,
NM_IP_CONFIG_SOURCE_UNKNOWN,
RT_SCOPE_NOWHERE,
&network,
plen,
NULL,
metric,
0,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
0,
0);
if (!nlmsg)
return FALSE;
nmp_object_stackinit_id_ip6_route (&obj_id, ifindex, &network, plen, metric);
return do_delete_object (platform, &obj_id, nlmsg);
return do_delete_object (platform, obj, nlmsg);
}
/*****************************************************************************/
@ -6593,8 +6540,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->ip4_route_add = ip4_route_add;
platform_class->ip6_route_add = ip6_route_add;
platform_class->ip4_route_delete = ip4_route_delete;
platform_class->ip6_route_delete = ip6_route_delete;
platform_class->ip_route_delete = ip_route_delete;
platform_class->check_support_kernel_extended_ifa_flags = check_support_kernel_extended_ifa_flags;
platform_class->check_support_user_ipv6ll = check_support_user_ipv6ll;

View file

@ -2831,40 +2831,6 @@ nm_platform_ip6_address_get_peer (const NMPlatformIP6Address *addr)
return &addr->peer_address;
}
static GArray *
ipx_address_get_all (NMPlatform *self, int ifindex, NMPObjectType obj_type)
{
NMPLookup lookup;
nm_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS));
nmp_lookup_init_addrroute (&lookup,
obj_type,
ifindex);
return nmp_cache_lookup_to_array (nmp_cache_lookup (nm_platform_get_cache (self), &lookup),
obj_type,
FALSE /*addresses are always visible. */);
}
GArray *
nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex)
{
_CHECK_SELF (self, klass, NULL);
g_return_val_if_fail (ifindex > 0, NULL);
return ipx_address_get_all (self, ifindex, NMP_OBJECT_TYPE_IP4_ADDRESS);
}
GArray *
nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex)
{
_CHECK_SELF (self, klass, NULL);
g_return_val_if_fail (ifindex > 0, NULL);
return ipx_address_get_all (self, ifindex, NMP_OBJECT_TYPE_IP6_ADDRESS);
}
gboolean
nm_platform_ip4_address_add (NMPlatform *self,
int ifindex,
@ -3004,37 +2970,14 @@ nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr addr
return NMP_OBJECT_CAST_IP6_ADDRESS (obj);
}
static const NMPlatformIP4Address *
array_contains_ip4_address (const GArray *addresses, const NMPlatformIP4Address *address, gint32 now)
{
guint len = addresses ? addresses->len : 0;
guint i;
for (i = 0; i < len; i++) {
const NMPlatformIP4Address *candidate = &g_array_index (addresses, NMPlatformIP4Address, i);
if ( candidate->address == address->address
&& candidate->plen == address->plen
&& ((candidate->peer_address ^ address->peer_address) & nm_utils_ip4_prefix_to_netmask (address->plen)) == 0) {
guint32 lifetime, preferred;
if (nm_utils_lifetime_get (candidate->timestamp, candidate->lifetime, candidate->preferred,
now, &lifetime, &preferred))
return candidate;
}
}
return NULL;
}
static gboolean
array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address *address, gint32 now)
array_contains_ip6_address (const GPtrArray *addresses, const NMPlatformIP6Address *address, gint32 now)
{
guint len = addresses ? addresses->len : 0;
guint i;
for (i = 0; i < len; i++) {
NMPlatformIP6Address *candidate = &g_array_index (addresses, NMPlatformIP6Address, i);
NMPlatformIP6Address *candidate = NMP_OBJECT_CAST_IP6_ADDRESS (addresses->pdata[i]);
if (IN6_ARE_ADDR_EQUAL (&candidate->address, &address->address) && candidate->plen == address->plen) {
guint32 lifetime, preferred;
@ -3049,69 +2992,100 @@ array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address
}
static gboolean
_ptr_inside_ip4_addr_array (const GArray *array, gconstpointer needle)
ip4_addr_subnets_is_plain_address (const GPtrArray *addresses, gconstpointer needle)
{
return needle >= (gconstpointer) &g_array_index (array, const NMPlatformIP4Address, 0)
&& needle < (gconstpointer) &g_array_index (array, const NMPlatformIP4Address, array->len);
return needle >= (gconstpointer) &addresses->pdata[0]
&& needle < (gconstpointer) &addresses->pdata[addresses->len];
}
static const NMPObject **
ip4_addr_subnets_addr_list_get (const GPtrArray *addr_list, guint idx)
{
nm_assert (addr_list);
nm_assert (addr_list->len > 1);
nm_assert (idx < addr_list->len);
nm_assert (addr_list->pdata[idx]);
nm_assert ( !(*((gpointer *) addr_list->pdata[idx]))
|| NMP_OBJECT_CAST_IP4_ADDRESS (*((gpointer *) addr_list->pdata[idx])));
nm_assert (idx == 0 || ip4_addr_subnets_addr_list_get (addr_list, idx - 1));
return addr_list->pdata[idx];
}
static void
ip4_addr_subnets_destroy_index (GHashTable *ht, const GArray *addresses)
ip4_addr_subnets_destroy_index (GHashTable *subnets, const GPtrArray *addresses)
{
GHashTableIter iter;
gpointer p;
g_hash_table_iter_init (&iter, ht);
if (!subnets)
return;
g_hash_table_iter_init (&iter, subnets);
while (g_hash_table_iter_next (&iter, NULL, &p)) {
if (!_ptr_inside_ip4_addr_array (addresses, p)) {
if (!ip4_addr_subnets_is_plain_address (addresses, p))
g_ptr_array_free ((GPtrArray *) p, TRUE);
}
}
g_hash_table_unref (ht);
g_hash_table_unref (subnets);
}
static GHashTable *
ip4_addr_subnets_build_index (const GArray *addresses, gboolean consider_flags)
ip4_addr_subnets_build_index (const GPtrArray *addresses,
gboolean consider_flags,
gboolean full_index)
{
const NMPlatformIP4Address *address;
gpointer p;
GHashTable *subnets;
GPtrArray *ptr;
guint32 net;
guint i;
gint position;
if (!addresses)
return NULL;
nm_assert (addresses && addresses->len);
subnets = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
NULL);
subnets = g_hash_table_new (NULL, NULL);
/* Build a hash table of all addresses per subnet */
for (i = 0; i < addresses->len; i++) {
address = &g_array_index (addresses, const NMPlatformIP4Address, i);
const NMPlatformIP4Address *address;
gpointer p_address;
GPtrArray *addr_list;
guint32 net;
int position;
gpointer p;
if (!addresses->pdata[i])
continue;
p_address = &addresses->pdata[i];
address = NMP_OBJECT_CAST_IP4_ADDRESS (addresses->pdata[i]);
net = address->address & nm_utils_ip4_prefix_to_netmask (address->plen);
if (!g_hash_table_lookup_extended (subnets, GUINT_TO_POINTER (net), NULL, &p)) {
g_hash_table_insert (subnets, GUINT_TO_POINTER (net), (gpointer) address);
g_hash_table_insert (subnets, GUINT_TO_POINTER (net), p_address);
continue;
}
if (_ptr_inside_ip4_addr_array (addresses, p)) {
ptr = g_ptr_array_new ();
g_hash_table_insert (subnets, GUINT_TO_POINTER (net), ptr);
g_ptr_array_add (ptr, p);
} else
ptr = p;
nm_assert (p);
if (!consider_flags || NM_FLAGS_HAS (address->n_ifa_flags, IFA_F_SECONDARY))
position = -1; /* append */
else
position = 0; /* prepend */
if (full_index) {
if (ip4_addr_subnets_is_plain_address (addresses, p)) {
addr_list = g_ptr_array_new ();
g_hash_table_insert (subnets, GUINT_TO_POINTER (net), addr_list);
g_ptr_array_add (addr_list, p);
} else
addr_list = p;
g_ptr_array_insert (ptr, position, (gpointer) address);
if ( !consider_flags
|| NM_FLAGS_HAS (address->n_ifa_flags, IFA_F_SECONDARY))
position = -1; /* append */
else
position = 0; /* prepend */
g_ptr_array_insert (addr_list, position, p_address);
} else {
/* we only care about the primay. No need to track the secondaries
* as a GPtrArray. */
nm_assert (ip4_addr_subnets_is_plain_address (addresses, p));
if ( consider_flags
&& !NM_FLAGS_HAS (address->n_ifa_flags, IFA_F_SECONDARY)) {
g_hash_table_insert (subnets, GUINT_TO_POINTER (net), p_address);
}
}
}
return subnets;
@ -3130,22 +3104,32 @@ ip4_addr_subnets_build_index (const GArray *addresses, gboolean consider_flags)
* Returns: %TRUE if the address is secondary, %FALSE otherwise
*/
static gboolean
ip4_addr_subnets_is_secondary (const NMPlatformIP4Address *address, GHashTable *subnets, const GArray *addresses, GPtrArray **out_addr_list)
ip4_addr_subnets_is_secondary (const NMPObject *address,
GHashTable *subnets,
const GPtrArray *addresses,
const GPtrArray **out_addr_list)
{
GPtrArray *addr_list;
gpointer p;
const NMPlatformIP4Address *a;
const GPtrArray *addr_list;
gconstpointer p;
guint32 net;
const NMPObject **o;
net = address->address & nm_utils_ip4_prefix_to_netmask (address->plen);
a = NMP_OBJECT_CAST_IP4_ADDRESS (address);
net = a->address & nm_utils_ip4_prefix_to_netmask (a->plen);
p = g_hash_table_lookup (subnets, GUINT_TO_POINTER (net));
nm_assert (p);
if (!_ptr_inside_ip4_addr_array (addresses, p)) {
if (!ip4_addr_subnets_is_plain_address (addresses, p)) {
addr_list = p;
nm_assert (addr_list->len > 1);
NM_SET_OUT (out_addr_list, addr_list);
if (addr_list->pdata[0] != address)
o = ip4_addr_subnets_addr_list_get (addr_list, 0);
nm_assert (o && *o);
if (*o != address)
return TRUE;
} else {
nm_assert ((gconstpointer) address == p);
nm_assert (address == *((gconstpointer *) p));
NM_SET_OUT (out_addr_list, NULL);
}
return FALSE;
@ -3155,11 +3139,14 @@ ip4_addr_subnets_is_secondary (const NMPlatformIP4Address *address, GHashTable *
* nm_platform_ip4_address_sync:
* @self: platform instance
* @ifindex: Interface index
* @known_addresses: List of addresses
* @out_added_addresses: (out): (allow-none): if not %NULL, return a #GPtrArray
* with the addresses added. The pointers point into @known_addresses.
* It possibly does not contain all addresses from @known_address because
* some addresses might be expired.
* @known_addresses: List of addresses. The list will be modified and only
* addresses that were successfully added will be kept in the list.
* That means, expired addresses and addresses that could not be added
* will be dropped.
* Hence, the input argument @known_addresses is also an output argument
* telling which addresses were succesfully added.
* Addresses are removed by unrefing the instance via nmp_object_unref()
* and leaving a NULL tombstone.
*
* A convenience function to synchronize addresses for a specific interface
* with the least possible disturbance. It simply removes addresses that are
@ -3168,102 +3155,162 @@ ip4_addr_subnets_is_secondary (const NMPlatformIP4Address *address, GHashTable *
* Returns: %TRUE on success.
*/
gboolean
nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, GPtrArray **out_added_addresses)
nm_platform_ip4_address_sync (NMPlatform *self,
int ifindex,
GPtrArray *known_addresses)
{
GArray *addresses;
NMPlatformIP4Address *address;
gs_unref_ptrarray GPtrArray *plat_addresses = NULL;
const NMPlatformIP4Address *known_address;
gint32 now = nm_utils_get_monotonic_timestamp_s ();
GHashTable *plat_subnets;
GHashTable *known_subnets;
GPtrArray *ptr;
int i, j;
GHashTable *plat_subnets = NULL;
GHashTable *known_subnets = NULL;
gs_unref_hashtable GHashTable *known_addresses_idx = NULL;
guint i, j, len;
NMPLookup lookup;
guint32 lifetime, preferred;
_CHECK_SELF (self, klass, FALSE);
addresses = nm_platform_ip4_address_get_all (self, ifindex);
plat_subnets = ip4_addr_subnets_build_index (addresses, TRUE);
known_subnets = ip4_addr_subnets_build_index (known_addresses, FALSE);
if (known_addresses) {
/* remove all addresses that are already expired. */
for (i = 0; i < known_addresses->len; i++) {
const NMPObject *o;
o = known_addresses->pdata[i];
nm_assert (o);
known_address = NMP_OBJECT_CAST_IP4_ADDRESS (known_addresses->pdata[i]);
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
now, &lifetime, &preferred))
goto delete_and_next;
if (G_UNLIKELY (!known_addresses_idx)) {
known_addresses_idx = g_hash_table_new ((GHashFunc) nmp_object_hash,
(GEqualFunc) nmp_object_equal);
}
if (!nm_g_hash_table_insert (known_addresses_idx, (gpointer) o, (gpointer) o)) {
/* duplicate? Keep only the first instance. */
goto delete_and_next;
}
continue;
delete_and_next:
nmp_object_unref (o);
known_addresses->pdata[i] = NULL;
}
if ( !known_addresses_idx
|| g_hash_table_size (known_addresses_idx) == 0)
known_addresses = NULL;
}
plat_addresses = nm_platform_lookup_clone (self,
nmp_lookup_init_addrroute (&lookup,
NMP_OBJECT_TYPE_IP4_ADDRESS,
ifindex),
NULL, NULL);
if (plat_addresses)
plat_subnets = ip4_addr_subnets_build_index (plat_addresses, TRUE, TRUE);
/* Delete unknown addresses */
for (i = 0; i < addresses->len; i++) {
address = &g_array_index (addresses, NMPlatformIP4Address, i);
len = plat_addresses ? plat_addresses->len : 0;
for (i = 0; i < len; i++) {
const NMPObject *plat_obj;
const NMPlatformIP4Address *plat_address;
const GPtrArray *addr_list;
if (!address->ifindex) {
plat_obj = plat_addresses->pdata[i];
if (!plat_obj) {
/* Already deleted */
continue;
}
known_address = array_contains_ip4_address (known_addresses, address, now);
if (known_address) {
gboolean secondary;
plat_address = NMP_OBJECT_CAST_IP4_ADDRESS (plat_obj);
secondary = ip4_addr_subnets_is_secondary (known_address, known_subnets, known_addresses, NULL);
/* Ignore the matching address if it has a different primary/slave
* role. */
if (secondary != NM_FLAGS_HAS (address->n_ifa_flags, IFA_F_SECONDARY))
known_address = NULL;
if (known_addresses) {
const NMPObject *o;
o = g_hash_table_lookup (known_addresses_idx, plat_obj);
if (o) {
gboolean secondary;
if (!known_subnets)
known_subnets = ip4_addr_subnets_build_index (known_addresses, FALSE, FALSE);
secondary = ip4_addr_subnets_is_secondary (o, known_subnets, known_addresses, NULL);
if (secondary == NM_FLAGS_HAS (plat_address->n_ifa_flags, IFA_F_SECONDARY)) {
/* if we have an existing known-address, with matching secondary role,
* do not delete the platform-address. */
continue;
}
}
}
if (!known_address) {
nm_platform_ip4_address_delete (self, ifindex,
address->address,
address->plen,
address->peer_address);
if ( !ip4_addr_subnets_is_secondary (address, plat_subnets, addresses, &ptr)
&& ptr) {
/* If we just deleted a primary addresses and there were
* secondary ones the kernel can do two things, depending on
* version and sysctl setting: delete also secondary addresses
* or promote a secondary to primary. Ensure that secondary
* addresses are deleted, so that we can start with a clean
* slate and add addresses in the right order. */
for (j = 1; j < ptr->len; j++) {
address = ptr->pdata[j];
nm_platform_ip4_address_delete (self, ifindex,
plat_address->address,
plat_address->plen,
plat_address->peer_address);
if ( !ip4_addr_subnets_is_secondary (plat_obj, plat_subnets, plat_addresses, &addr_list)
&& addr_list) {
/* If we just deleted a primary addresses and there were
* secondary ones the kernel can do two things, depending on
* version and sysctl setting: delete also secondary addresses
* or promote a secondary to primary. Ensure that secondary
* addresses are deleted, so that we can start with a clean
* slate and add addresses in the right order. */
for (j = 1; j < addr_list->len; j++) {
const NMPObject **o;
o = ip4_addr_subnets_addr_list_get (addr_list, j);
nm_assert (o);
if (*o) {
const NMPlatformIP4Address *a;
a = NMP_OBJECT_CAST_IP4_ADDRESS (*o);
nm_platform_ip4_address_delete (self, ifindex,
address->address,
address->plen,
address->peer_address);
address->ifindex = 0;
a->address,
a->plen,
a->peer_address);
nmp_object_unref (*o);
*o = NULL;
}
}
}
}
ip4_addr_subnets_destroy_index (plat_subnets, addresses);
g_array_free (addresses, TRUE);
if (out_added_addresses)
*out_added_addresses = NULL;
ip4_addr_subnets_destroy_index (plat_subnets, plat_addresses);
ip4_addr_subnets_destroy_index (known_subnets, known_addresses);
if (!known_addresses)
return TRUE;
/* Add missing addresses */
for (i = 0; i < known_addresses->len; i++) {
guint32 lifetime, preferred;
const NMPObject *o;
known_address = &g_array_index (known_addresses, NMPlatformIP4Address, i);
o = known_addresses->pdata[i];
if (!o)
continue;
known_address = NMP_OBJECT_CAST_IP4_ADDRESS (o);
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
now, &lifetime, &preferred))
continue;
goto delete_and_next2;
if (!nm_platform_ip4_address_add (self, ifindex, known_address->address, known_address->plen,
known_address->peer_address, lifetime, preferred,
0, known_address->label)) {
ip4_addr_subnets_destroy_index (known_subnets, known_addresses);
return FALSE;
}
0, known_address->label))
goto delete_and_next2;
if (out_added_addresses) {
if (!*out_added_addresses)
*out_added_addresses = g_ptr_array_new ();
g_ptr_array_add (*out_added_addresses, (gpointer) known_address);
}
continue;
delete_and_next2:
nmp_object_unref (o);
known_addresses->pdata[i] = NULL;
}
ip4_addr_subnets_destroy_index (known_subnets, known_addresses);
return TRUE;
}
@ -3271,7 +3318,8 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
* nm_platform_ip6_address_sync:
* @self: platform instance
* @ifindex: Interface index
* @known_addresses: List of addresses
* @known_addresses: List of IPv6 addresses, as NMPObject. The list
* is not modified.
* @keep_link_local: Don't remove link-local address
*
* A convenience function to synchronize addresses for a specific interface
@ -3281,33 +3329,42 @@ nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known
* Returns: %TRUE on success.
*/
gboolean
nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, gboolean keep_link_local)
nm_platform_ip6_address_sync (NMPlatform *self,
int ifindex,
const GPtrArray *known_addresses,
gboolean keep_link_local)
{
GArray *addresses;
gs_unref_ptrarray GPtrArray *plat_addresses = NULL;
NMPlatformIP6Address *address;
gint32 now = nm_utils_get_monotonic_timestamp_s ();
int i;
guint i;
NMPLookup lookup;
/* Delete unknown addresses */
addresses = nm_platform_ip6_address_get_all (self, ifindex);
for (i = 0; i < addresses->len; i++) {
address = &g_array_index (addresses, NMPlatformIP6Address, i);
plat_addresses = nm_platform_lookup_clone (self,
nmp_lookup_init_addrroute (&lookup,
NMP_OBJECT_TYPE_IP6_ADDRESS,
ifindex),
NULL, NULL);
if (plat_addresses) {
for (i = 0; i < plat_addresses->len; i++) {
address = NMP_OBJECT_CAST_IP6_ADDRESS (plat_addresses->pdata[i]);
/* Leave link local address management to the kernel */
if (keep_link_local && IN6_IS_ADDR_LINKLOCAL (&address->address))
continue;
/* Leave link local address management to the kernel */
if (keep_link_local && IN6_IS_ADDR_LINKLOCAL (&address->address))
continue;
if (!array_contains_ip6_address (known_addresses, address, now))
nm_platform_ip6_address_delete (self, ifindex, address->address, address->plen);
if (!array_contains_ip6_address (known_addresses, address, now))
nm_platform_ip6_address_delete (self, ifindex, address->address, address->plen);
}
}
g_array_free (addresses, TRUE);
if (!known_addresses)
return TRUE;
/* Add missing addresses */
for (i = 0; i < known_addresses->len; i++) {
const NMPlatformIP6Address *known_address = &g_array_index (known_addresses, NMPlatformIP6Address, i);
const NMPlatformIP6Address *known_address = NMP_OBJECT_CAST_IP6_ADDRESS (known_addresses->pdata[i]);
guint32 lifetime, preferred;
if (NM_FLAGS_HAS (known_address->n_ifa_flags, IFA_F_TEMPORARY)) {
@ -3333,7 +3390,7 @@ nm_platform_address_flush (NMPlatform *self, int ifindex)
{
_CHECK_SELF (self, klass, FALSE);
return nm_platform_ip4_address_sync (self, ifindex, NULL, NULL)
return nm_platform_ip4_address_sync (self, ifindex, NULL)
&& nm_platform_ip6_address_sync (self, ifindex, NULL, FALSE);
}
@ -3389,29 +3446,19 @@ nm_platform_ip6_route_add (NMPlatform *self, const NMPlatformIP6Route *route)
}
gboolean
nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
nm_platform_ip_route_delete (NMPlatform *self,
const NMPObject *obj)
{
char str_dev[TO_STRING_DEV_BUF_SIZE];
_CHECK_SELF (self, klass, FALSE);
_LOGD ("route: deleting IPv4 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
nm_utils_inet4_ntop (network, NULL), plen, metric, ifindex,
_to_string_dev (self, ifindex, str_dev, sizeof (str_dev)));
return klass->ip4_route_delete (self, ifindex, network, plen, metric);
}
nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE,
NMP_OBJECT_TYPE_IP6_ROUTE));
gboolean
nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric)
{
char str_dev[TO_STRING_DEV_BUF_SIZE];
_LOGD ("route: deleting IPv%c route %s",
NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_IP4_ROUTE ? '4' : '6',
nmp_object_to_string (obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
_CHECK_SELF (self, klass, FALSE);
_LOGD ("route: deleting IPv6 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
nm_utils_inet6_ntop (&network, NULL), plen, metric, ifindex,
_to_string_dev (self, ifindex, str_dev, sizeof (str_dev)));
return klass->ip6_route_delete (self, ifindex, network, plen, metric);
return klass->ip_route_delete (self, obj);
}
const NMPlatformIP4Route *
@ -5103,44 +5150,12 @@ _vtr_v6_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *rout
return nm_platform_ip6_route_add (self, &rt);
}
static gboolean
_vtr_v4_route_delete (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route)
{
return nm_platform_ip4_route_delete (self,
ifindex > 0 ? ifindex : route->rx.ifindex,
route->r4.network,
route->rx.plen,
route->rx.metric);
}
static gboolean
_vtr_v6_route_delete (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route)
{
return nm_platform_ip6_route_delete (self,
ifindex > 0 ? ifindex : route->rx.ifindex,
route->r6.network,
route->rx.plen,
route->rx.metric);
}
static guint32
_vtr_v4_metric_normalize (guint32 metric)
{
return metric;
}
static gboolean
_vtr_v4_route_delete_default (NMPlatform *self, int ifindex, guint32 metric)
{
return nm_platform_ip4_route_delete (self, ifindex, 0, 0, metric);
}
static gboolean
_vtr_v6_route_delete_default (NMPlatform *self, int ifindex, guint32 metric)
{
return nm_platform_ip6_route_delete (self, ifindex, in6addr_any, 0, metric);
}
/*****************************************************************************/
const NMPlatformVTableRoute nm_platform_vtable_route_v4 = {
@ -5151,8 +5166,6 @@ const NMPlatformVTableRoute nm_platform_vtable_route_v4 = {
.route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b, gboolean consider_host_part)) nm_platform_ip4_route_cmp_full,
.route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, char *buf, gsize len)) nm_platform_ip4_route_to_string,
.route_add = _vtr_v4_route_add,
.route_delete = _vtr_v4_route_delete,
.route_delete_default = _vtr_v4_route_delete_default,
.metric_normalize = _vtr_v4_metric_normalize,
};
@ -5164,8 +5177,6 @@ const NMPlatformVTableRoute nm_platform_vtable_route_v6 = {
.route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b, gboolean consider_host_part)) nm_platform_ip6_route_cmp_full,
.route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, char *buf, gsize len)) nm_platform_ip6_route_to_string,
.route_add = _vtr_v6_route_add,
.route_delete = _vtr_v6_route_delete,
.route_delete_default = _vtr_v6_route_delete_default,
.metric_normalize = nm_utils_ip6_route_metric_normalize,
};

View file

@ -173,9 +173,9 @@ typedef enum {
NM_PLATFORM_SIGNAL_REMOVED,
} NMPlatformSignalChangeType;
typedef struct {
struct _NMPlatformObject {
__NMPlatformObject_COMMON;
} NMPlatformObject;
};
#define __NMPlatformIPAddress_COMMON \
@ -367,8 +367,6 @@ typedef struct {
int (*route_cmp) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b, gboolean consider_host_part);
const char *(*route_to_string) (const NMPlatformIPXRoute *route, char *buf, gsize len);
gboolean (*route_add) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, gint64 metric);
gboolean (*route_delete) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route);
gboolean (*route_delete_default) (NMPlatform *self, int ifindex, guint32 metric);
guint32 (*metric_normalize) (guint32 metric);
} NMPlatformVTableRoute;
@ -644,8 +642,7 @@ typedef struct {
gboolean (*ip4_route_add) (NMPlatform *, const NMPlatformIP4Route *route);
gboolean (*ip6_route_add) (NMPlatform *, const NMPlatformIP6Route *route);
gboolean (*ip4_route_delete) (NMPlatform *, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
gboolean (*ip6_route_delete) (NMPlatform *, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
gboolean (*ip_route_delete) (NMPlatform *, const NMPObject *obj);
gboolean (*check_support_kernel_extended_ifa_flags) (NMPlatform *);
gboolean (*check_support_user_ipv6ll) (NMPlatform *);
@ -931,8 +928,7 @@ NMPlatformError nm_platform_link_sit_add (NMPlatform *self,
const NMPlatformLink **out_link);
const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address);
GArray *nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex);
GArray *nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex);
gboolean nm_platform_ip4_address_add (NMPlatform *self,
int ifindex,
in_addr_t address,
@ -952,16 +948,15 @@ gboolean nm_platform_ip6_address_add (NMPlatform *self,
guint32 flags);
gboolean nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address);
gboolean nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen);
gboolean nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, GPtrArray **out_added_addresses);
gboolean nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, gboolean keep_link_local);
gboolean nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, GPtrArray *known_addresse);
gboolean nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GPtrArray *known_addresses, gboolean keep_link_local);
gboolean nm_platform_address_flush (NMPlatform *self, int ifindex);
const NMPlatformIP4Route *nm_platform_ip4_route_get (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
const NMPlatformIP6Route *nm_platform_ip6_route_get (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
gboolean nm_platform_ip4_route_add (NMPlatform *self, const NMPlatformIP4Route *route);
gboolean nm_platform_ip6_route_add (NMPlatform *self, const NMPlatformIP6Route *route);
gboolean nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
gboolean nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
gboolean nm_platform_ip_route_delete (NMPlatform *self, const NMPObject *route);
const char *nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len);
const char *nm_platform_lnk_gre_to_string (const NMPlatformLnkGre *lnk, char *buf, gsize len);

View file

@ -345,6 +345,22 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->link : NULL; \
})
#define NMP_OBJECT_CAST_IP_ADDRESS(obj) \
({ \
typeof (obj) _obj = (obj); \
\
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); \
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip_address : NULL; \
})
#define NMP_OBJECT_CAST_IPX_ADDRESS(obj) \
({ \
typeof (obj) _obj = (obj); \
\
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); \
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ipx_address : NULL; \
})
#define NMP_OBJECT_CAST_IP4_ADDRESS(obj) \
({ \
typeof (obj) _obj = (obj); \
@ -419,6 +435,15 @@ NMPObject *nmp_object_new (NMPObjectType obj_type, const NMPlatformObject *plob)
NMPObject *nmp_object_new_link (int ifindex);
const NMPObject *nmp_object_stackinit (NMPObject *obj, NMPObjectType obj_type, const NMPlatformObject *plobj);
static inline NMPObject *
nmp_object_stackinit_obj (NMPObject *obj, const NMPObject *src)
{
return obj == src
? obj
: (NMPObject *) nmp_object_stackinit (obj, NMP_OBJECT_GET_TYPE (src), &src->object);
}
const NMPObject *nmp_object_stackinit_id (NMPObject *obj, const NMPObject *src);
const NMPObject *nmp_object_stackinit_id_link (NMPObject *obj, int ifindex);
const NMPObject *nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifindex, guint32 address, guint8 plen, guint32 peer_address);

View file

@ -102,7 +102,7 @@ test_ip4_address_general (void)
accept_signals (address_changed, 0, 1);
/* Test address listing */
addresses = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addresses = nmtstp_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
g_assert (addresses);
g_assert_cmpint (addresses->len, ==, 1);
address = &g_array_index (addresses, NMPlatformIP4Address, 0);
@ -152,7 +152,7 @@ test_ip6_address_general (void)
accept_signals (address_changed, 0, 1);
/* Test address listing */
addresses = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
addresses = nmtstp_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
g_assert (addresses);
g_assert_cmpint (addresses->len, ==, 1);
address = &g_array_index (addresses, NMPlatformIP6Address, 0);
@ -329,7 +329,7 @@ test_ip4_address_peer_zero (void)
nmtstp_ip4_address_add (NULL, EX, ifindex, addr, plen, r_peers[i], lifetime, preferred, 0, label);
addrs = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addrs = nmtstp_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
g_assert (addrs);
g_assert_cmpint (addrs->len, ==, i + 1);
g_array_unref (addrs);
@ -344,7 +344,7 @@ test_ip4_address_peer_zero (void)
nmtstp_ip4_address_del (NULL, EX, ifindex, addr, plen, r_peers[i]);
addrs = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addrs = nmtstp_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
g_assert (addrs);
g_assert_cmpint (addrs->len, ==, G_N_ELEMENTS (peers) - i - 1);
g_array_unref (addrs);

View file

@ -70,8 +70,8 @@ test_cleanup_internal (void)
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, in6addr_any, metric, mss);
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, in6addr_any, metric, mss);
addresses4 = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addresses6 = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
addresses4 = nmtstp_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addresses6 = nmtstp_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
routes4 = nmtstp_ip4_route_get_all (NM_PLATFORM_GET, ifindex);
routes6 = nmtstp_ip6_route_get_all (NM_PLATFORM_GET, ifindex);
@ -88,8 +88,8 @@ test_cleanup_internal (void)
/* Delete interface with all addresses and routes */
g_assert (nm_platform_link_delete (NM_PLATFORM_GET, ifindex));
addresses4 = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addresses6 = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
addresses4 = nmtstp_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addresses6 = nmtstp_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
routes4 = nmtstp_ip4_route_get_all (NM_PLATFORM_GET, ifindex);
routes6 = nmtstp_ip6_route_get_all (NM_PLATFORM_GET, ifindex);

View file

@ -70,6 +70,90 @@ _init_platform (NMPlatform **platform, gboolean external_command)
/*****************************************************************************/
static GArray *
_ipx_address_get_all (NMPlatform *self, int ifindex, NMPObjectType obj_type)
{
NMPLookup lookup;
g_assert (NM_IS_PLATFORM (self));
g_assert (ifindex > 0);
g_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS));
nmp_lookup_init_addrroute (&lookup,
obj_type,
ifindex);
return nmp_cache_lookup_to_array (nm_platform_lookup (self, &lookup),
obj_type,
FALSE /*addresses are always visible. */);
}
GArray *
nmtstp_platform_ip4_address_get_all (NMPlatform *self, int ifindex)
{
return _ipx_address_get_all (self, ifindex, NMP_OBJECT_TYPE_IP4_ADDRESS);
}
GArray *
nmtstp_platform_ip6_address_get_all (NMPlatform *self, int ifindex)
{
return _ipx_address_get_all (self, ifindex, NMP_OBJECT_TYPE_IP6_ADDRESS);
}
/*****************************************************************************/
gboolean
nmtstp_platform_ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
{
NMDedupMultiIter iter;
nm_platform_process_events (platform);
nm_dedup_multi_iter_for_each (&iter,
nm_platform_lookup_addrroute (platform,
NMP_OBJECT_TYPE_IP4_ROUTE,
ifindex)) {
const NMPlatformIP4Route *r = NMP_OBJECT_CAST_IP4_ROUTE (iter.current->obj);
if ( r->ifindex != ifindex
|| r->network != network
|| r->plen != plen
|| r->metric != metric) {
continue;
}
return nm_platform_ip_route_delete (platform, NMP_OBJECT_UP_CAST (r));
}
return TRUE;
}
gboolean
nmtstp_platform_ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, guint8 plen, guint32 metric)
{
NMDedupMultiIter iter;
nm_platform_process_events (platform);
nm_dedup_multi_iter_for_each (&iter,
nm_platform_lookup_addrroute (platform,
NMP_OBJECT_TYPE_IP6_ROUTE,
ifindex)) {
const NMPlatformIP6Route *r = NMP_OBJECT_CAST_IP6_ROUTE (iter.current->obj);
if ( r->ifindex != ifindex
|| !IN6_ARE_ADDR_EQUAL (&r->network, &network)
|| r->plen != plen
|| r->metric != metric) {
continue;
}
return nm_platform_ip_route_delete (platform, NMP_OBJECT_UP_CAST (r));
}
return TRUE;
}
/*****************************************************************************/
SignalData *
add_signal_full (const char *name, NMPlatformSignalChangeType change_type, GCallback callback, int ifindex, const char *ifname)
{

View file

@ -214,6 +214,12 @@ nmtstp_ip6_route_get_all (NMPlatform *platform,
/*****************************************************************************/
GArray *nmtstp_platform_ip4_address_get_all (NMPlatform *self, int ifindex);
GArray *nmtstp_platform_ip6_address_get_all (NMPlatform *self, int ifindex);
gboolean nmtstp_platform_ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
gboolean nmtstp_platform_ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
const NMPlatformLink *nmtstp_link_get_typed (NMPlatform *platform, int ifindex, const char *name, NMLinkType link_type);
const NMPlatformLink *nmtstp_link_get (NMPlatform *platform, int ifindex, const char *name);

View file

@ -136,7 +136,7 @@ test_ip4_route_metric0 (void)
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* Deleting route with metric 0 does nothing */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
ensure_no_signal (route_removed);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
@ -150,21 +150,21 @@ test_ip4_route_metric0 (void)
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* Delete route with metric 0 */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
accept_signal (route_removed);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* Delete route with metric 0 again (we expect nothing to happen) */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, 0));
ensure_no_signal (route_removed);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* Delete the other route */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
accept_signal (route_removed);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
@ -250,19 +250,19 @@ test_ip4_route (void)
g_ptr_array_unref (routes);
/* Remove route */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
accept_signal (route_removed);
/* Remove route again */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
/* Remove default route */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, 0, 0, metric));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, 0, 0, metric));
accept_signal (route_removed);
/* Remove route to gateway */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, gateway, 32, metric));
g_assert (nmtstp_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, gateway, 32, metric));
accept_signal (route_removed);
free_signal (route_added);
@ -352,19 +352,19 @@ test_ip6_route (void)
g_ptr_array_unref (routes);
/* Remove route */
g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
g_assert (nmtstp_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
accept_signal (route_removed);
/* Remove route again */
g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
g_assert (nmtstp_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, network, plen, metric));
/* Remove default route */
g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
g_assert (nmtstp_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
accept_signal (route_removed);
/* Remove route to gateway */
g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, gateway, 128, metric));
g_assert (nmtstp_platform_ip6_route_delete (NM_PLATFORM_GET, ifindex, gateway, 128, metric));
accept_signal (route_removed);
free_signal (route_added);
@ -438,10 +438,11 @@ test_ip4_route_options (void)
rts[0].lock_cwnd = TRUE;
g_assert_cmpint (routes->len, ==, 1);
nmtst_platform_ip4_routes_equal_aptr ((const NMPObject *const*) routes->pdata, rts, routes->len, TRUE);
g_ptr_array_unref (routes);
/* Remove route */
g_assert (nm_platform_ip4_route_delete (NM_PLATFORM_GET, ifindex, network, 24, 20));
g_assert (nm_platform_ip_route_delete (NM_PLATFORM_GET, routes->pdata[0]));
g_ptr_array_unref (routes);
}
@ -536,9 +537,9 @@ test_ip6_route_options (gconstpointer test_data)
g_ptr_array_unref (routes);
for (i = 0; i < rts_n; i++) {
g_assert (nm_platform_ip6_route_delete (NM_PLATFORM_GET, IFINDEX,
rts_add[i].network, rts_add[i].plen,
rts_add[i].metric));
g_assert (nmtstp_platform_ip6_route_delete (NM_PLATFORM_GET, IFINDEX,
rts_add[i].network, rts_add[i].plen,
rts_add[i].metric));
}
for (i = 0; i < addr_n; i++) {

View file

@ -75,7 +75,7 @@ test_subtract (void)
const NMPlatformIP4Route *test_route;
const char *expected_addr = "192.168.1.12";
guint32 expected_addr_plen = 24;
const char *expected_route_dest = "8.7.6.5";
const char *expected_route_dest = "8.0.0.0";
guint32 expected_route_plen = 8;
const char *expected_route_next_hop = "192.168.1.1";
guint32 expected_ns1 = nmtst_inet4_from_string ("8.8.8.8");
@ -112,7 +112,7 @@ test_subtract (void)
/* ensure what's left is what we expect */
g_assert_cmpuint (nm_ip4_config_get_num_addresses (dst), ==, 1);
test_addr = nm_ip4_config_get_address (dst, 0);
test_addr = _nmtst_nm_ip4_config_get_address (dst, 0);
g_assert (test_addr != NULL);
g_assert_cmpuint (test_addr->address, ==, nmtst_inet4_from_string (expected_addr));
g_assert_cmpuint (test_addr->peer_address, ==, test_addr->address);
@ -196,27 +196,27 @@ test_add_address_with_source (void)
addr.addr_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip4_config_add_address (a, &addr);
test_addr = nm_ip4_config_get_address (a, 0);
test_addr = _nmtst_nm_ip4_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
addr.addr_source = NM_IP_CONFIG_SOURCE_VPN;
nm_ip4_config_add_address (a, &addr);
test_addr = nm_ip4_config_get_address (a, 0);
test_addr = _nmtst_nm_ip4_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
/* Test that a lower priority address source is overwritten */
nm_ip4_config_del_address (a, 0);
_nmtst_nm_ip4_config_del_address (a, 0);
addr.addr_source = NM_IP_CONFIG_SOURCE_KERNEL;
nm_ip4_config_add_address (a, &addr);
test_addr = nm_ip4_config_get_address (a, 0);
test_addr = _nmtst_nm_ip4_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_KERNEL);
addr.addr_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip4_config_add_address (a, &addr);
test_addr = nm_ip4_config_get_address (a, 0);
test_addr = _nmtst_nm_ip4_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
g_object_unref (a);
@ -232,7 +232,7 @@ test_add_route_with_source (void)
a = nmtst_ip4_config_new (1);
/* Test that a higher priority source is not overwritten */
route = *nmtst_platform_ip4_route ("1.2.3.4", 24, "1.2.3.1");
route = *nmtst_platform_ip4_route ("1.2.3.0", 24, "1.2.3.1");
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip4_config_add_route (a, &route);

View file

@ -37,8 +37,8 @@ build_test_config (void)
config = nmtst_ip6_config_new (1);
nm_ip6_config_add_address (config, nmtst_platform_ip6_address ("abcd:1234:4321::cdde", "1:2:3:4::5", 64));
nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL));
nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001:abba::", 16, "2001:abba::2234", NULL));
nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL));
nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001::", 16, "2001:abba::2234", NULL));
nm_ip6_config_set_gateway (config, nmtst_inet6_from_string ("3001:abba::3234"));
@ -60,7 +60,7 @@ test_subtract (void)
const NMPlatformIP6Route *test_route;
const char *expected_addr = "1122:3344:5566::7788";
guint32 expected_addr_plen = 96;
const char *expected_route_dest = "9991:8882:7773::";
const char *expected_route_dest = "9991:8800::";
guint32 expected_route_plen = 24;
const char *expected_route_next_hop = "1119:2228:3337:4446::5555";
struct in6_addr expected_ns1;
@ -88,7 +88,7 @@ test_subtract (void)
/* ensure what's left is what we expect */
g_assert_cmpuint (nm_ip6_config_get_num_addresses (dst), ==, 1);
test_addr = nm_ip6_config_get_address (dst, 0);
test_addr = _nmtst_nm_ip6_config_get_address (dst, 0);
g_assert (test_addr != NULL);
tmp = *nmtst_inet6_from_string (expected_addr);
g_assert (memcmp (&test_addr->address, &tmp, sizeof (tmp)) == 0);
@ -139,7 +139,7 @@ test_compare_with_source (void)
nm_ip6_config_add_address (b, &addr);
/* Route */
route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL);
route = *nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL);
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_route (a, &route);
@ -167,27 +167,27 @@ test_add_address_with_source (void)
addr.addr_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_address (a, &addr);
test_addr = nm_ip6_config_get_address (a, 0);
test_addr = _nmtst_nm_ip6_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
addr.addr_source = NM_IP_CONFIG_SOURCE_VPN;
nm_ip6_config_add_address (a, &addr);
test_addr = nm_ip6_config_get_address (a, 0);
test_addr = _nmtst_nm_ip6_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
/* Test that a lower priority address source is overwritten */
nm_ip6_config_del_address (a, 0);
_nmtst_nm_ip6_config_del_address (a, 0);
addr.addr_source = NM_IP_CONFIG_SOURCE_KERNEL;
nm_ip6_config_add_address (a, &addr);
test_addr = nm_ip6_config_get_address (a, 0);
test_addr = _nmtst_nm_ip6_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_KERNEL);
addr.addr_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_address (a, &addr);
test_addr = nm_ip6_config_get_address (a, 0);
test_addr = _nmtst_nm_ip6_config_get_address (a, 0);
g_assert_cmpint (test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
g_object_unref (a);
@ -203,7 +203,7 @@ test_add_route_with_source (void)
a = nmtst_ip6_config_new (1);
/* Test that a higher priority source is not overwritten */
route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL);
route = *nmtst_platform_ip6_route ("abcd:1200::", 24, "abcd:1234:4321:cdde::2", NULL);
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_route (a, &route);
@ -256,18 +256,18 @@ test_nm_ip6_config_addresses_sort_check (NMIP6Config *config, NMSettingIP6Config
int j = g_rand_int_range (nmtst_get_rand (), i, addr_count);
NMTST_SWAP (idx[i], idx[j]);
nm_ip6_config_add_address (copy, nm_ip6_config_get_address (config, idx[i]));
nm_ip6_config_add_address (copy, _nmtst_nm_ip6_config_get_address (config, idx[i]));
}
/* reorder them again */
nm_ip6_config_addresses_sort (copy);
_nmtst_nm_ip6_config_addresses_sort (copy);
/* check equality using nm_ip6_config_equal() */
if (!nm_ip6_config_equal (copy, config)) {
g_message ("%s", "SORTING yields unexpected output:");
for (i = 0; i < addr_count; i++) {
g_message (" >> [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (config, i), NULL, 0));
g_message (" << [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (copy, i), NULL, 0));
g_message (" >> [%d] = %s", i, nm_platform_ip6_address_to_string (_nmtst_nm_ip6_config_get_address (config, i), NULL, 0));
g_message (" << [%d] = %s", i, nm_platform_ip6_address_to_string (_nmtst_nm_ip6_config_get_address (copy, i), NULL, 0));
}
g_assert_not_reached ();
}

View file

@ -959,7 +959,8 @@ print_vpn_config (NMVpnConnection *self)
_LOGI ("Data: IPv4 configuration:");
address4 = nm_ip4_config_get_address (priv->ip4_config, 0);
address4 = nm_ip4_config_get_first_address (priv->ip4_config);
nm_assert (address4);
if (priv->ip4_internal_gw)
_LOGI ("Data: Internal Gateway: %s", nm_utils_inet4_ntop (priv->ip4_internal_gw, NULL));
@ -968,7 +969,7 @@ print_vpn_config (NMVpnConnection *self)
_LOGI ("Data: Internal Point-to-Point Address: %s", nm_utils_inet4_ntop (address4->peer_address, NULL));
_LOGI ("Data: Maximum Segment Size (MSS): %d", nm_ip4_config_get_mss (priv->ip4_config));
nm_ip4_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route) {
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route) {
_LOGI ("Data: Static Route: %s/%d Next Hop: %s",
nm_utils_inet4_ntop (route->network, NULL),
route->plen,
@ -996,7 +997,8 @@ print_vpn_config (NMVpnConnection *self)
_LOGI ("Data: IPv6 configuration:");
address6 = nm_ip6_config_get_address (priv->ip6_config, 0);
address6 = nm_ip6_config_get_first_address (priv->ip6_config);
nm_assert (address6);
if (priv->ip6_internal_gw)
_LOGI ("Data: Internal Gateway: %s", nm_utils_inet6_ntop (priv->ip6_internal_gw, NULL));
@ -1005,7 +1007,7 @@ print_vpn_config (NMVpnConnection *self)
_LOGI ("Data: Internal Point-to-Point Address: %s", nm_utils_inet6_ntop (&address6->peer_address, NULL));
_LOGI ("Data: Maximum Segment Size (MSS): %d", nm_ip6_config_get_mss (priv->ip6_config));
nm_ip6_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route) {
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route) {
_LOGI ("Data: Static Route: %s/%d Next Hop: %s",
nm_utils_inet6_ntop (&route->network, NULL),
route->plen,
@ -1506,7 +1508,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
NMDedupMultiIter ipconf_iter;
const NMPlatformIP4Route *route;
nm_ip4_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route)
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route)
nm_ip4_config_add_route (config, route);
}
} else if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, "aau", &iter)) {
@ -1529,6 +1531,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
if (plen > 32 || plen == 0)
break;
route.plen = plen;
route.network = nm_utils_ip4_address_clear_host_address (route.network, plen);
/* Ignore host routes to the VPN gateway since NM adds one itself
* below. Since NM knows more about the routing situation than
@ -1670,7 +1673,7 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Route *route;
nm_ip6_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route)
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route)
nm_ip6_config_add_route (config, route);
}
} else if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, "a(ayuayu)", &iter)) {