X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fdnsd.c;h=fe98400f7d6047fc38c40e02f317afa8e51b4c2d;hb=1f56e51ca1d96b70635eb1b9df1d1ab0edd98a72;hp=e73e244b0767747bd97cde5dda4d03e6ad73397d;hpb=343dfd7abe44a32b329379ec9039f2560543518d;p=oweals%2Fbusybox.git diff --git a/networking/dnsd.c b/networking/dnsd.c index e73e244b0..fe98400f7 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c @@ -6,7 +6,7 @@ * Copyright (C) 2005 Odd Arild Olsen (oao at fibula dot no) * Copyright (C) 2003 Paul Sheer * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. * * Odd Arild Olsen started out with the sheerdns [1] of Paul Sheer and rewrote * it into a shape which I believe is both easier to understand and maintain. @@ -17,6 +17,21 @@ * the first porting of oao' scdns to busybox also. */ +//usage:#define dnsd_trivial_usage +//usage: "[-dvs] [-c CONFFILE] [-t TTL_SEC] [-p PORT] [-i ADDR]" +//usage:#define dnsd_full_usage "\n\n" +//usage: "Small static DNS server daemon\n" +//usage: "\n -c FILE Config file" +//usage: "\n -t SEC TTL" +//usage: "\n -p PORT Listen on PORT" +//usage: "\n -i ADDR Listen on ADDR" +//usage: "\n -d Daemonize" +//usage: "\n -v Verbose" +//usage: "\n -s Send successful replies only. Use this if you want" +//usage: "\n to use /etc/resolv.conf with two nameserver lines:" +//usage: "\n nameserver DNSD_SERVER" +//usage: "\n nameserver NORMAL_DNS_SERVER" + #include "libbb.h" #include @@ -44,10 +59,15 @@ struct dns_head { uint16_t nauth; uint16_t nadd; }; +/* Structure used to access type and class fields. + * They are totally unaligned, but gcc 4.3.4 thinks that pointer of type uint16_t* + * is 16-bit aligned and replaces 16-bit memcpy (in move_from_unaligned16 macro) + * with aligned halfword access on arm920t! + * Oh well. Slapping PACKED everywhere seems to help: */ struct type_and_class { - uint16_t type; - uint16_t class; -}; + uint16_t type PACKED; + uint16_t class PACKED; +} PACKED; /* element of known name, ip address and reversed ip address */ struct dns_entry { struct dns_entry *next; @@ -376,11 +396,6 @@ static int process_packet(struct dns_entry *conf_data, /* QR = 1 "response", RCODE = 4 "Not Implemented" */ outr_flags = htons(0x8000 | 4); err_msg = NULL; - /* OPCODE != 0 "standard query" ? */ - if ((head->flags & htons(0x7800)) != 0) { - err_msg = "opcode != 0"; - goto empty_packet; - } /* start of query string */ query_string = (void *)(head + 1); @@ -388,10 +403,15 @@ static int process_packet(struct dns_entry *conf_data, query_len = strlen(query_string) + 1; /* may be unaligned! */ unaligned_type_class = (void *)(query_string + query_len); - query_len += sizeof(unaligned_type_class); + query_len += sizeof(*unaligned_type_class); /* where to append answer block */ answb = (void *)(unaligned_type_class + 1); + /* OPCODE != 0 "standard query"? */ + if ((head->flags & htons(0x7800)) != 0) { + err_msg = "opcode != 0"; + goto empty_packet; + } move_from_unaligned16(class, &unaligned_type_class->class); if (class != htons(1)) { /* not class INET? */ err_msg = "class != 1"; @@ -480,7 +500,8 @@ int dnsd_main(int argc UNUSED_PARAM, char **argv) unsigned lsa_size; int udps, opts; uint16_t port = 53; - uint8_t buf[MAX_PACK_LEN + 1]; + /* Ensure buf is 32bit aligned (we need 16bit, but 32bit can't hurt) */ + uint8_t buf[MAX_PACK_LEN + 1] ALIGN4; opts = getopt32(argv, "vsi:c:t:p:d", &listen_interface, &fileconf, &sttl, &sport); //if (opts & (1 << 0)) // -v