Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 337 lines (288 sloc) 10.989 kb
3027542 Remove trailing spaces
Frans Pop authored
1 /*
2 netcfg.c - Configure a network via DHCP or manual configuration
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
3 for debian-installer
e1d3f00 Works now, asks a few questions through debconf, then write etc/netwo…
David Whedon authored
4
489c2b5 - add french templates
David Whedon authored
5 Copyright (C) 2000-2002 David Kimdon <dwhedon@debian.org>
dbc5642 give some credit where credit is due
Joshua Kwan authored
6 and others (see debian/copyright)
3027542 Remove trailing spaces
Frans Pop authored
7
101fd7e add copyright, added German translatiosn from Michael Bramer <grisu@d…
David Whedon authored
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
3027542 Remove trailing spaces
Frans Pop authored
12
101fd7e add copyright, added German translatiosn from Michael Bramer <grisu@d…
David Whedon authored
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
3027542 Remove trailing spaces
Frans Pop authored
17
101fd7e add copyright, added German translatiosn from Michael Bramer <grisu@d…
David Whedon authored
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
6a47667 * Update GPL notices with the FSF's new address.
Colin Watson authored
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5c8bf69 check hostname to make sure it is valid
David Whedon authored
21
99a8525 Starting the network configuration. First goal iwill be manual confi…
David Whedon authored
22 */
101fd7e add copyright, added German translatiosn from Michael Bramer <grisu@d…
David Whedon authored
23
e86b003 Don't log "Starting netcfg" messages when invoked as ptom.
Colin Watson authored
24 #include "netcfg.h"
e1d3f00 Works now, asks a few questions through debconf, then write etc/netwo…
David Whedon authored
25 #include <string.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <sys/types.h>
abf9ed8 -fix nameserver problem
David Whedon authored
30 #include <cdebconf/debconfclient.h>
d4146ec apply patch from thomas poindessous to use libdebian-installer
Tollef Fog Heen authored
31 #include <debian-installer.h>
1f079a1 Support building without wireless support (NO_WIRELESS=1).
Colin Watson authored
32 #ifdef WIRELESS
11498e8 add a wireless heuristic
Joshua Kwan authored
33 #include <iwlib.h>
1f079a1 Support building without wireless support (NO_WIRELESS=1).
Colin Watson authored
34 #endif
99a8525 Starting the network configuration. First goal iwill be manual confi…
David Whedon authored
35
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
36 enum wpa_t wpa_supplicant_status;
03ef69f add 'mii-lite' to fix #247178. needs testing
Joshua Kwan authored
37 static method_t netcfg_method = DHCP;
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
38
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
39 response_t netcfg_get_method(struct debconfclient *client)
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
40 {
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
41 int iret, ret;
3027542 Remove trailing spaces
Frans Pop authored
42
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
43 iret = debconf_input(client, "medium", "netcfg/use_dhcp");
144f283 add a pile of debugging code, and a fix for get_method, which still d…
Joshua Kwan authored
44 ret = debconf_go(client);
3027542 Remove trailing spaces
Frans Pop authored
45
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
46 if (ret == 30)
a0ddba1 tidy up somewhat random C style
Philip Hands authored
47 return GO_BACK;
3027542 Remove trailing spaces
Frans Pop authored
48
7132d73 break out all support modules into dhcp.c, static.c, wireless.c
Joshua Kwan authored
49 debconf_get(client, "netcfg/use_dhcp");
3027542 Remove trailing spaces
Frans Pop authored
50
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
51 if (strcmp(client->value, "true") == 0)
a0ddba1 tidy up somewhat random C style
Philip Hands authored
52 netcfg_method = DHCP;
3027542 Remove trailing spaces
Frans Pop authored
53 else
a0ddba1 tidy up somewhat random C style
Philip Hands authored
54 netcfg_method = STATIC;
3027542 Remove trailing spaces
Frans Pop authored
55
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
56 if (iret == 30)
a0ddba1 tidy up somewhat random C style
Philip Hands authored
57 return NOT_ASKED;
3027542 Remove trailing spaces
Frans Pop authored
58
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
59 return 0;
60 }
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
61
70f29e2 land tested iproute changes
Joshua Kwan authored
62 int main(int argc, char *argv[])
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
63 {
c17a709 Code cleanup and whitespace police, run through the testmill this time.
Thiemo Seufer authored
64 int num_interfaces = 0;
6f0e0bd @otavio Apply patch from Glenn Saberton <gsaberton@foomagic.org> with coding …
otavio authored
65 enum { BACKUP,
66 GET_INTERFACE,
67 GET_HOSTNAME_ONLY,
68 GET_METHOD,
69 GET_DHCP,
70 GET_STATIC,
71 WCONFIG,
72 WCONFIG_ESSID,
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
73 WCONFIG_SECURITY_TYPE,
6f0e0bd @otavio Apply patch from Glenn Saberton <gsaberton@foomagic.org> with coding …
otavio authored
74 WCONFIG_WEP,
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
75 WCONFIG_WPA,
76 START_WPA,
6f0e0bd @otavio Apply patch from Glenn Saberton <gsaberton@foomagic.org> with coding …
otavio authored
77 QUIT } state = GET_INTERFACE;
3027542 Remove trailing spaces
Frans Pop authored
78
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
79 static struct debconfclient *client;
17d7273 Some bug squashing.
Joshua Kwan [obsolete] authored
80 static int requested_wireless_tools = 0;
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
81 extern enum wpa_t wpa_supplicant_status;
a0ddba1 tidy up somewhat random C style
Philip Hands authored
82 char **ifaces;
83 char *defiface = NULL, *defwireless = NULL;
7897182 lots of fixes and cleanups that make mii-lite work 100%
Joshua Kwan authored
84 response_t res;
3027542 Remove trailing spaces
Frans Pop authored
85
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
86 /* initialize libd-i */
87 di_system_init("netcfg");
3027542 Remove trailing spaces
Frans Pop authored
88
e86b003 Don't log "Starting netcfg" messages when invoked as ptom.
Colin Watson authored
89 if (strcmp(basename(argv[0]), "ptom") != 0)
90 di_info("Starting netcfg v.%s (built %s)", NETCFG_VERSION, NETCFG_BUILD_DATE);
c467d86 @mpalmer Print the netcfg version and build date when starting
mpalmer authored
91
70f29e2 land tested iproute changes
Joshua Kwan authored
92 parse_args (argc, argv);
b6d0d51 get rid of this ugly di_system_prebaseconfig_append junk and replace …
Joshua Kwan authored
93 reap_old_files ();
735275d templates cleanup, add amd64, standardize socket opening
Joshua Kwan authored
94 open_sockets();
3027542 Remove trailing spaces
Frans Pop authored
95
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
96 /* initialize debconf */
97 client = debconfclient_new();
98 debconf_capb(client, "backup");
1bcd8bf @otavio Add support to disable network configuration using preseeding in netc…
otavio authored
99
100 /* Check to see if netcfg should be run at all */
101 debconf_get(client, "netcfg/enable");
102 if (!strcmp(client->value, "false")) {
103 struct in_addr null_ipaddress;
104 char *hostname = NULL;
105
106 null_ipaddress.s_addr = 0;
1f8165b @otavio Minor fix provided by Anthony just after commiting it
otavio authored
107 netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 0);
1bcd8bf @otavio Add support to disable network configuration using preseeding in netc…
otavio authored
108
109 netcfg_write_common(null_ipaddress, hostname, NULL);
110 return 0;
111 }
3027542 Remove trailing spaces
Frans Pop authored
112
79218c7 fix a bunch of stuff
Joshua Kwan authored
113 /* always always always default back to DHCP, unless you've specified
114 * disable_dhcp on the command line. */
115 debconf_get(client, "netcfg/disable_dhcp");
3027542 Remove trailing spaces
Frans Pop authored
116
fd3dedd brown paper bag fixes
Joshua Kwan authored
117 if (!strcmp(client->value, "true"))
a0ddba1 tidy up somewhat random C style
Philip Hands authored
118 debconf_set(client, "netcfg/use_dhcp", "false");
fd3dedd brown paper bag fixes
Joshua Kwan authored
119 else
a0ddba1 tidy up somewhat random C style
Philip Hands authored
120 debconf_set(client, "netcfg/use_dhcp", "true");
3027542 Remove trailing spaces
Frans Pop authored
121
a0ddba1 tidy up somewhat random C style
Philip Hands authored
122 for (;;) {
123 switch(state) {
124 case BACKUP:
125 return 10;
126 case GET_INTERFACE:
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
127 /* If we have returned from outside of netcfg and want to
128 * reconfigure networking, check to see if wpasupplicant is
129 * running, and kill it if it is. If left running when
130 * the interfaces are taken up and down, it appears to
131 * leave it in an inconsistant state */
132 kill_wpa_supplicant();
133
145c337 @mpalmer Extend link detection time, with a progress bar. Closes: #414117
mpalmer authored
134 /* Choose a default by looking for link */
a0ddba1 tidy up somewhat random C style
Philip Hands authored
135 if (get_all_ifs(1, &ifaces) > 1) {
136 while (*ifaces) {
137 if (check_kill_switch(*ifaces)) {
138 debconf_subst(client, "netcfg/kill_switch_enabled", "iface", *ifaces);
139 debconf_input(client, "high", "netcfg/kill_switch_enabled");
140 if (debconf_go(client) == 30) {
141 state = BACKUP;
142 break;
143 }
144 /* Is it still enabled? */
145 if (check_kill_switch(*ifaces)) {
146 ifaces++;
147 continue;
148 }
149 }
3027542 Remove trailing spaces
Frans Pop authored
150
7760263 @mpalmer Wait for link detection on static interfaces. Closes: #606515
mpalmer authored
151 interface_up(*ifaces);
145c337 @mpalmer Extend link detection time, with a progress bar. Closes: #414117
mpalmer authored
152 if (netcfg_detect_link (client, *ifaces) == 1) /* CONNECTED */ {
8aff942 Log detected link status to make it possible to see if link
Petter Reinholdtsen authored
153 di_info("found link on interface %s, making it the default.", *ifaces);
a0ddba1 tidy up somewhat random C style
Philip Hands authored
154 defiface = strdup(*ifaces);
155 break;
8aff942 Log detected link status to make it possible to see if link
Petter Reinholdtsen authored
156 } else {
1f079a1 Support building without wireless support (NO_WIRELESS=1).
Colin Watson authored
157 #ifdef WIRELESS
a0ddba1 tidy up somewhat random C style
Philip Hands authored
158 struct wireless_config wc;
8aff942 Log detected link status to make it possible to see if link
Petter Reinholdtsen authored
159 #endif /* WIRELESS */
160 di_info("found no link on interface %s.", *ifaces);
161 #ifdef WIRELESS
a0ddba1 tidy up somewhat random C style
Philip Hands authored
162 if (iw_get_basic_config(wfd, *ifaces, &wc) == 0) {
163 wc.essid[0] = '\0';
164 wc.essid_on = 0;
3027542 Remove trailing spaces
Frans Pop authored
165
a0ddba1 tidy up somewhat random C style
Philip Hands authored
166 iw_set_basic_config(wfd, *ifaces, &wc);
3027542 Remove trailing spaces
Frans Pop authored
167
a0ddba1 tidy up somewhat random C style
Philip Hands authored
168 sleep(1);
3027542 Remove trailing spaces
Frans Pop authored
169
a0ddba1 tidy up somewhat random C style
Philip Hands authored
170 iw_get_basic_config(wfd, *ifaces, &wc);
3027542 Remove trailing spaces
Frans Pop authored
171
a0ddba1 tidy up somewhat random C style
Philip Hands authored
172 if (!empty_str(wc.essid)) {
173 di_info("%s is associated with %s. Selecting as default", *ifaces, wc.essid);
174 defiface = strdup(*ifaces);
175 interface_down(*ifaces);
176 break;
177 } else {
178 di_info("%s is not associated. Relegating to defwireless", *ifaces);
179 if (defwireless != NULL)
180 free (defwireless);
181 defwireless = strdup(*ifaces);
182 }
183 }
184 else
185 di_info("%s is not a wireless interface. Continuing.", *ifaces);
3027542 Remove trailing spaces
Frans Pop authored
186
a0ddba1 tidy up somewhat random C style
Philip Hands authored
187 interface_down(*ifaces);
1f079a1 Support building without wireless support (NO_WIRELESS=1).
Colin Watson authored
188 #endif
8aff942 Log detected link status to make it possible to see if link
Petter Reinholdtsen authored
189 }
3027542 Remove trailing spaces
Frans Pop authored
190
a0ddba1 tidy up somewhat random C style
Philip Hands authored
191 interface_down(*ifaces);
3027542 Remove trailing spaces
Frans Pop authored
192
a0ddba1 tidy up somewhat random C style
Philip Hands authored
193 ifaces++;
194 }
195 }
3027542 Remove trailing spaces
Frans Pop authored
196
a0ddba1 tidy up somewhat random C style
Philip Hands authored
197 if (state == BACKUP)
198 break;
3027542 Remove trailing spaces
Frans Pop authored
199
a0ddba1 tidy up somewhat random C style
Philip Hands authored
200 if (!defiface && defwireless)
201 defiface = defwireless;
3027542 Remove trailing spaces
Frans Pop authored
202
a0ddba1 tidy up somewhat random C style
Philip Hands authored
203 if(netcfg_get_interface(client, &interface, &num_interfaces, defiface))
204 state = BACKUP;
205 else if (! interface || ! num_interfaces)
206 state = GET_HOSTNAME_ONLY;
207 else {
208 if (is_wireless_iface (interface))
209 state = WCONFIG;
210 else
211 state = GET_METHOD;
212 }
213 break;
214 case GET_HOSTNAME_ONLY:
215 if(netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 0))
216 state = BACKUP;
217 else {
218 struct in_addr null_ipaddress;
219 null_ipaddress.s_addr = 0;
220 netcfg_write_common(null_ipaddress, hostname, NULL);
221 state = QUIT;
222 }
223 break;
224 case GET_METHOD:
225 if ((res = netcfg_get_method(client)) == GO_BACK)
226 state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE;
227 else {
3027542 Remove trailing spaces
Frans Pop authored
228 if (netcfg_method == DHCP)
a0ddba1 tidy up somewhat random C style
Philip Hands authored
229 state = GET_DHCP;
230 else
231 state = GET_STATIC;
232 }
233 break;
3027542 Remove trailing spaces
Frans Pop authored
234
a0ddba1 tidy up somewhat random C style
Philip Hands authored
235 case GET_DHCP:
236 switch (netcfg_activate_dhcp(client)) {
237 case 0:
ecc75a2 some random fixes
Joshua Kwan authored
238 state = QUIT;
239 break;
a0ddba1 tidy up somewhat random C style
Philip Hands authored
240 case 10:
24af64b Allow backup from ASK_OPTIONS to GET_INTERFACE
Thomas Hood authored
241 /*
242 * It doesn't make sense to go back to GET_METHOD because
243 * the user has already been asked whether he wants to
244 * try an alternate method.
245 */
246 state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE;
ecc75a2 some random fixes
Joshua Kwan authored
247 break;
a0ddba1 tidy up somewhat random C style
Philip Hands authored
248 case 15:
ecc75a2 some random fixes
Joshua Kwan authored
249 state = GET_STATIC;
250 break;
a0ddba1 tidy up somewhat random C style
Philip Hands authored
251 default:
f4d106a Clean up state machine transitions. Make netcfg-dhcp more like netcf…
Thomas Hood authored
252 return 1;
ecc75a2 some random fixes
Joshua Kwan authored
253 }
a0ddba1 tidy up somewhat random C style
Philip Hands authored
254 break;
3027542 Remove trailing spaces
Frans Pop authored
255
a0ddba1 tidy up somewhat random C style
Philip Hands authored
256 case GET_STATIC:
257 {
258 int ret;
259 /* Misnomer - this should actually take care of activation */
260 if ((ret = netcfg_get_static(client)) == 10)
261 state = GET_INTERFACE;
262 else if (ret)
263 state = GET_METHOD;
264 else
265 state = QUIT;
266 break;
267 }
3027542 Remove trailing spaces
Frans Pop authored
268
ecc75a2 some random fixes
Joshua Kwan authored
269 case WCONFIG:
a0ddba1 tidy up somewhat random C style
Philip Hands authored
270 if (requested_wireless_tools == 0) {
271 di_exec_shell_log("apt-install wireless-tools");
272 requested_wireless_tools = 1;
273 }
274 state = WCONFIG_ESSID;
275 break;
3027542 Remove trailing spaces
Frans Pop authored
276
a0ddba1 tidy up somewhat random C style
Philip Hands authored
277 case WCONFIG_ESSID:
6f0e0bd @otavio Apply patch from Glenn Saberton <gsaberton@foomagic.org> with coding …
otavio authored
278 if (netcfg_wireless_set_essid(client, interface, NULL) == GO_BACK)
a0ddba1 tidy up somewhat random C style
Philip Hands authored
279 state = BACKUP;
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
280 else {
281 init_wpa_supplicant_support();
282 if (wpa_supplicant_status == WPA_UNAVAIL)
283 state = WCONFIG_WEP;
284 else
285 state = WCONFIG_SECURITY_TYPE;
286 }
a0ddba1 tidy up somewhat random C style
Philip Hands authored
287 break;
3027542 Remove trailing spaces
Frans Pop authored
288
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
289 case WCONFIG_SECURITY_TYPE:
290 {
291 int ret;
292 ret = wireless_security_type(client, interface);
293 if (ret == GO_BACK)
294 state = WCONFIG_ESSID;
295 else if (ret == REPLY_WPA)
296 state = WCONFIG_WPA;
297 else
298 state = WCONFIG_WEP;
299 break;
300 }
301
a0ddba1 tidy up somewhat random C style
Philip Hands authored
302 case WCONFIG_WEP:
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
303 if (netcfg_wireless_set_wep(client, interface) == GO_BACK)
304 if (wpa_supplicant_status == WPA_UNAVAIL)
305 state = WCONFIG_ESSID;
306 else
307 state = WCONFIG_SECURITY_TYPE;
a0ddba1 tidy up somewhat random C style
Philip Hands authored
308 else
309 state = GET_METHOD;
310 break;
3027542 Remove trailing spaces
Frans Pop authored
311
f4272c7 @mpalmer Apply WPA patch from Glenn Saberton
mpalmer authored
312 case WCONFIG_WPA:
313 if (wpa_supplicant_status == WPA_OK) {
314 di_exec_shell_log("apt-install wpasupplicant");
315 wpa_supplicant_status = WPA_QUEUED;
316 }
317
318 if (netcfg_set_passphrase(client, interface) == GO_BACK)
319 state = WCONFIG_SECURITY_TYPE;
320 else
321 state = START_WPA;
322 break;
323
324 case START_WPA:
325 if (wpa_supplicant_start(client, interface, essid, passphrase) == GO_BACK)
326 state = WCONFIG_ESSID;
327 else
328 state = GET_METHOD;
329 break;
330
a0ddba1 tidy up somewhat random C style
Philip Hands authored
331 case QUIT:
3419850 On Linux, feed the output of 'ip addr show' into /dev/random after the
Colin Watson authored
332 netcfg_update_entropy();
a0ddba1 tidy up somewhat random C style
Philip Hands authored
333 return 0;
334 }
6219896 - add new combined dhcp and static netcfg
Gaudenz Steinlin authored
335 }
b9c0208 build netcfg-common, though it didn't work as I had planned, I still …
David Whedon authored
336 }
Something went wrong with that request. Please try again.