#!/bin/bash

# /etc/network/if-post-down.d/dhcpcd-sync
#
# Hook script provided by the 'tkl-dhcpcd-ifupdown-glue' package and part of
# TurnKey GNU/Linux network configuration.
#
# Removes denyinterfaces entry when interface is deconfigured.
# This ensures dhcp works again if the interface is later reconfigured to dhcp
# without an ifup cycle (e.g. manual dhcpcd invocation).

update_dhcpcd_conf=/usr/lib/dhcpcd-ifupdown-glue/update-dhcpcd-conf

_info() {
    logger --tag=dhcpcd-ifupdown-glue "$*"
}

_info "if-post-down hook running for $IFACE"

if [[ "$IFACE" == "lo" ]]; then
    _info "nothing to do for 'lo'"
    exit 0
fi

for _ipv in ipv4 ipv6; do
    $update_dhcpcd_conf remove-deny-dhcp "$IFACE" $_ipv
done

_info "if-post-down hook finished for $IFACE"

exit 0
