HOTPLUG.txt 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. Sane network interface management with Hotplug
  2. ----------------------------------------------
  3. INTRODUCTION
  4. ------------
  5. In the old days all wireless cards were managed by the
  6. excellent Pcmcia subsystem and its rich configuration scripts, and
  7. life was good. Then came the wireless PCI cards, then the wireless
  8. USB dongles. Some unification was needed, and rather than adapt the
  9. Pcmcia subsystem for PCI and USB, it was decided to create the much
  10. simpler Hotplug system.
  11. The USB subsystem already uses Hotplug. The Pcmcia subsystem
  12. is migrating to it : CardBus cards (32 bits) already use Hotplug,
  13. whereas Pcmcia cards (16 bits) still use the old Pcmcia scripts.
  14. The Hotplug system is still in its infancy, but already shows
  15. some good promise. Most users are disappointed at first by its
  16. apparent lack of features compared to the Pcmcia scripts. In this
  17. document, we will show how to fully exploit the Hotplug system and try
  18. to implement the equivalent of all the functionality of the Pcmcia
  19. scripts.
  20. ASSUMPTIONS
  21. -----------
  22. The target audience of this document is mostly power users and
  23. distribution maintainers, but it should give enough clues to help
  24. newbies. You should have read and understood DISTRIBUTIONS.txt. The
  25. procedures described here are more advanced than the simple
  26. configuration described in DISTRIBUTIONS.txt.
  27. The main focus is of course on removable wireless interfaces,
  28. but we will to talk about network interface management in general, so
  29. this should apply also to built-in Ethernet cards.
  30. PROBLEM STATEMENT
  31. -----------------
  32. Let's assume a Linux system and two or more network devices,
  33. Device A and Device B. Those devices may be built-in or removable,
  34. they may be present or absent from the system at any time, and they
  35. may activated in any particular order.
  36. The user wants to assign Configuration A to Device A and
  37. Configuration B to Device B, without the possibility that Device A
  38. gets assigned Configuration B.
  39. Different users may have different definitions of what is
  40. Device A. For some, it's a specific instance of a specific hardware,
  41. for others any hardware that meets some criteria (a wireless card, an
  42. Ethernet card).
  43. The user may also want to have multiple configurations for a
  44. given device such that the chosen configuration depends on various
  45. factors, just as with the old Pcmcia schemes. Device A may need
  46. Configuration A1 or Configuration A2 depending on those factors.
  47. By default, all network interfaces are created using default
  48. interface names (starting at "eth0" and going up). I call that the
  49. "all my cards are eth0" problem : im most distributions, "eth0" points
  50. to a single fixed configuration in the configuration
  51. database. Clearly, this won't satisfy our requirements.
  52. EXAMPLE SYSTEM
  53. --------------
  54. The distribution I use is Debian 3.0, and some parts of what I
  55. say here will be specific to it. However, it should be easy to
  56. translate this material to other distributions and I welcome additions
  57. to this document.
  58. The example system is as follows :
  59. o Linux 2.6.X SMP kernel with hotplug support
  60. o Fully modular system (all network drivers as modules)
  61. o PCI Ethernet card : AMD PCnet LANCE (pcnet32 - eth4)
  62. o PCI Ethernet card : HP 100VG J2585B (hp100 - eth2)
  63. o ISA Wireless card : Old AT&T Wavelan (wavelan - eth3)
  64. o ISA-Pcmcia bridge : VADEM VG-469 (i82365 - slot 0)
  65. o PCI-CardBus bridge : Ricoh RL5c475 (yenta_socket - slot 2)
  66. o Pcmcia 802.11 card : Aironet 350 (airo_cs - eth0)
  67. o Pcmcia 802.11 card : Lucent Orinoco (orinoco_cs - eth0)
  68. o CardBus 802.11 card : SMC 2835W (prism54 - prism0)
  69. This system just happens to be my Linux development box. It
  70. has enough interfaces to make it interesting. All the examples I
  71. present in this document are extracted from this system.
  72. BASIC CONCEPTS
  73. --------------
  74. Most of the concept and tricks presented here are not really
  75. new. The main contribution is to integrate them.
  76. 1) Removable network interfaces are managed by Hotplug
  77. (Pcmcia, CardBus, USB...). We can't assume that those interfaces are
  78. always present in this system and available at boot time (Pcmcia cards
  79. were not made to be soldered in the Pcmcia slot). Therefore Hotplug is
  80. the way to go.
  81. 2) Built-in PCI and ISA cards are managed by the init scripts,
  82. as they have always been. The ISA subsystem will never have Hotplug
  83. support, and hotplug is not necessary for PCI cards.
  84. 3) Built-in devices that are disable most of the time should
  85. be enabled manually by the user. Therefore both Hotplug and the init
  86. scripts should ignore those devices by default.
  87. 4) (1), (2) and (3) must be compatible on the same system and
  88. play nice with each other.
  89. 5) A well defined and consistent network interface name is
  90. assigned to each network hardware interface using 'ifrename'. Device A
  91. is always named 'ethA' (or whatever name you like such as
  92. 'mynetworkcard').
  93. 6) No interface is called 'eth0' (or 'wlan0'). Any unknown
  94. device would be 'eth0', so known devices should be called something
  95. else.
  96. 7) Multiple configurations for a single interface (schemes)
  97. are managed by the ifup/ifdown subsystem.
  98. CONFIGURATION FROM INIT SCRIPTS
  99. -------------------------------
  100. It may seem paradoxical, but before setting up Hotplug, we
  101. need to make sure that the initialisation of network cards via init
  102. scripts is done properly and doesn't get in the way of the Hotplug
  103. subsystem.
  104. The configuration of network cards via init scripts is the
  105. traditional way networking is initialised in Linux. The advantage of
  106. this method is that it's very well documented and understood, and has
  107. not changed much over the years. Unfortunately, it doesn't adequately
  108. support removable cards.
  109. The init scripts perform the following 3 functions in order :
  110. 1) Load necessary driver modules
  111. 2) Rename interface to name chosen by the user
  112. 3) Configure those network interfaces
  113. 1) Applicability
  114. ----------------
  115. Configuration from init scripts is applicable to any built-in
  116. network interface (ISA, PCI...), i.e., interfaces available at boot
  117. time and that will never be removed from the system.
  118. The Hotplug subsystem also has the ability to configure some
  119. of the built-in network interfaces, such as PCI cards. However, there
  120. is a class of devices that will never have Hotplug support, such as
  121. ISA and EISA cards.
  122. 2) Loading driver modules (if/as needed)
  123. ----------------------------------------
  124. Most distributions build the kernel drivers as modules. This
  125. modular setup allows to minimise the amount of memory used by the
  126. system and the flexible loading/unloading of drivers.
  127. You can also compile your kernel with static drivers
  128. (non-modular). In that case, the driver will always be available in
  129. the kernel, you don't need to configure the module subsystem, so you
  130. can skip directly to the next section.
  131. There are 3 alternatives to manage device drivers as
  132. modules.
  133. 1) Some distributions have an explicit list of modules
  134. that are loaded at boot time. If you want to use that feature you need
  135. to check the documentation of your distribution.
  136. 2) Some system, such as Hotplug, Discover or Kudzu,
  137. can scan the various buses of the PC and load the appropriate
  138. drivers. This is mostly configuration-free, but may not support all
  139. devices and may load unnecessary modules.
  140. 3) The module subsystem also allows to load modules
  141. 'on-demand'. When an application try to access or configure a network
  142. interface, the corresponding module is loaded.
  143. I personally prefer to use the 'on-demand' feature of the
  144. module subsystem, as this allow you to not have to specify a static
  145. list of modules that need to be loaded, and only modules really needed
  146. are loaded which saves kernel memory. You can also choose which module
  147. to load when there are multiple modules available that support your
  148. hardware (which happens quite often).
  149. With kernel 2.6.X the module subsystem is configured in the
  150. file /etc/modprobe.conf or files in the directory /etc/modprobe.d/. To
  151. configure 'on-demand' module loading, on my test system I need to add
  152. to the following lines to the configuration :
  153. --------- /etc/modprobe.d/local or /etc/modprobe.conf ------
  154. # HP 100VG J2585B PCI card
  155. alias eth2 hp100
  156. # AMD AMD PCnet LANCE PCI card
  157. alias eth4 pcnet32
  158. # Old AT&T Wavelan ISA card
  159. alias eth3 wavelan
  160. options wavelan io=0x390 irq=15
  161. ------------------------------------------------------------
  162. Your distribution may already have lines for your interfaces,
  163. either replace these or make sure they are correct (some distributions
  164. are notorious for picking the wrong driver name in some cases). This
  165. file also contains configuration for lot of other subsystems,
  166. obviously you don't want to touch that.
  167. In this file, you put the name you would like the interface to
  168. have (we'll fix that in a minute). Note that for modern PCI cards this
  169. is much more straightforward than for old ISA cards.
  170. 3) Installing 'ifrename'
  171. ------------------------
  172. You will need to install ifrename on your system. 'ifrename'
  173. is part of the Wireless Tools package (version 27 and later) and is a
  174. complete rewrite of the now obsolete 'nameif'.
  175. Some distributions, such as Debian Sarge, offer a separate
  176. package for 'ifrename', and in this case you should just install this
  177. package. Other distributions may include ifrename as part of their
  178. 'wireless-tools' package (this should be the case for Gentoo, Fedora
  179. and Mandrake). Other distributions, such as Debian 3.0, don't include
  180. ifrename at all, so you should compile yourself a recent version of
  181. Wireless Tools (v27 or later) and install it.
  182. In any case, you should verify that 'ifrename' is properly
  183. installed and check the path needed to call it :
  184. --------------------------
  185. > which ifrename
  186. /sbin/ifrename
  187. --------------------------
  188. Most distributions will install 'ifrename' in '/sbin', while if
  189. you compile your own wireless tools, it will be in '/usr/local/sbin'.
  190. 4) Making the boot scripts call 'ifrename'
  191. ------------------------------------------
  192. You need to make sure 'ifrename' is run at boot time. Most
  193. distributions don't do that yet by default.
  194. This is a part that is distribution-specific, so you will need
  195. to look into your own init files, or ask people familiar with your
  196. distribution. It will need to run just before the call to 'ifup' or
  197. 'ifconfig' command.
  198. In Debian 3.0 and Debian Sarge, it needs to be run from
  199. /etc/init.d/networking, which is not the default. The necessary patch
  200. is below :
  201. ----------------------------------------------------------------
  202. --- networking-orig Wed Feb 18 13:56:23 2004
  203. +++ networking Fri Feb 20 14:51:06 2004
  204. @@ -120,6 +120,15 @@ case "$1" in
  205. doopt syncookies no
  206. doopt ip_forward no
  207. + # Optionally remap interface names based on MAC address.
  208. + # '/sbin/ifrename' is part of wireless-tools package.
  209. + # /etc/iftab is currently not created by default. Jean II
  210. + if [ -x /sbin/ifrename ] && [ -r /etc/iftab ]; then
  211. + echo -n "Remapping network interfaces name: "
  212. + ifrename -p
  213. + echo "done."
  214. + fi
  215. +
  216. echo -n "Configuring network interfaces: "
  217. ifup -a
  218. echo "done."
  219. ----------------------------------------------------------------
  220. Don't forget to set the appropriate path to the ifrename
  221. command (see step (3) above).
  222. You may also want to also set the proper options for ifrename
  223. (check the man page).
  224. The option '-p' enables module autoloading compatibility.
  225. The default version of 'ifrename' also includes some special
  226. Debian support : using "ifrename -p -d", only the proper modules are
  227. loaded. If you are using Debian, you should use this option.
  228. 5) Renaming interfaces
  229. ----------------------
  230. As stated above, we use 'ifrename' to assign names to
  231. interfaces.
  232. First, you need to get the MAC address of each of your
  233. interfaces. You can read the MAC address on the label of the card, or
  234. display it using the 'ifconfig -a' command. Remember that the
  235. interface won't load yet with the proper name, so you may need to do a
  236. bit looking around :
  237. -----------------------------
  238. # modprobe pcnet32
  239. # ifconfig eth0
  240. eth0 Link encap:Ethernet HWaddr 00:10:83:34:BA:E5
  241. [...]
  242. -----------------------------
  243. The configuration of 'ifrename' is simple, you just specify
  244. which name should be used for each MAC address in the file
  245. /etc/iftab :
  246. --------- /etc/iftab ------------------------
  247. # HP 100VG J2585B PCI card
  248. eth2 mac 08:00:09:*
  249. # Old AT&T Wavelan ISA card
  250. eth3 mac 08:00:0E:*
  251. # AMD AMD PCnet LANCE PCI card
  252. eth4 mac 00:10:83:*
  253. ---------------------------------------------
  254. The '*' in the MAC address is a wildcard and allows me to
  255. replicate my configuration between multiple identical computers. If
  256. you have to manage large number of computers (like a rack of servers
  257. or clusters), then you may want to look at other selectors offered by
  258. 'ifrename'.
  259. To test that ifrename works, do the following :
  260. o Load all your drivers, see section (2)
  261. o Check /proc/net/dev to see which interface exist
  262. o Bring all interfaces down : ifconfig ethX down
  263. o Run ifrename
  264. o Check each interface with ifconfig
  265. o Bring all interfaces up : ifconfig ethX up
  266. 6) Configuring interfaces
  267. -------------------------
  268. Most likely, your distribution is already doing this part
  269. properly. Just assign the proper IP and wireless configuration to each
  270. of the interface names you have chosen.
  271. This part is distribution specific, and I already document it
  272. in the file DISTRIBUTIONS.txt.
  273. In Debian, you would need to modify the file
  274. /etc/network/interfaces so that it looks something like this :
  275. --------- /etc/network/interfaces -----------
  276. # AMD PCnet LANCE PCI card
  277. auto eth4
  278. iface eth4 inet dhcp
  279. # HP 100VG J2585B PCI card
  280. auto eth2
  281. iface eth2 inet static
  282. address 10.0.0.2
  283. netmask 255.255.255.0
  284. broadcast 10.0.0.255
  285. gateway 10.0.0.1
  286. ---------------------------------------------
  287. This was the last part. Now, at your next boot, all your
  288. interfaces should be assigned the proper name and the proper
  289. configuration.
  290. CONFIGURATION VIA HOTPLUG
  291. -------------------------
  292. Dealing with removable interfaces is similar to dealing with
  293. built-in interfaces, the main difference is that we will use the
  294. Hotplug scripts instead of the init scripts. Another difference is
  295. that it will likely require more work on your part because most
  296. distributions are not fully ready for it.
  297. 1) Applicability
  298. ----------------
  299. The Hotplug configuration method is the best choice for any
  300. removable network interface, such as :
  301. o Pcmcia (16 bits) network cards
  302. o CardBus (32 bits) network cards
  303. o USB network dongles
  304. o Hot-PCI network cards
  305. It may also be used to manage other types of network
  306. interfaces, although it may not be the best choice for them.
  307. 2) How Hotplug works
  308. --------------------
  309. Conceptually, Hotplug is very simple. When something
  310. interesting happens, the Linux kernel generates an Hotplug event. This
  311. runs the proper script from the /etc/hotplug directory.
  312. There are 3 types of Hotplug events we care about :
  313. o PCI event : a CardBus device is added or removed
  314. from the system. The script /etc/hotplug/pci.agent is run.
  315. o USB event : a USB device is added or removed
  316. from the system. The script /etc/hotplug/usb.agent is run.
  317. o Network event : a network interface is added or
  318. removed from the system. The script /etc/hotplug/net.agent is run.
  319. If we insert a CardBus network card in the system, the
  320. following happens :
  321. 1) Kernel detects new CardBus device
  322. 2) Kernel generates PCI Hotplug event
  323. 3) /etc/hotplug/pci.agent runs, finds proper driver module
  324. 4) /etc/hotplug/pci.agent loads driver module
  325. 5) Driver module initialises, creates new network device
  326. 6) Kernel detects new network device
  327. 7) Kernel generates Network Hotplug event
  328. 8) /etc/hotplug/net.agent runs, configures network device
  329. The sequence of events is similar for removals and USB devices.
  330. 3) Make sure ifup does not deadlock
  331. -----------------------------------
  332. <Most people should ignore this part>
  333. The first problem is that we need to make sure the command
  334. 'ifup' does not deadlock by calling itself re-entrantly. If the system
  335. has built-in interfaces, the 'ifup' may reenter itself at boot time
  336. via Hotplug :
  337. 1) Init scripts start running
  338. 2) Init script calls 'ifup -a' to initialise built-in
  339. network interfaces
  340. 3) 'ifup' auto-loads driver module for built-in network
  341. interface 'eth4'
  342. 4) Driver module initialises, creates new network device
  343. 5) Kernel generates Network hotplug event
  344. 6) /etc/hotplug/net.agent runs, call 'ifup eth4'
  345. Note that you can produce the same reentrancy if you call ifup
  346. manually on an interface which module is not yet loaded.
  347. The default version of 'ifup' for Debian 3.0 and Debian Sarge
  348. is not reentrant and can therefore deadlock if not used properly. The
  349. patch to make 'ifup' properly reentrant is available here :
  350. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=231197
  351. Contemporary versions of Debian (Sarge and later) have a
  352. net.agent script that contains workarounds to prevents deadlock
  353. situations, so for normal use the default 'ifup' should work fine.
  354. Other distributions have very different ifup programs and I
  355. have not tried those (tell me about it !).
  356. 4) Installing Hotplug for Debian Sarge (testing/unstable)
  357. ---------------------------------------------------------
  358. Thanks to the great work of many people, Debian Sarge has all
  359. the necessary packages and hotplug support, and will work mostly 'out
  360. of the box'.
  361. You will need to install the following packages :
  362. o hotplug
  363. o ifrename
  364. While the installation of Hotplug is simple, its configuration
  365. may seem complex. The current network Hotplug script has 3 modes :
  366. 'all', 'auto' and 'hotplug'. However for our purpose they all produce
  367. the same results when configured. This mode is controlled by the
  368. variable NET_AGENT_POLICY in /etc/default/hotplug.
  369. In the mode "all", Hotplug will run ifup for all network
  370. events. This will result in failure messages if some interfaces have
  371. already been configured by the init scripts. This mode is not
  372. recommended.
  373. In the mode "auto", Hotplug will run ifup only for those
  374. interfaces listed in a auto stanza in /etc/network/interfaces. If
  375. you choose this mode, you need to put in /etc/network/interfaces a
  376. "auto" line for the interfaces you want to control with hotplug.
  377. --------- /etc/network/interfaces -----------
  378. # Enable Hotplug support for "auto" mode (Sarge and later)
  379. auto eth0 eth1 eth2 eth3 eth4 wlan0 wlan1 prism0 prism1 airo0 airo1
  380. ---------------------------------------------
  381. This will result in some failure message at boot time, the
  382. init script will attempt to enable all those interfaces, and generate
  383. an error for all those not available at this time. It will also
  384. generate an error messages for interface which have already been
  385. configured by the init scripts. This mode is also not recommended.
  386. In the mode "hotplug", hotplug network events are ignored by
  387. ifup by default. To enable them you will need to add the following
  388. lines to /etc/network/interfaces :
  389. --------- /etc/network/interfaces -----------
  390. # Enable Hotplug support for "hotplug" mode (Sarge and later)
  391. mapping hotplug
  392. script echo
  393. ---------------------------------------------
  394. To enable them for only selected interfaces, e.g., ethA, make
  395. /etc/network/interfaces look like this :
  396. --------- /etc/network/interfaces -----------
  397. # Enable Hotplug support for "hotplug" mode (Sarge and later)
  398. mapping hotplug
  399. script grep
  400. map ethA
  401. ---------------------------------------------
  402. 5) Installing Hotplug for Debian 3.0
  403. ------------------------------------
  404. Debian 3.0 doesn't come by default with hotplug, but the
  405. hotplug package is available as regular Debian package (on the CD or
  406. downloadable in Debian archive), so you can just install that.
  407. Unfortunately, this version of hotplug is not fully compatible
  408. with kernel 2.6.X. You will need to do the following modifications to
  409. the file /etc/hotplug/net.agent.
  410. ------- /etc/hotplug/net.agent ------------------
  411. --- net.agent-d1 Fri Feb 20 18:18:05 2004
  412. +++ net.agent Fri Feb 20 18:22:50 2004
  413. @@ -26,7 +26,7 @@ if [ "$INTERFACE" = "" ]; then
  414. fi
  415. case $ACTION in
  416. -register)
  417. +add|register)
  418. case $INTERFACE in
  419. # interfaces that are registered after being "up" (?)
  420. @@ -52,7 +52,7 @@ register)
  421. mesg $1 $ACTION event not handled
  422. ;;
  423. -unregister)
  424. +remove|unregister)
  425. # Assume that we want to run ifdown no matter what,
  426. # because it is not going to remove the data from the
  427. # ifstate database otherwise.
  428. -------------------------------------------------
  429. Compared to the version in Sarge, this older version of
  430. hotplug is much more basic, and doesn't have any scanning at boot time
  431. and doesn't need to be enabled in /etc/network/interfaces.
  432. 6) Installing hotplug on other distributions
  433. --------------------------------------------
  434. The canonical version of hotplug is available at :
  435. http://linux-hotplug.sourceforge.net/
  436. Most distributions have customized hotplug packages and
  437. chances are that the canonical version won't completely work on your
  438. system. All these various changing versions make it difficult for me
  439. to tell what exactly needs to be changed in the hotplug scripts to
  440. make them work. However, most should work out of the box.
  441. My guess is that in a few releases, all these problems will
  442. sort themselves out. Just be patient.
  443. 7) Dealing with 'init' hotplug
  444. ------------------------------
  445. In addition to the standard kernel Hotplug events, modern
  446. versions of the Hotplug scripts add init scripts that scan the system
  447. buses and generate pseudo Hotplug events at boot time. For the PCI
  448. buses, the script /etc/hotplug/pci.rc is run, for the USB bus,
  449. /etc/hotplug/usb.rc is run.
  450. The end result is that the Hotplug subsystem will also attempt
  451. to configure built-in devices :
  452. 1) Kernel boots
  453. 2) Init runs, start to initialise the OS
  454. 3) /etc/hotplug/pci.rc runs, generates pseudo Hotplug event
  455. 4) /etc/hotplug/pci.agent loads driver module
  456. 5) Driver module initialises, creates new network device
  457. 6) Kernel generates Network Hotplug event
  458. 7) /etc/hotplug/net.agent runs, configures network device
  459. At this point, you realise that at initialisation, both
  460. Hotplug and the regular init scripts (see "CONFIGURATION FROM INIT
  461. SCRIPTS") are trying to configure the same devices in parallel. This
  462. may create problems and is totally redundant.
  463. Another reason I don't like this mechanism is that it blindly
  464. attempts to load drivers for all hardware present on the system and
  465. doesn't use the module loader configuration files to select preferred
  466. drivers. It's fairly common to have multiple drivers for a given
  467. hardware, and because of Murphy's law, Hotplug will usually load the
  468. wrong one. It's also fairly common to have hardware on the system that
  469. doesn't need enabling (for example, the IDE controller on my SCSI
  470. machine), not loading the driver makes your kernel smaller and boot
  471. faster.
  472. Hotplug does have a way of disabling the loading of drivers
  473. on a case by case basis. Drivers listed in /etc/hotplug/blacklist
  474. will not be loaded.
  475. Hotplug can be disabled for a whole subsystem by editing the
  476. appropriate .rc script in /etc/hotplug, or just deleting/renaming
  477. those files.
  478. 8) Making hotplug scripts call ifrename
  479. ---------------------------------------
  480. The last hotplug step is to make sure that 'ifrename' is run
  481. by the hotplug subsystem at the right time. As before, we want to run
  482. it just before calling 'ifup'.
  483. The latest version of the hotplug scripts have this feature
  484. integrated. However, you need to check that the path used for calling
  485. 'ifrename' is the proper one on your system. And, for older versions
  486. of hotplug scripts, you will need to add this support yourself.
  487. Check the path for ifrename :
  488. --------------------------
  489. > which ifrename
  490. /sbin/ifrename
  491. --------------------------
  492. The patch to add 'ifrename' to hotplug looks like :
  493. ------- /etc/hotplug/net.agent ------------------
  494. --- net.agent-s2 Fri Feb 20 17:18:46 2004
  495. +++ net.agent Fri Feb 20 17:32:43 2004
  496. @@ -40,6 +40,21 @@ add|register)
  497. # we can't do much here without distro-specific knowledge
  498. # such as whether/how to invoke DHCP, set up bridging, etc.
  499. + # Run ifrename as needed - Jean II
  500. + # Remap interface names based on MAC address. This works around
  501. + # the dreaded configuration problem "all my cards are 'eth0'"...
  502. + # This needs to be done before ifup, otherwise ifup will get
  503. + # confused by the name change and because iface needs to be
  504. + # down to change its name.
  505. + if [ -x /sbin/ifrename ] && [ -r /etc/iftab ]; then
  506. + debug_mesg invoke ifrename for $INTERFACE
  507. + NEWNAME=`/sbin/ifrename -i $INTERFACE`
  508. + if [ -n "$NEWNAME" ]; then
  509. + debug_mesg iface $INTERFACE is remapped to $NEWNAME
  510. + INTERFACE=$NEWNAME
  511. + fi;
  512. + fi
  513. +
  514. # RedHat and similar
  515. export IN_HOTPLUG=1
  516. if [ -x /sbin/ifup ]; then
  517. -------------------------------------------------
  518. If your hotplug scripts already include ifrename support then
  519. you should find a section in /etc/hotplug/net.agent looking like the
  520. patch above. Otherwise, just cut'n'paste the patch above in the right
  521. place.
  522. The path for 'ifrename' is used twice above, so don't forget
  523. to modify both occurences.
  524. 9) Loading driver modules
  525. -------------------------
  526. Wow ! The most difficult part is done.
  527. In theory, you don't need to do any specific configuration for
  528. the driver modules to be loaded. The 'pci.agent' and 'usb.agent'
  529. should load the right driver module for you.
  530. Also, you don't need to define aliases in /etc/modprobe.d/* or
  531. in /etc/modprobe.conf, it's useless and may be counterproductive.
  532. If you use a driver compiled statically in the kernel, you
  533. also have nothing to do.
  534. 10) Renaming interfaces
  535. -----------------------
  536. We still use ifrename to assign names to interfaces. The
  537. configuration of 'ifrename' is the same. To keep the possibility of
  538. having multiple wireless cards (one in each CardBus slot), we use
  539. wildcards in both the MAC address and the name :
  540. --------- /etc/iftab -----------------------
  541. # SMC 2835W wireless CardBus card
  542. prism* mac 00:30:B4:*
  543. ---------------------------------------------
  544. If you insert two cards, they would be named prism0 and
  545. prism1. Note that 'name wildcarding' is a feature only available in
  546. 2.6.X and 2.4.30 and later, so if you use older version of 2.4.X you
  547. will need to be explicit and list each card separatly :
  548. --------- /etc/iftab -----------------------
  549. # SMC 2835W wireless CardBus card
  550. prism0 mac 00:30:B4:64:27:8B
  551. prism1 mac 00:30:B4:64:27:8D
  552. ---------------------------------------------
  553. 11) Configuring interfaces
  554. -------------------------
  555. At this point, configuration of Hotplug interfaces is done
  556. just like their built-in counterparts. This part is still distribution
  557. specific, and still already documented in the file DISTRIBUTIONS.txt.
  558. In Debian, you would need to modify the file
  559. /etc/network/interfaces like this :
  560. --------- /etc/network/interfaces -----------
  561. # Enable Hotplug support (Sarge and later)
  562. mapping hotplug
  563. script grep
  564. map prism0
  565. # SMC 2835W wireless CardBus card
  566. iface prism0 inet static
  567. address 10.0.1.2
  568. netmask 255.255.255.0
  569. broadcast 10.0.1.255
  570. wireless-essid THE_ESSID
  571. wireless-mode ad-hoc
  572. wireless-channel 5
  573. ---------------------------------------------
  574. Note that you should not have wireless-* lines if you are
  575. using waproamd to set these parameters.
  576. Now, just cross your fingers and plug the card in the slot...
  577. PCMCIA INTERFACES (16 bits)
  578. ---------------------------
  579. The Pcmcia subsystem has quite some legacy, and can use
  580. various configuration procedures. The Pcmcia subsystem exclusively
  581. uses hotplug for 32 bits cards (if you are using the kernel Pcmcia
  582. modules, which is the only option for 2.6.X). For 16 bit cards cardmgr
  583. is still required for managing the sockets and loading
  584. modules. Cardmgr is configured by files in the /etc/pcmcia directory.
  585. To use Hotplug network configuration with 16 bits Pcmcia
  586. cards, first make sure the Pcmcia subsystem is properly configured and
  587. that cardmgr loads the right driver module (in most case, it
  588. should). Then, make sure that you don't have any configuration entries
  589. in /etc/pcmcia/network.opts and /etc/pcmcia/wireless.opts. Make sure
  590. that none of the entries in your system network configuration use
  591. 'eth0' or 'wlan0' (in /etc/network/interfaces for Debian users).
  592. Then, just follow the procedure described above for
  593. "Configuration Using Hotplug" to configure your network cards.
  594. You might want a little bit of explanation on why this magic
  595. will work (which would help in case it doesn't work).
  596. There are two types of Pcmcia network configuration scripts,
  597. available as /etc/pcmcia/network. The original Pcmcia script
  598. configures network cards using options found in
  599. /etc/pcmcia/network.opts and /etc/pcmcia/wireless.opts. Most
  600. distributions replace it with a script calling 'ifup'. By making sure
  601. that network.opts and wireless.opts are "empty", we neutralise the
  602. first set of scripts. By making sure no system configuration uses
  603. 'eth0' or 'wlan0', we neutralise the second set of scripts, the script
  604. would call 'ifup' with the default interface name, which is usually
  605. 'eth0', ifup would not find a configuration for it and would just
  606. ignore it.
  607. The card would still be configured because hotplug network
  608. events are generated for every interfaces, not only for devices
  609. managed by hotplug. So, net.agent would receive an event and perform
  610. the necessary steps to configure it.
  611. Personally, I'm still using the original Pcmcia scripts for my
  612. Pcmcia cards as described in the file PCMCIA.txt, because it still
  613. works and I will migrate my complex configurations over time.
  614. You can also decide to not use Hotplug for Pcmcia cards and
  615. modify the distribution Pcmcia scripts in /etc/pcmcia/* to handle
  616. Pcmcia cards with ifrename. You would need to modify
  617. /etc/pcmcia/network to add 'ifrename' before 'ifup' the same way it
  618. was done for /etc/hotplug/net.agent. But, as in the long term Pcmcia
  619. will migrate to Hotplug, I would not bother...
  620. MANUAL LOADING, DOCKING STATIONS
  621. --------------------------------
  622. Manual loading is used for built-in network interfaces that
  623. are only use at specific time, and that you want disabled the rest of
  624. the time. We assume that you still use modules so that when the
  625. interface is not used you can remove the driver from the kernel.
  626. First, you need to set the configuration for those interfaces,
  627. the same way it's done for other network interfaces. The main
  628. difference is that you need to specify that those interfaces should
  629. not be enabled at boot time. It's also a good idea to disable Hotplug
  630. init scripts.
  631. With Debian, you just need to make sure that the 'auto"
  632. keyword doesn't apply to this interface.
  633. If you use drivers statically built in the kernel, make sure
  634. that ifrename runs at boot time (see CONFIGURATION FROM INIT
  635. SCRIPTS). Once it's done, you can just enable and disable those
  636. interfaces with 'ifup ethX' and 'ifdown ethX'.
  637. If you use both a modular system, make sure that the
  638. 'on-demand' module loading is properly configured :
  639. --------- /etc/modprobe.d/local or /etc/modprobe.conf ------
  640. # HP 100VG J2585B PCI card
  641. alias eth2 hp100
  642. # AMD AMD PCnet LANCE PCI card
  643. alias eth4 pcnet32
  644. ------------------------------------------------------------
  645. Then, you should instruct 'ifup' to load module and use
  646. ifrename prior to configuring the interface, and remove the module
  647. when going down. With Debian, this is done with :
  648. --------- /etc/network/interfaces -----------
  649. # AMD AMD PCnet LANCE PCI card
  650. # noauto
  651. iface eth4 inet dhcp
  652. pre-up /sbin/ifrename -p -n eth4
  653. post-down /sbin/modprobe -r eth4
  654. # HP 100VG J2585B PCI card
  655. # noauto
  656. iface eth2 inet static
  657. address 10.0.0.2
  658. netmask 255.255.255.0
  659. broadcast 10.0.0.255
  660. gateway 10.0.0.1
  661. pre-up /sbin/ifrename -p -n eth2
  662. post-down /sbin/modprobe -r eth2
  663. ---------------------------------------------
  664. We use the '-n' option of ifrename to specify the name of the
  665. interface after renaming. This assume that the mapping for those
  666. interfaces don't use wildcards. The '-p' option make sure ifrename
  667. probes the module prior to using it.
  668. Using "modprobe -r" make sure that if the driver is composed
  669. of multiple module all the modules are unloaded.
  670. To enable the interface, just use :
  671. -----------------------------------
  672. ifup eth4
  673. -----------------------------------
  674. And to disable the interface :
  675. -----------------------------------
  676. ifdown eth4
  677. -----------------------------------
  678. This solution is obviously Debian specific, but could be
  679. adapted to other distributions. If you can't manage to get your
  680. distributions to use those tricks, you can do things manually.
  681. If you don't use Hotplug, you enable an interface with :
  682. -----------------------------------
  683. modprobe eth4
  684. ifrename
  685. ifup eth4
  686. -----------------------------------
  687. If you use hotplug, you only need to do :
  688. -----------------------------------
  689. modprobe eth4
  690. -----------------------------------
  691. On the other hand, disabling the interface is done with :
  692. -----------------------------------
  693. ifdown eth4
  694. modprobe -r eth4
  695. -----------------------------------
  696. Docking stations for laptops may contain built-in
  697. interfaces. My previous laptop had one, and Linux had no support for
  698. it. After docking, I was able to bring up the network ISA card in the
  699. docking station.
  700. However, with most laptops and version of Linux, the issue is
  701. that after docking, the new devices are not seen. The solutions is to
  702. force a rescan of the PCI bus. Documentation is unclear on that, maybe
  703. 'scanpci' may help.
  704. To be able to simply manage my docking station, I had created
  705. two little scripts to enable and disable my network interface.
  706. After docking, you would run :
  707. -------- /sbin/dock ----------------------------
  708. #!/bin/sh
  709. modprobe eth4
  710. ifrename
  711. ifup eth4
  712. ------------------------------------------------
  713. And prior to undocking, you would run :
  714. -------- /sbin/undock ----------------------------
  715. #!/bin/sh
  716. ifdown eth4
  717. modprobe -r eth4
  718. ------------------------------------------------
  719. Thanks to 'ifrename', the network interface in your dock will
  720. always be properly configured regardless of if you have a Pcmcia
  721. network card in the Pcmcia slot or not.
  722. SCHEMES (MULTI-CONFIG)
  723. ----------------------
  724. Most Ethernet cards will only connect to a single network, or
  725. can use DHCP to be auto-configured. With Wireless Cards, it's much
  726. more likely that you will need multiple configurations, for example at
  727. work, at home and on-the-go.
  728. Most distributions have various level of support for such
  729. schemes. Some distributions offer simple network schemes, while other
  730. offer "overall" schemes changing the whole configuration. I document
  731. the support for schemes in various distributions in the file
  732. DISTRIBUTIONS.txt.
  733. You can also use tools such as ifplugd, waproamd or
  734. wlandetect. Those tools are a kind of "wireless-DHCP", they attempt to
  735. automatically detect the proper wireless configuration and apply
  736. it. Most will also attempt to detect network changes.
  737. The main limitation of those tools is that they offer very
  738. little manual control. If two valid alternatives are possible, you
  739. can't switch between them. If a configuration can't be detected, they
  740. usually fail.
  741. That's the same concept as using DHCP versus Static IP
  742. addresses. Some people are very happy with DHCP, my style is Static IP
  743. addresses.
  744. If you use Debian and want to use simple manual schemes, these
  745. are the things you need to do.
  746. 1) Make sure that 'ifscheme' and 'ifscheme-mapping' are
  747. installed on the system. You may find them in a separate tar file on
  748. my web site.
  749. 2) Check the path for 'ifscheme-mapping' (using whereis).
  750. 3) Modify you /etc/network/interface to add proper mapping and
  751. configuration.
  752. ------- /etc/network/interfaces ----------------------
  753. # Enable Hotplug support (Sarge and later)
  754. mapping hotplug
  755. script echo
  756. # SMC 2835W wireless CardBus card
  757. mapping prism0
  758. script /sbin/ifscheme-mapping
  759. iface prism0-any inet dhcp
  760. wireless-essid any
  761. wireless-mode managed
  762. iface prism0-adhoc inet static
  763. address 10.0.1.2
  764. network 10.0.1.0
  765. netmask 255.255.255.0
  766. broadcast 10.0.1.255
  767. wireless-essid THE_ESSID
  768. wireless-mode ad-hoc
  769. wireless-channel 5
  770. iface prism0-other inet static
  771. address 10.10.10.2
  772. network 10.10.10.0
  773. netmask 255.255.255.0
  774. broadcast 10.10.10.255
  775. wireless-essid ANOTHER_ESSID
  776. wireless-mode ad-hoc
  777. wireless-key "s:secure"
  778. ------------------------------------------------------
  779. FIRMWARE LOADING
  780. ----------------
  781. A lot of modern wireless card don't have built in firmware and
  782. need firmware loading. Recent kernels (2.6.X) have a firmware
  783. loader. These are a few notes on how to use it.
  784. First, read the documentation coming with your driver, because
  785. each driver has specificities (like the name of the firmware file it
  786. requires). Some drivers may offer additional ways to load the
  787. firmware, but in the long term things should be standardised around
  788. the hotplug method to simplify packaging in distributions.
  789. You need to compile your kernel with firmware loading
  790. (CONFIG_FW_LOADER in "Generic Driver Options"). If your driver was
  791. built from the kernel, chances are that it enabled this feature
  792. already. Make sure you boot from this new kernel.
  793. The 'sysfs' file system must be mounted. The easiest is to
  794. mount it at boot time, add a line for it in /etc/fstab :
  795. -------- /etc/fstab ------------------------------
  796. sysfs /sys sysfs defaults 0 0
  797. --------------------------------------------------
  798. Then, you add the firmware file in the directory where it's
  799. expected, which is /usr/lib/hotplug/firmware/ in most cases.
  800. Most distributions nowadays have a version of the Hotplug
  801. scripts that knows how to deal with firmware. If it is not the case,
  802. just grab the 'firmware.agent' file from an alternate source and copy
  803. it into your /etc/hotplug directory (make sure it's executable).
  804. You can try the canonical version :
  805. http://linux-hotplug.sourceforge.net/
  806. Or Debian's version :
  807. http://packages.debian.org/unstable/admin/hotplug
  808. Note that firmware loading will usually only work with
  809. interfaces that are fully managed by Hotplug. This is the only way to
  810. ensure the that proper sequence of action is happening in the right
  811. order every time. Firmware loading may not work properly for
  812. interfaces configured in the init scripts.
  813. This means that if you have a built-in interface that require
  814. firmware loading, you should just use manage those interfaces like
  815. removable interfaces (see section above). However, interface
  816. configuration need to be explicitly triggered at boot time.
  817. One possibility is to set-up Hotplug to be run from the init
  818. script at boot time. This is usually an option for recent
  819. distributions (it's not the case for Hotplug in Debian 3.0). But, we
  820. have seen that this has some issues.
  821. The other possibility is to use an hybrid between the init
  822. script method and the hotplug method. First, you need to add an alias
  823. for the driver in /etc/modprobe.conf. Then, you need to specify a
  824. mapping for this interface in /etc/iftab, and specify a configuration
  825. for this interface and that it is enabled at boot time. Lastly,
  826. you make sure that the network init scripts run 'ifrename
  827. -p'. 'ifrename' will trigger the module to load, and all the Hotplug
  828. events will be generated properly to configure the interface.
  829. DEVICES WITH MULTIPLE NAMES
  830. ---------------------------
  831. Some wireless drivers offer multiple network interfaces for
  832. the same device. A classical example is the Aironet driver that
  833. creates a 'ethX' and 'wifiY' for each card.
  834. 'ifrename' allows you a finer selection of interfaces than
  835. 'nameif'. For example, to only rename the pseudo-Ethernet network
  836. interface name of the Aironet driver, you would do :
  837. --------- /etc/iftab -----------------------
  838. # Cisco Aironet 350 wireless Pcmcia card
  839. airo* mac 00:07:0E:* arp 1
  840. ---------------------------------------------
  841. After that, your device would be available through 'eth0' and
  842. 'wifi0'.
  843. You can rename both interfaces. You just need to remember that
  844. 'ifrename' starts matching from the last line of the file, so you
  845. would do :
  846. --------- /etc/iftab -----------------------
  847. # Cisco Aironet 350 wireless Pcmcia card
  848. wifi* mac 00:07:0E:*
  849. airo* mac 00:07:0E:* arp 1
  850. ---------------------------------------------
  851. The current version of 'ifrename' supports only the most useful
  852. selectors, but it is architectured such as adding selectors is relatively
  853. trivial. If you find a case that 'ifrename' can't handle, you should
  854. just extend it.
  855. DEVICES WITHOUT MAC ADDRESSES
  856. -----------------------------
  857. Most Ethernet and Wireless devices have a fixed and unique MAC
  858. address, and it is therefore advised to name them based on this
  859. criteria. However, there are also network interfaces that don't have a
  860. fixed and unique MAC address, for example Ethernet over USB, IP over
  861. FireWire, PPP and tunnel interfaces.
  862. The driver for those devices creates the interface with a name
  863. specific to the driver, such as ppp* for PPP interfaces and usb* for
  864. Ethernet over USB, and therefore they are easy to identify and
  865. configure, and few users feel the need to rename them. Moreover, some
  866. of them, such as PPP, have their own configuration scripts and
  867. methodology addressing their unique needs.
  868. There are a few cases where you might want to rename
  869. interfaces without MAC addresses. One example is two Ethernet over USB
  870. dongles. The way to do this is to use alternate ifrename
  871. selectors. Choosing the right selector depends on what you want to
  872. achieve.
  873. A quick theoretical example to illustrate :
  874. --------- /etc/iftab -----------------------
  875. # All other usbnet devices
  876. usb* driver usbnet
  877. # Specific usbnet devices
  878. usb-p firmware "Prolific PL-2301/PL-2302"
  879. usb-4 bus-info usb-00:02.0-1.4
  880. ---------------------------------------------
  881. TROUBLESHOOTING
  882. ---------------
  883. If your interface doesn't show up as expected with ifconfig,
  884. you will need to find out why. First, you need to be familiar with the
  885. sequence of actions in the system and find which one did not happen.
  886. You need to check that the driver module(s) was loaded using
  887. 'lsmod'.
  888. You need to check if the interface was properly renamed with
  889. 'ifrename'. You can use 'ifrename -D -V' to debug your /etc/iftab.
  890. Get the list of interfaces on your system with 'ifconfig -a'
  891. or 'cat /proc/net/dev', and check if an interface is using the name
  892. you assigned or 'eth0'. Check any suspicious interfaces with 'ifconfig
  893. eth0', and check its MAC address. Note that some rare drivers don't
  894. have a proper MAC address before brought up, which fools ifrename.
  895. Verify that no line in /etc/iftab matches the all-zero MAC
  896. address. The all-zero MAC address matches the loopback interface 'lo'
  897. and various pseudo network devices, renaming the loopback interface is
  898. highly discouraged.
  899. You need to check which configuration was given to the
  900. interface using 'ifconfig' and 'iwconfig'.
  901. The Hotplug subsystem has also good debugging facilities.
  902. To enable Hotplug debugging, just make sure the variable DEBUG
  903. is defined in /sbin/hotplug :
  904. --------- /sbin/hotplug ------------------------------
  905. --- /sbin/hotplug-old Tue Mar 26 09:00:20 2002
  906. +++ /sbin/hotplug Fri Feb 20 18:40:38 2004
  907. @@ -22,7 +22,7 @@
  908. cd /etc/hotplug
  909. . hotplug.functions
  910. -# DEBUG=yes export DEBUG
  911. +DEBUG=yes export DEBUG
  912. if [ "$DEBUG" != "" ]; then
  913. mesg "arguments ($*) env (`env`)"
  914. ------------------------------------------------------
  915. Then, you can check your message logs for Hotplug events with
  916. 'tail -f /var/log/messages'. Verify that the various Hotplug events
  917. happen as expected (pci, firmware, net...), and verify the log
  918. messages from 'net.agent'.
  919. Have fun...
  920. Jean