Skip to content

Commit 0a8da6e

Browse files
authored
Merge pull request #162 from BonnyAD9/export-vlan-id
Add vlan plugin
2 parents 078207e + 1578e2a commit 0a8da6e

File tree

14 files changed

+227
-3
lines changed

14 files changed

+227
-3
lines changed

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,16 @@ ipfixprobe_stats
9999
ipfixprobe-*.tar.gz
100100

101101
# Test Outputs
102-
tests/*.log
103-
tests/*.trs
102+
tests/*/*.log
103+
tests/*/*.trs
104104
tests/output/
105+
tests/functional/output
106+
# Unit test binaries
107+
tests/unit/byte_utils
108+
tests/unit/flowifc
109+
tests/unit/options
110+
tests/unit/unirec
111+
tests/unit/utils
105112

106113
# Mac Finder metafile
107114
**/.DS_Store

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ ipfixprobe_process_src=\
129129
process/ssadetector.cpp \
130130
process/icmp.hpp \
131131
process/icmp.cpp \
132+
process/vlan.hpp \
133+
process/vlan.cpp \
132134
process/nettisa.hpp \
133135
process/nettisa.cpp
134136

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,14 @@ The detector search for the SYN SYN-ACK ACK pattern in packet lengths. Multiple
635635
|:------------------:|:------:|:---------------------------------------:|
636636
| SSA_CONF_LEVEL | uint8 | 1 if SSA sequence detected, 0 otherwise |
637637

638+
### VLAN
639+
640+
List of fields exported together with basic flow fields on the interface by VLAN plugin.
641+
642+
| Output field | Type | Description |
643+
|:------------:|:------:|:--------------------------:|
644+
| VLAN_ID | uint16 | Vlan ID (used in flow key) |
645+
638646
## Simplified function diagram
639647
Diagram below shows how `ipfixprobe` works.
640648

