Skip to content

Commit

Permalink
Add VLAN and agent address, fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
jbemmel committed Apr 27, 2023
1 parent ab4e437 commit a478c11
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tools/runtime/sflow/goflow2-detect-ixp-bgp-sessions
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ use Socket;
use NetAddr::IP qw (:lower);
use Time::HiRes qw(ualarm gettimeofday tv_interval);

# To install: cpanm JSON::Tiny
use JSON::Tiny qw(decode_json);
use JSON qw(decode_json);

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

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

if ($ethertype eq '0x0800') {
$ipprotocol = 4;
Expand All @@ -130,9 +130,9 @@ while (<SFLOWTOOL>) {
next;
}

my $protocol = $sample->{ Proto }
my $srcport = $sample->{ SrcPort }
my $dstport = $sample->{ DstPort }
my $protocol = $sample->{ Proto };
my $srcport = $sample->{ SrcPort };
my $dstport = $sample->{ DstPort };

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

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

0 comments on commit a478c11

Please sign in to comment.