+ switch (af<<8 | safi) {
+ case (AFNUM_IP<<8 | SAFNUM_UNICAST):
+ case (AFNUM_IP<<8 | SAFNUM_MULTICAST):
+ case (AFNUM_IP<<8 | SAFNUM_UNIMULTICAST):
+ if (add_path4) {
+ path_id = GET_BE_U_4(tptr);
+ tptr += 4;
+ }
+ advance = decode_prefix4(ndo, tptr, len, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else if (advance == -2)
+ break; /* bytes left, but not enough */
+ else
+ ND_PRINT("\n\t %s", buf);
+ if (add_path4) {
+ ND_PRINT(" Path Id: %u", path_id);
+ advance += 4;
+ }
+ break;
+ case (AFNUM_IP<<8 | SAFNUM_LABUNICAST):
+ advance = decode_labeled_prefix4(ndo, tptr, len, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else if (advance == -2)
+ goto trunc;
+ else if (advance == -3)
+ break; /* bytes left, but not enough */
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ case (AFNUM_IP<<8 | SAFNUM_VPNUNICAST):
+ case (AFNUM_IP<<8 | SAFNUM_VPNMULTICAST):
+ case (AFNUM_IP<<8 | SAFNUM_VPNUNIMULTICAST):
+ advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ case (AFNUM_IP<<8 | SAFNUM_RT_ROUTING_INFO):
+ advance = decode_rt_routing_info(ndo, tptr);
+ break;
+ case (AFNUM_IP<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
+ case (AFNUM_IP6<<8 | SAFNUM_MULTICAST_VPN):
+ advance = decode_multicast_vpn(ndo, tptr, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else if (advance == -2)
+ goto trunc;
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+
+ case (AFNUM_IP<<8 | SAFNUM_MDT):
+ advance = decode_mdt_vpn_nlri(ndo, tptr, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else if (advance == -2)
+ goto trunc;
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ case (AFNUM_IP6<<8 | SAFNUM_UNICAST):
+ case (AFNUM_IP6<<8 | SAFNUM_MULTICAST):
+ case (AFNUM_IP6<<8 | SAFNUM_UNIMULTICAST):
+ if (add_path6) {
+ path_id = GET_BE_U_4(tptr);
+ tptr += 4;
+ }
+ advance = decode_prefix6(ndo, tptr, len, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else if (advance == -2)
+ break; /* bytes left, but not enough */
+ else
+ ND_PRINT("\n\t %s", buf);
+ if (add_path6) {
+ ND_PRINT(" Path Id: %u", path_id);
+ advance += 4;
+ }
+ break;
+ case (AFNUM_IP6<<8 | SAFNUM_LABUNICAST):
+ advance = decode_labeled_prefix6(ndo, tptr, len, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else if (advance == -2)
+ goto trunc;
+ else if (advance == -3)
+ break; /* bytes left, but not enough */
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ case (AFNUM_IP6<<8 | SAFNUM_VPNUNICAST):
+ case (AFNUM_IP6<<8 | SAFNUM_VPNMULTICAST):
+ case (AFNUM_IP6<<8 | SAFNUM_VPNUNIMULTICAST):
+ advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
+ case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
+ case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
+ case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
+ advance = decode_labeled_vpn_l2(ndo, tptr, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal length)");
+ else if (advance == -2)
+ goto trunc;
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
+ case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
+ case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
+ advance = decode_clnp_prefix(ndo, tptr, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
+ case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
+ case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
+ advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, buflen);
+ if (advance == -1)
+ ND_PRINT("\n\t (illegal prefix length)");
+ else
+ ND_PRINT("\n\t %s", buf);
+ break;
+ default:
+ /*
+ * This should not happen, we should have been protected
+ * by bgp_mp_af_print()'s return value.
+ */
+ ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af, safi);
+ advance = -4;
+ break;
+ }
+ return advance;
+trunc: /* we rely on the caller to recognize -2 return value */
+ return -2;
+}
+
+static const struct tok bgp_flags[] = {
+ { 0x80, "O"},
+ { 0x40, "T"},
+ { 0x20, "P"},
+ { 0x10, "E"},
+ { 0, NULL }
+};
+
+static int
+bgp_attr_print(netdissect_options *ndo,
+ uint8_t atype, const u_char *pptr, u_int len,
+ const unsigned attr_set_level)
+{
+ /* allocate space for the largest possible string */
+ char astostr[AS_STR_SIZE];
+ u_int i;
+ uint16_t af;
+ uint8_t safi, snpa, nhlen;
+ int advance;
+ u_int tlen;
+ const u_char *tptr;
+ char buf[MAXHOSTNAMELEN + 100];
+ u_int as_size;
+ int add_path4, add_path6;
+ int ret;
+
+ tptr = pptr;
+ tlen = len;
+
+ switch (atype) {
+ case BGPTYPE_ORIGIN:
+ if (len != 1)
+ ND_PRINT("invalid len");
+ else {
+ ND_PRINT("%s", tok2str(bgp_origin_values,
+ "Unknown Origin Typecode",
+ GET_U_1(tptr)));
+ }
+ break;
+
+ /*
+ * Process AS4 byte path and AS2 byte path attributes here.
+ */
+ case BGPTYPE_AS4_PATH:
+ case BGPTYPE_AS_PATH:
+ if (len % 2) {
+ ND_PRINT("invalid len");
+ break;
+ }
+ if (!len) {
+ ND_PRINT("empty");
+ break;
+ }
+
+ /*
+ * BGP updates exchanged between New speakers that support 4
+ * byte AS, ASs are always encoded in 4 bytes. There is no
+ * definitive way to find this, just by the packet's
+ * contents. So, check for packet's TLV's sanity assuming
+ * 2 bytes first, and it does not pass, assume that ASs are
+ * encoded in 4 bytes format and move on.
+ */
+ as_size = bgp_attr_get_as_size(ndo, atype, pptr, len);
+
+ while (tptr < pptr + len) {
+ ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values,
+ "?", GET_U_1(tptr)));
+ for (i = 0; i < GET_U_1(tptr + 1) * as_size; i += as_size) {
+ ND_TCHECK_LEN(tptr + 2 + i, as_size);
+ ND_PRINT("%s ",
+ as_printf(ndo, astostr, sizeof(astostr),
+ as_size == 2 ?
+ GET_BE_U_2(tptr + i + 2) :
+ GET_BE_U_4(tptr + i + 2)));
+ }
+ ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values,
+ "?", GET_U_1(tptr)));
+ tptr += 2 + GET_U_1(tptr + 1) * as_size;
+ }
+ break;
+ case BGPTYPE_NEXT_HOP:
+ if (len != 4)
+ ND_PRINT("invalid len");
+ else {
+ ND_PRINT("%s", GET_IPADDR_STRING(tptr));
+ }
+ break;
+ case BGPTYPE_MULTI_EXIT_DISC:
+ case BGPTYPE_LOCAL_PREF:
+ if (len != 4)
+ ND_PRINT("invalid len");
+ else {
+ ND_PRINT("%u", GET_BE_U_4(tptr));
+ }
+ break;
+ case BGPTYPE_ATOMIC_AGGREGATE:
+ if (len != 0)
+ ND_PRINT("invalid len");
+ break;
+ case BGPTYPE_AGGREGATOR:
+
+ /*
+ * Depending on the AS encoded is of 2 bytes or of 4 bytes,
+ * the length of this PA can be either 6 bytes or 8 bytes.
+ */
+ if (len != 6 && len != 8) {
+ ND_PRINT("invalid len");
+ break;
+ }
+ ND_TCHECK_LEN(tptr, len);
+ if (len == 6) {
+ ND_PRINT(" AS #%s, origin %s",
+ as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_2(tptr)),
+ GET_IPADDR_STRING(tptr + 2));
+ } else {
+ ND_PRINT(" AS #%s, origin %s",
+ as_printf(ndo, astostr, sizeof(astostr),
+ GET_BE_U_4(tptr)), GET_IPADDR_STRING(tptr + 4));
+ }
+ break;
+ case BGPTYPE_AGGREGATOR4:
+ if (len != 8) {
+ ND_PRINT("invalid len");
+ break;
+ }