+ # Check if a cable is plugged for wired interface
+ if echo "${DEVICE}" | grep -q "eth" ; then
+ count=0
+ while cat /sys/class/net/${DEVICE}/carrier | grep -q "0"; do
+ echo "Waiting for carrier to go up"
+ sleep 0.25
+
+ let count=count+1
+ # 2.5 seconds delay
+ if [ $count -gt 10 ]; then
+ echo "Interface ${DEVICE}: carrier not detected (cable unplugged?)"
+ exit ${EXIT_CODE_WARNING}
+ fi
+ done
+ fi
+}
+
+# Static IP address protocol
+proto_static()
+{
+ cmd_run_log ip addr add ${IPADDR}/${NETMASK_LENGTH} dev ${DEVICE} \
+ brd + ${IFSCOPE} || exit ${EXIT_CODE_FAILURE}
+
+ # Bring interface up
+ bring_if_up
+
+ if [ -n "${GATEWAY}" ]; then
+ cmd_run_log ip route add default via ${GATEWAY} || \
+ exit ${EXIT_CODE_FAILURE}
+ fi
+}
+
+# Obtain IP address from DHCP
+proto_dhcp()
+{
+ # Bring interface up
+ bring_if_up
+
+ cmd_run_log ${DHCP_PROG} ${DHCP_START} ${DEVICE}
+}
+
+proto_wireless()
+{
+ # Bring interface up
+ bring_if_up
+
+ # Check if a socket exists, meaning wpa_supplicant is running
+ if [ -S /var/run/wpa_supplicant/${DEVICE} ]; then
+ echo "wpa_supplicant already running"
+
+ # Make sure wpa_supplicant is responding
+ if ! wpa_cli -i ${DEVICE} status; then
+ echo "Stopping unresponding wpa_supplicant"
+ killall wpa_supplicant
+ rm /var/run/wpa_supplicant/${DEVICE}
+ fi
+ fi
+
+ # Start wpa_supplicant if it is not running
+ if [ ! -S /var/run/wpa_supplicant/${DEVICE} ]; then
+ echo "Starting wpa_supplicant"
+ wpa_supplicant ${WPA_SUPP_OPTS} -i ${DEVICE}