ospf6d: allow specifying area by number as well as id

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ospf6d: allow specifying area by number as well as id

Remi Locherer
Hi tech@,

David sent a diff for ospfd which allows specifying an area by number
as well as id.
--> https://marc.info/?l=openbsd-tech&m=155650284619263&w=2

This diff does the same for ospf6d and ospf6ctl without modifying any
outputs.

OK?

Remi

 
Index: ospf6d/ospf6d.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.conf.5,v
retrieving revision 1.18
diff -u -p -r1.18 ospf6d.conf.5
--- ospf6d/ospf6d.conf.5 29 Dec 2018 16:04:31 -0000 1.18
+++ ospf6d/ospf6d.conf.5 22 May 2019 21:04:58 -0000
@@ -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 {
Index: ospf6d/parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
retrieving revision 1.43
diff -u -p -r1.43 parse.y
--- ospf6d/parse.y 29 Apr 2019 05:14:38 -0000 1.43
+++ ospf6d/parse.y 22 May 2019 20:58:26 -0000
@@ -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;
@@ -476,6 +471,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: ospf6ctl/ospf6ctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6ctl/ospf6ctl.c,v
retrieving revision 1.49
diff -u -p -r1.49 ospf6ctl.c
--- ospf6ctl/ospf6ctl.c 12 Jul 2018 13:45:03 -0000 1.49
+++ ospf6ctl/ospf6ctl.c 22 May 2019 20:18:45 -0000
@@ -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);
Index: ospf6ctl/parser.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6ctl/parser.c,v
retrieving revision 1.13
diff -u -p -r1.13 parser.c
--- ospf6ctl/parser.c 17 Nov 2014 21:53:55 -0000 1.13
+++ ospf6ctl/parser.c 22 May 2019 20:20:17 -0000
@@ -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 stru
  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 *tabl
  case ADDRESS:
  fprintf(stderr, "  <address>\n");
  break;
+ case AREA:
+ fprintf(stderr, "  <area>\n");
+ break;
  case PREFIX:
  fprintf(stderr, "  <address>[/<len>]\n");
  break;
@@ -305,6 +317,31 @@ parse_addr(const char *word, struct in6_
  /* XXX address scope !!! */
  /* ((struct sockaddr_in6 *)r->ai_addr)->sin6_scope_id */
  freeaddrinfo(r);
+ return (1);
+ }
+ 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);
Index: ospf6ctl/parser.h
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6ctl/parser.h,v
retrieving revision 1.8
diff -u -p -r1.8 parser.h
--- ospf6ctl/parser.h 4 Sep 2010 21:31:04 -0000 1.8
+++ ospf6ctl/parser.h 22 May 2019 20:26:08 -0000
@@ -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 *);
 

Reply | Threaded
Open this post in threaded view
|

Re: ospf6d: allow specifying area by number as well as id

Denis Fondras-3
On Thu, May 23, 2019 at 10:58:51PM +0200, Remi Locherer wrote:

> Hi tech@,
>
> David sent a diff for ospfd which allows specifying an area by number
> as well as id.
> --> https://marc.info/?l=openbsd-tech&m=155650284619263&w=2
>
> This diff does the same for ospf6d and ospf6ctl without modifying any
> outputs.
>
> OK?
>

OK denis@

> Remi
>
>  
> Index: ospf6d/ospf6d.conf.5
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ospf6d/ospf6d.conf.5,v
> retrieving revision 1.18
> diff -u -p -r1.18 ospf6d.conf.5
> --- ospf6d/ospf6d.conf.5 29 Dec 2018 16:04:31 -0000 1.18
> +++ ospf6d/ospf6d.conf.5 22 May 2019 21:04:58 -0000
> @@ -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 {
> Index: ospf6d/parse.y
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
> retrieving revision 1.43
> diff -u -p -r1.43 parse.y
> --- ospf6d/parse.y 29 Apr 2019 05:14:38 -0000 1.43
> +++ ospf6d/parse.y 22 May 2019 20:58:26 -0000
> @@ -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;
> @@ -476,6 +471,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: ospf6ctl/ospf6ctl.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ospf6ctl/ospf6ctl.c,v
> retrieving revision 1.49
> diff -u -p -r1.49 ospf6ctl.c
> --- ospf6ctl/ospf6ctl.c 12 Jul 2018 13:45:03 -0000 1.49
> +++ ospf6ctl/ospf6ctl.c 22 May 2019 20:18:45 -0000
> @@ -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);
> Index: ospf6ctl/parser.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ospf6ctl/parser.c,v
> retrieving revision 1.13
> diff -u -p -r1.13 parser.c
> --- ospf6ctl/parser.c 17 Nov 2014 21:53:55 -0000 1.13
> +++ ospf6ctl/parser.c 22 May 2019 20:20:17 -0000
> @@ -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 stru
>   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 *tabl
>   case ADDRESS:
>   fprintf(stderr, "  <address>\n");
>   break;
> + case AREA:
> + fprintf(stderr, "  <area>\n");
> + break;
>   case PREFIX:
>   fprintf(stderr, "  <address>[/<len>]\n");
>   break;
> @@ -305,6 +317,31 @@ parse_addr(const char *word, struct in6_
>   /* XXX address scope !!! */
>   /* ((struct sockaddr_in6 *)r->ai_addr)->sin6_scope_id */
>   freeaddrinfo(r);
> + return (1);
> + }
> + 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);
> Index: ospf6ctl/parser.h
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ospf6ctl/parser.h,v
> retrieving revision 1.8
> diff -u -p -r1.8 parser.h
> --- ospf6ctl/parser.h 4 Sep 2010 21:31:04 -0000 1.8
> +++ ospf6ctl/parser.h 22 May 2019 20:26:08 -0000
> @@ -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 *);
>  
>