#!/bin/sh
#
# netplugd policy agent for Vyatta
#
# Copyright (c) 2019, AT&T Intellectual Property
# Copyright (c) 2014-2017 Brocade Communications Systems, Inc.
# Copyright 2003 Key Research, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.  You are forbidden from
# redistributing or modifying it under the terms of any other license,
# including other versions of the GNU General Public License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

dev="$1"
action="$2"
proto="$3"
addr="$4"

case "$action" in
in)
   run-parts -a $dev /etc/netplug/linkup.d
    ;;
out)
   run-parts -a $dev /etc/netplug/linkdown.d
    ;;
macchange)
   run-parts -a $dev /etc/netplug/macchange.d
    ;;

# probe loads and initialises the driver for the interface and brings the
# interface into the "up" state, so that it can generate netlink(7) events.
# This interferes with "admin down" for an interface. Thus, the probe action
# is empty. An "admin up" is treated as a "link up" and thus, "link up"
# action is executed.  To execute "link down" action on "admin down",
# run appropriate script in /etc/netplug/linkdown.d
probe)
    ;;

newaddr)
   run-parts -a $dev -a $proto -a $addr /etc/netplug/newaddr.d
    ;;

deladdr)
   run-parts -a $dev -a $proto -a $addr /etc/netplug/deladdr.d
    ;;
*)
    exit 1
    ;;
esac
