comparison 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
comparison
equal deleted inserted replaced
629:dbd752e285f6 630:58211c615a8c
1 #!/bin/sh
2 #
3 # /etc/rc.init -- basic networking script
4 #
5 # Copyright (c) 2019 David Demelier <markand@malikania.fr>
6 #
7 # Permission to use, copy, modify, and/or distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #
19
20 #
21 # This script is provided mostly for static configuration and/or more complex
22 # scenarios where the system administrator requires full control over the
23 # networking interfaces. Most people would prefer using dhcpcd for simple
24 # configurations or NetworkManager on desktop systems.
25 #
26 # The file /etc/rc.networking allows you to define functions for each interface
27 # and will automatically call "start" and "stop" at boot and shutdown
28 # respectively.
29 #
30 # See below for basic examples and uncomment the appropriate one.
31 #
32
33 if [ -f /etc/rc.conf ]; then
34 . /etc/rc.conf
35 fi
36
37 lo()
38 {
39 echo "Setting network interface: lo"
40
41 case $1 in
42 "start")
43 ip link set dev lo up
44 ip addr add 127.0.0.1/8 dev lo
45 ip -6 addr add ::1/128 dev lo
46 ;;
47 "stop")
48 ip -6 addr del ::1/128 dev lo
49 ip addr del 127.0.0.1 dev lo
50 ip link set dev lo down
51 ;;
52 esac
53 }
54
55 #
56 # Example 1: static IP on eth0 interface.
57 #
58 # eth0()
59 # {
60 # echo "Setting network interface: eth0"
61 #
62 # case $1 in
63 # "start")
64 # ip link set eth0 up
65 # ip addr add 192.168.0.1 dev eth0
66 # ;;
67 # "stop")
68 # ip addr del 192.168.0.1 dev eth0
69 # ip link set eth0 down
70 # ;;
71 # esac
72 # }
73 #
74
75 usage()
76 {
77 echo "usage: $(basename $0) start|stop [interface]" 1>&2
78 exit 1
79 }
80
81 if [ $# -eq 0 ]; then
82 usage
83 # NOTREACHED
84 fi
85
86 case $1 in
87 "start"|"stop")
88 #
89 # If no interface is given, iterate over all defined in
90 # INTERFACES from /etc/rc.conf.
91 #
92 if [ $# -eq 1 ]; then
93 for iface in $INTERFACES; do
94 $iface $1
95 done
96 else
97 $2 $1
98 fi
99
100 ;;
101 *)
102 usage
103 # NOTREACHED
104 ;;
105 esac