]>
git.proxmox.com Git - mirror_frr.git/blob - tools/nhrpd-event-handler.sh
4 # Released to public domain
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2 of the License, or (at your option)
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 # You should have received a copy of the GNU General Public License along
17 # with this program; see the file COPYING; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 PROGNAME
=`basename $0`
29 EV_LADDR
="local_address"
30 EV_VCINIT
="vc_initiated"
33 EV_RADDR
="remote_addr"
34 EV_RNBMA
="remote_nbma"
35 EV_RCERT
="remote_cert"
39 echo "Usage: $PROGNAME [-s nhrp-sock] [-d] [-i interface-name] [-t table] [-e execute-cmd] [-u user] [-g group] [-r] [-l logfile]"
41 echo "-s nhrp-sock file"
42 echo "-i interface-name to execute on, may be repeated multiple times"
43 echo "-t tableid to execute on for immdiate preceeding interface"
44 echo "-e execute command for immmediate preceeding interface"
45 echo " The command will be passed the following arguments $EV_ID $EV_TYPE $EV_INT $EV_LNMBA $EV_RADDR $EV_RNBMA int_table"
46 echo "-u user to own the sock"
47 echo "-g group to own the sock"
48 echo "-r send rejection (testing)"
49 echo "-l logfile to record conversation with nhrpd"
58 SOCK
="/var/run/frr/nhrp.sock"
65 while getopts rds
:i
:u
:g
:l
:t
:e
: opt
; do
74 INTARR
[((j
++))]="$OPTARG"
77 if [[ "$j" == "0" ]] ||
[[ "${INTARR[((j-1))]}" == "" ]]; then
78 echo "execute argument must follow interface argument"
81 EXECARR
["${INTARR[((j-1))]}"]="$OPTARG"
84 if [[ "$j" == "0" ]] ||
[[ "${INTARR[((j-1))]}" == "" ]]; then
85 echo "execute argument must follow interface argument"
88 TABLEARR
["${INTARR[((j-1))]}"]="$OPTARG"
100 EVLOGFILE
="${OPTARG}"
105 if [[ "$EVLOGFILE" != "" ]]; then
106 if [[ ! -w "${EVLOGFILE}" ]]; then
107 touch "$EVLOGFILE" ||
( echo "Cannot write to logfile $EVLOGFILE" ; usage
)
109 echo -e "PROG: $0 Startup\nPROG: Arguments $*" >> $EVLOGFILE
116 if [[ "$EVLOGFILE" != "" ]]; then
117 echo -e "PROG: `date -R`\nPROG: Starting mainloop" >> $EVLOGFILE
120 coproc socat
- UNIX-LISTEN
:$SOCK,unlink-early
,setuid-early
=$USER,unlink-close
=0 ||
exit 1
121 test -S $SOCK && chown
$USER:$GROUP $SOCK
128 if [[ "$EVLOGFILE" != "" ]]; then
129 echo "IN: $S" >> $EVLOGFILE
131 if [[ "$S" == "" ]]; then
132 if [[ "${NHRPEVENT[$EV_ID]}" != "" ]]; then
133 OUTMSG
="eventid=${NHRPEVENT[$EV_ID]}\nresult=$RESULT\n"
134 echo -e "$OUTMSG" >&"${COPROC[1]}"
135 if [[ "$EVLOGFILE" != "" ]]; then
136 echo -e "OUT:\n${OUTMSG}" >> $EVLOGFILE;
141 for((i
=0;i
<${#INTARR[@]};i
++)); do
142 if [[ "${NHRPEVENT[$EV_INT]}" == "" ]]; then break; fi
143 if [[ "${INTARR[$i]}" != "${NHRPEVENT[$EV_INT]}" ]]; then continue; fi
144 EVINT
="${NHRPEVENT[$EV_INT]}"
145 if [[ "${NHRPEVENT[$EV_RADDR]}" == "" ]]; then break; fi
146 if [[ "${NHRPEVENT[$EV_RNBMA]}" == "" ]]; then break; fi
147 if [[ "${NHRPEVENT[$EV_TYPE]}" != "dynamic" ]]; then break; fi
149 INTEXEC
=${EXECARR["$EVINT"]}
150 INTABLE
=${TABLEARR["$EVINT"]}
154 CMDADD
="ip neigh add "
155 CMDREPL
="ip neigh replace"
157 if [[ "$INTEXEC" != "" ]]; then
158 CMD
="$INTEXEC ${NHRPEVENT[$EV_ID]:-nil}"
159 CMD
="$CMD ${NHRPEVENT[$EV_TYPE]:-nil}"
160 CMD
="$CMD ${NHRPEVENT[$EV_INT]:-nil}"
161 CMD
="$CMD ${NHRPEVENT[$EV_LNBMA]:-nil}"
162 CMD
="$CMD ${NHRPEVENT[$EV_RADDR]:-nil}"
163 CMD
="$CMD ${NHRPEVENT[$EV_RNBMA]:-nil}"
164 CMD
="$CMD ${INTABLE:-nil}"
167 CMDTAB
="${INTABLE:+${TABLE}${INTABLE}}"
168 CMDEND
="$CMDEND ${NHRPEVENT[$EV_RADDR]} dev $EVINT lladdr ${NHRPEVENT[$EV_RNBMA]} nud noarp"
172 for ((k
=0;k
<2;k
++)); do
173 for ((l
=0;l
<2;l
++)); do
174 if [[ "$EVLOGFILE" != "" ]]; then
175 echo "PROG: Executing $CMD" >> $EVLOGFILE
176 CMDOUT
=`$CMDBEG $CMD $CMDTAB 2>&1`
178 if [[ "$CMDOUT" != "" ]]; then
179 echo "PROG: Execution output: $CMDOUT" >> $EVLOGFILE
184 if [[ "$CMDTAB" == "" ]] ||
[[ "$INTEXEC" != "" ]]; then break; fi
186 if [[ "$INTEXEC" != "" ]] ||
[[ "$CMDRET" == "0" ]]; then
195 declare -Ag NHRPEVENT
202 eval NHRPEVENT
[${SA[0]}]="\"${SA[1]}\""
204 done <&"${COPROC[0]}"
206 if [[ "$COPROC_PID" != "" ]]; then kill "$COPROC_PID"; fi
212 if [[ "$DAEMON" == "0" ]]; then