Home | History | Annotate | Line # | Download | only in dist
print-lspping.c revision 1.1
      1  1.1  christos /*
      2  1.1  christos  * Redistribution and use in source and binary forms, with or without
      3  1.1  christos  * modification, are permitted provided that: (1) source code
      4  1.1  christos  * distributions retain the above copyright notice and this paragraph
      5  1.1  christos  * in its entirety, and (2) distributions including binary code include
      6  1.1  christos  * the above copyright notice and this paragraph in its entirety in
      7  1.1  christos  * the documentation or other materials provided with the distribution.
      8  1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
      9  1.1  christos  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
     10  1.1  christos  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     11  1.1  christos  * FOR A PARTICULAR PURPOSE.
     12  1.1  christos  *
     13  1.1  christos  * Original code by Hannes Gredler (hannes (at) juniper.net)
     14  1.1  christos  */
     15  1.1  christos 
     16  1.1  christos #ifndef lint
     17  1.1  christos static const char rcsid[] _U_ =
     18  1.1  christos     "@(#) Header: /tcpdump/master/tcpdump/print-lspping.c,v 1.20 2008-01-28 14:20:43 hannes Exp";
     19  1.1  christos #endif
     20  1.1  christos 
     21  1.1  christos #ifdef HAVE_CONFIG_H
     22  1.1  christos #include "config.h"
     23  1.1  christos #endif
     24  1.1  christos 
     25  1.1  christos #include <tcpdump-stdinc.h>
     26  1.1  christos 
     27  1.1  christos #include <stdio.h>
     28  1.1  christos #include <stdlib.h>
     29  1.1  christos #include <string.h>
     30  1.1  christos 
     31  1.1  christos #include "interface.h"
     32  1.1  christos #include "extract.h"
     33  1.1  christos #include "addrtoname.h"
     34  1.1  christos 
     35  1.1  christos #include "bgp.h"
     36  1.1  christos #include "l2vpn.h"
     37  1.1  christos #include "oui.h"
     38  1.1  christos 
     39  1.1  christos /*
     40  1.1  christos  * LSPPING common header
     41  1.1  christos  *
     42  1.1  christos  *  0                   1                   2                   3
     43  1.1  christos  *  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  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     45  1.1  christos  * |         Version Number        |         Must Be Zero          |
     46  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     47  1.1  christos  * |  Message Type |   Reply mode  |  Return Code  | Return Subcode|
     48  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     49  1.1  christos  * |                        Sender's Handle                        |
     50  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     51  1.1  christos  * |                        Sequence Number                        |
     52  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     53  1.1  christos  * |                    TimeStamp Sent (seconds)                   |
     54  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     55  1.1  christos  * |                  TimeStamp Sent (microseconds)                |
     56  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     57  1.1  christos  * |                  TimeStamp Received (seconds)                 |
     58  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     59  1.1  christos  * |                TimeStamp Received (microseconds)              |
     60  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     61  1.1  christos  * |                            TLVs ...                           |
     62  1.1  christos  * .                                                               .
     63  1.1  christos  * .                                                               .
     64  1.1  christos  * .                                                               .
     65  1.1  christos  */
     66  1.1  christos 
     67  1.1  christos struct lspping_common_header {
     68  1.1  christos     u_int8_t version[2];
     69  1.1  christos     u_int8_t reserved[2];
     70  1.1  christos     u_int8_t msg_type;
     71  1.1  christos     u_int8_t reply_mode;
     72  1.1  christos     u_int8_t return_code;
     73  1.1  christos     u_int8_t return_subcode;
     74  1.1  christos     u_int8_t sender_handle[4];
     75  1.1  christos     u_int8_t seq_number[4];
     76  1.1  christos     u_int8_t ts_sent_sec[4];
     77  1.1  christos     u_int8_t ts_sent_usec[4];
     78  1.1  christos     u_int8_t ts_rcvd_sec[4];
     79  1.1  christos     u_int8_t ts_rcvd_usec[4];
     80  1.1  christos };
     81  1.1  christos 
     82  1.1  christos #define LSPPING_VERSION            1
     83  1.1  christos 
     84  1.1  christos static const struct tok lspping_msg_type_values[] = {
     85  1.1  christos     { 1, "MPLS Echo Request"},
     86  1.1  christos     { 2, "MPLS Echo Reply"},
     87  1.1  christos     { 0, NULL}
     88  1.1  christos };
     89  1.1  christos 
     90  1.1  christos static const struct tok lspping_reply_mode_values[] = {
     91  1.1  christos     { 1, "Do not reply"},
     92  1.1  christos     { 2, "Reply via an IPv4/IPv6 UDP packet"},
     93  1.1  christos     { 3, "Reply via an IPv4/IPv6 UDP packet with Router Alert"},
     94  1.1  christos     { 4, "Reply via application level control channel"},
     95  1.1  christos     { 0, NULL}
     96  1.1  christos };
     97  1.1  christos 
     98  1.1  christos static const struct tok lspping_return_code_values[] = {
     99  1.1  christos     {  0, "No return code or return code contained in the Error Code TLV"},
    100  1.1  christos     {  1, "Malformed echo request received"},
    101  1.1  christos     {  2, "One or more of the TLVs was not understood"},
    102  1.1  christos     {  3, "Replying router is an egress for the FEC at stack depth"},
    103  1.1  christos     {  4, "Replying router has no mapping for the FEC at stack depth"},
    104  1.1  christos     {  5, "Reserved"},
    105  1.1  christos     {  6, "Reserved"},
    106  1.1  christos     {  7, "Reserved"},
    107  1.1  christos     {  8, "Label switched at stack-depth"},
    108  1.1  christos     {  9, "Label switched but no MPLS forwarding at stack-depth"},
    109  1.1  christos     { 10, "Mapping for this FEC is not the given label at stack depth"},
    110  1.1  christos     { 11, "No label entry at stack-depth"},
    111  1.1  christos     { 12, "Protocol not associated with interface at FEC stack depth"},
    112  1.1  christos };
    113  1.1  christos 
    114  1.1  christos 
    115  1.1  christos /*
    116  1.1  christos  * LSPPING TLV header
    117  1.1  christos  *  0                   1                   2                   3
    118  1.1  christos  *  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  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    120  1.1  christos  * |             Type              |            Length             |
    121  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    122  1.1  christos  * |                             Value                             |
    123  1.1  christos  * .                                                               .
    124  1.1  christos  * .                                                               .
    125  1.1  christos  * .                                                               .
    126  1.1  christos  * |                                                               |
    127  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    128  1.1  christos  */
    129  1.1  christos 
    130  1.1  christos struct lspping_tlv_header {
    131  1.1  christos     u_int8_t type[2];
    132  1.1  christos     u_int8_t length[2];
    133  1.1  christos };
    134  1.1  christos 
    135  1.1  christos #define	LSPPING_TLV_TARGET_FEC_STACK      1
    136  1.1  christos #define	LSPPING_TLV_DOWNSTREAM_MAPPING    2
    137  1.1  christos #define	LSPPING_TLV_PAD                   3
    138  1.1  christos #define LSPPING_TLV_VENDOR_ENTERPRISE     5
    139  1.1  christos #define LSPPING_TLV_VENDOR_ENTERPRISE_LEN 4
    140  1.1  christos #define LSPPING_TLV_INTERFACE_LABEL_STACK 7
    141  1.1  christos #define	LSPPING_TLV_ERROR_CODE            9
    142  1.1  christos #define LSPPING_TLV_REPLY_TOS_BYTE        10
    143  1.1  christos #define	LSPPING_TLV_BFD_DISCRIMINATOR     15 /* draft-ietf-bfd-mpls-02 */
    144  1.1  christos #define LSPPING_TLV_BFD_DISCRIMINATOR_LEN 4
    145  1.1  christos #define	LSPPING_TLV_VENDOR_PRIVATE        0xfc00
    146  1.1  christos 
    147  1.1  christos static const struct tok lspping_tlv_values[] = {
    148  1.1  christos     { LSPPING_TLV_TARGET_FEC_STACK, "Target FEC Stack" },
    149  1.1  christos     { LSPPING_TLV_DOWNSTREAM_MAPPING, "Downstream Mapping" },
    150  1.1  christos     { LSPPING_TLV_PAD, "Pad" },
    151  1.1  christos     { LSPPING_TLV_ERROR_CODE, "Error Code" },
    152  1.1  christos     { LSPPING_TLV_VENDOR_ENTERPRISE, "Vendor Enterprise Code" },
    153  1.1  christos     { LSPPING_TLV_INTERFACE_LABEL_STACK, "Interface Label Stack" },
    154  1.1  christos     { LSPPING_TLV_REPLY_TOS_BYTE, "Reply TOS Byte" },
    155  1.1  christos     { LSPPING_TLV_BFD_DISCRIMINATOR, "BFD Discriminator" },
    156  1.1  christos     { LSPPING_TLV_VENDOR_PRIVATE, "Vendor Private Code" },
    157  1.1  christos     { 0, NULL}
    158  1.1  christos };
    159  1.1  christos 
    160  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4      1
    161  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6      2
    162  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4     3
    163  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6     4
    164  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4    6
    165  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6    7
    166  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT   8
    167  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID_OLD 9
    168  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID   10
    169  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4     11
    170  1.1  christos #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6     12
    171  1.1  christos 
    172  1.1  christos static const struct tok lspping_tlvtargetfec_subtlv_values[] = {
    173  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4, "LDP IPv4 prefix"},
    174  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6, "LDP IPv6 prefix"},
    175  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4, "RSVP IPv4 Session Query"},
    176  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6, "RSVP IPv6 Session Query"},
    177  1.1  christos     { 5, "Reserved"},
    178  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4, "VPN IPv4 prefix"},
    179  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6, "VPN IPv6 prefix"},
    180  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT, "L2 VPN endpoint"},
    181  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID_OLD, "L2 circuit ID (old)"},
    182  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID, "L2 circuit ID"},
    183  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4, "BGP labeled IPv4 prefix"},
    184  1.1  christos     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6, "BGP labeled IPv6 prefix"},
    185  1.1  christos     { 0, NULL}
    186  1.1  christos };
    187  1.1  christos 
    188  1.1  christos /*
    189  1.1  christos  *  0                   1                   2                   3
    190  1.1  christos  *  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
    191  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    192  1.1  christos  * |                          IPv4 prefix                          |
    193  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    194  1.1  christos  * | Prefix Length |         Must Be Zero                          |
    195  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    196  1.1  christos  */
    197  1.1  christos struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t {
    198  1.1  christos     u_int8_t prefix [4];
    199  1.1  christos     u_int8_t prefix_len;
    200  1.1  christos };
    201  1.1  christos 
    202  1.1  christos /*
    203  1.1  christos  *  0                   1                   2                   3
    204  1.1  christos  *  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
    205  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    206  1.1  christos  * |                          IPv6 prefix                          |
    207  1.1  christos  * |                          (16 octets)                          |
    208  1.1  christos  * |                                                               |
    209  1.1  christos  * |                                                               |
    210  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    211  1.1  christos  * | Prefix Length |         Must Be Zero                          |
    212  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    213  1.1  christos  */
    214  1.1  christos struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t {
    215  1.1  christos     u_int8_t prefix [16];
    216  1.1  christos     u_int8_t prefix_len;
    217  1.1  christos };
    218  1.1  christos 
    219  1.1  christos /*
    220  1.1  christos  * 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
    221  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    222  1.1  christos  * |                    Sender identifier                          |
    223  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    224  1.1  christos  * |                         IPv4 prefix                           |
    225  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    226  1.1  christos  * | Prefix Length |                 Must Be Zero                  |
    227  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    228  1.1  christos  */
    229  1.1  christos struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t {
    230  1.1  christos     u_int8_t sender_id [4];
    231  1.1  christos     u_int8_t prefix [4];
    232  1.1  christos     u_int8_t prefix_len;
    233  1.1  christos };
    234  1.1  christos 
    235  1.1  christos /*
    236  1.1  christos  * 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
    237  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    238  1.1  christos  * |                    Sender identifier                          |
    239  1.1  christos  * |                          (16 octets)                          |
    240  1.1  christos  * |                                                               |
    241  1.1  christos  * |                                                               |
    242  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    243  1.1  christos  * |                          IPv6 prefix                          |
    244  1.1  christos  * |                          (16 octets)                          |
    245  1.1  christos  * |                                                               |
    246  1.1  christos  * |                                                               |
    247  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    248  1.1  christos  * | Prefix Length |                 Must Be Zero                  |
    249  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    250  1.1  christos  */
    251  1.1  christos struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t {
    252  1.1  christos     u_int8_t sender_id [16];
    253  1.1  christos     u_int8_t prefix [16];
    254  1.1  christos     u_int8_t prefix_len;
    255  1.1  christos };
    256  1.1  christos 
    257  1.1  christos /*
    258  1.1  christos  *  0                   1                   2                   3
    259  1.1  christos  *  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
    260  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    261  1.1  christos  * |                 IPv4 tunnel end point address                 |
    262  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    263  1.1  christos  * |          Must Be Zero         |     Tunnel ID                 |
    264  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    265  1.1  christos  * |                       Extended Tunnel ID                      |
    266  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    267  1.1  christos  * |                   IPv4 tunnel sender address                  |
    268  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    269  1.1  christos  * |          Must Be Zero         |            LSP ID             |
    270  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    271  1.1  christos  */
    272  1.1  christos struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t {
    273  1.1  christos     u_int8_t tunnel_endpoint [4];
    274  1.1  christos     u_int8_t res[2];
    275  1.1  christos     u_int8_t tunnel_id[2];
    276  1.1  christos     u_int8_t extended_tunnel_id[4];
    277  1.1  christos     u_int8_t tunnel_sender [4];
    278  1.1  christos     u_int8_t res2[2];
    279  1.1  christos     u_int8_t lsp_id [2];
    280  1.1  christos };
    281  1.1  christos 
    282  1.1  christos /*
    283  1.1  christos  *  0                   1                   2                   3
    284  1.1  christos  *  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
    285  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    286  1.1  christos  * |                 IPv6 tunnel end point address                 |
    287  1.1  christos  * |                                                               |
    288  1.1  christos  * |                                                               |
    289  1.1  christos  * |                                                               |
    290  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    291  1.1  christos  * |          Must Be Zero         |          Tunnel ID            |
    292  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    293  1.1  christos  * |                       Extended Tunnel ID                      |
    294  1.1  christos  * |                                                               |
    295  1.1  christos  * |                                                               |
    296  1.1  christos  * |                                                               |
    297  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    298  1.1  christos  * |                   IPv6 tunnel sender address                  |
    299  1.1  christos  * |                                                               |
    300  1.1  christos  * |                                                               |
    301  1.1  christos  * |                                                               |
    302  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    303  1.1  christos  * |          Must Be Zero         |            LSP ID             |
    304  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    305  1.1  christos  */
    306  1.1  christos struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t {
    307  1.1  christos     u_int8_t tunnel_endpoint [16];
    308  1.1  christos     u_int8_t res[2];
    309  1.1  christos     u_int8_t tunnel_id[2];
    310  1.1  christos     u_int8_t extended_tunnel_id[16];
    311  1.1  christos     u_int8_t tunnel_sender [16];
    312  1.1  christos     u_int8_t res2[2];
    313  1.1  christos     u_int8_t lsp_id [2];
    314  1.1  christos };
    315  1.1  christos 
    316  1.1  christos /*
    317  1.1  christos  *  0                   1                   2                   3
    318  1.1  christos  *  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
    319  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    320  1.1  christos  * |                      Route Distinguisher                      |
    321  1.1  christos  * |                          (8 octets)                           |
    322  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    323  1.1  christos  * |                         IPv4 prefix                           |
    324  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    325  1.1  christos  * | Prefix Length |                 Must Be Zero                  |
    326  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    327  1.1  christos  */
    328  1.1  christos struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t {
    329  1.1  christos     u_int8_t rd [8];
    330  1.1  christos     u_int8_t prefix [4];
    331  1.1  christos     u_int8_t prefix_len;
    332  1.1  christos };
    333  1.1  christos 
    334  1.1  christos /*
    335  1.1  christos  *  0                   1                   2                   3
    336  1.1  christos  *  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
    337  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    338  1.1  christos  * |                      Route Distinguisher                      |
    339  1.1  christos  * |                          (8 octets)                           |
    340  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    341  1.1  christos  * |                          IPv6 prefix                          |
    342  1.1  christos  * |                          (16 octets)                          |
    343  1.1  christos  * |                                                               |
    344  1.1  christos  * |                                                               |
    345  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    346  1.1  christos  * | Prefix Length |                 Must Be Zero                  |
    347  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    348  1.1  christos  */
    349  1.1  christos struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t {
    350  1.1  christos     u_int8_t rd [8];
    351  1.1  christos     u_int8_t prefix [16];
    352  1.1  christos     u_int8_t prefix_len;
    353  1.1  christos };
    354  1.1  christos 
    355  1.1  christos /*
    356  1.1  christos  *  0                   1                   2                   3
    357  1.1  christos  *  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
    358  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    359  1.1  christos  * |                      Route Distinguisher                      |
    360  1.1  christos  * |                          (8 octets)                           |
    361  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    362  1.1  christos  * |         Sender's CE ID        |       Receiver's CE ID        |
    363  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    364  1.1  christos  * |      Encapsulation Type       |         Must Be Zero          |
    365  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    366  1.1  christos  *  0                   1                   2                   3
    367  1.1  christos  */
    368  1.1  christos struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t {
    369  1.1  christos     u_int8_t rd [8];
    370  1.1  christos     u_int8_t sender_ce_id [2];
    371  1.1  christos     u_int8_t receiver_ce_id [2];
    372  1.1  christos     u_int8_t encapsulation[2];
    373  1.1  christos };
    374  1.1  christos 
    375  1.1  christos /*
    376  1.1  christos  *  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
    377  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    378  1.1  christos  * |                      Remote PE Address                        |
    379  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    380  1.1  christos  * |                             VC ID                             |
    381  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    382  1.1  christos  * |      Encapsulation Type       |         Must Be Zero          |
    383  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    384  1.1  christos  */
    385  1.1  christos struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t {
    386  1.1  christos     u_int8_t remote_pe_address [4];
    387  1.1  christos     u_int8_t vc_id [4];
    388  1.1  christos     u_int8_t encapsulation[2];
    389  1.1  christos };
    390  1.1  christos 
    391  1.1  christos /*
    392  1.1  christos  *  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
    393  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    394  1.1  christos  * |                     Sender's PE Address                       |
    395  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    396  1.1  christos  * |                      Remote PE Address                        |
    397  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    398  1.1  christos  * |                             VC ID                             |
    399  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    400  1.1  christos  * |      Encapsulation Type       |         Must Be Zero          |
    401  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    402  1.1  christos  */
    403  1.1  christos struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t {
    404  1.1  christos     u_int8_t sender_pe_address [4];
    405  1.1  christos     u_int8_t remote_pe_address [4];
    406  1.1  christos     u_int8_t vc_id [4];
    407  1.1  christos     u_int8_t encapsulation[2];
    408  1.1  christos };
    409  1.1  christos 
    410  1.1  christos /*
    411  1.1  christos  *  0                   1                   2                   3
    412  1.1  christos  *  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
    413  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    414  1.1  christos  * |               MTU             | Address Type  |  Resvd (SBZ)  |
    415  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    416  1.1  christos  * |             Downstream IP Address (4 or 16 octets)            |
    417  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    418  1.1  christos  * |         Downstream Interface Address (4 or 16 octets)         |
    419  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    420  1.1  christos  * | Hash Key Type | Depth Limit   |        Multipath Length       |
    421  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    422  1.1  christos  * .                                                               .
    423  1.1  christos  * .                     (Multipath Information)                   .
    424  1.1  christos  * .                                                               .
    425  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    426  1.1  christos  * |               Downstream Label                |    Protocol   |
    427  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    428  1.1  christos  * .                                                               .
    429  1.1  christos  * .                                                               .
    430  1.1  christos  * .                                                               .
    431  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    432  1.1  christos  * |               Downstream Label                |    Protocol   |
    433  1.1  christos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    434  1.1  christos  */
    435  1.1  christos struct lspping_tlv_downstream_map_ipv4_t {
    436  1.1  christos     u_int8_t mtu [2];
    437  1.1  christos     u_int8_t address_type;
    438  1.1  christos     u_int8_t res;
    439  1.1  christos     u_int8_t downstream_ip[4];
    440  1.1  christos     u_int8_t downstream_interface[4];
    441  1.1  christos };
    442  1.1  christos 
    443  1.1  christos struct lspping_tlv_downstream_map_ipv6_t {
    444  1.1  christos     u_int8_t mtu [2];
    445  1.1  christos     u_int8_t address_type;
    446  1.1  christos     u_int8_t res;
    447  1.1  christos     u_int8_t downstream_ip[16];
    448  1.1  christos     u_int8_t downstream_interface[16];
    449  1.1  christos };
    450  1.1  christos 
    451  1.1  christos struct lspping_tlv_downstream_map_info_t {
    452  1.1  christos     u_int8_t hash_key_type;
    453  1.1  christos     u_int8_t depth_limit;
    454  1.1  christos     u_int8_t multipath_length [2];
    455  1.1  christos };
    456  1.1  christos 
    457  1.1  christos #define LSPPING_AFI_IPV4 1
    458  1.1  christos #define LSPPING_AFI_UNMB 2
    459  1.1  christos #define LSPPING_AFI_IPV6 3
    460  1.1  christos 
    461  1.1  christos static const struct tok lspping_tlv_downstream_addr_values[] = {
    462  1.1  christos     { LSPPING_AFI_IPV4, "IPv4"},
    463  1.1  christos     { LSPPING_AFI_IPV6, "IPv6"},
    464  1.1  christos     { LSPPING_AFI_UNMB, "Unnumbered"},
    465  1.1  christos     { 0, NULL}
    466  1.1  christos };
    467  1.1  christos 
    468  1.1  christos void
    469  1.1  christos lspping_print(register const u_char *pptr, register u_int len) {
    470  1.1  christos 
    471  1.1  christos     const struct lspping_common_header *lspping_com_header;
    472  1.1  christos     const struct lspping_tlv_header *lspping_tlv_header;
    473  1.1  christos     const struct lspping_tlv_header *lspping_subtlv_header;
    474  1.1  christos     const u_char *tptr,*tlv_tptr,*subtlv_tptr;
    475  1.1  christos     int tlen,lspping_tlv_len,lspping_tlv_type,tlv_tlen;
    476  1.1  christos     int tlv_hexdump,subtlv_hexdump;
    477  1.1  christos     int lspping_subtlv_len,lspping_subtlv_type;
    478  1.1  christos     struct timeval timestamp;
    479  1.1  christos 
    480  1.1  christos     union {
    481  1.1  christos         const struct lspping_tlv_downstream_map_ipv4_t *lspping_tlv_downstream_map_ipv4;
    482  1.1  christos         const struct lspping_tlv_downstream_map_ipv6_t *lspping_tlv_downstream_map_ipv6;
    483  1.1  christos         const struct lspping_tlv_downstream_map_info_t  *lspping_tlv_downstream_map_info;
    484  1.1  christos     } tlv_ptr;
    485  1.1  christos 
    486  1.1  christos     union {
    487  1.1  christos         const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *lspping_tlv_targetfec_subtlv_ldp_ipv4;
    488  1.1  christos         const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *lspping_tlv_targetfec_subtlv_ldp_ipv6;
    489  1.1  christos         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *lspping_tlv_targetfec_subtlv_rsvp_ipv4;
    490  1.1  christos         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *lspping_tlv_targetfec_subtlv_rsvp_ipv6;
    491  1.1  christos         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv4;
    492  1.1  christos         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv6;
    493  1.1  christos         const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *lspping_tlv_targetfec_subtlv_l2vpn_endpt;
    494  1.1  christos         const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t *lspping_tlv_targetfec_subtlv_l2vpn_vcid_old;
    495  1.1  christos         const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t *lspping_tlv_targetfec_subtlv_l2vpn_vcid;
    496  1.1  christos         const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *lspping_tlv_targetfec_subtlv_bgp_ipv4;
    497  1.1  christos         const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *lspping_tlv_targetfec_subtlv_bgp_ipv6;
    498  1.1  christos     } subtlv_ptr;
    499  1.1  christos 
    500  1.1  christos     tptr=pptr;
    501  1.1  christos     lspping_com_header = (const struct lspping_common_header *)pptr;
    502  1.1  christos     TCHECK(*lspping_com_header);
    503  1.1  christos 
    504  1.1  christos     /*
    505  1.1  christos      * Sanity checking of the header.
    506  1.1  christos      */
    507  1.1  christos     if (EXTRACT_16BITS(&lspping_com_header->version[0]) != LSPPING_VERSION) {
    508  1.1  christos 	printf("LSP-PING version %u packet not supported",
    509  1.1  christos                EXTRACT_16BITS(&lspping_com_header->version[0]));
    510  1.1  christos 	return;
    511  1.1  christos     }
    512  1.1  christos 
    513  1.1  christos     /* in non-verbose mode just lets print the basic Message Type*/
    514  1.1  christos     if (vflag < 1) {
    515  1.1  christos         printf("LSP-PINGv%u, %s, seq %u, length: %u",
    516  1.1  christos                EXTRACT_16BITS(&lspping_com_header->version[0]),
    517  1.1  christos                tok2str(lspping_msg_type_values, "unknown (%u)",lspping_com_header->msg_type),
    518  1.1  christos                EXTRACT_32BITS(lspping_com_header->seq_number),
    519  1.1  christos                len);
    520  1.1  christos         return;
    521  1.1  christos     }
    522  1.1  christos 
    523  1.1  christos     /* ok they seem to want to know everything - lets fully decode it */
    524  1.1  christos 
    525  1.1  christos     tlen=len;
    526  1.1  christos 
    527  1.1  christos     printf("\n\tLSP-PINGv%u, msg-type: %s (%u), length: %u\n\t  reply-mode: %s (%u)",
    528  1.1  christos            EXTRACT_16BITS(&lspping_com_header->version[0]),
    529  1.1  christos            tok2str(lspping_msg_type_values, "unknown",lspping_com_header->msg_type),
    530  1.1  christos            lspping_com_header->msg_type,
    531  1.1  christos            len,
    532  1.1  christos            tok2str(lspping_reply_mode_values, "unknown",lspping_com_header->reply_mode),
    533  1.1  christos            lspping_com_header->reply_mode);
    534  1.1  christos 
    535  1.1  christos     /*
    536  1.1  christos      *  the following return codes require that the subcode is attached
    537  1.1  christos      *  at the end of the translated token output
    538  1.1  christos      */
    539  1.1  christos     if (lspping_com_header->return_code == 3 ||
    540  1.1  christos         lspping_com_header->return_code == 4 ||
    541  1.1  christos         lspping_com_header->return_code == 8 ||
    542  1.1  christos         lspping_com_header->return_code == 10 ||
    543  1.1  christos         lspping_com_header->return_code == 11 ||
    544  1.1  christos         lspping_com_header->return_code == 12 )
    545  1.1  christos         printf("\n\t  Return Code: %s %u (%u)\n\t  Return Subcode: (%u)",
    546  1.1  christos                tok2str(lspping_return_code_values, "unknown",lspping_com_header->return_code),
    547  1.1  christos                lspping_com_header->return_subcode,
    548  1.1  christos                lspping_com_header->return_code,
    549  1.1  christos                lspping_com_header->return_subcode);
    550  1.1  christos     else
    551  1.1  christos         printf("\n\t  Return Code: %s (%u)\n\t  Return Subcode: (%u)",
    552  1.1  christos                tok2str(lspping_return_code_values, "unknown",lspping_com_header->return_code),
    553  1.1  christos                lspping_com_header->return_code,
    554  1.1  christos                lspping_com_header->return_subcode);
    555  1.1  christos 
    556  1.1  christos     printf("\n\t  Sender Handle: 0x%08x, Sequence: %u",
    557  1.1  christos            EXTRACT_32BITS(lspping_com_header->sender_handle),
    558  1.1  christos            EXTRACT_32BITS(lspping_com_header->seq_number));
    559  1.1  christos 
    560  1.1  christos     timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_sent_sec);
    561  1.1  christos     timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_sent_usec);
    562  1.1  christos     printf("\n\t  Sender Timestamp: ");
    563  1.1  christos     ts_print(&timestamp);
    564  1.1  christos 
    565  1.1  christos     timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_sec);
    566  1.1  christos     timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_usec);
    567  1.1  christos     printf("Receiver Timestamp: ");
    568  1.1  christos     if ((timestamp.tv_sec != 0) && (timestamp.tv_usec != 0))
    569  1.1  christos         ts_print(&timestamp);
    570  1.1  christos     else
    571  1.1  christos         printf("no timestamp");
    572  1.1  christos 
    573  1.1  christos     tptr+=sizeof(const struct lspping_common_header);
    574  1.1  christos     tlen-=sizeof(const struct lspping_common_header);
    575  1.1  christos 
    576  1.1  christos     while(tlen>(int)sizeof(struct lspping_tlv_header)) {
    577  1.1  christos 
    578  1.1  christos         /* did we capture enough for fully decoding the tlv header ? */
    579  1.1  christos         if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
    580  1.1  christos             goto trunc;
    581  1.1  christos 
    582  1.1  christos         lspping_tlv_header = (const struct lspping_tlv_header *)tptr;
    583  1.1  christos         lspping_tlv_type=EXTRACT_16BITS(lspping_tlv_header->type);
    584  1.1  christos         lspping_tlv_len=EXTRACT_16BITS(lspping_tlv_header->length);
    585  1.1  christos 
    586  1.1  christos         /* some little sanity checking */
    587  1.1  christos         if (lspping_tlv_type == 0 || lspping_tlv_len == 0)
    588  1.1  christos             return;
    589  1.1  christos 
    590  1.1  christos         if(lspping_tlv_len < 4) {
    591  1.1  christos             printf("\n\t  ERROR: TLV %u bogus size %u",lspping_tlv_type,lspping_tlv_len);
    592  1.1  christos             return;
    593  1.1  christos         }
    594  1.1  christos 
    595  1.1  christos         printf("\n\t  %s TLV (%u), length: %u",
    596  1.1  christos                tok2str(lspping_tlv_values,
    597  1.1  christos                        "Unknown",
    598  1.1  christos                        lspping_tlv_type),
    599  1.1  christos                lspping_tlv_type,
    600  1.1  christos                lspping_tlv_len);
    601  1.1  christos 
    602  1.1  christos         tlv_tptr=tptr+sizeof(struct lspping_tlv_header);
    603  1.1  christos         tlv_tlen=lspping_tlv_len; /* header not included -> no adjustment */
    604  1.1  christos 
    605  1.1  christos         /* did we capture enough for fully decoding the tlv ? */
    606  1.1  christos         if (!TTEST2(*tptr, lspping_tlv_len))
    607  1.1  christos             goto trunc;
    608  1.1  christos         tlv_hexdump=FALSE;
    609  1.1  christos 
    610  1.1  christos         switch(lspping_tlv_type) {
    611  1.1  christos         case LSPPING_TLV_TARGET_FEC_STACK:
    612  1.1  christos             while(tlv_tlen>(int)sizeof(struct lspping_tlv_header)) {
    613  1.1  christos 
    614  1.1  christos                 /* did we capture enough for fully decoding the subtlv header ? */
    615  1.1  christos                 if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
    616  1.1  christos                     goto trunc;
    617  1.1  christos                 subtlv_hexdump=FALSE;
    618  1.1  christos 
    619  1.1  christos                 lspping_subtlv_header = (const struct lspping_tlv_header *)tlv_tptr;
    620  1.1  christos                 lspping_subtlv_type=EXTRACT_16BITS(lspping_subtlv_header->type);
    621  1.1  christos                 lspping_subtlv_len=EXTRACT_16BITS(lspping_subtlv_header->length);
    622  1.1  christos                 subtlv_tptr=tlv_tptr+sizeof(struct lspping_tlv_header);
    623  1.1  christos 
    624  1.1  christos                 if (lspping_subtlv_len == 0)
    625  1.1  christos                     break;
    626  1.1  christos 
    627  1.1  christos                 printf("\n\t    %s subTLV (%u), length: %u",
    628  1.1  christos                        tok2str(lspping_tlvtargetfec_subtlv_values,
    629  1.1  christos                                "Unknown",
    630  1.1  christos                                lspping_subtlv_type),
    631  1.1  christos                        lspping_subtlv_type,
    632  1.1  christos                        lspping_subtlv_len);
    633  1.1  christos 
    634  1.1  christos                 switch(lspping_subtlv_type) {
    635  1.1  christos 
    636  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4:
    637  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4 = \
    638  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *)subtlv_tptr;
    639  1.1  christos                     printf("\n\t      %s/%u",
    640  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix),
    641  1.1  christos                            subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix_len);
    642  1.1  christos                     break;
    643  1.1  christos 
    644  1.1  christos #ifdef INET6
    645  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6:
    646  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6 = \
    647  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *)subtlv_tptr;
    648  1.1  christos                     printf("\n\t      %s/%u",
    649  1.1  christos                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix),
    650  1.1  christos                            subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix_len);
    651  1.1  christos                     break;
    652  1.1  christos #endif
    653  1.1  christos 
    654  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4:
    655  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4 = \
    656  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *)subtlv_tptr;
    657  1.1  christos                     printf("\n\t      %s/%u, sender-id %s",
    658  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix),
    659  1.1  christos                            subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix_len,
    660  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->sender_id));
    661  1.1  christos                     break;
    662  1.1  christos 
    663  1.1  christos #ifdef INET6
    664  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6:
    665  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6 = \
    666  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *)subtlv_tptr;
    667  1.1  christos                     printf("\n\t      %s/%u, sender-id %s",
    668  1.1  christos                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix),
    669  1.1  christos                            subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix_len,
    670  1.1  christos                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->sender_id));
    671  1.1  christos                     break;
    672  1.1  christos #endif
    673  1.1  christos 
    674  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4:
    675  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4 = \
    676  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *)subtlv_tptr;
    677  1.1  christos                     printf("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x" \
    678  1.1  christos                            "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
    679  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_endpoint),
    680  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_sender),
    681  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->lsp_id),
    682  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_id),
    683  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->extended_tunnel_id));
    684  1.1  christos                     break;
    685  1.1  christos 
    686  1.1  christos #ifdef INET6
    687  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6:
    688  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6 = \
    689  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *)subtlv_tptr;
    690  1.1  christos                     printf("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x" \
    691  1.1  christos                            "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
    692  1.1  christos                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_endpoint),
    693  1.1  christos                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_sender),
    694  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->lsp_id),
    695  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_id),
    696  1.1  christos                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->extended_tunnel_id));
    697  1.1  christos                     break;
    698  1.1  christos #endif
    699  1.1  christos 
    700  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4:
    701  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4 = \
    702  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *)subtlv_tptr;
    703  1.1  christos                     printf("\n\t      RD: %s, %s/%u",
    704  1.1  christos                            bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->rd),
    705  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix),
    706  1.1  christos                            subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix_len);
    707  1.1  christos                     break;
    708  1.1  christos 
    709  1.1  christos #ifdef INET6
    710  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6:
    711  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6 = \
    712  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *)subtlv_tptr;
    713  1.1  christos                     printf("\n\t      RD: %s, %s/%u",
    714  1.1  christos                            bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->rd),
    715  1.1  christos                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix),
    716  1.1  christos                            subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix_len);
    717  1.1  christos                     break;
    718  1.1  christos #endif
    719  1.1  christos 
    720  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT:
    721  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt = \
    722  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *)subtlv_tptr;
    723  1.1  christos                     printf("\n\t      RD: %s, Sender CE-ID: %u, Receiver CE-ID: %u" \
    724  1.1  christos                            "\n\t      Encapsulation Type: %s (%u)",
    725  1.1  christos                            bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->rd),
    726  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->sender_ce_id),
    727  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->receiver_ce_id),
    728  1.1  christos                            tok2str(l2vpn_encaps_values,
    729  1.1  christos                                    "unknown",
    730  1.1  christos                                    EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
    731  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation));
    732  1.1  christos 
    733  1.1  christos                     break;
    734  1.1  christos 
    735  1.1  christos                     /* the old L2VPN VCID subTLV does not have support for the sender field */
    736  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID_OLD:
    737  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old = \
    738  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t *)subtlv_tptr;
    739  1.1  christos                     printf("\n\t      Remote PE: %s" \
    740  1.1  christos                            "\n\t      VC-ID: 0x%08x, Encapsulation Type: %s (%u)",
    741  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->remote_pe_address),
    742  1.1  christos                            EXTRACT_32BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->vc_id),
    743  1.1  christos                            tok2str(l2vpn_encaps_values,
    744  1.1  christos                                    "unknown",
    745  1.1  christos                                    EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->encapsulation)),
    746  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->encapsulation));
    747  1.1  christos 
    748  1.1  christos                     break;
    749  1.1  christos 
    750  1.1  christos                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID:
    751  1.1  christos                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid = \
    752  1.1  christos                         (const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t *)subtlv_tptr;
    753  1.1  christos                     printf("\n\t      Sender PE: %s, Remote PE: %s" \
    754  1.1  christos                            "\n\t      VC-ID: 0x%08x, Encapsulation Type: %s (%u)",
    755  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->sender_pe_address),
    756  1.1  christos                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->remote_pe_address),
    757  1.1  christos                            EXTRACT_32BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->vc_id),
    758  1.1  christos                            tok2str(l2vpn_encaps_values,
    759  1.1  christos                                    "unknown",
    760  1.1  christos                                    EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->encapsulation)),
    761  1.1  christos                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->encapsulation));
    762  1.1  christos 
    763  1.1  christos                     break;
    764  1.1  christos 
    765  1.1  christos                 default:
    766  1.1  christos                     subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
    767  1.1  christos                     break;
    768  1.1  christos                 }
    769  1.1  christos                 /* do we want to see an additionally subtlv hexdump ? */
    770  1.1  christos                 if (vflag > 1 || subtlv_hexdump==TRUE)
    771  1.1  christos                     print_unknown_data(tlv_tptr+sizeof(struct lspping_tlv_header), \
    772  1.1  christos                                        "\n\t      ",
    773  1.1  christos                                        lspping_subtlv_len);
    774  1.1  christos 
    775  1.1  christos                 tlv_tptr+=lspping_subtlv_len;
    776  1.1  christos                 tlv_tlen-=lspping_subtlv_len+sizeof(struct lspping_tlv_header);
    777  1.1  christos             }
    778  1.1  christos             break;
    779  1.1  christos 
    780  1.1  christos         case LSPPING_TLV_DOWNSTREAM_MAPPING:
    781  1.1  christos             /* that strange thing with the downstream map TLV is that until now
    782  1.1  christos              * we do not know if its IPv4 or IPv6 , after we found the adress-type
    783  1.1  christos              * lets recast the tlv_tptr and move on */
    784  1.1  christos 
    785  1.1  christos             tlv_ptr.lspping_tlv_downstream_map_ipv4= \
    786  1.1  christos                 (const struct lspping_tlv_downstream_map_ipv4_t *)tlv_tptr;
    787  1.1  christos             tlv_ptr.lspping_tlv_downstream_map_ipv6= \
    788  1.1  christos                 (const struct lspping_tlv_downstream_map_ipv6_t *)tlv_tptr;
    789  1.1  christos             printf("\n\t    MTU: %u, Address-Type: %s (%u)",
    790  1.1  christos                    EXTRACT_16BITS(tlv_ptr.lspping_tlv_downstream_map_ipv4->mtu),
    791  1.1  christos                    tok2str(lspping_tlv_downstream_addr_values,
    792  1.1  christos                            "unknown",
    793  1.1  christos                            tlv_ptr.lspping_tlv_downstream_map_ipv4->address_type),
    794  1.1  christos                    tlv_ptr.lspping_tlv_downstream_map_ipv4->address_type);
    795  1.1  christos 
    796  1.1  christos             switch(tlv_ptr.lspping_tlv_downstream_map_ipv4->address_type) {
    797  1.1  christos 
    798  1.1  christos             case LSPPING_AFI_IPV4:
    799  1.1  christos                 printf("\n\t    Downstream IP: %s" \
    800  1.1  christos                        "\n\t    Downstream Interface IP: %s",
    801  1.1  christos                        ipaddr_string(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_ip),
    802  1.1  christos                        ipaddr_string(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_interface));
    803  1.1  christos                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
    804  1.1  christos                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
    805  1.1  christos                 break;
    806  1.1  christos #ifdef INET6
    807  1.1  christos              case LSPPING_AFI_IPV6:
    808  1.1  christos                 printf("\n\t    Downstream IP: %s" \
    809  1.1  christos                        "\n\t    Downstream Interface IP: %s",
    810  1.1  christos                        ip6addr_string(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_ip),
    811  1.1  christos                        ip6addr_string(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_interface));
    812  1.1  christos                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
    813  1.1  christos                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
    814  1.1  christos                 break;
    815  1.1  christos #endif
    816  1.1  christos             case LSPPING_AFI_UNMB:
    817  1.1  christos                 printf("\n\t    Downstream IP: %s" \
    818  1.1  christos                        "\n\t    Downstream Interface Index: 0x%08x",
    819  1.1  christos                        ipaddr_string(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_ip),
    820  1.1  christos                        EXTRACT_32BITS(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_interface));
    821  1.1  christos                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
    822  1.1  christos                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
    823  1.1  christos                 break;
    824  1.1  christos 
    825  1.1  christos             default:
    826  1.1  christos                 /* should not happen ! - no error message - tok2str() has barked already */
    827  1.1  christos                 break;
    828  1.1  christos             }
    829  1.1  christos 
    830  1.1  christos             tlv_ptr.lspping_tlv_downstream_map_info= \
    831  1.1  christos                 (const struct lspping_tlv_downstream_map_info_t *)tlv_tptr;
    832  1.1  christos 
    833  1.1  christos             /* FIXME add hash-key type, depth limit, multipath processing */
    834  1.1  christos 
    835  1.1  christos 
    836  1.1  christos             tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_info_t);
    837  1.1  christos             tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_info_t);
    838  1.1  christos 
    839  1.1  christos             /* FIXME print downstream labels */
    840  1.1  christos 
    841  1.1  christos 
    842  1.1  christos             tlv_hexdump=TRUE; /* dump the TLV until code complete */
    843  1.1  christos 
    844  1.1  christos             break;
    845  1.1  christos 
    846  1.1  christos         case LSPPING_TLV_BFD_DISCRIMINATOR:
    847  1.1  christos             tptr += sizeof(struct lspping_tlv_header);
    848  1.1  christos             if (!TTEST2(*tptr, LSPPING_TLV_BFD_DISCRIMINATOR_LEN))
    849  1.1  christos                 goto trunc;
    850  1.1  christos             printf("\n\t    BFD Discriminator 0x%08x", EXTRACT_32BITS(tptr));
    851  1.1  christos             break;
    852  1.1  christos 
    853  1.1  christos         case  LSPPING_TLV_VENDOR_ENTERPRISE:
    854  1.1  christos         {
    855  1.1  christos             u_int32_t vendor_id;
    856  1.1  christos 
    857  1.1  christos             if (!TTEST2(*tptr, LSPPING_TLV_VENDOR_ENTERPRISE_LEN))
    858  1.1  christos                 goto trunc;
    859  1.1  christos             vendor_id = EXTRACT_32BITS(tlv_tptr);
    860  1.1  christos             printf("\n\t    Vendor: %s (0x%04x)",
    861  1.1  christos                    tok2str(smi_values, "Unknown", vendor_id),
    862  1.1  christos                    vendor_id);
    863  1.1  christos         }
    864  1.1  christos             break;
    865  1.1  christos 
    866  1.1  christos             /*
    867  1.1  christos              *  FIXME those are the defined TLVs that lack a decoder
    868  1.1  christos              *  you are welcome to contribute code ;-)
    869  1.1  christos              */
    870  1.1  christos         case LSPPING_TLV_PAD:
    871  1.1  christos         case LSPPING_TLV_ERROR_CODE:
    872  1.1  christos         case LSPPING_TLV_VENDOR_PRIVATE:
    873  1.1  christos 
    874  1.1  christos         default:
    875  1.1  christos             if (vflag <= 1)
    876  1.1  christos                 print_unknown_data(tlv_tptr,"\n\t    ",tlv_tlen);
    877  1.1  christos             break;
    878  1.1  christos         }
    879  1.1  christos         /* do we want to see an additionally tlv hexdump ? */
    880  1.1  christos         if (vflag > 1 || tlv_hexdump==TRUE)
    881  1.1  christos             print_unknown_data(tptr+sizeof(sizeof(struct lspping_tlv_header)),"\n\t    ",
    882  1.1  christos                                lspping_tlv_len);
    883  1.1  christos 
    884  1.1  christos 
    885  1.1  christos         /* All TLVs are aligned to four octet boundary */
    886  1.1  christos         if (lspping_tlv_len % 4) {
    887  1.1  christos             lspping_tlv_len += (4 - lspping_tlv_len % 4);
    888  1.1  christos         }
    889  1.1  christos 
    890  1.1  christos         tptr+=lspping_tlv_len+sizeof(struct lspping_tlv_header);
    891  1.1  christos         tlen-=lspping_tlv_len+sizeof(struct lspping_tlv_header);
    892  1.1  christos     }
    893  1.1  christos     return;
    894  1.1  christos trunc:
    895  1.1  christos     printf("\n\t\t packet exceeded snapshot");
    896  1.1  christos }
    897