diff core/rc/rc.networking @ 630:58211c615a8c

core/rc: add basic rc.networking support
author David Demelier <markand@malikania.fr>
date Tue, 23 Jul 2019 23:00:00 +0200
parents
children 4088afe6988e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/rc/rc.networking	Tue Jul 23 23:00:00 2019 +0200
@@ -0,0 +1,105 @@
+#!/bin/sh
+#
+# /etc/rc.init -- basic networking script
+#
+# Copyright (c) 2019 David Demelier <markand@malikania.fr>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+#
+# This script is provided mostly for static configuration and/or more complex
+# scenarios where the system administrator requires full control over the
+# networking interfaces. Most people would prefer using dhcpcd for simple
+# configurations or NetworkManager on desktop systems.
+#
+# The file /etc/rc.networking allows you to define functions for each interface
+# and will automatically call "start" and "stop" at boot and shutdown
+# respectively.
+#
+# See below for basic examples and uncomment the appropriate one.
+#
+
+if [ -f /etc/rc.conf ]; then
+	. /etc/rc.conf
+fi
+
+lo()
+{
+	echo "Setting network interface: lo"
+
+	case $1 in
+	"start")
+		ip link set dev lo up
+		ip addr add 127.0.0.1/8 dev lo
+		ip -6 addr add ::1/128 dev lo
+		;;
+	"stop")
+		ip -6 addr del ::1/128 dev lo
+		ip addr del 127.0.0.1 dev lo
+		ip link set dev lo down
+		;;
+	esac
+}
+
+#
+# Example 1: static IP on eth0 interface.
+#
+# eth0()
+# {
+# 	echo "Setting network interface: eth0"
+#
+# 	case $1 in
+# 	"start")
+# 		ip link set eth0 up
+# 		ip addr add 192.168.0.1 dev eth0
+# 		;;
+# 	"stop")
+# 		ip addr del 192.168.0.1 dev eth0
+# 		ip link set eth0 down
+# 		;;
+# 	esac
+# }
+#
+
+usage()
+{
+	echo "usage: $(basename $0) start|stop [interface]" 1>&2
+	exit 1
+}
+
+if [ $# -eq 0 ]; then
+	usage
+	# NOTREACHED
+fi
+
+case $1 in
+"start"|"stop")
+	#
+	# If no interface is given, iterate over all defined in
+	# INTERFACES from /etc/rc.conf.
+	#
+	if [ $# -eq 1 ]; then
+		for iface in $INTERFACES; do
+			$iface $1
+		done
+	else
+		$2 $1
+	fi
+
+	;;
+*)
+	usage
+	# NOTREACHED
+	;;
+esac