Annotation of embedaddon/bird/proto/rip/config.Y, revision 1.1
1.1 ! misho 1: /*
! 2: * BIRD -- RIP Configuration
! 3: *
! 4: * (c) 1998--1999 Pavel Machek <pavel@ucw.cz>
! 5: * (c) 2004--2013 Ondrej Filip <feela@network.cz>
! 6: * (c) 2009--2015 Ondrej Zajicek <santiago@crfreenet.org>
! 7: * (c) 2009--2015 CZ.NIC z.s.p.o.
! 8: *
! 9: * Can be freely distributed and used under the terms of the GNU GPL.
! 10: */
! 11:
! 12: CF_HDR
! 13:
! 14: #include "proto/rip/rip.h"
! 15: #include "nest/iface.h"
! 16:
! 17: CF_DEFINES
! 18:
! 19: #define RIP_CFG ((struct rip_config *) this_proto)
! 20: #define RIP_IFACE ((struct rip_iface_config *) this_ipatt)
! 21:
! 22: static inline int rip_cfg_is_v2(void) { return RIP_CFG->rip2; }
! 23: static inline int rip_cfg_is_ng(void) { return ! RIP_CFG->rip2; }
! 24:
! 25: static inline void
! 26: rip_check_auth(void)
! 27: {
! 28: if (rip_cfg_is_ng())
! 29: cf_error("Authentication not supported in RIPng");
! 30: }
! 31:
! 32:
! 33: CF_DECLS
! 34:
! 35: CF_KEYWORDS(RIP, ECMP, LIMIT, WEIGHT, INFINITY, METRIC, UPDATE, TIMEOUT,
! 36: GARBAGE, PORT, ADDRESS, MODE, BROADCAST, MULTICAST, PASSIVE,
! 37: VERSION, SPLIT, HORIZON, POISON, REVERSE, CHECK, ZERO, TIME, BFD,
! 38: AUTHENTICATION, NONE, PLAINTEXT, CRYPTOGRAPHIC, MD5, TTL, SECURITY,
! 39: RX, TX, BUFFER, LENGTH, PRIORITY, ONLY, LINK, RIP_METRIC, RIP_TAG)
! 40:
! 41: %type <i> rip_auth
! 42:
! 43: CF_GRAMMAR
! 44:
! 45: CF_ADDTO(proto, rip_proto)
! 46:
! 47: rip_proto_start: proto_start RIP
! 48: {
! 49: this_proto = proto_config_new(&proto_rip, $1);
! 50: init_list(&RIP_CFG->patt_list);
! 51:
! 52: RIP_CFG->rip2 = RIP_IS_V2;
! 53: RIP_CFG->infinity = RIP_DEFAULT_INFINITY;
! 54:
! 55: RIP_CFG->min_timeout_time = 60;
! 56: RIP_CFG->max_garbage_time = 60;
! 57: };
! 58:
! 59: rip_proto_item:
! 60: proto_item
! 61: | ECMP bool { RIP_CFG->ecmp = $2 ? RIP_DEFAULT_ECMP_LIMIT : 0; }
! 62: | ECMP bool LIMIT expr { RIP_CFG->ecmp = $2 ? $4 : 0; if ($4 < 0) cf_error("ECMP limit cannot be negative"); }
! 63: | INFINITY expr { RIP_CFG->infinity = $2; }
! 64: | INTERFACE rip_iface
! 65: ;
! 66:
! 67: rip_proto_opts:
! 68: /* empty */
! 69: | rip_proto_opts rip_proto_item ';'
! 70: ;
! 71:
! 72: rip_proto:
! 73: rip_proto_start proto_name '{' rip_proto_opts '}';
! 74:
! 75:
! 76: rip_iface_start:
! 77: {
! 78: this_ipatt = cfg_allocz(sizeof(struct rip_iface_config));
! 79: add_tail(&RIP_CFG->patt_list, NODE this_ipatt);
! 80: init_list(&this_ipatt->ipn_list);
! 81: reset_passwords();
! 82:
! 83: RIP_IFACE->metric = 1;
! 84: RIP_IFACE->port = rip_cfg_is_v2() ? RIP_PORT : RIP_NG_PORT;
! 85: RIP_IFACE->version = rip_cfg_is_v2() ? RIP_V2 : RIP_V1;
! 86: RIP_IFACE->split_horizon = 1;
! 87: RIP_IFACE->poison_reverse = 1;
! 88: RIP_IFACE->check_zero = 1;
! 89: RIP_IFACE->ttl_security = rip_cfg_is_v2() ? 0 : 1;
! 90: RIP_IFACE->rx_buffer = rip_cfg_is_v2() ? RIP_MAX_PKT_LENGTH : 0;
! 91: RIP_IFACE->tx_length = rip_cfg_is_v2() ? RIP_MAX_PKT_LENGTH : 0;
! 92: RIP_IFACE->tx_tos = IP_PREC_INTERNET_CONTROL;
! 93: RIP_IFACE->tx_priority = sk_priority_control;
! 94: RIP_IFACE->update_time = RIP_DEFAULT_UPDATE_TIME;
! 95: RIP_IFACE->timeout_time = RIP_DEFAULT_TIMEOUT_TIME;
! 96: RIP_IFACE->garbage_time = RIP_DEFAULT_GARBAGE_TIME;
! 97: };
! 98:
! 99: rip_iface_finish:
! 100: {
! 101: /* Default mode is broadcast for RIPv1, multicast for RIPv2 and RIPng */
! 102: if (!RIP_IFACE->mode)
! 103: RIP_IFACE->mode = (rip_cfg_is_v2() && (RIP_IFACE->version == RIP_V1)) ?
! 104: RIP_IM_BROADCAST : RIP_IM_MULTICAST;
! 105:
! 106: RIP_IFACE->passwords = get_passwords();
! 107:
! 108: if (!RIP_IFACE->auth_type != !RIP_IFACE->passwords)
! 109: log(L_WARN "Authentication and password options should be used together");
! 110:
! 111: if (RIP_IFACE->passwords)
! 112: {
! 113: struct password_item *pass;
! 114: WALK_LIST(pass, *RIP_IFACE->passwords)
! 115: {
! 116: if (pass->alg && (RIP_IFACE->auth_type != RIP_AUTH_CRYPTO))
! 117: cf_error("Password algorithm option requires cryptographic authentication");
! 118:
! 119: /* Set default crypto algorithm (MD5) */
! 120: if (!pass->alg && (RIP_IFACE->auth_type == RIP_AUTH_CRYPTO))
! 121: pass->alg = ALG_MD5;
! 122: }
! 123: }
! 124:
! 125: RIP_CFG->min_timeout_time = MIN_(RIP_CFG->min_timeout_time, RIP_IFACE->timeout_time);
! 126: RIP_CFG->max_garbage_time = MAX_(RIP_CFG->max_garbage_time, RIP_IFACE->garbage_time);
! 127: };
! 128:
! 129: rip_iface_item:
! 130: METRIC expr { RIP_IFACE->metric = $2; if (($2<1) || ($2>255)) cf_error("Metric must be in range 1-255"); }
! 131: | MODE MULTICAST { RIP_IFACE->mode = RIP_IM_MULTICAST; }
! 132: | MODE BROADCAST { RIP_IFACE->mode = RIP_IM_BROADCAST; if (rip_cfg_is_ng()) cf_error("Broadcast not supported in RIPng"); }
! 133: | PASSIVE bool { RIP_IFACE->passive = $2; }
! 134: | ADDRESS ipa { RIP_IFACE->address = $2; }
! 135: | PORT expr { RIP_IFACE->port = $2; if (($2<1) || ($2>65535)) cf_error("Invalid port number"); }
! 136: | VERSION expr { RIP_IFACE->version = $2;
! 137: if (rip_cfg_is_ng()) cf_error("Version not supported in RIPng");
! 138: if (($2 != RIP_V1) && ($2 != RIP_V2)) cf_error("Unsupported version");
! 139: }
! 140: | VERSION ONLY bool { RIP_IFACE->version_only = $3; }
! 141: | SPLIT HORIZON bool { RIP_IFACE->split_horizon = $3; }
! 142: | POISON REVERSE bool { RIP_IFACE->poison_reverse = $3; }
! 143: | CHECK ZERO bool { RIP_IFACE->check_zero = $3; }
! 144: | UPDATE TIME expr { RIP_IFACE->update_time = $3; if ($3<=0) cf_error("Update time must be positive"); }
! 145: | TIMEOUT TIME expr { RIP_IFACE->timeout_time = $3; if ($3<=0) cf_error("Timeout time must be positive"); }
! 146: | GARBAGE TIME expr { RIP_IFACE->garbage_time = $3; if ($3<=0) cf_error("Garbage time must be positive"); }
! 147: | ECMP WEIGHT expr { RIP_IFACE->ecmp_weight = $3 - 1; if (($3<1) || ($3>256)) cf_error("ECMP weight must be in range 1-256"); }
! 148: | RX BUFFER expr { RIP_IFACE->rx_buffer = $3; if (($3<256) || ($3>65535)) cf_error("RX length must be in range 256-65535"); }
! 149: | TX LENGTH expr { RIP_IFACE->tx_length = $3; if (($3<256) || ($3>65535)) cf_error("TX length must be in range 256-65535"); }
! 150: | TX tos { RIP_IFACE->tx_tos = $2; }
! 151: | TX PRIORITY expr { RIP_IFACE->tx_priority = $3; }
! 152: | TTL SECURITY bool { RIP_IFACE->ttl_security = $3; }
! 153: | TTL SECURITY TX ONLY { RIP_IFACE->ttl_security = 2; }
! 154: | CHECK LINK bool { RIP_IFACE->check_link = $3; }
! 155: | BFD bool { RIP_IFACE->bfd = $2; cf_check_bfd($2); }
! 156: | AUTHENTICATION rip_auth { RIP_IFACE->auth_type = $2; if ($2) rip_check_auth(); }
! 157: | password_list { rip_check_auth(); }
! 158: ;
! 159:
! 160: rip_auth:
! 161: NONE { $$ = RIP_AUTH_NONE; }
! 162: | PLAINTEXT { $$ = RIP_AUTH_PLAIN; }
! 163: | CRYPTOGRAPHIC { $$ = RIP_AUTH_CRYPTO; }
! 164: | MD5 { $$ = RIP_AUTH_CRYPTO; } /* For backward compatibility */
! 165: ;
! 166:
! 167: rip_iface_opts:
! 168: /* empty */
! 169: | rip_iface_opts rip_iface_item ';'
! 170: ;
! 171:
! 172: rip_iface_opt_list:
! 173: /* empty */
! 174: | '{' rip_iface_opts '}'
! 175: ;
! 176:
! 177: rip_iface:
! 178: rip_iface_start iface_patt_list_nopx rip_iface_opt_list rip_iface_finish;
! 179:
! 180:
! 181: CF_ADDTO(dynamic_attr, RIP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_RIP_METRIC); })
! 182: CF_ADDTO(dynamic_attr, RIP_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_RIP_TAG); })
! 183:
! 184: CF_CLI_HELP(SHOW RIP, ..., [[Show information about RIP protocol]]);
! 185:
! 186: CF_CLI(SHOW RIP INTERFACES, optsym opttext, [<name>] [\"<interface>\"], [[Show information about RIP interfaces]])
! 187: { rip_show_interfaces(proto_get_named($4, &proto_rip), $5); };
! 188:
! 189: CF_CLI(SHOW RIP NEIGHBORS, optsym opttext, [<name>] [\"<interface>\"], [[Show information about RIP neighbors]])
! 190: { rip_show_neighbors(proto_get_named($4, &proto_rip), $5); };
! 191:
! 192:
! 193: CF_CODE
! 194:
! 195: CF_END
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>