From 98bf329be6955a2d8f47467e4be8eb01124a0fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Tvrd=C3=ADk?= Date: Thu, 17 Sep 2015 17:15:30 +0200 Subject: [PATCH] RPKI: add new protocol skeleton --- configure.in | 2 +- nest/proto.c | 3 ++ nest/protocol.h | 2 +- proto/Doc | 3 +- proto/rpki/Doc | 1 + proto/rpki/Makefile | 5 +++ proto/rpki/config.Y | 48 +++++++++++++++++++++++ proto/rpki/rpki.c | 93 ++++++++++++++++++++++++++++++++++++++++++++ proto/rpki/rpki.h | 30 ++++++++++++++ sysdep/autoconf.h.in | 1 + 10 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 proto/rpki/Doc create mode 100644 proto/rpki/Makefile create mode 100644 proto/rpki/config.Y create mode 100644 proto/rpki/rpki.c create mode 100644 proto/rpki/rpki.h diff --git a/configure.in b/configure.in index c81709e6..41838d3b 100644 --- a/configure.in +++ b/configure.in @@ -205,7 +205,7 @@ fi AC_SUBST(iproutedir) -all_protocols="$proto_bfd bgp ospf pipe $proto_radv rip static" +all_protocols="$proto_bfd bgp ospf pipe $proto_radv rip rpki static" all_protocols=`echo $all_protocols | sed 's/ /,/g'` if test "$with_protocols" = all ; then diff --git a/nest/proto.c b/nest/proto.c index 6531083c..e86b69b7 100644 --- a/nest/proto.c +++ b/nest/proto.c @@ -919,6 +919,9 @@ protos_build(void) proto_build(&proto_bfd); bfd_init_all(); #endif +#ifdef CONFIG_RPKI + proto_build(&proto_rpki); +#endif proto_pool = rp_new(&root_pool, "Protocols"); proto_flush_event = ev_new(proto_pool); diff --git a/nest/protocol.h b/nest/protocol.h index 8c49154f..384f805b 100644 --- a/nest/protocol.h +++ b/nest/protocol.h @@ -76,7 +76,7 @@ void protos_dump_all(void); extern struct protocol proto_device, proto_radv, proto_rip, proto_static, - proto_ospf, proto_pipe, proto_bgp, proto_bfd; + proto_ospf, proto_pipe, proto_bgp, proto_bfd, proto_rpki; /* * Routing Protocol Instance diff --git a/proto/Doc b/proto/Doc index 7863472f..48f754ce 100644 --- a/proto/Doc +++ b/proto/Doc @@ -3,7 +3,8 @@ C bfd C bgp C ospf C pipe -C rip C radv +C rip +C rpki C static S ../nest/rt-dev.c diff --git a/proto/rpki/Doc b/proto/rpki/Doc new file mode 100644 index 00000000..3ffa7cb0 --- /dev/null +++ b/proto/rpki/Doc @@ -0,0 +1 @@ +C rpki.c diff --git a/proto/rpki/Makefile b/proto/rpki/Makefile new file mode 100644 index 00000000..66da9ad9 --- /dev/null +++ b/proto/rpki/Makefile @@ -0,0 +1,5 @@ +source=rpki.c +root-rel=../../ +dir-name=proto/rpki + +include ../../Rules diff --git a/proto/rpki/config.Y b/proto/rpki/config.Y new file mode 100644 index 00000000..b45e3a1d --- /dev/null +++ b/proto/rpki/config.Y @@ -0,0 +1,48 @@ +/* + * BIRD -- The Resource Public Key Infrastructure (RPKI) to Router Protocol + * + * (c) 2015 CZ.NIC + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +CF_HDR + +#include "proto/rpki/rpki.h" + +CF_DEFINES + +#define RPKI_CFG ((struct rpki_config *) this_proto) + +CF_DECLS + +CF_KEYWORDS(RPKI, CACHE, SERVER, SERVERS) + +CF_GRAMMAR + +CF_ADDTO(proto, rpki_proto) + +rpki_proto_start: proto_start RPKI { + this_proto = proto_config_new(&proto_rpki, $1); + } + ; + +rpki_proto_item: + proto_item + | CACHE SERVER ipa expr { + RPKI_CFG->remote.ip = $3; + RPKI_CFG->remote.port = $4; + } + ; + +rpki_proto_opts: + /* empty */ + | rpki_proto_opts rpki_proto_item ';' + ; + +rpki_proto: + rpki_proto_start proto_name '{' rpki_proto_opts '}' + +CF_CODE + +CF_END diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c new file mode 100644 index 00000000..301769f3 --- /dev/null +++ b/proto/rpki/rpki.c @@ -0,0 +1,93 @@ +/* + * BIRD -- The Resource Public Key Infrastructure (RPKI) to Router Protocol + * + * (c) 2015 CZ.NIC + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +/** + * DOC: The Resource Public Key Infrastructure (RPKI) to Router Protocol + */ + +#define LOCAL_DEBUG + +#include "proto/rpki/rpki.h" + +static struct proto * +rpki_init(struct proto_config *c) +{ + struct proto *p = proto_new(c, sizeof(struct rpki_proto)); + + log(L_DEBUG "------------- rpki_init -------------"); + + /* TODO: Add defaults */ + return p; +} + +static int +rpki_start(struct proto *p) +{ + struct proto_rpki *rpki = (struct proto_rpki *) p; + struct rpki_config *cf = (struct rpki_config *) (p->cf); + + log(L_DEBUG "------------- rpki_start -------------"); + + return PS_UP; +} + +static int +rpki_shutdown(struct proto *p) +{ + struct proto_rpki *rp = (struct proto_rpki *) p; + + log(L_DEBUG "------------- rpki_shutdown -------------"); + + return PS_DOWN; +} + +static int +rpki_reconfigure(struct proto *p, struct proto_config *c) +{ + struct proto_rpki *rpki = (struct proto_rpki *) p; + struct rpki_config *new = (struct rpki_config *) c; + + log(L_DEBUG "------------- rpki_reconfigure -------------"); + + return 1; +} + +static void +rpki_copy_config(struct proto_config *dest, struct proto_config *src) +{ + struct rpki_config *d = (struct rpki_config *) dest; + struct rpki_config *s = (struct rpki_config *) src; + + log(L_DEBUG "------------- rpki_copy_config -------------"); +} + +static void +rpki_get_status(struct proto *p, byte *buf) +{ + struct proto_rpki *rpki = (struct proto_rpki *) p; + + log(L_DEBUG "------------- rpki_get_status -------------"); +} + +struct protocol proto_rpki = { + .name = "RPKI", + .template = "rpki%d", +// .attr_class = EAP_BGP, +// .preference = DEF_PREF_BGP, + .config_size = sizeof(struct rpki_config), + .init = rpki_init, + .start = rpki_start, + .shutdown = rpki_shutdown, +// .cleanup = rpki_cleanup, + .reconfigure = rpki_reconfigure, + .copy_config = rpki_copy_config, + .get_status = rpki_get_status, +// .get_attr = rpki_get_attr, +// .get_route_info = rpki_get_route_info, +// .show_proto_info = rpki_show_proto_info +}; diff --git a/proto/rpki/rpki.h b/proto/rpki/rpki.h new file mode 100644 index 00000000..6e79053a --- /dev/null +++ b/proto/rpki/rpki.h @@ -0,0 +1,30 @@ +/* + * BIRD -- The Resource Public Key Infrastructure (RPKI) to Router Protocol + * + * (c) 2015 CZ.NIC + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#ifndef _BIRD_RPKI_H_ +#define _BIRD_RPKI_H_ + +#include "nest/bird.h" +#include "nest/protocol.h" + +struct cache_server { + ip_addr ip; + u16 port; +}; + +struct rpki_config { + struct proto_config c; + struct cache_server remote; +}; + +struct rpki_proto { + struct proto p; +}; + + +#endif /* _BIRD_RPKI_H_ */ diff --git a/sysdep/autoconf.h.in b/sysdep/autoconf.h.in index a9e46e27..047a49ca 100644 --- a/sysdep/autoconf.h.in +++ b/sysdep/autoconf.h.in @@ -43,6 +43,7 @@ #undef CONFIG_BGP #undef CONFIG_OSPF #undef CONFIG_PIPE +#undef CONFIG_RPKI /* We use multithreading */ #undef USE_PTHREADS