platform: signal missing firmware in nm_platform_set_up()

Don't use nm_platform_get_error() anymore.
This commit is contained in:
Thomas Haller 2015-06-15 17:41:27 +02:00
parent 8334171a4e
commit c1a945b95d
14 changed files with 56 additions and 42 deletions

View file

@ -352,7 +352,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_reason)
_LOGD (LOGD_ADSL, "ATM setup successful");
/* otherwise we're good for stage3 */
nm_platform_link_set_up (NM_PLATFORM_GET, priv->nas_ifindex);
nm_platform_link_set_up (NM_PLATFORM_GET, priv->nas_ifindex, NULL);
ret = NM_ACT_STAGE_RETURN_SUCCESS;
} else if (g_strcmp0 (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA) == 0) {

View file

@ -598,7 +598,7 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface)
nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, priv->ip_ifindex, TRUE);
if (!nm_platform_link_is_up (NM_PLATFORM_GET, priv->ip_ifindex))
nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex);
nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL);
} else {
/* Device IP interface must always be a kernel network interface */
_LOGW (LOGD_HW, "failed to look up interface index");
@ -5527,7 +5527,7 @@ nm_device_activate_ip4_config_commit (gpointer user_data)
/* Interface must be IFF_UP before IP config can be applied */
ip_ifindex = nm_device_get_ip_ifindex (self);
if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_uses_assumed_connection (self)) {
nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex);
nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex, NULL);
if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex))
_LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self));
}
@ -5648,7 +5648,7 @@ nm_device_activate_ip6_config_commit (gpointer user_data)
/* Interface must be IFF_UP before IP config can be applied */
ip_ifindex = nm_device_get_ip_ifindex (self);
if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_uses_assumed_connection (self)) {
nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex);
nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex, NULL);
if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex))
_LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self));
}
@ -6792,9 +6792,7 @@ bring_up (NMDevice *self, gboolean *no_firmware)
return TRUE;
}
result = nm_platform_link_set_up (NM_PLATFORM_GET, ifindex);
if (no_firmware)
*no_firmware = nm_platform_get_error (NM_PLATFORM_GET) == NM_PLATFORM_ERROR_NO_FIRMWARE;
result = nm_platform_link_set_up (NM_PLATFORM_GET, ifindex, no_firmware);
/* Store carrier immediately. */
if (result && nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT))

View file

@ -477,7 +477,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);
nm_platform_link_set_up (NM_PLATFORM_GET, 1, NULL);
success = TRUE;

View file

