Browse Source

Merge upstream version 1.6.1

Christoph Biedl 6 months ago
parent
commit
af72f322c2
11 changed files with 162 additions and 61 deletions
  1. 21 0
      .gitignore
  2. 0 4
      .hg_archival.txt
  3. 0 11
      .hgtags
  4. 15 0
      ChangeLog
  5. 10 7
      Makefile.in
  6. 2 2
      README
  7. 71 21
      bgpdump.c
  8. 6 2
      bgpdump.spec.in
  9. 13 12
      bgpdump_lib.c
  10. 6 2
      configure.in
  11. 18 0
      test.sh

+ 21 - 0
.gitignore

@@ -0,0 +1,21 @@
+*.o
+*.pbxuser
+*.mode1v3
+*.swp
+bgpdump-config.h
+bgpdump-config.h.in
+config.log
+config.status
+configure
+bgpdump
+testbgpdump
+libbgpdump.a
+libbgpdump.so
+Makefile
+test_out/*
+build/
+bgpdump.spec
+~$
+libbgpdump-.*\.tgz
+autom4te.cache/
+.DS_Store

+ 0 - 4
.hg_archival.txt

@@ -1,4 +0,0 @@
-repo: fc85b5d83c23266299237988401380dcb3d3c4f3
-node: 6be858c0cc9e14607c6bb1dd6015df536dd642c5
-branch: default
-tag: 1.6.0

+ 0 - 11
.hgtags

@@ -1,11 +0,0 @@
-6271706a4a0e495b2cc5e48822d0d73abfc55807 1.4.98.7
-e9617d1b0fa959ad3436797701d027958b335667 1.4.99.8
-aeead79922f7eeac5d8e678b43101deef02cf847 1.4.99.9
-397bfe76c57fe46694ac06735843575683c772e6 1.4.99.10
-4cce25d5026009a1ba2924afa8b10907ecf4498e 1.4.99.11
-9fe2f50927688e4560941e655b3c970c4b668540 1.4.99.12
-b8e3ed2b370ca220f46bfa59193665dfdee5d5ef 1.4.99.13
-c4c53146f09af40a0068992d67a345a05ac54514 1.4.99.14
-d8e8bcf60eb4c7ce065b2744d6a32003c728d8b2 1.4.99.15
-601292759e414fd15a59332928956012b3dc3ddb 1.5.00.00
-a8ca3180d6d46836b4d4f3f66696b7ed1f7884ee 1.5.0

+ 15 - 0
ChangeLog

@@ -8,6 +8,21 @@ PLEASE DO NOT E-MAIL INDIVIDUAL DEVELOPERS ABOUT
 ISSUES, AS YOUR E-MAIL MAY BE LOST
 ==========================================================
 
+2020-04-27 Colin Petrie <colin@spakka.net> v1.6.1
+	* Version bump for Github release/tag migration
+
+2019-04-28 Robert Scheck <robert@fedoraproject.org>
+	* Use $(DESTDIR), $(INSTALL) and $(LDFLAGS) for downstreams
+	* Correct permissions for installed header files (*.h)
+
+2019-03-06 Kevin White <bitbucket-kevin@kevbo.org>
+	* Update Makefile.in to use $(DESTDIR) in the install stanza
+	* Transistion spec file to use %make_install, rather than %makeinstall
+	* Update spec file to move the static library to the -devel package
+
+2019-02-09 Italo Cunha <cunha@dcc.ufmg.br>
+	* Add '-u' flag to print unknown attributes in oneline (-m) mode
+
 2018-09-26 Colin Petrie <cpetrie@ripe.net> v1.6.0
 	* Fix overflow for large records
 	* Add basic '-q' quiet mode

+ 10 - 7
Makefile.in

@@ -5,10 +5,13 @@ COMPILE  = $(CC) $(CFLAGS) $(INCLUDES)
 
 LD	= @CC@
 LDFLAGS	= @LDFLAGS@
+SOFLAGS = @SOFLAGS@
 RANLIB	= @RANLIB@
 
 SYS_LIBS= @LIBS@
 
+INSTALL  = install
+
 prefix   = @prefix@
 exec_prefix = @exec_prefix@
 bindir   = @bindir@
@@ -26,13 +29,13 @@ libbgpdump.a: $(LIB_H) $(LIB_O) Makefile cfile_tools.h util.h
 	$(RANLIB) libbgpdump.a
 
 libbgpdump.so: libbgpdump.a
-	$(COMPILE) $(LDFLAGS) -o libbgpdump.so $(LIB_O) $(SYS_LIBS)
+	$(COMPILE) $(LDFLAGS) $(SOFLAGS) -o libbgpdump.so $(LIB_O) $(SYS_LIBS)
 
 example: example.c libbgpdump.a
-	$(COMPILE) -o example example.c libbgpdump.a $(SYS_LIBS)
+	$(COMPILE) $(LDFLAGS) -o example example.c libbgpdump.a $(SYS_LIBS)
 
 bgpdump: bgpdump.c libbgpdump.a
-	$(COMPILE) -o bgpdump bgpdump.c libbgpdump.a $(SYS_LIBS)
+	$(COMPILE) $(LDFLAGS) -o bgpdump bgpdump.c libbgpdump.a $(SYS_LIBS)
 
 check-clean:
 	rm -f test_out/*.bgp.gz
@@ -48,10 +51,10 @@ distclean: clean
 	rm -Rf $(PKG)
 
 install: all
-	install -d $(bindir) $(includedir) $(libdir)
-	install bgpdump $(bindir)
-	install $(LIB_H) $(includedir)
-	install libbgpdump.so libbgpdump.a $(libdir)
+	$(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(includedir) $(DESTDIR)$(libdir)
+	$(INSTALL) bgpdump $(DESTDIR)$(bindir)
+	$(INSTALL) -m 0644 $(LIB_H) $(DESTDIR)$(includedir)
+	$(INSTALL) libbgpdump.so libbgpdump.a $(DESTDIR)$(libdir)
 
 PKG=@PACKAGE_NAME@-@PACKAGE_VERSION@
 dist:

+ 2 - 2
README

@@ -1,8 +1,8 @@
 == libBGPdump ==
 
 A C library designed to help with analyzing dump
-files produced by Zebra/Quagga or MRT. Documenation
+files produced by Zebra/Quagga or MRT. Documentation
 is available at:
 
-https://bitbucket.org/ripencc/bgpdump/wiki/Home
+https://github.com/RIPE-NCC/bgpdump/wiki
 

+ 71 - 21
bgpdump.c

@@ -143,10 +143,27 @@ static const char* get_bgp_state_name(u_int16_t state) {
     }
 }
 
+/* Check if -u (compact attributes) is enabled and append a field
+ * to the output to show any unknown attributes. */
+static void append_compact_unknown_attributes(attributes_t *attr) {
+	for(int i = 0; i < attr->unknown_num; i++) {
+		struct unknown_attr *ua = &(attr->unknown[i]);
+		printf("%02x:%02x:", ua->type, ua->flag);
+		for(size_t s = 0; s < ua->len; s++) {
+			printf("%02x", (uint8_t)(ua->raw[s]));
+		}
+		if(i < attr->unknown_num - 1) {
+			printf(" ");
+		}
+	}
+	printf("|");
+}
+
 static int mode=0;
 static int timetype=0;
 static int show_packet_index = 0;
 static int show_large_comms = 0;
