aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-03-11 14:40:00 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-03-11 14:40:00 +0000
commita19e64933c600b7f05232ad80bb5db85c115e42d (patch)
treebb832b3fc677066c155b19eaccea085298b1b718 /networking
parent4774179cb9e04030485773adf2b7b1055a10faeb (diff)
downloadbusybox-w32-a19e64933c600b7f05232ad80bb5db85c115e42d.tar.gz
busybox-w32-a19e64933c600b7f05232ad80bb5db85c115e42d.tar.bz2
busybox-w32-a19e64933c600b7f05232ad80bb5db85c115e42d.zip
docs/logging_and_backgrounding.txt: new mini-doc
dnsd: remove statics, remove nerly-useless SIGINT handler crond: correct more of logfile to 0666 (as usual, umask allows user to remove unwanted bits). nameif: print errors to stderr too, not just to syslog function old new delta udhcp_read_interface 308 306 -2 ttl 4 - -4 fileconf 4 - -4 dnsentry 4 - -4 interrupt 19 - -19 dnsd_main 1463 1394 -69 ------------------------------------------------------------------------------ (add/remove: 0/4 grow/shrink: 0/2 up/down: 0/-102) Total: -102 bytes text data bss dec hex filename 808161 476 7864 816501 c7575 busybox_old 807994 468 7856 816318 c74be busybox_unstripped
Diffstat (limited to '')
-rw-r--r--networking/dnsd.c96
-rw-r--r--networking/inetd.c2
-rw-r--r--networking/nameif.c4
-rw-r--r--networking/udhcp/dhcpc.c2
-rw-r--r--networking/udhcp/dhcpd.c4
-rw-r--r--networking/udhcp/socket.c2
6 files changed, 53 insertions, 57 deletions
diff --git a/networking/dnsd.c b/networking/dnsd.c
index 434903fe1..f95ba6b40 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -63,14 +63,7 @@ struct dns_entry { // element of known name, ip address and reversed ip address
63 char name[MAX_HOST_LEN]; 63 char name[MAX_HOST_LEN];
64}; 64};
65 65
66static struct dns_entry *dnsentry; 66#define OPT_verbose (option_mask32)
67static uint32_t ttl = DEFAULT_TTL;
68
69static const char *fileconf = "/etc/dnsd.conf";
70
71// Must match getopt32 call
72#define OPT_daemon (option_mask32 & 0x10)
73#define OPT_verbose (option_mask32 & 0x20)
74 67
75 68
76/* 69/*
@@ -88,7 +81,7 @@ static void convname(char *a, uint8_t *q)
88/* 81/*
89 * Insert length of substrings instead of dots 82 * Insert length of substrings instead of dots
90 */ 83 */
91static void undot(uint8_t * rip) 84static void undot(uint8_t *rip)
92{ 85{
93 int i = 0, s = 0; 86 int i = 0, s = 0;
94 while (rip[i]) 87 while (rip[i])
@@ -104,13 +97,13 @@ static void undot(uint8_t * rip)
104/* 97/*
105 * Read hostname/IP records from file 98 * Read hostname/IP records from file
106 */ 99 */
107static void dnsentryinit(void) 100static struct dns_entry *parse_conf_file(const char *fileconf)
108{ 101{
109 char *token[2]; 102 char *token[2];
110 parser_t *parser; 103 parser_t *parser;
111 struct dns_entry *m, *prev; 104 struct dns_entry *m, *prev, *conf_data;
112 105
113 prev = dnsentry = NULL; 106 prev = conf_data = NULL;
114 parser = config_open(fileconf); 107 parser = config_open(fileconf);
115 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { 108 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
116 unsigned a, b, c, d; 109 unsigned a, b, c, d;
@@ -132,50 +125,54 @@ static void dnsentryinit(void)
132 convname(m->name, (uint8_t*)token[0]); 125 convname(m->name, (uint8_t*)token[0]);
133 126
134 if (OPT_verbose) 127 if (OPT_verbose)
135 fprintf(stderr, "\tname:%s, ip:%s\n", &(m->name[1]), m->ip); 128 bb_error_msg("name:%s, ip:%s", &(m->name[1]), m->ip);
136 129
137 if (prev == NULL) 130 if (prev == NULL)
138 dnsentry = m; 131 conf_data = m;
139 else 132 else
140 prev->next = m; 133 prev->next = m;
141 prev = m; 134 prev = m;
142 } 135 }
143 config_close(parser); 136 config_close(parser);
137 return conf_data;
144} 138}
145 139
146/* 140/*
147 * Look query up in dns records and return answer if found 141 * Look query up in dns records and return answer if found
148 * qs is the query string, first byte the string length 142 * qs is the query string, first byte the string length
149 */ 143 */
150static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs) 144static int table_lookup(struct dns_entry *d, uint16_t type, uint8_t *as, uint8_t *qs)
151{ 145{
152 int i; 146 int i;
153 struct dns_entry *d = dnsentry;
154 147
155 do { 148 do {
156#if DEBUG 149#if DEBUG
157 char *p,*q; 150 char *p, *q;
158 q = (char *)&(qs[1]); 151 q = (char *)&(qs[1]);
159 p = &(d->name[1]); 152 p = &(d->name[1]);
160 fprintf(stderr, "\n%s: %d/%d p:%s q:%s %d", 153 fprintf(stderr, "\n%s: %d/%d p:%s q:%s %d",
161 __FUNCTION__, (int)strlen(p), (int)(d->name[0]), 154 __FUNCTION__, (int)strlen(p), (int)(d->name[0]),
162 p, q, (int)strlen(q)); 155 p, q, (int)strlen(q));
163#endif 156#endif
164 if (type == REQ_A) { /* search by host name */ 157 if (type == REQ_A) {
158 /* search by host name */
165 for (i = 1; i <= (int)(d->name[0]); i++) 159 for (i = 1; i <= (int)(d->name[0]); i++)
166 if (tolower(qs[i]) != d->name[i]) 160 if (tolower(qs[i]) != d->name[i])
167 break; 161 break;
168 if (i > (int)(d->name[0]) || 162 if (i > (int)(d->name[0])
169 (d->name[0] == 1 && d->name[1] == '*')) { 163 || (d->name[0] == 1 && d->name[1] == '*')
164 ) {
170 strcpy((char *)as, d->ip); 165 strcpy((char *)as, d->ip);
171#if DEBUG 166#if DEBUG
172 fprintf(stderr, " OK as:%s\n", as); 167 fprintf(stderr, " OK as:%s\n", as);
173#endif 168#endif
174 return 0; 169 return 0;
175 } 170 }
176 } else if (type == REQ_PTR) { /* search by IP-address */ 171 } else if (type == REQ_PTR) {
177 if ((d->name[0] != 1 || d->name[1] != '*') && 172 /* search by IP-address */
178 !strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) { 173 if ((d->name[0] != 1 || d->name[1] != '*')
174 && !strncmp(d->rip + 1, (char*)qs + 1, strlen(d->rip)-1)
175 ) {
179 strcpy((char *)as, d->name); 176 strcpy((char *)as, d->name);
180 return 0; 177 return 0;
181 } 178 }
@@ -188,7 +185,7 @@ static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
188/* 185/*
189 * Decode message and generate answer 186 * Decode message and generate answer
190 */ 187 */
191static int process_packet(uint8_t *buf) 188static int process_packet(struct dns_entry *conf_data, uint32_t conf_ttl, uint8_t *buf)
192{ 189{
193 uint8_t answstr[MAX_NAME_LEN + 1]; 190 uint8_t answstr[MAX_NAME_LEN + 1];
194 struct dns_head *head; 191 struct dns_head *head;
@@ -240,7 +237,7 @@ static int process_packet(uint8_t *buf)
240 237
241 // We have a standard query 238 // We have a standard query
242 bb_info_msg("%s", (char *)from); 239 bb_info_msg("%s", (char *)from);
243 lookup_result = table_lookup(type, answstr, from); 240 lookup_result = table_lookup(conf_data, type, answstr, from);
244 if (lookup_result != 0) { 241 if (lookup_result != 0) {
245 outr_flags = 3 | 0x0400; // name do not exist and auth 242 outr_flags = 3 | 0x0400; // name do not exist and auth
246 goto empty_packet; 243 goto empty_packet;
@@ -267,7 +264,7 @@ static int process_packet(uint8_t *buf)
267 264
268 // and append answer rr 265 // and append answer rr
269// FIXME: unaligned accesses?? 266// FIXME: unaligned accesses??
270 *(uint32_t *) answb = htonl(ttl); 267 *(uint32_t *) answb = htonl(conf_ttl);
271 answb += 4; 268 answb += 4;
272 *(uint16_t *) answb = htons(outr_rlen); 269 *(uint16_t *) answb = htons(outr_rlen);
273 answb += 2; 270 answb += 2;
@@ -290,49 +287,48 @@ static int process_packet(uint8_t *buf)
290/* 287/*
291 * Exit on signal 288 * Exit on signal
292 */ 289 */
293static void interrupt(int sig) 290//static void interrupt(int sig)
294{ 291//{
295 /* unlink("/var/run/dnsd.lock"); */ 292// /* unlink("/var/run/dnsd.lock"); */
296 bb_error_msg("interrupt, exiting\n"); 293// bb_error_msg("interrupt, exiting\n");
297 kill_myself_with_sig(sig); 294// kill_myself_with_sig(sig);
298} 295//}
299 296
300int dnsd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 297int dnsd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
301int dnsd_main(int argc UNUSED_PARAM, char **argv) 298int dnsd_main(int argc UNUSED_PARAM, char **argv)
302{ 299{
303 const char *listen_interface = "0.0.0.0"; 300 const char *listen_interface = "0.0.0.0";
301 const char *fileconf = "/etc/dnsd.conf";
302 struct dns_entry *conf_data;
303 uint32_t conf_ttl = DEFAULT_TTL;
304 char *sttl, *sport; 304 char *sttl, *sport;
305 len_and_sockaddr *lsa, *from, *to; 305 len_and_sockaddr *lsa, *from, *to;
306 unsigned lsa_size; 306 unsigned lsa_size;
307 int udps; 307 int udps, opts;
308 uint16_t port = 53; 308 uint16_t port = 53;
309 /* Paranoid sizing: querystring x2 + ttl + outr_rlen + answstr */ 309 /* Paranoid sizing: querystring x2 + ttl + outr_rlen + answstr */
310 /* I'd rather see process_packet() fixed instead... */ 310 /* I'd rather see process_packet() fixed instead... */
311 uint8_t buf[MAX_PACK_LEN * 2 + 4 + 2 + (MAX_NAME_LEN+1)]; 311 uint8_t buf[MAX_PACK_LEN * 2 + 4 + 2 + (MAX_NAME_LEN+1)];
312 312
313 getopt32(argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport); 313 opts = getopt32(argv, "vi:c:t:p:d", &listen_interface, &fileconf, &sttl, &sport);
314 //if (option_mask32 & 0x1) // -i 314 //if (opts & 0x1) // -v
315 //if (option_mask32 & 0x2) // -c 315 //if (opts & 0x2) // -i
316 if (option_mask32 & 0x4) // -t 316 //if (opts & 0x4) // -c
317 ttl = xatou_range(sttl, 1, 0xffffffff); 317 if (opts & 0x8) // -t
318 if (option_mask32 & 0x8) // -p 318 conf_ttl = xatou_range(sttl, 1, 0xffffffff);
319 if (opts & 0x10) // -p
319 port = xatou_range(sport, 1, 0xffff); 320 port = xatou_range(sport, 1, 0xffff);
320 321 if (opts & 0x20) { // -d
321 if (OPT_verbose) {
322 bb_info_msg("listen_interface: %s", listen_interface);
323 bb_info_msg("ttl: %d, port: %d", ttl, port);
324 bb_info_msg("fileconf: %s", fileconf);
325 }
326
327 if (OPT_daemon) {
328 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); 322 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
329 openlog(applet_name, LOG_PID, LOG_DAEMON); 323 openlog(applet_name, LOG_PID, LOG_DAEMON);
330 logmode = LOGMODE_SYSLOG; 324 logmode = LOGMODE_SYSLOG;
331 } 325 }
326 /* Clear all except "verbose" bit */
327 option_mask32 &= 1;
332 328
333 dnsentryinit(); 329 conf_data = parse_conf_file(fileconf);
334 330
335 signal(SIGINT, interrupt); 331// signal(SIGINT, interrupt); - just for one message?
336 bb_signals(0 332 bb_signals(0
337 /* why? + (1 << SIGPIPE) */ 333 /* why? + (1 << SIGPIPE) */
338 + (1 << SIGHUP) 334 + (1 << SIGHUP)
@@ -371,7 +367,7 @@ int dnsd_main(int argc UNUSED_PARAM, char **argv)
371 if (OPT_verbose) 367 if (OPT_verbose)
372 bb_info_msg("Got UDP packet"); 368 bb_info_msg("Got UDP packet");
373 buf[r] = '\0'; /* paranoia */ 369 buf[r] = '\0'; /* paranoia */
374 r = process_packet(buf); 370 r = process_packet(conf_data, conf_ttl, buf);
375 if (r <= 0) 371 if (r <= 0)
376 continue; 372 continue;
377 send_to_from(udps, buf, r, 0, &from->u.sa, &to->u.sa, lsa->len); 373 send_to_from(udps, buf, r, 0, &from->u.sa, &to->u.sa, lsa->len);
diff --git a/networking/inetd.c b/networking/inetd.c
index bf018d774..72d51010e 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1299,7 +1299,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
1299 if (sep->se_builtin) { 1299 if (sep->se_builtin) {
1300 if (pid) { /* "pid" is -1: we did vfork */ 1300 if (pid) { /* "pid" is -1: we did vfork */
1301 close(sep->se_fd); /* listening socket */ 1301 close(sep->se_fd); /* listening socket */
1302 logmode = 0; /* make xwrite etc silent */ 1302 logmode = LOGMODE_NONE; /* make xwrite etc silent */
1303 } 1303 }
1304 restore_sigmask(&omask); 1304 restore_sigmask(&omask);
1305 if (sep->se_socktype == SOCK_STREAM) 1305 if (sep->se_socktype == SOCK_STREAM)
diff --git a/networking/nameif.c b/networking/nameif.c
index 4d68c8d63..fb31fbfff 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -144,7 +144,9 @@ int nameif_main(int argc, char **argv)
144 144
145 if (1 & getopt32(argv, "sc:", &fname)) { 145 if (1 & getopt32(argv, "sc:", &fname)) {
146 openlog(applet_name, 0, LOG_LOCAL0); 146 openlog(applet_name, 0, LOG_LOCAL0);
147 logmode = LOGMODE_SYSLOG; 147 /* Why not just "="? I assume logging to stderr
148 * can't hurt. 2>/dev/null if you don't like it: */
149 logmode |= LOGMODE_SYSLOG;
148 } 150 }
149 argc -= optind; 151 argc -= optind;
150 argv += optind; 152 argv += optind;
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 903f3d326..e9f99e39c 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -280,7 +280,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
280 /* on NOMMU reexec (i.e., background) early */ 280 /* on NOMMU reexec (i.e., background) early */
281 if (!(opt & OPT_f)) { 281 if (!(opt & OPT_f)) {
282 bb_daemonize_or_rexec(0 /* flags */, argv); 282 bb_daemonize_or_rexec(0 /* flags */, argv);
283 logmode = 0; 283 logmode = LOGMODE_NONE;
284 } 284 }
285#endif 285#endif
286 if (opt & OPT_S) { 286 if (opt & OPT_S) {
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 15b31eb3d..a82fd8c47 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -46,12 +46,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
46 46
47 opt = getopt32(argv, "fS" USE_FEATURE_UDHCP_PORT("P:", &str_P)); 47 opt = getopt32(argv, "fS" USE_FEATURE_UDHCP_PORT("P:", &str_P));
48 argv += optind; 48 argv += optind;
49
50 if (!(opt & 1)) { /* no -f */ 49 if (!(opt & 1)) { /* no -f */
51 bb_daemonize_or_rexec(0, argv); 50 bb_daemonize_or_rexec(0, argv);
52 logmode &= ~LOGMODE_STDIO; 51 logmode = LOGMODE_NONE;
53 } 52 }
54
55 if (opt & 2) { /* -S */ 53 if (opt & 2) { /* -S */
56 openlog(applet_name, LOG_PID, LOG_DAEMON); 54 openlog(applet_name, LOG_PID, LOG_DAEMON);
57 logmode |= LOGMODE_SYSLOG; 55 logmode |= LOGMODE_SYSLOG;
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index fdb558db4..edf4355b5 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -57,7 +57,7 @@ int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t
57 } 57 }
58 our_ip = (struct sockaddr_in *) &ifr.ifr_addr; 58 our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
59 *addr = our_ip->sin_addr.s_addr; 59 *addr = our_ip->sin_addr.s_addr;
60 DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr)); 60 DEBUG("ip of %s = %s", interface, inet_ntoa(our_ip->sin_addr));
61 } 61 }
62 62
63 if (ifindex) { 63 if (ifindex) {