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

Initial commit for new protocol `snmp'

This commit is contained in:
Vojtech Vilimek 2022-08-01 13:01:49 +02:00
parent f60f7dfdee
commit 203c63ad5d
8 changed files with 222 additions and 2 deletions

View File

@ -292,7 +292,7 @@ if test "$enable_mpls_kernel" != no ; then
fi fi
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'` all_protocols=`echo $all_protocols | sed 's/ /,/g'`
if test "$with_protocols" = all ; then if test "$with_protocols" = all ; then

View File

@ -84,7 +84,8 @@ void protos_dump_all(void);
extern struct protocol extern struct protocol
proto_device, proto_radv, proto_rip, proto_static, proto_mrt, proto_device, proto_radv, proto_rip, proto_static, proto_mrt,
proto_ospf, proto_perf, 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 * Routing Protocol Instance
@ -447,6 +448,7 @@ struct channel_class {
}; };
extern struct channel_class channel_bgp; extern struct channel_class channel_bgp;
extern struct channel_class channel_snmp;
struct channel_config { struct channel_config {
node n; node n;

View File

@ -7,5 +7,6 @@ C pipe
C radv C radv
C rip C rip
C rpki C rpki
C snmp
C static C static
S ../nest/rt-dev.c S ../nest/rt-dev.c

1
proto/snmp/Doc Normal file
View File

@ -0,0 +1 @@
S snmp.c

7
proto/snmp/Makefile Normal file
View File

@ -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)

75
proto/snmp/config.Y Normal file
View File

@ -0,0 +1,75 @@
/*
* 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"
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 <cc> 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

101
proto/snmp/snmp.c Normal file
View File

@ -0,0 +1,101 @@
/*
* BIRD -- Simple Network Management Protocol (SNMP)
*
* (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.
*/
#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);
}

33
proto/snmp/snmp.h Normal file
View File

@ -0,0 +1,33 @@
/*
* BIRD -- Simple Network Management Protocol (SNMP)
*
* (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.
*/
#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