1. ripencc
  2. bgpdump

Commits

ruben  committed 84bef66

IS-136/IS-138/IS-149

* Fixed a case where during -M dumps aspaths where printed for entries that
did not have their BGP_ATTR_AS_PATH flag set. Such entries will now print
an empty field.
* Changed -fpic to -fPIC: newer gccs coerce -fpic to -fPIC any way.
difference is that with -fpic the global offset table has a maximum size
* Fixed nit in getopt handling
* Added distclean target

  • Participants
  • Parent commits 734909e
  • Branches default

Comments (0)

Files changed (6)

File ChangeLog

View file
 
 You can reach us at ris@ripe.net.
 
+2009-07-22 Ruben van Staveren <ruben@ripe.net>
+	* Fixed a case where during -M dumps aspaths where printed for entries that
+	  did not have their BGP_ATTR_AS_PATH flag set. Such entries will now print
+	  an empty field.
+	* Changed -fpic to -fPIC: newer gccs coerce -fpic to -fPIC any way.
+	  difference is that with -fpic the global offset table has a maximum size
+	* Fixed nit in getopt handling
+	* Added distclean target
+
 2008-02-01 Erik Romijn <eromijn@ripe.net>
 	* Fixed a few memleaks based on a patch from
 	  Antony Antony <antony@phenome.org>

File Makefile.in

View file
 all: libbgpdump.so libbgpdump.a testbgpdump bgpdump 
 
 libbgpdump.so: $(LIB_H) $(LIB_C) Makefile
-	$(COMPILE) -fpic -c $(LIB_C)
+	$(COMPILE) -fPIC -c $(LIB_C)
 	$(COMPILE) $(LDFLAGS) -o libbgpdump.so $(LIB_O) $(SYS_LIBS)
 
 libbgpdump.a: $(LIB_H) $(LIB_C) $(LIB_O) Makefile
 
 clean:
 	rm -f libbgpdump.so libbgpdump.a testbgpdump bgpdump *.o 
+
+distclean: clean
+	rm -rf config.log config.status *.dSYM core *.core autom4te.cache bgpdump-config.h Makefile

File VERSION

View file
-libbgpdump-1.4.99.8
+libbgpdump-1.4.99.9

File bgpdump.c

View file
 	default:
 		break;
 	}
+	argc -= optind;
+	argv += optind;
     
-    if(argc>1) {
-	my_dump=bgpdump_open_dump(argv[optind]);
+    if(argc>=1 && argv[0] != NULL) {
+	my_dump=bgpdump_open_dump(argv[0]);
     } else {
 	my_dump=bgpdump_open_dump("dumps/updates.20020701.0032");
     }
 				printf("BGP4MP|%ld|A|%s|%s|",entry->time,inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),print_asn(entry->body.zebra_message.source_as));
 				break;
 			}
-			printf("%s/%d|%s|%s|",inet_ntoa(prefix[index].address.v4_addr),prefix[index].len,entry->attr->aspath->str,tmp1);
+			printf("%s/%d|%s|%s|",inet_ntoa(prefix[index].address.v4_addr),prefix[index].len,ATTR_ASPATH(entry->attr),tmp1);
 		    npref=entry->attr->local_pref;
 	            if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
 	            npref=0;
 				printf("BGP4MP|%s|A|%s|%s|",time_str,inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),print_asn(entry->body.zebra_message.source_as));
 				break;
 			}
-			printf("%s/%d|%s|%s\n",inet_ntoa(prefix[index].address.v4_addr),prefix[index].len,entry->attr->aspath->str,tmp1);
+			printf("%s/%d|%s|%s\n",inet_ntoa(prefix[index].address.v4_addr),prefix[index].len,ATTR_ASPATH(entry->attr),tmp1);
 				
 		}
 	}
 					printf("BGP4MP|%ld|A|%s|%s|",entry->time,inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),print_asn(entry->body.zebra_message.source_as));
 					break;
 				}
-				printf("%s/%d|%s|%s|",inet_ntoa(prefix->nlri[index].address.v4_addr),prefix->nlri[index].len,entry->attr->aspath->str,tmp1);
+				printf("%s/%d|%s|%s|",inet_ntoa(prefix->nlri[index].address.v4_addr),prefix->nlri[index].len,ATTR_ASPATH(entry->attr),tmp1);
 
 		    npref=entry->attr->local_pref;
 	            if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
 					printf("BGP4MP|%ld|A|%s|%s|",entry->time,inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),print_asn(entry->body.zebra_message.source_as));
 					break;
 				}
