static gboolean component_added (NMDevice *device, GObject *component) { NMDeviceVlan *self = NM_DEVICE_VLAN (device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self); NMDevice *added_device; int parent_ifindex = -1; if (priv->parent) return FALSE; if (!NM_IS_DEVICE (component)) return FALSE; added_device = NM_DEVICE (component); if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, nm_device_get_ifindex (device), &parent_ifindex, NULL)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info while checking added component."); return FALSE; } if ( parent_ifindex <= 0 || nm_device_get_ifindex (added_device) != parent_ifindex) return FALSE; nm_device_vlan_set_parent (self, added_device); /* Don't claim parent exclusively */ return FALSE; }
static void update_connection (NMDevice *device, NMConnection *connection) { NMDeviceVlan *self = NM_DEVICE_VLAN (device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); NMSettingVlan *s_vlan = nm_connection_get_setting_vlan (connection); int ifindex = nm_device_get_ifindex (device); int parent_ifindex = -1, vlan_id = -1; NMDevice *parent; const char *setting_parent, *new_parent; if (!s_vlan) { s_vlan = (NMSettingVlan *) nm_setting_vlan_new (); nm_connection_add_setting (connection, (NMSetting *) s_vlan); } if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent_ifindex, &vlan_id)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info while updating connection."); return; } if (priv->vlan_id != vlan_id) { priv->vlan_id = vlan_id; g_object_notify (G_OBJECT (device), NM_DEVICE_VLAN_ID); } if (vlan_id != nm_setting_vlan_get_id (s_vlan)) g_object_set (s_vlan, NM_SETTING_VLAN_ID, priv->vlan_id, NULL); if (parent_ifindex != NM_PLATFORM_LINK_OTHER_NETNS) parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex); else parent = NULL; nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent); /* Update parent in the connection; default to parent's interface name */ if (parent) { new_parent = nm_device_get_iface (parent); setting_parent = nm_setting_vlan_get_parent (s_vlan); if (setting_parent && nm_utils_is_uuid (setting_parent)) { NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent); if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection)) new_parent = NULL; } if (new_parent) g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, new_parent, NULL); } else g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, NULL, NULL); }
static gboolean do_vlan_get_info (char **argv) { int ifindex = parse_ifindex (*argv++); int parent; int vlanid; if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent, &vlanid)) return FALSE; printf ("%d %d\n", parent, vlanid); return TRUE; }
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 gboolean realize (NMDevice *device, NMPlatformLink *plink, GError **error) { NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); int parent_ifindex = -1, vlan_id = -1; NMDevice *parent; g_return_val_if_fail (plink, FALSE); g_assert (plink->type == NM_LINK_TYPE_VLAN); if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, plink->ifindex, &parent_ifindex, &vlan_id)) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "(%s): failed to read VLAN properties", plink->name); return FALSE; } if (vlan_id < 0) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "(%s): VLAN ID invalid", plink->name); return FALSE; } if (parent_ifindex != NM_PLATFORM_LINK_OTHER_NETNS) { parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex); if (!parent) { nm_log_dbg (LOGD_HW, "(%s): VLAN parent interface unknown", plink->name); g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "(%s): VLAN parent interface unknown", plink->name); return FALSE; } } else parent = NULL; g_warn_if_fail (priv->parent == NULL); nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent); priv->vlan_id = vlan_id; return TRUE; }
static void dump_interface (NMPlatformLink *link) { GArray *ip6_addresses; GArray *ip4_addresses; const NMPlatformIP6Address *ip6_address; const NMPlatformIP4Address *ip4_address; char addrstr[INET6_ADDRSTRLEN]; GArray *ip6_routes; GArray *ip4_routes; const NMPlatformIP6Route *ip6_route; const NMPlatformIP4Route *ip4_route; char networkstr[INET6_ADDRSTRLEN]; char gatewaystr[INET6_ADDRSTRLEN]; int vlan_id, vlan_parent; const char *address; size_t addrlen; int i; g_assert (link->up || !link->connected); printf ("%d: %s: %s", link->ifindex, link->name, link->type_name); if (link->up) printf (" %s", link->connected ? "CONNECTED" : "DISCONNECTED"); else printf (" DOWN"); if (!link->arp) printf (" noarp"); if (link->master) printf (" master %d", link->master); if (link->parent) printf (" parent %d", link->parent); printf (" mtu %d", link->mtu); printf ("\n"); if (link->driver) printf (" driver: %s\n", link->driver); printf (" UDI: %s\n", link->udi); nm_platform_vlan_get_info (link->ifindex, &vlan_parent, &vlan_id); if (vlan_parent) printf (" vlan parent %d id %d\n", vlan_parent, vlan_id); if (nm_platform_link_is_software (link->ifindex)) printf (" class software\n"); if (nm_platform_link_supports_slaves (link->ifindex)) printf (" class supports-slaves\n"); if (nm_platform_link_supports_carrier_detect (link->ifindex)) printf (" feature carrier-detect\n"); if (nm_platform_link_supports_vlans (link->ifindex)) printf (" feature vlans\n"); address = nm_platform_link_get_address (link->ifindex, &addrlen); if (address) { printf (" link-address "); for (i = 0; i < addrlen; i++) printf ("%s%02hhx", i ? ":" : "", address[i]); printf ("\n"); } ip4_addresses = nm_platform_ip4_address_get_all (link->ifindex); ip6_addresses = nm_platform_ip6_address_get_all (link->ifindex); g_assert (ip4_addresses); g_assert (ip6_addresses); for (i = 0; i < ip4_addresses->len; i++) { ip4_address = &g_array_index (ip4_addresses, NMPlatformIP4Address, i); inet_ntop (AF_INET, &ip4_address->address, addrstr, sizeof (addrstr)); printf (" ip4-address %s/%d\n", addrstr, ip4_address->plen); } for (i = 0; i < ip6_addresses->len; i++) { ip6_address = &g_array_index (ip6_addresses, NMPlatformIP6Address, i); inet_ntop (AF_INET6, &ip6_address->address, addrstr, sizeof (addrstr)); printf (" ip6-address %s/%d\n", addrstr, ip6_address->plen); } g_array_unref (ip4_addresses); g_array_unref (ip6_addresses); ip4_routes = nm_platform_ip4_route_get_all (link->ifindex); ip6_routes = nm_platform_ip6_route_get_all (link->ifindex); g_assert (ip4_routes); g_assert (ip6_routes); for (i = 0; i < ip4_routes->len; i++) { ip4_route = &g_array_index (ip4_routes, NMPlatformIP4Route, i); inet_ntop (AF_INET, &ip4_route->network, networkstr, sizeof (networkstr)); inet_ntop (AF_INET, &ip4_route->gateway, gatewaystr, sizeof (gatewaystr)); printf (" ip4-route %s/%d via %s\n", networkstr, ip4_route->plen, gatewaystr); } for (i = 0; i < ip6_routes->len; i++) { ip6_route = &g_array_index (ip6_routes, NMPlatformIP6Route, i); inet_ntop (AF_INET6, &ip6_route->network, networkstr, sizeof (networkstr)); inet_ntop (AF_INET6, &ip6_route->gateway, gatewaystr, sizeof (gatewaystr)); printf (" ip6-route %s/%d via %s\n", networkstr, ip6_route->plen, gatewaystr); } g_array_unref (ip4_routes); g_array_unref (ip6_routes); }