diff --git a/vpn-daemons/openvpn/ChangeLog b/vpn-daemons/openvpn/ChangeLog index 1bd8667255..9bc3bcd1e7 100644 --- a/vpn-daemons/openvpn/ChangeLog +++ b/vpn-daemons/openvpn/ChangeLog @@ -1,3 +1,8 @@ +2008-08-06 Dan Williams + + * src/nm-openvpn-service-openvpn-helper.c + - (get_routes): handle route metrics + 2008-07-28 Dan Williams * properties/auth-helpers.c 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 b819cdc4b3..f4c4cd7502 100644 --- a/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c +++ b/vpn-daemons/openvpn/src/nm-openvpn-service-openvpn-helper.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -197,7 +198,7 @@ get_routes (void) struct in_addr network; struct in_addr netmask; struct in_addr gateway = { 0, }; - guint32 prefix; + guint32 prefix, metric = 0; snprintf (buf, BUFLEN, "route_network_%d", i); tmp = getenv (buf); @@ -218,16 +219,33 @@ get_routes (void) snprintf (buf, BUFLEN, "route_gateway_%d", i); tmp = getenv (buf); - if (!tmp || inet_pton (AF_INET, tmp, &gateway) <= 0) { + /* gateway can be missing */ + if (tmp && (inet_pton (AF_INET, tmp, &gateway) <= 0)) { nm_warning ("Ignoring invalid static route gateway '%s'", tmp ? tmp : "NULL"); continue; } - array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); + snprintf (buf, BUFLEN, "route_metric_%d", i); + tmp = getenv (buf); + /* metric can be missing */ + if (tmp && strlen (tmp)) { + long int tmp_metric; + + errno = 0; + tmp_metric = strtol (tmp, NULL, 10); + if (errno || tmp_metric < 0 || tmp_metric > G_MAXUINT32) { + nm_warning ("Ignoring invalid static route metric '%s'", tmp); + continue; + } + metric = (guint32) tmp_metric; + } + + array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4); g_array_append_val (array, network.s_addr); prefix = nm_utils_ip4_netmask_to_prefix (netmask.s_addr); g_array_append_val (array, prefix); g_array_append_val (array, gateway.s_addr); + g_array_append_val (array, metric); g_ptr_array_add (routes, array); }