char * nm_netlink_index_to_iface (int idx) { NMNetlinkMonitor *self; NMNetlinkMonitorPrivate *priv; char *buf = NULL; g_return_val_if_fail (idx >= 0, NULL); self = nm_netlink_monitor_get (); priv = NM_NETLINK_MONITOR_GET_PRIVATE (self); buf = g_malloc0 (MAX_IFACE_LEN); g_assert (buf); nl_cache_refill (priv->nlh_sync, priv->link_cache); if (!rtnl_link_i2name (priv->link_cache, idx, buf, MAX_IFACE_LEN - 1)) { nm_log_warn (LOGD_HW, "(%d) failed to find interface name for index", idx); g_free (buf); buf = NULL; } g_object_unref (self); return buf; }
static void nm_ip6_manager_init (NMIP6Manager *manager) { NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager); priv->devices = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) nm_ip6_device_destroy); priv->monitor = nm_netlink_monitor_get (); nm_netlink_monitor_subscribe (priv->monitor, RTNLGRP_IPV6_IFADDR, NULL); nm_netlink_monitor_subscribe (priv->monitor, RTNLGRP_IPV6_PREFIX, NULL); nm_netlink_monitor_subscribe (priv->monitor, RTNLGRP_IPV6_ROUTE, NULL); nm_netlink_monitor_subscribe (priv->monitor, RTNLGRP_ND_USEROPT, NULL); nm_netlink_monitor_subscribe (priv->monitor, RTNLGRP_LINK, NULL); priv->netlink_id = g_signal_connect (priv->monitor, "notification", G_CALLBACK (netlink_notification), manager); priv->nlh = nm_netlink_get_default_handle (); rtnl_addr_alloc_cache (priv->nlh, &priv->addr_cache); g_warn_if_fail (priv->addr_cache != NULL); rtnl_route_alloc_cache (priv->nlh, NETLINK_ROUTE, NL_AUTO_PROVIDE, &priv->route_cache); g_warn_if_fail (priv->route_cache != NULL); }
struct nl_sock * nm_netlink_get_default_handle (void) { NMNetlinkMonitor *self; struct nl_sock *nlh; self = nm_netlink_monitor_get (); nlh = NM_NETLINK_MONITOR_GET_PRIVATE (self)->nlh_sync; return nlh; }
int nm_netlink_iface_to_index (const char *iface) { NMNetlinkMonitor *self; NMNetlinkMonitorPrivate *priv; int idx; g_return_val_if_fail (iface != NULL, -1); self = nm_netlink_monitor_get (); priv = NM_NETLINK_MONITOR_GET_PRIVATE (self); nl_cache_refill (priv->nlh_sync, priv->link_cache); idx = rtnl_link_name2i (priv->link_cache, iface); g_object_unref (self); return idx; }
struct rtnl_link * nm_netlink_index_to_rtnl_link (int idx) { NMNetlinkMonitor *self; NMNetlinkMonitorPrivate *priv; struct rtnl_link *ret = NULL; if (idx <= 0) return NULL; self = nm_netlink_monitor_get (); priv = NM_NETLINK_MONITOR_GET_PRIVATE (self); nl_cache_refill (priv->nlh_sync, priv->link_cache); ret = rtnl_link_get (priv->link_cache, idx); g_object_unref (self); return ret; }
static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { GObject *object; NMDeviceWiredPrivate *priv; NMDevice *self; guint32 caps; object = G_OBJECT_CLASS (nm_device_wired_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; self = NM_DEVICE (object); priv = NM_DEVICE_WIRED_GET_PRIVATE (self); nm_log_dbg (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (NM_DEVICE (self)), "(%s): kernel ifindex %d", nm_device_get_iface (NM_DEVICE (self)), nm_device_get_ifindex (NM_DEVICE (self))); if (nm_device_get_device_type (self) == NM_DEVICE_TYPE_ETHERNET) { priv->hw_addr_type = ARPHRD_ETHER; priv->hw_addr_len = ETH_ALEN; } else if (nm_device_get_device_type (self) == NM_DEVICE_TYPE_INFINIBAND) { priv->hw_addr_type = ARPHRD_INFINIBAND; priv->hw_addr_len = INFINIBAND_ALEN; } else if (nm_device_get_device_type (self) == NM_DEVICE_TYPE_BOND) { /* We may not know the hardware address type until a slave is added */ priv->hw_addr_type = ARPHRD_ETHER; priv->hw_addr_len = ETH_ALEN; } else g_assert_not_reached (); caps = nm_device_get_capabilities (self); if (caps & NM_DEVICE_CAP_CARRIER_DETECT) { /* Only listen to netlink for cards that support carrier detect */ priv->monitor = nm_netlink_monitor_get (); priv->link_connected_id = g_signal_connect (priv->monitor, "carrier-on", G_CALLBACK (carrier_on), self); priv->link_disconnected_id = g_signal_connect (priv->monitor, "carrier-off", G_CALLBACK (carrier_off), self); priv->carrier = get_carrier_sync (NM_DEVICE_WIRED (self)); nm_log_info (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (NM_DEVICE (self)), "(%s): carrier is %s", nm_device_get_iface (NM_DEVICE (self)), priv->carrier ? "ON" : "OFF"); /* Request link state again just in case an error occurred getting the * initial link state. */ nm_netlink_monitor_request_status (priv->monitor); } else { nm_log_info (LOGD_HW | NM_DEVICE_WIRED_LOG_LEVEL (NM_DEVICE (self)), "(%s): driver '%s' does not support carrier detection.", nm_device_get_iface (self), nm_device_get_driver (self)); priv->carrier = TRUE; } return object; }