2022-08-01 11:01:49 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- Statistics Protocol Configuration
|
|
|
|
*
|
|
|
|
* (c) 2022 Vojtech Vilimek <vojtech.vilimek@nic.cz>
|
|
|
|
* (c) 2022 CZ.NIC z.s.p.o.
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CF_HDR
|
|
|
|
|
|
|
|
#include "proto/snmp/snmp.h"
|
2023-09-04 11:58:59 +00:00
|
|
|
#include "proto/snmp/subagent.h"
|
2022-08-01 11:01:49 +00:00
|
|
|
|
|
|
|
CF_DEFINES
|
|
|
|
|
|
|
|
#define SNMP_CFG ((struct snmp_config *) this_proto)
|
|
|
|
|
|
|
|
CF_DECLS
|
|
|
|
|
2024-05-24 13:20:30 +00:00
|
|
|
CF_KEYWORDS(SNMP, PROTOCOL, BGP, LOCAL, AS, REMOTE, ADDRESS, PORT, DESCRIPTION,
|
2023-11-15 14:03:55 +00:00
|
|
|
TIMEOUT, PRIORITY, CONTEXT, DEFAULT, MESSAGE)
|
2022-08-01 11:01:49 +00:00
|
|
|
|
|
|
|
CF_GRAMMAR
|
|
|
|
|
2023-11-15 14:03:55 +00:00
|
|
|
proto: snmp_proto ;
|
2022-08-01 11:01:49 +00:00
|
|
|
|
|
|
|
snmp_proto:
|
2023-11-15 14:03:55 +00:00
|
|
|
snmp_proto_start proto_name '{' snmp_proto_opts '}' ;
|
|
|
|
|
|
|
|
snmp_proto_item:
|
|
|
|
proto_item
|
|
|
|
| snmp_bgp_bond
|
|
|
|
| LOCAL PORT expr {
|
|
|
|
if (($3 < 1) || ($3 > 65535)) cf_error("Invalid port number");
|
|
|
|
SNMP_CFG->local_port = $3;
|
2023-09-04 11:58:59 +00:00
|
|
|
}
|
2023-11-15 14:03:55 +00:00
|
|
|
| REMOTE PORT expr {
|
|
|
|
if (($3 < 1) || ($3 > 65535)) cf_error("Invalid port number");
|
|
|
|
SNMP_CFG->remote_port = $3;
|
2023-09-04 11:58:59 +00:00
|
|
|
}
|
2024-01-10 11:21:46 +00:00
|
|
|
| LOCAL ID IP4 { SNMP_CFG->bgp_local_id = $3; }
|
|
|
|
| LOCAL ADDRESS IP4 { SNMP_CFG->local_ip = $3; }
|
2024-07-22 16:17:35 +00:00
|
|
|
| REMOTE ADDRESS DEFAULT {
|
|
|
|
if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
|
|
|
|
cf_error("Duplicit option remote address");
|
|
|
|
}
|
2024-07-26 10:28:33 +00:00
|
|
|
| REMOTE ADDRESS ipa {
|
2024-07-22 16:17:35 +00:00
|
|
|
if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
|
|
|
|
cf_error("Duplicit option remote address");
|
|
|
|
|
2023-11-15 14:03:55 +00:00
|
|
|
SNMP_CFG->remote_ip = $3;
|
2024-07-22 16:17:35 +00:00
|
|
|
SNMP_CFG->trans_type = SNMP_TRANS_TCP;
|
|
|
|
}
|
|
|
|
| REMOTE ADDRESS text {
|
|
|
|
if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
|
|
|
|
cf_error("Duplicit option remote address");
|
|
|
|
|
|
|
|
if (strcmp($3, agentx_master_addr)) {
|
|
|
|
SNMP_CFG->remote_path = $3;
|
|
|
|
SNMP_CFG->trans_type = SNMP_TRANS_UNIX;
|
|
|
|
}
|
2023-09-04 11:58:59 +00:00
|
|
|
}
|
2023-11-15 14:03:55 +00:00
|
|
|
| LOCAL AS expr {
|
2024-07-22 16:17:35 +00:00
|
|
|
if ($3 < 1 || $3 > UINT16_MAX) cf_error("Invalid local AS");
|
2023-11-15 14:03:55 +00:00
|
|
|
SNMP_CFG->bgp_local_as = $3;
|
2023-09-04 11:58:59 +00:00
|
|
|
}
|
2023-11-15 14:03:55 +00:00
|
|
|
| SNMP DESCRIPTION text {
|
2023-09-04 11:58:59 +00:00
|
|
|
if (strlen($3) > UINT32_MAX) cf_error("Description is too long");
|
|
|
|
SNMP_CFG->description = $3;
|
|
|
|
}
|
2023-11-15 14:03:55 +00:00
|
|
|
| PRIORITY expr {
|
|
|
|
if ($2 > 255) cf_error("Registration priority must be in range 0-255");
|
|
|
|
SNMP_CFG->priority = $2;
|
|
|
|
}
|
|
|
|
| MESSAGE TIMEOUT expr_us {
|
|
|
|
/* TODO */
|
2024-08-09 19:05:32 +00:00
|
|
|
if ($3 TO_S > 255 || $3 TO_S < 1)
|
|
|
|
log(L_WARN "resolution of AgentX message timeout is from 1 to 255 s.");
|
|
|
|
if (($3 TO_S) - (int)($3 TO_S) > 0)
|
|
|
|
log(L_WARN "AgentX message timeout cannot use second fraction, "
|
|
|
|
"will use rounded up value.");
|
2023-09-04 11:58:59 +00:00
|
|
|
SNMP_CFG->timeout = $3;
|
|
|
|
}
|
2023-11-15 14:03:55 +00:00
|
|
|
/*
|
|
|
|
| ERROR TIMEOUT expr_us {
|
|
|
|
/ * TODO * /
|
|
|
|
SNMP_CFG->error_timeout = $3;
|
2023-09-04 11:58:59 +00:00
|
|
|
}
|
2023-11-15 14:03:55 +00:00
|
|
|
*/
|
|
|
|
| START DELAY TIME expr_us { SNMP_CFG->startup_delay = $4; }
|
|
|
|
;
|
|
|
|
|
|
|
|
snmp_proto_opts:
|
|
|
|
/* empty */
|
|
|
|
| snmp_proto_opts snmp_proto_item ';'
|
2022-08-01 11:01:49 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
snmp_proto_start: proto_start SNMP
|
|
|
|
{
|
|
|
|
this_proto = proto_config_new(&proto_snmp, $1);
|
2022-09-20 12:28:57 +00:00
|
|
|
|
2022-08-02 14:04:25 +00:00
|
|
|
init_list(&SNMP_CFG->bgp_entries);
|
2022-09-30 07:36:09 +00:00
|
|
|
SNMP_CFG->bonds = 0;
|
2022-08-10 15:31:32 +00:00
|
|
|
|
2024-01-10 11:21:46 +00:00
|
|
|
SNMP_CFG->local_ip = IP4_NONE;
|
2024-07-26 10:28:33 +00:00
|
|
|
SNMP_CFG->remote_ip = IPA_NONE;
|
2024-07-22 16:17:35 +00:00
|
|
|
SNMP_CFG->remote_path = agentx_master_addr;
|
|
|
|
SNMP_CFG->trans_type = SNMP_TRANS_DEFAULT;
|
2024-01-10 11:21:46 +00:00
|
|
|
SNMP_CFG->bgp_local_id = IP4_NONE;
|
2022-08-10 15:31:32 +00:00
|
|
|
SNMP_CFG->local_port = 0;
|
|
|
|
SNMP_CFG->remote_port = 705;
|
2023-10-11 08:44:18 +00:00
|
|
|
SNMP_CFG->bgp_local_as = 0;
|
2022-08-10 15:31:32 +00:00
|
|
|
|
2023-09-04 11:58:59 +00:00
|
|
|
SNMP_CFG->description = "bird";
|
2022-08-10 15:31:32 +00:00
|
|
|
SNMP_CFG->timeout = 15;
|
2023-09-04 11:58:59 +00:00
|
|
|
SNMP_CFG->priority = AGENTX_PRIORITY;
|
2022-08-01 11:01:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 14:23:39 +00:00
|
|
|
snmp_bgp_bond: BGP symbol
|
2022-08-01 11:01:49 +00:00
|
|
|
{
|
2023-09-11 11:06:20 +00:00
|
|
|
/* the snmp_context rule sets the correct value of this_bond */
|
2023-11-15 14:03:55 +00:00
|
|
|
cf_assert_symbol($2, SYM_PROTO);
|
|
|
|
|
|
|
|
if (!$2->proto) cf_error("BGP protocol %s not found", $2->name);
|
|
|
|
|
|
|
|
cf_assert($2->proto->protocol == &proto_bgp,
|
|
|
|
"SNMP BGP bond accepts only BGP protocols");
|
|
|
|
|
|
|
|
struct bgp_config *bgp_config = SKIP_BACK(struct bgp_config, c, $2->proto);
|
|
|
|
|
|
|
|
if (!ipa_is_ip4(bgp_config->remote_ip))
|
|
|
|
cf_error("BGP4-MIB does not support IPv6 addresses.");
|
|
|
|
|
2023-10-25 14:23:39 +00:00
|
|
|
struct snmp_bond *this_bond = cfg_alloc(sizeof(struct snmp_bond));
|
2022-08-02 14:04:25 +00:00
|
|
|
this_bond->type = SNMP_BGP;
|
2023-11-15 14:03:55 +00:00
|
|
|
this_bond->config = $2->proto;
|
2022-08-01 11:01:49 +00:00
|
|
|
|
2023-09-11 11:06:20 +00:00
|
|
|
add_tail(&SNMP_CFG->bgp_entries, &this_bond->n);
|
2022-09-30 07:36:09 +00:00
|
|
|
SNMP_CFG->bonds++;
|
2022-08-02 14:04:25 +00:00
|
|
|
}
|
2022-08-01 11:01:49 +00:00
|
|
|
|
|
|
|
CF_CODE
|
|
|
|
|
|
|
|
CF_END
|