/[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.4 - (show annotations) (download) (as text)
Tue Jun 14 10:16:47 2005 UTC (9 years, 2 months ago) by swift
Branch: MAIN
Changes since 1.3: +56 -56 lines
File MIME type: application/xml
Use two spaces instead of a tab

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

  ViewVC Help
Powered by ViewVC 1.1.20