/[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.13 - (show annotations) (download) (as text)
Sun Oct 30 11:56:08 2011 UTC (2 years, 5 months ago) by swift
Branch: MAIN
Changes since 1.12: +5 -5 lines
File MIME type: application/xml
Fix bug #388953 - Refer to /usr/share/doc/openrc-*/net.example.bz2 instead of /etc/conf.d/net.example

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

  ViewVC Help
Powered by ViewVC 1.1.20