#!/usr/bin/lua

-- This script must be ordered after 300-gluon-client-bridge-network, as
-- it overrides parts of network.client


local site = require 'gluon.site'
local util = require 'gluon.util'
local uci = require('simple-uci').cursor()


uci:section('network', 'interface', 'client', {
	ipv6 = true,
	proto = 'dhcpv6',
	reqprefix = 'no',
	peerdns = not site.dns.servers(),
	sourcefilter = false,
	keep_ra_dnslifetime = true,
	robustness = 9,
	query_interval = 2000,
	query_response_interval = 500,
})

uci:delete('network', 'client_lan')

uci:delete('network', 'local_node_route')

uci:delete('network', 'local_node_route6')
uci:section('network', 'route6', 'local_node_route6', {
	interface = 'client',
	target = site.prefix6(),
	gateway = '::',
})

uci:save('network')

local networks = uci:get_list('firewall', 'mesh', 'network')
util.add_to_set(networks, 'client')
uci:set_list('firewall', 'mesh', 'network', networks)

networks = uci:get_list('firewall', 'drop', 'network')
util.remove_from_set(networks, 'client')
uci:set_list('firewall', 'drop', 'network', networks)

uci:delete('firewall', 'local_node_dns')

uci:save('firewall')
