aboutsummaryrefslogtreecommitdiffstats
path: root/sysconfig/network-scripts/ifup-hdlc
blob: 63cfa92cea883dc9c28d5d1fba1c0db141bfc0c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/sh
#
#  ifup-hdlc  --  Interface config script for up'ing HDLC devices
#             by  ||ugh Daniel <hugh@toad.com> 2000/02/18
#                 Copyright (C) 2000, under the terms of the GPLv2
#                 portions of this code are from the ifup script
#
#  RCSID $Id: ifup-hdlc,v 1.1 2000/02/25 15:55:27 notting Exp $
#
#

#
#  This script is called via network-scripts/ifup's OTHERSCRIPT mechanism
#  Tested and found working for LMC cards on RedHat-6.1 systems.

PATH=/sbin:/usr/sbin:/bin:/usr/bin

cd /etc/sysconfig/network-scripts
. network-functions

need_hostname

CONFIG=$1

[ -z "$CONFIG" ] && {
	echo "usage: ifup-hdlc <device name>" >&2
	exit 1
}

[ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIG
[ -f "$CONFIG" ] || {
	echo "$0: no settings file for <device name>" >&2
	exit 1
}

if [ $UID != 0 ]; then
	if [ -x /usr/sbin/usernetctl ]; then
		if /usr/sbin/usernetctl $CONFIG report ; then
			exec /usr/sbin/usernetctl $CONFIG up
		fi
	fi
	echo "Users cannot control this device." >&2
	exit 1
fi

source_config

if [ "foo$2" = "fooboot" -a "${ONBOOT}" = "no" ]; then
	exit
fi

DEVICETYPE=`echo $DEVICE | sed "s/[0-9]*$//"`
REALDEVICE=`echo $DEVICE | sed 's/:.*//g'`
if echo $DEVICE | grep -q ':' ; then
	ISALIAS=yes
  else
	ISALIAS=no
fi

if [ -z "${DEVICE}" ] ; then
	# Sysadmin must state driver device file
	# FIXUP: this could/should come from the command line argument
	echo "$0: Error: no DEVICE= setting in ./$CONFIG" >&2
	exit 1
fi

if [ -z "${IPADDR}" ] ; then
	# Sysadmin must state our ends IP address in the config file
	echo "$0: Error: no IPADDR= setting in ./$CONFIG" >&2
	exit 1
fi

if [ -z "${POINTOPOINT}" ] ; then
	# Sysadmin must state other ends IP address in the config file
	echo "$0: Error: no POINTOPOINT= setting in ./$CONFIG" >&2
	exit 1
fi

#
#  WARNING: this currently only works for LMC cards...
#  FIXUP: we need a general interface for all cards on this...
#	hdlcctl -i DEV --interface DEV --linkencap=cisco --status # etc.
if [ -n "${LINKENCAP}" ]; then
	# The sysadmin needs to explictly set the line line encapsulation
	# Possbile values: cisco, syncppp, ???
	PATH=${PATH}:/usr/local/sbin
	if [ -z "`type -path lmcctl`" ]; then
		# Can't find the 
		echo "$0: Error: can't find the lmcctl sbinary command" >&2
		exit 1
	fi
	case  "${LINKENCAP}" in
	  "syncppp")
		/sbin/ifconfig ${DEVICE} down
		lmcctl -i ${DEVICE} -P
		retval=$?
		if [ $retval -ne 0 ]; then
			# Something failed
			echo "$0: Failed: could not set the requested line encap (${LINKENCAP}) on ${DEVICE}, error number ${retval}." >&2
		fi
		;;
	  "cisco")
		/sbin/ifconfig ${DEVICE} down
		lmcctl -i ${DEVICE} -p
		retval=$?
		if [ $retval -ne 0 ]; then
			# Something failed
			echo "$0: Failed: could not set the requested line encap (${LINKENCAP}) on ${DEVICE}, error number ${retval}." >&2
		fi
		;;
	  *)
		# Unknown link encapsulation error
		echo "$0: Error: LINKENCAP type (${LINKENCAP}) unknown." >&2
		exit 1
	esac
fi

# Warning: this block of code is, by nature, vendor specific.
if [ -n "${LMCCTL}" ]; then
	# The user wants to run a LMC (www.lanmedia.com) cards control command
	PATH=${PATH}:/usr/local/sbin
	if [ -z "`type -path lmcctl`" ]; then
		# Can't find the 
		echo "$0: Error: can't find the lmcctl sbinary command" >&2
		exit 1
	fi
	/sbin/ifconfig ${DEVICE} down
	lmcctl -i ${DEVICE} ${LMCCTL}
	retval=$?
	if [ $retval -ne 0 ]; then
		# Something went wrong
		echo "$0: Error: The LMCCTL for ${DEVICE} failed, returning ${retval}" >&2
		exit ${retval}
	fi
fi

# is this device available? (this catches PCMCIA devices for us)
/sbin/ifconfig ${REALDEVICE} 2>&1 | grep -s "not found" > /dev/null
if [ "$?" = "0" ]; then
    echo "Delaying ${DEVICE} initialization due to missing device."
    exit 1
fi

/sbin/ifconfig ${DEVICE} up ${IPADDR} pointopoint ${POINTOPOINT} netmask 255.255.255.255
retval=$?

if [ ${retval} -ne 0 ]; then
	#  The ifconfig failed, report it to the poor sysadmin
        echo "$0: Failure: ifconfig of ${DEVICE} failed with a return value of ${retval}" >&2
	exit ${retval}
fi

. /etc/sysconfig/network

if [ "${GATEWAY}" != "" ]; then
	if [ "${GATEWAYDEV}" = "" -o "${GATEWAYDEV}" = "${DEVICE}" ]; then
	# set up default gateway
		route add default gw ${GATEWAY} ${DEVICE}
		retval=$?
		if [ ${retval} -ne 0 ]; then
			# The g
			echo "$0: Error: failed to install the default route on ${DEVICE}" >&2
			exit ${retval}
		fi
		DEFGW=${GATEWAY}
	fi
fi

if [ "$IPX" = yes ]; then
	/etc/sysconfig/network-scripts/ifup-ipx $DEVICE
fi

exec /etc/sysconfig/network-scripts/ifup-post $CONFIG