From 203c63ad5d7a6fed7b87eaf4eeb88a980bf22576 Mon Sep 17 00:00:00 2001 From: Vojtech Vilimek Date: Mon, 1 Aug 2022 13:01:49 +0200 Subject: [PATCH] Initial commit for new protocol `snmp' --- configure.ac | 2 +- nest/protocol.h | 4 +- proto/Doc | 1 + proto/snmp/Doc | 1 + proto/snmp/Makefile | 7 +++ proto/snmp/config.Y | 75 ++++++++++++++++++++++++++++++++ proto/snmp/snmp.c | 101 ++++++++++++++++++++++++++++++++++++++++++++ proto/snmp/snmp.h | 33 +++++++++++++++ 8 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 proto/snmp/Doc create mode 100644 proto/snmp/Makefile create mode 100644 proto/snmp/config.Y create mode 100644 proto/snmp/snmp.c create mode 100644 proto/snmp/snmp.h diff --git a/configure.ac b/configure.ac index 330add87..3703652a 100644 --- a/configure.ac +++ b/configure.ac @@ -292,7 +292,7 @@ if test "$enable_mpls_kernel" != no ; then fi fi -all_protocols="bfd babel bgp mrt ospf perf pipe radv rip rpki static" +all_protocols="bfd babel bgp mrt ospf perf pipe radv rip rpki snmp static" all_protocols=`echo $all_protocols | sed 's/ /,/g'` if test "$with_protocols" = all ; then diff --git a/nest/protocol.h b/nest/protocol.h index 3c823ae1..0b927446 100644 --- a/nest/protocol.h +++ b/nest/protocol.h @@ -84,7 +84,8 @@ void protos_dump_all(void); extern struct protocol proto_device, proto_radv, proto_rip, proto_static, proto_mrt, proto_ospf, proto_perf, - proto_pipe, proto_bgp, proto_bfd, proto_babel, proto_rpki; + proto_pipe, proto_bgp, proto_bfd, proto_babel, proto_rpki, + proto_snmp; /* * Routing Protocol Instance @@ -447,6 +448,7 @@ struct channel_class { }; extern struct channel_class channel_bgp; +extern struct channel_class channel_snmp; struct channel_config { node n; diff --git a/proto/Doc b/proto/Doc index ef573d2a..19523477 100644 --- a/proto/Doc +++ b/proto/Doc @@ -7,5 +7,6 @@ C pipe C radv C rip C rpki +C snmp C static S ../nest/rt-dev.c diff --git a/proto/snmp/Doc b/proto/snmp/Doc new file mode 100644 index 00000000..74738427 --- /dev/null +++ b/proto/snmp/Doc @@ -0,0 +1 @@ +S snmp.c diff --git a/proto/snmp/Makefile b/proto/snmp/Makefile new file mode 100644 index 00000000..844f5a03 --- /dev/null +++ b/proto/snmp/Makefile @@ -0,0 +1,7 @@ +src := snmp.c +obj := $(src-o-files) +$(all-daemon) +$(cf-local) +$(call proto-build,snmp_build) + +tests_objs := $(tests_objs) $(src-o-files) diff --git a/proto/snmp/config.Y b/proto/snmp/config.Y new file mode 100644 index 00000000..e2d85f19 --- /dev/null +++ b/proto/snmp/config.Y @@ -0,0 +1,75 @@ +/* + * BIRD -- Statistics Protocol Configuration + * + * (c) 2022 Vojtech Vilimek + * (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" + +CF_DEFINES + +#define SNMP_CFG ((struct snmp_config *) this_proto) +#define SNMP_CC ((struct snmp_channel_config *) this_channel) + +CF_DECLS + +CF_KEYWORDS(SNMP, TABLE, PROTOCOL, BPG) + +%type snmp_channel_start + +CF_GRAMMAR + +proto: snmp_proto '}' { this_channel = NULL; } ; + +snmp_proto: + snmp_proto_start '{' + | snmp_proto proto_item ';' + | snmp_proto snmp_proto_channel ';' + | snmp_proto ';' + ; + +snmp_proto_start: proto_start SNMP +{ + this_proto = proto_config_new(&proto_snmp, $1); +} + +snmp_proto_channel: snmp_channel_start snmp_channel_opt_list channel_end ; + +snmp_channel_start: net_type symbol +{ + this_channel = channel_config_get(&channel_snmp, $2->name, $1, this_proto); +} + +snmp_channel_opt_list: + /* empty */ + | '{' snmp_opts '}' + ; + +snmp_opts: + /* empty */ + | snmp_opts channel_item ';' + | snmp_opts snmp_opt ';' + ; + +snmp_opt: + PROTOCOL BGP symbol { + SNMP_CC->bgp = NULL; + + struct proto_config *pc; + WALK_LIST(pc, this_proto->global->protos) + if (!strcmp(pc->name, $3->name) + && pc->protocol == &proto_bgp) + SNMP_CC->bgp = (struct bgp_config *) pc; + + if (!SNMP_CC->bgp) cf_error("BGP protocol %s not found", $3); + } + ; + +CF_CODE + +CF_END diff --git a/proto/snmp/snmp.c b/proto/snmp/snmp.c new file mode 100644 index 00000000..3e8785fd --- /dev/null +++ b/proto/snmp/snmp.c @@ -0,0 +1,101 @@ +/* + * BIRD -- Simple Network Management Protocol (SNMP) + * + * (c) 2022 Vojtech Vilimek + * (c) 2022 CZ.NIC z.s.p.o. + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#include "nest/bird.h" +#include "nest/protocol.h" +#include "nest/cli.h" + +#include "proto/snmp/snmp.h" + +static struct proto * +snmp_init(struct proto_config *CF) +{ + struct proto *P = proto_new(CF); + struct snmp_proto *p = (void *) P; + + p->rl_gen = (struct tbf) TBF_DEFAULT_LOG_LIMITS; + + return P; +} + +static int +snmp_start(struct proto *P) +{ + struct channel_config *cc; + WALK_LIST(cc, P->cf->channels) + { + struct channel *c = NULL; + proto_configure_channel(P, &c, cc); + } + + return PS_UP; +} + +static int +snmp_reconfigure(struct proto *P, struct proto_config *CF) +{ + return 0; +} + +static void +snmp_show_proto_info(struct proto *P) +{ + //struct stats_proto *p = (void *) P; + + struct snmp_channel *sc; + + WALK_LIST(sc, P->channels) + { + cli_msg(-1006, " Channel %s", sc->c.name); + + if (!P->disabled) + { + cli_msg(-1006, " enabled"); + } + else + cli_msg(-1006, " disabled"); + } +} + +static int +snmp_channel_start(struct channel *C) +{ + return 0; +} + +static void +snmp_channel_shutdown(struct channel *C) +{ + +} + +struct channel_class channel_snmp = { + .channel_size = sizeof(struct snmp_channel), + .config_size = sizeof(struct snmp_channel_config), + .start = snmp_channel_start, + .shutdown = snmp_channel_shutdown, +}; + +struct protocol proto_snmp = { + .name = "Snmp", + .template = "snmp%d", + .channel_mask = NB_ANY, + .proto_size = sizeof(struct snmp_proto), + .config_size = sizeof(struct snmp_config), + .init = snmp_init, + .start = snmp_start, + .reconfigure = snmp_reconfigure, + .show_proto_info = snmp_show_proto_info, +}; + +void +snmp_build(void) +{ + proto_build(&proto_snmp); +} diff --git a/proto/snmp/snmp.h b/proto/snmp/snmp.h new file mode 100644 index 00000000..e3101b8b --- /dev/null +++ b/proto/snmp/snmp.h @@ -0,0 +1,33 @@ +/* + * BIRD -- Simple Network Management Protocol (SNMP) + * + * (c) 2022 Vojtech Vilimek + * (c) 2022 CZ.NIC z.s.p.o + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#ifndef _BIRD_SNMP_H_ +#define _BIRD_SNPM_H_ + +#include "proto/bgp/bgp.h" + +struct snmp_config { + struct channel_config c; +}; + +struct snmp_proto { + struct channel c; + struct tbf rl_gen; +}; + +struct snmp_channel_config { + struct channel_config c; + struct bgp_config *bgp; +}; + +struct snmp_channel { + struct channel c; +}; + +#endif