platform: introduce nm_platform_link_change_flags()

Having two functions like link_set_x() and link_set_nox() it is not a
good idea. This patch is introducing nm_platform_link_change_flags().

This allow flag modification directly, so the developer does not need to
define the virtual functions all the time everywhere.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
This commit is contained in:
Fernando Fernandez Mancera 2021-04-15 09:50:48 +02:00 committed by Beniamino Galvani
parent 27e37a4b17
commit 1dfe536386
18 changed files with 933 additions and 800 deletions

View file

@ -265,7 +265,7 @@ pppoe_vcc_config(NMDeviceAdsl *self)
_LOGD(LOGD_ADSL, "ATM setup successful");
/* otherwise we're good for stage3 */
nm_platform_link_set_up(nm_device_get_platform(device), priv->nas_ifindex, NULL);
nm_platform_link_change_flags(nm_device_get_platform(device), priv->nas_ifindex, IFF_UP, TRUE);
return TRUE;
}

View file

@ -2978,10 +2978,10 @@ nm_device_take_over_link(NMDevice *self, int ifindex, char **old_name, GError **
/* Rename the link to the device ifname */
if (up)
nm_platform_link_set_down(platform, ifindex);
nm_platform_link_change_flags(platform, ifindex, IFF_UP, FALSE);
success = nm_platform_link_set_name(platform, ifindex, nm_device_get_iface(self));
if (up)
nm_platform_link_set_up(platform, ifindex, NULL);
nm_platform_link_change_flags(platform, ifindex, IFF_UP, TRUE);
if (!success) {
nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "failure renaming link %d", ifindex);
@ -3109,7 +3109,7 @@ _set_ip_ifindex(NMDevice *self, int ifindex, const char *ifname)
nm_platform_link_set_user_ipv6ll_enabled(platform, priv->ip_ifindex, TRUE);
if (!nm_platform_link_is_up(platform, priv->ip_ifindex))
nm_platform_link_set_up(platform, priv->ip_ifindex, NULL);
nm_platform_link_change_flags(platform, priv->ip_ifindex, IFF_UP, TRUE);
}
/* We don't care about any saved values from the old iface */
@ -11833,7 +11833,7 @@ activate_stage5_ip_config_result_x(NMDevice *self, int addr_family)
if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex)
&& !nm_device_sys_iface_state_is_external_or_assume(self)) {
nm_platform_link_set_up(nm_device_get_platform(self), ip_ifindex, NULL);
nm_platform_link_change_flags(nm_device_get_platform(self), ip_ifindex, IFF_UP, TRUE);
if (!nm_platform_link_is_up(nm_device_get_platform(self), ip_ifindex))
_LOGW(LOGD_DEVICE,
"interface %s not up for IP configuration",
@ -14049,6 +14049,7 @@ nm_device_bring_up(NMDevice *self, gboolean block, gboolean *no_firmware)
gboolean device_is_up = FALSE;
NMDeviceCapabilities capabilities;
int ifindex;
int r;
g_return_val_if_fail(NM_IS_DEVICE(self), FALSE);
@ -14064,7 +14065,9 @@ nm_device_bring_up(NMDevice *self, gboolean block, gboolean *no_firmware)
if (ifindex <= 0) {
/* assume success. */
} else {
if (!nm_platform_link_set_up(nm_device_get_platform(self), ifindex, no_firmware))
r = nm_platform_link_change_flags(nm_device_get_platform(self), ifindex, IFF_UP, TRUE);
NM_SET_OUT(no_firmware, (r == -NME_PL_NO_FIRMWARE));
if (r < 0)
return FALSE;
}
@ -14151,7 +14154,7 @@ nm_device_take_down(NMDevice *self, gboolean block)
return;
}
if (!nm_platform_link_set_down(nm_device_get_platform(self), ifindex))
if (!nm_platform_link_change_flags(nm_device_get_platform(self), ifindex, IFF_UP, FALSE))
return;
device_is_up = nm_device_is_up(self);

View file

@ -78,8 +78,8 @@ fixture_setup(test_fixture *fixture, gconstpointer user_data)
fixture->ifindex1 =
nmtstp_link_get_typed(NM_PLATFORM_GET, -1, IFACE_VETH1, NM_LINK_TYPE_VETH)->ifindex;
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, fixture->ifindex0, NULL));
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, fixture->ifindex1, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, fixture->ifindex0, IFF_UP, TRUE) >= 0);
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, fixture->ifindex1, IFF_UP, TRUE) >= 0);
fixture->hwaddr0 =
nm_platform_link_get_address(NM_PLATFORM_GET, fixture->ifindex0, &fixture->hwaddr0_len);

