From 7625a0deea89119a69a8dd37d0c5392fa1c90e5e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 21 Oct 2015 10:00:47 -0400 Subject: [PATCH] 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 --- bgpd/Makefile.am | 4 ++++ bgpd/bgp_btoa.c | 55 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/bgpd/Makefile.am b/bgpd/Makefile.am index 54b26187a7..f6162696d4 100644 --- a/bgpd/Makefile.am +++ b/bgpd/Makefile.am @@ -9,6 +9,7 @@ AM_LDFLAGS = $(PILDFLAGS) 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 \ @@ -29,6 +30,9 @@ noinst_HEADERS = \ 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 7c70881451..edc80b2fe6 100644 --- a/bgpd/bgp_btoa.c +++ b/bgpd/bgp_btoa.c @@ -25,12 +25,36 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #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 @@ enum MRT_MSG_TYPES { 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 @@ attr_parse (struct stream *s, u_int16_t len) 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 @@ attr_parse (struct stream *s, u_int16_t len) break; case BGP_ATTR_AS_PATH: { - 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); + struct aspath *aspath; + + 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 @@ main (int argc, char **argv) time_t now; int type; int subtype; - int len; + size_t len; int source_as; int dest_as; int ifindex; @@ -150,7 +169,7 @@ main (int argc, char **argv) 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 @@ main (int argc, char **argv) } } - printf ("len: %d\n", len); + printf ("len: %zd\n", len); ret = fread (s->data + 12, len, 1, fp); if (feof (fp)) -- 2.39.5