summaryrefslogtreecommitdiff
path: root/sbin/iked/parse.y
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2011-01-17 17:16:44 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2011-01-17 17:16:44 +0000
commitd427546c43cc129b4ae15ba4603fe445e5b009c2 (patch)
tree74c484dd266a0dfd3b4d3cb85f63f9c45d4bfe48 /sbin/iked/parse.y
parentb4594c9759476528df1b498b3b717500416aeb4a (diff)
move mask2prefixlen functions to the util module; ok reyk
Diffstat (limited to 'sbin/iked/parse.y')
-rw-r--r--sbin/iked/parse.y67
1 files changed, 3 insertions, 64 deletions
diff --git a/sbin/iked/parse.y b/sbin/iked/parse.y
index 1efb79feb74..e9b34fb67cb 100644
--- a/sbin/iked/parse.y
+++ b/sbin/iked/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.18 2010/12/23 16:39:38 mikeb Exp $ */
+/* $OpenBSD: parse.y,v 1.19 2011/01/17 17:16:43 mikeb Exp $ */
/* $vantronix: parse.y,v 1.22 2010/06/03 11:08:34 reyk Exp $ */
/*
@@ -271,8 +271,6 @@ struct ipsec_addr_wrap *host_v4(const char *, int);
struct ipsec_addr_wrap *host_dns(const char *, int);
struct ipsec_addr_wrap *host_if(const char *, int);
struct ipsec_addr_wrap *host_any(void);
-u_int8_t mask2prefixlen(struct sockaddr_in *);
-u_int8_t mask2prefixlen6(struct sockaddr_in6 *);
void ifa_load(void);
int ifa_exists(const char *);
struct ipsec_addr_wrap *ifa_lookup(const char *ifa_name);
@@ -1793,65 +1791,6 @@ host_any(void)
return (ipa);
}
-u_int8_t
-mask2prefixlen(struct sockaddr_in *sa_in)
-{
- in_addr_t ina = sa_in->sin_addr.s_addr;
-
- if (ina == 0)
- return (0);
- else
- return (33 - ffs(ntohl(ina)));
-}
-
-u_int8_t
-mask2prefixlen6(struct sockaddr_in6 *sa_in6)
-{
- u_int8_t l = 0, *ap, *ep;
-
- /*
- * sin6_len is the size of the sockaddr so substract the offset of
- * the possibly truncated sin6_addr struct.
- */
- ap = (u_int8_t *)&sa_in6->sin6_addr;
- ep = (u_int8_t *)sa_in6 + sa_in6->sin6_len;
- for (; ap < ep; ap++) {
- /* this "beauty" is adopted from sbin/route/show.c ... */
- switch (*ap) {
- case 0xff:
- l += 8;
- break;
- case 0xfe:
- l += 7;
- return (l);
- case 0xfc:
- l += 6;
- return (l);
- case 0xf8:
- l += 5;
- return (l);
- case 0xf0:
- l += 4;
- return (l);
- case 0xe0:
- l += 3;
- return (l);
- case 0xc0:
- l += 2;
- return (l);
- case 0x80:
- l += 1;
- return (l);
- case 0x00:
- return (l);
- default:
- fatalx("non continguous inet6 netmask");
- }
- }
-
- return (l);
-}
-
/* interface lookup routintes */
struct ipsec_addr_wrap *iftab;
@@ -1882,12 +1821,12 @@ ifa_load(void)
sa_in = (struct sockaddr_in *)ifa->ifa_addr;
memcpy(&n->address, sa_in, sizeof(*sa_in));
sa_in = (struct sockaddr_in *)ifa->ifa_netmask;
- n->mask = mask2prefixlen(sa_in);
+ n->mask = mask2prefixlen((struct sockaddr *)sa_in);
} else if (n->af == AF_INET6) {
sa_in6 = (struct sockaddr_in6 *)ifa->ifa_addr;
memcpy(&n->address, sa_in6, sizeof(*sa_in6));
sa_in6 = (struct sockaddr_in6 *)ifa->ifa_netmask;
- n->mask = mask2prefixlen6(sa_in6);
+ n->mask = mask2prefixlen6((struct sockaddr *)sa_in6);
}
n->next = NULL;
n->tail = n;