]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blame - pkgs/core/network/src/hooks/ethernet
network: New package.
[people/amarx/ipfire-3.x.git] / pkgs / core / network / src / hooks / ethernet
CommitLineData
6c72e5f5
MT
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
02dbf7e7 15. /lib/network/hook-header
b9947383 16
6ad03435
MT
17HOOK_NAME=ethernet
18HOOK_TYPE=port
ae69ea7e 19
cd1bc684 20function port_name() {
bb1844e1 21 echo ${zone}p+
cd1bc684
MT
22}
23
6ad03435
MT
24case "${action}" in
25 help)
e68e56b5
MT
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."
2b6a66e1 38 #echo " Example: --port=port0 or --port=00:11:22:33:44:55"
e68e56b5
MT
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
2b6a66e1 50 echo " Example: network zone addport green0 ethernet port0"
e68e56b5
MT
51 echo " network zone addport green0 ethernet 00:11:22:33:44:55"
52 echo
6ad03435
MT
53 ;;
54
55 info)
56 echo "HOOK_NAME=${HOOK_NAME}"
57 echo "HOOK_TYPE=${HOOK_TYPE}"
58 ;;
59
42b87165
MT
60 pre-up)
61 device_is_up ${MAC} || ip link set $(devicify ${MAC}) up
e70f9d78 62 ;;
42b87165
MT
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...)
e70f9d78 86 ;;
6c72e5f5 87
ae69ea7e 88 add)
42b87165
MT
89 ### XXX error handling
90
91 for dev in $@; do
92 MAC=$(macify ${dev})
93 UUID=$(uuid)
94 cat <<EOF > ${CONFIG_UUIDS}/${UUID}
95HOOK="${HOOK_NAME}"
96MAC="${MAC}"
ae69ea7e 97EOF
42b87165
MT
98 ln -sf ${CONFIG_UUIDS}/${UUID} \
99 ${CONFIG_ZONES}/${zone}/${HOOK_NAME}-${UUID}
ae69ea7e 100
42b87165
MT
101 log_success_msg "Configuration successfully saved!"
102 echo " Device : $(devicify ${MAC})"
103 echo " MAC address : ${MAC}"
104 done
e70f9d78 105 ;;
90af6f24 106
42b87165
MT
107 rem)
108 # XXX to be done
e70f9d78 109 ;;
cd1bc684
MT
110
111 status)
26bfb541
MT
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}"
42b87165 122 else
26bfb541 123 echo -e "${CLR_BOLD_RED}no${NORMAL}"
42b87165 124 fi
26bfb541
MT
125 echo "#"
126
127 device_is_up ${MAC}
128 exit ${?}
e70f9d78 129 ;;
90af6f24 130
6c72e5f5 131 *)
cd1bc684 132 echo "Usage: ${0} [interface] {up|down|add|remove|attach|detach|status}"
6c72e5f5 133 exit 1
e70f9d78 134 ;;
6c72e5f5
MT
135esac
136
137# End $NETWORK_DEVICES/services/ethernet