View file

@ -10,6 +10,7 @@
#include <fcntl.h>
#include <termios.h>
#include <linux/if.h>
#include <linux/rtnetlink.h>
#include "libnm-core-intern/nm-core-internal.h"
@ -799,8 +800,10 @@ nm_modem_ip4_pre_commit(NMModem *modem, NMDevice *device, NMIP4Config *config)
g_assert(address);
if (address->plen == 32)
nm_platform_link_set_noarp(nm_device_get_platform(device),
nm_device_get_ip_ifindex(device));
nm_platform_link_change_flags(nm_device_get_platform(device),
nm_device_get_ip_ifindex(device),
IFF_NOARP,
TRUE);
}
}
@ -1199,7 +1202,7 @@ deactivate_cleanup(NMModem *self, NMDevice *device, gboolean stop_ppp_manager)
nm_platform_ip_route_flush(platform, AF_UNSPEC, ifindex);
nm_platform_ip_address_flush(platform, AF_UNSPEC, ifindex);
nm_platform_link_set_down(platform, ifindex);
nm_platform_link_change_flags(platform, ifindex, IFF_UP, FALSE);
}
}
}

View file

@ -12,6 +12,7 @@
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/if.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/resource.h>
@ -508,7 +509,7 @@ main(int argc, char *argv[])
* physical interfaces.
*/
nm_log_dbg(LOGD_CORE, "setting up local loopback");
nm_platform_link_set_up(NM_PLATFORM_GET, 1, NULL);
nm_platform_link_change_flags(NM_PLATFORM_GET, 1, IFF_UP, TRUE);
success = TRUE;

View file

@ -503,6 +503,21 @@ link_set_flags(NMPlatform *platform, NMFakePlatformLink *device, guint n_ifi_fla
link_set_obj(platform, device, obj_tmp);
}
static int
link_change_flags(NMPlatform *platform, int ifindex, unsigned flags_mask, unsigned flags_set)
{
NMFakePlatformLink *device = link_get(platform, ifindex);
if (!device)
return -ENOENT;
link_set_flags(platform,
device,
NM_FLAGS_ASSIGN_MASK(device->obj->link.n_ifi_flags, flags_mask, flags_set));
return 0;
}
static void
link_changed(NMPlatform * platform,
NMFakePlatformLink *device,
@ -540,65 +555,6 @@ link_changed(NMPlatform * platform,
}
}
static gboolean
link_set_up(NMPlatform *platform, int ifindex, gboolean *out_no_firmware)
{
NMFakePlatformLink *device = link_get(platform, ifindex);
if (out_no_firmware)
*out_no_firmware = FALSE;
if (!device) {
_LOGE("failure changing link: netlink error (No such device)");
return FALSE;
}
link_set_flags(platform, device, NM_FLAGS_ASSIGN(device->obj->link.n_ifi_flags, IFF_UP, TRUE));
return TRUE;
}
static gboolean
link_set_down(NMPlatform *platform, int ifindex)
{
NMFakePlatformLink *device = link_get(platform, ifindex);
if (!device) {
_LOGE("failure changing link: netlink error (No such device)");
return FALSE;
}
link_set_flags(platform, device, NM_FLAGS_UNSET(device->obj->link.n_ifi_flags, IFF_UP));
return TRUE;
}
static gboolean
link_set_arp(NMPlatform *platform, int ifindex)
{
NMFakePlatformLink *device = link_get(platform, ifindex);
if (!device) {
_LOGE("failure changing link: netlink error (No such device)");
return FALSE;
}
link_set_flags(platform, device, NM_FLAGS_UNSET(device->obj->link.n_ifi_flags, IFF_NOARP));
return TRUE;
}
static gboolean
link_set_noarp(NMPlatform *platform, int ifindex)
{
NMFakePlatformLink *device = link_get(platform, ifindex);
if (!device) {
_LOGE("failure changing link: netlink error (No such device)");
return FALSE;
}
link_set_flags(platform, device, NM_FLAGS_SET(device->obj->link.n_ifi_flags, IFF_NOARP));
return TRUE;
}
static int
link_set_address(NMPlatform *platform, int ifindex, gconstpointer addr, size_t len)
{
@ -1354,14 +1310,11 @@ nm_fake_platform_class_init(NMFakePlatformClass *klass)
platform_class->link_add = link_add;
platform_class->link_delete = link_delete;
platform_class->link_set_up = link_set_up;
platform_class->link_set_down = link_set_down;
platform_class->link_set_arp = link_set_arp;
platform_class->link_set_noarp = link_set_noarp;
platform_class->link_set_address = link_set_address;
platform_class->link_set_mtu = link_set_mtu;
platform_class->link_change_flags = link_change_flags;
platform_class->link_get_driver_info = link_get_driver_info;
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;

View file

@ -235,7 +235,7 @@ test_ip4_address_general_2(void)
/* Looks like addresses are not announced by kernel when the interface
* is down. Link-local IPv6 address is automatically added.
*/
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, DEVICE_IFINDEX, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, DEVICE_IFINDEX, IFF_UP, TRUE) >= 0);
/* Add/delete notification */
nmtstp_ip4_address_add(NULL, EX, ifindex, addr, IP4_PLEN, addr, lifetime, preferred, 0, NULL);
@ -325,7 +325,7 @@ test_ip4_address_peer(void)
g_assert(addr != addr_peer);
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, ifindex, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_UP, TRUE) >= 0);
accept_signals(address_removed, 0, G_MAXINT);
accept_signals(address_added, 0, G_MAXINT);
@ -397,7 +397,7 @@ test_ip4_address_peer_zero(void)
peers[1] = addr_peer;
peers[2] = 0;
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, ifindex, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_UP, TRUE) >= 0);
nmtst_rand_perm(NULL, r_peers, peers, sizeof(peers[0]), G_N_ELEMENTS(peers));
for (i = 0; i < G_N_ELEMENTS(peers); i++) {

View file

@ -44,9 +44,12 @@ test_cleanup_internal(void)
g_assert(NMTST_NM_ERR_SUCCESS(nm_platform_link_dummy_add(NM_PLATFORM_GET, DEVICE_NAME, NULL)));
accept_signal(link_added);
free_signal(link_added);
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET,
nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME),
NULL));
g_assert(
nm_platform_link_change_flags(NM_PLATFORM_GET,
nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME),
IFF_UP,
TRUE)
>= 0);
ifindex = nm_platform_link_get_ifindex(NM_PLATFORM_GET, DEVICE_NAME);
g_assert(ifindex > 0);

