From db7403d3f4ae52165910a5be614d03caea007591 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 16 Jan 2006 22:58:13 +0000 Subject: [PATCH] 2006-01-16 Dan Williams Apply the PtP Address bits of a patch from Tim Niemueller * src/nm-ip4-config.[ch] - Add ip4_ptp_address member to object - (nm_ip4_config_copy): copy ptp address too - (nm_ip4_config_get_ptp_address, nm_ip4_config_set_ptp_address): new functions - (nm_ip4_config_to_rtnl_addr): use ptp address when asked to, rather than local tunnel ip address * src/vpn-manager/nm-vpn-service.c - (print_vpn_config): update for PtP address - (nm_vpn_service_stage4_ip_config_get): switch parsing to DBusMessageIters in preparation for getting routes from the VPN service daemons too * vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c - (send_config_info): update for PtP address, clean up code - (main): update for PtP address, clean up code, fix typo * vpn-daemons/openvpn/src/nm-openvpn-service.c - (nm_openvpn_dbus_process_helper_ip4_config): update for PtP address * vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c - (pptp_ip_up): update for PtP address * vpn-daemons/pptp/src/nm-pptp-service.c - (nm_pptp_dbus_process_helper_ip4_config): update for PtP address * vpn-daemons/vpnc/src/nm-vpnc-service.c - (print_vpn_config): update for PtP address - (nm_vpnc_dbus_process_helper_ip4_config): update for PtP address git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1346 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 35 +++ src/nm-ip4-config.c | 21 +- src/nm-ip4-config.h | 3 + src/vpn-manager/nm-vpn-service.c | 237 ++++++++++++------ .../src/nm-openvpn-service-openvpn-helper.c | 217 ++++++++-------- vpn-daemons/openvpn/src/nm-openvpn-service.c | 15 +- .../pptp/src/nm-pptp-service-pppd-plugin.c | 2 + vpn-daemons/pptp/src/nm-pptp-service.c | 3 + vpn-daemons/vpnc/src/nm-vpnc-service.c | 124 ++++----- 9 files changed, 412 insertions(+), 245 deletions(-) diff --git a/ChangeLog b/ChangeLog index d24c80cb31..f4b30e0970 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2006-01-16 Dan Williams + + Apply the PtP Address bits of a patch from Tim Niemueller + + * src/nm-ip4-config.[ch] + - Add ip4_ptp_address member to object + - (nm_ip4_config_copy): copy ptp address too + - (nm_ip4_config_get_ptp_address, nm_ip4_config_set_ptp_address): + new functions + - (nm_ip4_config_to_rtnl_addr): use ptp address when asked to, + rather than local tunnel ip address + + * src/vpn-manager/nm-vpn-service.c + - (print_vpn_config): update for PtP address + - (nm_vpn_service_stage4_ip_config_get): switch parsing to + DBusMessageIters in preparation for getting routes from the VPN + service daemons too + + * vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c + - (send_config_info): update for PtP address, clean up code + - (main): update for PtP address, clean up code, fix typo + + * vpn-daemons/openvpn/src/nm-openvpn-service.c + - (nm_openvpn_dbus_process_helper_ip4_config): update for PtP address + + * vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c + - (pptp_ip_up): update for PtP address + + * vpn-daemons/pptp/src/nm-pptp-service.c + - (nm_pptp_dbus_process_helper_ip4_config): update for PtP address + + * vpn-daemons/vpnc/src/nm-vpnc-service.c + - (print_vpn_config): update for PtP address + - (nm_vpnc_dbus_process_helper_ip4_config): update for PtP address + 2006-01-16 Dan Williams * gnome/applet/applet.c diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index ef1c1768db..852c389058 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -31,14 +31,16 @@ #include #include - struct NMIP4Config { guint refcount; + guint32 ip4_address; + guint32 ip4_ptp_address; guint32 ip4_gateway; guint32 ip4_netmask; guint32 ip4_broadcast; + GSList * nameservers; GSList * domains; @@ -73,6 +75,7 @@ NMIP4Config *nm_ip4_config_copy (NMIP4Config *src_config) dst_config->refcount = 1; dst_config->ip4_address = nm_ip4_config_get_address (src_config); + dst_config->ip4_ptp_address = nm_ip4_config_get_ptp_address (src_config); dst_config->ip4_gateway = nm_ip4_config_get_gateway (src_config); dst_config->ip4_netmask = nm_ip4_config_get_netmask (src_config); dst_config->ip4_broadcast = nm_ip4_config_get_broadcast (src_config); @@ -147,6 +150,20 @@ void nm_ip4_config_set_address (NMIP4Config *config, guint32 addr) config->ip4_address = addr; } +guint32 nm_ip4_config_get_ptp_address (NMIP4Config *config) +{ + g_return_val_if_fail (config != NULL, 0); + + return config->ip4_ptp_address; +} + +void nm_ip4_config_set_ptp_address (NMIP4Config *config, guint32 ptp_addr) +{ + g_return_if_fail (config != NULL); + + config->ip4_ptp_address = ptp_addr; +} + guint32 nm_ip4_config_get_gateway (NMIP4Config *config) { g_return_val_if_fail (config != NULL, 0); @@ -357,7 +374,7 @@ struct rtnl_addr * nm_ip4_config_to_rtnl_addr (NMIP4Config *config, guint32 flag success = (ip4_addr_to_rtnl_local (config->ip4_address, addr) >= 0); if (flags & NM_RTNL_ADDR_PTP_ADDR) - success = (ip4_addr_to_rtnl_peer (config->ip4_address, addr) >= 0); + success = (ip4_addr_to_rtnl_peer (config->ip4_ptp_address, addr) >= 0); if (flags & NM_RTNL_ADDR_NETMASK) ip4_addr_to_rtnl_prefixlen (config->ip4_netmask, addr); diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index ce0203777b..ddef8be771 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -38,6 +38,9 @@ void nm_ip4_config_set_secondary (NMIP4Config *config, gboolean secondary); guint32 nm_ip4_config_get_address (NMIP4Config *config); void nm_ip4_config_set_address (NMIP4Config *config, guint32 addr); +guint32 nm_ip4_config_get_ptp_address (NMIP4Config *config); +void nm_ip4_config_set_ptp_address (NMIP4Config *config, guint32 ptp_addr); + guint32 nm_ip4_config_get_gateway (NMIP4Config *config); void nm_ip4_config_set_gateway (NMIP4Config *config, guint32 gateway); diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index 9ecb3aa949..b55bae5dc0 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -54,12 +54,13 @@ static void nm_vpn_service_stop_connection_internal (NMVPNService *service); #ifdef NM_DEBUG_VPN_CONFIG static void print_vpn_config (guint32 ip4_vpn_gateway, const char *tundev, - guint32 ip4_internal_address, - gint32 ip4_internal_netmask, - guint32 *ip4_internal_dns, - guint32 ip4_internal_dns_len, - guint32 *ip4_internal_nbns, - guint32 ip4_internal_nbns_len, + guint32 ip4_address, + guint32 ip4_ptp_address, + gint32 ip4_netmask, + guint32 *ip4_dns, + guint32 ip4_dns_len, + guint32 *ip4_nbns, + guint32 ip4_nbns_len, const char *dns_domain, const char *login_banner); #endif @@ -622,26 +623,58 @@ static void nm_vpn_service_cancel_callback (NMVPNService *service, NMVPNActReque } +static gboolean +get_dbus_guint32_helper (DBusMessageIter *iter, + guint32 *num, + char *desc) +{ + if (!dbus_message_iter_next (iter) + || (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_UINT32)) + { + nm_warning ("Error: couldn't get %s from VPN IP Config message.", desc); + return FALSE; + } + dbus_message_iter_get_basic (iter, num); + return TRUE; +} + +static gboolean +get_dbus_string_helper (DBusMessageIter *iter, + char **str, + char *desc) +{ + if (!dbus_message_iter_next (iter) + || (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_STRING)) + { + nm_warning ("Error: couldn't get %s from VPN IP Config message.", desc); + return FALSE; + } + dbus_message_iter_get_basic (iter, str); + return TRUE; +} + + /* * nm_vpn_service_stage4_ip_config_get * * Configure a device with IPv4 config info in response the the VPN daemon. * */ -static void nm_vpn_service_stage4_ip_config_get (NMVPNService *service, NMVPNActRequest *req, DBusMessage *message) +static void +nm_vpn_service_stage4_ip_config_get (NMVPNService *service, + NMVPNActRequest *req, + DBusMessage *message) { NMVPNConnection * vpn; - guint32 ip4_vpn_gateway; + guint32 num; + char * str; char * tundev; - guint32 ip4_internal_address; - guint32 ip4_internal_netmask; - guint32 * ip4_internal_dns; - guint32 ip4_internal_dns_len; - guint32 * ip4_internal_nbns; - guint32 ip4_internal_nbns_len; - char * dns_domain; char * login_banner; gboolean success = FALSE; + DBusMessageIter iter; + DBusMessageIter subiter; + NMIP4Config * config; + NMDevice * parent_dev; g_return_if_fail (service != NULL); g_return_if_fail (message != NULL); @@ -652,65 +685,116 @@ static void nm_vpn_service_stage4_ip_config_get (NMVPNService *service, NMVPNAct nm_info ("VPN Activation (%s) Stage 4 (IP Config Get) reply received.", nm_vpn_connection_get_name (vpn)); - if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &ip4_vpn_gateway, - DBUS_TYPE_STRING, &tundev, - DBUS_TYPE_UINT32, &ip4_internal_address, - DBUS_TYPE_UINT32, &ip4_internal_netmask, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_internal_dns, &ip4_internal_dns_len, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_internal_nbns, &ip4_internal_nbns_len, - DBUS_TYPE_STRING, &dns_domain, - DBUS_TYPE_STRING, &login_banner, DBUS_TYPE_INVALID)) + config = nm_ip4_config_new (); + nm_ip4_config_set_secondary (config, TRUE); + + dbus_message_iter_init (message, &iter); + + /* First arg: IP4 VPN Gateway address (UINT32) */ + if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { - NMIP4Config * config; - NMDevice * parent_dev; - guint32 i; + nm_warning ("Error: couldn't get IP4 VPN Gateway Address" + " from VPN IP Config message."); + goto out; + } + dbus_message_iter_get_basic (&iter, &num); + nm_ip4_config_set_gateway (config, num); -#ifdef NM_DEBUG_VPN_CONFIG - print_vpn_config (ip4_vpn_gateway, tundev, ip4_internal_address, ip4_internal_netmask, - ip4_internal_dns, ip4_internal_dns_len, ip4_internal_nbns, ip4_internal_nbns_len, - dns_domain, login_banner); -#endif + /* Second arg: Tunnel device, if any (STRING) */ + if (!get_dbus_string_helper (&iter, &tundev, "Tunnel Device")) + goto out; - config = nm_ip4_config_new (); + /* Third arg: IP4 VPN Local Address (UINT32) */ + if (!get_dbus_guint32_helper (&iter, &num, "IP4 VPN Local Address")) + goto out; + nm_ip4_config_set_address (config, num); - nm_ip4_config_set_secondary (config, TRUE); + /* Fourth arg: IP4 VPN Point-to-Point Address (UINT32) */ + if (!get_dbus_guint32_helper (&iter, &num, "IP4 VPN PtP Address")) + goto out; + nm_ip4_config_set_ptp_address (config, num); - nm_ip4_config_set_address (config, ip4_internal_address); + /* Fifth arg: IP4 VPN Local Netmask (UINT32) */ + if (!get_dbus_guint32_helper (&iter, &num, "IP4 VPN Local Netmask")) + goto out; + /* If no netmask, default to Class C address */ + nm_ip4_config_set_netmask (config, num ? num : 0x00FF); - if (ip4_internal_netmask) - nm_ip4_config_set_netmask (config, ip4_internal_netmask); - else - nm_ip4_config_set_netmask (config, 0x00FF); /* Class C */ - - nm_ip4_config_set_gateway (config, ip4_vpn_gateway); - - if (strlen (dns_domain)) - nm_ip4_config_add_domain (config, dns_domain); - - for (i = 0; i < ip4_internal_dns_len; i++) - { - if (ip4_internal_dns[i] != 0) - nm_ip4_config_add_nameserver (config, ip4_internal_dns[i]); - } - - parent_dev = nm_vpn_act_request_get_parent_dev (req); - g_assert (parent_dev); - - if (nm_vpn_connection_set_config (vpn, tundev, parent_dev, config)) - { - if (login_banner && strlen (login_banner)) - nm_dbus_vpn_signal_vpn_login_banner (service->app_data->dbus_connection, vpn, login_banner); - success = TRUE; - } + /* Sixth arg: IP4 DNS Server Addresses (ARRAY, UINT32) */ + if ( !dbus_message_iter_next (&iter) + || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)) + { + nm_warning ("Error: couldn't get IP4 DNS Server Addresses" + " from VPN IP Config message."); + goto out; + } + dbus_message_iter_recurse (&iter, &subiter); + while (dbus_message_iter_get_arg_type (&subiter) == DBUS_TYPE_UINT32) + { + dbus_message_iter_get_basic (&subiter, &num); + if (num) + nm_ip4_config_add_nameserver (config, num); + dbus_message_iter_next (&subiter); } + /* Seventh arg: IP4 NBNS Server Addresses (ARRAY, UINT32) */ + if ( !dbus_message_iter_next (&iter) + || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY)) + { + nm_warning ("Error: couldn't get IP4 NBNS Server Addresses" + " from VPN IP Config message."); + goto out; + } + dbus_message_iter_recurse (&iter, &subiter); + while (dbus_message_iter_get_arg_type (&subiter) == DBUS_TYPE_UINT32) + { + dbus_message_iter_get_basic (&subiter, &num); + /* We don't do anything with these yet */ + dbus_message_iter_next (&subiter); + } + + /* Eigth arg: DNS Domain (STRING) */ + if (!get_dbus_string_helper (&iter, &str, "DNS Domain")) + goto out; + if (strlen (str)) + nm_ip4_config_add_domain (config, str); + + /* Ninth arg: VPN Login Banner (STRING) */ + if (!get_dbus_string_helper (&iter, &login_banner, "Login Banner")) + goto out; + +#ifdef NM_DEBUG_VPN_CONFIG + print_vpn_config (ip4_vpn_gateway, + tundev, + ip4_address, + ip4_ptp_address, + ip4_netmask, + ip4_dns, + ip4_dns_len, + ip4_nbns, + ip4_nbns_len, + dns_domain, + login_banner); +#endif + + if (!(parent_dev = nm_vpn_act_request_get_parent_dev (req))) + goto out; + + if (nm_vpn_connection_set_config (vpn, tundev, parent_dev, config)) + { + if (login_banner && strlen (login_banner)) + nm_dbus_vpn_signal_vpn_login_banner (service->app_data->dbus_connection, vpn, login_banner); + success = TRUE; + nm_vpn_service_activation_success (service, req); + } + +out: if (!success) { + nm_ip4_config_unref (config); nm_warning ("nm_vpn_service_stage4_ip_config_get(%s): did not receive valid IP config information.", service->service); nm_vpn_service_act_request_failed (service, req); } - else - nm_vpn_service_activation_success (service, req); } @@ -908,12 +992,13 @@ gboolean nm_vpn_service_process_signal (NMVPNService *service, NMVPNActRequest * */ static void print_vpn_config (guint32 ip4_vpn_gateway, const char *tundev, - guint32 ip4_internal_address, - gint32 ip4_internal_netmask, - guint32 *ip4_internal_dns, - guint32 ip4_internal_dns_len, - guint32 *ip4_internal_nbns, - guint32 ip4_internal_nbns_len, + guint32 ip4_address, + guint32 ip4_ptp_address, + guint32 ip4_netmask, + guint32 *ip4_dns, + guint32 ip4_dns_len, + guint32 *ip4_nbns, + guint32 ip4_nbns_len, const char *dns_domain, const char *login_banner) { @@ -923,25 +1008,27 @@ static void print_vpn_config (guint32 ip4_vpn_gateway, temp_addr.s_addr = ip4_vpn_gateway; nm_info ("VPN Gateway: %s", inet_ntoa (temp_addr)); nm_info ("Tunnel Device: %s", tundev); - temp_addr.s_addr = ip4_internal_address; + temp_addr.s_addr = ip4_address; nm_info ("Internal IP4 Address: %s", inet_ntoa (temp_addr)); - temp_addr.s_addr = ip4_internal_netmask; + temp_addr.s_addr = ip4_netmask; nm_info ("Internal IP4 Netmask: %s", inet_ntoa (temp_addr)); + temp_addr.s_addr = ip4_ptp_address; + nm_info ("Internal IP4 Point-to-Point Address: %s", inet_ntoa (temp_addr)); - for (i = 0; i < ip4_internal_dns_len; i++) + for (i = 0; i < ip4_dns_len; i++) { - if (ip4_internal_dns[i] != 0) + if (ip4_dns[i] != 0) { - temp_addr.s_addr = ip4_internal_dns[i]; + temp_addr.s_addr = ip4_dns[i]; nm_info ("Internal IP4 DNS: %s", inet_ntoa (temp_addr)); } } - for (i = 0; i < ip4_internal_nbns_len; i++) + for (i = 0; i < ip4_nbns_len; i++) { - if (ip4_internal_nbns[i] != 0) + if (ip4_nbns[i] != 0) { - temp_addr.s_addr = ip4_internal_nbns[i]; + temp_addr.s_addr = ip4_nbns[i]; nm_info ("Internal IP4 NBNS: %s", inet_ntoa (temp_addr)); } } diff --git a/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c b/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c index c82336e14c..271b4ffe71 100644 --- a/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c +++ b/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c @@ -69,31 +69,90 @@ static void send_config_error (DBusConnection *con, const char *item) } + /* + * gpa_to_uint32arr + * + * Convert GPtrArray of uint32 to a uint32* array + * + */ +static void +gpa_to_uint32arr (const GPtrArray *gpa, + guint32 **uia, + guint32 *uia_len) +{ + + guint32 num_valid = 0, i = 0; + struct in_addr temp_addr; + + *uia = NULL; + + if ( gpa->len > 0 ) { + /* Pass over the array first to determine how many valid entries there are */ + num_valid = 0; + for (i = 0; i < gpa->len; ++i) { + if (inet_aton ((char *)gpa->pdata[i], &temp_addr)) { + num_valid++; + } + } + + /* Do the actual string->int conversion and assign to the array. */ + if (num_valid > 0) { + *uia = g_new0 (guint32, num_valid); + for (i = 0; i < gpa->len; ++i) { + if (inet_aton ((char *)gpa->pdata[i], &temp_addr)) { + (*uia)[i] = temp_addr.s_addr; + } + } + } + + *uia_len = num_valid; + } + if (*uia == NULL) { + *uia = g_malloc0 (sizeof (guint32)); + *uia_len = 1; + } +} + +static gboolean +ipstr_to_uint32 (const char *ip_str, guint32 *ip) +{ + struct in_addr temp_addr; + + /* Convert IPv4 address arguments from strings into numbers */ + if (!inet_aton (ip_str, &temp_addr)) + return FALSE; + *ip = temp_addr.s_addr; + return TRUE; +} + + /* * send_config_info * * Send IP config info to nm-openvpn-service * */ -static gboolean send_config_info (DBusConnection *con, - const char *str_vpn_gateway, - const char *str_tundev, - const char *str_ip4_address, - const char *str_ip4_netmask, - const GPtrArray *gpa_ip4_dns, - const GPtrArray *gpa_ip4_nbns - ) +static gboolean +send_config_info (DBusConnection *con, + const char *str_vpn_gateway, + const char *str_tundev, + const char *str_ip4_address, + const char *str_ip4_ptpaddr, + const char *str_ip4_netmask, + const GPtrArray *gpa_ip4_dns, + const GPtrArray *gpa_ip4_nbns + ) { DBusMessage * message; struct in_addr temp_addr; guint32 uint_vpn_gateway = 0; guint32 uint_ip4_address = 0; + guint32 uint_ip4_ptpaddr = 0; guint32 uint_ip4_netmask = 0xFFFFFFFF; /* Default mask of 255.255.255.255 */ guint32 * uint_ip4_dns = NULL; guint32 uint_ip4_dns_len = 0; guint32 * uint_ip4_nbns = NULL; guint32 uint_ip4_nbns_len = 0; - guint32 num_valid = 0, i = 0; gboolean success = FALSE; g_return_val_if_fail (con != NULL, FALSE); @@ -104,79 +163,35 @@ static gboolean send_config_info (DBusConnection *con, return FALSE; } - /* Convert IPv4 address arguments from strings into numbers */ - if (!inet_aton (str_vpn_gateway, &temp_addr)) - { - nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a valid VPN Gateway from openvpn."); - send_config_error (con, "VPN Gateway"); - goto out; - } - uint_vpn_gateway = temp_addr.s_addr; + if (! ipstr_to_uint32 (str_vpn_gateway, &uint_vpn_gateway) ) { + nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a valid VPN Gateway from openvpn."); + send_config_error (con, "VPN Gateway"); + goto out; + } - if (!inet_aton (str_ip4_address, &temp_addr)) - { - nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a valid Internal IP4 Address from openvpn."); - send_config_error (con, "IP4 Address"); - goto out; - } - uint_ip4_address = temp_addr.s_addr; + if (! ipstr_to_uint32 (str_ip4_address, &uint_ip4_address) ) { + nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a valid Internal IP4 Address from openvpn."); + send_config_error (con, "IP4 Address"); + goto out; + } - if (strlen (str_ip4_netmask) && inet_aton (str_ip4_netmask, &temp_addr)) - uint_ip4_netmask = temp_addr.s_addr; + if (! ipstr_to_uint32 (str_ip4_ptpaddr, &uint_ip4_ptpaddr) ) { + nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a valid PtP IP4 Address from openvpn."); + send_config_error (con, "IP4 PtP Address"); + goto out; + } - if ( gpa_ip4_dns->len > 0 ) - { - /* Pass over the array first to determine how many valid entries there are */ - num_valid = 0; - for (i = 0; i < gpa_ip4_dns->len; ++i) - if (inet_aton ((char *)gpa_ip4_dns->pdata[i], &temp_addr)) - num_valid++; - - /* Do the actual string->int conversion and assign to the array. */ - if (num_valid > 0) - { - uint_ip4_dns = g_new0 (guint32, num_valid); - for (i = 0; i < gpa_ip4_dns->len; ++i) - if (inet_aton ((char *)gpa_ip4_dns->pdata[i], &temp_addr)) - uint_ip4_dns[i] = temp_addr.s_addr; - } - - uint_ip4_dns_len = num_valid; - } - if (!uint_ip4_dns) - { - uint_ip4_dns = g_malloc0 (sizeof (guint32)); - uint_ip4_dns_len = 1; - } + if (strlen (str_ip4_netmask) > 0) { + ipstr_to_uint32 (str_ip4_netmask, &uint_ip4_netmask); + } - if ( gpa_ip4_nbns->len > 0 ) - { - /* Pass over the array first to determine how many valid entries there are */ - num_valid = 0; - for (i = 0; i < gpa_ip4_nbns->len; ++i) - if (inet_aton ((char *)gpa_ip4_nbns->pdata[i], &temp_addr)) - num_valid++; - - /* Do the actual string->int conversion and assign to the array. */ - if (num_valid > 0) - { - uint_ip4_nbns = g_new0 (guint32, num_valid); - for (i = 0; i < gpa_ip4_nbns->len; ++i) - if (inet_aton ((char *)gpa_ip4_nbns->pdata[i], &temp_addr)) - uint_ip4_nbns[i] = temp_addr.s_addr; - } - - uint_ip4_nbns_len = num_valid; - } - if (!uint_ip4_nbns) - { - uint_ip4_nbns = g_malloc0 (sizeof (guint32)); - uint_ip4_nbns_len = 1; - } + gpa_to_uint32arr (gpa_ip4_dns, &uint_ip4_dns, &uint_ip4_dns_len); + gpa_to_uint32arr (gpa_ip4_nbns, &uint_ip4_nbns, &uint_ip4_nbns_len); dbus_message_append_args (message, DBUS_TYPE_UINT32, &uint_vpn_gateway, DBUS_TYPE_STRING, &str_tundev, DBUS_TYPE_UINT32, &uint_ip4_address, + DBUS_TYPE_UINT32, &uint_ip4_ptpaddr, DBUS_TYPE_UINT32, &uint_ip4_netmask, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_dns, uint_ip4_dns_len, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &uint_ip4_nbns, uint_ip4_nbns_len, @@ -188,6 +203,9 @@ static gboolean send_config_info (DBusConnection *con, dbus_message_unref (message); + g_free (uint_ip4_dns); + g_free (uint_ip4_nbns); + out: return success; } @@ -299,41 +317,38 @@ int main( int argc, char *argv[] ) { FILE *file = fopen ("/tmp/vpnstuff", "w"); fprintf (file, "VPNGATEWAY: '%s'\n", vpn_gateway); - fprintf (file, "TUNDEF: '%s'\n", tundev); + fprintf (file, "TUNDEV: '%s'\n", tundev); fprintf (file, "IP4_ADDRESS: '%s'\n", ip4_address); fprintf (file, "IP4_NETMASK: '%s'\n", ip4_netmask); fclose (file); } #endif - if (!vpn_gateway) - { - nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a VPN Gateway from openvpn."); - send_config_error (con, "VPN Gateway"); - exit (1); - } - if (!tundev || !g_utf8_validate (tundev, -1, NULL)) - { - nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a Tunnel Device from openvpn, or the tunnel device was not valid UTF-8."); - send_config_error (con, "Tunnel Device"); - exit (1); - } - if (!ip4_address) - { - nm_warning ("nm-openvpn-service-openvpn-helper didn't receive an Internal IP4 Address from openvpn."); - send_config_error (con, "IP4 Address"); - exit (1); - } + if (!vpn_gateway) { + nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a VPN Gateway from openvpn."); + send_config_error (con, "VPN Gateway"); + exit (1); + } + if (!tundev || !g_utf8_validate (tundev, -1, NULL)) { + nm_warning ("nm-openvpn-service-openvpn-helper didn't receive a Tunnel Device from openvpn, or the tunnel device was not valid UTF-8."); + send_config_error (con, "Tunnel Device"); + exit (1); + } + if (!ip4_address) { + nm_warning ("nm-openvpn-service-openvpn-helper didn't receive an Internal IP4 Address from openvpn."); + send_config_error (con, "IP4 Address"); + exit (1); + } - if (!ip4_netmask) + if (!ip4_netmask) { ip4_netmask = g_strdup (""); - - - /* Send the config info to nm-openvpn-service */ - if (!send_config_info (con, vpn_gateway, tundev, ip4_address, ip4_netmask, ip4_dns, ip4_nbns)) - { - exit_code = 1; - } + } + + if (!send_config_info (con, vpn_gateway, tundev, + ip4_address, ip4_ptp, ip4_netmask, + ip4_dns, ip4_nbns)) { + exit_code = 1; + } g_strfreev( split ); g_ptr_array_free( ip4_dns, TRUE ); diff --git a/vpn-daemons/openvpn/src/nm-openvpn-service.c b/vpn-daemons/openvpn/src/nm-openvpn-service.c index 3acecc175e..9e02c52301 100644 --- a/vpn-daemons/openvpn/src/nm-openvpn-service.c +++ b/vpn-daemons/openvpn/src/nm-openvpn-service.c @@ -1234,6 +1234,7 @@ nm_openvpn_dbus_process_helper_ip4_config (DBusConnection *con, DBusMessage *mes guint32 ip4_vpn_gateway; char * tundev; guint32 ip4_address; + guint32 ip4_ptpaddr; guint32 ip4_netmask; guint32 * ip4_dns; guint32 ip4_dns_len; @@ -1253,9 +1254,11 @@ nm_openvpn_dbus_process_helper_ip4_config (DBusConnection *con, DBusMessage *mes nm_openvpn_cancel_helper_timer (data); nm_openvpn_disconnect_management_socket (data); - if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &ip4_vpn_gateway, + if (dbus_message_get_args(message, NULL, + DBUS_TYPE_UINT32, &ip4_vpn_gateway, DBUS_TYPE_STRING, &tundev, DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_UINT32, &ip4_ptpaddr, DBUS_TYPE_UINT32, &ip4_netmask, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_dns, &ip4_dns_len, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_nbns, &ip4_nbns_len, @@ -1263,21 +1266,17 @@ nm_openvpn_dbus_process_helper_ip4_config (DBusConnection *con, DBusMessage *mes { DBusMessage *signal; - struct in_addr a; - - if (!(signal = dbus_message_new_signal (NM_DBUS_PATH_OPENVPN, NM_DBUS_INTERFACE_OPENVPN, NM_DBUS_VPN_SIGNAL_IP4_CONFIG))) { nm_warning ("Not enough memory for new dbus message!"); goto out; } - a.s_addr = ip4_vpn_gateway; - a.s_addr = ip4_address; - - dbus_message_append_args (signal, DBUS_TYPE_UINT32, &ip4_vpn_gateway, + dbus_message_append_args (signal, + DBUS_TYPE_UINT32, &ip4_vpn_gateway, DBUS_TYPE_STRING, &tundev, DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_UINT32, &ip4_ptpaddr, DBUS_TYPE_UINT32, &ip4_netmask, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_dns, ip4_dns_len, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_nbns, ip4_nbns_len, diff --git a/vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c b/vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c index 97ad392cd2..db6d7776f0 100644 --- a/vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c +++ b/vpn-daemons/pptp/src/nm-pptp-service-pppd-plugin.c @@ -106,6 +106,7 @@ static void pptp_ip_up(void *opaque, int arg) guint32 uint_ip4_wins2 = 0; guint32 uint_ip4_wins_len = 0; guint32 uint_ip4_address = 0; + guint32 uint_ip4_ptp_address = 0; guint32 uint_ip4_netmask = 0xFFFFFFFF; /* Default mask of 255.255.255.255 */ guint32 i=0; @@ -178,6 +179,7 @@ static void pptp_ip_up(void *opaque, int arg) dbus_message_append_args (message, DBUS_TYPE_STRING, &str_ifname, DBUS_TYPE_UINT32, &uint_ip4_address, + DBUS_TYPE_UINT32, &uint_ip4_ptp_address, DBUS_TYPE_UINT32, &uint_ip4_netmask, // Array workaround DBUS_TYPE_UINT32, &uint_ip4_dns1, diff --git a/vpn-daemons/pptp/src/nm-pptp-service.c b/vpn-daemons/pptp/src/nm-pptp-service.c index 8dbc0c944a..d0f4a4f4c4 100644 --- a/vpn-daemons/pptp/src/nm-pptp-service.c +++ b/vpn-daemons/pptp/src/nm-pptp-service.c @@ -815,6 +815,7 @@ static void nm_pptp_dbus_process_helper_ip4_config (DBusConnection *con, DBusMes guint32 ip4_vpn_gateway; char * tundev; guint32 ip4_address; + guint32 ip4_ptp_address; guint32 ip4_netmask; guint32 * ip4_dns; guint32 ip4_dns_len; @@ -840,6 +841,7 @@ static void nm_pptp_dbus_process_helper_ip4_config (DBusConnection *con, DBusMes if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &tundev, DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_UINT32, &ip4_ptp_address, DBUS_TYPE_UINT32, &ip4_netmask, DBUS_TYPE_UINT32, &ip4_dns1, DBUS_TYPE_UINT32, &ip4_dns2, @@ -876,6 +878,7 @@ static void nm_pptp_dbus_process_helper_ip4_config (DBusConnection *con, DBusMes DBUS_TYPE_UINT32, &ip4_vpn_gateway, DBUS_TYPE_STRING, &tundev, DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_UINT32, &ip4_ptp_address, DBUS_TYPE_UINT32, &ip4_netmask, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_dns, ip4_dns_len, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_nbns, ip4_nbns_len, diff --git a/vpn-daemons/vpnc/src/nm-vpnc-service.c b/vpn-daemons/vpnc/src/nm-vpnc-service.c index 29c3f08d58..96f3a17ae9 100644 --- a/vpn-daemons/vpnc/src/nm-vpnc-service.c +++ b/vpn-daemons/vpnc/src/nm-vpnc-service.c @@ -795,16 +795,18 @@ static void nm_vpnc_dbus_process_helper_config_error (DBusConnection *con, DBusM /* * Prints config returned from vpnc-helper */ -static void print_vpn_config (guint32 ip4_vpn_gateway, - const char *tundev, - guint32 ip4_internal_address, - gint32 ip4_internal_netmask, - guint32 *ip4_internal_dns, - guint32 ip4_internal_dns_len, - guint32 *ip4_internal_nbns, - guint32 ip4_internal_nbns_len, - const char *cisco_def_domain, - const char *cisco_banner) +static void +print_vpn_config (guint32 ip4_vpn_gateway, + const char *tundev, + guint32 ip4_address, + guint32 ip4_ptp_address, + gint32 ip4_netmask, + guint32 *ip4_dns, + guint32 ip4_dns_len, + guint32 *ip4_nbns, + guint32 ip4_nbns_len, + const char *cisco_def_domain, + const char *cisco_banner) { struct in_addr temp_addr; guint32 i; @@ -812,25 +814,27 @@ static void print_vpn_config (guint32 ip4_vpn_gateway, temp_addr.s_addr = ip4_vpn_gateway; nm_info ("VPN Gateway: %s", inet_ntoa (temp_addr)); nm_info ("Tunnel Device: %s", tundev); - temp_addr.s_addr = ip4_internal_address; + temp_addr.s_addr = ip4_address; nm_info ("Internal IP4 Address: %s", inet_ntoa (temp_addr)); - temp_addr.s_addr = ip4_internal_netmask; + temp_addr.s_addr = ip4_netmask; nm_info ("Internal IP4 Netmask: %s", inet_ntoa (temp_addr)); + temp_addr.s_addr = ip4_ptp_address; + nm_info ("Internal IP4 Point-to-Point Address: %s", inet_ntoa (temp_addr)); - for (i = 0; i < ip4_internal_dns_len; i++) + for (i = 0; i < ip4_dns_len; i++) { - if (ip4_internal_dns[i] != 0) + if (ip4_dns[i] != 0) { - temp_addr.s_addr = ip4_internal_dns[i]; + temp_addr.s_addr = ip4_dns[i]; nm_info ("Internal IP4 DNS: %s", inet_ntoa (temp_addr)); } } - for (i = 0; i < ip4_internal_nbns_len; i++) + for (i = 0; i < ip4_nbns_len; i++) { - if (ip4_internal_nbns[i] != 0) + if (ip4_nbns[i] != 0) { - temp_addr.s_addr = ip4_internal_nbns[i]; + temp_addr.s_addr = ip4_nbns[i]; nm_info ("Internal IP4 NBNS: %s", inet_ntoa (temp_addr)); } } @@ -853,15 +857,17 @@ static void nm_vpnc_dbus_process_helper_ip4_config (DBusConnection *con, DBusMes { guint32 ip4_vpn_gateway; char * tundev; - guint32 ip4_internal_address; - guint32 ip4_internal_netmask; - guint32 * ip4_internal_dns; - guint32 ip4_internal_dns_len; - guint32 * ip4_internal_nbns; - guint32 ip4_internal_nbns_len; + guint32 ip4_address; + guint32 ip4_ptp_address; + guint32 ip4_netmask; + guint32 * ip4_dns; + guint32 ip4_dns_len; + guint32 * ip4_nbns; + guint32 ip4_nbns_len; char * cisco_def_domain; char * cisco_banner; gboolean success = FALSE; + DBusMessage * signal; g_return_if_fail (data != NULL); g_return_if_fail (con != NULL); @@ -873,48 +879,48 @@ static void nm_vpnc_dbus_process_helper_ip4_config (DBusConnection *con, DBusMes nm_vpnc_cancel_helper_timer (data); - if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT32, &ip4_vpn_gateway, - DBUS_TYPE_STRING, &tundev, - DBUS_TYPE_UINT32, &ip4_internal_address, - DBUS_TYPE_UINT32, &ip4_internal_netmask, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_internal_dns, &ip4_internal_dns_len, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_internal_nbns, &ip4_internal_nbns_len, - DBUS_TYPE_STRING, &cisco_def_domain, - DBUS_TYPE_STRING, &cisco_banner, DBUS_TYPE_INVALID)) - { - DBusMessage *signal; + if (!dbus_message_get_args(message, NULL, + DBUS_TYPE_UINT32, &ip4_vpn_gateway, + DBUS_TYPE_STRING, &tundev, + DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_UINT32, &ip4_netmask, + DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_dns, &ip4_dns_len, + DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_nbns, &ip4_nbns_len, + DBUS_TYPE_STRING, &cisco_def_domain, + DBUS_TYPE_STRING, &cisco_banner, DBUS_TYPE_INVALID)) + goto out; + /* For Cisco/vpnc, PtP address == local VPN address */ + ip4_ptp_address = ip4_address; #if 0 - print_vpn_config (ip4_vpn_gateway, tundev, ip4_internal_address, ip4_internal_netmask, - ip4_internal_dns, ip4_internal_dns_len, ip4_internal_nbns, ip4_internal_nbns_len, - cisco_def_domain, cisco_banner); + print_vpn_config (ip4_vpn_gateway, tundev, ip4_address, ip4_netmask, + ip4_dns, ip4_dns_len, ip4_nbns, ip4_nbns_len, + cisco_def_domain, cisco_banner); #endif - if (!(signal = dbus_message_new_signal (NM_DBUS_PATH_VPNC, NM_DBUS_INTERFACE_VPNC, NM_DBUS_VPN_SIGNAL_IP4_CONFIG))) - { - nm_warning ("Not enough memory for new dbus message!"); - goto out; - } + if (!(signal = dbus_message_new_signal (NM_DBUS_PATH_VPNC, NM_DBUS_INTERFACE_VPNC, NM_DBUS_VPN_SIGNAL_IP4_CONFIG))) + goto out; - dbus_message_append_args (signal, DBUS_TYPE_UINT32, &ip4_vpn_gateway, - DBUS_TYPE_STRING, &tundev, - DBUS_TYPE_UINT32, &ip4_internal_address, - DBUS_TYPE_UINT32, &ip4_internal_netmask, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_internal_dns, ip4_internal_dns_len, - DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_internal_nbns, ip4_internal_nbns_len, - DBUS_TYPE_STRING, &cisco_def_domain, - DBUS_TYPE_STRING, &cisco_banner, DBUS_TYPE_INVALID); - if (!dbus_connection_send (data->con, signal, NULL)) - { - nm_warning ("Could not raise the "NM_DBUS_VPN_SIGNAL_IP4_CONFIG" signal!"); - goto out; - } - - dbus_message_unref (signal); - nm_vpnc_set_state (data, NM_VPN_STATE_STARTED); - success = TRUE; + dbus_message_append_args (signal, + DBUS_TYPE_UINT32, &ip4_vpn_gateway, + DBUS_TYPE_STRING, &tundev, + DBUS_TYPE_UINT32, &ip4_address, + DBUS_TYPE_UINT32, &ip4_ptp_address, + DBUS_TYPE_UINT32, &ip4_netmask, + DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_dns, ip4_dns_len, + DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &ip4_nbns, ip4_nbns_len, + DBUS_TYPE_STRING, &cisco_def_domain, + DBUS_TYPE_STRING, &cisco_banner, DBUS_TYPE_INVALID); + if (!dbus_connection_send (data->con, signal, NULL)) + { + nm_warning ("Could not raise the "NM_DBUS_VPN_SIGNAL_IP4_CONFIG" signal!"); + goto out; } + dbus_message_unref (signal); + nm_vpnc_set_state (data, NM_VPN_STATE_STARTED); + success = TRUE; + out: if (!success) {