1998-12-06 18:21:23 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- Static Protocol Configuration
|
|
|
|
*
|
1999-02-05 21:38:22 +00:00
|
|
|
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
|
1998-12-06 18:21:23 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CF_HDR
|
|
|
|
|
|
|
|
#include "proto/static/static.h"
|
|
|
|
|
2000-04-28 15:11:10 +00:00
|
|
|
CF_DEFINES
|
|
|
|
|
2010-11-11 11:24:27 +00:00
|
|
|
#define STATIC_CFG ((struct static_config *) this_proto)
|
2017-02-20 01:26:45 +00:00
|
|
|
static struct static_route *this_srt, *this_snh;
|
2015-07-20 09:12:02 +00:00
|
|
|
static struct f_inst **this_srt_last_cmd;
|
1998-12-06 23:13:31 +00:00
|
|
|
|
2017-02-20 01:26:45 +00:00
|
|
|
static struct static_route *
|
|
|
|
static_nexthop_new(void)
|
|
|
|
{
|
2017-03-07 17:42:41 +00:00
|
|
|
struct static_route *nh = this_srt;
|
2017-02-20 01:26:45 +00:00
|
|
|
|
2017-03-07 17:42:41 +00:00
|
|
|
if (this_snh)
|
2017-02-20 01:26:45 +00:00
|
|
|
{
|
|
|
|
/* Additional next hop */
|
|
|
|
nh = cfg_allocz(sizeof(struct static_route));
|
|
|
|
nh->net = this_srt->net;
|
|
|
|
this_snh->mp_next = nh;
|
|
|
|
}
|
|
|
|
|
|
|
|
nh->dest = RTD_UNICAST;
|
|
|
|
nh->mp_head = this_srt;
|
|
|
|
return nh;
|
|
|
|
};
|
|
|
|
|
2017-07-04 12:49:37 +00:00
|
|
|
static void
|
|
|
|
static_route_start(net_addr *n)
|
|
|
|
{
|
|
|
|
this_srt = cfg_allocz(sizeof(struct static_route));
|
|
|
|
add_tail(&STATIC_CFG->routes, &this_srt->n);
|
|
|
|
this_srt->net = n;
|
|
|
|
this_srt_last_cmd = &(this_srt->cmds);
|
|
|
|
this_srt->mp_next = NULL;
|
|
|
|
this_snh = NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-24 16:02:07 +00:00
|
|
|
static void
|
|
|
|
static_route_finish(void)
|
2017-04-05 14:16:04 +00:00
|
|
|
{
|
|
|
|
if (net_type_match(this_srt->net, NB_DEST) == !this_srt->dest)
|
|
|
|
cf_error("Unexpected or missing nexthop/type");
|
|
|
|
}
|
2015-07-24 16:02:07 +00:00
|
|
|
|
2017-07-04 12:49:37 +00:00
|
|
|
static void
|
|
|
|
static_flow_action(u64 ec)
|
|
|
|
{
|
|
|
|
NEW_F_VAL;
|
|
|
|
|
|
|
|
val->type = T_EC; val->val.ec = ec;
|
2018-04-04 08:42:54 +00:00
|
|
|
struct f_inst *fic = f_new_inst(FI_CONSTANT_INDIRECT);
|
|
|
|
fic->a1.p = val;
|
2017-07-04 12:49:37 +00:00
|
|
|
*this_srt_last_cmd = f_generate_complex(
|
2018-04-04 08:42:54 +00:00
|
|
|
FI_CLIST_ADD_DEL, 'a',
|
2017-07-04 12:49:37 +00:00
|
|
|
f_new_dynamic_attr(EAF_TYPE_EC_SET, T_ECLIST, EA_CODE(EAP_BGP, BA_EXT_COMMUNITY)),
|
|
|
|
fic
|
|
|
|
);
|
|
|
|
this_srt_last_cmd = &((*this_srt_last_cmd)->next);
|
|
|
|
}
|
|
|
|
|
1998-12-06 18:21:23 +00:00
|
|
|
CF_DECLS
|
|
|
|
|
2017-07-04 12:49:37 +00:00
|
|
|
%type <fl> float_rate
|
|
|
|
|
2010-11-11 11:24:27 +00:00
|
|
|
CF_KEYWORDS(STATIC, ROUTE, VIA, DROP, REJECT, PROHIBIT, PREFERENCE, CHECK, LINK)
|
2017-07-04 21:36:21 +00:00
|
|
|
CF_KEYWORDS(ONLINK, WEIGHT, RECURSIVE, IGP, TABLE, BLACKHOLE, UNREACHABLE, BFD, MPLS)
|
2017-07-04 12:49:37 +00:00
|
|
|
CF_KEYWORDS(RATE, SAMPLE, LAST, DSCP)
|
|
|
|
CF_KEYWORDS_CS(mBps, mbps, Bps, bps, kBps, kbps, MBps, Mbps, GBps, Gbps, TBps, Tbps)
|
2010-12-07 22:34:36 +00:00
|
|
|
|
1998-12-06 18:21:23 +00:00
|
|
|
|
|
|
|
CF_GRAMMAR
|
|
|
|
|
|
|
|
CF_ADDTO(proto, static_proto '}')
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
static_proto_start: proto_start STATIC
|
|
|
|
{
|
|
|
|
this_proto = proto_config_new(&proto_static, $1);
|
2017-03-07 17:42:41 +00:00
|
|
|
init_list(&STATIC_CFG->routes);
|
2016-01-26 10:48:58 +00:00
|
|
|
};
|
1998-12-06 18:21:23 +00:00
|
|
|
|
|
|
|
static_proto:
|
|
|
|
static_proto_start proto_name '{'
|
|
|
|
| static_proto proto_item ';'
|
2016-01-26 10:48:58 +00:00
|
|
|
| static_proto proto_channel ';' { this_proto->net_type = $2->net_type; }
|
2010-11-19 12:46:21 +00:00
|
|
|
| static_proto CHECK LINK bool ';' { STATIC_CFG->check_link = $4; }
|
2017-03-30 11:29:34 +00:00
|
|
|
| static_proto IGP TABLE rtable ';' {
|
|
|
|
if ($4->addr_type == NET_IP4)
|
|
|
|
STATIC_CFG->igp_table_ip4 = $4;
|
|
|
|
else if ($4->addr_type == NET_IP6)
|
|
|
|
STATIC_CFG->igp_table_ip6 = $4;
|
|
|
|
else
|
|
|
|
cf_error("Incompatible IGP table type");
|
|
|
|
}
|
2015-07-24 16:02:07 +00:00
|
|
|
| static_proto stat_route stat_route_opt_list ';' { static_route_finish(); }
|
1998-12-06 23:13:31 +00:00
|
|
|
;
|
|
|
|
|
2017-02-20 01:26:45 +00:00
|
|
|
stat_nexthop:
|
|
|
|
VIA ipa ipa_scope {
|
|
|
|
this_snh = static_nexthop_new();
|
|
|
|
this_snh->via = $2;
|
|
|
|
this_snh->iface = $3;
|
2016-06-13 13:49:53 +00:00
|
|
|
}
|
2017-02-20 01:26:45 +00:00
|
|
|
| VIA TEXT {
|
|
|
|
this_snh = static_nexthop_new();
|
|
|
|
this_snh->via = IPA_NONE;
|
2017-03-07 17:42:41 +00:00
|
|
|
this_snh->iface = if_get_by_name($2);
|
2016-06-13 13:49:53 +00:00
|
|
|
}
|
2017-02-20 01:26:45 +00:00
|
|
|
| stat_nexthop MPLS label_stack {
|
2017-03-17 14:48:09 +00:00
|
|
|
this_snh->mls = $3;
|
2016-06-13 13:49:53 +00:00
|
|
|
}
|
2017-07-04 21:36:21 +00:00
|
|
|
| stat_nexthop ONLINK bool {
|
|
|
|
this_snh->onlink = $3;
|
|
|
|
}
|
2017-02-20 01:26:45 +00:00
|
|
|
| stat_nexthop WEIGHT expr {
|
|
|
|
this_snh->weight = $3 - 1;
|
2016-06-13 13:49:53 +00:00
|
|
|
if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256");
|
|
|
|
}
|
2017-02-20 01:26:45 +00:00
|
|
|
| stat_nexthop BFD bool {
|
|
|
|
this_snh->use_bfd = $3; cf_check_bfd($3);
|
|
|
|
}
|
2016-06-13 13:49:53 +00:00
|
|
|
;
|
|
|
|
|
2017-02-20 01:26:45 +00:00
|
|
|
stat_nexthops:
|
|
|
|
stat_nexthop
|
|
|
|
| stat_nexthops stat_nexthop
|
2016-06-13 13:49:53 +00:00
|
|
|
;
|
|
|
|
|
2015-11-12 01:03:59 +00:00
|
|
|
stat_route0: ROUTE net_any {
|
2017-07-04 12:49:37 +00:00
|
|
|
if (net_type_match($2, NB_FLOW))
|
|
|
|
cf_error("Flowspec rules are not routes. Apologize!");
|
|
|
|
static_route_start($2);
|
1998-12-06 23:13:31 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
stat_route:
|
2017-02-20 01:26:45 +00:00
|
|
|
stat_route0 stat_nexthops
|
2011-09-24 00:21:52 +00:00
|
|
|
| stat_route0 RECURSIVE ipa {
|
|
|
|
this_srt->dest = RTDX_RECURSIVE;
|
|
|
|
this_srt->via = $3;
|
|
|
|
}
|
2016-08-09 12:47:51 +00:00
|
|
|
| stat_route0 RECURSIVE ipa MPLS label_stack {
|
|
|
|
this_srt->dest = RTDX_RECURSIVE;
|
|
|
|
this_srt->via = $3;
|
2017-03-17 14:48:09 +00:00
|
|
|
this_srt->mls = $5;
|
2016-08-09 12:47:51 +00:00
|
|
|
}
|
2017-04-05 14:16:04 +00:00
|
|
|
| stat_route0 { this_srt->dest = RTD_NONE; }
|
2012-11-27 01:08:04 +00:00
|
|
|
| stat_route0 DROP { this_srt->dest = RTD_BLACKHOLE; }
|
|
|
|
| stat_route0 REJECT { this_srt->dest = RTD_UNREACHABLE; }
|
|
|
|
| stat_route0 BLACKHOLE { this_srt->dest = RTD_BLACKHOLE; }
|
|
|
|
| stat_route0 UNREACHABLE { this_srt->dest = RTD_UNREACHABLE; }
|
|
|
|
| stat_route0 PROHIBIT { this_srt->dest = RTD_PROHIBIT; }
|
2018-04-17 13:02:06 +00:00
|
|
|
| net_flow_ { static_route_start($1); } flowspec_action
|
1998-12-06 18:21:23 +00:00
|
|
|
;
|
|
|
|
|
2015-07-20 09:12:02 +00:00
|
|
|
stat_route_item:
|
|
|
|
cmd { *this_srt_last_cmd = $1; this_srt_last_cmd = &($1->next); }
|
|
|
|
;
|
|
|
|
|
|
|
|
stat_route_opts:
|
|
|
|
/* empty */
|
|
|
|
| stat_route_opts stat_route_item
|
|
|
|
;
|
|
|
|
|
|
|
|
stat_route_opt_list:
|
|
|
|
/* empty */
|
|
|
|
| '{' stat_route_opts '}'
|
|
|
|
;
|
|
|
|
|
2017-07-04 12:49:37 +00:00
|
|
|
flowspec_action: ACTION '{' flowspec_action0 '}' ;
|
|
|
|
|
|
|
|
flowspec_action0:
|
|
|
|
/* empty */
|
|
|
|
| flowspec_action0 RATE float_rate ';' { static_flow_action(flow_action_encode_byterate(0, $3)); }
|
|
|
|
| flowspec_action0 SAMPLE ';' { static_flow_action(flow_action_encode_sample()); }
|
|
|
|
| flowspec_action0 LAST ';' { static_flow_action(flow_action_encode_last()); }
|
|
|
|
| flowspec_action0 RT cnum ',' cnum ';' { static_flow_action(flow_action_encode_redirect($3, $5)); }
|
|
|
|
| flowspec_action0 DSCP NUM ';' { static_flow_action(flow_action_encode_dscp($3)); }
|
|
|
|
;
|
|
|
|
|
|
|
|
float_rate:
|
|
|
|
NUM mBps { $$ = $1 / 1000.0; }
|
|
|
|
| NUM mbps { $$ = $1 / 8000.0; }
|
|
|
|
| NUM Bps { $$ = $1; }
|
|
|
|
| NUM bps { $$ = $1 / 8.0; }
|
|
|
|
| NUM kBps { $$ = 1000.0 * $1; }
|
|
|
|
| NUM kbps { $$ = 1000.0 * $1 / 8.0; }
|
|
|
|
| NUM MBps { $$ = 1000000.0 * $1; }
|
|
|
|
| NUM Mbps { $$ = 1000000.0 * $1 / 8.0; }
|
|
|
|
| NUM GBps { $$ = 1000000000.0 * $1; }
|
|
|
|
| NUM Gbps { $$ = 1000000000.0 * $1 / 8.0; }
|
|
|
|
| NUM TBps { $$ = 1000000000000.0 * $1; }
|
|
|
|
| NUM Tbps { $$ = 1000000000000.0 * $1 / 8.0; }
|
|
|
|
;
|
2015-07-20 09:12:02 +00:00
|
|
|
|
1999-12-03 11:41:23 +00:00
|
|
|
CF_CLI(SHOW STATIC, optsym, [<name>], [[Show details of static protocol]])
|
|
|
|
{ static_show(proto_get_named($3, &proto_static)); } ;
|
|
|
|
|
1998-12-06 18:21:23 +00:00
|
|
|
CF_CODE
|
|
|
|
|
|
|
|
CF_END
|