View file

@ -2284,9 +2284,9 @@ nmtstp_link_set_updown(NMPlatform *platform, gboolean external_command, int ifin
nmtstp_run_command_check("ip link set %s %s", ifname, up ? "up" : "down");
} else {
if (up)
g_assert(nm_platform_link_set_up(platform, ifindex, NULL));
g_assert(nm_platform_link_change_flags(platform, ifindex, IFF_UP, TRUE) >= 0);
else
g_assert(nm_platform_link_set_down(platform, ifindex));
g_assert(nm_platform_link_change_flags(platform, ifindex, IFF_UP, FALSE) >= 0);
}
/* Let's wait until we get the result */

View file

@ -542,7 +542,7 @@ _nmtstp_env1_wrapper_setup(const NmtstTestData *test_data)
g_assert_cmpint(NMTSTP_ENV1_IFINDEX, ==, -1);
if (GPOINTER_TO_INT(p_ifup))
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, *p_ifindex, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, *p_ifindex, IFF_UP, TRUE) >= 0);
nm_platform_process_events(NM_PLATFORM_GET);

View file

@ -48,13 +48,15 @@ test_bogus(void)
g_assert(!nm_platform_link_get_type(NM_PLATFORM_GET, BOGUS_IFINDEX));
g_assert(!nm_platform_link_get_type_name(NM_PLATFORM_GET, BOGUS_IFINDEX));
g_assert(!nm_platform_link_set_up(NM_PLATFORM_GET, BOGUS_IFINDEX, NULL));
g_assert(!(nm_platform_link_change_flags(NM_PLATFORM_GET, BOGUS_IFINDEX, IFF_UP, TRUE) >= 0));
g_assert(!nm_platform_link_set_down(NM_PLATFORM_GET, BOGUS_IFINDEX));
g_assert(!(nm_platform_link_change_flags(NM_PLATFORM_GET, BOGUS_IFINDEX, IFF_UP, FALSE) >= 0));
g_assert(!nm_platform_link_set_arp(NM_PLATFORM_GET, BOGUS_IFINDEX));
g_assert(
!(nm_platform_link_change_flags(NM_PLATFORM_GET, BOGUS_IFINDEX, IFF_NOARP, TRUE) >= 0));
g_assert(!nm_platform_link_set_noarp(NM_PLATFORM_GET, BOGUS_IFINDEX));
g_assert(
!(nm_platform_link_change_flags(NM_PLATFORM_GET, BOGUS_IFINDEX, IFF_NOARP, FALSE) >= 0));
g_assert(!nm_platform_link_is_up(NM_PLATFORM_GET, BOGUS_IFINDEX));
g_assert(!nm_platform_link_is_connected(NM_PLATFORM_GET, BOGUS_IFINDEX));
@ -147,7 +149,8 @@ software_add(NMLinkType link_type, const char *name)
NM_PLATFORM_SIGNAL_CHANGED,
link_callback,
parent_ifindex);
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, parent_ifindex, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, parent_ifindex, IFF_UP, TRUE)
>= 0);
if (was_up) {
/* when NM is running in the background, it will mess with addrgenmode which might cause additional signals. */
accept_signals(parent_changed, 0, 1);
@ -233,7 +236,7 @@ test_slave(int master, int type, SignalData *master_changed)
* See https://bugzilla.redhat.com/show_bug.cgi?id=910348
*/
g_assert(!nm_platform_link_is_up(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_set_down(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_UP, FALSE) >= 0);
g_assert(!nm_platform_link_is_up(NM_PLATFORM_GET, ifindex));
ensure_no_signal(link_changed);
@ -263,7 +266,7 @@ test_slave(int master, int type, SignalData *master_changed)
&test_link_changed_signal_arg2);
/* Set master up */
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, master, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, master, IFF_UP, TRUE) >= 0);
g_assert(nm_platform_link_is_up(NM_PLATFORM_GET, master));
accept_signals(master_changed, 1, 3);
@ -284,7 +287,7 @@ test_slave(int master, int type, SignalData *master_changed)
switch (nm_platform_link_get_type(NM_PLATFORM_GET, master)) {
case NM_LINK_TYPE_BOND:
case NM_LINK_TYPE_TEAM:
g_assert(nm_platform_link_set_down(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_UP, FALSE) >= 0);
accept_signal(link_changed);
accept_signals(master_changed, 0, 3);
break;
@ -317,7 +320,7 @@ test_slave(int master, int type, SignalData *master_changed)
}
/* Set slave up and see if master gets up too */
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, ifindex, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_UP, TRUE) >= 0);
g_assert(nm_platform_link_is_connected(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_is_connected(NM_PLATFORM_GET, master));
accept_signals(link_changed, 1, 3);
@ -439,10 +442,10 @@ test_software(NMLinkType link_type, const char *link_typename)
/* Set ARP/NOARP */
g_assert(nm_platform_link_uses_arp(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_set_noarp(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_NOARP, TRUE) >= 0);
g_assert(!nm_platform_link_uses_arp(NM_PLATFORM_GET, ifindex));
accept_signals(link_changed, 1, 2);
g_assert(nm_platform_link_set_arp(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_NOARP, FALSE) >= 0);
g_assert(nm_platform_link_uses_arp(NM_PLATFORM_GET, ifindex));
accept_signal(link_changed);
@ -672,21 +675,21 @@ test_internal(void)
/* Up/connected */
g_assert(!nm_platform_link_is_up(NM_PLATFORM_GET, ifindex));
g_assert(!nm_platform_link_is_connected(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_set_up(NM_PLATFORM_GET, ifindex, NULL));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_UP, TRUE) >= 0);
g_assert(nm_platform_link_is_up(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_is_connected(NM_PLATFORM_GET, ifindex));
accept_signals(link_changed, 1, 2);
g_assert(nm_platform_link_set_down(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_UP, FALSE) >= 0);
g_assert(!nm_platform_link_is_up(NM_PLATFORM_GET, ifindex));
g_assert(!nm_platform_link_is_connected(NM_PLATFORM_GET, ifindex));
accept_signal(link_changed);
/* arp/noarp */
g_assert(!nm_platform_link_uses_arp(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_set_arp(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_NOARP, FALSE) >= 0);
g_assert(nm_platform_link_uses_arp(NM_PLATFORM_GET, ifindex));
accept_signal(link_changed);
g_assert(nm_platform_link_set_noarp(NM_PLATFORM_GET, ifindex));
g_assert(nm_platform_link_change_flags(NM_PLATFORM_GET, ifindex, IFF_NOARP, TRUE) >= 0);
g_assert(!nm_platform_link_uses_arp(NM_PLATFORM_GET, ifindex));
accept_signal(link_changed);

View file

@ -82,8 +82,8 @@ _test_fixture_1_setup(TestFixture1 *f, int test_idx)
f->hwaddr0 = l0->l_address;
f->hwaddr1 = l1->l_address;
g_assert(nm_platform_link_set_up(f->platform, f->ifindex0, NULL));
g_assert(nm_platform_link_set_up(f->platform, f->ifindex1, NULL));
g_assert(nm_platform_link_change_flags(f->platform, f->ifindex0, IFF_UP, TRUE) >= 0);
g_assert(nm_platform_link_change_flags(f->platform, f->ifindex1, IFF_UP, TRUE) >= 0);
return f;
}

View file

@ -14,6 +14,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <linux/if.h>
#include <linux/rtnetlink.h>
#include "nm-proxy-config.h"
@ -371,7 +372,7 @@ vpn_cleanup(NMVpnConnection *self, NMDevice *parent_dev)
if (priv->ip_ifindex) {
NMPlatform *platform = nm_netns_get_platform(priv->netns);
nm_platform_link_set_down(platform, priv->ip_ifindex);
nm_platform_link_change_flags(platform, priv->ip_ifindex, IFF_UP, FALSE);
nm_platform_ip_route_flush(platform, AF_UNSPEC, priv->ip_ifindex);
nm_platform_ip_address_flush(platform, AF_UNSPEC, priv->ip_ifindex);
}
@ -1157,7 +1158,10 @@ nm_vpn_connection_apply_config(NMVpnConnection *self)
apply_parent_device_config(self);
if (priv->ip_ifindex > 0) {
nm_platform_link_set_up(nm_netns_get_platform(priv->netns), priv->ip_ifindex, NULL);
nm_platform_link_change_flags(nm_netns_get_platform(priv->netns),
priv->ip_ifindex,
IFF_UP,
TRUE);
if (priv->ip4_config) {
nm_assert(priv->ip_ifindex == nm_ip4_config_get_ifindex(priv->ip4_config));

View file

@ -7485,34 +7485,6 @@ link_change_flags(NMPlatform *platform, int ifindex, unsigned flags_mask, unsign
return do_change_link(platform, CHANGE_LINK_TYPE_UNSPEC, ifindex, nlmsg, NULL);
}
static gboolean
link_set_up(NMPlatform *platform, int ifindex, gboolean *out_no_firmware)
{
int r;
r = link_change_flags(platform, ifindex, IFF_UP, IFF_UP);
NM_SET_OUT(out_no_firmware, (r == -NME_PL_NO_FIRMWARE));
return r >= 0;
}
static gboolean
link_set_down(NMPlatform *platform, int ifindex)
{
return (link_change_flags(platform, ifindex, IFF_UP, 0) >= 0);
}
static gboolean
link_set_arp(NMPlatform *platform, int ifindex)
{
return (link_change_flags(platform, ifindex, IFF_NOARP, 0) >= 0);
}
static gboolean
link_set_noarp(NMPlatform *platform, int ifindex)
{
return (link_change_flags(platform, ifindex, IFF_NOARP, IFF_NOARP) >= 0);
}
static int
link_set_user_ipv6ll_enabled(NMPlatform *platform, int ifindex, gboolean enabled)
{
@ -9664,10 +9636,7 @@ nm_linux_platform_class_init(NMLinuxPlatformClass *klass)
platform_class->link_set_netns = link_set_netns;
platform_class->link_set_up = link_set_up;
platform_class->link_set_down = link_set_down;
platform_class->link_set_arp = link_set_arp;
platform_class->link_set_noarp = link_set_noarp;
platform_class->link_change_flags = link_change_flags;
platform_class->link_set_user_ipv6ll_enabled = link_set_user_ipv6ll_enabled;
platform_class->link_set_token = link_set_token;

View file

@ -1873,76 +1873,28 @@ nm_platform_link_set_bridge_vlans(NMPlatform * self,
}
/**
* nm_platform_link_set_up:
* nm_platform_link_change_flags_full:
* @self: platform instance
* @ifindex: Interface index
* @out_no_firmware: (allow-none): if the failure reason is due to missing firmware.
* @ifindex: interface index
* @flags_mask: flag mask to be set
* @flags_set: flag to be set on the flag mask
*
* Change the interface flag mask to the value specified.
*
* Returns: nm-errno code.
*
* Bring the interface up.
*/
gboolean
nm_platform_link_set_up(NMPlatform *self, int ifindex, gboolean *out_no_firmware)
int
nm_platform_link_change_flags_full(NMPlatform *self,
int ifindex,
unsigned flags_mask,
unsigned flags_set)
{
_CHECK_SELF(self, klass, FALSE);
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(ifindex > 0, -NME_BUG);
_LOG3D("link: setting up");
return klass->link_set_up(self, ifindex, out_no_firmware);
}
/**
* nm_platform_link_set_down:
* @self: platform instance
* @ifindex: Interface index
*
* Take the interface down.
*/
gboolean
nm_platform_link_set_down(NMPlatform *self, int ifindex)
{
_CHECK_SELF(self, klass, FALSE);
g_return_val_if_fail(ifindex > 0, FALSE);
_LOG3D("link: setting down");
return klass->link_set_down(self, ifindex);
}
/**
* nm_platform_link_set_arp:
* @self: platform instance
* @ifindex: Interface index
*
* Enable ARP on the interface.
*/
gboolean
nm_platform_link_set_arp(NMPlatform *self, int ifindex)
{
_CHECK_SELF(self, klass, FALSE);
g_return_val_if_fail(ifindex >= 0, FALSE);
_LOG3D("link: setting arp");
return klass->link_set_arp(self, ifindex);
}
/**
* nm_platform_link_set_noarp:
* @self: platform instance
* @ifindex: Interface index
*
* Disable ARP on the interface.
*/
gboolean
nm_platform_link_set_noarp(NMPlatform *self, int ifindex)
{
_CHECK_SELF(self, klass, FALSE);
g_return_val_if_fail(ifindex >= 0, FALSE);
_LOG3D("link: setting noarp");
return klass->link_set_noarp(self, ifindex);
return klass->link_change_flags(self, ifindex, flags_mask, flags_set);
}
/**

View file

@ -1091,10 +1091,10 @@ typedef struct {
gboolean (*link_delete)(NMPlatform *self, int ifindex);
gboolean (*link_refresh)(NMPlatform *self, int ifindex);
gboolean (*link_set_netns)(NMPlatform *self, int ifindex, int netns_fd);
gboolean (*link_set_up)(NMPlatform *self, int ifindex, gboolean *out_no_firmware);
gboolean (*link_set_down)(NMPlatform *self, int ifindex);
gboolean (*link_set_arp)(NMPlatform *self, int ifindex);
gboolean (*link_set_noarp)(NMPlatform *self, int ifindex);
int (*link_change_flags)(NMPlatform *platform,
int ifindex,
unsigned flags_mask,
unsigned flags_set);
int (*link_set_user_ipv6ll_enabled)(NMPlatform *self, int ifindex, gboolean enabled);
gboolean (*link_set_token)(NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId iid);
@ -1817,10 +1817,28 @@ void nm_platform_process_events(NMPlatform *self);
const NMPlatformLink *
nm_platform_process_events_ensure_link(NMPlatform *self, int ifindex, const char *ifname);
gboolean nm_platform_link_set_up(NMPlatform *self, int ifindex, gboolean *out_no_firmware);
gboolean nm_platform_link_set_down(NMPlatform *self, int ifindex);
gboolean nm_platform_link_set_arp(NMPlatform *self, int ifindex);
gboolean nm_platform_link_set_noarp(NMPlatform *self, int ifindex);
int nm_platform_link_change_flags_full(NMPlatform *self,
int ifindex,
unsigned flags_mask,
unsigned flags_set);
/**
* nm_platform_link_change_flags:
* @self: platform instance
* @ifindex: interface index
* @value: flag to be set
* @set: value to be set
*
* Change the interface flag to the value set.
*
* Returns: nm-errno code.
*
*/
static inline int
nm_platform_link_change_flags(NMPlatform *self, int ifindex, unsigned value, gboolean set)
{
return nm_platform_link_change_flags_full(self, ifindex, value, set ? value : 0u);
}
const char *nm_platform_link_get_udi(NMPlatform *self, int ifindex);
const char *nm_platform_link_get_path(NMPlatform *self, int ifindex);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff