aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2020-06-05 14:44:55 +0300
committerCem Keylan <cem@ckyln.com>2020-06-05 14:44:55 +0300
commit64d01a482cf80a28ff012cf8fac03c6085deefcf (patch)
tree85ae3f9185ac3843e527cedf942a9dbda6c98104 /core
parent9110a242e726aecdd4dd25563e636d81a52618bc (diff)
downloadrepository-64d01a482cf80a28ff012cf8fac03c6085deefcf.tar.gz
busybox: udhcpc script
Diffstat (limited to 'core')
-rwxr-xr-xcore/busybox/build3
-rw-r--r--core/busybox/checksums3
-rw-r--r--core/busybox/files/.config32
-rw-r--r--core/busybox/files/udhcpc.script140
-rw-r--r--core/busybox/sources1
5 files changed, 164 insertions, 15 deletions
diff --git a/core/busybox/build b/core/busybox/build
index 568836ed..df00282d 100755
--- a/core/busybox/build
+++ b/core/busybox/build
@@ -52,3 +52,6 @@ done
kinstall 644 ntp.conf "$1/etc/ntp.conf"
kinstall 644 inittab "$1/etc/inittab"
kinstall 644 mdev.conf "$1/etc/mdev.conf"
+
+# Install udhcpc configuration script.
+kinstall 755 udhcpc.script "$1/etc/udhcpc"
diff --git a/core/busybox/checksums b/core/busybox/checksums
index fede3dcd..f1625d02 100644
--- a/core/busybox/checksums
+++ b/core/busybox/checksums
@@ -1,5 +1,5 @@
d0f940a72f648943c1f2211e0e3117387c31d765137d92bd8284a3fb9752a998 busybox-1.31.1.tar.bz2
-ccb775673d9315174b353e137a5362e5446f6593a4bb2b622c22b1e41c219ed8 .config
+d72b6a0098c5db4235200c5acc4e327b387951224670b7812012200dce6a8349 .config
47473c15263d52cc741993ca0386d0042a719b23c89e406e173510e42e0f23a5 .config-suid
ebd61afac770d3d9cae5c411f44002496fb18b28cf7b77520072a3909852246e acpid.run
814dea14ac612125e97dcc1d619219b2c9dfc14850bf48d858421fb2c98eca12 crond.run
@@ -9,6 +9,7 @@ af4c302ed9ae6fa1cd8aa51c6f94de11550625e6f1dc0b138605e3429214d082 mdev.conf
3999bb8986a55b14389196ad70f810c9333ebdf5e03c0fbca2d100a6e8ba3d7e ntpd.run
4a5981f4b0d791fe9b84b0b2e01ae905f6565c8245b3cd603e6decf34ddad71a syslogd.run
2c6012579f669ea790785bb522a879a2005aad0d7977f96863918d3ed3cb03dd ntp.conf
+8ce7d65bc9a6da2003bd4dfd89aa355fd8f24fc1fafc37400400f7ac10958caf udhcpc.script
8d84b1719dca2a751c09072c20cd782a3c47f119a68d35316f89d851daf67b88 fsck-resolve-uuid.patch
0f54301a73af461e8066bc805b48d991cfed513d08a2f036e015b19f97cb424a modprobe-kernel-version.patch
09c2f601fec4e5c10664c22f787dafb9424efe219bf826727c356da90dfd60d5 adduser-no-setgid.patch
diff --git a/core/busybox/files/.config b/core/busybox/files/.config
index 87c7b94f..6d7a181b 100644
--- a/core/busybox/files/.config
+++ b/core/busybox/files/.config
@@ -1,7 +1,7 @@
#
# Automatically generated make config: don't edit
# Busybox version: 1.31.1
-# Mon Jun 1 11:10:36 2020
+# Fri Jun 5 11:32:04 2020
#
CONFIG_HAVE_DOT_CONFIG=y
@@ -979,20 +979,24 @@ CONFIG_WHOIS=y
CONFIG_DHCPD_LEASES_FILE=""
# CONFIG_DUMPLEASES is not set
# CONFIG_DHCPRELAY is not set
-# CONFIG_UDHCPC is not set
-# CONFIG_FEATURE_UDHCPC_ARPING is not set
-# CONFIG_FEATURE_UDHCPC_SANITIZEOPT is not set
-CONFIG_UDHCPC_DEFAULT_SCRIPT=""
-# CONFIG_UDHCPC6 is not set
-# CONFIG_FEATURE_UDHCPC6_RFC3646 is not set
-# CONFIG_FEATURE_UDHCPC6_RFC4704 is not set
-# CONFIG_FEATURE_UDHCPC6_RFC4833 is not set
-# CONFIG_FEATURE_UDHCPC6_RFC5970 is not set
+CONFIG_UDHCPC=y
+CONFIG_FEATURE_UDHCPC_ARPING=y
+CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y
+CONFIG_UDHCPC_DEFAULT_SCRIPT="/etc/udhcpc"
+CONFIG_UDHCPC6=y
+CONFIG_FEATURE_UDHCPC6_RFC3646=y
+CONFIG_FEATURE_UDHCPC6_RFC4704=y
+CONFIG_FEATURE_UDHCPC6_RFC4833=y
+CONFIG_FEATURE_UDHCPC6_RFC5970=y
+
+#
+# Common options for DHCP applets
+#
# CONFIG_FEATURE_UDHCP_PORT is not set
-CONFIG_UDHCP_DEBUG=0
-CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=0
-# CONFIG_FEATURE_UDHCP_RFC3397 is not set
-# CONFIG_FEATURE_UDHCP_8021Q is not set
+CONFIG_UDHCP_DEBUG=2
+CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
+CONFIG_FEATURE_UDHCP_RFC3397=y
+CONFIG_FEATURE_UDHCP_8021Q=y
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"
#
diff --git a/core/busybox/files/udhcpc.script b/core/busybox/files/udhcpc.script
new file mode 100644
index 00000000..b3003cd0
--- /dev/null
+++ b/core/busybox/files/udhcpc.script
@@ -0,0 +1,140 @@
+#!/bin/sh
+# shellcheck source=/dev/null
+# shellcheck disable=1090
+
+# script for udhcpc
+# Copyright (c) 2008 Natanael Copa <natanael.copa@gmail.com>
+# Copyright (c) 2020 Cem Keylan <cem@ckyln.com>
+
+# I have made some minor changes, POSIX shell fixes, and linting.
+# Rest of the script is pretty much the same.
+# - Cem
+
+[ -f "${UDHCPC:=/etc/udhcpc.d}/udhcpc.conf" ] && . "$UDHCPC/udhcpc.conf"
+
+RESOLV_CONF="/etc/resolv.conf"
+
+# Export variables so that hooks can also make use of them.
+export broadcast
+export dns
+export domain
+export interface
+export ip
+export mask
+export metric
+export router
+export search
+export subnet
+
+run_scripts() {
+ for file in "$1/"*; do
+ [ -f "$file" ] && "$file"
+ done
+}
+
+deconfig() { ip -4 addr flush dev "$interface" ;}
+
+is_wifi() { [ -e "/sys/class/net/$interface/phy80211" ] ;}
+
+if_index() {
+ if [ -e "/sys/class/net/$interface/ifindex" ]; then
+ read -r ifindex < "/sys/class/net/$interface/ifindex"
+ else
+ ifindex="$(ip -4 link show dev "$interface")"
+ fi
+ printf '%s\n' "${ifindex%%:*}"
+}
+
+calc_metric() {
+ is_wifi && { printf '%s\n' "$(( 300 + $(if_index) ))"; return ;}
+ printf '%s\n' "$(( 200 + $(if_index) ))"
+}
+
+routes() {
+ [ "$router" ] || return
+ for i in $NO_GATEWAY; do
+ [ "$i" = "$interface" ] && return
+ done
+ while ip -4 route del default via dev "$interface" 2>/dev/null; do
+ :
+ done
+ num=-1
+ for gw in $router; do
+ if [ "$subnet" = "255.255.255.255" ]; then
+ # special case for /32 subnets:
+ # /32 instructs kernel to always use routing for all outgoing packets
+ # (they can never be sent to local subnet - there is no local subnet for /32).
+ # Used in datacenters, avoids the need for private ip-addresses between two hops.
+ ip -4 route add "$gw" dev "$interface"
+ fi
+ ip -4 route add 0.0.0.0/0 via "$gw" dev "$interface" \
+ metric $(( (num += 1) + ${IF_METRIC:-$(calc_metric)} ))
+ done
+}
+
+resolvconf() {
+ case "$IF_PEER_DNS" in yes|'') ;; *) return; esac
+ case "$RESOLV_CONF" in [Nn][Oo]|'') return; esac
+ case " $NO_DNS " in *" $interface "*) return; esac
+ :> "$RESOLV_CONF.$$"
+ if [ "$search" ]; then
+ printf 'search %s\n' "$search" >> "$RESOLV_CONF.$$"
+ elif [ "$domain" ]; then
+ printf 'search %s\n' "$domain" >> "$RESOLV_CONF.$$"
+ fi
+
+ # Word-splitting is intentional
+ # shellcheck disable=2086
+ printf 'nameserver %s\n' $dns >> "$RESOLV_CONF.$$"
+ chmod a+r "$RESOLV_CONF.$$"
+ mv "$RESOLV_CONF.$$" "$RESOLV_CONF"
+}
+
+bound() {
+ ip -4 addr add "$ip/$mask" ${broadcast:+broadcast $broadcast} dev "$interface"
+ ip -4 link set dev "$interface" up
+ routes
+ resolvconf
+}
+
+renew() {
+ ip -4 addr show dev "$interface" | grep -q "$ip/$mask" || {
+ ip -4 addr flush dev "$interface"
+ ip -4 addr add "$ip/$mask" ${broadcast:+broadcast $broadcast} dev "$interface"
+ }
+ for i in $router; do
+ ip -4 route show | grep ^default | grep -q "$i" || {
+ routes
+ break
+ }
+ done
+ if ! grep -q "^search $domain" "$RESOLV_CONF" ; then
+ resolvconf
+ return
+ fi
+ for i in $dns; do
+ if ! grep -q "^nameserver $i" "$RESOLV_CONF" ; then
+ resolvconf
+ return
+ fi
+ done
+}
+
+case "$1" in
+ deconfig|renew|bound)
+ run_scripts "$UDHCPC/pre-$1"
+ $1
+ run_scripts "$UDHCPC/post-$1"
+ ;;
+ leasefail)
+ echo "udhcpc failed to get a DHCP lease" >&2
+ ;;
+ nak)
+ echo "udhcpc received DHCP NAK" >&2
+ ;;
+ *)
+ echo "Error: this script should be called from udhcpc" >&2
+ exit 1
+ ;;
+esac
+exit 0
diff --git a/core/busybox/sources b/core/busybox/sources
index 435b330b..f1190747 100644
--- a/core/busybox/sources
+++ b/core/busybox/sources
@@ -9,6 +9,7 @@ files/mdev.run
files/ntpd.run
files/syslogd.run
files/ntp.conf
+files/udhcpc.script
patches/fsck-resolve-uuid.patch
patches/modprobe-kernel-version.patch
patches/adduser-no-setgid.patch