@@ -38,8 +38,7 @@ use Socket;
3838use NetAddr::IP qw ( :lower) ;
3939use 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
4443use FindBin qw( $Bin) ;
4544use 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