updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / netcfg-iproute / iproute
blob399b2c1c8cc186510f0f4ee158e9ce572140d2ce
1 #!/bin/bash
2 . /usr/lib/network/network
4 fail()
6 report_fail "$*"
7 exit 1
10 int_setup() {
11 int=$1
12 addr=$2
13 route=$3
15 report_debug iproute_up ifup $int
16 ip link set up dev "$int" up || \
17 fail "Could not bring interface $int up"
19 while read str; do
20 [[ -n "$str" ]] || continue
21 report_debug iproute_up ip addr add dev "$int" $str
22 ip addr add dev "$int" $str || \
23 fail "Adding address \"$str\" to $int failed"
24 done <<<"$addr"
26 while read str; do
27 [[ -n "$str" ]] || continue
28 report_debug iproute_up ip route add dev "$int" $str
29 ip route add dev "$int" $str || \
30 fail "Adding route \"$str\" to $int failed"
31 done <<<"$route"
34 vlan_create() {
35 int=$1
36 vlan=$2
37 ip link add link "$int" name "vlan$vlan" type vlan id "$vlan"
40 vlan_drop() {
41 vlan=$1
42 ip link delete "vlan$vlan"
45 iproute_up() {
46 load_profile "$1"
48 [[ -e /sys/class/net/"$INTERFACE" ]] || \
49 fail "Interface $INTERFACE does not exist"
51 if [[ -n "$GATEWAY" ]]; then
52 ROUTE="$ROUTE"$'\n'"default via $GATEWAY"
54 int_setup "$INTERFACE" "$ADDR" "$ROUTE"
56 # setup vlans
57 [[ -n "$VLANS" ]] && for vlan in $VLANS; do
58 report_debug iproute_up add vlan "$INTERFACE" "$vlan"
59 vlan_create "$INTERFACE" "$vlan"
60 addr="ADDR_vlan$vlan"
61 route="ROUTE_vlan$vlan"
62 int_setup "vlan$vlan" "${!addr}" "${!route}"
63 done
65 # set the hostname
66 if [[ -n "$HOSTNAME" ]]; then
67 report_debug iproute_up hostname "$HOSTNAME"
68 hostname "$HOSTNAME" || \
69 fail "Cannot set hostname to $HOSTNAME"
72 # Generate a new resolv.conf
73 if [[ -n "$DNS" ]]; then
74 : >/etc/resolv.conf
75 [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
76 [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
78 for str in $DNS; do
79 echo "nameserver $str" >>/etc/resolv.conf
80 done
82 return 0
85 iproute_down() {
86 load_profile "$1"
88 # drop vlans
89 [[ -n "$VLANS" ]] && for vlan in $VLANS; do
90 report_debug iproute_up drop vlan "$vlan"
91 vlan_drop "$vlan"
92 done
94 report_debug ethernet_down if_down
95 ip addr flush dev "$INTERFACE"
96 quirk "nodown" || ip link set down dev "$INTERFACE"
99 iproute_status() {
100 [[ -e /var/run/network/profiles/"$1" ]] && return 0
101 return 1
104 iproute_$1 "$2"
105 exit $?
107 # vim: ts=4:et:sw=4: