summaryrefslogtreecommitdiffstats
path: root/urunlevel/runlevel/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'urunlevel/runlevel/network.c')
-rw-r--r--urunlevel/runlevel/network.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/urunlevel/runlevel/network.c b/urunlevel/runlevel/network.c
new file mode 100644
index 0000000..dff5fc1
--- /dev/null
+++ b/urunlevel/runlevel/network.c
@@ -0,0 +1,146 @@
1/*
2 * Mini network boot implementation for busybox.
3 *
4 * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 * 02111-1307 USA
20 *
21 */
22
23#include <string.h>
24#include <unistd.h>
25
26#include "busybox.h"
27#include "lib_init_d.h"
28
29
30static int start(struct init_d_handle_s *, int);
31static int status(struct init_d_handle_s *init_d, int);
32static int stop(struct init_d_handle_s *, int);
33
34
35static init_d_handle_t my_commands =
36{
37 &start,
38 &stop,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
43 &status,
44 NULL,
45 "network",
46 NULL,
47 NULL,
48 NULL,
49 INIT_D_BEGIN \
50 INIT_D_PROV "$network" \
51 INIT_D_RSTART "$syslog" \
52 INIT_D_DSTART "3 4 5" \
53 INIT_D_DSTOP "0 1 2 6" \
54 INIT_D_SDESC "Basic network setup" \
55 INIT_D_DESC "Configures all your network interfaces," \
56 INIT_D_CONT "brings them all up and sets up routing." \
57 INIT_D_CONT "Also configures things like port forwarding," \
58 INIT_D_CONT "hostnames, etc." \
59 INIT_D_END
60};
61
62
63int network_main(int argc, char **argv)
64{
65 return do_init_from_main(argc, argv, &my_commands);
66}
67
68
69static int start(struct init_d_handle_s *init_d, int just_checking)
70{
71 int i;
72 int my_status = (init_d->status)(init_d, 0);
73 char *IPADDR = 0;
74
75 if (my_status == INIT_D_STATUS_NOT_RUNNING)
76 {
77 my_status = INIT_D_ERROR_NOT_RUNNING;
78// if (stat("/proc/net/pnp", &path_stat) == 0)
79// copy_file("/proc/net/pnp", "/etc/resolv.conf", FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
80
81 fflush(stdout);
82 doit(QUIET, "ifup -af");
83 for (i = 20; stat("/var/lib/network/ipaddr", &path_stat) != 0; i--)
84 {
85 bb_printf(".");
86 fflush(stdout);
87 sleep(2);
88 if (i <= 0)
89 {
90 bb_printf(" timeout.");
91 break;
92 }
93 }
94
95 if (stat("/var/lib/network/ipaddr", &path_stat) == 0)
96 IPADDR = quick_read("/var/lib/network/ipaddr");
97
98 if ((IPADDR != 0) && (IPADDR[0] != '\0'))
99 {
100 if (stat("/proc/sys/net/ipv4/tcp_syn_retries", &path_stat) == 0)
101 quick_write("/proc/sys/net/ipv4/tcp_syn_retries", "7");
102 if (stat("/var/lib/my_linux/config/ipfwd", &path_stat) == 0)
103 {
104 bb_printf("Enabling IP forwarding\n");
105 quick_write("/proc/sys/net/ipv4/ip_forward", "1");
106 }
107 if (stat("/var/lib/my_linux/config/noping", &path_stat) == 0)
108 quick_write("/proc/sys/net/ipv4/icmp_echo_ignore_all", "1");
109 my_status = INIT_D_OK;
110 }
111 else
112 my_status = INIT_D_ERROR_GENERIC;
113
114 free(IPADDR);
115 }
116 else
117 my_status = INIT_D_OK;
118
119 return my_status;
120}
121
122
123static int status(struct init_d_handle_s *init_d, int quiet)
124{
125 int my_status = INIT_D_STATUS_NOT_RUNNING;
126 char *ip = NULL;
127
128 bb_xasprintf(&ip, "%s", doit(REDIR, "ip -o addr | grep lo: | cut -d\" \" -f3 | cut -d\",\" -f2"));
129 if ((ip != NULL) && (strncmp("UP", ip, 2) == 0))
130 my_status = INIT_D_STATUS_OK;
131
132 return print_status(init_d, quiet, my_status);
133}
134
135
136static int stop(struct init_d_handle_s *init_d, int just_checking)
137{
138 int my_status = default_stop(init_d, 1);
139
140 if (my_status == INIT_D_ERROR_JUST_RUNNING)
141 {
142 doit(QUIET, "ifdown -af");
143 my_status = INIT_D_OK;
144 }
145 return my_status;
146}