/[gentoo]/xml/htdocs/doc/en/handbook/hb-net-functions.xml
Gentoo

Contents of /xml/htdocs/doc/en/handbook/hb-net-functions.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download) (as text)
Sat Oct 28 09:17:55 2006 UTC (8 years, 6 months ago) by neysx
Branch: MAIN
Changes since 1.8: +5 -1 lines
File MIME type: application/xml
Moved chapter abstracts into shared chapters
No content change, hence no bump

1 swift 1.1 <?xml version="1.0" encoding="UTF-8"?>
2     <!DOCTYPE sections SYSTEM "/dtd/book.dtd">
3    
4     <!-- The content of this document is licensed under the CC-BY-SA license -->
5 swift 1.2 <!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
6 swift 1.1
7 neysx 1.9 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-net-functions.xml,v 1.8 2006/08/30 22:52:28 nightmorph Exp $ -->
8 neysx 1.5
9 swift 1.1 <sections>
10    
11 neysx 1.9 <abstract>
12     If you're feeling adventurous, you can add your own functions to networking.
13     </abstract>
14    
15 nightmorph 1.8 <version>7.0</version>
16     <date>2006-08-30</date>
17 swift 1.1
18     <section>
19     <title>Standard function hooks</title>
20     <body>
21    
22     <p>
23 jkt 1.7 Four functions can be defined which will be called surrounding the
24     <c>start</c>/<c>stop</c> operations. The functions are called with the
25     interface name first so that one function can control multiple adapters.
26 swift 1.1 </p>
27    
28     <p>
29 jkt 1.7 The return values for the <c>preup()</c> and <c>predown()</c> functions should
30     be 0 (success) to indicate that configuration or deconfiguration of the
31     interface can continue. If <c>preup()</c> returns a non-zero value, then
32     interface configuration will be aborted. If <c>predown()</c> returns a non-zero
33     value, then the interface will not be allowed to continue deconfiguration.
34 swift 1.1 </p>
35    
36     <p>
37 jkt 1.7 The return values for the <c>postup()</c> and <c>postdown()</c> functions are
38     ignored since there's nothing to do if they indicate failure.
39 swift 1.1 </p>
40    
41     <p>
42 jkt 1.6 <c>${IFACE}</c> is set to the interface being brought up/down. <c>${IFVAR}</c>
43     is <c>${IFACE}</c> converted to variable name bash allows.
44 swift 1.1 </p>
45    
46     <pre caption="pre/post up/down function examples">
47     preup() {
48 swift 1.4 <comment># Test for link on the interface prior to bringing it up. This
49     # only works on some network adapters and requires the mii-diag
50     # package to be installed.</comment>
51     if mii-tool ${IFACE} 2> /dev/null | grep -q 'no link'; then
52     ewarn "No link on ${IFACE}, aborting configuration"
53     return 1
54     fi
55    
56     <comment># Test for link on the interface prior to bringing it up. This
57     # only works on some network adapters and requires the ethtool
58     # package to be installed.</comment>
59     if ethtool ${IFACE} | grep -q 'Link detected: no'; then
60     ewarn "No link on ${IFACE}, aborting configuration"
61     return 1
62     fi
63 swift 1.1
64 swift 1.4 <comment># Remember to return 0 on success</comment>
65     return 0
66 swift 1.1 }
67    
68     predown() {
69 swift 1.4 <comment># The default in the script is to test for NFS root and disallow
70     # downing interfaces in that case. Note that if you specify a
71     # predown() function you will override that logic. Here it is, in
72     # case you still want it...</comment>
73     if is_net_fs /; then
74     eerror "root filesystem is network mounted -- can't stop ${IFACE}"
75     return 1
76     fi
77 swift 1.1
78 swift 1.4 <comment># Remember to return 0 on success</comment>
79     return 0
80 swift 1.1 }
81    
82     postup() {
83 swift 1.4 <comment># This function could be used, for example, to register with a
84     # dynamic DNS service. Another possibility would be to
85     # send/receive mail once the interface is brought up.</comment>
86 swift 1.1 return 0
87     }
88    
89     postdown() {
90 swift 1.4 <comment># This function is mostly here for completeness... I haven't
91     # thought of anything nifty to do with it yet ;-)</comment>
92     return 0
93 swift 1.1 }
94     </pre>
95    
96     </body>
97     </section>
98     <section>
99     <title>Wireless Tools function hooks</title>
100     <body>
101    
102     <note>
103     This will not work with WPA Supplicant - but the <c>${ESSID}</c> and
104 jkt 1.7 <c>${ESSIDVAR}</c> variables are available in the <c>postup()</c> function.
105 swift 1.1 </note>
106    
107     <p>
108 jkt 1.6 Two functions can be defined which will be called surrounding the associate
109     function. The functions are called with the interface name first so that one
110     function can control multiple adapters.
111 swift 1.1 </p>
112    
113     <p>
114 jkt 1.7 The return values for the <c>preassociate()</c> function should be 0 (success)
115     to indicate that configuration or deconfiguration of the interface can continue.
116     If <c>preassociate()</c> returns a non-zero value, then interface configuration
117     will be aborted.
118 swift 1.1 </p>
119    
120     <p>
121 jkt 1.7 The return value for the <c>postassociate()</c> function is ignored since
122     there's nothing to do if it indicates failure.
123 swift 1.1 </p>
124    
125     <p>
126 swift 1.3 <c>${ESSID}</c> is set to the exact ESSID of the AP you're connecting to.
127 jkt 1.6 <c>${ESSIDVAR}</c> is <c>${ESSID}</c> converted to variable name bash allows.
128 swift 1.1 </p>
129    
130     <pre caption="pre/post association functions">
131     preassociate() {
132 swift 1.4 <comment># The below adds two configuration variables leap_user_ESSID
133     # and leap_pass_ESSID. When they are both configured for the ESSID
134     # being connected to then we run the CISCO LEAP script</comment>
135    
136     local user pass
137     eval user=\"\$\{leap_user_${ESSIDVAR}\}\"
138     eval pass=\"\$\{leap_pass_${ESSIDVAR}\}\"
139    
140     if [[ -n ${user} &amp;&amp; -n ${pass} ]]; then
141     if [[ ! -x /opt/cisco/bin/leapscript ]]; then
142     eend "For LEAP support, please emerge net-misc/cisco-aironet-client-utils"
143     return 1
144     fi
145     einfo "Waiting for LEAP Authentication on \"${ESSID//\\\\//}\""
146     if /opt/cisco/bin/leapscript ${user} ${pass} | grep -q 'Login incorrect'; then
147     ewarn "Login Failed for ${user}"
148     return 1
149     fi
150     fi
151 swift 1.1
152 swift 1.4 return 0
153 swift 1.1 }
154    
155     postassociate() {
156 swift 1.4 <comment># This function is mostly here for completeness... I haven't
157     # thought of anything nifty to do with it yet ;-)</comment>
158 swift 1.1
159 swift 1.4 return 0
160 swift 1.1 }
161     </pre>
162    
163     <note>
164 jkt 1.7 <c>${ESSID}</c> and <c>${ESSIDVAR}</c> are unavailable in <c>predown()</c> and
165     <c>postdown()</c> functions.
166 swift 1.1 </note>
167    
168     </body>
169     </section>
170    
171     </sections>

  ViewVC Help
Powered by ViewVC 1.1.20