-				printf("%s/%d|%s|%s|",inet_ntoa(prefix->nlri[index].address.v4_addr),prefix->nlri[index].len,entry->attr->aspath->str,tmp1);
+				printf("%s/%d|%s|%s|",inet_ntoa(prefix->nlri[index].address.v4_addr),prefix->nlri[index].len,ATTR_ASPATH(entry->attr),tmp1);
 
 		    npref=entry->attr->local_pref;
 	            if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
 				printf("BGP4MP|%s|A|%s|%s|",time_str,inet_ntoa(entry->body.zebra_message.source_ip.v4_addr),print_asn(entry->body.zebra_message.source_as));
 				break;
 			}
-			printf("%s/%d|%s|%s\n",inet_ntoa(prefix->nlri[index].address.v4_addr),prefix->nlri[index].len,entry->attr->aspath->str,tmp1);
+			printf("%s/%d|%s|%s\n",inet_ntoa(prefix->nlri[index].address.v4_addr),prefix->nlri[index].len,ATTR_ASPATH(entry->attr),tmp1);
 				
 		}
 	}
 	            if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ) ==0)
 	            nmed=0;
 			    
-				printf("BGP4MP|%ld|A|%s|%s|%s/%d|%s|%s|%s|%d|%d|",entry->time,inet_ntop(AF_INET6,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf2,128),prefix->nlri[index].len,entry->attr->aspath->str,tmp1,inet_ntop(AF_INET6,&prefix->nexthop,buf,128),npref,nmed);
+				printf("BGP4MP|%ld|A|%s|%s|%s/%d|%s|%s|%s|%d|%d|",entry->time,inet_ntop(AF_INET6,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf2,128),prefix->nlri[index].len,ATTR_ASPATH(entry->attr),tmp1,inet_ntop(AF_INET6,&prefix->nexthop,buf,128),npref,nmed);
 				break;
 			case AFI_IP:
 			default:
 	            nmed=0;
 			    
 			//printf("%s|%d|%d|",inet_ntoa(entry->attr->nexthop),nprof,nmed);
-				printf("BGP4MP|%ld|A|%s|%s|%s/%d|%s|%s|%s|%d|%d|",entry->time,inet_ntop(AF_INET,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf2,128),prefix->nlri[index].len,entry->attr->aspath->str,tmp1,inet_ntop(AF_INET6,&prefix->nexthop,buf,128),npref,nmed);
+				printf("BGP4MP|%ld|A|%s|%s|%s/%d|%s|%s|%s|%d|%d|",entry->time,inet_ntop(AF_INET,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf2,128),prefix->nlri[index].len,ATTR_ASPATH(entry->attr),tmp1,inet_ntop(AF_INET6,&prefix->nexthop,buf,128),npref,nmed);
 				break;
 			}
 			if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES) ) !=0)	
 			switch(entry->body.zebra_message.address_family)
 			{
 			case AFI_IP6:
-				printf("BGP4MP|%s|A|%s|%s|%s/%d|%s|%s\n",time_str,inet_ntop(AF_INET6,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf,128),prefix->nlri[index].len,entry->attr->aspath->str,tmp1);
+				printf("BGP4MP|%s|A|%s|%s|%s/%d|%s|%s\n",time_str,inet_ntop(AF_INET6,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf,128),prefix->nlri[index].len,ATTR_ASPATH(entry->attr),tmp1);
 				break;
 			case AFI_IP:
 			default:
-				printf("BGP4MP|%s|A|%s|%s|%s/%d|%s|%s\n",time_str,inet_ntop(AF_INET,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf,128),prefix->nlri[index].len,entry->attr->aspath->str,tmp1);
+				printf("BGP4MP|%s|A|%s|%s|%s/%d|%s|%s\n",time_str,inet_ntop(AF_INET,&entry->body.zebra_message.source_ip,buf1,128),print_asn(entry->body.zebra_message.source_as),inet_ntop(AF_INET6,&prefix->nlri[index].address.v6_addr,buf,128),prefix->nlri[index].len,ATTR_ASPATH(entry->attr),tmp1);
 				break;
 			}
 		}		
 		   }else if(timetype==1){
 	   	   printf("TABLE_DUMP|%ld|B|%s|%s|",route->uptime,peer,print_asn(route->peer_as));
 		   }
-	      	   printf("%s/%d|%s|%s|",prefix,route->mask,entry->attr->aspath->str,tmp1);
+	      	   printf("%s/%d|%s|%s|",prefix,route->mask,ATTR_ASPATH(entry->attr),tmp1);
 
 		    npref=entry->attr->local_pref;
 	            if( (entry->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF) ) ==0)
 		    }
 	            time2str(time,time_str);	
 	 	    printf("TABLE_DUMP|%s|A|%s|%s|",time_str,peer,print_asn(route->peer_as));
-			printf("%s/%d|%s|%s\n",prefix,route->mask,entry->attr->aspath->str,tmp1);
+			printf("%s/%d|%s|%s\n",prefix,route->mask,ATTR_ASPATH(entry->attr),tmp1);
 				
 		}
 

