aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-cisco-marker.c
blob: 4d2fda2809324cf27a69145ce8c4240ba65c9aea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* packet-cisco-marker.c
 * Routines for CISCO's ERSPAN3 Marker Packet
 * See: http://www.cisco.com/c/en/us/products/collateral/switches/nexus-9000-series-switches/white-paper-c11-733921.html#_Toc413144488
 * Copyright 2015, Peter Membrey
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-time.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#define NEW_PROTO_TREE_API

#include "config.h"

#include <epan/packet.h>

void proto_register_erspan_marker(void);
void proto_reg_handoff_erspan_marker(void);
void proto_register_erpsan_marker(void);


static dissector_handle_t marker_handle;

static header_field_info *hfi_marker = NULL;


#define CISCO_ERSPAN_MARKER_HFI_INIT HFI_INIT(proto_marker)

static header_field_info cisco_erspan_prop_header CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Proprietary CISCO Header", "cisco_erspan_marker.prop_header",
  FT_BYTES, BASE_NONE, NULL, 0x0,
  NULL, HFILL };

static header_field_info cisco_erspan_info CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Header", "cisco_erspan_marker.header",
  FT_BOOLEAN, 8, NULL, 0x0,
  NULL, HFILL };

static header_field_info cisco_erspan_version CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Version", "cisco_erspan_marker.version",
  FT_UINT16, BASE_DEC, NULL, 0x0f00,
  NULL, HFILL };

static header_field_info cisco_erspan_type CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Type", "cisco_erspan_marker.type",
  FT_UINT16, BASE_DEC, NULL, 0xf000,
  NULL, HFILL };

static header_field_info cisco_erspan_ssid CISCO_ERSPAN_MARKER_HFI_INIT =
{ "SSID", "cisco_erspan_marker.ssid",
  FT_UINT16, BASE_DEC, NULL, 0x00ff,
  NULL, HFILL };

static header_field_info cisco_erspan_granularity CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Granularity", "cisco_erspan_marker.granularity",
  FT_UINT16, BASE_DEC, NULL, 0xff00,
  NULL, HFILL };

static header_field_info cisco_erspan_utcoffset CISCO_ERSPAN_MARKER_HFI_INIT =
{ "UTC Offset", "cisco_erspan_marker.utc_offset",
  FT_UINT16, BASE_DEC, NULL, 0x00ff,
  NULL, HFILL };

static header_field_info cisco_erspan_timestamp CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Timestamp", "cisco_erspan_marker.timestamp",
  FT_UINT32, BASE_DEC, NULL, 0xffffffff,
  NULL, HFILL };

static header_field_info cisco_erspan_utc_sec CISCO_ERSPAN_MARKER_HFI_INIT =
{ "UTC Seconds", "cisco_erspan_marker.utc_sec",
  FT_UINT32, BASE_DEC, NULL, 0xffffffff,
  NULL, HFILL };

static header_field_info cisco_erspan_utc_usec CISCO_ERSPAN_MARKER_HFI_INIT =
{ "UTC Microseconds", "cisco_erspan_marker.utc_usec",
  FT_UINT32, BASE_DEC, NULL, 0xffffffff,
  NULL, HFILL };

static header_field_info cisco_erspan_sequence_number CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Sequence Number", "cisco_erspan_marker.sequence_number",
  FT_UINT32, BASE_DEC, NULL, 0xffffffff,
  NULL, HFILL };

static header_field_info cisco_erspan_reserved CISCO_ERSPAN_MARKER_HFI_INIT =
{ "Reserved", "cisco_erspan_marker.sequence_number",
  FT_UINT32, BASE_DEC, NULL, 0xffffffff,
  NULL, HFILL };

static header_field_info cisco_erspan_tail CISCO_ERSPAN_MARKER_HFI_INIT =
{ "TAIL", "cisco_erspan_marker.tail",
  FT_UINT32, BASE_DEC, NULL, 0xffffffff,
  NULL, HFILL };





static gint ett_marker = -1;


static int
dissect_marker(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
  proto_tree    *marker_tree;
  proto_item    *ti;

  col_set_str(pinfo->cinfo, COL_PROTOCOL, "CISCO ERSPAN3 MARKER");


  if (tree) {

    /* Skip the proprietary CISCO header - no docs have been released for this */
    guint32 offset = 20;

    ti = proto_tree_add_item(tree, hfi_marker, tvb, 0, -1, ENC_NA);
    marker_tree = proto_item_add_subtree(ti, ett_marker);

    proto_tree_add_item(marker_tree, &cisco_erspan_prop_header, tvb, 0, 20, ENC_LITTLE_ENDIAN);
    proto_tree_add_item(marker_tree, &cisco_erspan_info, tvb, offset, 2, ENC_LITTLE_ENDIAN);
    offset += 2;

    proto_tree_add_item(marker_tree, &cisco_erspan_version, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(marker_tree, &cisco_erspan_type, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(marker_tree, &cisco_erspan_ssid, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(marker_tree, &cisco_erspan_granularity, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(marker_tree, &cisco_erspan_utcoffset, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset+= 2;

    proto_tree_add_item(marker_tree, &cisco_erspan_timestamp, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;

    proto_tree_add_item(marker_tree, &cisco_erspan_utc_sec, tvb, offset, 4, ENC_LITTLE_ENDIAN);
    offset+=4;

    proto_tree_add_item(marker_tree, &cisco_erspan_utc_usec, tvb, offset, 4, ENC_LITTLE_ENDIAN);
    offset+=4;

    proto_tree_add_item(marker_tree, &cisco_erspan_sequence_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
    offset+=4;

    proto_tree_add_item(marker_tree, &cisco_erspan_reserved, tvb, offset, 4, ENC_LITTLE_ENDIAN);
    offset+=4;

    proto_tree_add_item(marker_tree, &cisco_erspan_tail, tvb, offset, 4, ENC_LITTLE_ENDIAN);
  }
  return tvb_captured_length(tvb);
}


void
proto_register_erpsan_marker(void)
{


#ifndef HAVE_HFI_SECTION_INIT
  static header_field_info *hfi[] = {
    &cisco_erspan_prop_header,
    &cisco_erspan_info,
    &cisco_erspan_version,
    &cisco_erspan_type,
    &cisco_erspan_ssid,
    &cisco_erspan_granularity,
    &cisco_erspan_utcoffset,
    &cisco_erspan_timestamp,
    &cisco_erspan_utc_sec,
    &cisco_erspan_utc_usec,
    &cisco_erspan_sequence_number,
    &cisco_erspan_reserved,
    &cisco_erspan_tail
  };
#endif

  static gint *ett[] = {
    &ett_marker,
  };

  int proto_marker;



  proto_marker = proto_register_protocol("CISCO ERSPAN3 Marker Packet", "CISCO3 ERSPAN MARKER", "cisco-erspan3-marker");

  hfi_marker = proto_registrar_get_nth(proto_marker);

  proto_register_fields(proto_marker, hfi, array_length(hfi));
  proto_register_subtree_array(ett, array_length(ett));

  marker_handle = create_dissector_handle(dissect_marker, proto_marker);
}

void
proto_reg_handoff_erspan_marker(void)
{
  dissector_add_for_decode_as("udp.port", marker_handle);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local Variables:
 * c-basic-offset: 2
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=2 tabstop=8 expandtab:
 * :indentSize=2:tabSize=8:noTabs=true:
 */