summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/policy/vyatta-policy.pl52
-rw-r--r--templates/policy/large-community-list/node.def2
-rw-r--r--templates/policy/large-community-list/node.tag/rule/node.def16
-rw-r--r--templates/policy/large-community-list/node.tag/rule/node.tag/regex/node.def2
4 files changed, 56 insertions, 16 deletions
diff --git a/scripts/policy/vyatta-policy.pl b/scripts/policy/vyatta-policy.pl
index cbff3d4b..3e73a3bb 100755
--- a/scripts/policy/vyatta-policy.pl
+++ b/scripts/policy/vyatta-policy.pl
@@ -8,7 +8,7 @@ use Getopt::Long;
my $VTYSH = '/usr/bin/vtysh';
my $ACL_CONSUMERS_DIR = "/opt/vyatta/sbin/policy";
-my ( $accesslist, $accesslist6, $aspathlist, $communitylist, $extcommunitylist, $peer );
+my ( $accesslist, $accesslist6, $aspathlist, $communitylist, $extcommunitylist, $largecommunitylist, $peer );
my ( $routemap, $deleteroutemap, $listpolicy );
GetOptions(
@@ -17,6 +17,7 @@ GetOptions(
"update-aspath-list=s" => \$aspathlist,
"update-community-list=s" => \$communitylist,
"update-extcommunity-list=s" => \$extcommunitylist,
+ "update-large-community-list=s" => \$largecommunitylist,
"check-peer-syntax=s" => \$peer,
"check-routemap-action=s" => \$routemap,
"check-delete-routemap-action=s" => \$deleteroutemap,
@@ -28,6 +29,7 @@ update_access_list6($accesslist6) if ($accesslist6);
update_as_path($aspathlist) if ($aspathlist);
update_community_list($communitylist) if ($communitylist);
update_ext_community_list($extcommunitylist) if ($extcommunitylist);
+update_large_community_list($largecommunitylist) if ($largecommunitylist);
check_peer_syntax($peer) if ($peer);
check_routemap_action($routemap) if ($routemap);
check_delete_routemap_action($deleteroutemap) if ($deleteroutemap);
@@ -71,6 +73,54 @@ sub is_extcommunity_list {
}
}
+sub is_large_community_list {
+ my $list = shift;
+
+ my $count = `$VTYSH -c \"show bgp large-community-list $list detail\" | grep -c $list`;
+ if ( $count > 0 ) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+sub update_large_community_list {
+ my $name = shift;
+ my $config = new Vyatta::Config;
+ my @rules = ();
+
+ # remove the old rules
+ if ( is_large_community_list($name) ) {
+ my $clist = `$VTYSH -c \"show bgp large-community-list $name detail\" | grep -v \"expanded list $name\"`;
+ my @oldrules = split(/\n/, $clist);
+ foreach my $oldrule (@oldrules) {
+ system("$VTYSH -c \"conf t\" -c \"no bgp large-community-list expanded $name $oldrule\"");
+ }
+ }
+
+ $config->setLevel("policy large-community-list $name rule");
+ @rules = $config->listNodes();
+ foreach my $rule ( sort numerically @rules ) {
+ # set the action
+ my $action = $config->returnValue("$rule action");
+ die
+ "large-community-list $name rule $rule: You must specify an action\n"
+ unless $action;
+
+ # grab the regex
+ my $regex = $config->returnValue("$rule regex");
+ if(!defined($regex)) {
+ die "large-community-list $name rule $rule: You must specify a regex\n";
+ }
+ if (!($regex =~ /(.*):(.*):(.*)/) and (isIpAddress($1)or($1=~/^\d+$/) ) and ($2=~/^\d+$/)) {
+ die "large-community-list $name rule $rule: Malformed large-community-list regex";
+ }
+ system("$VTYSH -c \"conf t\" -c \"bgp large-community-list expanded $name $action $regex\"");
+ }
+
+ exit(0);
+}
sub update_ext_community_list {
my $name = shift;
diff --git a/templates/policy/large-community-list/node.def b/templates/policy/large-community-list/node.def
index 61687d47..51b68ef1 100644
--- a/templates/policy/large-community-list/node.def
+++ b/templates/policy/large-community-list/node.def
@@ -2,3 +2,5 @@ tag:
priority: 470
type: txt
help: Border Gateway Protocol (BGP) large-community-list filter
+
+end: /opt/vyatta/sbin/vyatta-policy.pl --update-large-community-list $VAR(@) \ No newline at end of file
diff --git a/templates/policy/large-community-list/node.tag/rule/node.def b/templates/policy/large-community-list/node.tag/rule/node.def
index 6cb593b7..738dfb39 100644
--- a/templates/policy/large-community-list/node.tag/rule/node.def
+++ b/templates/policy/large-community-list/node.tag/rule/node.def
@@ -3,18 +3,4 @@ type: u32
help: create a rule for this BGP large-community list
val_help: u32:1-65535; large-community-list rule number
-syntax:expression: $VAR(@) >= 1 && $VAR(@) <= 65535; "rule number must be between 1 and 65535"
-
-commit:expression: $VAR(./regex/) != ""; "You must specify a regex"
-commit:expression: $VAR(./action/) != ""; "You must specify an action"
-
-end:
- # If the rule exists in the running config
- if cli-shell-api existsActive policy large-community-list $VAR(../@) rule $VAR(@); then
- orig_action=$(cli-shell-api returnActiveValue policy large-community-list $VAR(../@) rule $VAR(@) action)
- orig_regex=$(cli-shell-api returnActiveValue policy large-community-list $VAR(../@) rule $VAR(@) regex)
- vtysh -c "configure terminal" -c "no bgp large-community-list expanded $VAR(../@) $orig_action $VAR(@) regex $orig_regex"
- fi
- if [[ ${COMMIT_ACTION} != 'DELETE' ]]; then
- vtysh -c "configure terminal" -c "bgp large-community-list expanded $VAR(../@) $VAR(./action/@) $VAR(@) regex $VAR(./regex/@)"
- fi
+syntax:expression: $VAR(@) >= 1 && $VAR(@) <= 65535; "rule number must be between 1 and 65535" \ No newline at end of file
diff --git a/templates/policy/large-community-list/node.tag/rule/node.tag/regex/node.def b/templates/policy/large-community-list/node.tag/rule/node.tag/regex/node.def
index 2a820bc6..37272454 100644
--- a/templates/policy/large-community-list/node.tag/rule/node.tag/regex/node.def
+++ b/templates/policy/large-community-list/node.tag/rule/node.tag/regex/node.def
@@ -1,3 +1,5 @@
type: txt
help: Regular expression to match against a community list
val_help: Community list regular expression
+
+commit:expression: $VAR(../action/@) != ""; "You must specify an action" \ No newline at end of file