Navigation


Changeset 12:418d2ce80dc8 in freeDiameter for freeDiameter/fdd.y


Ignore:
Timestamp:
Sep 28, 2009, 5:29:25 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added support in configuration file for peers declaration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/fdd.y

    r10 r12  
    7070}
    7171
     72int got_peer_noip = 0;
     73int got_peer_noipv6 = 0;
     74int got_peer_notcp = 0;
     75int got_peer_nosctp = 0;
     76
     77struct peer_info fddpi;
     78
    7279%}
    7380
    7481/* Values returned by lex for token */
    7582%union {
    76         char            *string;        /* The string is allocated by strdup in lex.*/
    77         int              integer;       /* Store integer values */
     83        char             *string;       /* The string is allocated by strdup in lex.*/
     84        int               integer;      /* Store integer values */
    7885}
    7986
     
    8491%token <integer> INTEGER
    8592
    86 %type <string> extconf
    87 
    88 %token          LOCALIDENTITY
    89 %token          LOCALREALM
    90 %token          LOCALPORT
    91 %token          LOCALSECPORT
     93%type <string>  extconf
     94
     95%token          IDENTITY
     96%token          REALM
     97%token          PORT
     98%token          SECPORT
    9299%token          NOIP
    93100%token          NOIP6
     
    96103%token          PREFERTCP
    97104%token          OLDTLS
     105%token          NOTLS
    98106%token          SCTPSTREAMS
    99107%token          LISTENON
     
    102110%token          NORELAY
    103111%token          LOADEXT
     112%token          CONNPEER
     113%token          CONNTO
    104114
    105115
     
    109119        /* The grammar definition - Sections blocs. */
    110120conffile:               /* Empty is OK */
    111                         | conffile localidentity
    112                         | conffile localrealm
     121                        | conffile identity
     122                        | conffile realm
    113123                        | conffile tctimer
    114124                        | conffile twtimer
    115                         | conffile localport
    116                         | conffile localsecport
     125                        | conffile port
     126                        | conffile secport
    117127                        | conffile sctpstreams
    118128                        | conffile listenon
     
    125135                        | conffile oldtls
    126136                        | conffile loadext
    127                         ;
    128 
    129 localidentity:          LOCALIDENTITY '=' QSTRING ';'
     137                        | conffile connpeer
     138                        | conffile errors
     139                        {
     140                                yyerror(&yylloc, conf, "An error occurred while parsing the configuration file");
     141                                return EINVAL;
     142                        }
     143                        ;
     144
     145                        /* Lexical or syntax error */
     146errors:                 LEX_ERROR
     147                        | error
     148                        ;
     149
     150identity:               IDENTITY '=' QSTRING ';'
    130151                        {
    131152                                conf->cnf_diamid = $3;
     
    133154                        ;
    134155
    135 localrealm:             LOCALREALM '=' QSTRING ';'
     156realm:                  REALM '=' QSTRING ';'
    136157                        {
    137158                                conf->cnf_diamrlm = $3;
     
    155176                        ;
    156177
    157 localport:              LOCALPORT '=' INTEGER ';'
     178port:                   PORT '=' INTEGER ';'
    158179                        {
    159180                                CHECK_PARAMS_DO( ($3 > 0) && ($3 < 1<<16),
     
    163184                        ;
    164185
    165 localsecport:           LOCALSECPORT '=' INTEGER ';'
     186secport:                SECPORT '=' INTEGER ';'
    166187                        {
    167188                                CHECK_PARAMS_DO( ($3 > 0) && ($3 < 1<<16),
     
    210231noip:                   NOIP ';'
    211232                        {
     233                                if (got_peer_noipv6) {
     234                                        yyerror (&yylloc, conf, "No_IP conflicts with a ConnectPeer directive No_IPv6.");
     235                                        YYERROR;
     236                                }
    212237                                conf->cnf_flags.no_ip4 = 1;
    213238                        }
     
    216241noip6:                  NOIP6 ';'
    217242                        {
     243                                if (got_peer_noip) {
     244                                        yyerror (&yylloc, conf, "No_IP conflicts with a ConnectPeer directive No_IP.");
     245                                        YYERROR;
     246                                }
    218247                                conf->cnf_flags.no_ip6 = 1;
    219248                        }
     
    222251notcp:                  NOTCP ';'
    223252                        {
     253                                #ifdef DISABLE_SCTP
     254                                yyerror (&yylloc, conf, "No_TCP cannot be specified for daemon compiled with DISABLE_SCTP option.");
     255                                YYERROR;
     256                                #endif
     257                                if (conf->cnf_flags.no_sctp)
     258                                {
     259                                        yyerror (&yylloc, conf, "No_TCP conflicts with No_SCTP directive." );
     260                                        YYERROR;
     261                                }
     262                                if (got_peer_nosctp) {
     263                                        yyerror (&yylloc, conf, "No_TCP conflicts with a ConnectPeer directive No_SCTP.");
     264                                        YYERROR;
     265                                }
    224266                                conf->cnf_flags.no_tcp = 1;
    225267                        }
     
    228270nosctp:                 NOSCTP ';'
    229271                        {
     272                                if (conf->cnf_flags.no_tcp)
     273                                {
     274                                        yyerror (&yylloc, conf, "No_SCTP conflicts with No_TCP directive." );
     275                                        YYERROR;
     276                                }
     277                                if (got_peer_notcp) {
     278                                        yyerror (&yylloc, conf, "No_SCTP conflicts with a ConnectPeer directive No_TCP.");
     279                                        YYERROR;
     280                                }
    230281                                conf->cnf_flags.no_sctp = 1;
    231282                        }
     
    260311                        }
    261312                        ;
     313                       
     314connpeer:               {
     315                                memset(&fddpi, 0, sizeof(fddpi));
     316                        }
     317                        CONNPEER '=' QSTRING peerinfo ';'
     318                        {
     319                                fddpi.pi_diamid = $4;
     320                                CHECK_FCT_DO( fd_peer_add ( &fddpi, conf->cnf_file, NULL, NULL ),
     321                                        { yyerror (&yylloc, conf, "Error adding ConnectPeer information"); YYERROR; } );
     322                                       
     323                                /* Now destroy any content in the structure */
     324                                free(fddpi.pi_diamid);
     325                                while (!FD_IS_LIST_EMPTY(&fddpi.pi_endpoints)) {
     326                                        struct fd_list * li = fddpi.pi_endpoints.next;
     327                                        fd_list_unlink(li);
     328                                        free(li);
     329                                }
     330                        }
     331                        ;
     332                       
     333peerinfo:               /* empty */
     334                        | '{' peerparams '}'
     335                        ;
     336                       
     337peerparams:             /* empty */
     338                        | peerparams NOIP ';'
     339                        {
     340                                if ((conf->cnf_flags.no_ip6) || (fddpi.pi_flags.pro3 == PI_P3_IP)) {
     341                                        yyerror (&yylloc, conf, "No_IP conflicts with a No_IPv6 directive.");
     342                                        YYERROR;
     343                                }
     344                                got_peer_noip++;
     345                                fddpi.pi_flags.pro3 = PI_P3_IPv6;
     346                        }
     347                        | peerparams NOIP6 ';'
     348                        {
     349                                if ((conf->cnf_flags.no_ip4) || (fddpi.pi_flags.pro3 == PI_P3_IPv6)) {
     350                                        yyerror (&yylloc, conf, "No_IPv6 conflicts with a No_IP directive.");
     351                                        YYERROR;
     352                                }
     353                                got_peer_noipv6++;
     354                                fddpi.pi_flags.pro3 = PI_P3_IP;
     355                        }
     356                        | peerparams NOTCP ';'
     357                        {
     358                                #ifdef DISABLE_SCTP
     359                                        yyerror (&yylloc, conf, "No_TCP cannot be specified in daemon compiled with DISABLE_SCTP option.");
     360                                        YYERROR;
     361                                #endif
     362                                if ((conf->cnf_flags.no_sctp) || (fddpi.pi_flags.pro4 == PI_P4_TCP)) {
     363                                        yyerror (&yylloc, conf, "No_TCP conflicts with a No_SCTP directive.");
     364                                        YYERROR;
     365                                }
     366                                got_peer_notcp++;
     367                                fddpi.pi_flags.pro4 = PI_P4_SCTP;
     368                        }
     369                        | peerparams NOSCTP ';'
     370                        {
     371                                if ((conf->cnf_flags.no_tcp) || (fddpi.pi_flags.pro4 == PI_P4_SCTP)) {
     372                                        yyerror (&yylloc, conf, "No_SCTP conflicts with a No_TCP directive.");
     373                                        YYERROR;
     374                                }
     375                                got_peer_nosctp++;
     376                                fddpi.pi_flags.pro4 = PI_P4_TCP;
     377                        }
     378                        | peerparams PREFERTCP ';'
     379                        {
     380                                fddpi.pi_flags.alg = PI_ALGPREF_TCP;
     381                        }
     382                        | peerparams OLDTLS ';'
     383                        {
     384                                if (fddpi.pi_flags.sec == PI_SEC_NONE) {
     385                                        yyerror (&yylloc, conf, "ConnectPeer: TLS_old_method conflicts with No_TLS.");
     386                                        YYERROR;
     387                                }
     388                                fddpi.pi_flags.sec = PI_SEC_TLS_OLD;
     389                        }
     390                        | peerparams NOTLS ';'
     391                        {
     392                                if (fddpi.pi_flags.sec == PI_SEC_TLS_OLD) {
     393                                        yyerror (&yylloc, conf, "ConnectPeer: No_TLS conflicts with TLS_old_method.");
     394                                        YYERROR;
     395                                }
     396                                fddpi.pi_flags.sec = PI_SEC_NONE;
     397                        }
     398                        | peerparams PORT '=' INTEGER ';'
     399                        {
     400                                CHECK_PARAMS_DO( ($4 > 0) && ($4 < 1<<16),
     401                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
     402                                fddpi.pi_port = (uint16_t)$4;
     403                        }
     404                        | peerparams SCTPSTREAMS '=' INTEGER ';'
     405                        {
     406                                CHECK_PARAMS_DO( ($4 > 0) && ($4 < 1<<16),
     407                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
     408                                fddpi.pi_streams = (uint16_t)$4;
     409                        }
     410                        | peerparams TCTIMER '=' INTEGER ';'
     411                        {
     412                                fddpi.pi_tctimer = $4;
     413                        }
     414                        | peerparams TWTIMER '=' INTEGER ';'
     415                        {
     416                                fddpi.pi_twtimer = $4;
     417                        }
     418                        | peerparams CONNTO '=' QSTRING ';'
     419                        {
     420                                struct fd_endpoint * ep;
     421                                struct addrinfo hints, *ai;
     422                                int ret;
     423                               
     424                                CHECK_MALLOC_DO( ep = malloc(sizeof(struct fd_endpoint)),
     425                                        { yyerror (&yylloc, conf, "Out of memory"); YYERROR; } );
     426                                memset(ep, 0, sizeof(struct fd_endpoint));
     427                                fd_list_init(&ep->chain, NULL);
     428                               
     429                                memset(&hints, 0, sizeof(hints));
     430                                hints.ai_flags = AI_ADDRCONFIG;
     431                                ret = getaddrinfo($4, NULL, &hints, &ai);
     432                                if (ret) { yyerror (&yylloc, conf, gai_strerror(ret)); YYERROR; }
     433                               
     434                                memcpy(&ep->ss, ai->ai_addr, ai->ai_addrlen);
     435                                free($4);
     436                                freeaddrinfo(ai);
     437                                fd_list_insert_before(&fddpi.pi_endpoints, &ep->chain);
     438                        }
     439                        ;
Note: See TracChangeset for help on using the changeset viewer.