summaryrefslogtreecommitdiffstats
path: root/src/openvpn/route.c
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-08-07 12:03:57 +0200
committerDavid Sommerseth <davids@redhat.com>2012-09-02 21:18:43 +0200
commitf2d6f3bc06db4f9e0815fc25e35e393f794c193a (patch)
tree3ba404041bb2c68bc2d9225deff0ec8949bd2df2 /src/openvpn/route.c
parent3630a7a50099874d55bf8e212ad4a97d6e70966f (diff)
downloadopenvpn-f2d6f3bc06db4f9e0815fc25e35e393f794c193a.tar.gz
openvpn-f2d6f3bc06db4f9e0815fc25e35e393f794c193a.tar.xz
openvpn-f2d6f3bc06db4f9e0815fc25e35e393f794c193a.zip
Merge getaddr_multi and getaddr6 into one function
the getaddr6 and getaddr_mutli functions are duplicates of each other. Since we always require getaddrinfo to be present both function are merge into one openvpn_getaddrinfo. This functions also returns a standard struct addrinfo* so our resolve interface is closer to the standard unix interface. The getaddr function is a wrapper which provides backward compatibility for IPv4 addresses. Ipv6 calls and calls to getaddr_multi are replaced with the new interface. Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: 1344333837-22076-1-git-send-email-arne@rfc2549.org URL: http://article.gmane.org/gmane.network.openvpn.devel/6959 Signed-off-by: David Sommerseth <davids@redhat.com> [DS: Applied proper indenting on the changes wherever needed]
Diffstat (limited to 'src/openvpn/route.c')
-rw-r--r--src/openvpn/route.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index d967d4f..8c3d0dc 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -268,12 +268,14 @@ is_special_addr (const char *addr_str)
static bool
init_route (struct route *r,
- struct resolve_list *network_list,
+ struct addrinfo **network_list,
const struct route_option *ro,
const struct route_list *rl)
{
const in_addr_t default_netmask = IPV4_NETMASK_HOST;
bool status;
+ int ret;
+ struct in_addr special;
CLEAR (*r);
r->option = ro;
@@ -284,19 +286,22 @@ init_route (struct route *r,
{
goto fail;
}
-
- if (!get_special_addr (rl, ro->network, &r->network, &status))
+
+
+ /* get_special_addr replaces specialaddr with a special ip addr
+ like gw. getaddrinfo is called to convert a a addrinfo struct */
+
+ if(get_special_addr (rl, ro->network, &special.s_addr, &status))
{
- r->network = getaddr_multi (
- GETADDR_RESOLVE
- | GETADDR_HOST_ORDER
- | GETADDR_WARN_ON_SIGNAL,
- ro->network,
- 0,
- &status,
- NULL,
- network_list);
+ special.s_addr = htonl(special.s_addr);
+ ret = openvpn_getaddrinfo(0, inet_ntoa(special), 0, NULL,
+ AF_INET, network_list);
}
+ else
+ ret = openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL,
+ ro->network, 0, NULL, AF_INET, network_list);
+
+ status = (ret == 0);
if (!status)
goto fail;
@@ -642,11 +647,8 @@ init_route_list (struct route_list *rl,
bool warned = false;
for (i = 0; i < opt->n; ++i)
{
- struct resolve_list netlist;
+ struct addrinfo* netlist;
struct route r;
- int k;
-
- CLEAR(netlist); /* init_route() will not always init this */
if (!init_route (&r,
&netlist,
@@ -655,16 +657,12 @@ init_route_list (struct route_list *rl,
ret = false;
else
{
- if (!netlist.len)
- {
- netlist.data[0] = r.network;
- netlist.len = 1;
- }
- for (k = 0; k < netlist.len; ++k)
+ struct addrinfo* curele;
+ for (curele = netlist; curele; curele = curele->ai_next)
{
if (j < rl->capacity)
{
- r.network = netlist.data[k];
+ r.network = ntohl(((struct sockaddr_in*)(curele)->ai_addr)->sin_addr.s_addr);
rl->routes[j++] = r;
}
else
@@ -676,6 +674,7 @@ init_route_list (struct route_list *rl,
}
}
}
+ freeaddrinfo(netlist);
}
}
rl->n = j;