/[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.6 - (show annotations) (download) (as text)
Wed Dec 21 13:27:46 2005 UTC (9 years ago) by jkt
Branch: MAIN
Changes since 1.5: +26 -27 lines
File MIME type: application/xml
coding style fixes, *no content change*

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

  ViewVC Help
Powered by ViewVC 1.1.20