Skip to content

Commit a478c11

Browse files
committed
Add VLAN and agent address, fix typos
1 parent ab4e437 commit a478c11

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tools/runtime/sflow/goflow2-detect-ixp-bgp-sessions

100644100755
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ use Socket;
3838
use NetAddr::IP qw (:lower);
3939
use Time::HiRes qw(ualarm gettimeofday tv_interval);
4040

41-
# To install: cpanm JSON::Tiny
42-
use JSON::Tiny qw(decode_json);
41+
use JSON qw(decode_json);
4342

4443
use FindBin qw($Bin);
4544
use File::Spec;
@@ -115,10 +114,11 @@ while (<SFLOWTOOL>) {
115114
# $srcip, $dstip, $protocol, $tos, $ttl,
116115
# $srcport, $dstport, $tcpflags, $pktsize, $payloadsize, $samplerate) = @sample;
117116

118-
# SrcAddr,DstAddr,Etype,Proto,SrcPort,DstPort,TCPFlags
119-
my $ethertype = $sample->{ Etype }
120-
my $srcip = $sample->{ SrcAddr }
121-
my $dstip = $sample->{ DstAddr }
117+
# SrcAddr,DstAddr,Etype,Proto,SrcPort,DstPort,TCPFlags,SamplerAddress,VlanId
118+
# see https://github.com/netsampler/goflow2/blob/main/docs/protocols.md for more fields
119+
my $ethertype = $sample->{ Etype };
120+
my $srcip = $sample->{ SrcAddr };
121+
my $dstip = $sample->{ DstAddr };
122122

123123
if ($ethertype eq '0x0800') {
124124
$ipprotocol = 4;
@@ -130,9 +130,9 @@ while (<SFLOWTOOL>) {
130130
next;
131131
}
132132

133-
my $protocol = $sample->{ Proto }
134-
my $srcport = $sample->{ SrcPort }
135-
my $dstport = $sample->{ DstPort }
133+
my $protocol = $sample->{ Proto };
134+
my $srcport = $sample->{ SrcPort };
135+
my $dstport = $sample->{ DstPort };
136136

137137
# BGP data is protocol 6 (tcp) and one port == 179
138138
if ($protocol == 6 && ($srcport == 179 || $dstport == 179)) {
@@ -147,6 +147,8 @@ while (<SFLOWTOOL>) {
147147
}
148148

149149
# we're also only interested in ip addresses that have a database match
150+
my $agent = $sample->{ SamplerAddress };
151+
my $vlan = $sample->{ VlanId };
150152
if ($ipmappings->{$ipprotocol}->{$srcip} && $ipmappings->{$ipprotocol}->{$dstip}) {
151153
print STDERR " database updated" if ($debug);
152154
if (!$sth->execute($ipmappings->{$ipprotocol}->{$srcip}, $ipmappings->{$ipprotocol}->{$dstip}, $ipprotocol, $vlan, $agent)) {

0 commit comments

Comments
 (0)