Home | History | Annotate | Line # | Download | only in dist
      1 /*
      2  * Redistribution and use in source and binary forms, with or without
      3  * modification, are permitted provided that: (1) source code
      4  * distributions retain the above copyright notice and this paragraph
      5  * in its entirety, and (2) distributions including binary code include
      6  * the above copyright notice and this paragraph in its entirety in
      7  * the documentation or other materials provided with the distribution.
      8  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
      9  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
     10  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     11  * FOR A PARTICULAR PURPOSE.
     12  *
     13  * Original code by Hannes Gredler (hannes (at) gredler.at)
     14  */
     15 
     16 #include <sys/cdefs.h>
     17 #ifndef lint
     18 __RCSID("$NetBSD: print-lspping.c,v 1.12 2026/03/19 00:05:13 christos Exp $");
     19 #endif
     20 
     21 /* \summary: MPLS LSP PING printer */
     22 
     23 /* specification: RFC 4379 */
     24 
     25 #include <config.h>
     26 
     27 #include "netdissect-stdinc.h"
     28 
     29 #define ND_LONGJMP_FROM_TCHECK
     30 #include "netdissect.h"
     31 #include "extract.h"
     32 #include "addrtoname.h"
     33 #include "ntp.h"
     34 
     35 #include "l2vpn.h"
     36 #include "oui.h"
     37 
     38 
     39 /*
     40  * LSPPING common header
     41  *
     42  *  0                   1                   2                   3
     43  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     44  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     45  * |         Version Number        |         Must Be Zero          |
     46  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     47  * |  Message Type |   Reply mode  |  Return Code  | Return Subcode|
     48  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     49  * |                        Sender's Handle                        |
     50  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     51  * |                        Sequence Number                        |
     52  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     53  * |                    TimeStamp Sent (seconds)                   |
     54  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     55  * |                  TimeStamp Sent (microseconds)                |
     56  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     57  * |                  TimeStamp Received (seconds)                 |
     58  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     59  * |                TimeStamp Received (microseconds)              |
     60  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     61  * |                            TLVs ...                           |
     62  * .                                                               .
     63  * .                                                               .
     64  * .                                                               .
     65  */
     66 
     67 struct lspping_common_header {
     68     nd_uint16_t version;
     69     nd_uint16_t global_flags;
     70     nd_uint8_t  msg_type;
     71     nd_uint8_t  reply_mode;
     72     nd_uint8_t  return_code;
     73     nd_uint8_t  return_subcode;
     74     nd_uint32_t sender_handle;
     75     nd_uint32_t seq_number;
     76     struct l_fixedpt ts_sent;
     77     struct l_fixedpt ts_rcvd;
     78 };
     79 
     80 #define LSPPING_VERSION            1
     81 
     82 static const struct tok lspping_msg_type_values[] = {
     83     { 1, "MPLS Echo Request"},
     84     { 2, "MPLS Echo Reply"},
     85     { 0, NULL}
     86 };
     87 
     88 static const struct tok lspping_reply_mode_values[] = {
     89     { 1, "Do not reply"},
     90     { 2, "Reply via an IPv4/IPv6 UDP packet"},
     91     { 3, "Reply via an IPv4/IPv6 UDP packet with Router Alert"},
     92     { 4, "Reply via application level control channel"},
     93     { 0, NULL}
     94 };
     95 
     96 static const struct tok lspping_return_code_values[] = {
     97     {  0, "No return code or return code contained in the Error Code TLV"},
     98     {  1, "Malformed echo request received"},
     99     {  2, "One or more of the TLVs was not understood"},
    100     {  3, "Replying router is an egress for the FEC at stack depth"},
    101     {  4, "Replying router has no mapping for the FEC at stack depth"},
    102     {  5, "Reserved"},
    103     {  6, "Reserved"},
    104     {  7, "Reserved"},
    105     {  8, "Label switched at stack-depth"},
    106     {  9, "Label switched but no MPLS forwarding at stack-depth"},
    107     { 10, "Mapping for this FEC is not the given label at stack depth"},
    108     { 11, "No label entry at stack-depth"},
    109     { 12, "Protocol not associated with interface at FEC stack depth"},
    110     { 13, "Premature termination of ping due to label stack shrinking to a single label"},
    111     { 0,  NULL},
    112 };
    113 
    114 
    115 /*
    116  * LSPPING TLV header
    117  *  0                   1                   2                   3
    118  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    119  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    120  * |             Type              |            Length             |
    121  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    122  * |                             Value                             |
    123  * .                                                               .
    124  * .                                                               .
    125  * .                                                               .
    126  * |                                                               |
    127  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    128  */
    129 
    130 struct lspping_tlv_header {
    131     nd_uint16_t type;
    132     nd_uint16_t length;
    133 };
    134 
    135 #define	LSPPING_TLV_TARGET_FEC_STACK      1
    136 #define	LSPPING_TLV_DOWNSTREAM_MAPPING    2
    137 #define	LSPPING_TLV_PAD                   3
    138 /* not assigned                           4 */
    139 #define LSPPING_TLV_VENDOR_ENTERPRISE     5
    140 #define LSPPING_TLV_VENDOR_ENTERPRISE_LEN 4
    141 /* not assigned                           6 */
    142 #define LSPPING_TLV_INTERFACE_LABEL_STACK 7
    143 /* not assigned                           8 */
    144 #define	LSPPING_TLV_ERROR_CODE            9
    145 #define LSPPING_TLV_REPLY_TOS_BYTE        10
    146 #define	LSPPING_TLV_BFD_DISCRIMINATOR     15 /* draft-ietf-bfd-mpls-02 */
    147 #define LSPPING_TLV_BFD_DISCRIMINATOR_LEN 4
    148 #define	LSPPING_TLV_VENDOR_PRIVATE        0xfc00
    149 
    150 static const struct tok lspping_tlv_values[] = {
    151     { LSPPING_TLV_TARGET_FEC_STACK, "Target FEC Stack" },
    152     { LSPPING_TLV_DOWNSTREAM_MAPPING, "Downstream Mapping" },
    153     { LSPPING_TLV_PAD, "Pad" },
    154     { LSPPING_TLV_ERROR_CODE, "Error Code" },
    155     { LSPPING_TLV_VENDOR_ENTERPRISE, "Vendor Enterprise Code" },
    156     { LSPPING_TLV_INTERFACE_LABEL_STACK, "Interface Label Stack" },
    157     { LSPPING_TLV_REPLY_TOS_BYTE, "Reply TOS Byte" },
    158     { LSPPING_TLV_BFD_DISCRIMINATOR, "BFD Discriminator" },
    159     { LSPPING_TLV_VENDOR_PRIVATE, "Vendor Private Code" },
    160     { 0, NULL}
    161 };
    162 
    163 #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4       1
    164 #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6       2
    165 #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4      3
    166 #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6      4
    167 /* not assigned                                     5 */
    168 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4     6
    169 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6     7
    170 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT    8
    171 #define	LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW_OLD 9
    172 #define	LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW     10
    173 #define	LSPPING_TLV_TARGETFEC_SUBTLV_FEC_129_PW     11
    174 #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4       12
    175 #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6       13
    176 #define	LSPPING_TLV_TARGETFEC_SUBTLV_GENERIC_IPV4   14
    177 #define	LSPPING_TLV_TARGETFEC_SUBTLV_GENERIC_IPV6   15
    178 #define	LSPPING_TLV_TARGETFEC_SUBTLV_NIL_FEC        16
    179 
    180 static const struct tok lspping_tlvtargetfec_subtlv_values[] = {
    181     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4, "LDP IPv4 prefix"},
    182     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6, "LDP IPv6 prefix"},
    183     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4, "RSVP IPv4 Session Query"},
    184     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6, "RSVP IPv6 Session Query"},
    185     { 5, "Reserved"},
    186     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4, "VPN IPv4 prefix"},
    187     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6, "VPN IPv6 prefix"},
    188     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT, "L2 VPN endpoint"},
    189     { LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW_OLD, "FEC 128 pseudowire (old)"},
    190     { LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW, "FEC 128 pseudowire"},
    191     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4, "BGP labeled IPv4 prefix"},
    192     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6, "BGP labeled IPv6 prefix"},
    193     { 0, NULL}
    194 };
    195 
    196 /*
    197  *  0                   1                   2                   3
    198  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    199  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    200  * |                          IPv4 prefix                          |
    201  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    202  * | Prefix Length |         Must Be Zero                          |
    203  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    204  */
    205 struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t {
    206     nd_ipv4    prefix;
    207     nd_uint8_t prefix_len;
    208 };
    209 
    210 /*
    211  *  0                   1                   2                   3
    212  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    213  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    214  * |                          IPv6 prefix                          |
    215  * |                          (16 octets)                          |
    216  * |                                                               |
    217  * |                                                               |
    218  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    219  * | Prefix Length |         Must Be Zero                          |
    220  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    221  */
    222 struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t {
    223     nd_ipv6    prefix;
    224     nd_uint8_t prefix_len;
    225 };
    226 
    227 /*
    228  *  0                   1                   2                   3
    229  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    230  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    231  * |                 IPv4 tunnel end point address                 |
    232  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    233  * |          Must Be Zero         |     Tunnel ID                 |
    234  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    235  * |                       Extended Tunnel ID                      |
    236  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    237  * |                   IPv4 tunnel sender address                  |
    238  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    239  * |          Must Be Zero         |            LSP ID             |
    240  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    241  */
    242 struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t {
    243     nd_ipv4     tunnel_endpoint;
    244     nd_byte     res[2];
    245     nd_uint16_t tunnel_id;
    246     nd_ipv4     extended_tunnel_id;
    247     nd_ipv4     tunnel_sender;
    248     nd_byte     res2[2];
    249     nd_uint16_t lsp_id;
    250 };
    251 
    252 /*
    253  *  0                   1                   2                   3
    254  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    255  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    256  * |                 IPv6 tunnel end point address                 |
    257  * |                                                               |
    258  * |                                                               |
    259  * |                                                               |
    260  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    261  * |          Must Be Zero         |          Tunnel ID            |
    262  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    263  * |                       Extended Tunnel ID                      |
    264  * |                                                               |
    265  * |                                                               |
    266  * |                                                               |
    267  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    268  * |                   IPv6 tunnel sender address                  |
    269  * |                                                               |
    270  * |                                                               |
    271  * |                                                               |
    272  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    273  * |          Must Be Zero         |            LSP ID             |
    274  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    275  */
    276 struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t {
    277     nd_ipv6     tunnel_endpoint;
    278     nd_byte     res[2];
    279     nd_uint16_t tunnel_id;
    280     nd_ipv6     extended_tunnel_id;
    281     nd_ipv6     tunnel_sender;
    282     nd_byte     res2[2];
    283     nd_uint16_t lsp_id;
    284 };
    285 
    286 /*
    287  *  0                   1                   2                   3
    288  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    289  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    290  * |                      Route Distinguisher                      |
    291  * |                          (8 octets)                           |
    292  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    293  * |                         IPv4 prefix                           |
    294  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    295  * | Prefix Length |                 Must Be Zero                  |
    296  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    297  */
    298 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t {
    299     nd_byte    rd[8];
    300     nd_ipv4    prefix;
    301     nd_uint8_t prefix_len;
    302 };
    303 
    304 /*
    305  *  0                   1                   2                   3
    306  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    307  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    308  * |                      Route Distinguisher                      |
    309  * |                          (8 octets)                           |
    310  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    311  * |                          IPv6 prefix                          |
    312  * |                          (16 octets)                          |
    313  * |                                                               |
    314  * |                                                               |
    315  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    316  * | Prefix Length |                 Must Be Zero                  |
    317  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    318  */
    319 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t {
    320     nd_byte    rd[8];
    321     nd_ipv6    prefix;
    322     nd_uint8_t prefix_len;
    323 };
    324 
    325 /*
    326  *  0                   1                   2                   3
    327  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    328  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    329  * |                      Route Distinguisher                      |
    330  * |                          (8 octets)                           |
    331  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    332  * |         Sender's VE ID        |       Receiver's VE ID        |
    333  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    334  * |      Encapsulation Type       |         Must Be Zero          |
    335  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    336  *  0                   1                   2                   3
    337  */
    338 struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t {
    339     nd_byte     rd[8];
    340     nd_uint16_t sender_ve_id;
    341     nd_uint16_t receiver_ve_id;
    342     nd_uint16_t encapsulation;
    343 };
    344 
    345 /*
    346  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    347  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    348  * |                      Remote PE Address                        |
    349  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    350  * |                             PW ID                             |
    351  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    352  * |            PW Type            |          Must Be Zero         |
    353  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    354  */
    355 struct lspping_tlv_targetfec_subtlv_fec_128_pw_old {
    356     nd_ipv4     remote_pe_address;
    357     nd_uint32_t pw_id;
    358     nd_uint16_t pw_type;
    359 };
    360 
    361 /*
    362  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    363  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    364  * |                     Sender's PE Address                       |
    365  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    366  * |                      Remote PE Address                        |
    367  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    368  * |                             PW ID                             |
    369  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    370  * |            PW Type            |          Must Be Zero         |
    371  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    372  */
    373 struct lspping_tlv_targetfec_subtlv_fec_128_pw {
    374     nd_ipv4     sender_pe_address;
    375     nd_ipv4     remote_pe_address;
    376     nd_uint32_t pw_id;
    377     nd_uint16_t pw_type;
    378 };
    379 
    380 /*
    381  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    382  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    383  * |                         IPv4 prefix                           |
    384  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    385  * | Prefix Length |                 Must Be Zero                  |
    386  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    387  */
    388 struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t {
    389     nd_ipv4    prefix;
    390     nd_uint8_t prefix_len;
    391 };
    392 
    393 /*
    394  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    395  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    396  * |                          IPv6 prefix                          |
    397  * |                          (16 octets)                          |
    398  * |                                                               |
    399  * |                                                               |
    400  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    401  * | Prefix Length |                 Must Be Zero                  |
    402  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    403  */
    404 struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t {
    405     nd_ipv6    prefix;
    406     nd_uint8_t prefix_len;
    407 };
    408 
    409 /*
    410  *  0                   1                   2                   3
    411  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    412  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    413  * |               MTU             | Address Type  |  Resvd (SBZ)  |
    414  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    415  * |             Downstream IP Address (4 or 16 octets)            |
    416  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    417  * |         Downstream Interface Address (4 or 16 octets)         |
    418  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    419  * | Multipath Type| Depth Limit   |        Multipath Length       |
    420  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    421  * .                                                               .
    422  * .                     (Multipath Information)                   .
    423  * .                                                               .
    424  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    425  * |               Downstream Label                |    Protocol   |
    426  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    427  * .                                                               .
    428  * .                                                               .
    429  * .                                                               .
    430  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    431  * |               Downstream Label                |    Protocol   |
    432  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    433  */
    434 /* Enough to get the address type */
    435 struct lspping_tlv_downstream_map_t {
    436     nd_uint16_t mtu;
    437     nd_uint8_t  address_type;
    438     nd_uint8_t  ds_flags;
    439 };
    440 
    441 struct lspping_tlv_downstream_map_ipv4_t {
    442     nd_uint16_t mtu;
    443     nd_uint8_t  address_type;
    444     nd_uint8_t  ds_flags;
    445     nd_ipv4     downstream_ip;
    446     nd_ipv4     downstream_interface;
    447 };
    448 
    449 struct lspping_tlv_downstream_map_ipv4_unmb_t {
    450     nd_uint16_t mtu;
    451     nd_uint8_t  address_type;
    452     nd_uint8_t  ds_flags;
    453     nd_ipv4     downstream_ip;
    454     nd_uint32_t downstream_interface;
    455 };
    456 
    457 struct lspping_tlv_downstream_map_ipv6_t {
    458     nd_uint16_t mtu;
    459     nd_uint8_t  address_type;
    460     nd_uint8_t  ds_flags;
    461     nd_ipv6     downstream_ip;
    462     nd_ipv6     downstream_interface;
    463 };
    464 
    465 struct lspping_tlv_downstream_map_ipv6_unmb_t {
    466     nd_uint16_t mtu;
    467     nd_uint8_t  address_type;
    468     nd_uint8_t  ds_flags;
    469     nd_ipv6     downstream_ip;
    470     nd_uint32_t downstream_interface;
    471 };
    472 
    473 struct lspping_tlv_downstream_map_info_t {
    474     nd_uint8_t  multipath_type;
    475     nd_uint8_t  depth_limit;
    476     nd_uint16_t multipath_length;
    477 };
    478 
    479 #define LSPPING_AFI_IPV4      1
    480 #define LSPPING_AFI_IPV4_UNMB 2
    481 #define LSPPING_AFI_IPV6      3
    482 #define LSPPING_AFI_IPV6_UNMB 4
    483 
    484 static const struct tok lspping_tlv_downstream_addr_values[] = {
    485     { LSPPING_AFI_IPV4,      "IPv4"},
    486     { LSPPING_AFI_IPV4_UNMB, "Unnumbered IPv4"},
    487     { LSPPING_AFI_IPV6,      "IPv6"},
    488     { LSPPING_AFI_IPV6_UNMB, "IPv6"},
    489     { 0, NULL}
    490 };
    491 
    492 void
    493 lspping_print(netdissect_options *ndo,
    494               const u_char *pptr, u_int len)
    495 {
    496     const struct lspping_common_header *lspping_com_header;
    497     const struct lspping_tlv_header *lspping_tlv_header;
    498     const struct lspping_tlv_header *lspping_subtlv_header;
    499     const u_char *tptr,*tlv_tptr,*subtlv_tptr;
    500     u_int return_code, return_subcode;
    501     u_int tlen,lspping_tlv_len,lspping_tlv_type,tlv_tlen;
    502     int tlv_hexdump,subtlv_hexdump;
    503     u_int lspping_subtlv_len,lspping_subtlv_type;
    504     uint32_t int_part, fraction;
    505     u_int address_type;
    506 
    507     union {
    508         const struct lspping_tlv_downstream_map_t *lspping_tlv_downstream_map;
    509         const struct lspping_tlv_downstream_map_ipv4_t *lspping_tlv_downstream_map_ipv4;
    510         const struct lspping_tlv_downstream_map_ipv4_unmb_t *lspping_tlv_downstream_map_ipv4_unmb;
    511         const struct lspping_tlv_downstream_map_ipv6_t *lspping_tlv_downstream_map_ipv6;
    512         const struct lspping_tlv_downstream_map_ipv6_unmb_t *lspping_tlv_downstream_map_ipv6_unmb;
    513         const struct lspping_tlv_downstream_map_info_t  *lspping_tlv_downstream_map_info;
    514     } tlv_ptr;
    515 
    516     union {
    517         const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *lspping_tlv_targetfec_subtlv_ldp_ipv4;
    518         const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *lspping_tlv_targetfec_subtlv_ldp_ipv6;
    519         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *lspping_tlv_targetfec_subtlv_rsvp_ipv4;
    520         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *lspping_tlv_targetfec_subtlv_rsvp_ipv6;
    521         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv4;
    522         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv6;
    523         const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *lspping_tlv_targetfec_subtlv_l2vpn_endpt;
    524         const struct lspping_tlv_targetfec_subtlv_fec_128_pw_old *lspping_tlv_targetfec_subtlv_l2vpn_vcid_old;
    525         const struct lspping_tlv_targetfec_subtlv_fec_128_pw *lspping_tlv_targetfec_subtlv_l2vpn_vcid;
    526         const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *lspping_tlv_targetfec_subtlv_bgp_ipv4;
    527         const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *lspping_tlv_targetfec_subtlv_bgp_ipv6;
    528     } subtlv_ptr;
    529 
    530     ndo->ndo_protocol = "lspping";
    531     tptr=pptr;
    532     lspping_com_header = (const struct lspping_common_header *)pptr;
    533     if (len < sizeof(struct lspping_common_header))
    534         goto tooshort;
    535     ND_TCHECK_SIZE(lspping_com_header);
    536 
    537     /*
    538      * Sanity checking of the header.
    539      */
    540     if (GET_BE_U_2(lspping_com_header->version) != LSPPING_VERSION) {
    541 	ND_PRINT("LSP-PING version %u packet not supported",
    542                GET_BE_U_2(lspping_com_header->version));
    543 	return;
    544     }
    545 
    546     /* in non-verbose mode just lets print the basic Message Type*/
    547     if (ndo->ndo_vflag < 1) {
    548         ND_PRINT("LSP-PINGv%u, %s, seq %u, length: %u",
    549                GET_BE_U_2(lspping_com_header->version),
    550                tok2str(lspping_msg_type_values, "unknown (%u)",GET_U_1(lspping_com_header->msg_type)),
    551                GET_BE_U_4(lspping_com_header->seq_number),
    552                len);
    553         return;
    554     }
    555 
    556     /* ok they seem to want to know everything - lets fully decode it */
    557 
    558     tlen=len;
    559 
    560     ND_PRINT("\n\tLSP-PINGv%u, msg-type: %s (%u), length: %u\n\t  reply-mode: %s (%u)",
    561            GET_BE_U_2(lspping_com_header->version),
    562            tok2str(lspping_msg_type_values, "unknown",GET_U_1(lspping_com_header->msg_type)),
    563            GET_U_1(lspping_com_header->msg_type),
    564            len,
    565            tok2str(lspping_reply_mode_values, "unknown",GET_U_1(lspping_com_header->reply_mode)),
    566            GET_U_1(lspping_com_header->reply_mode));
    567 
    568     /*
    569      *  the following return codes require that the subcode is attached
    570      *  at the end of the translated token output
    571      */
    572     return_code = GET_U_1(lspping_com_header->return_code);
    573     return_subcode = GET_U_1(lspping_com_header->return_subcode);
    574     if (return_code == 3 ||
    575         return_code == 4 ||
    576         return_code == 8 ||
    577         return_code == 10 ||
    578         return_code == 11 ||
    579         return_code == 12 )
    580         ND_PRINT("\n\t  Return Code: %s %u (%u)\n\t  Return Subcode: (%u)",
    581                tok2str(lspping_return_code_values, "unknown",return_code),
    582                return_subcode,
    583                return_code,
    584                return_subcode);
    585     else
    586         ND_PRINT("\n\t  Return Code: %s (%u)\n\t  Return Subcode: (%u)",
    587                tok2str(lspping_return_code_values, "unknown",return_code),
    588                return_code,
    589                return_subcode);
    590 
    591     ND_PRINT("\n\t  Sender Handle: 0x%08x, Sequence: %u",
    592            GET_BE_U_4(lspping_com_header->sender_handle),
    593            GET_BE_U_4(lspping_com_header->seq_number));
    594 
    595     ND_PRINT("\n\t  TimeStamp Sent: ");
    596     p_ntp_time(ndo, &lspping_com_header->ts_sent);
    597 
    598     int_part=GET_BE_U_4(lspping_com_header->ts_rcvd.int_part);
    599     fraction=GET_BE_U_4(lspping_com_header->ts_rcvd.fraction);
    600     ND_PRINT("\n\t  TimeStamp Received: ");
    601     if (! (int_part == 0 && fraction == 0))
    602         p_ntp_time(ndo, &lspping_com_header->ts_rcvd);
    603     else
    604         ND_PRINT("no timestamp");
    605 
    606     tptr+=sizeof(struct lspping_common_header);
    607     tlen-=sizeof(struct lspping_common_header);
    608 
    609     while (tlen != 0) {
    610         /* Does the TLV go past the end of the packet? */
    611         if (tlen < sizeof(struct lspping_tlv_header))
    612             goto tooshort;
    613 
    614         lspping_tlv_header = (const struct lspping_tlv_header *)tptr;
    615         lspping_tlv_type=GET_BE_U_2(lspping_tlv_header->type);
    616         lspping_tlv_len=GET_BE_U_2(lspping_tlv_header->length);
    617 
    618         ND_PRINT("\n\t  %s TLV (%u), length: %u",
    619                tok2str(lspping_tlv_values,
    620                        "Unknown",
    621                        lspping_tlv_type),
    622                lspping_tlv_type,
    623                lspping_tlv_len);
    624 
    625         /* some little sanity checking */
    626         if (lspping_tlv_len == 0) {
    627             tptr+=sizeof(struct lspping_tlv_header);
    628             tlen-=sizeof(struct lspping_tlv_header);
    629             continue;    /* no value to dissect */
    630         }
    631 
    632         tlv_tptr=tptr+sizeof(struct lspping_tlv_header);
    633         tlv_tlen=lspping_tlv_len; /* header not included -> no adjustment */
    634 
    635         /* Does the TLV go past the end of the packet? */
    636         if (tlen < lspping_tlv_len+sizeof(struct lspping_tlv_header))
    637             goto tooshort;
    638         /* did we capture enough for fully decoding the tlv ? */
    639         ND_TCHECK_LEN(tlv_tptr, lspping_tlv_len);
    640         tlv_hexdump=FALSE;
    641 
    642         switch(lspping_tlv_type) {
    643         case LSPPING_TLV_TARGET_FEC_STACK:
    644             while (tlv_tlen != 0) {
    645                 /* Does the subTLV header go past the end of the TLV? */
    646                 if (tlv_tlen < sizeof(struct lspping_tlv_header)) {
    647                     ND_PRINT("\n\t      TLV is too short");
    648                     tlv_hexdump = TRUE;
    649                     goto tlv_tooshort;
    650                 }
    651                 subtlv_hexdump=FALSE;
    652 
    653                 lspping_subtlv_header = (const struct lspping_tlv_header *)tlv_tptr;
    654                 lspping_subtlv_type=GET_BE_U_2(lspping_subtlv_header->type);
    655                 lspping_subtlv_len=GET_BE_U_2(lspping_subtlv_header->length);
    656                 subtlv_tptr=tlv_tptr+sizeof(struct lspping_tlv_header);
    657 
    658                 /* Does the subTLV go past the end of the TLV? */
    659                 if (tlv_tlen < lspping_subtlv_len+sizeof(struct lspping_tlv_header)) {
    660                     ND_PRINT("\n\t      TLV is too short");
    661                     tlv_hexdump = TRUE;
    662                     goto tlv_tooshort;
    663                 }
    664 
    665                 /* Did we capture enough for fully decoding the subTLV? */
    666                 ND_TCHECK_LEN(subtlv_tptr, lspping_subtlv_len);
    667 
    668                 ND_PRINT("\n\t    %s subTLV (%u), length: %u",
    669                        tok2str(lspping_tlvtargetfec_subtlv_values,
    670                                "Unknown",
    671                                lspping_subtlv_type),
    672                        lspping_subtlv_type,
    673                        lspping_subtlv_len);
    674 
    675                 switch(lspping_subtlv_type) {
    676 
    677                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4:
    678                     /* Is the subTLV length correct? */
    679                     if (lspping_subtlv_len != 5) {
    680                         ND_PRINT("\n\t      invalid subTLV length, should be 5");
    681                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    682                     } else {
    683                         subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4 =
    684                             (const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *)subtlv_tptr;
    685                         ND_PRINT("\n\t      %s/%u",
    686                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix),
    687                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix_len));
    688                     }
    689                     break;
    690 
    691                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6:
    692                     /* Is the subTLV length correct? */
    693                     if (lspping_subtlv_len != 17) {
    694                         ND_PRINT("\n\t      invalid subTLV length, should be 17");
    695                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    696                     } else {
    697                         subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6 =
    698                             (const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *)subtlv_tptr;
    699                         ND_PRINT("\n\t      %s/%u",
    700                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix),
    701                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix_len));
    702                     }
    703                     break;
    704 
    705                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4:
    706                     /* Is the subTLV length correct? */
    707                     if (lspping_subtlv_len != 5) {
    708                         ND_PRINT("\n\t      invalid subTLV length, should be 5");
    709                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    710                     } else {
    711                         subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4 =
    712                             (const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *)subtlv_tptr;
    713                         ND_PRINT("\n\t      %s/%u",
    714                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix),
    715                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix_len));
    716                     }
    717                     break;
    718 
    719                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6:
    720                     /* Is the subTLV length correct? */
    721                     if (lspping_subtlv_len != 17) {
    722                         ND_PRINT("\n\t      invalid subTLV length, should be 17");
    723                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    724                     } else {
    725                         subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6 =
    726                             (const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *)subtlv_tptr;
    727                         ND_PRINT("\n\t      %s/%u",
    728                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix),
    729                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix_len));
    730                     }
    731                     break;
    732 
    733                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4:
    734                     /* Is the subTLV length correct? */
    735                     if (lspping_subtlv_len != 20) {
    736                         ND_PRINT("\n\t      invalid subTLV length, should be 20");
    737                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    738                     } else {
    739                         subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4 =
    740                             (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *)subtlv_tptr;
    741                         ND_PRINT("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x"
    742                                "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
    743                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_endpoint),
    744                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_sender),
    745                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->lsp_id),
    746                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_id),
    747                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->extended_tunnel_id));
    748                     }
    749                     break;
    750 
    751                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6:
    752                     /* Is the subTLV length correct? */
    753                     if (lspping_subtlv_len != 56) {
    754                         ND_PRINT("\n\t      invalid subTLV length, should be 56");
    755                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    756                     } else {
    757                         subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6 =
    758                             (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *)subtlv_tptr;
    759                         ND_PRINT("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x"
    760                                "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
    761                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_endpoint),
    762                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_sender),
    763                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->lsp_id),
    764                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_id),
    765                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->extended_tunnel_id));
    766                     }
    767                     break;
    768 
    769                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4:
    770                     /* Is the subTLV length correct? */
    771                     if (lspping_subtlv_len != 13) {
    772                         ND_PRINT("\n\t      invalid subTLV length, should be 13");
    773                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    774                     } else {
    775                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4 =
    776                             (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *)subtlv_tptr;
    777                         ND_PRINT("\n\t      RD: %s, %s/%u",
    778                                bgp_vpn_rd_print(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->rd),
    779                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix),
    780                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix_len));
    781                     }
    782                     break;
    783 
    784                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6:
    785                     /* Is the subTLV length correct? */
    786                     if (lspping_subtlv_len != 25) {
    787                         ND_PRINT("\n\t      invalid subTLV length, should be 25");
    788                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    789                     } else {
    790                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6 =
    791                             (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *)subtlv_tptr;
    792                         ND_PRINT("\n\t      RD: %s, %s/%u",
    793                                bgp_vpn_rd_print(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->rd),
    794                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix),
    795                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix_len));
    796                     }
    797                     break;
    798 
    799                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT:
    800                     /* Is the subTLV length correct? */
    801                     if (lspping_subtlv_len != 14) {
    802                         ND_PRINT("\n\t      invalid subTLV length, should be 14");
    803                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    804                     } else {
    805                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt =
    806                             (const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *)subtlv_tptr;
    807                         ND_PRINT("\n\t      RD: %s, Sender VE ID: %u, Receiver VE ID: %u"
    808                                "\n\t      Encapsulation Type: %s (%u)",
    809                                bgp_vpn_rd_print(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->rd),
    810                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->sender_ve_id),
    811                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->receiver_ve_id),
    812                                tok2str(mpls_pw_types_values,
    813                                        "unknown",
    814                                        GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
    815                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation));
    816                     }
    817                     break;
    818 
    819                     /* the old L2VPN VCID subTLV does not have support for the sender field */
    820                 case LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW_OLD:
    821                     /* Is the subTLV length correct? */
    822                     if (lspping_subtlv_len != 10) {
    823                         ND_PRINT("\n\t      invalid subTLV length, should be 10");
    824                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    825                     } else {
    826                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old =
    827                             (const struct lspping_tlv_targetfec_subtlv_fec_128_pw_old *)subtlv_tptr;
    828                         ND_PRINT("\n\t      Remote PE: %s"
    829                                "\n\t      PW ID: 0x%08x, PW Type: %s (%u)",
    830                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->remote_pe_address),
    831                                GET_BE_U_4(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_id),
    832                                tok2str(mpls_pw_types_values,
    833                                        "unknown",
    834                                        GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type)),
    835                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type));
    836                     }
    837                     break;
    838 
    839                 case LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW:
    840                     /* Is the subTLV length correct? */
    841                     if (lspping_subtlv_len != 14) {
    842                         ND_PRINT("\n\t      invalid subTLV length, should be 14");
    843                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    844                     } else {
    845                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid =
    846                             (const struct lspping_tlv_targetfec_subtlv_fec_128_pw *)subtlv_tptr;
    847                         ND_PRINT("\n\t      Sender PE: %s, Remote PE: %s"
    848                                "\n\t      PW ID: 0x%08x, PW Type: %s (%u)",
    849                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->sender_pe_address),
    850                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->remote_pe_address),
    851                                GET_BE_U_4(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_id),
    852                                tok2str(mpls_pw_types_values,
    853                                        "unknown",
    854                                        GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type)),
    855                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type));
    856                     }
    857                     break;
    858 
    859                 default:
    860                     subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    861                     break;
    862                 }
    863                 /* do we want to see an additionally subtlv hexdump ? */
    864                 if (ndo->ndo_vflag > 1 || subtlv_hexdump==TRUE)
    865                     print_unknown_data(ndo, tlv_tptr+sizeof(struct lspping_tlv_header),
    866                                        "\n\t      ",
    867                                        lspping_subtlv_len);
    868 
    869                 /* All subTLVs are aligned to four octet boundary */
    870                 if (lspping_subtlv_len % 4) {
    871                     lspping_subtlv_len += 4 - (lspping_subtlv_len % 4);
    872                     /* Does the subTLV, including padding, go past the end of the TLV? */
    873                     if (tlv_tlen < lspping_subtlv_len+sizeof(struct lspping_tlv_header)) {
    874                         ND_PRINT("\n\t\t TLV is too short");
    875                         return;
    876                     }
    877                 }
    878                 tlv_tptr+=lspping_subtlv_len;
    879                 tlv_tlen-=lspping_subtlv_len+sizeof(struct lspping_tlv_header);
    880             }
    881             break;
    882 
    883         case LSPPING_TLV_DOWNSTREAM_MAPPING:
    884             /* Does the header go past the end of the TLV? */
    885             if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_t)) {
    886                 ND_PRINT("\n\t      TLV is too short");
    887                 tlv_hexdump = TRUE;
    888                 goto tlv_tooshort;
    889             }
    890             /* Did we capture enough to get the address family? */
    891             ND_TCHECK_LEN(tlv_tptr,
    892                           sizeof(struct lspping_tlv_downstream_map_t));
    893 
    894             tlv_ptr.lspping_tlv_downstream_map=
    895                 (const struct lspping_tlv_downstream_map_t *)tlv_tptr;
    896 
    897             /* that strange thing with the downstream map TLV is that until now
    898              * we do not know if its IPv4 or IPv6 or is unnumbered; after
    899              * we find the address-type, we recast the tlv_tptr and move on. */
    900 
    901             address_type = GET_U_1(tlv_ptr.lspping_tlv_downstream_map->address_type);
    902             ND_PRINT("\n\t    MTU: %u, Address-Type: %s (%u)",
    903                    GET_BE_U_2(tlv_ptr.lspping_tlv_downstream_map->mtu),
    904                    tok2str(lspping_tlv_downstream_addr_values,
    905                            "unknown",
    906                            address_type),
    907                    address_type);
    908 
    909             switch(address_type) {
    910 
    911             case LSPPING_AFI_IPV4:
    912                 /* Does the data go past the end of the TLV? */
    913                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv4_t)) {
    914                     ND_PRINT("\n\t      TLV is too short");
    915                     tlv_hexdump = TRUE;
    916                     goto tlv_tooshort;
    917                 }
    918                 /* Did we capture enough for this part of the TLV? */
    919                 ND_TCHECK_LEN(tlv_tptr,
    920                               sizeof(struct lspping_tlv_downstream_map_ipv4_t));
    921 
    922                 tlv_ptr.lspping_tlv_downstream_map_ipv4=
    923                     (const struct lspping_tlv_downstream_map_ipv4_t *)tlv_tptr;
    924                 ND_PRINT("\n\t    Downstream IP: %s"
    925                        "\n\t    Downstream Interface IP: %s",
    926                        GET_IPADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_ip),
    927                        GET_IPADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_interface));
    928                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
    929                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
    930                 break;
    931             case LSPPING_AFI_IPV4_UNMB:
    932                 /* Does the data go past the end of the TLV? */
    933                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t)) {
    934                     ND_PRINT("\n\t      TLV is too short");
    935                     tlv_hexdump = TRUE;
    936                     goto tlv_tooshort;
    937                 }
    938                 /* Did we capture enough for this part of the TLV? */
    939                 ND_TCHECK_LEN(tlv_tptr,
    940                               sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t));
    941 
    942                 tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb=
    943                     (const struct lspping_tlv_downstream_map_ipv4_unmb_t *)tlv_tptr;
    944                 ND_PRINT("\n\t    Downstream IP: %s"
    945                        "\n\t    Downstream Interface Index: 0x%08x",
    946                        GET_IPADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb->downstream_ip),
    947                        GET_BE_U_4(tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb->downstream_interface));
    948                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t);
    949                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t);
    950                 break;
    951             case LSPPING_AFI_IPV6:
    952                 /* Does the data go past the end of the TLV? */
    953                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv6_t)) {
    954                     ND_PRINT("\n\t      TLV is too short");
    955                     tlv_hexdump = TRUE;
    956                     goto tlv_tooshort;
    957                 }
    958                 /* Did we capture enough for this part of the TLV? */
    959                 ND_TCHECK_LEN(tlv_tptr,
    960                               sizeof(struct lspping_tlv_downstream_map_ipv6_t));
    961 
    962                 tlv_ptr.lspping_tlv_downstream_map_ipv6=
    963                     (const struct lspping_tlv_downstream_map_ipv6_t *)tlv_tptr;
    964                 ND_PRINT("\n\t    Downstream IP: %s"
    965                        "\n\t    Downstream Interface IP: %s",
    966                        GET_IP6ADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_ip),
    967                        GET_IP6ADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_interface));
    968                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
    969                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
    970                 break;
    971              case LSPPING_AFI_IPV6_UNMB:
    972                 /* Does the data go past the end of the TLV? */
    973                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t)) {
    974                     ND_PRINT("\n\t      TLV is too short");
    975                     tlv_hexdump = TRUE;
    976                     goto tlv_tooshort;
    977                 }
    978                 /* Did we capture enough for this part of the TLV? */
    979                 ND_TCHECK_LEN(tlv_tptr,
    980                               sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t));
    981 
    982                 tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb=
    983                    (const struct lspping_tlv_downstream_map_ipv6_unmb_t *)tlv_tptr;
    984                 ND_PRINT("\n\t    Downstream IP: %s"
    985                        "\n\t    Downstream Interface Index: 0x%08x",
    986                        GET_IP6ADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb->downstream_ip),
    987                        GET_BE_U_4(tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb->downstream_interface));
    988                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t);
    989                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t);
    990                 break;
    991 
    992             default:
    993                 /* should not happen ! - no error message - tok2str() has barked already */
    994                 break;
    995             }
    996 
    997             /* Does the data go past the end of the TLV? */
    998             if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_info_t)) {
    999                 ND_PRINT("\n\t      TLV is too short");
   1000                 tlv_hexdump = TRUE;
   1001                 goto tlv_tooshort;
   1002             }
   1003             /* Did we capture enough for this part of the TLV? */
   1004             ND_TCHECK_LEN(tlv_tptr,
   1005                           sizeof(struct lspping_tlv_downstream_map_info_t));
   1006 
   1007             tlv_ptr.lspping_tlv_downstream_map_info=
   1008                 (const struct lspping_tlv_downstream_map_info_t *)tlv_tptr;
   1009 
   1010             /* FIXME add hash-key type, depth limit, multipath processing */
   1011 
   1012             /* FIXME print downstream labels */
   1013 
   1014             tlv_hexdump=TRUE; /* dump the TLV until code complete */
   1015 
   1016             break;
   1017 
   1018         case LSPPING_TLV_BFD_DISCRIMINATOR:
   1019             if (tlv_tlen < LSPPING_TLV_BFD_DISCRIMINATOR_LEN) {
   1020                 ND_PRINT("\n\t      TLV is too short");
   1021                 tlv_hexdump = TRUE;
   1022                 goto tlv_tooshort;
   1023             } else {
   1024                 ND_PRINT("\n\t    BFD Discriminator 0x%08x", GET_BE_U_4(tlv_tptr));
   1025             }
   1026             break;
   1027 
   1028         case  LSPPING_TLV_VENDOR_ENTERPRISE:
   1029         {
   1030             uint32_t vendor_id;
   1031 
   1032             if (tlv_tlen < LSPPING_TLV_VENDOR_ENTERPRISE_LEN) {
   1033                 ND_PRINT("\n\t      TLV is too short");
   1034                 tlv_hexdump = TRUE;
   1035                 goto tlv_tooshort;
   1036             } else {
   1037                 vendor_id = GET_BE_U_4(tlv_tptr);
   1038                 ND_PRINT("\n\t    Vendor: %s (0x%04x)",
   1039                        tok2str(smi_values, "Unknown", vendor_id),
   1040                        vendor_id);
   1041             }
   1042         }
   1043             break;
   1044 
   1045             /*
   1046              *  FIXME those are the defined TLVs that lack a decoder
   1047              *  you are welcome to contribute code ;-)
   1048              */
   1049         case LSPPING_TLV_PAD:
   1050         case LSPPING_TLV_ERROR_CODE:
   1051         case LSPPING_TLV_VENDOR_PRIVATE:
   1052 
   1053         default:
   1054             if (ndo->ndo_vflag <= 1)
   1055                 print_unknown_data(ndo, tlv_tptr, "\n\t    ", tlv_tlen);
   1056             break;
   1057         }
   1058         /* do we want to see an additionally tlv hexdump ? */
   1059     tlv_tooshort:
   1060         if (ndo->ndo_vflag > 1 || tlv_hexdump==TRUE)
   1061             print_unknown_data(ndo, tptr+sizeof(struct lspping_tlv_header), "\n\t    ",
   1062                                lspping_tlv_len);
   1063 
   1064 
   1065         /* All TLVs are aligned to four octet boundary */
   1066         if (lspping_tlv_len % 4) {
   1067             lspping_tlv_len += (4 - lspping_tlv_len % 4);
   1068             /* Does the TLV, including padding, go past the end of the packet? */
   1069             if (tlen < lspping_tlv_len+sizeof(struct lspping_tlv_header))
   1070                 goto tooshort;
   1071         }
   1072 
   1073         tptr+=lspping_tlv_len+sizeof(struct lspping_tlv_header);
   1074         tlen-=lspping_tlv_len+sizeof(struct lspping_tlv_header);
   1075     }
   1076     return;
   1077 tooshort:
   1078     ND_PRINT("\n\t\t packet is too short");
   1079 }
   1080