0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 09:58:43 +00:00

fixup! tbf: logging rate is settable for rtables, protocol rip, ospf and babel. It can se set both by config and cmd

This commit is contained in:
Katerina Kubecova 2024-05-09 13:37:25 +02:00
parent d36d170d3a
commit 3579682353
12 changed files with 61 additions and 100 deletions

View File

@ -122,11 +122,9 @@ struct tbf {
enum tbf_targets { enum tbf_targets {
TBF_INVALID = 0, TBF_INVALID = 0,
TBF_OSPF_PKT, TBF_PKT,
TBF_OSPF_LSA, TBF_LSA,
TBF_RIP_PKT, TBF_RTE,
TBF_RIP_RTE,
TBF_BABEL_PKT,
TBF_ALL TBF_ALL
}; };
@ -136,6 +134,7 @@ struct logging_rate_targets {
}; };
struct cmd_logging_rate_info { struct cmd_logging_rate_info {
int all_protos;
struct tbf_config *tbfc; struct tbf_config *tbfc;
struct logging_rate_targets *targets; struct logging_rate_targets *targets;
}; };

View File

@ -129,9 +129,8 @@ CF_KEYWORDS(MIN, IDLE, RX, TX, INTERVAL, MULTIPLIER, PASSIVE)
CF_KEYWORDS(CHECK, LINK) CF_KEYWORDS(CHECK, LINK)
CF_KEYWORDS(SORTED, TRIE, MIN, MAX, SETTLE, TIME, GC, THRESHOLD, PERIOD) CF_KEYWORDS(SORTED, TRIE, MIN, MAX, SETTLE, TIME, GC, THRESHOLD, PERIOD)
CF_KEYWORDS(MPLS_LABEL, MPLS_POLICY, MPLS_CLASS) CF_KEYWORDS(MPLS_LABEL, MPLS_POLICY, MPLS_CLASS)
CF_KEYWORDS(ASPA_PROVIDERS)
CF_KEYWORDS(LOGGING, RATE) CF_KEYWORDS(LOGGING, RATE)
CF_KEYWORDS( OSPF_PKT, OSPF_LSA, RIP_PKT, RIP_RTE, BABEL_PKT) CF_KEYWORDS(PKT, LSA, RTE)
/* For r_args_channel */ /* For r_args_channel */
CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, IPV6_SADR, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC) CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, IPV6_SADR, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC)
@ -948,14 +947,10 @@ CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging via BIRD logs]])
CF_CLI(DEBUG, debug_args, (<protocol> | <channel> | \"<pattern>\" | all) (all | off | { states|routes|filters|interfaces|events|packets [, ...] }), [[Control protocol debugging via BIRD logs]]) CF_CLI(DEBUG, debug_args, (<protocol> | <channel> | \"<pattern>\" | all) (all | off | { states|routes|filters|interfaces|events|packets [, ...] }), [[Control protocol debugging via BIRD logs]])
{ /* Done in debug_args */ }; { /* Done in debug_args */ };
logging_rate_target: PIPE ;
tbf_target: tbf_target:
OSPF_PKT { $$ = TBF_OSPF_PKT; } PKT { $$ = TBF_PKT; }
|OSPF_LSA { $$ = TBF_OSPF_LSA; } |LSA { $$ = TBF_LSA; }
|RIP_PKT { $$ = TBF_RIP_PKT; } |RTE { $$ = TBF_RTE; }
|RIP_RTE { $$ = TBF_RIP_RTE; }
|BABEL_PKT { $$ = TBF_BABEL_PKT; }
|ALL { $$ = TBF_ALL; } |ALL { $$ = TBF_ALL; }
logging_rate_targets: logging_rate_targets:
@ -981,6 +976,7 @@ CF_CLI(LOGGING RATE PROTOCOL, proto_patt logging_rate_targets logging_rate, (<pr
struct cmd_logging_rate_info info = { struct cmd_logging_rate_info info = {
.tbfc = $6, .tbfc = $6,
.targets = $5, .targets = $5,
.all_protos = $4.ptr == NULL
}; };
proto_apply_cmd($4, proto_cmd_logging_rate, 1, (uintptr_t) &info); proto_apply_cmd($4, proto_cmd_logging_rate, 1, (uintptr_t) &info);
}; };

View File

@ -2283,10 +2283,38 @@ proto_cmd_mrtdump(struct proto *p, uintptr_t mask, int cnt UNUSED)
void void
proto_cmd_logging_rate(struct proto *p, uintptr_t arg, int cnt UNUSED) proto_cmd_logging_rate(struct proto *p, uintptr_t arg, int cnt UNUSED)
{ {
if (p->set_logging_rate) struct cmd_logging_rate_info *args = (struct cmd_logging_rate_info *) arg;
p->set_logging_rate(p, arg); struct logging_rate_targets *targets = args->targets;
while (targets)
{
int rate_changed = 0;
if ((targets->target == TBF_PKT || targets->target == TBF_ALL) && p->tbfs.pkt)
{
p->tbfs.pkt->cf.rate = args->tbfc->rate;
p->tbfs.pkt->cf.burst = args->tbfc->burst;
rate_changed++;
}
if ((targets->target == TBF_LSA || targets->target == TBF_ALL) && p->tbfs.lsa)
{
p->tbfs.lsa->cf.rate = args->tbfc->rate;
p->tbfs.lsa->cf.burst = args->tbfc->burst;
rate_changed++;
}
if ((targets->target == TBF_RTE || targets->target == TBF_ALL) && p->tbfs.rte)
{
p->tbfs.rte->cf.rate = args->tbfc->rate;
p->tbfs.rte->cf.burst = args->tbfc->burst;
rate_changed++;
}
if (rate_changed == 0 && args->all_protos == 0)
{
if (p->tbfs.pkt || p->tbfs.lsa || p->tbfs.rte)
cli_msg(9002, "%s supports rated logging only for%s%s%s", p->name, p->tbfs.pkt? " PKT":"", p->tbfs.lsa? " LSA":"", p->tbfs.rte? " RTE":"");
else else
cli_msg(9002, "protocol %s does not support logging rate changes", p->name); cli_msg(9002, "%s does not use rated logging", p->name);
}
targets = targets->next;
}
} }
static void static void

View File

@ -136,6 +136,14 @@ struct proto_config {
/* Protocol-specific data follow... */ /* Protocol-specific data follow... */
}; };
struct proto_tbfs
{
/* Pointers to rate limiting logging structures */
struct tbf *pkt;
struct tbf *lsa;
struct tbf *rte;
};
/* Protocol statistics */ /* Protocol statistics */
struct proto_stats { struct proto_stats {
/* Import - from protocol to core */ /* Import - from protocol to core */
@ -196,6 +204,7 @@ struct proto {
btime last_state_change; /* Time of last state transition */ btime last_state_change; /* Time of last state transition */
char *last_state_name_announced; /* Last state name we've announced to the user */ char *last_state_name_announced; /* Last state name we've announced to the user */
char *message; /* State-change message, allocated from proto_pool */ char *message; /* State-change message, allocated from proto_pool */
struct proto_tbfs tbfs; /* Pointers to rate limiting logging structures */
/* /*
* General protocol hooks: * General protocol hooks:
@ -243,7 +252,6 @@ struct proto {
void (*rte_insert)(struct network *, struct rte *); void (*rte_insert)(struct network *, struct rte *);
void (*rte_remove)(struct network *, struct rte *); void (*rte_remove)(struct network *, struct rte *);
u32 (*rte_igp_metric)(struct rte *); u32 (*rte_igp_metric)(struct rte *);
void (*set_logging_rate)(struct proto *P, uintptr_t arg);
/* Hic sunt protocol-specific data */ /* Hic sunt protocol-specific data */
}; };

View File

@ -2582,8 +2582,10 @@ babel_start(struct proto *P)
p->msg_slab = sl_new(P->pool, sizeof(struct babel_msg_node)); p->msg_slab = sl_new(P->pool, sizeof(struct babel_msg_node));
p->seqno_slab = sl_new(P->pool, sizeof(struct babel_seqno_request)); p->seqno_slab = sl_new(P->pool, sizeof(struct babel_seqno_request));
P->set_logging_rate = babel_set_logging_rate;
p->log_pkt_tbf = (struct tbf){ .cf.rate = cf->log_pkt_tbf.rate, .cf.burst = cf->log_pkt_tbf.burst }; p->log_pkt_tbf = (struct tbf){ .cf.rate = cf->log_pkt_tbf.rate, .cf.burst = cf->log_pkt_tbf.burst };
P->tbfs.pkt = &p->log_pkt_tbf;
P->tbfs.rte = NULL;
P->tbfs.lsa = NULL;
return PS_UP; return PS_UP;
} }
@ -2644,26 +2646,6 @@ babel_reconfigure(struct proto *P, struct proto_config *CF)
return 1; return 1;
} }
void
babel_set_logging_rate(struct proto *P, uintptr_t arg)
{
struct babel_proto *p = (void *) P;
struct cmd_logging_rate_info *info = (struct cmd_logging_rate_info*) arg;
struct logging_rate_targets *targets = info->targets;
while (targets)
{
if (targets->target == TBF_BABEL_PKT || targets->target == TBF_ALL)
{
p->log_pkt_tbf.cf.rate = info->tbfc->rate;
p->log_pkt_tbf.cf.burst = info->tbfc->burst;
}
else
cli_msg(9002, "protocol %s: wrong logging rate change type for babel protocol", P->name);
targets = targets->next;
}
}
struct protocol proto_babel = { struct protocol proto_babel = {
.name = "Babel", .name = "Babel",

View File

@ -457,7 +457,6 @@ void babel_show_routes(struct proto *P);
void babel_auth_reset_index(struct babel_iface *ifa); void babel_auth_reset_index(struct babel_iface *ifa);
int babel_auth_check_pc(struct babel_iface *ifa, struct babel_msg_auth *msg); int babel_auth_check_pc(struct babel_iface *ifa, struct babel_msg_auth *msg);
void babel_set_logging_rate(struct proto *P, uintptr_t arg);
/* packets.c */ /* packets.c */
void babel_enqueue(union babel_msg *msg, struct babel_iface *ifa); void babel_enqueue(union babel_msg *msg, struct babel_iface *ifa);

View File

@ -575,8 +575,6 @@ lsadb_args:
| lsadb_args CF_SYM_KNOWN { cf_assert_symbol($2, SYM_PROTO); $$ = $1; $$->proto = (struct ospf_proto *) proto_get_named($2, &proto_ospf); } | lsadb_args CF_SYM_KNOWN { cf_assert_symbol($2, SYM_PROTO); $$ = $1; $$->proto = (struct ospf_proto *) proto_get_named($2, &proto_ospf); }
; ;
logging_rate_target: OSPF_PKT | OSPF_LSA ;
CF_CODE CF_CODE
CF_END CF_END

View File

@ -313,7 +313,9 @@ ospf_start(struct proto *P)
p->log_pkt_tbf = (struct tbf){ .cf.rate = c->log_pkt_tbf.rate, .cf.burst = c->log_pkt_tbf.burst }; p->log_pkt_tbf = (struct tbf){ .cf.rate = c->log_pkt_tbf.rate, .cf.burst = c->log_pkt_tbf.burst };
p->log_lsa_tbf = (struct tbf){ .cf.rate = c->log_lsa_tbf.rate, .cf.burst = c->log_lsa_tbf.burst }; p->log_lsa_tbf = (struct tbf){ .cf.rate = c->log_lsa_tbf.rate, .cf.burst = c->log_lsa_tbf.burst };
P->set_logging_rate = ospf_set_logging_rate; // for setting logging tbf temporarily from cmd P->tbfs.pkt = &p->log_pkt_tbf;
P->tbfs.rte = NULL;
P->tbfs.lsa = &p->log_lsa_tbf;
/* Lock the channel when in GR recovery mode */ /* Lock the channel when in GR recovery mode */
if (p->p.gr_recovery && (p->gr_mode == OSPF_GR_ABLE)) if (p->p.gr_recovery && (p->gr_mode == OSPF_GR_ABLE))
@ -774,31 +776,6 @@ ospf_reconfigure(struct proto *P, struct proto_config *CF)
return 1; return 1;
} }
void
ospf_set_logging_rate(struct proto *P, uintptr_t arg)
{
struct ospf_proto *p = (void *) P;
struct cmd_logging_rate_info *info = (struct cmd_logging_rate_info*) arg;
struct logging_rate_targets *targets = info->targets;
while (targets)
{
if (targets->target == TBF_OSPF_PKT || targets->target == TBF_ALL)
{
p->log_pkt_tbf.cf.rate = info->tbfc->rate;
p->log_pkt_tbf.cf.burst = info->tbfc->burst;
}
else if (targets->target == TBF_OSPF_LSA || targets->target == TBF_ALL)
{
p->log_lsa_tbf.cf.rate = info->tbfc->rate;
p->log_lsa_tbf.cf.burst = info->tbfc->burst;
}
else
cli_msg(9002, "protocol %s: wrong logging rate change type for ospf protocol", P->name);
targets = targets->next;
}
}
void void
ospf_sh_neigh(struct proto *P, const char *iff) ospf_sh_neigh(struct proto *P, const char *iff)
{ {

View File

@ -1023,7 +1023,6 @@ void ospf_iface_remove(struct ospf_iface *ifa);
void ospf_iface_shutdown(struct ospf_iface *ifa); void ospf_iface_shutdown(struct ospf_iface *ifa);
int ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen); int ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen);
int ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new); int ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new);
void ospf_set_logging_rate(struct proto *P, uintptr_t arg);
void ospf_reconfigure_ifaces(struct ospf_proto *p); void ospf_reconfigure_ifaces(struct ospf_proto *p);
void ospf_open_vlink_sk(struct ospf_proto *p); void ospf_open_vlink_sk(struct ospf_proto *p);
struct nbma_node *find_nbma_node_(list *nnl, ip_addr ip); struct nbma_node *find_nbma_node_(list *nnl, ip_addr ip);

