]>
git.ipfire.org Git - people/stevee/network.git/blob - hooks/ethernet
2 ########################################################################
3 # Begin $NETWORK_DEVICES/services/ethernet
5 # Description : Ethernet Script
7 # Authors : Michael Tremer - michael.tremer@ipfire.org
11 # Notes : This script adds ethernet support.
13 ########################################################################
15 .
/lib
/network
/hook-header
20 function port_name
() {
26 echo -e "${BOLD}Hook (${HOOK_NAME}) help:"
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."
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"
43 #echo -e " ${BOLD}Commands:${NORMAL}"
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."
50 echo " Example: network zone addport green0 ethernet port0"
51 echo " network zone addport green0 ethernet 00:11:22:33:44:55"
56 echo "HOOK_NAME=${HOOK_NAME}"
57 echo "HOOK_TYPE=${HOOK_TYPE}"
61 device_is_up
${MAC} || ip link
set $
(devicify
${MAC}) up
65 if zone_has_device_attached
${zone} $
(get_device
${MAC}); then
66 # Device is already attached to the bridge
69 message
="Attaching ethernet port ${MAC}..."
70 device_rename $
(get_device
${MAC}) $
(port_name
)
71 zone_add_port
${zone} $
(get_device_by_mac
${MAC})
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}
85 ## Possibly pull down the device (if there are no more vlan devices up...)
89 ### XXX error handling
94 cat <<EOF > ${CONFIG_UUIDS}/${UUID}
98 ln -sf ${CONFIG_UUIDS}/${UUID} \
99 ${CONFIG_ZONES}/${zone}/${HOOK_NAME}-${UUID}
101 log_success_msg
"Configuration successfully saved!"
102 echo " Device : $(devicify ${MAC})"
103 echo " MAC address : ${MAC}"
112 echo -e "# ${CLR_BOLD_CYN}Ethernet port $(devicify ${MAC}) (${MAC})${NORMAL}"
114 if device_is_up
${MAC}; then
115 echo -e "${CLR_BOLD_GRN}up${NORMAL}"
117 echo -e "${CLR_BOLD_RED}down${NORMAL}"
120 if device_has_carrier
${MAC}; then
121 echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
123 echo -e "${CLR_BOLD_RED}no${NORMAL}"
132 echo "Usage: ${0} [interface] {up|down|add|remove|attach|detach|status}"
137 # End $NETWORK_DEVICES/services/ethernet