diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-06 09:49:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-06 09:49:47 +0000 |
commit | c12f53090bd41dbb87279083bc442769cb0610f0 (patch) | |
tree | 079fff1c37f04ea7f25f00cdc4360d52a69b77c5 /networking | |
parent | 4e6ceb44554d265eed24c414b9a201d51d00fee2 (diff) | |
download | busybox-w32-c12f53090bd41dbb87279083bc442769cb0610f0.tar.gz busybox-w32-c12f53090bd41dbb87279083bc442769cb0610f0.tar.bz2 busybox-w32-c12f53090bd41dbb87279083bc442769cb0610f0.zip |
dnsd fix; option_mask32 added. dnsd needs more love.
Diffstat (limited to 'networking')
-rw-r--r-- | networking/dnsd.c | 138 | ||||
-rw-r--r-- | networking/ifupdown.c | 17 |
2 files changed, 80 insertions, 75 deletions
diff --git a/networking/dnsd.c b/networking/dnsd.c index ab3704707..35f6c1096 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -23,6 +23,12 @@ static char *fileconf = "/etc/dnsd.conf"; | |||
23 | #define LOCK_FILE "/var/run/dnsd.lock" | 23 | #define LOCK_FILE "/var/run/dnsd.lock" |
24 | #define LOG_FILE "/var/log/dnsd.log" | 24 | #define LOG_FILE "/var/log/dnsd.log" |
25 | 25 | ||
26 | // Must matct getopt32 call | ||
27 | #define OPT_daemon (option_mask32 & 0x10) | ||
28 | #define OPT_verbose (option_mask32 & 0x20) | ||
29 | |||
30 | //#define DEBUG 1 | ||
31 | |||
26 | enum { | 32 | enum { |
27 | MAX_HOST_LEN = 16, // longest host name allowed is 15 | 33 | MAX_HOST_LEN = 16, // longest host name allowed is 15 |
28 | IP_STRING_LEN = 18, // .xxx.xxx.xxx.xxx\0 | 34 | IP_STRING_LEN = 18, // .xxx.xxx.xxx.xxx\0 |
@@ -70,7 +76,8 @@ struct dns_entry { // element of known name, ip address and reversed ip address | |||
70 | }; | 76 | }; |
71 | 77 | ||
72 | static struct dns_entry *dnsentry = NULL; | 78 | static struct dns_entry *dnsentry = NULL; |
73 | static int daemonmode = 0; | 79 | // FIXME! unused! :( |
80 | static int daemonmode; | ||
74 | static uint32_t ttl = DEFAULT_TTL; | 81 | static uint32_t ttl = DEFAULT_TTL; |
75 | 82 | ||
76 | /* | 83 | /* |
@@ -79,7 +86,7 @@ static uint32_t ttl = DEFAULT_TTL; | |||
79 | static void convname(char *a, uint8_t *q) | 86 | static void convname(char *a, uint8_t *q) |
80 | { | 87 | { |
81 | int i = (q[0] == '.') ? 0 : 1; | 88 | int i = (q[0] == '.') ? 0 : 1; |
82 | for(; i < MAX_HOST_LEN-1 && *q; i++, q++) | 89 | for (; i < MAX_HOST_LEN-1 && *q; i++, q++) |
83 | a[i] = tolower(*q); | 90 | a[i] = tolower(*q); |
84 | a[0] = i - 1; | 91 | a[0] = i - 1; |
85 | a[i] = 0; | 92 | a[i] = 0; |
@@ -91,9 +98,10 @@ static void convname(char *a, uint8_t *q) | |||
91 | static void undot(uint8_t * rip) | 98 | static void undot(uint8_t * rip) |
92 | { | 99 | { |
93 | int i = 0, s = 0; | 100 | int i = 0, s = 0; |
94 | while(rip[i]) i++; | 101 | while (rip[i]) |
95 | for(--i; i >= 0; i--) { | 102 | i++; |
96 | if(rip[i] == '.') { | 103 | for (--i; i >= 0; i--) { |
104 | if (rip[i] == '.') { | ||
97 | rip[i] = s; | 105 | rip[i] = s; |
98 | s = 0; | 106 | s = 0; |
99 | } else s++; | 107 | } else s++; |
@@ -124,41 +132,42 @@ static void log_message(char *filename, char *message) | |||
124 | * converting to a length/string substring for that label. | 132 | * converting to a length/string substring for that label. |
125 | */ | 133 | */ |
126 | 134 | ||
127 | static int getfileentry(FILE * fp, struct dns_entry *s, int verb) | 135 | static int getfileentry(FILE * fp, struct dns_entry *s) |
128 | { | 136 | { |
129 | unsigned int a,b,c,d; | 137 | unsigned int a,b,c,d; |
130 | char *r, *name; | 138 | char *r, *name; |
131 | 139 | ||
132 | restart: | 140 | restart: |
133 | if(!(r = bb_get_line_from_file(fp))) | 141 | r = bb_get_line_from_file(fp); |
142 | if (!r) | ||
134 | return -1; | 143 | return -1; |
135 | while(*r == ' ' || *r == '\t') { | 144 | while (*r == ' ' || *r == '\t') { |
136 | r++; | 145 | r++; |
137 | if(!*r || *r == '#' || *r == '\n') | 146 | if (!*r || *r == '#' || *r == '\n') |
138 | goto restart; /* skipping empty/blank and commented lines */ | 147 | goto restart; /* skipping empty/blank and commented lines */ |
139 | } | 148 | } |
140 | name = r; | 149 | name = r; |
141 | while(*r != ' ' && *r != '\t') | 150 | while (*r != ' ' && *r != '\t') |
142 | r++; | 151 | r++; |
143 | *r++ = 0; | 152 | *r++ = 0; |
144 | if(sscanf(r,"%u.%u.%u.%u",&a,&b,&c,&d) != 4) | 153 | if (sscanf(r, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) |
145 | goto restart; /* skipping wrong lines */ | 154 | goto restart; /* skipping wrong lines */ |
146 | 155 | ||
147 | sprintf(s->ip,"%u.%u.%u.%u",a,b,c,d); | 156 | sprintf(s->ip, "%u.%u.%u.%u", a, b, c, d); |
148 | sprintf(s->rip,".%u.%u.%u.%u",d,c,b,a); | 157 | sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a); |
149 | undot((uint8_t*)s->rip); | 158 | undot((uint8_t*)s->rip); |
150 | convname(s->name,(uint8_t*)name); | 159 | convname(s->name,(uint8_t*)name); |
151 | 160 | ||
152 | if(verb) | 161 | if (OPT_verbose) |
153 | fprintf(stderr,"\tname:%s, ip:%s\n",&(s->name[1]),s->ip); | 162 | fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip); |
154 | 163 | ||
155 | return 0; /* warningkiller */ | 164 | return 0; |
156 | } | 165 | } |
157 | 166 | ||
158 | /* | 167 | /* |
159 | * Read hostname/IP records from file | 168 | * Read hostname/IP records from file |
160 | */ | 169 | */ |
161 | static void dnsentryinit(int verb) | 170 | static void dnsentryinit(void) |
162 | { | 171 | { |
163 | FILE *fp; | 172 | FILE *fp; |
164 | struct dns_entry *m, *prev; | 173 | struct dns_entry *m, *prev; |
@@ -170,7 +179,7 @@ static void dnsentryinit(int verb) | |||
170 | m = xmalloc(sizeof(struct dns_entry)); | 179 | m = xmalloc(sizeof(struct dns_entry)); |
171 | 180 | ||
172 | m->next = NULL; | 181 | m->next = NULL; |
173 | if (getfileentry(fp, m, verb)) | 182 | if (getfileentry(fp, m)) |
174 | break; | 183 | break; |
175 | 184 | ||
176 | if (prev == NULL) | 185 | if (prev == NULL) |
@@ -224,28 +233,32 @@ static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs) | |||
224 | char *p,*q; | 233 | char *p,*q; |
225 | q = (char *)&(qs[1]); | 234 | q = (char *)&(qs[1]); |
226 | p = &(d->name[1]); | 235 | p = &(d->name[1]); |
227 | fprintf(stderr, "\ntest: %d <%s> <%s> %d", strlen(p), p, q, strlen(q)); | 236 | fprintf(stderr, "\n%s: %d/%d p:%s q:%s %d", |
237 | __FUNCTION__, strlen(p), (int)(d->name[0]), p, q, strlen(q)); | ||
228 | #endif | 238 | #endif |
229 | if (type == REQ_A) { /* search by host name */ | 239 | if (type == REQ_A) { /* search by host name */ |
230 | for(i = 1; i <= (int)(d->name[0]); i++) | 240 | for (i = 1; i <= (int)(d->name[0]); i++) |
231 | if(tolower(qs[i]) != d->name[i]) | 241 | if (tolower(qs[i]) != d->name[i]) |
232 | continue; | 242 | break; |
243 | if (i > (int)(d->name[0])) { | ||
233 | #ifdef DEBUG | 244 | #ifdef DEBUG |
234 | fprintf(stderr, " OK"); | 245 | fprintf(stderr, " OK"); |
235 | #endif | 246 | #endif |
236 | strcpy((char *)as, d->ip); | 247 | strcpy((char *)as, d->ip); |
237 | #ifdef DEBUG | 248 | #ifdef DEBUG |
238 | fprintf(stderr, " %s ", as); | 249 | fprintf(stderr, " as:%s\n", as); |
239 | #endif | 250 | #endif |
240 | return 0; | 251 | return 0; |
241 | } | 252 | } |
242 | else if (type == REQ_PTR) { /* search by IP-address */ | 253 | } else |
254 | if (type == REQ_PTR) { /* search by IP-address */ | ||
243 | if (!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) { | 255 | if (!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) { |
244 | strcpy((char *)as, d->name); | 256 | strcpy((char *)as, d->name); |
245 | return 0; | 257 | return 0; |
246 | } | 258 | } |
247 | } | 259 | } |
248 | } while ((d = d->next) != NULL); | 260 | d = d->next; |
261 | } while (d); | ||
249 | return -1; | 262 | return -1; |
250 | } | 263 | } |
251 | 264 | ||
@@ -253,7 +266,7 @@ static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs) | |||
253 | /* | 266 | /* |
254 | * Decode message and generate answer | 267 | * Decode message and generate answer |
255 | */ | 268 | */ |
256 | #define eret(s) do { fprintf (stderr, "%s\n", s); return -1; } while (0) | 269 | #define eret(s) do { fputs(s, stderr); return -1; } while (0) |
257 | static int process_packet(uint8_t * buf) | 270 | static int process_packet(uint8_t * buf) |
258 | { | 271 | { |
259 | struct dns_head *head; | 272 | struct dns_head *head; |
@@ -269,13 +282,13 @@ static int process_packet(uint8_t * buf) | |||
269 | 282 | ||
270 | head = (struct dns_head *)buf; | 283 | head = (struct dns_head *)buf; |
271 | if (head->nquer == 0) | 284 | if (head->nquer == 0) |
272 | eret("no queries"); | 285 | eret("no queries\n"); |
273 | 286 | ||
274 | if ((head->flags & 0x8000)) | 287 | if (head->flags & 0x8000) |
275 | eret("ignoring response packet"); | 288 | eret("ignoring response packet\n"); |
276 | 289 | ||
277 | from = (void *)&head[1]; // start of query string | 290 | from = (void *)&head[1]; // start of query string |
278 | next = answb = from + strlen((char *)&head[1]) + 1 + sizeof(struct dns_prop); // where to append answer block | 291 | next = answb = from + strlen((char *)from) + 1 + sizeof(struct dns_prop); // where to append answer block |
279 | 292 | ||
280 | outr.rlen = 0; // may change later | 293 | outr.rlen = 0; // may change later |
281 | outr.r = NULL; | 294 | outr.r = NULL; |
@@ -299,9 +312,8 @@ static int process_packet(uint8_t * buf) | |||
299 | goto empty_packet; | 312 | goto empty_packet; |
300 | 313 | ||
301 | // We have a standard query | 314 | // We have a standard query |
302 | 315 | log_message(LOG_FILE, (char *)from); | |
303 | log_message(LOG_FILE, (char *)head); | 316 | lookup_result = table_lookup(type, answstr, (uint8_t*)from); |
304 | lookup_result = table_lookup(type, answstr, (uint8_t*)(&head[1])); | ||
305 | if (lookup_result != 0) { | 317 | if (lookup_result != 0) { |
306 | outr.flags = 3 | 0x0400; //name do not exist and auth | 318 | outr.flags = 3 | 0x0400; //name do not exist and auth |
307 | goto empty_packet; | 319 | goto empty_packet; |
@@ -335,7 +347,7 @@ static int process_packet(uint8_t * buf) | |||
335 | memcpy(next, (void *)answstr, outr.rlen); | 347 | memcpy(next, (void *)answstr, outr.rlen); |
336 | next += outr.rlen; | 348 | next += outr.rlen; |
337 | 349 | ||
338 | empty_packet: | 350 | empty_packet: |
339 | 351 | ||
340 | flags = ntohs(head->flags); | 352 | flags = ntohs(head->flags); |
341 | // clear rcode and RA, set responsebit and our new flags | 353 | // clear rcode and RA, set responsebit and our new flags |
@@ -358,35 +370,31 @@ static void interrupt(int x) | |||
358 | exit(2); | 370 | exit(2); |
359 | } | 371 | } |
360 | 372 | ||
361 | #define is_daemon() (flags&16) | ||
362 | #define is_verbose() (flags&32) | ||
363 | //#define DEBUG 1 | ||
364 | |||
365 | int dnsd_main(int argc, char **argv) | 373 | int dnsd_main(int argc, char **argv) |
366 | { | 374 | { |
367 | int udps; | 375 | int udps; |
368 | uint16_t port = 53; | 376 | uint16_t port = 53; |
369 | uint8_t buf[MAX_PACK_LEN]; | 377 | uint8_t buf[MAX_PACK_LEN]; |
370 | unsigned long flags = 0; | ||
371 | char *listen_interface = "0.0.0.0"; | 378 | char *listen_interface = "0.0.0.0"; |
372 | char *sttl=NULL, *sport=NULL; | 379 | char *sttl, *sport; |
373 | 380 | ||
374 | if(argc > 1) | 381 | getopt32(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport); |
375 | flags = getopt32(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport); | 382 | //if (option_mask32 & 0x1) // -i |
376 | if(sttl) | 383 | //if (option_mask32 & 0x2) // -c |
377 | if(!(ttl = atol(sttl))) | 384 | if (option_mask32 & 0x4) // -t |
385 | if (!(ttl = atol(sttl))) | ||
378 | bb_show_usage(); | 386 | bb_show_usage(); |
379 | if(sport) | 387 | if (option_mask32 & 0x8) // -p |
380 | if(!(port = atol(sport))) | 388 | if (!(port = atol(sport))) |
381 | bb_show_usage(); | 389 | bb_show_usage(); |
382 | 390 | ||
383 | if(is_verbose()) { | 391 | if (OPT_verbose) { |
384 | fprintf(stderr,"listen_interface: %s\n", listen_interface); | 392 | bb_info_msg("listen_interface: %s", listen_interface); |
385 | fprintf(stderr,"ttl: %d, port: %d\n", ttl, port); | 393 | bb_info_msg("ttl: %d, port: %d", ttl, port); |
386 | fprintf(stderr,"fileconf: %s\n", fileconf); | 394 | bb_info_msg("fileconf: %s", fileconf); |
387 | } | 395 | } |
388 | 396 | ||
389 | if(is_daemon()) | 397 | if (OPT_daemon) |
390 | #ifdef BB_NOMMU | 398 | #ifdef BB_NOMMU |
391 | /* reexec for vfork() do continue parent */ | 399 | /* reexec for vfork() do continue parent */ |
392 | vfork_daemon_rexec(1, 0, argc, argv, "-d"); | 400 | vfork_daemon_rexec(1, 0, argc, argv, "-d"); |
@@ -394,7 +402,7 @@ int dnsd_main(int argc, char **argv) | |||
394 | xdaemon(1, 0); | 402 | xdaemon(1, 0); |
395 | #endif | 403 | #endif |
396 | 404 | ||
397 | dnsentryinit(is_verbose()); | 405 | dnsentryinit(); |
398 | 406 | ||
399 | signal(SIGINT, interrupt); | 407 | signal(SIGINT, interrupt); |
400 | signal(SIGPIPE, SIG_IGN); | 408 | signal(SIGPIPE, SIG_IGN); |
@@ -417,20 +425,20 @@ int dnsd_main(int argc, char **argv) | |||
417 | FD_ZERO(&fdset); | 425 | FD_ZERO(&fdset); |
418 | FD_SET(udps, &fdset); | 426 | FD_SET(udps, &fdset); |
419 | // Block until a message arrives | 427 | // Block until a message arrives |
420 | if((r = select(udps + 1, &fdset, NULL, NULL, NULL)) < 0) | 428 | r = select(udps + 1, &fdset, NULL, NULL, NULL); |
429 | if (r < 0) | ||
421 | bb_perror_msg_and_die("select error"); | 430 | bb_perror_msg_and_die("select error"); |
422 | else | 431 | if (r == 0) |
423 | if(r == 0) | ||
424 | bb_perror_msg_and_die("select spurious return"); | 432 | bb_perror_msg_and_die("select spurious return"); |
425 | 433 | ||
426 | /* Can this test ever be false? */ | 434 | /* Can this test ever be false? - yes */ |
427 | if (FD_ISSET(udps, &fdset)) { | 435 | if (FD_ISSET(udps, &fdset)) { |
428 | struct sockaddr_in from; | 436 | struct sockaddr_in from; |
429 | int fromlen = sizeof(from); | 437 | int fromlen = sizeof(from); |
430 | r = recvfrom(udps, buf, sizeof(buf), 0, | 438 | r = recvfrom(udps, buf, sizeof(buf), 0, |
431 | (struct sockaddr *)&from, | 439 | (struct sockaddr *)&from, |
432 | (void *)&fromlen); | 440 | (void *)&fromlen); |
433 | if(is_verbose()) | 441 | if (OPT_verbose) |
434 | fprintf(stderr, "\n--- Got UDP "); | 442 | fprintf(stderr, "\n--- Got UDP "); |
435 | log_message(LOG_FILE, "\n--- Got UDP "); | 443 | log_message(LOG_FILE, "\n--- Got UDP "); |
436 | 444 | ||
@@ -445,9 +453,7 @@ int dnsd_main(int argc, char **argv) | |||
445 | r, 0, (struct sockaddr *)&from, | 453 | r, 0, (struct sockaddr *)&from, |
446 | fromlen); | 454 | fromlen); |
447 | } | 455 | } |
448 | } // end if | 456 | } // end if |
449 | } // end while | 457 | } // end while |
450 | return 0; | 458 | return 0; |
451 | } | 459 | } |
452 | |||
453 | |||
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 6334cbc43..f572b487d 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -89,7 +89,6 @@ struct interfaces_file_t | |||
89 | struct mapping_defn_t *mappings; | 89 | struct mapping_defn_t *mappings; |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static unsigned option_mask; | ||
93 | #define OPTION_STR "anvf" USE_FEATURE_IFUPDOWN_MAPPING("m") "i:" | 92 | #define OPTION_STR "anvf" USE_FEATURE_IFUPDOWN_MAPPING("m") "i:" |
94 | enum { | 93 | enum { |
95 | OPT_do_all = 0x1, | 94 | OPT_do_all = 0x1, |
@@ -98,11 +97,11 @@ enum { | |||
98 | OPT_force = 0x8, | 97 | OPT_force = 0x8, |
99 | OPT_no_mappings = 0x10, | 98 | OPT_no_mappings = 0x10, |
100 | }; | 99 | }; |
101 | #define DO_ALL (option_mask & OPT_do_all) | 100 | #define DO_ALL (option_mask32 & OPT_do_all) |
102 | #define NO_ACT (option_mask & OPT_no_act) | 101 | #define NO_ACT (option_mask32 & OPT_no_act) |
103 | #define VERBOSE (option_mask & OPT_verbose) | 102 | #define VERBOSE (option_mask32 & OPT_verbose) |
104 | #define FORCE (option_mask & OPT_force) | 103 | #define FORCE (option_mask32 & OPT_force) |
105 | #define NO_MAPPINGS (option_mask & OPT_no_mappings) | 104 | #define NO_MAPPINGS (option_mask32 & OPT_no_mappings) |
106 | 105 | ||
107 | static char **__myenviron; | 106 | static char **__myenviron; |
108 | 107 | ||
@@ -881,10 +880,10 @@ static void set_environ(struct interface_defn_t *iface, const char *mode) | |||
881 | 880 | ||
882 | static int doit(char *str) | 881 | static int doit(char *str) |
883 | { | 882 | { |
884 | if (option_mask & (OPT_no_act|OPT_verbose)) { | 883 | if (option_mask32 & (OPT_no_act|OPT_verbose)) { |
885 | puts(str); | 884 | puts(str); |
886 | } | 885 | } |
887 | if (!(option_mask & OPT_no_act)) { | 886 | if (!(option_mask32 & OPT_no_act)) { |
888 | pid_t child; | 887 | pid_t child; |
889 | int status; | 888 | int status; |
890 | 889 | ||
@@ -1088,7 +1087,7 @@ int ifupdown_main(int argc, char **argv) | |||
1088 | cmds = iface_down; | 1087 | cmds = iface_down; |
1089 | } | 1088 | } |
1090 | 1089 | ||
1091 | option_mask = getopt32(argc, argv, OPTION_STR, &interfaces); | 1090 | getopt32(argc, argv, OPTION_STR, &interfaces); |
1092 | if (argc - optind > 0) { | 1091 | if (argc - optind > 0) { |
1093 | if (DO_ALL) bb_show_usage(); | 1092 | if (DO_ALL) bb_show_usage(); |
1094 | } else | 1093 | } else |