static void release_slave (NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceBond *self = NM_DEVICE_BOND (device); gboolean success, no_firmware = FALSE; if (configure) { success = nm_platform_link_release (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) { _LOGI (LOGD_BOND, "released bond slave %s", nm_device_get_ip_iface (slave)); } else { _LOGW (LOGD_BOND, "failed to release bond slave %s", nm_device_get_ip_iface (slave)); } /* Kernel bonding code "closes" the slave when releasing it, (which clears * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released slave. */ if (!nm_device_bring_up (slave, TRUE, &no_firmware)) _LOGW (LOGD_BOND, "released bond slave could not be brought up."); } else { _LOGI (LOGD_BOND, "bond slave %s was released", nm_device_get_ip_iface (slave)); } }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection) { gboolean success; NMSettingBridgePort *s_port; const char *iface = nm_device_get_ip_iface (device); const char *slave_iface = nm_device_get_ip_iface (slave); success = nm_system_bridge_attach (nm_device_get_ip_ifindex (device), iface, nm_device_get_ip_ifindex (slave), slave_iface); if (!success) return FALSE; /* Set port properties */ s_port = nm_connection_get_setting_bridge_port (connection); if (s_port) { set_sysfs_uint (slave_iface, G_OBJECT (s_port), NM_SETTING_BRIDGE_PORT_PRIORITY, "brport", "priority", TRUE, FALSE); set_sysfs_uint (slave_iface, G_OBJECT (s_port), NM_SETTING_BRIDGE_PORT_PATH_COST, "brport", "path_cost", TRUE, FALSE); set_sysfs_uint (slave_iface, G_OBJECT (s_port), NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, "brport", "hairpin_mode", FALSE, FALSE); } nm_log_info (LOGD_BRIDGE, "(%s): attached bridge port %s", iface, slave_iface); g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES); return TRUE; }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { gboolean success = TRUE, no_firmware = FALSE; const char *iface = nm_device_get_ip_iface (device); const char *slave_iface = nm_device_get_ip_iface (slave); nm_device_master_check_slave_physical_port (device, slave, LOGD_BOND); if (configure) { nm_device_take_down (slave, TRUE); success = nm_platform_link_enslave (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); } if (success) { nm_log_info (LOGD_BOND, "(%s): enslaved bond slave %s", iface, slave_iface); g_object_notify (G_OBJECT (device), "slaves"); } return success; }
static void release_slave (NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceTeam *self = NM_DEVICE_TEAM (device); gboolean success, no_firmware = FALSE; if (configure) { success = nm_platform_link_release (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) _LOGI (LOGD_TEAM, "released team port %s", nm_device_get_ip_iface (slave)); else _LOGW (LOGD_TEAM, "failed to release team port %s", nm_device_get_ip_iface (slave)); /* Kernel team code "closes" the port when releasing it, (which clears * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released port. */ if (!nm_device_bring_up (slave, TRUE, &no_firmware)) _LOGW (LOGD_TEAM, "released team port %s could not be brought up", nm_device_get_ip_iface (slave)); } else _LOGI (LOGD_TEAM, "team port %s was released", nm_device_get_ip_iface (slave)); }
static void release_slave (NMDevice *device, NMDevice *slave, gboolean configure) { NMDeviceBridge *self = NM_DEVICE_BRIDGE (device); gboolean success; if (configure) { success = nm_platform_link_release (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); if (success) { _LOGI (LOGD_BRIDGE, "detached bridge port %s", nm_device_get_ip_iface (slave)); } else { _LOGW (LOGD_BRIDGE, "failed to detach bridge port %s", nm_device_get_ip_iface (slave)); } } else { _LOGI (LOGD_BRIDGE, "bridge port %s was detached", nm_device_get_ip_iface (slave)); } }
static gboolean release_slave (NMDevice *device, NMDevice *slave) { gboolean success, no_firmware = FALSE; success = nm_platform_link_release (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_log_info (LOGD_BOND, "(%s): released bond slave %s (success %d)", nm_device_get_ip_iface (device), nm_device_get_ip_iface (slave), success); g_object_notify (G_OBJECT (device), "slaves"); /* Kernel bonding code "closes" the slave when releasing it, (which clears * IFF_UP), so we must bring it back up here to ensure carrier changes and * other state is noticed by the now-released slave. */ if (!nm_device_bring_up (slave, TRUE, &no_firmware)) { nm_log_warn (LOGD_BOND, "(%s): released bond slave could not be brought up.", nm_device_get_iface (slave)); } return success; }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { NMDeviceBond *self = NM_DEVICE_BOND (device); gboolean success = TRUE, no_firmware = FALSE; const char *slave_iface = nm_device_get_ip_iface (slave); nm_device_master_check_slave_physical_port (device, slave, LOGD_BOND); if (configure) { nm_device_take_down (slave, TRUE); success = nm_platform_link_enslave (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); if (!success) return FALSE; _LOGI (LOGD_BOND, "enslaved bond slave %s", slave_iface); } else _LOGI (LOGD_BOND, "bond slave %s was enslaved", slave_iface); return TRUE; }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { #if WITH_TEAMDCTL NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device); #endif gboolean success = TRUE, no_firmware = FALSE; const char *iface = nm_device_get_ip_iface (device); const char *slave_iface = nm_device_get_ip_iface (slave); NMSettingTeamPort *s_team_port; nm_device_master_check_slave_physical_port (device, slave, LOGD_TEAM); if (configure) { nm_device_take_down (slave, TRUE); s_team_port = nm_connection_get_setting_team_port (connection); if (s_team_port) { const char *config = nm_setting_team_port_get_config (s_team_port); if (config) { #if WITH_TEAMDCTL if (!priv->tdc) { nm_log_warn (LOGD_TEAM, "(%s): enslaved team port %s config not changed, not connected to teamd", iface, slave_iface); } else { int err; char *sanitized_config; sanitized_config = g_strdelimit (g_strdup (config), "\r\n", ' '); err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, sanitized_config); g_free (sanitized_config); if (err != 0) { nm_log_err (LOGD_TEAM, "(%s): failed to update config for port %s (err=%d)", iface, slave_iface, err); return FALSE; } } #else nm_log_warn (LOGD_TEAM, "(%s): enslaved team port %s config not changed due to lack of Teamd control support", iface, slave_iface); #endif } } success = nm_platform_link_enslave (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); } if (success) { nm_log_info (LOGD_TEAM, "(%s): enslaved team port %s", iface, slave_iface); g_object_notify (G_OBJECT (device), "slaves"); } return success; }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { NMDeviceTeam *self = NM_DEVICE_TEAM (device); NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device); gboolean success = TRUE, no_firmware = FALSE; const char *slave_iface = nm_device_get_ip_iface (slave); NMSettingTeamPort *s_team_port; nm_device_master_check_slave_physical_port (device, slave, LOGD_TEAM); if (configure) { nm_device_take_down (slave, TRUE); s_team_port = nm_connection_get_setting_team_port (connection); if (s_team_port) { const char *config = nm_setting_team_port_get_config (s_team_port); if (config) { if (!priv->tdc) { _LOGW (LOGD_TEAM, "enslaved team port %s config not changed, not connected to teamd", slave_iface); } else { int err; char *sanitized_config; sanitized_config = g_strdelimit (g_strdup (config), "\r\n", ' '); err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, sanitized_config); g_free (sanitized_config); if (err != 0) { _LOGE (LOGD_TEAM, "failed to update config for port %s (err=%d)", slave_iface, err); return FALSE; } } } } success = nm_platform_link_enslave (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); if (!success) return FALSE; _LOGI (LOGD_TEAM, "enslaved team port %s", slave_iface); } else _LOGI (LOGD_TEAM, "team port %s was enslaved", slave_iface); g_object_notify (G_OBJECT (device), NM_DEVICE_TEAM_SLAVES); return TRUE; }
static gboolean release_slave (NMDevice *device, NMDevice *slave) { gboolean success; success = nm_platform_link_release (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_log_info (LOGD_BRIDGE, "(%s): detached bridge port %s (success %d)", nm_device_get_ip_iface (device), nm_device_get_ip_iface (slave), success); g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES); return success; }
void _nm_audit_manager_log_device_op (NMAuditManager *self, const char *file, guint line, const char *func, const char *op, NMDevice *device, gboolean result, gpointer subject_context, const char *reason) { gs_unref_ptrarray GPtrArray *fields = NULL; AuditField interface_field = { }, ifindex_field = { }; int ifindex; g_return_if_fail (op); g_return_if_fail (device); fields = g_ptr_array_new (); _audit_field_init_string (&interface_field, "interface", nm_device_get_ip_iface (device), TRUE, BACKEND_ALL); g_ptr_array_add (fields, &interface_field); ifindex = nm_device_get_ip_ifindex (device); if (ifindex > 0) { _audit_field_init_uint (&ifindex_field, "ifindex", ifindex, BACKEND_ALL); g_ptr_array_add (fields, &ifindex_field); } _audit_log_helper (self, fields, file, line, func, op, result, subject_context, reason); }
gboolean nm_modem_hw_bring_up (NMModem *self, NMDevice *device, gboolean *no_firmware) { int ifindex = nm_device_get_ip_ifindex (device); return ifindex > 0 ? nm_system_iface_set_up (ifindex, TRUE, no_firmware) : TRUE; }
gboolean nm_modem_hw_is_up (NMModem *self, NMDevice *device) { int ifindex = nm_device_get_ip_ifindex (device); return ifindex > 0 ? nm_system_iface_is_up (ifindex) : TRUE; }
static gboolean real_hw_bring_up (NMDevice *dev, gboolean *no_firmware) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (dev); if (!priv->enabled || !priv->wimaxd_enabled) return FALSE; return nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), TRUE, no_firmware); }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { if (configure) { if (!nm_platform_link_enslave (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave))) return FALSE; commit_slave_options (slave, nm_connection_get_setting_bridge_port (connection)); } nm_log_info (LOGD_BRIDGE, "(%s): attached bridge port %s", nm_device_get_ip_iface (device), nm_device_get_ip_iface (slave)); g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES); return TRUE; }
static void real_deactivate (NMModem *self, NMDevice *device) { NMModemPrivate *priv; int ifindex; g_return_if_fail (self != NULL); g_return_if_fail (NM_IS_MODEM (self)); g_return_if_fail (device != NULL); g_return_if_fail (NM_IS_DEVICE (device)); priv = NM_MODEM_GET_PRIVATE (self); priv->secrets_tries = 0; if (priv->act_request) { cancel_get_secrets (self); g_object_unref (priv->act_request); priv->act_request = NULL; } if (priv->call) { dbus_g_proxy_cancel_call (priv->proxy, priv->call); priv->call = NULL; } priv->in_bytes = priv->out_bytes = 0; if (priv->ppp_manager) { g_object_unref (priv->ppp_manager); priv->ppp_manager = NULL; } switch (priv->ip_method) { case MM_MODEM_IP_METHOD_PPP: break; case MM_MODEM_IP_METHOD_STATIC: case MM_MODEM_IP_METHOD_DHCP: ifindex = nm_device_get_ip_ifindex (device); if (ifindex >= 0) { /* FIXME: use AF_UNSPEC here when we have IPv6 support */ nm_system_iface_flush_routes (ifindex, AF_INET); nm_system_iface_flush_addresses (ifindex, AF_UNSPEC); nm_system_iface_set_up (ifindex, FALSE, NULL); } break; default: nm_log_err (LOGD_MB, "unknown IP method %d", priv->ip_method); break; } }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { NMDeviceBridge *self = NM_DEVICE_BRIDGE (device); if (configure) { if (!nm_platform_link_enslave (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave))) return FALSE; commit_slave_options (slave, nm_connection_get_setting_bridge_port (connection)); _LOGI (LOGD_BRIDGE, "attached bridge port %s", nm_device_get_ip_iface (slave)); } else { _LOGI (LOGD_BRIDGE, "bridge port %s was attached", nm_device_get_ip_iface (slave)); } return TRUE; }
static void realize_start_notify (NMDevice *device, const NMPlatformLink *plink) { NMDeviceGeneric *self = NM_DEVICE_GENERIC (device); NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self); int ifindex; NM_DEVICE_CLASS (nm_device_generic_parent_class)->realize_start_notify (device, plink); g_clear_pointer (&priv->type_description, g_free); ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self)); if (ifindex > 0) priv->type_description = g_strdup (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex)); }
static void constructed (GObject *object) { NMDeviceGeneric *self = NM_DEVICE_GENERIC (object); NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self); if (!priv->type_description) { int ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self)); if (ifindex != 0) priv->type_description = g_strdup (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex)); } G_OBJECT_CLASS (nm_device_generic_parent_class)->constructed (object); }
static gboolean hw_bring_up (NMDevice *dev, gboolean *no_firmware) { gboolean success, carrier; guint32 caps; success = nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), TRUE, no_firmware); if (success) { caps = nm_device_get_capabilities (dev); if (caps & NM_DEVICE_CAP_CARRIER_DETECT) { carrier = get_carrier_sync (NM_DEVICE_WIRED (dev)); set_carrier (NM_DEVICE_WIRED (dev), carrier, carrier ? FALSE : TRUE); } } return success; }
static void constructed (GObject *object) { NMDeviceVlan *self = NM_DEVICE_VLAN (object); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); int ifindex = nm_device_get_ifindex (NM_DEVICE (self)); int parent_ifindex = -1, itype; int vlan_id; if (G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed) G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed (object); if (!priv->parent) { _LOGE (LOGD_VLAN, "no parent specified."); priv->invalid = TRUE; return; } itype = nm_platform_link_get_type (ifindex); if (itype != NM_LINK_TYPE_VLAN) { _LOGE (LOGD_VLAN, "failed to get VLAN interface type."); priv->invalid = TRUE; return; } if (!nm_platform_vlan_get_info (ifindex, &parent_ifindex, &vlan_id)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info."); priv->invalid = TRUE; return; } if ( parent_ifindex < 0 || parent_ifindex != nm_device_get_ip_ifindex (priv->parent) || vlan_id < 0) { _LOGW (LOGD_VLAN, "VLAN parent ifindex (%d) or VLAN ID (%d) invalid.", parent_ifindex, priv->vlan_id); priv->invalid = TRUE; return; } priv->vlan_id = vlan_id; _LOGI (LOGD_HW | LOGD_VLAN, "VLAN ID %d with parent %s", priv->vlan_id, nm_device_get_iface (priv->parent)); }
static void deactivate_cleanup (NMModem *self, NMDevice *device) { NMModemPrivate *priv; int ifindex; g_return_if_fail (NM_IS_MODEM (self)); priv = NM_MODEM_GET_PRIVATE (self); priv->secrets_tries = 0; if (priv->act_request) { cancel_get_secrets (self); g_object_unref (priv->act_request); priv->act_request = NULL; } priv->in_bytes = priv->out_bytes = 0; nm_exported_object_clear_and_unexport (&priv->ppp_manager); if (device) { g_return_if_fail (NM_IS_DEVICE (device)); if (priv->ip4_method == NM_MODEM_IP_METHOD_STATIC || priv->ip4_method == NM_MODEM_IP_METHOD_AUTO || priv->ip6_method == NM_MODEM_IP_METHOD_STATIC || priv->ip6_method == NM_MODEM_IP_METHOD_AUTO) { ifindex = nm_device_get_ip_ifindex (device); if (ifindex > 0) { nm_route_manager_route_flush (nm_route_manager_get (), ifindex); nm_platform_address_flush (NM_PLATFORM_GET, ifindex); nm_platform_link_set_down (NM_PLATFORM_GET, ifindex); } } } priv->ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; priv->ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; g_free (priv->ppp_iface); priv->ppp_iface = NULL; }
void nm_modem_ip4_pre_commit (NMModem *modem, NMDevice *device, NMIP4Config *config) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (modem); /* If the modem has an ethernet-type data interface (ie, not PPP and thus * not point-to-point) and IP config has a /32 prefix, then we assume that * ARP will be pointless and we turn it off. */ if ( priv->ip_method == MM_MODEM_IP_METHOD_STATIC || priv->ip_method == MM_MODEM_IP_METHOD_DHCP) { NMIP4Address *addr = nm_ip4_config_get_address (config, 0); g_assert (addr); if (nm_ip4_address_get_prefix (addr) == 32) nm_system_iface_set_arp (nm_device_get_ip_ifindex (device), FALSE); } }
void nm_modem_ip4_pre_commit (NMModem *modem, NMDevice *device, NMIP4Config *config) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (modem); /* If the modem has an ethernet-type data interface (ie, not PPP and thus * not point-to-point) and IP config has a /32 prefix, then we assume that * ARP will be pointless and we turn it off. */ 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); g_assert (address); if (address->plen == 32) nm_platform_link_set_noarp (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device)); } }
static gboolean get_carrier_sync (NMDeviceWired *self) { NMDeviceWiredPrivate *priv = NM_DEVICE_WIRED_GET_PRIVATE (self); GError *error = NULL; guint32 ifflags = 0; /* Get initial link state */ if (!nm_netlink_monitor_get_flags_sync (priv->monitor, nm_device_get_ip_ifindex (NM_DEVICE (self)), &ifflags, &error)) { nm_log_warn (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (NM_DEVICE (self)), "(%s): couldn't get carrier state: (%d) %s", nm_device_get_ip_iface (NM_DEVICE (self)), error ? error->code : -1, (error && error->message) ? error->message : "unknown"); g_clear_error (&error); } return !!(ifflags & IFF_LOWER_UP); }
static void update_hw_address (NMDevice *dev) { NMDeviceWired *self = NM_DEVICE_WIRED (dev); NMDeviceWiredPrivate *priv = NM_DEVICE_WIRED_GET_PRIVATE (self); struct rtnl_link *rtnl; struct nl_addr *addr; rtnl = nm_netlink_index_to_rtnl_link (nm_device_get_ip_ifindex (dev)); if (!rtnl) { nm_log_err (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (dev), "(%s) failed to read hardware address (error %d)", nm_device_get_iface (dev), errno); return; } addr = rtnl_link_get_addr (rtnl); if (!addr) { nm_log_err (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (dev), "(%s) no hardware address?", nm_device_get_iface (dev)); rtnl_link_put (rtnl); return; } if (nl_addr_get_len (addr) != priv->hw_addr_len) { nm_log_err (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (dev), "(%s) hardware address is wrong length (expected %d got %d)", nm_device_get_iface (dev), priv->hw_addr_len, nl_addr_get_len (addr)); } else { memcpy (&priv->hw_addr, nl_addr_get_binary_addr (addr), priv->hw_addr_len); } rtnl_link_put (rtnl); }
static void hw_take_down (NMDevice *dev) { nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), FALSE, NULL); }
static gboolean hw_is_up (NMDevice *device) { return nm_system_iface_is_up (nm_device_get_ip_ifindex (device)); }
static gboolean real_hw_bring_up (NMDevice *dev, gboolean *no_firmware) { return nm_system_iface_set_up (nm_device_get_ip_ifindex (dev), TRUE, no_firmware); }