diff options
-rw-r--r-- | usr.sbin/ospf6ctl/ospf6ctl.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospf6ctl/parser.c | 43 | ||||
-rw-r--r-- | usr.sbin/ospf6ctl/parser.h | 4 | ||||
-rw-r--r-- | usr.sbin/ospf6d/ospf6d.conf.5 | 6 | ||||
-rw-r--r-- | usr.sbin/ospf6d/parse.y | 32 |
5 files changed, 70 insertions, 19 deletions
diff --git a/usr.sbin/ospf6ctl/ospf6ctl.c b/usr.sbin/ospf6ctl/ospf6ctl.c index ec2b5c3c2c6..e19a1270f7e 100644 --- a/usr.sbin/ospf6ctl/ospf6ctl.c +++ b/usr.sbin/ospf6ctl/ospf6ctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospf6ctl.c,v 1.49 2018/07/12 13:45:03 remi Exp $ */ +/* $OpenBSD: ospf6ctl.c,v 1.50 2019/05/26 09:27:09 remi Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -170,7 +170,7 @@ main(int argc, char *argv[]) break; case SHOW_DBBYAREA: imsg_compose(ibuf, IMSG_CTL_SHOW_DATABASE, 0, 0, -1, - &res->addr, sizeof(res->addr)); + &res->area, sizeof(res->area)); break; case SHOW_DBEXT: imsg_compose(ibuf, IMSG_CTL_SHOW_DB_EXT, 0, 0, -1, NULL, 0); diff --git a/usr.sbin/ospf6ctl/parser.c b/usr.sbin/ospf6ctl/parser.c index 79d2fbda907..a23bd44d6e8 100644 --- a/usr.sbin/ospf6ctl/parser.c +++ b/usr.sbin/ospf6ctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.13 2014/11/17 21:53:55 tobias Exp $ */ +/* $OpenBSD: parser.c,v 1.14 2019/05/26 09:27:09 remi Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -40,7 +40,8 @@ enum token_type { ADDRESS, FLAG, PREFIX, - IFNAME + IFNAME, + AREA }; struct token { @@ -108,7 +109,7 @@ static const struct token t_show_db[] = { }; static const struct token t_show_area[] = { - {ADDRESS, "", NONE, NULL}, + {AREA, "", NONE, NULL}, {ENDTOKEN, "", NONE, NULL} }; @@ -218,6 +219,14 @@ match_token(const char *word, const struct token *table, res->action = t->value; } break; + case AREA: + if (parse_area(word, &res->area)) { + match++; + t = &table[i]; + if (t->value) + res->action = t->value; + } + break; case PREFIX: if (parse_prefix(word, &res->addr, &res->prefixlen)) { match++; @@ -274,6 +283,9 @@ show_valid_args(const struct token *table) case ADDRESS: fprintf(stderr, " <address>\n"); break; + case AREA: + fprintf(stderr, " <area>\n"); + break; case PREFIX: fprintf(stderr, " <address>[/<len>]\n"); break; @@ -310,6 +322,31 @@ parse_addr(const char *word, struct in6_addr *addr) return (0); } +int +parse_area(const char *word, struct in_addr *addr) +{ + struct in_addr ina; + const char *errstr; + + 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; + return (1); + } + + ina.s_addr = htonl(strtonum(word, 0, 0xffffffff, &errstr)); + if (errstr == NULL) { + addr->s_addr = ina.s_addr; + return (1); + } + return (0); +} + /* XXX shared with parse.y should be merged */ int parse_prefix(const char *word, struct in6_addr *addr, u_int8_t *prefixlen) diff --git a/usr.sbin/ospf6ctl/parser.h b/usr.sbin/ospf6ctl/parser.h index ae7ed925bed..b5bf971419b 100644 --- a/usr.sbin/ospf6ctl/parser.h +++ b/usr.sbin/ospf6ctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.8 2010/09/04 21:31:04 tedu Exp $ */ +/* $OpenBSD: parser.h,v 1.9 2019/05/26 09:27:09 remi Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -55,6 +55,7 @@ enum actions { struct parse_result { struct in6_addr addr; + struct in_addr area; char ifname[IF_NAMESIZE]; int flags; enum actions action; @@ -63,6 +64,7 @@ struct parse_result { struct parse_result *parse(int, char *[]); int parse_addr(const char *, struct in6_addr *); +int parse_area(const char *, struct in_addr *); int parse_prefix(const char *, struct in6_addr *, u_int8_t *); diff --git a/usr.sbin/ospf6d/ospf6d.conf.5 b/usr.sbin/ospf6d/ospf6d.conf.5 index 1071b7e991b..0a70d025c35 100644 --- a/usr.sbin/ospf6d/ospf6d.conf.5 +++ b/usr.sbin/ospf6d/ospf6d.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ospf6d.conf.5,v 1.18 2018/12/29 16:04:31 remi Exp $ +.\" $OpenBSD: ospf6d.conf.5,v 1.19 2019/05/26 09:27:09 remi Exp $ .\" .\" Copyright (c) 2005 Esben Norby <norby@openbsd.org> .\" Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -17,7 +17,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: December 29 2018 $ +.Dd $Mdocdate: May 26 2019 $ .Dt OSPF6D.CONF 5 .Os .Sh NAME @@ -237,7 +237,7 @@ Areas are used for grouping interfaces. All interface-specific parameters can be configured per area, overruling the global settings. .Bl -tag -width Ds -.It Ic area Ar address +.It Ic area Ar address Ns | Ns Ar id Specify an area section, grouping one or more interfaces. .Bd -literal -offset indent area 0.0.0.0 { diff --git a/usr.sbin/ospf6d/parse.y b/usr.sbin/ospf6d/parse.y index 633634dba6b..4a9b5331946 100644 --- a/usr.sbin/ospf6d/parse.y +++ b/usr.sbin/ospf6d/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.43 2019/04/29 05:14:38 remi Exp $ */ +/* $OpenBSD: parse.y,v 1.44 2019/05/26 09:27:09 remi Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -117,6 +117,7 @@ typedef struct { int64_t number; char *string; struct redistribute *redist; + struct in_addr id; } v; int lineno; } YYSTYPE; @@ -139,6 +140,7 @@ typedef struct { %type <v.number> yesno no optlist, optlist_l option demotecount %type <v.string> string dependon %type <v.redist> redistribute +%type <v.id> areaid %% @@ -456,15 +458,8 @@ comma : ',' | /*empty*/ ; -area : AREA STRING { - struct in_addr id; - if (inet_aton($2, &id) == 0) { - yyerror("error parsing area"); - free($2); - YYERROR; - } - free($2); - area = conf_get_area(id); +area : AREA areaid { + area = conf_get_area($2); memcpy(&areadefs, defs, sizeof(areadefs)); defs = &areadefs; @@ -478,6 +473,23 @@ demotecount : NUMBER { $$ = $1; } | /*empty*/ { $$ = 1; } ; +areaid : NUMBER { + if ($1 < 0 || $1 > 0xffffffff) { + yyerror("invalid area id"); + YYERROR; + } + $$.s_addr = htonl($1); + } + | STRING { + if (inet_aton($1, &$$) == 0) { + yyerror("error parsing area"); + free($1); + YYERROR; + } + free($1); + } + ; + areaopts_l : areaopts_l areaoptsl nl | areaoptsl optnl ; |