Annotation of embedaddon/bird2/proto/rpki/config.Y, revision 1.1

1.1     ! misho       1: /*
        !             2:  *     BIRD -- The Resource Public Key Infrastructure (RPKI) to Router Protocol
        !             3:  *
        !             4:  *     (c) 2015 CZ.NIC
        !             5:  *
        !             6:  *     Can be freely distributed and used under the terms of the GNU GPL.
        !             7:  */
        !             8: 
        !             9: CF_HDR
        !            10: 
        !            11: #include "proto/rpki/rpki.h"
        !            12: 
        !            13: CF_DEFINES
        !            14: 
        !            15: #define RPKI_CFG ((struct rpki_config *) this_proto)
        !            16: #define RPKI_TR_SSH_CFG ((struct rpki_tr_ssh_config *) RPKI_CFG->tr_config.spec)
        !            17: 
        !            18: static void
        !            19: rpki_check_unused_hostname(void)
        !            20: {
        !            21:   if (RPKI_CFG->hostname != NULL)
        !            22:     cf_error("Only one cache server per protocol allowed");
        !            23: }
        !            24: 
        !            25: static void
        !            26: rpki_check_unused_transport(void)
        !            27: {
        !            28:   if (RPKI_CFG->tr_config.spec != NULL)
        !            29:     cf_error("At the most one transport per protocol allowed");
        !            30: }
        !            31: 
        !            32: CF_DECLS
        !            33: 
        !            34: CF_KEYWORDS(RPKI, REMOTE, BIRD, PRIVATE, PUBLIC, KEY, TCP, SSH, TRANSPORT, USER,
        !            35:            RETRY, REFRESH, EXPIRE, KEEP)
        !            36: 
        !            37: %type <i> rpki_keep_interval
        !            38: 
        !            39: CF_GRAMMAR
        !            40: 
        !            41: proto: rpki_proto ;
        !            42: 
        !            43: rpki_proto_start: proto_start RPKI {
        !            44:   this_proto = proto_config_new(&proto_rpki, $1);
        !            45:   RPKI_CFG->retry_interval = RPKI_RETRY_INTERVAL;
        !            46:   RPKI_CFG->refresh_interval = RPKI_REFRESH_INTERVAL;
        !            47:   RPKI_CFG->expire_interval = RPKI_EXPIRE_INTERVAL;
        !            48: };
        !            49: 
        !            50: rpki_proto: rpki_proto_start proto_name '{' rpki_proto_opts '}' { rpki_check_config(RPKI_CFG); };
        !            51: 
        !            52: rpki_proto_opts:
        !            53:    /* empty */
        !            54:  | rpki_proto_opts rpki_proto_item ';'
        !            55:  ;
        !            56: 
        !            57: rpki_proto_item:
        !            58:    proto_item
        !            59:  | proto_channel
        !            60:  | REMOTE rpki_cache_addr
        !            61:  | REMOTE rpki_cache_addr rpki_proto_item_port
        !            62:  | rpki_proto_item_port
        !            63:  | TRANSPORT rpki_transport
        !            64:  | REFRESH rpki_keep_interval expr {
        !            65:      if (rpki_check_refresh_interval($3))
        !            66:        cf_error(rpki_check_refresh_interval($3));
        !            67:      RPKI_CFG->refresh_interval = $3;
        !            68:      RPKI_CFG->keep_refresh_interval = $2;
        !            69:    }
        !            70:  | RETRY rpki_keep_interval expr {
        !            71:      if (rpki_check_retry_interval($3))
        !            72:        cf_error(rpki_check_retry_interval($3));
        !            73:      RPKI_CFG->retry_interval = $3;
        !            74:      RPKI_CFG->keep_retry_interval = $2;
        !            75:    }
        !            76:  | EXPIRE rpki_keep_interval expr {
        !            77:      if (rpki_check_expire_interval($3))
        !            78:        cf_error(rpki_check_expire_interval($3));
        !            79:      RPKI_CFG->expire_interval = $3;
        !            80:      RPKI_CFG->keep_expire_interval = $2;
        !            81:    }
        !            82:  ;
        !            83: 
        !            84: rpki_keep_interval:
        !            85:  /* empty */ { $$ = 0; }
        !            86:  | KEEP { $$ = 1; }
        !            87:  ;
        !            88: 
        !            89: rpki_proto_item_port: PORT expr { check_u16($2); RPKI_CFG->port = $2; };
        !            90: 
        !            91: rpki_cache_addr:
        !            92:    text {
        !            93:      rpki_check_unused_hostname();
        !            94:      RPKI_CFG->hostname = $1;
        !            95:    }
        !            96:  | ipa {
        !            97:      rpki_check_unused_hostname();
        !            98:      RPKI_CFG->ip = $1;
        !            99:      /* Ensure hostname is filled */
        !           100:      char *hostname = cfg_allocz(INET6_ADDRSTRLEN + 1);
        !           101:      bsnprintf(hostname, INET6_ADDRSTRLEN+1, "%I", RPKI_CFG->ip);
        !           102:      RPKI_CFG->hostname = hostname;
        !           103:    }
        !           104:  ;
        !           105: 
        !           106: rpki_transport:
        !           107:    TCP rpki_transport_tcp_init
        !           108:  | SSH rpki_transport_ssh_init '{' rpki_transport_ssh_opts '}' rpki_transport_ssh_check
        !           109:  ;
        !           110: 
        !           111: rpki_transport_tcp_init:
        !           112: {
        !           113:   rpki_check_unused_transport();
        !           114:   RPKI_CFG->tr_config.spec = cfg_allocz(sizeof(struct rpki_tr_tcp_config));
        !           115:   RPKI_CFG->tr_config.type = RPKI_TR_TCP;
        !           116: };
        !           117: 
        !           118: rpki_transport_ssh_init:
        !           119: {
        !           120:   rpki_check_unused_transport();
        !           121:   RPKI_CFG->tr_config.spec = cfg_allocz(sizeof(struct rpki_tr_ssh_config));
        !           122:   RPKI_CFG->tr_config.type = RPKI_TR_SSH;
        !           123: };
        !           124: 
        !           125: rpki_transport_ssh_opts:
        !           126:    /* empty */
        !           127:  | rpki_transport_ssh_opts rpki_transport_ssh_item ';'
        !           128:  ;
        !           129: 
        !           130: rpki_transport_ssh_item:
        !           131:    BIRD PRIVATE KEY text  { RPKI_TR_SSH_CFG->bird_private_key = $4; }
        !           132:  | REMOTE PUBLIC KEY text { RPKI_TR_SSH_CFG->cache_public_key = $4; }
        !           133:  | USER text              { RPKI_TR_SSH_CFG->user = $2; }
        !           134:  ;
        !           135: 
        !           136: rpki_transport_ssh_check:
        !           137: {
        !           138:   if (RPKI_TR_SSH_CFG->user == NULL)
        !           139:     cf_error("User must be set");
        !           140: };
        !           141: 
        !           142: CF_CODE
        !           143: 
        !           144: CF_END

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>