/[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.1 - (show annotations) (download) (as text)
Thu Jun 9 07:33:59 2005 UTC (11 years, 11 months ago) by swift
Branch: MAIN
File MIME type: application/xml
#88188 - New baselayout -> new part on the Gentoo Handbook

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.0 -->
6
7 <sections>
8
9 <version>1.0</version>
10 <date>2005-06-06</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<br/>
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
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
105 associate function. The functions are called with the interface
106 name first so that one function can control multiple adapters.
107 </p>
108
109 <p>
110 The return values for the preassociate function should be 0
111 (success) to indicate that configuration or deconfiguration of the
112 interface can continue. If preassociate returns a non-zero value, then
113 interface configuration will be aborted.
114 </p>
115
116 <p>
117 The return value for the postassociate function is ignored
118 since there's nothing 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<br/>
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 postdown() functions
161 </note>
162
163 </body>
164 </section>
165
166 </sections>

  ViewVC Help
Powered by ViewVC 1.1.20