summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ipnet.c
blob: 6e47db3213b7679215e6d519ad889018798f21c1 (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
/* packet-ipnet.c
 * Routines for decoding Solaris IPNET packet disassembly
 *
 * 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 <epan/aftypes.h>
#include <wiretap/wtap.h>

void proto_register_ipnet(void);
void proto_reg_handoff_ipnet(void);

static int proto_ipnet   = -1;
static int hf_version    = -1;
static int hf_family     = -1;
static int hf_htype      = -1;
static int hf_pktlen     = -1;
static int hf_ifindex    = -1;
static int hf_grifindex  = -1;
static int hf_zsrc       = -1;
static int hf_zdst       = -1;

static gint ett_raw = -1;

static dissector_handle_t ipnet_handle;
static dissector_handle_t ip_handle;
static dissector_handle_t ipv6_handle;

static const value_string solaris_family_vals[] = {
  { SOLARIS_AF_INET,  "Solaris AF_INET"  },
  { SOLARIS_AF_INET6, "Solaris AF_INET6" },
  { 0, NULL }
};

static const value_string htype_vals[] = {
  { 0, "Inbound"  },
  { 1, "Outbound" },
  { 2, "Local"    },
  { 0, NULL }
};

static int
dissect_ipnet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
  proto_tree *fh_tree;
  proto_item *ti;
  tvbuff_t *next_tvb;
  guint32 pktlen;
  guint8 family;

  /* load the top pane info. This should be overwritten by
     the next protocol in the stack */
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPNET");
  col_set_str(pinfo->cinfo, COL_INFO, "Solaris IPNET");

  /* populate a tree in the second pane with the IPNET header data */
  if(tree) {
    ti = proto_tree_add_item (tree, proto_ipnet, tvb, 0, 24, ENC_NA);
    fh_tree = proto_item_add_subtree(ti, ett_raw);

    proto_tree_add_item(fh_tree, hf_version, tvb, 0, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(fh_tree, hf_family, tvb, 1, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(fh_tree, hf_htype, tvb, 2, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(fh_tree, hf_pktlen, tvb, 4, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(fh_tree, hf_ifindex, tvb, 8, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(fh_tree, hf_grifindex, tvb, 12, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(fh_tree, hf_zsrc, tvb, 16, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(fh_tree, hf_zdst, tvb, 20, 4, ENC_BIG_ENDIAN);
  }

  pktlen = tvb_get_ntohl(tvb, 4);
  next_tvb = tvb_new_subset_remaining(tvb, tvb_captured_length(tvb) - pktlen);

  family = tvb_get_guint8(tvb, 1);
  switch (family) {
  case SOLARIS_AF_INET:
    call_dissector(ip_handle, next_tvb, pinfo, tree);
    break;
  case SOLARIS_AF_INET6:
    call_dissector(ipv6_handle, next_tvb, pinfo, tree);
    break;
  default:
    break;
  }
  return tvb_captured_length(tvb);
}

void
proto_register_ipnet(void)
{
  static hf_register_info hf[] = {
    { &hf_version,      { "Header version",             "ipnet.version",
      FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},

    { &hf_family,       { "Address family",             "ipnet.family",
      FT_UINT8, BASE_DEC, VALS(solaris_family_vals), 0x0, NULL, HFILL }},

    { &hf_htype,        { "Hook type",                  "ipnet.htype",
      FT_UINT16, BASE_DEC, VALS(htype_vals), 0x0, NULL, HFILL }},

    { &hf_pktlen,       { "Data length",                "ipnet.pktlen",
      FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},

    { &hf_ifindex,      { "Interface index",            "ipnet.ifindex",
      FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},

    { &hf_grifindex,    { "Group interface index",      "ipnet.grifindex",
      FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},

    { &hf_zsrc,         { "Source Zone ID",             "ipnet.zsrc",
      FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},

    { &hf_zdst,         { "Destination Zone ID",        "ipnet.zdst",
      FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
  };
  static gint *ett[] = {
    &ett_raw,
  };

  proto_ipnet = proto_register_protocol("Solaris IPNET", "IPNET", "ipnet");
  proto_register_field_array(proto_ipnet, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));
  ipnet_handle = register_dissector("ipnet", dissect_ipnet, proto_ipnet);
}

void
proto_reg_handoff_ipnet(void)
{
  /*
   * Get handles for the IP and IPv6 dissectors.
   */
  ip_handle = find_dissector_add_dependency("ip", proto_ipnet);
  ipv6_handle = find_dissector_add_dependency("ipv6", proto_ipnet);

  dissector_add_uint("wtap_encap", WTAP_ENCAP_IPNET, ipnet_handle);
}

/*
 * Editor modelines  -  https://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:
 */