OSDN Git Service

Update to v30-pre9
[android-x86/external-wireless-tools.git] / wireless_tools / HOTPLUG-UDEV.txt
1                 Sane network interface management with Hotplug or uDev
2                 ------------------------------------------------------
3
4 INTRODUCTION
5 ------------
6         In the old days all wireless cards were managed by the
7 excellent Pcmcia subsystem and its rich configuration scripts, and
8 life was good. Then came the wireless PCI cards, then the wireless
9 USB dongles. Some unification was needed, and rather than adapt the
10 Pcmcia subsystem for PCI and USB, it was decided to create the much
11 simpler Hotplug system.
12         The USB subsystem already uses Hotplug. The Pcmcia subsystem
13 is migrating to it : CardBus cards (32 bits) already use Hotplug,
14 whereas Pcmcia cards (16 bits) often still use the old Pcmcia scripts.
15         The Hotplug system is now very mature. Most users comming from
16 the old Pcmcia scripts are disappointed at first by its apparent lack
17 of features, however it is very flexible and powerful. The new uDev
18 system depend on Hotplug and integrates tightly with it.
19         In this document, we will show how to fully exploit the
20 Hotplug system and try to implement the equivalent of all the
21 functionality of the Pcmcia scripts.
22
23
24 ASSUMPTIONS
25 -----------
26         The target audience of this document is mostly power users and
27 distribution maintainers, but it should give enough clues to help
28 newbies. You should have read and understood DISTRIBUTIONS.txt. The
29 procedures described here are more advanced than the simple
30 configuration described in DISTRIBUTIONS.txt.
31         The main focus is of course on removable wireless interfaces,
32 but we will to talk about network interface management in general, so
33 this should apply also to built-in Ethernet cards.
34
35
36 PROBLEM STATEMENT
37 -----------------
38         Let's assume a Linux system and two or more network devices,
39 Device A and Device B. Those devices may be built-in or removable,
40 they may be present or absent from the system at any time, and they
41 may activated in any particular order.
42         The user wants to assign Configuration A to Device A and
43 Configuration B to Device B, without the possibility that Device A
44 gets assigned Configuration B.
45         Different users may have different definitions of what is
46 Device A. For some, it's a specific instance of a specific hardware,
47 for others any hardware that meets some criteria (a wireless card, an
48 Ethernet card).
49         The user may also want to have multiple configurations for a
50 given device such that the chosen configuration depends on various
51 factors, just as with the old Pcmcia schemes. Device A may need
52 Configuration A1 or Configuration A2 depending on those factors.
53         By default, all network interfaces are created using default
54 interface names (starting at "eth0" and going up). I call that the
55 "all my cards are eth0" problem : im most distributions, "eth0" points
56 to a single fixed configuration in the configuration
57 database. Clearly, this won't satisfy our requirements.
58
59
60 EXAMPLE SYSTEM
61 --------------
62         The distribution I use is Debian 3.0, and some parts of what I
63 say here will be specific to it. However, it should be easy to
64 translate this material to other distributions and I welcome additions
65 to this document.
66
67         The example system is as follows :
68                 o Linux 2.6.X SMP kernel with hotplug support
69                 o Fully modular system (all network drivers as modules)
70                 o PCI Ethernet card : AMD PCnet LANCE (pcnet32 - eth4)
71                 o PCI Ethernet card : HP 100VG J2585B (hp100 - eth2)
72                 o ISA Wireless card : Old AT&T Wavelan (wavelan - eth3)
73                 o ISA-Pcmcia bridge : VADEM VG-469 (i82365 - slot 0)
74                 o PCI-CardBus bridge : Ricoh RL5c475 (yenta_socket - slot 2)
75                 o Pcmcia 802.11 card : Aironet 350 (airo_cs - eth0)
76                 o Pcmcia 802.11 card : Lucent Orinoco (orinoco_cs - eth0)
77                 o CardBus 802.11 card : SMC 2835W (prism54 - prism0)
78
79         This system just happens to be my Linux development box. It
80 has enough interfaces to make it interesting. All the examples I
81 present in this document are extracted from this system.
82
83
84 BASIC CONCEPTS
85 --------------
86         Most of the concept and tricks presented here are not really
87 new. The main contribution is to integrate them.
88
89         1) Removable network interfaces are managed by Hotplug
90 (Pcmcia, CardBus, USB...). We can't assume that those interfaces are
91 always present in this system and available at boot time (Pcmcia cards
92 were not made to be soldered in the Pcmcia slot). Therefore Hotplug is
93 the way to go.
94         2) The Hotplug system can use either the original Hotplug
95 scripts or the uDev daemon with the uDev scripts.
96         3) Built-in PCI and ISA cards are managed by the init scripts,
97 as they have always been. The ISA subsystem will never have Hotplug
98 support, and hotplug is not necessary for PCI cards.
99         4) Built-in devices that are disable most of the time should
100 be enabled manually by the user. Therefore both Hotplug and the init
101 scripts should ignore those devices by default.
102         5) (1), (3) and (4) must be compatible on the same system and
103 play nice with each other.
104
105         6) A well defined and consistent network interface name is
106 assigned to each network hardware interface using 'ifrename'. Device A
107 is always named 'ethA' (or whatever name you like such as
108 'mynetworkcard').
109         7) No interface is called 'eth0' (or 'wlan0'). Any unknown
110 device would be 'eth0', so known devices should be called something
111 else. There are also other issues with using 'eth0'.
112         8) Multiple configurations for a single interface (schemes)
113 are managed by the ifup/ifdown subsystem.
114
115
116 CONFIGURATION FROM INIT SCRIPTS
117 -------------------------------
118         It may seem paradoxical, but before setting up Hotplug, we
119 need to make sure that the initialisation of network cards via init
120 scripts is done properly and doesn't get in the way of the Hotplug
121 subsystem.
122         The configuration of network cards via init scripts is the
123 traditional way networking is initialised in Linux. The advantage of
124 this method is that it's very well documented and understood, and has
125 not changed much over the years. Unfortunately, it doesn't adequately
126 support removable cards.
127
128         The init scripts perform the following 3 functions in order :
129                 1) Load necessary driver modules
130                 2) Rename interface to name chosen by the user
131                 3) Configure those network interfaces
132
133         1) Applicability
134         ----------------
135         Configuration from init scripts is applicable to any built-in
136 network interface (ISA, PCI...), i.e., interfaces available at boot
137 time and that will never be removed from the system.
138         The Hotplug subsystem also has the ability to configure some
139 of the built-in network interfaces, such as PCI cards. However, there
140 is a class of devices that will never have Hotplug support, such as
141 ISA and EISA cards.
142
143         2) Loading driver modules (if/as needed)
144         ----------------------------------------
145         Most distributions build the kernel drivers as modules. This
146 modular setup allows to minimise the amount of memory used by the
147 system and the flexible loading/unloading of drivers.
148         You can also compile your kernel with static drivers
149 (non-modular). In that case, the driver will always be available in
150 the kernel, you don't need to configure the module subsystem, so you
151 can skip directly to the next section.
152
153         There are 3 alternatives to manage device drivers as
154 modules.
155                 1) Some distributions have an explicit list of modules
156 that are loaded at boot time, usuall in /etc/modules. If you want to
157 use that feature you need to check the documentation of your
158 distribution.
159                 2) Some system, such as Hotplug, Discover or Kudzu,
160 can scan the various buses of the PC and load the appropriate
161 drivers. This is mostly configuration-free, but may not support all
162 devices and may load unnecessary modules.
163                 3) The module subsystem also allows to load modules
164 'on-demand'. When an application try to access or configure a network
165 interface, the corresponding module is loaded.
166
167         I personally prefer to use the 'on-demand' feature of the
168 module subsystem, as this allow you to not have to specify a static
169 list of modules that need to be loaded, and only modules really needed
170 are loaded which saves kernel memory. You can also choose which module
171 to load when there are multiple modules available that support your
172 hardware (which happens quite often).
173
174         With kernel 2.6.X the module subsystem is configured in the
175 file /etc/modprobe.conf or files in the directory /etc/modprobe.d/. To
176 configure 'on-demand' module loading, on my test system I need to add
177 to the following lines to the configuration :
178
179 --------- /etc/modprobe.d/local or /etc/modprobe.conf ------
180 # HP 100VG J2585B PCI card
181 alias eth2 hp100
182
183 # AMD AMD PCnet LANCE PCI card
184 alias eth4 pcnet32
185
186 # Old AT&T Wavelan ISA card
187 alias eth3 wavelan
188 options wavelan io=0x390 irq=15
189 ------------------------------------------------------------
190
191         Your distribution may already have lines for your interfaces,
192 either replace these or make sure they are correct (some distributions
193 are notorious for picking the wrong driver name in some cases). This
194 file also contains configuration for lot of other subsystems,
195 obviously you don't want to touch that.
196         In this file, you put the name you would like the interface to
197 have (we'll fix that in a minute). Note that for modern PCI cards this
198 is much more straightforward than for old ISA cards.
199
200         When loading modules on-demand, you usually can not use the
201 name 'eth0' or other 'ethX' with a low number for your interfaces, as
202 on-demand module may fail to load them. If there is a unknown
203 interface or an interface not yet renamed on the system, it will be
204 eth0, and the system will assume the module for eth0 is already loaded
205 and will fail to load the proper module.
206         To test on-demand loading of module, you can do :
207 --------------------------
208 > /sbin/modprobe -r eth2
209 > /sbin/modprobe eth2
210 --------------------------
211
212         3) Installing 'ifrename'
213         ------------------------
214         You will need to install ifrename on your system. 'ifrename'
215 is part of the Wireless Tools package (version 27 and later) and is a
216 complete rewrite of the now obsolete 'nameif'.
217         Some distributions, such as Debian 3.1/4.0, offer a separate
218 package for 'ifrename', and in this case you should just install this
219 package. Other distributions may include ifrename as part of their
220 'wireless-tools' package (this should be the case for Gentoo, Fedora
221 and Mandrake). Other distributions, such as Debian 3.0 and Unbuntu
222 7.10, don't include ifrename at all, so you should compile yourself a
223 recent version of Wireless Tools (v29 or later) and install it.
224         The installation of Wireless Tools is described in the INSTALL
225 file of the Wireless Tools package. If you plan to only use ifrename,
226 a good option is to compile a static version of Wireless Tools and
227 only copy the resulting ifrename executable.
228
229         In any case, you should verify that 'ifrename' is properly
230 installed and check the path needed to call it :
231 --------------------------
232 > which ifrename
233 /sbin/ifrename
234 > whereis ifrename
235 ifrename: /sbin/ifrename /usr/man/man8/ifrename.8 /usr/share/man/man8/ifrename.8.gz
236 --------------------------
237         Most distributions will install 'ifrename' in '/sbin', while
238 if you compile your own wireless tools, by default it will be in
239 '/usr/local/sbin' (see Makefile on how to change that).
240         If you are upgrading ifrename from a previous version, you
241 should make sure that the new version of ifrename is either installed
242 in the same location (overwrite old version) or in a place earlier in
243 the PATH (check with whereis).
244
245         4) Making the boot scripts call 'ifrename'
246         ------------------------------------------
247         You need to make sure 'ifrename' is run at boot time. Most
248 distributions don't do that yet by default.
249         This is a part that is distribution-specific, so you will need
250 to look into your own init files, or ask people familiar with your
251 distribution. It will need to run just before the call to 'ifup' or
252 'ifconfig' command.
253
254         In Debian 4.0 (Etch) and later, the 'ifrename' package adds it
255 own init script at the right place, called /etc/init.d/ifrename. You
256 don't have to do anything.
257         In Debian 3.0 (Woody) and Debian 3.1 (Sarge), ifrename needs
258 to be run from /etc/init.d/networking, which is not the default. The
259 necessary patch to the init script is below :
260
261 ----------------------------------------------------------------
262 --- networking-orig     Wed Feb 18 13:56:23 2004
263 +++ networking  Fri Feb 20 14:51:06 2004
264 @@ -120,6 +120,15 @@ case "$1" in
265          doopt syncookies no
266          doopt ip_forward no
267
268 +       # Optionally remap interface names based on MAC address.
269 +       # '/sbin/ifrename' is part of wireless-tools package.
270 +       # /etc/iftab is currently not created by default. Jean II
271 +       if [ -x /sbin/ifrename ] && [ -r /etc/iftab ]; then
272 +           echo -n "Remapping network interfaces name: "
273 +           ifrename -p
274 +           echo "done."
275 +       fi
276 +
277          echo -n "Configuring network interfaces: "
278          ifup -a
279         echo "done."
280 ----------------------------------------------------------------
281         Don't forget to set the appropriate path to the ifrename
282 command (see step (3) above).
283
284         You may also want to also set the proper options for ifrename
285 (check the man page).
286         The option '-p' enables module autoloading compatibility.
287         The default version of 'ifrename' also includes some special
288 Debian support : using "ifrename -p -d", only the proper modules are
289 loaded. If you are using Debian, you should use this option.
290
291         5) Renaming interfaces
292         ----------------------
293         As stated above, we use 'ifrename' to assign names to
294 interfaces.
295
296         First, you need to get the MAC address of each of your
297 interfaces. You can read the MAC address on the label of the card, or
298 display it using the 'ifconfig -a' command. Remember that the
299 interface won't load yet with the proper name, so you may need to do a
300 bit looking around :
301
302 -----------------------------
303 # modprobe pcnet32
304 # ifconfig eth0
305 eth0      Link encap:Ethernet  HWaddr 00:10:83:34:BA:E5
306 [...]
307 -----------------------------
308
309         The configuration of 'ifrename' is simple, you just specify
310 which name should be used for each MAC address in the file
311 /etc/iftab :
312
313 --------- /etc/iftab ------------------------
314 # HP 100VG J2585B PCI card
315 eth2            mac 08:00:09:*
316
317 # Old AT&T Wavelan ISA card
318 eth3            mac 08:00:0E:*
319
320 # AMD AMD PCnet LANCE PCI card
321 eth4            mac 00:10:83:*
322 ---------------------------------------------
323
324         The '*' in the MAC address is a wildcard and allows me to
325 replicate my configuration between multiple identical computers. If
326 you have to manage large number of computers (like a rack of servers
327 or clusters), then you may want to look at other selectors offered by
328 'ifrename'.
329
330         In this example, we used the MAC address of the card. Using
331 the MAC address is not always an option, there is a section at the end
332 of this document dedicated to those cases.
333
334         To test that ifrename works, do the following :
335                 o Load all your drivers, see section (2)
336                 o Check /proc/net/dev to see which interface exist
337                 o Bring all interfaces down : ifconfig ethX down
338                 o Run ifrename
339                 o Check each interface with ifconfig
340                 o Bring all interfaces up : ifconfig ethX up
341
342         6) Configuring interfaces
343         -------------------------
344         Most likely, your distribution is already doing this part
345 properly. Just assign the proper IP and wireless configuration to each
346 of the interface names you have chosen.
347         This part is distribution specific, and I already document it
348 in the file DISTRIBUTIONS.txt.
349
350         In Debian, you would need to modify the file
351 /etc/network/interfaces so that it looks something like this :
352
353 --------- /etc/network/interfaces -----------
354 # AMD PCnet LANCE PCI card
355 auto eth4
356 iface eth4 inet dhcp
357
358 # HP 100VG J2585B PCI card
359 auto eth2
360 iface eth2 inet static
361     address 10.0.0.2
362     netmask 255.255.255.0
363     broadcast 10.0.0.255
364     gateway 10.0.0.1
365 ---------------------------------------------
366
367         This was the last part. Now, at your next boot, all your
368 interfaces should be assigned the proper name and the proper
369 configuration.
370         If this is not the case, there is a troubleshooting section at
371 the end of this document.
372
373
374 CONFIGURATION VIA UDEV
375 ----------------------
376         Dealing with removable interfaces is similar to dealing with
377 built-in interfaces, the main difference is that we will use Hotplug
378 event with the uDev system instead of the init scripts. This requires
379 a fairly recent distributions, older distributions don't have uDev or
380 uDev system not capable enough.
381         Note that you can also use removable interfaces with the
382 original Hotplug scripts. This is detailed in the next section. The
383 installation of uDev changes a lot of things on a system, so may not
384 be for everybody, however recent version of Gnome and KDE seem to
385 require it.
386
387         1) Applicability
388         ----------------
389         The Hotplug configuration method is the best choice for any
390 removable network interface, such as :
391                 o Pcmcia (16 bits) network cards
392                 o CardBus (32 bits) network cards
393                 o USB network dongles
394                 o Hot-PCI network cards
395         It may also be used to manage other types of network
396 interfaces, although it may not be the best choice for them.
397
398         2) How Hotplug works with the uDev scripts
399         ------------------------------------------
400         When using uDev, the concept is similar to the original
401 Hotplug scripts, however the implementation is slightly less
402 transparent. Also, the name of the rules and the location of scripts
403 vary from distribution from distribution.
404
405         When something interesting happens, the Linux kernel generates
406 an Hotplug event. The uDev deamon (udevd) receive the event, does some
407 processing on its own, use the rules in /etc/udev/rules.d/, and
408 finally run the proper script in /lib/udev/.
409         There are 3 types of Hotplug events we care about :
410                 o PCI event : a CardBus device is added or removed
411 from the system. The hotplug rule loads the driver, in my case
412 /etc/udev/rules.d/z55_hotplug.rules.
413                 o USB event : a USB device is added or removed from
414 the system. The hotplug rule loads the driver, in my case
415 /etc/udev/rules.d/z55_hotplug.rules.
416                 o Network event : a network interface is added or
417 removed from the system. The script /lib/udev/net.agent is run.
418
419         If we insert a CardBus network card in the system, the
420 following happens :
421                 1) Kernel detects new CardBus device
422                 2) Kernel generates PCI Hotplug event
423                 3) udevd receive the event, runs the Hotplug rule.
424                 4) The Hotplug rule find the proper driver module and loads it.
425                 5) Driver module initialises, creates new network device
426                 6) Kernel detects new network device
427                 7) Kernel generates Network Hotplug event
428                 8) /lib/udev/net.agent runs, configures network device
429         The sequence of events is similar for USB devices and for removals.
430
431         3) Installing uDev for Debian Lenny
432         -----------------------------------
433         Thanks to the great work of many people, Debian Lenny has all
434 the necessary packages and complete udev support, and will work mostly
435 'out of the box'.
436         You will need to install the following packages :
437                 o udev
438                 o ifrename
439
440         The configuration of Hotplug and uDev is simple. You only have
441 to modify the file /etc/network/interfaces to enable your interfaces
442 to be managed with Hotplug and uDev.
443         By default, ifup ignore all hotplug network events, as it
444 assume network interfaces are configured using the static init
445 scripts. To enable ifup to configure specific network interfaces on
446 hotplug events, you need to list those interface in a "allow-hotplug"
447 statement.
448         For example, your /etc/network/interfaces would include :
449 --------- /etc/network/interfaces -----------
450 # Enable Hotplug support (Etch and later)
451 #
452 allow-hotplug prism0 acx0
453 ---------------------------------------------
454
455         4) Installing uDev for Debian Etch (4.0)
456         ----------------------------------------
457         The uDev system provided with Debian Etch (4.0) is fully
458 functional, except for one missing feature. This version of uDev can
459 not integrate with ifrename. The version of ifrename provided also
460 lacks uDev support.
461         If you want to use uDev with Debian Etch (4.0), there are two
462 possibilities. The first solution is use the uDev system to rename
463 interfaces, loosing some of the power of ifrename. The second solution
464 is to upgrade both udevd and ifrename.
465
466         This is the procedure I personally use to upgrade udevd on
467 Debian Etch (4.0) :
468         o Get the canonical version of udev 107 from :
469                 http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html
470         o Compile it with "make".
471         o Do not "make install" !
472         o Run "strip udevd"
473         o Save a copy of the original udevd "cp /sbin/udevd /sbin/udevd.orig"
474         o Copy the new udevd with "cp udevd /sbin/udevd".
475         Note that udevd is an essential component of the OS. This
476 procedure should be safe, but I do not guarantee it will always be
477 safe.
478
479         Upgrading ifrename is simple, this is like installing ifrename
480 and is described above in this document.
481
482         Once those two packages are upgraded, you can go follow the
483 procedure going back to step (3).
484
485         5) Installing uDev for Debian Sarge (3.1)
486         -----------------------------------------
487         The uDev system provided with Debian Sarge (3.1) is a very old
488 version of uDev that is not integrated with the Hotplug scripts. In
489 other words, if you install uDev with Sarge, you will still need to
490 use the original Hotplug scripts and configure your system with them.
491
492         6) Installing uDev on other distributions
493         --------------------------------------------
494         The canonical version of hotplug is available at :
495                 http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html
496         The mailing list for udev is the Hotplug mailins list :
497                 http://linux-hotplug.sourceforge.net/
498                 http://marc.theaimsgroup.com/?l=linux-hotplug-devel&r=1&w=2
499
500         Most distributions have highly customized uDev packages and
501 most likely the canonical version won't completely work on your
502 system. The udevd deamon is has usually little changes, however the
503 rules and scripts are very different.
504         To be able to use uDev with ifrename, you will need uDev
505 version 107 and later, which has support for calling ifrename. You
506 will also need ifrename version 29.pre17 or later (I recommend version
507 29). Most modern distributions should already have those versions.
508         If this is the case, you only need to install the uDev and
509 ifrename package. If there is no ifrename package, it's easy to
510 compile it from source and install it.
511
512         7) Making uDev call ifrename
513         ----------------------------
514         We need to make sure that 'ifrename' is run by the uDev
515 subsystem at the right time. Because of the complex way uDev works,
516 the smooth integration can only be done one way. Other methods may
517 leave the uDev system in a confused state, which may be a problem when
518 the card/interface is removed.
519
520         Most often, the only thing to do it to copy the file
521 '19-udev-ifrename.rules' from the Wireless Tools package to the
522 directory "/etc/udev/rules.d/". It should work on most system.
523
524         What follow is a detailed explanation of what this additional
525 rules does.
526         uDev needs to call ifrename as an IMPORT rule, and with the
527 right parameter. As I said, this requires uDev version 107 and later
528 and ifrename version 29.pre17 or later.
529         The ifrename rule need to be called *before* the 'persistent'
530 rules. I also like the ifrename rule to happen after local rules. The
531 uDev rules are processed in alphabetical orders, which is why the
532 rules filename start usually with numbers. However, those name vary
533 betwen distributions. Make sure the ifrename rule has a proper
534 filename for your distribution.
535
536         The rules we add looks like this :
537 ------ /etc/udev/rules.d/19-udev-ifrename.rules ------
538 # Main ifrename rule.
539 # If interface is found in /etc/iftab, subsequent rename rules are bypassed.
540 # If interface is not found in /etc/iftab, subsequent rename rules applies.
541 SUBSYSTEM=="net", ACTION=="add", IMPORT="/sbin/ifrename -u -i %k", NAME:="%k"
542 ------------------------------------------------------
543
544         Lastly, make sure the rule has the right path for ifrename :
545 --------------------------
546 > which ifrename
547 /sbin/ifrename
548 --------------------------
549
550         8) Loading driver modules
551         -------------------------
552         Wow ! The most difficult part is done.
553         In theory, you don't need to do any specific configuration for
554 the driver modules to be loaded. The uDev system should load the right
555 driver module for you.
556         Also, you don't need to define aliases in /etc/modprobe.d/* or
557 in /etc/modprobe.conf, it's useless and may be counterproductive.
558
559         If you use a driver compiled statically in the kernel, you
560 also have nothing to do.
561
562         9) Renaming interfaces
563         -----------------------
564         We still use ifrename to assign names to interfaces. The
565 configuration of 'ifrename' is the same. To keep the possibility of
566 having multiple wireless cards (one in each CardBus slot), we use
567 wildcards in both the MAC address and the name :
568
569 --------- /etc/iftab -----------------------
570 # SMC 2835W wireless CardBus card
571 prism*          mac 00:30:B4:*
572 ---------------------------------------------
573
574         If you insert two cards, they would be named prism0 and
575 prism1. If you want to control which card get each name, you should
576 not use wildcards and set a specific line for each card :
577
578 --------- /etc/iftab -----------------------
579 # SMC 2835W wireless CardBus card
580 prism0          mac 00:30:B4:64:27:8B
581 prism1          mac 00:30:B4:64:27:8D
582 ---------------------------------------------
583
584         10) Configuring interfaces
585         --------------------------
586         At this point, configuration of uDev network interfaces is done
587 just like their built-in counterparts. This part is still distribution
588 specific, and still already documented in the file DISTRIBUTIONS.txt.
589
590         In Debian, you would need to modify the file
591 /etc/network/interfaces like this :
592
593 --------- /etc/network/interfaces -----------
594 # Enable Hotplug support (Etch and later)
595 #
596 allow-hotplug prism0
597
598 # SMC 2835W wireless CardBus card
599 iface prism0 inet static
600     address 10.0.1.2
601     netmask 255.255.255.0
602     broadcast 10.0.1.255
603     wireless-essid THE_ESSID
604     wireless-mode ad-hoc
605     wireless-channel 5
606 ---------------------------------------------
607
608         Note that you can also use graphical tools such as
609 NetworkManager to configure interfaces at this point.
610
611         Now, just cross your fingers and plug the card in the slot...
612         If it does not work, there is a troubleshooting section at the
613 end of this document.
614
615
616 CONFIGURATION VIA THE ORIGINAL HOTPLUG SCRIPTS
617 ----------------------------------------------
618         The previous section was dealing with removable interfaces
619 with Hotplug events and the uDev system. In various cases, or for old
620 distributions, it's preferable to use the original Hotplug
621 scripts. The original Hotplug scripts are much less invasive on the
622 system than uDev.
623         Using the original Hotplug scripts is similar to using uDev or
624 dealing with built-in interfaces, the main difference is that the
625 script used are different. Another difference is that it will likely
626 require more work on your part because most distributions do not have
627 all part properly integrated.
628
629         1) Applicability
630         ----------------
631         The Hotplug configuration method is the best choice for any
632 removable network interface, such as :
633                 o Pcmcia (16 bits) network cards
634                 o CardBus (32 bits) network cards
635                 o USB network dongles
636                 o Hot-PCI network cards
637         It may also be used to manage other types of network
638 interfaces, although it may not be the best choice for them.
639
640         2) How the original Hotplug scripts works
641         -----------------------------------------
642         Conceptually, Hotplug is very simple, and the Hotplug scripts
643 are quite easy to follow.
644
645         When something interesting happens, the Linux kernel generates
646 an Hotplug event. This runs the main Hotplug script, which in turn
647 runs the appropriate script from the /etc/hotplug directory.
648         There are 3 types of Hotplug events we care about :
649                 o PCI event : a CardBus device is added or removed
650 from the system. The script /etc/hotplug/pci.agent is run.
651                 o USB event : a USB device is added or removed
652 from the system. The script /etc/hotplug/usb.agent is run.
653                 o Network event : a network interface is added or
654 removed from the system. The script /etc/hotplug/net.agent is run.
655
656         If we insert a CardBus network card in the system, the
657 following happens :
658                 1) Kernel detects new CardBus device
659                 2) Kernel generates PCI Hotplug event
660                 3) /etc/hotplug/pci.agent runs, finds proper driver module
661                 4) /etc/hotplug/pci.agent loads driver module
662                 5) Driver module initialises, creates new network device
663                 6) Kernel detects new network device
664                 7) Kernel generates Network Hotplug event
665                 8) /etc/hotplug/net.agent runs, configures network device
666         The sequence of events is similar for USB devices and for removals.
667
668         3) Make sure ifup does not deadlock
669         -----------------------------------
670         <Most people should ignore this part>
671         <This applies only to Debian 3.0 and earlier>
672
673         The first problem is that we need to make sure the command
674 'ifup' does not deadlock by calling itself re-entrantly. If the system
675 has built-in interfaces, the 'ifup' may reenter itself at boot time
676 via Hotplug :
677                 1) Init scripts start running
678                 2) Init script calls 'ifup -a' to initialise built-in
679                         network interfaces
680                 3) 'ifup' auto-loads driver module for built-in network
681                         interface 'eth4'
682                 4) Driver module initialises, creates new network device
683                 5) Kernel generates Network hotplug event
684                 6) /etc/hotplug/net.agent runs, call 'ifup eth4'
685         Note that you can produce the same reentrancy if you call ifup
686 manually on an interface which module is not yet loaded.
687
688         The default version of 'ifup' for Debian 3.0 and Debian 3.1
689 is not reentrant and can therefore deadlock if not used properly. The
690 patch to make 'ifup' properly reentrant is available here :
691                 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=231197
692         Contemporary versions of Debian (3.1 and later) have a
693 net.agent script that contains workarounds to prevents deadlock
694 situations, so for normal use the default 'ifup' should work fine.
695         Modern version of Debian (4.0 and later) have a version of
696 'ifup' that is reentrant and that won't deadlock.
697
698         Other distributions have very different ifup programs and I
699 have not tried those (tell me about it !).
700
701         4) Installing uDev for Debian Etch (4.0) or Lenny
702         -------------------------------------------------
703         Thanks to the great work of many people, Debian Etch and Lenny
704 has all the necessary packages and hotplug support, and will work
705 mostly 'out of the box'.
706         You will need to install the following packages :
707                 o hotplug
708                 o ifrename
709
710         The configuration of network Hotplug has been much simplified
711 compared to Debian Sarge (3.0). You only have
712 to modify the file /etc/network/interfaces to enable your interfaces
713 to be managed with Hotplug and uDev.
714         By default, ifup ignore all hotplug network events, as it
715 assume network interfaces are configured using the static init
716 scripts. To enable ifup to configure specific network interfaces on
717 hotplug events, you need to list those interface in a "allow-hotplug"
718 statement.
719         For example, your /etc/network/interfaces would include :
720 --------- /etc/network/interfaces -----------
721 # Enable Hotplug support (Etch and later)
722 #
723 allow-hotplug prism0 acx0
724 ---------------------------------------------
725
726         5) Installing Hotplug for Debian Sarge (3.1)
727         --------------------------------------------
728         Thanks to the great work of many people, Debian Sarge has all
729 the necessary packages and hotplug support, and will work mostly 'out
730 of the box'.
731         You will need to install the following packages :
732                 o hotplug
733                 o ifrename
734
735         While the installation of Hotplug is simple, its configuration
736 may seem complex. The current network Hotplug script has 3 modes :
737 'all', 'auto' and 'hotplug'. However for our purpose they all produce
738 the same results when configured. This mode is controlled by the
739 variable NET_AGENT_POLICY in /etc/default/hotplug.
740
741         In the mode "all", Hotplug will run ifup for all network
742 events. This will result in failure messages if some interfaces have
743 already been configured by the init scripts. This mode is not
744 recommended.
745
746         In the mode "auto", Hotplug will run ifup only for those
747 interfaces listed in a auto stanza in /etc/network/interfaces. If
748 you choose this mode, you need to put in /etc/network/interfaces a
749 "auto" line for the interfaces you want to control with hotplug.
750 --------- /etc/network/interfaces -----------
751 # Enable Hotplug support for "auto" mode (Sarge and later)
752 auto eth0 eth1 eth2 eth3 eth4 wlan0 wlan1 prism0 prism1 airo0 airo1
753 ---------------------------------------------
754         This will result in some failure message at boot time, the
755 init script will attempt to enable all those interfaces, and generate
756 an error for all those not available at this time. It will also
757 generate an error messages for interface which have already been
758 configured by the init scripts. This mode is also not recommended.
759
760         In the mode "hotplug", hotplug network events are ignored by
761 ifup by default. To enable them you will need to add the following
762 lines to /etc/network/interfaces :
763 --------- /etc/network/interfaces -----------
764 # Enable Hotplug support for "hotplug" mode (Sarge and later)
765 mapping hotplug
766     script echo
767 ---------------------------------------------
768
769         To enable them for only selected interfaces, e.g., ethA, make
770 /etc/network/interfaces look like this :
771 --------- /etc/network/interfaces -----------
772 # Enable Hotplug support for "hotplug" mode (Sarge and later)
773 mapping hotplug
774     script grep
775     map ethA
776 ---------------------------------------------
777
778         6) Installing Hotplug for Debian 3.0
779         ------------------------------------
780         Debian 3.0 doesn't come by default with hotplug, but the
781 hotplug package is available as regular Debian package (on the CD or
782 downloadable in Debian archive), so you can just install that.
783
784         Unfortunately, this version of hotplug is not fully compatible
785 with kernel 2.6.X. You will need to do the following modifications to
786 the file /etc/hotplug/net.agent.
787
788 ------- /etc/hotplug/net.agent ------------------
789 --- net.agent-d1        Fri Feb 20 18:18:05 2004
790 +++ net.agent   Fri Feb 20 18:22:50 2004
791 @@ -26,7 +26,7 @@ if [ "$INTERFACE" = "" ]; then
792  fi
793
794  case $ACTION in
795 -register)
796 +add|register)
797
798      case $INTERFACE in
799         # interfaces that are registered after being "up" (?)
800 @@ -52,7 +52,7 @@ register)
801      mesg $1 $ACTION event not handled
802      ;;
803
804 -unregister)
805 +remove|unregister)
806      # Assume that we want to run ifdown no matter what,
807      # because it is not going to remove the data from the
808      # ifstate database otherwise.
809 -------------------------------------------------
810
811         Compared to the version in Sarge, this older version of
812 hotplug is much more basic, and doesn't have any scanning at boot time
813 and doesn't need to be enabled in /etc/network/interfaces.
814
815         7) Installing hotplug on other distributions
816         --------------------------------------------
817         The canonical version of hotplug is available at :
818                 http://linux-hotplug.sourceforge.net/
819
820         Most distributions have customized hotplug packages and
821 chances are that the canonical version won't completely work on your
822 system. All these various changing versions make it difficult for me
823 to tell what exactly needs to be changed in the hotplug scripts to
824 make them work. However, most should work out of the box.
825         Remember also that in most cases, you can not have the
826 original Hotplug scripts and uDev together. If uDev is already
827 installed on your system, downgrading to the original Hotplug scripts
828 may be tricky.
829
830         My guess is that in a few releases, all these problems will
831 sort themselves out. Just be patient.
832
833         8) Dealing with 'init' hotplug
834         ------------------------------
835         In addition to the standard kernel Hotplug events, modern
836 versions of the Hotplug scripts add init scripts that scan the system
837 buses and generate pseudo Hotplug events at boot time. For the PCI
838 buses, the script /etc/hotplug/pci.rc is run, for the USB bus,
839 /etc/hotplug/usb.rc is run.
840         The end result is that the Hotplug subsystem will also attempt
841 to configure built-in devices :
842                 1) Kernel boots
843                 2) Init runs, start to initialise the OS
844                 3) /etc/hotplug/pci.rc runs, generates pseudo Hotplug event
845                 4) /etc/hotplug/pci.agent loads driver module
846                 5) Driver module initialises, creates new network device
847                 6) Kernel generates Network Hotplug event
848                 7) /etc/hotplug/net.agent runs, configures network device
849
850         At this point, you realise that at initialisation, both
851 Hotplug and the regular init scripts (see "CONFIGURATION FROM INIT
852 SCRIPTS") are trying to configure the same devices in parallel. This
853 may create problems and is totally redundant.
854         Another reason I don't like this mechanism is that it blindly
855 attempts to load drivers for all hardware present on the system and
856 doesn't use the module loader configuration files to select preferred
857 drivers. It's fairly common to have multiple drivers for a given
858 hardware, and because of Murphy's law, Hotplug will usually load the
859 wrong one. It's also fairly common to have hardware on the system that
860 doesn't need enabling (for example, the IDE controller on my SCSI
861 machine), not loading the driver makes your kernel smaller and boot
862 faster.
863
864         Hotplug does have a way of disabling the loading of drivers
865 on a case by case basis. Drivers listed in /etc/hotplug/blacklist
866 will not be loaded.
867         Hotplug can be disabled for a whole subsystem by editing the
868 appropriate .rc script in /etc/hotplug, or just deleting/renaming
869 those files.
870
871         9) Making hotplug scripts call ifrename
872         ---------------------------------------
873         The last hotplug step is to make sure that 'ifrename' is run
874 by the hotplug subsystem at the right time. As before, we want to run
875 it just before calling 'ifup'.
876         The latest version of the hotplug scripts have this feature
877 integrated. However, you need to check that the path used for calling
878 'ifrename' is the proper one on your system. And, for older versions
879 of hotplug scripts, you will need to add this support yourself.
880
881         Check the path for ifrename :
882 --------------------------
883 > which ifrename
884 /sbin/ifrename
885 --------------------------
886
887         The patch to add 'ifrename' to hotplug looks like :
888
889 ------- /etc/hotplug/net.agent ------------------
890 --- net.agent-s2        Fri Feb 20 17:18:46 2004
891 +++ net.agent   Fri Feb 20 17:32:43 2004
892 @@ -40,6 +40,21 @@ add|register)
893             # we can't do much here without distro-specific knowledge
894             # such as whether/how to invoke DHCP, set up bridging, etc.
895
896 +           # Run ifrename as needed - Jean II
897 +           # Remap interface names based on MAC address. This works around
898 +           # the dreaded configuration problem "all my cards are 'eth0'"...
899 +           # This needs to be done before ifup, otherwise ifup will get
900 +           # confused by the name change and because iface needs to be
901 +           # down to change its name.
902 +           if [ -x /sbin/ifrename ] && [ -r /etc/iftab ]; then
903 +               debug_mesg invoke ifrename for $INTERFACE
904 +               NEWNAME=`/sbin/ifrename -i $INTERFACE`
905 +               if [ -n "$NEWNAME" ]; then
906 +                   debug_mesg iface $INTERFACE is remapped to $NEWNAME
907 +                   INTERFACE=$NEWNAME
908 +               fi;
909 +           fi
910 +
911             # RedHat and similar
912             export IN_HOTPLUG=1
913             if [ -x /sbin/ifup ]; then
914 -------------------------------------------------
915
916         If your hotplug scripts already include ifrename support then
917 you should find a section in /etc/hotplug/net.agent looking like the
918 patch above. Otherwise, just cut'n'paste the patch above in the right
919 place.
920         The path for 'ifrename' is used twice above, so don't forget
921 to modify both occurences.
922
923
924         9) Loading driver modules
925         -------------------------
926         Wow ! The most difficult part is done.
927         In theory, you don't need to do any specific configuration for
928 the driver modules to be loaded. The 'pci.agent' and 'usb.agent'
929 should load the right driver module for you.
930         Also, you don't need to define aliases in /etc/modprobe.d/* or
931 in /etc/modprobe.conf, it's useless and may be counterproductive.
932
933         If you use a driver compiled statically in the kernel, you
934 also have nothing to do.
935
936         10) Renaming interfaces
937         -----------------------
938         We still use ifrename to assign names to interfaces. The
939 configuration of 'ifrename' is the same. To keep the possibility of
940 having multiple wireless cards (one in each CardBus slot), we use
941 wildcards in both the MAC address and the name :
942
943 --------- /etc/iftab -----------------------
944 # SMC 2835W wireless CardBus card
945 prism*          mac 00:30:B4:*
946 ---------------------------------------------
947
948         If you insert two cards, they would be named prism0 and
949 prism1. Note that 'name wildcarding' is a feature only available in
950 2.6.X and 2.4.30 and later, so if you use older version of 2.4.X you
951 will need to be explicit and list each card separatly :
952
953 --------- /etc/iftab -----------------------
954 # SMC 2835W wireless CardBus card
955 prism0          mac 00:30:B4:64:27:8B
956 prism1          mac 00:30:B4:64:27:8D
957 ---------------------------------------------
958
959         11) Configuring interfaces
960         -------------------------
961         At this point, configuration of Hotplug network interfaces is
962 done just like their built-in counterparts. This part is still
963 distribution specific, and still already documented in the file
964 DISTRIBUTIONS.txt.
965
966         In Debian, you would need to modify the file
967 /etc/network/interfaces like this :
968
969 --------- /etc/network/interfaces -----------
970 # Enable Hotplug support (Etch and later)
971 #
972 allow-hotplug prism0 acx0
973
974 # Enable Hotplug support (Sarge and later)
975 mapping hotplug
976     script grep
977     map prism0
978
979 # SMC 2835W wireless CardBus card
980 iface prism0 inet static
981     address 10.0.1.2
982     netmask 255.255.255.0
983     broadcast 10.0.1.255
984     wireless-essid THE_ESSID
985     wireless-mode ad-hoc
986     wireless-channel 5
987 ---------------------------------------------
988
989         Note that you should not have wireless-* lines if you are
990 using waproamd to set these parameters.
991
992         Now, just cross your fingers and plug the card in the slot...
993
994
995 PCMCIA INTERFACES (16 bits)
996 ---------------------------
997         The Pcmcia subsystem has quite some legacy, and can use
998 various configuration procedures. The Pcmcia subsystem exclusively
999 uses hotplug for 32 bits cards (if you are using the kernel Pcmcia
1000 modules, which is the only option for 2.6.X). For 16 bit cards cardmgr
1001 is still required for managing the sockets and loading
1002 modules. Cardmgr is configured by files in the /etc/pcmcia directory.
1003
1004         To use Hotplug network configuration with 16 bits Pcmcia
1005 cards, first make sure the Pcmcia subsystem is properly configured and
1006 that cardmgr loads the right driver module (in most case, it
1007 should). Then, make sure that you don't have any configuration entries
1008 in /etc/pcmcia/network.opts and /etc/pcmcia/wireless.opts. Make sure
1009 that none of the entries in your system network configuration use
1010 'eth0' or 'wlan0' (in /etc/network/interfaces for Debian users).
1011         Then, just follow the procedure described above for
1012 "Configuration Using Hotplug" to configure your network cards.
1013
1014         You might want a little bit of explanation on why this magic
1015 will work (which would help in case it doesn't work).
1016         There are two types of Pcmcia network configuration scripts,
1017 available as /etc/pcmcia/network. The original Pcmcia script
1018 configures network cards using options found in
1019 /etc/pcmcia/network.opts and /etc/pcmcia/wireless.opts. Most
1020 distributions replace it with a script calling 'ifup'. By making sure
1021 that network.opts and wireless.opts are "empty", we neutralise the
1022 first set of scripts. By making sure no system configuration uses
1023 'eth0' or 'wlan0', we neutralise the second set of scripts, the script
1024 would call 'ifup' with the default interface name, which is usually
1025 'eth0', ifup would not find a configuration for it and would just
1026 ignore it.
1027         The card would still be configured because hotplug network
1028 events are generated for every interfaces, not only for devices
1029 managed by hotplug. So, net.agent would receive an event and perform
1030 the necessary steps to configure it.
1031
1032         Personally, I'm still using the original Pcmcia scripts for my
1033 Pcmcia cards as described in the file PCMCIA.txt, because it still
1034 works and I will migrate my complex configurations over time.
1035         You can also decide to not use Hotplug for Pcmcia cards and
1036 modify the distribution Pcmcia scripts in /etc/pcmcia/* to handle
1037 Pcmcia cards with ifrename. You would need to modify
1038 /etc/pcmcia/network to add 'ifrename' before 'ifup' the same way it
1039 was done for /etc/hotplug/net.agent. But, as in the long term Pcmcia
1040 will migrate to Hotplug, I would not bother...
1041
1042
1043 MANUAL LOADING, DOCKING STATIONS
1044 --------------------------------
1045         Manual loading is used for built-in network interfaces that
1046 are only use at specific time, and that you want disabled the rest of
1047 the time. We assume that you still use modules so that when the
1048 interface is not used you can remove the driver from the kernel.
1049
1050         First, you need to set the configuration for those interfaces,
1051 the same way it's done for other network interfaces. The main
1052 difference is that you need to specify that those interfaces should
1053 not be enabled at boot time. It's also a good idea to disable Hotplug
1054 init scripts.
1055         With Debian, you just need to make sure that the 'auto"
1056 keyword doesn't apply to this interface.
1057
1058         If you use drivers statically built in the kernel, make sure
1059 that ifrename runs at boot time (see CONFIGURATION FROM INIT
1060 SCRIPTS). Once it's done, you can just enable and disable those
1061 interfaces with 'ifup ethX' and 'ifdown ethX'.
1062
1063         If you use both a modular system, make sure that the
1064 'on-demand' module loading is properly configured :
1065
1066 --------- /etc/modprobe.d/local or /etc/modprobe.conf ------
1067 # HP 100VG J2585B PCI card
1068 alias eth2 hp100
1069
1070 # AMD AMD PCnet LANCE PCI card
1071 alias eth4 pcnet32
1072 ------------------------------------------------------------
1073
1074         Then, you should instruct 'ifup' to load module and use
1075 ifrename prior to configuring the interface, and remove the module
1076 when going down. With Debian, this is done with :
1077
1078 --------- /etc/network/interfaces -----------
1079 # AMD AMD PCnet LANCE PCI card
1080 # noauto
1081 iface eth4 inet dhcp
1082     pre-up /sbin/ifrename -p -n eth4
1083     post-down /sbin/modprobe -r eth4
1084
1085 # HP 100VG J2585B PCI card
1086 # noauto
1087 iface eth2 inet static
1088     address 10.0.0.2
1089     netmask 255.255.255.0
1090     broadcast 10.0.0.255
1091     gateway 10.0.0.1
1092     pre-up /sbin/ifrename -p -n eth2
1093     post-down /sbin/modprobe -r eth2
1094 ---------------------------------------------
1095
1096         We use the '-n' option of ifrename to specify the name of the
1097 interface after renaming. This assume that the mapping for those
1098 interfaces don't use wildcards. The '-p' option make sure ifrename
1099 probes the module prior to using it.
1100         Using "modprobe -r" make sure that if the driver is composed
1101 of multiple module all the modules are unloaded.
1102
1103         To enable the interface, just use :
1104 -----------------------------------
1105 ifup eth4
1106 -----------------------------------
1107         And to disable the interface :
1108 -----------------------------------
1109 ifdown eth4
1110 -----------------------------------
1111
1112         This solution is obviously Debian specific, but could be
1113 adapted to other distributions. If you can't manage to get your
1114 distributions to use those tricks, you can do things manually.
1115         If you don't use Hotplug, you enable an interface with :
1116 -----------------------------------
1117 modprobe eth4
1118 ifrename
1119 ifup eth4
1120 -----------------------------------
1121         If you use hotplug, you only need to do :
1122 -----------------------------------
1123 modprobe eth4
1124 -----------------------------------
1125         On the other hand, disabling the interface is done with :
1126 -----------------------------------
1127 ifdown eth4
1128 modprobe -r eth4
1129 -----------------------------------
1130
1131
1132         Docking stations for laptops may contain built-in
1133 interfaces. My previous laptop had one, and Linux had no support for
1134 it. After docking, I was able to bring up the network ISA card in the
1135 docking station.
1136         However, with most laptops and version of Linux, the issue is
1137 that after docking, the new devices are not seen. The solutions is to
1138 force a rescan of the PCI bus. Documentation is unclear on that, maybe
1139 'scanpci' may help.
1140
1141         To be able to simply manage my docking station, I had created
1142 two little scripts to enable and disable my network interface.
1143         After docking, you would run :
1144 -------- /sbin/dock ----------------------------
1145 #!/bin/sh
1146 modprobe eth4
1147 ifrename
1148 ifup eth4
1149 ------------------------------------------------
1150         And prior to undocking, you would run :
1151 -------- /sbin/undock ----------------------------
1152 #!/bin/sh
1153 ifdown eth4
1154 modprobe -r eth4
1155 ------------------------------------------------
1156         Thanks to 'ifrename', the network interface in your dock will
1157 always be properly configured regardless of if you have a Pcmcia
1158 network card in the Pcmcia slot or not.
1159
1160
1161 SCHEMES (MULTI-CONFIG)
1162 ----------------------
1163         Most Ethernet cards will only connect to a single network, or
1164 can use DHCP to be auto-configured. With Wireless Cards, it's much
1165 more likely that you will need multiple configurations, for example at
1166 work, at home and on-the-go.
1167
1168         Most distributions have various level of support for such
1169 schemes. Some distributions offer simple network schemes, while other
1170 offer "overall" schemes changing the whole configuration. I document
1171 the support for schemes in various distributions in the file
1172 DISTRIBUTIONS.txt.
1173
1174         You can also use tools such as ifplugd, waproamd or
1175 wlandetect. Those tools are a kind of "wireless-DHCP", they attempt to
1176 automatically detect the proper wireless configuration and apply
1177 it. Most will also attempt to detect network changes.
1178         The main limitation of those tools is that they offer very
1179 little manual control. If two valid alternatives are possible, you
1180 can't switch between them. If a configuration can't be detected, they
1181 usually fail.
1182         That's the same concept as using DHCP versus Static IP
1183 addresses. Some people are very happy with DHCP, my style is Static IP
1184 addresses.
1185
1186         If you use Debian and want to use simple manual schemes, these
1187 are the things you need to do.
1188         1) Make sure that 'ifscheme' and 'ifscheme-mapping' are
1189 installed on the system. You may find them in a separate tar file on
1190 my web site.
1191         2) Check the path for 'ifscheme-mapping' (using whereis).
1192         3) Modify you /etc/network/interface to add proper mapping and
1193 configuration.
1194
1195 ------- /etc/network/interfaces ----------------------
1196 # Enable Hotplug support (Sarge and later)
1197 mapping hotplug
1198     script echo
1199
1200 # SMC 2835W wireless CardBus card
1201 mapping prism0
1202     script /sbin/ifscheme-mapping
1203
1204 iface prism0-any inet dhcp
1205     wireless-essid any
1206     wireless-mode managed
1207
1208 iface prism0-adhoc inet static
1209     address 10.0.1.2
1210     network 10.0.1.0
1211     netmask 255.255.255.0
1212     broadcast 10.0.1.255
1213     wireless-essid THE_ESSID
1214     wireless-mode ad-hoc
1215     wireless-channel 5
1216
1217 iface prism0-other inet static
1218     address 10.10.10.2
1219     network 10.10.10.0
1220     netmask 255.255.255.0
1221     broadcast 10.10.10.255
1222     wireless-essid ANOTHER_ESSID
1223     wireless-mode ad-hoc
1224     wireless-key "s:secure"
1225 ------------------------------------------------------
1226
1227
1228 FIRMWARE LOADING
1229 ----------------
1230         A lot of modern wireless card don't have built in firmware and
1231 need firmware loading. Recent kernels (2.6.X) have a firmware
1232 loader. These are a few notes on how to use it.
1233
1234         First, read the documentation coming with your driver, because
1235 each driver has specificities (like the name of the firmware file it
1236 requires). Some drivers may offer additional ways to load the
1237 firmware, but in the long term things should be standardised around
1238 the hotplug method to simplify packaging in distributions.
1239
1240         You need to compile your kernel with firmware loading
1241 (CONFIG_FW_LOADER in "Generic Driver Options"). If your driver was
1242 built from the kernel, chances are that it enabled this feature
1243 already. Make sure you boot from this new kernel.
1244
1245         The 'sysfs' file system must be mounted. The easiest is to
1246 mount it at boot time, add a line for it in /etc/fstab :
1247
1248 -------- /etc/fstab ------------------------------
1249 sysfs           /sys          sysfs  defaults                   0      0
1250 --------------------------------------------------
1251
1252         Then, you add the firmware file in the directory where it's
1253 expected, which is /lib/firmware/ in most cases, and
1254 /usr/lib/hotplug/firmware/ on older systems.
1255
1256         Most distributions nowadays have a version of the Hotplug
1257 scripts that knows how to deal with firmware. If it is not the case,
1258 just grab the 'firmware.agent' file from an alternate source and copy
1259 it into your /etc/hotplug directory (make sure it's executable).
1260         You can try the canonical version :
1261                 http://linux-hotplug.sourceforge.net/
1262         Or Debian's version :
1263                 http://packages.debian.org/unstable/admin/hotplug
1264
1265         Note that firmware loading will usually only work with
1266 interfaces that are fully managed by Hotplug. This is the only way to
1267 ensure the that proper sequence of action is happening in the right
1268 order every time. Firmware loading may not work properly for
1269 interfaces configured in the init scripts.
1270         This means that if you have a built-in interface that require
1271 firmware loading, you should just use manage those interfaces like
1272 removable interfaces (see section above). However, interface
1273 configuration need to be explicitly triggered at boot time.
1274
1275         One possibility is to set-up Hotplug to be run from the init
1276 script at boot time. This is usually an option for recent
1277 distributions (it's not the case for Hotplug in Debian 3.0). But, we
1278 have seen that this has some issues.
1279         The other possibility is to use an hybrid between the init
1280 script method and the hotplug method. First, you need to add an alias
1281 for the driver in /etc/modprobe.conf. Then, you need to specify a
1282 mapping for this interface in /etc/iftab, and specify a configuration
1283 for this interface and that it is enabled at boot time. Lastly,
1284 you make sure that the network init scripts run 'ifrename
1285 -p'. 'ifrename' will trigger the module to load, and all the Hotplug
1286 events will be generated properly to configure the interface.
1287
1288
1289 DEVICES WITH MULTIPLE NAMES/INTERFACES
1290 --------------------------------------
1291         Some wireless drivers offer multiple network interfaces for
1292 the same device. A classical example is the Aironet driver that
1293 creates a 'ethX' and 'wifiY' for each card.
1294
1295         'ifrename' allows you a finer selection of interfaces than
1296 'nameif'. For example, to only rename the pseudo-Ethernet network
1297 interface name of the Aironet driver, you would do :
1298
1299 --------- /etc/iftab -----------------------
1300 # Cisco Aironet 350 wireless Pcmcia card
1301 airo*           mac 00:07:0E:* arp 1
1302 ---------------------------------------------
1303
1304         After that, your device would be available through 'eth0' and
1305 'wifi0'.
1306
1307         You can rename both interfaces. You just need to remember that
1308 'ifrename' starts matching from the last line of the file, so you
1309 would do :
1310 --------- /etc/iftab -----------------------
1311 # Cisco Aironet 350 wireless Pcmcia card
1312 wifi*           mac 00:07:0E:* arp 801
1313 airo*           mac 00:07:0E:* arp 1
1314 ---------------------------------------------
1315
1316         The current version of 'ifrename' supports only the most useful
1317 selectors, but it is architectured such as adding selectors is relatively
1318 trivial. If you find a case that 'ifrename' can't handle, you should
1319 just extend it.
1320
1321
1322 DEVICES WITHOUT MAC ADDRESSES
1323 -----------------------------
1324         Most Ethernet and Wireless devices have a fixed and unique MAC
1325 address, and it is therefore advised to name them based on this
1326 criteria. However, there are also network interfaces that don't have a
1327 fixed and unique MAC address, for example Ethernet over USB, IP over
1328 FireWire, PPP and tunnel interfaces.
1329         The driver for those devices creates the interface with a name
1330 specific to the driver, such as ppp* for PPP interfaces and usb* for
1331 Ethernet over USB, and therefore they are easy to identify and
1332 configure, and few users feel the need to rename them. Moreover, some
1333 of them, such as PPP, have their own configuration scripts and
1334 methodology addressing their unique needs.
1335
1336         There are a few cases where you might want to rename
1337 interfaces without MAC addresses. One example is two Ethernet over USB
1338 dongles. The way to do this is to use alternate ifrename
1339 selectors. Choosing the right selector depends on what you want to
1340 achieve.
1341         A quick theoretical example to illustrate :
1342 --------- /etc/iftab -----------------------
1343 # All other usbnet devices
1344 usb*            driver usbnet
1345 # Specific usbnet devices
1346 usb-p           firmware "Prolific PL-2301/PL-2302"
1347 usb-4           bus-info usb-00:02.0-1.4
1348 ---------------------------------------------
1349
1350
1351 TROUBLESHOOTING
1352 ---------------
1353         If your interface doesn't show up as expected with ifconfig,
1354 you will need to find out why. First, you need to be familiar with the
1355 sequence of actions in the system and find which one did not happen.
1356
1357         1) Interfaces on the system
1358         ---------------------------
1359         You first need to check which network interfaces are currently
1360 available on your system and configuration was assigned to it. This is
1361 mostly done using 'ifconfig'.
1362         To list only the configured network interfaces :
1363 --------------------------
1364 > /sbin/ifconfig
1365 --------------------------
1366         The list all network interfaces :
1367 --------------------------
1368 > /sbin/ifconfig -a
1369 --------------------------
1370         You can also use 'iwconfig' to check the wireless configuration.
1371
1372         2) Modules
1373         ----------
1374         You need to check that the driver module(s) was loaded using
1375 'lsmod'.
1376
1377         If this device is configure via init scripts, you should test
1378 if the on-demand loading of module (module probing works). This is
1379 done with :
1380 --------------------------
1381 > /sbin/modprobe -r eth2
1382 > /sbin/modprobe eth2
1383 --------------------------
1384
1385         If your module does not load, first you should check that the
1386 hardware is present. This depend on the bus used, for PCI bus you will
1387 use 'lspci' and for USB bus you will use 'lsusb'.
1388         The second step is to check if the driver for your hardware is
1389 available on the system.
1390
1391         3) Ifrename
1392         -----------
1393         You need to check if the interface was properly renamed with
1394 'ifrename'. You can use 'ifrename -D -V' to debug your /etc/iftab.
1395         Get the list of interfaces on your system with 'ifconfig -a'
1396 or 'cat /proc/net/dev', and check if an interface is using the name
1397 you assigned or 'eth0'. Check any suspicious interfaces with 'ifconfig
1398 eth0', and check its MAC address.
1399         Verify that no line in /etc/iftab matches the all-zero MAC
1400 address. The all-zero MAC address matches the loopback interface 'lo'
1401 and various pseudo network devices, renaming the loopback interface is
1402 highly discouraged.
1403         Finally, run ifrename in debug mode :
1404 --------------------------
1405 > /sbin/ifrename -D -V
1406 --------------------------
1407
1408         The only case where running ifrename in debug mode would
1409 differ from when it is run normally are drivers that don't have valid
1410 descriptor value until after ifrename is run. There are a few drivers,
1411 such as prism54, which don't have a proper MAC address before brought
1412 up. This obviously fools ifrename.
1413         A way to debug that is to change the way ifrename is called to
1414 save the debug output. For example, you could call ifrename that way :
1415 ------- /etc/hotplug/net.agent ------------------
1416                 NEWNAME=`/sbin/ifrename -i $INTERFACE -V 2>> /var/log/ifrename`
1417 -------------------------------------------------
1418
1419         4) Original Hotplug scripts
1420         ---------------------------
1421         The Hotplug subsystem has also good debugging facilities.
1422         To enable Hotplug debugging, just make sure the variable DEBUG
1423 is defined in /sbin/hotplug :
1424 --------- /sbin/hotplug ------------------------------
1425 --- /sbin/hotplug-old      Tue Mar 26 09:00:20 2002
1426 +++ /sbin/hotplug       Fri Feb 20 18:40:38 2004
1427 @@ -22,7 +22,7 @@
1428  cd /etc/hotplug
1429  . hotplug.functions
1430
1431 -# DEBUG=yes export DEBUG
1432 +DEBUG=yes export DEBUG
1433
1434  if [ "$DEBUG" != "" ]; then
1435      mesg "arguments ($*) env (`env`)"
1436 ------------------------------------------------------
1437         Then, you can check your message logs for Hotplug events with
1438 'tail -f /var/log/messages'. Verify that the various Hotplug events
1439 happen as expected (pci, firmware, net...), and verify the log
1440 messages from 'net.agent'.
1441
1442         5) UDev
1443         -------
1444         There are two main facilities to debug uDev, the 'udevtest'
1445 program and udev daemon debugging.
1446
1447         The uDev package comes with 'udevtest', a program that
1448 simulate a hotplug event, however this has many limitations and is not
1449 exactly like the real thing.
1450         The file 19-udev-ifrename.rules has a special rule to work
1451 with udevtest. This rule runs ifrename in dry-run mode. This rule is
1452 disabled by default, and if you intend to use udevtest you should
1453 enable this rule :
1454 --------- 19-udev-ifrename.rules ---------------------
1455 # Enable this rule to test with udevtest.
1456 ENV{UDEV_LOG}=="6", SUBSYSTEM=="net", ACTION=="add", IMPORT="/sbin/ifrename -D -V -u -i %k", NAME:="%k"
1457 ------------------------------------------------------
1458         Then, to test on a specific interface, you would run it like this :
1459 ----------------------
1460 > udevtest /sys/class/net/eth5
1461 [...]
1462 run_program: '/usr/sbin/ifrename' (stderr) 'Dry-run : Would rename eth0 to eth5.'
1463 [...]
1464 udev_rules_get_name: rule applied, 'eth0' becomes 'eth5'
1465 ----------------------
1466         The advantage of this procedure is that it's very simple to
1467 try and all the output is on the console.
1468
1469         The enable udevd debugging, you need to change the default log
1470 level to "debug" in the file /etc/udev/udev.conf :
1471 --------- /etc/udev/udev.conf ------------------------
1472 udev_log="debug"
1473 ------------------------------------------------------
1474         You will also need to reboot for this change to be
1475 effective. The alternative is to use 'udevcontrol'.
1476         Make sure the special udevtest rule for ifrename described
1477 above is *NOT* enabled, i.e. it should be commented out or
1478 eliminated.
1479         The debug message may be spread in various log files depending
1480 on the distribution. On Debian, I would find them with 'tail -f
1481 /var/log/debug'.
1482
1483
1484
1485
1486         Have fun...
1487
1488         Jean