On Tue, Apr 30, 2019 at 11:10:37PM +0200, Remi Locherer wrote:
> On Mon, Apr 29, 2019 at 11:10:31AM +0100, Stuart Henderson wrote:
> > On 2019/04/29 11:58, Sebastian Benoit wrote:
> > > David Gwynne(da...@gwynne.id.au) on 2019.04.29 19:36:51 +1000:
> > > > 
> > > > 
> > > > > On 29 Apr 2019, at 4:59 pm, Remi Locherer <remi.loche...@relo.ch> 
> > > > > wrote:
> > > > > 
> > > > > Hi David
> > > > > 
> > > > > On Mon, Apr 29, 2019 at 11:53:27AM +1000, David Gwynne wrote:
> > > > >> 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?
> > > > > 
> > > > > I like it to be able to use a number instead of an address!
> > > > > 
> > > > > It worked fine in my short test I performed.
> > > > > 
> > > > > The output with the comment looks a bit strange to me.
> > > > 
> > > > Are you sure it doesn't look... awesome?
> > > 
> > > I like it!
> > 
> > I don't really, but if we change this it needs to be displayed somehow
> > and I don't have an idea to make it look nicer than this (cisco's method
> > seems pretty horrible and wouldn't work for us anyway - looks like they
> > remember which format was used to configure an area and use that as
> > the output format...)
> > 
> 
> Maybe it's better when we just allow both input formats but don't change
> any output.

Any opinions or comments on this? I think this would be a valuable addition
to ospfd.

> 
> Below diff changes ospfctl to accept the address and number format for
> "ospfct show database area XXX".
> 
> 
> Index: parser.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ospfctl/parser.c,v
> retrieving revision 1.20
> diff -u -p -r1.20 parser.c
> --- parser.c  9 May 2011 12:25:35 -0000       1.20
> +++ parser.c  30 Apr 2019 20:28:18 -0000
> @@ -39,7 +39,8 @@ enum token_type {
>       ADDRESS,
>       FLAG,
>       PREFIX,
> -     IFNAME
> +     IFNAME,
> +     AREA
>  };
>  
>  struct token {
> @@ -107,7 +108,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->addr)) {
> +                             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;
> @@ -298,6 +310,32 @@ parse_addr(const char *word, struct in_a
>       bzero(&ina, sizeof(ina));
>  
>       if (inet_pton(AF_INET, word, &ina)) {
> +             addr->s_addr = ina.s_addr;
> +             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);
>       }
> Index: parser.h
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ospfctl/parser.h,v
> retrieving revision 1.13
> diff -u -p -r1.13 parser.h
> --- parser.h  9 May 2011 12:25:35 -0000       1.13
> +++ parser.h  30 Apr 2019 20:28:52 -0000
> @@ -64,6 +64,7 @@ struct parse_result {
>  
>  struct parse_result  *parse(int, char *[]);
>  int                   parse_addr(const char *, struct in_addr *);
> +int                   parse_area(const char *, struct in_addr *);
>  int                   parse_prefix(const char *, struct in_addr *,
>                            u_int8_t *);
>  
> 

Reply via email to