it's always bothered me that i config areas on a crisco using a number, but then have to think hard to convert that number to an address for use in openbsd. eg, i was given area 700 in one place, which is 0.0.2.188 as an address. super annoying.
so this changes the ospfd parser so it accepts both a number or address. i also changed it so it prints the number by default, which may be contentious. the manpage is slightly tweaked too. thoughts? with this diff, i can do the following and things keep working: --- /etc/ospfd.conf Mon Apr 29 11:29:56 2019 +++ /etc/ospfd.conf.new Mon Apr 29 11:39:45 2019 @@ -7,5 +7,5 @@ redistribute rtlabel "backup" set metric 65535 -area 0.0.2.188 { +area 700 { router-dead-time minimal fast-hello-interval msec 300 Index: ospfd.conf.5 =================================================================== RCS file: /cvs/src/usr.sbin/ospfd/ospfd.conf.5,v retrieving revision 1.55 diff -u -p -r1.55 ospfd.conf.5 --- ospfd.conf.5 28 Dec 2018 19:25:10 -0000 1.55 +++ ospfd.conf.5 29 Apr 2019 01:45:40 -0000 @@ -68,7 +68,7 @@ Macros are not expanded inside quotes. For example: .Bd -literal -offset indent hi="5" -area 0.0.0.0 { +area 0 { interface em0 { hello-interval $hi } @@ -257,10 +257,10 @@ 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 id Ns | Ns Ar address Specify an area section, grouping one or more interfaces. .Bd -literal -offset indent -area 0.0.0.0 { +area 0 { interface em0 interface em1 { metric 10 Index: parse.y =================================================================== RCS file: /cvs/src/usr.sbin/ospfd/parse.y,v retrieving revision 1.95 diff -u -p -r1.95 parse.y --- parse.y 13 Feb 2019 22:57:08 -0000 1.95 +++ parse.y 29 Apr 2019 01:45:40 -0000 @@ -120,6 +120,7 @@ typedef struct { int64_t number; char *string; struct redistribute *redist; + struct in_addr id; } v; int lineno; } YYSTYPE; @@ -145,6 +146,7 @@ typedef struct { %type <v.number> deadtime %type <v.string> string dependon %type <v.redist> redistribute +%type <v.id> areaid %% @@ -588,15 +590,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)); md_list_copy(&areadefs.md_list, &defs->md_list); @@ -610,6 +605,23 @@ area : AREA STRING { 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 Index: printconf.c =================================================================== RCS file: /cvs/src/usr.sbin/ospfd/printconf.c,v retrieving revision 1.20 diff -u -p -r1.20 printconf.c --- printconf.c 28 Dec 2018 19:25:10 -0000 1.20 +++ printconf.c 29 Apr 2019 01:45:40 -0000 @@ -181,7 +181,8 @@ print_config(struct ospfd_conf *conf) printf("\n"); LIST_FOREACH(area, &conf->area_list, entry) { - printf("area %s {\n", inet_ntoa(area->id)); + printf("area %u { # %s\n", ntohl(area->id.s_addr), + inet_ntoa(area->id)); if (area->stub) { printf("\tstub"); if (SIMPLEQ_EMPTY(&area->redist_list))