lfs-uefi: fix efivar-37 FTBFS
[linux_from_scratch_hints.git] / network-recognition.txt
blobf0e582be71176b7c01264b6988b23c5b1076d465
1 AUTHOR: Eloi Primaux eloi AT bliscat dot org
3 DATE: 2007-10-11
5 LICENSE: GNU Free Documentation License Version 2
7 SYNOPSIS: Very basic network recognition using MAC address
9 PRIMARY URL:
10 https://www.harasdebondereau.com/bliscat/hints/network-recognition/network-recognition-0.0.2.tar.bz2
12 DESCRIPTION:
13         This hint explains how to make a very basic automatic network recognition
14 ATTACHMENTS:
16 http://www.linuxfromscratch.org/hints/downloads/files/ATTACHMENTS/network-recognition/network-recognition-0.0.2.tar.bz2
18 PREREQUISITES:
20 - A working LFS-6.2 system or newer with wireless capabilities  
21 - Almost two networks services like ipv4-static/dhcpcd installed
23 HINT:
25 0) Requirement and Optional tools
26 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 Well, we will need the arpdiscover tool which comes from the arptools package.
29 The ArpTools package provides arpdiscover, arpfool and the so called arpflush.
30 You should only install the arpdiscover program, the others are used for network
31 security check.
33 The ArpTools package requires libnet and libpcap
35 0.1) libpcap >= 0.8.1
36 ~~~~~~~~~~~~~~~~~~~~~~
37 download it from:
38 http://ovh.dl.sourceforge.net/sourceforge/libpcap/libpcap-0.8.1.tar.gz
40 install it with these commands:
41 ./configure --prefix=/usr &&
42 make &&
43 make install
45 0.2) libnet >= 1.1.3-RC-01
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~
47 download it from:
48 http://www.packetfactory.net/libnet/dist/libnet-1.1.3-RC-01.tar.gz
50 install it with these commands:
51 ./configure --prefix=/usr &&
52 make &&
53 make install
55 0.3) ArpTools >=  1.0.2 'The core'
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57 download it from:
58 http://freshmeat.net/redir/arptools/63568/url_tgz/arptools-1.0.2.tar.gz
60 install it with these commands:
61 ./configure --prefix=/usr &&
62 make &&
63 make install
65 0.3) NetDiscover >=  0.3-beta6
66 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 you can download it from:
68 http://nixgeneration.com/~jaime/netdiscover/releases/netdiscover-0.3-beta6.tar.gz
70 install it with:
71 ./configure --prefix=/usr &&
72 make &&
73 make install
75 0.3) ifplugd >=  0.28
76 ~~~~~~~~~~~~~~~~~~~~~
77 you can download it from:
78 http://0pointer.de/lennart/projects/ifplugd/ifplugd-0.28.tar.gz
79 patches from ubuntnu:
80 http://launchpadlibrarian.net/6580436/ifplugd_0.28-2.3ubuntu1.diff.gz
83 in the package directory, run this command to really apply the patch:
84 gunzip ../ifplugd_0.28-2.3ubuntu1.diff
85 patch -Np1 -i ../ifplugd_0.28-2.3ubuntu1.diff
86 patch -Np1 -i debian/patches/01_fix_ftbfs_feisty.dpatch
88 ifplugd install it's configuration in /etc/ifplugd, i don't like this
89 run:
90 sed 's,/ifplugd/ifplugd.action,/sysconfig/ifplugd/ifplugd.action,' -i src/ifplugd.c
91 sed 's,ifplugd/ifplugd.conf,/sysconfig/ifplugd/ifplugd.conf,' -i conf/ifplugd.init.in
93 now compile and install:
94 ./configure --prefix=/usr --sysconfdir=/etc &&
95 make &&
96 make install
100 1) This Hints
101 ~~~~~~~~~~~~~
102 Well ...
103 now we have a tool which can discover MAC address  
105 1.1) Install Files and Directories (this is only a proposal)
106 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 Extract network-recognition-0.0.1.tar.bz2 and in the extracted directory and run the
108 following commands:
110 OPION 1 : 
112   install -dv -m 700 /etc/sysconfig/network.d
113   install -dv /etc/sysconfig/network-recognition
114   install -dv /usr/share/doc/network-recognition
115         
116   install -m 744 netdevices-example /etc/sysconfig/network.d/netdevice.example
117   install -v -m644 network-recognition-conf /etc/sysconfig/network-recognition/network-recognition.conf
118   install -v -m750 network-recognition-script /usr/sbin/network-recognition
121 OPTION 2: same as above but in a script
122         ./install.sh (if present ;)
124 2) The principle
125 ~~~~~~~~~~~~~~~~
127 The network-recognition script use a netdevices file in which are stored
128 network names, with specific ip and mac address of knowned permanent network
129 devices such as routers. The script call arpdiscover to check if that device is
130 present, if the device is present the script exit the loop and returns the name
131 of the network it successfully recognized.
133 This first discovering method is really slow (10-15 sec per scan), it uses
134 arpdiscover, the second method is faster and uses netdiscover.
136 2) IP service integration
137 ~~~~~~~~~~~~~~~~~~~~~~~~~
138 In the case of wpa-service you simply edit the wpa-actions file and replace
139 the function get_ssid by :
141 function get_ssid {
142 if [ "$EVENT" == "CONNECTED" ]; then
143         RET=`network-discover $IFACE`
144         echo $RET > "$WPA_ACCESS_DIR/$IFACE.ssid"
145         else
146         if [ -e "$WPA_ACCESS_DIR" ]; then
147                 RET=$(cat "$WPA_ACCESS_DIR/$IFACE.ssid")
148         fi
152 In the case of ifplugd you can modify the ifplugd.action file like this:
154 BEGIN of ifplugd.action
155 set -e
156 . /etc/sysconfig/network-recognition/network-recognition.conf
158 if [ -z "$1" ] || [ -z "$2" ] ; then
159         echo "Wrong arguments" > /dev/stderr
160         exit 1
163 function reload_avahi {
164         $AVAHI_DAEMON -c
165         RET=$?
166         if [ "$RET" == "0" ]; then
167                 $AVAHI_DAEMON -r
168         fi
171 IFACE=$1
172 [ "$2" == "up" ] && EVENT="CONNECTED"
173 [ "$2" == "down" ] && EVENT="DISCONNECTED"
175 function get_ssid {
176 if [ "$EVENT" == "CONNECTED" ]; then
177         RET=`network-recognition $IFACE` &> /dev/null
178         echo $RET > "/tmp/$IFACE.ssid"
179         else
180         if [ -e "/tmp/$IFACE.ssid" ]; then
181                 RET=$(cat "/tmp/$IFACE.ssid")
182         fi
187 if [ "$EVENT" == "CONNECTED" ]; then
188         get_ssid
189         SSID=$RET
190         # configure network, signal DHCP client, etc.
191         # If special networks definition exist, use it
192         if [ -f "$NETWORKDIR/$SSID" ]; then
193                 IFCONFIG="$NETWORKDIR/$SSID"
194                 . $IFCONFIG
195                 export IFCONFIG
196                 $SERVICESDIR/$SERVICE $IFACE up
197         else
198                 IFCONFIG="$NETWORKDIR/AUTO"
199                 . $IFCONFIG
200                 export IFCONFIG
201                 $SERVICESDIR/$SERVICE $IFACE up
202         fi
203         RET=$?
204         # reload the Avahi daemon if it runs
205         reload_avahi
206         exit $RET
210 if [ "$EVENT" == "DISCONNECTED" ]; then
211     # remove network configuration, if needed
212         get_ssid
213         if [ "x$RET" != "x" ]; then
214         # this is false when there is nothing known around
215         # and when the system is disabling the service
216         SSID=$RET
217         # configure network, signal DHCP client, etc.
218         # If special networks definition exist, use it
219         if [ -f "$NETWORKDIR/$SSID" ]; then
220                 IFCONFIG="$NETWORKDIR/$SSID"            
221                 . $IFCONFIG
222                 export IFCONFIG
223                 $SERVICESDIR/$SERVICE $IFACE down
224         else
225                 IFCONFIG="$NETWORKDIR/AUTO"
226                 . $IFCONFIG
227                 export IFCONFIG
228                 $SERVICESDIR/$SERVICE $IFACE down
229         fi
230         fi
231         RET=$?
232         # reload the Avahi daemon if it runs
233         reload_avahi
234         exit $RET
236 END of ifplugd.action
238 remember to add your computer network device to /etc/sysconfig/ifplugd/ifplugd.conf 
240 3) Configuration
241 ~~~~~~~~~~~~~~~~
243 Script configuration go in the 
244 /etc/sysconfig/network-recognition/network-recognition.conf file
247 2.1) Network configurations (IP):
248 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250 In fact i strongly use the wpa-service ipconf methods, that why i use the same
251 configuration files for networks.
253 this part comes from the wpa-service hint:
255 you can set up your network according to it's network_name (eg SSID), this means
256 that if the SSID "DHCP_network" manage ip via a dhcp server, wpa-service will
257 use the SSID file descriptor to set up you network when connecting to the SSID
258 network.
260 Those ssid descriptors are named with the name of the SSID they describe,
261 and took place in the /etc/sysconfig/network.d directory.
263 The "AzErTy" SSID descriptor will be /etc/sysconfig/network.d/AzeRtY
265 2.1.1) SSID descriptor syntax:
266 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268 An SSID descriptor is a regular network configuration file as used in LFS BOOK.
269 it means that if SSID "IPV4" use ipv4-static, the the descriptor "IPV4" will be
271         cat > /etc/sysconfig/network.d/IPV4 << "EOF"
272         ONBOOT=yes
273         SERVICE=ipv4-static
274         IP=192.168.1.1
275         GATEWAY=192.168.1.2
276         PREFIX=24
277         BROADCAST=192.168.1.255
278         EOF
280 and if the "DHCP" SSID use dhcp :
282         cat > /etc/sysconfig/network.d/DHCP << "EOF"
283         ONBOOT="yes"
284         SERVICE="dhcpcd"
285         DHCP_START="-o"
286         DHCP_STOP="-k -o"
287         # the '-o' prevent your interface being destroyed by dhcpcd 
289         # Set PRINTIP="yes" to have the script print
290         # the DHCP assigned IP address
291         PRINTIP="no"
293         # Set PRINTALL="yes" to print the DHCP assigned values for
294         # IP, SM, DG, and 1st NS. This requires PRINTIP="yes".
295         PRINTALL="no"
296         EOF
298 for convenience, your ip manager will fall back to /etc/sysconfig/network.d/AUTO
299  when no SSID descriptor is available.
301 Then install a common/automatic network configuration:
302 I use dhcpcd:   
304         cat > /etc/sysconfig/network.d/AUTO << "EOF"
305         ONBOOT="yes"
306         SERVICE="dhcpcd"
307         DHCP_START="-o"
308         DHCP_STOP="-k -o"
309         # the '-o' prevent your interface being destroyed by dhcpcd
311         # Set PRINTIP="yes" to have the script print
312         # the DHCP assigned IP address
313         PRINTIP="no"
315         # Set PRINTALL="yes" to print the DHCP assigned values for
316         # IP, SM, DG, and 1st NS. This requires PRINTIP="yes".
317         PRINTALL="no"
318         EOF
320 3) The netdevice file (The network description) 
321 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323 We've installed an example file in /etc/sysconfig/network.d
325 Now edit the newly created netdevices file:
326 Which should contains something similar to:
328 network={
329         network_name=LaboPhy
330         # ip of the permanent device
331         ip=192.168.0.23
332         # mac address of the permanent device
333         mac=00:0F:B5:EE:88:8C
337 You will directly see that you can define more than one network and also more
338 than one permanent device by duplicating the network blocs
340 You can feed this file by running directly arpdiscover when you plug in a new
341 network:
343 arpdiscover IP iterations computer_network_device
346 another usefull tool to do this would be netdiscover
350 4) Feeding our netdevices file
351 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352 The perfect tool: NetDiscover
354 use it as follow:
356 netdiscover -i IFACE
358 it will show you everything connected to your network (and more)
361 CHANGELOG:
362 2007 11 11 First release, first send to lfshint
363 2007 11 22 Second release added netdiscover method and some bugs fixed
364                         + avahi-daemon reload in ifplugd.action
365                         + a work around for bad promiscuous netcards mode