+static int show_unknown_attributes = 0;
 static int packet_index = 0;
 
 static const char USAGE[] = "\
@@ -170,6 +187,7 @@ Options for -m and -M modes:\n\
     -t change  timestamps for RIB dumps reflect the last route modification\n\
     -p         show packet index at second position\n\
     -l         show large communities field after regular communities\n\
+    -u         show unassigned attributes in one-line mode\n\
 \n\
 Special options:\n\
     -T         run unit tests and exit\n\
@@ -188,7 +206,7 @@ int main(int argc, char *argv[]) {
  
     log_to_stderr();
     
-    while ((c=getopt(argc,argv,"if:o:t:mMHO:svTplq"))!=-1)
+    while ((c=getopt(argc,argv,"if:o:t:mMHO:svTplqu"))!=-1)
 	switch(c)
 	{
        case 'H':
@@ -239,6 +257,9 @@ int main(int argc, char *argv[]) {
         case 'l':
                 show_large_comms = 1;
                 break;
+        case 'u':
+                show_unknown_attributes = 1;
+                break;
         case 'q':
                 quiet = true;
                 break;
@@ -1562,10 +1583,15 @@ static void table_line_announce(struct prefix *prefix,int count,BGPDUMP_ENTRY *e
 
 		    printf("%s|", aggregate); /* AG/NAG */
 
-			if (entry->attr->aggregator_addr.s_addr != -1)
-				printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
-			else
-				printf("|\n");
+			if (entry->attr->aggregator_addr.s_addr != -1) {
+				printf("%u %s",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
+			}
+			printf("|");
+
+			if (show_unknown_attributes) {
+				append_compact_unknown_attributes(entry->attr);
+			}
+			printf("\n");
 		}
 		else
 		{
@@ -1716,10 +1742,16 @@ static void table_line_announce_1(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY
                 printf("%s|",aggregate); /* AG/NAG */
 
 			}
-			if (entry->attr->aggregator_addr.s_addr != -1)
-				printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
-			else
-				printf("|\n");
+			if (entry->attr->aggregator_addr.s_addr != -1) {
+				printf("%u %s",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
+			}
+			printf("|");
+
+			if (show_unknown_attributes) {
+				append_compact_unknown_attributes(entry->attr);
+			}
+
+			printf("\n");
 		}
 		else
 		{
@@ -1829,11 +1861,16 @@ static void table_line_announce6(struct mp_nlri *prefix,int count,BGPDUMP_ENTRY
             printf("%s|", aggregate); /* AG/NAG */
 
 
-			if (entry->attr->aggregator_addr.s_addr != -1)
-				printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
-			else
-				printf("|\n");
+			if (entry->attr->aggregator_addr.s_addr != -1) {
+				printf("%u %s",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
+			}
+			printf("|");
+
+			if (show_unknown_attributes) {
+				append_compact_unknown_attributes(entry->attr);
+			}
 
+			printf("\n");
 		}
 		else
 		{
@@ -1946,17 +1983,25 @@ static void table_line_mrtd_route(BGPDUMP_MRTD_TABLE_DUMP *route,BGPDUMP_ENTRY *
 
             printf("%s|",aggregate); /* AG/NAG */
 				
-			if (entry->attr->aggregator_addr.s_addr != -1)
-				printf("%u %s|\n",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
-			else
-				printf("|\n");
+            if (entry->attr->aggregator_addr.s_addr != -1) {
+                printf("%u %s",entry->attr->aggregator_as,inet_ntoa(entry->attr->aggregator_addr));
+            }
+            printf("|");
+
+            if (show_unknown_attributes) {
+                append_compact_unknown_attributes(entry->attr);
+            }
+            printf("\n");
+
 		}
+
 		else
 		{
 	 	    printf("%s|%u|",peer,route->peer_as);
                     printf("%s/%d|%s|%s\n",prefix,route->mask,attr_aspath(entry->attr),describe_origin(entry->attr->origin));
 		}
 
+
 }
 
 static char *describe_origin(int origin) {
@@ -2072,10 +2117,15 @@ static void table_line_dump_v2_prefix(BGPDUMP_TABLE_DUMP_V2_PREFIX *e,BGPDUMP_EN
             
             printf("%s|",aggregate);
 
-            if (attr->aggregator_addr.s_addr != -1)
-                printf("%u %s|\n",attr->aggregator_as,inet_ntoa(attr->aggregator_addr));
-            else
-                printf("|\n");
+            if (attr->aggregator_addr.s_addr != -1) {
+                printf("%u %s",attr->aggregator_as,inet_ntoa(attr->aggregator_addr));
+            }
+            printf("|");
+
+            if (show_unknown_attributes) {
+                append_compact_unknown_attributes(attr);
+            }
+            printf("\n");
         }
         else
         {

+ 6 - 2
bgpdump.spec.in

@@ -36,7 +36,7 @@ make CFLAGS="$RPM_OPT_FLAGS"
 
 %install
 rm -rf %{buildroot}
-%makeinstall
+%make_install
 
 %clean
 rm -rf %{buildroot}
@@ -45,16 +45,20 @@ rm -rf %{buildroot}
 %defattr(0755,root,root)
 %{_bindir}/bgpdump
 %defattr(-,root,root)
-%{_libdir}/libbgpdump.a
 %{_libdir}/libbgpdump.so
 
 %files devel
 %defattr(-,root,root)
+%{_libdir}/libbgpdump.a
 %{_includedir}/bgpdump_attr.h
 %{_includedir}/bgpdump_formats.h
 %{_includedir}/bgpdump_lib.h
 %{_includedir}/bgpdump_mstream.h
 
 %changelog
+* Wed Mar 06 2019 Kevin White <bitbucket-kevin@kevbo.org> 1.6.0-1
+- use make_install (after updating Makefile to support DESTDIR).
+- Move static lib to -devel
+
 * Wed Jul 04 2008 Erik Romijn <eromijn@ripe.net> 1.4.99.9-1
 - Initial release

+ 13 - 12
bgpdump_lib.c

@@ -78,7 +78,7 @@ static    void process_asn32_trans(attributes_t *attr, u_int8_t asn_len);
 static    struct aspath *asn32_merge_paths(struct aspath *path, struct aspath *newpath);
 static    void asn32_expand_16_to_32(char *dst, char *src, int len);
 
-#if defined(linux)
+#ifndef HAVE_STRLCAT
 static    size_t strlcat(char *dst, const char *src, size_t size);
 #endif
 
@@ -259,18 +259,19 @@ static void bgpdump_free_mp_info(struct mp_info *info) {
     u_int8_t safi;
 
     for(afi = 1; afi <= BGPDUMP_MAX_AFI; afi++) {
-	for(safi = 1; safi <= BGPDUMP_MAX_SAFI; safi++) {
-	    if(info->announce[afi][safi])
-		free(info->announce[afi][safi]);
-		info->announce[afi][safi] = NULL;
-	    if(info->withdraw[afi][safi]) {
-		free(info->withdraw[afi][safi]);
-		info->withdraw[afi][safi] = NULL;
-	    }
-	}
+    for(safi = 1; safi <= BGPDUMP_MAX_SAFI; safi++) {
+        if(info->announce[afi][safi]) {
+            free(info->announce[afi][safi]);
+            info->announce[afi][safi] = NULL;
+        }
+        if(info->withdraw[afi][safi]) {
+            free(info->withdraw[afi][safi]);
+            info->withdraw[afi][safi] = NULL;
+        }
+    }
     }
 
-	free(info);
+    free(info);
 }
 
 void bgpdump_free_mem(BGPDUMP_ENTRY *entry) {
@@ -1748,7 +1749,7 @@ void asn32_expand_16_to_32(char *dst, char *src, int len) {
   }
 }
 
-#if defined(linux)
+#ifndef HAVE_STRLCAT
 size_t strlcat(char *dst, const char *src, size_t size) {
   if (strlen (dst) + strlen (src) >= size)
     return -1;

+ 6 - 2
configure.in

@@ -26,16 +26,20 @@ AC_CHECK_TYPE(u_int32_t, , AC_DEFINE(u_int32_t, uint32_t, [Define if system head
 AC_CHECK_LIB(z, gzopen, [], AC_MSG_ERROR([libz not found],1))
 AC_CHECK_LIB(bz2, BZ2_bzReadOpen, [], AC_MSG_ERROR([libbzip2 not found],1))
 
+# check for strlcat, used to not be in Linux but is now appearing in newer glibc
+AC_CHECK_FUNCS([strlcat])
+
 # Check for inet_ntoa in -lnsl if not found (Solaris)
 AC_CHECK_FUNCS(inet_ntoa, [], AC_CHECK_LIB(nsl, inet_ntoa, [], AC_MSG_ERROR([inet_ntoa not found],1)))
 AC_CHECK_FUNCS(inet_ntop, [], AC_CHECK_LIB(nsl, inet_ntop, [], AC_MSG_ERROR([inet_ntop not found],1)))
 
 case `uname` in
-	Darwin*) LDFLAGS="$LDFLAGS -dynamiclib" ;;
-	*)       LDFLAGS="$LDFLAGS -shared" ;;
+	Darwin*) SOFLAGS="$SOFLAGS -dynamiclib" ;;
+	*)       SOFLAGS="$SOFLAGS -shared" ;;
 esac
 
 AC_SUBST(CFLAGS)
 AC_SUBST(LIBS)
+AC_SUBST(SOFLAGS)
 
 AC_OUTPUT([bgpdump.spec Makefile])

+ 18 - 0
test.sh

@@ -17,6 +17,24 @@ for mrt in `ls test_data`; do
     fi
 done
 
+if [ ! -z "$BGPDUMP_TEST_UATTR" ] ; then
+for mrt in $(ls test_data) ; do
+    printf "      testing -u %s..." "$mrt"
+    OUT="$mrt.bgp.gz"
+    # The pipe into sed removes the last field added by -u on table dump
+    # and announcement (update files) lines, and allows us to chekc
+    # everything else is the same without adding new test_expect files
+    # to the repository.
+    ./bgpdump -u -vm test_data/$mrt | sed '/|A\|B|/ s/|[^|]*|$/|/' > test_out/$OUT
+    gzip -cd test_expect/$OUT | diff -q test_out/$OUT -
+    if [ $? = 0 ]; then
+        echo "success"
+    else
+        FAILURES=$(( FAILURES + 1 ))
+    fi
+done
+fi
+
 if [ $FAILURES != 0 ]; then
     echo !!! $FAILURES failures !!!
     exit 1