Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/networking/dnsd.c

    r902 r1770  
    1818 */
    1919
    20 #include <unistd.h>
    21 #include <string.h>
    22 #include <signal.h>
    23 #include <arpa/inet.h>
    24 #include <sys/socket.h>
    25 #include <ctype.h>
    26 #include "busybox.h"
    27 
    28 static char *fileconf = "/etc/dnsd.conf";
    29 #define LOCK_FILE       "/var/run/dnsd.lock"
    30 #define LOG_FILE        "/var/log/dnsd.log"
    31 
    32 #define is_daemon()  (flags&16)
    33 #define is_verbose() (flags&32)
    34 //#define DEBUG
    35 
     20#include <syslog.h>
     21#include "libbb.h"
     22
     23//#define DEBUG 1
     24#define DEBUG 0
    3625
    3726enum {
     
    8170};
    8271
    83 static struct dns_entry *dnsentry = NULL;
    84 static int daemonmode = 0;
     72static struct dns_entry *dnsentry;
    8573static uint32_t ttl = DEFAULT_TTL;
    8674
     75static const char *fileconf = "/etc/dnsd.conf";
     76
     77// Must match getopt32 call
     78#define OPT_daemon  (option_mask32 & 0x10)
     79#define OPT_verbose (option_mask32 & 0x20)
     80
     81
    8782/*
    8883 * Convert host name from C-string to dns length/string.
     
    9186{
    9287    int i = (q[0] == '.') ? 0 : 1;
    93     for(; i < MAX_HOST_LEN-1 && *q; i++, q++)
     88    for (; i < MAX_HOST_LEN-1 && *q; i++, q++)
    9489        a[i] = tolower(*q);
    9590    a[0] = i - 1;
     
    10398{
    10499    int i = 0, s = 0;
    105     while(rip[i]) i++;
    106     for(--i; i >= 0; i--) {
    107         if(rip[i] == '.') {
     100    while (rip[i])
     101        i++;
     102    for (--i; i >= 0; i--) {
     103        if (rip[i] == '.') {
    108104            rip[i] = s;
    109105            s = 0;
     
    113109
    114110/*
    115  * Append message to log file
    116  */
    117 static void log_message(char *filename, char *message)
    118 {
    119     FILE *logfile;
    120     if (!daemonmode)
    121         return;
    122     logfile = fopen(filename, "a");
    123     if (!logfile)
    124         return;
    125     fprintf(logfile, "%s\n", message);
    126     fclose(logfile);
    127 }
    128 
    129 /*
    130111 * Read one line of hostname/IP from file
    131112 * Returns 0 for each valid entry read, -1 at EOF
    132113 * Assumes all host names are lower case only
    133  * Hostnames with more than one label is not handled correctly.
     114 * Hostnames with more than one label are not handled correctly.
    134115 * Presently the dot is copied into name without
    135116 * converting to a length/string substring for that label.
    136117 */
    137 
    138 static int getfileentry(FILE * fp, struct dns_entry *s, int verb)
     118static int getfileentry(FILE * fp, struct dns_entry *s)
    139119{
    140120    unsigned int a,b,c,d;
    141     char *r, *name;
    142 
    143 restart:
    144     if(!(r = bb_get_line_from_file(fp)))
     121    char *line, *r, *name;
     122
     123 restart:
     124    line = r = xmalloc_fgets(fp);
     125    if (!r)
    145126        return -1;
    146     while(*r == ' ' || *r == '\t') {
     127    while (*r == ' ' || *r == '\t') {
    147128        r++;
    148         if(!*r || *r == '#' || *r == '\n')
     129        if (!*r || *r == '#' || *r == '\n') {
     130            free(line);
    149131            goto restart; /* skipping empty/blank and commented lines  */
     132        }
    150133    }
    151134    name = r;
    152     while(*r != ' ' && *r != '\t')
     135    while (*r != ' ' && *r != '\t')
    153136        r++;
    154     *r++ = 0;
    155     if(sscanf(r,"%u.%u.%u.%u",&a,&b,&c,&d) != 4)
    156             goto restart; /* skipping wrong lines */
    157 
    158     sprintf(s->ip,"%u.%u.%u.%u",a,b,c,d);
    159     sprintf(s->rip,".%u.%u.%u.%u",d,c,b,a);
     137    *r++ = '\0';
     138    if (sscanf(r, ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4) {
     139        free(line);
     140        goto restart; /* skipping wrong lines */
     141    }
     142
     143    sprintf(s->ip, ".%u.%u.%u.%u"+1, a, b, c, d);
     144    sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a);
    160145    undot((uint8_t*)s->rip);
    161     convname(s->name,(uint8_t*)name);
    162 
    163     if(verb)
    164         fprintf(stderr,"\tname:%s, ip:%s\n",&(s->name[1]),s->ip);
    165 
    166     return 0; /* warningkiller */
     146    convname(s->name, (uint8_t*)name);
     147
     148    if (OPT_verbose)
     149        fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip);
     150
     151    free(line);
     152    return 0;
    167153}
    168154
     
    170156 * Read hostname/IP records from file
    171157 */
    172 static void dnsentryinit(int verb)
     158static void dnsentryinit(void)
    173159{
    174160    FILE *fp;
    175161    struct dns_entry *m, *prev;
     162
    176163    prev = dnsentry = NULL;
    177 
    178     fp = bb_xfopen(fileconf, "r");
     164    fp = xfopen(fileconf, "r");
    179165
    180166    while (1) {
    181         m = xmalloc(sizeof(struct dns_entry));
    182 
    183         m->next = NULL;
    184         if (getfileentry(fp, m, verb))
     167        m = xzalloc(sizeof(*m));
     168        /*m->next = NULL;*/
     169        if (getfileentry(fp, m))
    185170            break;
    186171
     
    194179}
    195180
    196 
    197 /*
    198  * Set up UDP socket
    199  */
    200 static int listen_socket(char *iface_addr, int listen_port)
    201 {
    202     struct sockaddr_in a;
    203     char msg[100];
    204     int s;
    205     int yes = 1;
    206     s = bb_xsocket(PF_INET, SOCK_DGRAM, 0);
    207 #ifdef SO_REUSEADDR
    208     if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0)
    209         bb_perror_msg_and_die("setsockopt() failed");
    210 #endif
    211     memset(&a, 0, sizeof(a));
    212     a.sin_port = htons(listen_port);
    213     a.sin_family = AF_INET;
    214     if (!inet_aton(iface_addr, &a.sin_addr))
    215         bb_perror_msg_and_die("bad iface address");
    216     bb_xbind(s, (struct sockaddr *)&a, sizeof(a));
    217     listen(s, 50); /* bb_xlisten? */
    218     sprintf(msg, "accepting UDP packets on addr:port %s:%d\n",
    219         iface_addr, (int)listen_port);
    220     log_message(LOG_FILE, msg);
    221     return s;
    222 }
    223 
    224181/*
    225182 * Look query up in dns records and return answer if found
     
    231188    struct dns_entry *d = dnsentry;
    232189
    233     if(d) do {
    234 #ifdef DEBUG
    235         if(qs && d) {
    236             char *p,*q;
    237             q = (char *)&(qs[1]);
    238             p = &(d->name[1]);
    239             fprintf(stderr, "\n%s: %d/%d p:%s q:%s %d",
    240                 __FUNCTION__, strlen(p), (int)(d->name[0]),
    241                 p, q, strlen(q));
    242         }
     190    do {
     191#if DEBUG
     192        char *p,*q;
     193        q = (char *)&(qs[1]);
     194        p = &(d->name[1]);
     195        fprintf(stderr, "\n%s: %d/%d p:%s q:%s %d",
     196            __FUNCTION__, (int)strlen(p), (int)(d->name[0]),
     197            p, q, (int)strlen(q));
    243198#endif
    244         if (type == REQ_A) {            /* search by host name */
    245             for(i = 1; i <= (int)(d->name[0]); i++)
    246                 if(tolower(qs[i]) != d->name[i])
     199        if (type == REQ_A) { /* search by host name */
     200            for (i = 1; i <= (int)(d->name[0]); i++)
     201                if (tolower(qs[i]) != d->name[i])
    247202                    break;
    248             if(i > (int)(d->name[0])) {
    249 #ifdef DEBUG
    250                 fprintf(stderr, " OK");
    251 #endif
     203            if (i > (int)(d->name[0])) {
    252204                strcpy((char *)as, d->ip);
    253 #ifdef DEBUG
    254                 fprintf(stderr, " as:%s\n", as);
     205#if DEBUG
     206                fprintf(stderr, " OK as:%s\n", as);
    255207#endif
    256208                return 0;
    257209            }
    258         } else
    259         if (type == REQ_PTR) {          /* search by IP-address */
     210        } else if (type == REQ_PTR) { /* search by IP-address */
    260211            if (!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) {
    261212                strcpy((char *)as, d->name);
     
    263214            }
    264215        }
    265     } while ((d = d->next) != NULL);
     216        d = d->next;
     217    } while (d);
    266218    return -1;
    267219}
     
    271223 * Decode message and generate answer
    272224 */
    273 #define eret(s) do { fprintf (stderr, "%s\n", s); return -1; } while (0)
    274225static int process_packet(uint8_t * buf)
    275226{
     
    286237
    287238    head = (struct dns_head *)buf;
    288     if (head->nquer == 0)
    289         eret("no queries");
    290 
    291     if ((head->flags & 0x8000))
    292         eret("ignoring response packet");
     239    if (head->nquer == 0) {
     240        bb_error_msg("no queries");
     241        return -1;
     242    }
     243
     244    if (head->flags & 0x8000) {
     245        bb_error_msg("ignoring response packet");
     246        return -1;
     247    }
    293248
    294249    from = (void *)&head[1];    //  start of query string
     
    317272
    318273    // We have a standard query
    319     log_message(LOG_FILE, (char *)from);
     274    bb_info_msg("%s", (char *)from);
    320275    lookup_result = table_lookup(type, answstr, (uint8_t*)from);
    321276    if (lookup_result != 0) {
     
    331286        memcpy(answstr, &a.s_addr, 4);  // save before a disappears
    332287        outr.rlen = 4;          // uint32_t IP
    333     }
    334     else
     288    } else
    335289        outr.rlen = strlen((char *)answstr) + 1;    // a host name
    336290    outr.r = answstr;           // 32 bit ip or a host name
     
    352306    next += outr.rlen;
    353307
    354 empty_packet:
     308 empty_packet:
     309
    355310    flags = ntohs(head->flags);
    356311    // clear rcode and RA, set responsebit and our new flags
     
    360315    head->nquer = htons(1);
    361316
    362     packet_len = next - (void *)buf;
     317    packet_len = (uint8_t *)next - buf;
    363318    return packet_len;
    364319}
     
    369324static void interrupt(int x)
    370325{
    371     unlink(LOCK_FILE);
    372     write(2, "interrupt exiting\n", 18);
     326    /* unlink("/var/run/dnsd.lock"); */
     327    bb_error_msg("interrupt, exiting\n");
    373328    exit(2);
    374329}
    375330
    376 
     331int dnsd_main(int argc, char **argv);
    377332int dnsd_main(int argc, char **argv)
    378333{
     334    const char *listen_interface = "0.0.0.0";
     335    char *sttl, *sport;
     336    len_and_sockaddr *lsa;
    379337    int udps;
    380338    uint16_t port = 53;
    381339    uint8_t buf[MAX_PACK_LEN];
    382     unsigned long flags = 0;
    383     char *listen_interface = "0.0.0.0";
    384     char *sttl=NULL, *sport=NULL;
    385 
    386     if(argc > 1)
    387         flags = bb_getopt_ulflags(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
    388     if(sttl)
    389         if(!(ttl = atol(sttl)))
    390             bb_show_usage();
    391     if(sport)
    392         if(!(port = atol(sport)))
    393             bb_show_usage();
    394 
    395     if(is_verbose()) {
    396         fprintf(stderr,"listen_interface: %s\n", listen_interface);
    397         fprintf(stderr,"ttl: %d, port: %d\n", ttl, port);
    398         fprintf(stderr,"fileconf: %s\n", fileconf);
    399     }
    400 
    401     if(is_daemon())
    402 #ifdef BB_NOMMU
    403         /* reexec for vfork() do continue parent */
    404         vfork_daemon_rexec(1, 0, argc, argv, "-d");
    405 #else
    406         bb_xdaemon(1, 0);
    407 #endif
    408 
    409     dnsentryinit(is_verbose());
     340
     341    getopt32(argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
     342    //if (option_mask32 & 0x1) // -i
     343    //if (option_mask32 & 0x2) // -c
     344    if (option_mask32 & 0x4) // -t
     345        ttl = xatou_range(sttl, 1, 0xffffffff);
     346    if (option_mask32 & 0x8) // -p
     347        port = xatou_range(sport, 1, 0xffff);
     348
     349    if (OPT_verbose) {
     350        bb_info_msg("listen_interface: %s", listen_interface);
     351        bb_info_msg("ttl: %d, port: %d", ttl, port);
     352        bb_info_msg("fileconf: %s", fileconf);
     353    }
     354
     355    if (OPT_daemon) {
     356        bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
     357        openlog(applet_name, LOG_PID, LOG_DAEMON);
     358        logmode = LOGMODE_SYSLOG;
     359    }
     360
     361    dnsentryinit();
    410362
    411363    signal(SIGINT, interrupt);
    412     signal(SIGPIPE, SIG_IGN);
     364    /* why? signal(SIGPIPE, SIG_IGN); */
    413365    signal(SIGHUP, SIG_IGN);
    414366#ifdef SIGTSTP
     
    419371#endif
    420372
    421     udps = listen_socket(listen_interface, port);
    422     if (udps < 0)
    423         exit(1);
     373    lsa = xdotted2sockaddr(listen_interface, port);
     374    udps = xsocket(lsa->sa.sa_family, SOCK_DGRAM, 0);
     375    xbind(udps, &lsa->sa, lsa->len);
     376    /* xlisten(udps, 50); - ?!! DGRAM sockets are never listened on I think? */
     377    bb_info_msg("Accepting UDP packets on %s",
     378            xmalloc_sockaddr2dotted(&lsa->sa));
    424379
    425380    while (1) {
    426         fd_set fdset;
    427381        int r;
    428 
    429         FD_ZERO(&fdset);
    430         FD_SET(udps, &fdset);
    431         // Block until a message arrives
    432         if((r = select(udps + 1, &fdset, NULL, NULL, NULL)) < 0)
    433             bb_perror_msg_and_die("select error");
    434         else
    435         if(r == 0)
    436             bb_perror_msg_and_die("select spurious return");
    437 
    438         /* Can this test ever be false? */
    439         if (FD_ISSET(udps, &fdset)) {
    440             struct sockaddr_in from;
    441             int fromlen = sizeof(from);
    442             r = recvfrom(udps, buf, sizeof(buf), 0,
    443                      (struct sockaddr *)&from,
    444                      (void *)&fromlen);
    445             if(is_verbose())
    446                 fprintf(stderr, "\n--- Got UDP size=%d ", r);
    447             log_message(LOG_FILE, "\n--- Got UDP ");
    448 
    449             if (r < 12 || r > 512) {
    450                 bb_error_msg("invalid packet size");
    451                 continue;
    452             }
    453             if (r > 0) {
    454                 r = process_packet(buf);
    455                 if (r > 0)
    456                     sendto(udps, buf,
    457                            r, 0, (struct sockaddr *)&from,
    458                            fromlen);
    459             }
    460         }       // end if
    461     }           // end while
     382        socklen_t fromlen = lsa->len;
     383// FIXME: need to get *DEST* address (to which of our addresses
     384// this query was directed), and reply from the same address.
     385// Or else we can exhibit usual UDP ugliness:
     386// [ip1.multihomed.ip2] <=  query to ip1  <= peer
     387// [ip1.multihomed.ip2] => reply from ip2 => peer (confused)
     388        r = recvfrom(udps, buf, sizeof(buf), 0, &lsa->sa, &fromlen);
     389        if (OPT_verbose)
     390            bb_info_msg("Got UDP packet");
     391        if (r < 12 || r > 512) {
     392            bb_error_msg("invalid packet size");
     393            continue;
     394        }
     395        r = process_packet(buf);
     396        if (r <= 0)
     397            continue;
     398        sendto(udps, buf, r, 0, &lsa->sa, fromlen);
     399    }
    462400    return 0;
    463401}
    464 
    465 
Note: See TracChangeset for help on using the changeset viewer.