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.c176
1 files changed, 87 insertions, 89 deletions
diff --git a/urunlevel/runlevel/network.c b/urunlevel/runlevel/network.c
index dff5fc1..99d4717 100644
--- a/urunlevel/runlevel/network.c
+++ b/urunlevel/runlevel/network.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au 4 * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au
5 * 5 *
6 * Originally based on code from Trinux.
7 *
6 * This program is free software; you can redistribute it and/or modify 8 * 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 9 * 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 10 * the Free Software Foundation; either version 2 of the License, or
@@ -32,115 +34,111 @@ static int status(struct init_d_handle_s *init_d, int);
32static int stop(struct init_d_handle_s *, int); 34static int stop(struct init_d_handle_s *, int);
33 35
34 36
35static init_d_handle_t my_commands = 37static init_d_handle_t my_commands = {
36{ 38 &start,
37 &start, 39 &stop,
38 &stop, 40 NULL,
39 NULL, 41 NULL,
40 NULL, 42 NULL,
41 NULL, 43 NULL,
42 NULL, 44 &status,
43 &status, 45 NULL,
44 NULL, 46 "network",
45 "network", 47 NULL,
46 NULL, 48 NULL,
47 NULL, 49 NULL,
48 NULL, 50 INIT_D_BEGIN
49 INIT_D_BEGIN \ 51 INIT_D_PROV "$network"
50 INIT_D_PROV "$network" \ 52 INIT_D_RSTART "$syslog"
51 INIT_D_RSTART "$syslog" \ 53 INIT_D_DSTART "3 4 5"
52 INIT_D_DSTART "3 4 5" \ 54 INIT_D_DSTOP "0 1 2 6"
53 INIT_D_DSTOP "0 1 2 6" \ 55 INIT_D_SDESC "Basic network setup"
54 INIT_D_SDESC "Basic network setup" \ 56 INIT_D_DESC "Configures all your network interfaces,"
55 INIT_D_DESC "Configures all your network interfaces," \ 57 INIT_D_CONT "brings them all up and sets up routing."
56 INIT_D_CONT "brings them all up and sets up routing." \ 58 INIT_D_CONT "Also configures things like port forwarding,"
57 INIT_D_CONT "Also configures things like port forwarding," \ 59 INIT_D_CONT "hostnames, etc." INIT_D_END
58 INIT_D_CONT "hostnames, etc." \
59 INIT_D_END
60}; 60};
61 61
62 62
63int network_main(int argc, char **argv) 63int network_main(int argc, char **argv)
64{ 64{
65 return do_init_from_main(argc, argv, &my_commands); 65 return do_init_from_main(argc, argv, &my_commands);
66} 66}
67 67
68 68
69static int start(struct init_d_handle_s *init_d, int just_checking) 69static int start(struct init_d_handle_s *init_d, int just_checking)
70{ 70{
71 int i; 71 int i;
72 int my_status = (init_d->status)(init_d, 0); 72 int my_status = (init_d->status) (init_d, 0);
73 char *IPADDR = 0; 73 char *IPADDR = 0;
74 74
75 if (my_status == INIT_D_STATUS_NOT_RUNNING) 75 if (my_status == INIT_D_STATUS_NOT_RUNNING) {
76 { 76 my_status = INIT_D_ERROR_NOT_RUNNING;
77 my_status = INIT_D_ERROR_NOT_RUNNING; 77// if (stat("/proc/net/pnp", &path_stat) == 0)
78// if (stat("/proc/net/pnp", &path_stat) == 0) 78// copy_file("/proc/net/pnp", "/etc/resolv.conf", FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
79// copy_file("/proc/net/pnp", "/etc/resolv.conf", FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); 79
80 80 fflush(stdout);
81 fflush(stdout); 81 doit(QUIET, "ifup -af");
82 doit(QUIET, "ifup -af"); 82 for (i = 20; stat("/var/lib/network/ipaddr", &path_stat) != 0; i--) {
83 for (i = 20; stat("/var/lib/network/ipaddr", &path_stat) != 0; i--) 83 bb_printf(".");
84 { 84 fflush(stdout);
85 bb_printf("."); 85 sleep(2);
86 fflush(stdout); 86 if (i <= 0) {
87 sleep(2); 87 bb_printf(" timeout.");
88 if (i <= 0) 88 break;
89 { 89 }
90 bb_printf(" timeout."); 90 }
91 break; 91
92 } 92 if (stat("/var/lib/network/ipaddr", &path_stat) == 0)
93 } 93 IPADDR = quick_read("/var/lib/network/ipaddr");
94 94
95 if (stat("/var/lib/network/ipaddr", &path_stat) == 0) 95 if ((IPADDR != 0) && (IPADDR[0] != '\0')) {
96 IPADDR = quick_read("/var/lib/network/ipaddr"); 96 char *tcp_syn_retries = getenv("tcp_syn_retries");
97 97 char *ip_forward = getenv("ip_forward");
98 if ((IPADDR != 0) && (IPADDR[0] != '\0')) 98 char *icmp_echo_ignore_all = getenv("icmp_echo_ignore_all");
99 { 99
100 if (stat("/proc/sys/net/ipv4/tcp_syn_retries", &path_stat) == 0) 100 if (tcp_syn_retries)
101 quick_write("/proc/sys/net/ipv4/tcp_syn_retries", "7"); 101 quick_write("/proc/sys/net/ipv4/tcp_syn_retries", tcp_syn_retries);
102 if (stat("/var/lib/my_linux/config/ipfwd", &path_stat) == 0) 102 if (ip_forward) {
103 { 103 bb_printf("Enabling IP forwarding\n");
104 bb_printf("Enabling IP forwarding\n"); 104 quick_write("/proc/sys/net/ipv4/ip_forward", ip_forward);
105 quick_write("/proc/sys/net/ipv4/ip_forward", "1"); 105 }
106 } 106 if (icmp_echo_ignore_all)
107 if (stat("/var/lib/my_linux/config/noping", &path_stat) == 0) 107 quick_write("/proc/sys/net/ipv4/icmp_echo_ignore_all", icmp_echo_ignore_all);
108 quick_write("/proc/sys/net/ipv4/icmp_echo_ignore_all", "1"); 108 my_status = INIT_D_OK;
109 my_status = INIT_D_OK; 109 } else
110 } 110 my_status = INIT_D_ERROR_GENERIC;
111 else 111
112 my_status = INIT_D_ERROR_GENERIC; 112 free(IPADDR);
113 113 } else
114 free(IPADDR); 114 my_status = INIT_D_OK;
115 } 115
116 else 116 return my_status;
117 my_status = INIT_D_OK;
118
119 return my_status;
120} 117}
121 118
122 119
123static int status(struct init_d_handle_s *init_d, int quiet) 120static int status(struct init_d_handle_s *init_d, int quiet)
124{ 121{
125 int my_status = INIT_D_STATUS_NOT_RUNNING; 122 int my_status = INIT_D_STATUS_NOT_RUNNING;
126 char *ip = NULL; 123 char *ip = NULL;
127 124
128 bb_xasprintf(&ip, "%s", doit(REDIR, "ip -o addr | grep lo: | cut -d\" \" -f3 | cut -d\",\" -f2")); 125 bb_xasprintf(&ip, "%s",
129 if ((ip != NULL) && (strncmp("UP", ip, 2) == 0)) 126 doit(REDIR,
130 my_status = INIT_D_STATUS_OK; 127 "ip -o addr | grep lo: | cut -d\" \" -f3 | cut -d\",\" -f2"));
128 if ((ip != NULL) && (strncmp("UP", ip, 2) == 0))
129 my_status = INIT_D_STATUS_OK;
131 130
132 return print_status(init_d, quiet, my_status); 131 return print_status(init_d, quiet, my_status);
133} 132}
134 133
135 134
136static int stop(struct init_d_handle_s *init_d, int just_checking) 135static int stop(struct init_d_handle_s *init_d, int just_checking)
137{ 136{
138 int my_status = default_stop(init_d, 1); 137 int my_status = default_stop(init_d, 1);
139 138
140 if (my_status == INIT_D_ERROR_JUST_RUNNING) 139 if (my_status == INIT_D_ERROR_JUST_RUNNING) {
141 { 140 doit(QUIET, "ifdown -af");
142 doit(QUIET, "ifdown -af"); 141 my_status = INIT_D_OK;
143 my_status = INIT_D_OK; 142 }
144 } 143 return my_status;
145 return my_status;
146} 144}