Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions scripts/vyatta-netflow.pl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ sub acct_conf_globals {
$output .= "aggregate: tag,src_mac,dst_mac,vlan,src_host,dst_host";
$output .= ",src_port,dst_port,proto,tos,flows";

if (-e '/etc/pmacct/networks.lst') {
my $uacctd_as = $config->returnValue('system flow-accounting generate-asn');

if (defined $uacctd_as) {
$output .= ",src_as,dst_as\n";
$output .= "networks_file: /etc/pmacct/networks.lst\n";
$output .= "uacctd_as: $uacctd_as\n";
$output .= $uacctd_as eq 'file' ? "networks_file: /etc/pmacct/networks.lst\n" : "bgp_daemon: true\nbgp_agent_map: /etc/pmacct/agent_to_peer.map\n"
} else {
$output .= "\n";
}
Expand Down Expand Up @@ -274,6 +277,27 @@ sub acct_get_sflow {
return $output;
}

sub acct_get_bgp_daemon {
my ($config) = @_;

my $path = 'system flow-accounting';
my $output = undef;

$config->setLevel($path);
return $output if !$config->exists('bgp-daemon');

$config->setLevel("$path bgp-daemon");
my $bgp_ip = $config->returnValue('ip');
my $bgp_port = $config->returnValue('port');
my $bgp_max_peers = $config->returnValue('max-peers');

$output .= "bgp_daemon_ip: $bgp_ip\n" if defined $bgp_ip;
$output .= "bgp_daemon_port: $bgp_port\n" if defined $bgp_port;
$output .= "bgp_daemon_max_peers: $bgp_max_peers\n" if defined $bgp_max_peers;

return $output
}

sub acct_get_config {

my $config = new Vyatta::Config;
Expand All @@ -286,6 +310,9 @@ sub acct_get_config {
my $facility = $config->returnValue('syslog-facility');
$output .= "syslog: $facility\n" if defined $facility;

my $bgp_daemon = acct_get_bgp_daemon($config);
$output .= $bgp_daemon if defined $bgp_daemon;

my $plugins = '';
if (!defined($config->returnValue('disable-imt'))) {
$plugins = 'plugins: memory';
Expand Down Expand Up @@ -322,6 +349,7 @@ sub acct_get_config {
$output .= "$plugins\n";
$output .= $netflow if defined $netflow;
$output .= $sflow if defined $sflow;

return $output;
}

Expand Down Expand Up @@ -386,6 +414,19 @@ sub acct_get_int_map {
return $output;
}

sub acct_get_bgp_agent_map {
my ($config) = @_;
my $output = undef;
$config->setLevel('system flow-accounting bgp-daemon neighbors');

my @neighbors = $config->returnValues();
if (scalar(@neighbors) > 0) {
foreach my $neighbor (@neighbors) {
$output .= "bgp_ip=$neighbor\tip=0.0.0.0/0\n";
}
}
return $output
}
#
# main
#
Expand Down Expand Up @@ -425,6 +466,9 @@ sub acct_get_int_map {
$config->setLevel('system flow-accounting interface');
my @interfaces = $config->returnValues();
my $conf_file = acct_get_conf_file();
my $map_bgp_agent = acct_get_bgp_agent_map($config);
acct_write_file('/etc/pmacct/agent_to_peer.map', $map_bgp_agent) if defined $map_bgp_agent;

if (scalar(@interfaces) > 0) {
my $map_conf = acct_get_int_map(@interfaces);
my $map_changed = acct_write_file('/etc/pmacct/int_map', $map_conf);
Expand Down
4 changes: 4 additions & 0 deletions templates-cfg/system/flow-accounting/bgp-daemon/ip/node.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: txt
help: binds the BGP daemon to a specific interface. Expects as value an IPv4 address. The same is used as BGP Router-ID to its peers - otherwise a dumb "1.2.3.4" value is presented. Setting this directive is highly adviced.
val_help: ipv4; IPv4 address to listen BGP daemon
syntax:expression: exec "${vyos_libexec_dir}/validate-value.py --exec \"${vyos_validators_dir}/ipv4-address \" --value \'$VAR(@)\'"; "Invalid value"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
multi:

type: txt

help: specify BGP neighbors. it is necessary only for generate valid agent_to_peer.map

val_help: ipv4; IPv4 address of bgp-peer

syntax:expression: exec "${vyos_libexec_dir}/validate-value.py --exec \"${vyos_validators_dir}/ipv4-address \" --value \'$VAR(@)\'"; "Invalid value"
1 change: 1 addition & 0 deletions templates-cfg/system/flow-accounting/bgp-daemon/node.def
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
help: The skinny BGP daemon thread
4 changes: 4 additions & 0 deletions templates-cfg/system/flow-accounting/bgp-daemon/port/node.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: txt
help: Binds the BGP daemon to a port different from the standard BGP port: 179/tcp.
val_help: 1-65535; Numeric IP port
syntax:expression: exec "${vyos_libexec_dir}/validate-value.py --exec \"${vyos_validators_dir}/numeric --range 1-65535\" --value \'$VAR(@)\'"; "Invalid value"
8 changes: 8 additions & 0 deletions templates-cfg/system/flow-accounting/generate-asn/node.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: txt

help: Generate ASN from file or BGP thread

syntax:expression: $VAR(@) in "file", "bgp" ; "must be file or bgp."

val_help: file ; generate ASNs by using a networks_file pointing to a valid Networks File
val_help: bgp ; generate ASNs from the uacctd BGP thread