CF_DECLS
-CF_KEYWORDS(SNMP, PROTOCOL, BGP, LOCAL, AS, REMOTE, ADDRESS, PORT, DESCRIPTION,
- TIMEOUT, PRIORITY, CONTEXT, DEFAULT, MESSAGE, VERBOSE)
+CF_KEYWORDS(SNMP, PROTOCOL, LOCAL, AS, REMOTE, ADDRESS, PORT, DESCRIPTION,
+ TIMEOUT, PRIORITY, CONTEXT, DEFAULT, MESSAGE, VERBOSE, AGENTX,
+ SUBAGENT, MASTER, BGP4, MIB, REGISTRATION, PEER)
CF_GRAMMAR
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;
- }
- | REMOTE PORT expr {
- if (($3 < 1) || ($3 > 65535)) cf_error("Invalid port number");
- SNMP_CFG->remote_port = $3;
- }
- | LOCAL ID IP4 { SNMP_CFG->bgp_local_id = $3; }
- | LOCAL ADDRESS IP4 { SNMP_CFG->local_ip = $3; }
- | REMOTE ADDRESS DEFAULT {
+ | SOURCE ADDRESS ipa { SNMP_CFG->local_ip = $3; }
+ | AGENTX MASTER ADDRESS DEFAULT {
if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
cf_error("Duplicit option remote address");
}
- | REMOTE ADDRESS ipa {
+ | AGENTX MASTER ADDRESS text {
if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
cf_error("Duplicit option remote address");
- SNMP_CFG->remote_ip = $3;
- SNMP_CFG->trans_type = SNMP_TRANS_TCP;
+ if (strcmp($4, agentx_master_addr)) {
+ SNMP_CFG->master_path = $4;
+ SNMP_CFG->trans_type = SNMP_TRANS_UNIX;
+ }
}
- | REMOTE ADDRESS text {
+ | AGENTX MASTER ADDRESS ipa {
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;
- }
+ SNMP_CFG->master_ip = $4;
+ SNMP_CFG->trans_type = SNMP_TRANS_TCP;
}
- | LOCAL AS expr {
- if ($3 < 1 || $3 > UINT16_MAX) cf_error("Invalid local AS");
- SNMP_CFG->bgp_local_as = $3;
+ | AGENTX MASTER PORT expr {
+ /* TODO better grammar name (maybe: AX MSTR ADDRESS ipa / ADDRESS ipa [PORT] expr) */
+ if (($4 < 1) || ($4 > 65535)) cf_error("Invalid port number");
+ SNMP_CFG->master_port = $4;
}
- | SNMP DESCRIPTION text {
+ | SUBAGENT DESCRIPTION text {
if (strlen($3) > UINT16_MAX - 1) cf_error("Description is too long");
SNMP_CFG->description = $3;
}
- | PRIORITY expr {
- if ($2 > 255) cf_error("Registration priority must be in range 0-255");
- SNMP_CFG->priority = $2;
+ | REGISTRATION PRIORITY expr {
+ if ($3 > 255) cf_error("Registration priority must be in range 0-255");
+ SNMP_CFG->priority = $3;
}
| MESSAGE TIMEOUT expr_us {
/* TODO */
/ * TODO * /
SNMP_CFG->error_timeout = $3;
}
+ | RETRY TIME expr_us {
+ / * TODO * /
+ SNMP_CFG->retry_timeout = $3;
+ }
*/
| START DELAY TIME expr_us { SNMP_CFG->startup_delay = $4; }
| VERBOSE bool { SNMP_CFG->verbose = $2; }
;
-snmp_proto_opts:
- /* empty */
- | snmp_proto_opts snmp_proto_item ';'
+bgp4_mib:
+ BGP4 MIB '{' bgp4_mib_items '}'
+ | MIB BGP4 '{' bgp4_mib_items '}'
;
-snmp_proto_start: proto_start SNMP
-{
- this_proto = proto_config_new(&proto_snmp, $1);
+bgp4_mib_items:
+ bgp4_mib_items_opt bgp4_mib_as bgp4_mib_items_opt bgp4_mib_id bgp4_mib_items_opt
+ ;
- init_list(&SNMP_CFG->bgp_entries);
- SNMP_CFG->bonds = 0;
+bgp4_mib_as:
+ LOCAL AS expr ';' {
+ if ($3 < 1 || $3 > UINT16_MAX) cf_error("Invalid local AS for BGP4-MIB");
+ SNMP_CFG->bgp4_local_as = $3;
+ }
+ /* TODO add option to follow some bgp peer local as */
+ ;
- SNMP_CFG->local_ip = IP4_NONE;
- SNMP_CFG->remote_ip = IPA_NONE;
- SNMP_CFG->remote_path = agentx_master_addr;
- SNMP_CFG->trans_type = SNMP_TRANS_DEFAULT;
- SNMP_CFG->bgp_local_id = IP4_NONE;
- SNMP_CFG->local_port = 0;
- SNMP_CFG->remote_port = 705;
- SNMP_CFG->bgp_local_as = 0;
- SNMP_CFG->verbose = 0;
+bgp4_mib_id:
+ LOCAL ROUTER ID idval ';' { SNMP_CFG->bgp4_local_id = $4; }
+ /* TODO add option to inherit global router id, or follow some bgp peer */
+ ;
- SNMP_CFG->description = "bird";
- SNMP_CFG->timeout = 15;
- SNMP_CFG->priority = AGENTX_PRIORITY;
-}
+bgp4_mib_items_opt:
+ /* empty */
+ | bgp4_mib_items_opt bgp4_mib_peer ';'
+ ;
-snmp_bgp_bond: BGP symbol
+bgp4_mib_peer: PEER symbol
{
/* the snmp_context rule sets the correct value of this_bond */
cf_assert_symbol($2, SYM_PROTO);
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.");
-
struct snmp_bond *this_bond = cfg_alloc(sizeof(struct snmp_bond));
this_bond->type = SNMP_BGP;
this_bond->config = $2->proto;
SNMP_CFG->bonds++;
}
+snmp_proto_opts:
+ /* empty */
+ | snmp_proto_opts snmp_proto_item ';'
+ | snmp_proto_opts bgp4_mib
+ ;
+
+snmp_proto_start: proto_start SNMP
+{
+ this_proto = proto_config_new(&proto_snmp, $1);
+
+ init_list(&SNMP_CFG->bgp_entries);
+ SNMP_CFG->bonds = 0;
+
+ SNMP_CFG->local_ip = IPA_NONE;
+ SNMP_CFG->master_ip = IPA_NONE;
+ SNMP_CFG->master_port = SNMP_PORT;
+ SNMP_CFG->master_path = agentx_master_addr;
+ SNMP_CFG->trans_type = SNMP_TRANS_DEFAULT;
+ SNMP_CFG->bgp4_local_id = 0;
+ SNMP_CFG->bgp4_local_as = 0;
+ SNMP_CFG->verbose = 0;
+
+ SNMP_CFG->description = "bird";
+ SNMP_CFG->timeout = 15;
+ SNMP_CFG->priority = AGENTX_PRIORITY;
+}
+
+
CF_CODE
CF_END
/* We need to lock the IP address */
struct object_lock *lock;
lock = p->lock = olock_new(p->pool);
- lock->addr = p->remote_ip;
- lock->port = p->remote_port;
+ lock->addr = p->master_ip;
+ lock->port = p->master_port;
lock->type = OBJLOCK_TCP;
lock->hook = snmp_start_locked;
lock->data = p;
if (cf->trans_type == SNMP_TRANS_TCP)
{
s->type = SK_TCP_ACTIVE;
- s->daddr = p->remote_ip;
- s->dport = p->remote_port;
+ s->daddr = p->master_ip;
+ s->dport = p->master_port;
s->rbsize = SNMP_RX_BUFFER_SIZE;
s->tbsize = SNMP_TX_BUFFER_SIZE;
}
else
{
s->type = SK_UNIX_ACTIVE;
- s->host = cf->remote_path; /* daddr */
+ s->host = cf->master_path; /* daddr */
s->rbsize = SNMP_RX_BUFFER_SIZE;
s->tbsize = SNMP_TX_BUFFER_SIZE;
}
return 0;
if (old->trans_type == SNMP_TRANS_TCP &&
- (ipa_compare(old->remote_ip, new->remote_ip)
- || old->remote_port != new->remote_port))
+ (ipa_compare(old->master_ip, new->master_ip)
+ || old->master_port != new->master_port))
return 0;
if (old->trans_type != SNMP_TRANS_TCP &&
- bstrcmp(old->remote_path, new->remote_path))
+ bstrcmp(old->master_path, new->master_path))
return 0;
- return !(ip4_compare(old->bgp_local_id, new->bgp_local_id)
- || old->bgp_local_as != new->bgp_local_as
+ return (old->bgp4_local_id != new->bgp4_local_id
+ || old->bgp4_local_as != new->bgp4_local_as
|| old->timeout != new->timeout // TODO distinguish message timemout
//(Open.timeout and timeout for timer)
|| old->priority != new->priority
struct snmp_config *cf = (struct snmp_config *) P->cf;
p->local_ip = cf->local_ip;
- p->remote_ip = cf->remote_ip;
- p->local_port = cf->local_port;
- p->remote_port = cf->remote_port;
- p->bgp_local_as = cf->bgp_local_as;
- p->bgp_local_id = cf->bgp_local_id;
+ p->master_ip = cf->master_ip;
+ p->master_port = cf->master_port;
+ p->bgp4_local_as = cf->bgp4_local_as;
+ p->bgp4_local_id = cf->bgp4_local_id;
p->timeout = cf->timeout;
p->startup_delay = cf->startup_delay;
p->verbose = cf->verbose;
const struct snmp_config *cf = (struct snmp_config *) CF;
/* Walk the BGP protocols and cache their references. */
- if (cf->bgp_local_as == 0)
+ if (cf->bgp4_local_as == 0)
cf_error("local as not specified");
}