]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Initial commit for new protocol `snmp'
authorVojtech Vilimek <vojtech.vilimek@nic.cz>
Mon, 1 Aug 2022 11:01:49 +0000 (13:01 +0200)
committerVojtech Vilimek <vojtech.vilimek@nic.cz>
Mon, 1 Aug 2022 11:01:49 +0000 (13:01 +0200)
configure.ac
nest/protocol.h
proto/Doc
proto/snmp/Doc [new file with mode: 0644]
proto/snmp/Makefile [new file with mode: 0644]
proto/snmp/config.Y [new file with mode: 0644]
proto/snmp/snmp.c [new file with mode: 0644]
proto/snmp/snmp.h [new file with mode: 0644]

index 330add8798a085038817b3756397f2d1654e6018..3703652aa82e9e9c1f57a83d765dce0e3bae75c0 100644 (file)
@@ -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
index 3c823ae11d860aa3fb374ce7d582ee6e3d24fdf9..0b927446d049417dbe8f122e2936abcaf1e2f6c5 100644 (file)
@@ -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;
index ef573d2afa64772eae8fdbea75fbec81d4809b93..195234773ea647e6b1046aac1ed9ef4f235cc1a0 100644 (file)
--- 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 (file)
index 0000000..7473842
--- /dev/null
@@ -0,0 +1 @@
+S snmp.c
diff --git a/proto/snmp/Makefile b/proto/snmp/Makefile
new file mode 100644 (file)
index 0000000..844f5a0
--- /dev/null
@@ -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 (file)
index 0000000..e2d85f1
--- /dev/null
@@ -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
diff --git a/proto/snmp/snmp.c b/proto/snmp/snmp.c
new file mode 100644 (file)
index 0000000..3e8785f
--- /dev/null
@@ -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);
+}
diff --git a/proto/snmp/snmp.h b/proto/snmp/snmp.h
new file mode 100644 (file)
index 0000000..e3101b8
--- /dev/null
@@ -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