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)
|
|
|
|
|
2023-09-11 11:06:20 +00:00
|
|
|
struct snmp_bond *this_bond = NULL;
|
|
|
|
|
2022-08-01 11:01:49 +00:00
|
|
|
CF_DECLS
|
|
|
|
|
2023-09-04 11:58:59 +00:00
|
|
|
CF_KEYWORDS(SNMP, PROTOCOL, BPG, LOCAL, AS, REMOTE, ADDRESS, PORT, DESCRIPTION,
|
2023-09-11 11:06:20 +00:00
|
|
|
TIMEOUT, PRIORITY, CONTEXT, DEFAULT)
|
2022-08-01 11:01:49 +00:00
|
|
|
|
|
|
|
CF_GRAMMAR
|
|
|
|
|
|
|
|
proto: snmp_proto '}' { this_channel = NULL; } ;
|
|
|
|
|
|
|
|
snmp_proto:
|
|
|
|
snmp_proto_start '{'
|
|
|
|
| snmp_proto proto_item ';'
|
2022-08-02 14:04:25 +00:00
|
|
|
| snmp_proto snmp_bgp_bond ';'
|
2023-09-04 11:58:59 +00:00
|
|
|
| snmp_proto LOCAL PORT expr ';' {
|
|
|
|
if (($4 < 1) || ($4 > 65535)) cf_error("Invalid port number");
|
|
|
|
SNMP_CFG->local_port = $4;
|
|
|
|
}
|
|
|
|
| snmp_proto REMOTE PORT expr ';' {
|
|
|
|
if (($4 < 1) || ($4 > 65535)) cf_error("Invalid port number");
|
|
|
|
SNMP_CFG->remote_port = $4;
|
|
|
|
}
|
2023-10-11 08:44:18 +00:00
|
|
|
| snmp_proto LOCAL ID ipa ';' { SNMP_CFG->bgp_local_id = $4; }
|
2023-09-04 11:58:59 +00:00
|
|
|
| snmp_proto LOCAL ADDRESS ipa ';' { SNMP_CFG->local_ip = $4; }
|
|
|
|
| snmp_proto REMOTE ADDRESS ipa ';' {
|
|
|
|
if (ipa_zero($4)) cf_error("Invalid remote ip address");
|
|
|
|
SNMP_CFG->remote_ip = $4;
|
|
|
|
}
|
|
|
|
| snmp_proto LOCAL AS expr ';' {
|
|
|
|
if ($4 < 1 || $4 > 65535) cf_error("Invalid local AS");
|
2023-10-11 08:44:18 +00:00
|
|
|
SNMP_CFG->bgp_local_as = $4;
|
2023-09-04 11:58:59 +00:00
|
|
|
}
|
|
|
|
| snmp_proto DESCRIPTION text ';' {
|
|
|
|
if (strlen($3) > UINT32_MAX) cf_error("Description is too long");
|
|
|
|
SNMP_CFG->description = $3;
|
|
|
|
}
|
|
|
|
| snmp_proto TIMEOUT expr ';' {
|
|
|
|
if ($3 < 1 || $3 > 255) cf_error("Timeout must be in range 1-255");
|
|
|
|
SNMP_CFG->timeout = $3;
|
|
|
|
}
|
|
|
|
| snmp_proto PRIORITY expr ';' {
|
|
|
|
if ($3 > 255) cf_error("Registration priority must be in range 0-255");
|
|
|
|
SNMP_CFG->priority = $3;
|
|
|
|
}
|
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;
|
2023-09-11 11:06:20 +00:00
|
|
|
/* We always have the default context */
|
|
|
|
SNMP_CFG->contexts = 1;
|
2022-08-10 15:31:32 +00:00
|
|
|
|
|
|
|
SNMP_CFG->local_ip = IPA_NONE;
|
|
|
|
SNMP_CFG->remote_ip = ipa_build4(127,0,0,1);
|
2023-10-11 08:44:18 +00:00
|
|
|
SNMP_CFG->bgp_local_id = IPA_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
|
|
|
}
|
|
|
|
|
2022-08-10 15:31:32 +00:00
|
|
|
proto_name ;
|
|
|
|
|
2023-09-11 11:06:20 +00:00
|
|
|
snmp_context:
|
|
|
|
/* empty */ {
|
|
|
|
if (!this_bond)
|
|
|
|
{
|
|
|
|
log(L_INFO "snmp_context no string alloc");
|
|
|
|
this_bond = cfg_alloc(sizeof(struct snmp_bond));
|
|
|
|
}
|
2022-08-10 15:31:32 +00:00
|
|
|
|
2023-09-11 11:06:20 +00:00
|
|
|
this_bond->context = NULL;
|
|
|
|
}
|
|
|
|
| CONTEXT DEFAULT {
|
|
|
|
if (!this_bond)
|
|
|
|
{
|
|
|
|
log(L_INFO "snmp_context CONTEXT DEFAULT alloc");
|
|
|
|
this_bond = cfg_alloc(sizeof(struct snmp_bond));
|
|
|
|
}
|
|
|
|
this_bond->context = NULL;
|
|
|
|
}
|
|
|
|
| CONTEXT text {
|
|
|
|
if(!this_bond)
|
|
|
|
{
|
|
|
|
log(L_INFO "snmp_context CONTEXT text alloc");
|
|
|
|
this_bond = cfg_alloc(sizeof(struct snmp_bond));
|
|
|
|
}
|
|
|
|
this_bond->context = $2;
|
|
|
|
SNMP_CFG->contexts++;
|
|
|
|
log(L_INFO "storing context %s to bond at 0x%p", $2, this_bond);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
snmp_bgp_bond: BGP symbol snmp_context
|
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 */
|
|
|
|
log(L_INFO "this_bond (at 0x%p) has value %s", this_bond,
|
|
|
|
(this_bond->context) ? this_bond->context : "<no_val>");
|
|
|
|
if (!this_bond)
|
|
|
|
{
|
|
|
|
log(L_INFO "snmp_bgp_bond BGP symbol ... alloc");
|
|
|
|
this_bond = cfg_alloc(sizeof(struct snmp_bond));
|
|
|
|
log(L_INFO "Unexpedted alloc in snmp_bgp_bond rule");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log(L_INFO, "working with this_bond (at 0x%p)", this_bond);
|
|
|
|
}
|
2022-08-02 14:04:25 +00:00
|
|
|
this_bond->type = SNMP_BGP;
|
2022-08-01 11:01:49 +00:00
|
|
|
|
2022-09-30 07:36:09 +00:00
|
|
|
cf_assert_symbol($2, SYM_PROTO);
|
|
|
|
this_bond->proto = $2->proto;
|
2022-08-01 11:01:49 +00:00
|
|
|
|
2022-08-02 14:04:25 +00:00
|
|
|
if (!this_bond->proto) cf_error("BGP protocol %s not found", $2->name);
|
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++;
|
2023-09-11 11:06:20 +00:00
|
|
|
|
|
|
|
this_bond = NULL;
|
2022-08-02 14:04:25 +00:00
|
|
|
}
|
2022-08-01 11:01:49 +00:00
|
|
|
|
|
|
|
CF_CODE
|
|
|
|
|
|
|
|
CF_END
|