]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/pccard_ether
This commit was generated by cvs2svn to compensate for changes in r147801,
[FreeBSD/FreeBSD.git] / etc / pccard_ether
1 #!/bin/sh -
2 #
3 # $FreeBSD$
4 #
5 # pccard_ether interfacename [start|stop]
6 #
7 # example: pccard_ether fxp0 start
8 #
9
10 . /etc/rc.subr
11 . /etc/network.subr
12
13 usage()
14 {
15         err 3 'USAGE: $0 interface (start|stop)'
16 }
17
18 setup_routes()
19 {
20         # Add default route into $static_routes
21         case ${defaultrouter} in
22         [Nn][Oo] | '')
23                 ;;
24         *)
25                 static_routes="default ${static_routes}"
26                 route_default="default ${defaultrouter}"
27                 ;;
28         esac
29
30         # Add private route for this interface into $static_routes
31         eval ifx_routes=\$static_routes_${ifn}
32         if [ -n "${ifx_routes}" ]; then
33                 static_routes="${ifx_routes} ${static_routes}"
34         fi
35
36         # Set up any static routes if specified
37         if [ -n "${static_routes}" ]; then
38                 for i in ${static_routes}; do
39                         eval route_args=\$route_${i}
40                         route add ${route_args}
41                 done
42         fi
43 }
44
45 remove_routes()
46 {
47         # Delete static route if specified
48         eval ifx_routes=\$static_routes_${ifn}
49         if [ -n "${ifx_routes}" ]; then
50                 for i in ${ifx_routes}; do
51                         eval route_args=\$route_${i}
52                         route delete ${route_args}
53                 done
54         fi
55 }
56
57 ifn=$1
58 shift
59 startstop=$1
60 shift
61
62 load_rc_config pccard_ether
63
64 # Ignore interfaces not in removable_interfaces
65 expr "${removable_interfaces}" : ".*${ifn}" > /dev/null || exit 0
66
67 if [ -n "$1" ]; then
68         usage
69 fi
70
71 case ${startstop} in
72 [Ss][Tt][Aa][Rr][Tt] | '')
73         if [ -x /usr/bin/grep ]; then
74                 if ifconfig $ifn | grep -s netmask > /dev/null 2>&1; then
75                     # Interface is already up, so ignore it.
76                     exit 0
77                 fi
78         fi
79
80         /etc/rc.d/netif start $ifn
81
82         # Do route configuration if needed.
83         # XXX: should probably do this by calling rc.d/routing.
84         if [ -n "`ifconfig_getargs $ifn`" ]; then
85                 if ! dhcpif $ifn; then
86                         setup_routes
87                 fi
88         fi
89
90         # IPv6 setup
91         if checkyesno ipv6_enable; then
92                 network6_interface_setup $ifn
93         fi
94         ;;
95
96 # Stop the interface
97 [Ss][Tt][Oo][Pp])
98         if [ -n "`ifconfig_getargs $ifn`" ]; then
99                 if ! dhcpif $ifn; then
100                         remove_routes
101                 fi
102         fi
103
104         /etc/rc.d/netif stop $ifn
105
106         # clean ARP table
107         arp -d -a
108
109         # Clean the routing table
110         if checkyesno removable_route_flush; then
111                 route -n flush -inet > /dev/null
112         fi
113         ;;
114 *)
115         usage
116 esac