aboutsummaryrefslogtreecommitdiffstats
path: root/src/charon/plugins/nm
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2008-10-14 08:46:31 +0000
committerTobias Brunner <tobias@strongswan.org>2008-10-14 08:46:31 +0000
commit1adaa02bb2bcd72ad6d41b22719dba29fd7d57b7 (patch)
tree03324c1a74ce2f7fff3c0f740ae44b5b06207582 /src/charon/plugins/nm
parent9257c3a287ac873a75b5386295e2a06439c66886 (diff)
downloadstrongswan-1adaa02bb2bcd72ad6d41b22719dba29fd7d57b7.tar.bz2
strongswan-1adaa02bb2bcd72ad6d41b22719dba29fd7d57b7.tar.xz
merging kernel_pfkey plugin back from kernel-interface branch
Diffstat (limited to 'src/charon/plugins/nm')
-rw-r--r--src/charon/plugins/nm/nm_service.c41
1 files changed, 7 insertions, 34 deletions
diff --git a/src/charon/plugins/nm/nm_service.c b/src/charon/plugins/nm/nm_service.c
index fbc094a3b..22cef472e 100644
--- a/src/charon/plugins/nm/nm_service.c
+++ b/src/charon/plugins/nm/nm_service.c
@@ -49,41 +49,14 @@ typedef struct {
*/
static u_int ts2subnet(traffic_selector_t* ts, u_int8_t *mask)
{
- /* there is no way to do this cleanly, as the address range may
- * be anything else but a subnet. We use from_addr as subnet
- * and try to calculate a usable subnet mask.
- */
- int byte, bit, net;
- bool found = FALSE;
- chunk_t from, to;
- size_t size = (ts->get_type(ts) == TS_IPV4_ADDR_RANGE) ? 4 : 16;
-
- from = ts->get_from_address(ts);
- to = ts->get_to_address(ts);
+ u_int net;
+ host_t *net_host;
+ chunk_t net_chunk;
- *mask = (size * 8);
- /* go trough all bits of the addresses, beginning in the front.
- * as long as they are equal, the subnet gets larger
- */
- for (byte = 0; byte < size; byte++)
- {
- for (bit = 7; bit >= 0; bit--)
- {
- if ((1<<bit & from.ptr[byte]) != (1<<bit & to.ptr[byte]))
- {
- *mask = ((7 - bit) + (byte * 8));
- found = TRUE;
- break;
- }
- }
- if (found)
- {
- break;
- }
- }
- net = *(u_int32_t*)from.ptr;
- chunk_free(&from);
- chunk_free(&to);
+ ts->to_subnet(ts, &net_host, mask);
+ net_chunk = net_host->get_address(net_host);
+ net = *(u_int32_t*)net_chunk.ptr;
+ net_host->destroy(net_host);
return net;
}