~ubuntu-branches/ubuntu/precise/tcpdump/precise-updates

« back to all changes in this revision

Viewing changes to print-bgp.c

  • Committer: Bazaar Package Importer
  • Author(s): Romain Francoise
  • Date: 2008-03-08 19:24:02 UTC
  • mfrom: (6.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080308192402-9n7erk2yyyd5mpt3
Tags: 3.9.8-4
debian/control: Build-Depend on libpcap0.8-dev (>= 0.9.3),
not (>= 0.9.3-1).

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
#ifndef lint
38
38
static const char rcsid[] _U_ =
39
 
     "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.91.2.9 2006/02/02 12:36:46 hannes Exp $";
 
39
     "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.91.2.12 2007/07/14 22:26:35 guy Exp $";
40
40
#endif
41
41
 
42
42
#include <tcpdump-stdinc.h>
50
50
#include "extract.h"
51
51
#include "bgp.h"
52
52
#include "l2vpn.h"
 
53
#include "af.h"
53
54
 
54
55
struct bgp {
55
56
        u_int8_t bgp_marker[16];
339
340
#define BGP_COMMUNITY_NO_ADVERT                 0xffffff02
340
341
#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED       0xffffff03
341
342
 
342
 
/* RFC1700 address family numbers */
343
 
#define AFNUM_INET      1
344
 
#define AFNUM_INET6     2
345
 
#define AFNUM_NSAP      3
346
 
#define AFNUM_HDLC      4
347
 
#define AFNUM_BBN1822   5
348
 
#define AFNUM_802       6
349
 
#define AFNUM_E163      7
350
 
#define AFNUM_E164      8
351
 
#define AFNUM_F69       9
352
 
#define AFNUM_X121      10
353
 
#define AFNUM_IPX       11
354
 
#define AFNUM_ATALK     12
355
 
#define AFNUM_DECNET    13
356
 
#define AFNUM_BANYAN    14
357
 
#define AFNUM_E164NSAP  15
358
 
#define AFNUM_VPLS      25
359
 
/* draft-kompella-ppvpn-l2vpn */
360
 
#define AFNUM_L2VPN     196 /* still to be approved by IANA */
361
 
 
362
 
static struct tok bgp_afi_values[] = {
363
 
    { 0,                      "Reserved"},
364
 
    { AFNUM_INET,             "IPv4"},
365
 
    { AFNUM_INET6,            "IPv6"},
366
 
    { AFNUM_NSAP,             "NSAP"},
367
 
    { AFNUM_HDLC,             "HDLC"},
368
 
    { AFNUM_BBN1822,          "BBN 1822"},
369
 
    { AFNUM_802,              "802"},
370
 
    { AFNUM_E163,             "E.163"},
371
 
    { AFNUM_E164,             "E.164"},
372
 
    { AFNUM_F69,              "F.69"},
373
 
    { AFNUM_X121,             "X.121"},
374
 
    { AFNUM_IPX,              "Novell IPX"},
375
 
    { AFNUM_ATALK,            "Appletalk"},
376
 
    { AFNUM_DECNET,           "Decnet IV"},
377
 
    { AFNUM_BANYAN,           "Banyan Vines"},
378
 
    { AFNUM_E164NSAP,         "E.164 with NSAP subaddress"},
379
 
    { AFNUM_L2VPN,            "Layer-2 VPN"},
380
 
    { AFNUM_VPLS,             "VPLS"},
381
 
    { 0, NULL},
382
 
};
383
 
 
384
343
/* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
385
344
#define BGP_EXT_COM_RT_0        0x0002  /* Route Target,Format AS(2bytes):AN(4bytes) */
386
345
#define BGP_EXT_COM_RT_1        0x0102  /* Route Target,Format IP address:AN(2bytes) */
650
609
        return -2;
651
610
}
652
611
 
 
612
/*
 
613
 * As I remember, some versions of systems have an snprintf() that
 
614
 * returns -1 if the buffer would have overflowed.  If the return
 
615
 * value is negative, set buflen to 0, to indicate that we've filled
 
616
 * the buffer up.
 
617
 *
 
618
 * If the return value is greater than buflen, that means that
 
619
 * the buffer would have overflowed; again, set buflen to 0 in
 
620
 * that case.
 
621
 */
 
622
#define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
 
623
    if (strlen<0) \
 
624
        buflen=0; \
 
625
    else if ((u_int)strlen>buflen) \
 
626
        buflen=0; \
 
627
    else { \
 
628
        buflen-=strlen; \
 
629
        buf+=strlen; \
 
630
    }
 
631
 
653
632
static int
654
633
decode_labeled_vpn_l2(const u_char *pptr, char *buf, u_int buflen)
655
634
{
660
639
        tlen=plen;
661
640
        pptr+=2;
662
641
        TCHECK2(pptr[0],15);
 
642
        buf[0]='\0';
663
643
        strlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
664
644
                        bgp_vpn_rd_print(pptr),
665
645
                        EXTRACT_16BITS(pptr+8),
666
646
                        EXTRACT_16BITS(pptr+10),
667
647
                        EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
 
648
        UPDATE_BUF_BUFLEN(buf, buflen, strlen);
668
649
        pptr+=15;
669
650
        tlen-=15;
670
651
 
680
661
 
681
662
            switch(tlv_type) {
682
663
            case 1:
683
 
                strlen+=snprintf(buf+strlen,buflen-strlen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
684
 
                                 tlv_type,
685
 
                                 tlv_len);
 
664
                if (buflen!=0) {
 
665
                    strlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
 
666
                                    tlv_type,
 
667
                                    tlv_len);
 
668
                    UPDATE_BUF_BUFLEN(buf, buflen, strlen);
 
669
                }
686
670
                ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
687
671
                while (ttlv_len>0) {
688
672
                    TCHECK(pptr[0]);
689
 
                    strlen+=snprintf(buf+strlen,buflen-strlen, "%02x",*pptr++);
 
673
                    if (buflen!=0) {
 
674
                        strlen=snprintf(buf,buflen, "%02x",*pptr++);
 
675
                        UPDATE_BUF_BUFLEN(buf, buflen, strlen);
 
676
                    }
690
677
                    ttlv_len--;
691
678
                }
692
679
                break;
693
680
            default:
694
 
                snprintf(buf+strlen,buflen-strlen, "\n\t\tunknown TLV #%u, length: %u",
695
 
                         tlv_type,
696
 
                         tlv_len);
 
681
                if (buflen!=0) {
 
682
                    strlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u",
 
683
                                    tlv_type,
 
684
                                    tlv_len);
 
685
                    UPDATE_BUF_BUFLEN(buf, buflen, strlen);
 
686
                }
697
687
                break;
698
688
            }
