Return to config.Y CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / bird2 / proto / static |
1.1 ! misho 1: /* ! 2: * BIRD -- Static Protocol Configuration ! 3: * ! 4: * (c) 1998--1999 Martin Mares <mj@ucw.cz> ! 5: * ! 6: * Can be freely distributed and used under the terms of the GNU GPL. ! 7: */ ! 8: ! 9: CF_HDR ! 10: ! 11: #include "proto/static/static.h" ! 12: ! 13: CF_DEFINES ! 14: ! 15: #define STATIC_CFG ((struct static_config *) this_proto) ! 16: static struct static_route *this_srt, *this_snh; ! 17: static struct f_inst *this_srt_cmds, *this_srt_last_cmd; ! 18: ! 19: static struct static_route * ! 20: static_nexthop_new(void) ! 21: { ! 22: struct static_route *nh = this_srt; ! 23: ! 24: if (this_snh) ! 25: { ! 26: /* Additional next hop */ ! 27: nh = cfg_allocz(sizeof(struct static_route)); ! 28: nh->net = this_srt->net; ! 29: this_snh->mp_next = nh; ! 30: } ! 31: ! 32: nh->dest = RTD_UNICAST; ! 33: nh->mp_head = this_srt; ! 34: return nh; ! 35: }; ! 36: ! 37: static void ! 38: static_route_finish(void) ! 39: { ! 40: if (net_type_match(this_srt->net, NB_DEST) == !this_srt->dest) ! 41: cf_error("Unexpected or missing nexthop/type"); ! 42: ! 43: this_srt->cmds = f_linearize(this_srt_cmds); ! 44: } ! 45: ! 46: CF_DECLS ! 47: ! 48: CF_KEYWORDS(STATIC, ROUTE, VIA, DROP, REJECT, PROHIBIT, PREFERENCE, CHECK, LINK) ! 49: CF_KEYWORDS(ONLINK, WEIGHT, RECURSIVE, IGP, TABLE, BLACKHOLE, UNREACHABLE, BFD, MPLS) ! 50: ! 51: ! 52: CF_GRAMMAR ! 53: ! 54: proto: static_proto '}' ; ! 55: ! 56: static_proto_start: proto_start STATIC ! 57: { ! 58: this_proto = proto_config_new(&proto_static, $1); ! 59: init_list(&STATIC_CFG->routes); ! 60: }; ! 61: ! 62: static_proto: ! 63: static_proto_start proto_name '{' ! 64: | static_proto proto_item ';' ! 65: | static_proto proto_channel ';' { this_proto->net_type = $2->net_type; } ! 66: | static_proto CHECK LINK bool ';' { STATIC_CFG->check_link = $4; } ! 67: | static_proto IGP TABLE rtable ';' { ! 68: if ($4->addr_type == NET_IP4) ! 69: STATIC_CFG->igp_table_ip4 = $4; ! 70: else if ($4->addr_type == NET_IP6) ! 71: STATIC_CFG->igp_table_ip6 = $4; ! 72: else ! 73: cf_error("Incompatible IGP table type"); ! 74: } ! 75: | static_proto stat_route stat_route_opt_list ';' { static_route_finish(); } ! 76: ; ! 77: ! 78: stat_nexthop: ! 79: VIA ipa ipa_scope { ! 80: this_snh = static_nexthop_new(); ! 81: this_snh->via = $2; ! 82: this_snh->iface = $3; ! 83: } ! 84: | VIA TEXT { ! 85: this_snh = static_nexthop_new(); ! 86: this_snh->via = IPA_NONE; ! 87: this_snh->iface = if_get_by_name($2); ! 88: } ! 89: | stat_nexthop MPLS label_stack { ! 90: this_snh->mls = $3; ! 91: } ! 92: | stat_nexthop ONLINK bool { ! 93: this_snh->onlink = $3; ! 94: } ! 95: | stat_nexthop WEIGHT expr { ! 96: this_snh->weight = $3 - 1; ! 97: if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256"); ! 98: } ! 99: | stat_nexthop BFD bool { ! 100: this_snh->use_bfd = $3; cf_check_bfd($3); ! 101: } ! 102: ; ! 103: ! 104: stat_nexthops: ! 105: stat_nexthop ! 106: | stat_nexthops stat_nexthop ! 107: ; ! 108: ! 109: stat_route0: ROUTE net_any { ! 110: this_srt = cfg_allocz(sizeof(struct static_route)); ! 111: add_tail(&STATIC_CFG->routes, &this_srt->n); ! 112: this_srt->net = $2; ! 113: this_srt_cmds = NULL; ! 114: this_srt_last_cmd = NULL; ! 115: this_srt->mp_next = NULL; ! 116: this_snh = NULL; ! 117: } ! 118: ; ! 119: ! 120: stat_route: ! 121: stat_route0 stat_nexthops ! 122: | stat_route0 RECURSIVE ipa { ! 123: this_srt->dest = RTDX_RECURSIVE; ! 124: this_srt->via = $3; ! 125: } ! 126: | stat_route0 RECURSIVE ipa MPLS label_stack { ! 127: this_srt->dest = RTDX_RECURSIVE; ! 128: this_srt->via = $3; ! 129: this_srt->mls = $5; ! 130: } ! 131: | stat_route0 { this_srt->dest = RTD_NONE; } ! 132: | stat_route0 DROP { this_srt->dest = RTD_BLACKHOLE; } ! 133: | stat_route0 REJECT { this_srt->dest = RTD_UNREACHABLE; } ! 134: | stat_route0 BLACKHOLE { this_srt->dest = RTD_BLACKHOLE; } ! 135: | stat_route0 UNREACHABLE { this_srt->dest = RTD_UNREACHABLE; } ! 136: | stat_route0 PROHIBIT { this_srt->dest = RTD_PROHIBIT; } ! 137: ; ! 138: ! 139: stat_route_item: ! 140: cmd { ! 141: if (this_srt_last_cmd) ! 142: this_srt_last_cmd->next = $1; ! 143: else ! 144: this_srt_cmds = $1; ! 145: this_srt_last_cmd = $1; ! 146: } ! 147: ; ! 148: ! 149: stat_route_opts: ! 150: /* empty */ ! 151: | stat_route_opts stat_route_item ! 152: ; ! 153: ! 154: stat_route_opt_list: ! 155: /* empty */ ! 156: | '{' stat_route_opts '}' ! 157: ; ! 158: ! 159: ! 160: CF_CLI(SHOW STATIC, optproto, [<name>], [[Show details of static protocol]]) ! 161: { static_show(proto_get_named($3, &proto_static)); } ; ! 162: ! 163: CF_CODE ! 164: ! 165: CF_END