2016-04-29 00:01:40 +08:00
/*
* BIRD -- Babel Configuration
*
* Copyright (c) 2015-2016 Toke Hoiland-Jorgensen
2017-11-28 22:11:41 +08:00
* (c) 2016--2017 Ondrej Zajicek <santiago@crfreenet.org>
* (c) 2016--2017 CZ.NIC z.s.p.o.
2016-04-29 00:01:40 +08:00
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
CF_HDR
#include "proto/babel/babel.h"
#include "nest/iface.h"
CF_DEFINES
#define BABEL_CFG ((struct babel_config *) this_proto)
#define BABEL_IFACE ((struct babel_iface_config *) this_ipatt)
CF_DECLS
2018-03-08 00:35:24 +08:00
CF_KEYWORDS(BABEL, INTERFACE, METRIC, RXCOST, HELLO, UPDATE, INTERVAL, PORT,
2022-04-18 07:03:01 +08:00
TYPE, WIRED, WIRELESS, TUNNEL, RX, TX, BUFFER, PRIORITY, LENGTH, CHECK,
LINK, NEXT, HOP, IPV4, IPV6, BABEL_METRIC, SHOW, INTERFACES, NEIGHBORS,
ENTRIES, RANDOMIZE, ROUTER, ID, AUTHENTICATION, NONE, MAC, PERMISSIVE,
2022-12-07 13:02:20 +08:00
RTT, MIN, MAX, DECAY, WINLEN, SEND, TIMESTAMPS)
2016-04-29 00:01:40 +08:00
CF_GRAMMAR
2018-06-26 20:29:03 +08:00
proto: babel_proto ;
2016-04-29 00:01:40 +08:00
babel_proto_start: proto_start BABEL
{
this_proto = proto_config_new(&proto_babel, $1);
init_list(&BABEL_CFG->iface_list);
2017-11-28 22:11:41 +08:00
BABEL_CFG->hold_time = 1 S_;
2022-04-21 06:57:23 +08:00
BABEL_CFG->metric_decay = BABEL_SMOOTHING_DECAY;
};
babel_proto_finish:
{
if (BABEL_CFG->metric_decay)
BABEL_CFG->smooth_recp = BABEL_SMOOTHING_UNIT + BABEL_SMOOTHING_CONSTANT / BABEL_CFG->metric_decay;
2016-04-29 00:01:40 +08:00
};
babel_proto_item:
proto_item
2016-12-10 07:11:26 +08:00
| proto_channel
2016-04-29 00:01:40 +08:00
| INTERFACE babel_iface
2018-05-03 22:55:11 +08:00
| RANDOMIZE ROUTER ID bool { BABEL_CFG->randomize_router_id = $4; }
2022-04-21 06:57:23 +08:00
| METRIC DECAY expr_us { BABEL_CFG->metric_decay = $3; if ($3 && (($3 < BABEL_SMOOTHING_STEP) || ($3 > BABEL_SMOOTHING_DECAY_MAX))) cf_error("Metric decay must be 0, or between 1-180s"); }
2016-04-29 00:01:40 +08:00
;
babel_proto_opts:
/* empty */
| babel_proto_opts babel_proto_item ';'
;
babel_proto:
2022-04-21 06:57:23 +08:00
babel_proto_start proto_name '{' babel_proto_opts '}' babel_proto_finish;
2016-04-29 00:01:40 +08:00
babel_iface_start:
{
this_ipatt = cfg_allocz(sizeof(struct babel_iface_config));
add_tail(&BABEL_CFG->iface_list, NODE this_ipatt);
init_list(&this_ipatt->ipn_list);
2021-04-17 21:04:16 +08:00
reset_passwords();
2016-04-29 00:01:40 +08:00
BABEL_IFACE->port = BABEL_PORT;
BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRED;
2017-10-25 23:14:08 +08:00
BABEL_IFACE->limit = BABEL_HELLO_LIMIT;
2016-04-29 00:01:40 +08:00
BABEL_IFACE->tx_tos = IP_PREC_INTERNET_CONTROL;
BABEL_IFACE->tx_priority = sk_priority_control;
2022-04-18 07:03:01 +08:00
BABEL_IFACE->rtt_min = BABEL_RTT_MIN;
BABEL_IFACE->rtt_max = BABEL_RTT_MAX;
2022-12-07 13:02:20 +08:00
BABEL_IFACE->rtt_win_len = BABEL_RTT_WINLEN;
2022-04-18 07:03:01 +08:00
BABEL_IFACE->rtt_send = 1;
2016-04-29 00:01:40 +08:00
BABEL_IFACE->check_link = 1;
};
babel_iface_finish:
{
if (BABEL_IFACE->type == BABEL_IFACE_TYPE_WIRELESS)
{
if (!BABEL_IFACE->hello_interval)
BABEL_IFACE->hello_interval = BABEL_HELLO_INTERVAL_WIRELESS;
if (!BABEL_IFACE->rxcost)
BABEL_IFACE->rxcost = BABEL_RXCOST_WIRELESS;
}
else
{
if (!BABEL_IFACE->hello_interval)
BABEL_IFACE->hello_interval = BABEL_HELLO_INTERVAL_WIRED;
if (!BABEL_IFACE->rxcost)
BABEL_IFACE->rxcost = BABEL_RXCOST_WIRED;
2022-04-18 07:03:01 +08:00
if (BABEL_IFACE->type == BABEL_IFACE_TYPE_TUNNEL && !BABEL_IFACE->rtt_cost)
BABEL_IFACE->rtt_cost = BABEL_RXCOST_RTT;
2016-04-29 00:01:40 +08:00
}
2022-04-18 07:03:01 +08:00
if (BABEL_IFACE->rtt_cost && !BABEL_IFACE->rtt_send)
cf_error("Can't set RTT cost when sending timestamps is disabled");
if (BABEL_IFACE->rtt_min >= BABEL_IFACE->rtt_max)
cf_error("Min RTT must be smaller than max RTT");
2016-07-19 17:57:20 +08:00
/* Make sure we do not overflow the 16-bit centisec fields */
2016-04-29 00:01:40 +08:00
if (!BABEL_IFACE->update_interval)
2016-07-19 17:57:20 +08:00
BABEL_IFACE->update_interval = MIN_(BABEL_IFACE->hello_interval*BABEL_UPDATE_INTERVAL_FACTOR, BABEL_MAX_INTERVAL);
BABEL_IFACE->ihu_interval = MIN_(BABEL_IFACE->hello_interval*BABEL_IHU_INTERVAL_FACTOR, BABEL_MAX_INTERVAL);
2017-11-28 22:11:41 +08:00
BABEL_CFG->hold_time = MAX_(BABEL_CFG->hold_time, BABEL_IFACE->update_interval*BABEL_HOLD_TIME_FACTOR);
2021-04-17 21:04:16 +08:00
BABEL_IFACE->passwords = get_passwords();
if (!BABEL_IFACE->auth_type != !BABEL_IFACE->passwords)
cf_error("Authentication and password options should be used together");
if (BABEL_IFACE->passwords)
{
struct password_item *pass;
uint len = 0, i = 0;
2021-06-06 21:22:59 +08:00
2021-04-17 21:04:16 +08:00
WALK_LIST(pass, *BABEL_IFACE->passwords)
{
/* Set default crypto algorithm (HMAC-SHA256) */
if (!pass->alg)
pass->alg = ALG_HMAC_SHA256;
2021-06-06 21:22:59 +08:00
if (!((pass->alg & ALG_HMAC) ||
(pass->alg == ALG_BLAKE2S_128) ||
(pass->alg == ALG_BLAKE2S_256) ||
(pass->alg == ALG_BLAKE2B_256) ||
(pass->alg == ALG_BLAKE2B_512)))
cf_error("Only HMAC and Blake2 algorithms are supported");
2021-04-17 21:04:16 +08:00
len += mac_type_length(pass->alg);
i++;
}
2021-06-06 21:22:59 +08:00
2021-04-17 21:04:16 +08:00
BABEL_IFACE->mac_num_keys = i;
BABEL_IFACE->mac_total_len = len;
}
2016-04-29 00:01:40 +08:00
};
babel_iface_item:
| PORT expr { BABEL_IFACE->port = $2; if (($2<1) || ($2>65535)) cf_error("Invalid port number"); }
| RXCOST expr { BABEL_IFACE->rxcost = $2; if (($2<1) || ($2>65535)) cf_error("Invalid rxcost"); }
2017-10-25 23:14:08 +08:00
| LIMIT expr { BABEL_IFACE->limit = $2; if (($2<1) || ($2>16)) cf_error("Limit must be in range 1-16"); }
2016-04-29 00:01:40 +08:00
| TYPE WIRED { BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRED; }
| TYPE WIRELESS { BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRELESS; }
2022-04-18 07:03:01 +08:00
| TYPE TUNNEL { BABEL_IFACE->type = BABEL_IFACE_TYPE_TUNNEL; }
2017-10-13 18:34:08 +08:00
| HELLO INTERVAL expr_us { BABEL_IFACE->hello_interval = $3; if (($3<BABEL_MIN_INTERVAL) || ($3>BABEL_MAX_INTERVAL)) cf_error("Hello interval must be in range 10 ms - 655 s"); }
| UPDATE INTERVAL expr_us { BABEL_IFACE->update_interval = $3; if (($3<BABEL_MIN_INTERVAL) || ($3>BABEL_MAX_INTERVAL)) cf_error("Update interval must be in range 10 ms - 655 s"); }
2016-04-29 00:01:40 +08:00
| RX BUFFER expr { BABEL_IFACE->rx_buffer = $3; if (($3<256) || ($3>65535)) cf_error("RX buffer must be in range 256-65535"); }
| TX LENGTH expr { BABEL_IFACE->tx_length = $3; if (($3<256) || ($3>65535)) cf_error("TX length must be in range 256-65535"); }
| TX tos { BABEL_IFACE->tx_tos = $2; }
| TX PRIORITY expr { BABEL_IFACE->tx_priority = $3; }
| CHECK LINK bool { BABEL_IFACE->check_link = $3; }
2017-06-08 18:18:16 +08:00
| NEXT HOP IPV4 ipa { BABEL_IFACE->next_hop_ip4 = $4; if (!ipa_is_ip4($4)) cf_error("Must be an IPv4 address"); }
| NEXT HOP IPV6 ipa { BABEL_IFACE->next_hop_ip6 = $4; if (!ipa_is_ip6($4)) cf_error("Must be an IPv6 address"); }
2021-04-17 21:04:16 +08:00
| AUTHENTICATION NONE { BABEL_IFACE->auth_type = BABEL_AUTH_NONE; }
2021-06-06 21:22:59 +08:00
| AUTHENTICATION MAC { BABEL_IFACE->auth_type = BABEL_AUTH_MAC; BABEL_IFACE->auth_permissive = 0; }
2021-04-17 21:04:16 +08:00
| AUTHENTICATION MAC PERMISSIVE { BABEL_IFACE->auth_type = BABEL_AUTH_MAC; BABEL_IFACE->auth_permissive = 1; }
2022-04-18 07:03:01 +08:00
| RTT MIN expr_us { BABEL_IFACE->rtt_min = $3; }
| RTT MAX expr_us { BABEL_IFACE->rtt_max = $3; }
| RTT COST expr { BABEL_IFACE->rtt_cost = $3; if ($3 >= BABEL_INFINITY) cf_error("RTT cost must be < 65535"); }
2022-12-07 13:02:20 +08:00
| RTT WINLEN expr { BABEL_IFACE->rtt_win_len = $3; if (($3 < 1) || ($3 > 65535)) cf_error("RTT winlen must be between 1-65535"); }
2022-04-18 07:03:01 +08:00
| SEND TIMESTAMPS bool { BABEL_IFACE->rtt_send = $3; }
2021-06-06 21:22:59 +08:00
| password_list
2016-04-29 00:01:40 +08:00
;
babel_iface_opts:
/* empty */
| babel_iface_opts babel_iface_item ';'
;
babel_iface_opt_list:
/* empty */
| '{' babel_iface_opts '}'
;
babel_iface:
babel_iface_start iface_patt_list_nopx babel_iface_opt_list babel_iface_finish;
2019-07-03 06:00:11 +08:00
dynamic_attr: BABEL_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_BABEL_METRIC); } ;
2016-04-29 00:01:40 +08:00
CF_CLI_HELP(SHOW BABEL, ..., [[Show information about Babel protocol]]);
2019-01-30 21:03:47 +08:00
CF_CLI(SHOW BABEL INTERFACES, optproto opttext, [<name>] [\"<interface>\"], [[Show information about Babel interfaces]])
2020-05-14 09:48:17 +08:00
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_interfaces(p, $5); };
2016-04-29 00:01:40 +08:00
2019-01-30 21:03:47 +08:00
CF_CLI(SHOW BABEL NEIGHBORS, optproto opttext, [<name>] [\"<interface>\"], [[Show information about Babel neighbors]])
2020-05-14 09:48:17 +08:00
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_neighbors(p, $5); };
2016-04-29 00:01:40 +08:00
2019-01-30 21:03:47 +08:00
CF_CLI(SHOW BABEL ENTRIES, optproto opttext, [<name>], [[Show information about Babel prefix entries]])
2020-05-14 09:48:17 +08:00
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_entries(p); };
2016-04-29 00:01:40 +08:00
2019-01-30 21:03:47 +08:00
CF_CLI(SHOW BABEL ROUTES, optproto opttext, [<name>], [[Show information about Babel route entries]])
2020-05-14 09:48:17 +08:00
{ PROTO_WALK_CMD($4, &proto_babel, p) babel_show_routes(p); };
2017-11-28 22:11:41 +08:00
2016-04-29 00:01:40 +08:00
CF_CODE
CF_END