699
 
            tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it tright */
 
689
            tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */
700
690
        }
701
691
        return plen+2;
702
692
 
1020
1010
                safi = tptr[2];
1021
1011
        
1022
1012
                printf("\n\t    AFI: %s (%u), %sSAFI: %s (%u)",
1023
 
                       tok2strbuf(bgp_afi_values, "Unknown AFI", af,
 
1013
                       tok2strbuf(af_values, "Unknown AFI", af,
1024
1014
                                  tokbuf, sizeof(tokbuf)),
1025
1015
                       af,
1026
1016
                       (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1356
1346
                safi = tptr[2];
1357
1347
 
1358
1348
                printf("\n\t    AFI: %s (%u), %sSAFI: %s (%u)",
1359
 
                       tok2strbuf(bgp_afi_values, "Unknown AFI", af,
 
1349
                       tok2strbuf(af_values, "Unknown AFI", af,
1360
1350
                                  tokbuf, sizeof(tokbuf)),
1361
1351
                       af,
1362
1352
                       (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1548
1538
                                          *(tptr+6),
1549
1539
                                          tokbuf, sizeof(tokbuf)),
1550
1540
                               (*(tptr+7) &  BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
1551
 
                               (*(tptr+6) == (BGP_OSPF_RTYPE_EXT ||BGP_OSPF_RTYPE_NSSA )) ? "E1" : "");
 
1541
                               ((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : "");
1552
1542
                        break;
1553
1543
                    case BGP_EXT_COM_L2INFO:
1554
1544
                        printf(": %s Control Flags [0x%02x]:MTU %u",
1685
1675
                    switch(cap_type) {
1686
1676
                    case BGP_CAPCODE_MP:
1687
1677
                        printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1688
 
                               tok2strbuf(bgp_afi_values, "Unknown",
 
1678
                               tok2strbuf(af_values, "Unknown",
1689
1679
                                          EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2),
1690
1680
                                          tokbuf, sizeof(tokbuf)),
1691
1681
                               EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2),
1702
1692
                        cap_offset=4;
1703
1693
                        while(tcap_len>=4) {
1704
1694
                            printf("\n\t\t  AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1705
 
                                   tok2strbuf(bgp_afi_values,"Unknown",
 
1695
                                   tok2strbuf(af_values,"Unknown",
1706
1696
                                              EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+cap_offset),
1707
1697
                                              tokbuf, sizeof(tokbuf)),
1708
1698
                                   EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+cap_offset),
1916
1906
                tptr = dat + BGP_NOTIFICATION_SIZE;
1917
1907
                TCHECK2(*tptr, 7);
1918
1908
                printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1919
 
                       tok2strbuf(bgp_afi_values, "Unknown",
 
1909
                       tok2strbuf(af_values, "Unknown",
1920
1910
                                  EXTRACT_16BITS(tptr), tokbuf, sizeof(tokbuf)),
1921
1911
                       EXTRACT_16BITS(tptr),
1922
1912
                       tok2strbuf(bgp_safi_values, "Unknown", *(tptr+2),
1950
1940
        bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
1951
1941
 
1952
1942
        printf("\n\t  AFI %s (%u), SAFI %s (%u)",
1953
 
               tok2strbuf(bgp_afi_values,"Unknown",
 
1943
               tok2strbuf(af_values,"Unknown",
1954
1944
                          /* this stinks but the compiler pads the structure
1955
1945
                           * weird */
1956
1946
                          EXTRACT_16BITS(&bgp_route_refresh_header->afi),