Home | History | Annotate | Download | only in tcpdump
      1 /*
      2  * Copyright (c) 1998-2007 The TCPDUMP project
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that: (1) source code
      6  * distributions retain the above copyright notice and this paragraph
      7  * in its entirety, and (2) distributions including binary code include
      8  * the above copyright notice and this paragraph in its entirety in
      9  * the documentation or other materials provided with the distribution.
     10  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
     11  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
     12  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     13  * FOR A PARTICULAR PURPOSE.
     14  *
     15  * Dynamic Trunk Protocol (DTP)
     16  *
     17  * Original code by Carles Kishimoto <carles.kishimoto (at) gmail.com>
     18  */
     19 
     20 #define NETDISSECT_REWORKED
     21 #ifdef HAVE_CONFIG_H
     22 #include "config.h"
     23 #endif
     24 
     25 #include <tcpdump-stdinc.h>
     26 
     27 #include "interface.h"
     28 #include "addrtoname.h"
     29 #include "extract.h"
     30 
     31 #define DTP_HEADER_LEN			1
     32 #define DTP_DOMAIN_TLV			0x0001
     33 #define DTP_STATUS_TLV			0x0002
     34 #define DTP_DTP_TYPE_TLV		0x0003
     35 #define DTP_NEIGHBOR_TLV		0x0004
     36 
     37 static const struct tok dtp_tlv_values[] = {
     38     { DTP_DOMAIN_TLV, "Domain TLV"},
     39     { DTP_STATUS_TLV, "Status TLV"},
     40     { DTP_DTP_TYPE_TLV, "DTP type TLV"},
     41     { DTP_NEIGHBOR_TLV, "Neighbor TLV"},
     42     { 0, NULL}
     43 };
     44 
     45 void
     46 dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
     47 {
     48     int type, len;
     49     const u_char *tptr;
     50 
     51     if (length < DTP_HEADER_LEN)
     52         goto trunc;
     53 
     54     tptr = pptr;
     55 
     56     ND_TCHECK2(*tptr, DTP_HEADER_LEN);
     57 
     58     ND_PRINT((ndo, "DTPv%u, length %u",
     59            (*tptr),
     60            length));
     61 
     62     /*
     63      * In non-verbose mode, just print version.
     64      */
     65     if (ndo->ndo_vflag < 1) {
     66 	return;
     67     }
     68 
     69     tptr += DTP_HEADER_LEN;
     70 
     71     while (tptr < (pptr+length)) {
     72 
     73         ND_TCHECK2(*tptr, 4);
     74 
     75 	type = EXTRACT_16BITS(tptr);
     76         len  = EXTRACT_16BITS(tptr+2);
     77 
     78         /* infinite loop check */
     79         if (type == 0 || len == 0) {
     80             return;
     81         }
     82 
     83         ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
     84                tok2str(dtp_tlv_values, "Unknown", type),
     85                type, len));
     86 
     87         switch (type) {
     88 	case DTP_DOMAIN_TLV:
     89 		ND_PRINT((ndo, ", %s", tptr+4));
     90 		break;
     91 
     92 	case DTP_STATUS_TLV:
     93 	case DTP_DTP_TYPE_TLV:
     94                 ND_PRINT((ndo, ", 0x%x", *(tptr+4)));
     95                 break;
     96 
     97 	case DTP_NEIGHBOR_TLV:
     98                 ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4)));
     99                 break;
    100 
    101         default:
    102             break;
    103         }
    104         tptr += len;
    105     }
    106 
    107     return;
    108 
    109  trunc:
    110     ND_PRINT((ndo, "[|dtp]"));
    111 }
    112 
    113 /*
    114  * Local Variables:
    115  * c-style: whitesmith
    116  * c-basic-offset: 4
    117  * End:
    118  */
    119