## modules/rpsl/ifaddr.y

/* [<][>][^][v][top][bottom][index][help] */

## FUNCTIONS

This source file includes following functions.

1. yyparse
2. ifaddrerror

       1 %{
       2 /*
       3   filename: ifaddr.y
       4
       5   description:
       6     Defines the grammar for an RPSL ifaddr attribute.  It was mostly
       7     stolen from the IRRToolSet, simplified by removing ability to parse
       8     things defined by a dictionary (we use XML for extensibility rather
       9     than a dictionary).
      10
      11   notes:
      12     Defines tokens for the associated lexer, ifaddr.l.
      13 */
      14 %}
      15
      16 %union {
      17     char *sval;
      18 }
      19
      20 %token OP_OR OP_EQUAL OP_APPEND OP_COMPARE
      21 %token TKN_ASNO
      22 %token TKN_IPV4
      23 %token KEYW_ACTION
      24 %token TKN_PREF TKN_MED TKN_DPA TKN_ASPATH TKN_COMMUNITY TKN_NEXT_HOP TKN_COST
      25 %token TKN_COMM_NO
      26 %token KEYW_IGP_COST KEYW_SELF KEYW_PREPEND
      27 %token KEYW_APPEND KEYW_DELETE KEYW_CONTAINS
      28 %token KEYW_INTERNET KEYW_NO_EXPORT KEYW_NO_ADVERTISE KEYW_MASKLEN
      29 %token <sval> TKN_INT TKN_DNS
      30
      31 %{
      32 #include <stdio.h>
      33 #include <stdarg.h>
      34 #include <stdlib.h>
      35
      36 int yyerror(const char *s);
      37 void syntax_error(char *fmt, ...);
      38
      39 %}
      40
      41 %%
         /* [<][>][^][v][top][bottom][index][help] */
      42
      43 ifaddr: TKN_IPV4 KEYW_MASKLEN masklen
      44 | TKN_IPV4 KEYW_MASKLEN masklen KEYW_ACTION action
      45 ;
      46
      47 masklen: TKN_INT {
      48       long int val;
      49       char *s, *p;
      50       p = $1;
      51       val = strtol(p, &s, 10);
      52       if ((val < 0) || (val > 32) || (*s != '\0')) {
      53           syntax_error("masklen \"%s\" is not between 0 and 32", p);
      54       }
      55 }
      56 ;
      57
      58 action: rp_attribute ';'
      59 | action rp_attribute ';'
      60 ;
      61
      62 rp_attribute: pref
      63 | med
      64 | dpa
      65 | aspath
      66 | community
      67 | next_hop
      68 | cost
      69 ;
      70
      71 pref: TKN_PREF OP_EQUAL TKN_INT {
      72       long int val;
      73       char *s, *p;
      74       p = $3;
      75       val = strtol(p, &s, 10);
      76       if ((val < 0) || (val > 65535)) {
      77           syntax_error("pref value \"%s\" is not between 0 and 65535", p);
      78       }
      79 }
      80 ;
      81
      82 med: TKN_MED OP_EQUAL TKN_INT {
      83       long int val;
      84       char *s, *p;
      85       p = $3;
      86       val = strtol(p, &s, 10);
      87       if ((val < 0) || (val > 65535)) {
      88           syntax_error("med value \"%s\" is not between 0 and 65535", p);
      89       }
      90 }
      91 | TKN_MED OP_EQUAL KEYW_IGP_COST
      92 ;
      93
      94 dpa: TKN_DPA OP_EQUAL TKN_INT {
      95       long int val;
      96       char *s, *p;
      97       p = $3;
      98       val = strtol(p, &s, 10);
      99       if ((val < 0) || (val > 65535)) {
     100           syntax_error("dpa value \"%s\" is not between 0 and 65535", p);
     101       }
     102 }
     103 ;
     104
     105 aspath: TKN_ASPATH '.' KEYW_PREPEND '(' asno_list ')'
     106 ;
     107
     108 asno_list: TKN_ASNO
     109 | asno_list ',' TKN_ASNO
     110 ;
     111
     112 community: TKN_COMMUNITY OP_EQUAL community_list
     113 | TKN_COMMUNITY OP_APPEND community_list
     114 | TKN_COMMUNITY '.' KEYW_APPEND '(' community_elm_list ')'
     115 | TKN_COMMUNITY '.' KEYW_DELETE '(' community_elm_list ')'
     116 | TKN_COMMUNITY '.' KEYW_CONTAINS '(' community_elm_list ')'
     117 | TKN_COMMUNITY '(' community_elm_list ')'
     118 | TKN_COMMUNITY OP_COMPARE community_list
     119 ;
     120
     121 community_list: '{' community_elm_list '}'
     122 ;
     123
     124 community_elm_list: community_elm
     125 | community_elm_list ',' community_elm
     126 ;
     127
     128 community_elm: KEYW_INTERNET
     129 | KEYW_NO_EXPORT
     130 | KEYW_NO_ADVERTISE
     131 | TKN_INT {
     132       unsigned long int val;
     133       char *s, *p;
     134       p = $1;
     135       val = strtoul(p, &s, 10);
     136       if ((val < 1) || (val > 4294967295UL) || (*s != '\0')) {
     137           syntax_error("community element \"%s\" is not between 1 and 4294967295",
     138                        p);
     139       }
     140 }
     141 | TKN_COMM_NO
     142 ;
     143
     144 next_hop: TKN_NEXT_HOP OP_EQUAL TKN_IPV4
     145 | TKN_NEXT_HOP OP_EQUAL KEYW_SELF
     146 ;
     147
     148 cost: TKN_COST OP_EQUAL TKN_INT {
     149       long int val;
     150       char *s, *p;
     151       p = $3;
     152       val = strtol(p, &s, 10);
     153       if ((val < 0) || (val > 65535)) {
     154           syntax_error("cost value \"%s\" is not between 0 and 65535", p);
     155       }
     156 }
     157 ;
     158
     159 %%
     160
     161 #undef ifaddrerror
     162 #undef yyerror
     163
     164 int
     165 ifaddrerror (const char *s)
         /* [<][>][^][v][top][bottom][index][help] */
     166 {
     167     yyerror(s);
     168     return 0;
     169 }
     170

/* [<][>][^][v][top][bottom][index][help] */