include/ipfixprobe/ipfix-elements.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ namespace ipxp {
8383

8484
#define ETHERTYPE(F) F(0, 256, 2, nullptr)
8585

86+
#define VLAN_ID(F) F(0, 58, 2, nullptr)
87+
8688
#define L2_SRC_MAC(F) F(0, 56, 6, flow.src_mac)
8789
#define L2_DST_MAC(F) F(0, 80, 6, flow.dst_mac)
8890

@@ -509,6 +511,9 @@ namespace ipxp {
509511
#define IPFIX_ICMP_TEMPLATE(F) \
510512
F(L4_ICMP_TYPE_CODE)
511513

514+
#define IPFIX_VLAN_TEMPLATE(F) \
515+
F(VLAN_ID)
516+
512517
#define IPFIX_NETTISA_TEMPLATE(F) \
513518
F(NTS_MEAN) \
514519
F(NTS_MIN) \
@@ -523,7 +528,7 @@ namespace ipxp {
523528
F(NTS_MAX_DIFFTIMES) \
524529
F(NTS_TIME_DISTRIBUTION) \
525530
F(NTS_SWITCHING_RATIO)
526-
531+
527532
#ifdef WITH_FLEXPROBE
528533
#define IPFIX_FLEXPROBE_DATA_TEMPLATE(F) F(FX_FRAME_SIGNATURE) F(FX_INPUT_INTERFACE)
529534
#define IPFIX_FLEXPROBE_TCP_TEMPLATE(F) F(FX_TCP_TRACKING)

include/ipfixprobe/options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <stdexcept>
3636
#include <string>
3737
#include <iostream>
38+
#include <cstdint>
3839

3940
namespace ipxp {
4041

include/ipfixprobe/utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <utility>
3838
#include <algorithm>
3939
#include <stdexcept>
40+
#include <cstdint>
4041

4142
namespace ipxp {
4243

pcaps/vlan.pcap

1.41 KB
Binary file not shown.

process/create_plugin.sh

100644100755
File mode changed.

process/vlan.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* \file vlan.cpp
3+
* \brief Plugin for parsing vlan traffic.
4+
* \author Jakub Antonín Štigler xstigl00@[email protected]
5+
* \date 2023
6+
*/
7+
/*
8+
* Copyright (C) 2023 CESNET
9+
*
10+
* LICENSE TERMS
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions
14+
* are met:
15+
* 1. Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright
18+
* notice, this list of conditions and the following disclaimer in
19+
* the documentation and/or other materials provided with the
20+
* distribution.
21+
* 3. Neither the name of the Company nor the names of its contributors
22+
* may be used to endorse or promote products derived from this
23+
* software without specific prior written permission.
24+
*
25+
*
26+
*
27+
*/
28+
29+
#include <iostream>
30+
31+
#include "vlan.hpp"
32+
33+
namespace ipxp {
34+
35+
int RecordExtVLAN::REGISTERED_ID = -1;
36+
37+
__attribute__((constructor)) static void register_this_plugin()
38+
{
39+
static PluginRecord rec = PluginRecord("vlan", [](){return new VLANPlugin();});
40+
register_plugin(&rec);
41+
RecordExtVLAN::REGISTERED_ID = register_extension();
42+
}
43+
44+
ProcessPlugin *VLANPlugin::copy()
45+
{
46+
return new VLANPlugin(*this);
47+
}
48+
49+
int VLANPlugin::post_create(Flow &rec, const Packet &pkt)
50+
{
51+
auto ext = new RecordExtVLAN();
52+
ext->vlan_id = pkt.vlan_id;
53+
rec.add_extension(ext);
54+
return 0;
55+
}
56+
57+
}
58+

process/vlan.hpp

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* \file vlan.hpp
3+
* \brief Plugin for parsing vlan traffic.
4+
* \author Jakub Antonín Štigler xstigl00@[email protected]
5+
* \date 2023
6+
*/
7+
/*
8+
* Copyright (C) 2023 CESNET
9+
*
10+
* LICENSE TERMS
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions
14+
* are met:
15+
* 1. Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright
18+
* notice, this list of conditions and the following disclaimer in
19+
* the documentation and/or other materials provided with the
20+
* distribution.
21+
* 3. Neither the name of the Company nor the names of its contributors
22+
* may be used to endorse or promote products derived from this
23+
* software without specific prior written permission.
24+
*
25+
*
26+
*
27+
*/
28+
29+
#ifndef IPXP_PROCESS_VLAN_HPP
30+
#define IPXP_PROCESS_VLAN_HPP
31+
32+
#include <cstring>
33+
34+
#ifdef WITH_NEMEA
35+
#include "fields.h"
36+
#endif
37+
38+
#include <ipfixprobe/process.hpp>
39+
#include <ipfixprobe/flowifc.hpp>
40+
#include <ipfixprobe/packet.hpp>
41+
#include <ipfixprobe/ipfix-elements.hpp>
42+
43+
#include <cstdint>
44+
#include <string>
45+
#include <sstream>
46+
47+
namespace ipxp {
48+
49+
#define VLAN_UNIREC_TEMPLATE "VLAN_ID"
50+
51+
UR_FIELDS (
52+
uint16 VLAN_ID
53+
)
54+
55+
/**
56+
* \brief Flow record extension header for storing parsed VLAN data.
57+
*/
58+
struct RecordExtVLAN : public RecordExt {
59+
static int REGISTERED_ID;
60+
61+
// vlan id is in the host byte order
62+
uint16_t vlan_id;
63+
64+
RecordExtVLAN() : RecordExt(REGISTERED_ID), vlan_id(0)
65+
{
66+
}
67+
68+
#ifdef WITH_NEMEA
69+
virtual void fill_unirec(ur_template_t *tmplt, void *record)
70+
{
71+
ur_set(tmplt, record, F_VLAN_ID, vlan_id);
72+
}
73+
74+
const char *get_unirec_tmplt() const
75+
{
76+
return VLAN_UNIREC_TEMPLATE;
77+
}
78+
#endif
79+
80+
virtual int fill_ipfix(uint8_t *buffer, int size)
81+
{
82+
const int LEN = sizeof(vlan_id);
83+
84+
if (size < LEN) {
85+
return -1;
86+
}
87+
88+
*reinterpret_cast<uint16_t *>(buffer) = htons(vlan_id);
89+
return 0;
90+
}
91+
92+
const char **get_ipfix_tmplt() const
93+
{
94+
static const char *ipfix_template[] = {
95+
IPFIX_VLAN_TEMPLATE(IPFIX_FIELD_NAMES)
96+
NULL
97+
};
98+
return ipfix_template;
99+
}
100+
101+
std::string get_text() const
102+
{
103+
std::ostringstream out;
104+
out << "vlan_id=\"" << vlan_id << '"';
105+
return out.str();
106+
}
107+
};
108+
109+
/**
110+
* \brief Process plugin for parsing VLAN packets.
111+
*/
112+
class VLANPlugin : public ProcessPlugin
113+
{
114+
public:
115+
OptionsParser *get_parser() const { return new OptionsParser("vlan", "Parse VLAN traffic"); }
116+
std::string get_name() const { return "vlan"; }
117+
RecordExt *get_ext() const { return new RecordExtVLAN(); }
118+
ProcessPlugin *copy();
119+
120+
int post_create(Flow &rec, const Packet &pkt);
121+
};
122+
123+
}
124+
#endif /* IPXP_PROCESS_VLAN_HPP */
125+

0 commit comments

Comments
 (0)