File bgpdump.h

View file
 
 #define AS_TRAN 23456
 
+/* If no aspath was present as a string in the packet, return an empty string
+ * so everything stays machine parsable */
+#define ATTR_ASPATH(a) ( ((a->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)) != 0 ) && a->aspath && a->aspath->str ? a->aspath->str : "") 
+
 #endif

File bgpdump_lib.c

View file
 AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 */
 
-/* 
+/*
 
 Parts of this code have been engineered after analiyzing GNU Zebra's
 source code and therefore might contain declarations/code from GNU
 static    int process_mrtd_table_dump_v2_ipv6_unicast(struct mstream *s,BGPDUMP_ENTRY *entry);
 static    int process_zebra_bgp(struct mstream *s,BGPDUMP_ENTRY *entry);
 static    int process_zebra_bgp_state_change(struct mstream *s,BGPDUMP_ENTRY *entry, u_int8_t asn_len);
-    
+
 static    int process_zebra_bgp_message(struct mstream *s,BGPDUMP_ENTRY *entry, u_int8_t asn_len);
 static    int process_zebra_bgp_message_update(struct mstream *s,BGPDUMP_ENTRY *entry, u_int8_t asn_len);
 static    int process_zebra_bgp_message_open(struct mstream *s,BGPDUMP_ENTRY *entry, u_int8_t asn_len);
     {
 	strcpy(this_dump->filename, filename);
     }
-    
+
     if(f == NULL) {
 	free(this_dump);
 	return NULL;
     }
-    
+
     this_dump->f = f;
     this_dump->eof=0;
     this_dump->parsed = 0;
 
 void bgpdump_close_dump(BGPDUMP *dump) {
     if(dump!=NULL) {
-	
+
     	if(table_dump_v2_peer_index_table){
 		if(table_dump_v2_peer_index_table->entries) {
 			free(table_dump_v2_peer_index_table->entries);
 }
 
 BGPDUMP_ENTRY*	bgpdump_read_next(BGPDUMP *dump) {
-    BGPDUMP_ENTRY *this_entry=NULL;    
+    BGPDUMP_ENTRY *this_entry=NULL;
     struct mstream s;
     u_char *buffer;
     int ok=0;
 	}
 	/* Nothing more to read, quit */
 	free(this_entry);
-	dump->eof=1; 
+	dump->eof=1;
 	return(NULL);
     }
 
 
     buffer = malloc(this_entry->length);
     bytes_read = cfr_read_n(dump->f, buffer, this_entry->length);
-    if(bytes_read != this_entry->length) { 
+    if(bytes_read != this_entry->length) {
 	syslog(LOG_ERR,
 	       "bgpdump_read_next: incomplete dump record (%d bytes read, expecting %d)",
 	       bytes_read, this_entry->length);
-	free(this_entry); 
+	free(this_entry);
 	free(buffer);
 	dump->eof=1;
 	return(NULL);
     }
-        
+
 
     ok=0;
     mstream_init(&s,buffer,this_entry->length);
 
     switch(this_entry->type) {
-	case BGPDUMP_TYPE_MRTD_BGP:		
+	case BGPDUMP_TYPE_MRTD_BGP:
 		break;
-	case BGPDUMP_TYPE_MRTD_TABLE_DUMP:	
-		ok = process_mrtd_table_dump(&s,this_entry); 
+	case BGPDUMP_TYPE_MRTD_TABLE_DUMP:
+		ok = process_mrtd_table_dump(&s,this_entry);
 		break;
 	case BGPDUMP_TYPE_ZEBRA_BGP:
-		ok = process_zebra_bgp(&s,this_entry); 
+		ok = process_zebra_bgp(&s,this_entry);
 		break;
 	case BGPDUMP_TYPE_TABLE_DUMP_V2:
-		ok = process_mrtd_table_dump_v2(&s,this_entry); 
+		ok = process_mrtd_table_dump_v2(&s,this_entry);
 		break;
     }
-	
+
     free(buffer);
     if(ok) {
 	dump->parsed_ok++;
 		free(path);
 	      }
 	    }
-	    
+
 	    if(attr->community != NULL) {
 		if(attr->community->val != NULL)
 		    free(attr->community->val);
 }
 
 
-int 
+int
 process_zebra_bgp_state_change(struct mstream *s,BGPDUMP_ENTRY *entry, u_int8_t asn_len) {
     read_asn(s, &entry->body.zebra_state_change.source_as, asn_len);
     read_asn(s, &entry->body.zebra_state_change.destination_as, asn_len);
 	    }
 	    /* Note fall through! If we don't recognize this type of data corruption, we say
 	     * the address family is unsupported (since FFFF is not a valid address family) */
