0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

SNMP: Config grammar changes

This commit is contained in:
Vojtech Vilimek 2024-08-16 10:50:46 +02:00
parent 3c6d50c240
commit f22dd17634
4 changed files with 109 additions and 91 deletions

View File

@ -308,7 +308,7 @@ fill_local_as(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
{ {
if (c->sr_vb_start->name.n_subid != 4) if (c->sr_vb_start->name.n_subid != 4)
return SNMP_SEARCH_NO_INSTANCE; return SNMP_SEARCH_NO_INSTANCE;
snmp_varbind_int(c, c->p->bgp_local_as); snmp_varbind_int(c, c->p->bgp4_local_as);
return SNMP_SEARCH_OK; return SNMP_SEARCH_OK;
} }
@ -663,7 +663,8 @@ fill_local_id(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
{ {
if (c->sr_vb_start->name.n_subid != 4) if (c->sr_vb_start->name.n_subid != 4)
return SNMP_SEARCH_NO_INSTANCE; return SNMP_SEARCH_NO_INSTANCE;
snmp_varbind_ip4(c, c->p->bgp_local_id); ip4_addr router_id_ip = ip4_from_u32(c->p->bgp4_local_id);
snmp_varbind_ip4(c, router_id_ip);
return SNMP_SEARCH_OK; return SNMP_SEARCH_OK;
} }
@ -749,8 +750,8 @@ void
snmp_bgp4_show_info(struct snmp_proto *p) snmp_bgp4_show_info(struct snmp_proto *p)
{ {
cli_msg(-1006, " BGP4-MIB"); cli_msg(-1006, " BGP4-MIB");
cli_msg(-1006, " Local AS %u", p->bgp_local_as); cli_msg(-1006, " Local AS %u", p->bgp4_local_as);
cli_msg(-1006, " Local router id %R", p->bgp_local_id); cli_msg(-1006, " Local router id %R", p->bgp4_local_id);
cli_msg(-1006, " BGP peers"); cli_msg(-1006, " BGP peers");
if (p->bgp_hash.count == 0) if (p->bgp_hash.count == 0)

View File

@ -18,8 +18,9 @@ CF_DEFINES
CF_DECLS CF_DECLS
CF_KEYWORDS(SNMP, PROTOCOL, BGP, LOCAL, AS, REMOTE, ADDRESS, PORT, DESCRIPTION, CF_KEYWORDS(SNMP, PROTOCOL, LOCAL, AS, REMOTE, ADDRESS, PORT, DESCRIPTION,
TIMEOUT, PRIORITY, CONTEXT, DEFAULT, MESSAGE, VERBOSE) TIMEOUT, PRIORITY, CONTEXT, DEFAULT, MESSAGE, VERBOSE, AGENTX,
SUBAGENT, MASTER, BGP4, MIB, REGISTRATION, PEER)
CF_GRAMMAR CF_GRAMMAR
@ -30,48 +31,39 @@ snmp_proto:
snmp_proto_item: snmp_proto_item:
proto_item proto_item
| snmp_bgp_bond | SOURCE ADDRESS ipa { SNMP_CFG->local_ip = $3; }
| LOCAL PORT expr { | AGENTX MASTER ADDRESS DEFAULT {
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 {
if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT) if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
cf_error("Duplicit option remote address"); cf_error("Duplicit option remote address");
} }
| REMOTE ADDRESS ipa { | AGENTX MASTER ADDRESS text {
if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT) if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
cf_error("Duplicit option remote address"); cf_error("Duplicit option remote address");
SNMP_CFG->remote_ip = $3; if (strcmp($4, agentx_master_addr)) {
SNMP_CFG->trans_type = SNMP_TRANS_TCP; SNMP_CFG->master_path = $4;
}
| 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; SNMP_CFG->trans_type = SNMP_TRANS_UNIX;
} }
} }
| LOCAL AS expr { | AGENTX MASTER ADDRESS ipa {
if ($3 < 1 || $3 > UINT16_MAX) cf_error("Invalid local AS"); if (SNMP_CFG->trans_type != SNMP_TRANS_DEFAULT)
SNMP_CFG->bgp_local_as = $3; cf_error("Duplicit option remote address");
SNMP_CFG->master_ip = $4;
SNMP_CFG->trans_type = SNMP_TRANS_TCP;
} }
| SNMP DESCRIPTION text { | 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;
}
| SUBAGENT DESCRIPTION text {
if (strlen($3) > UINT16_MAX - 1) cf_error("Description is too long"); if (strlen($3) > UINT16_MAX - 1) cf_error("Description is too long");
SNMP_CFG->description = $3; SNMP_CFG->description = $3;
} }
| PRIORITY expr { | REGISTRATION PRIORITY expr {
if ($2 > 255) cf_error("Registration priority must be in range 0-255"); if ($3 > 255) cf_error("Registration priority must be in range 0-255");
SNMP_CFG->priority = $2; SNMP_CFG->priority = $3;
} }
| MESSAGE TIMEOUT expr_us { | MESSAGE TIMEOUT expr_us {
/* TODO */ /* TODO */
@ -87,39 +79,43 @@ snmp_proto_item:
/ * TODO * / / * TODO * /
SNMP_CFG->error_timeout = $3; 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; } | START DELAY TIME expr_us { SNMP_CFG->startup_delay = $4; }
| VERBOSE bool { SNMP_CFG->verbose = $2; } | VERBOSE bool { SNMP_CFG->verbose = $2; }
; ;
snmp_proto_opts: bgp4_mib:
/* empty */ BGP4 MIB '{' bgp4_mib_items '}'
| snmp_proto_opts snmp_proto_item ';' | MIB BGP4 '{' bgp4_mib_items '}'
; ;
snmp_proto_start: proto_start SNMP bgp4_mib_items:
{ bgp4_mib_items_opt bgp4_mib_as bgp4_mib_items_opt bgp4_mib_id bgp4_mib_items_opt
this_proto = proto_config_new(&proto_snmp, $1); ;
init_list(&SNMP_CFG->bgp_entries); bgp4_mib_as:
SNMP_CFG->bonds = 0; 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; bgp4_mib_id:
SNMP_CFG->remote_ip = IPA_NONE; LOCAL ROUTER ID idval ';' { SNMP_CFG->bgp4_local_id = $4; }
SNMP_CFG->remote_path = agentx_master_addr; /* TODO add option to inherit global router id, or follow some bgp peer */
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;
SNMP_CFG->description = "bird"; bgp4_mib_items_opt:
SNMP_CFG->timeout = 15; /* empty */
SNMP_CFG->priority = AGENTX_PRIORITY; | 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 */ /* the snmp_context rule sets the correct value of this_bond */
cf_assert_symbol($2, SYM_PROTO); cf_assert_symbol($2, SYM_PROTO);
@ -129,11 +125,6 @@ snmp_bgp_bond: BGP symbol
cf_assert($2->proto->protocol == &proto_bgp, cf_assert($2->proto->protocol == &proto_bgp,
"SNMP BGP bond accepts only BGP protocols"); "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)); struct snmp_bond *this_bond = cfg_alloc(sizeof(struct snmp_bond));
this_bond->type = SNMP_BGP; this_bond->type = SNMP_BGP;
this_bond->config = $2->proto; this_bond->config = $2->proto;
@ -142,6 +133,34 @@ snmp_bgp_bond: BGP symbol
SNMP_CFG->bonds++; 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_CODE
CF_END CF_END

View File

@ -328,8 +328,8 @@ snmp_set_state(struct snmp_proto *p, enum snmp_proto_state state)
/* We need to lock the IP address */ /* We need to lock the IP address */
struct object_lock *lock; struct object_lock *lock;
lock = p->lock = olock_new(p->pool); lock = p->lock = olock_new(p->pool);
lock->addr = p->remote_ip; lock->addr = p->master_ip;
lock->port = p->remote_port; lock->port = p->master_port;
lock->type = OBJLOCK_TCP; lock->type = OBJLOCK_TCP;
lock->hook = snmp_start_locked; lock->hook = snmp_start_locked;
lock->data = p; lock->data = p;
@ -349,15 +349,15 @@ snmp_set_state(struct snmp_proto *p, enum snmp_proto_state state)
if (cf->trans_type == SNMP_TRANS_TCP) if (cf->trans_type == SNMP_TRANS_TCP)
{ {
s->type = SK_TCP_ACTIVE; s->type = SK_TCP_ACTIVE;
s->daddr = p->remote_ip; s->daddr = p->master_ip;
s->dport = p->remote_port; s->dport = p->master_port;
s->rbsize = SNMP_RX_BUFFER_SIZE; s->rbsize = SNMP_RX_BUFFER_SIZE;
s->tbsize = SNMP_TX_BUFFER_SIZE; s->tbsize = SNMP_TX_BUFFER_SIZE;
} }
else else
{ {
s->type = SK_UNIX_ACTIVE; s->type = SK_UNIX_ACTIVE;
s->host = cf->remote_path; /* daddr */ s->host = cf->master_path; /* daddr */
s->rbsize = SNMP_RX_BUFFER_SIZE; s->rbsize = SNMP_RX_BUFFER_SIZE;
s->tbsize = SNMP_TX_BUFFER_SIZE; s->tbsize = SNMP_TX_BUFFER_SIZE;
} }
@ -517,16 +517,16 @@ snmp_reconfigure_logic(struct snmp_proto *p, const struct snmp_config *new)
return 0; return 0;
if (old->trans_type == SNMP_TRANS_TCP && if (old->trans_type == SNMP_TRANS_TCP &&
(ipa_compare(old->remote_ip, new->remote_ip) (ipa_compare(old->master_ip, new->master_ip)
|| old->remote_port != new->remote_port)) || old->master_port != new->master_port))
return 0; return 0;
if (old->trans_type != SNMP_TRANS_TCP && if (old->trans_type != SNMP_TRANS_TCP &&
bstrcmp(old->remote_path, new->remote_path)) bstrcmp(old->master_path, new->master_path))
return 0; return 0;
return !(ip4_compare(old->bgp_local_id, new->bgp_local_id) return (old->bgp4_local_id != new->bgp4_local_id
|| old->bgp_local_as != new->bgp_local_as || old->bgp4_local_as != new->bgp4_local_as
|| old->timeout != new->timeout // TODO distinguish message timemout || old->timeout != new->timeout // TODO distinguish message timemout
//(Open.timeout and timeout for timer) //(Open.timeout and timeout for timer)
|| old->priority != new->priority || old->priority != new->priority
@ -594,11 +594,10 @@ snmp_start(struct proto *P)
struct snmp_config *cf = (struct snmp_config *) P->cf; struct snmp_config *cf = (struct snmp_config *) P->cf;
p->local_ip = cf->local_ip; p->local_ip = cf->local_ip;
p->remote_ip = cf->remote_ip; p->master_ip = cf->master_ip;
p->local_port = cf->local_port; p->master_port = cf->master_port;
p->remote_port = cf->remote_port; p->bgp4_local_as = cf->bgp4_local_as;
p->bgp_local_as = cf->bgp_local_as; p->bgp4_local_id = cf->bgp4_local_id;
p->bgp_local_id = cf->bgp_local_id;
p->timeout = cf->timeout; p->timeout = cf->timeout;
p->startup_delay = cf->startup_delay; p->startup_delay = cf->startup_delay;
p->verbose = cf->verbose; p->verbose = cf->verbose;
@ -651,7 +650,7 @@ snmp_postconfig(struct proto_config *CF)
const struct snmp_config *cf = (struct snmp_config *) CF; const struct snmp_config *cf = (struct snmp_config *) CF;
/* Walk the BGP protocols and cache their references. */ /* 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"); cf_error("local as not specified");
} }

View File

@ -65,14 +65,13 @@ struct snmp_bgp_peer {
struct snmp_config { struct snmp_config {
struct proto_config cf; struct proto_config cf;
enum snmp_transport_type trans_type; enum snmp_transport_type trans_type;
ip4_addr local_ip; ip_addr local_ip;
u16 local_port; ip_addr master_ip; /* master agentx IP address for TCP transport */
ip_addr remote_ip; /* master agentx IP address for TCP transport */ u16 master_port;
u16 remote_port; const char *master_path; /* master agentx UNIX socket name */
const char *remote_path; /* master agentx UNIX socket name */
ip4_addr bgp_local_id; /* BGP4-MIB related fields */ u32 bgp4_local_id; /* BGP4-MIB related fields */
u32 bgp_local_as; u32 bgp4_local_as;
btime timeout; btime timeout;
btime startup_delay; btime startup_delay;
@ -96,13 +95,13 @@ struct snmp_proto {
enum snmp_proto_state state; enum snmp_proto_state state;
ip4_addr local_ip; ip_addr local_ip;
ip_addr remote_ip; ip_addr master_ip;
u16 local_port; u16 master_port;
u16 remote_port;
ip4_addr bgp_local_id; /* BGP4-MIB related fields */ /* TODO add struct for grouping BGP4-MIB data */
u32 bgp_local_as; u32 bgp4_local_id; /* BGP4-MIB related fields */
u32 bgp4_local_as;
sock *sock; sock *sock;