blob: 1350636ba4300f4ef69508576597de99c0193c1f [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2uci -q get dhcp.odhcpd && exit 0
3touch /etc/config/dhcp
4
5. /usr/share/libubox/jshn.sh
6
7json_load "$(cat /etc/board.json)"
8json_select network
9json_select lan
10json_get_vars protocol
11json_select ..
12json_select ..
13
14ODHCPDONLY=0
15V4MODE=disabled
16V6MODE=disabled
17
18[ -e /usr/sbin/dnsmasq ] || ODHCPDONLY=1
19
20case "$protocol" in
21# only enable server mode on statically addressed lan ports
22"static")
23 V4MODE=server
24 [ -e /proc/sys/net/ipv6 ] && V6MODE=server
25 ;;
26esac
27
28uci get dhcp.lan 1>/dev/null 2>/dev/null || {
29uci batch <<EOF
30set dhcp.lan=dhcp
31set dhcp.lan.interface='lan'
32set dhcp.lan.start='100'
33set dhcp.lan.limit='150'
34set dhcp.lan.leasetime='12h'
35set dhcp.lan.domain='lan'
36EOF
37}
38
39uci batch <<EOF
40set dhcp.odhcpd=odhcpd
41set dhcp.odhcpd.maindhcp=$ODHCPDONLY
42set dhcp.odhcpd.leasefile=/tmp/hosts/odhcpd
43set dhcp.odhcpd.leasetrigger=/usr/sbin/odhcpd-update
44set dhcp.odhcpd.loglevel=4
45set dhcp.lan.dhcpv4=$V4MODE
46set dhcp.lan.dhcpv6=$V6MODE
47set dhcp.lan.ra=$V6MODE
48set dhcp.lan.ra_slaac=1
49add_list dhcp.lan.ra_flags=managed-config
50add_list dhcp.lan.ra_flags=other-config
51commit dhcp
52EOF