static void detail_vpn (gpointer data, gpointer user_data) { NMActiveConnection *active = NM_ACTIVE_CONNECTION (data); NMConnection *connection; NMSettingConnection *s_con; NMVPNConnectionState state; const char *banner; if (!NM_IS_VPN_CONNECTION (active)) return; connection = get_connection_for_active (active); g_return_if_fail (connection != NULL); s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); g_return_if_fail (s_con != NULL); print_header ("VPN", NULL, nm_setting_connection_get_id (s_con)); state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (active)); print_string ("State", get_vpn_state_string (state)); if (nm_active_connection_get_default (active)) print_string ("Default", "yes"); else print_string ("Default", "no"); banner = nm_vpn_connection_get_banner (NM_VPN_CONNECTION (active)); if (banner) { char **lines, **iter; printf ("\n Message:\n"); lines = g_strsplit_set (banner, "\n\r", -1); for (iter = lines; *iter; iter++) { if (*iter && strlen (*iter)) printf (" %s\n", *iter); } g_strfreev (lines); } printf ("\n\n"); }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMVpnConnection *self = NM_VPN_CONNECTION (object); switch (prop_id) { case PROP_VPN_STATE: g_value_set_enum (value, nm_vpn_connection_get_vpn_state (self)); break; case PROP_BANNER: g_value_set_string (value, nm_vpn_connection_get_banner (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void update_ip6_routing_and_dns (NMPolicy *policy, gboolean force_update) { NMDnsIPConfigType dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE; NMDevice *best = NULL; NMActRequest *best_req = NULL; NMDnsManager *dns_mgr; GSList *devices = NULL, *iter; #if NOT_YET GSList *vpns; #endif NMIP6Config *ip6_config = NULL; NMIP6Address *addr; const char *ip_iface = NULL; NMConnection *connection = NULL; NMSettingConnection *s_con = NULL; const char *connection_id; best = get_best_ip6_device (policy->manager, &best_req); if (!best) goto out; if (!force_update && (best == policy->default_device6)) goto out; #if NOT_YET /* If a VPN connection is active, it is preferred */ vpns = nm_vpn_manager_get_active_connections (policy->vpn_manager); for (iter = vpns; iter; iter = g_slist_next (iter)) { NMVPNConnection *candidate = NM_VPN_CONNECTION (iter->data); NMConnection *vpn_connection; NMSettingIP6Config *s_ip6; gboolean can_default = TRUE; NMVPNConnectionState vpn_state; /* If it's marked 'never-default', don't make it default */ vpn_connection = nm_vpn_connection_get_connection (candidate); g_assert (vpn_connection); s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (vpn_connection, NM_TYPE_SETTING_IP6_CONFIG); if (s_ip6 && nm_setting_ip6_config_get_never_default (s_ip6)) can_default = FALSE; vpn_state = nm_vpn_connection_get_vpn_state (candidate); if (can_default && (vpn_state == NM_VPN_CONNECTION_STATE_ACTIVATED)) { NMIP6Config *parent_ip6; NMDevice *parent; ip_iface = nm_vpn_connection_get_ip_iface (candidate); connection = nm_vpn_connection_get_connection (candidate); ip6_config = nm_vpn_connection_get_ip6_config (candidate); addr = nm_ip6_config_get_address (ip6_config, 0); parent = nm_vpn_connection_get_parent_device (candidate); parent_ip6 = nm_device_get_ip6_config (parent); nm_system_replace_default_ip6_route_vpn (ip_iface, nm_ip6_address_get_gateway (addr), nm_vpn_connection_get_ip4_internal_gateway (candidate), nm_ip6_config_get_mss (ip4_config), nm_device_get_ip_iface (parent), nm_ip6_config_get_mss (parent_ip4)); dns_type = NM_DNS_IP_CONFIG_TYPE_VPN; } g_object_unref (candidate); } g_slist_free (vpns); #endif /* The best device gets the default route if a VPN connection didn't */ if (!ip_iface || !ip6_config) { connection = nm_act_request_get_connection (best_req); ip_iface = nm_device_get_ip_iface (best); ip6_config = nm_device_get_ip6_config (best); g_assert (ip6_config); addr = nm_ip6_config_get_address (ip6_config, 0); nm_system_replace_default_ip6_route (ip_iface, nm_ip6_address_get_gateway (addr)); dns_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE; } if (!ip_iface || !ip6_config) { nm_log_warn (LOGD_CORE, "couldn't determine IP interface (%p) or IPv6 config (%p)!", ip_iface, ip6_config); goto out; } /* Update the default active connection. Only mark the new default * active connection after setting default = FALSE on all other connections * first. The order is important, we don't want two connections marked * default at the same time ever. */ devices = nm_manager_get_devices (policy->manager); for (iter = devices; iter; iter = g_slist_next (iter)) { NMDevice *dev = NM_DEVICE (iter->data); NMActRequest *req; req = nm_device_get_act_request (dev); if (req && (req != best_req)) nm_act_request_set_default6 (req, FALSE); } dns_mgr = nm_dns_manager_get (NULL); nm_dns_manager_add_ip6_config (dns_mgr, ip_iface, ip6_config, dns_type); g_object_unref (dns_mgr); /* Now set new default active connection _after_ updating DNS info, so that * if the connection is shared dnsmasq picks up the right stuff. */ if (best_req) nm_act_request_set_default6 (best_req, TRUE); if (connection) s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); connection_id = s_con ? nm_setting_connection_get_id (s_con) : NULL; if (connection_id) { nm_log_info (LOGD_CORE, "Policy set '%s' (%s) as default for IPv6 routing and DNS.", connection_id, ip_iface); } else { nm_log_info (LOGD_CORE, "Policy set (%s) as default for IPv6 routing and DNS.", ip_iface); } out: policy->default_device6 = best; }