]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/pccard_ether
This commit was generated by cvs2svn to compensate for changes in r162079,
[FreeBSD/FreeBSD.git] / etc / pccard_ether
1 #!/bin/sh -
2 #
3 # $FreeBSD$
4 #
5 # pccard_ether interfacename [start|stop|restart]
6 #
7 # example: pccard_ether fxp0 start
8 #
9
10 . /etc/rc.subr
11 . /etc/network.subr
12
13 name="pccard_ether"
14 start_precmd="checkauto"
15 start_cmd="pccard_ether_start"
16 stop_precmd="checkauto"
17 stop_cmd="pccard_ether_stop"
18 restart_precmd="checkauto"
19 restart_cmd="pccard_ether_restart"
20
21 setup_routes()
22 {
23         # Add default route into $static_routes
24         case ${defaultrouter} in
25         [Nn][Oo] | '')
26                 ;;
27         *)
28                 static_routes="default ${static_routes}"
29                 route_default="default ${defaultrouter}"
30                 ;;
31         esac
32
33         # Add private route for this interface into $static_routes
34         eval ifx_routes=\$static_routes_${ifn}
35         if [ -n "${ifx_routes}" ]; then
36                 static_routes="${ifx_routes} ${static_routes}"
37         fi
38
39         # Set up any static routes if specified
40         if [ -n "${static_routes}" ]; then
41                 for i in ${static_routes}; do
42                         eval route_args=\$route_${i}
43                         route add ${route_args}
44                 done
45         fi
46 }
47
48 remove_routes()
49 {
50         # Delete static route if specified
51         eval ifx_routes=\$static_routes_${ifn}
52         if [ -n "${ifx_routes}" ]; then
53                 for i in ${ifx_routes}; do
54                         eval route_args=\$route_${i}
55                         route delete ${route_args}
56                 done
57         fi
58 }
59
60 checkauto()
61 {
62         if [ -z "$rc_force" ]; then
63                 # Ignore interfaces with the NOAUTO keyword
64                 autoif $ifn || exit 0
65         fi
66 }
67
68 pccard_ether_start()
69 {
70         ifexists $ifn || exit 1
71
72         if [ -z "$rc_force" -a -x /usr/bin/grep ]; then
73                 if ifconfig $ifn | grep -s '[<,]UP[,>]' > /dev/null 2>&1; then
74                     # Interface is already up, so ignore it.
75                     exit 0
76                 fi
77         fi
78
79         /etc/rc.d/netif start $ifn
80
81         # Do route configuration if needed.
82         # XXX: should probably do this by calling rc.d/routing.
83         if [ -n "`ifconfig_getargs $ifn`" ]; then
84                 if ! dhcpif $ifn; then
85                         setup_routes
86                 fi
87         fi
88
89         # IPv6 setup
90         if checkyesno ipv6_enable; then
91                 network6_interface_setup $ifn
92         fi
93 }
94
95 pccard_ether_stop()
96 {
97         if [ -n "`ifconfig_getargs $ifn`" ]; then
98                 if ! dhcpif $ifn; then
99                         remove_routes
100                 fi
101         fi
102
103         /etc/rc.d/netif stop $ifn
104
105         # clean ARP table
106         ifexists $ifn && arp -d -i $ifn -a
107
108         # Clean the routing table
109         if checkyesno removable_route_flush; then
110                 route -n flush -inet > /dev/null
111         fi
112 }
113
114 pccard_ether_restart()
115 {
116         # Hand implemented because the default implementation runs
117         # the equivalent of "$0 start; $0 stop" and this script
118         # doesn't support that syntax
119         pccard_ether_stop
120         pccard_ether_start
121 }
122
123 ifn=$1
124 shift
125 if [ -z "$*" ]; then
126         args="start"
127 else
128         args=$*
129 fi
130
131 load_rc_config pccard_ether
132 run_rc_command $args