It should be a fast-forward merge instead of this.
Revert "Merge tag '0.12' into debian"
This reverts commit 047e235bf52e57eccee541f449d4982018a3089f.
Benda Xu
10 years ago
4 | 4 | include Makefile.inc |
5 | 5 | |
6 | 6 | SUBDIR= conf.d etc init.d local.d man scripts sh src sysctl.d |
7 | ||
8 | # Build our old net foo or not | |
9 | ifeq (${MKNET},oldnet) | |
10 | SUBDIR+= net doc | |
11 | endif | |
7 | 12 | |
8 | 13 | # Build pkgconfig or not |
9 | 14 | MKPKGCONFIG?= yes |
9 | 9 | PROGLDFLAGS=-static |
10 | 10 | LIBNAME=lib64 |
11 | 11 | DESTDIR=/tmp/openrc-image |
12 | MKNET=no | |
12 | MKNET=oldnet | |
13 | 13 | MKPAM=pam |
14 | 14 | MKPREFIX=yes |
15 | 15 | MKPKGCONFIG=no |
17 | 17 | MKSTATICLIBS=no |
18 | 18 | MKTERMCAP=ncurses |
19 | 19 | MKTERMCAP=termcap |
20 | MKTOOLS=yes | |
21 | 20 | PKG_PREFIX=/usr/pkg |
22 | 21 | LOCAL_PREFIX=/usr/local |
23 | 22 | PREFIX=/usr/local |
56 | 55 | tweaking on a per distro basis. They are also non essential to the operation |
57 | 56 | of the system. |
58 | 57 | |
59 | As of OpenRC-0.12, the net.* scripts, originally from Gentoo Linux, have | |
60 | been removed. If you need these scripts, look for a package called | |
61 | netifrc, which is maintained by them. | |
62 | 58 | |
63 | 59 | Reporting Bugs |
64 | 60 | -------------- |
0 | Using Busybox as your Default Shell | |
1 | ----------------------------------- | |
2 | ||
3 | ||
4 | If you have/bin/sh linked to busybox, you need to be aware of several | |
5 | incompatibilities between busybox's applets and the standalone | |
6 | counterparts. Since it is possible to configure busybox to not include | |
7 | these applets or to prefer the standalone counterparts, OpenRC does not | |
8 | attempt to support the busybox applets. | |
9 | ||
10 | All of these apply to busybox 1.20.2, which is the current version of | |
11 | busybox as of this writing. | |
12 | ||
13 | 1. The start-stop-daemon applet is not compatible with start-stop-daemon | |
14 | in OpenRC. Please make sure CONFIG_START_STOP_DAEMON is not set to y in | |
15 | the configuration file you use to build busybox. | |
16 | ||
17 | 2. The -O option for the mount applet does not support the [no]_netdev | |
18 | options from util-linux for handling network file systems. | |
19 | ||
20 | 3. The umount applet does not support the -O option from util-linux. | |
21 | ||
22 | 4. The swapon applet does not support the -e option from util-linux. | |
23 | ||
24 | 5. the setfont applet does not support the -u option from kbd. | |
25 | ||
26 | There is work to get most of these supported by busybox, so this file | |
27 | will be updated as things change. |
0 | The following applies only to the newnet stack, which is not presently | |
1 | maintained in OpenRC. The oldnet stack is maintained instead. | |
2 | - Robin H. Johnson <robbat2@gentoo.org>, 2011/02/21 | |
3 | ||
0 | 4 | OpenRC Network Ideals |
1 | 5 | --------------------- |
2 | 6 |
50 | 50 | the body entirely); tools like rebase can get confused if you run the |
51 | 51 | two together. |
52 | 52 | |
53 | Write your commit message in the imperative: "Fix bug" and not "Fixed | |
53 | Write your commit message in the present tense: "Fix bug" and not "Fixed | |
54 | 54 | bug." This convention matches up with commit messages generated by |
55 | 55 | commands like git merge and git revert. |
56 | 56 |
0 | include ../mk/net.mk | |
1 | ||
2 | 0 | DIR= ${CONFDIR} |
3 | 1 | CONF= bootmisc fsck hostname localmount netmount urandom tmpfiles \ |
4 | 2 | ${CONF-${OS}} |
5 | 3 | |
6 | ifeq (${MKNET},yes) | |
4 | ifeq (${MKNET},) | |
7 | 5 | CONF+= network staticroute |
8 | 6 | TARGETS+= network staticroute |
9 | 7 | CLEANFILES+= network staticroute |
0 | # This blank configuration will automatically use DHCP for any net.* | |
1 | # scripts in /etc/init.d. To create a more complete configuration, | |
2 | # please review /usr/share/doc/openrc*/net.example* and save your configuration | |
3 | # in /etc/conf.d/net (this file :]!). |
6 | 6 | # You also have ifup_eth0 and ifdown_eth0 to run other commands when |
7 | 7 | # eth0 is started and stopped. |
8 | 8 | # You should note that we don't stop the network at system shutdown by default. |
9 | # If you really need this, then set keep_network=NO | |
9 | # If you really need this, then set shutdown_network=YES | |
10 | 10 | |
11 | 11 | # Lastly, the interfaces variable pulls in virtual interfaces that cannot |
12 | 12 | # be automatically detected. |
0 | net.example |
0 | DIR= ${DOCDIR}/openrc | |
1 | SRCS= net.example.in | |
2 | INC= net.example | |
3 | ||
4 | MK= ../mk | |
5 | include ${MK}/os.mk | |
6 | ||
7 | %.example.in: %.example${SFX} | |
8 | ${CP} $< $@ | |
9 | ||
10 | include ${MK}/scripts.mk |
0 | ############################################################################## | |
1 | # QUICK-START | |
2 | # | |
3 | # The quickest start is if you want to use DHCP. | |
4 | # In that case, everything should work out of the box, no configuration | |
5 | # necessary, though the startup script will warn you that you haven't | |
6 | # specified anything. | |
7 | ||
8 | # WARNING :- some examples have a mixture of IPv4 (ie 192.168.0.1) and IPv6 | |
9 | # (ie 4321:0:1:2:3:4:567:89ab) internet addresses. They only work if you have | |
10 | # the relevant kernel option enabled. So if you don't have an IPv6 enabled | |
11 | # kernel then remove the IPv6 address from your config. | |
12 | ||
13 | # If you want to use a static address or use DHCP explicitly, jump | |
14 | # down to the section labeled INTERFACE HANDLERS. | |
15 | # | |
16 | # If you want to do anything more fancy, you should take the time to | |
17 | # read through the rest of this file. | |
18 | ||
19 | ############################################################################## | |
20 | # MODULES | |
21 | # | |
22 | # We now support modular networking scripts which means we can easily | |
23 | # add support for new interface types and modules while keeping | |
24 | # compatibility with existing ones. | |
25 | # | |
26 | # Modules load by default if the package they need is installed. If | |
27 | # you specify a module here that doesn't have its package installed | |
28 | # then you get an error stating which package you need to install. | |
29 | # Ideally, you only use the modules setting when you have two or more | |
30 | # packages installed that supply the same service. | |
31 | # | |
32 | # In other words, you probably should DO NOTHING HERE... | |
33 | ||
34 | ############################################################################## | |
35 | # INTERFACE HANDLERS | |
36 | ||
37 | # For a static configuration, use something like this | |
38 | #config_eth0="192.168.0.2/24" | |
39 | ||
40 | # If you need more than one address, you can use something like this | |
41 | # NOTE: ifconfig creates an aliased device for each extra IPv4 address | |
42 | # (eth0:1, eth0:2, etc) | |
43 | # iproute2 does not do this as there is no need to | |
44 | #config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24" | |
45 | ||
46 | # You can also use IPv6 addresses | |
47 | # (you should always specify a prefix length with IPv6 here) | |
48 | #config_eth0="192.168.0.2/24 4321:0:1:2:3:4:567:89ab/64 4321:0:1:2:3:4:567:89ac/64" | |
49 | ||
50 | # If you wish to keep existing addresses + routing and the interface is up, | |
51 | # you can specify a noop (no operation). If the interface is down or there | |
52 | # are no addresses assigned, then we move onto the next step (default dhcp) | |
53 | # This is useful when configuring your interface with a kernel command line | |
54 | # or similar | |
55 | #config_eth0="noop 192.168.0.2/24" | |
56 | ||
57 | # If you don't want ANY address (only useful when calling for advanced stuff) | |
58 | #config_eth0="null" | |
59 | ||
60 | # Here's how to do routing if you need it | |
61 | # We add an IPv4 default route, IPv4 subnet route and an IPv6 unicast route | |
62 | #routes_eth0="default via 192.168.0.1 | |
63 | #10.0.0.0/8 via 192.168.0.1 | |
64 | #::/0" | |
65 | ||
66 | # If a specified module fails (like dhcp - see below), you can specify a | |
67 | # fallback like so | |
68 | #fallback_eth0="192.168.0.2 netmask 255.255.255.0" | |
69 | #fallback_routes_eth0="default via 192.168.0.1" | |
70 | ||
71 | # NOTE: fallback entry must match the entry location in config_eth0 | |
72 | # As such you can only have one fallback route. | |
73 | # Also, if you do not set a fallback_routes entry for an interface, the | |
74 | # routes entry will be used if that is set. | |
75 | ||
76 | # Some users may need to alter the MTU - here's how | |
77 | #mtu_eth0="1500" | |
78 | ||
79 | # Most drivers that report carrier status function correctly, but some do not | |
80 | # One of these faulty drivers is for the Intel e1000 network card, but only | |
81 | # at boot time. To get around this you may alter the carrier_timeout value for | |
82 | # the interface. 0 is disable and any other number of seconds is how | |
83 | # long we wait for carrier. The current default is disabled. | |
84 | #carrier_timeout_eth0=0 | |
85 | ||
86 | # You may wish to disable the interface being brought down when stopping. | |
87 | # This is only of use for WakeOnLan. | |
88 | #ifdown_eth0="NO" | |
89 | ||
90 | ############################################################################## | |
91 | # OPTIONAL MODULES | |
92 | ||
93 | #----------------------------------------------------------------------------- | |
94 | # WIRELESS (802.11 support) | |
95 | # Wireless can be provided by BSDs ifconfig (iwconfig) or wpa_supplicant | |
96 | # wpa_supplicant is preferred, use the modules directive to prefer iwconfig. | |
97 | #modules="iwconfig" | |
98 | ||
99 | # ifconfig (iwconig) support is a one shot script - wpa_supplicant is daemon | |
100 | # that scans, associates and re-configures if association is lost. | |
101 | # We call it iwconfig to separate the wireless setup from ifconfig. | |
102 | #################################### | |
103 | # HINTS | |
104 | # | |
105 | # Most users will just need to set the following options | |
106 | # key_SSID1="s:yourkeyhere enc open" # s: means a text key | |
107 | # key_SSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key | |
108 | # preferred_aps="SSID1 SSID2" | |
109 | # | |
110 | # Clear? Good. Now configure your wireless network below | |
111 | ||
112 | #################################### | |
113 | # SETTINGS | |
114 | # Hard code an SSID to an interface - leave this unset if you wish the driver | |
115 | # to scan for available Access Points | |
116 | # I would only set this as a last resort really - use the preferred_aps | |
117 | # setting at the bottom of this file | |
118 | #essid_eth0='foo' | |
119 | ||
120 | # Some drivers/hardware don't scan all that well. We have no control over this | |
121 | # but we can say how many scans we want to do to try and get a better sweep of | |
122 | # the area. The default is 1. | |
123 | #scans_eth0="1" | |
124 | ||
125 | #Channel can be set (1-14), but defaults to 3 if not set. | |
126 | # | |
127 | # The below is taken verbatim from the BSD wavelan documentation found at | |
128 | # http://www.netbsd.org/Documentation/network/wavelan.html | |
129 | # There are 14 channels possible; We are told that channels 1-11 are legal for | |
130 | # North America, channels 1-13 for most of Europe, channels 10-13 for France, | |
131 | # and only channel 14 for Japan. If in doubt, please refer to the documentation | |
132 | # that came with your card or access point. Make sure that the channel you | |
133 | # select is the same channel your access point (or the other card in an ad-hoc | |
134 | # network) is on. The default for cards sold in North America and most of Europe | |
135 | # is 3; the default for cards sold in France is 11, and the default for cards | |
136 | # sold in Japan is 14. | |
137 | #channel_eth0="3" | |
138 | ||
139 | # Setup any other config commands. This is basically the ifconfig argument | |
140 | # without the ifconfig $iface. | |
141 | #ifconfig_eth0="" | |
142 | # You can do the same per SSID too. | |
143 | #ifconfig_SSID="" | |
144 | ||
145 | # Seconds to wait until associated. The default is to wait 10 seconds. | |
146 | # 0 means wait indefinitely. WARNING: this can cause an infinite delay when | |
147 | # booting. | |
148 | #associate_timeout_eth0="5" | |
149 | ||
150 | # Define a WEP key per SSID or MAC address (of the AP, not your card) | |
151 | # The encryption type (open or restricted) must match the | |
152 | # encryption type on the Access Point. | |
153 | # To set a hex key, prefix with 0x | |
154 | #key_SSID="0x12341234123412341234123456" | |
155 | # or you can use strings. Passphrase IS NOT supported | |
156 | #key_SSID="foobar" | |
157 | #key_SSID="foobar" | |
158 | ||
159 | # WEP key for the AP with MAC address 001122334455 | |
160 | #mac_key_001122334455="foobar" | |
161 | ||
162 | # You can also override the interface settings found in /etc/conf.d/net | |
163 | # per SSID - which is very handy if you use different networks a lot | |
164 | #config_SSID="dhcp" | |
165 | #routes_SSID= | |
166 | #fallback_SSID= | |
167 | ||
168 | # Setting name/domain server causes /etc/resolv.conf to be overwritten | |
169 | # Note that if DHCP is used, and you want this to take precedence then | |
170 | # please put -R in your dhcpcd options | |
171 | #dns_servers_SSID="192.168.0.1 192.168.0.2" | |
172 | #dns_domain_SSID="some.domain" | |
173 | #dns_search_SSID="search.this.domain search.that.domain" | |
174 | # Please check the man page for resolv.conf for more information | |
175 | # as domain and search (searchdomains) are mutually exclusive and | |
176 | # searchdomains takes precedence | |
177 | ||
178 | # You can also set any of the /etc/conf.d/net variables per MAC address | |
179 | # incase you use Access Points with the same SSID but need different | |
180 | # networking configs. Below is an example - of course you use the same | |
181 | # method with other variables | |
182 | #config_001122334455="dhcp" | |
183 | #dns_servers_001122334455="192.168.0.1 192.168.0.2" | |
184 | ||
185 | # Map a MAC address to an SSID | |
186 | # This is used when the Access Point is not broadcasting its SSID | |
187 | # WARNING: This will override the SSID being broadcast due to some | |
188 | # Access Points sending an SSID even when they have been configured | |
189 | # not to! | |
190 | # Change 001122334455 to the MAC address and SSID to the SSID | |
191 | # it should map to | |
192 | #mac_essid_001122334455="SSID" | |
193 | ||
194 | # This lists the preferred SSIDs to connect to in order | |
195 | # SSID's can contain any characters here as they must match the broadcast | |
196 | # SSID exactly. | |
197 | # Surround each SSID with the " character and separate them with a space | |
198 | # If the first SSID isn't found then it moves onto the next | |
199 | # If this isn't defined then it connects to the first one found | |
200 | #preferred_aps="SSID1 SSID2" | |
201 | ||
202 | # You can also define a preferred_aps list per interface | |
203 | #preferred_aps_eth0="SSID3 SSID4" | |
204 | ||
205 | # You can also say whether we only connect to preferred APs or not | |
206 | # Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" | |
207 | # and "forceany" | |
208 | # "any" means it will connect to visible APs in the preferred list and then | |
209 | # any other available AP | |
210 | # "preferredonly" means it will only connect to visible APs in the preferred | |
211 | # list | |
212 | # "forcepreferred" means it will forcibly connect to APs in order if it does | |
213 | # not find them in a scan | |
214 | # "forcepreferredonly" means it forcibly connects to the APs in order and | |
215 | # does not bother to scan | |
216 | # "forceany" does the same as forcepreferred + connects to any other | |
217 | # available AP | |
218 | # Default is "any" | |
219 | #associate_order="any" | |
220 | #associate_order_eth0="any" | |
221 | ||
222 | # You can define blacklisted Access Points in the same way | |
223 | #blacklist_aps="SSID1 SSID2" | |
224 | #blacklist_aps_eth0="SSID3 SSID4" | |
225 | ||
226 | # If you have more than one wireless card, you can say if you want | |
227 | # to allow each card to associate with the same Access Point or not | |
228 | # Values are "yes" and "no" | |
229 | # Default is "yes" | |
230 | #unique_ap="yes" | |
231 | #unique_ap_eth0="yes" | |
232 | ||
233 | # IMPORTANT: preferred_only, blacklisted_aps and unique_ap only work when | |
234 | # essid_eth0 is not set and your card is capable of scanning | |
235 | ||
236 | # NOTE: preferred_aps list ignores blacklisted_aps - so if you have | |
237 | # the same SSID in both, well, you're a bit silly :p | |
238 | ||
239 | ################################################## | |
240 | # wpa_supplicant | |
241 | # emerge net-wireless/wpa_supplicant | |
242 | # Wireless options are held in /etc/wpa_supplicant/wpa_supplicant.conf | |
243 | # Consult the wpa_supplicant.conf.example that is installed in | |
244 | # /usr/share/doc/wpa_supplicant | |
245 | ||
246 | # By default we don't wait for wpa_supplicant to associate and authenticate. | |
247 | # If you would like to, so can specify how long in seconds | |
248 | #associate_timeout_eth0=60 | |
249 | # A value of 0 means wait forever. | |
250 | ||
251 | # You can also override any settings found here per SSID - which is very | |
252 | # handy if you use different networks a lot. See below for using the SSID | |
253 | # in our variables | |
254 | #config_SSID="dhcp" | |
255 | # See the System module below for setting dns/nis/ntp per SSID | |
256 | ||
257 | # You can also override any settings found here per MAC address of the AP | |
258 | # in case you use Access Points with the same SSID but need different | |
259 | # networking configs. Below is an example - of course you use the same | |
260 | # method with other variables | |
261 | #mac_config_001122334455="dhcp" | |
262 | #mac_dns_servers_001122334455="192.168.0.1 192.168.0.2" | |
263 | ||
264 | # When an interface has been associated with an Access Point, a global | |
265 | # variable called SSID is set to the Access Point's SSID for use in the | |
266 | # pre/post user functions below (although it's not available in preup as you | |
267 | # won't have associated then) | |
268 | ||
269 | # If you're using anything else to configure wireless on your interface AND | |
270 | # you have installed wpa_supplicant, you need to disable wpa_supplicant | |
271 | #modules="!iwconfig !wpa_supplicant" | |
272 | #or | |
273 | #modules="!wireless" | |
274 | ||
275 | ############################################################################## | |
276 | # WIRELESS SSID IN VARIABLES | |
277 | ############################################################################## | |
278 | # Remember to change SSID to your SSID. | |
279 | # Say that your SSID is My NET - the line | |
280 | # #key_SSID="s:passkey" | |
281 | # becomes | |
282 | # #key_My_NET="s:passkey" | |
283 | # Notice that the space has changed to an underscore - do the same with all | |
284 | # characters not in a-z A-Z (English alphabet) 0-9. This only applies to | |
285 | # variables and not values. | |
286 | # | |
287 | # Any SSID's in values like essid_eth0="My NET" may need to be escaped | |
288 | # This means placing the character \ before the character | |
289 | # \" need to be escaped for example | |
290 | # So if your SSID is | |
291 | # My "\ NET | |
292 | # it becomes | |
293 | # My \"\\ NET | |
294 | # for example | |
295 | # #essid_eth0="My\"\\NET" | |
296 | # | |
297 | # So using the above we can use | |
298 | # #dns_domain_My____NET="My\"\\NET" | |
299 | # which is an invalid dns domain, but shows the how to use the variable | |
300 | # structure | |
301 | ######################################################### | |
302 | ||
303 | #----------------------------------------------------------------------------- | |
304 | # DHCP | |
305 | # DHCP can be provided by dhclient. | |
306 | # | |
307 | # dhcpcd: emerge net-misc/dhcpcd | |
308 | # dhclient: emerge net-misc/dhcp | |
309 | ||
310 | # Regardless of which DHCP client you prefer, you configure them the | |
311 | # same way using one of following depending on which interface modules | |
312 | # you're using. | |
313 | #config_eth0="dhcp" | |
314 | ||
315 | # For passing custom options to dhcpcd use something like the following. This | |
316 | # example reduces the timeout for retrieving an address from 60 seconds (the | |
317 | # default) to 10 seconds. | |
318 | #dhcpcd_eth0="-t 10" | |
319 | ||
320 | # GENERIC DHCP OPTIONS | |
321 | # Set generic DHCP options like so | |
322 | #dhcp_eth0="release nodns nontp nonis nogateway nosendhost" | |
323 | ||
324 | # This tells the dhcp client to release its lease when it stops, not to | |
325 | # overwrite dns, ntp and nis settings, not to set a default route and not to | |
326 | # send the current hostname to the dhcp server and when it starts. | |
327 | # You can use any combination of the above options - the default is not to | |
328 | # use any of them. | |
329 | ||
330 | ||
331 | #----------------------------------------------------------------------------- | |
332 | # System | |
333 | # For configuring system specifics such as domain, dns, ntp and nis servers | |
334 | # It's rare that you would need todo this, but you can anyway. | |
335 | # This is most benefit to wireless users who don't use DHCP so they can change | |
336 | # their configs based on SSID. | |
337 | ||
338 | # If you omit the _eth0 suffix, then it applies to all interfaces unless | |
339 | # overridden by the interface suffix. | |
340 | #dns_domain_eth0="your.domain" | |
341 | #dns_servers_eth0="192.168.0.2 192.168.0.3" | |
342 | #dns_search_eth0="this.domain that.domain" | |
343 | #dns_options_eth0="timeout:1 rotate" | |
344 | #dns_sortlist_eth0="130.155.160.0/255.255.240.0 130.155.0.0" | |
345 | # See the man page for resolv.conf for details about the options and sortlist | |
346 | # directives | |
347 | ||
348 | #ntp_servers_eth0="192.168.0.2 192.168.0.3" | |
349 | ||
350 | #nis_domain_eth0="domain" | |
351 | #nis_servers_eth0="192.168.0.2 192.168.0.3" | |
352 | ||
353 | # NOTE: Setting any of these will stamp on the files in question. So if you | |
354 | # don't specify dns_servers but you do specify dns_domain then no nameservers | |
355 | # will be listed in /etc/resolv.conf even if there were any there to start | |
356 | # with. | |
357 | # If this is an issue for you then maybe you should look into a resolv.conf | |
358 | # manager like resolvconf-gentoo to manage this file for you. All packages | |
359 | # that baselayout supports use resolvconf-gentoo if installed. | |
360 | ||
361 | #----------------------------------------------------------------------------- | |
362 | # Cable in/out detection | |
363 | # Sometimes the cable is in, others it's out. Obviously you don't want to | |
364 | # restart net.eth0 every time when you plug it in either. | |
365 | # BSD has the Device State Change Daemon - or devd for short | |
366 | # To enable this, simple add devd to the boot runlevel | |
367 | #rc-update add devd boot | |
368 | #rc | |
369 | ||
370 | ############################################################################## | |
371 | # ADVANCED CONFIGURATION | |
372 | # | |
373 | # Four functions can be defined which will be called surrounding the | |
374 | # start/stop operations. The functions are called with the interface | |
375 | # name first so that one function can control multiple adapters. An extra two | |
376 | # functions can be defined when an interface fails to start or stop. | |
377 | # | |
378 | # The return values for the preup and predown functions should be 0 | |
379 | # (success) to indicate that configuration or deconfiguration of the | |
380 | # interface can continue. If preup returns a non-zero value, then | |
381 | # interface configuration will be aborted. If predown returns a | |
382 | # non-zero value, then the interface will not be allowed to continue | |
383 | # deconfiguration. | |
384 | # | |
385 | # The return values for the postup, postdown, failup and faildown functions are | |
386 | # ignored since there's nothing to do if they indicate failure. | |
387 | # | |
388 | # ${IFACE} is set to the interface being brought up/down | |
389 | # ${IFVAR} is ${IFACE} converted to variable name bash allows | |
390 | # | |
391 | # For historical and compatibility reasons, preup is actually normally called | |
392 | # in the following sequence: up ; preup ; up. | |
393 | # The first up causes the kernel to initialize the device, so | |
394 | # that it is available for use in the preup function. However, for some | |
395 | # hardware, e.g. CAN devices, some configuration is needed before trying to up | |
396 | # the interface will actually work. For such hardware, the | |
397 | # up_before_preup variables will allow skipping the first up call if set | |
398 | # to yes. | |
399 | #up_before_preup_IFVAR="NO" | |
400 | #up_before_preup="NO" | |
401 | ||
402 | #preup() { | |
403 | # # Remember to return 0 on success | |
404 | # return 0 | |
405 | #} | |
406 | ||
407 | #predown() { | |
408 | # # The default in the script is to test for NFS root and disallow | |
409 | # # downing interfaces in that case. Note that if you specify a | |
410 | # # predown() function you will override that logic. Here it is, in | |
411 | # # case you still want it... | |
412 | # if is_net_fs /; then | |
413 | # eerror "root filesystem is network mounted -- can't stop ${IFACE}" | |
414 | # return 1 | |
415 | # fi | |
416 | # | |
417 | # # Remember to return 0 on success | |
418 | # return 0 | |
419 | #} | |
420 | ||
421 | #postup() { | |
422 | # # This function could be used, for example, to register with a | |
423 | # # dynamic DNS service. Another possibility would be to | |
424 | # # send/receive mail once the interface is brought up. | |
425 | ||
426 | #} | |
427 | ||
428 | #postdown() { | |
429 | # # Return 0 always | |
430 | # return 0 | |
431 | #} | |
432 | ||
433 | #failup() { | |
434 | # # This function is mostly here for completeness... I haven't | |
435 | # # thought of anything nifty to do with it yet ;-) | |
436 | #} | |
437 | ||
438 | #faildown() { | |
439 | # # This function is mostly here for completeness... I haven't | |
440 | # # thought of anything nifty to do with it yet ;-) | |
441 | #} |
0 | ############################################################################## | |
1 | # QUICK-START | |
2 | # | |
3 | # The quickest start is if you want to use DHCP. | |
4 | # In that case, everything should work out of the box, no configuration | |
5 | # necessary, though the startup script will warn you that you haven't | |
6 | # specified anything. | |
7 | ||
8 | # WARNING :- some examples have a mixture of IPv4 (ie 192.168.0.1) and IPv6 | |
9 | # (ie 4321:0:1:2:3:4:567:89ab) internet addresses. They only work if you have | |
10 | # the relevant kernel option enabled. So if you don't have an IPv6 enabled | |
11 | # kernel then remove the IPv6 address from your config. | |
12 | ||
13 | # If you want to use a static address or use DHCP explicitly, jump | |
14 | # down to the section labeled INTERFACE HANDLERS. | |
15 | # | |
16 | # If you want to do anything more fancy, you should take the time to | |
17 | # read through the rest of this file. | |
18 | ||
19 | ||
20 | ############################################################################## | |
21 | # MODULES | |
22 | # | |
23 | # We now support modular networking scripts which means we can easily | |
24 | # add support for new interface types and modules while keeping | |
25 | # compatibility with existing ones. | |
26 | # | |
27 | # Modules load by default if the package they need is installed. If | |
28 | # you specify a module here that doesn't have its package installed | |
29 | # then you get an error stating which package you need to install. | |
30 | # Ideally, you only use the modules setting when you have two or more | |
31 | # packages installed that supply the same service. | |
32 | # | |
33 | # In other words, you probably should DO NOTHING HERE... | |
34 | ||
35 | # Prefer ifconfig over iproute2 | |
36 | #modules="!iproute2" | |
37 | ||
38 | # You can also specify other modules for an interface | |
39 | # In this case we prefer udhcpc over dhcpcd | |
40 | #modules_eth0="udhcpc" | |
41 | ||
42 | # You can also specify which modules not to use - for example you may be | |
43 | # using a supplicant or linux-wlan-ng to control wireless configuration but | |
44 | # you still want to configure network settings per SSID associated with. | |
45 | #modules="!iwconfig !wpa_supplicant" | |
46 | # IMPORTANT: If you need the above, please disable modules in that order | |
47 | ||
48 | ||
49 | ############################################################################## | |
50 | # INTERFACE HANDLERS | |
51 | # | |
52 | # We provide two interface handlers presently: ifconfig and iproute2. | |
53 | # You need one of these to do any kind of network configuration. | |
54 | # For ifconfig support, emerge sys-apps/net-tools | |
55 | # For iproute2 support, emerge sys-apps/iproute2 | |
56 | ||
57 | # If you don't specify an interface then we prefer iproute2 if it's installed | |
58 | # To prefer ifconfig over iproute2 | |
59 | #modules="!iproute2" | |
60 | ||
61 | # For a static configuration, use something like this | |
62 | # (They all do exactly the same thing btw) | |
63 | #config_eth0="192.168.0.2/24" | |
64 | #config_eth0="192.168.0.2 netmask 255.255.255.0" | |
65 | ||
66 | # If you need more than one address, you can use something like this | |
67 | # NOTE: ifconfig creates an aliased device for each extra IPv4 address | |
68 | # (eth0:1, eth0:2, etc) | |
69 | # iproute2 does not do this as there is no need to | |
70 | # WARNING: You cannot mix multiple addresses on a line with other parameters! | |
71 | #config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24" | |
72 | # However, that only works with CIDR addresses, so you can't use netmask. | |
73 | ||
74 | # You can also use IPv6 addresses | |
75 | # (you should always specify a prefix length with IPv6 here) | |
76 | #config_eth0="192.168.0.2/24 4321:0:1:2:3:4:567:89ab/64 4321:0:1:2:3:4:567:89ac/64" | |
77 | ||
78 | # If you wish to keep existing addresses + routing and the interface is up, | |
79 | # you can specify a noop (no operation). If the interface is down or there | |
80 | # are no addresses assigned, then we move onto the next step (default dhcp) | |
81 | # This is useful when configuring your interface with a kernel command line | |
82 | # or similar | |
83 | #config_eth0="noop 192.168.0.2/24" | |
84 | ||
85 | # If you don't want ANY address (only useful when calling for advanced stuff) | |
86 | #config_eth0="null" | |
87 | ||
88 | # If you need to pass parameters to go with an address, you can do so on the | |
89 | # same line as the address. You should split multiple addresses with newlines. | |
90 | # WARNING: You cannot mix multiple addresses on a line with other parameters! | |
91 | #config_eth0="192.168.0.2/24 scope host" | |
92 | #config_eth0="4321:0:1:2:3:4:567:89ab/64 nodad home preferred_lft 0" | |
93 | #config_eth0="192.168.0.2/24 scope host | |
94 | #4321:0:1:2:3:4:567:89ab/64 nodad home preferred_lft 0" | |
95 | ||
96 | # Here's how to do routing if you need it | |
97 | # We add an IPv4 default route, IPv4 subnet route and an IPv6 unicast route | |
98 | #routes_eth0="default via 192.168.0.1 | |
99 | #10.0.0.0/8 via 192.168.0.1 | |
100 | #::/0" | |
101 | ||
102 | # If a specified module fails (like dhcp - see below), you can specify a | |
103 | # fallback like so | |
104 | #fallback_eth0="192.168.0.2/24" | |
105 | #fallback_routes_eth0="default via 192.168.0.1" | |
106 | ||
107 | # NOTE: fallback entry must match the entry location in config_eth0 | |
108 | # As such you can only have one fallback route. | |
109 | # Also, if you do not set a fallback_routes entry for an interface, the | |
110 | # routes entry will be used if that is set. | |
111 | ||
112 | # Some users may need to alter the MTU - here's how | |
113 | #mtu_eth0="1500" | |
114 | # Same for TX Queue Length | |
115 | #txqueuelen_eth0="1000" | |
116 | ||
117 | # Each module described below can set a default base metric, lower is | |
118 | # preferred over higher. This is so we can prefer a wired route over a | |
119 | # wireless route automatically. You can override this by setting | |
120 | #metric_eth0="100" | |
121 | # or on a global basis | |
122 | #metric="100" | |
123 | # The only downside of the global setting is that you have to ensure that | |
124 | # there are no conflicting routes yourself. For users with large routing | |
125 | # tables you may have to set a global metric as the due to a simple read of | |
126 | # the routing table taking over a minute at a time. | |
127 | ||
128 | # Most drivers that report carrier status function correctly, but some do not | |
129 | # One of these faulty drivers is for the Intel e1000 network card, but only | |
130 | # at boot time. To get around this you may alter the carrier_timeout value for | |
131 | # the interface. 0 is disable and any other number of seconds is how | |
132 | # long we wait for carrier. The current default is disabled. | |
133 | #carrier_timeout_eth0=0 | |
134 | ||
135 | # You may wish to disable the interface being brought down when stopping. | |
136 | # This is only of use for WakeOnLan. | |
137 | #ifdown_eth0="NO" | |
138 | ||
139 | ############################################################################## | |
140 | # OPTIONAL MODULES | |
141 | ||
142 | #----------------------------------------------------------------------------- | |
143 | # WIRELESS (802.11 support) | |
144 | # Wireless can be provided by iwconfig or wpa_supplicant | |
145 | # wpa_supplicant is preferred, use the modules directive to prefer iwconfig. | |
146 | #modules="iwconfig" | |
147 | # | |
148 | # iwconfig | |
149 | # emerge net-wireless/wireless-tools | |
150 | ############################################### | |
151 | # HINTS | |
152 | # | |
153 | # Most users will just need to set the following options | |
154 | # key_SSID1="s:yourkeyhere enc open" # s: means a text key | |
155 | # key_SSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key | |
156 | # preferred_aps="'SSID 1' 'SSID 2'" | |
157 | # | |
158 | # Clear? Good. Now configure your wireless network below | |
159 | ||
160 | ############################################### | |
161 | # SETTINGS | |
162 | # Hard code an SSID to an interface - leave this unset if you wish the driver | |
163 | # to scan for available Access Points | |
164 | # Set to "any" to connect to any SSID - the driver picks an Access Point | |
165 | # This needs to be done when the driver doesn't support scanning | |
166 | # This may work for drivers that don't support scanning but you need automatic | |
167 | # AP association | |
168 | # I would only set this as a last resort really - use the preferred_aps | |
169 | # setting at the bottom of this file | |
170 | ||
171 | # However, using ad-hoc (without scanning for APs) and master mode | |
172 | # do require the SSID to be set - do this here | |
173 | #essid_eth0="any" | |
174 | ||
175 | # Set the mode of the interface (managed, ad-hoc, master or auto) | |
176 | # The default is auto | |
177 | # If it's ad-hoc or master you also may need to specify the channel below | |
178 | #mode_eth0="auto" | |
179 | ||
180 | # If managed mode fails, drop to ad-hoc mode with the below SSID? | |
181 | #adhoc_essid_eth0="WLAN" | |
182 | ||
183 | # Some drivers/hardware don't scan all that well. We have no control over this | |
184 | # but we can say how many scans we want to do to try and get a better sweep of | |
185 | # the area. The default is 1. | |
186 | #scans_eth0="1" | |
187 | ||
188 | #Channel can be set (1-14), but defaults to 3 if not set. | |
189 | # | |
190 | # The below is taken verbatim from the BSD wavelan documentation found at | |
191 | # http://www.netbsd.org/Documentation/network/wavelan.html | |
192 | # There are 14 channels possible; We are told that channels 1-11 are legal for | |
193 | # North America, channels 1-13 for most of Europe, channels 10-13 for France, | |
194 | # and only channel 14 for Japan. If in doubt, please refer to the documentation | |
195 | # that came with your card or access point. Make sure that the channel you | |
196 | # select is the same channel your access point (or the other card in an ad-hoc | |
197 | # network) is on. The default for cards sold in North America and most of Europe | |
198 | # is 3; the default for cards sold in France is 11, and the default for cards | |
199 | # sold in Japan is 14. | |
200 | #channel_eth0="3" | |
201 | ||
202 | # Setup any other config commands. This is basically the iwconfig argument | |
203 | # without the iwconfig $iface. | |
204 | #iwconfig_eth0="" | |
205 | ||
206 | # Set private driver ioctls. This is basically the iwpriv argument without | |
207 | # the iwpriv $iface. If you use the rt2500 driver (not the rt2x00 one) then | |
208 | # you can set WPA here, below is an example. | |
209 | #iwpriv_eth0="" | |
210 | #iwpriv_SSID="set AuthMode=WPAPSK | |
211 | #set EncrypType=TKIP | |
212 | #set WPAPSK=yourpasskey" | |
213 | #NOTE: Even though you can use WPA like so, you may have to set a WEP key | |
214 | #if your driver claims the AP is encrypted. The WEP key itself will not be | |
215 | #used though. | |
216 | ||
217 | # Seconds to wait before scanning | |
218 | # Some drivers need to wait until they have finished "loading" | |
219 | # before they can scan - otherwise they error and claim that they cannot scan | |
220 | # or resource is unavailable. The default is to wait zero seconds | |
221 | #sleep_scan_eth0="1" | |
222 | ||
223 | # Seconds to wait until associated. The default is to wait 10 seconds. | |
224 | # 0 means wait indefinitely. WARNING: this can cause an infinite delay when | |
225 | # booting. | |
226 | #associate_timeout_eth0="5" | |
227 | ||
228 | # By default a successful association in Managed mode sets the MAC | |
229 | # address of the AP connected to. However, some drivers (namely | |
230 | # the ipw2100) don't set an invalid MAC address when association | |
231 | # fails - so we need to check on link quality which some drivers | |
232 | # don't report properly either. | |
233 | # So if you have connection problems try flipping this setting | |
234 | # Valid options are MAC, quality and all - defaults to MAC | |
235 | #associate_test_eth0="MAC" | |
236 | ||
237 | # Some driver/card combinations need to scan in Ad-Hoc mode | |
238 | # After scanning, the mode is reset to the one defined above | |
239 | #scan_mode_eth0="Ad-Hoc" | |
240 | ||
241 | # Below you can define private ioctls to run before and after scanning | |
242 | # Format is the same as the iwpriv_eth0 above | |
243 | # This is needed for the HostAP drivers | |
244 | #iwpriv_scan_pre_eth0="'host_roaming 2'" | |
245 | #iwpriv_scan_post_eth0="'host_roaming 0'" | |
246 | ||
247 | # Define a WEP key per SSID or MAC address (of the AP, not your card) | |
248 | # The encryption type (open or restricted) must match the | |
249 | # encryption type on the Access Point | |
250 | # You can't use "any" for an SSID here | |
251 | #key_SSID="1234-1234-1234-1234-1234-1234-56" | |
252 | # or you can use strings. Passphrase IS NOT supported | |
253 | # To use a string, prefix it with s: | |
254 | # Note - this example also sets the encryption method to open | |
255 | # which is regarded as more secure than restricted | |
256 | #key_SSID="s:foobar enc open" | |
257 | #key_SSID="s:foobar enc restricted" | |
258 | ||
259 | # If you have whitespace in your key, here's how to set it and use other | |
260 | # commands like using open encryption. | |
261 | #key_SSID="s:'foo bar' enc open" | |
262 | ||
263 | # WEP key for the AP with MAC address 001122334455 | |
264 | #mac_key_001122334455="s:foobar" | |
265 | ||
266 | # Here are some more examples of keys as some users find others work | |
267 | # and some don't where they should all do the same thing | |
268 | #key_SSID="open s:foobar" | |
269 | #key_SSID="open 1234-5678-9012" | |
270 | #key_SSID="s:foobar enc open" | |
271 | #key_SSID="1234-5678-9012 enc open" | |
272 | ||
273 | # You may want to set multiple keys - here's an example | |
274 | # It sets 4 keys on the card and instructs to use key 2 by default | |
275 | #key_SSID="[1] s:passkey1 key [2] s:passkey2 key [3] s:passkey3 key [4] s:passkey4 key [2]" | |
276 | ||
277 | # You can also override the interface settings found in /etc/conf.d/net | |
278 | # per SSID - which is very handy if you use different networks a lot | |
279 | #config_SSID="dhcp" | |
280 | #dhcpcd_SSID="-t 5" | |
281 | #routes_SSID= | |
282 | #fallback_SSID= | |
283 | ||
284 | # Setting name/domain server causes /etc/resolv.conf to be overwritten | |
285 | # Note that if DHCP is used, and you want this to take precedence then | |
286 | # please put -R in your dhcpcd options | |
287 | #dns_servers_SSID="192.168.0.1 192.168.0.2" | |
288 | #dns_domain_SSID="some.domain" | |
289 | #dns_search_SSID="search.this.domain search.that.domain" | |
290 | # Please check the man page for resolv.conf for more information | |
291 | # as domain and search (searchdomains) are mutually exclusive and | |
292 | # searchdomains takes precedence | |
293 | ||
294 | # You can also set any of the /etc/conf.d/net variables per MAC address | |
295 | # incase you use Access Points with the same SSID but need different | |
296 | # networking configs. Below is an example - of course you use the same | |
297 | # method with other variables | |
298 | #config_001122334455="dhcp" | |
299 | #dhcpcd_001122334455="-t 10" | |
300 | #dns_servers_001122334455="192.168.0.1 192.168.0.2" | |
301 | ||
302 | # Map a MAC address to an SSID | |
303 | # This is used when the Access Point is not broadcasting its SSID | |
304 | # WARNING: This will override the SSID being broadcast due to some | |
305 | # Access Points sending an SSID even when they have been configured | |
306 | # not to! | |
307 | # Change 001122334455 to the MAC address and SSID to the SSID | |
308 | # it should map to | |
309 | #mac_essid_001122334455="SSID" | |
310 | ||
311 | # This lists the preferred SSIDs to connect to in order | |
312 | # SSID's can contain any characters here as they must match the broadcast | |
313 | # SSID exactly. | |
314 | # Surround each SSID with the " character and separate them with a space | |
315 | # If the first SSID isn't found then it moves onto the next | |
316 | # If this isn't defined then it connects to the first one found | |
317 | #preferred_aps="SSID1 SSID2" | |
318 | ||
319 | # You can also define a preferred_aps list per interface | |
320 | #preferred_aps_eth0="SSID3 SSID4" | |
321 | ||
322 | # You can also say whether we only connect to preferred APs or not | |
323 | # Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" and "forceany" | |
324 | # "any" means it will connect to visible APs in the preferred list and then any | |
325 | # other available AP | |
326 | # "preferredonly" means it will only connect to visible APs in the preferred list | |
327 | # "forcepreferred" means it will forcibly connect to APs in order if it does not find | |
328 | # them in a scan | |
329 | # "forcepreferredonly" means it forcibly connects to the APs in order and does not bother | |
330 | # to scan | |
331 | # "forceany" does the same as forcepreferred + connects to any other available AP | |
332 | # Default is "any" | |
333 | #associate_order="any" | |
334 | #associate_order_eth0="any" | |
335 | ||
336 | # You can define blacklisted Access Points in the same way | |
337 | #blacklist_aps="SSID1 SSID2" | |
338 | #blacklist_aps_eth0="SSID3 SSID4" | |
339 | ||
340 | # If you have more than one wireless card, you can say if you want | |
341 | # to allow each card to associate with the same Access Point or not | |
342 | # Values are "yes" and "no" | |
343 | # Default is "yes" | |
344 | #unique_ap="yes" | |
345 | #unique_ap_eth0="yes" | |
346 | ||
347 | # IMPORTANT: preferred_only, blacklisted_aps and unique_ap only work when | |
348 | # essid_eth0 is not set and your card is capable of scanning | |
349 | ||
350 | # NOTE: preferred_aps list ignores blacklisted_aps - so if you have | |
351 | # the same SSID in both, well, you're a bit silly :p | |
352 | ||
353 | ||
354 | ############################################################ | |
355 | # wpa_supplicant | |
356 | # emerge net-wireless/wpa_supplicant | |
357 | # Wireless options are held in /etc/wpa_supplicant/wpa_supplicant.conf | |
358 | # Consult the wpa_supplicant.conf.example that is installed in | |
359 | # /usr/share/doc/wpa_supplicant | |
360 | # To configure wpa_supplicant | |
361 | #wpa_supplicant_ath0="-Dmadwifi" # For Atheros based cards | |
362 | # Consult wpa_supplicant for more drivers - the default is -Dwext which should | |
363 | # work for most cards. | |
364 | ||
365 | # By default we don't wait for wpa_supplicant to associate and authenticate. | |
366 | # If you need to change this behaviour then you don't know how our scripts work | |
367 | # and setting this value could cause strange things to happen. | |
368 | # If you would like it to wait, you can specify how long in seconds. | |
369 | #associate_timeout_eth0=60 | |
370 | # A value of 0 means wait forever. | |
371 | ||
372 | # You can also override any settings found here per SSID - which is very | |
373 | # handy if you use different networks a lot. See below for using the SSID | |
374 | # in our variables | |
375 | #config_SSID="dhcp" | |
376 | # See the System module below for setting dns/nis/ntp per SSID | |
377 | ||
378 | # You can also override any settings found here per MAC address of the AP | |
379 | # in case you use Access Points with the same SSID but need different | |
380 | # networking configs. Below is an example - of course you use the same | |
381 | # method with other variables | |
382 | #mac_config_001122334455="dhcp" | |
383 | #mac_dns_servers_001122334455="192.168.0.1 192.168.0.2" | |
384 | ||
385 | # When an interface has been associated with an Access Point, a global | |
386 | # variable called SSID is set to the Access Point's SSID for use in the | |
387 | # pre/post user functions below (although it's not available in preup as you | |
388 | # won't have associated then) | |
389 | ||
390 | # If you're using anything else to configure wireless on your interface AND | |
391 | # you have installed wpa_supplicant, you need to disable wpa_supplicant | |
392 | #modules="!iwconfig !wpa_supplicant" | |
393 | #or | |
394 | #modules="!wireless" | |
395 | ||
396 | ############################################################################## | |
397 | # WIRELESS SSID IN VARIABLES | |
398 | ############################################################################## | |
399 | # Remember to change SSID to your SSID. | |
400 | # Say that your SSID is My NET - the line | |
401 | # #key_SSID="s:passkey" | |
402 | # becomes | |
403 | # #key_My_NET="s:passkey" | |
404 | # Notice that the space has changed to an underscore - do the same with all | |
405 | # characters not in a-z A-Z (English alphabet) 0-9. This only applies to | |
406 | # variables and not values. | |
407 | # | |
408 | # Any SSID's in values like essid_eth0="My NET" may need to be escaped | |
409 | # This means placing the character \ before the character | |
410 | # \" need to be escaped for example | |
411 | # So if your SSID is | |
412 | # My "\ NET | |
413 | # it becomes | |
414 | # My \"\\ NET | |
415 | # for example | |
416 | # #essid_eth0="My\"\\NET" | |
417 | # | |
418 | # So using the above we can use | |
419 | # #dns_domain_My____NET="My\"\\NET" | |
420 | # which is an invalid dns domain, but shows the how to use the variable | |
421 | # structure | |
422 | ######################################################### | |
423 | ||
424 | ||
425 | #----------------------------------------------------------------------------- | |
426 | # DHCP | |
427 | # DHCP can be provided by dhclient, dhcpcd, pump or udhcpc. | |
428 | # | |
429 | # dhclient: emerge net-misc/dhcp | |
430 | # dhcpcd: emerge net-misc/dhcpcd | |
431 | # pump: emerge net-misc/pump | |
432 | # udhcpc: emerge sys-apps/busybox | |
433 | ||
434 | # If you have more than one DHCP client installed, you need to specify which | |
435 | # one to use - otherwise we default to dhcpcd if available. | |
436 | #modules="dhclient" # to select dhclient over dhcpcd | |
437 | # | |
438 | # Notes: | |
439 | # - All clients send the current hostname to the DHCP server by default | |
440 | # - dhcpcd does not daemonize when the lease time is infinite | |
441 | # - udhcp-0.9.3-r3 and earlier do not support getting NTP servers | |
442 | # - pump does not support getting NIS servers | |
443 | # - DHCP tends to erase any existing device information - so add | |
444 | # static addresses after dhcp if you need them | |
445 | # - dhclient and udhcpc can set other resolv.conf options such as "option" | |
446 | # and "sortlist"- see the System module for more details | |
447 | ||
448 | # Regardless of which DHCP client you prefer, you configure them the | |
449 | # same way using one of following depending on which interface modules | |
450 | # you're using. | |
451 | #config_eth0="dhcp" | |
452 | ||
453 | # For passing custom options to dhcpcd use something like the following. This | |
454 | # example reduces the timeout for retrieving an address from 60 seconds (the | |
455 | # default) to 10 seconds. | |
456 | #dhcpcd_eth0="-t 10" | |
457 | ||
458 | # dhclient, udhcpc and pump don't have many runtime options | |
459 | # You can pass options to them in a similar manner to dhcpcd though | |
460 | #dhclient_eth0="..." | |
461 | #udhcpc_eth0="..." | |
462 | #pump_eth0="..." | |
463 | ||
464 | # GENERIC DHCP OPTIONS | |
465 | # Set generic DHCP options like so | |
466 | #dhcp_eth0="release nodns nontp nonis nogateway nosendhost" | |
467 | ||
468 | # This tells the dhcp client to release its lease when it stops, not to | |
469 | # overwrite dns, ntp and nis settings, not to set a default route and not to | |
470 | # send the current hostname to the dhcp server and when it starts. | |
471 | # You can use any combination of the above options - the default is not to | |
472 | # use any of them. | |
473 | ||
474 | #----------------------------------------------------------------------------- | |
475 | # For APIPA support, emerge net-misc/iputils or net-analyzer/arping | |
476 | ||
477 | # APIPA is a module that tries to find a free address in the range | |
478 | # 169.254.0.0-169.254.255.255 by arping a random address in that range on the | |
479 | # interface. If no reply is found then we assign that address to the interface | |
480 | ||
481 | # This is only useful for LANs where there is no DHCP server and you don't | |
482 | # connect directly to the internet. | |
483 | #config_eth0="dhcp" | |
484 | #fallback_eth0="apipa" | |
485 | ||
486 | #----------------------------------------------------------------------------- | |
487 | # ARPING Gateway configuration | |
488 | # and | |
489 | # Automatic Private IP Addressing (APIPA) | |
490 | # For arpingnet / apipa support, emerge net-misc/iputils or net-analyzer/arping | |
491 | # | |
492 | # This is a module that tries to find a gateway IP. If it exists then we use | |
493 | # that gateways configuration for our own. For the configuration variables | |
494 | # simply ensure that each octet is zero padded and the dots are removed. | |
495 | # Below is an example. | |
496 | # | |
497 | #gateways_eth0="192.168.0.1 10.0.0.1" | |
498 | #config_192168000001="192.168.0.2/24" | |
499 | #routes_192168000001="default via 192.168.0.1" | |
500 | #dns_servers_192168000001="192.168.0.1" | |
501 | #config_010000000001="10.0.0.254/8" | |
502 | #routes_010000000001="default via 10.0.0.1" | |
503 | #dns_servers_010000000001="10.0.0.1" | |
504 | ||
505 | # We can also specify a specific MAC address for each gateway if different | |
506 | # networks have the same gateway. | |
507 | #gateways_eth0="192.168.0.1,00:11:22:AA:BB:CC 10.0.0.1,33:44:55:DD:EE:FF" | |
508 | #config_192168000001_001122AABBCC="192.168.0.2/24" | |
509 | #routes_192168000001_001122AABBCC="default via 192.168.0.1" | |
510 | #dns_servers_192168000001_001122AABBCC="192.168.0.1" | |
511 | #config_010000000001_334455DDEEFF="10.0.0.254/8" | |
512 | #routes_010000000001_334455DDEEFF="default via 10.0.0.1" | |
513 | #dns_servers_010000000001_334455DDEEFF="10.0.0.1" | |
514 | ||
515 | # If you need to spoof the source address, you can add that as third parameter | |
516 | # like so | |
517 | #gateways_eth0="192.168.0.1,00:11:22:AA:BB:CC,192.168.0.50" | |
518 | #or | |
519 | #gateways_eth0="192.168.0.1,,192.168.0.50" | |
520 | # This requires arping to be installed though | |
521 | ||
522 | # If we don't find any gateways (or there are none configured) then we try and | |
523 | # use APIPA to find a free address in the range 169.254.0.0-169.254.255.255 | |
524 | # by arping a random address in that range on the interface. If no reply is | |
525 | # found then we assign that address to the interface. | |
526 | ||
527 | # This is only useful for LANs where there is no DHCP server. | |
528 | #config_eth0="arping" | |
529 | ||
530 | # or if no DHCP server can be found | |
531 | #config_eth0="dhcp" | |
532 | #fallback_eth0="arping" | |
533 | ||
534 | # NOTE: We default to sleeping for 1 second the first time we attempt an | |
535 | # arping to give the interface time to settle on the LAN. This appears to | |
536 | # be a good default for most instances, but if not you can alter it here. | |
537 | #arping_sleep=5 | |
538 | #arping_sleep_lan=7 | |
539 | ||
540 | # NOTE: We default to waiting 3 seconds to get an arping response. You can | |
541 | # change the default wait like so. | |
542 | #arping_wait=3 | |
543 | #arping_wait_lan=2 | |
544 | ||
545 | #----------------------------------------------------------------------------- | |
546 | # VLAN (802.1q support) | |
547 | # For VLAN support, emerge sys-apps/iproute2 | |
548 | # The old vconfig based VLAN support is no longer available. | |
549 | ||
550 | # Specify the VLAN numbers for the interface like so | |
551 | # Please ensure your VLAN IDs are NOT zero-padded | |
552 | #vlans_eth0="1 2" | |
553 | ||
554 | # You may not want to assign an IP the the physical interface, but we still | |
555 | # need it up. | |
556 | #config_eth0="null" | |
557 | ||
558 | # You can also configure the VLAN - see for ip man page for more details | |
559 | # To change the vlan interface name. If not set, the standard "iface.vlanid" | |
560 | # will be used. This is the replacement for the old 'vconfig set_name_type' | |
561 | # functionality. If you previously relied on the DEV_PLUS_VID or | |
562 | # DEV_PLUS_VID_NO_PAD options to have different VLANs with same ID value, on | |
563 | # different interfaces, please note that you need to use both the interface and | |
564 | # vlan number in the numbering. This applies for all of the options: name, | |
565 | # txqueuelen, mac, broadcast, mtu, ingress, egress, flags | |
566 | #vlan1_name="vlan1" | |
567 | #eth0_vlan2_name="eth0.2" | |
568 | #eth1_vlan2_name="eth1.2" | |
569 | ||
570 | # The following shows the old set_name_type setting and what new option to set: | |
571 | # Using eth9 & VLAN VID 26 as an example. | |
572 | # VLAN_PLUS_VID vlan26_name="vlan0026" | |
573 | # VLAN_PLUS_VID_NO_PAD vlan26_name="vlan26" | |
574 | # DEV_PLUS_VID eth9_vlan26_name="eth9.0026" | |
575 | # DEV_PLUS_VID_NO_PAD eth9_vlan26_name="eth9.26" | |
576 | ||
577 | # Set the vlan flags | |
578 | #vlan1_flags="reorder_hdr off gvrp on loose_binding on" | |
579 | #eth0_vlan1_flags="reorder_hdr off gvrp on loose_binding on" | |
580 | ||
581 | # Configure in/egress maps | |
582 | #vlan1_ingress="2:6 3:5" | |
583 | #eth0_vlan1_egress="1:2" | |
584 | ||
585 | #config_vlan1="172.16.2.1/24" | |
586 | #config_vlan2="172.16.3.1/24" | |
587 | #config_eth0_1="172.16.4.1/24" | |
588 | #config_eth1_1="172.16.5.1/24" | |
589 | ||
590 | # NOTE: Vlans can be configured with a . in their interface names | |
591 | # When configuring vlans with this name type, you need to replace . with a _ | |
592 | #config_eth0.1="dhcp" - does not work | |
593 | #config_eth0_1="dhcp" - does work | |
594 | ||
595 | # NOTE: Vlans are controlled by their physical interface and not per vlan | |
596 | # This means you do not need to create init scripts in /etc/init.d for each | |
597 | # vlan, you must need to create one for the physical interface. | |
598 | # If you wish to control the configuration of each vlan through a separate | |
599 | # script then you need to do this. | |
600 | #vlan_start_eth0="no" | |
601 | ||
602 | # If you do the above then you may want to depend on eth0 like so | |
603 | # rc_net_vlan1_need="net.eth0" | |
604 | # NOTE: depend functions only work in /etc/conf.d/net | |
605 | # and not in profile configs such as /etc/conf.d/net.foo | |
606 | ||
607 | # Also, you might want to make eth0 not provide net in this case so that | |
608 | # dependent services will start when the vlan is active instead of the | |
609 | # physical interface. | |
610 | # rc_net_eth0_provide="!net" | |
611 | ||
612 | # MAC-VLAN support | |
613 | # The following configuration can be used to create a new interface 'macvlan0' | |
614 | # linked to 'eth0' | |
615 | #macvlan_macvlan0="eth0" | |
616 | ||
617 | # MAC-VLAN mode (private, vepa, bridge, passtru) | |
618 | #mode_macvlan0="private" | |
619 | ||
620 | # IP address, MAC address, ... are configured as a normal interface | |
621 | #config_macvlan0="192.168.20.20/24" | |
622 | #mac_macvlan0="00:50:06:20:20:20" | |
623 | ||
624 | #----------------------------------------------------------------------------- | |
625 | # Bonding | |
626 | # For link bonding/trunking on 2.4 kernels, or kernels without sysfs | |
627 | # emerge net-misc/ifenslave | |
628 | ||
629 | # To bond interfaces together | |
630 | #slaves_bond0="eth0 eth1 eth2" | |
631 | #config_bond0="null" # You may not want to assign an IP the the bond | |
632 | ||
633 | # Please note, that you should generally NOT try to change the MAC addresses of | |
634 | # a bond interface yourself. If you do so, the kernel and your network switches | |
635 | # may not work quite right. It is permissible to set the MAC addresses of bond | |
636 | # slaves BEFORE the bond comes up, but not after the bond is up (it will change | |
637 | # MAC addresses of the slaves on it's own). | |
638 | ||
639 | # You can also configure the parameters of the bond here, which must be done | |
640 | # via sysfs on 2.6 kernels or newer. The description of all the options can be | |
641 | # found in the kernel: /usr/src/linux-*/Documentation/networking/bonding.txt | |
642 | # You will probably want the 'mode' option at the least. | |
643 | # Some possible parameters: mode fail_over_mac arp_validate arp_interval | |
644 | # arp_ip_target downdelay updelay lacp_rate ad_select xmit_hash_policy | |
645 | # num_grat_arp num_unsol_na miimon primary primary_reselect use_carrier | |
646 | # active_slave queue_id all_slaves_active resend_igmp min_links | |
647 | #mode_bond0="round-robin" | |
648 | #miimon_bond0="100" | |
649 | #arp_ip_target_bond0="+26.0.0.0" | |
650 | ||
651 | # If any of the slaves require extra configuration - for example wireless or | |
652 | # ppp devices - we need to depend function on the bonded interfaces | |
653 | #rc_net_bond0_need="net.eth0 net.eth1" | |
654 | ||
655 | # Bonding subsume support (prevents crashes for root-on-NFS) | |
656 | # - Only tested in the default bonding mode ('active-backup') with | |
657 | # IPv4 | |
658 | # - Only subsumes basic interface characteristics (IP, netmask) and | |
659 | # excludes additional routes, interface properties such as MTU, | |
660 | # interface-associated netfilter rules, etc. | |
661 | # In the example below, the (usually kernel-autoconfigured) | |
662 | # 'eth0' interface is a member of bond0, which subsumes the | |
663 | # existing interface configuration without upsetting NFS. | |
664 | #slaves_bond0="eth0 eth1" | |
665 | #subsume_bond0="eth0" | |
666 | ||
667 | #----------------------------------------------------------------------------- | |
668 | # Classical IP over ATM | |
669 | # For CLIP support emerge net-dialup/linux-atm | |
670 | ||
671 | # Ensure that you have /etc/atmsigd.conf setup correctly | |
672 | # Now setup each clip interface like so | |
673 | #clip_atm0="peer_ip [if.]vpi.vci [opts]," | |
674 | # where "peer_ip" is the IP address of a PVC peer (in case of an ATM connection | |
675 | # with your ISP, your only peer is usually the ISP gateway closest to you), | |
676 | # "if" is the number of the ATM interface which will carry the PVC, "vpi.vci" | |
677 | # is the ATM VC address, and "opts" may optionally specify VC parameters like | |
678 | # qos, pcr, and the like (see "atmarp -s" for further reference). Please also | |
679 | # note quoting: it is meant to distinguish the VCs you want to create. You may, | |
680 | # in example, create an atm0 interface to more peers, like this: | |
681 | #clip_atm0="1.1.1.254,0.8.35 1.1.1.253,1.8.35" | |
682 | ||
683 | # By default, the PVC will use the LLC/SNAP encapsulation. If you rather need a | |
684 | # null encapsulation (aka "VC mode"), please add the keyword "null" to opts. | |
685 | ||
686 | ||
687 | #----------------------------------------------------------------------------- | |
688 | # PPP | |
689 | # For PPP support, emerge net-dialup/ppp | |
690 | # PPP is used for most dialup connections, including ADSL. | |
691 | # The older ADSL module is documented below, but you are encouraged to try | |
692 | # this module first. | |
693 | # | |
694 | # You need to create the PPP net script yourself. Make it like so | |
695 | #ln -s net.lo /etc/init.d/net.ppp0 | |
696 | # | |
697 | # Each PPP interface requires an interface to use as a "Link" | |
698 | #link_ppp0="/dev/ttyS0" # Most PPP links will use a serial port | |
699 | #link_ppp0="eth0" # PPPoE requires an ethernet interface | |
700 | #link_ppp0="[itf.]vpi.vci" # PPPoA requires the ATM VC's address | |
701 | #link_ppp0="/dev/null" # ISDN links should have this | |
702 | #link_ppp0="pty 'your_link_command'" # PPP links over ssh, rsh, etc | |
703 | # | |
704 | # Here you should specify what pppd plugins you want to use | |
705 | # Available plugins are: pppoe, pppoa, capi, dhcpc, minconn, radius, | |
706 | # radattr, radrealms and winbind | |
707 | #plugins_ppp0="pppoe" # Required plugin for PPPoE | |
708 | #plugins_ppp0="pppoa vc-encaps" # Required plugin for PPPoA with an option | |
709 | #plugins_ppp0="capi" # Required plugin for ISDN | |
710 | # | |
711 | # PPP requires at least a username. You can optionally set a password here too | |
712 | # If you don't, then it will use the password specified in /etc/ppp/*-secrets | |
713 | # against the specified username | |
714 | #username_ppp0='user' | |
715 | #password_ppp0='password' | |
716 | # NOTE: You can set a blank password like so | |
717 | #password_ppp0= | |
718 | # | |
719 | # The PPP daemon has many options you can specify - although there are many | |
720 | # and may seem daunting, it is recommended that you read the pppd man page | |
721 | # before enabling any of them | |
722 | #pppd_ppp0=" | |
723 | # maxfail 0 # WARNING: It's not recommended you use this | |
724 | # # if you don't specify maxfail then we assume 0 | |
725 | # updetach # If not set, "/etc/init.d/net.ppp0 start" will return | |
726 | # # immediately, without waiting the link to come up | |
727 | # # for the first time. | |
728 | # # Do not use it for dial-on-demand links! | |
729 | # debug # Enables syslog debugging | |
730 | # noauth # Do not require the peer to authenticate itself | |
731 | # defaultroute # Make this PPP interface the default route | |
732 | # usepeerdns # Use the DNS settings provided by PPP | |
733 | # | |
734 | # On demand options | |
735 | # demand # Enable dial on demand | |
736 | # idle 30 # Link goes down after 30 seconds of inactivity | |
737 | # 10.112.112.112:10.112.112.113 # Phony IP addresses | |
738 | # ipcp-accept-remote # Accept the peers idea of remote address | |
739 | # ipcp-accept-local # Accept the peers idea of local address | |
740 | # holdoff 3 # Wait 3 seconds after link dies before re-starting | |
741 | # | |
742 | # Dead peer detection | |
743 | # lcp-echo-interval 15 # Send a LCP echo every 15 seconds | |
744 | # lcp-echo-failure 3 # Make peer dead after 3 consecutive | |
745 | # # echo-requests | |
746 | # | |
747 | # Compression options - use these to completely disable compression | |
748 | # noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp | |
749 | # | |
750 | # Dial-up settings | |
751 | # lock # Lock serial port | |
752 | # 115200 # Set the serial port baud rate | |
753 | # modem crtscts # Enable hardware flow control | |
754 | # 192.168.0.1:192.168.0.2 # Local and remote IP addresses | |
755 | #" | |
756 | # | |
757 | # Dial-up PPP users need to specify at least one telephone number | |
758 | #phone_number_ppp0="12345689" # Maximum 2 phone numbers are supported | |
759 | # They will also need a chat script - here's a good one | |
760 | #chat_ppp0=" | |
761 | #ABORT BUSY | |
762 | #ABORT ERROR | |
763 | #ABORT 'NO ANSWER' | |
764 | #ABORT 'NO CARRIER' | |
765 | #ABORT 'NO DIALTONE' | |
766 | #ABORT 'Invalid Login' | |
767 | #ABORT 'Login incorrect' | |
768 | #TIMEOUT 5 | |
769 | #'' ATZ | |
770 | #OK AT # Put your modem initialization string here | |
771 | #OK 'ATDT\T' | |
772 | #TIMEOUT 60 | |
773 | #CONNECT '' | |
774 | #TIMEOUT 5 | |
775 | #~-- '' | |
776 | #" | |
777 | ||
778 | # If the link require extra configuration - for example wireless or | |
779 | # RFC 268 bridge - we need to depend on the bridge so they get | |
780 | # configured correctly. | |
781 | #rc_net_ppp0_need="net.nas0" | |
782 | ||
783 | #WARNING: if MTU of the PPP interface is less than 1500 and you use this | |
784 | #machine as a router, you should add the following rule to your firewall | |
785 | # | |
786 | #iptables -I FORWARD 1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu | |
787 | ||
788 | #----------------------------------------------------------------------------- | |
789 | # ADSL | |
790 | # For ADSL support, emerge net-dialup/rp-pppoe | |
791 | # WARNING: This ADSL module is being deprecated in favour of the PPP module | |
792 | # above. | |
793 | # You should make the following settings and also put your | |
794 | # username/password information in /etc/ppp/pap-secrets | |
795 | ||
796 | # Configure the interface to use ADSL | |
797 | #config_eth0="adsl" | |
798 | ||
799 | # You probably won't need to edit /etc/ppp/pppoe.conf if you set this | |
800 | #adsl_user_eth0="my-adsl-username" | |
801 | ||
802 | #----------------------------------------------------------------------------- | |
803 | # ISDN | |
804 | # For ISDN support, emerge net-dialup/isdn4k-utils | |
805 | # You should make the following settings and also put your | |
806 | # username/password information in /etc/ppp/pap-secrets | |
807 | ||
808 | # Configure the interface to use ISDN | |
809 | #config_ippp0="dhcp" | |
810 | # It's important to specify dhcp if you need it! | |
811 | #config_ippp0="192.168.0.1/24" | |
812 | # Otherwise, you can use a static IP | |
813 | ||
814 | # NOTE: The interface name must be either ippp or isdn followed by a number | |
815 | ||
816 | # You may need this option to set the default route | |
817 | #ipppd_eth0="defaultroute" | |
818 | ||
819 | #----------------------------------------------------------------------------- | |
820 | # MAC changer | |
821 | # Warning: Do NOT use this on bonding interfaces! Bonding changes MACs itself. | |
822 | # | |
823 | # To set a specific MAC address | |
824 | #mac_eth0="00:11:22:33:44:55" | |
825 | ||
826 | # For changing MAC addresses using the below, emerge net-analyzer/macchanger | |
827 | # - to randomize the last 3 bytes only | |
828 | #mac_eth0="random-ending" | |
829 | # - to randomize between the same physical type of connection (e.g. fibre, | |
830 | # copper, wireless) , all vendors | |
831 | #mac_eth0="random-samekind" | |
832 | # - to randomize between any physical type of connection (e.g. fibre, copper, | |
833 | # wireless) , all vendors | |
834 | #mac_eth0="random-anykind" | |
835 | # - full randomization - WARNING: some MAC addresses generated by this may NOT | |
836 | # act as expected | |
837 | #mac_eth0="random-full" | |
838 | # custom - passes all parameters directly to net-analyzer/macchanger | |
839 | #mac_eth0="some custom set of parameters" | |
840 | ||
841 | # You can also set other options based on the MAC address of your network card | |
842 | # Handy if you use different docking stations with laptops | |
843 | #config_001122334455="dhcp" | |
844 | ||
845 | #----------------------------------------------------------------------------- | |
846 | # TUN/TAP | |
847 | # For TUN/TAP support install iproute2, openvpn or usermode-utilities | |
848 | # | |
849 | # You must specify if we're a tun or tap device. Then you can give it any | |
850 | # name you like - such as vpn | |
851 | #tuntap_vpn="tun" | |
852 | #config_vpn="192.168.0.1/24" | |
853 | ||
854 | # Or stick wit the generic names - like tap0 | |
855 | #tuntap_tap0="tap" | |
856 | #config_tap0="192.168.0.1/24" | |
857 | ||
858 | # Use something like this to pass custom options to iproute2 during | |
859 | # tunnel creation. This sets the user and group ownership of the node. | |
860 | #iproute2_tun1="user foo group bar" | |
861 | # For passing custom options to tunctl use something like the following. This | |
862 | # example sets the owner to adm | |
863 | #tunctl_tun1="-u adm" | |
864 | # OpenVPN-2.1_rc6 and newer allow --user and --group to set owner and group | |
865 | # of the node as well | |
866 | #openvpn_tun1="--user foo --group bar" | |
867 | ||
868 | #----------------------------------------------------------------------------- | |
869 | # Bridging (802.1d) | |
870 | # For bridging support emerge net-misc/bridge-utils | |
871 | ||
872 | # To add ports to bridge br0 | |
873 | #bridge_br0="eth0 eth1" | |
874 | # or dynamically add them when the interface comes up | |
875 | #bridge_add_eth0="br0" | |
876 | #bridge_add_eth1="br0" | |
877 | ||
878 | # NOTE: If you want to manually start an empty bridge, and then dynamically add | |
879 | # ports to it you must set at least one of the following variables based on the | |
880 | # interface name, so that we can pick it up from your configuration. Even an | |
881 | # empty value variable is fine, but at least one of them must be set: | |
882 | # brctl_IFVAR | |
883 | ||
884 | # You need to configure the ports to null values so dhcp does not get started | |
885 | #config_eth0="null" | |
886 | #config_eth1="null" | |
887 | ||
888 | # Finally give the bridge an address - dhcp or a static IP, this is assigned to | |
889 | # the bridge when the bridge is explicitly started. | |
890 | #config_br0="dhcp" # may not work when adding ports dynamically | |
891 | #config_br0="192.168.0.1/24" | |
892 | ||
893 | # If any of the ports require extra configuration - for example wireless or | |
894 | # ppp devices - we need to depend on them like so. | |
895 | #rc_net_br0_need="net.eth0 net.eth1" | |
896 | ||
897 | # Below is an example of configuring the bridge | |
898 | # Consult "man brctl" for more details | |
899 | #brctl_br0="setfd 15 | |
900 | #sethello 2 | |
901 | #stp on" | |
902 | ||
903 | # You can also configure the bridge or bridge members via sysfs on 2.6 kernels | |
904 | # or newer. See the kernel bridge documentation for a description of these | |
905 | # options. | |
906 | #stp_state_br0="0" | |
907 | #forward_delay_br0="10" | |
908 | #hairpin_mode_eth0="1" | |
909 | ||
910 | #----------------------------------------------------------------------------- | |
911 | # RFC 2684 Bridge Support | |
912 | # For RFC 2684 bridge support emerge net-misc/br2684ctl | |
913 | ||
914 | # Interface names have to be of the form nas0, nas1, nas2, etc. | |
915 | # You have to specify a VPI and VCI for the interface like so | |
916 | #br2684ctl_nas0="-a 0.38" # UK VPI and VCI | |
917 | ||
918 | # You may want to configure the encapsulation method as well by adding the -e | |
919 | # option to the command above (may need to be before the -a command) | |
920 | # -e 0 # LLC (default) | |
921 | # -e 1 # VC mux | |
922 | ||
923 | # Then you can configure the interface as normal | |
924 | #config_nas0="'192.168.0.1/24'" | |
925 | ||
926 | #----------------------------------------------------------------------------- | |
927 | # Tunneling | |
928 | # WARNING: For tunneling it is highly recommended that you | |
929 | # emerge sys-apps/iproute2 | |
930 | # | |
931 | # For GRE tunnels | |
932 | #iptunnel_vpn0="mode gre remote 207.170.82.1 key 0xffffffff ttl 255" | |
933 | ||
934 | # For IPIP tunnels | |
935 | #iptunnel_vpn0="mode ipip remote 207.170.82.2 ttl 255" | |
936 | ||
937 | # To configure the interface | |
938 | #config_vpn0="192.168.0.2 pointopoint 192.168.1.2" # ifconfig style | |
939 | #config_vpn0="192.168.0.2 peer 192.168.1.1" # iproute2 style | |
940 | ||
941 | # 6to4 Tunnels allow IPv6 to work over IPv4 addresses, provided you | |
942 | # have a non-private address configured on an interface. | |
943 | # link_6to4="eth0" # Interface to base its addresses on | |
944 | # config_6to4="ip6to4" | |
945 | # You may want to depend on eth0 like so | |
946 | #rc_net_6to4_need="net.eth0" | |
947 | # To ensure that eth0 is configured before 6to4. Of course, the tunnel could be | |
948 | # any name and this also works for any configured interface. | |
949 | # NOTE: If you're not using iproute2 then your 6to4 tunnel has to be called | |
950 | # sit0 - otherwise use a different name like 6to4 in the example above. | |
951 | ||
952 | # You can also specify a relay and suffix if you like. | |
953 | # The default relay is 192.88.99.1 and the default suffix is :1 | |
954 | #relay_6to4="192.168.3.2" | |
955 | #suffix_6to4=":ff" | |
956 | ||
957 | #----------------------------------------------------------------------------- | |
958 | # Advanced Routing | |
959 | # WARNING: For advanced routing you MUST be using sys-apps/iproute2 | |
960 | # | |
961 | # This provides a means to do multi-homing and more using the Routing Policy | |
962 | # Database (RPDB). | |
963 | # | |
964 | # See the following links for background and more information. | |
965 | # http://linux-ip.net/html/ch-routing.html | |
966 | # http://linux-ip.net/html/ch-advanced-routing.html | |
967 | ||
968 | # The rules listed will be added with 'ip rule add LINE' when the interface is | |
969 | # being brought up. They will also be removed with 'ip rule delete LINE'. | |
970 | # The rules added are also stored for later removal, so if you alter your rules | |
971 | # directly before stopping, you should review your rules again after stopping. | |
972 | ||
973 | # Note in earlier versions of openrc, this was provided as an example in | |
974 | # postup/postdown, however that implementation suffered some bugs in corner | |
975 | # cases, which are now fixed with this merger. If you used the previous | |
976 | # example, you should only need to drop the relevent portions of your | |
977 | # postup/postdown functions, and review the quoting in your rules_IFACE | |
978 | # variables. | |
979 | ||
980 | # Below is a trivial example for a dual-homed connection where there is an OOB | |
981 | # management network. Only packets explicitly with an address from or to the | |
982 | # OOB are sent via eth0. All others go via eth1 as the eth1 rules have a lower | |
983 | # priority. | |
984 | ||
985 | # If you want to use names for your tables, you should put lines into | |
986 | # /etc/iproute2/rt_tables, an example follows: | |
987 | # 2 oob | |
988 | # 3 external | |
989 | # | |
990 | # IPv6 RPDB entries are to be found in the rules6_IFVAR variables: | |
991 | ||
992 | #rules_eth0=" | |
993 | #from ZZZ.ZZZ.200.128/27 table oob priority 500 | |
994 | #to ZZZ.ZZZ.200.128/27 table oob priority 550" | |
995 | #rules_eth1=" | |
996 | #from XXX.XXX.112.0/24 table external priority 400 | |
997 | #to XXX.XXX.112.0/24 table external priority 450" | |
998 | #routes_eth0=" | |
999 | #ZZZ.ZZZ.200.128/27 dev eth0 table oob scope link | |
1000 | #default via ZZZ.ZZZ.200.129 table oob" | |
1001 | #routes_eth1=" | |
1002 | #XXX.XXX.112.0/24 dev eth1 table external scope link | |
1003 | #default via XXX.XXX.112.1 dev eth1" | |
1004 | ||
1005 | # IPv6 example: | |
1006 | #rules6_eth0=" | |
1007 | #from 2001:0DB8:AAAA:BBBB::/64 table vpn priority 100 | |
1008 | #to 2001:0DB8:AAAA:BBBB::/64 table vpn priority 150" | |
1009 | ||
1010 | ||
1011 | #----------------------------------------------------------------------------- | |
1012 | # System | |
1013 | # For configuring system specifics such as domain, dns, ntp and nis servers | |
1014 | # It's rare that you would need todo this, but you can anyway. | |
1015 | # This is most benefit to wireless users who don't use DHCP so they can change | |
1016 | # their configs based on SSID. | |
1017 | ||
1018 | # If you omit the _eth0 suffix, then it applies to all interfaces unless | |
1019 | # overridden by the interface suffix. | |
1020 | #dns_domain_eth0="your.domain" | |
1021 | #dns_servers_eth0="192.168.0.2 192.168.0.3" | |
1022 | #dns_search_eth0="this.domain that.domain" | |
1023 | #dns_options_eth0="timeout:1 rotate" | |
1024 | #dns_sortlist_eth0="130.155.160.0/255.255.240.0 130.155.0.0" | |
1025 | # See the man page for resolv.conf for details about the options and sortlist | |
1026 | # directives | |
1027 | ||
1028 | #ntp_servers_eth0="192.168.0.2 192.168.0.3" | |
1029 | ||
1030 | #nis_domain_eth0="domain" | |
1031 | #nis_servers_eth0="192.168.0.2 192.168.0.3" | |
1032 | ||
1033 | # NOTE: Setting any of these will stamp on the files in question. So if you | |
1034 | # don't specify dns_servers but you do specify dns_domain then no nameservers | |
1035 | # will be listed in /etc/resolv.conf even if there were any there to start | |
1036 | # with. | |
1037 | # If this is an issue for you then maybe you should look into a resolv.conf | |
1038 | # manager like resolvconf-gentoo to manage this file for you. All packages | |
1039 | # that baselayout supports use resolvconf-gentoo if installed. | |
1040 | ||
1041 | #----------------------------------------------------------------------------- | |
1042 | # Cable in/out detection | |
1043 | # Sometimes the cable is in, others it's out. Obviously you don't want to | |
1044 | # restart net.eth0 every time when you plug it in either. | |
1045 | # | |
1046 | # netplug is a package that detects this and requires no extra configuration | |
1047 | # on your part. | |
1048 | # emerge sys-apps/netplug | |
1049 | # or | |
1050 | # emerge sys-apps/ifplugd | |
1051 | # and you're done :) | |
1052 | ||
1053 | # By default we don't wait for netplug/ifplugd to configure the interface. | |
1054 | # If you would like it to wait so that other services know that network is | |
1055 | # up then you can specify a timeout here. A value of 0 means wait forever, | |
1056 | # and a negative value means never wait. | |
1057 | #plug_timeout_eth0="10" | |
1058 | # If you want to set it for all interfaces: | |
1059 | #plug_timeout="10" | |
1060 | ||
1061 | # If you don't want to use netplug on a specific interface but you have it | |
1062 | # installed, you can disable it for that interface via the modules statement | |
1063 | #modules_eth0="!netplugd" | |
1064 | # You can do the same for ifplugd | |
1065 | # | |
1066 | # You can disable them both with the generic plug | |
1067 | #modules_eth0="!plug" | |
1068 | ||
1069 | # To use specific ifplugd options, fex specifying wireless mode | |
1070 | #ifplugd_eth0="--api-mode=wlan" | |
1071 | # man ifplugd for more options | |
1072 | ||
1073 | #----------------------------------------------------------------------------- | |
1074 | # Interface hardware tuning & configuration via ethtool | |
1075 | # If you need to change explicit hardware settings on your network card prior | |
1076 | # to bringing the interface up, the following is available. | |
1077 | # | |
1078 | # For a full listing of settings, please consulting ethtool(8) and the output | |
1079 | # of "ethtool --help". | |
1080 | # | |
1081 | # Multiple entries (seperated by newlines) are supported in all of the | |
1082 | # variables as some settings cannot be changed at the same time. | |
1083 | # | |
1084 | # Valid variable name fragments: change pause coalesce ring offload | |
1085 | # change_eeprom identify nfc flash rxfh_indir ntuple | |
1086 | ||
1087 | # Set Wake-On-Lan to listen for SecureOn MagicPacket(tm), the message level to | |
1088 | # notify us of WOL changes, and the SecureOn password to 'DE:AD:BE:EF:CA:FE'. | |
1089 | #ethtool_change_eth0="wol gs | |
1090 | #msglvl wol on | |
1091 | #sopass DE:AD:BE:EF:CA:FE" | |
1092 | ||
1093 | # Disable pause auto-negotiation and explicitly enable RX and TX pause. | |
1094 | #ethtool_pause_eth0="autoneg off | |
1095 | #rx on tx on" | |
1096 | ||
1097 | # Enasble adaptive RX and TX coalescing | |
1098 | #ethtool_coalesce_eth0="adaptive-rx on adaptive-tx on" | |
1099 | ||
1100 | # Change ring buffer settings | |
1101 | #ethtool_ring_eth0="" | |
1102 | ||
1103 | # Enable all offload settings | |
1104 | #ethtool_offload_eth0="rx on tx on sg on tso on ufo on gso on gro on lro on" | |
1105 | ||
1106 | # Change specific bytes in the EEPROM | |
1107 | #ethtool_change_eeprom_eth0="" | |
1108 | ||
1109 | # Run the identify sequence on the interface for 1 second (does not return until completion) | |
1110 | #ethtool_identify_eth0="1" | |
1111 | ||
1112 | # Configure receive network flow classification | |
1113 | #ethtool_nfc_eth0=" | |
1114 | #rx-flow-hash tcp4 f | |
1115 | #rx-flow-hash udp4 s" | |
1116 | ||
1117 | # Flash firmware to all regions | |
1118 | #ethtool_flash_eth0="/some/path/firmware1 0" | |
1119 | ||
1120 | # Flash firmware to region 1 | |
1121 | #ethtool_flash_eth0="/some/path/firmware2 1" | |
1122 | ||
1123 | # Set receive flow hash indirection table for even balancing between N receive queues | |
1124 | #ethtool_rxfh_indir_eth0="equal 4" | |
1125 | ||
1126 | # Configure Rx ntuple filters and actions | |
1127 | #ethtool_ntuple_eth0="" | |
1128 | ||
1129 | # Additionally, there is a special control variable, if you need to change the | |
1130 | # order of option processing. The default order is: | |
1131 | # flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple | |
1132 | ||
1133 | # Set global order to default | |
1134 | #ethtool_order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple" | |
1135 | ||
1136 | # Hypothetical network card that requires a change-eeprom toggle to enable flashing | |
1137 | #ethtool_order_eth0="change-eeprom flash change pause coalesce ring offload nfc rxfh-indir ntuple" | |
1138 | ||
1139 | #----------------------------------------------------------------------------- | |
1140 | # Firewalld support | |
1141 | # If you are using the firewalld daemon to configure your firewall | |
1142 | # settings and you have specific zones you want to apply to your | |
1143 | # interfaces, you can do this here. | |
1144 | #firewalld_zone_eth0="myzone" | |
1145 | ||
1146 | ############################################################################## | |
1147 | # ADVANCED CONFIGURATION | |
1148 | # | |
1149 | # Four functions can be defined which will be called surrounding the | |
1150 | # start/stop operations. The functions are called with the interface | |
1151 | # name first so that one function can control multiple adapters. An extra two | |
1152 | # functions can be defined when an interface fails to start or stop. | |
1153 | # | |
1154 | # The return values for the preup and predown functions should be 0 | |
1155 | # (success) to indicate that configuration or deconfiguration of the | |
1156 | # interface can continue. If preup returns a non-zero value, then | |
1157 | # interface configuration will be aborted. If predown returns a | |
1158 | # non-zero value, then the interface will not be allowed to continue | |
1159 | # deconfiguration. | |
1160 | # | |
1161 | # The return values for the postup, postdown, failup and faildown functions are | |
1162 | # ignored since there's nothing to do if they indicate failure. | |
1163 | # | |
1164 | # ${IFACE} is set to the interface being brought up/down | |
1165 | # ${IFVAR} is ${IFACE} converted to variable name bash allows | |
1166 | # | |
1167 | # For historical and compatibility reasons, preup is actually normally called | |
1168 | # in the following sequence: up ; preup ; up. | |
1169 | # The first up causes the kernel to initialize the device, so | |
1170 | # that it is available for use in the preup function. However, for some | |
1171 | # hardware, e.g. CAN devices, some configuration is needed before trying to up | |
1172 | # the interface will actually work. For such hardware, the | |
1173 | # up_before_preup variables will allow skipping the first up call if set | |
1174 | # to yes. | |
1175 | #up_before_preup_IFVAR="NO" | |
1176 | #up_before_preup="NO" | |
1177 | ||
1178 | #preup() { | |
1179 | # # Test for link on the interface prior to bringing it up. This | |
1180 | # # only works on some network adapters and requires the | |
1181 | # # sys-apps/net-tools package to be installed. | |
1182 | # if mii-tool "${IFACE}" 2> /dev/null | grep -q 'no link'; then | |
1183 | # ewarn "No link on ${IFACE}, aborting configuration" | |
1184 | # return 1 | |
1185 | # fi | |
1186 | # | |
1187 | # # Test for link on the interface prior to bringing it up. This | |
1188 | # # only works on some network adapters and requires the ethtool | |
1189 | # # package to be installed. | |
1190 | # if ethtool "${IFACE}" | grep -q 'Link detected: no'; then | |
1191 | # ewarn "No link on ${IFACE}, aborting configuration" | |
1192 | # return 1 | |
1193 | # fi | |
1194 | # | |
1195 | # # Test to see if we're docked or not and configure like so | |
1196 | # # config_docked="dhcp" | |
1197 | # if grep -q "1" /sys/devices/platform/dock.0/docked; then | |
1198 | # einfo "${IFACE} is docked - configuring" | |
1199 | # _configure_variables "docked" | |
1200 | # fi | |
1201 | # | |
1202 | # # Remember to return 0 on success | |
1203 | # return 0 | |
1204 | #} | |
1205 | ||
1206 | #predown() { | |
1207 | # # The default in the script is to test for NFS root and disallow | |
1208 | # # downing interfaces in that case. Note that if you specify a | |
1209 | # # predown() function you will override that logic. Here it is, in | |
1210 | # # case you still want it... | |
1211 | # if is_net_fs /; then | |
1212 | # eerror "root filesystem is network mounted -- can't stop ${IFACE}" | |
1213 | # return 1 | |
1214 | # fi | |
1215 | # | |
1216 | # # Remember to return 0 on success | |
1217 | # return 0 | |
1218 | #} | |
1219 | ||
1220 | #postup() { | |
1221 | # # This function could be used, for example, to register with a | |
1222 | # # dynamic DNS service. Another possibility would be to | |
1223 | # # send/receive mail once the interface is brought up. | |
1224 | #} | |
1225 | ||
1226 | #postdown() { | |
1227 | # # Enable Wake-On-LAN for every interface except for lo | |
1228 | # # Probably a good idea to set ifdown="no" in /etc/conf.d/net | |
1229 | # # as well ;) | |
1230 | # [ "${IFACE}" != "lo" ] && ethtool -s "${IFACE}" wol g | |
1231 | # # Return 0 always | |
1232 | # return 0 | |
1233 | #} | |
1234 | ||
1235 | #failup() { | |
1236 | # # This function is mostly here for completeness... I haven't | |
1237 | # # thought of anything nifty to do with it yet ;-) | |
1238 | #} | |
1239 | ||
1240 | #faildown() { | |
1241 | # # This function is mostly here for completeness... I haven't | |
1242 | # # thought of anything nifty to do with it yet ;-) | |
1243 | #} |
0 | ############################################################################## | |
1 | # DragonFly BSD SPECIFIC OPTIONS | |
2 | ||
3 | # This is the subsystem type. Valid options on DragonFly BSD: | |
4 | # "" - nothing special | |
5 | # "jail" - DragonFly BSD jails | |
6 | # "prefix" - Prefix | |
7 | # If this is commented out, automatic detection will be used. | |
8 | # | |
9 | # This should be set to the value representing the environment this file is | |
10 | # PRESENTLY in, not the virtualization the environment is capable of. | |
11 | #rc_sys="" | |
12 |
19 | 19 | # consolefont, numlock, etc ...) |
20 | 20 | rc_tty_number=12 |
21 | 21 | |
22 | ############################################################################## | |
23 | # CGROUPS RESOURCE MANAGEMENT | |
24 | ||
25 | 22 | # If you have cgroups turned on in your kernel, this switch controls |
26 | 23 | # whether or not a group for each controller is mounted under |
27 | 24 | # /sys/fs/cgroup. |
28 | # None of the other options in this section work if this is set to "NO". | |
25 | # Support for process management by cgroups is planned in the future, | |
26 | # so if you turn this off, be aware that you may not be able to use that | |
27 | # feature. | |
29 | 28 | #rc_controller_cgroups="YES" |
30 | ||
31 | # The following settings allow you to set up values for the cgroup | |
32 | # controllers for your services. | |
33 | # They can be set in this file;, however, if you do this, the settings | |
34 | # will apply to all of your services. | |
35 | # If you want different settings for each service, place the settings in | |
36 | # /etc/conf.d/foo for service foo. | |
37 | # The format is to specify the names of the settings followed by their | |
38 | # values. Each variable can hold multiple settings. | |
39 | # For example, you would use this to set the cpu.shares setting in the | |
40 | # cpu controller to 512 for your service. | |
41 | # rc_cgroup_cpu=" | |
42 | # cpu.shares 512 | |
43 | # " | |
44 | # | |
45 | #For more information about the adjustments that can be made with | |
46 | #cgroups, see Documentation/cgroups/* in the linux kernel source tree. | |
47 | ||
48 | # Set the blkio controller settings for this service. | |
49 | #rc_cgroup_blkio="" | |
50 | ||
51 | # Set the cpu controller settings for this service. | |
52 | #rc_cgroup_cpu="" | |
53 | ||
54 | # Add this service to the cpuacct controller (any value means yes). | |
55 | #rc_cgroup_cpuacct="" | |
56 | ||
57 | # Set the cpuset controller settings for this service. | |
58 | #rc_cgroup_cpuset="" | |
59 | ||
60 | # Set the devices controller settings for this service. | |
61 | #rc_cgroup_devices="" | |
62 | ||
63 | # Set the memory controller settings for this service. | |
64 | #rc_cgroup_memory="" | |
65 | ||
66 | # Set the net_prio controller settings for this service. | |
67 | #rc_cgroup_net_prio="" | |
68 | ||
69 | # Set this to YES if yu want all of the processes in a service's cgroup | |
70 | # killed when the service is stopped or restarted. | |
71 | # This should not be set globally because it kills all of the service's | |
72 | # child processes, and most of the time this is undesirable. Please set | |
73 | # it in /etc/conf.d/<service>. | |
74 | # To perform this cleanup manually for a stopped service, you can | |
75 | # execute cgroup_cleanup with /etc/init.d/<service> cgroup_cleanup or | |
76 | # rc-service <service> cgroup_cleanup. | |
77 | # rc_cgroup_cleanup="NO" |
79 | 79 | # Set unicode to YES to turn on unicode support for keyboards and screens. |
80 | 80 | #unicode="NO" |
81 | 81 | |
82 | # This is how long fuser should wait for a remote server to respond. The | |
83 | # default is 60 seconds, but it can be adjusted here. | |
84 | #rc_fuser_timeout=60 | |
85 | ||
86 | 82 | # Below is the default list of network fstypes. |
87 | 83 | # |
88 | 84 | # afs cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre ncpfs |
104 | 100 | |
105 | 101 | # Some daemons are started and stopped via start-stop-daemon. |
106 | 102 | # We can set some things on a per service basis, like the nicelevel. |
107 | #SSD_NICELEVEL="-19" | |
103 | #export SSD_NICELEVEL="-19" | |
108 | 104 | |
109 | 105 | # Pass ulimit parameters |
110 | 106 | #rc_ulimit="-u 30" |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
4 | 4 | # Inform RC that we are in the background and hotplugged |
5 | IN_BACKGROUND=yes | |
6 | IN_HOTPLUG=yes | |
7 | export IN_BACKGROUND IN_HOTPLUG | |
5 | export IN_BACKGROUND=yes | |
6 | export IN_HOTPLUG=yes | |
8 | 7 | |
9 | 8 | getmedia() { |
10 | 9 | ifconfig "$1" | while read line; do |
3 | 3 | |
4 | 4 | # If $TERM is not set then assume default of @TERM@ |
5 | 5 | # This gives us a nice colour boot :) |
6 | [ -z "$TERM" -o "$TERM" = "dumb" ] && TERM="@TERM@" && export TERM | |
6 | [ -z "$TERM" -o "$TERM" = "dumb" ] && export TERM="@TERM@" | |
7 | 7 | |
8 | 8 | # Handle interrupts |
9 | 9 | trap : SIGINT |
6 | 6 | |
7 | 7 | # Try and use stuff in /lib over anywhere else so we can shutdown |
8 | 8 | # local mounts correctly. |
9 | LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}" ; export LD_LIBRARY_PATH | |
9 | export LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}" | |
10 | 10 | |
11 | 11 | # If $TERM is not set then assume default of @TERM@ |
12 | 12 | # This gives us a nice colour boot :) |
13 | [ -z "$TERM" -o "$TERM" = "dumb" ] && TERM="@TERM@" && export TERM | |
13 | [ -z "$TERM" -o "$TERM" = "dumb" ] && export TERM="@TERM@" | |
14 | 14 | |
15 | 15 | action=${1:-shutdown} |
16 | 16 | exec /sbin/rc "${action}" |
0 | include ../mk/net.mk | |
1 | ||
2 | 0 | DIR= ${INITDIR} |
3 | SRCS= bootmisc.in fsck.in hostname.in local.in localmount.in loopback.in \ | |
4 | netmount.in root.in savecache.in swap.in swapfiles.in \ | |
1 | SRCS= bootmisc.in fsck.in hostname.in local.in localmount.in netmount.in \ | |
2 | root.in savecache.in swap.in swapfiles.in \ | |
5 | 3 | tmpfiles.setup.in swclock.in sysctl.in urandom.in ${SRCS-${OS}} |
6 | 4 | BIN= ${OBJS} |
7 | 5 | |
8 | # Are we installing our network scripts? | |
9 | ifeq (${MKNET},yes) | |
6 | # Build our old net foo or not | |
7 | ifeq (${MKNET},) | |
10 | 8 | SRCS+= network.in staticroute.in |
9 | endif | |
10 | ||
11 | ifeq (${MKNET},oldnet) | |
12 | INSTALLAFTER= _installafter_net.lo | |
13 | SRCS+= net.lo.in | |
11 | 14 | endif |
12 | 15 | |
13 | 16 | MK= ../mk |
14 | 17 | include ${MK}/os.mk |
15 | 18 | |
19 | NET_LO-FreeBSD= net.lo0 | |
16 | 20 | # Generic BSD scripts |
17 | 21 | SRCS-FreeBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \ |
18 | 22 | rpcbind.in savecore.in syslogd.in |
20 | 24 | SRCS-FreeBSD+= adjkerntz.in devd.in dumpon.in encswap.in ipfw.in \ |
21 | 25 | mixer.in nscd.in powerd.in syscons.in |
22 | 26 | |
27 | NET_LO-Linux= net.lo | |
23 | 28 | SRCS-Linux= devfs.in dmesg.in hwclock.in consolefont.in keymaps.in \ |
24 | 29 | killprocs.in modules.in mount-ro.in mtab.in numlock.in \ |
25 | procfs.in sysfs.in termencoding.in tmpfiles.dev.in | |
30 | procfs.in sysfs.in termencoding.in | |
26 | 31 | |
32 | NET_LO-NetBSD= net.lo0 | |
27 | 33 | # Generic BSD scripts |
28 | 34 | SRCS-NetBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \ |
29 | 35 | rpcbind.in savecore.in syslogd.in |
36 | 42 | include ${MK}/scripts.mk |
37 | 43 | |
38 | 44 | _installafter_: realinstall |
45 | ||
46 | _installafter_net.lo: realinstall | |
47 | ${INSTALL} -m ${BINMODE} net.lo ${DESTDIR}/${INITDIR}/${NET_LO-${OS}} |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
26 | 26 | ebegin "Wiping $dir directory" |
27 | 27 | |
28 | 28 | # Faster than raw find |
29 | if ! rm -rf -- [!ajlq\.]* 2>/dev/null ; then | |
29 | if ! rm -rf -- [^ajlq\.]* 2>/dev/null ; then | |
30 | 30 | # Blah, too many files |
31 | find . -maxdepth 1 -name '[!ajlq\.]*' -exec rm -rf -- {} + | |
31 | find . -maxdepth 1 -name '[^ajlq\.]*' -exec rm -rf -- {} + | |
32 | 32 | fi |
33 | 33 | |
34 | 34 | # pam_mktemp creates a .private directory within which |
56 | 56 | .*-unix |
57 | 57 | eend 0 |
58 | 58 | fi |
59 | } | |
60 | ||
61 | cleanup_var_run_dir() | |
62 | { | |
63 | ebegin "Cleaning /var/run" | |
64 | for x in $(find /var/run ! -type d ! -name utmp \ | |
65 | ! -name random-seed ! -name dev.db \ | |
66 | ! -name ld-elf.so.hints ! -name ld.so.hints); | |
67 | do | |
68 | # Clean stale sockets | |
69 | if [ -S "$x" ]; then | |
70 | if type fuser >/dev/null 2>&1; then | |
71 | fuser "$x" >/dev/null 2>&1 || rm -- "$x" | |
72 | else | |
73 | rm -- "$x" | |
74 | fi | |
75 | fi | |
76 | [ ! -f "$x" ] && continue | |
77 | # Do not remove pidfiles of already running daemons | |
78 | case "$x" in | |
79 | *.pid) | |
80 | start-stop-daemon --test --quiet \ | |
81 | --stop --pidfile "$x" && continue | |
82 | ;; | |
83 | esac | |
84 | rm -f -- "$x" | |
85 | done | |
86 | eend 0 | |
87 | 59 | } |
88 | 60 | |
89 | 61 | mkutmp() |
114 | 86 | fi |
115 | 87 | } |
116 | 88 | |
117 | clean_run() | |
118 | { | |
119 | local dir | |
120 | dir=$(mktemp -d) | |
121 | mount --bind / $dir | |
122 | rm -rf $dir/run/* | |
123 | umount $dir | |
124 | rm -rf $dir | |
125 | } | |
126 | ||
127 | 89 | start() |
128 | 90 | { |
129 | 91 | # Remove any added console dirs |
152 | 114 | if [ "$RC_UNAME" = Linux -a -d /run ]; then |
153 | 115 | migrate_to_run /var/lock /run/lock |
154 | 116 | migrate_to_run /var/run /run |
155 | clean_run | |
156 | 117 | fi |
157 | 118 | |
158 | 119 | if checkpath -W /var/run; then |
165 | 126 | [ -e /var/log/wtmp ] || mkutmp /var/log/wtmp |
166 | 127 | eend 0 |
167 | 128 | |
168 | mountinfo -q -f tmpfs /var/run || cleanup_var_run_dir | |
129 | ebegin "Cleaning /var/run" | |
130 | for x in $(find /var/run ! -type d ! -name utmp \ | |
131 | ! -name random-seed ! -name dev.db \ | |
132 | ! -name ld-elf.so.hints ! -name ld.so.hints); | |
133 | do | |
134 | # Clean stale sockets | |
135 | if [ -S "$x" ]; then | |
136 | if type fuser >/dev/null 2>&1; then | |
137 | fuser "$x" >/dev/null 2>&1 || rm -- "$x" | |
138 | else | |
139 | rm -- "$x" | |
140 | fi | |
141 | fi | |
142 | [ ! -f "$x" ] && continue | |
143 | # Do not remove pidfiles of already running daemons | |
144 | case "$x" in | |
145 | *.pid) | |
146 | start-stop-daemon --test --quiet \ | |
147 | --stop --pidfile "$x" && continue | |
148 | ;; | |
149 | esac | |
150 | rm -f -- "$x" | |
151 | done | |
152 | eend 0 | |
169 | 153 | fi |
170 | 154 | |
171 | 155 | # Clean up /tmp directories |
172 | 156 | local tmp= |
173 | 157 | for tmp in ${clean_tmp_dirs:-${wipe_tmp_dirs-/tmp}}; do |
174 | mountinfo -q -f tmpfs "$tmp" || cleanup_tmp_dir "$tmp" | |
158 | cleanup_tmp_dir "$tmp" | |
175 | 159 | done |
176 | 160 | |
177 | 161 | if checkpath -W /tmp; then |
189 | 173 | if yesno $log_dmesg; then |
190 | 174 | if $logw || checkpath -W /var/log; then |
191 | 175 | # Create an 'after-boot' dmesg log |
192 | if [ "$RC_SYS" != VSERVER -a "$RC_SYS" != OPENVZ -a "$RC_SYS" != LXC ]; then | |
176 | if [ "$RC_SYS" != VSERVER -a "$RC_SYS" != OPENVZ ]; then | |
193 | 177 | dmesg > /var/log/dmesg |
194 | 178 | chmod 640 /var/log/dmesg |
195 | 179 | fi |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
52 | 52 | done |
53 | 53 | eend $retval |
54 | 54 | |
55 | # Store the font so we can use it ASAP on boot | |
55 | # Store the last font so we can use it ASAP on boot | |
56 | 56 | if [ $retval -eq 0 ] && checkpath -W "$RC_LIBEXECDIR"; then |
57 | 57 | mkdir -p "$RC_LIBEXECDIR"/console |
58 | setfont -O "$RC_LIBEXECDIR"/console/font | |
58 | for font in /usr/share/consolefonts/"$consolefont".*; do | |
59 | : | |
60 | done | |
61 | cp "$font" "$RC_LIBEXECDIR"/console | |
62 | echo "${font##*/}" >"$RC_LIBEXECDIR"/console/font | |
59 | 63 | fi |
60 | 64 | |
61 | 65 | return $retval |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
6 | 6 | depend() { |
7 | 7 | use dev-mount |
8 | 8 | before dev |
9 | keyword -prefix -vserver -lxc | |
9 | keyword -prefix -vserver | |
10 | 10 | } |
11 | 11 | |
12 | 12 | start() { |
13 | 13 | # Mount required stuff as user may not have then in /etc/fstab |
14 | 14 | for x in \ |
15 | "mqueue /dev/mqueue 1777 ,nodev mqueue" \ | |
16 | 15 | "devpts /dev/pts 0755 ,gid=5,mode=0620 devpts" \ |
17 | 16 | "tmpfs /dev/shm 1777 ,nodev shm" \ |
18 | 17 | ; do |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright 1992-2012 FreeBSD Project |
2 | 2 | # Released under the 2-clause BSD license |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
70 | 70 | done |
71 | 71 | |
72 | 72 | if [ "$RC_UNAME" = Linux ]; then |
73 | local skiptypes | |
74 | skiptypes=$(printf 'no%s,' ${net_fs_list} ${extra_net_fs_list}) | |
75 | [ "${skiptypes}" = "no," ] && skiptypes="" | |
76 | fsck_opts="$fsck_opts -C0 -T -t ${skiptypes}noopts=_netdev" | |
73 | local skiptypes x | |
74 | for x in $net_fs_list $extra_net_fs_list; do | |
75 | skiptypes="${skiptypes}no${x}," | |
76 | done | |
77 | skiptypes="${skiptypes}noopts=_netdev" | |
78 | fsck_opts="$fsck_opts -C0 -T -t $skiptypes" | |
77 | 79 | if [ -z "$fsck_passno" -a -z "$fsck_mnt" ]; then |
78 | fsck_args=${fsck_args:--A -p} | |
80 | fsck_args=${fsck_args--A -p} | |
79 | 81 | if echo 2>/dev/null >/.test.$$; then |
80 | 82 | rm -f /.test.$$ |
81 | 83 | fsck_opts="$fsck_opts -R" |
84 | 86 | fi |
85 | 87 | |
86 | 88 | trap : INT QUIT |
87 | fsck ${fsck_args:--p} $fsck_opts "$@" | |
89 | fsck ${fsck_args--p} $fsck_opts "$@" | |
88 | 90 | case $? in |
89 | 91 | 0) eend 0; return 0;; |
90 | 92 | 1) ewend 1 "Filesystems repaired"; return 0;; |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
9 | 9 | |
10 | 10 | start() |
11 | 11 | { |
12 | # HOSTNAME variable used to be defined in caps in conf.d/hostname. | |
13 | # It is also a magic variable in bash. | |
14 | hostname=${hostname-${HOSTNAME-localhost}} # checkbashisms: false positive | |
12 | hostname=${hostname-${HOSTNAME-localhost}} | |
15 | 13 | ebegin "Setting hostname to $hostname" |
16 | 14 | hostname "$hostname" |
17 | 15 | eend $? "Failed to set the hostname" |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
7 | 7 | ipfw_ports_in=${ipfw_ports_in-auth ssh} |
8 | 8 | ipfw_ports_nolog=${ipfw_ports_nolog-135-139,445 1026,1027 1433,1434} |
9 | 9 | |
10 | extra_commands="panic showstatus" | |
10 | opts="panic showstatus" | |
11 | 11 | |
12 | 12 | depend() { |
13 | 13 | before net |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
57 | 57 | if yesno $fix_euro; then |
58 | 58 | ebegin "Fixing font for euro symbol" |
59 | 59 | # Fix some fonts displaying the Euro, #173528. |
60 | echo "altgr keycode 18 = U+20AC" | loadkeys -q - | |
60 | echo "altgr keycode 18 = U+20AC" | loadkeys -q | |
61 | 61 | eend $? |
62 | 62 | fi |
63 | 63 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
16 | 16 | # Mount local filesystems in /etc/fstab. |
17 | 17 | local types="noproc" x= no_netdev= |
18 | 18 | for x in $net_fs_list $extra_net_fs_list; do |
19 | types="${types},no${x}" | |
19 | types="${types},${x}" | |
20 | 20 | done |
21 | 21 | |
22 | 22 | if [ "$RC_UNAME" = Linux ]; then |
23 | 23 | no_netdev="-O no_netdev" |
24 | 24 | if mountinfo -q /usr; then |
25 | touch "$RC_SVCDIR"/usr_premounted | |
25 | touch $RC_SVCDIR/usr_premounted | |
26 | 26 | fi |
27 | 27 | fi |
28 | 28 | ebegin "Mounting local filesystems" |
39 | 39 | # We never unmount / or /dev or $RC_SVCDIR |
40 | 40 | |
41 | 41 | # Bug 381783 |
42 | local rc_svcdir=$(printf '%s\n' "$RC_SVCDIR" | sed 's:/lib\(32\|64\)\?/:/lib(32|64)?/:g') | |
42 | local rc_svcdir=$(echo $RC_SVCDIR | sed 's:/lib\(32\|64\)\?/:/lib(32|64)?/:g') | |
43 | 43 | |
44 | 44 | local x= no_umounts_r="/|/dev|/dev/.*|${rc_svcdir}" |
45 | 45 | no_umounts_r="${no_umounts_r}|/bin|/sbin|/lib(32|64)?|/libexec" |
51 | 51 | |
52 | 52 | if [ "$RC_UNAME" = Linux ]; then |
53 | 53 | no_umounts_r="$no_umounts_r|/proc|/proc/.*|/run|/sys|/sys/.*" |
54 | if [ -e "$rc_svcdir"/usr_premounted ]; then | |
54 | if [ -e $rc_svcdir/usr_premounted ]; then | |
55 | 55 | no_umounts_r="$no_umounts_r|/usr" |
56 | 56 | fi |
57 | 57 | fi |
0 | #!@SBINDIR@/runscript | |
1 | # Copyright (c) 2013 William Hubbs <w.d.hubbs@gmail.com> | |
2 | # Released under the 2-clause BSD license. | |
3 | ||
4 | description="Configures the loopback interface." | |
5 | ||
6 | depend() | |
7 | { | |
8 | return 0 | |
9 | } | |
10 | ||
11 | start() | |
12 | { | |
13 | if [ "$RC_UNAME" = Linux ]; then | |
14 | ebegin "Bringing up network interface lo" | |
15 | if type ip > /dev/null 2>&1; then | |
16 | ip addr add 127.0.0.1/8 dev lo brd + scope host | |
17 | ip route add 127.0.0.0/8 dev lo scope host | |
18 | ip link set lo up | |
19 | else | |
20 | ifconfig lo 127.0.0.1 netmask 255.0.0.0 | |
21 | route add -net 127.0.0.0 netmask 255.0.0.0 gw 127.0.0.1 | |
22 | fi | |
23 | else | |
24 | ebegin "Bringing up network interface lo0" | |
25 | ifconfig lo0 127.0.0.1 netmask 255.0.0.0 | |
26 | route -q add -inet 127.0.0.0 -netmask 255.0.0.0 127.0.0.1 | |
27 | fi | |
28 | eend $? | |
29 | } | |
30 | ||
31 | stop() | |
32 | { | |
33 | return 0 | |
34 | } |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
27 | 27 | # makes / readonly and dismounts all tmpfs even if in use which is |
28 | 28 | # not good. Luckily, umount uses /etc/mtab instead of /proc/mounts |
29 | 29 | # which allows this hack to work. |
30 | grep -v "^[! ]* / tmpfs " /proc/mounts > /etc/mtab | |
30 | grep -v "^[^ ]* / tmpfs " /proc/mounts > /etc/mtab | |
31 | 31 | |
32 | 32 | # Remove stale backups |
33 | 33 | rm -f /etc/mtab~ /etc/mtab~~ |
0 | #!@PREFIX@/sbin/runscript | |
1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> | |
2 | # Released under the 2-clause BSD license. | |
3 | ||
4 | MODULESDIR="${RC_LIBEXECDIR}/net" | |
5 | MODULESLIST="${RC_SVCDIR}/nettree" | |
6 | _config_vars="config routes" | |
7 | ||
8 | [ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND="NO" | |
9 | ||
10 | description="Configures network interfaces." | |
11 | ||
12 | # Handy var so we don't have to embed new lines everywhere for array splitting | |
13 | __IFS=" | |
14 | " | |
15 | depend() | |
16 | { | |
17 | local IFACE=${RC_SVCNAME#*.} | |
18 | local IFVAR=$(shell_var "${IFACE}") | |
19 | ||
20 | need localmount | |
21 | if [ "$RC_UNAME" = Linux -a "$IFACE" != lo ]; then | |
22 | need sysfs | |
23 | fi | |
24 | after bootmisc | |
25 | keyword -jail -prefix -vserver | |
26 | ||
27 | case "${IFACE}" in | |
28 | lo|lo0) ;; | |
29 | *) | |
30 | after net.lo net.lo0 dbus | |
31 | provide net | |
32 | ;; | |
33 | esac | |
34 | ||
35 | if [ "$(command -v "depend_${IFVAR}")" = "depend_${IFVAR}" ]; then | |
36 | depend_${IFVAR} | |
37 | fi | |
38 | ||
39 | local dep= prov= | |
40 | for dep in need use before after provide keyword; do | |
41 | eval prov=\$rc_${dep}_${IFVAR} | |
42 | if [ -n "${prov}" ]; then | |
43 | ${dep} ${prov} | |
44 | ewarn "rc_${dep}_${IFVAR} is deprecated." | |
45 | ewarn "Please use rc_net_${IFVAR}_${dep} instead." | |
46 | fi | |
47 | done | |
48 | } | |
49 | ||
50 | # Support bash arrays - sigh | |
51 | _array_helper() | |
52 | { | |
53 | local _a= | |
54 | ||
55 | eval _a=\$$1 | |
56 | _a=$(echo "${_a}" | sed -e 's:^[[:space:]]*::' -e 's:[[:space:]]*$::' -e '/^$/d' -e 's:[[:space:]]\{1,\}: :g') | |
57 | ||
58 | [ -n "${_a}" ] && printf "%s\n" "${_a}" | |
59 | } | |
60 | ||
61 | _get_array() | |
62 | { | |
63 | local _a= | |
64 | if [ -n "${BASH}" ]; then | |
65 | case "$(declare -p "$1" 2>/dev/null)" in | |
66 | "declare -a "*) | |
67 | ewarn "You are using a bash array for $1." | |
68 | ewarn "This feature will be removed in the future." | |
69 | ewarn "Please see net.example for the correct format for $1." | |
70 | eval "set -- \"\${$1[@]}\"" | |
71 | for _a; do | |
72 | printf "%s\n" "${_a}" | |
73 | done | |
74 | return 0 | |
75 | ;; | |
76 | esac | |
77 | fi | |
78 | ||
79 | _array_helper $1 | |
80 | } | |
81 | ||
82 | # Flatten bash arrays to simple strings | |
83 | _flatten_array() | |
84 | { | |
85 | if [ -n "${BASH}" ]; then | |
86 | case "$(declare -p "$1" 2>/dev/null)" in | |
87 | "declare -a "*) | |
88 | ewarn "You are using a bash array for $1." | |
89 | ewarn "This feature will be removed in the future." | |
90 | ewarn "Please see net.example for the correct format for $1." | |
91 | eval "set -- \"\${$1[@]}\"" | |
92 | for x; do | |
93 | printf "'%s' " "$(printf "$x" | sed "s:':'\\\'':g")" | |
94 | done | |
95 | return 0 | |
96 | ;; | |
97 | esac | |
98 | fi | |
99 | ||
100 | _array_helper $1 | |
101 | } | |
102 | ||
103 | _wait_for_carrier() | |
104 | { | |
105 | local timeout= efunc=einfon | |
106 | ||
107 | _has_carrier && return 0 | |
108 | ||
109 | eval timeout=\$carrier_timeout_${IFVAR} | |
110 | timeout=${timeout:-${carrier_timeout:-0}} | |
111 | ||
112 | # Incase users don't want this nice feature ... | |
113 | [ ${timeout} -le 0 ] && return 0 | |
114 | ||
115 | yesno ${RC_PARALLEL} && efunc=einfo | |
116 | ${efunc} "Waiting for carrier (${timeout} seconds) " | |
117 | while [ ${timeout} -gt 0 ]; do | |
118 | sleep 1 | |
119 | if _has_carrier; then | |
120 | [ "${efunc}" = "einfon" ] && echo | |
121 | eend 0 | |
122 | return 0 | |
123 | fi | |
124 | : $(( timeout -= 1 )) | |
125 | [ "${efunc}" = "einfon" ] && printf "." | |
126 | done | |
127 | ||
128 | [ "${efunc}" = "einfon" ] && echo | |
129 | eend 1 | |
130 | return 1 | |
131 | } | |
132 | ||
133 | _netmask2cidr() | |
134 | { | |
135 | # Some shells cannot handle hex arithmetic, so we massage it slightly | |
136 | # Buggy shells include FreeBSD sh, dash and busybox. | |
137 | # bash and NetBSD sh don't need this. | |
138 | case $1 in | |
139 | 0x*) | |
140 | local hex=${1#0x*} quad= | |
141 | while [ -n "${hex}" ]; do | |
142 | local lastbut2=${hex#??*} | |
143 | quad=${quad}${quad:+.}0x${hex%${lastbut2}*} | |
144 | hex=${lastbut2} | |
145 | done | |
146 | set -- ${quad} | |
147 | ;; | |
148 | esac | |
149 | ||
150 | local i= len= | |
151 | local IFS=. | |
152 | for i in $1; do | |
153 | while [ ${i} -ne 0 ]; do | |
154 | : $(( len += i % 2 )) | |
155 | : $(( i >>= 1 )) | |
156 | done | |
157 | done | |
158 | ||
159 | echo "${len}" | |
160 | } | |
161 | ||
162 | _configure_variables() | |
163 | { | |
164 | local var= v= t= | |
165 | ||
166 | for var in ${_config_vars}; do | |
167 | local v= | |
168 | for t; do | |
169 | eval v=\$${var}_${t} | |
170 | if [ -n "${v}" ]; then | |
171 | eval ${var}_${IFVAR}=\$${var}_${t} | |
172 | continue 2 | |
173 | fi | |
174 | done | |
175 | done | |
176 | } | |
177 | ||
178 | _which() | |
179 | { | |
180 | local i OIFS | |
181 | # Empty | |
182 | [ -z "$1" ] && return | |
183 | # check paths | |
184 | OIFS="$IFS" | |
185 | IFS=: | |
186 | for i in $PATH ; do | |
187 | [ -x $i/$1 ] && echo $i/$1 && break | |
188 | done | |
189 | IFS=$OIFS | |
190 | } | |
191 | ||
192 | # Like _which, but also consider shell builtins, and multiple alternatives | |
193 | _program_available() | |
194 | { | |
195 | [ -z "$1" ] && return 0 | |
196 | local x= | |
197 | for x; do | |
198 | case "${x}" in | |
199 | /*) [ -x "${x}" ] && break;; | |
200 | *) type "${x}" >/dev/null 2>&1 && break;; | |
201 | esac | |
202 | unset x | |
203 | done | |
204 | [ -n "${x}" ] && echo $x && return 0 | |
205 | return 1 | |
206 | } | |
207 | ||
208 | _show_address() | |
209 | { | |
210 | einfo "received address $(_get_inet_address "${IFACE}")" | |
211 | } | |
212 | ||
213 | # Basically sorts our modules into order and saves the list | |
214 | _gen_module_list() | |
215 | { | |
216 | local x= f= force=$1 | |
217 | if ! ${force} && [ -s "${MODULESLIST}" -a "${MODULESLIST}" -nt "${MODULESDIR}" ]; then | |
218 | local update=false | |
219 | for x in "${MODULESDIR}"/*.sh; do | |
220 | [ -e "${x}" ] || continue | |
221 | if [ "${x}" -nt "${MODULESLIST}" ]; then | |
222 | update=true | |
223 | break | |
224 | fi | |
225 | done | |
226 | ${update} || return 0 | |
227 | fi | |
228 | ||
229 | einfo "Caching network module dependencies" | |
230 | # Run in a subshell to protect the main script | |
231 | ( | |
232 | after() { | |
233 | eval ${MODULE}_after="\"\${${MODULE}_after}\${${MODULE}_after:+ }$*\"" | |
234 | } | |
235 | ||
236 | before() { | |
237 | local mod=${MODULE} | |
238 | local MODULE= | |
239 | for MODULE; do | |
240 | after "${mod}" | |
241 | done | |
242 | } | |
243 | ||
244 | program() { | |
245 | if [ "$1" = "start" -o "$1" = "stop" ]; then | |
246 | local s="$1" | |
247 | shift | |
248 | eval ${MODULE}_program_${s}="\"\${${MODULE}_program_${s}}\${${MODULE}_program_${s}:+ }$*\"" | |
249 | else | |
250 | eval ${MODULE}_program="\"\${${MODULE}_program}\${${MODULE}_program:+ }$*\"" | |
251 | fi | |
252 | } | |
253 | ||
254 | provide() { | |
255 | eval ${MODULE}_provide="\"\${${MODULE}_provide}\${${MODULE}_provide:+ }$*\"" | |
256 | local x | |
257 | for x in $*; do | |
258 | eval ${x}_providedby="\"\${${MODULE}_providedby}\${${MODULE}_providedby:+ }${MODULE}\"" | |
259 | done | |
260 | } | |
261 | ||
262 | for MODULE in "${MODULESDIR}"/*.sh; do | |
263 | sh -n "${MODULE}" || continue | |
264 | . "${MODULE}" || continue | |
265 | MODULE=${MODULE#${MODULESDIR}/} | |
266 | MODULE=${MODULE%.sh} | |
267 | eval ${MODULE}_depend | |
268 | MODULES="${MODULES} ${MODULE}" | |
269 | done | |
270 | ||
271 | VISITED= | |
272 | SORTED= | |
273 | visit() { | |
274 | case " ${VISITED} " in | |
275 | *" $1 "*) return;; | |
276 | esac | |
277 | VISITED="${VISITED} $1" | |
278 | ||
279 | eval AFTER=\$${1}_after | |
280 | for MODULE in ${AFTER}; do | |
281 | eval PROVIDEDBY=\$${MODULE}_providedby | |
282 | if [ -n "${PROVIDEDBY}" ]; then | |
283 | for MODULE in ${PROVIDEDBY}; do | |
284 | visit "${MODULE}" | |
285 | done | |
286 | else | |
287 | visit "${MODULE}" | |
288 | fi | |
289 | done | |
290 | ||
291 | eval PROVIDE=\$${1}_provide | |
292 | for MODULE in ${PROVIDE}; do | |
293 | visit "${MODULE}" | |
294 | done | |
295 | ||
296 | eval PROVIDEDBY=\$${1}_providedby | |
297 | [ -z "${PROVIDEDBY}" ] && SORTED="${SORTED} $1" | |
298 | } | |
299 | ||
300 | for MODULE in ${MODULES}; do | |
301 | visit "${MODULE}" | |
302 | done | |
303 | ||
304 | printf "" > "${MODULESLIST}" | |
305 | i=0 | |
306 | for MODULE in ${SORTED}; do | |
307 | eval PROGRAM=\$${MODULE}_program | |
308 | eval PROGRAM_START=\$${MODULE}_program_start | |
309 | eval PROGRAM_STOP=\$${MODULE}_program_stop | |
310 | eval PROVIDE=\$${MODULE}_provide | |
311 | echo "module_${i}='${MODULE}'" >> "${MODULESLIST}" | |
312 | echo "module_${i}_program='${PROGRAM}'" >> "${MODULESLIST}" | |
313 | echo "module_${i}_program_start='${PROGRAM_START}'" >> "${MODULESLIST}" | |
314 | echo "module_${i}_program_stop='${PROGRAM_STOP}'" >> "${MODULESLIST}" | |
315 | echo "module_${i}_provide='${PROVIDE}'" >> "${MODULESLIST}" | |
316 | : $(( i += 1 )) | |
317 | done | |
318 | echo "module_${i}=" >> "${MODULESLIST}" | |
319 | ) | |
320 | ||
321 | return 0 | |
322 | } | |
323 | ||
324 | _load_modules() | |
325 | { | |
326 | local starting=$1 mymods= | |
327 | ||
328 | # Ensure our list is up to date | |
329 | _gen_module_list false | |
330 | if ! . "${MODULESLIST}"; then | |
331 | _gen_module_list true | |
332 | . "${MODULESLIST}" | |
333 | fi | |
334 | ||
335 | MODULES= | |
336 | if [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then | |
337 | eval mymods=\$modules_${IFVAR} | |
338 | [ -z "${mymods}" ] && mymods=${modules} | |
339 | fi | |
340 | ||
341 | local i=-1 x= mod= f= provides= | |
342 | while true; do | |
343 | : $(( i += 1 )) | |
344 | eval mod=\$module_${i} | |
345 | [ -z "${mod}" ] && break | |
346 | [ -e "${MODULESDIR}/${mod}.sh" ] || continue | |
347 | ||
348 | eval set -- \$module_${i}_program | |
349 | if [ -n "$1" ]; then | |
350 | if ! _program_available "$@" >/dev/null; then | |
351 | vewarn "Skipping module $mod due to missing program: $@" | |
352 | continue | |
353 | fi | |
354 | fi | |
355 | if ${starting}; then | |
356 | eval set -- \$module_${i}_program_start | |
357 | else | |
358 | eval set -- \$module_${i}_program_stop | |
359 | fi | |
360 | if [ -n "$1" ]; then | |
361 | if ! _program_available "$@" >/dev/null; then | |
362 | vewarn "Skipping module $mod due to missing program: $@" | |
363 | continue | |
364 | fi | |
365 | fi | |
366 | ||
367 | eval provides=\$module_${i}_provide | |
368 | if ${starting}; then | |
369 | case " ${mymods} " in | |
370 | *" !${mod} "*) continue;; | |
371 | *" !${provides} "*) [ -n "${provides}" ] && continue;; | |
372 | esac | |
373 | fi | |
374 | MODULES="${MODULES}${MODULES:+ }${mod}" | |
375 | ||
376 | # Now load and wrap our functions | |
377 | if ! . "${MODULESDIR}/${mod}.sh"; then | |
378 | eend 1 "${RC_SVCNAME}: error loading module \`${mod}'" | |
379 | exit 1 | |
380 | fi | |
381 | ||
382 | [ -z "${provides}" ] && continue | |
383 | ||
384 | # Wrap our provides | |
385 | local f= | |
386 | for f in pre_start start post_start; do | |
387 | eval "${provides}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }" | |
388 | done | |
389 | ||
390 | eval module_${mod}_provides="${provides}" | |
391 | eval module_${provides}_providedby="${mod}" | |
392 | done | |
393 | ||
394 | # Wrap our preferred modules | |
395 | for mod in ${mymods}; do | |
396 | case " ${MODULES} " in | |
397 | *" ${mod} "*) | |
398 | eval x=\$module_${mod}_provides | |
399 | [ -z "${x}" ] && continue | |
400 | for f in pre_start start post_start; do | |
401 | eval "${x}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }" | |
402 | done | |
403 | eval module_${x}_providedby="${mod}" | |
404 | ;; | |
405 | esac | |
406 | done | |
407 | ||
408 | # Finally remove any duplicated provides from our list if we're starting | |
409 | # Otherwise reverse the list | |
410 | local LIST="${MODULES}" p= | |
411 | MODULES= | |
412 | if ${starting}; then | |
413 | for mod in ${LIST}; do | |
414 | eval x=\$module_${mod}_provides | |
415 | if [ -n "${x}" ]; then | |
416 | eval p=\$module_${x}_providedby | |
417 | [ "${mod}" != "${p}" ] && continue | |
418 | fi | |
419 | MODULES="${MODULES}${MODULES:+ }${mod}" | |
420 | done | |
421 | else | |
422 | for mod in ${LIST}; do | |
423 | MODULES="${mod}${MODULES:+ }${MODULES}" | |
424 | done | |
425 | fi | |
426 | ||
427 | veinfo "Loaded modules: ${MODULES}" | |
428 | } | |
429 | ||
430 | _load_config() | |
431 | { | |
432 | local config="$(_get_array "config_${IFVAR}")" | |
433 | local fallback="$(_get_array fallback_${IFVAR})" | |
434 | ||
435 | config_index=0 | |
436 | local IFS="$__IFS" | |
437 | set -- ${config} | |
438 | ||
439 | # We should support a space separated array for cidr configs | |
440 | # But only as long as they do not contain other parameters for the address | |
441 | if [ $# = 1 ]; then | |
442 | unset IFS | |
443 | set -- ${config} | |
444 | # Of course, we may have a single address added old style. | |
445 | # If the NEXT argument is a v4 or v6 address, it's the next config. | |
446 | # Otherwise, it's arguments to the first config... | |
447 | if [ "${2#*.*}" = "${2}" -a "${2#*:*}" = "${2}" ]; then | |
448 | # Not an IPv4/IPv6 | |
449 | local IFS="$__IFS" | |
450 | set -- ${config} | |
451 | fi | |
452 | fi | |
453 | ||
454 | # Ensure that loopback has the correct address | |
455 | if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ]; then | |
456 | if [ "$1" != "null" ]; then | |
457 | config_0="127.0.0.1/8" | |
458 | config_index=1 | |
459 | fi | |
460 | else | |
461 | if [ -z "$1" ]; then | |
462 | ewarn "No configuration specified; defaulting to DHCP" | |
463 | config_0="dhcp" | |
464 | config_index=1 | |
465 | fi | |
466 | fi | |
467 | ||
468 | ||
469 | # We store our config in an array like vars | |
470 | # so modules can influence it | |
471 | for cmd; do | |
472 | eval config_${config_index}="'${cmd}'" | |
473 | : $(( config_index += 1 )) | |
474 | done | |
475 | # Terminate the list | |
476 | eval config_${config_index}= | |
477 | ||
478 | config_index=0 | |
479 | for cmd in ${fallback}; do | |
480 | eval fallback_${config_index}="'${cmd}'" | |
481 | : $(( config_index += 1 )) | |
482 | done | |
483 | # Terminate the list | |
484 | eval fallback_${config_index}= | |
485 | ||
486 | # Don't set to zero, so any net modules don't have to do anything extra | |
487 | config_index=-1 | |
488 | } | |
489 | ||
490 | # Support functions | |
491 | _run_if() | |
492 | { | |
493 | local cmd=$1 iface=$2 ifr=${IFACE} ifv=${IFVAR} | |
494 | # Ensure that we don't stamp on real values | |
495 | local IFACE= IFVAR= | |
496 | shift | |
497 | if [ -n "${iface}" ]; then | |
498 | IFACE="${iface}" | |
499 | [ "${iface}" != "${ifr}" ] && IFVAR=$(shell_var "${IFACE}") | |
500 | else | |
501 | IFACE=${ifr} | |
502 | IFVAR=${ifv} | |
503 | fi | |
504 | ${cmd} | |
505 | } | |
506 | interface_exists() | |
507 | { | |
508 | _run_if _exists "$@" | |
509 | } | |
510 | interface_up() | |
511 | { | |
512 | _run_if _up "$@" | |
513 | } | |
514 | interface_down() | |
515 | { | |
516 | _run_if _down "$@" | |
517 | } | |
518 | ||
519 | start() | |
520 | { | |
521 | local IFACE=${RC_SVCNAME#*.} oneworked=false fallback=false module= | |
522 | local IFVAR=$(shell_var "${IFACE}") cmd= our_metric= | |
523 | local metric=0 _up_before_preup | |
524 | eval _up_before_preup="\$up_before_preup_${IFVAR}" | |
525 | [ -z "${_up_before_preup}" ] && _up_before_preup=$up_before_preup | |
526 | ||
527 | einfo "Bringing up interface ${IFACE}" | |
528 | eindent | |
529 | ||
530 | if [ -z "${MODULES}" ]; then | |
531 | local MODULES= | |
532 | _load_modules true | |
533 | fi | |
534 | ||
535 | # We up the iface twice if we have a preup to ensure it's up if | |
536 | # available in preup and afterwards incase the user inadvertently | |
537 | # brings it down | |
538 | if [ "$(command -v preup)" = "preup" ]; then | |
539 | yesno "${_up_before_preup:-yes}" && _up 2>/dev/null | |
540 | ebegin "Running preup" | |
541 | eindent | |
542 | preup || return 1 | |
543 | eoutdent | |
544 | fi | |
545 | ||
546 | _up 2>/dev/null | |
547 | ||
548 | for module in ${MODULES}; do | |
549 | if [ "$(command -v "${module}_pre_start")" = "${module}_pre_start" ]; then | |
550 | ${module}_pre_start || exit $? | |
551 | fi | |
552 | done | |
553 | ||
554 | if ! _exists; then | |
555 | eerror "ERROR: interface ${IFACE} does not exist" | |
556 | eerror "Ensure that you have loaded the correct kernel module for your hardware" | |
557 | return 1 | |
558 | fi | |
559 | ||
560 | if ! _wait_for_carrier; then | |
561 | if service_started devd; then | |
562 | ewarn "no carrier, but devd will start us when we have one" | |
563 | mark_service_inactive "${RC_SVCNAME}" | |
564 | else | |
565 | eerror "no carrier" | |
566 | fi | |
567 | return 1 | |
568 | fi | |
569 | ||
570 | local config= config_index= | |
571 | _load_config | |
572 | config_index=0 | |
573 | ||
574 | eval our_metric=\$metric_${IFVAR} | |
575 | if [ -n "${our_metric}" ]; then | |
576 | metric=${our_metric} | |
577 | elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then | |
578 | : $(( metric += $(_ifindex) )) | |
579 | fi | |
580 | ||
581 | while true; do | |
582 | eval config=\$config_${config_index} | |
583 | [ -z "${config}" ] && break | |
584 | ||
585 | set -- ${config} | |
586 | if [ "$1" != "null" -a "$1" != "noop" ]; then | |
587 | ebegin "$1" | |
588 | fi | |
589 | eindent | |
590 | case "$1" in | |
591 | noop) | |
592 | if [ -n "$(_get_inet_address)" ]; then | |
593 | oneworked=true | |
594 | break | |
595 | fi | |
596 | ;; | |
597 | null) :;; | |
598 | [0-9]*|*:*) _add_address ${config};; | |
599 | *) | |
600 | if [ "$(command -v "${config}_start")" = "${config}_start" ]; then | |
601 | "${config}"_start | |
602 | else | |
603 | eerror "nothing provides \`${config}'" | |
604 | fi | |
605 | ;; | |
606 | esac | |
607 | if eend $?; then | |
608 | oneworked=true | |
609 | else | |
610 | eval config=\$fallback_${config_index} | |
611 | if [ -n "${config}" ]; then | |
612 | fallback=true | |
613 | eoutdent | |
614 | ewarn "Trying fallback configuration ${config}" | |
615 | eindent | |
616 | eval config_${config_index}=\$config | |
617 | unset fallback_${config_index} | |
618 | : $(( config_index -= 1 )) | |
619 | fi | |
620 | fi | |
621 | eoutdent | |
622 | : $(( config_index += 1 )) | |
623 | done | |
624 | ||
625 | if ! ${oneworked}; then | |
626 | if [ "$(command -v failup)" = "failup" ]; then | |
627 | ebegin "Running failup" | |
628 | eindent | |
629 | failup | |
630 | eoutdent | |
631 | fi | |
632 | return 1 | |
633 | fi | |
634 | ||
635 | local hidefirstroute=false first=true routes= | |
636 | if ${fallback}; then | |
637 | routes="$(_get_array "fallback_routes_${IFVAR}")" | |
638 | fi | |
639 | if [ -z "${routes}" ]; then | |
640 | routes="$(_get_array "routes_${IFVAR}")" | |
641 | fi | |
642 | if [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ]; then | |
643 | if [ "${config_0}" != "null" ]; then | |
644 | routes="127.0.0.0/8 via 127.0.0.1 | |
645 | ${routes}" | |
646 | hidefirstroute=true | |
647 | fi | |
648 | fi | |
649 | ||
650 | local OIFS="${IFS}" SIFS="${IFS-y}" | |
651 | local IFS="$__IFS" | |
652 | for cmd in ${routes}; do | |
653 | unset IFS | |
654 | if ${first}; then | |
655 | first=false | |
656 | einfo "Adding routes" | |
657 | fi | |
658 | eindent | |
659 | ebegin ${cmd} | |
660 | # Work out if we're a host or a net if not told | |
661 | case ${cmd} in | |
662 | -net" "*|-host" "*);; | |
663 | *" "netmask" "*) cmd="-net ${cmd}";; | |
664 | *.*.*.*/32*) cmd="-host ${cmd}";; | |
665 | *.*.*.*/*|0.0.0.0|0.0.0.0" "*) cmd="-net ${cmd}";; | |
666 | default|default" "*) cmd="-net ${cmd}";; | |
667 | *) cmd="-host ${cmd}";; | |
668 | esac | |
669 | if ${hidefirstroute}; then | |
670 | _add_route ${cmd} >/dev/null 2>&1 | |
671 | hidefirstroute=false | |
672 | else | |
673 | _add_route ${cmd} >/dev/null | |
674 | fi | |
675 | eend $? | |
676 | eoutdent | |
677 | done | |
678 | if [ "${SIFS}" = "y" ]; then | |
679 | unset IFS | |
680 | else | |
681 | IFS="${OIFS}" | |
682 | fi | |
683 | ||
684 | for module in ${MODULES}; do | |
685 | if [ "$(command -v "${module}_post_start")" = "${module}_post_start" ]; then | |
686 | ${module}_post_start || exit $? | |
687 | fi | |
688 | done | |
689 | ||
690 | if [ "$(command -v postup)" = "postup" ]; then | |
691 | ebegin "Running postup" | |
692 | eindent | |
693 | postup | |
694 | eoutdent | |
695 | fi | |
696 | ||
697 | return 0 | |
698 | } | |
699 | ||
700 | stop() | |
701 | { | |
702 | local IFACE=${RC_SVCNAME#*.} module= | |
703 | local IFVAR=$(shell_var "${IFACE}") opts= | |
704 | ||
705 | einfo "Bringing down interface ${IFACE}" | |
706 | eindent | |
707 | ||
708 | if [ -z "${MODULES}" ]; then | |
709 | local MODULES= | |
710 | _load_modules false | |
711 | fi | |
712 | ||
713 | if [ "$(command -v predown)" = "predown" ]; then | |
714 | ebegin "Running predown" | |
715 | eindent | |
716 | predown || return 1 | |
717 | eoutdent | |
718 | else | |
719 | if is_net_fs /; then | |
720 | eerror "root filesystem is network mounted -- can't stop ${IFACE}" | |
721 | return 1 | |
722 | fi | |
723 | fi | |
724 | ||
725 | for module in ${MODULES}; do | |
726 | if [ "$(command -v "${module}_pre_stop")" = "${module}_pre_stop" ]; then | |
727 | ${module}_pre_stop || exit $? | |
728 | fi | |
729 | done | |
730 | ||
731 | for module in ${MODULES}; do | |
732 | if [ "$(command -v "${module}_stop")" = "${module}_stop" ]; then | |
733 | ${module}_stop | |
734 | fi | |
735 | done | |
736 | ||
737 | # Only delete addresses for interfaces that exist | |
738 | if _exists; then | |
739 | # PPP can manage it's own addresses when IN_BACKGROUND | |
740 | # Important in case "demand" set on the ppp link | |
741 | if ! (yesno ${IN_BACKGROUND} && is_ppp) ; then | |
742 | _delete_addresses "${IFACE}" | |
743 | fi | |
744 | fi | |
745 | ||
746 | for module in ${MODULES}; do | |
747 | if [ "$(command -v "${module}_post_stop")" = "${module}_post_stop" ]; then | |
748 | ${module}_post_stop | |
749 | fi | |
750 | done | |
751 | ||
752 | # If not in background, and not loopback then bring the interface down | |
753 | # unless overridden. | |
754 | if ! yesno ${IN_BACKGROUND} && \ | |
755 | [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then | |
756 | eval module=\$ifdown_${IFVAR} | |
757 | module=${module:-${ifdown:-YES}} | |
758 | yesno ${module} && _down 2>/dev/null | |
759 | fi | |
760 | ||
761 | type resolvconf >/dev/null 2>&1 && resolvconf -d "${IFACE}" 2>/dev/null | |
762 | ||
763 | if [ "$(command -v "postdown")" = "postdown" ]; then | |
764 | ebegin "Running postdown" | |
765 | eindent | |
766 | postdown | |
767 | eoutdent | |
768 | fi | |
769 | ||
770 | return 0 | |
771 | } |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
222 | 222 | |
223 | 223 | einfo "Starting network" |
224 | 224 | routeflush |
225 | if [ "$RC_UNAME" = "Linux" ]; then | |
226 | ifconfig lo 127.0.0.1 netmask 255.0.0.0 || cr=1 | |
227 | route add -net 127.0.0.0 netmask 255.0.0.0 \ | |
228 | gw 127.0.0.1 reject 2>/dev/null | |
229 | else | |
230 | ifconfig lo0 127.0.0.1 netmask 255.0.0.0 || cr=1 | |
231 | route -q add -inet 127.0.0.0 -netmask 255.0.0.0 \ | |
232 | 127.0.0.1 -reject || cr=1 | |
233 | fi | |
225 | 234 | eindent |
226 | 235 | for int in $(interfaces); do |
227 | 236 | local func= cf= |
313 | 322 | # Don't stop the network at shutdown. |
314 | 323 | # We don't use the noshutdown keyword so that we are started again |
315 | 324 | # correctly if we go back to multiuser. |
316 | yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0 | |
325 | yesno ${shutdown_network:-YES} && yesno $RC_GOINGDOWN && return 0 | |
317 | 326 | |
318 | 327 | local int= intv= cmd= downcmd= r= |
319 | 328 | einfo "Stopping network" |
320 | 329 | routeflush |
321 | 330 | eindent |
322 | 331 | for int in $(reverse $(interfaces u)); do |
323 | case "$int" in | |
324 | lo|lo0) continue ;; | |
325 | *) ;; | |
326 | esac | |
327 | 332 | intv=$(shell_var "$int") |
328 | 333 | eval downcmd=\$ifdown_$intv |
329 | 334 | eval cmd=\$ip_$intv |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
30 | 30 | ebegin "Loading custom binary format handlers" |
31 | 31 | fmts=$(grep -hsv -e '^[#;]' -e '^[[:space:]]*$' \ |
32 | 32 | /run/binfmt.d/*.conf \ |
33 | /etc/binfmt.d/*.conf \ | |
33 | @SYSCONFDIR@/binfmt.d/*.conf \ | |
34 | 34 | ""/usr/lib/binfmt.d/*.conf) |
35 | 35 | if [ -n "${fmts}" ]; then |
36 | 36 | echo "${fmts}" > /proc/sys/fs/binfmt_misc/register |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
20 | 20 | stop() |
21 | 21 | { |
22 | 22 | ebegin "Deactivating additional swap space" |
23 | ||
24 | # Try to unmount all tmpfs filesystems not in use, else a deadlock may | |
25 | # occur. As $RC_SVCDIR may also be tmpfs we cd to it to lock it | |
26 | # fixme: Do we need this here since we are only unmounting swap files | |
27 | # and loopback swap? | |
28 | cd "$RC_SVCDIR" | |
29 | umount -a -t tmpfs 2>/dev/null | |
30 | ||
23 | 31 | case "$RC_UNAME" in |
24 | 32 | Linux) |
25 | 33 | if [ -e /proc/swaps ]; then |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
16 | 16 | { |
17 | 17 | ebegin "Setting the local clock based on last shutdown time" |
18 | 18 | if ! swclock 2> /dev/null; then |
19 | swclock --warn @SBINDIR@/runscript | |
19 | swclock --warn @PREFIX@/sbin/runscript | |
20 | 20 | fi |
21 | 21 | eend $? |
22 | 22 | } |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
4 | 4 | description="Mount the sys filesystem." |
5 | ||
6 | sysfs_opts=nodev,noexec,nosuid | |
7 | 5 | |
8 | 6 | depend() |
9 | 7 | { |
24 | 22 | |
25 | 23 | ebegin "Mounting /sys" |
26 | 24 | if ! fstabinfo --mount /sys; then |
27 | mount -n -t sysfs -o ${sysfs_opts} sysfs /sys | |
25 | mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys | |
28 | 26 | fi |
29 | 27 | eend $? |
30 | 28 | } |
36 | 34 | ! mountinfo -q /sys/kernel/security; then |
37 | 35 | if grep -qs securityfs /proc/filesystems; then |
38 | 36 | ebegin "Mounting security filesystem" |
39 | mount -n -t securityfs -o ${sysfs_opts} \ | |
37 | mount -n -t securityfs -o nodev,noexec,nosuid \ | |
40 | 38 | securityfs /sys/kernel/security |
41 | 39 | eend $? |
42 | 40 | fi |
46 | 44 | if [ -d /sys/kernel/debug ] && ! mountinfo -q /sys/kernel/debug; then |
47 | 45 | if grep -qs debugfs /proc/filesystems; then |
48 | 46 | ebegin "Mounting debug filesystem" |
49 | mount -n -t debugfs -o ${sysfs_opts} debugfs /sys/kernel/debug | |
47 | mount -n -t debugfs -o nodev,noexec,nosuid \ | |
48 | debugfs /sys/kernel/debug | |
50 | 49 | eend $? |
51 | 50 | fi |
52 | 51 | fi |
55 | 54 | if [ -d /sys/kernel/config ] && ! mountinfo -q /sys/kernel/config; then |
56 | 55 | if grep -qs configfs /proc/filesystems; then |
57 | 56 | ebegin "Mounting config filesystem" |
58 | mount -n -t configfs -o ${sysfs_opts} configfs /sys/kernel/config | |
57 | mount -n -t configfs -o nodev,noexec,nosuid \ | |
58 | configfs /sys/kernel/config | |
59 | 59 | eend $? |
60 | 60 | fi |
61 | 61 | fi |
64 | 64 | if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then |
65 | 65 | if grep -qs cgroup /proc/filesystems; then |
66 | 66 | ebegin "Mounting cgroup filesystem" |
67 | local opts="${sysfs_opts},mode=755,size=${rc_cgroupsize:-10m}" | |
67 | local opts="nodev,noexec,nosuid,mode=755,size=${rc_cgroupsize:-10m}" | |
68 | 68 | mount -n -t tmpfs -o ${opts} cgroup_root /sys/fs/cgroup |
69 | eend $? | |
70 | fi | |
71 | fi | |
72 | ||
73 | # set up kernel support for fusectl | |
74 | if [ -d /sys/fs/fuse/connections ] \ | |
75 | && ! mountinfo -q /sys/fs/fuse/connections; then | |
76 | if grep -qs fusectl /proc/filesystems; then | |
77 | ebegin "Mounting fuse control filesystem" | |
78 | mount -n -t fusectl -o ${sysfs_opts} \ | |
79 | fusectl /sys/fs/fuse/connections | |
80 | eend $? | |
81 | fi | |
82 | fi | |
83 | ||
84 | # setup up kernel support for efivarfs | |
85 | # slightly complicated, as if it's build as a module but NOT yet loaded, | |
86 | # it will NOT appear in /proc/filesystems yet | |
87 | if [ -d /sys/firmware/efi/efivars ] \ | |
88 | && ! mountinfo -q /sys/firmware/efi/efivars; then | |
89 | modprobe -q efivarfs | |
90 | if grep -qs efivarfs /proc/filesystems; then | |
91 | ebegin "Mounting efivarfs filesystem" | |
92 | mount -n -t efivarfs -o ${sysfs_opts} \ | |
93 | efivarfs /sys/firmware/efi/efivars | |
94 | 69 | eend $? |
95 | 70 | fi |
96 | 71 | fi |
103 | 78 | local agent="@LIBEXECDIR@/sh/cgroup-release-agent.sh" |
104 | 79 | mkdir /sys/fs/cgroup/openrc |
105 | 80 | mount -n -t cgroup \ |
106 | -o none,${sysfs_opts},name=openrc,release_agent="$agent" \ | |
81 | -o none,nodev,noexec,nosuid,name=openrc,release_agent="$agent" \ | |
107 | 82 | openrc /sys/fs/cgroup/openrc |
108 | 83 | echo 1 > /sys/fs/cgroup/openrc/notify_on_release |
109 | 84 | |
111 | 86 | while read name hier groups enabled rest; do |
112 | 87 | case "${enabled}" in |
113 | 88 | 1) mkdir /sys/fs/cgroup/${name} |
114 | mount -n -t cgroup -o ${sysfs_opts},${name} \ | |
89 | mount -n -t cgroup -o nodev,noexec,nosuid,${name} \ | |
115 | 90 | ${name} /sys/fs/cgroup/${name} |
116 | 91 | ;; |
117 | 92 | esac |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2008-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
1 | # Copyright 1999-2012 Gentoo Foundation | |
2 | # Released under the 2-clause BSD license. | |
3 | ||
4 | description="set up tmpfiles.d entries" | |
5 | ||
6 | depend() | |
7 | { | |
8 | use dev-mount | |
9 | before dev | |
10 | keyword -prefix -vserver | |
11 | } | |
12 | ||
13 | start() | |
14 | { | |
15 | ebegin "setting up tmpfiles.d entries for /dev" | |
16 | @LIBEXECDIR@/sh/tmpfiles.sh --prefix=/dev --create --remove \ | |
17 | ${tmpfiles_opts} | |
18 | eend $? | |
19 | return 0 | |
20 | } |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright 1999-2012 Gentoo Foundation |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 | |
11 | 11 | start() |
12 | 12 | { |
13 | 13 | ebegin "setting up tmpfiles.d entries" |
14 | @LIBEXECDIR@/sh/tmpfiles.sh --exclude-prefix=/dev --create --remove \ | |
15 | ${tmpfiles_opts} | |
14 | @LIBEXECDIR@/sh/tmpfiles.sh --create --remove ${tmpfiles_opts} | |
16 | 15 | eend $? |
17 | 16 | return 0 |
18 | 17 | } |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2008-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
0 | #!@SBINDIR@/runscript | |
0 | #!@PREFIX@/sbin/runscript | |
1 | 1 | # Copyright (c) 2009 Roy Marples <roy@marples.name> |
2 | 2 | # Released under the 2-clause BSD license. |
3 | 3 |
6 | 6 | service is stopped. |
7 | 7 | |
8 | 8 | All files are processed in lexical order. |
9 | ||
10 | Keep in mind that files in this directory are processed sequencially, | |
11 | and the local service is not considered started or stopped until | |
12 | everything is processed, so if you have a process which takes a long | |
13 | time to run, it can delay your boot or shutdown processing. |
1 | 1 | rc_config.3 rc_deptree.3 rc_find_pids.3 rc_plugin_hook.3 \ |
2 | 2 | rc_runlevel.3 rc_service.3 rc_stringlist.3 |
3 | 3 | MAN8= rc-service.8 rc-status.8 rc-update.8 rc.8 runscript.8 \ |
4 | service.8 start-stop-daemon.8 | |
4 | start-stop-daemon.8 | |
5 | 5 | |
6 | 6 | # Handy macro to create symlinks |
7 | 7 | # This does rely on correctly formatting our manpages! |
104 | 104 | respectively, but only work when |
105 | 105 | .Va EINFO_VERBOSE |
106 | 106 | is true. You can also make the |
107 | .Fn einfo , | |
108 | .Fn ewarn , | |
109 | .Fn eerror , | |
107 | .Fn einfo | |
110 | 108 | and |
111 | 109 | .Fn ebegin |
112 | 110 | functions silent by setting |
28 | 28 | .Nd stops and starts services for the specified runlevel |
29 | 29 | .Sh SYNOPSIS |
30 | 30 | .Nm |
31 | .Op Fl n , -no-stop | |
32 | 31 | .Op Fl o , -override |
33 | 32 | .Op Ar runlevel |
34 | 33 | .Sh DESCRIPTION |
35 | 34 | .Nm |
36 | first stops any services that are not in the specified runlevel unless | |
37 | --no-stop is specified, then starts any services in the runlevel and | |
38 | stacked runlevels added by | |
35 | first stops any services that are not for the runlevel and then starts any | |
36 | services in the runlevel and from stacked runlevels added by | |
39 | 37 | .Nm rc-update |
40 | 38 | that are not currently started. |
41 | If no runlevel is specified, we use the current runlevel. | |
39 | If no runlevel is specified then we use the current runlevel the system | |
40 | is currently in. | |
42 | 41 | .Pp |
43 | 42 | There are some special runlevels that you should be aware of: |
44 | 43 | .Bl -tag -width "shutdown" |
59 | 59 | services that need us fail to stop then we exit with a suitable error, |
60 | 60 | otherwise call the supplied stop function if it exists. |
61 | 61 | .It Ar restart |
62 | Stops and starts the service, including dependencies. This cannot be | |
63 | overridden. See the description of the RC_CMD variable below for the | |
64 | method to make your service behave differently when restart is being | |
65 | executed. | |
62 | Stop and start the service, including dependencies. | |
66 | 63 | .It Ar status |
67 | Shows the status of the service. The return code matches the status, with the | |
64 | Show the status of the service. The return code matches the status, with the | |
68 | 65 | exception of "started" returning 0 to match standard command behaviour. |
69 | 66 | .It Ar zap |
70 | 67 | Resets the service state to stopped and removes all saved data about the |
87 | 84 | .It Fl v , -verbose |
88 | 85 | Turns on any extra informational output the service generates. |
89 | 86 | .It Fl Z , -dry-run |
90 | Shows which services would be stopped and/or started without actually stopping | |
91 | or starting them. | |
87 | Shows what services would be stopped and/or started without actually starting | |
88 | or stopping them. | |
92 | 89 | .El |
93 | 90 | .Pp |
94 | 91 | The following variables affect the service script: |
155 | 152 | The service will start before these services and stop after these services. |
156 | 153 | .It Ic provide |
157 | 154 | We provide this virtual service. For example, named provides dns. |
158 | Virtual services take precedence over real services, so it is highly | |
159 | recommended that you do not have a real service that has the same name | |
160 | as a virtual service. | |
161 | 155 | .It Ic config |
162 | 156 | We should recalculate our dependencies if the listed files have changed. |
163 | 157 | .It Ic keyword |
364 | 358 | The result of `uname -s`. |
365 | 359 | .It Va RC_CMD |
366 | 360 | This contains the name of the command the service script is executing, such |
367 | as start, stop, restart etc. One example of using this is to make a | |
368 | service script behave differently when restart is being executed. | |
361 | as start, stop, restart etc. | |
369 | 362 | .El |
370 | 363 | .Sh FILES |
371 | 364 | .Pp |
470 | 463 | # stop_post. |
471 | 464 | fi |
472 | 465 | # Ensure that our dirs are correct |
473 | checkpath --directory --owner foo:foo --mode 0775 \\ | |
466 | checkpath --dir --owner foo:foo --mode 0664 \\ | |
474 | 467 | /var/run/foo /var/cache/foo |
475 | 468 | } |
476 | 469 |
0 | # Copyright (c) 2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | # Generic definitions | |
4 | ||
5 | include ${MK}/os-BSD.mk |
11 | 11 | _LCL_SED_SH= if test "${PREFIX}" = "${LOCAL_PREFIX}"; then echo "-e 's:@LOCAL_PREFIX@::g'"; else echo "-e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g'"; fi |
12 | 12 | _LCL_SED:= $(shell ${_LCL_SED_SH}) |
13 | 13 | |
14 | SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' -e 's:@PREFIX@:${PREFIX}:g' -e 's:@BINDIR@:${BINDIR}:g' -e 's:@SBINDIR@:${SBINDIR}:g' ${_PKG_SED} ${_LCL_SED} | |
14 | SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' -e 's:@PREFIX@:${PREFIX}:g' ${_PKG_SED} ${_LCL_SED} | |
15 | 15 | |
16 | 16 | # Tweak our shell scripts |
17 | 17 | %.sh: %.sh.in |
28 | 28 | LOCALDIR?= ${SYSCONFDIR}/local.d |
29 | 29 | SYSCTLDIR?= ${SYSCONFDIR}/sysctl.d |
30 | 30 | |
31 | BINDIR?= ${PREFIX}/bin | |
31 | BINDIR?= ${PREFIX}/sbin | |
32 | 32 | BINMODE?= 0755 |
33 | ||
34 | SBINDIR?= ${PREFIX}/sbin | |
35 | SBINMODE?= 0755 | |
36 | 33 | |
37 | 34 | INCDIR?= ${UPREFIX}/include |
38 | 35 | INCMODE?= 0444 |
0 | 0 | ifeq (${MKTERMCAP},ncurses) |
1 | LTERMCAP:= $(shell pkg-config ncurses --libs 2> /dev/null) | |
2 | ifeq ($(LTERMCAP),) | |
3 | 1 | LIBTERMCAP?= -lncurses |
4 | else | |
5 | LIBTERMCAP?= $(LTERMCAP) | |
6 | endif | |
7 | 2 | CPPFLAGS+= -DHAVE_TERMCAP |
8 | 3 | LDADD+= ${LIBTERMCAP} |
9 | 4 | else ifeq (${MKTERMCAP},termcap) |
0 | DIR= ${LIBEXECDIR}/net | |
1 | SRCS= ifconfig.sh.in ${SRCS-${OS}} | |
2 | INC= dhclient.sh dhcpcd.sh ifconfig.sh macchanger.sh macnet.sh \ | |
3 | ssidnet.sh system.sh wpa_supplicant.sh ${INC-${OS}} | |
4 | ||
5 | MK= ../mk | |
6 | include ${MK}/os.mk | |
7 | ||
8 | SRCS-FreeBSD= iwconfig.sh.in | |
9 | INC-FreeBSD= iwconfig.sh | |
10 | ||
11 | SRCS-Linux= iwconfig.sh.in | |
12 | INC-Linux= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \ | |
13 | ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \ | |
14 | ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \ | |
15 | vlan.sh macvlan.sh ip6rd.sh firewalld.sh | |
16 | ||
17 | SRCS-NetBSD= | |
18 | INC-NetBSD= ifwatchd.sh | |
19 | ||
20 | %.sh: %.sh${SFX} | |
21 | ${CP} $< $@ | |
22 | ||
23 | include ${MK}/scripts.mk |
0 | # Copyright (c) 2004-2007 Gentoo Foundation | |
1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
2 | # Released under the 2-clause BSD license. | |
3 | ||
4 | adsl_depend() | |
5 | { | |
6 | program /usr/sbin/adsl-start /usr/sbin/pppoe-start | |
7 | before dhcp | |
8 | } | |
9 | ||
10 | adsl_setup_vars() | |
11 | { | |
12 | local startstop="$1" cfgexe= | |
13 | ||
14 | if [ -x /usr/sbin/pppoe-start ]; then | |
15 | exe="/usr/sbin/pppoe-${startstop}" | |
16 | cfgexe=pppoe-setup | |
17 | else | |
18 | exe="/usr/sbin/adsl-${startstop}" | |
19 | cfgexe=adsl-setup | |
20 | fi | |
21 | ||
22 | # Decide which configuration to use. Hopefully there is an | |
23 | # interface-specific one | |
24 | cfgfile="/etc/ppp/pppoe-${IFACE}.conf" | |
25 | [ -f "${cfgfile}" ] || cfgfile="/etc/ppp/pppoe.conf" | |
26 | ||
27 | if [ ! -f "${cfgfile}" ]; then | |
28 | eerror "no pppoe.conf file found!" | |
29 | eerror "Please run ${cfgexe} to create one" | |
30 | return 1 | |
31 | fi | |
32 | ||
33 | return 0 | |
34 | } | |
35 | ||
36 | adsl_start() | |
37 | { | |
38 | local exe= cfgfile= user= | |
39 | ||
40 | adsl_setup_vars start || return 1 | |
41 | ||
42 | # Might or might not be set in conf.d/net | |
43 | eval user=\$adsl_user_${IFVAR} | |
44 | ||
45 | # Start ADSL with the cfgfile, but override ETH and PIDFILE | |
46 | einfo "Starting ADSL for ${IFACE}" | |
47 | ( | |
48 | cat "${cfgfile}"; | |
49 | echo "ETH=${IFACE}"; | |
50 | echo "PIDFILE=/var/run/rp-pppoe-${IFACE}.pid"; | |
51 | [ -n "${user}" ] && echo "USER=${user}"; | |
52 | ) | ${exe} >/dev/null | |
53 | eend $? | |
54 | } | |
55 | ||
56 | adsl_stop() | |
57 | { | |
58 | local exe= cfgfile= | |
59 | ||
60 | [ ! -f /var/run/rp-pppoe-"${IFACE}".pid ] && return 0 | |
61 | ||
62 | adsl_setup_vars stop || return 1 | |
63 | ||
64 | einfo "Stopping ADSL for ${IFACE}" | |
65 | ( | |
66 | cat "${cfgfile}"; | |
67 | echo "ETH=${IFACE}"; | |
68 | echo "PIDFILE=/var/run/rp-pppoe-${IFACE}.pid"; | |
69 | ) | ${exe} >/dev/null | |
70 | eend $? | |
71 | ||
72 | return 0 | |
73 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | apipa_depend() | |
4 | { | |
5 | program /sbin/arping | |
6 | } | |
7 | ||
8 | _random() | |
9 | { | |
10 | local r=${RANDOM} | |
11 | if [ -n "${r}" ]; then | |
12 | echo "${r}" | |
13 | else | |
14 | uuidgen | sed -n -e 's/[^[:digit:]]//g' -e 's/\(^.\{1,7\}\).*/\1/p' | |
15 | fi | |
16 | } | |
17 | ||
18 | apipa_start() | |
19 | { | |
20 | local iface="$1" i1= i2= addr= i=0 | |
21 | ||
22 | _exists true || return 1 | |
23 | ||
24 | einfo "Searching for free addresses in 169.254.0.0/16" | |
25 | eindent | |
26 | ||
27 | while [ ${i} -lt 64516 ]; do | |
28 | : $(( i1 = (_random % 255) + 1 )) | |
29 | : $(( i2 = (_random % 255) + 1 )) | |
30 | ||
31 | addr="169.254.${i1}.${i2}" | |
32 | vebegin "${addr}/16" | |
33 | if ! arping_address "${addr}"; then | |
34 | eval config_${config_index}="\"${addr}/16 broadcast 169.254.255.255\"" | |
35 | : $(( config_index -= 1 )) | |
36 | veend 0 | |
37 | eoutdent | |
38 | return 0 | |
39 | fi | |
40 | ||
41 | : $(( i += 1 )) | |
42 | done | |
43 | ||
44 | eerror "No free address found!" | |
45 | eoutdent | |
46 | return 1 | |
47 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | arping_depend() | |
4 | { | |
5 | program /sbin/arping /usr/sbin/arping2 | |
6 | before interface | |
7 | } | |
8 | ||
9 | arping_address() | |
10 | { | |
11 | local ip=${1%%/*} mac="$2" spoof="$3" foundmac= i= w= opts= | |
12 | ||
13 | # We only handle IPv4 addresses | |
14 | case "${ip}" in | |
15 | 0.0.0.0|0) return 1;; | |
16 | *.*.*.*);; | |
17 | *) return 1;; | |
18 | esac | |
19 | ||
20 | # We need to bring the interface up to test | |
21 | _exists "${iface}" || return 1 | |
22 | _up "${iface}" | |
23 | ||
24 | eval w=\$arping_wait_${IFVAR} | |
25 | [ -z "${w}" ] && w=${arping_wait:-5} | |
26 | ||
27 | if type arping2 >/dev/null 2>&1; then | |
28 | if [ -n "${spoof}" ]; then | |
29 | opts="${opts} -S ${spoof}" | |
30 | else | |
31 | [ -z "$(_get_inet_address)" ] && opts="${opts} -0" | |
32 | fi | |
33 | while [ ${w} -gt 0 -a -z "${foundmac}" ]; do | |
34 | foundmac="$(arping2 ${opts} -r -c 1 -i "${IFACE}" "${ip}" 2>/dev/null | \ | |
35 | sed -e 'y/abcdef/ABCDEF/')" | |
36 | : $(( w -= 1 )) | |
37 | done | |
38 | else | |
39 | [ -z "$(_get_inet_address)" ] && opts="${opts} -D" | |
40 | ||
41 | foundmac="$(arping -w "${w}" ${opts} -f -I "${IFACE}" "${ip}" 2>/dev/null | \ | |
42 | sed -n -e 'y/abcdef/ABCDEF/' -e 's/[^[]*\[\([^]]*\)\].*/\1/p')" | |
43 | fi | |
44 | [ -z "${foundmac}" ] && return 1 | |
45 | ||
46 | if [ -n "${mac}" ]; then | |
47 | if [ "${mac}" != "${foundmac}" ]; then | |
48 | vewarn "Found ${ip} but MAC ${foundmac} does not match" | |
49 | return 1 | |
50 | fi | |
51 | fi | |
52 | ||
53 | return 0 | |
54 | } | |
55 | ||
56 | _arping_in_config() | |
57 | { | |
58 | _get_array "config_${IFVAR}" | while read i; do | |
59 | [ "${i}" = "arping" ] && return 1 | |
60 | done | |
61 | return 1 | |
62 | } | |
63 | ||
64 | arping_start() | |
65 | { | |
66 | local gateways= x= conf= i= | |
67 | einfo "Pinging gateways on ${IFACE} for configuration" | |
68 | ||
69 | eval gateways=\$gateways_${IFVAR} | |
70 | if [ -z "${gateways}" ]; then | |
71 | eerror "No gateways have been defined (gateways_${IFVAR}=\"...\")" | |
72 | return 1 | |
73 | fi | |
74 | ||
75 | eindent | |
76 | ||
77 | for x in ${gateways}; do | |
78 | local IFS=, | |
79 | set -- ${x} | |
80 | local ip=$1 mac=$2 spoof=$3 extra= | |
81 | unset IFS | |
82 | ||
83 | if [ -n "${mac}" ]; then | |
84 | mac="$(echo "${mac}" | tr '[:lower:]' '[:upper:]')" | |
85 | extra="(MAC ${mac})" | |
86 | fi | |
87 | ||
88 | vebegin "${ip} ${extra}" | |
89 | if arping_address "${ip}" "${mac}" "${spoof}"; then | |
90 | local IFS=. | |
91 | for i in ${ip}; do | |
92 | if [ "${#i}" = "2" ]; then | |
93 | conf="${conf}0${i}" | |
94 | elif [ "${#i}" = "1" ]; then | |
95 | conf="${conf}00${i}" | |
96 | else | |
97 | conf="${conf}${i}" | |
98 | fi | |
99 | done | |
100 | unset IFS | |
101 | [ -n "${mac}" ] && conf="${conf}_$(echo "${mac}" | sed -e 's/://g')" | |
102 | ||
103 | eend 0 | |
104 | eoutdent | |
105 | veinfo "Configuring ${IFACE} for ${ip} ${extra}" | |
106 | _configure_variables ${conf} | |
107 | ||
108 | # Call the system module as we've aleady passed it by .... | |
109 | # And it *has* to be pre_start for other things to work correctly | |
110 | system_pre_start | |
111 | ||
112 | # Ensure that we have a valid config - ie arping is no longer there | |
113 | local IFS="$__IFS" | |
114 | for i in $(_get_array "config_${IFVAR}"); do | |
115 | if [ "${i}" = "arping" ]; then | |
116 | eend 1 "No config found for ${ip} (config_${conf}=\"...\")" | |
117 | continue 2 | |
118 | fi | |
119 | done | |
120 | unset IFS | |
121 | ||
122 | _load_config | |
123 | return 0 | |
124 | fi | |
125 | veend 1 | |
126 | done | |
127 | ||
128 | eoutdent | |
129 | return 1 | |
130 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | bonding_depend() | |
4 | { | |
5 | before interface macchanger | |
6 | program /sbin/ifconfig /bin/ifconfig | |
7 | # If you do not have sysfs, you MUST have this binary instead for ioctl | |
8 | # Also you will loose some functionality that cannot be done via sysfs: | |
9 | if [ ! -d /sys/class/net ]; then | |
10 | program /sbin/ifenslave | |
11 | fi | |
12 | } | |
13 | ||
14 | _config_vars="$_config_vars slaves" | |
15 | ||
16 | _is_bond() | |
17 | { | |
18 | [ -f "/proc/net/bonding/${IFACE}" ] | |
19 | } | |
20 | ||
21 | bonding_pre_start() | |
22 | { | |
23 | local x= s= n= slaves= primary= | |
24 | ||
25 | slaves="$(_get_array "slaves_${IFVAR}")" | |
26 | unset slaves_${IFVAR} | |
27 | ||
28 | eval primary="\$primary_${IFVAR}" | |
29 | unset primary_${IFVAR} | |
30 | ||
31 | eval subsume="\$subsume_${IFVAR}" | |
32 | unset subsume_${IFVAR} | |
33 | ||
34 | ||
35 | [ -z "${slaves}" ] && return 0 | |
36 | ||
37 | # Load the kernel module if required | |
38 | if [ ! -d /proc/net/bonding ]; then | |
39 | if ! modprobe bonding; then | |
40 | eerror "Cannot load the bonding module" | |
41 | return 1 | |
42 | fi | |
43 | fi | |
44 | ||
45 | if [ ! -d /sys/class/net ]; then | |
46 | ewarn "sysfs is not available! You will be unable to create new bonds, or change dynamic parameters!" | |
47 | fi | |
48 | ||
49 | # We can create the interface name we like now, but this | |
50 | # requires sysfs | |
51 | if ! _exists && [ -d /sys/class/net ]; then | |
52 | echo "+${IFACE}" > /sys/class/net/bonding_masters | |
53 | fi | |
54 | _exists true || return 1 | |
55 | ||
56 | if ! _is_bond; then | |
57 | eerror "${IFACE} is not capable of bonding" | |
58 | return 1 | |
59 | fi | |
60 | ||
61 | # Interface must be down in order to configure | |
62 | _down | |
63 | ||
64 | # Configure the bond mode, then we can reloop to ensure we configure | |
65 | # All other options | |
66 | [ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/mode; do | |
67 | [ -f "${x}" ] || continue | |
68 | n=${x##*/} | |
69 | eval s=\$${n}_${IFVAR} | |
70 | if [ -n "${s}" ]; then | |
71 | einfo "Setting ${n}: ${s}" | |
72 | echo "${s}" >"${x}" || \ | |
73 | eerror "Failed to configure $n (${n}_${IFVAR})" | |
74 | fi | |
75 | done | |
76 | # Configure link monitoring | |
77 | for x in /sys/class/net/"${IFACE}"/bonding/miimon; do | |
78 | [ -f "${x}" ] || continue | |
79 | n=${x##*/} | |
80 | eval s=\$${n}_${IFVAR} | |
81 | if [ -n "${s}" ]; then | |
82 | einfo "Setting ${n}: ${s}" | |
83 | echo "${s}" >"${x}" || \ | |
84 | eerror "Failed to configure $n (${n}_${IFVAR})" | |
85 | fi | |
86 | done | |
87 | # Nice and dynamic for remaining options:) | |
88 | [ -d /sys/class/net ] && for x in /sys/class/net/"${IFACE}"/bonding/*; do | |
89 | [ -f "${x}" ] || continue | |
90 | n=${x##*/} | |
91 | eval s=\$${n}_${IFVAR} | |
92 | [ "${n}" != "mode" -o "${n}" != "miimon" ] || continue | |
93 | if [ -n "${s}" ]; then | |
94 | einfo "Setting ${n}: ${s}" | |
95 | echo "${s}" >"${x}" || \ | |
96 | eerror "Failed to configure $n (${n}_${IFVAR})" | |
97 | fi | |
98 | done | |
99 | ||
100 | ebegin "Adding slaves to ${IFACE}" | |
101 | eindent | |
102 | einfo "${slaves}" | |
103 | ||
104 | # Check that our slaves exist | |
105 | ( | |
106 | for IFACE in ${slaves}; do | |
107 | _exists true || return 1 | |
108 | done | |
109 | ||
110 | # Unless we are subsuming an existing interface (NFS root), we down | |
111 | # slave interfaces to work around bugs supposedly in some chipsets | |
112 | # that cause failure to enslave from other states. | |
113 | if [ -z "${subsume}" ]; then | |
114 | for IFACE in ${slaves}; do | |
115 | _delete_addresses | |
116 | _down | |
117 | done | |
118 | fi | |
119 | ) | |
120 | ||
121 | # Now force the master to up | |
122 | # - First test for interface subsume request (required for NFS root) | |
123 | if [ -n "${subsume}" ]; then | |
124 | einfo "Subsuming ${subsume} interface characteristics." | |
125 | eindent | |
126 | local oiface=${IFACE} | |
127 | IFACE=${subsume} | |
128 | local addr="$(_get_inet_address)" | |
129 | einfo "address: ${addr}" | |
130 | IFACE=${oiface} | |
131 | unset oiface | |
132 | eoutdent | |
133 | # subsume (presumably kernel auto-)configured IP | |
134 | ifconfig ${IFACE} ${addr} up | |
135 | else | |
136 | # warn if root on nfs and no subsume interface supplied | |
137 | local root_fs_type=$(mountinfo -s /) | |
138 | if [ "${root_fs_type}" == "nfs" ]; then | |
139 | warn_nfs=1 | |
140 | ewarn "NFS root detected!!!" | |
141 | ewarn " If your system crashes here, /etc/conf.d/net needs" | |
142 | ewarn " subsume_${IFACE}=\"<iface>\" ... where <iface> is the" | |
143 | ewarn " existing, (usually kernel auto-)configured interface." | |
144 | fi | |
145 | # up the interface | |
146 | _up | |
147 | fi | |
148 | ||
149 | # finally add in slaves | |
150 | # things needed in the process, and if they are done by ifenslave, openrc, and/or the kernel. | |
151 | # down new slave interface: ifenslave, openrc | |
152 | # set mtu: ifenslave, kernel | |
153 | # set slave MAC: ifenslave, kernel | |
154 | eoutdent | |
155 | if [ -d /sys/class/net ]; then | |
156 | sys_bonding_path=/sys/class/net/"${IFACE}"/bonding | |
157 | local oiface | |
158 | oiface=$IFACE | |
159 | if [ -n "${primary}" ]; then | |
160 | IFACE=$primary | |
161 | _down | |
162 | IFACE=$oiface | |
163 | echo "+${primary}" >$sys_bonding_path/slaves | |
164 | echo "${primary}" >$sys_bonding_path/primary | |
165 | fi | |
166 | for s in ${slaves}; do | |
167 | [ "${s}" = "${primary}" ] && continue | |
168 | if ! grep -q ${s} $sys_bonding_path/slaves; then | |
169 | IFACE=$s | |
170 | _down | |
171 | IFACE=$oiface | |
172 | echo "+${s}" >$sys_bonding_path/slaves | |
173 | fi | |
174 | done | |
175 | else | |
176 | ifenslave "${IFACE}" ${slaves} >/dev/null | |
177 | fi | |
178 | eend $? | |
179 | ||
180 | return 0 #important | |
181 | } | |
182 | ||
183 | bonding_stop() | |
184 | { | |
185 | _is_bond || return 0 | |
186 | ||
187 | # Wipe subsumed interface | |
188 | if [ -n "${subsume}" ]; then | |
189 | ifconfig ${subsume} 0.0.0.0 | |
190 | fi | |
191 | ||
192 | local slaves= s= | |
193 | slaves=$( \ | |
194 | sed -n -e 's/^Slave Interface: //p' "/proc/net/bonding/${IFACE}" \ | |
195 | | tr '\n' ' ' \ | |
196 | ) | |
197 | [ -z "${slaves}" ] && return 0 | |
198 | ||
199 | # remove all slaves | |
200 | ebegin "Removing slaves from ${IFACE}" | |
201 | eindent | |
202 | einfo "${slaves}" | |
203 | eoutdent | |
204 | if [ -d /sys/class/net ]; then | |
205 | for s in ${slaves}; do | |
206 | echo -"${s}" > /sys/class/net/"${IFACE}"/bonding/slaves | |
207 | done | |
208 | else | |
209 | ifenslave -d "${IFACE}" ${slaves} | |
210 | fi | |
211 | ||
212 | # reset all slaves | |
213 | ( | |
214 | for IFACE in ${slaves}; do | |
215 | if _exists; then | |
216 | _delete_addresses | |
217 | _down | |
218 | fi | |
219 | done | |
220 | ) | |
221 | ||
222 | _down | |
223 | ||
224 | if [ -d /sys/class/net ]; then | |
225 | echo "-${IFACE}" > /sys/class/net/bonding_masters | |
226 | fi | |
227 | ||
228 | eend 0 | |
229 | return 0 | |
230 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | br2684ctl_depend() | |
4 | { | |
5 | before ppp | |
6 | program start br2684ctl | |
7 | } | |
8 | ||
9 | _config_vars="$_config_vars bridge bridge_add brctl" | |
10 | ||
11 | br2684ctl_pre_start() | |
12 | { | |
13 | local opts= | |
14 | eval opts=\$br2684ctl_${IFVAR} | |
15 | [ -z "${opts}" ] && return 0 | |
16 | ||
17 | if [ "${IFACE#nas[0-9]*}" = "${IFACE}" ]; then | |
18 | eerror "Interface must be called nas[0-9] for RFC 2684 Bridging" | |
19 | return 1 | |
20 | fi | |
21 | ||
22 | case " ${opts} " in | |
23 | *" -b "*|*" -c "*) | |
24 | eerror "The -b and -c options are not allowed for br2684ctl_${IVAR}" | |
25 | return 1 | |
26 | ;; | |
27 | *" -a "*);; | |
28 | *) | |
29 | eerror "-a option (VPI and VCI) is required in br2684ctl_${IFVAR}" | |
30 | return 1 | |
31 | ;; | |
32 | esac | |
33 | ||
34 | einfo "Starting RFC 2684 Bridge control on ${IFACE}" | |
35 | start-stop-daemon --start --exec $(_which br2684ctl) --background \ | |
36 | --make-pidfile --pidfile "/var/run/br2684ctl-${IFACE}.pid" \ | |
37 | -- -c "${IFACE#nas*}" ${opts} | |
38 | eend $? | |
39 | } | |
40 | ||
41 | br2684ctl_post_stop() | |
42 | { | |
43 | local pidfile="/var/run/br2684ctl-${IFACE}.pid" | |
44 | [ -e "${pidfile}" ] || return 0 | |
45 | ||
46 | einfo "Stopping RFC 2684 Bridge control on ${IFACE}" | |
47 | start-stop-daemon --stop --quiet --pidfile "${pidfile}" | |
48 | eend $? | |
49 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | bridge_depend() | |
4 | { | |
5 | before interface macnet | |
6 | program brctl | |
7 | } | |
8 | ||
9 | _config_vars="$_config_vars bridge bridge_add brctl" | |
10 | ||
11 | _is_bridge() | |
12 | { | |
13 | [ -d /sys/class/net/"${1:-${IFACE}}"/bridge ] | |
14 | return $? | |
15 | } | |
16 | ||
17 | _is_bridge_port() | |
18 | { | |
19 | [ -d /sys/class/net/"${1:-${IFACE}}"/brport ] | |
20 | return $? | |
21 | } | |
22 | ||
23 | _bridge_ports() | |
24 | { | |
25 | for x in /sys/class/net/"${1:-${IFACE}}"/brif/*; do | |
26 | n=${x##*/} | |
27 | echo $n | |
28 | done | |
29 | } | |
30 | ||
31 | bridge_pre_start() | |
32 | { | |
33 | local brif= oiface="${IFACE}" e= x= | |
34 | # ports is for static add | |
35 | local ports="$(_get_array "bridge_${IFVAR}")" | |
36 | # old config options | |
37 | local opts="$(_get_array "brctl_${IFVAR}")" | |
38 | # brif is used for dynamic add | |
39 | eval brif=\$bridge_add_${IFVAR} | |
40 | ||
41 | # we need a way to if the bridge exists in a variable name, not just the | |
42 | # contents of a variable. Eg if somebody has only bridge_add_eth0='br0', | |
43 | # with no other lines mentioning br0. | |
44 | eval bridge_unset=\${bridge_${IFVAR}-y\} | |
45 | eval brctl_unset=\${brctl_${IFVAR}-y\} | |
46 | ||
47 | if [ -z "${brif}" -a "${brctl_unset}" = 'y' ]; then | |
48 | if [ -z "${ports}" -a "${bridge_unset}" = "y" ]; then | |
49 | #eerror "Misconfigured static bridge detected (see net.example)" | |
50 | return 0 | |
51 | fi | |
52 | fi | |
53 | ||
54 | # If the bridge was already up, we should clear it | |
55 | [ "${bridge_unset}" != "y" ] && bridge_post_stop | |
56 | ||
57 | ( | |
58 | # Normalize order of variables | |
59 | if [ -z "${ports}" -a -n "${brif}" ]; then | |
60 | # Dynamic mode detected | |
61 | ports="${IFACE}" | |
62 | IFACE="${brif}" | |
63 | IFVAR=$(shell_var "${IFACE}") | |
64 | else | |
65 | # Static mode detected | |
66 | ports="${ports}" | |
67 | metric=1000 | |
68 | fi | |
69 | ||
70 | if ! _is_bridge ; then | |
71 | ebegin "Creating bridge ${IFACE}" | |
72 | if ! brctl addbr "${IFACE}"; then | |
73 | eend 1 | |
74 | return 1 | |
75 | fi | |
76 | fi | |
77 | ||
78 | # TODO: does this reset the bridge every time we add a interface to the | |
79 | # bridge? We should probably NOT do that. | |
80 | ||
81 | # Old configuration set mechanism | |
82 | # Only a very limited subset of the options are available in the old | |
83 | # configuration method. The sysfs interface is in the next block instead. | |
84 | local IFS="$__IFS" | |
85 | for x in ${opts}; do | |
86 | unset IFS | |
87 | set -- ${x} | |
88 | x=$1 | |
89 | shift | |
90 | set -- "${x}" "${IFACE}" "$@" | |
91 | brctl "$@" | |
92 | done | |
93 | unset IFS | |
94 | ||
95 | # New configuration set mechanism, matches bonding | |
96 | for x in /sys/class/net/"${IFACE}"/bridge/*; do | |
97 | [ -f "${x}" ] || continue | |
98 | n=${x##*/} | |
99 | eval s=\$${n}_${IFVAR} | |
100 | if [ -n "${s}" ]; then | |
101 | einfo "Setting ${n}: ${s}" | |
102 | echo "${s}" >"${x}" || \ | |
103 | eerror "Failed to configure $n (${n}_${IFVAR})" | |
104 | fi | |
105 | done | |
106 | ||
107 | if [ -n "${ports}" ]; then | |
108 | einfo "Adding ports to ${IFACE}" | |
109 | eindent | |
110 | ||
111 | local BR_IFACE="${IFACE}" | |
112 | for x in ${ports}; do | |
113 | ebegin "${x}" | |
114 | local IFACE="${x}" | |
115 | local IFVAR=$(shell_var "${IFACE}") | |
116 | if ! _exists "${IFACE}" ; then | |
117 | eerror "Cannot add non-existent interface ${IFACE} to ${BR_IFACE}" | |
118 | return 1 | |
119 | fi | |
120 | # The interface is known to exist now | |
121 | _up | |
122 | if ! brctl addif "${BR_IFACE}" "${x}"; then | |
123 | eend 1 | |
124 | return 1 | |
125 | fi | |
126 | # Per-interface bridge settings | |
127 | for x in /sys/class/net/"${IFACE}"/brport/*; do | |
128 | [ -f "${x}" ] || continue | |
129 | n=${x##*/} | |
130 | eval s=\$${n}_${IFVAR} | |
131 | if [ -n "${s}" ]; then | |
132 | einfo "Setting ${n}@${IFACE}: ${s}" | |
133 | echo "${s}" >"${x}" || \ | |
134 | eerror "Failed to configure $n (${n}_${IFVAR})" | |
135 | fi | |
136 | done | |
137 | eend 0 | |
138 | done | |
139 | eoutdent | |
140 | fi | |
141 | ) || return 1 | |
142 | ||
143 | # Bring up the bridge | |
144 | _set_flag promisc | |
145 | _up | |
146 | } | |
147 | ||
148 | bridge_post_stop() | |
149 | { | |
150 | local port= ports= delete=false extra= | |
151 | ||
152 | if _is_bridge "${IFACE}"; then | |
153 | ebegin "Destroying bridge ${IFACE}" | |
154 | _down | |
155 | for x in /sys/class/net/"${IFACE}"/brif/*; do | |
156 | [ -s $x ] || continue | |
157 | n=${x##*/} | |
158 | ports="${ports} ${n}" | |
159 | done | |
160 | delete=true | |
161 | iface=${IFACE} | |
162 | eindent | |
163 | else | |
164 | # We are taking down an interface that is part of a bridge maybe | |
165 | ports="${IFACE}" | |
166 | local brport_dir="/sys/class/net/${IFACE}/brport" | |
167 | [ -d ${brport_dir} ] || return 0 | |
168 | iface=$(readlink ${brport_dir}/bridge) | |
169 | iface=${iface##*/} | |
170 | [ -z "${iface}" ] && return 0 | |
171 | extra=" from ${iface}" | |
172 | fi | |
173 | ||
174 | for port in ${ports}; do | |
175 | ebegin "Removing port ${port}${extra}" | |
176 | local IFACE="${port}" | |
177 | _set_flag -promisc | |
178 | brctl delif "${iface}" "${port}" | |
179 | eend $? | |
180 | done | |
181 | ||
182 | if ${delete}; then | |
183 | eoutdent | |
184 | brctl delbr "${iface}" | |
185 | eend $? | |
186 | fi | |
187 | ||
188 | return 0 | |
189 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars ccwgroup" | |
4 | ||
5 | ccwgroup_depend() | |
6 | { | |
7 | before interface | |
8 | } | |
9 | ||
10 | ccwgroup_load_modules() | |
11 | { | |
12 | # make sure we have ccwgroup support or this is a crap shoot | |
13 | if [ ! -d /sys/bus/ccwgroup ] ; then | |
14 | modprobe -q ccwgroup | |
15 | if [ ! -d /sys/bus/ccwgroup ] ; then | |
16 | eerror "ccwgroup support missing in kernel" | |
17 | return 1 | |
18 | fi | |
19 | fi | |
20 | ||
21 | # verify the specific interface is supported | |
22 | if [ ! -d /sys/bus/ccwgroup/drivers/$1 ] ; then | |
23 | modprobe $1 >& /dev/null | |
24 | if [ ! -d /sys/bus/ccwgroup/drivers/$1 ] ; then | |
25 | eerror "$1 support missing in kernel" | |
26 | return 1 | |
27 | fi | |
28 | fi | |
29 | ||
30 | return 0 | |
31 | } | |
32 | ||
33 | ccwgroup_pre_start() | |
34 | { | |
35 | local ccwgroup="$(_get_array "ccwgroup_${IFVAR}")" | |
36 | [ -z "${ccwgroup}" ] && return 0 | |
37 | ||
38 | local ccw_type | |
39 | eval ccw_type=\${ccwgroup_type_${IFVAR}:-qeth} | |
40 | ||
41 | ccwgroup_load_modules ${ccw_type} || return 1 | |
42 | ||
43 | einfo "Enabling ccwgroup/${ccw_type} on ${IFACE}" | |
44 | ||
45 | set -- ${ccwgroup} | |
46 | local first=$1; shift | |
47 | if [ -e /sys/devices/${ccw_type}/${first}/online ]; then | |
48 | echo "0" >/sys/devices/${ccw_type}/${first}/online | |
49 | else | |
50 | echo "${first}$(printf ',%s' "$@")" >/sys/bus/ccwgroup/drivers/${ccw_type}/group | |
51 | fi | |
52 | ||
53 | local var val | |
54 | for var in $(_get_array "ccwgroup_opts_${IFVAR}") online=1 ; do | |
55 | val=${var#*=} | |
56 | var=${var%%=*} | |
57 | echo "${val}" > /sys/devices/${ccw_type}/${first}/${var} | |
58 | done | |
59 | eend $? | |
60 | ||
61 | # Now that we've properly configured the device, we can run | |
62 | # bring the interface up. Common code tried to do this already, | |
63 | # but it failed because we didn't setup sysfs yet. | |
64 | _up | |
65 | } | |
66 | ||
67 | ccwgroup_pre_stop() | |
68 | { | |
69 | local path="/sys/class/net/${IFACE}" | |
70 | ||
71 | # Erase any existing ccwgroup to be safe | |
72 | service_set_value ccwgroup_device "" | |
73 | service_set_value ccwgroup_type "" | |
74 | ||
75 | [ ! -L "${path}"/device/driver ] && return 0 | |
76 | case "$(readlink "${path}"/device/driver)" in | |
77 | */bus/ccwgroup/*) ;; | |
78 | *) return 0;; | |
79 | esac | |
80 | ||
81 | local device | |
82 | device="$(readlink "${path}"/device)" | |
83 | device=${device##*/} | |
84 | service_set_value ccwgroup_device "${device}" | |
85 | device="$(readlink "${path}"/device/driver)" | |
86 | device=${device##*/} | |
87 | service_set_value ccwgroup_type "${device}" | |
88 | } | |
89 | ||
90 | ccwgroup_post_stop() | |
91 | { | |
92 | local device="$(service_get_value ccwgroup_device)" | |
93 | [ -z "${device}" ] && return 0 | |
94 | local ccw_type="$(service_get_value ccwgroup_type)" | |
95 | local path="/sys/devices/${ccw_type}/${device}" | |
96 | ||
97 | einfo "Disabling ccwgroup/${ccw_type} on ${IFACE}" | |
98 | if echo "0" >"${path}"/online && | |
99 | echo "1" >"${path}"/ungroup ; then | |
100 | # The device doesn't disappear right away which breaks | |
101 | # restart, or a quick start up, so wait around. | |
102 | while [ -e "${path}" ] ; do :; done | |
103 | fi | |
104 | eend $? | |
105 | } |
0 | # Copyright (c) 2005-2007 Gentoo Foundation | |
1 | # Distributed under the terms of the GNU General Public License v2 | |
2 | ||
3 | clip_depend() | |
4 | { | |
5 | program /usr/sbin/atmsigd | |
6 | before interface | |
7 | } | |
8 | ||
9 | _config_vars="$_config_vars clip" | |
10 | ||
11 | # This starts a service. Albeit atmsigd, ilmid and atmarpd do allow for back- | |
12 | # grounding through the -b option, its usage causes them to be sensible to | |
13 | # SIGHUP, which is sent to all daemons when console detaches right after | |
14 | # startup. This is probably due to the fact that these programs don't detach | |
15 | # themself from the controlling terminal when backgrounding... The only way I | |
16 | # see to overcame this is to use the --background option in start-stop-daemon, | |
17 | # which is reported as a "last resort" method, but it acts correctly about this. | |
18 | atmclip_svc_start() | |
19 | { | |
20 | ebegin "Starting $2 Daemon ($1)" | |
21 | start-stop-daemon --start \ | |
22 | --background \ | |
23 | --make-pidfile --pidfile "/var/run/$1.pid" \ | |
24 | --exec "/usr/sbin/$1" -- -l syslog | |
25 | eend $? | |
26 | } | |
27 | ||
28 | atmclip_svcs_start() | |
29 | { | |
30 | einfo "First CLIP instance: starting ATM CLIP daemons" | |
31 | eindent | |
32 | ||
33 | if yesno ${clip_full:-yes}; then | |
34 | atmclip_svc_start atmsigd "Signaling" && \ | |
35 | atmclip_svc_start ilmid "Integrated Local Management Interface" && \ | |
36 | atmclip_svc_start atmarpd "Address Resolution Protocol" | |
37 | else | |
38 | atmclip_svc_start atmarpd "Address Resolution Protocol" | |
39 | fi | |
40 | ||
41 | local r=$? | |
42 | ||
43 | eoutdent | |
44 | return ${r} | |
45 | } | |
46 | ||
47 | atmclip_svc_stop() | |
48 | { | |
49 | ebegin "Stopping $2 Daemon ($1)" | |
50 | start-stop-daemon --stop --quiet \ | |
51 | --pidfile "/var/run/$1.pid" \ | |
52 | --exec "/usr/sbin/$1" | |
53 | eend $? | |
54 | } | |
55 | ||
56 | atmclip_svcs_stop() | |
57 | { | |
58 | einfo "Last CLIP instance: stopping ATM CLIP daemons" | |
59 | eindent | |
60 | ||
61 | # Heartake operation! | |
62 | sync | |
63 | ||
64 | atmclip_svc_stop atmarpd "Address Resolution Protocol" | |
65 | if yesno ${clip_full:-yes}; then | |
66 | atmclip_svc_stop ilmid "Integrated Local Management Interface" | |
67 | atmclip_svc_stop atmsigd "Signaling" | |
68 | fi | |
69 | ||
70 | eoutdent | |
71 | } | |
72 | ||
73 | are_atmclip_svcs_running() | |
74 | { | |
75 | ||
76 | start-stop-daemon --quiet --test --stop --pidfile /var/run/atmarpd.pid || return 1 | |
77 | ||
78 | if yesno ${clip_full:-yes}; then | |
79 | start-stop-daemon --quiet --test --stop --pidfile /var/run/ilmid.pid || return 1 | |
80 | start-stop-daemon --quiet --test --stop --pidfile /var/run/atmsigd.pid || return 1 | |
81 | fi | |
82 | ||
83 | return 0 | |
84 | } | |
85 | ||
86 | clip_pre_start() | |
87 | { | |
88 | local clip= | |
89 | eval clip=\$clip_${IFVAR} | |
90 | [ -z "${clip}" ] && return 0 | |
91 | ||
92 | if [ ! -r /proc/net/atm/arp ]; then | |
93 | modprobe clip && sleep 2 | |
94 | if [ ! -r /proc/net/atm/arp ]; then | |
95 | eerror "You need first to enable kernel support for ATM CLIP" | |
96 | return 1 | |
97 | fi | |
98 | fi | |
99 | ||
100 | local started_here= | |
101 | if ! are_atmclip_svcs_running; then | |
102 | atmclip_svcs_start || return 1 | |
103 | started_here=1 | |
104 | fi | |
105 | ||
106 | if ! _exists; then | |
107 | ebegin "Creating CLIP interface ${IFACE}" | |
108 | atmarp -c "${IFACE}" | |
109 | if ! eend $?; then | |
110 | [ -z "${started_here}" ] && atmclip_svcs_stop | |
111 | return 1 | |
112 | fi | |
113 | fi | |
114 | ||
115 | return 0 | |
116 | } | |
117 | ||
118 | clip_post_start() | |
119 | { | |
120 | local clip="$(_get_array "clip_${IFVAR}")" | |
121 | [ -z "${clip}" ] && return 0 | |
122 | ||
123 | are_atmclip_svcs_running || return 1 | |
124 | ||
125 | # The atm tools (atmarpd?) are silly enough that they would not work with | |
126 | # iproute2 interface setup as opposed to the ifconfig one. | |
127 | # The workaround is to temporarily toggle the interface state from up | |
128 | # to down and then up again, without touching its address. This (should) | |
129 | # work with both iproute2 and ifconfig. | |
130 | _down | |
131 | _up | |
132 | ||
133 | # Now the real thing: create a PVC with our peer(s). | |
134 | # There are cases in which the ATM interface is not yet | |
135 | # ready to establish new VCCs. In that cases, atmarp would | |
136 | # fail. Here we allow 10 retries to happen every 2 seconds before | |
137 | # reporting problems. Also, when no defined VC can be established, | |
138 | # we stop the ATM daemons. | |
139 | local has_failures= i= | |
140 | for i in ${clip}; do | |
141 | local IFS="," | |
142 | set -- ${i} | |
143 | unset IFS | |
144 | local peerip="$1"; shift | |
145 | local ifvpivci="$1"; shift | |
146 | ebegin "Creating PVC ${ifvpivci} for peer ${peerip}" | |
147 | ||
148 | local nleftretries=10 emsg= ecode= | |
149 | while [ ${nleftretries} -gt 0 ]; do | |
150 | : $(( nleftretries -= 1 )) | |
151 | emsg="$(atmarp -s "${peerip}" "${ifvpivci}" "$@" 2>&1)" | |
152 | ecode=$? && break | |
153 | sleep 2 | |
154 | done | |
155 | ||
156 | if ! eend ${ecode}; then | |
157 | eerror "Creation failed for PVC ${ifvpivci}: ${emsg}" | |
158 | has_failures=1 | |
159 | fi | |
160 | done | |
161 | ||
162 | if [ -n "${has_failures}" ]; then | |
163 | clip_pre_stop "${iface}" | |
164 | clip_post_stop "${iface}" | |
165 | return 1 | |
166 | else | |
167 | return 0 | |
168 | fi | |
169 | } | |
170 | ||
171 | clip_pre_stop() | |
172 | { | |
173 | are_atmclip_svcs_running || return 0 | |
174 | ||
175 | # We remove all the PVCs which may have been created by | |
176 | # clip_post_start for this interface. This shouldn't be | |
177 | # needed by the ATM stack, but sometimes I got a panic | |
178 | # killing CLIP daemons without previously vacuuming | |
179 | # every active CLIP PVCs. | |
180 | # The linux 2.6's ATM stack is really a mess... | |
181 | local itf= t= encp= idle= ipaddr= left= | |
182 | einfo "Removing PVCs on this interface" | |
183 | eindent | |
184 | { | |
185 | read left && \ | |
186 | while read itf t encp idle ipaddr left; do | |
187 | if [ "${itf}" = "${IFACE}" ]; then | |
188 | ebegin "Removing PVC to ${ipaddr}" | |
189 | atmarp -d "${ipaddr}" | |
190 | eend $? | |
191 | fi | |
192 | done | |
193 | } < /proc/net/atm/arp | |
194 | eoutdent | |
195 | } | |
196 | ||
197 | # Here we should teorically delete the interface previously created in the | |
198 | # clip_pre_start function, but there is no way to "undo" an interface creation. | |
199 | # We can just leave the interface down. "ifconfig -a" will still list it... | |
200 | # Also, here we can stop the ATM CLIP daemons if there is no other CLIP PVC | |
201 | # outstanding. We check this condition by inspecting the /proc/net/atm/arp file. | |
202 | clip_post_stop() | |
203 | { | |
204 | are_atmclip_svcs_running || return 0 | |
205 | ||
206 | local itf= left= hasothers= | |
207 | { | |
208 | read left && \ | |
209 | while read itf left; do | |
210 | if [ "${itf}" != "${IFACE}" ]; then | |
211 | hasothers=1 | |
212 | break | |
213 | fi | |
214 | done | |
215 | } < /proc/net/atm/arp | |
216 | ||
217 | if [ -z "${hasothers}" ]; then | |
218 | atmclip_svcs_stop || return 1 | |
219 | fi | |
220 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | dhclient_depend() | |
4 | { | |
5 | after interface | |
6 | program start /sbin/dhclient | |
7 | provide dhcp | |
8 | } | |
9 | ||
10 | _config_vars="$_config_vars dhcp dhcpcd" | |
11 | ||
12 | dhclient_start() | |
13 | { | |
14 | local args= opt= opts= pidfile="/var/run/dhclient-${IFACE}.pid" | |
15 | local sendhost=true dconf= | |
16 | ||
17 | # Get our options | |
18 | # These options only work in Gentoo, and maybe RedHat | |
19 | eval args=\$dhclient_${IFVAR} | |
20 | eval opts=\$dhcp_${IFVAR} | |
21 | [ -z "${opts}" ] && opts=${dhcp} | |
22 | ||
23 | for opt in ${opts}; do | |
24 | case "${opt}" in | |
25 | nodns) args="${args} -e PEER_DNS=no";; | |
26 | nontp) args="${args} -e PEER_NTP=no";; | |
27 | nogateway) args="${args} -e PEER_ROUTERS=no";; | |
28 | nosendhost) sendhost=false;; | |
29 | esac | |
30 | done | |
31 | ||
32 | # Add our route metric | |
33 | [ "${metric:-0}" != "0" ] && args="${args} -e IF_METRIC=${metric}" | |
34 | ||
35 | if ${sendhost}; then | |
36 | local hname="$(hostname)" | |
37 | if [ "${hname}" != "(none)" -a "${hname}" != "localhost" ]; then | |
38 | dhconf="${dhconf} interface \"${IFACE}\" {" | |
39 | dhconf="${dhconf} send host-name \"${hname}\";" | |
40 | dhconf="${dhconf}}" | |
41 | fi | |
42 | fi | |
43 | ||
44 | # Bring up DHCP for this interface | |
45 | ebegin "Running dhclient" | |
46 | echo "${dhconf}" | start-stop-daemon --start --exec /sbin/dhclient \ | |
47 | --pidfile "${pidfile}" \ | |
48 | -- ${args} -q -1 -pf "${pidfile}" "${IFACE}" | |
49 | eend $? || return 1 | |
50 | ||
51 | _show_address | |
52 | return 0 | |
53 | } | |
54 | ||
55 | dhclient_stop() | |
56 | { | |
57 | local pidfile="/var/run/dhclient-${IFACE}.pid" opts= | |
58 | [ ! -f "${pidfile}" ] && return 0 | |
59 | ||
60 | # Get our options | |
61 | if [ -x /sbin/dhclient ]; then | |
62 | eval opts=\$dhcp_${IFVAR} | |
63 | [ -z "${opts}" ] && opts=${dhcp} | |
64 | fi | |
65 | ||
66 | ebegin "Stopping dhclient on ${IFACE}" | |
67 | case " ${opts} " in | |
68 | *" release "*) dhclient -q -r -pf "${pidfile}" "${IFACE}";; | |
69 | *) | |
70 | start-stop-daemon --stop --quiet \ | |
71 | --exec /sbin/dhclient --pidfile "${pidfile}" | |
72 | ;; | |
73 | esac | |
74 | eend $? | |
75 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | dhcpcd_depend() | |
4 | { | |
5 | after interface | |
6 | program start dhcpcd | |
7 | provide dhcp | |
8 | ||
9 | # We prefer dhcpcd over the others | |
10 | after dhclient pump udhcpc | |
11 | } | |
12 | ||
13 | _config_vars="$_config_vars dhcp dhcpcd" | |
14 | ||
15 | dhcpcd_start() | |
16 | { | |
17 | local args= opt= opts= pidfile="/var/run/dhcpcd-${IFACE}.pid" new=true | |
18 | eval args=\$dhcpcd_${IFVAR} | |
19 | [ -z "${args}" ] && args=${dhcpcd} | |
20 | ||
21 | # Get our options | |
22 | eval opts=\$dhcp_${IFVAR} | |
23 | [ -z "${opts}" ] && opts=${dhcp} | |
24 | ||
25 | case "$(dhcpcd --version)" in | |
26 | "dhcpcd "[123]*) new=false;; | |
27 | esac | |
28 | ||
29 | # Map some generic options to dhcpcd | |
30 | for opt in ${opts}; do | |
31 | case "${opt}" in | |
32 | nodns) | |
33 | if ${new}; then | |
34 | args="${args} -C resolv.conf" | |
35 | else | |
36 | args="${args} -R" | |
37 | fi | |
38 | ;; | |
39 | nontp) | |
40 | if ${new}; then | |
41 | args="${args} -C ntp.conf" | |
42 | else | |
43 | args="${args} -N" | |
44 | fi | |
45 | ;; | |
46 | nonis) | |
47 | if ${new}; then | |
48 | args="${args} -C yp.conf" | |
49 | else | |
50 | args="${args} -Y" | |
51 | fi | |
52 | ;; | |
53 | nogateway) args="${args} -G";; | |
54 | nosendhost) args="${args} -h ''"; | |
55 | esac | |
56 | done | |
57 | ||
58 | # Add our route metric if not given | |
59 | case " $args " in | |
60 | *" -m "*) ;; | |
61 | *) [ "${metric:-0}" != 0 ] && args="$args -m $metric";; | |
62 | esac | |
63 | ||
64 | # Bring up DHCP for this interface | |
65 | ebegin "Running dhcpcd" | |
66 | ||
67 | eval dhcpcd "${args}" "${IFACE}" | |
68 | eend $? || return 1 | |
69 | ||
70 | _show_address | |
71 | return 0 | |
72 | } | |
73 | ||
74 | dhcpcd_stop() | |
75 | { | |
76 | local pidfile="/var/run/dhcpcd-${IFACE}.pid" opts= sig=SIGTERM | |
77 | [ ! -f "${pidfile}" ] && return 0 | |
78 | ||
79 | ebegin "Stopping dhcpcd on ${IFACE}" | |
80 | eval opts=\$dhcp_${IFVAR} | |
81 | [ -z "${opts}" ] && opts=${dhcp} | |
82 | case " ${opts} " in | |
83 | *" release "*) sig=SIGHUP;; | |
84 | esac | |
85 | start-stop-daemon --stop --quiet --signal ${sig} --pidfile "${pidfile}" | |
86 | eend $? | |
87 | } |
0 | # Copyright (c) 2011 by Gentoo Foundation | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | ethtool_depend() | |
4 | { | |
5 | program ethtool | |
6 | before interface | |
7 | } | |
8 | ||
9 | # This is just to trim whitespace, do not add any quoting! | |
10 | _trim() { | |
11 | echo $* | |
12 | } | |
13 | ||
14 | ethtool_pre_start() { | |
15 | local order opt OFS="${OIFS}" | |
16 | eval order=\$ethtool_order_${IFVAR} | |
17 | [ -z "${order}" ] && eval order=\$ethtool_order | |
18 | [ -z "${order}" ] && order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple" | |
19 | # ethtool options not used: --driver, --register-dump, --eeprom-dump, --negotiate, --test, --statistics | |
20 | eindent | |
21 | for opt in ${order} ; do | |
22 | local args | |
23 | eval args=\$ethtool_$(echo $opt | tr - _)_${IFVAR} | |
24 | ||
25 | # Skip everything if no arguments | |
26 | [ -z "${args}" ] && continue | |
27 | ||
28 | # Split on \n | |
29 | OIFS="${IFS}" | |
30 | local IFS="$__IFS" | |
31 | ||
32 | for p in ${args} ; do | |
33 | IFS="${OIFS}" | |
34 | local args_pretty="$(_trim "${p}")" | |
35 | # Do nothing if empty | |
36 | [ -z "${args_pretty}" ] && continue | |
37 | [ "${opt}" = "ring" ] && opt="set-ring" | |
38 | args_pretty="--${opt} $IFACE ${args_pretty}" | |
39 | args="--${opt} $IFACE ${args}" | |
40 | ebegin "ethtool ${args_pretty}" | |
41 | ethtool ${args} | |
42 | rc=$? | |
43 | eend $rc "ethtool exit code $rc" | |
44 | # TODO: ethtool has MANY different exit codes, with no | |
45 | # documentation as to which ones are fatal or not. For now we | |
46 | # simply print the exit code and don't stop the start sequence. | |
47 | done | |
48 | IFS="${OIFS}" | |
49 | done | |
50 | eoutdent | |
51 | } |
0 | # Copyright (c) 2012 Doug Goldstein <cardoe@cardoe.com> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | firewalld_depend() | |
4 | { | |
5 | after interface | |
6 | before dhcp | |
7 | program firewall-cmd | |
8 | [ "$IFACE" != "lo" ] && need firewalld | |
9 | } | |
10 | ||
11 | _config_vars="$_config_vars firewalld_zone" | |
12 | ||
13 | firewalld_post_start() | |
14 | { | |
15 | local firewalld_zone= | |
16 | eval firewalld_zone=\$firewalld_zone_${IFVAR} | |
17 | ||
18 | _exists || return 0 | |
19 | ||
20 | if [ "${IFACE}" != "lo" ]; then | |
21 | firewall-cmd --zone="${firewalld_zone}" \ | |
22 | --change-interface="${IFACE}" > /dev/null 2>&1 | |
23 | fi | |
24 | ||
25 | return 0 | |
26 | } | |
27 | ||
28 | firewalld_pre_stop() | |
29 | { | |
30 | _exists || return 0 | |
31 | ||
32 | if [ "${IFACE}" != "lo" ]; then | |
33 | firewall-cmd --remove-interface="${IFACE}" > /dev/null 2>&1 | |
34 | fi | |
35 | ||
36 | return 0 | |
37 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | ifconfig_depend() | |
4 | { | |
5 | program /sbin/ifconfig | |
6 | provide interface | |
7 | } | |
8 | ||
9 | _exists() | |
10 | { | |
11 | # Only FreeBSD sees to have /dev/net .... is there something | |
12 | # other than ifconfig we can use for the others? | |
13 | if [ -d /dev/net ]; then | |
14 | [ -e /dev/net/"${IFACE}" ] | |
15 | else | |
16 | ifconfig "${IFACE}" >/dev/null 2>&1 | |
17 | fi | |
18 | } | |
19 | ||
20 | _up() | |
21 | { | |
22 | ifconfig "${IFACE}" up | |
23 | } | |
24 | ||
25 | _down() | |
26 | { | |
27 | ifconfig "${IFACE}" down | |
28 | } | |
29 | ||
30 | _ifindex() | |
31 | { | |
32 | local x= i=1 | |
33 | case "${RC_UNAME}" in | |
34 | FreeBSD|DragonFly) | |
35 | for x in /dev/net[0-9]*; do | |
36 | if [ "${x}" -ef /dev/net/"${IFACE}" ]; then | |
37 | echo "${x#/dev/net}" | |
38 | return 0 | |
39 | fi | |
40 | : $(( i += 1 )) | |
41 | done | |
42 | ;; | |
43 | default) | |
44 | for x in $(ifconfig -l); do | |
45 | if [ "${x}" = "${IFACE}" ]; then | |
46 | echo "${i}" | |
47 | return 0 | |
48 | fi | |
49 | : $(( i += 1 )) | |
50 | done | |
51 | ;; | |
52 | esac | |
53 | ||
54 | # Return the next available index | |
55 | echo "${i}" | |
56 | return 1 | |
57 | } | |
58 | ||
59 | _ifconfig_ent() | |
60 | { | |
61 | LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | while read ent rest; do | |
62 | case "${ent}" in | |
63 | $1) echo "${rest}";; | |
64 | esac | |
65 | done | |
66 | } | |
67 | ||
68 | _get_mac_address() | |
69 | { | |
70 | local ent="ether" | |
71 | case "${RC_UNAME}" in | |
72 | NetBSD|OpenBSD) ent="address:";; | |
73 | esac | |
74 | ||
75 | case $(_ifconfig_ent "${ent}") in | |
76 | 00:00:00:00:00:00);; | |
77 | 44:44:44:44:44:44);; | |
78 | FF:FF:FF:FF:FF:FF);; | |
79 | "") return 1;; | |
80 | *) echo "${address}";; | |
81 | esac | |
82 | ||
83 | return 0; | |
84 | } | |
85 | ||
86 | ||
87 | _is_wireless() | |
88 | { | |
89 | case "$(_ifconfig_ent "media:")" in | |
90 | IEEE802.11*|"IEEE 802.11 Wireless"*) return 0;; | |
91 | *) return 1;; | |
92 | esac | |
93 | } | |
94 | ||
95 | _get_inet_address() | |
96 | { | |
97 | local inet= address= n= netmask= rest= | |
98 | LC_ALL=C ifconfig "${IFACE}" | while read inet address n netmask rest; do | |
99 | if [ "${inet}" = "inet" ]; then | |
100 | echo "${address}/$(_netmask2cidr "${netmask}")" | |
101 | return 0 | |
102 | fi | |
103 | done | |
104 | } | |
105 | ||
106 | _add_address() | |
107 | { | |
108 | local inet6= | |
109 | ||
110 | case "$@" in | |
111 | *:*) inet6=inet6;; | |
112 | esac | |
113 | ||
114 | if [ "${metric:-0}" != "0" ]; then | |
115 | set -- "$@" metric ${metric} | |
116 | fi | |
117 | ||
118 | # ifconfig doesn't like CIDR addresses | |
119 | case "${RC_UNAME}" in | |
120 | OpenBSD) | |
121 | local ip="${1%%/*}" cidr="${1##*/}" netmask= | |
122 | if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then | |
123 | netmask="$(_cidr2netmask "${cidr}")" | |
124 | shift | |
125 | set -- "${ip}" netmask "${netmask}" "$@" | |
126 | fi | |
127 | ;; | |
128 | esac | |
129 | ||
130 | ifconfig "${IFACE}" ${inet6} "$@" alias | |
131 | } | |
132 | ||
133 | _add_route() | |
134 | { | |
135 | if [ $# -gt 3 ]; then | |
136 | if [ "$3" = "gw" -o "$3" = "via" ]; then | |
137 | local one=$1 two=$2 | |
138 | shift; shift; shift | |
139 | set -- "${one}" "${two}" "$@" | |
140 | fi | |
141 | fi | |
142 | ||
143 | case "$@" in | |
144 | *:*) route add -inet6 "$@";; | |
145 | *) route add "$@";; | |
146 | esac | |
147 | } | |
148 | ||
149 | _delete_addresses() | |
150 | { | |
151 | einfo "Removing addresses" | |
152 | eindent | |
153 | LC_ALL=C ifconfig "${IFACE}" | while read inet address ali rest; do | |
154 | case "${inet}" in | |
155 | inet|inet6) | |
156 | if [ "${address}" = "alias" ]; then | |
157 | address="${ali}" | |
158 | fi | |
159 | case "${address}" in | |
160 | *"%${IFACE}"|::1) continue;; | |
161 | 127.0.0.1) [ "${IFACE}" = "lo0" ] && continue;; | |
162 | esac | |
163 | einfo "${address}" | |
164 | ifconfig "${IFACE}" "${inet}" "${address}" -alias | |
165 | eend $? | |
166 | ;; | |
167 | esac | |
168 | done | |
169 | eoutdent | |
170 | return 0 | |
171 | } | |
172 | ||
173 | _show_address() | |
174 | { | |
175 | einfo "received address $(_get_inet_address "${IFACE}")" | |
176 | } | |
177 | ||
178 | _has_carrier() | |
179 | { | |
180 | case "$(_ifconfig_ent "status:")" in | |
181 | ""|active|associated) return 0;; | |
182 | *) return 1;; | |
183 | esac | |
184 | } | |
185 | ||
186 | ifconfig_pre_start() | |
187 | { | |
188 | local config="$(_get_array "ifconfig_${IFVAR}")" conf= arg= args= | |
189 | local IFS="$__IFS" | |
190 | ||
191 | [ -z "${config}" ] && return 0 | |
192 | ||
193 | veinfo "Running ifconfig commands" | |
194 | eindent | |
195 | for conf in ${config}; do | |
196 | unset IFS | |
197 | args= | |
198 | for arg in ${conf}; do | |
199 | case ${arg} in | |
200 | [Dd][Hh][Cc][Pp]);; | |
201 | [Nn][Oo][Aa][Uu][Tt][Oo]);; | |
202 | [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]);; | |
203 | [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]);; | |
204 | [Ww][Pp][Aa]);; | |
205 | *) args="${args} ${arg}";; | |
206 | esac | |
207 | done | |
208 | ||
209 | [ -z "${args}" ] && continue | |
210 | vebegin "ifconfig${args}" | |
211 | eval ifconfig "${IFACE}" "${args}" | |
212 | veend $? | |
213 | done | |
214 | eoutdent | |
215 | ||
216 | return 0 | |
217 | } | |
218 | ||
219 | _ifconfig_ipv6_tentative() | |
220 | { | |
221 | local inet= address= rest= | |
222 | LC_ALL=C ifconfig "${IFACE}" | while read inet address rest; do | |
223 | case "${inet}" in | |
224 | inet6) | |
225 | case "${rest}" in | |
226 | *" "tentative*) return 2;; | |
227 | esac | |
228 | ;; | |
229 | esac | |
230 | done | |
231 | [ $? = 2 ] | |
232 | } | |
233 | ||
234 | ifconfig_post_start() | |
235 | { | |
236 | if _ifconfig_ipv6_tentative; then | |
237 | ebegin "Waiting for IPv6 addresses" | |
238 | while true; do | |
239 | _ifconfig_ipv6_tentative || break | |
240 | done | |
241 | eend 0 | |
242 | fi | |
243 | } | |
244 | ||
245 | # Is the interface administratively/operationally up? | |
246 | # The 'UP' status in ifconfig is the administrative status | |
247 | # Operational state does not seem to be available in BSD? | |
248 | # 0: up | |
249 | # 1: down | |
250 | # 2: invalid arguments | |
251 | is_admin_up() | |
252 | { | |
253 | local iface="$1" | |
254 | [ -z "$iface" ] && iface="$IFACE" | |
255 | ifconfig "${iface}" | \ | |
256 | sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; ' | |
257 | } | |
258 | ||
259 | is_oper_up() | |
260 | { | |
261 | eerror "TODO: is_oper_up not available on BSD" | |
262 | return 2 | |
263 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | ifconfig_depend() | |
4 | { | |
5 | program /sbin/ifconfig /bin/ifconfig | |
6 | provide interface | |
7 | } | |
8 | ||
9 | _up() | |
10 | { | |
11 | ifconfig "${IFACE}" up | |
12 | } | |
13 | ||
14 | _down() | |
15 | { | |
16 | ifconfig "${IFACE}" down | |
17 | } | |
18 | ||
19 | _exists() | |
20 | { | |
21 | [ -e /sys/class/net/"$IFACE" ] | |
22 | } | |
23 | ||
24 | _ifindex() | |
25 | { | |
26 | local index=-1 | |
27 | local f v | |
28 | if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then | |
29 | index=$(cat /sys/class/net/"${IFACE}"/ifindex) | |
30 | else | |
31 | for f in /sys/class/net/*/ifindex ; do | |
32 | v=$(cat $f) | |
33 | [ $v -gt $index ] && index=$v | |
34 | done | |
35 | : $(( index += 1 )) | |
36 | fi | |
37 | echo "${index}" | |
38 | return 0 | |
39 | } | |
40 | ||
41 | _is_wireless() | |
42 | { | |
43 | # Support new sysfs layout | |
44 | [ -d /sys/class/net/"${IFACE}"/wireless -o \ | |
45 | -d /sys/class/net/"${IFACE}"/phy80211 ] && return 0 | |
46 | ||
47 | [ ! -e /proc/net/wireless ] && return 1 | |
48 | grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless | |
49 | } | |
50 | ||
51 | _set_flag() | |
52 | { | |
53 | ifconfig "${IFACE}" "$1" | |
54 | } | |
55 | ||
56 | _get_mac_address() | |
57 | { | |
58 | local mac=$(LC_ALL=C ifconfig "${IFACE}" | \ | |
59 | sed -n -e 's/.* \(HWaddr\|ether\) \(..:..:..:..:..:..\).*/\2/p') | |
60 | ||
61 | case "${mac}" in | |
62 | 00:00:00:00:00:00);; | |
63 | 44:44:44:44:44:44);; | |
64 | FF:FF:FF:FF:FF:FF);; | |
65 | "");; | |
66 | *) echo "${mac}"; return 0;; | |
67 | esac | |
68 | ||
69 | return 1 | |
70 | } | |
71 | ||
72 | _set_mac_address() | |
73 | { | |
74 | ifconfig "${IFACE}" hw ether "$1" | |
75 | } | |
76 | ||
77 | _get_inet_address() | |
78 | { | |
79 | set -- $(LC_ALL=C ifconfig "${IFACE}" | | |
80 | sed -n -e 's/.*\(inet addr:\|inet \)\([^ ]*\).*\(Mask:\|netmask \)\([^ ]*\).*/\2 \4/p') | |
81 | [ -z "$1" ] && return 1 | |
82 | ||
83 | echo -n "$1" | |
84 | shift | |
85 | echo "/$(_netmask2cidr "$1")" | |
86 | } | |
87 | ||
88 | _get_inet_addresses() | |
89 | { | |
90 | local iface=${IFACE} i=0 | |
91 | local addrs="$(_get_inet_address)" | |
92 | ||
93 | while true; do | |
94 | local IFACE="${iface}:${i}" | |
95 | _exists || break | |
96 | local addr="$(_get_inet_address)" | |
97 | [ -n "${addr}" ] && addrs="${addrs}${addrs:+ }${addr}" | |
98 | : $(( i += 1 )) | |
99 | done | |
100 | echo "${addrs}" | |
101 | } | |
102 | ||
103 | _cidr2netmask() | |
104 | { | |
105 | local cidr="$1" netmask="" done=0 i=0 sum=0 cur=128 | |
106 | local octets= frac= | |
107 | ||
108 | local octets=$(( cidr / 8 )) | |
109 | local frac=$(( cidr % 8 )) | |
110 | while [ ${octets} -gt 0 ]; do | |
111 | netmask="${netmask}.255" | |
112 | : $(( octets -= 1 )) | |
113 | : $(( done += 1 )) | |
114 | done | |
115 | ||
116 | if [ ${done} -lt 4 ]; then | |
117 | while [ ${i} -lt ${frac} ]; do | |
118 | : $(( sum += cur )) | |
119 | : $(( cur /= 2 )) | |
120 | : $(( i += 1 )) | |
121 | done | |
122 | netmask="${netmask}.${sum}" | |
123 | : $(( done += 1 )) | |
124 | ||
125 | while [ ${done} -lt 4 ]; do | |
126 | netmask="${netmask}.0" | |
127 | : $(( done += 1 )) | |
128 | done | |
129 | fi | |
130 | ||
131 | echo "${netmask#.*}" | |
132 | } | |
133 | ||
134 | _add_address() | |
135 | { | |
136 | if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then | |
137 | ifconfig "${IFACE}" "$@" 2>/dev/null | |
138 | return 0 | |
139 | fi | |
140 | ||
141 | case "$1" in | |
142 | *:*) ifconfig "${IFACE}" inet6 add "$@"; return $?;; | |
143 | esac | |
144 | ||
145 | # IPv4 is tricky - ifconfig requires an aliased device | |
146 | # for multiple addresses | |
147 | local iface="${IFACE}" | |
148 | if LC_ALL=C ifconfig "${iface}" | grep -Eq '\<inet (addr:)?.*'; then | |
149 | # Get the last alias made for the interface and add 1 to it | |
150 | i=$(ifconfig | sed '1!G;h;$!d' | grep -m 1 -o "^${iface}:[0-9]*" \ | |
151 | | sed -n -e 's/'"${iface}"'://p') | |
152 | : $(( i = ${i:-0} + 1 )) | |
153 | iface="${iface}:${i}" | |
154 | fi | |
155 | ||
156 | # ifconfig doesn't like CIDR addresses | |
157 | local ip="${1%%/*}" cidr="${1##*/}" netmask= | |
158 | if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then | |
159 | netmask="$(_cidr2netmask "${cidr}")" | |
160 | shift | |
161 | set -- "${ip}" netmask "${netmask}" "$@" | |
162 | fi | |
163 | ||
164 | local arg= cmd= | |
165 | while [ -n "$1" ]; do | |
166 | case "$1" in | |
167 | brd) | |
168 | if [ "$2" = "+" ]; then | |
169 | shift | |
170 | else | |
171 | cmd="${cmd} broadcast" | |
172 | fi | |
173 | ;; | |
174 | peer) cmd="${cmd} pointopoint";; | |
175 | *) cmd="${cmd} $1";; | |
176 | esac | |
177 | shift | |
178 | done | |
179 | ||
180 | ifconfig "${iface}" ${cmd} | |
181 | } | |
182 | ||
183 | _add_route() | |
184 | { | |
185 | local inet6= family= | |
186 | ||
187 | if [ "$1" = "-A" -o "$1" = "-f" -o "$1" = "-family" ]; then | |
188 | family="-A $2" | |
189 | shift; shift | |
190 | elif [ "$1" = "-4" ]; then | |
191 | family="-A inet" | |
192 | shift | |
193 | elif [ "$1" = "-6" ]; then | |
194 | family="-A inet6" | |
195 | shift | |
196 | fi | |
197 | ||
198 | if [ -n "${metric}" ]; then | |
199 | set -- "$@" metric ${metric} | |
200 | fi | |
201 | ||
202 | if [ $# -eq 3 ]; then | |
203 | set -- "$1" "$2" gw "$3" | |
204 | elif [ "$3" = "via" ]; then | |
205 | local one=$1 two=$2 | |
206 | shift; shift; shift | |
207 | set -- "${one}" "${two}" gw "$@" | |
208 | fi | |
209 | ||
210 | case "$@" in | |
211 | *:*) [ "$1" = "-net" ] && shift;; | |
212 | esac | |
213 | ||
214 | route ${family} add "$@" dev "${IFACE}" | |
215 | } | |
216 | ||
217 | _delete_addresses() | |
218 | { | |
219 | # We don't remove addresses from aliases | |
220 | case "${IFACE}" in | |
221 | *:*) return 0;; | |
222 | esac | |
223 | ||
224 | einfo "Removing addresses" | |
225 | eindent | |
226 | # iproute2 can add many addresses to an iface unlike ifconfig ... | |
227 | # iproute2 added addresses cause problems for ifconfig | |
228 | # as we delete an address, a new one appears, so we have to | |
229 | # keep polling | |
230 | while true; do | |
231 | local addr=$(_get_inet_address) | |
232 | [ -z "${addr}" ] && break | |
233 | ||
234 | if [ "${addr}" = "127.0.0.1/8" ]; then | |
235 | # Don't delete the loopback address | |
236 | [ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] && break | |
237 | fi | |
238 | einfo "${addr}" | |
239 | ifconfig "${IFACE}" 0.0.0.0 || break | |
240 | done | |
241 | ||
242 | # Remove IPv6 addresses | |
243 | local addr= | |
244 | for addr in $(LC_ALL=C ifconfig "${IFACE}" | \ | |
245 | sed -n -e 's/^.*\(inet6 addr:\|inet6\) \([^ ]*\) .*\(Scope:[^L]\|scopeid [^<]*<[^l]\).*/\2/p'); do | |
246 | if [ "${IFACE}" = "lo" ]; then | |
247 | case "${addr}" in | |
248 | "::1/128"|"/128") continue;; | |
249 | esac | |
250 | fi | |
251 | einfo "${addr}" | |
252 | ifconfig "${IFACE}" inet6 del "${addr}" | |
253 | done | |
254 | ||
255 | return 0 | |
256 | } | |
257 | ||
258 | _has_carrier() | |
259 | { | |
260 | return 0 | |
261 | } | |
262 | ||
263 | _tunnel() | |
264 | { | |
265 | iptunnel "$@" | |
266 | } | |
267 | ||
268 | ifconfig_pre_start() | |
269 | { | |
270 | local tunnel= | |
271 | eval tunnel=\$iptunnel_${IFVAR} | |
272 | if [ -n "${tunnel}" ]; then | |
273 | # Set our base metric to 1000 | |
274 | metric=1000 | |
275 | ebegin "Creating tunnel ${IFVAR}" | |
276 | iptunnel add ${tunnel} | |
277 | eend $? || return 1 | |
278 | _up | |
279 | fi | |
280 | ||
281 | # MTU support | |
282 | local mtu= | |
283 | eval mtu=\$mtu_${IFVAR} | |
284 | [ -n "${mtu}" ] && ifconfig "${IFACE}" mtu "${mtu}" | |
285 | ||
286 | # TX Queue Length support | |
287 | local len= | |
288 | eval len=\$txqueuelen_${IFVAR} | |
289 | [ -n "${len}" ] && ifconfig "${IFACE}" txqueuelen "${len}" | |
290 | ||
291 | return 0 | |
292 | } | |
293 | ||
294 | ifconfig_post_stop() | |
295 | { | |
296 | # Don't delete sit0 as it's a special tunnel | |
297 | [ "${IFACE}" = "sit0" ] && return 0 | |
298 | ||
299 | [ -z "$(iptunnel show "${IFACE}" 2>/dev/null)" ] && return 0 | |
300 | ||
301 | ebegin "Destroying tunnel ${IFACE}" | |
302 | iptunnel del "${IFACE}" | |
303 | eend $? | |
304 | } | |
305 | ||
306 | # Is the interface administratively/operationally up? | |
307 | # The 'UP' status in ifconfig/iproute2 is the administrative status | |
308 | # Operational state is available in iproute2 output as 'state UP', or the | |
309 | # operstate sysfs variable. | |
310 | # 0: up | |
311 | # 1: down | |
312 | # 2: invalid arguments | |
313 | is_admin_up() | |
314 | { | |
315 | local iface="$1" | |
316 | [ -z "$iface" ] && iface="$IFACE" | |
317 | ifconfig "${iface}" | \ | |
318 | sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; ' | |
319 | } | |
320 | ||
321 | is_oper_up() | |
322 | { | |
323 | local iface="$1" | |
324 | [ -z "$iface" ] && iface="$IFACE" | |
325 | read state </sys/class/net/"${iface}"/operstate | |
326 | [ "x$state" = "up" ] | |
327 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars plug_timeout" | |
4 | ||
5 | ifplugd_depend() | |
6 | { | |
7 | program start /usr/sbin/ifplugd | |
8 | after macnet rename | |
9 | before interface | |
10 | provide plug | |
11 | } | |
12 | ||
13 | ifplugd_pre_start() | |
14 | { | |
15 | local pidfile="/var/run/ifplugd.${IFACE}.pid" timeout= args= | |
16 | ||
17 | # We don't start ifplugd if we're being called from the background | |
18 | yesno ${IN_BACKGROUND} && return 0 | |
19 | ||
20 | _exists || return 0 | |
21 | ||
22 | # We need a valid MAC address | |
23 | # It's a basic test to ensure it's not a virtual interface | |
24 | if ! _get_mac_address >/dev/null 2>&1; then | |
25 | vewarn "ifplugd only works on interfaces with a valid MAC address" | |
26 | return 0 | |
27 | fi | |
28 | ||
29 | # We don't work on bonded, bridges, tun/tap, vlan or wireless | |
30 | for f in bond bridge tuntap vlan wireless; do | |
31 | if type "_is_${f}" >/dev/null 2>&1; then | |
32 | if _is_${f}; then | |
33 | veinfo "ifplugd does not work with ${f}" | |
34 | return 0 | |
35 | fi | |
36 | fi | |
37 | done | |
38 | ||
39 | ebegin "Starting ifplugd on ${IFACE}" | |
40 | ||
41 | eval args=\$ifplugd_${IFVAR} | |
42 | ||
43 | # Mark the us as inactive so netplug can restart us | |
44 | mark_service_inactive | |
45 | ||
46 | # Start ifplugd | |
47 | eval start-stop-daemon --start --exec /usr/sbin/ifplugd \ | |
48 | --pidfile "${pidfile}" -- "${args}" --iface="${IFACE}" | |
49 | eend $? || return 1 | |
50 | ||
51 | eindent | |
52 | ||
53 | # IFACE-specific, then global, then default | |
54 | eval timeout=\$plug_timeout_${IFVAR} | |
55 | [ -z "${timeout}" ] && timeout=$plug_timeout | |
56 | [ -z "${timeout}" ] && timeout=-1 | |
57 | if [ ${timeout} -eq 0 ]; then | |
58 | ewarn "WARNING: infinite timeout set for ${IFACE} to come up" | |
59 | elif [ ${timeout} -lt 0 ]; then | |
60 | einfo "Backgrounding ..." | |
61 | exit 1 | |
62 | fi | |
63 | ||
64 | veinfo "Waiting for ${IFACE} to be marked as started" | |
65 | ||
66 | local i=0 | |
67 | while true; do | |
68 | if service_started; then | |
69 | _show_address | |
70 | exit 0 | |
71 | fi | |
72 | sleep 1 | |
73 | [ ${timeout} -eq 0 ] && continue | |
74 | : $(( i += 1 )) | |
75 | [ ${i} -ge ${timeout} ] && break | |
76 | done | |
77 | ||
78 | eend 1 "Failed to configure ${IFACE} in the background" | |
79 | exit 1 | |
80 | } | |
81 | ||
82 | ifplugd_stop() | |
83 | { | |
84 | yesno ${IN_BACKGROUND} && return 0 | |
85 | ||
86 | local pidfile="/var/run/ifplugd.${IFACE}.pid" | |
87 | [ ! -e "${pidfile}" ] && return 0 | |
88 | ||
89 | ebegin "Stopping ifplugd on ${IFACE}" | |
90 | start-stop-daemon --stop --quiet --exec /usr/sbin/ifplugd \ | |
91 | --pidfile "${pidfile}" --signal QUIT | |
92 | eend $? | |
93 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars plug_timeout" | |
4 | ||
5 | ifwatchd_depend() | |
6 | { | |
7 | program start /usr/sbin/ifwatchd | |
8 | after macnet rename wireless | |
9 | before interface | |
10 | provide plug | |
11 | } | |
12 | ||
13 | ifwatchd_pre_start() | |
14 | { | |
15 | # We don't start ifwatchd if we're being called from the background | |
16 | yesno ${IN_BACKGROUND} && return 0 | |
17 | ||
18 | _exists || return 0 | |
19 | ||
20 | # We need a valid MAC address | |
21 | # It's a basic test to ensure it's not a virtual interface | |
22 | if ! _get_mac_address >/dev/null 2>&1; then | |
23 | vewarn "ifwatchd only works on interfaces with a valid MAC address" | |
24 | return 0 | |
25 | fi | |
26 | ||
27 | ebegin "Starting ifwatchd on ${IFACE}" | |
28 | ||
29 | # Mark the us as inactive so ifwatchd can restart us | |
30 | mark_service_inactive | |
31 | ||
32 | # Start ifwatchd | |
33 | export IN_BACKGROUND=yes | |
34 | start-stop-daemon --start --exec /usr/sbin/ifwatchd \ | |
35 | -- -c "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \ | |
36 | -n "${RC_LIBEXECDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" | |
37 | unset IN_BACKGROUND | |
38 | eend "$?" || return 1 | |
39 | ||
40 | einfo "Backgrounding ..." | |
41 | exit 1 | |
42 | } | |
43 | ||
44 | ifwatchd_stop() | |
45 | { | |
46 | yesno ${IN_BACKGROUND} && return 0 | |
47 | ||
48 | start-stop-daemon --test --quiet --stop --exec /usr/sbin/ifwatchd \ | |
49 | -- -c "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \ | |
50 | -n "${RC_LIBEXECDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" \ | |
51 | || return 0 | |
52 | ||
53 | ebegin "Stopping ifwatchd on" "${IFACE}" | |
54 | start-stop-daemon --stop --exec /usr/sbin/ifwatchd \ | |
55 | -- -c "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \ | |
56 | -n "${RC_LIBEXECDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" | |
57 | eend $? | |
58 | } |
0 | # Copyright (c) 2011 by Gentoo Foundation | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars link prefix suffix ipv4mask relay" | |
4 | ||
5 | ip6rd_depend() | |
6 | { | |
7 | program ip | |
8 | after interface | |
9 | } | |
10 | ||
11 | ip6rd_pre_start() | |
12 | { | |
13 | # ALL interfaces run pre_start blocks, not just those with something | |
14 | # assigned, so we must check if we need to run on this interface before we | |
15 | # do so. | |
16 | local config | |
17 | eval config=\$config_${IFVAR} | |
18 | [ "$config" = "ip6rd" ] || return 0 | |
19 | ||
20 | case "${MODULES}" in | |
21 | *" ifconfig "*) | |
22 | eerror "ifconfig is not supported for 6rd" | |
23 | eerror "Please emerge sys-apps/iproute2" | |
24 | return 1 | |
25 | ;; | |
26 | esac | |
27 | ||
28 | local host= suffix= relay= addr= iface=${IFACE} config_ip6rd= localip= ipv4mask= | |
29 | eval host=\$link_${IFVAR} | |
30 | if [ -z "${host}" ]; then | |
31 | eerror "link_${IFVAR} not set" | |
32 | return 1 | |
33 | fi | |
34 | ||
35 | eval host=\${link_${IFVAR}} | |
36 | eval ipv4mask=\${ipv4mask_${IFVAR}:-0} | |
37 | eval suffix=\${suffix_${IFVAR}:-1} | |
38 | eval relay=\${relay_${IFVAR}} | |
39 | eval prefix=\${prefix_${IFVAR}} | |
40 | ||
41 | IFACE=${host} | |
42 | addrs=$(_get_inet_addresses) | |
43 | IFACE=${iface} | |
44 | if [ -z "${addrs}" ]; then | |
45 | eerror "${host} is not configured with an IPv4 address" | |
46 | return 1 | |
47 | fi | |
48 | # TODO: Get this settings from DHCP (Option 212) | |
49 | if [ -z "${prefix}" ]; then | |
50 | eerror "prefix_${IFVAR} not set" | |
51 | return 1 | |
52 | fi | |
53 | if [ -z "${relay}" ]; then | |
54 | eerror "relay_${IFVAR} not set" | |
55 | return 1 | |
56 | fi | |
57 | for addr in ${addrs}; do | |
58 | # Strip the subnet | |
59 | local ip="${addr%/*}" subnet="${addr#*/}" | |
60 | # We don't work on private IPv4 addresses | |
61 | if _ip6rd_inet_is_private_network "${ip}" | |
62 | then | |
63 | continue | |
64 | fi | |
65 | ||
66 | local ip6= ip6_prefix="${prefix%::/*}" ip6_subnet="${prefix#*/}" | |
67 | ip6_subnet=$((ip6_subnet + (32-ipv4mask))) | |
68 | eval ip6="$(printf "${ip6_prefix}:%s::%s" \ | |
69 | $(_ip6rd_prefix_shave_bits ${ip} ${ipv4mask}) ${suffix})" | |
70 | veinfo "Derived IPv6 address: ${ip6}" | |
71 | ||
72 | # Now apply our IPv6 address to our config | |
73 | config_ip6rd="${config_ip6rd}${config_ip6rd:+ }${ip6}/${ip6_subnet}" | |
74 | ||
75 | if [ -n "${localip}" ]; then | |
76 | localip="any" | |
77 | else | |
78 | localip="${ip}" | |
79 | fi | |
80 | done | |
81 | ||
82 | if [ -z "${config_ip6rd}" ]; then | |
83 | eerror "No global IPv4 addresses found on interface ${host}" | |
84 | return 1 | |
85 | fi | |
86 | ||
87 | ebegin "Creating 6rd tunnel ${IFACE}" | |
88 | if [ "${IFACE}" != "sit0" ]; then | |
89 | _tunnel add "${IFACE}" mode sit ttl 255 remote any local "${localip}" | |
90 | fi | |
91 | _tunnel 6rd dev "${IFACE}" 6rd-prefix "${prefix}" | |
92 | eend $? || return 1 | |
93 | _up | |
94 | ||
95 | routes_ip6rd="2003::/3 via ::${relay} metric 2147483647" | |
96 | service_set_value "config_ip6rd_$IFVAR" "$config_ip6rd" | |
97 | service_set_value "routes_ip6rd_$IFVAR" "$routes_ip6rd" | |
98 | } | |
99 | ||
100 | ip6rd_start() | |
101 | { | |
102 | local config_ip6rd=$(service_get_value "config_ip6rd_$IFVAR") | |
103 | local routes_ip6rd=$(service_get_value "routes_ip6rd_$IFVAR") | |
104 | ||
105 | # Now apply our config | |
106 | eval config_${config_index}=\'"${config_ip6rd}"\' | |
107 | : $(( config_index -= 1 )) | |
108 | ||
109 | # Add a route for us, ensuring we don't delete anything else | |
110 | local routes="$(_get_array "routes_${IFVAR}") | |
111 | $routes_ip6rd" | |
112 | eval routes_${IFVAR}=\$routes | |
113 | } | |
114 | ||
115 | _ip6rd_inet_atoi() | |
116 | { | |
117 | local IFS="${IFS}." ipi=0 j=3 | |
118 | for i in $1 ; do | |
119 | ipi=$(( ipi | i << 8*j-- )) | |
120 | done | |
121 | echo ${ipi} | |
122 | } | |
123 | ||
124 | _ip6rd_inet_itoa() | |
125 | { | |
126 | local ipi=$1 | |
127 | for i in 0 1 2 3; do | |
128 | if [ $i != 3 ] ; then | |
129 | printf "%d." $(( (ipi & ~((1<<24)-1)) >> 24 )) | |
130 | ipi=$(( (ipi & ((1<<24)-1)) << 8)) | |
131 | else | |
132 | printf "%d\n" $(( (ipi & ~((1<<24)-1)) >> 24 )) | |
133 | fi | |
134 | done | |
135 | } | |
136 | ||
137 | _ip6rd_inet_get_network() | |
138 | { | |
139 | echo $(_ip6rd_inet_itoa $(( ($(_ip6rd_inet_atoi $1) & ((1<<$2)-1) << (32-$2) ) )) ) | |
140 | } | |
141 | ||
142 | _ip6rd_inet_is_private_network() | |
143 | { | |
144 | if [ "$(_ip6rd_inet_get_network $1 16)" = "192.168.0.0" ]\ | |
145 | || [ "$(_ip6rd_inet_get_network $1 8)" = "10.0.0.0" ]\ | |
146 | || [ "$(_ip6rd_inet_get_network $1 12)" = "172.16.0.0" ]\ | |
147 | || [ "$(_ip6rd_inet_get_network $1 16)" = "169.254.0.0" ] | |
148 | then | |
149 | return 0; | |
150 | fi | |
151 | return 1; | |
152 | } | |
153 | ||
154 | _ip6rd_prefix_shave_bits() | |
155 | { | |
156 | local ipi= | |
157 | ipi=$(( ($(_ip6rd_inet_atoi $1) & (1<<(32-$2))-1) << $2)) | |
158 | if [ $2 -le 16 ] | |
159 | then | |
160 | printf "%04x:%0$(( (16-$2>>2)+(($2%4)?1:0) ))x" \ | |
161 | $((ipi >> 16)) $((ipi & (1<<(16-$2))-1)) | |
162 | elif [ $2 -lt 32 ] | |
163 | then | |
164 | printf "%0$(( (32-$2>>2)+(($2%4)?1:0) ))x" \ | |
165 | $((ipi >> 16)) | |
166 | fi | |
167 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars link suffix relay" | |
4 | ||
5 | ip6to4_depend() | |
6 | { | |
7 | after interface | |
8 | program ip | |
9 | } | |
10 | ||
11 | ip6to4_pre_start() | |
12 | { | |
13 | # ALL interfaces run pre_start blocks, not just those with something | |
14 | # assigned, so we must check if we need to run on this interface before we | |
15 | # do so. | |
16 | local config | |
17 | eval config=\$config_${IFVAR} | |
18 | [ "$config" = "ip6to4" ] || return 0 | |
19 | ||
20 | case " ${MODULES} " in | |
21 | *" ifconfig "*) | |
22 | if [ "${IFACE}" != "sit0" ]; then | |
23 | eerror "ip6to4 can only work on the sit0 interface using ifconfig" | |
24 | eerror "emerge sys-apps/iproute2 to use other interfaces" | |
25 | return 1 | |
26 | fi | |
27 | esac | |
28 | ||
29 | local host= suffix= relay= addr= iface=${IFACE} config_ip6to4= localip= | |
30 | eval host=\$link_${IFVAR} | |
31 | if [ -z "${host}" ]; then | |
32 | eerror "link_${IFVAR} not set" | |
33 | return 1 | |
34 | fi | |
35 | ||
36 | eval suffix=\${suffix_${IFVAR}:-1} | |
37 | eval relay=\${relay_${IFVAR}:-192.88.99.1} | |
38 | ||
39 | IFACE=${host} | |
40 | addrs=$(_get_inet_addresses) | |
41 | IFACE=${iface} | |
42 | if [ -z "${addrs}" ]; then | |
43 | eerror "${host} is not configured with an IPv4 address" | |
44 | return 1 | |
45 | fi | |
46 | ||
47 | for addr in ${addrs}; do | |
48 | # Strip the subnet | |
49 | local ip="${addr%/*}" subnet="${addr#*/}" | |
50 | # We don't work on private IPv4 addresses | |
51 | case "${ip}" in | |
52 | 127.*) continue;; | |
53 | 10.*) continue;; | |
54 | 192.168.*) continue;; | |
55 | 172.*) | |
56 | local i=16 | |
57 | while [ ${i} -lt 32 ]; do | |
58 | case "${ip}" in | |
59 | 172.${i}.*) break;; | |
60 | esac | |
61 | : $(( i += 1 )) | |
62 | done | |
63 | [ ${i} -lt 32 ] && continue | |
64 | ;; | |
65 | esac | |
66 | ||
67 | veinfo "IPv4 address on ${host}: ${ip}/${subnet}" | |
68 | local ipa= ip6= IFS="${IFS}." | |
69 | for i in ${ip}; do | |
70 | ipa="${ipa} ${i}" | |
71 | done | |
72 | unset IFS | |
73 | eval ip6="$(printf "2002:%02x%02x:%02x%02x::%s" ${ipa} ${suffix})" | |
74 | veinfo "Derived IPv6 address: ${ip6}" | |
75 | ||
76 | # Now apply our IPv6 address to our config | |
77 | config_ip6to4="${config_ip6to4}${config_ip6to4:+ }${ip6}/48" | |
78 | ||
79 | if [ -n "${localip}" ]; then | |
80 | localip="any" | |
81 | else | |
82 | localip="${ip}" | |
83 | fi | |
84 | done | |
85 | ||
86 | if [ -z "${config_ip6to4}" ]; then | |
87 | eerror "No global IPv4 addresses found on interface ${host}" | |
88 | return 1 | |
89 | fi | |
90 | ||
91 | if [ "${IFACE}" != "sit0" ]; then | |
92 | ebegin "Creating 6to4 tunnel on ${IFACE}" | |
93 | _tunnel add "${IFACE}" mode sit ttl 255 remote any local "${localip}" | |
94 | eend $? || return 1 | |
95 | _up | |
96 | fi | |
97 | routes_ip6to4="2003::/3 via ::${relay} metric 2147483647" | |
98 | service_set_value "config_ip6to4_$IFVAR" "$config_ip6to4" | |
99 | service_set_value "routes_ip6to4_$IFVAR" "$routes_ip6to4" | |
100 | } | |
101 | ||
102 | ip6to4_start() | |
103 | { | |
104 | local config_ip6to4=$(service_get_value "config_ip6to4_$IFVAR") | |
105 | local routes_ip6to4=$(service_get_value "routes_ip6to4_$IFVAR") | |
106 | ||
107 | # Now apply our config | |
108 | eval config_${config_index}=\'"${config_ip6to4}"\' | |
109 | : $(( config_index -= 1 )) | |
110 | ||
111 | # Add a route for us, ensuring we don't delete anything else | |
112 | local routes="$(_get_array "routes_${IFVAR}") | |
113 | $routes_ip6to4" | |
114 | eval routes_${IFVAR}=\$routes | |
115 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | ipppd_depend() | |
4 | { | |
5 | program start /usr/sbin/ipppd | |
6 | after macnet | |
7 | before interface | |
8 | provide isdn | |
9 | } | |
10 | ||
11 | _config_vars="$_config_vars ipppd" | |
12 | ||
13 | ipppd_pre_start() | |
14 | { | |
15 | local opts= pidfile="/var/run/ipppd-${IFACE}.pid" | |
16 | ||
17 | # Check that we are a valid ippp interface | |
18 | case "${IFACE}" in | |
19 | ippp[0-9]*);; | |
20 | *) return 0;; | |
21 | esac | |
22 | ||
23 | # Check that the interface exists | |
24 | _exists || return 1 | |
25 | ||
26 | # Might or might not be set in conf.d/net | |
27 | eval opts=\$ipppd_${IFVAR} | |
28 | ||
29 | einfo "Starting ipppd for ${IFACE}" | |
30 | start-stop-daemon --start --exec /usr/sbin/ipppd \ | |
31 | --pidfile "${pidfile}" \ | |
32 | -- ${opts} pidfile "${pidfile}" \ | |
33 | file "/etc/ppp/options.${IFACE}" >/dev/null | |
34 | eend $? | |
35 | } | |
36 | ||
37 | ipppd_post_stop() | |
38 | { | |
39 | local pidfile="/var/run/ipppd-${IFACE}.pid" | |
40 | ||
41 | [ ! -f "${pidfile}" ] && return 0 | |
42 | ||
43 | einfo "Stopping ipppd for ${IFACE}" | |
44 | start-stop-daemon --stop --quiet --exec /usr/sbin/ipppd \ | |
45 | --pidfile "${pidfile}" | |
46 | eend $? | |
47 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | iproute2_depend() | |
4 | { | |
5 | program ip | |
6 | provide interface | |
7 | after ifconfig | |
8 | } | |
9 | ||
10 | _up() | |
11 | { | |
12 | ip link set dev "${IFACE}" up | |
13 | } | |
14 | ||
15 | _down() | |
16 | { | |
17 | ip link set dev "${IFACE}" down | |
18 | } | |
19 | ||
20 | _exists() | |
21 | { | |
22 | [ -e /sys/class/net/"$IFACE" ] | |
23 | } | |
24 | ||
25 | _ifindex() | |
26 | { | |
27 | local index=-1 | |
28 | local f v | |
29 | if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then | |
30 | index=$(cat /sys/class/net/"${IFACE}"/ifindex) | |
31 | else | |
32 | for f in /sys/class/net/*/ifindex ; do | |
33 | v=$(cat $f) | |
34 | [ $v -gt $index ] && index=$v | |
35 | done | |
36 | : $(( index += 1 )) | |
37 | fi | |
38 | echo "${index}" | |
39 | return 0 | |
40 | } | |
41 | ||
42 | _is_wireless() | |
43 | { | |
44 | # Support new sysfs layout | |
45 | [ -d /sys/class/net/"${IFACE}"/wireless -o \ | |
46 | -d /sys/class/net/"${IFACE}"/phy80211 ] && return 0 | |
47 | ||
48 | [ ! -e /proc/net/wireless ] && return 1 | |
49 | grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless | |
50 | } | |
51 | ||
52 | _set_flag() | |
53 | { | |
54 | local flag=$1 opt="on" | |
55 | if [ "${flag#-}" != "${flag}" ]; then | |
56 | flag=${flag#-} | |
57 | opt="off" | |
58 | fi | |
59 | ip link set dev "${IFACE}" "${flag}" "${opt}" | |
60 | } | |
61 | ||
62 | _get_mac_address() | |
63 | { | |
64 | local mac=$(LC_ALL=C ip link show "${IFACE}" | sed -n \ | |
65 | -e 'y/abcdef/ABCDEF/' \ | |
66 | -e '/link\// s/^.*\<\(..:..:..:..:..:..\)\>.*/\1/p') | |
67 | ||
68 | case "${mac}" in | |
69 | 00:00:00:00:00:00);; | |
70 | 44:44:44:44:44:44);; | |
71 | FF:FF:FF:FF:FF:FF);; | |
72 | "");; | |
73 | *) echo "${mac}"; return 0;; | |
74 | esac | |
75 | ||
76 | return 1 | |
77 | } | |
78 | ||
79 | _set_mac_address() | |
80 | { | |
81 | ip link set dev "${IFACE}" address "$1" | |
82 | } | |
83 | ||
84 | _get_inet_addresses() | |
85 | { | |
86 | LC_ALL=C ip -family inet addr show "${IFACE}" | \ | |
87 | sed -n -e 's/.*inet \([^ ]*\).*/\1/p' | |
88 | } | |
89 | ||
90 | _get_inet_address() | |
91 | { | |
92 | set -- $(_get_inet_addresses) | |
93 | [ $# = "0" ] && return 1 | |
94 | echo "$1" | |
95 | } | |
96 | ||
97 | _add_address() | |
98 | { | |
99 | if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then | |
100 | ip addr add "$@" dev "${IFACE}" 2>/dev/null | |
101 | return 0 | |
102 | fi | |
103 | local x | |
104 | local address netmask broadcast peer anycast label scope | |
105 | local valid_lft preferred_lft home nodad | |
106 | local confflaglist | |
107 | address="$1" ; shift | |
108 | while [ -n "$*" ]; do | |
109 | x=$1 ; shift | |
110 | case "$x" in | |
111 | netmask|ne*) | |
112 | netmask="/$(_netmask2cidr "$1")" ; shift ;; | |
113 | broadcast|brd|br*) | |
114 | broadcast="$1" ; shift ;; | |
115 | pointopoint|pointtopoint|peer|po*|pe*) | |
116 | peer="$1" ; shift ;; | |
117 | anycast|label|scope|valid_lft|preferred_lft|a*|l*|s*|v*|pr*) | |
118 | case $x in | |
119 | a*) x=anycast ;; | |
120 | l*) x=label ;; | |
121 | s*) x=scope ;; | |
122 | v*) x=valid_lft ;; | |
123 | pr*) x=preferred_lft ;; | |
124 | esac | |
125 | eval "$x=$1" ; shift ;; | |
126 | home|nodad|h*|no*) | |
127 | case $x in h*) x=home ;; n*) x=nodad ;; esac | |
128 | # FIXME: If we need to reorder these, this will take more code | |
129 | confflaglist="${confflaglist} $x" ; ;; | |
130 | *) | |
131 | ewarn "Unknown argument to config_$IFACE: $x" | |
132 | esac | |
133 | done | |
134 | ||
135 | # Always scope lo addresses as host unless specified otherwise | |
136 | if [ "${IFACE}" = "lo" ]; then | |
137 | [ -z "$scope" ] && scope="host" | |
138 | fi | |
139 | ||
140 | # figure out the broadcast address if it is not specified | |
141 | # This must NOT be set for IPv6 addresses | |
142 | if [ "${address#*:}" = "${address}" ]; then | |
143 | [ -z "$broadcast" ] && broadcast="+" | |
144 | elif [ -n "$broadcast" ]; then | |
145 | eerror "Broadcast keywords are not valid with IPv6 addresses" | |
146 | return 1 | |
147 | fi | |
148 | ||
149 | # This must appear on a single line, continuations cannot be used | |
150 | set -- "${address}${netmask}" ${peer:+peer} ${peer} ${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} ${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" ${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} $preferred_lft $confflaglist | |
151 | veinfo ip addr add "$@" | |
152 | ip addr add "$@" | |
153 | } | |
154 | ||
155 | _add_route() | |
156 | { | |
157 | local family= | |
158 | ||
159 | if [ "$1" = "-A" -o "$1" = "-f" -o "$1" = "-family" ]; then | |
160 | family="-f $2" | |
161 | shift; shift | |
162 | elif [ "$1" = "-4" ]; then | |
163 | family="-f inet" | |
164 | shift | |
165 | elif [ "$1" = "-6" ]; then | |
166 | family="-f inet6" | |
167 | shift | |
168 | fi | |
169 | ||
170 | if [ $# -eq 3 ]; then | |
171 | set -- "$1" "$2" via "$3" | |
172 | elif [ "$3" = "gw" ]; then | |
173 | local one=$1 two=$2 | |
174 | shift; shift; shift | |
175 | set -- "${one}" "${two}" via "$@" | |
176 | fi | |
177 | ||
178 | local cmd= have_metric=false | |
179 | while [ -n "$1" ]; do | |
180 | case "$1" in | |
181 | metric) cmd="${cmd} $1"; have_metric=true;; | |
182 | netmask) cmd="${cmd}/$(_netmask2cidr "$2")"; shift;; | |
183 | -host|-net);; | |
184 | *) cmd="${cmd} $1";; | |
185 | esac | |
186 | shift | |
187 | done | |
188 | ||
189 | # We cannot use a metric if we're using a nexthop | |
190 | if ! ${have_metric} && \ | |
191 | [ -n "${metric}" -a \ | |
192 | "${cmd##* nexthop }" = "$cmd" ] | |
193 | then | |
194 | cmd="${cmd} metric ${metric}" | |
195 | fi | |
196 | ||
197 | veinfo ip ${family} route append ${cmd} dev "${IFACE}" | |
198 | ip ${family} route append ${cmd} dev "${IFACE}" | |
199 | eend $? | |
200 | } | |
201 | ||
202 | _delete_addresses() | |
203 | { | |
204 | ip addr flush dev "${IFACE}" scope global 2>/dev/null | |
205 | ip addr flush dev "${IFACE}" scope site 2>/dev/null | |
206 | if [ "${IFACE}" != "lo" ]; then | |
207 | ip addr flush dev "${IFACE}" scope host 2>/dev/null | |
208 | fi | |
209 | return 0 | |
210 | } | |
211 | ||
212 | _has_carrier() | |
213 | { | |
214 | LC_ALL=C ip link show dev "${IFACE}" | grep -q "LOWER_UP" | |
215 | } | |
216 | ||
217 | _tunnel() | |
218 | { | |
219 | ip tunnel "$@" | |
220 | } | |
221 | ||
222 | # This is just to trim whitespace, do not add any quoting! | |
223 | _trim() { | |
224 | echo $* | |
225 | } | |
226 | ||
227 | # This is our interface to Routing Policy Database RPDB | |
228 | # This allows for advanced routing tricks | |
229 | _ip_rule_runner() { | |
230 | local cmd rules OIFS="${IFS}" family | |
231 | if [ "$1" = "-4" -o "$1" = "-6" ]; then | |
232 | family="$1" | |
233 | shift | |
234 | else | |
235 | family="-4" | |
236 | fi | |
237 | cmd="$1" | |
238 | rules="$2" | |
239 | veindent | |
240 | local IFS="$__IFS" | |
241 | for ru in $rules ; do | |
242 | unset IFS | |
243 | ruN="$(_trim "${ru}")" | |
244 | [ -z "${ruN}" ] && continue | |
245 | vebegin "${cmd} ${ruN}" | |
246 | ip $family rule ${cmd} ${ru} | |
247 | veend $? | |
248 | local IFS="$__IFS" | |
249 | done | |
250 | IFS="${OIFS}" | |
251 | veoutdent | |
252 | } | |
253 | ||
254 | iproute2_pre_start() | |
255 | { | |
256 | local tunnel= | |
257 | eval tunnel=\$iptunnel_${IFVAR} | |
258 | if [ -n "${tunnel}" ]; then | |
259 | # Set our base metric to 1000 | |
260 | metric=1000 | |
261 | # Bug#347657: If the mode is 'ipip6' or 'ip6ip6', the -6 must be passed | |
262 | # to iproute2 during tunnel creation. | |
263 | local ipproto='' | |
264 | [ "${tunnel##mode ipip6}" != "${tunnel}" ] && ipproto='-6' | |
265 | [ "${tunnel##mode ip6ip6}" != "${tunnel}" ] && ipproto='-6' | |
266 | ||
267 | ebegin "Creating tunnel ${IFVAR}" | |
268 | ip ${ipproto} tunnel add ${tunnel} name "${IFACE}" | |
269 | eend $? || return 1 | |
270 | _up | |
271 | fi | |
272 | ||
273 | # MTU support | |
274 | local mtu= | |
275 | eval mtu=\$mtu_${IFVAR} | |
276 | [ -n "${mtu}" ] && ip link set dev "${IFACE}" mtu "${mtu}" | |
277 | ||
278 | # TX Queue Length support | |
279 | local len= | |
280 | eval len=\$txqueuelen_${IFVAR} | |
281 | [ -n "${len}" ] && ip link set dev "${IFACE}" txqueuelen "${len}" | |
282 | ||
283 | return 0 | |
284 | } | |
285 | ||
286 | _iproute2_ipv6_tentative() | |
287 | { | |
288 | # Only check tentative when we have a carrier. | |
289 | _has_carrier || return 1 | |
290 | LC_ALL=C ip addr show dev "${IFACE}" | \ | |
291 | grep -q "^[[:space:]]*inet6 .* tentative" | |
292 | } | |
293 | ||
294 | iproute2_post_start() | |
295 | { | |
296 | local n=5 | |
297 | ||
298 | # Kernel may not have IP built in | |
299 | if [ -e /proc/net/route ]; then | |
300 | local rules="$(_get_array "rules_${IFVAR}")" | |
301 | if [ -n "${rules}" ]; then | |
302 | if ! ip -4 rule list | grep -q "^"; then | |
303 | eerror "IP Policy Routing (CONFIG_IP_MULTIPLE_TABLES) needed for ip rule" | |
304 | else | |
305 | service_set_value "ip_rule" "${rules}" | |
306 | einfo "Adding IPv4 RPDB rules" | |
307 | _ip_rule_runner -4 add "${rules}" | |
308 | fi | |
309 | fi | |
310 | ip -4 route flush table cache dev "${IFACE}" | |
311 | fi | |
312 | ||
313 | # Kernel may not have IPv6 built in | |
314 | if [ -e /proc/net/ipv6_route ]; then | |
315 | local rules="$(_get_array "rules6_${IFVAR}")" | |
316 | if [ -n "${rules}" ]; then | |
317 | if ! ip -6 rule list | grep -q "^"; then | |
318 | eerror "IPv6 Policy Routing (CONFIG_IPV6_MULTIPLE_TABLES) needed for ip rule" | |
319 | else | |
320 | service_set_value "ip6_rule" "${rules}" | |
321 | einfo "Adding IPv6 RPDB rules" | |
322 | _ip_rule_runner -6 add "${rules}" | |
323 | fi | |
324 | fi | |
325 | ip -6 route flush table cache dev "${IFACE}" | |
326 | fi | |
327 | ||
328 | if _iproute2_ipv6_tentative; then | |
329 | ebegin "Waiting for IPv6 addresses" | |
330 | while [ $n -ge 0 ]; do | |
331 | _iproute2_ipv6_tentative || break | |
332 | sleep 1 | |
333 | : $(( n -= 1 )) | |
334 | done | |
335 | [ $n -ge 0 ] | |
336 | eend $? | |
337 | fi | |
338 | ||
339 | return 0 | |
340 | } | |
341 | ||
342 | iproute2_post_stop() | |
343 | { | |
344 | # Kernel may not have IP built in | |
345 | if [ -e /proc/net/route ]; then | |
346 | local rules="$(service_get_value "ip_rule")" | |
347 | if [ -n "${rules}" ]; then | |
348 | einfo "Removing IPv4 RPDB rules" | |
349 | _ip_rule_runner -4 del "${rules}" | |
350 | fi | |
351 | ||
352 | # Only do something if the interface actually exist | |
353 | if _exists; then | |
354 | ip -4 route flush table cache dev "${IFACE}" | |
355 | fi | |
356 | fi | |
357 | ||
358 | # Kernel may not have IPv6 built in | |
359 | if [ -e /proc/net/ipv6_route ]; then | |
360 | local rules="$(service_get_value "ip6_rule")" | |
361 | if [ -n "${rules}" ]; then | |
362 | einfo "Removing IPv6 RPDB rules" | |
363 | _ip_rule_runner -6 del "${rules}" | |
364 | fi | |
365 | ||
366 | # Only do something if the interface actually exist | |
367 | if _exists; then | |
368 | ip -6 route flush table cache dev "${IFACE}" | |
369 | fi | |
370 | fi | |
371 | ||
372 | # Don't delete sit0 as it's a special tunnel | |
373 | if [ "${IFACE}" != "sit0" ]; then | |
374 | if [ -n "$(ip tunnel show "${IFACE}" 2>/dev/null)" ]; then | |
375 | ebegin "Destroying tunnel ${IFACE}" | |
376 | ip tunnel del "${IFACE}" | |
377 | eend $? | |
378 | fi | |
379 | fi | |
380 | } | |
381 | ||
382 | # Is the interface administratively/operationally up? | |
383 | # The 'UP' status in ifconfig/iproute2 is the administrative status | |
384 | # Operational state is available in iproute2 output as 'state UP', or the | |
385 | # operstate sysfs variable. | |
386 | # 0: up | |
387 | # 1: down | |
388 | # 2: invalid arguments | |
389 | is_admin_up() | |
390 | { | |
391 | local iface="$1" | |
392 | [ -z "$iface" ] && iface="$IFACE" | |
393 | ip link show dev $iface | \ | |
394 | sed -n '1,1{ /[<,]UP[,>]/{ q 0 }}; q 1; ' | |
395 | } | |
396 | ||
397 | is_oper_up() | |
398 | { | |
399 | local iface="$1" | |
400 | [ -z "$iface" ] && iface="$IFACE" | |
401 | read state </sys/class/net/"${iface}"/operstate | |
402 | [ "x$state" = "up" ] | |
403 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars ssid mode associate_timeout preferred_aps" | |
4 | _config_vars="$_config_vars blacklist_aps" | |
5 | ||
6 | iwconfig_depend() | |
7 | { | |
8 | program /sbin/ifconfig | |
9 | after plug | |
10 | before interface | |
11 | provide wireless | |
12 | } | |
13 | ||
14 | iwconfig_get_wep_status() | |
15 | { | |
16 | local status="disabled" | |
17 | local mode=$(LC_ALL=C ifconfig "${IFACE}" \ | |
18 | | sed -n -e 's/^[[:space:]]*authmode \([^ ]*\) privacy ON .*/\1/p') | |
19 | if [ -n "${mode}" ] ; then | |
20 | status="enabled - ${mode}" | |
21 | fi | |
22 | ||
23 | echo "(WEP ${status})" | |
24 | } | |
25 | ||
26 | _iwconfig_get() | |
27 | { | |
28 | LC_ALL=C ifconfig "${IFACE}" | \ | |
29 | sed -n -e "s/^[[:space:]]*ssid \(.*\) channel \([0-9]*\).* bssid \(..:..:..:..:..:..\)\$/\\$1/p" | |
30 | } | |
31 | ||
32 | _get_ssid() | |
33 | { | |
34 | local ssid="$(_iwconfig_get 1)" | |
35 | # If the ssid has a space then it's wrapped in quotes. This is a | |
36 | # problem if the real ssid has a quote at the start or the end :/ | |
37 | ssid=${ssid#\"} | |
38 | ssid=${ssid%\"} | |
39 | echo "${ssid}" | |
40 | } | |
41 | ||
42 | _get_ap_mac_address() | |
43 | { | |
44 | _iwconfig_get 3 | |
45 | } | |
46 | ||
47 | _get_channel() | |
48 | { | |
49 | _iwconfig_get 2 | |
50 | } | |
51 | ||
52 | iwconfig_report() | |
53 | { | |
54 | local m="connected to" | |
55 | local ssid="$(_get_ssid)" | |
56 | local mac="$(_get_ap_mac_address "${iface}")" | |
57 | [ -n "${mac}" ] && mac=" at ${mac}" | |
58 | local wep_status="$(iwconfig_get_wep_status "${iface}")" | |
59 | local channel="$(_get_channel)" | |
60 | [ -n "${channel}" ] && channel="on channel ${channel} " | |
61 | ||
62 | eindent | |
63 | einfo "${IFACE} ${m} \"${ssid}\"${mac}" | |
64 | einfo "${channel}${wep_status}" | |
65 | eoutdent | |
66 | } | |
67 | ||
68 | iwconfig_get_wep_key() | |
69 | { | |
70 | local mac="$1" key= | |
71 | [ -n "${mac}" ] && mac="$(echo "${mac}" | sed -e 's/://g')" | |
72 | eval key=\$mac_key_${mac} | |
73 | [ -z "${key}" ] && eval key=\$key_${SSIDVAR} | |
74 | echo "${key:--}" | |
75 | } | |
76 | ||
77 | iwconfig_user_config() | |
78 | { | |
79 | local conf= | |
80 | eval set -- \$ifconfig_${SSIDVAR} | |
81 | for conf in "$@" ; do | |
82 | ifconfig "${IFACE}" ${conf} | |
83 | done | |
84 | } | |
85 | ||
86 | iwconfig_set_mode() | |
87 | { | |
88 | local x= opt= unopt="hostap adhoc" | |
89 | case "$1" in | |
90 | master|hostap) unopt="adhoc" opt="hostap" ;; | |
91 | ad-hoc|adhoc) unopt="hostap" opt="adhoc" ;; | |
92 | esac | |
93 | for x in ${unopt} ; do | |
94 | ifconfig "${IFACE}" -mediaopt ${x} | |
95 | done | |
96 | for x in ${opt} ; do | |
97 | ifconfig "${IFACE}" mediaopt ${x} | |
98 | done | |
99 | } | |
100 | ||
101 | iwconfig_setup_specific() | |
102 | { | |
103 | local mode="${1:-master}" channel= | |
104 | if [ -z "${SSID}" ]; then | |
105 | eerror "${IFACE} requires an SSID to be set to operate in ${mode} mode" | |
106 | eerror "adjust the ssid_${IFVAR} setting in /etc/conf.d/net" | |
107 | return 1 | |
108 | fi | |
109 | ||
110 | iwconfig_set_mode "${mode}" || return 1 | |
111 | ||
112 | SSIDVAR=$(shell_var "${SSID}") | |
113 | local key=$(iwconfig_get_wep_key) | |
114 | ||
115 | # Now set the key | |
116 | ifconfig "${IFACE}" wepkey "${key}" | |
117 | ||
118 | ifconfig "${IFACE}" ssid "${SSID}" || return 1 | |
119 | ||
120 | eval channel=\$channel_${IFVAR} | |
121 | # We default the channel to 3 | |
122 | ifconfig "${IFACE}" channel "${channel:-3}" || return 1 | |
123 | ||
124 | iwconfig_user_config | |
125 | iwconfig_report "${iface}" | |
126 | return 0 | |
127 | } | |
128 | ||
129 | iwconfig_associate() | |
130 | { | |
131 | local mac="$1" channel="$2" caps="$3" | |
132 | local mode= w="(WEP Disabled)" key= | |
133 | ||
134 | SSIDVAR=$(shell_var "${SSID}") | |
135 | key=$(iwconfig_get_wep_key "${mac}") | |
136 | case "${caps}" in | |
137 | [EI]P*) | |
138 | if [ "${key}" = "-" ] ; then | |
139 | ewarn "WEP key is not set for \"${SSID}\"" | |
140 | return 1 | |
141 | fi | |
142 | ;; | |
143 | "") ;; | |
144 | *) | |
145 | if [ "${key}" != "-" ] ; then | |
146 | key="-" | |
147 | ewarn "\"${SSID}\" is not WEP enabled" | |
148 | fi | |
149 | ;; | |
150 | esac | |
151 | ||
152 | # Set mode accordingly | |
153 | case "${caps}" in | |
154 | *E*) | |
155 | mode="managed" | |
156 | if LC_ALL=C ifconfig "${IFACE}" | \ | |
157 | grep -q "^[[:space:]]*media: .*adhoc" ; then | |
158 | ifconfig "${IFACE}" down -mediaopt adhoc up | |
159 | fi | |
160 | ;; | |
161 | *I*) | |
162 | mode="adhoc" | |
163 | if ! LC_ALL=C ifconfig "${IFACE}" | \ | |
164 | grep -q "^[[:space:]]*media: .*adhoc" ; then | |
165 | ifconfig "${IFACE}" down mediaopt adhoc up | |
166 | fi | |
167 | ;; | |
168 | *) | |
169 | if LC_ALL=C ifconfig "${IFACE}" \ | |
170 | | grep -q "^[[:space:]]*media: .*adhoc" ; then | |
171 | mode="adhoc" | |
172 | else | |
173 | mode="managed" | |
174 | fi | |
175 | ;; | |
176 | esac | |
177 | ||
178 | if [ "${key}" = "-" ] ; then | |
179 | ifconfig "${IFACE}" wepmode off | |
180 | else | |
181 | ifconfig "${IFACE}" wepmode on | |
182 | ifconfig "${IFACE}" deftxkey 1 | |
183 | w=$(iwconfig_get_wep_status) | |
184 | fi | |
185 | ||
186 | ebegin "Connecting to \"${SSID}\" in ${mode} mode ${w}" | |
187 | ||
188 | if ! ifconfig "${IFACE}" wepkey "${key}" ; then | |
189 | eerror "Invalid WEP key ${key}" | |
190 | return 1 | |
191 | fi | |
192 | ||
193 | ifconfig "${IFACE}" ssid "${SSID}" || return 1 | |
194 | iwconfig_user_config | |
195 | ||
196 | if [ "${SSID}" != "any" ] && type preassociate >/dev/null 2>/dev/null ; then | |
197 | veinfo "Running preassociate function" | |
198 | veindent | |
199 | ( preassociate ) | |
200 | local e=$? | |
201 | veoutdent | |
202 | if [ ${e} -eq 0 ] ; then | |
203 | veend 1 "preassociate \"${SSID}\" on ${IFACE} failed" | |
204 | return 1 | |
205 | fi | |
206 | fi | |
207 | ||
208 | local timeout= i=0 | |
209 | eval timeout=\$associate_timeout_${IFVAR} | |
210 | timeout=${timeout:-10} | |
211 | ||
212 | [ ${timeout} -eq 0 ] \ | |
213 | && vewarn "WARNING: infinite timeout set for association on ${IFACE}" | |
214 | ||
215 | while true; do | |
216 | _has_carrier && break | |
217 | sleep 1 | |
218 | ||
219 | [ ${timeout} -eq 0 ] && continue | |
220 | : $(( i += 1 )) | |
221 | [ ${i} -ge ${timeout} ] && { eend 1; return 1; } | |
222 | done | |
223 | ||
224 | _has_carrier || { eend 1; return 1; } | |
225 | eend 0 | |
226 | ||
227 | if [ "${SSID}" = "any" ]; then | |
228 | SSID="$(_get_ssid)" | |
229 | iwconfig_associate | |
230 | return $? | |
231 | fi | |
232 | ||
233 | iwconfig_report | |
234 | ||
235 | if type postassociate >/dev/null 2>/dev/null ; then | |
236 | veinfo "Running postassociate function" | |
237 | veindent | |
238 | ( postassociate ) | |
239 | veoutdent | |
240 | fi | |
241 | ||
242 | return 0 | |
243 | } | |
244 | ||
245 | iwconfig_scan() | |
246 | { | |
247 | local x= i=0 scan= quality= | |
248 | einfo "Scanning for access points" | |
249 | eindent | |
250 | ||
251 | scan="$(LC_ALL=C ifconfig -v "${IFACE}" list scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")" | |
252 | while [ ${i} -lt 3 -a -z "${scan}" ] ; do | |
253 | scan="${scan}${scan:+ }$(LC_ALL=C ifconfig -v "${IFACE}" scan 2>/dev/null | sed -e "1 d" -e "s/$/'/g" -e "s/^/'/g")" | |
254 | : $(( i += 1 )) | |
255 | done | |
256 | ||
257 | APS=-1 | |
258 | eval set -- ${scan} | |
259 | for line in "$@" ; do | |
260 | : $(( APS += 1 )) | |
261 | set -- ${line} | |
262 | while true ; do | |
263 | case "$1" in | |
264 | *:*:*:*:*:*) break ;; | |
265 | esac | |
266 | eval SSID_${APS}="\"\${SSID_${APS}}\${SSID_${APS}:+ }$1\"" | |
267 | shift | |
268 | done | |
269 | eval MAC_${APS}="$(echo "$1" | tr '[:lower:]' '[:upper:]')" | |
270 | eval CHAN_${APS}="$2" | |
271 | quality=${4%:*} | |
272 | shift ; shift ; shift ; shift ; shift | |
273 | eval CAPS_${APS}="\"$*\"" | |
274 | ||
275 | # Add 1000 for managed nodes as we prefer them to adhoc | |
276 | set -- $* | |
277 | case "$1" in | |
278 | *E*) eval QUAL_${APS}=$(( quality + 1000 )) ;; | |
279 | *) eval QUAL_${APS}=\$quality ;; | |
280 | esac | |
281 | done | |
282 | ||
283 | if [ -z "${MAC_0}" ]; then | |
284 | ewarn "no access points found" | |
285 | eoutdent | |
286 | return 1 | |
287 | fi | |
288 | ||
289 | # Sort based on quality | |
290 | local i=0 k=1 a= b= x= t= | |
291 | while [ ${i} -lt ${APS} ] ; do | |
292 | : $(( k = i + 1 )) | |
293 | while [ ${k} -le ${APS} ] ; do | |
294 | eval a=\$QUALITY_${i} | |
295 | [ -z "${a}" ] && break | |
296 | eval b=\$QUALITY_${k} | |
297 | if [ -n "${b}" -a "${a}" -lt "${b}" ] ; then | |
298 | for x in MAC SSID CHAN QUALITY CAPS ; do | |
299 | eval t=\$${x}_${i} | |
300 | eval ${x}_${i}=\$${x}_${k} | |
301 | eval ${x}_${k}=\$t | |
302 | done | |
303 | fi | |
304 | : $(( k += 1 )) | |
305 | done | |
306 | : $(( i += 1 )) | |
307 | done | |
308 | ||
309 | # Strip any duplicates | |
310 | local i=0 k=1 a= b= | |
311 | while [ ${i} -lt ${APS} ] ; do | |
312 | : $(( k = i + 1 )) | |
313 | while [ ${k} -le ${APS} ] ; do | |
314 | eval a=\$MAC_${i} | |
315 | eval b=\$MAC_${k} | |
316 | if [ "${a}" = "${b}" ] ; then | |
317 | eval a=\$QUALITY_${i} | |
318 | eval b=\$QUALITY_${k} | |
319 | if [ -n "${a}" -a -n "${b}" ] ; then | |
320 | if [ ${a} -ge ${b} ] ; then | |
321 | unset MAC_${k} SSID_${k} CHAN_${k} QUALITY_${k} CAPS_${k} | |
322 | else | |
323 | unset MAC_${i} SSID_${i} CHAN_${i} QUALITY_${i} CAPS_${i} | |
324 | fi | |
325 | else | |
326 | unset MAC_${k} SSID_${k} CHAN_${k} QUALITY_${k} CAPS_${k} | |
327 | fi | |
328 | fi | |
329 | : $(( k += 1 )) | |
330 | done | |
331 | : $(( i += 1 )) | |
332 | done | |
333 | ||
334 | local i=0 e= m= s= | |
335 | ||
336 | while [ ${i} -le ${APS} ] ; do | |
337 | eval x=\$MAC_${i} | |
338 | if [ -z "${x}" ] ; then | |
339 | : $(( i += 1 )) | |
340 | continue | |
341 | fi | |
342 | ||
343 | eval m=\$MODE_${i} | |
344 | [ -n "${m}" ] && m=", ${m}" | |
345 | eval s=\$SSID_${i} | |
346 | eval q=\$QUALITY_${i} | |
347 | eval e=\$CAPS_${i} | |
348 | case "${e}" in | |
349 | [EI]P*) e=", encrypted" ;; | |
350 | *) e="" ;; | |
351 | esac | |
352 | if [ -z "${s}" ] ; then | |
353 | einfo "Found ${x}${m}${e}" | |
354 | else | |
355 | einfo "Found \"${s}\" at ${x}${m}${e}" | |
356 | fi | |
357 | ||
358 | x="$(echo "${x}" | sed -e 's/://g')" | |
359 | eval x=\$mac_ssid_${x} | |
360 | if [ -n "${x}" ] ; then | |
361 | eval SSID_${i}=\$x | |
362 | s=${x} | |
363 | eindent | |
364 | einfo "mapping to \"${x}\"" | |
365 | eoutdent | |
366 | fi | |
367 | ||
368 | eval set -- $(_flatten_array "blacklist_aps_${IFVAR}") | |
369 | [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps") | |
370 | for x; do | |
371 | if [ "${x}" = "${s}" ] ; then | |
372 | ewarn "${s} has been blacklisted - not connecting" | |
373 | unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} CAPS_${i} | |
374 | fi | |
375 | done | |
376 | : $(( i += 1 )) | |
377 | done | |
378 | eoutdent | |
379 | return 0 | |
380 | } | |
381 | ||
382 | iwconfig_force_preferred() | |
383 | { | |
384 | eval set -- $(_flatten_array "preferred_aps_${IFVAR}") | |
385 | [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") | |
386 | [ $# = 0 ] && return 1 | |
387 | ||
388 | ewarn "Trying to force preferred in case they are hidden" | |
389 | local ssid= | |
390 | for ssid; do | |
391 | local found_AP=false i=0 e= | |
392 | while [ ${i} -le ${APS:--1} ] ; do | |
393 | eval e=\$SSID_${i} | |
394 | if [ "${e}" = "${ssid}" ] ; then | |
395 | found_AP=true | |
396 | break | |
397 | fi | |
398 | : $(( i += 1 )) | |
399 | done | |
400 | if ! ${found_AP} ; then | |
401 | SSID=${ssid} | |
402 | iwconfig_associate && return 0 | |
403 | fi | |
404 | done | |
405 | ||
406 | ewarn "Failed to associate with any preferred access points on ${IFACE}" | |
407 | return 1 | |
408 | } | |
409 | ||
410 | iwconfig_connect_preferred() | |
411 | { | |
412 | eval set -- $(_flatten_array "preferred_aps_${IFVAR}") | |
413 | [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") | |
414 | [ $# = 0 ] && return 1 | |
415 | ||
416 | local ssid= i= mode= mac= caps= freq= chan= | |
417 | for ssid; do | |
418 | i=0 | |
419 | while [ ${i} -le ${APS} ] ; do | |
420 | eval e=\$SSID_${i} | |
421 | if [ "${e}" = "${ssid}" ] ; then | |
422 | SSID=${e} | |
423 | eval mac=\$MAC_${i} | |
424 | eval caps=\$CAPS_${i} | |
425 | eval freq=\$FREQ_${i} | |
426 | eval chan=\$CHAN_${i} | |
427 | iwconfig_associate "${mac}" \ | |
428 | "${chan}" "${caps}" && return 0 | |
429 | fi | |
430 | : $(( i += 1 )) | |
431 | done | |
432 | done | |
433 | ||
434 | return 1 | |
435 | } | |
436 | ||
437 | iwconfig_connect_not_preferred() | |
438 | { | |
439 | local ssid= i=0 mode= mac= caps= freq= chan= pref= | |
440 | ||
441 | while [ ${i} -le ${APS} ] ; do | |
442 | eval e=\$SSID_${i} | |
443 | if [ -z "${e}" ] ; then | |
444 | : $(( i += 1 )) | |
445 | continue | |
446 | fi | |
447 | ||
448 | eval set -- $(_flatten_array "preferred_aps_${IFVAR}") | |
449 | [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") | |
450 | pref=false | |
451 | for ssid; do | |
452 | if [ "${e}" = "${ssid}" ] ; then | |
453 | pref=true | |
454 | break | |
455 | fi | |
456 | done | |
457 | ||
458 | if ! ${pref} ; then | |
459 | SSID=${e} | |
460 | eval mac=\$MAC_${i} | |
461 | eval caps=\$CAPS_${i} | |
462 | eval freq=\$FREQ_${i} | |
463 | eval chan=\$CHAN_${i} | |
464 | iwconfig_associate "${mac}" \ | |
465 | "${chan}" "${caps}" && return 0 | |
466 | fi | |
467 | : $(( i += 1 )) | |
468 | done | |
469 | ||
470 | return 1 | |
471 | } | |
472 | ||
473 | iwconfig_defaults() | |
474 | { | |
475 | # Set some defaults | |
476 | #ifconfig "${iface}" txpower 100 2>/dev/null | |
477 | ifconfig "${IFACE}" bssid - | |
478 | ifconfig "${IFACE}" ssid - | |
479 | ifconfig "${IFACE}" wepkey 1:- wepkey 2:- wepkey 3:- wepkey 4:- | |
480 | ifconfig "${IFACE}" authmode open | |
481 | ifconfig "${IFACE}" -mediaopt adhoc | |
482 | ifconfig "${IFACE}" -mediaopt hostap | |
483 | } | |
484 | ||
485 | iwconfig_configure() | |
486 | { | |
487 | local x= APS=-1 | |
488 | eval SSID=\$ssid_${IFVAR} | |
489 | ||
490 | # Setup ad-hoc mode? | |
491 | eval x=\$mode_${IFVAR} | |
492 | x=${x:-managed} | |
493 | case "${x}" in | |
494 | ad-hoc|adhoc|hostap|master) iwconfig_setup_specific "${x}" ;; | |
495 | esac | |
496 | ||
497 | if [ "${x}" != "managed" -a "${x}" != "auto" -a "${x}" != "ad-hoc" -a "${x}" != "adhoc" -a ${x} != "master" ] ; then | |
498 | eerror "Only managed, ad-hoc, master and auto modes are supported" | |
499 | return 1 | |
500 | fi | |
501 | ||
502 | # Has an SSID been forced? | |
503 | if [ -n "${SSID}" ]; then | |
504 | iwconfig_set_mode "${x}" | |
505 | iwconfig_associate && return 0 | |
506 | [ "${SSID}" = "any" ] && iwconfig_force_preferred && return 0 | |
507 | ||
508 | eval SSID=\$adhoc_ssid_${IFVAR} | |
509 | if [ -n "${SSID}" ]; then | |
510 | iwconfig_setup_specific adhoc | |
511 | return $? | |
512 | fi | |
513 | return 1 | |
514 | fi | |
515 | ||
516 | # Are we forcing preferred only? | |
517 | eval x=\$associate_order_${IFVAR} | |
518 | [ -n "${x}" ] && associate_order=${x} | |
519 | associate_order=${associate_order:-any} | |
520 | if [ "${associate_order}" = "forcepreferredonly" ]; then | |
521 | iwconfig_force_preferred && return 0 | |
522 | else | |
523 | iwconfig_scan || return 1 | |
524 | iwconfig_connect_preferred && return 0 | |
525 | [ "${associate_order}" = "forcepreferred" ] || \ | |
526 | [ "${associate_order}" = "forceany" ] && \ | |
527 | iwconfig_force_preferred && return 0 | |
528 | [ "${associate_order}" = "any" ] || \ | |
529 | [ "${associate_order}" = "forceany" ] && \ | |
530 | iwconfig_connect_not_preferred && return 0 | |
531 | fi | |
532 | ||
533 | e="associate with" | |
534 | [ -z "${MAC_0}" ] && e="find" | |
535 | [ "${preferred_aps}" = "force" ] || \ | |
536 | [ "${preferred_aps}" = "forceonly" ] && \ | |
537 | e="force" | |
538 | e="Couldn't ${e} any access points on ${IFACE}" | |
539 | ||
540 | eval SSID=\$adhoc_ssid_${IFVAR} | |
541 | if [ -n "${SSID}" ]; then | |
542 | ewarn "${e}" | |
543 | iwconfig_setup_specific adhoc | |
544 | return $? | |
545 | fi | |
546 | ||
547 | eerror "${e}" | |
548 | return 1 | |
549 | } | |
550 | ||
551 | iwconfig_pre_start() | |
552 | { | |
553 | # We don't configure wireless if we're being called from | |
554 | # the background | |
555 | yesno ${IN_BACKGROUND} && return 0 | |
556 | ||
557 | service_set_value "SSID" "" | |
558 | _exists || return 0 | |
559 | ||
560 | if ! _is_wireless ; then | |
561 | veinfo "${IFACE} is not wireless" | |
562 | return 0 | |
563 | fi | |
564 | ||
565 | iwconfig_defaults | |
566 | iwconfig_user_config | |
567 | ||
568 | # Set the base metric to be 2000 | |
569 | metric=2000 | |
570 | ||
571 | einfo "Configuring wireless network for ${IFACE}" | |
572 | ||
573 | if iwconfig_configure ; then | |
574 | service_set_value "SSID" "${SSID}" | |
575 | return 0 | |
576 | fi | |
577 | ||
578 | eerror "Failed to configure wireless for ${IFACE}" | |
579 | iwconfig_defaults | |
580 | #iwconfig "${IFACE}" txpower 0 2>/dev/null | |
581 | unset SSID SSIDVAR | |
582 | _down | |
583 | return 1 | |
584 | } | |
585 | ||
586 | iwconfig_post_stop() | |
587 | { | |
588 | yesno ${IN_BACKGROUND} && return 0 | |
589 | _is_wireless || return 0 | |
590 | iwconfig_defaults | |
591 | #iwconfig "${IFACE}" txpower 0 2>/dev/null | |
592 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars ssid mode associate_timeout sleep_scan" | |
4 | _config_vars="$_config_vars preferred_aps blacklist_aps" | |
5 | ||
6 | iwconfig_depend() | |
7 | { | |
8 | program /sbin/iwconfig | |
9 | after plug | |
10 | before interface | |
11 | provide wireless | |
12 | } | |
13 | ||
14 | iwconfig_get_wep_status() | |
15 | { | |
16 | local mode= status="disabled" | |
17 | ||
18 | # No easy way of doing this grep in bash regex :/ | |
19 | if LC_ALL=C iwconfig "${IFACE}" | \ | |
20 | grep -qE "^ +Encryption key:[*0-9,A-F]"; then | |
21 | status="enabled" | |
22 | mode=$(LC_ALL=C iwconfig "${IFACE}" | \ | |
23 | sed -n -e 's/^.*Security mode:\(.*[^ ]\).*/\1/p') | |
24 | [ -n "${mode}" ] && mode=" - ${mode}" | |
25 | fi | |
26 | ||
27 | echo "(WEP ${status}${mode})" | |
28 | } | |
29 | ||
30 | _get_ssid() | |
31 | { | |
32 | local i=5 ssid= | |
33 | ||
34 | while [ ${i} -gt 0 ]; do | |
35 | ssid=$(iwgetid --raw "${IFACE}") | |
36 | if [ -n "${ssid}" ]; then | |
37 | echo "${ssid}" | |
38 | return 0 | |
39 | fi | |
40 | sleep 1 | |
41 | : $(( i -= 1 )) | |
42 | done | |
43 | ||
44 | return 1 | |
45 | } | |
46 | ||
47 | _get_ap_mac_address() | |
48 | { | |
49 | local mac="$(iwgetid --raw --ap "${IFACE}")" | |
50 | case "${mac}" in | |
51 | "00:00:00:00:00:00") return 1;; | |
52 | "44:44:44:44:44:44") return 1;; | |
53 | "FF:00:00:00:00:00") return 1;; | |
54 | "FF:FF:FF:FF:FF:FF") return 1;; | |
55 | *) echo "${mac}";; | |
56 | esac | |
57 | } | |
58 | ||
59 | iwconfig_get_mode() | |
60 | { | |
61 | LC_ALL=C iwgetid --mode "${IFACE}" | \ | |
62 | sed -n -e 's/^.*Mode:\(.*\)/\1/p' | \ | |
63 | tr '[:upper:]' '[:lower:]' | |
64 | } | |
65 | ||
66 | iwconfig_set_mode() | |
67 | { | |
68 | local mode="$1" | |
69 | [ "${mode}" = "$(iwconfig_get_mode)" ] && return 0 | |
70 | ||
71 | # Devicescape stack requires the interface to be down | |
72 | _down | |
73 | iwconfig "${IFACE}" mode "${mode}" || return 1 | |
74 | _up | |
75 | } | |
76 | ||
77 | iwconfig_get_type() | |
78 | { | |
79 | LC_ALL=C iwconfig "${IFACE}" | \ | |
80 | sed -n -e 's/^'"$1"' *\([^ ]* [^ ]*\).*/\1/p' | |
81 | } | |
82 | ||
83 | iwconfig_report() | |
84 | { | |
85 | local mac= m="connected to" | |
86 | local ssid="$(_get_ssid)" | |
87 | local wep_status="$(iwconfig_get_wep_status)" | |
88 | local channel="$(iwgetid --raw --channel "${iface}")" | |
89 | [ -n "${channel}" ] && channel="on channel ${channel} " | |
90 | local mode="$(iwconfig_get_mode)" | |
91 | if [ "${mode}" = "master" ]; then | |
92 | m="configured as" | |
93 | else | |
94 | mac="$(_get_ap_mac_address)" | |
95 | [ -n "${mac}" ] && mac=" at ${mac}" | |
96 | fi | |
97 | ||
98 | eindent | |
99 | einfo "${IFACE} ${m} SSID \"${SSID}\"${mac}" | |
100 | einfo "in ${mode} mode ${channel}${wep_status}" | |
101 | eoutdent | |
102 | } | |
103 | ||
104 | iwconfig_get_wep_key() | |
105 | { | |
106 | local mac="$1" key= | |
107 | [ -n "${mac}" ] && mac="$(echo "${mac}" | sed -e 's/://g')" | |
108 | eval key=\$mac_key_${mac} | |
109 | [ -z "${key}" ] && eval key=\$key_${SSIDVAR} | |
110 | if [ -z "${key}" ]; then | |
111 | echo "off" | |
112 | else | |
113 | set -- ${key} | |
114 | local x= e=false | |
115 | for x; do | |
116 | if [ "${x}" = "enc" ]; then | |
117 | e=true | |
118 | break | |
119 | fi | |
120 | done | |
121 | ${e} || key="${key} enc open" | |
122 | echo "${key}" | |
123 | fi | |
124 | } | |
125 | ||
126 | iwconfig_user_config() | |
127 | { | |
128 | local conf= var=${SSIDVAR} config= | |
129 | [ -z "${var}" ] && var=${IFVAR} | |
130 | ||
131 | config="$(_get_array "iwconfig_${var}")" | |
132 | local IFS="$__IFS" | |
133 | for conf in ${config}; do | |
134 | unset IFS | |
135 | if ! eval iwconfig "${IFACE}" "${conf}"; then | |
136 | ewarn "${IFACE} does not support the following configuration commands" | |
137 | ewarn " ${conf}" | |
138 | fi | |
139 | done | |
140 | unset IFS | |
141 | ||
142 | config="$(_get_array "iwpriv_${var}")" | |
143 | local IFS="$__IFS" | |
144 | for conf in ${config}; do | |
145 | unset IFS | |
146 | if ! eval iwpriv "${IFACE}" "${conf}"; then | |
147 | ewarn "${IFACE} does not support the following private ioctls" | |
148 | ewarn " ${conf}" | |
149 | fi | |
150 | done | |
151 | } | |
152 | ||
153 | iwconfig_setup_specific() | |
154 | { | |
155 | local mode="$1" channel= | |
156 | if [ -z "${SSID}" ]; then | |
157 | eerror "${IFACE} requires an SSID to be set to operate in ${mode} mode" | |
158 | eerror "adjust the ssid_${IFVAR} setting in /etc/conf.d/net" | |
159 | return 1 | |
160 | fi | |
161 | SSIDVAR=$(shell_var "${SSID}") | |
162 | local key=$(iwconfig_get_wep_key) | |
163 | ||
164 | iwconfig_set_mode "${mode}" | |
165 | ||
166 | # Now set the key | |
167 | if ! eval iwconfig "${IFACE}" key "${key}"; then | |
168 | if [ "${key}" != "off" ]; then | |
169 | ewarn "${IFACE} does not support setting keys" | |
170 | ewarn "or the parameter \"mac_key_${SSIDVAR}\" or \"key_${SSIDVAR}\" is incorrect" | |
171 | fi | |
172 | fi | |
173 | ||
174 | # Then set the SSID | |
175 | if ! iwconfig "${IFACE}" essid "${SSID}"; then | |
176 | eerror "${IFACE} does not support setting SSID to \"${SSID}\"" | |
177 | return 1 | |
178 | fi | |
179 | ||
180 | eval channel=\$channel_${SSIDVAR} | |
181 | [ -z "${channel}" ] && eval channel=\$channel_${IFVAR} | |
182 | # We default the channel to 3 | |
183 | if ! iwconfig "${IFACE}" channel "${channel:-3}"; then | |
184 | ewarn "${IFACE} does not support setting the channel to \"${channel:-3}\"" | |
185 | return 1 | |
186 | fi | |
187 | ||
188 | # Finally apply the user Config | |
189 | iwconfig_user_config | |
190 | ||
191 | iwconfig_report | |
192 | return 0 | |
193 | } | |
194 | ||
195 | iwconfig_wait_for_association() | |
196 | { | |
197 | local timeout= i=0 | |
198 | eval timeout=\$associate_timeout_${IFVAR} | |
199 | timeout=${timeout:-10} | |
200 | ||
201 | [ ${timeout} -eq 0 ] \ | |
202 | && vewarn "WARNING: infinite timeout set for association on ${IFACE}" | |
203 | ||
204 | while true; do | |
205 | # Use sysfs if we can | |
206 | if [ -e /sys/class/net/"${IFACE}"/carrier ]; then | |
207 | if [ "$(cat /sys/class/net/"${IFACE}"/carrier)" = "1" ]; then | |
208 | # Double check we have an ssid and a non-zero | |
209 | # mac address. This is mainly for buggy | |
210 | # prism54 drivers that always set their | |
211 | # carrier on or buggy madwifi drivers that | |
212 | # sometimes have carrier on and ssid set | |
213 | # without being associated. :/ | |
214 | [ -n "$(iwgetid --raw "${IFACE}")" ] && [ "$(iwgetid --ap --raw "${IFACE}")" != "00:00:00:00:00:00" ] && return 0 | |
215 | fi | |
216 | else | |
217 | local atest= | |
218 | eval atest=\$associate_test_${IFVAR} | |
219 | atest=${atest:-mac} | |
220 | if [ "${atest}" = "mac" -o "${atest}" = "all" ]; then | |
221 | [ -n "$(_get_ap_mac_address)" ] && return 0 | |
222 | fi | |
223 | if [ "${atest}" = "quality" -o "${atest}" = "all" ]; then | |
224 | [ "$(sed -n -e 's/^.*'"${IFACE}"': *[0-9]* *\([0-9]*\).*/\1/p' \ | |
225 | /proc/net/wireless)" != "0" ] && return 0 | |
226 | fi | |
227 | fi | |
228 | ||
229 | sleep 1 | |
230 | [ ${timeout} -eq 0 ] && continue | |
231 | : $(( i += 1 )) | |
232 | [ ${i} -ge ${timeout} ] && return 1 | |
233 | done | |
234 | return 1 | |
235 | } | |
236 | ||
237 | iwconfig_associate() | |
238 | { | |
239 | local mode="${1:-managed}" mac="$2" wep_required="$3" | |
240 | local freq="$4" chan="$5" | |
241 | local w="(WEP Disabled)" key= | |
242 | ||
243 | iwconfig_set_mode "${mode}" | |
244 | ||
245 | if [ "${SSID}" = "any" ]; then | |
246 | iwconfig "${IFACE}" ap any 2>/dev/null | |
247 | unset SSIDVAR | |
248 | else | |
249 | SSIDVAR=$(shell_var "${SSID}") | |
250 | key="$(iwconfig_get_wep_key "${mac}")" | |
251 | if [ "${wep_required}" = "on" -a "${key}" = "off" ]; then | |
252 | ewarn "WEP key is not set for \"${SSID}\"" | |
253 | return 1 | |
254 | fi | |
255 | if [ "${wep_required}" = "off" -a "${key}" != "off" ]; then | |
256 | key="off" | |
257 | ewarn "\"${SSID}\" is not WEP enabled" | |
258 | fi | |
259 | ||
260 | if ! eval iwconfig "${IFACE}" key "${key}"; then | |
261 | if [ "${key}" != "off" ]; then | |
262 | ewarn "${IFACE} does not support setting keys" | |
263 | ewarn "or the parameter \"mac_key_${SSIDVAR}\" or \"key_${SSIDVAR}\" is incorrect" | |
264 | return 1 | |
265 | fi | |
266 | fi | |
267 | [ "${key}" != "off" ] && w="$(iwconfig_get_wep_status "${iface}")" | |
268 | fi | |
269 | ||
270 | if ! iwconfig "${IFACE}" essid "${SSID}"; then | |
271 | if [ "${SSID}" != "any" ]; then | |
272 | ewarn "${IFACE} does not support setting SSID to \"${SSID}\"" | |
273 | fi | |
274 | fi | |
275 | ||
276 | # Only use channel or frequency | |
277 | if [ -n "${chan}" ]; then | |
278 | iwconfig "${IFACE}" channel "${chan}" | |
279 | elif [ -n "${freq}" ]; then | |
280 | iwconfig "${IFACE}" freq "${freq}" | |
281 | fi | |
282 | [ -n "${mac}" ] && iwconfig "${IFACE}" ap "${mac}" | |
283 | ||
284 | # Finally apply the user Config | |
285 | iwconfig_user_config | |
286 | ||
287 | ebegin "Connecting to \"${SSID}\" in ${mode} mode ${w}" | |
288 | ||
289 | if [ "${SSID}" != "any" ] && type preassociate >/dev/null 2>&1; then | |
290 | veinfo "Running preassociate function" | |
291 | veindent | |
292 | ( preassociate ) | |
293 | local e=$? | |
294 | veoutdent | |
295 | if [ ${e} -eq 0 ]; then | |
296 | veend 1 "preassociate \"${SSID}\" on ${IFACE} failed" | |
297 | return 1 | |
298 | fi | |
299 | fi | |
300 | ||
301 | if ! iwconfig_wait_for_association; then | |
302 | eend 1 | |
303 | return 1 | |
304 | fi | |
305 | eend 0 | |
306 | ||
307 | if [ "${SSID}" = "any" ]; then | |
308 | SSID="$(_get_ssid)" | |
309 | iwconfig_associate | |
310 | return $? | |
311 | fi | |
312 | ||
313 | iwconfig_report | |
314 | ||
315 | if type postassociate >/dev/null 2>&1; then | |
316 | veinfo "Running postassociate function" | |
317 | veindent | |
318 | ( postassociate ) | |
319 | veoutdent | |
320 | fi | |
321 | ||
322 | return 0 | |
323 | } | |
324 | ||
325 | iwconfig_scan() | |
326 | { | |
327 | local x= i=0 scan= | |
328 | einfo "Scanning for access points" | |
329 | eindent | |
330 | ||
331 | # Sleep if required | |
332 | eval x=\$sleep_scan_${IFVAR} | |
333 | [ -n "${x}" ] && sleep "${x}" | |
334 | ||
335 | while [ ${i} -lt 3 ]; do | |
336 | local scan="${scan}${scan:+ }$(LC_ALL=C iwlist "${IFACE}" scan 2>/dev/null | sed -e "s/'/'\\\\''/g" -e "s/$/'/g" -e "s/^/'/g")" | |
337 | # If this is the first pass and txpower as off and we have no | |
338 | # results then we need to wait for at least 2 seconds whilst | |
339 | # the interface does an initial scan. | |
340 | if [ "${i}" = "0" -a "${txpowerwasoff}" = "0" ]; then | |
341 | case "${scan}" in | |
342 | "'${IFACE} "*"No scan results"*) | |
343 | sleep 2 | |
344 | txpowerwasoff=1 | |
345 | continue | |
346 | ;; | |
347 | esac | |
348 | fi | |
349 | : $(( i += 1 )) | |
350 | done | |
351 | ||
352 | if [ -z "${scan}" ]; then | |
353 | ewarn "${iface} does not support scanning" | |
354 | eoutdent | |
355 | eval x=\$adhoc_ssid_${IFVAR} | |
356 | [ -n "${x}" ] && return 0 | |
357 | if [ -n "${preferred_aps}" ]; then | |
358 | [ "${associate_order}" = "forcepreferred" ] || \ | |
359 | [ "${associate_order}" = "forcepreferredonly" ] && return 0 | |
360 | fi | |
361 | eerror "You either need to set a preferred_aps list in /etc/conf.d/wireless" | |
362 | eerror " preferred_aps=\"SSID1 SSID2\"" | |
363 | eerror " and set associate_order_${IFVAR}=\"forcepreferred\"" | |
364 | eerror " or set associate_order_${IFVAR}=\"forcepreferredonly\"" | |
365 | eerror "or hardcode the SSID to \"any\" and let the driver find an Access Point" | |
366 | eerror " ssid_${IFVAR}=\"any\"" | |
367 | eerror "or configure defaulting to Ad-Hoc when Managed fails" | |
368 | eerror " adhoc_ssid_${IFVAR}=\"WLAN\"" | |
369 | eerror "or hardcode the SSID against the interface (not recommended)" | |
370 | eerror " ssid_${IFVAR}=\"SSID\"" | |
371 | return 1 | |
372 | fi | |
373 | ||
374 | APS=-1 | |
375 | eval set -- ${scan} | |
376 | for line; do | |
377 | case "${line}" in | |
378 | *Address:*) | |
379 | : $(( APS += 1 )) | |
380 | eval MAC_${APS}="\""$(echo "${line#*: }" | tr '[:lower:]' '[:upper:]')"\"" | |
381 | eval QUALITY_${APS}=0 | |
382 | ;; | |
383 | *ESSID:*) | |
384 | x=${line#*\"} | |
385 | x=${x%*\"} | |
386 | eval SSID_${APS}=\$x | |
387 | ;; | |
388 | *Mode:*) | |
389 | x="$(echo "${line#*:}" | tr '[:upper:]' '[:lower:]')" | |
390 | if [ "${x}" = "master" ]; then | |
391 | eval MODE_${APS}=managed | |
392 | else | |
393 | eval MODE_${APS}=\$x | |
394 | fi | |
395 | ;; | |
396 | *'Encryption key:'*) | |
397 | x=${line#*:} | |
398 | eval ENC_${APS}=\$x | |
399 | ;; | |
400 | #*Frequency:*) | |
401 | # freq[i]="${line#*:}" | |
402 | # x="${freq[i]#* }" | |
403 | # freq[i]="${freq[i]%% *}${x:0:1}" | |
404 | # ;; | |
405 | *Channel:*) | |
406 | x=${line#*:} | |
407 | x=${x%% *} | |
408 | eval CHAN_${APS}=\$x | |
409 | ;; | |
410 | *Quality*) | |
411 | x=${line#*:} | |
412 | x=${x%/*} | |
413 | x="$(echo "${x}" | sed -e 's/[^[:digit:]]//g')" | |
414 | x=${x:-0} | |
415 | eval QUALITY_${APS}=\$x | |
416 | ;; | |
417 | esac | |
418 | done | |
419 | ||
420 | if [ -z "${MAC_0}" ]; then | |
421 | ewarn "no access points found" | |
422 | eoutdent | |
423 | return 1 | |
424 | fi | |
425 | ||
426 | # Sort based on quality | |
427 | local i=0 k=1 a= b= x= t= | |
428 | while [ ${i} -lt ${APS} ]; do | |
429 | : $(( k = i + 1 )) | |
430 | while [ ${k} -le ${APS} ]; do | |
431 | eval a=\$QUALITY_${i} | |
432 | [ -z "${a}" ] && break | |
433 | eval b=\$QUALITY_${k} | |
434 | if [ -n "${b}" -a "${a}" -lt "${b}" ]; then | |
435 | for x in MAC SSID MODE CHAN QUALITY ENC; do | |
436 | eval t=\$${x}_${i} | |
437 | eval ${x}_${i}=\$${x}_${k} | |
438 | eval ${x}_${k}=\$t | |
439 | done | |
440 | fi | |
441 | : $(( k += 1 )) | |
442 | done | |
443 | : $(( i += 1 )) | |
444 | done | |
445 | ||
446 | # Strip any duplicates | |
447 | local i=0 k=1 a= b= | |
448 | while [ ${i} -lt ${APS} ]; do | |
449 | : $(( k = i + 1 )) | |
450 | while [ ${k} -le ${APS} ]; do | |
451 | eval a=\$MAC_${i} | |
452 | eval b=\$MAC_${k} | |
453 | if [ "${a}" = "${b}" ]; then | |
454 | eval a=\$QUALITY_${i} | |
455 | eval b=\$QUALITY_${k} | |
456 | local u=${k} | |
457 | # We need to split this into two tests, otherwise bash errors | |
458 | [ -n "${a}" -a -n "${b}" ] && [ "${a}" -lt "${b}" ] && u=${i} | |
459 | unset MAC_${u} SSID_${u} MODE_${u} CHAN_${u} QUALITY_${u} ENC_${u} | |
460 | fi | |
461 | : $(( k += 1 )) | |
462 | done | |
463 | : $(( i += 1 )) | |
464 | done | |
465 | ||
466 | local i=0 e= m= s= | |
467 | ||
468 | while [ ${i} -le ${APS} ]; do | |
469 | eval x=\$MAC_${i} | |
470 | if [ -z "${x}" ]; then | |
471 | : $(( i += 1 )) | |
472 | continue | |
473 | fi | |
474 | ||
475 | eval m=\$MODE_${i} | |
476 | eval s=\$SSID_${i} | |
477 | eval q=\$QUALITY_${i} | |
478 | eval e=\$ENC_${i} | |
479 | if [ -n "${e}" -a "${e}" != "off" ]; then | |
480 | e=", encrypted" | |
481 | else | |
482 | e="" | |
483 | fi | |
484 | if [ -z "${s}" ]; then | |
485 | einfo "Found ${x}, ${m}${e}" | |
486 | else | |
487 | einfo "Found \"${s}\" at ${x}, ${m}${e}" | |
488 | fi | |
489 | ||
490 | x="$(echo "${x}" | sed -e 's/://g')" | |
491 | eval x=\$mac_ssid_${x} | |
492 | if [ -n "${x}" ]; then | |
493 | eval SSID_${i}=\$x | |
494 | s=${x} | |
495 | eindent | |
496 | einfo "mapping to \"${x}\"" | |
497 | eoutdent | |
498 | fi | |
499 | ||
500 | eval set -- $(_flatten_array "blacklist_aps_${IFVAR}") | |
501 | [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps") | |
502 | for x; do | |
503 | if [ "${x}" = "${s}" ]; then | |
504 | ewarn "${s} has been blacklisted - not connecting" | |
505 | unset SSID_${i} MAC_${i} ${MODE}_${i} CHAN_${i} QUALITY_${i} ENC_${i} | |
506 | fi | |
507 | done | |
508 | : $(( i += 1 )) | |
509 | done | |
510 | eoutdent | |
511 | } | |
512 | ||
513 | iwconfig_force_preferred() | |
514 | { | |
515 | eval set -- $(_flatten_array "preferred_aps_${IFVAR}") | |
516 | [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") | |
517 | [ $# = 0 ] && return 1 | |
518 | ||
519 | ewarn "Trying to force preferred in case they are hidden" | |
520 | for ssid; do | |
521 | local found_AP=false i=0 e= | |
522 | while [ ${i} -le ${APS} ]; do | |
523 | eval e=\$SSID_${i} | |
524 | if [ "${e}" = "${ssid}" ]; then | |
525 | found_AP=true | |
526 | break | |
527 | fi | |
528 | : $(( i += 1 )) | |
529 | done | |
530 | if ! ${found_AP}; then | |
531 | SSID=${ssid} | |
532 | iwconfig_associate && return 0 | |
533 | fi | |
534 | done | |
535 | ||
536 | ewarn "Failed to associate with any preferred access points on ${IFACE}" | |
537 | return 1 | |
538 | } | |
539 | ||
540 | iwconfig_connect_preferred() | |
541 | { | |
542 | local ssid= i= mode= mac= enc= freq= chan= | |
543 | eval set -- $(_flatten_array "preferred_aps_${IFVAR}") | |
544 | [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") | |
545 | ||
546 | for ssid; do | |
547 | unset IFS | |
548 | i=0 | |
549 | while [ ${i} -le ${APS} ]; do | |
550 | eval e=\$SSID_${i} | |
551 | if [ "${e}" = "${ssid}" ]; then | |
552 | SSID=${e} | |
553 | eval mode=\$MODE_${i} | |
554 | eval mac=\$MAC_${i} | |
555 | eval enc=\$ENC_${i} | |
556 | eval freq=\$FREQ_${i} | |
557 | eval chan=\$CHAN_${i} | |
558 | iwconfig_associate "${mode}" "${mac}" "${enc}" "${freq}" \ | |
559 | "${chan}" && return 0 | |
560 | fi | |
561 | : $(( i += 1 )) | |
562 | done | |
563 | done | |
564 | ||
565 | return 1 | |
566 | } | |
567 | ||
568 | iwconfig_connect_not_preferred() | |
569 | { | |
570 | local ssid= i=0 mode= mac= enc= freq= chan= pref=false | |
571 | ||
572 | while [ ${i} -le ${APS} ]; do | |
573 | eval e=\$SSID_${i} | |
574 | if [ -n "${e}" ]; then | |
575 | eval set -- $(_flatten_array "preferred_aps_${IFVAR}") | |
576 | [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") | |
577 | for ssid; do | |
578 | if [ "${e}" = "${ssid}" ]; then | |
579 | pref=true | |
580 | break | |
581 | fi | |
582 | done | |
583 | ||
584 | if ! ${pref}; then | |
585 | SSID=${e} | |
586 | eval mode=\$MODE_${i} | |
587 | eval mac=\$MAC_${i} | |
588 | eval enc=\$ENC_${i} | |
589 | eval freq=\$FREQ_${i} | |
590 | eval chan=\$CHAN_${i} | |
591 | iwconfig_associate "${mode}" "${mac}" "${enc}" "${freq}" \ | |
592 | "${chan}" && return 0 | |
593 | fi | |
594 | fi | |
595 | : $(( i += 1 )) | |
596 | done | |
597 | ||
598 | return 1 | |
599 | } | |
600 | ||
601 | iwconfig_defaults() | |
602 | { | |
603 | # Turn on the radio | |
604 | iwconfig "${IFACE}" txpower on 2>/dev/null | |
605 | ||
606 | # Release the AP forced | |
607 | # Must do ap and then ssid otherwise scanning borks | |
608 | iwconfig "${IFACE}" ap off 2>/dev/null | |
609 | iwconfig "${IFACE}" essid off 2>/dev/null | |
610 | } | |
611 | ||
612 | iwconfig_configure() | |
613 | { | |
614 | local x= APS=-1 | |
615 | eval SSID=\$ssid_${IFVAR} | |
616 | ||
617 | # Support old variable | |
618 | [ -z "${SSID}" ] && eval SSID=\$essid_${IFVAR} | |
619 | ||
620 | # Setup ad-hoc mode? | |
621 | eval x=\$mode_${IFVAR} | |
622 | x=${x:-managed} | |
623 | if [ "${x}" = "ad-hoc" -o "${x}" = "master" ]; then | |
624 | iwconfig_setup_specific "${x}" | |
625 | return $? | |
626 | fi | |
627 | ||
628 | if [ "${x}" != "managed" -a "${x}" != "auto" ]; then | |
629 | eerror "Only managed, ad-hoc, master and auto modes are supported" | |
630 | return 1 | |
631 | fi | |
632 | ||
633 | # Has an SSID been forced? | |
634 | if [ -n "${SSID}" ]; then | |
635 | iwconfig_set_mode "${x}" | |
636 | iwconfig_associate && return 0 | |
637 | [ "${SSID}" = "any" ] && iwconfig_force_preferred && return 0 | |
638 | ||
639 | eval SSID=\$adhoc_ssid_${IFVAR} | |
640 | if [ -n "${SSID}" ]; then | |
641 | iwconfig_setup_specific ad-hoc | |
642 | return $? | |
643 | fi | |
644 | return 1 | |
645 | fi | |
646 | ||
647 | eval x=\$preferred_aps_${IFVAR} | |
648 | [ -n "${x}" ] && preferred_aps=${x} | |
649 | ||
650 | eval x=\$blacklist_aps_${IFVAR} | |
651 | [ -n "${x}" ] && blacklist_aps=${x} | |
652 | ||
653 | eval x=\$associate_order_${IFVAR} | |
654 | [ -n "${x}" ] && associate_order=${x} | |
655 | associate_order=${associate_order:-any} | |
656 | ||
657 | if [ "${associate_order}" = "forcepreferredonly" ]; then | |
658 | iwconfig_force_preferred && return 0 | |
659 | else | |
660 | iwconfig_scan || return 1 | |
661 | iwconfig_connect_preferred && return 0 | |
662 | [ "${associate_order}" = "forcepreferred" ] || \ | |
663 | [ "${associate_order}" = "forceany" ] && \ | |
664 | iwconfig_force_preferred && return 0 | |
665 | [ "${associate_order}" = "any" ] || \ | |
666 | [ "${associate_order}" = "forceany" ] && \ | |
667 | iwconfig_connect_not_preferred && return 0 | |
668 | fi | |
669 | ||
670 | e="associate with" | |
671 | [ -z "${MAC_0}" ] && e="find" | |
672 | [ "${preferred_aps}" = "force" ] || \ | |
673 | [ "${preferred_aps}" = "forceonly" ] && \ | |
674 | e="force" | |
675 | e="Couldn't ${e} any access points on ${IFACE}" | |
676 | ||
677 | eval SSID=\$adhoc_ssid_${IFVAR} | |
678 | if [ -n "${SSID}" ]; then | |
679 | ewarn "${e}" | |
680 | iwconfig_setup_specific ad-hoc | |
681 | return $? | |
682 | fi | |
683 | ||
684 | eerror "${e}" | |
685 | return 1 | |
686 | } | |
687 | ||
688 | iwconfig_pre_start() | |
689 | { | |
690 | # We don't configure wireless if we're being called from | |
691 | # the background | |
692 | yesno ${IN_BACKGROUND} && return 0 | |
693 | ||
694 | service_set_value "SSID" "" | |
695 | _exists || return 0 | |
696 | ||
697 | if ! _is_wireless; then | |
698 | veinfo "Wireless extensions not found for ${IFACE}" | |
699 | return 0 | |
700 | fi | |
701 | ||
702 | # Warn about old file - we want to punt it really | |
703 | if [ -e /etc/conf.d/wireless ]; then | |
704 | ewarn "/etc/conf.d/wireless is deprecated" | |
705 | ewarn "Please put all settings into /etc/conf.d/net" | |
706 | . /etc/conf.d/wireless | |
707 | fi | |
708 | ||
709 | # Store the fact that tx-power was off so we default to a longer | |
710 | # wait if our scan returns nothing | |
711 | LC_ALL=C iwconfig "${IFACE}" | sed -e '1d' | grep -q "Tx-Power=off" | |
712 | local txpowerwasoff=$? | |
713 | ||
714 | iwconfig_defaults | |
715 | iwconfig_user_config | |
716 | ||
717 | # Set the base metric to be 2000 | |
718 | metric=2000 | |
719 | ||
720 | # Check for rf_kill - only ipw supports this at present, but other | |
721 | # cards may in the future. | |
722 | if [ -e /sys/class/net/"${IFACE}"/device/rf_kill ]; then | |
723 | if [ $(cat /sys/class/net/"${IFACE}"/device/rf_kill) != "0" ]; then | |
724 | eerror "Wireless radio has been killed for interface ${IFACE}" | |
725 | return 1 | |
726 | fi | |
727 | fi | |
728 | ||
729 | einfo "Configuring wireless network for ${IFACE}" | |
730 | ||
731 | # Are we a proper IEEE device? | |
732 | # Most devices reutrn IEEE 802.11b/g - but intel cards return IEEE | |
733 | # in lower case and RA cards return RAPCI or similar | |
734 | # which really sucks :( | |
735 | # For the time being, we will test prism54 not loading firmware | |
736 | # which reports NOT READY! | |
737 | x="$(iwconfig_get_type)" | |
738 | if [ "${x}" = "NOT READY!" ]; then | |
739 | eerror "Looks like there was a problem loading the firmware for ${IFACE}" | |
740 | return 1 | |
741 | fi | |
742 | ||
743 | if iwconfig_configure; then | |
744 | service_set_value "SSID" "${SSID}" | |
745 | return 0 | |
746 | fi | |
747 | ||
748 | eerror "Failed to configure wireless for ${IFACE}" | |
749 | iwconfig_defaults | |
750 | iwconfig "${IFACE}" txpower off 2>/dev/null | |
751 | unset SSID SSIDVAR | |
752 | _down | |
753 | return 1 | |
754 | } | |
755 | ||
756 | iwconfig_post_stop() | |
757 | { | |
758 | yesno ${IN_BACKGROUND} && return 0 | |
759 | _exists || return 0 | |
760 | iwconfig_defaults | |
761 | iwconfig "${IFACE}" txpower off 2>/dev/null | |
762 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | macchanger_depend() | |
4 | { | |
5 | before macnet | |
6 | # no program 'macchanger', as we have partial functionality without it | |
7 | } | |
8 | ||
9 | _config_vars="$_config_vars mac" | |
10 | ||
11 | macchanger_pre_start() | |
12 | { | |
13 | # We don't change MAC addresses from background | |
14 | yesno ${IN_BACKGROUND} && return 0 | |
15 | ||
16 | local mac= opts= | |
17 | ||
18 | eval mac=\$mac_${IFVAR} | |
19 | [ -z "${mac}" ] && return 0 | |
20 | ||
21 | _exists true || return 1 | |
22 | ||
23 | ebegin "Changing MAC address of ${IFACE}" | |
24 | ||
25 | # The interface needs to be up for macchanger to work most of the time | |
26 | _down | |
27 | ||
28 | mac=$(echo "${mac}" | tr '[:upper:]' '[:lower:]') | |
29 | local hex="[0-9a-f][0-9a-f]" | |
30 | case "${mac}" in | |
31 | # specific mac-addr | |
32 | ${hex}:${hex}:${hex}:${hex}:${hex}:${hex}) | |
33 | # We don't need macchanger to change to a specific | |
34 | # mac address | |
35 | _set_mac_address "${mac}" | |
36 | if eend "$?"; then | |
37 | mac=$(_get_mac_address) | |
38 | eindent | |
39 | einfo "changed to ${mac}" | |
40 | eoutdent | |
41 | _up | |
42 | return 0 | |
43 | fi | |
44 | ;; | |
45 | ||
46 | # increment MAC address, default macchanger behavior | |
47 | increment) opts="${opts}";; | |
48 | ||
49 | # randomize just the ending bytes | |
50 | random-ending) opts="${opts} -e";; | |
51 | ||
52 | # keep the same kind of physical layer (eg fibre, copper) | |
53 | random-samekind) opts="${opts} -a";; | |
54 | ||
55 | # randomize to any known vendor of any physical layer type | |
56 | random-anykind) opts="${opts} -A";; | |
57 | ||
58 | # fully random bytes | |
59 | random-full|random) opts="${opts} -r";; | |
60 | ||
61 | # default case is just to pass on all the options | |
62 | *) opts="${opts} ${mac}";; | |
63 | esac | |
64 | ||
65 | if [ ! -x /sbin/macchanger ]; then | |
66 | eerror "For changing MAC addresses, emerge net-analyzer/macchanger" | |
67 | return 1 | |
68 | fi | |
69 | ||
70 | mac=$(/sbin/macchanger ${opts} "${IFACE}" \ | |
71 | | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' ) | |
72 | _up | |
73 | ||
74 | # Sometimes the interface needs to be up .... | |
75 | if [ -z "${mac}" ]; then | |
76 | mac=$(/sbin/macchanger ${opts} "${IFACE}" \ | |
77 | | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' ) | |
78 | fi | |
79 | ||
80 | if [ -z "${mac}" ]; then | |
81 | eend 1 "Failed to set MAC address" | |
82 | return 1 | |
83 | fi | |
84 | ||
85 | eend 0 | |
86 | eindent | |
87 | einfo "changed to" "${mac}" | |
88 | eoutdent | |
89 | ||
90 | return 0 | |
91 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | macnet_depend() | |
4 | { | |
5 | before rename interface wireless | |
6 | after macchanger | |
7 | } | |
8 | ||
9 | macnet_pre_start() | |
10 | { | |
11 | local mac=$(_get_mac_address 2>/dev/null) | |
12 | [ -z "${mac}" ] && return 0 | |
13 | ||
14 | vebegin "Configuring ${IFACE} for MAC address ${mac}" | |
15 | mac=$(echo "${mac}" | sed -e 's/://g') | |
16 | _configure_variables "${mac}" | |
17 | veend 0 | |
18 | } |
0 | # 2011-09-22 Stef Simoens <stef@bgs.org> | |
1 | # based on vlan.sh & tuntap.sh | |
2 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
3 | # All rights reserved. Released under the 2-clause BSD license. | |
4 | ||
5 | macvlan_depend() | |
6 | { | |
7 | program ip | |
8 | after interface | |
9 | before dhcp macchanger | |
10 | } | |
11 | ||
12 | _is_macvlan() | |
13 | { | |
14 | [ -n "$(export RC_SVCNAME="net.${IFACE}"; service_get_value macvlan)" ] | |
15 | } | |
16 | ||
17 | macvlan_pre_start() | |
18 | { | |
19 | # MAC-VLAN needs an existing interface to link to | |
20 | local macvlan= | |
21 | eval macvlan=\$macvlan_${IFVAR} | |
22 | [ -z "${macvlan}" ] && return 0 | |
23 | ||
24 | case " ${MODULES} " in | |
25 | *" ifconfig "*) | |
26 | eerror "sys-apps/iproute2 is required to configure MACVLANs" | |
27 | return 1 ;; | |
28 | esac | |
29 | ||
30 | # optional mode, default to "private" | |
31 | local mode= | |
32 | eval mode=\$mode_${IFVAR} | |
33 | [ -z "${mode}" ] && mode="private" | |
34 | ||
35 | ebegin "Creating MAC-VLAN ${IFACE} to ${macvlan}" | |
36 | e="$(ip link add link "${macvlan}" name "${IFACE}" type macvlan mode "${mode}" 2>&1 1>/dev/null)" | |
37 | if [ -n "${e}" ]; then | |
38 | eend 1 "${e}" | |
39 | else | |
40 | eend 0 && _up && service_set_value macvlan "${macvlan}" | |
41 | fi | |
42 | } | |
43 | ||
44 | ||
45 | macvlan_post_stop() | |
46 | { | |
47 | _is_macvlan || return 0 | |
48 | ||
49 | ebegin "Removing MAC-VLAN ${IFACE}" | |
50 | ip link delete "${IFACE}" type macvlan >/dev/null | |
51 | eend $? | |
52 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars plug_timeout" | |
4 | ||
5 | netplugd_depend() | |
6 | { | |
7 | program start /sbin/netplugd | |
8 | after macnet rename | |
9 | before interface | |
10 | provide plug | |
11 | ||
12 | # Prefer ifplugd | |
13 | before ifplugd | |
14 | } | |
15 | ||
16 | netplugd_pre_start() | |
17 | { | |
18 | local pidfile="/var/run/netplugd-${IFACE}.pid" timeout= | |
19 | ||
20 | # We don't start netplug if we're being called from the background | |
21 | yesno ${IN_BACKGROUND} && return 0 | |
22 | ||
23 | _exists || return 0 | |
24 | ||
25 | # We need a valid MAC address | |
26 | # It's a basic test to ensure it's not a virtual interface | |
27 | if ! _get_mac_address >/dev/null 2>&1; then | |
28 | vewarn "netplug only works on interfaces with a valid MAC address" | |
29 | return 0 | |
30 | fi | |
31 | ||
32 | # We don't work on bonded, bridges, tun/tap, vlan or wireless | |
33 | for f in bond bridge tuntap vlan wireless; do | |
34 | if type "_is_${f}" >/dev/null 2>&1; then | |
35 | if _is_${f}; then | |
36 | veinfo "netplug does not work with" "${f}" | |
37 | return 0 | |
38 | fi | |
39 | fi | |
40 | done | |
41 | ||
42 | ebegin "Starting netplug on" "${IFACE}" | |
43 | ||
44 | # Mark the us as inactive so netplug can restart us | |
45 | mark_service_inactive | |
46 | ||
47 | # Start netplug | |
48 | start-stop-daemon --start --exec /sbin/netplugd \ | |
49 | --pidfile "${pidfile}" \ | |
50 | -- -i "${IFACE}" -P -p "${pidfile}" -c /dev/null | |
51 | eend "$?" || return 1 | |
52 | ||
53 | eindent | |
54 | ||
55 | # IFACE-specific, then global, then default | |
56 | eval timeout=\$plug_timeout_${IFVAR} | |
57 | [ -z "${timeout}" ] && timeout=$plug_timeout | |
58 | [ -z "${timeout}" ] && timeout=-1 | |
59 | if [ ${timeout} -eq 0 ]; then | |
60 | ewarn "WARNING: infinite timeout set for ${IFACE} to come up" | |
61 | elif [ ${timeout} -lt 0 ]; then | |
62 | einfo "Backgrounding ..." | |
63 | exit 1 | |
64 | fi | |
65 | ||
66 | veinfo "Waiting for ${IFACE} to be marked as started" | |
67 | ||
68 | local i=0 | |
69 | while true; do | |
70 | if service_started; then | |
71 | _show_address | |
72 | exit 0 | |
73 | fi | |
74 | sleep 1 | |
75 | [ ${timeout} -eq 0 ] && continue | |
76 | : $(( i += 1 )) | |
77 | [ ${i} -ge ${timeout} ] && break | |
78 | done | |
79 | ||
80 | eend 1 "Failed to configure ${IFACE} in the background" | |
81 | exit 1 | |
82 | } | |
83 | ||
84 | netplugd_stop() | |
85 | { | |
86 | yesno ${IN_BACKGROUND} && return 0 | |
87 | ||
88 | local pidfile="/var/run/netplugd-${IFACE}.pid" | |
89 | [ ! -e "${pidfile}" ] && return 0 | |
90 | ||
91 | ebegin "Stopping netplug on" "${IFACE}" | |
92 | start-stop-daemon --stop --quiet --exec /sbin/netplugd \ | |
93 | --pidfile "${pidfile}" | |
94 | eend $? | |
95 | } |
0 | # Copyright (c) 2005-2007 Gentoo Foundation | |
1 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
2 | # Released under the 2-clause BSD license. | |
3 | ||
4 | pppd_depend() | |
5 | { | |
6 | program /usr/sbin/pppd | |
7 | after interface | |
8 | before dhcp | |
9 | provide ppp | |
10 | } | |
11 | ||
12 | is_ppp() | |
13 | { | |
14 | [ -e /var/run/ppp-"${IFACE}".pid ] | |
15 | } | |
16 | ||
17 | requote() | |
18 | { | |
19 | printf "'%s' " "$@" | |
20 | } | |
21 | ||
22 | pppd_pre_start() | |
23 | { | |
24 | # Interface has to be called ppp | |
25 | [ "${IFACE%%[0-9]*}" = "ppp" ] || return 0 | |
26 | ||
27 | # Set our base metric | |
28 | metric=4000 | |
29 | ||
30 | if yesno ${IN_BACKGROUND}; then | |
31 | local config= | |
32 | eval config=\$config_${IFVAR} | |
33 | # If no config for ppp then don't default to DHCP | |
34 | if [ -z "${config}" ]; then | |
35 | eval config_${IFVAR}=null | |
36 | fi | |
37 | return 0 | |
38 | fi | |
39 | ||
40 | local link= i= unit="${IFACE#ppp}" opts= | |
41 | ||
42 | # PPP requires a link to communicate over - normally a serial port | |
43 | # PPPoE communicates over Ethernet | |
44 | # PPPoA communicates over ATM | |
45 | # In all cases, the link needs to be available before we start PPP | |
46 | eval link=\$link_${IFVAR} | |
47 | [ -n "${link}" ] || return 0 | |
48 | ||
49 | case "${link}" in | |
50 | /*) | |
51 | if [ ! -e "${link}" ]; then | |
52 | eerror "${link} does not exist" | |
53 | eerror "Please verify hardware or kernel module (driver)" | |
54 | return 1 | |
55 | fi | |
56 | ;; | |
57 | esac | |
58 | ||
59 | if [ -z "${unit}" ]; then | |
60 | eerror "PPP requires a unit - use net.ppp[0-9] instead of net.ppp" | |
61 | return 1 | |
62 | fi | |
63 | ||
64 | # We need to flatten the useless array | |
65 | set -- $(_get_array "pppd_${IFVAR}") | |
66 | opts="$@" | |
67 | ||
68 | local mtu= hasmtu=false hasmru=false hasmaxfail=false haspersist=false | |
69 | local hasupdetach=false hasdefaultmetric=false | |
70 | for i in ${opts}; do | |
71 | case "${i}" in | |
72 | unit|nodetach|linkname) | |
73 | eerror "The option \"${i}\" is not allowed in pppd_${IFVAR}" | |
74 | return 1 | |
75 | ;; | |
76 | defaultmetric) hasdefaultmetric=true;; | |
77 | mtu) hasmtu=true;; | |
78 | mru) hasmru=true;; | |
79 | maxfail) hasmaxfail=true;; | |
80 | persist) haspersist=true;; | |
81 | updetach) hasupdetach=true;; | |
82 | esac | |
83 | done | |
84 | ||
85 | # Might be set in conf.d/net | |
86 | local username= password= passwordset= | |
87 | eval username=\$username_${IFVAR} | |
88 | eval password=\$password_${IFVAR} | |
89 | eval passwordset=\$\{password_${IFVAR}-x\} | |
90 | if [ -n "${username}" ] \ | |
91 | && [ -n "${password}" -o -z "${passwordset}" ]; then | |
92 | opts="plugin passwordfd.so ${opts} passwordfd 0" | |
93 | fi | |
94 | ||
95 | if ! ${hasdefaultmetric}; then | |
96 | local m= | |
97 | eval m=\$metric_${IFVAR} | |
98 | [ -z "${m}" ] && : $(( m = metric + $(_ifindex) )) | |
99 | opts="${opts} defaultmetric ${m}" | |
100 | fi | |
101 | if [ -n "${mtu}" ]; then | |
102 | ${hasmtu} || opts="${opts} mtu ${mtu}" | |
103 | ${hasmru} || opts="${opts} mru ${mtu}" | |
104 | fi | |
105 | ${hasmaxfail} || opts="${opts} maxfail 0" | |
106 | ${haspersist} || opts="${opts} persist" | |
107 | ||
108 | # Set linkname because we need /var/run/ppp-${linkname}.pid | |
109 | # This pidfile has the advantage of being there, | |
110 | # even if ${IFACE} interface was never started | |
111 | opts="linkname ${IFACE} ${opts}" | |
112 | ||
113 | # Setup auth info | |
114 | if [ -n "${username}" ]; then | |
115 | opts="user '${username}' remotename ${IFACE} ${opts}" | |
116 | fi | |
117 | ||
118 | # Load a custom interface configuration file if it exists | |
119 | [ -f "/etc/ppp/options.${IFACE}" ] \ | |
120 | && opts="${opts} file '/etc/ppp/options.${IFACE}'" | |
121 | ||
122 | # Set unit | |
123 | opts="unit ${unit} ${opts}" | |
124 | ||
125 | # Setup connect script | |
126 | local chatprog="/usr/sbin/chat -e -E -v" phone= | |
127 | eval phone=\$phone_number_${IFVAR} | |
128 | set -- ${phone} | |
129 | [ -n "$1" ] && chatprog="${chatprog} -T '$1'" | |
130 | [ -n "$2" ] && chatprog="${chatprog} -U '$2'" | |
131 | # We need to flatten the useless array | |
132 | set -- $(_get_array "chat_${IFVAR}") | |
133 | if [ $# != 0 ]; then | |
134 | opts="${opts} connect '$(echo ${chatprog} $@ | sed -e "s:':'\\\\'':g")'" | |
135 | fi | |
136 | ||
137 | # Add plugins | |
138 | local haspppoa=false haspppoe=false plugins="$(_get_array "plugins_${IFVAR}")" | |
139 | local IFS="$__IFS" | |
140 | for i in ${plugins}; do | |
141 | unset IFS | |
142 | set -- ${i} | |
143 | case "$1" in | |
144 | passwordfd) continue;; | |
145 | pppoa) shift; set -- "pppoatm" "$@";; | |
146 | pppoe) shift; set -- "rp-pppoe" "$@";; | |
147 | capi) shift; set -- "capiplugin" "$@";; | |
148 | esac | |
149 | case "$1" in | |
150 | rp-pppoe) haspppoe=true;; | |
151 | pppoatm) haspppoa=true;; | |
152 | esac | |
153 | if [ "$1" = "rp-pppoe" ] || [ "$1" = "pppoatm" -a "${link}" != "/dev/null" ]; then | |
154 | opts="${opts} connect true" | |
155 | set -- "$@" "${link}" | |
156 | fi | |
157 | opts="plugin $1.so ${opts}" | |
158 | shift | |
159 | opts="${opts} $@" | |
160 | done | |
161 | unset IFS | |
162 | ||
163 | #Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi) | |
164 | local insert_link_in_opts=1 | |
165 | if ${haspppoe}; then | |
166 | if [ ! -e /proc/net/pppoe ]; then | |
167 | # Load the PPPoE kernel module | |
168 | if ! modprobe pppoe; then | |
169 | eerror "kernel does not support PPPoE" | |
170 | return 1 | |
171 | fi | |
172 | fi | |
173 | ||
174 | # Ensure that the link exists and is up | |
175 | ( IFACE="${link}"; _exists true && _up ) || return 1 | |
176 | insert_link_in_opts=0 | |
177 | fi | |
178 | ||
179 | if ${haspppoa}; then | |
180 | if [ ! -d /proc/net/atm ]; then | |
181 | # Load the PPPoA kernel module | |
182 | if ! modprobe pppoatm; then | |
183 | eerror "kernel does not support PPPoATM" | |
184 | return 1 | |
185 | fi | |
186 | fi | |
187 | ||
188 | if [ "${link}" != "/dev/null" ]; then | |
189 | insert_link_in_opts=0 | |
190 | else | |
191 | ewarn "WARNING: An [itf.]vpi.vci ATM address was expected in link_${IFVAR}" | |
192 | fi | |
193 | ||
194 | fi | |
195 | [ "${insert_link_in_opts}" = "0" ] || opts="${link} ${opts}" | |
196 | ||
197 | ebegin "Starting pppd in ${IFACE}" | |
198 | mark_service_inactive | |
199 | if [ -n "${username}" ] \ | |
200 | && [ -n "${password}" -o -z "${passwordset}" ]; then | |
201 | printf "%s" "${password}" | \ | |
202 | eval start-stop-daemon --start --exec /usr/sbin/pppd \ | |
203 | --pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null | |
204 | else | |
205 | eval start-stop-daemon --start --exec /usr/sbin/pppd \ | |
206 | --pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null | |
207 | fi | |
208 | ||
209 | if ! eend $? "Failed to start PPP"; then | |
210 | mark_service_stopped | |
211 | return 1 | |
212 | fi | |
213 | ||
214 | if ${hasupdetach}; then | |
215 | _show_address | |
216 | else | |
217 | einfo "Backgrounding ..." | |
218 | fi | |
219 | ||
220 | # pppd will re-call us when we bring the interface up | |
221 | exit 0 | |
222 | } | |
223 | ||
224 | # Dummy function for users that still have config_ppp0="ppp" | |
225 | pppd_start() | |
226 | { | |
227 | return 0 | |
228 | } | |
229 | ||
230 | pppd_stop() | |
231 | { | |
232 | yesno ${IN_BACKGROUND} && return 0 | |
233 | local pidfile="/var/run/ppp-${IFACE}.pid" | |
234 | ||
235 | [ ! -s "${pidfile}" ] && return 0 | |
236 | ||
237 | # Give pppd at least 30 seconds do die, #147490 | |
238 | einfo "Stopping pppd on ${IFACE}" | |
239 | start-stop-daemon --stop --quiet --exec /usr/sbin/pppd \ | |
240 | --pidfile "${pidfile}" --retry 30 | |
241 | eend $? | |
242 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | pump_depend() | |
4 | { | |
5 | program /sbin/pump | |
6 | after interface | |
7 | provide dhcp | |
8 | } | |
9 | ||
10 | _config_vars="$_config_vars dhcp pump" | |
11 | ||
12 | pump_start() | |
13 | { | |
14 | local args= opt= opts= | |
15 | ||
16 | # Get our options | |
17 | eval opts=\$dhcp_${IFVAR} | |
18 | [ -z "${opts}" ] && opts=${dhcp} | |
19 | ||
20 | # Map some generic options to dhcpcd | |
21 | for opt in ${opts}; do | |
22 | case "${opt}" in | |
23 | nodns) args="${args} --no-dns";; | |
24 | nontp) args="${args} --no-ntp";; | |
25 | nogateway) args="${args} --no-gateway";; | |
26 | esac | |
27 | done | |
28 | ||
29 | # Add our route metric | |
30 | [ "${metric:-0}" != "0" ] && args="${args} --route-metric ${metric}" | |
31 | ||
32 | args="${args} --win-client-ident" | |
33 | args="${args} --keep-up --interface ${IFACE}" | |
34 | ||
35 | ebegin "Running pump" | |
36 | eval pump "${args}" | |
37 | eend $? || return 1 | |
38 | ||
39 | _show_address | |
40 | return 0 | |
41 | } | |
42 | ||
43 | pump_stop() | |
44 | { | |
45 | # We check for a pump process first as querying for status | |
46 | # causes pump to spawn a process | |
47 | start-stop-daemon --quiet --test --stop --exec /sbin/pump || return 0 | |
48 | ||
49 | # Check that pump is running on the interface | |
50 | if ! pump --status --interface "${IFACE}" >/dev/null 2>&1; then | |
51 | return 0 | |
52 | fi | |
53 | ||
54 | # Pump always releases the lease | |
55 | ebegin "Stopping pump on ${IFACE}" | |
56 | pump --release --interface "${IFACE}" | |
57 | eend $? "Failed to stop pump" | |
58 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | ssidnet_depend() | |
4 | { | |
5 | before interface system | |
6 | after wireless | |
7 | } | |
8 | ||
9 | ssidnet_pre_start() | |
10 | { | |
11 | [ -z "${SSID}" -a -z "${SSIDVAR}" ] && return 0 | |
12 | ||
13 | local mac=$(_get_ap_mac_address | sed -e 's/://g') x= | |
14 | ||
15 | vebegin "Configuring ${IFACE} for SSID ${SSID}" | |
16 | _configure_variables "${mac}" "${SSIDVAR}" | |
17 | ||
18 | # Backwards compat for old gateway var | |
19 | eval x=\$gateway_${SSIDVAR} | |
20 | [ -n "${x}" ] && gateway=${x} | |
21 | ||
22 | veend 0 | |
23 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | _config_vars="$_config_vars dns_servers dns_domain dns_search" | |
4 | _config_vars="$_config_vars dns_sortlist dns_options" | |
5 | _config_vars="$_config_vars ntp_servers nis_servers nis_domain" | |
6 | ||
7 | system_depend() | |
8 | { | |
9 | after interface | |
10 | before dhcp | |
11 | } | |
12 | ||
13 | _system_dns() | |
14 | { | |
15 | local servers= domain= search= sortlist= options= x= imetric= | |
16 | ||
17 | eval servers=\$dns_servers_${IFVAR} | |
18 | [ -z "${servers}" ] && servers=${dns_servers} | |
19 | ||
20 | eval domain=\$dns_domain_${IFVAR} | |
21 | [ -z "${domain}" ] && domain=${dns_domain} | |
22 | ||
23 | eval search=\$dns_search_${IFVAR} | |
24 | [ -z "${search}" ] && search=${dns_search} | |
25 | ||
26 | eval sortlist=\$dns_sortlist_${IFVAR} | |
27 | [ -z "${sortlist}" ] && sortlist=${dns_sortlist} | |
28 | ||
29 | eval options=\$dns_options_${IFVAR} | |
30 | [ -z "${options}" ] && options=${dns_options} | |
31 | ||
32 | [ -z "${servers}" -a -z "${domain}" -a -z "${search}" \ | |
33 | -a -z "${sortlist}" -a -z "${options}" ] && return 0 | |
34 | ||
35 | local buffer="# Generated by net-scripts for interface ${IFACE}\n" | |
36 | [ -n "${domain}" ] && buffer="${buffer}domain ${domain}\n" | |
37 | [ -n "${search}" ] && buffer="${buffer}search ${search}\n" | |
38 | ||
39 | for x in ${servers}; do | |
40 | buffer="${buffer}nameserver ${x}\n" | |
41 | done | |
42 | ||
43 | [ -n "${sortlist}" ] && buffer="${buffer}sortlist ${sortlist}\n" | |
44 | [ -n "${options}" ] && buffer="${buffer}options ${options}\n" | |
45 | ||
46 | # Support resolvconf if we have it. | |
47 | if [ -x /sbin/resolvconf ]; then | |
48 | x="-a ${IFACE}" | |
49 | eval imetric=\${metric_${IFVAR}} | |
50 | if [ -n "${imetric}" ]; then | |
51 | x="${x} -m ${imetric}" | |
52 | fi | |
53 | printf "${buffer}" | resolvconf ${x} | |
54 | else | |
55 | printf "${buffer}" > /etc/resolv.conf | |
56 | chmod 644 /etc/resolv.conf | |
57 | fi | |
58 | } | |
59 | ||
60 | _system_ntp() | |
61 | { | |
62 | local servers= buffer= x= | |
63 | ||
64 | eval servers=\$ntp_servers_${IFVAR} | |
65 | [ -z "${servers}" ] && servers=${ntp_servers} | |
66 | [ -z "${servers}" ] && return 0 | |
67 | ||
68 | buffer="# Generated by net-scripts for interface ${IFACE}\n" | |
69 | buffer="${buffer}restrict default noquery notrust nomodify\n" | |
70 | buffer="${buffer}restrict 127.0.0.1\n" | |
71 | ||
72 | for x in ${servers}; do | |
73 | buffer="${buffer}restrict ${x} nomodify notrap noquery\n" | |
74 | buffer="${buffer}server ${x}\n" | |
75 | done | |
76 | ||
77 | printf "${buffer}" > /etc/ntp.conf | |
78 | chmod 644 /etc/ntp.conf | |
79 | } | |
80 | ||
81 | _system_nis() | |
82 | { | |
83 | local servers= domain= x= buffer= | |
84 | ||
85 | eval servers=\$nis_servers_${IFVAR} | |
86 | [ -z "${servers}" ] && servers=${nis_servers} | |
87 | ||
88 | eval domain=\$nis_domain_${IFVAR} | |
89 | [ -z "${domain}" ] && domain=${nis_domain} | |
90 | ||
91 | [ -z "${servers}" -a -z "${domain}" ] && return 0 | |
92 | ||
93 | buffer="# Generated by net-scripts for interface ${iface}\n" | |
94 | ||
95 | if [ -n "${domain}" ]; then | |
96 | hostname -y "${domain}" | |
97 | if [ -n "${servers}" ]; then | |
98 | for x in ${servers}; do | |
99 | buffer="${buffer}domain ${domain} server ${x}\n" | |
100 | done | |
101 | else | |
102 | buffer="${buffer}domain ${domain} broadcast\n" | |
103 | fi | |
104 | else | |
105 | for x in ${servers}; do | |
106 | buffer="${buffer}ypserver ${x}\n" | |
107 | done | |
108 | fi | |
109 | ||
110 | printf "${buffer}" > /etc/yp.conf | |
111 | chmod 644 /etc/yp.conf | |
112 | } | |
113 | ||
114 | system_pre_start() | |
115 | { | |
116 | _system_dns | |
117 | _system_ntp | |
118 | _system_nis | |
119 | ||
120 | return 0 | |
121 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | tuntap_depend() | |
4 | { | |
5 | before bridge interface macchanger | |
6 | program ip openvpn tunctl | |
7 | } | |
8 | ||
9 | _config_vars="$_config_vars iproute2 openvpn tunctl" | |
10 | ||
11 | _is_tuntap() | |
12 | { | |
13 | [ -n "$(export RC_SVCNAME="net.${IFACE}"; service_get_value tuntap)" ] | |
14 | } | |
15 | ||
16 | tuntap_pre_start() | |
17 | { | |
18 | local tuntap= | |
19 | local rc= | |
20 | eval tuntap=\$tuntap_${IFVAR} | |
21 | ||
22 | [ -z "${tuntap}" ] && return 0 | |
23 | ||
24 | if [ ! -e /dev/net/tun ]; then | |
25 | if ! modprobe tun; then | |
26 | eerror "TUN/TAP support is not present in this kernel" | |
27 | return 1 | |
28 | fi | |
29 | vebegin "Waiting for /dev/net/tun" | |
30 | # /dev/net/tun can take its time to appear | |
31 | local timeout=10 | |
32 | while [ ! -e /dev/net/tun -a ${timeout} -gt 0 ]; do | |
33 | sleep 1 | |
34 | : $(( timeout -= 1 )) | |
35 | done | |
36 | if [ ! -e /dev/net/tun ]; then | |
37 | eerror "TUN/TAP support present but /dev/net/tun is not" | |
38 | return 1 | |
39 | fi | |
40 | veend 0 | |
41 | fi | |
42 | ||
43 | ebegin "Creating Tun/Tap interface ${IFACE}" | |
44 | ||
45 | # Set the base metric to 1000 | |
46 | metric=1000 | |
47 | ||
48 | local i_opts= o_opts= t_opts= | |
49 | local do_iproute2=false do_openvpn=false do_tunctl=false | |
50 | eval i_opts=\$iproute2_${IFVAR} | |
51 | eval o_opts=\$openvpn_${IFVAR} | |
52 | eval t_opts=\$tunctl_${IFVAR} | |
53 | ||
54 | if [ -n "${i_opts}" ] && type ip >/dev/null 2>&1; then | |
55 | do_iproute2=true | |
56 | elif [ -n "${o_opts}" ] && type openvpn >/dev/null 2>&1; then | |
57 | do_openvpn=true | |
58 | elif [ -n "${t_opts}" ] && type tunctl >/dev/null 2>&1; then | |
59 | do_tunctl=true | |
60 | elif type ip >/dev/null 2>&1; then | |
61 | do_iproute2=true | |
62 | elif type openvpn >/dev/null 2>&1; then | |
63 | do_openvpn=true | |
64 | elif type tunctl >/dev/null 2>&1; then | |
65 | do_tunctl=true | |
66 | fi | |
67 | ||
68 | if ${do_iproute2}; then | |
69 | ip tuntap add dev "${IFACE}" mode "${tuntap}" ${i_opts} | |
70 | rc=$? | |
71 | elif ${do_openvpn}; then | |
72 | openvpn --mktun --dev-type "${tuntap}" --dev "${IFACE}" \ | |
73 | ${o_opts} >/dev/null | |
74 | rc=$? | |
75 | elif ${do_tunctl}; then | |
76 | tunctl ${t_opts} -t "${IFACE}" >/dev/null | |
77 | rc=$? | |
78 | else | |
79 | eerror "Neither iproute2, openvpn nor tunctl has been found, please install" | |
80 | eerror "either \"iproute2\" \"openvpn\" or \"usermode-utilities\"." | |
81 | rc=1 | |
82 | fi | |
83 | eend $rc && _up && service_set_value tuntap "${tuntap}" | |
84 | } | |
85 | ||
86 | tuntap_post_stop() | |
87 | { | |
88 | _is_tuntap || return 0 | |
89 | ||
90 | ebegin "Destroying Tun/Tap interface ${IFACE}" | |
91 | if type ip > /dev/null 2>&1; then | |
92 | ip tuntap del dev ${IFACE} mode $(service_get_value tuntap) | |
93 | elif type tunctl >/dev/null 2>&1; then | |
94 | tunctl -d "${IFACE}" >/dev/null | |
95 | else | |
96 | openvpn --rmtun \ | |
97 | --dev-type "$(service_get_value tuntap)" \ | |
98 | --dev "${IFACE}" >/dev/null | |
99 | fi | |
100 | eend $? | |
101 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | udhcpc_depend() | |
4 | { | |
5 | program start /bin/busybox | |
6 | after interface | |
7 | provide dhcp | |
8 | } | |
9 | ||
10 | _config_vars="$_config_vars dhcp udhcpc" | |
11 | ||
12 | udhcpc_start() | |
13 | { | |
14 | local args= opt= opts= pidfile="/var/run/udhcpc-${IFACE}.pid" | |
15 | local sendhost=true cachefile="/var/cache/udhcpc-${IFACE}.lease" | |
16 | ||
17 | eval args=\$udhcpc_${IFVAR} | |
18 | ||
19 | # Get our options | |
20 | eval opts=\$dhcp_${IFVAR} | |
21 | [ -z "${opts}" ] && opts=${dhcp} | |
22 | ||
23 | # This omits the Gentoo specific patch to busybox, | |
24 | # but it creates temporary files. | |
25 | # We can move this stuff to udhcpc hook script to avoid that, should we do? | |
26 | local conf="/var/run/udhcpc-${IFACE}.conf" | |
27 | echo -n >"$conf" | |
28 | # Map some generic options to dhcpcd | |
29 | for opt in ${opts}; do | |
30 | case "${opt}" in | |
31 | nodns) echo "PEER_DNS=no" >>"$conf" ;; | |
32 | nontp) echo "PEER_NTP=no" >>"$conf" ;; | |
33 | nogateway) echo "PEER_ROUTERS=no" >>"$conf" ;; | |
34 | nosendhost) sendhost=false; | |
35 | esac | |
36 | done | |
37 | ||
38 | [ "${metric:-0}" != "0" ] && echo "IF_METRIC=${metric}" >>"$conf" | |
39 | ||
40 | ebegin "Running udhcpc" | |
41 | ||
42 | # Try and load the cache if it exists | |
43 | if [ -f "${cachefile}" ]; then | |
44 | case "$ {args} " in | |
45 | *" --request="*|*" -r "*);; | |
46 | *) | |
47 | local x=$(cat "${cachefile}") | |
48 | # Check for a valid ip | |
49 | case "${x}" in | |
50 | *.*.*.*) args="${args} --request=${x}";; | |
51 | esac | |
52 | ;; | |
53 | esac | |
54 | fi | |
55 | ||
56 | case " ${args} " in | |
57 | *" --quit "*|*" -q "*) x="/bin/busybox udhcpc";; | |
58 | *) x="start-stop-daemon --start --exec /bin/busybox \ | |
59 | --pidfile \"${pidfile}\" -- udhcpc";; | |
60 | esac | |
61 | ||
62 | case " ${args} " in | |
63 | *" --hostname="*|*" -h "*|*" -H "*);; | |
64 | *) | |
65 | if ${sendhost}; then | |
66 | local hname="$(hostname)" | |
67 | if [ "${hname}" != "(none)" ] && [ "${hname}" != "localhost" ]; then | |
68 | args="${args} -x hostname:'${hname}'" | |
69 | fi | |
70 | fi | |
71 | ;; | |
72 | esac | |
73 | ||
74 | eval "${x}" "${args}" --interface="${IFACE}" --now \ | |
75 | --script="${RC_LIBEXECDIR}/sh/udhcpc-hook.sh" \ | |
76 | --pidfile="${pidfile}" >/dev/null | |
77 | eend $? || return 1 | |
78 | ||
79 | _show_address | |
80 | return 0 | |
81 | } | |
82 | ||
83 | udhcpc_stop() | |
84 | { | |
85 | local pidfile="/var/run/udhcpc-${IFACE}.pid" opts= | |
86 | [ ! -f "${pidfile}" ] && return 0 | |
87 | ||
88 | # Get our options | |
89 | eval opts=\$dhcp_${IFVAR} | |
90 | [ -z "${opts}" ] && opts=${dhcp} | |
91 | ||
92 | ebegin "Stopping udhcpc on ${IFACE}" | |
93 | case " ${opts} " in | |
94 | *" release "*) | |
95 | start-stop-daemon --stop --quiet --signal USR2 \ | |
96 | --exec /bin/busybox --pidfile "${pidfile}" | |
97 | if [ -f /var/cache/udhcpc-"${IFACE}".lease ]; then | |
98 | rm -f /var/cache/udhcpc-"${IFACE}".lease | |
99 | fi | |
100 | ;; | |
101 | esac | |
102 | ||
103 | start-stop-daemon --stop --exec /bin/busybox --pidfile "${pidfile}" | |
104 | eend $? | |
105 | ||
106 | if [ -e "/var/run/udhcpc-${IFACE}.conf" ]; then | |
107 | rm -f "/var/run/udhcpc-${IFACE}.conf" | |
108 | fi | |
109 | } |
0 | # Copyright (c) 2007-2008 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | vlan_depend() | |
4 | { | |
5 | program ip | |
6 | after interface | |
7 | before dhcp | |
8 | } | |
9 | ||
10 | _config_vars="$_config_vars vlans" | |
11 | ||
12 | _is_vlan() | |
13 | { | |
14 | [ ! -d /proc/net/vlan ] && return 1 | |
15 | [ -e /proc/net/vlan/"${IFACE}" ] && return 0 | |
16 | grep -Eq "^${IFACE}[[:space:]]+" /proc/net/vlan/config | |
17 | } | |
18 | ||
19 | _get_vlans() | |
20 | { | |
21 | [ -e /proc/net/vlan/config ] || return 1 | |
22 | sed -n -e 's/^\W*\([^ ]*\) \(.* \) .*'"${IFACE}"'$/\1/p' /proc/net/vlan/config | |
23 | } | |
24 | ||
25 | _check_vlan() | |
26 | { | |
27 | if [ ! -d /proc/net/vlan ]; then | |
28 | modprobe 8021q | |
29 | if [ ! -d /proc/net/vlan ]; then | |
30 | eerror "VLAN (802.1q) support is not present in this kernel" | |
31 | return 1 | |
32 | fi | |
33 | fi | |
34 | } | |
35 | ||
36 | vlan_pre_start() | |
37 | { | |
38 | local vconfig | |
39 | eval vconfig=\$vconfig_${IFVAR} | |
40 | if [ -n "${vconfig}" ]; then | |
41 | eerror "You must convert your vconfig_ VLAN entries to vlan${N} entries." | |
42 | return 1 | |
43 | fi | |
44 | local vlans= | |
45 | eval vlans=\$vlans_${IFVAR} | |
46 | [ -z "$vlans" ] && return 0 | |
47 | case " ${MODULES} " in | |
48 | *" ifconfig "*) | |
49 | eerror "sys-apps/iproute2 is required to configure VLANs" | |
50 | return 1 ;; | |
51 | esac | |
52 | } | |
53 | ||
54 | vlan_post_start() | |
55 | { | |
56 | local vlans= | |
57 | eval vlans=\$vlans_${IFVAR} | |
58 | [ -z "${vlans}" ] && return 0 | |
59 | ||
60 | _check_vlan || return 1 | |
61 | _exists || return 1 | |
62 | ||
63 | local vlan= e= s= vname= vflags= vingress= vegress= | |
64 | for vlan in ${vlans}; do | |
65 | einfo "Adding VLAN ${vlan} to ${IFACE}" | |
66 | # We need to gather all interface configuration options | |
67 | # 1) naming. Default to the standard "${IFACE}.${vlan}" but it can be anything | |
68 | eval vname=\$${IFACE}_vlan${vlan}_name | |
69 | [ -z "${vname}" ] && eval vname=\$vlan${vlan}_name | |
70 | [ -z "${vname}" ] && vname="${IFACE}.${vlan}" | |
71 | # 2) flags | |
72 | eval vflags=\$${IFACE}_vlan${vlan}_flags | |
73 | [ -z "${vname}" ] && eval vflags=\$vlan${vlan}_flags | |
74 | # 3) ingress/egress map | |
75 | eval vingress=\$${IFACE}_vlan${vlan}_ingress | |
76 | [ -z "${vingress}" ] && eval vingress=\$vlan${vlan}_ingress | |
77 | [ -z "${vingress}" ] || vingress="ingress-qos-map ${vingress}" | |
78 | eval vegress=\$${IFACE}_vlan${vlan}_egress | |
79 | [ -z "${vegress}" ] && eval vegress=\$vlan${vlan}_egress | |
80 | [ -z "${vegress}" ] || vegress="egress-qos-map ${vegress}" | |
81 | ||
82 | # txqueue | |
83 | local txqueuelen= | |
84 | eval txqueuelen=\$txqueuelen_${IFACE}_vlan${vlan} | |
85 | [ -z "${txqueuelen}" ] && eval txqueuelen=\$txqueuelen_vlan${vlan} | |
86 | # mac | |
87 | local mac= | |
88 | eval mac=\$mac_${IFACE}_vlan${vlan} | |
89 | [ -z "${mac}" ] && eval mac=\$mac_vlan${vlan} | |
90 | # broadcast | |
91 | local broadcast= | |
92 | eval broadcast=\$broadcast_${IFACE}_vlan${vlan} | |
93 | [ -z "${broadcast}" ] && eval broadcast=\$broadcast_vlan${vlan} | |
94 | # mtu | |
95 | local mtu= | |
96 | eval mtu=\$mtu_${IFACE}_vlan${vlan} | |
97 | [ -z "${mtu}" ] && eval mtu=\$mtu_vlan${vlan} | |
98 | ||
99 | # combine it all | |
100 | local opts="${txqueuelen:+txqueuelen} ${txqueuelen} ${mac:+address} ${mac} ${broadcast:+broadcast} ${broadcast} ${mtu:+mtu} ${mtu}" | |
101 | ||
102 | veinfo "ip link add link \"${IFACE}\" name \"${vname}\" ${opts} type vlan id \"${vlan}\" ${vflags} ${vingress} ${vegress}" | |
103 | e="$(ip link add link "${IFACE}" name "${vname}" ${opts} type vlan id "${vlan}" ${vflags} ${vingress} ${vegress} 2>&1 1>/dev/null)" | |
104 | if [ -n "${e}" ]; then | |
105 | eend 1 "${e}" | |
106 | continue | |
107 | fi | |
108 | ||
109 | # We may not want to start the vlan ourselves | |
110 | eval s=\$vlan_start_${IFVAR} | |
111 | yesno ${s:-yes} || continue | |
112 | ||
113 | # We need to work out the interface name of our new vlan id | |
114 | local ifname="$(sed -n -e \ | |
115 | 's/^\([^[:space:]]*\) *| '"${vlan}"' *| .*'"${IFACE}"'$/\1/p' \ | |
116 | /proc/net/vlan/config )" | |
117 | mark_service_started "net.${ifname}" | |
118 | ( | |
119 | export RC_SVCNAME="net.${ifname}" | |
120 | start | |
121 | ) || mark_service_stopped "net.${ifname}" | |
122 | done | |
123 | ||
124 | return 0 | |
125 | } | |
126 | ||
127 | vlan_pre_stop() | |
128 | { | |
129 | local vlan= | |
130 | ||
131 | _exists || return 0 | |
132 | ||
133 | for vlan in $(_get_vlans); do | |
134 | einfo "Removing VLAN ${vlan##*.} from ${IFACE}" | |
135 | ( | |
136 | export RC_SVCNAME="net.${vlan}" | |
137 | stop | |
138 | ) && { | |
139 | mark_service_stopped "net.${vlan}" | |
140 | ip link delete "${vlan}" type vlan >/dev/null | |
141 | } | |
142 | done | |
143 | ||
144 | return 0 | |
145 | } |
0 | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> | |
1 | # Released under the 2-clause BSD license. | |
2 | ||
3 | wpa_supplicant_depend() | |
4 | { | |
5 | wpas=/usr/sbin/wpa_supplicant | |
6 | [ -x ${wpas} ] || wpas=/sbin/wpa_supplicant | |
7 | if [ -x ${wpas} ]; then | |
8 | program start ${wpas} | |
9 | # bug 345281: if wpa_supplicant is built w/ USE=dbus, we need to start | |
10 | # dbus before we can start wpa_supplicant. | |
11 | ${wpas} -h |grep DBus -sq | |
12 | [ $? -eq 0 ] && need dbus | |
13 | fi | |
14 | after macnet plug | |
15 | before interface | |
16 | provide wireless | |
17 | ||
18 | # Prefer us over iwconfig | |
19 | after iwconfig | |
20 | } | |
21 | ||
22 | # Only set these functions if not set already | |
23 | # IE, prefer to use iwconfig | |
24 | if ! type _get_ssid >/dev/null 2>&1; then | |
25 | _get_ssid() | |
26 | { | |
27 | local timeout=5 ssid= | |
28 | ||
29 | while [ ${timeout} -gt 0 ]; do | |
30 | ssid=$(wpa_cli -i"${IFACE}" status | sed -n -e 's/^ssid=//p') | |
31 | if [ -n "${ssid}" ]; then | |
32 | echo "${ssid}" | |
33 | return 0 | |
34 | fi | |
35 | sleep 1 | |
36 | : $(( timeout -= 1 )) | |
37 | done | |
38 | ||
39 | return 1 | |
40 | } | |
41 | ||
42 | _get_ap_mac_address() | |
43 | { | |
44 | wpa_cli -i"${IFACE}" status | sed -n -e 's/^bssid=\(.*\)$/\1/p' \ | |
45 | | tr '[:lower:]' '[:upper:]' | |
46 | } | |
47 | fi | |
48 | ||
49 | wpa_supplicant_pre_start() | |
50 | { | |
51 | local opts= cliopts= cfgfile= ctrl_dir= wireless=true | |
52 | local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli | |
53 | local actfile=/etc/wpa_supplicant/wpa_cli.sh | |
54 | ||
55 | if [ ! -x "${wpas}" ]; then | |
56 | wpas=/sbin/wpa_supplicant | |
57 | wpac=/bin/wpa_cli | |
58 | fi | |
59 | [ "${RC_UNAME}" = "Linux" ] || unset wpac | |
60 | [ -e "${actfile}" ] || unset wpac | |
61 | ||
62 | eval opts=\$wpa_supplicant_${IFVAR} | |
63 | eval cliopts=\$wpa_cli_${IFVAR} | |
64 | [ -z "${cliopts}" ] && cliopts=${wpa_cli} | |
65 | case " ${opts} " in | |
66 | *" -Dwired "*) wireless=false;; | |
67 | *) _is_wireless || return 0;; | |
68 | esac | |
69 | ||
70 | # We don't configure wireless if we're being called from | |
71 | # the background unless we're not currently running | |
72 | if yesno ${IN_BACKGROUND}; then | |
73 | if ${wireless} && \ | |
74 | service_started_daemon "${RC_SVCNAME}" "${wpas}"; then | |
75 | SSID=$(_get_ssid "${IFACE}") | |
76 | SSIDVAR=$(shell_var "${SSID}") | |
77 | service_set_value "SSID" "${SSID}" | |
78 | metric=2000 | |
79 | fi | |
80 | return 0 | |
81 | fi | |
82 | ||
83 | service_set_value "SSID" "" | |
84 | ebegin "Starting wpa_supplicant on ${IFVAR}" | |
85 | ||
86 | if type iwconfig_defaults >/dev/null 2>&1; then | |
87 | iwconfig_defaults | |
88 | iwconfig_user_config | |
89 | fi | |
90 | ||
91 | cfgfile=${opts##* -c} | |
92 | if [ -n "${cfgfile}" -a "${cfgfile}" != "${opts}" ]; then | |
93 | case "${cfgfile}" in | |
94 | " "*) cfgfile=${cfgfile# *};; | |
95 | esac | |
96 | cfgfile=${cfgfile%% *} | |
97 | else | |
98 | # Support new and old style locations | |
99 | cfgfile="/etc/wpa_supplicant/wpa_supplicant-${IFACE}.conf" | |
100 | [ ! -e "${cfgfile}" ] \ | |
101 | && cfgfile="/etc/wpa_supplicant/wpa_supplicant.conf" | |
102 | [ ! -e ${cfgfile} ] \ | |
103 | && cfgfile="/etc/wpa_supplicant.conf" | |
104 | opts="${opts} -c ${cfgfile}" | |
105 | fi | |
106 | ||
107 | if [ ! -f ${cfgfile} ]; then | |
108 | eend 1 "/etc/wpa_supplicant/wpa_supplicant.conf not found" | |
109 | return 1 | |
110 | fi | |
111 | ||
112 | # Work out where the ctrl_interface dir is if it's not specified | |
113 | local ctrl_dir=$(sed -e 's/^ *//' \ | |
114 | -e '/^ctrl_interface=/!d' \ | |
115 | -e 's/^ctrl_interface=//' \ | |
116 | -e 's/^ *//' \ | |
117 | -e 's/^DIR=//' \ | |
118 | -e 's/^ *//' \ | |
119 | -e 's/GROUP=.*//' \ | |
120 | -e 's/ *$//' \ | |
121 | "${cfgfile}") | |
122 | if [ -z "${ctrl_dir}" ]; then | |
123 | ctrl_dir=${opts##* -C} | |
124 | if [ -n "${ctrl_dir}" -a "${ctrl_dir}" != "${opts}" ]; then | |
125 | case "${ctrl_dir}" in | |
126 | " "*) ctrl_dir=${ctrl_dir# *};; | |
127 | esac | |
128 | ctrl_dir=${ctrl_dir%% *} | |
129 | else | |
130 | ctrl_dir="/var/run/wpa_supplicant" | |
131 | opts="${opts} -C ${ctrl_dir}" | |
132 | fi | |
133 | fi | |
134 | service_set_value ctrl_dir "${ctrl_dir}" | |
135 | ||
136 | if [ -n "${wpac}" ]; then | |
137 | opts="${opts} -W" | |
138 | elif service_started devd; then | |
139 | mark_service_inactive | |
140 | fi | |
141 | start-stop-daemon --start --exec "${wpas}" \ | |
142 | --pidfile "/var/run/wpa_supplicant-${IFACE}.pid" \ | |
143 | -- ${opts} -B -i "${IFACE}" \ | |
144 | -P "/var/run/wpa_supplicant-${IFACE}.pid" | |
145 | eend $? || return 1 | |
146 | ||
147 | # If we don't have a working wpa_cli and action file continue | |
148 | if [ -z "${wpac}" ]; then | |
149 | if service_started devd; then | |
150 | ebegin "Backgrounding ..." | |
151 | exit 1 | |
152 | fi | |
153 | return 0 | |
154 | fi | |
155 | ||
156 | # Starting wpa_supplication-0.4.0, we can get wpa_cli to | |
157 | # start/stop our scripts from wpa_supplicant messages | |
158 | local inact=false | |
159 | service_inactive && inact=true | |
160 | mark_service_inactive | |
161 | ||
162 | ebegin "Starting wpa_cli on" "${IFACE}" | |
163 | start-stop-daemon --start --exec "${wpac}" \ | |
164 | --pidfile "/var/run/wpa_cli-${IFACE}.pid" \ | |
165 | -- ${cliopts} -a "${actfile}" -p "${ctrl_dir}" -i "${IFACE}" \ | |
166 | -P "/var/run/wpa_cli-${IFACE}.pid" -B | |
167 | if eend $?; then | |
168 | ebegin "Backgrounding ..." | |
169 | exit 1 | |
170 | fi | |
171 | ||
172 | # wpa_cli failed to start? OK, error here | |
173 | start-stop-daemon --quiet --stop --exec "${wpas}" \ | |
174 | --pidfile "/var/run/wpa_supplicant-${IFACE}.pid" | |
175 | ${inact} || mark_service_stopped | |
176 | return 1 | |
177 | } | |
178 | ||
179 | wpa_supplicant_post_stop() | |
180 | { | |
181 | local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli | |
182 | ||
183 | if [ ! -x "${wpas}" ]; then | |
184 | wpas=/sbin/wpa_supplicant | |
185 | wpac=/bin/wpa_cli | |
186 | fi | |
187 | ||
188 | if yesno "${IN_BACKGROUND}"; then | |
189 | # Only stop wpa_supplicant if it's not the controlling daemon | |
190 | ! service_started_daemon "${RC_SVCNAME}" "${wpas}" 1 | |
191 | fi | |
192 | [ $? != 0 ] && return 0 | |
193 | ||
194 | local pidfile="/var/run/wpa_cli-${IFACE}.pid" | |
195 | if [ -f ${pidfile} ]; then | |
196 | ebegin "Stopping wpa_cli on ${IFACE}" | |
197 | start-stop-daemon --stop --exec "${wpac}" --pidfile "${pidfile}" | |
198 | eend $? | |
199 | fi | |
200 | ||
201 | pidfile="/var/run/wpa_supplicant-${IFACE}.pid" | |
202 | if [ -f ${pidfile} ]; then | |
203 | ebegin "Stopping wpa_supplicant on ${IFACE}" | |
204 | start-stop-daemon --stop --exec "${wpas}" --pidfile "${pidfile}" | |
205 | eend $? | |
206 | fi | |
207 | ||
208 | # If wpa_supplicant exits uncleanly, we need to remove the stale dir | |
209 | [ -S "/var/run/wpa_supplicant/${IFACE}" ] \ | |
210 | && rm -f "/var/run/wpa_supplicant/${IFACE}" | |
211 | } |
0 | include ../mk/net.mk | |
1 | ||
2 | BOOT= bootmisc fsck hostname localmount loopback \ | |
0 | BOOT= bootmisc fsck hostname localmount \ | |
3 | 1 | root swap swapfiles sysctl urandom ${BOOT-${OS}} |
4 | 2 | DEFAULT= local netmount |
5 | 3 | SHUTDOWN= savecache ${SHUTDOWN-${OS}} |
11 | 9 | DEFAULTDIR= ${LEVELDIR}/default |
12 | 10 | SHUTDOWNDIR= ${LEVELDIR}/shutdown |
13 | 11 | |
14 | ifeq (${MKNET},yes) | |
12 | ifeq (${MKNET},) | |
15 | 13 | BOOT+= network staticroute |
16 | 14 | endif |
17 | 15 | |
26 | 24 | SHUTDOWN-${OS}= |
27 | 25 | SYSINIT-${OS}= |
28 | 26 | |
27 | ifeq (${MKNET},oldnet) | |
28 | BOOT-FreeBSD+= net.lo0 | |
29 | BOOT-Linux+= net.lo | |
30 | BOOT-NetBSD+= net.lo0 | |
31 | endif | |
32 | ||
29 | 33 | BOOT-BSD= hostid newsyslog savecore syslogd swap-blk |
30 | 34 | |
31 | 35 | # Generic BSD stuff |
35 | 39 | |
36 | 40 | BOOT-Linux+= hwclock keymaps modules mtab procfs termencoding tmpfiles.setup |
37 | 41 | SHUTDOWN-Linux= killprocs mount-ro |
38 | SYSINIT-Linux= devfs dmesg sysfs tmpfiles.dev | |
42 | SYSINIT-Linux= devfs dmesg sysfs | |
39 | 43 | |
40 | 44 | # Generic BSD stuff |
41 | 45 | BOOT-NetBSD+= hostid newsyslog savecore syslogd |
48 | 52 | if ! test -d "${SYSINITDIR}"; then \ |
49 | 53 | ${INSTALL} -d ${SYSINITDIR} || exit $$?; \ |
50 | 54 | for x in ${SYSINIT}; do \ |
51 | if test "${MKPREFIX}" = yes; then \ | |
55 | if test -n "${PREFIX}"; then \ | |
52 | 56 | grep -q "keyword .*-prefix" ${INITFILES}/"$$x" && continue; \ |
53 | 57 | fi; \ |
54 | 58 | ln -snf ${INITDIR}/"$$x" ${SYSINITDIR}/"$$x" || exit $$?; done \ |
56 | 60 | if ! test -d "${BOOTDIR}"; then \ |
57 | 61 | ${INSTALL} -d ${BOOTDIR} || exit $$?; \ |
58 | 62 | for x in ${BOOT}; do \ |
59 | if test "${MKPREFIX}" = yes; then \ | |
63 | if test -n "${PREFIX}"; then \ | |
60 | 64 | grep -q "keyword .*-prefix" ${INITFILES}/"$$x" && continue; \ |
61 | 65 | fi; \ |
62 | 66 | ln -snf ${INITDIR}/"$$x" ${BOOTDIR}/"$$x" || exit $$?; \ |
65 | 69 | if ! test -d "${DEFAULTDIR}"; then \ |
66 | 70 | ${INSTALL} -d ${DEFAULTDIR} || exit $$?; \ |
67 | 71 | for x in ${DEFAULT}; do \ |
68 | if test "${MKPREFIX}" = yes; then \ | |
72 | if test -n "${PREFIX}"; then \ | |
69 | 73 | grep -q "keyword .*-prefix" ${INITFILES}/"$$x" && continue; \ |
70 | 74 | fi; \ |
71 | 75 | ln -snf ${INITDIR}/"$$x" ${DEFAULTDIR}/"$$x" || exit $$?; done \ |
73 | 77 | if ! test -d "${SHUTDOWNDIR}"; then \ |
74 | 78 | ${INSTALL} -d ${SHUTDOWNDIR} || exit $$?; \ |
75 | 79 | for x in ${SHUTDOWN}; do \ |
76 | if test "${MKPREFIX}" = yes; then \ | |
80 | if test -n "${PREFIX}"; then \ | |
77 | 81 | grep -q "keyword .*-prefix" ${INITFILES}/"$$x" && continue; \ |
78 | 82 | fi; \ |
79 | 83 | ln -snf ${INITDIR}/"$$x" ${SHUTDOWNDIR}/"$$x" || exit $$?; done \ |
5 | 5 | cgroup-release-agent.sh |
6 | 6 | init.sh |
7 | 7 | init-early.sh |
8 | rc-cgroup.sh | |
8 | ifwatchd-carrier.sh | |
9 | ifwatchd-nocarrier.sh | |
10 | udhcpc-hook.sh | |
9 | 11 | tmpfiles.sh |
10 | 12 | migrate-to-run.sh |
12 | 12 | BIN-FreeBSD= |
13 | 13 | |
14 | 14 | SRCS-Linux= cgroup-release-agent.sh.in init-early.sh.in migrate-to-run.sh.in \ |
15 | rc-cgroup.sh.in | |
15 | udhcpc-hook.sh.in | |
16 | 16 | BIN-Linux= cgroup-release-agent.sh init-early.sh migrate-to-run.sh \ |
17 | rc-cgroup.sh | |
17 | udhcpc-hook.sh | |
18 | 18 | |
19 | SRCS-NetBSD= | |
20 | BIN-NetBSD= | |
19 | SRCS-NetBSD= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in | |
20 | BIN-NetBSD= ifwatchd-carrier.sh ifwatchd-nocarrier.sh | |
21 | 21 | |
22 | 22 | include ${MK}/scripts.mk |
23 | 23 |
4 | 4 | |
5 | 5 | cgroup=/sys/fs/cgroup/openrc |
6 | 6 | PATH=/bin:/usr/bin:/sbin:/usr/sbin |
7 | if [ -d ${cgroup}/"$1" ]; then | |
8 | rmdir ${cgroup}/"$1" | |
7 | if [ -d ${cgroup}/$1 ]; then | |
8 | rmdir ${cgroup}/$1 | |
9 | 9 | fi |
48 | 48 | for p in $PATH; do |
49 | 49 | case "$p" in |
50 | 50 | @LIBEXECDIR@/bin|@LIBEXECDIR@/sbin);; |
51 | @BINDIR@|@SBINDIR@|/usr/bin|/usr/sbin);; | |
51 | @PREFIX@/bin|@PREFIX@/sbin|/usr/bin|/usr/sbin);; | |
52 | 52 | @PKG_PREFIX@/bin|@PKG_PREFIX@/sbin);; |
53 | 53 | @LOCAL_PREFIX@/bin|@LOCAL_PREFIX@/sbin);; |
54 | 54 | *) path="$path${path:+:}$p";; |
84 | 84 | _PATH="$_PATH:$_LOCAL_PREFIX/bin:$_LOCAL_PREFIX/sbin" |
85 | 85 | fi |
86 | 86 | _path="$(_sanitize_path "$PATH")" |
87 | PATH="$_PATH${_path:+:}$_path" ; export PATH | |
87 | export PATH="$_PATH${_path:+:}$_path" | |
88 | 88 | unset _sanitize_path _PREFIX _PKG_PREFIX _LOCAL_PREFIX _PATH _path |
89 | 89 | |
90 | 90 | for arg; do |
91 | 91 | case "$arg" in |
92 | 92 | --nocolor|--nocolour|-C) |
93 | EINFO_COLOR="NO" ; export EINFO_COLOR | |
93 | export EINFO_COLOR="NO" | |
94 | 94 | ;; |
95 | 95 | esac |
96 | 96 | done |
105 | 105 | for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \ |
106 | 106 | vebegin veend veinfo vewarn vewend; do |
107 | 107 | eval "$_e() { local _r; command $_e \"\$@\"; _r=\$?; \ |
108 | EINFO_LASTCMD=$_e; export EINFO_LASTCMD ; return \$_r; }" | |
108 | export EINFO_LASTCMD=$_e; return \$_r; }" | |
109 | 109 | done |
110 | 110 | unset _e |
111 | 111 | fi |
52 | 52 | |
53 | 53 | # Only generate dependencies for runscripts |
54 | 54 | read one two three <"$RC_SERVICE" |
55 | [ "$one" = "#!@SBINDIR@/runscript" ] || \ | |
56 | [ "$one" = "#!" -a "$two" = "@SBINDIR@/runscript" ] || \ | |
55 | [ "$one" = "#!@PREFIX@/sbin/runscript" ] || \ | |
56 | [ "$one" = "#!" -a "$two" = "@PREFIX@/sbin/runscript" ] || \ | |
57 | 57 | continue |
58 | 58 | unset one two three |
59 | 59 | |
60 | RC_SVCNAME=${RC_SERVICE##*/} ; export RC_SVCNAME | |
60 | export RC_SVCNAME=${RC_SERVICE##*/} | |
61 | 61 | |
62 | 62 | # Compat |
63 | SVCNAME=$RC_SVCNAME ; export SVCNAME | |
63 | export SVCNAME=$RC_SVCNAME | |
64 | 64 | |
65 | 65 | ( |
66 | 66 | # Save stdout in fd3, then remap it to stderr |
6 | 6 | |
7 | 7 | service_present() |
8 | 8 | { |
9 | local p="@SYSCONFDIR@/runlevels/$1/$2" | |
9 | local p="/etc/runlevels/$1/$2" | |
10 | 10 | # fail if the file doesn't exist |
11 | 11 | [ ! -e "$p" ] && return 1 |
12 | 12 | # succeed if $RC_SYS empty, can't check further, assume script will run |
29 | 29 | if service_present "$RC_DEFAULTLEVEL" consolefont || |
30 | 30 | service_present "$RC_BOOTLEVEL" consolefont; then |
31 | 31 | printf "\033%s" "$termencoding" >"$CONSOLE" 2>/dev/null |
32 | if [ -r "$RC_LIBEXECDIR"/console/font ] && \ | |
33 | type setfont > /dev/null 2>&1; then | |
32 | if [ -r "$RC_LIBEXECDIR"/console/font -a -x /usr/bin/setfont ]; then | |
33 | font="$(cat "$RC_LIBEXECDIR"/console/font)" | |
34 | 34 | [ -c "$CONSOLE" ] && cons="-C $CONSOLE" |
35 | setfont $cons "$RC_LIBEXECDIR"/console/font 2>/dev/null | |
35 | setfont $cons "$RC_LIBEXECDIR"/console/"$font" 2>/dev/null | |
36 | 36 | fi |
37 | 37 | fi |
38 | 38 |
21 | 21 | } |
22 | 22 | |
23 | 23 | . "$RC_LIBEXECDIR"/sh/functions.sh |
24 | [ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf" | |
24 | [ -r /etc/rc.conf ] && . /etc/rc.conf | |
25 | 25 | |
26 | 26 | # Disable devd until we need it |
27 | 27 | if [ -z "$RC_SYS" -a "$RC_UNAME" = "FreeBSD" ]; then |
3 | 3 | # Released under the 2-clause BSD license. |
4 | 4 | |
5 | 5 | . "$RC_LIBEXECDIR"/sh/functions.sh |
6 | [ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf" | |
6 | [ -r /etc/rc.conf ] && . /etc/rc.conf | |
7 | 7 | |
8 | 8 | # By default VServer already has /proc mounted, but OpenVZ does not! |
9 | 9 | # However, some of our users have an old proc image in /proc |
50 | 50 | fi |
51 | 51 | fi |
52 | 52 | |
53 | if [ -L /run/openrc ]; then | |
54 | rm /run/openrc | |
55 | fi | |
56 | ||
53 | 57 | if [ "$sys" = VSERVER ]; then |
54 | 58 | rm -rf /run/* |
55 | 59 | elif ! mountinfo -q /run; then |
56 | 60 | ebegin "Mounting /run" |
57 | 61 | rc=0 |
58 | 62 | if ! fstabinfo --mount /run; then |
59 | mount -t tmpfs -o mode=0755,nosuid,nodev,size=10% tmpfs /run | |
63 | mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run | |
60 | 64 | rc=$? |
61 | 65 | fi |
62 | 66 | if [ $rc != 0 ]; then |
3 | 3 | |
4 | 4 | . "@LIBEXECDIR@/sh/functions.sh" |
5 | 5 | |
6 | if [ -e /run/openrc/softlevel ]; then | |
6 | if ! mountinfo -q -f tmpfs "@LIBEXECDIR@/init.d"; then | |
7 | 7 | einfo "The OpenRC dependency data has already been migrated." |
8 | 8 | exit 0 |
9 | 9 | fi |
0 | #!@SHELL@ | |
1 | # Copyright (c) 2012 Alexander Vershilov <qnikst@gentoo.org> | |
2 | # Released under the 2-clause BSD license. | |
3 | extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup" | |
4 | ||
5 | cgroup_find_path() | |
6 | { | |
7 | local OIFS n name dir result | |
8 | [ -n "$1" ] || return 0 | |
9 | OIFS="$IFS" | |
10 | IFS=":" | |
11 | while read n name dir; do | |
12 | [ "$name" = "$1" ] && result="$dir" | |
13 | done < /proc/1/cgroup | |
14 | IFS="$OIFS" | |
15 | echo $result | |
16 | } | |
17 | ||
18 | cgroup_get_pids() | |
19 | { | |
20 | local p | |
21 | pids= | |
22 | while read p; do | |
23 | [ $p -eq $$ ] || pids="${pids} ${p}" | |
24 | done < /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks | |
25 | [ -n "$pids" ] | |
26 | } | |
27 | ||
28 | cgroup_running() | |
29 | { | |
30 | [ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ] | |
31 | } | |
32 | ||
33 | cgroup_set_values() | |
34 | { | |
35 | [ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0 | |
36 | ||
37 | local controller="$1" h=$(cgroup_find_path "$1") | |
38 | cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}" | |
39 | [ -d "$cgroup" ] || mkdir -p "$cgroup" | |
40 | ||
41 | set -- $2 | |
42 | local name val | |
43 | while [ -n "$1" -a "$controller" != "cpuacct" ]; do | |
44 | case "$1" in | |
45 | $controller.*) | |
46 | if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then | |
47 | veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val" | |
48 | echo $val > "$cgroup/$name" | |
49 | fi | |
50 | name=$1 | |
51 | val= | |
52 | ;; | |
53 | *) | |
54 | val="$val $1" | |
55 | ;; | |
56 | esac | |
57 | shift | |
58 | done | |
59 | if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then | |
60 | veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val" | |
61 | echo $val > "$cgroup/$name" | |
62 | fi | |
63 | ||
64 | if [ -f "$cgroup/tasks" ]; then | |
65 | veinfo "$RC_SVCNAME: adding to $cgroup/tasks" | |
66 | echo 0 > "$cgroup/tasks" | |
67 | fi | |
68 | ||
69 | return 0 | |
70 | } | |
71 | ||
72 | cgroup_add_service() | |
73 | { | |
74 | # relocate starting process to the top of the cgroup | |
75 | # it prevents from unwanted inheriting of the user | |
76 | # cgroups. But may lead to a problems where that inheriting | |
77 | # is needed. | |
78 | for d in /sys/fs/cgroup/* ; do | |
79 | [ -f "${d}"/tasks ] && echo 0 > "${d}"/tasks | |
80 | done | |
81 | ||
82 | openrc_cgroup=/sys/fs/cgroup/openrc | |
83 | if [ -d "$openrc_cgroup" ]; then | |
84 | cgroup="$openrc_cgroup/$RC_SVCNAME" | |
85 | mkdir -p "$cgroup" | |
86 | [ -f "$cgroup/tasks" ] && echo 0 > "$cgroup/tasks" | |
87 | fi | |
88 | } | |
89 | ||
90 | cgroup_set_limits() | |
91 | { | |
92 | local blkio="${rc_cgroup_blkio:-$RC_CGROUP_BLKIO}" | |
93 | [ -n "$blkio" ] && cgroup_set_values blkio "$blkio" | |
94 | ||
95 | local cpu="${rc_cgroup_cpu:-$RC_CGROUP_CPU}" | |
96 | [ -n "$cpu" ] && cgroup_set_values cpu "$cpu" | |
97 | ||
98 | local cpuacct="${rc_cgroup_cpuacct:-$RC_CGROUP_CPUACCT}" | |
99 | [ -n "$cpuacct" ] && cgroup_set_values cpuacct "$cpuacct" | |
100 | ||
101 | local cpuset="${rc_cgroup_cpuset:-$RC_CGROUP_cpuset}" | |
102 | [ -n "$cpuset" ] && cgroup_set_values cpuset "$cpuset" | |
103 | ||
104 | local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}" | |
105 | [ -n "$devices" ] && cgroup_set_values devices "$devices" | |
106 | ||
107 | local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}" | |
108 | [ -n "$memory" ] && cgroup_set_values memory "$memory" | |
109 | ||
110 | local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}" | |
111 | [ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio" | |
112 | ||
113 | return 0 | |
114 | } | |
115 | ||
116 | cgroup_cleanup() | |
117 | { | |
118 | yesno "${rc_cgroup_cleanup:-no}" && cgroup_running || return 0 | |
119 | ebegin "starting cgroups cleanup" | |
120 | for sig in TERM QUIT INT; do | |
121 | cgroup_get_pids || { eend 0 "finished" ; return 0 ; } | |
122 | for i in 0 1; do | |
123 | kill -s $sig $pids | |
124 | for j in 0 1 2; do | |
125 | cgroup_get_pids || { eend 0 "finished" ; return 0 ; } | |
126 | sleep 1 | |
127 | done | |
128 | done 2>/dev/null | |
129 | done | |
130 | cgroup_get_pids || { eend 0 "finished" ; return 0; } | |
131 | kill -9 $pids | |
132 | eend $(cgroup_running && echo 1 || echo 0) "fail to stop all processes" | |
133 | } |
37 | 37 | ( import_addon "$1-stop" ) |
38 | 38 | } |
39 | 39 | |
40 | net_fs_list="afs ceph cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre | |
40 | net_fs_list="afs cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre | |
41 | 41 | ncpfs nfs nfs4 ocfs2 shfs smbfs" |
42 | 42 | is_net_fs() |
43 | 43 | { |
108 | 108 | # Add our sbin to $PATH |
109 | 109 | case "$PATH" in |
110 | 110 | "$RC_LIBEXECDIR"/sbin|"$RC_LIBEXECDIR"/sbin:*);; |
111 | *) PATH="$RC_LIBEXECDIR/sbin:$PATH" ; export PATH ;; | |
111 | *) export PATH="$RC_LIBEXECDIR/sbin:$PATH";; | |
112 | 112 | esac |
40 | 40 | retry=4 # Effectively TERM, sleep 1, TERM, sleep 1, KILL, sleep 1 |
41 | 41 | while ! LC_ALL=C $cmd "$mnt" 2>/dev/null; do |
42 | 42 | if type fuser >/dev/null 2>&1; then |
43 | pids="$(timeout -k 10 -s KILL "${rc_fuser_timeout:-60}" \ | |
44 | fuser $f_opts "$mnt" 2>/dev/null)" | |
43 | pids="$(fuser $f_opts "$mnt" 2>/dev/null)" | |
45 | 44 | fi |
46 | 45 | case " $pids " in |
47 | 46 | *" $$ "*) |
33 | 33 | |
34 | 34 | sourcex "@LIBEXECDIR@/sh/functions.sh" |
35 | 35 | sourcex "@LIBEXECDIR@/sh/rc-functions.sh" |
36 | [ "$RC_SYS" != "PREFIX" ] && sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh" | |
37 | 36 | |
38 | 37 | # Support LiveCD foo |
39 | 38 | if sourcex -e "/sbin/livecd-functions.sh"; then |
46 | 45 | fi |
47 | 46 | |
48 | 47 | # So daemons know where to recall us if needed |
49 | RC_SERVICE="$1" ; export RC_SERVICE | |
48 | export RC_SERVICE="$1" | |
50 | 49 | shift |
51 | 50 | |
52 | 51 | # Compat |
53 | SVCNAME=$RC_SVCNAME ; export SVCNAME | |
52 | export SVCNAME=$RC_SVCNAME | |
54 | 53 | |
55 | 54 | # Dependency function |
56 | 55 | config() { |
145 | 144 | ${pidfile:+--pidfile} $pidfile \ |
146 | 145 | $_background $start_stop_daemon_args \ |
147 | 146 | -- $command_args |
148 | if eend $? "Failed to start $RC_SVCNAME"; then | |
149 | service_set_value "command" "${command}" | |
150 | [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}" | |
151 | [ -n "${procname}" ] && service_set_value "procname" "${procname}" | |
152 | return 0 | |
153 | fi | |
147 | eend $? "Failed to start $RC_SVCNAME" && return 0 | |
154 | 148 | if yesno "$start_inactive"; then |
155 | 149 | if ! $_inactive; then |
156 | 150 | mark_service_stopped |
161 | 155 | |
162 | 156 | stop() |
163 | 157 | { |
164 | local startcommand="$(service_get_value "command")" | |
165 | local startpidfile="$(service_get_value "pidfile")" | |
166 | local startprocname="$(service_get_value "procname")" | |
167 | command="${startcommand:-$command}" | |
168 | pidfile="${startpidfile:-$pidfile}" | |
169 | procname="${startprocname:-$procname}" | |
170 | 158 | [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0 |
171 | 159 | ebegin "Stopping ${name:-$RC_SVCNAME}" |
172 | 160 | start-stop-daemon --stop \ |
204 | 192 | # Load any system overrides |
205 | 193 | sourcex -e "@SYSCONFDIR@/rc.conf" |
206 | 194 | |
195 | if [ "$RC_UNAME" = "Linux" -a "$1" = "start" ]; then | |
196 | if [ -d /sys/fs/cgroup/openrc ]; then | |
197 | mkdir -p /sys/fs/cgroup/openrc/${RC_SVCNAME} | |
198 | echo $$ > /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks | |
199 | fi | |
200 | #todo: add processes to cgroups based on settings in conf.d | |
201 | fi | |
202 | ||
207 | 203 | # Apply any ulimit defined |
208 | 204 | [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT} |
209 | ||
210 | # Apply cgroups settings if defined | |
211 | if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then | |
212 | cgroup_add_service /sys/fs/cgroup/openrc | |
213 | cgroup_add_service /sys/fs/cgroup/systemd/system | |
214 | fi | |
215 | [ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && \ | |
216 | cgroup_set_limits | |
217 | 205 | |
218 | 206 | # Load our script |
219 | 207 | sourcex "$RC_SERVICE" |
305 | 293 | then |
306 | 294 | "$1"_post || exit $? |
307 | 295 | fi |
308 | [ "$(command -v cgroup_cleanup)" = "cgroup_cleanup" -a \ | |
309 | "$1" = "stop" ] && \ | |
310 | cgroup_cleanup | |
311 | 296 | shift |
312 | 297 | continue 2 |
313 | 298 | else |
13 | 13 | # |
14 | 14 | |
15 | 15 | DRYRUN=0 |
16 | ||
17 | checkprefix() { | |
18 | n=$1 | |
19 | shift | |
20 | for x in $@; do | |
21 | case $n in | |
22 | ${x}*) return 0 ;; | |
23 | esac | |
24 | done | |
25 | return 1 | |
26 | } | |
27 | 16 | |
28 | 17 | warninvalid() { |
29 | 18 | printf "tmpfiles: ignoring invalid entry on line %d of \`%s'\n" "$LINENUM" "$FILE" |
53 | 42 | _b() { |
54 | 43 | # Create a block device node if it doesn't exist yet |
55 | 44 | local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6 |
56 | if [ ! -e "$path" ]; then | |
57 | dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:} | |
58 | dryrun_or_real chown $uid:$gid $path | |
59 | fi | |
45 | [ ! -e "$path" ] && dryrun_or_real mknod $path b ${arg%:*} ${arg#*:} | |
60 | 46 | } |
61 | 47 | |
62 | 48 | _c() { |
63 | 49 | # Create a character device node if it doesn't exist yet |
64 | 50 | local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6 |
65 | if [ ! -e "$path" ]; then | |
66 | dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:} | |
67 | dryrun_or_real chown $uid:$gid $path | |
68 | fi | |
51 | [ ! -e "$path" ] && dryrun_or_real mknod $path c ${arg%:*} ${arg#*:} | |
69 | 52 | } |
70 | 53 | |
71 | 54 | |
118 | 101 | _L() { |
119 | 102 | # Create a symlink if it doesn't exist yet |
120 | 103 | local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6 |
121 | [ ! -e "$path" ] && dryrun_or_real ln -s "$arg" "$path" | |
104 | [ ! -e "$path" ] && dryrun_or_real ln -s "$args" "$path" | |
122 | 105 | } |
123 | 106 | |
124 | 107 | _p() { |
142 | 125 | # XXX: we don't implement this |
143 | 126 | } |
144 | 127 | |
145 | _X() { | |
146 | # Ignore a path during cleanup. Use this type to prevent path | |
147 | # removal as controled with the age parameter. Note that if path is | |
148 | # a directory, the content of the directory is not excluded from | |
149 | # clean-up, only the directory itself. | |
150 | # Lines of this type accept shell-style globs in place of normal path names. | |
151 | : | |
152 | # XXX: we don't implement this | |
153 | } | |
154 | ||
155 | 128 | _r() { |
156 | 129 | # Remove a file or directory if it exists. This may not be used to remove |
157 | 130 | # non-empty directories, use R for that. Lines of this type accept shell-style |
214 | 187 | } |
215 | 188 | |
216 | 189 | CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0 |
217 | EXCLUDE= | |
218 | PREFIX= | |
219 | 190 | FILE= |
220 | 191 | fragments= |
221 | 192 | # XXX: The harcoding of /usr/lib/ is an explicit choice by upstream |
251 | 222 | --clean) CLEAN=1 ;; # TODO: Not implemented |
252 | 223 | --verbose) VERBOSE=1 ;; |
253 | 224 | --dryrun|--dry-run) DRYRUN=1 ;; |
254 | --exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} " ;; | |
255 | --prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;; | |
256 | 225 | esac |
257 | 226 | shift |
258 | 227 | done |
263 | 232 | fi |
264 | 233 | |
265 | 234 | if [ "$CREATE$REMOVE" = '00' ]; then |
266 | printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}" | |
235 | printf 'usage: %s [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}" | |
267 | 236 | exit 1 |
268 | 237 | fi |
269 | 238 | |
293 | 262 | |
294 | 263 | # whine about invalid entries |
295 | 264 | case $cmd in |
296 | f|F|w|d|D|p|L|c|b|x|X|r|R|z|Z) ;; | |
265 | f|F|w|d|D|p|L|c|b|x|r|R|z|Z) ;; | |
297 | 266 | \#) continue ;; |
298 | 267 | *) warninvalid ; continue ;; |
299 | 268 | esac |
313 | 282 | [ "$arg" = '-' -o "$arg" = '' ] && arg='' |
314 | 283 | set -- "$path" "$mode" "$uid" "$gid" "$age" "$arg" |
315 | 284 | |
316 | [ -n "$EXCLUDE" ] && checkprefix $path $EXCLUDE && continue | |
317 | [ -n "$PREFIX" ] && ! checkprefix $path $PREFIX && continue | |
318 | 285 | [ "$VERBOSE" -eq "1" ] && echo _$cmd "$@" |
319 | 286 | _$cmd "$@" |
320 | 287 | rc=$? |
0 | #!@SHELL@ | |
1 | # busybox udhcp setup script | |
2 | ||
3 | PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
4 | ||
5 | peer_var() | |
6 | { | |
7 | [ -n "$1" ] && [ "$1" != "yes" ] | |
8 | } | |
9 | ||
10 | update_dns() | |
11 | { | |
12 | peer_var "${PEER_DNS}" && return | |
13 | [ -z "${domain}" ] && [ -z "${dns}" ] && return | |
14 | ||
15 | conf="# Generated by udhcpc for ${interface}\n" | |
16 | [ -n "${domain}" ] && conf="${conf}search ${domain}\n" | |
17 | for i in ${dns} ; do | |
18 | conf="${conf}nameserver ${i}\n" | |
19 | done | |
20 | if [ -x /sbin/resolvconf ] ; then | |
21 | printf "${conf}" | resolvconf -a ${interface} | |
22 | else | |
23 | printf "${conf}" > /etc/resolv.conf | |
24 | chmod 644 /etc/resolv.conf | |
25 | fi | |
26 | } | |
27 | ||
28 | update_ntp() | |
29 | { | |
30 | peer_var "${PEER_NTP}" && return | |
31 | [ -z "${ntpsrv}" ] && return | |
32 | ||
33 | conf="# Generated by udhcpc for interface ${interface}\n" | |
34 | conf="${conf}restrict default noquery notrust nomodify\n" | |
35 | conf="${conf}restrict 127.0.0.1\n" | |
36 | for i in ${ntpsrv} ; do | |
37 | conf="${conf}restrict ${i} nomodify notrap noquery\n" | |
38 | conf="${conf}server ${i}\n" | |
39 | done | |
40 | conf="${conf}driftfile /var/lib/ntp/ntp.drift\n" | |
41 | conf="${conf}logfile /var/log/ntp.log\n" | |
42 | printf "${conf}" > /etc/ntp.conf | |
43 | chmod 644 /etc/ntp.conf | |
44 | } | |
45 | ||
46 | update_hostname() | |
47 | { | |
48 | peer_var "${PEER_HOSTNAME}" && return | |
49 | [ -z "${hostname}" ] && return | |
50 | ||
51 | myhost="$(hostname)" | |
52 | [ -z "${myhost}" ] || [ "${myhost}" = "(none)" ] && hostname "${hostname}" | |
53 | } | |
54 | ||
55 | update_interface() | |
56 | { | |
57 | [ -n "${broadcast}" ] && broadcast="broadcast ${broadcast}" | |
58 | [ -n "${subnet}" ] && netmask="netmask ${subnet}" | |
59 | [ -n "${mtu}" ] && mtu="mtu ${mtu}" | |
60 | ifconfig "${interface}" ${ip} ${broadcast} ${netmask} ${mtu} | |
61 | } | |
62 | ||
63 | update_routes() | |
64 | { | |
65 | peer_var "${PEER_ROUTERS}" && return | |
66 | ||
67 | if [ -n "${router}" ] ; then | |
68 | metric= | |
69 | [ -n "${IF_METRIC}" ] && metric="metric ${IF_METRIC}" | |
70 | for i in ${router} ; do | |
71 | route add default gw "${i}" ${metric} dev "${interface}" | |
72 | done | |
73 | fi | |
74 | } | |
75 | ||
76 | deconfig() | |
77 | { | |
78 | ifconfig "${interface}" 0.0.0.0 | |
79 | ||
80 | if ! peer_var "${PEER_ROUTERS}" ; then | |
81 | while route del default dev "${interface}" >& /dev/null; do | |
82 | : | |
83 | done | |
84 | fi | |
85 | ||
86 | if ! peer_var "${PEER_DNS}" ; then | |
87 | [ -x /sbin/resolvconf ] && resolvconf -d "${interface}" | |
88 | fi | |
89 | } | |
90 | ||
91 | if [ -r "/var/run/udhcpc-${interface}.conf" ]; then | |
92 | . "/var/run/udhcpc-${interface}.conf" | |
93 | fi | |
94 | ||
95 | case "$1" in | |
96 | bound|renew) | |
97 | update_hostname | |
98 | update_interface | |
99 | update_routes | |
100 | update_dns | |
101 | update_ntp | |
102 | ;; | |
103 | deconfig|leasefail) | |
104 | deconfig | |
105 | ;; | |
106 | nak) | |
107 | echo "nak: ${message}" | |
108 | ;; | |
109 | *) | |
110 | echo "unknown option $1" >&2 | |
111 | echo "Usage: $0 {bound|deconfig|leasefail|nak|renew}" >&2 | |
112 | exit 1 | |
113 | ;; | |
114 | esac | |
115 | ||
116 | exit 0 |
2 | 2 | |
3 | 3 | SUBDIR= test libeinfo librc rc |
4 | 4 | |
5 | ifeq (${MKTOOLS},yes) | |
6 | SUBDIR+= tools | |
7 | endif | |
8 | ||
9 | 5 | MK= ../mk |
10 | 6 | include ${MK}/subdir.mk |
149 | 149 | static char termcapbuf[2048]; |
150 | 150 | static char tcapbuf[512]; |
151 | 151 | #else |
152 | /* No curses support, so we hardcode a list of colour capable terms | |
153 | * Only terminals without "color" in the name need to be explicitly listed */ | |
152 | /* No curses support, so we hardcode a list of colour capable terms */ | |
154 | 153 | static const char *const color_terms[] = { |
155 | 154 | "Eterm", |
156 | 155 | "ansi", |
156 | "color-xterm", | |
157 | 157 | "con132x25", |
158 | 158 | "con132x30", |
159 | 159 | "con132x43", |
173 | 173 | "kterm", |
174 | 174 | "linux", |
175 | 175 | "linux-c", |
176 | "mach-color", | |
176 | 177 | "mlterm", |
177 | 178 | "putty", |
178 | 179 | "rxvt", |
187 | 188 | "vt220", |
188 | 189 | "wsvt25", |
189 | 190 | "xterm", |
191 | "xterm-256color", | |
192 | "xterm-color", | |
190 | 193 | "xterm-debian", |
191 | 194 | NULL |
192 | 195 | }; |
398 | 401 | * which is not available to us when we boot */ |
399 | 402 | if (term_is_cons25 || strcmp(term, "wsvt25") == 0) { |
400 | 403 | #else |
401 | if (strstr(term, "color")) | |
402 | in_colour = 1; | |
403 | ||
404 | while (color_terms[i] && in_colour != 1) { | |
404 | while (color_terms[i]) { | |
405 | 405 | if (strcmp(color_terms[i], term) == 0) { |
406 | 406 | in_colour = 1; |
407 | 407 | } |
673 | 673 | int retval; |
674 | 674 | va_list ap; |
675 | 675 | |
676 | if (!fmt || is_quiet()) | |
677 | return 0; | |
678 | 676 | va_start(ap, fmt); |
679 | 677 | retval = _eerrorvn(fmt, ap); |
680 | 678 | va_end(ap); |
706 | 704 | int retval; |
707 | 705 | va_list ap; |
708 | 706 | |
709 | if (!fmt || is_quiet()) | |
707 | if (!fmt) | |
710 | 708 | return 0; |
711 | 709 | va_start(ap, fmt); |
712 | 710 | elogv(LOG_WARNING, fmt, ap); |
741 | 739 | int retval; |
742 | 740 | va_list ap; |
743 | 741 | |
744 | if (!fmt || is_quiet()) | |
742 | if (!fmt) | |
745 | 743 | return 0; |
746 | 744 | va_start(ap, fmt); |
747 | 745 | elogv(LOG_ERR, fmt, ap); |
758 | 756 | { |
759 | 757 | va_list ap; |
760 | 758 | |
761 | if (fmt && !is_quiet()) { | |
759 | if (fmt) { | |
762 | 760 | va_start(ap, fmt); |
763 | 761 | elogv(LOG_ERR, fmt, ap); |
764 | 762 | _eerrorvn(fmt, ap); |
17 | 17 | SED_CMD+= -e 's:@LIB@:${LIBNAME}:g' |
18 | 18 | SED_CMD+= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' |
19 | 19 | SED_CMD+= -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' |
20 | SED_CMD+= -e 's:@BINDIR@:${BINDIR}:g' | |
21 | SED_CMD+= -e 's:@SBINDIR@:${SBINDIR}:g' | |
22 | 20 | |
23 | 21 | _PKG_PREFIX= -e 's:.*@PKG_PREFIX@.*:\#undef RC_PKG_PREFIX:g' |
24 | 22 | ifneq (${PKG_PREFIX},) |
163 | 163 | # endif |
164 | 164 | # define _KINFO_PROC kinfo_proc |
165 | 165 | # define _KVM_GETARGV kvm_getargv |
166 | # if defined(__DragonFly__) | |
167 | # define _GET_KINFO_UID(kp) (kp.kp_ruid) | |
168 | # define _GET_KINFO_COMM(kp) (kp.kp_comm) | |
169 | # define _GET_KINFO_PID(kp) (kp.kp_pid) | |
170 | # else | |
171 | # define _GET_KINFO_UID(kp) (kp.ki_ruid) | |
172 | # define _GET_KINFO_COMM(kp) (kp.ki_comm) | |
173 | # define _GET_KINFO_PID(kp) (kp.ki_pid) | |
174 | # endif | |
166 | # define _GET_KINFO_UID(kp) (kp.ki_ruid) | |
167 | # define _GET_KINFO_COMM(kp) (kp.ki_comm) | |
168 | # define _GET_KINFO_PID(kp) (kp.ki_pid) | |
175 | 169 | # define _KVM_PATH _PATH_DEVNULL |
176 | 170 | # define _KVM_FLAGS O_RDONLY |
177 | 171 | # endif |
167 | 167 | char *line = NULL; |
168 | 168 | size_t len = 0; |
169 | 169 | regex_t re; |
170 | bool retval = true; | |
170 | bool retval = false; | |
171 | 171 | int result; |
172 | 172 | |
173 | 173 | if (!(fp = fopen(file, "r"))) |
183 | 183 | } |
184 | 184 | |
185 | 185 | while ((rc_getline(&line, &len, fp))) { |
186 | char *str = line; | |
187 | /* some /proc files have \0 separated content so we have to | |
188 | loop through the 'line' */ | |
189 | do { | |
190 | if (regexec(&re, str, 0, NULL, 0) == 0) | |
191 | goto found; | |
192 | str += strlen(str) + 1; | |
193 | /* len is the size of allocated buffer and we don't | |
194 | want call regexec BUFSIZE times. find next str */ | |
195 | while (*str == '\0' && str < line + len) | |
196 | str++; | |
197 | } while (str < line + len); | |
198 | } | |
199 | retval = false; | |
200 | found: | |
186 | if (regexec(&re, line, 0, NULL, 0) == 0) | |
187 | retval = true; | |
188 | if (retval) | |
189 | break; | |
190 | } | |
201 | 191 | fclose(fp); |
202 | 192 | free(line); |
203 | 193 | regfree(&re); |
10 | 10 | LINKDIR= ${LIBEXECDIR} |
11 | 11 | |
12 | 12 | BINLINKS= rc-status |
13 | SBINLINKS= rc-service rc-update runscript service start-stop-daemon | |
13 | SBINLINKS= rc-service rc-update runscript start-stop-daemon | |
14 | 14 | RC_BINLINKS= einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \ |
15 | 15 | eindent eoutdent esyslog eval_ecolors ewaitfile \ |
16 | 16 | veinfo vewarn vebegin veend vewend veindent veoutdent \ |
50 | 50 | # $3 is the path where the links are created |
51 | 51 | define make-links |
52 | 52 | for x in $(1); do \ |
53 | if [ "${MKSELINUX}" = yes ]; then \ | |
53 | if test -n "${MKSELINUX}"; then \ | |
54 | 54 | printf '#!/bin/sh\nexec ${2} --applet %s "$$@"\n' $$x >${3}/$$x; \ |
55 | 55 | chmod ${BINMODE} ${3}/$$x; \ |
56 | 56 | else \ |
37 | 37 | "Disable color output", \ |
38 | 38 | "Display software version", \ |
39 | 39 | "Run verbosely", \ |
40 | "Run quietly" | |
40 | "Run quietly (Does not affect errors)" | |
41 | 41 | |
42 | 42 | #define case_RC_COMMON_getopt_case_C setenv ("EINFO_COLOR", "NO", 1); |
43 | 43 | #define case_RC_COMMON_getopt_case_h usage (EXIT_SUCCESS); |
506 | 506 | { "rc-service", rc_service, }, |
507 | 507 | { "rc-status", rc_status, }, |
508 | 508 | { "rc-update", rc_update, }, |
509 | { "service", rc_service, }, | |
510 | 509 | { "update-rc", rc_update, }, |
511 | 510 | A(runscript), |
512 | 511 | { "start-stop-daemon", start_stop_daemon, }, |
40 | 40 | void rc_plugin_run(RC_HOOK, const char *value); |
41 | 41 | |
42 | 42 | /* dlfunc defines needed to avoid ISO errors. FreeBSD has this right :) */ |
43 | #if !defined(__FreeBSD__) && !defined(__DragonFly__) | |
43 | #ifndef __FreeBSD__ | |
44 | 44 | struct __dlfunc_arg { |
45 | 45 | int __dlfunc_dummy; |
46 | 46 | }; |
41 | 41 | extern char *applet; |
42 | 42 | |
43 | 43 | #include "_usage.h" |
44 | #define usagestring "" \ | |
45 | "Usage: rc-service [options] [-i] <service> <cmd>...\n" \ | |
46 | " or: rc-service [options] -e <service>\n" \ | |
47 | " or: rc-service [options] -l\n" \ | |
48 | " or: rc-service [options] -r <service>" | |
49 | 44 | #define getoptstring "e:ilr:" getoptstring_COMMON |
50 | 45 | static const struct option longopts[] = { |
51 | 46 | { "exists", 1, NULL, 'e' }, |
171 | 171 | } |
172 | 172 | |
173 | 173 | #include "_usage.h" |
174 | #define usagestring "" \ | |
175 | "Usage: rc-status [options] <runlevel>...\n" \ | |
176 | " or: rc-status [options] [-a | -c | -l | -r | -s | -u]" | |
174 | #define extraopts "[runlevel1] [runlevel2] ..." | |
177 | 175 | #define getoptstring "aclrsu" getoptstring_COMMON |
178 | 176 | static const struct option longopts[] = { |
179 | 177 | {"all", 0, NULL, 'a'}, |
350 | 348 | rc_stringlist_free(tmp); |
351 | 349 | } |
352 | 350 | l->value = p; |
353 | /* we are unsetting RC_SVCNAME because last loaded service | |
354 | wount be added to list */ | |
355 | unsetenv("RC_SVCNAME"); | |
356 | 351 | print_level("Dynamic", "needed"); |
357 | 352 | print_services(NULL, nservices); |
358 | 353 | print_level("Dynamic", "manual"); |
194 | 194 | } |
195 | 195 | |
196 | 196 | #include "_usage.h" |
197 | #define usagestring "" \ | |
198 | "Usage: rc-update [options] add <service> [<runlevel>...]\n" \ | |
199 | " or: rc-update [options] del <service> [<runlevel>...]\n" \ | |
200 | " or: rc-update [options] [show [<runlevel>...]]" | |
197 | #define usagestring "" \ | |
198 | "Usage: rc-update [options] add service <runlevel>\n" \ | |
199 | " rc-update [options] del service <runlevel>\n" \ | |
200 | " rc-update [options] show" | |
201 | 201 | #define getoptstring "su" getoptstring_COMMON |
202 | 202 | static const struct option longopts[] = { |
203 | 203 | { "stack", 0, NULL, 's' }, |
726 | 726 | #endif |
727 | 727 | |
728 | 728 | #include "_usage.h" |
729 | #define usagestring "" \ | |
730 | "Usage: rc [options] [<runlevel>]" | |
731 | #define getoptstring "a:no:s:S" getoptstring_COMMON | |
729 | #define getoptstring "a:o:s:S" getoptstring_COMMON | |
732 | 730 | static const struct option longopts[] = { |
733 | 731 | { "applet", 1, NULL, 'a' }, |
734 | { "no-stop", 0, NULL, 'n' }, | |
735 | { "override", 1, NULL, 'o' }, | |
736 | { "service", 1, NULL, 's' }, | |
737 | { "sys", 0, NULL, 'S' }, | |
732 | { "override", 1, NULL, 'o' }, | |
733 | { "service", 1, NULL, 's' }, | |
734 | { "sys", 0, NULL, 'S' }, | |
738 | 735 | longopts_COMMON |
739 | 736 | }; |
740 | 737 | static const char * const longopts_help[] = { |
741 | 738 | "runs the applet specified by the next argument", |
742 | "do not stop any services", | |
743 | 739 | "override the next runlevel to change into\n" |
744 | 740 | "when leaving single user or boot runlevels", |
745 | 741 | "runs the service specified with the rest\nof the arguments", |
763 | 759 | int opt; |
764 | 760 | bool parallel; |
765 | 761 | int regen = 0; |
766 | bool nostop = false; | |
767 | 762 | #ifdef __linux__ |
768 | 763 | char *proc; |
769 | 764 | char *p; |
813 | 808 | case 'a': |
814 | 809 | /* Do nothing, actual logic in run_applets, this |
815 | 810 | * is a placeholder */ |
816 | break; | |
817 | case 'n': | |
818 | nostop = true; | |
819 | 811 | break; |
820 | 812 | case 'o': |
821 | 813 | if (*optarg == '\0') |
1027 | 1019 | parallel = rc_conf_yesno("rc_parallel"); |
1028 | 1020 | |
1029 | 1021 | /* Now stop the services that shouldn't be running */ |
1030 | if (stop_services && !nostop) | |
1022 | if (stop_services) | |
1031 | 1023 | do_stop_services(newlevel, parallel, going_down); |
1032 | 1024 | |
1033 | 1025 | /* Wait for our services to finish */ |
310 | 310 | lock_fd = open(PREFIX_LOCK, O_WRONLY | O_CREAT, 0664); |
311 | 311 | |
312 | 312 | if (lock_fd != -1) { |
313 | while (flock(lock_fd, LOCK_EX) != 0) { | |
314 | if (errno != EINTR) { | |
315 | eerror("flock() failed: %s", strerror(errno)); | |
316 | break; | |
317 | } | |
318 | } | |
313 | if (flock(lock_fd, LOCK_EX) != 0) | |
314 | eerror("flock() failed: %s", strerror(errno)); | |
319 | 315 | } |
320 | 316 | #ifdef RC_DEBUG |
321 | 317 | else |
109 | 109 | #if !defined(SYS_ioprio_set) && defined(__NR_ioprio_set) |
110 | 110 | # define SYS_ioprio_set __NR_ioprio_set |
111 | 111 | #endif |
112 | #if !defined(__DragonFly__) | |
113 | 112 | static inline int ioprio_set(int which, int who, int ioprio) |
114 | 113 | { |
115 | 114 | #ifdef SYS_ioprio_set |
118 | 117 | return 0; |
119 | 118 | #endif |
120 | 119 | } |
121 | #endif | |
122 | 120 | |
123 | 121 | static void |
124 | 122 | free_schedulelist(void) |
354 | 352 | |
355 | 353 | LIST_FOREACH_SAFE(pi, pids, entries, np) { |
356 | 354 | if (test) { |
357 | einfo("Would send signal %d to PID %d", sig, pi->pid); | |
355 | if (!quiet) | |
356 | einfo("Would send signal %d to PID %d", sig, pi->pid); | |
358 | 357 | nkilled++; |
359 | 358 | } else { |
360 | 359 | if (verbose) |
415 | 414 | } |
416 | 415 | |
417 | 416 | if (pidfile) { |
418 | pid = get_pid(pidfile, quiet); | |
417 | pid = get_pid(pidfile, false); | |
419 | 418 | if (pid == -1) |
420 | 419 | return 0; |
421 | 420 | } |
434 | 433 | if (tkilled == 0) { |
435 | 434 | if (progressed) |
436 | 435 | printf("\n"); |
437 | if (! quiet) | |
438 | 436 | eerror("%s: no matching processes found", applet); |
439 | 437 | } |
440 | 438 | return tkilled; |
505 | 503 | |
506 | 504 | if (progressed) |
507 | 505 | printf("\n"); |
508 | if (! quiet) { | |
509 | if (nrunning == 1) | |
510 | eerror("%s: %d process refused to stop", applet, nrunning); | |
511 | else | |
512 | eerror("%s: %d process(es) refused to stop", applet, nrunning); | |
513 | } | |
506 | if (nrunning == 1) | |
507 | eerror("%s: %d process refused to stop", applet, nrunning); | |
508 | else | |
509 | eerror("%s: %d process(es) refused to stop", applet, nrunning); | |
514 | 510 | |
515 | 511 | return -nrunning; |
516 | 512 | } |
1290 | 1286 | /* We don't redirect stdin as some daemons may need it */ |
1291 | 1287 | if (background || quiet || redirect_stdout) |
1292 | 1288 | dup2(stdout_fd, STDOUT_FILENO); |
1293 | if (background || quiet || redirect_stderr) | |
1289 | if (background || redirect_stderr) | |
1294 | 1290 | dup2(stderr_fd, STDERR_FILENO); |
1295 | 1291 | |
1296 | 1292 | for (i = getdtablesize() - 1; i >= 3; --i) |
1321 | 1317 | return -1; |
1322 | 1318 | } |
1323 | 1319 | } while (!WIFEXITED(i) && !WIFSIGNALED(i)); |
1324 | if (!WIFEXITED(i) || WEXITSTATUS(i) != 0) { | |
1325 | if (!quiet) | |
1326 | eerrorx("%s: failed to start `%s'", applet, exec); | |
1327 | exit(EXIT_FAILURE); | |
1328 | } | |
1320 | if (!WIFEXITED(i) || WEXITSTATUS(i) != 0) | |
1321 | eerrorx("%s: failed to start `%s'", applet, exec); | |
1322 | ||
1329 | 1323 | pid = spid; |
1330 | 1324 | } |
1331 | 1325 | |
1359 | 1353 | alive = true; |
1360 | 1354 | } else { |
1361 | 1355 | if (pidfile) { |
1362 | pid = get_pid(pidfile, true); | |
1356 | pid = get_pid(pidfile, false); | |
1363 | 1357 | if (pid == -1) { |
1364 | 1358 | eerrorx("%s: did not " |
1365 | 1359 | "create a valid" |
0 | #!/usr/bin/perl -w | |
1 | # -*- cperl -*- | |
2 | # Copyright © 2012 Diego Elio Pettenò <flameeyes@flameeyes.eu> | |
3 | # Released under the 2-clause BSD license. | |
4 | # | |
5 | #Example usage: | |
6 | #deptree2dot > deptree.dot | |
7 | #deptree2dot | dot -Tpng -o deptree.png | |
8 | ||
9 | my $deptree = defined($ARGV[0]) ? $ARGV[0] : "/run/openrc/deptree"; | |
10 | ||
11 | open DEPTREE, $deptree or exit 1; | |
12 | ||
13 | print "digraph deptree {\n"; | |
14 | ||
15 | my @deptree; | |
16 | ||
17 | while(my $line = readline(DEPTREE)) { | |
18 | $line =~ /^depinfo_([0-9]+)_([a-z]+)(?:_[0-9]+)?='(.*)'\n$/; | |
19 | my $index = $1; | |
20 | my $prop = $2; | |
21 | my $value = $3; $value =~ s/[-\.:~]/_/g; | |
22 | ||
23 | if ( $prop eq "service" ) { | |
24 | $deptree[$index] = $value; | |
25 | printf "%s [shape=box];\n", $value; | |
26 | } else { | |
27 | my $service = $deptree[$index]; | |
28 | ||
29 | if ( $prop eq "ineed" ) { | |
30 | printf "%s -> %s;\n", $service, $value; | |
31 | } elsif ( $prop eq "iuse" ) { | |
32 | printf "%s -> %s [color=blue];\n", $service, $value; | |
33 | } elsif ( $prop eq "ibefore" ) { | |
34 | printf "%s -> %s [style=dotted];\n", $service, $value; | |
35 | } elsif ( $prop eq "iafter" ) { | |
36 | printf "%s -> %s [style=dotted color=purple];\n", $value, $service; | |
37 | } elsif ( $prop eq "iprovide" ) { | |
38 | printf "%s -> %s [color=red];\n", $value, $service; | |
39 | } | |
40 | } | |
41 | } | |
42 | ||
43 | print "}\n"; |
17 | 17 | # Re-enter the init script to stop any dependant services |
18 | 18 | if [ -x "${RC_SERVICE}" ]; then |
19 | 19 | if "${RC_SERVICE}" --quiet status; then |
20 | IN_BACKGROUND=YES | |
21 | export IN_BACKGROUND | |
20 | export IN_BACKGROUND=YES | |
22 | 21 | "${RC_SERVICE}" --quiet stop |
23 | 22 | fi |
24 | 23 | fi |
63 | 63 | # Re-enter the init script to start any dependant services |
64 | 64 | if [ -x "${RC_SERVICE}" ]; then |
65 | 65 | if ! "${RC_SERVICE}" --quiet status; then |
66 | IN_BACKGROUND=YES | |
67 | export IN_BACKGROUND | |
66 | export IN_BACKGROUND=true | |
68 | 67 | "${RC_SERVICE}" --quiet start |
69 | 68 | fi |
70 | 69 | fi |
16 | 16 | exit 1 |
17 | 17 | fi |
18 | 18 | |
19 | LD_LIBRARY_PATH=${top_builddir}/src/libeinfo:${top_builddir}/src/librc:${LD_LIBRARY_PATH} | |
20 | PATH=${top_builddir}/src/rc:${PATH} | |
21 | export LD_LIBRARY_PATH PATH | |
19 | export LD_LIBRARY_PATH=${top_builddir}/src/libeinfo:${top_builddir}/src/librc:${LD_LIBRARY_PATH} | |
20 | export PATH=${top_builddir}/src/rc:${PATH} | |
22 | 21 | |
23 | 22 | cd ${top_srcdir}/src/rc |
24 | 23 | ${MAKE:-make} links >/dev/null |