summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Westphal <renato@cvs.openbsd.org>2016-05-23 19:04:56 +0000
committerRenato Westphal <renato@cvs.openbsd.org>2016-05-23 19:04:56 +0000
commit37fe2ca3530b7bcdd7ab773f9a955f62917f1375 (patch)
tree0aedde5d95ce83780985af2a2dd8a1c05fd6cbc4
parentf1ee6cbdee766108e6508013d61d1a66fed57925 (diff)
Sync with the latest IPv6 bits in ldpd(8).
-rw-r--r--usr.sbin/ldpctl/Makefile4
-rw-r--r--usr.sbin/ldpctl/ldpctl.840
-rw-r--r--usr.sbin/ldpctl/ldpctl.c163
-rw-r--r--usr.sbin/ldpctl/parser.c149
-rw-r--r--usr.sbin/ldpctl/parser.h9
5 files changed, 227 insertions, 138 deletions
diff --git a/usr.sbin/ldpctl/Makefile b/usr.sbin/ldpctl/Makefile
index b6e6ac4c561..9e915a9bef1 100644
--- a/usr.sbin/ldpctl/Makefile
+++ b/usr.sbin/ldpctl/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.2 2010/05/26 16:44:32 nicm Exp $
+# $OpenBSD: Makefile,v 1.3 2016/05/23 19:04:55 renato Exp $
.PATH: ${.CURDIR}/../ldpd
PROG= ldpctl
-SRCS= log.c ldpctl.c parser.c
+SRCS= util.c log.c ldpctl.c parser.c
CFLAGS+= -Wall
CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
CFLAGS+= -Wmissing-declarations
diff --git a/usr.sbin/ldpctl/ldpctl.8 b/usr.sbin/ldpctl/ldpctl.8
index fe368c290f8..9df8a04a2d0 100644
--- a/usr.sbin/ldpctl/ldpctl.8
+++ b/usr.sbin/ldpctl/ldpctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ldpctl.8,v 1.11 2016/05/23 19:01:32 renato Exp $
+.\" $OpenBSD: ldpctl.8,v 1.12 2016/05/23 19:04:55 renato Exp $
.\"
.\" Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
.\" Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -50,8 +50,14 @@ Disable verbose debug logging.
Enable verbose debug logging.
.It Cm reload
Reload the configuration file.
-.It Cm show fib Op Ar destination | filter
+.It Xo
+.Cm show fib
+.Op Cm family Ar family
+.Op Ar destination | filter
+.Xc
Show the Label Forwarding Information Base.
+.Ar family ,
+if given, limit the output to the given address family.
.Ar destination
can be specified to show the route matching a destination IP address.
.Ar filter
@@ -70,14 +76,34 @@ Show only static routes.
and
.Cm static
may be specified together.
-.It Cm show interfaces
+.It Xo
+.Cm show interfaces
+.Op Cm family Ar family
+.Xc
Show details for all interfaces.
-.It Cm show discovery
+.Ar family ,
+if given, limit the output to the given address family.
+.It Xo
+.Cm show discovery
+.Op Cm family Ar family
+.Xc
Show adjacencies.
-.It Cm show neighbor
+.Ar family ,
+if given, limit the output to the given address family.
+.It Xo
+.Cm show neighbor
+.Op Cm family Ar family
+.Xc
Show neighbors.
-.It Cm show lib
-Show the IPv4 Label Information Base.
+.Ar family ,
+if given, limit the output to the given address family.
+.It Xo
+.Cm show lib
+.Op Cm family Ar family
+.Xc
+Show the Label Information Base.
+.Ar family ,
+if given, limit the output to the given address family.
.It Cm show l2vpn bindings
Show the PWID Label Information Base.
.It Cm show l2vpn pseudowires
diff --git a/usr.sbin/ldpctl/ldpctl.c b/usr.sbin/ldpctl/ldpctl.c
index 1f1709cb632..17be13badad 100644
--- a/usr.sbin/ldpctl/ldpctl.c
+++ b/usr.sbin/ldpctl/ldpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpctl.c,v 1.29 2016/05/23 19:03:52 renato Exp $
+/* $OpenBSD: ldpctl.c,v 1.30 2016/05/23 19:04:55 renato Exp $
*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -38,18 +38,19 @@
#include "ldp.h"
#include "ldpd.h"
#include "ldpe.h"
+#include "log.h"
#include "parser.h"
__dead void usage(void);
const char *fmt_timeframe_core(time_t);
const char *get_linkstate(uint8_t, int);
-int show_interface_msg(struct imsg *);
-int show_discovery_msg(struct imsg *);
+int show_interface_msg(struct imsg *, struct parse_result *);
+int show_discovery_msg(struct imsg *, struct parse_result *);
uint64_t get_ifms_type(uint8_t);
-int show_lib_msg(struct imsg *);
-int show_nbr_msg(struct imsg *);
+int show_lib_msg(struct imsg *, struct parse_result *);
+int show_nbr_msg(struct imsg *, struct parse_result *);
void show_fib_head(void);
-int show_fib_msg(struct imsg *);
+int show_fib_msg(struct imsg *, struct parse_result *);
void show_interface_head(void);
int show_fib_interface_msg(struct imsg *);
int show_l2vpn_pw_msg(struct imsg *);
@@ -77,6 +78,7 @@ main(int argc, char *argv[])
struct parse_result *res;
struct imsg imsg;
unsigned int ifidx = 0;
+ struct kroute kr;
int ctl_sock;
int done = 0, verbose = 0;
int n;
@@ -110,8 +112,8 @@ main(int argc, char *argv[])
/* not reached */
case SHOW:
case SHOW_IFACE:
- printf("%-11s %-10s %-10s %-8s %-12s %3s\n",
- "Interface", "State", "Linkstate", "Uptime",
+ printf("%-4s %-11s %-6s %-10s %-8s %-12s %3s\n",
+ "AF", "Interface", "State", "Linkstate", "Uptime",
"Hello Timers", "ac");
if (*res->ifname) {
ifidx = if_nametoindex(res->ifname);
@@ -122,28 +124,33 @@ main(int argc, char *argv[])
&ifidx, sizeof(ifidx));
break;
case SHOW_DISC:
- printf("%-15s %-9s %-15s %-9s\n",
- "ID", "Type", "Source", "Holdtime");
+ printf("%-4s %-15s %-8s %-15s %9s\n",
+ "AF", "ID", "Type", "Source", "Holdtime");
imsg_compose(ibuf, IMSG_CTL_SHOW_DISCOVERY, 0, 0, -1,
NULL, 0);
break;
case SHOW_NBR:
- printf("%-15s %-18s %-15s %-10s\n", "ID",
- "State", "Address", "Uptime");
+ printf("%-4s %-15s %-11s %-15s %8s\n",
+ "AF", "ID", "State", "Remote Address", "Uptime");
imsg_compose(ibuf, IMSG_CTL_SHOW_NBR, 0, 0, -1, NULL, 0);
break;
case SHOW_LIB:
- printf("%-20s %-17s %-14s %-14s %-10s\n", "Destination",
- "Nexthop", "Local Label", "Remote Label", "In Use");
+ printf("%-4s %-20s %-15s %-11s %-13s %6s\n", "AF",
+ "Destination", "Nexthop", "Local Label", "Remote Label",
+ "In Use");
imsg_compose(ibuf, IMSG_CTL_SHOW_LIB, 0, 0, -1, NULL, 0);
break;
case SHOW_FIB:
- if (!res->addr.s_addr)
+ if (!ldp_addrisset(res->family, &res->addr))
imsg_compose(ibuf, IMSG_CTL_KROUTE, 0, 0, -1,
&res->flags, sizeof(res->flags));
- else
+ else {
+ memset(&kr, 0, sizeof(kr));
+ kr.af = res->family;
+ kr.prefix = res->addr;
imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1,
- &res->addr, sizeof(res->addr));
+ &kr, sizeof(kr));
+ }
show_fib_head();
break;
case SHOW_FIB_IFACE:
@@ -210,19 +217,19 @@ main(int argc, char *argv[])
switch (res->action) {
case SHOW:
case SHOW_IFACE:
- done = show_interface_msg(&imsg);
+ done = show_interface_msg(&imsg, res);
break;
case SHOW_DISC:
- done = show_discovery_msg(&imsg);
+ done = show_discovery_msg(&imsg, res);
break;
case SHOW_NBR:
- done = show_nbr_msg(&imsg);
+ done = show_nbr_msg(&imsg, res);
break;
case SHOW_LIB:
- done = show_lib_msg(&imsg);
+ done = show_lib_msg(&imsg, res);
break;
case SHOW_FIB:
- done = show_fib_msg(&imsg);
+ done = show_fib_msg(&imsg, res);
break;
case SHOW_FIB_IFACE:
done = show_fib_interface_msg(&imsg);
@@ -309,18 +316,8 @@ fmt_timeframe_core(time_t t)
return (buf);
}
-/* prototype defined in ldpd.h and shared with the kroute.c version */
-uint8_t
-mask2prefixlen(in_addr_t ina)
-{
- if (ina == 0)
- return (0);
- else
- return (33 - ffs(ntohl(ina)));
-}
-
int
-show_interface_msg(struct imsg *imsg)
+show_interface_msg(struct imsg *imsg, struct parse_result *res)
{
struct ctl_iface *iface;
char *timers;
@@ -329,16 +326,18 @@ show_interface_msg(struct imsg *imsg)
case IMSG_CTL_SHOW_INTERFACE:
iface = imsg->data;
+ if (res->family != AF_UNSPEC && res->family != iface->af)
+ break;
+
if (asprintf(&timers, "%u/%u", iface->hello_interval,
iface->hello_holdtime) == -1)
err(1, NULL);
- printf("%-11s %-10s %-10s %-8s %12s %3u\n",
- iface->name, if_state_name(iface->state),
- get_linkstate(iface->if_type, iface->linkstate),
- iface->uptime == 0 ? "00:00:00" :
- fmt_timeframe_core(iface->uptime), timers,
- iface->adj_cnt);
+ printf("%-4s %-11s %-6s %-10s %-8s %-12s %3u\n",
+ af_name(iface->af), iface->name,
+ if_state_name(iface->state), get_linkstate(iface->if_type,
+ iface->linkstate), iface->uptime == 0 ? "00:00:00" :
+ fmt_timeframe_core(iface->uptime), timers, iface->adj_cnt);
free(timers);
break;
case IMSG_CTL_END:
@@ -352,25 +351,32 @@ show_interface_msg(struct imsg *imsg)
}
int
-show_discovery_msg(struct imsg *imsg)
+show_discovery_msg(struct imsg *imsg, struct parse_result *res)
{
- struct ctl_adj *adj;
+ struct ctl_adj *adj;
+ const char *addr;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_DISCOVERY:
adj = imsg->data;
- printf("%-15s ", inet_ntoa(adj->id));
+ if (res->family != AF_UNSPEC && res->family != adj->af)
+ break;
+
+ printf("%-4s %-15s ", af_name(adj->af), inet_ntoa(adj->id));
switch(adj->type) {
case HELLO_LINK:
- printf("%-9s %-15s ", "Link", adj->ifname);
+ printf("%-8s %-15s ", "Link", adj->ifname);
break;
case HELLO_TARGETED:
- printf("%-9s %-15s ", "Targeted",
- inet_ntoa(adj->src_addr));
+ addr = log_addr(adj->af, &adj->src_addr);
+
+ printf("%-8s %-15s ", "Targeted", addr);
+ if (strlen(addr) > 15)
+ printf("\n%46s", " ");
break;
}
- printf("%-9u\n", adj->holdtime);
+ printf("%9u\n", adj->holdtime);
break;
case IMSG_CTL_END:
printf("\n");
@@ -383,7 +389,7 @@ show_discovery_msg(struct imsg *imsg)
}
int
-show_lib_msg(struct imsg *imsg)
+show_lib_msg(struct imsg *imsg, struct parse_result *res)
{
struct ctl_rt *rt;
char *dstnet, *local = NULL, *remote = NULL;
@@ -391,15 +397,22 @@ show_lib_msg(struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_LIB:
rt = imsg->data;
- if (asprintf(&dstnet, "%s/%d", inet_ntoa(rt->prefix),
+
+ if (res->family != AF_UNSPEC && res->family != rt->af)
+ break;
+
+ if (asprintf(&dstnet, "%s/%d", log_addr(rt->af, &rt->prefix),
rt->prefixlen) == -1)
err(1, NULL);
- printf("%-20s %-17s %-14s %-14s %s\n", dstnet,
- inet_ntoa(rt->nexthop),
+ printf("%-4s %-20s", af_name(rt->af), dstnet);
+ if (strlen(dstnet) > 20)
+ printf("\n%25s", " ");
+ printf(" %-15s %-11s %-13s %6s\n", inet_ntoa(rt->nexthop),
print_label(&local, rt->local_label),
print_label(&remote, rt->remote_label),
rt->in_use ? "yes" : "no");
+
free(remote);
free(local);
free(dstnet);
@@ -415,17 +428,27 @@ show_lib_msg(struct imsg *imsg)
}
int
-show_nbr_msg(struct imsg *imsg)
+show_nbr_msg(struct imsg *imsg, struct parse_result *res)
{
struct ctl_nbr *nbr;
+ const char *addr;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_NBR:
nbr = imsg->data;
- printf("%-15s %-19s", inet_ntoa(nbr->id),
- nbr_state_name(nbr->nbr_state));
- printf("%-15s %-15s\n", inet_ntoa(nbr->addr),
- nbr->uptime == 0 ? "-" : fmt_timeframe_core(nbr->uptime));
+
+ if (res->family != AF_UNSPEC && res->family != nbr->af)
+ break;
+
+ addr = log_addr(nbr->af, &nbr->raddr);
+
+ printf("%-4s %-15s %-11s %-15s",
+ af_name(nbr->af), inet_ntoa(nbr->id),
+ nbr_state_name(nbr->nbr_state), addr);
+ if (strlen(addr) > 15)
+ printf("\n%48s", " ");
+ printf(" %8s\n", nbr->uptime == 0 ? "-" :
+ fmt_timeframe_core(nbr->uptime));
break;
case IMSG_CTL_END:
printf("\n");
@@ -446,11 +469,12 @@ show_fib_head(void)
}
int
-show_fib_msg(struct imsg *imsg)
+show_fib_msg(struct imsg *imsg, struct parse_result *res)
{
struct kroute *k;
char *p;
char *local = NULL, *remote = NULL;
+ const char *nexthop;
switch (imsg->hdr.type) {
case IMSG_CTL_KROUTE:
@@ -458,6 +482,9 @@ show_fib_msg(struct imsg *imsg)
errx(1, "wrong imsg len");
k = imsg->data;
+ if (res->family != AF_UNSPEC && res->family != k->af)
+ break;
+
if (k->flags & F_CONNECTED)
printf("C");
else if (k->flags & F_STATIC)
@@ -466,15 +493,31 @@ show_fib_msg(struct imsg *imsg)
printf(" ");
printf(" %3d ", k->priority);
- if (asprintf(&p, "%s/%u", inet_ntoa(k->prefix),
+ if (asprintf(&p, "%s/%u", log_addr(k->af, &k->prefix),
k->prefixlen) == -1)
err(1, NULL);
printf("%-20s ", p);
+ if (strlen(p) > 20)
+ printf("\n%27s", " ");
free(p);
- if (k->nexthop.s_addr)
- printf("%-18s", inet_ntoa(k->nexthop));
- else if (k->flags & F_CONNECTED)
+ if (ldp_addrisset(k->af, &k->nexthop)) {
+ switch (k->af) {
+ case AF_INET:
+ printf("%-18s", inet_ntoa(k->nexthop.v4));
+ break;
+ case AF_INET6:
+ nexthop = log_in6addr_scope(&k->nexthop.v6,
+ k->ifindex);
+ printf("%-18s", nexthop);
+ if (strlen(nexthop) > 18)
+ printf("\n%45s", " ");
+ break;
+ default:
+ printf("%-18s", " ");
+ break;
+ }
+ } else if (k->flags & F_CONNECTED)
printf("link#%-13u", k->ifindex);
printf("%-18s", print_label(&local, k->local_label));
diff --git a/usr.sbin/ldpctl/parser.c b/usr.sbin/ldpctl/parser.c
index d8c073e312d..058f112a37e 100644
--- a/usr.sbin/ldpctl/parser.c
+++ b/usr.sbin/ldpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.10 2016/05/23 19:02:49 renato Exp $ */
+/* $OpenBSD: parser.c,v 1.11 2016/05/23 19:04:55 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <netdb.h>
#include "ldpd.h"
@@ -37,9 +38,9 @@ enum token_type {
NOTOKEN,
ENDTOKEN,
KEYWORD,
+ FAMILY,
ADDRESS,
FLAG,
- PREFIX,
IFNAME
};
@@ -54,11 +55,15 @@ static const struct token t_main[];
static const struct token t_fib[];
static const struct token t_show[];
static const struct token t_show_iface[];
+static const struct token t_show_iface_af[];
static const struct token t_show_disc[];
-
+static const struct token t_show_disc_af[];
static const struct token t_show_nbr[];
+static const struct token t_show_nbr_af[];
static const struct token t_show_lib[];
+static const struct token t_show_lib_af[];
static const struct token t_show_fib[];
+static const struct token t_show_fib_af[];
static const struct token t_show_l2vpn[];
static const struct token t_log[];
@@ -88,38 +93,62 @@ static const struct token t_show[] = {
};
static const struct token t_show_iface[] = {
- {NOTOKEN, "", NONE, NULL},
- {ENDTOKEN, "", NONE, NULL}
+ {NOTOKEN, "", NONE, NULL},
+ {KEYWORD, "family", NONE, t_show_iface_af},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_show_iface_af[] = {
+ {FAMILY, "", NONE, t_show_iface},
+ {ENDTOKEN, "", NONE, NULL}
};
static const struct token t_show_disc[] = {
- {NOTOKEN, "", NONE, NULL},
- {ENDTOKEN, "", NONE, NULL}
+ {NOTOKEN, "", NONE, NULL},
+ {KEYWORD, "family", NONE, t_show_disc_af},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_show_disc_af[] = {
+ {FAMILY, "", NONE, t_show_disc},
+ {ENDTOKEN, "", NONE, NULL}
};
static const struct token t_show_nbr[] = {
{NOTOKEN, "", NONE, NULL},
+ {KEYWORD, "family", NONE, t_show_nbr_af},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_show_nbr_af[] = {
+ {FAMILY, "", NONE, t_show_nbr},
{ENDTOKEN, "", NONE, NULL}
};
static const struct token t_show_lib[] = {
{NOTOKEN, "", NONE, NULL},
+ {KEYWORD, "family", NONE, t_show_lib_af},
{ENDTOKEN, "", NONE, NULL}
};
-static const struct token t_log[] = {
- {KEYWORD, "verbose", LOG_VERBOSE, NULL},
- {KEYWORD, "brief", LOG_BRIEF, NULL},
+static const struct token t_show_lib_af[] = {
+ {FAMILY, "", NONE, t_show_lib},
{ENDTOKEN, "", NONE, NULL}
};
static const struct token t_show_fib[] = {
- {NOTOKEN, "", NONE, NULL},
- {KEYWORD, "interface", SHOW_FIB_IFACE, t_show_iface},
- {FLAG, "connected", F_CONNECTED, t_show_fib},
- {FLAG, "static", F_STATIC, t_show_fib},
- {ADDRESS, "", NONE, NULL},
- {ENDTOKEN, "", NONE, NULL}
+ {NOTOKEN, "", NONE, NULL},
+ {KEYWORD, "family", NONE, t_show_fib_af},
+ {KEYWORD, "interface", SHOW_FIB_IFACE, t_show_iface},
+ {FLAG, "connected", F_CONNECTED, t_show_fib},
+ {FLAG, "static", F_STATIC, t_show_fib},
+ {ADDRESS, "", NONE, NULL},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_show_fib_af[] = {
+ {FAMILY, "", NONE, t_show_fib},
+ {ENDTOKEN, "", NONE, NULL}
};
static const struct token t_show_l2vpn[] = {
@@ -128,6 +157,12 @@ static const struct token t_show_l2vpn[] = {
{ENDTOKEN, "", NONE, NULL}
};
+static const struct token t_log[] = {
+ {KEYWORD, "verbose", LOG_VERBOSE, NULL},
+ {KEYWORD, "brief", LOG_BRIEF, NULL},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
static const struct token *match_token(const char *, const struct token *,
struct parse_result *);
static void show_valid_args(const struct token *);
@@ -199,16 +234,24 @@ match_token(const char *word, const struct token *table,
res->flags |= t->value;
}
break;
- case ADDRESS:
- if (parse_addr(word, &res->addr)) {
+ case FAMILY:
+ if (word == NULL)
+ break;
+ if (!strcmp(word, "inet") ||
+ !strcasecmp(word, "IPv4")) {
match++;
t = &table[i];
- if (t->value)
- res->action = t->value;
+ res->family = AF_INET;
+ }
+ if (!strcmp(word, "inet6") ||
+ !strcasecmp(word, "IPv6")) {
+ match++;
+ t = &table[i];
+ res->family = AF_INET6;
}
break;
- case PREFIX:
- if (parse_prefix(word, &res->addr, &res->prefixlen)) {
+ case ADDRESS:
+ if (parse_addr(word, &res->family, &res->addr)) {
match++;
t = &table[i];
if (t->value)
@@ -260,12 +303,12 @@ show_valid_args(const struct token *table)
case FLAG:
fprintf(stderr, " %s\n", table[i].keyword);
break;
+ case FAMILY:
+ fprintf(stderr, " [ inet | inet6 | IPv4 | IPv6 ]\n");
+ break;
case ADDRESS:
fprintf(stderr, " <address>\n");
break;
- case PREFIX:
- fprintf(stderr, " <address>[/<len>]\n");
- break;
case IFNAME:
fprintf(stderr, " <interface>\n");
case ENDTOKEN:
@@ -275,57 +318,35 @@ show_valid_args(const struct token *table)
}
int
-parse_addr(const char *word, struct in_addr *addr)
+parse_addr(const char *word, int *family, union ldpd_addr *addr)
{
- struct in_addr ina;
+ struct in_addr ina;
+ struct addrinfo hints, *r;
+ struct sockaddr_in6 *sa_in6;
if (word == NULL)
return (0);
- memset(addr, 0, sizeof(struct in_addr));
+ memset(addr, 0, sizeof(*addr));
memset(&ina, 0, sizeof(ina));
- if (inet_pton(AF_INET, word, &ina)) {
- addr->s_addr = ina.s_addr;
+ if (inet_net_pton(AF_INET, word, &ina, sizeof(ina)) != -1) {
+ *family = AF_INET;
+ addr->v4.s_addr = ina.s_addr;
return (1);
}
- return (0);
-}
-
-int
-parse_prefix(const char *word, struct in_addr *addr, uint8_t *prefixlen)
-{
- struct in_addr ina;
- int bits = 32;
-
- if (word == NULL)
- return (0);
-
- memset(addr, 0, sizeof(struct in_addr));
- memset(&ina, 0, sizeof(ina));
-
- if (strrchr(word, '/') != NULL) {
- if ((bits = inet_net_pton(AF_INET, word,
- &ina, sizeof(ina))) == -1)
- return (0);
- addr->s_addr = ina.s_addr & htonl(prefixlen2mask(bits));
- *prefixlen = bits;
+ memset(&hints, 0, 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) {
+ sa_in6 = (struct sockaddr_in6 *)r->ai_addr;
+ *family = AF_INET6;
+ addr->v6 = sa_in6->sin6_addr;
+ freeaddrinfo(r);
return (1);
- } else {
- *prefixlen = 32;
- return (parse_addr(word, addr));
}
return (0);
}
-
-/* XXX local copy from kroute.c, should go to shared file */
-in_addr_t
-prefixlen2mask(uint8_t prefixlen)
-{
- if (prefixlen == 0)
- return (0);
-
- return (0xffffffff << (32 - prefixlen));
-}
diff --git a/usr.sbin/ldpctl/parser.h b/usr.sbin/ldpctl/parser.h
index 3cb816c04ee..a294e7ada5c 100644
--- a/usr.sbin/ldpctl/parser.h
+++ b/usr.sbin/ldpctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.8 2016/05/23 19:01:08 renato Exp $ */
+/* $OpenBSD: parser.h,v 1.9 2016/05/23 19:04:55 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -45,7 +45,8 @@ enum actions {
};
struct parse_result {
- struct in_addr addr;
+ int family;
+ union ldpd_addr addr;
char ifname[IF_NAMESIZE];
int flags;
enum actions action;
@@ -53,8 +54,6 @@ struct parse_result {
};
struct parse_result *parse(int, char *[]);
-int parse_addr(const char *, struct in_addr *);
-int parse_prefix(const char *, struct in_addr *,
- uint8_t *);
+int parse_addr(const char *, int *, union ldpd_addr *);
#endif /* _PARSER_H_ */