View File

@ -208,8 +208,6 @@ CF_CLI(SHOW RIP INTERFACES, optproto opttext, [<name>] [\"<interface>\"], [[Show
CF_CLI(SHOW RIP NEIGHBORS, optproto opttext, [<name>] [\"<interface>\"], [[Show information about RIP neighbors]]) CF_CLI(SHOW RIP NEIGHBORS, optproto opttext, [<name>] [\"<interface>\"], [[Show information about RIP neighbors]])
{ PROTO_WALK_CMD($4, &proto_rip, p) rip_show_neighbors(p, $5); }; { PROTO_WALK_CMD($4, &proto_rip, p) rip_show_neighbors(p, $5); };
logging_rate_target: RIP_PKT | RIP_RTE ;
CF_CODE CF_CODE

View File

@ -1163,7 +1163,9 @@ rip_start(struct proto *P)
p->log_pkt_tbf = (struct tbf){ .cf.rate = cf->log_pkt_tbf.rate, .cf.burst = cf->log_pkt_tbf.burst }; p->log_pkt_tbf = (struct tbf){ .cf.rate = cf->log_pkt_tbf.rate, .cf.burst = cf->log_pkt_tbf.burst };
p->log_rte_tbf = (struct tbf){ .cf.rate = cf->log_rte_tbf.rate, .cf.burst = cf->log_pkt_tbf.burst }; p->log_rte_tbf = (struct tbf){ .cf.rate = cf->log_rte_tbf.rate, .cf.burst = cf->log_pkt_tbf.burst };
P->set_logging_rate = rip_set_logging_rate; P->tbfs.pkt = &p->log_pkt_tbf;
P->tbfs.rte = &p->log_rte_tbf;
P->tbfs.lsa = NULL;
tm_start(p->timer, MIN(cf->min_timeout_time, cf->max_garbage_time)); tm_start(p->timer, MIN(cf->min_timeout_time, cf->max_garbage_time));
@ -1216,30 +1218,6 @@ rip_reconfigure(struct proto *P, struct proto_config *CF)
return 1; return 1;
} }
void
rip_set_logging_rate(struct proto *P, uintptr_t arg)
{
struct rip_proto *p = (void *) P;
struct cmd_logging_rate_info *info = (struct cmd_logging_rate_info*) arg;
struct logging_rate_targets *targets = info->targets;
while (targets)
{
if (targets->target == TBF_RIP_PKT || targets->target == TBF_ALL)
{
p->log_pkt_tbf.cf.rate = info->tbfc->rate;
p->log_pkt_tbf.cf.burst = info->tbfc->burst;
}
else if (targets->target == TBF_RIP_RTE || targets->target == TBF_ALL)
{
p->log_rte_tbf.cf.rate = info->tbfc->rate;
p->log_rte_tbf.cf.burst = info->tbfc->burst;
}
else
cli_msg(9002, "protocol %s: wrong logging rate change type for rip protocol", P->name);
targets = targets->next;
}
}
static void static void
rip_get_route_info(rte *rte, byte *buf) rip_get_route_info(rte *rte, byte *buf)
{ {

View File

@ -226,7 +226,6 @@ struct rip_neighbor * rip_get_neighbor(struct rip_proto *p, ip_addr *a, struct r
void rip_update_bfd(struct rip_proto *p, struct rip_neighbor *n); void rip_update_bfd(struct rip_proto *p, struct rip_neighbor *n);
void rip_show_interfaces(struct proto *P, const char *iff); void rip_show_interfaces(struct proto *P, const char *iff);
void rip_show_neighbors(struct proto *P, const char *iff); void rip_show_neighbors(struct proto *P, const char *iff);
void rip_set_logging_rate(struct proto *P, uintptr_t arg);
/* packets.c */ /* packets.c */
void rip_send_request(struct rip_proto *p, struct rip_iface *ifa); void rip_send_request(struct rip_proto *p, struct rip_iface *ifa);