summaryrefslogtreecommitdiff
path: root/scripts/vyatta-next-hop-check
blob: a00c54f4a22595753d80b263ca0dd266c0745032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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 or dhcp-interface 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} dhcp-interface
  RETVAL_DHCP=$?
  cli-shell-api exists protocols static route${SUFFIX} ${ROUTE}
  RETVAL_PARENT=$?
  if [ ${#ARR} -eq 0 ] && [ $RETVAL_BH -eq 1 ] && [ $RETVAL_DHCP -eq 1 ]&& [ $RETVAL_PARENT -eq 0 ]
  then
    echo "Must add either a next-hop or blackhole or dhcp-interface 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