Coverage Report

Created: 2025-08-04 07:15

/src/wireshark/epan/dissectors/packet-pktgen.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-pktgen.c
2
 * Routines for "Linux pktgen" dissection
3
 * Copyright 2006 _FF_
4
 * Francesco Fondelli <francesco dot fondelli, gmail dot com>
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 * Copyright 1998 Gerald Combs
9
 *
10
 * SPDX-License-Identifier: GPL-2.0-or-later
11
 */
12
13
/* FF:
14
 * The linux packet generator is a tool to generate packets at very high speed in the kernel.
15
 * See linux/net/core/pktgen.c and linux/Documentation/networking/pktgen.txt for more info.
16
 */
17
18
#include "config.h"
19
20
#include <epan/packet.h>
21
22
void proto_register_pktgen(void);
23
void proto_reg_handoff_pktgen(void);
24
25
/* magic num used for heuristic */
26
798
#define PKTGEN_MAGIC 0xbe9be955
27
28
/* Initialize the protocol and registered fields */
29
static int proto_pktgen;
30
31
/* pktgen header */
32
static int hf_pktgen_magic;
33
static int hf_pktgen_seqnum;
34
static int hf_pktgen_tvsec;
35
static int hf_pktgen_tvusec;
36
static int hf_pktgen_timestamp;
37
38
/* Initialize the subtree pointer */
39
static int ett_pktgen;
40
41
/* entry point */
42
static bool dissect_pktgen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
43
1.47k
{
44
1.47k
    proto_item *ti          = NULL;
45
1.47k
    proto_item *tmp         = NULL;
46
1.47k
    proto_tree *pktgen_tree = NULL;
47
1.47k
    uint32_t    offset      = 0;
48
1.47k
    nstime_t    tstamp;
49
1.47k
    uint32_t    magic;
50
51
    /* check for min size */
52
1.47k
    if (tvb_reported_length(tvb) < 16) {  /* Not a PKTGEN packet. */
53
672
        return false;
54
672
    }
55
56
    /* check for magic number */
57
798
    magic = tvb_get_ntohl(tvb,0);
58
798
    if (magic != PKTGEN_MAGIC) {
59
        /* Not a PKTGEN packet. */
60
798
        return false;
61
798
    }
62
63
64
    /* Make entries in Protocol column and Info column on summary display */
65
66
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PKTGEN");
67
68
0
    col_add_fstr(pinfo->cinfo, COL_INFO, "Seq: %u", tvb_get_ntohl(tvb, 4));
69
70
0
    if (tree) {
71
72
        /* create display subtree for the protocol */
73
74
0
        ti = proto_tree_add_item(tree, proto_pktgen, tvb, 0, -1, ENC_NA);
75
76
0
        pktgen_tree = proto_item_add_subtree(ti, ett_pktgen);
77
78
        /* add items to the subtree */
79
80
0
        proto_tree_add_item(pktgen_tree, hf_pktgen_magic, tvb, offset, 4, ENC_BIG_ENDIAN);
81
0
        offset += 4;
82
83
0
        proto_tree_add_item(pktgen_tree, hf_pktgen_seqnum, tvb, offset, 4, ENC_BIG_ENDIAN);
84
0
        offset += 4;
85
86
0
        tstamp.secs = tvb_get_ntohl(tvb, offset);
87
0
        tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvsec, tvb, offset, 4, ENC_BIG_ENDIAN);
88
0
        proto_item_set_generated(tmp);
89
0
        offset += 4;
90
91
0
        tstamp.nsecs = tvb_get_ntohl(tvb, offset) /* microsecond on the wire so... */ * 1000;
92
0
        tmp = proto_tree_add_item(pktgen_tree, hf_pktgen_tvusec, tvb, offset, 4, ENC_BIG_ENDIAN);
93
0
        proto_item_set_generated(tmp);
94
0
        offset += 4;
95
96
0
        proto_tree_add_time(pktgen_tree, hf_pktgen_timestamp, tvb, offset - 8, 8, &tstamp);
97
98
0
        if (tvb_reported_length_remaining(tvb, offset)) /* random data */
99
0
            call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo,
100
0
            pktgen_tree);
101
0
    }
102
103
0
    return true;
104
798
}
105
106
107
/* Register the protocol with Wireshark */
108
void proto_register_pktgen(void)
109
14
{
110
    /* Setup list of header fields */
111
112
14
    static hf_register_info hf[] = {
113
114
14
        { &hf_pktgen_magic,
115
14
          {
116
14
              "Magic number", "pktgen.magic",
117
14
              FT_UINT32, BASE_HEX, NULL, 0x0,
118
14
              "The pktgen magic number", HFILL
119
14
          }
120
14
        },
121
122
14
        { &hf_pktgen_seqnum,
123
14
          {
124
14
              "Sequence number", "pktgen.seqnum",
125
14
              FT_UINT32, BASE_DEC, NULL, 0x0,
126
14
              NULL, HFILL
127
14
          }
128
14
        },
129
130
14
        { &hf_pktgen_tvsec,
131
14
          {
132
14
              "Timestamp tvsec", "pktgen.tvsec",
133
14
              FT_UINT32, BASE_DEC, NULL, 0x0,
134
14
              "Timestamp tvsec part", HFILL
135
14
          }
136
14
        },
137
138
14
        { &hf_pktgen_tvusec,
139
14
          {
140
14
              "Timestamp tvusec", "pktgen.tvusec",
141
14
              FT_UINT32, BASE_DEC, NULL, 0x0,
142
14
              "Timestamp tvusec part", HFILL
143
14
          }
144
14
        },
145
146
14
        { &hf_pktgen_timestamp,
147
14
          {
148
14
              "Timestamp", "pktgen.timestamp",
149
14
              FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
150
14
              NULL, HFILL
151
14
          }
152
14
        }
153
14
    };
154
155
    /* Setup protocol subtree array */
156
157
14
    static int *ett[] = {
158
14
        &ett_pktgen
159
14
    };
160
161
    /* Register the protocol name and description */
162
163
14
    proto_pktgen = proto_register_protocol("Linux Kernel Packet Generator", "PKTGEN", "pktgen");
164
165
    /* Required function calls to register the header fields and subtrees used */
166
167
14
    proto_register_field_array(proto_pktgen, hf, array_length(hf));
168
14
    proto_register_subtree_array(ett, array_length(ett));
169
14
}
170
171
172
void proto_reg_handoff_pktgen(void)
173
14
{
174
    /* Register as a heuristic UDP dissector */
175
14
    heur_dissector_add("udp", dissect_pktgen, "Linux Kernel Packet Generator over UDP", "pktgen_udp", proto_pktgen, HEURISTIC_ENABLE);
176
14
}
177
178
179
/*
180
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
181
 *
182
 * Local variables:
183
 * c-basic-offset: 4
184
 * tab-width: 8
185
 * indent-tabs-mode: nil
186
 * End:
187
 *
188
 * vi: set shiftwidth=4 tabstop=8 expandtab:
189
 * :indentSize=4:tabSize=8:noTabs=true:
190
 */