ROA entires are allowing to define a prefix with a maxlen.
In the end this is just another way to specify a prefixlen range
and mostly an or-longer case with an upper limit.
So these two prefix statements are equivalent:
        prefix 10.0.0.0/8 prefixlen 8 - 24
        prefix 10.0.0.0/8 maxlen 24

I think this is a worthwhile addition.

While there also make 'prefixlen = 17' a OP_RANGE and because of that also
usable in prefix-set tables. Finally adjust printconf.c for those to
changes to print them nicely.
-- 
:wq Claudio


Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v
retrieving revision 1.350
diff -u -p -r1.350 parse.y
--- parse.y     10 Sep 2018 11:09:25 -0000      1.350
+++ parse.y     13 Sep 2018 09:30:54 -0000
@@ -218,7 +219,7 @@ typedef struct {
 %token IPSEC ESP AH SPI IKE
 %token IPV4 IPV6
 %token QUALIFY VIA
-%token NE LE GE XRANGE LONGER
+%token NE LE GE XRANGE LONGER MAXLEN
 %token <v.string>              STRING
 %token <v.number>              NUMBER
 %type  <v.number>              asnumber as4number as4number_any optnumber
@@ -2189,6 +2174,17 @@ prefixlenop      : /* empty */                   { 
bzero(&$$,
                        $$.len_min = -1;
                        $$.len_max = -1;
                }
+               | MAXLEN NUMBER                         {
+                       bzero(&$$, sizeof($$));
+                       if ($2 < 0 || $2 > 128) {
+                               yyerror("prefixlen must be >= 0 and <= 128");
+                               YYERROR;
+                       }
+
+                       $$.op = OP_RANGE;
+                       $$.len_min = -1;
+                       $$.len_max = $2;
+               }
                | PREFIXLEN unaryop NUMBER              {
                        int min, max;
 
@@ -2204,10 +2200,10 @@ prefixlenop     : /* empty */                   { 
bzero(&$$,
                        $$.op = OP_RANGE;
 
                        switch ($2) {
-                       case OP_EQ:
                        case OP_NE:
-                               min = max = $3;
                                $$.op = $2;
+                       case OP_EQ:
+                               min = max = $3;
                                break;
                        case OP_LT:
                                if ($3 == 0) {
@@ -2713,6 +2709,7 @@ lookup(char *s)
                { "max-as-len",         MAXASLEN},
                { "max-as-seq",         MAXASSEQ},
                { "max-prefix",         MAXPREFIX},
+               { "maxlen",             MAXLEN},
                { "md5sig",             MD5SIG},
                { "med",                MED},
                { "metric",             METRIC},
Index: printconf.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/printconf.c,v
retrieving revision 1.117
diff -u -p -r1.117 printconf.c
--- printconf.c 10 Sep 2018 11:01:15 -0000      1.117
+++ printconf.c 13 Sep 2018 09:29:25 -0000
@@ -77,9 +77,6 @@ print_prefix(struct filter_prefix *p)
        switch (p->op) {
        case OP_NONE:
                break;
-       case OP_EQ:
-               printf(" prefixlen = %u", p->len_min);
-               break;
        case OP_NE:
                printf(" prefixlen != %u", p->len_min);
                break;
@@ -87,8 +84,12 @@ print_prefix(struct filter_prefix *p)
                printf(" prefixlen %u >< %u ", p->len_min, p->len_max);
                break;
        case OP_RANGE:
-               if (p->len == p->len_min && p->len_max == max_len)
+               if (p->len == p->len_min && p->len == p->len_max)
+                       printf(" prefixlen = %u", p->len);
+               else if (p->len == p->len_min && p->len_max == max_len)
                        printf(" or-longer");
+               else if (p->len == p->len_min)
+                       printf(" maxlen %u", p->len_max);
                else if (p->len_max == max_len)
                        printf(" prefixlen >= %u", p->len_min);
                else

Reply via email to