static gboolean device_set_ra_flags (NMIP6Device *device, guint ra_flags) { guint old_ra_flags; gchar *ra_flags_str, *old_ra_flags_str; g_return_val_if_fail (device != NULL, FALSE); if (ra_flags == device->ra_flags) return FALSE; old_ra_flags = device->ra_flags; device->ra_flags = ra_flags; if (nm_logging_level_enabled (LOGL_DEBUG)) { ra_flags_str = ra_flags_to_string (ra_flags); old_ra_flags_str = ra_flags_to_string (old_ra_flags); nm_log_dbg (LOGD_IP6, "(%s) IP6 device ra_flags: 0x%08x %s -> 0x%08x %s", device_get_iface (device), old_ra_flags, old_ra_flags_str, ra_flags, ra_flags_str); g_free (ra_flags_str); g_free (old_ra_flags_str); } return TRUE; }
static GByteArray * get_duid (NMDHCPClient *self) { static GByteArray *duid = NULL; GByteArray *copy = NULL; char *escaped; if (G_UNLIKELY (duid == NULL)) { duid = generate_duid_from_machine_id (); g_assert (duid); if (nm_logging_level_enabled (LOGL_DEBUG)) { escaped = escape_duid (duid); nm_log_dbg (LOGD_DHCP6, "Generated DUID %s", escaped); g_free (escaped); } } if (G_LIKELY (duid)) { copy = g_byte_array_sized_new (duid->len); g_byte_array_append (copy, duid->data, duid->len); } return copy; }
static void foreach_route_cb (struct nl_object *object, void *user_data) { ForeachRouteInfo *info = user_data; struct rtnl_route *route = (struct rtnl_route *) object; struct nl_addr *dst; if (info->out_route) return; if (nm_logging_level_enabled (LOGL_DEBUG)) dump_route (route); if ( info->ifindex > 0 && rtnl_route_get_oif (route) != info->ifindex) return; if ( info->scope != RT_SCOPE_UNIVERSE && rtnl_route_get_scope (route) != info->scope) return; if ( info->family != AF_UNSPEC && rtnl_route_get_family (route) != info->family) return; dst = rtnl_route_get_dst (route); /* Check for IPv6 LL and MC routes that might need to be ignored */ if ( (info->family == AF_INET6 || info->family == AF_UNSPEC) && (rtnl_route_get_family (route) == AF_INET6)) { struct in6_addr *addr = NULL; if (dst) addr = nl_addr_get_binary_addr (dst); if (addr) { if ( IN6_IS_ADDR_LINKLOCAL (addr) || IN6_IS_ADDR_MC_LINKLOCAL (addr) || (IN6_IS_ADDR_MULTICAST (addr) && (nl_addr_get_prefixlen (dst) == 8))) return; } } info->out_route = info->callback (route, dst, info->iface, info->user_data); if (info->out_route) { /* Ref the route so it sticks around after the cache is cleared */ rtnl_route_get (info->out_route); } }
gboolean nm_dhcp_client_start_ip6 (NMDHCPClient *self, NMSettingIP6Config *s_ip6, guint8 *dhcp_anycast_addr, const char *hostname, gboolean info_only) { NMDHCPClientPrivate *priv; char *escaped; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE); priv = NM_DHCP_CLIENT_GET_PRIVATE (self); g_return_val_if_fail (priv->pid == -1, FALSE); g_return_val_if_fail (priv->ipv6 == TRUE, FALSE); g_return_val_if_fail (priv->uuid != NULL, FALSE); /* If we don't have one yet, read the default DUID for this DHCPv6 client * from the client-specific persistent configuration. */ if (!priv->duid) priv->duid = NM_DHCP_CLIENT_GET_CLASS (self)->get_duid (self); if (nm_logging_level_enabled (LOGL_DEBUG)) { escaped = escape_duid (priv->duid); nm_log_dbg (LOGD_DHCP, "(%s): DHCPv6 DUID is '%s'", priv->iface, escaped); g_free (escaped); } priv->info_only = info_only; nm_log_info (LOGD_DHCP, "Activation (%s) Beginning DHCPv6 transaction (timeout in %d seconds)", priv->iface, priv->timeout); priv->pid = NM_DHCP_CLIENT_GET_CLASS (self)->ip6_start (self, s_ip6, dhcp_anycast_addr, hostname, info_only, priv->duid); if (priv->pid > 0) start_monitor (self); return priv->pid ? TRUE : FALSE; }
static NMIP6Device * process_newlink (NMIP6Manager *manager, struct nl_msg *msg) { struct nlmsghdr *hdr = nlmsg_hdr (msg); struct ifinfomsg *ifi; NMIP6Device *device; struct nlattr *tb[IFLA_MAX + 1]; struct nlattr *pi[IFLA_INET6_MAX + 1]; int err; char *flags_str = NULL; /* FIXME: we have to do this manually for now since libnl doesn't yet * support the IFLA_PROTINFO attribute of NEWLINK messages. When it does, * we can get rid of this function and just grab IFLA_PROTINFO from * nm_ip6_device_sync_from_netlink(), then get the IFLA_INET6_FLAGS out of * the PROTINFO. */ err = nlmsg_parse (hdr, sizeof (*ifi), tb, IFLA_MAX, link_policy); if (err < 0) { nm_log_dbg (LOGD_IP6, "ignoring invalid newlink netlink message " "while parsing PROTINFO attribute"); return NULL; } ifi = nlmsg_data (hdr); if (ifi->ifi_family != AF_INET6) { nm_log_dbg (LOGD_IP6, "ignoring netlink message family %d", ifi->ifi_family); return NULL; } device = nm_ip6_manager_get_device (manager, ifi->ifi_index); if (!device || device->addrconf_complete) { nm_log_dbg (LOGD_IP6, "(%s): ignoring unknown or completed device", device ? device->iface : "(none)"); return NULL; } if (!tb[IFLA_PROTINFO]) { nm_log_dbg (LOGD_IP6, "(%s): message had no PROTINFO attribute", device->iface); return NULL; } err = nla_parse_nested (pi, IFLA_INET6_MAX, tb[IFLA_PROTINFO], link_prot_policy); if (err < 0) { nm_log_dbg (LOGD_IP6, "(%s): error parsing PROTINFO flags", device->iface); return NULL; } if (!pi[IFLA_INET6_FLAGS]) { nm_log_dbg (LOGD_IP6, "(%s): message had no PROTINFO flags", device->iface); return NULL; } device->ra_flags = nla_get_u32 (pi[IFLA_INET6_FLAGS]); if (nm_logging_level_enabled (LOGL_DEBUG)) flags_str = ra_flags_to_string (device->ra_flags); nm_log_dbg (LOGD_IP6, "(%s): got IPv6 flags 0x%X%s", device->iface, device->ra_flags, flags_str ? flags_str : ""); g_free (flags_str); return device; }
static NMCmdLine * create_pppd_cmd_line (NMPPPManager *self, NMSettingPPP *setting, NMSettingPPPOE *pppoe, const char *ppp_name, GError **err) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); const char *ppp_binary; NMCmdLine *cmd; gboolean ppp_debug; g_return_val_if_fail (setting != NULL, NULL); ppp_binary = nm_find_pppd (); if (!ppp_binary) { g_set_error (err, NM_PPP_MANAGER_ERROR, NM_PPP_MANAGER_ERROR, "Could not find ppp binary."); return NULL; } /* Create pppd command line */ cmd = nm_cmd_line_new (); nm_cmd_line_add_string (cmd, ppp_binary); nm_cmd_line_add_string (cmd, "nodetach"); nm_cmd_line_add_string (cmd, "lock"); /* NM handles setting the default route */ nm_cmd_line_add_string (cmd, "nodefaultroute"); ppp_debug = !!getenv ("NM_PPP_DEBUG"); if ( nm_logging_level_enabled (LOGL_DEBUG) && nm_logging_domain_enabled (LOGD_PPP)) ppp_debug = TRUE; if (ppp_debug) nm_cmd_line_add_string (cmd, "debug"); if (ppp_name) { nm_cmd_line_add_string (cmd, "user"); nm_cmd_line_add_string (cmd, ppp_name); } if (pppoe) { char *dev_str; const char *pppoe_service; nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, "rp-pppoe.so"); dev_str = g_strdup_printf ("nic-%s", priv->parent_iface); nm_cmd_line_add_string (cmd, dev_str); g_free (dev_str); pppoe_service = nm_setting_pppoe_get_service (pppoe); if (pppoe_service) { nm_cmd_line_add_string (cmd, "rp_pppoe_service"); nm_cmd_line_add_string (cmd, pppoe_service); } } else { nm_cmd_line_add_string (cmd, priv->parent_iface); /* Don't send some random address as the local address */ nm_cmd_line_add_string (cmd, "noipdefault"); } if (nm_setting_ppp_get_baud (setting)) nm_cmd_line_add_int (cmd, nm_setting_ppp_get_baud (setting)); /* noauth by default, because we certainly don't have any information * with which to verify anything the peer gives us if we ask it to * authenticate itself, which is what 'auth' really means. */ nm_cmd_line_add_string (cmd, "noauth"); if (nm_setting_ppp_get_refuse_eap (setting)) nm_cmd_line_add_string (cmd, "refuse-eap"); if (nm_setting_ppp_get_refuse_pap (setting)) nm_cmd_line_add_string (cmd, "refuse-pap"); if (nm_setting_ppp_get_refuse_chap (setting)) nm_cmd_line_add_string (cmd, "refuse-chap"); if (nm_setting_ppp_get_refuse_mschap (setting)) nm_cmd_line_add_string (cmd, "refuse-mschap"); if (nm_setting_ppp_get_refuse_mschapv2 (setting)) nm_cmd_line_add_string (cmd, "refuse-mschap-v2"); if (nm_setting_ppp_get_nobsdcomp (setting)) nm_cmd_line_add_string (cmd, "nobsdcomp"); if (nm_setting_ppp_get_no_vj_comp (setting)) nm_cmd_line_add_string (cmd, "novj"); if (nm_setting_ppp_get_nodeflate (setting)) nm_cmd_line_add_string (cmd, "nodeflate"); if (nm_setting_ppp_get_require_mppe (setting)) nm_cmd_line_add_string (cmd, "require-mppe"); if (nm_setting_ppp_get_require_mppe_128 (setting)) nm_cmd_line_add_string (cmd, "require-mppe-128"); if (nm_setting_ppp_get_mppe_stateful (setting)) nm_cmd_line_add_string (cmd, "mppe-stateful"); if (nm_setting_ppp_get_crtscts (setting)) nm_cmd_line_add_string (cmd, "crtscts"); /* Always ask for DNS, we don't have to use them if the connection * overrides the returned servers. */ nm_cmd_line_add_string (cmd, "usepeerdns"); if (nm_setting_ppp_get_mru (setting)) { nm_cmd_line_add_string (cmd, "mru"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_mru (setting)); } if (nm_setting_ppp_get_mtu (setting)) { nm_cmd_line_add_string (cmd, "mtu"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_mtu (setting)); } nm_cmd_line_add_string (cmd, "lcp-echo-failure"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_lcp_echo_failure (setting)); nm_cmd_line_add_string (cmd, "lcp-echo-interval"); nm_cmd_line_add_int (cmd, nm_setting_ppp_get_lcp_echo_interval (setting)); nm_cmd_line_add_string (cmd, "ipparam"); nm_cmd_line_add_string (cmd, priv->dbus_path); nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, NM_PPPD_PLUGIN); return cmd; }