summaryrefslogtreecommitdiff
path: root/usr.sbin/ospf6ctl
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-10-16 08:43:45 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-10-16 08:43:45 +0000
commit8fb77df34b1ce799cb9d7a11d87c084bedd7cf47 (patch)
treed33eba12a610aa9eab13eeef0f03fb8a26cbb12e /usr.sbin/ospf6ctl
parentd4e4e58151fffde93ba80f36b690328c719beeae (diff)
Adapt to the changes in ospf6d. Fix more IPv6 addressing and probably break
some currently not working commands but show interface and show neighbor should work. OK norby@
Diffstat (limited to 'usr.sbin/ospf6ctl')
-rw-r--r--usr.sbin/ospf6ctl/ospf6ctl.c41
-rw-r--r--usr.sbin/ospf6ctl/parser.c137
-rw-r--r--usr.sbin/ospf6ctl/parser.h8
3 files changed, 134 insertions, 52 deletions
diff --git a/usr.sbin/ospf6ctl/ospf6ctl.c b/usr.sbin/ospf6ctl/ospf6ctl.c
index 75b5564aee2..4522ad157df 100644
--- a/usr.sbin/ospf6ctl/ospf6ctl.c
+++ b/usr.sbin/ospf6ctl/ospf6ctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospf6ctl.c,v 1.6 2007/10/16 08:07:56 norby Exp $ */
+/* $OpenBSD: ospf6ctl.c,v 1.7 2007/10/16 08:43:44 claudio Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -181,7 +181,7 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_RIB, 0, 0, NULL, 0);
break;
case SHOW_FIB:
- if (!res->addr.s_addr)
+ if (IN6_IS_ADDR_UNSPECIFIED(&res->addr))
imsg_compose(ibuf, IMSG_CTL_KROUTE, 0, 0,
&res->flags, sizeof(res->flags));
else
@@ -515,16 +515,6 @@ log_adv_rtr(u_int32_t adv_rtr)
return (buf);
}
-/* prototype defined in ospfd.h and shared with the kroute.c version */
-u_int8_t
-mask2prefixlen(in_addr_t ina)
-{
- if (ina == 0)
- return (0);
- else
- return (33 - ffs(ntohl(ina)));
-}
-
void
show_database_head(struct in_addr aid, u_int8_t type)
{
@@ -911,13 +901,13 @@ show_rib_msg(struct imsg *imsg)
rt = imsg->data;
switch (rt->d_type) {
case DT_NET:
- if (asprintf(&dstnet, "%s/%d", inet_ntoa(rt->prefix),
+ if (asprintf(&dstnet, "%s/%d", log_in6addr(&rt->prefix),
rt->prefixlen) == -1)
err(1, NULL);
break;
case DT_RTR:
if (asprintf(&dstnet, "%s",
- inet_ntoa(rt->prefix)) == -1)
+ log_in6addr(&rt->prefix)) == -1)
err(1, NULL);
break;
default:
@@ -925,7 +915,7 @@ show_rib_msg(struct imsg *imsg)
}
printf("%-20s %-17s %-12s %-9s %-7d %s\n", dstnet,
- inet_ntoa(rt->nexthop), path_type_name(rt->p_type),
+ log_in6addr(&rt->nexthop), path_type_name(rt->p_type),
dst_type_name(rt->d_type), rt->cost,
rt->uptime == 0 ? "-" : fmt_timeframe_core(rt->uptime));
free(dstnet);
@@ -1018,7 +1008,8 @@ show_rib_detail_msg(struct imsg *imsg)
show_rib_head(rt->area, rt->d_type,
rt->p_type);
if (asprintf(&dstnet, "%s/%d",
- inet_ntoa(rt->prefix), rt->prefixlen) == -1)
+ log_in6addr(&rt->prefix),
+ rt->prefixlen) == -1)
err(1, NULL);
lasttype = RIB_NET;
break;
@@ -1027,14 +1018,15 @@ show_rib_detail_msg(struct imsg *imsg)
show_rib_head(rt->area, rt->d_type,
rt->p_type);
if (asprintf(&dstnet, "%s",
- inet_ntoa(rt->prefix)) == -1)
+ log_in6addr(&rt->prefix)) == -1)
err(1, NULL);
lasttype = RIB_RTR;
break;
default:
errx(1, "unknown route type");
}
- printf("%-18s %-15s ", dstnet, inet_ntoa(rt->nexthop));
+ printf("%-18s %-15s ", dstnet,
+ log_in6addr(&rt->nexthop));
printf("%-15s %-12s %-7d", inet_ntoa(rt->adv_rtr),
path_type_name(rt->p_type), rt->cost);
free(dstnet);
@@ -1051,10 +1043,11 @@ show_rib_detail_msg(struct imsg *imsg)
show_rib_head(rt->area, rt->d_type, rt->p_type);
if (asprintf(&dstnet, "%s/%d",
- inet_ntoa(rt->prefix), rt->prefixlen) == -1)
+ log_in6addr(&rt->prefix), rt->prefixlen) == -1)
err(1, NULL);
- printf("%-18s %-15s ", dstnet, inet_ntoa(rt->nexthop));
+ printf("%-18s %-15s ", dstnet,
+ log_in6addr(&rt->nexthop));
printf("%-15s %-12s %-7d %-7d\n",
inet_ntoa(rt->adv_rtr), path_type_name(rt->p_type),
rt->cost, rt->cost2);
@@ -1113,14 +1106,14 @@ show_fib_msg(struct imsg *imsg)
printf(" ");
printf(" ");
- if (asprintf(&p, "%s/%u", inet_ntoa(k->prefix), k->prefixlen) ==
- -1)
+ if (asprintf(&p, "%s/%u", log_in6addr(&k->prefix),
+ k->prefixlen) == -1)
err(1, NULL);
printf("%-20s ", p);
free(p);
- if (k->nexthop.s_addr)
- printf("%s", inet_ntoa(k->nexthop));
+ if (!IN6_IS_ADDR_UNSPECIFIED(&k->nexthop))
+ printf("%s", log_in6addr(&k->nexthop));
else if (k->flags & F_CONNECTED)
printf("link#%u", k->ifindex);
printf("\n");
diff --git a/usr.sbin/ospf6ctl/parser.c b/usr.sbin/ospf6ctl/parser.c
index 27453c8ebd8..1337beb5c03 100644
--- a/usr.sbin/ospf6ctl/parser.c
+++ b/usr.sbin/ospf6ctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.2 2007/10/14 01:28:06 deraadt Exp $ */
+/* $OpenBSD: parser.c,v 1.3 2007/10/16 08:43:44 claudio Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -24,6 +24,7 @@
#include <err.h>
#include <errno.h>
#include <limits.h>
+#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -272,55 +273,143 @@ show_valid_args(const struct token table[])
}
}
+/* XXX shared with parse.y should be merged */
int
-parse_addr(const char *word, struct in_addr *addr)
+parse_addr(const char *word, struct in6_addr *addr)
{
- struct in_addr ina;
+ struct addrinfo hints, *r;
if (word == NULL)
return (0);
- bzero(addr, sizeof(struct in_addr));
- bzero(&ina, sizeof(ina));
-
- if (inet_pton(AF_INET, word, &ina)) {
- addr->s_addr = ina.s_addr;
+ bzero(addr, sizeof(struct in6_addr));
+ bzero(&hints, sizeof(hints));
+ hints.ai_family = AF_INET6;
+ hints.ai_socktype = SOCK_DGRAM; /*dummy*/
+ hints.ai_flags = AI_NUMERICHOST;
+ if (getaddrinfo(word, "0", &hints, &r) == 0) {
+ *addr = ((struct sockaddr_in6 *)r->ai_addr)->sin6_addr;
+ /* XXX address scope !!! */
+ /* ((struct sockaddr_in6 *)r->ai_addr)->sin6_scope_id */
+ freeaddrinfo(r);
return (1);
}
-
return (0);
}
+/* XXX shared with parse.y should be merged */
int
-parse_prefix(const char *word, struct in_addr *addr, u_int8_t *prefixlen)
+parse_prefix(const char *word, struct in6_addr *addr, u_int8_t *prefixlen)
{
- struct in_addr ina;
- int bits = 32;
+ char *p, *ps;
+ const char *errstr;
+ int mask;
if (word == NULL)
return (0);
- bzero(addr, sizeof(struct in_addr));
- bzero(&ina, sizeof(ina));
+ if ((p = strrchr(word, '/')) != NULL) {
+ mask = strtonum(p + 1, 0, 128, &errstr);
+ if (errstr)
+ errx(1, "invalid netmask: %s", errstr);
+
+ if ((ps = malloc(strlen(word) - strlen(p) + 1)) == NULL)
+ err(1, "parse_prefix: malloc");
+ strlcpy(ps, word, strlen(word) - strlen(p) + 1);
- if (strrchr(word, '/') != NULL) {
- if ((bits = inet_net_pton(AF_INET, word,
- &ina, sizeof(ina))) == -1)
+ if (parse_addr(ps, addr) == 0) {
+ free(ps);
return (0);
- addr->s_addr = ina.s_addr & htonl(prefixlen2mask(bits));
- *prefixlen = bits;
+ }
+
+ inet6applymask(addr, addr, mask);
+ *prefixlen = mask;
return (1);
}
- *prefixlen = 32;
+ *prefixlen = 128;
return (parse_addr(word, addr));
}
+/* XXX prototype defined in ospfd.h and shared with the kroute.c version */
+u_int8_t
+mask2prefixlen(struct sockaddr_in6 *sa_in6)
+{
+ u_int8_t l = 0, i, len;
+
+ /*
+ * sin6_len is the size of the sockaddr so substract the offset of
+ * the possibly truncated sin6_addr struct.
+ */
+ len = sa_in6->sin6_len -
+ (u_int8_t)(&((struct sockaddr_in6 *)NULL)->sin6_addr);
+ for (i = 0; i < len; i++) {
+ /* this "beauty" is adopted from sbin/route/show.c ... */
+ switch (sa_in6->sin6_addr.s6_addr[i]) {
+ 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:
+ errx(1, "non continguous inet6 netmask");
+ }
+ }
+
+ return (l);
+}
+
/* XXX local copy from kroute.c, should go to shared file */
-in_addr_t
+struct in6_addr *
prefixlen2mask(u_int8_t prefixlen)
{
- if (prefixlen == 0)
- return (0);
+ static struct in6_addr mask;
+ int i;
- return (0xffffffff << (32 - prefixlen));
+ bzero(&mask, sizeof(mask));
+ for (i = 0; i < prefixlen / 8; i++)
+ mask.s6_addr[i] = 0xff;
+ i = prefixlen % 8;
+ if (i)
+ mask.s6_addr[prefixlen / 8] = 0xff00 >> i;
+
+ return (&mask);
+}
+
+/* XXX local copy from kroute.c, should go to shared file */
+void
+inet6applymask(struct in6_addr *dest, const struct in6_addr *src, int prefixlen)
+{
+ struct in6_addr mask;
+ int i;
+
+ bzero(&mask, sizeof(mask));
+ for (i = 0; i < prefixlen / 8; i++)
+ mask.s6_addr[i] = 0xff;
+ i = prefixlen % 8;
+ if (i)
+ mask.s6_addr[prefixlen / 8] = 0xff00 >> i;
+
+ for (i = 0; i < 16; i++)
+ dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i];
}
diff --git a/usr.sbin/ospf6ctl/parser.h b/usr.sbin/ospf6ctl/parser.h
index 58820e269e9..fe3e9be8e8a 100644
--- a/usr.sbin/ospf6ctl/parser.h
+++ b/usr.sbin/ospf6ctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.1 2007/10/12 08:22:53 norby Exp $ */
+/* $OpenBSD: parser.h,v 1.2 2007/10/16 08:43:44 claudio Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -51,7 +51,7 @@ enum actions {
};
struct parse_result {
- struct in_addr addr;
+ struct in6_addr addr;
char ifname[IF_NAMESIZE];
int flags;
enum actions action;
@@ -61,8 +61,8 @@ struct parse_result {
struct parse_result *parse(int, char *[]);
const struct token *match_token(const char *, const struct token []);
void show_valid_args(const struct token []);
-int parse_addr(const char *, struct in_addr *);
-int parse_prefix(const char *, struct in_addr *,
+int parse_addr(const char *, struct in6_addr *);
+int parse_prefix(const char *, struct in6_addr *,
u_int8_t *);
#endif /* _PARSER_H_ */