@ -363,11 +363,14 @@ link_changed (NMPlatform *platform, NMFakePlatformLink *device, gboolean raise_s
}
static gboolean
link_set_up (NMPlatform *platform, int ifindex)
link_set_up (NMPlatform *platform, int ifindex, gboolean *out_no_firmware)
{
NMFakePlatformLink *device = link_get (platform, ifindex);
gboolean up, connected;
if (out_no_firmware)
*out_no_firmware = FALSE;
if (!device)
return FALSE;

View file

@ -2697,7 +2697,7 @@ do_delete_object (NMPlatform *platform, const NMPObject *obj_id, const struct nl
return nle >= 0;
}
static gboolean
static NMPlatformError
do_change_link (NMPlatform *platform, struct rtnl_link *nlo, gboolean complete_from_cache)
{
int nle;
@ -2706,7 +2706,7 @@ do_change_link (NMPlatform *platform, struct rtnl_link *nlo, gboolean complete_f
ifindex = rtnl_link_get_ifindex (nlo);
if (ifindex <= 0)
g_return_val_if_reached (FALSE);
g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
nle = kernel_change_link (platform, nlo, &complete_from_cache2);
@ -2726,13 +2726,13 @@ do_change_link (NMPlatform *platform, struct rtnl_link *nlo, gboolean complete_f
_LOGD ("do-change-link: failure changing link %d: link does not exist in cache", ifindex);
} else
_LOGE ("do-change-link: failure changing link %d: %s (%d)", ifindex, nl_geterror (nle), -nle);
return FALSE;
return nle == -NLE_OBJ_NOTFOUND ? NM_PLATFORM_ERROR_NO_FIRMWARE : NM_PLATFORM_ERROR_UNSPECIFIED;
}
/* FIXME: as we modify the link via a separate socket, the cache is not in
* sync and we have to refetch the link. */
do_request_link (platform, ifindex, NULL, TRUE);
return TRUE;
return NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
@ -2894,7 +2894,7 @@ link_uses_arp (NMPlatform *platform, int ifindex)
return !(link_get_flags (platform, ifindex) & IFF_NOARP);
}
static gboolean
static NMPlatformError
link_change_flags (NMPlatform *platform, int ifindex, unsigned int flags, gboolean value)
{
auto_nl_object struct rtnl_link *change = _nl_rtnl_link_alloc (ifindex, NULL);
@ -2903,7 +2903,7 @@ link_change_flags (NMPlatform *platform, int ifindex, unsigned int flags, gboole
obj_cache = cache_lookup_link (platform, ifindex);
if (!obj_cache)
return FALSE;
return NM_PLATFORM_ERROR_NOT_FOUND;
rtnl_link_set_flags (change, obj_cache->link.flags);
if (value)
@ -2920,27 +2920,32 @@ link_change_flags (NMPlatform *platform, int ifindex, unsigned int flags, gboole
}
static gboolean
link_set_up (NMPlatform *platform, int ifindex)
link_set_up (NMPlatform *platform, int ifindex, gboolean *out_no_firmware)
{
return link_change_flags (platform, ifindex, IFF_UP, TRUE);
NMPlatformError plerr;
plerr = link_change_flags (platform, ifindex, IFF_UP, TRUE);
if (out_no_firmware)
*out_no_firmware = plerr == NM_PLATFORM_ERROR_NO_FIRMWARE;
return plerr == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
link_set_down (NMPlatform *platform, int ifindex)
{
return link_change_flags (platform, ifindex, IFF_UP, FALSE);
return link_change_flags (platform, ifindex, IFF_UP, FALSE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
link_set_arp (NMPlatform *platform, int ifindex)
{
return link_change_flags (platform, ifindex, IFF_NOARP, FALSE);
return link_change_flags (platform, ifindex, IFF_NOARP, FALSE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
link_set_noarp (NMPlatform *platform, int ifindex)
{
return link_change_flags (platform, ifindex, IFF_NOARP, TRUE);
return link_change_flags (platform, ifindex, IFF_NOARP, TRUE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
@ -3007,7 +3012,7 @@ link_set_user_ipv6ll_enabled (NMPlatform *platform, int ifindex, gboolean enable
rtnl_link_inet6_set_addr_gen_mode (nlo, mode);
debug ("link: change %d: set IPv6 address generation mode to %s",
ifindex, rtnl_link_inet6_addrgenmode2str (mode, buf, sizeof (buf)));
return do_change_link (platform, nlo, TRUE);
return do_change_link (platform, nlo, TRUE) == NM_PLATFORM_ERROR_SUCCESS;
}
#endif
return FALSE;
@ -3054,7 +3059,7 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size
_LOGD ("link: change %d: address %s (%lu bytes)", ifindex,
(mac = nm_utils_hwaddr_ntoa (address, length)),
(unsigned long) length);
return do_change_link (platform, change, TRUE);
return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gconstpointer
@ -3096,7 +3101,7 @@ link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu)
rtnl_link_set_mtu (change, mtu);
debug ("link: change %d: mtu %lu", ifindex, (unsigned long)mtu);
return do_change_link (platform, change, TRUE);
return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS;
}
static guint32
@ -3206,7 +3211,7 @@ vlan_set_ingress_map (NMPlatform *platform, int ifindex, int from, int to)
debug ("link: change %d: vlan ingress map %d -> %d", ifindex, from, to);
return do_change_link (platform, change, TRUE);
return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
@ -3219,7 +3224,7 @@ vlan_set_egress_map (NMPlatform *platform, int ifindex, int from, int to)
debug ("link: change %d: vlan egress map %d -> %d", ifindex, from, to);
return do_change_link (platform, change, TRUE);
return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
@ -3230,7 +3235,7 @@ link_enslave (NMPlatform *platform, int master, int slave)
rtnl_link_set_master (change, master);
debug ("link: change %d: enslave to master %d", slave, master);
return do_change_link (platform, change, TRUE);
return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean

View file

@ -1143,11 +1143,12 @@ nm_platform_link_supports_vlans (NMPlatform *self, int ifindex)
* nm_platform_link_set_up:
* @self: platform instance
* @ifindex: Interface index
* @out_no_firmware: (allow-none): if the failure reason is due to missing firmware.
*
* Bring the interface up.
*/
gboolean
nm_platform_link_set_up (NMPlatform *self, int ifindex)
nm_platform_link_set_up (NMPlatform *self, int ifindex, gboolean *out_no_firmware)
{
_CHECK_SELF (self, klass, FALSE);
reset_error (self);
@ -1156,7 +1157,7 @@ nm_platform_link_set_up (NMPlatform *self, int ifindex)
g_return_val_if_fail (klass->link_set_up, FALSE);
debug ("link: setting up '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex);
return klass->link_set_up (self, ifindex);
return klass->link_set_up (self, ifindex, out_no_firmware);
}
/**

View file

@ -429,7 +429,7 @@ typedef struct {
gboolean (*link_refresh) (NMPlatform *, int ifindex);
gboolean (*link_set_up) (NMPlatform *, int ifindex);
gboolean (*link_set_up) (NMPlatform *, int ifindex, gboolean *out_no_firmware);
gboolean (*link_set_down) (NMPlatform *, int ifindex);
gboolean (*link_set_arp) (NMPlatform *, int ifindex);
gboolean (*link_set_noarp) (NMPlatform *, int ifindex);
@ -620,7 +620,7 @@ gboolean nm_platform_link_supports_slaves (NMPlatform *self, int ifindex);
gboolean nm_platform_link_refresh (NMPlatform *self, int ifindex);
gboolean nm_platform_link_set_up (NMPlatform *self, int ifindex);
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);

View file

@ -182,7 +182,14 @@ LINK_CMD_GET_FULL (get_type, decimal, value > 0)
LINK_CMD_GET (is_software, boolean)
LINK_CMD_GET (supports_slaves, boolean)
LINK_CMD (set_up)
static gboolean
do_link_set_up (char **argv)
{
int ifindex = parse_ifindex (argv[0]);
return ifindex ? nm_platform_link_set_up (NM_PLATFORM_GET, ifindex, NULL) : FALSE;
}
LINK_CMD (set_down)
LINK_CMD (set_arp)
LINK_CMD (set_noarp)

View file

@ -175,7 +175,7 @@ test_ip4_address_external (void)
/* Looks like addresses are not announced by kerenl when the interface
* is down. Link-local IPv6 address is automatically added.
*/
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME)));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME), NULL));
/* Add/delete notification */
run_command ("ip address add %s/%d dev %s valid_lft %d preferred_lft %d",

View file

@ -38,7 +38,7 @@ test_cleanup_internal (void)
g_assert (nm_platform_dummy_add (NM_PLATFORM_GET, DEVICE_NAME, NULL) == NM_PLATFORM_ERROR_SUCCESS);
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)));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME), NULL));
ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME);
g_assert (ifindex > 0);

