57 |
57 |
58 . $ETHERCAT_CONFIG |
58 . $ETHERCAT_CONFIG |
59 |
59 |
60 #------------------------------------------------------------------------------ |
60 #------------------------------------------------------------------------------ |
61 |
61 |
|
62 # |
|
63 # Function for setting up the EoE bridge |
|
64 # |
|
65 build_eoe_bridge() { |
|
66 if [ -z "$EOE_BRIDGE" ]; then return; fi |
|
67 |
|
68 EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "` |
|
69 |
|
70 # add bridge, if it does not already exist |
|
71 if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then |
|
72 if ! /sbin/brctl addbr $EOE_BRIDGE; then |
|
73 /bin/false |
|
74 rc_status -v |
|
75 rc_exit |
|
76 fi |
|
77 fi |
|
78 |
|
79 # check if specified interfaces are bridged |
|
80 for interf in $EOEIF $EOE_EXTRA_INTERFACES; do |
|
81 # interface is already part of the bridge |
|
82 if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf |
|
83 then continue |
|
84 fi |
|
85 # clear IP address and open interface |
|
86 if ! /sbin/ifconfig $interf 0.0.0.0 up; then |
|
87 /bin/false |
|
88 rc_status -v |
|
89 rc_exit |
|
90 fi |
|
91 # add interface to the bridge |
|
92 if ! /sbin/brctl addif $EOE_BRIDGE $interf; then |
|
93 /bin/false |
|
94 rc_status -v |
|
95 rc_exit |
|
96 fi |
|
97 done |
|
98 |
|
99 # configure IP on bridge |
|
100 if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then |
|
101 if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \ |
|
102 netmask $EOE_IP_NETMASK; then |
|
103 /bin/false |
|
104 rc_status -v |
|
105 rc_exit |
|
106 fi |
|
107 fi |
|
108 |
|
109 # open bridge |
|
110 if ! /sbin/ifconfig $EOE_BRIDGE up; then |
|
111 /bin/false |
|
112 rc_status -v |
|
113 rc_exit |
|
114 fi |
|
115 |
|
116 # install new default gateway |
|
117 if [ -n "$EOE_GATEWAY" ]; then |
|
118 while /sbin/route -n | grep -E -q "^0.0.0.0"; do |
|
119 if ! /sbin/route del default; then |
|
120 echo "Failed to remove route!" 1>&2 |
|
121 /bin/false |
|
122 rc_status -v |
|
123 rc_exit |
|
124 fi |
|
125 done |
|
126 if ! /sbin/route add default gw $EOE_GATEWAY; then |
|
127 /bin/false |
|
128 rc_status -v |
|
129 rc_exit |
|
130 fi |
|
131 fi |
|
132 } |
|
133 |
|
134 #------------------------------------------------------------------------------ |
|
135 |
62 . /etc/rc.status |
136 . /etc/rc.status |
63 rc_reset |
137 rc_reset |
64 |
138 |
65 case "$1" in |
139 case "$1" in |
66 start) |
140 start) |
71 /bin/false |
145 /bin/false |
72 rc_status -v |
146 rc_status -v |
73 rc_exit |
147 rc_exit |
74 fi |
148 fi |
75 |
149 |
76 if [ -z "$EOE_DEVICES" ]; then |
150 if [ -z "$EOE_INTERFACES" ]; then |
77 EOE_DEVICES=0 |
151 if [ -n "$EOE_DEVICES"]; then # support legacy sysconfig files |
78 fi |
152 EOE_INTERFACES=$EOE_DEVICES |
79 |
153 else |
|
154 EOE_INTERFACES=0 |
|
155 fi |
|
156 fi |
|
157 |
|
158 # unload conflicting modules at first |
80 for mod in 8139too 8139cp; do |
159 for mod in 8139too 8139cp; do |
81 if lsmod | grep "^$mod " > /dev/null; then |
160 if lsmod | grep "^$mod " > /dev/null; then |
82 if ! rmmod $mod; then |
161 if ! rmmod $mod; then |
83 /bin/false |
162 /bin/false |
84 rc_status -v |
163 rc_status -v |
85 rc_exit |
164 rc_exit |
86 fi |
165 fi |
87 fi |
166 fi |
88 done |
167 done |
89 |
168 |
90 if ! modprobe ec_master ec_eoe_devices=$EOE_DEVICES; then |
169 # load master module |
|
170 if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then |
91 /bin/false |
171 /bin/false |
92 rc_status -v |
172 rc_status -v |
93 rc_exit |
173 rc_exit |
94 fi |
174 fi |
95 |
175 |
|
176 # load device module |
96 if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then |
177 if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then |
97 /bin/false |
178 /bin/false |
98 rc_status -v |
179 rc_status -v |
99 rc_exit |
180 rc_exit |
100 fi |
181 fi |
101 |
182 |
102 # Build EoE bridge |
183 # build EoE bridge |
103 if [ -n "$EOE_BRIDGE" ]; then |
184 build_eoe_bridge |
104 |
|
105 EOE_INTERFACES=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "` |
|
106 |
|
107 # add bridge, if it does not already exist |
|
108 if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then |
|
109 if ! /sbin/brctl addbr $EOE_BRIDGE; then |
|
110 /bin/false |
|
111 rc_status -v |
|
112 rc_exit |
|
113 fi |
|
114 fi |
|
115 |
|
116 # free all interfaces of their addresses and add them to the bridge |
|
117 for interface in $EOE_INTERFACES $EOE_EXTRA_INTERFACES; do |
|
118 if ! /sbin/ifconfig $interface 0.0.0.0 up; then |
|
119 /bin/false |
|
120 rc_status -v |
|
121 rc_exit |
|
122 fi |
|
123 if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE.*$interface"; then |
|
124 if ! /sbin/brctl addif $EOE_BRIDGE $interface; then |
|
125 /bin/false |
|
126 rc_status -v |
|
127 rc_exit |
|
128 fi |
|
129 fi |
|
130 done |
|
131 if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then |
|
132 if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \ |
|
133 netmask $EOE_IP_NETMASK; then |
|
134 /bin/false |
|
135 rc_status -v |
|
136 rc_exit |
|
137 fi |
|
138 fi |
|
139 if ! /sbin/ifconfig $EOE_BRIDGE up; then |
|
140 /bin/false |
|
141 rc_status -v |
|
142 rc_exit |
|
143 fi |
|
144 |
|
145 # install new default gateway |
|
146 if [ -n "$EOE_GATEWAY" ]; then |
|
147 while /sbin/route -n | grep -E -q "^0.0.0.0"; do |
|
148 if ! /sbin/route del default; then |
|
149 echo "Failed to remove default route!" 1>&2 |
|
150 /bin/false |
|
151 rc_status -v |
|
152 rc_exit |
|
153 fi |
|
154 done |
|
155 if ! /sbin/route add default gw $EOE_GATEWAY; then |
|
156 /bin/false |
|
157 rc_status -v |
|
158 rc_exit |
|
159 fi |
|
160 fi |
|
161 fi |
|
162 |
185 |
163 rc_status -v |
186 rc_status -v |
164 ;; |
187 ;; |
165 |
188 |
166 stop) |
189 stop) |
167 echo -n "Shutting down EtherCAT master " |
190 echo -n "Shutting down EtherCAT master " |
168 |
191 |
|
192 # unload modules |
169 for mod in ec_8139too ec_master; do |
193 for mod in ec_8139too ec_master; do |
170 if lsmod | grep "^$mod " > /dev/null; then |
194 if lsmod | grep "^$mod " > /dev/null; then |
171 if ! rmmod $mod; then |
195 if ! rmmod $mod; then |
172 /bin/false |
196 /bin/false |
173 rc_status -v |
197 rc_status -v |
174 rc_exit |
198 rc_exit |
175 fi; |
199 fi; |
176 fi; |
200 fi; |
177 done |
201 done |
178 |
202 |
|
203 sleep 1 |
|
204 |
|
205 # reload previous modules |
179 if ! modprobe 8139too; then |
206 if ! modprobe 8139too; then |
180 echo "Warning: Failed to restore 8139too module." |
207 echo "Warning: Failed to restore 8139too module." |
181 fi |
208 fi |
182 |
209 |
183 rc_status -v |
210 rc_status -v |
184 ;; |
211 ;; |
185 |
212 |
186 restart) |
213 restart) |
187 $0 stop |
214 $0 stop || exit 1 |
|
215 |
|
216 sleep 1 |
|
217 |
188 $0 start |
218 $0 start |
189 |
219 |
190 rc_status |
220 rc_status |
191 ;; |
221 ;; |
192 |
222 |
195 |
225 |
196 lsmod | grep "^ec_master " > /dev/null |
226 lsmod | grep "^ec_master " > /dev/null |
197 master_running=$? |
227 master_running=$? |
198 lsmod | grep "^ec_8139too " > /dev/null |
228 lsmod | grep "^ec_8139too " > /dev/null |
199 device_running=$? |
229 device_running=$? |
|
230 |
|
231 # master module and device module loaded? |
200 test $master_running -eq 0 -a $device_running -eq 0 |
232 test $master_running -eq 0 -a $device_running -eq 0 |
201 |
233 |
202 rc_status -v |
234 rc_status -v |
|
235 ;; |
|
236 |
|
237 bridge) |
|
238 echo -n "Building EoE bridge " |
|
239 |
|
240 build_eoe_bridge |
|
241 |
|
242 rc_status -v |
|
243 ;; |
|
244 |
|
245 *) |
|
246 echo "USAGE: $0 {start|stop|restart|status|bridge}" |
203 ;; |
247 ;; |
204 esac |
248 esac |
205 rc_exit |
249 rc_exit |
206 |
250 |
207 #------------------------------------------------------------------------------ |
251 #------------------------------------------------------------------------------ |