#!/bin/sh /etc/rc.common
# Copyright (C) 2012 OpenWrt.org

START=91

SERVICE_SIG="KILL"
SERVICE_PID_FILE="/var/run/dhcrelay6.pid"
SERVICE_USE_PID=1

start() {
    local relay_dhcpserver
    local relay_upper
    local relay_lowers
    local relay_lower_args

    config_load dhcrelay
    config_get relay_dhcpserver ipv6 dhcpserver
    config_get relay_upper ipv6 upper
    config_get relay_lowers ipv6 lower

    # If a specific DHCP server is specified,
    # add it to the upper interface.
    if [ -n "$relay_dhcpserver" ]; then
        relay_upper="${relay_dhcpserver}%$relay_upper"
    fi

    # Add all lower interfaces at the end.
    if [ -n "$relay_lowers" ]; then
        local relay_lower
        for relay_lower in $relay_lowers; do
            append relay_lower_args "-U $relay_lower"
        done
    fi

    service_start /usr/sbin/dhcrelay -6 -q \
        -pf $SERVICE_PID_FILE \
        -u $relay_upper $relay_lower_args
}

stop() {
    service_stop /usr/sbin/dhcrelay
}
