aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-mpls-mac.c
blob: 13b14ea243248d9fa7f8e42f4a2cc664dd67dfe6 (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/* packet-mpls-mac.c
 *
 * Routines for MPLS Media Access Control (MAC) Address Withdrawal over Static Pseudowire.
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include "packet-mpls.h"

void proto_register_mpls_mac(void);
void proto_reg_handoff_mpls_mac(void);

static gint proto_mpls_mac = -1;

static gint ett_mpls_mac = -1;
static gint ett_mpls_mac_flags = -1;
static gint ett_mpls_mac_tlv = -1;

static int hf_mpls_mac_reserved = -1;
static int hf_mpls_mac_tlv_length_total = -1;
static int hf_mpls_mac_flags = -1;
static int hf_mpls_mac_flags_a = -1;
static int hf_mpls_mac_flags_r = -1;
static int hf_mpls_mac_flags_reserved = -1;
static int hf_mpls_mac_tlv = -1;
static int hf_mpls_mac_tlv_res = -1;
static int hf_mpls_mac_tlv_type = -1;
static int hf_mpls_mac_tlv_length = -1;
static int hf_mpls_mac_tlv_value = -1;
static int hf_mpls_mac_tlv_sequence_number = -1;


static int * const mpls_mac_flags[] = {
  &hf_mpls_mac_flags_a,
  &hf_mpls_mac_flags_r,
  &hf_mpls_mac_flags_reserved,
  NULL
};

static int
dissect_mpls_mac(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    proto_item *ti;
    proto_tree *mac_tree;
    guint32     offset = 0, tlv_length, offset_end;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-MAC");
    col_clear(pinfo->cinfo, COL_INFO);

    ti = proto_tree_add_item(tree, proto_mpls_mac, tvb, 0, -1, ENC_NA);
    mac_tree = proto_item_add_subtree(ti, ett_mpls_mac);
    /* Reserved */
    proto_tree_add_item(mac_tree, hf_mpls_mac_reserved, tvb, offset, 2, ENC_NA);
    offset += 2;
    /* TLV length */
    proto_tree_add_item_ret_uint(mac_tree, hf_mpls_mac_tlv_length_total, tvb, offset, 1, ENC_BIG_ENDIAN, &tlv_length);
    offset += 1;
    /* Flags */
    proto_tree_add_bitmask(mac_tree, tvb, offset, hf_mpls_mac_flags,
                         ett_mpls_mac_flags,
                         mpls_mac_flags,
                         ENC_BIG_ENDIAN);
    offset += 1;
    offset_end = offset + tlv_length;

    while(offset < offset_end){
        guint32 type, length;
        proto_tree *tlv_tree;

        ti = proto_tree_add_item(mac_tree, hf_mpls_mac_tlv, tvb, offset, 4, ENC_NA);

        tlv_tree = proto_item_add_subtree(ti, ett_mpls_mac_tlv);
        /* res(erved) */
        proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_res, tvb, offset, 2, ENC_BIG_ENDIAN);

        /* TLV Type */
        proto_tree_add_item_ret_uint(tlv_tree, hf_mpls_mac_tlv_type, tvb, offset, 2, ENC_BIG_ENDIAN, &type);
        offset += 2;

        /* TLV Length */
        proto_tree_add_item_ret_uint(tlv_tree, hf_mpls_mac_tlv_length, tvb, offset, 2, ENC_BIG_ENDIAN, &length);
        offset += 2;
        proto_item_set_len(ti, 2+2+length);
        proto_item_append_text(ti, " (t=0x%x, l=%u)", type, length);

        /* TLV Value */
        proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_value, tvb, offset, length, ENC_NA);

        switch(type){
            case 0x0001:
                proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_sequence_number, tvb, offset, 4, ENC_BIG_ENDIAN);
                offset += 4;
            break;
            default:
                offset += length;
            break;
        }

    }
    return offset;
}

void
proto_register_mpls_mac(void)
{
    static hf_register_info hf[] = {
        {
            &hf_mpls_mac_reserved,
            {
                "Reserved", "mpls_mac.reserved",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_tlv_length_total,
            {
                "TLV Length (Total)", "mpls_mac.tlv_length_total",
                FT_UINT8, BASE_DEC, NULL, 0x0,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_flags,
            {
                "Flags", "mpls_mac.flags",
                FT_UINT8, BASE_HEX, NULL, 0x0,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_flags_a,
            {
                "Flags A", "mpls_mac.flags.a",
                FT_BOOLEAN, 8, NULL, 0x80,
                "set by a receiver to acknowledge receipt and processing of a MAC Address Withdraw OAM Message", HFILL
            }
        },
        {
            &hf_mpls_mac_flags_r,
            {
                "Flags R", "mpls_mac.flags.r",
                FT_BOOLEAN, 8, NULL, 0x40,
                "Set to indicate if the sender is requesting reset of the sequence numbers", HFILL
            }
        },
        {
            &hf_mpls_mac_flags_reserved,
            {
                "Flags Reserved", "mpls_mac.flags.reserved",
                FT_UINT8, BASE_HEX, NULL, 0x3F,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_tlv,
            {
                "TLV", "mpls_mac.tlv",
                FT_NONE, BASE_NONE, NULL, 0x0,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_tlv_res,
            {
                "Res(erved)", "mpls_mac.tlv.res",
                FT_UINT16, BASE_HEX, NULL, 0xC000,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_tlv_type,
            {
                "TLV Type", "mpls_mac.tlv.type",
                FT_UINT16, BASE_HEX, NULL, 0x3FFF,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_tlv_length,
            {
                "TLV Length", "mpls_mac.tlv.length",
                FT_UINT16, BASE_DEC, NULL, 0x0,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_tlv_value,
            {
                "TLV Value", "mpls_mac.tlv.value",
                FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL
            }
        },
        {
            &hf_mpls_mac_tlv_sequence_number,
            {
                "Sequence Number", "mpls_mac.tlv.sequence_number",
                FT_UINT32, BASE_DEC, NULL, 0x0,
                NULL, HFILL
            }
        },
    };

    static gint *ett[] = {
        &ett_mpls_mac,
        &ett_mpls_mac_flags,
        &ett_mpls_mac_tlv,
    };

    proto_mpls_mac =
        proto_register_protocol("MPLS-MAC",
                                "Media Access Control (MAC) Address Withdrawal over Static Pseudowire",
                                "mpls_mac");

    proto_register_field_array(proto_mpls_mac, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_mpls_mac(void)
{
    dissector_handle_t mpls_mac_handle;

    mpls_mac_handle    = create_dissector_handle( dissect_mpls_mac, proto_mpls_mac );
    dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_MAC, mpls_mac_handle);
}

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