static void nm_ip_up (void *data, int arg) { guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit); ipcp_options opts = ipcp_gotoptions[0]; ipcp_options peer_opts = ipcp_hisoptions[0]; GVariantBuilder builder; struct sockaddr_in addr; g_return_if_fail (G_IS_DBUS_PROXY (proxy)); g_message ("nm-sstp-ppp-plugin: (%s): ip-up event", __func__); if (!opts.ouraddr) { g_warning ("nm-sstp-ppp-plugin: (%s): didn't receive an internal IP from pppd!", __func__); return; } g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, g_variant_new_string (ifname)); g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, g_variant_new_uint32 (opts.ouraddr)); /* Request the address of the server sstpc connected to */ if (0 == nm_sstp_getaddr(&addr)) { /* This will eliminate the need to have nm-sstp-service * insert a new entry for "gateway" as we have already set it. */ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, g_variant_new_uint32 (addr.sin_addr.s_addr)); } /* Prefer the peer options remote address first, _unless_ pppd made the * address up, at which point prefer the local options remote address, * and if that's not right, use the made-up address as a last resort. */ if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) { g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_PTP, g_variant_new_uint32 (peer_opts.hisaddr)); } else if (opts.hisaddr) { g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_PTP, g_variant_new_uint32 (opts.hisaddr)); } else if (peer_opts.hisaddr == pppd_made_up_address) { /* As a last resort, use the made-up address */ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_PTP, g_variant_new_uint32 (peer_opts.ouraddr)); } g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, g_variant_new_uint32 (32)); if (opts.dnsaddr[0] || opts.dnsaddr[1]) { guint32 dns[2]; int len = 0; if (opts.dnsaddr[0]) dns[len++] = opts.dnsaddr[0]; if (opts.dnsaddr[1]) dns[len++] = opts.dnsaddr[1]; g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_DNS, g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, dns, len, sizeof (guint32))); } /* Default MTU to 1400, which is also what Windows XP/Vista use */ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_MTU, g_variant_new_uint32 (1400)); g_message ("nm-sstp-ppp-plugin: (%s): sending Ip4Config to NetworkManager-sstp...", __func__); g_dbus_proxy_call (proxy, "SetIp4Config", g_variant_new ("(a{sv})", &builder), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); }
static void nm_ip_up (void *data, int arg) { guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit); ipcp_options opts = ipcp_gotoptions[0]; ipcp_options peer_opts = ipcp_hisoptions[0]; GHashTable *hash; GArray *array; GValue *val; struct sockaddr_in addr; g_return_if_fail (DBUS_IS_G_PROXY (proxy)); g_message ("nm-sstp-ppp-plugin: (%s): ip-up event", __func__); if (!opts.ouraddr) { g_warning ("nm-sstp-ppp-plugin: (%s): didn't receive an internal IP from pppd!", __func__); return; } hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy); /* Request the address of the server sstpc connected to */ if (0 == nm_sstp_getaddr(&addr)) { /* This will eliminate the need to have nm-sstp-service * insert a new entry for "gateway" as we have already set it. */ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, uint_to_gvalue (addr.sin_addr.s_addr)); } g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, str_to_gvalue (ifname)); /* Prefer the peer options remote address first, _unless_ pppd made the * address up, at which point prefer the local options remote address, * and if that's not right, use the made-up address as a last resort. */ if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) { g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP, uint_to_gvalue (peer_opts.hisaddr)); } else if (opts.hisaddr) { g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP, uint_to_gvalue (opts.hisaddr)); } else if (peer_opts.hisaddr == pppd_made_up_address) { /* As a last resort, use the made-up address */ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP, uint_to_gvalue (peer_opts.hisaddr)); } g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, uint_to_gvalue (opts.ouraddr)); g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, uint_to_gvalue (32)); if (opts.dnsaddr[0] || opts.dnsaddr[1]) { array = g_array_new (FALSE, FALSE, sizeof (guint32)); if (opts.dnsaddr[0]) g_array_append_val (array, opts.dnsaddr[0]); if (opts.dnsaddr[1]) g_array_append_val (array, opts.dnsaddr[1]); val = g_slice_new0 (GValue); g_value_init (val, DBUS_TYPE_G_UINT_ARRAY); g_value_set_boxed (val, array); g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_DNS, val); } /* Default MTU to 1400, which is also what Windows XP/Vista use */ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_MTU, uint_to_gvalue (1400)); g_message ("nm-sstp-ppp-plugin: (%s): sending Ip4Config to NetworkManager-sstp...", __func__); dbus_g_proxy_call_no_reply (proxy, "SetIp4Config", DBUS_TYPE_G_MAP_OF_VARIANT, hash, G_TYPE_INVALID, G_TYPE_INVALID); g_hash_table_destroy (hash); }