]> git.ipfire.org Git - people/stevee/network.git/blob - hooks/ethernet
network: Remove support for blue zone.
[people/stevee/network.git] / hooks / ethernet
1 #!/bin/sh
2 ########################################################################
3 # Begin $NETWORK_DEVICES/services/ethernet
4 #
5 # Description : Ethernet Script
6 #
7 # Authors : Michael Tremer - michael.tremer@ipfire.org
8 #
9 # Version : 00.00
10 #
11 # Notes : This script adds ethernet support.
12 #
13 ########################################################################
14
15 . /lib/network/hook-header
16
17 HOOK_NAME=ethernet
18 HOOK_TYPE=port
19
20 function port_name() {
21 echo ${zone}p+
22 }
23
24 case "${action}" in
25 help)
26 echo -e "${BOLD}Hook (${HOOK_NAME}) help:"
27 echo
28 echo -e " ${BOLD}Summary:${NORMAL}"
29 echo " The ethernet-hook controls connection via ethernet."
30 echo " You will need this to access your local lan."
31 echo
32 echo -e " ${BOLD}Usage:${NORMAL}"
33 #echo " --config=<FILE>"
34 #echo " Includes a config file."
35 #echo " Example: --config=/etc/sysconfig/network/green0/port-00:11:22:33:44:55"
36 #echo " --port=<MAC or Name>"
37 #echo " Passes the port to the script."
38 #echo " Example: --port=port0 or --port=00:11:22:33:44:55"
39 #echo " --zone=<zone>"
40 #echo " Passes the zone to the script."
41 #echo " Example: --zone=green0"
42 #echo
43 #echo -e " ${BOLD}Commands:${NORMAL}"
44 #echo
45 echo " This hook only needs the name of the network device"
46 echo " that should be attached to the zone."
47 echo " The device identifier can either be a mac address or"
48 echo " a device name."
49 echo
50 echo " Example: network zone addport green0 ethernet port0"
51 echo " network zone addport green0 ethernet 00:11:22:33:44:55"
52 echo
53 ;;
54
55 info)
56 echo "HOOK_NAME=${HOOK_NAME}"
57 echo "HOOK_TYPE=${HOOK_TYPE}"
58 ;;
59
60 pre-up)
61 device_is_up ${MAC} || ip link set $(devicify ${MAC}) up
62 ;;
63
64 post-up)
65 if zone_has_device_attached ${zone} $(get_device ${MAC}); then
66 # Device is already attached to the bridge
67 exit ${EXIT_OK}
68 fi
69 message="Attaching ethernet port ${MAC}..."
70 device_rename $(get_device ${MAC}) $(port_name)
71 zone_add_port ${zone} $(get_device_by_mac ${MAC})
72 evaluate_retval
73 ;;
74
75 pre-down)
76 if zone_has_device_attached ${zone} $(get_device ${MAC}); then
77 message="Detatching ethernet port ${MAC}..."
78 zone_del_port ${zone} $(get_device_by_mac ${MAC})
79 device_rename $(get_device_by_mac ${MAC}) ${COMMON_DEVICE}
80 evaluate_retval
81 fi
82 ;;
83
84 post-down)
85 ## Possibly pull down the device (if there are no more vlan devices up...)
86 ;;
87
88 add)
89 ### XXX error handling
90
91 for dev in $@; do
92 MAC=$(macify ${dev})
93 UUID=$(uuid)
94 cat <<EOF > ${CONFIG_UUIDS}/${UUID}
95 HOOK="${HOOK_NAME}"
96 MAC="${MAC}"
97 EOF
98 ln -sf ${CONFIG_UUIDS}/${UUID} \
99 ${CONFIG_ZONES}/${zone}/${HOOK_NAME}-${UUID}
100
101 log_success_msg "Configuration successfully saved!"
102 echo " Device : $(devicify ${MAC})"
103 echo " MAC address : ${MAC}"
104 done
105 ;;
106
107 rem)
108 # XXX to be done
109 ;;
110
111 status)
112 echo -e "# ${CLR_BOLD_CYN}Ethernet port $(devicify ${MAC}) (${MAC})${NORMAL}"
113 echo -n "# State: "
114 if device_is_up ${MAC}; then
115 echo -e "${CLR_BOLD_GRN}up${NORMAL}"
116 else
117 echo -e "${CLR_BOLD_RED}down${NORMAL}"
118 fi
119 echo -n "# Link : "
120 if device_has_carrier ${MAC}; then
121 echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
122 else
123 echo -e "${CLR_BOLD_RED}no${NORMAL}"
124 fi
125 echo "#"
126
127 device_is_up ${MAC}
128 exit ${?}
129 ;;
130
131 *)
132 echo "Usage: ${0} [interface] {up|down|add|remove|attach|detach|status}"
133 exit 1
134 ;;
135 esac
136
137 # End $NETWORK_DEVICES/services/ethernet