View file

@ -34,7 +34,7 @@ test_bogus(void)
g_assert (!nm_platform_link_get_type_name (NM_PLATFORM_GET, BOGUS_IFINDEX));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (!nm_platform_link_set_up (NM_PLATFORM_GET, BOGUS_IFINDEX));
g_assert (!nm_platform_link_set_up (NM_PLATFORM_GET, BOGUS_IFINDEX, NULL));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (!nm_platform_link_set_down (NM_PLATFORM_GET, BOGUS_IFINDEX));
error (NM_PLATFORM_ERROR_NOT_FOUND);
@ -124,7 +124,7 @@ software_add (NMLinkType link_type, const char *name)
gboolean was_up = nm_platform_link_is_up (NM_PLATFORM_GET, parent_ifindex);
parent_changed = add_signal_ifindex (NM_PLATFORM_SIGNAL_LINK_CHANGED, NM_PLATFORM_SIGNAL_CHANGED, link_callback, parent_ifindex);
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, parent_ifindex));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, parent_ifindex, NULL));
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);
@ -183,7 +183,7 @@ test_slave (int master, int type, SignalData *master_changed)
g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex));
/* Set master up */
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, master));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, master, NULL));
g_assert (nm_platform_link_is_up (NM_PLATFORM_GET, master));
accept_signals (master_changed, 1, 2);
@ -220,7 +220,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)); no_error ();
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, ifindex, NULL)); no_error ();
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);
@ -461,7 +461,7 @@ test_internal (void)
/* Up/connected */
g_assert (!nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); no_error ();
g_assert (!nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); no_error ();
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, ifindex)); no_error ();
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, ifindex, NULL)); no_error ();
g_assert (nm_platform_link_is_up (NM_PLATFORM_GET, ifindex)); no_error ();
g_assert (nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex)); no_error ();
accept_signal (link_changed);

View file

@ -327,7 +327,7 @@ setup_tests (void)
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)));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME), NULL));
g_test_add_func ("/route/ip4", test_ip4_route);
g_test_add_func ("/route/ip6", test_ip6_route);

View file

@ -652,7 +652,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
accept_signal (link_added);
free_signal (link_added);
fixture->ifindex0 = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device0");
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex0));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex0, NULL));
link_added = add_signal_ifname (NM_PLATFORM_SIGNAL_LINK_CHANGED,
NM_PLATFORM_SIGNAL_ADDED,
@ -664,7 +664,7 @@ fixture_setup (test_fixture *fixture, gconstpointer user_data)
accept_signal (link_added);
free_signal (link_added);
fixture->ifindex1 = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "nm-test-device1");
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex1));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex1, NULL));
}
static void

View file

@ -921,7 +921,7 @@ nm_vpn_connection_apply_config (NMVpnConnection *connection)
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
if (priv->ip_ifindex > 0) {
nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex);
nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL);
if (priv->ip4_config) {
if (!nm_ip4_config_commit (priv->ip4_config, priv->ip_ifindex,