@@ -1539,6 +1539,180 @@ check_add_path(netdissect_options *ndo, const u_char *pptr, u_int length,
1539
1539
return 0 ;
1540
1540
}
1541
1541
1542
+ static int
1543
+ bgp_nlri_print (netdissect_options * ndo , uint16_t af , uint8_t safi ,
1544
+ const u_char * tptr , u_int len ,
1545
+ char * buf , size_t buflen ,
1546
+ int add_path4 , int add_path6 )
1547
+ {
1548
+ int advance ;
1549
+ u_int path_id = 0 ;
1550
+
1551
+ switch (af <<8 | safi ) {
1552
+ case (AFNUM_INET <<8 | SAFNUM_UNICAST ):
1553
+ case (AFNUM_INET <<8 | SAFNUM_MULTICAST ):
1554
+ case (AFNUM_INET <<8 | SAFNUM_UNIMULTICAST ):
1555
+ if (add_path4 ) {
1556
+ path_id = GET_BE_U_4 (tptr );
1557
+ tptr += 4 ;
1558
+ }
1559
+ advance = decode_prefix4 (ndo , tptr , len , buf , buflen );
1560
+ if (advance == -1 )
1561
+ ND_PRINT ("\n\t (illegal prefix length)" );
1562
+ else if (advance == -2 )
1563
+ goto trunc ;
1564
+ else if (advance == -3 )
1565
+ break ; /* bytes left, but not enough */
1566
+ else
1567
+ ND_PRINT ("\n\t %s" , buf );
1568
+ if (add_path4 ) {
1569
+ ND_PRINT (" Path Id: %u" , path_id );
1570
+ advance += 4 ;
1571
+ }
1572
+ break ;
1573
+ case (AFNUM_INET <<8 | SAFNUM_LABUNICAST ):
1574
+ advance = decode_labeled_prefix4 (ndo , tptr , len , buf , buflen );
1575
+ if (advance == -1 )
1576
+ ND_PRINT ("\n\t (illegal prefix length)" );
1577
+ else if (advance == -2 )
1578
+ goto trunc ;
1579
+ else if (advance == -3 )
1580
+ break ; /* bytes left, but not enough */
1581
+ else
1582
+ ND_PRINT ("\n\t %s" , buf );
1583
+ break ;
1584
+ case (AFNUM_INET <<8 | SAFNUM_VPNUNICAST ):
1585
+ case (AFNUM_INET <<8 | SAFNUM_VPNMULTICAST ):
1586
+ case (AFNUM_INET <<8 | SAFNUM_VPNUNIMULTICAST ):
1587
+ advance = decode_labeled_vpn_prefix4 (ndo , tptr , buf , buflen );
1588
+ if (advance == -1 )
1589
+ ND_PRINT ("\n\t (illegal prefix length)" );
1590
+ else if (advance == -2 )
1591
+ goto trunc ;
1592
+ else
1593
+ ND_PRINT ("\n\t %s" , buf );
1594
+ break ;
1595
+ case (AFNUM_INET <<8 | SAFNUM_RT_ROUTING_INFO ):
1596
+ advance = decode_rt_routing_info (ndo , tptr );
1597
+ if (advance == -2 )
1598
+ goto trunc ;
1599
+ break ;
1600
+ case (AFNUM_INET <<8 | SAFNUM_MULTICAST_VPN ): /* fall through */
1601
+ case (AFNUM_INET6 <<8 | SAFNUM_MULTICAST_VPN ):
1602
+ advance = decode_multicast_vpn (ndo , tptr , buf , buflen );
1603
+ if (advance == -1 )
1604
+ ND_PRINT ("\n\t (illegal prefix length)" );
1605
+ else if (advance == -2 )
1606
+ goto trunc ;
1607
+ else
1608
+ ND_PRINT ("\n\t %s" , buf );
1609
+ break ;
1610
+
1611
+ case (AFNUM_INET <<8 | SAFNUM_MDT ):
1612
+ advance = decode_mdt_vpn_nlri (ndo , tptr , buf , buflen );
1613
+ if (advance == -1 )
1614
+ ND_PRINT ("\n\t (illegal prefix length)" );
1615
+ else if (advance == -2 )
1616
+ goto trunc ;
1617
+ else
1618
+ ND_PRINT ("\n\t %s" , buf );
1619
+ break ;
1620
+ case (AFNUM_INET6 <<8 | SAFNUM_UNICAST ):
1621
+ case (AFNUM_INET6 <<8 | SAFNUM_MULTICAST ):
1622
+ case (AFNUM_INET6 <<8 | SAFNUM_UNIMULTICAST ):
1623
+ if (add_path6 ) {
1624
+ path_id = GET_BE_U_4 (tptr );
1625
+ tptr += 4 ;
1626
+ }
1627
+ advance = decode_prefix6 (ndo , tptr , len , buf , buflen );
1628
+ if (advance == -1 )
1629
+ ND_PRINT ("\n\t (illegal prefix length)" );
1630
+ else if (advance == -2 )
1631
+ goto trunc ;
1632
+ else if (advance == -3 )
1633
+ break ; /* bytes left, but not enough */
1634
+ else
1635
+ ND_PRINT ("\n\t %s" , buf );
1636
+ if (add_path6 ) {
1637
+ ND_PRINT (" Path Id: %u" , path_id );
1638
+ advance += 4 ;
1639
+ }
1640
+ break ;
1641
+ case (AFNUM_INET6 <<8 | SAFNUM_LABUNICAST ):
1642
+ advance = decode_labeled_prefix6 (ndo , tptr , len , buf , buflen );
1643
+ if (advance == -1 )
1644
+ ND_PRINT ("\n\t (illegal prefix length)" );
1645
+ else if (advance == -2 )
1646
+ goto trunc ;
1647
+ else if (advance == -3 )
1648
+ break ; /* bytes left, but not enough */
1649
+ else
1650
+ ND_PRINT ("\n\t %s" , buf );
1651
+ break ;
1652
+ case (AFNUM_INET6 <<8 | SAFNUM_VPNUNICAST ):
1653
+ case (AFNUM_INET6 <<8 | SAFNUM_VPNMULTICAST ):
1654
+ case (AFNUM_INET6 <<8 | SAFNUM_VPNUNIMULTICAST ):
1655
+ advance = decode_labeled_vpn_prefix6 (ndo , tptr , buf , buflen );
1656
+ if (advance == -1 )
1657
+ ND_PRINT ("\n\t (illegal prefix length)" );
1658
+ else if (advance == -2 )
1659
+ goto trunc ;
1660
+ else
1661
+ ND_PRINT ("\n\t %s" , buf );
1662
+ break ;
1663
+ case (AFNUM_VPLS <<8 | SAFNUM_VPLS ):
1664
+ case (AFNUM_L2VPN <<8 | SAFNUM_VPNUNICAST ):
1665
+ case (AFNUM_L2VPN <<8 | SAFNUM_VPNMULTICAST ):
1666
+ case (AFNUM_L2VPN <<8 | SAFNUM_VPNUNIMULTICAST ):
1667
+ advance = decode_labeled_vpn_l2 (ndo , tptr , buf , buflen );
1668
+ if (advance == -1 )
1669
+ ND_PRINT ("\n\t (illegal length)" );
1670
+ else if (advance == -2 )
1671
+ goto trunc ;
1672
+ else
1673
+ ND_PRINT ("\n\t %s" , buf );
1674
+ break ;
1675
+ case (AFNUM_NSAP <<8 | SAFNUM_UNICAST ):
1676
+ case (AFNUM_NSAP <<8 | SAFNUM_MULTICAST ):
1677
+ case (AFNUM_NSAP <<8 | SAFNUM_UNIMULTICAST ):
1678
+ advance = decode_clnp_prefix (ndo , tptr , buf , buflen );
1679
+ if (advance == -1 )
1680
+ ND_PRINT ("\n\t (illegal prefix length)" );
1681
+ else if (advance == -2 )
1682
+ goto trunc ;
1683
+ else
1684
+ ND_PRINT ("\n\t %s" , buf );
1685
+ break ;
1686
+ case (AFNUM_NSAP <<8 | SAFNUM_VPNUNICAST ):
1687
+ case (AFNUM_NSAP <<8 | SAFNUM_VPNMULTICAST ):
1688
+ case (AFNUM_NSAP <<8 | SAFNUM_VPNUNIMULTICAST ):
1689
+ advance = decode_labeled_vpn_clnp_prefix (ndo , tptr , buf , buflen );
1690
+ if (advance == -1 )
1691
+ ND_PRINT ("\n\t (illegal prefix length)" );
1692
+ else if (advance == -2 )
1693
+ goto trunc ;
1694
+ else
1695
+ ND_PRINT ("\n\t %s" , buf );
1696
+ break ;
1697
+ default :
1698
+ /*
1699
+ * We're just confused here.
1700
+ * tlen was the next-hop length.
1701
+ ND_TCHECK_LEN(tptr, tlen);
1702
+ */
1703
+ ND_PRINT ("\n\t no AFI %u / SAFI %u decoder" , af , safi );
1704
+ /*
1705
+ if (ndo->ndo_vflag <= 1)
1706
+ print_unknown_data(ndo, tptr, "\n\t ", tlen);
1707
+ */
1708
+ advance = -4 ;
1709
+ break ;
1710
+ }
1711
+ return advance ;
1712
+ trunc : /* we rely on the caller to recognize -2 return value */
1713
+ return -2 ;
1714
+ }
1715
+
1542
1716
static int
1543
1717
bgp_attr_print (netdissect_options * ndo ,
1544
1718
uint8_t atype , const u_char * pptr , u_int len )
@@ -1929,159 +2103,10 @@ bgp_attr_print(netdissect_options *ndo,
1929
2103
add_path6 = check_add_path (ndo , tptr , (len - (tptr - pptr )), 128 );
1930
2104
1931
2105
while (tptr < pptr + len ) {
1932
- switch (af <<8 | safi ) {
1933
- case (AFNUM_INET <<8 | SAFNUM_UNICAST ):
1934
- case (AFNUM_INET <<8 | SAFNUM_MULTICAST ):
1935
- case (AFNUM_INET <<8 | SAFNUM_UNIMULTICAST ):
1936
- if (add_path4 ) {
1937
- path_id = GET_BE_U_4 (tptr );
1938
- tptr += 4 ;
1939
- }
1940
- advance = decode_prefix4 (ndo , tptr , len , buf , sizeof (buf ));
1941
- if (advance == -1 )
1942
- ND_PRINT ("\n\t (illegal prefix length)" );
1943
- else if (advance == -2 )
1944
- goto trunc ;
1945
- else if (advance == -3 )
1946
- break ; /* bytes left, but not enough */
1947
- else
1948
- ND_PRINT ("\n\t %s" , buf );
1949
- if (add_path4 ) {
1950
- ND_PRINT (" Path Id: %u" , path_id );
1951
- }
1952
- break ;
1953
- case (AFNUM_INET <<8 | SAFNUM_LABUNICAST ):
1954
- advance = decode_labeled_prefix4 (ndo , tptr , len , buf , sizeof (buf ));
1955
- if (advance == -1 )
1956
- ND_PRINT ("\n\t (illegal prefix length)" );
1957
- else if (advance == -2 )
1958
- goto trunc ;
1959
- else if (advance == -3 )
1960
- break ; /* bytes left, but not enough */
1961
- else
1962
- ND_PRINT ("\n\t %s" , buf );
1963
- break ;
1964
- case (AFNUM_INET <<8 | SAFNUM_VPNUNICAST ):
1965
- case (AFNUM_INET <<8 | SAFNUM_VPNMULTICAST ):
1966
- case (AFNUM_INET <<8 | SAFNUM_VPNUNIMULTICAST ):
1967
- advance = decode_labeled_vpn_prefix4 (ndo , tptr , buf , sizeof (buf ));
1968
- if (advance == -1 )
1969
- ND_PRINT ("\n\t (illegal prefix length)" );
1970
- else if (advance == -2 )
1971
- goto trunc ;
1972
- else
1973
- ND_PRINT ("\n\t %s" , buf );
1974
- break ;
1975
- case (AFNUM_INET <<8 | SAFNUM_RT_ROUTING_INFO ):
1976
- advance = decode_rt_routing_info (ndo , tptr );
1977
- if (advance == -2 )
1978
- goto trunc ;
1979
- break ;
1980
- case (AFNUM_INET <<8 | SAFNUM_MULTICAST_VPN ): /* fall through */
1981
- case (AFNUM_INET6 <<8 | SAFNUM_MULTICAST_VPN ):
1982
- advance = decode_multicast_vpn (ndo , tptr , buf , sizeof (buf ));
1983
- if (advance == -1 )
1984
- ND_PRINT ("\n\t (illegal prefix length)" );
1985
- else if (advance == -2 )
1986
- goto trunc ;
1987
- else
1988
- ND_PRINT ("\n\t %s" , buf );
1989
- break ;
1990
-
1991
- case (AFNUM_INET <<8 | SAFNUM_MDT ):
1992
- advance = decode_mdt_vpn_nlri (ndo , tptr , buf , sizeof (buf ));
1993
- if (advance == -1 )
1994
- ND_PRINT ("\n\t (illegal prefix length)" );
1995
- else if (advance == -2 )
1996
- goto trunc ;
1997
- else
1998
- ND_PRINT ("\n\t %s" , buf );
1999
- break ;
2000
- case (AFNUM_INET6 <<8 | SAFNUM_UNICAST ):
2001
- case (AFNUM_INET6 <<8 | SAFNUM_MULTICAST ):
2002
- case (AFNUM_INET6 <<8 | SAFNUM_UNIMULTICAST ):
2003
- if (add_path6 ) {
2004
- path_id = GET_BE_U_4 (tptr );
2005
- tptr += 4 ;
2006
- }
2007
- advance = decode_prefix6 (ndo , tptr , len , buf , sizeof (buf ));
2008
- if (advance == -1 )
2009
- ND_PRINT ("\n\t (illegal prefix length)" );
2010
- else if (advance == -2 )
2011
- goto trunc ;
2012
- else if (advance == -3 )
2013
- break ; /* bytes left, but not enough */
2014
- else
2015
- ND_PRINT ("\n\t %s" , buf );
2016
- if (add_path6 ) {
2017
- ND_PRINT (" Path Id: %u" , path_id );
2018
- }
2019
- break ;
2020
- case (AFNUM_INET6 <<8 | SAFNUM_LABUNICAST ):
2021
- advance = decode_labeled_prefix6 (ndo , tptr , len , buf , sizeof (buf ));
2022
- if (advance == -1 )
2023
- ND_PRINT ("\n\t (illegal prefix length)" );
2024
- else if (advance == -2 )
2025
- goto trunc ;
2026
- else if (advance == -3 )
2027
- break ; /* bytes left, but not enough */
2028
- else
2029
- ND_PRINT ("\n\t %s" , buf );
2030
- break ;
2031
- case (AFNUM_INET6 <<8 | SAFNUM_VPNUNICAST ):
2032
- case (AFNUM_INET6 <<8 | SAFNUM_VPNMULTICAST ):
2033
- case (AFNUM_INET6 <<8 | SAFNUM_VPNUNIMULTICAST ):
2034
- advance = decode_labeled_vpn_prefix6 (ndo , tptr , buf , sizeof (buf ));
2035
- if (advance == -1 )
2036
- ND_PRINT ("\n\t (illegal prefix length)" );
2037
- else if (advance == -2 )
2038
- goto trunc ;
2039
- else
2040
- ND_PRINT ("\n\t %s" , buf );
2041
- break ;
2042
- case (AFNUM_VPLS <<8 | SAFNUM_VPLS ):
2043
- case (AFNUM_L2VPN <<8 | SAFNUM_VPNUNICAST ):
2044
- case (AFNUM_L2VPN <<8 | SAFNUM_VPNMULTICAST ):
2045
- case (AFNUM_L2VPN <<8 | SAFNUM_VPNUNIMULTICAST ):
2046
- advance = decode_labeled_vpn_l2 (ndo , tptr , buf , sizeof (buf ));
2047
- if (advance == -1 )
2048
- ND_PRINT ("\n\t (illegal length)" );
2049
- else if (advance == -2 )
2050
- goto trunc ;
2051
- else
2052
- ND_PRINT ("\n\t %s" , buf );
2053
- break ;
2054
- case (AFNUM_NSAP <<8 | SAFNUM_UNICAST ):
2055
- case (AFNUM_NSAP <<8 | SAFNUM_MULTICAST ):
2056
- case (AFNUM_NSAP <<8 | SAFNUM_UNIMULTICAST ):
2057
- advance = decode_clnp_prefix (ndo , tptr , buf , sizeof (buf ));
2058
- if (advance == -1 )
2059
- ND_PRINT ("\n\t (illegal prefix length)" );
2060
- else if (advance == -2 )
2061
- goto trunc ;
2062
- else
2063
- ND_PRINT ("\n\t %s" , buf );
2064
- break ;
2065
- case (AFNUM_NSAP <<8 | SAFNUM_VPNUNICAST ):
2066
- case (AFNUM_NSAP <<8 | SAFNUM_VPNMULTICAST ):
2067
- case (AFNUM_NSAP <<8 | SAFNUM_VPNUNIMULTICAST ):
2068
- advance = decode_labeled_vpn_clnp_prefix (ndo , tptr , buf , sizeof (buf ));
2069
- if (advance == -1 )
2070
- ND_PRINT ("\n\t (illegal prefix length)" );
2071
- else if (advance == -2 )
2072
- goto trunc ;
2073
- else
2074
- ND_PRINT ("\n\t %s" , buf );
2075
- break ;
2076
- default :
2077
- ND_TCHECK_LEN (tptr , tlen );
2078
- ND_PRINT ("\n\t no AFI %u / SAFI %u decoder" , af , safi );
2079
- if (ndo -> ndo_vflag <= 1 )
2080
- print_unknown_data (ndo , tptr , "\n\t " , tlen );
2081
- advance = 0 ;
2082
- tptr = pptr + len ;
2083
- break ;
2084
- }
2106
+ advance = bgp_nlri_print (ndo , af , safi , tptr , len , buf , sizeof (buf ),
2107
+ add_path4 , add_path6 );
2108
+ if (advance == -2 )
2109
+ goto trunc ;
2085
2110
if (advance < 0 )
2086
2111
break ;
2087
2112
tptr += advance ;
0 commit comments