-	default:			
+	default:
 	    /* unsupported address family */
 	    syslog(LOG_WARNING, "process_zebra_bgp_message: unsupported AFI %d",
 		   entry->body.zebra_message.address_family);
 
     if(memcmp(marker, "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377", 16) != 0) {
 	/* bad marker... ignore packet */
-	syslog(LOG_WARNING, 
+	syslog(LOG_WARNING,
 	       "bgp_message: bad marker: %02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x",
 	       marker[0],marker[1],marker[2],marker[3],marker[4],marker[5],marker[6],marker[7],
 	       marker[8],marker[9],marker[10],marker[11],marker[12],marker[13],marker[14],marker[15]);
     mstream_getc (s,&entry->body.zebra_message.type);
 
     entry->body.zebra_message.cut_bytes = entry->body.zebra_message.size - 19 - mstream_can_read(s);
-    
-    switch(entry->body.zebra_message.type) {    
+
+    switch(entry->body.zebra_message.type) {
 	case BGP_MSG_OPEN:
 	    return process_zebra_bgp_message_open(s,entry, asn_len);
 	case BGP_MSG_UPDATE:
 void process_attr_init(BGPDUMP_ENTRY *entry) {
 
     entry->attr = malloc(sizeof(struct attr));
-    
+
     entry->attr->flag			= 0;
     entry->attr->origin			= -1;
     entry->attr->nexthop.s_addr		= -1;
     entry->attr->community		= NULL;
     entry->attr->transit		= NULL;
 
-    entry->attr->mp_info		= NULL;    
+    entry->attr->mp_info		= NULL;
     entry->attr->len			= 0;
     entry->attr->data			= NULL;
 
     u_int32_t	len, end;
     u_int32_t	truelen;
     struct unknown_attr *unknown;
-    
+
     mstream_getw(s, &attr->len);
     if(attr->len == 0)
       return;
     memcpy(attr->data, &s->start[s->position], truelen);
 
     end = s->position + truelen;
-    
+
     while(s->position < end) {
 	mstream_getc(s,&flag);
 	mstream_getc(s,&type);
-	
-	if(flag & BGP_ATTR_FLAG_EXTLEN) 
+
+	if(flag & BGP_ATTR_FLAG_EXTLEN)
 	    len=mstream_getw(s,NULL);
 	else
 	    len=mstream_getc(s,NULL);
-	
+
 	/* Take note of all attributes, including unknown ones */
 	if(type <= sizeof(attr->flag) * 8)
 	  attr->flag = attr->flag | ATTR_FLAG_BIT (type);
 	switch(type) {
 	    case BGP_ATTR_ORIGIN:
 		mstream_getc(s,&attr->origin);
-		break;	    
+		break;
 	    case BGP_ATTR_AS_PATH:
 		attr->aspath = create_aspath(len, asn_len);
 		mstream_get(s,attr->aspath->data,len);
       assegment = (struct assegment *) pnt;
 
       /* Check AS type validity. */
-      if ((assegment->type != AS_SET) && 
+      if ((assegment->type != AS_SET) &&
 	  (assegment->type != AS_SEQUENCE) &&
-	  (assegment->type != AS_CONFED_SET) && 
+	  (assegment->type != AS_CONFED_SET) &&
 	  (assegment->type != AS_CONFED_SEQUENCE))
 	{
 	  free(str_buf);
         default:
           estimate_len = ((assegment->length * 12) + 4);
       }
-      
+
       /* String length check. */
       while (str_pnt + estimate_len >= str_size)
 	{
 
   memset (buf, 0, BUFSIZ);
 
-  for (i = 0; i < com->size; i++) 
+  for (i = 0; i < com->size; i++)
     {
       memcpy (&comval, com_nthval (com, i), sizeof (u_int32_t));
       comval = ntohl (comval);
-      switch (comval) 
+      switch (comval)
 	{
 	case COMMUNITY_NO_EXPORT:
 	  strlcat (buf, " no-export", BUFSIZ);
 	default:
 	  as = (comval >> 16) & 0xFFFF;
 	  val = comval & 0xFFFF;
-	  snprintf (buf + strlen (buf), BUFSIZ - strlen (buf), 
+	  snprintf (buf + strlen (buf), BUFSIZ - strlen (buf),
 		    " %d:%d", as, val);
 	  break;
 	}
      presentation format for 32-bit ASNs will be. If in the end it turns out to
      be a 32-bit integer, it can simply be removed. */
 	static char asn_str[strlen("65535.65535") + 1];
-	//if(asn >> 16) {
-	//	sprintf(asn_str, "%d.%d", (asn >> 16) & 0xFFFF, asn & 0xFFFF);
-	//} else {
-		sprintf(asn_str, "%d", asn);
-	//}
+	sprintf(asn_str, "%d", asn);
 	return asn_str;
 }