+
+ const u_char *rd;
+ const u_char *vpn_ip;
+
+ ND_TCHECK(pptr[0]);
+
+ /* if the NLRI is not predefined length, quit.*/
+ if (*pptr != MDT_VPN_NLRI_LEN * 8)
+ return -1;
+ pptr++;
+
+ /* RD */
+ ND_TCHECK2(pptr[0], 8);
+ rd = pptr;
+ pptr+=8;
+
+ /* IPv4 address */
+ ND_TCHECK2(pptr[0], sizeof(struct in_addr));
+ vpn_ip = pptr;
+ pptr+=sizeof(struct in_addr);
+
+ /* MDT Group Address */
+ ND_TCHECK2(pptr[0], sizeof(struct in_addr));
+
+ snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
+ bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr));
+
+ return MDT_VPN_NLRI_LEN + 1;
+
+ trunc:
+
+return -2;
+}
+
+#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
+#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
+#define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
+#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
+#define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
+#define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
+#define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
+
+static const struct tok bgp_multicast_vpn_route_type_values[] = {
+ { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"},
+ { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"},
+ { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"},
+ { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"},
+ { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
+ { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
+ { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
+};
+
+static int
+decode_multicast_vpn(netdissect_options *ndo,
+ const u_char *pptr, char *buf, u_int buflen)
+{
+ uint8_t route_type, route_length, addr_length, sg_length;
+ u_int offset;
+
+ ND_TCHECK2(pptr[0], 2);
+ route_type = *pptr++;
+ route_length = *pptr++;
+
+ snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
+ tok2str(bgp_multicast_vpn_route_type_values,
+ "Unknown", route_type),
+ route_type, route_length);
+
+ switch(route_type) {
+ case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
+ ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
+ offset = strlen(buf);
+ snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
+ bgp_vpn_rd_print(ndo, pptr),
+ bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN,
+ (route_length - BGP_VPN_RD_LEN) << 3));
+ break;
+ case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
+ ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
+ offset = strlen(buf);
+ snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
+ bgp_vpn_rd_print(ndo, pptr),
+ as_printf(ndo, astostr, sizeof(astostr),
+ EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
+ break;
+
+ case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
+ ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
+ offset = strlen(buf);
+ snprintf(buf + offset, buflen - offset, ", RD: %s",
+ bgp_vpn_rd_print(ndo, pptr));
+ pptr += BGP_VPN_RD_LEN;
+
+ sg_length = bgp_vpn_sg_print(ndo, pptr, buf, buflen);
+ addr_length = route_length - sg_length;
+
+ ND_TCHECK2(pptr[0], addr_length);
+ offset = strlen(buf);
+ snprintf(buf + offset, buflen - offset, ", Originator %s",
+ bgp_vpn_ip_print(ndo, pptr, addr_length << 3));
+ break;
+
+ case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
+ ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
+ offset = strlen(buf);
+ snprintf(buf + offset, buflen - offset, ", RD: %s",
+ bgp_vpn_rd_print(ndo, pptr));
+ pptr += BGP_VPN_RD_LEN;
+
+ bgp_vpn_sg_print(ndo, pptr, buf, buflen);
+ break;
+
+ case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
+ case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
+ ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
+ offset = strlen(buf);
+ snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
+ bgp_vpn_rd_print(ndo, pptr),
+ as_printf(ndo, astostr, sizeof(astostr),
+ EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
+ pptr += BGP_VPN_RD_LEN;
+
+ bgp_vpn_sg_print(ndo, pptr, buf, buflen);
+ break;
+
+ /*
+ * no per route-type printing yet.
+ */
+ case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF:
+ default:
+ break;
+ }
+
+ return route_length + 2;
+
+trunc:
+ return -2;
+}
+
+/*
+ * As I remember, some versions of systems have an snprintf() that
+ * returns -1 if the buffer would have overflowed. If the return
+ * value is negative, set buflen to 0, to indicate that we've filled
+ * the buffer up.
+ *
+ * If the return value is greater than buflen, that means that
+ * the buffer would have overflowed; again, set buflen to 0 in
+ * that case.
+ */
+#define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
+ if (stringlen<0) \
+ buflen=0; \
+ else if ((u_int)stringlen>buflen) \
+ buflen=0; \
+ else { \
+ buflen-=stringlen; \
+ buf+=stringlen; \
+ }
+
+static int
+decode_labeled_vpn_l2(netdissect_options *ndo,
+ const u_char *pptr, char *buf, u_int buflen)
+{
+ int plen,tlen,stringlen,tlv_type,tlv_len,ttlv_len;
+
+ ND_TCHECK2(pptr[0], 2);