aboutsummaryrefslogtreecommitdiffstats
path: root/src/libhydra
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-07-10 16:08:56 +0200
committerTobias Brunner <tobias@strongswan.org>2013-07-17 17:45:18 +0200
commitb308a97944511155b3bcc51d52ebbb0d8992da55 (patch)
treeae7b1544542a39da588e31e7c2c4a8adbda19b24 /src/libhydra
parent5310f485d98313812a8bad4bbd7030c526091634 (diff)
downloadstrongswan-b308a97944511155b3bcc51d52ebbb0d8992da55.tar.bz2
strongswan-b308a97944511155b3bcc51d52ebbb0d8992da55.tar.xz
kernel-pfroute: Properly enumerate sockaddrs in interface messages
The ifa_msghdr and rt_msghdr structs are not compatible (at least not on FreeBSD).
Diffstat (limited to 'src/libhydra')
-rw-r--r--src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c b/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c
index ca9e06975..6a191842e 100644
--- a/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c
+++ b/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c
@@ -601,11 +601,11 @@ METHOD(enumerator_t, rt_enumerate, bool,
}
/**
- * Create a safe enumerator over sockaddrs in ifa/ifam/rt_msg
+ * Create an enumerator over sockaddrs in rt/if messages
*/
-static enumerator_t *create_rtmsg_enumerator(void *hdr, size_t hdrlen)
+static enumerator_t *create_rt_enumerator(int types, int remaining,
+ struct sockaddr *addr)
{
- struct rt_msghdr *rthdr = hdr;
rt_enumerator_t *this;
INIT(this,
@@ -613,14 +613,32 @@ static enumerator_t *create_rtmsg_enumerator(void *hdr, size_t hdrlen)
.enumerate = (void*)_rt_enumerate,
.destroy = (void*)free,
},
- .types = rthdr->rtm_addrs,
- .remaining = rthdr->rtm_msglen - hdrlen,
- .addr = hdr + hdrlen,
+ .types = types,
+ .remaining = remaining,
+ .addr = addr,
);
return &this->public;
}
/**
+ * Create a safe enumerator over sockaddrs in rt_msghdr
+ */
+static enumerator_t *create_rtmsg_enumerator(struct rt_msghdr *hdr)
+{
+ return create_rt_enumerator(hdr->rtm_addrs, hdr->rtm_msglen - sizeof(*hdr),
+ (struct sockaddr *)(hdr + 1));
+}
+
+/**
+ * Create a safe enumerator over sockaddrs in ifa_msghdr
+ */
+static enumerator_t *create_ifamsg_enumerator(struct ifa_msghdr *hdr)
+{
+ return create_rt_enumerator(hdr->ifam_addrs, hdr->ifam_msglen - sizeof(*hdr),
+ (struct sockaddr *)(hdr + 1));
+}
+
+/**
* Process an RTM_*ADDR message from the kernel
*/
static void process_addr(private_kernel_pfroute_net_t *this,
@@ -636,7 +654,7 @@ static void process_addr(private_kernel_pfroute_net_t *this,
char *ifname = NULL;
int type;
- enumerator = create_rtmsg_enumerator(ifa, sizeof(*ifa));
+ enumerator = create_ifamsg_enumerator(ifa);
while (enumerator->enumerate(enumerator, &type, &sockaddr))
{
if (type == RTAX_IFA)
@@ -1483,8 +1501,7 @@ retry:
{
continue;
}
- enumerator = create_rtmsg_enumerator(this->reply,
- sizeof(*this->reply));
+ enumerator = create_rtmsg_enumerator(this->reply);
while (enumerator->enumerate(enumerator, &type, &addr))
{
if (nexthop)