diff options
6 files changed, 44 insertions, 39 deletions
diff --git a/Makefile.am b/Makefile.am index f6c04a85..9dfe6451 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,7 @@ sbin_SCRIPTS += scripts/policy/vyatta-check-as-prepend.pl sbin_SCRIPTS += scripts/vyatta-policy-action-verify.pl sbin_SCRIPTS += scripts/vyatta-gateway-static_route-check.pl sbin_SCRIPTS += scripts/vyatta-link-detect +sbin_SCRIPTS += scripts/vyatta-next-hop-check sbin_PROGRAMS = src/check_prefix_boundary diff --git a/scripts/vyatta-next-hop-check b/scripts/vyatta-next-hop-check new file mode 100644 index 00000000..bd81284d --- /dev/null +++ b/scripts/vyatta-next-hop-check @@ -0,0 +1,35 @@ +#!/bin/bash +if [ $# -ne 3 ]; then + echo 1>&2 Usage: $0 prefix family type + exit 127 +fi +ROUTE=$1 +FAM=$2 +TYPE=$3 +SUFFIX='' +if [[ ${FAM} = 'ipv6' ]]; then + SUFFIX='6' +fi +if [[ ${TYPE} = 'address' ]]; then + # Check that there is still a next-hop or blackhole if the parent is not deleted + ARR=( $(cli-shell-api listNodes protocols static route${SUFFIX} ${ROUTE} next-hop) ) + cli-shell-api exists protocols static route${SUFFIX} ${ROUTE} blackhole + RETVAL_BH=$? + cli-shell-api exists protocols static route${SUFFIX} ${ROUTE} + RETVAL_PARENT=$? + if [ ${#ARR} -eq 0 ] && [ $RETVAL_BH -eq 1 ] && [ $RETVAL_PARENT -eq 0 ] + then + echo "Must add either a next-hop or blackhole for route ${ROUTE}" + exit 1 + fi +elif [[ ${TYPE} = 'interface' ]];then + # Check that there is still a next-hop-interface if the parent is not deleted + ARR=( $(cli-shell-api listNodes protocols static interface-route${SUFFIX} ${ROUTE} next-hop-interface) ) + cli-shell-api exists protocols static interface-route${SUFFIX} ${ROUTE} + RETVAL_PARENT=$? + if [ ${#ARR} -eq 0 ] && [ $RETVAL_PARENT -eq 0 ] + then + echo "Must add a next-hop-interface for route ${ROUTE}" + exit 1 + fi +fi diff --git a/templates/protocols/static/interface-route/node.tag/next-hop-interface/node.def b/templates/protocols/static/interface-route/node.tag/next-hop-interface/node.def index 7e31ef40..019978f9 100644 --- a/templates/protocols/static/interface-route/node.tag/next-hop-interface/node.def +++ b/templates/protocols/static/interface-route/node.tag/next-hop-interface/node.def @@ -11,16 +11,9 @@ end: then if [[ ${COMMIT_ACTION} = 'DELETE' ]] then - # Check that there is still a next-hop-interface if the parent is not deleted - ARR=( $(cli-shell-api listNodes protocols static interface-route $VAR(../@) next-hop-interface) ) - cli-shell-api exists protocols static interface-route $VAR(../@) - RETVAL_PARENT=$? - if [ ${#ARR} -eq 0 ] && [ $RETVAL_PARENT -eq 0 ] - then - echo "Must add a next-hop-interface for route $VAR(../@)" - exit 1 + if ! ${vyatta_sbindir}/vyatta-next-hop-check $VAR(../@) ipv4 interface; then + exit 1; fi - vtysh -c "configure terminal" \ -c "no ip route $VAR(../@) $VAR(@)" else diff --git a/templates/protocols/static/interface-route6/node.tag/next-hop-interface/node.def b/templates/protocols/static/interface-route6/node.tag/next-hop-interface/node.def index 84e619cc..279329d6 100644 --- a/templates/protocols/static/interface-route6/node.tag/next-hop-interface/node.def +++ b/templates/protocols/static/interface-route6/node.tag/next-hop-interface/node.def @@ -10,14 +10,8 @@ end: then if [[ ${COMMIT_ACTION} = 'DELETE' ]] then - # Check that there is still a next-hop-interface if the parent is not deleted - ARR=( $(cli-shell-api listNodes protocols static interface-route6 $VAR(../@) next-hop-interface) ) - cli-shell-api exists protocols static interface-route6 $VAR(../@) - RETVAL_PARENT=$? - if [ ${#ARR} -eq 0 ] && [ $RETVAL_PARENT -eq 0 ] - then - echo "Must add a next-hop-interface for route $VAR(../@)" - exit 1 + if ! ${vyatta_sbindir}/vyatta-next-hop-check $VAR(../@) ipv6 interface; then + exit 1; fi vtysh -c "configure terminal" \ diff --git a/templates/protocols/static/route/node.tag/next-hop/node.def b/templates/protocols/static/route/node.tag/next-hop/node.def index 9160dd8d..eb41b4e4 100644 --- a/templates/protocols/static/route/node.tag/next-hop/node.def +++ b/templates/protocols/static/route/node.tag/next-hop/node.def @@ -6,18 +6,9 @@ end: then if [[ ${COMMIT_ACTION} = 'DELETE' ]] then - # Check that there is still a next-hop or blackhole if the parent is not deleted - ARR=( $(cli-shell-api listNodes protocols static route $VAR(../@) next-hop) ) - cli-shell-api exists protocols static route $VAR(../@) blackhole - RETVAL_BH=$? - cli-shell-api exists protocols static route $VAR(../@) - RETVAL_PARENT=$? - if [ ${#ARR} -eq 0 ] && [ $RETVAL_BH -eq 1 ] && [ $RETVAL_PARENT -eq 0 ] - then - echo "Must add either a next-hop or blackhole for route $VAR(../@)" - exit 1 + if ! ${vyatta_sbindir}/vyatta-next-hop-check $VAR(../@) ipv4 address; then + exit 1; fi - if ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl \ "$VAR(../@)" "$VAR(@)" then diff --git a/templates/protocols/static/route6/node.tag/next-hop/node.def b/templates/protocols/static/route6/node.tag/next-hop/node.def index 28b6ec00..e3a668b7 100644 --- a/templates/protocols/static/route6/node.tag/next-hop/node.def +++ b/templates/protocols/static/route6/node.tag/next-hop/node.def @@ -9,18 +9,9 @@ end: then if [[ ${COMMIT_ACTION} = 'DELETE' ]] then - # Check that there is still a next-hop or blackhole if the parent is not deleted - ARR=( $(cli-shell-api listNodes protocols static route6 $VAR(../@) next-hop) ) - cli-shell-api exists protocols static route6 $VAR(../@) blackhole - RETVAL_BH=$? - cli-shell-api exists protocols static route6 $VAR(../@) - RETVAL_PARENT=$? - if [ ${#ARR} -eq 0 ] && [ $RETVAL_BH -eq 1 ] && [ $RETVAL_PARENT -eq 0 ] - then - echo "Must add either a next-hop or blackhole for route $VAR(../@)" - exit 1 + if ! ${vyatta_sbindir}/vyatta-next-hop-check $VAR(../@) ipv6 address; then + exit 1; fi - if ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl \ "$VAR(../@)" "$VAR(@)" then |