#!/bin/sh /etc/rc.common
# Copyright (C) 2018-2020 Lienol <lawlienol@gmail.com>

START=99

CONFIG="pppoe-relay"

setup_service() {
	config_get enabled $1 enabled
	[ "$enabled" -eq 0 ] && return 0
	config_get server_interface $1 server_interface
	config_get client_interface $1 client_interface
	[ -n "$server_interface" -a -n "$client_interface" ] && {	
		is_run=$(ps | grep "/usr/sbin/pppoe-relay -S $server_interface -C $client_interface" | grep -v "grep")
		[ -z "$is_run" ] && /usr/sbin/pppoe-relay -S $server_interface -C $client_interface
	}
}

start() {
	config_load $CONFIG
	config_foreach setup_service service
}

stop() {
	killall -q -9 pppoe-relay
}
