bgpd: Fix bgp_btoa to compile
bgp_btoa was abandoned at some point in time in the past.
This commit gets it to compile and to be added to /usr/bin.
At this point in time no work has done for 'correctness' of execution
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
diff --git a/bgpd/Makefile.am b/bgpd/Makefile.am
index b2614f4..a35ad87 100644
--- a/bgpd/Makefile.am
+++ b/bgpd/Makefile.am
@@ -8,6 +8,7 @@
noinst_LIBRARIES = libbgp.a
sbin_PROGRAMS = bgpd
+bin_PROGRAMS = bgp_btoa
libbgp_a_SOURCES = \
bgpd.c bgp_fsm.c bgp_aspath.c bgp_community.c bgp_attr.c \
@@ -26,6 +27,9 @@
bgpd_SOURCES = bgp_main.c
bgpd_LDADD = libbgp.a ../lib/libzebra.la @LIBCAP@ @LIBM@
+bgp_btoa_SOURCES = bgp_btoa.c
+bgp_btoa_LDADD = libbgp.a ../lib/libzebra.la @LIBCAP@ @LIBM@
+
examplesdir = $(exampledir)
dist_examples_DATA = bgpd.conf.sample bgpd.conf.sample2
diff --git a/bgpd/bgp_btoa.c b/bgpd/bgp_btoa.c
index 7c70881..edc80b2 100644
--- a/bgpd/bgp_btoa.c
+++ b/bgpd/bgp_btoa.c
@@ -25,12 +25,36 @@
#include "log.h"
#include "prefix.h"
#include "command.h"
+#include "memory.h"
+#include "privs.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_dump.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_aspath.h"
+/* privileges */
+static zebra_capabilities_t _caps_p [] =
+{
+ ZCAP_BIND,
+ ZCAP_NET_RAW,
+ ZCAP_NET_ADMIN,
+};
+
+struct zebra_privs_t bgpd_privs =
+{
+#if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
+ .user = QUAGGA_USER,
+ .group = QUAGGA_GROUP,
+#endif
+#ifdef VTY_GROUP
+ .vty_group = VTY_GROUP,
+#endif
+ .caps_p = _caps_p,
+ .cap_num_p = array_size(_caps_p),
+ .cap_num_i = 0,
+};
+
enum MRT_MSG_TYPES {
MSG_NULL,
MSG_START, /* sender is starting up */
@@ -47,7 +71,7 @@
MSG_TABLE_DUMP /* routing table dump */
};
-int
+static int
attr_parse (struct stream *s, u_int16_t len)
{
u_int flag;
@@ -57,14 +81,14 @@
lim = s->getp + len;
- printf ("attr_parse s->getp %d, len %d, lim %d\n", s->getp, len, lim);
+ printf ("attr_parse s->getp %zd, len %d, lim %d\n", s->getp, len, lim);
while (s->getp < lim)
{
flag = stream_getc (s);
type = stream_getc (s);
- if (flag & ATTR_FLAG_EXTLEN)
+ if (flag & BGP_ATTR_FLAG_EXTLEN)
length = stream_getw (s);
else
length = stream_getc (s);
@@ -84,27 +108,22 @@
break;
case BGP_ATTR_AS_PATH:
{
- struct aspath aspath;
+ struct aspath *aspath;
- aspath.data = (s->data + s->getp);
- aspath.length = length;
- aspath.str = aspath_make_str_count (&aspath);
- printf ("ASPATH: %s\n", aspath.str);
- free (aspath.str);
-
- stream_forward (s, length);
+ aspath = aspath_parse (s, length, 1);
+ printf ("ASPATH: %s\n", aspath->str);
+ aspath_free(aspath);
}
break;
- case BGP_ATTR_NEXT_HOP:
+ case BGP_ATTR_NEXT_HOP:
{
struct in_addr nexthop;
nexthop.s_addr = stream_get_ipv4 (s);
printf ("NEXTHOP: %s\n", inet_ntoa (nexthop));
- /* stream_forward (s, length); */
}
break;
default:
- stream_forward (s, length);
+ stream_getw_from (s, length);
break;
}
}
@@ -121,7 +140,7 @@
time_t now;
int type;
int subtype;
- int len;
+ size_t len;
int source_as;
int dest_as;
int ifindex;
@@ -150,7 +169,7 @@
stream_reset (s);
ret = fread (s->data, 12, 1, fp);
- if (feof (fp))
+ if (!ret || feof (fp))
{
printf ("END OF FILE\n");
break;
@@ -213,7 +232,7 @@
}
}
- printf ("len: %d\n", len);
+ printf ("len: %zd\n", len);
ret = fread (s->data + 12, len, 1, fp);
if (feof (fp))