#!/bin/bash

#used for cli command "clear ipv6-neighbors"
#if no input var ,then clear all neighbor information for IPv6
#if $1 is a ipv6 address,then clear neighbor info for specific IPv6 address
#no output var

if [ ! -z $1 ] ; then
    /sbin/ip -6 neigh | \grep -v FAILED | sed 's+^.*(++' | tr -d ')' | awk '/[0-9]/ {print $1 " " $2 " " $3}' | \grep "$1"
    if [ "$?" = 1 ]; then 
        echo "No NEIGH entry for $1"
    else
        /sbin/ip -6 neigh | \grep -v FAILED | sed 's+^.*(++' | tr -d ')' | \grep "$1" | awk '/[0-9]/ {system("/sbin/ip -6 neigh del " $1 " " $2 " " $3)}' 
    fi
else
  /sbin/ip -6 neigh | \grep -v FAILED | sed 's+^.*(++' | tr -d ')' | awk '/[0-9]/ {system("/sbin/ip -6 neigh del " $1 " " $2 " " $3) }'
fi

exit 0
