platform: add @peer_address argument to nm_platform_ip4_address_delete()
Deleting an IPv4 address using libnl requires the proper peer address. Pass the address of the peer on to nm_platform_ip4_address_delete(). Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -901,7 +901,7 @@ ip6_address_add (NMPlatform *platform, int ifindex,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen)
|
||||
ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in_addr_t peer_address)
|
||||
{
|
||||
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
|
||||
int i;
|
||||
@@ -909,7 +909,8 @@ ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen)
|
||||
for (i = 0; i < priv->ip4_addresses->len; i++) {
|
||||
NMPlatformIP4Address *address = &g_array_index (priv->ip4_addresses, NMPlatformIP4Address, i);
|
||||
|
||||
if (address->ifindex == ifindex && address->plen == plen && address->address == addr) {
|
||||
if (address->ifindex == ifindex && address->plen == plen && address->address == addr &&
|
||||
(!peer_address || address->peer_address == peer_address)) {
|
||||
NMPlatformIP4Address deleted_address;
|
||||
|
||||
memcpy (&deleted_address, address, sizeof (deleted_address));
|
||||
|
@@ -3567,9 +3567,9 @@ ip6_address_add (NMPlatform *platform,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen)
|
||||
ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen, in_addr_t peer_address)
|
||||
{
|
||||
return delete_object (platform, build_rtnl_addr (AF_INET, ifindex, &addr, NULL, plen, 0, 0, 0, NULL), TRUE);
|
||||
return delete_object (platform, build_rtnl_addr (AF_INET, ifindex, &addr, peer_address ? &peer_address : NULL, plen, 0, 0, 0, NULL), TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@@ -1567,9 +1567,10 @@ nm_platform_ip6_address_add (int ifindex,
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen)
|
||||
nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen, in_addr_t peer_address)
|
||||
{
|
||||
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
||||
char str_peer[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
reset_error ();
|
||||
|
||||
@@ -1577,10 +1578,14 @@ nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen)
|
||||
g_return_val_if_fail (plen > 0, FALSE);
|
||||
g_return_val_if_fail (klass->ip4_address_delete, FALSE);
|
||||
|
||||
debug ("address: deleting IPv4 address %s/%d, ifindex %d%s",
|
||||
nm_utils_inet4_ntop (address, NULL), plen, ifindex,
|
||||
debug ("address: deleting IPv4 address %s/%d, %s%s%sifindex %d%s",
|
||||
nm_utils_inet4_ntop (address, NULL), plen,
|
||||
peer_address ? "peer " : "",
|
||||
peer_address ? nm_utils_inet4_ntop (peer_address, str_peer) : "",
|
||||
peer_address ? ", " : "",
|
||||
ifindex,
|
||||
_to_string_dev (ifindex, str_dev, sizeof (str_dev)));
|
||||
return klass->ip4_address_delete (platform, ifindex, address, plen);
|
||||
return klass->ip4_address_delete (platform, ifindex, address, plen, peer_address);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -1744,7 +1749,7 @@ nm_platform_ip4_address_sync (int ifindex, const GArray *known_addresses)
|
||||
address = &g_array_index (addresses, NMPlatformIP4Address, i);
|
||||
|
||||
if (!array_contains_ip4_address (known_addresses, address))
|
||||
nm_platform_ip4_address_delete (ifindex, address->address, address->plen);
|
||||
nm_platform_ip4_address_delete (ifindex, address->address, address->plen, address->peer_address);
|
||||
}
|
||||
g_array_free (addresses, TRUE);
|
||||
|
||||
|
@@ -447,7 +447,7 @@ typedef struct {
|
||||
gboolean (*ip6_address_add) (NMPlatform *, int ifindex,
|
||||
struct in6_addr address, struct in6_addr peer_address, int plen,
|
||||
guint32 lifetime, guint32 preferred_lft, guint flags);
|
||||
gboolean (*ip4_address_delete) (NMPlatform *, int ifindex, in_addr_t address, int plen);
|
||||
gboolean (*ip4_address_delete) (NMPlatform *, int ifindex, in_addr_t address, int plen, in_addr_t peer_address);
|
||||
gboolean (*ip6_address_delete) (NMPlatform *, int ifindex, struct in6_addr address, int plen);
|
||||
gboolean (*ip4_address_exists) (NMPlatform *, int ifindex, in_addr_t address, int plen);
|
||||
gboolean (*ip6_address_exists) (NMPlatform *, int ifindex, struct in6_addr address, int plen);
|
||||
@@ -591,7 +591,7 @@ gboolean nm_platform_ip4_address_add (int ifindex,
|
||||
gboolean nm_platform_ip6_address_add (int ifindex,
|
||||
struct in6_addr address, struct in6_addr peer_address, int plen,
|
||||
guint32 lifetime, guint32 preferred_lft, guint flags);
|
||||
gboolean nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen);
|
||||
gboolean nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen, in_addr_t peer_address);
|
||||
gboolean nm_platform_ip6_address_delete (int ifindex, struct in6_addr address, int plen);
|
||||
gboolean nm_platform_ip4_address_exists (int ifindex, in_addr_t address, int plen);
|
||||
gboolean nm_platform_ip6_address_exists (int ifindex, struct in6_addr address, int plen);
|
||||
|
@@ -597,7 +597,7 @@ do_ip6_address_add (char **argv)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#define ADDR_CMD_FULL(v, cmdname, print) \
|
||||
#define ADDR_CMD_FULL(v, cmdname, print, ...) \
|
||||
static gboolean \
|
||||
do_##v##_address_##cmdname (char **argv) \
|
||||
{ \
|
||||
@@ -605,7 +605,7 @@ do_ip6_address_add (char **argv)
|
||||
v##_t address; \
|
||||
int plen; \
|
||||
if (ifindex && parse_##v##_address (*argv++, &address, &plen)) { \
|
||||
gboolean value = nm_platform_##v##_address_##cmdname (ifindex, address, plen); \
|
||||
gboolean value = nm_platform_##v##_address_##cmdname (ifindex, address, plen, ##__VA_ARGS__); \
|
||||
if (print) { \
|
||||
print_boolean (value); \
|
||||
return TRUE; \
|
||||
@@ -614,7 +614,7 @@ do_ip6_address_add (char **argv)
|
||||
} else \
|
||||
return FALSE; \
|
||||
}
|
||||
#define ADDR_CMD(cmdname) ADDR_CMD_FULL (ip4, cmdname, FALSE) ADDR_CMD_FULL (ip6, cmdname, FALSE)
|
||||
#define ADDR_CMD(cmdname) ADDR_CMD_FULL (ip4, cmdname, FALSE, 0) ADDR_CMD_FULL (ip6, cmdname, FALSE)
|
||||
#define ADDR_CMD_PRINT(cmdname) ADDR_CMD_FULL (ip4, cmdname, TRUE) ADDR_CMD_FULL (ip6, cmdname, TRUE)
|
||||
|
||||
ADDR_CMD (delete)
|
||||
|
@@ -91,13 +91,13 @@ test_ip4_address (void)
|
||||
g_array_unref (addresses);
|
||||
|
||||
/* Remove address */
|
||||
g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN));
|
||||
g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN, 0));
|
||||
no_error ();
|
||||
g_assert (!nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN));
|
||||
accept_signal (address_removed);
|
||||
|
||||
/* Remove address again */
|
||||
g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN));
|
||||
g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN, 0));
|
||||
no_error ();
|
||||
|
||||
free_signal (address_added);
|
||||
@@ -196,7 +196,7 @@ test_ip4_address_external (void)
|
||||
g_assert (nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN));
|
||||
accept_signal (address_added);
|
||||
/*run_command ("ip address delete %s/%d dev %s", IP4_ADDRESS, IP4_PLEN, DEVICE_NAME);
|
||||
g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN));
|
||||
g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN, 0));
|
||||
no_error ();
|
||||
g_assert (!nm_platform_ip4_address_exists (ifindex, addr, IP4_PLEN));
|
||||
accept_signal (address_removed);*/
|
||||
|
Reference in New Issue
Block a user