Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (13 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/udhcp/dhcpd.c

    r821 r1770  
     1/* vi: set sw=4 ts=4: */
    12/* dhcpd.c
    23 *
     
    1011 */
    1112
    12 #include <fcntl.h>
    13 #include <string.h>
    14 #include <stdlib.h>
    15 #include <sys/wait.h>
    16 #include <arpa/inet.h>
    17 #include <netdb.h>
    18 #include <netinet/in.h>
    19 #include <sys/socket.h>
    20 #include <unistd.h>
    21 #include <signal.h>
    22 #include <errno.h>
    23 #include <sys/ioctl.h>
    24 #include <time.h>
    25 
     13#include <syslog.h>
     14#include "common.h"
    2615#include "dhcpd.h"
    27 #include "arpping.h"
    28 #include "socket.h"
    2916#include "options.h"
    30 #include "files.h"
    31 #include "serverpacket.h"
    32 #include "common.h"
    33 #include "signalpipe.h"
    34 #include "static_leases.h"
    3517
    3618
     
    4022
    4123
    42 int udhcpd_main(int argc, char *argv[])
     24int udhcpd_main(int argc, char **argv);
     25int udhcpd_main(int argc, char **argv)
    4326{
    4427    fd_set rfds;
     
    4831    uint8_t *state, *server_id, *requested;
    4932    uint32_t server_id_align, requested_align, static_lease_ip;
    50     unsigned long timeout_end, num_ips;
     33    unsigned timeout_end;
     34    unsigned num_ips;
     35    unsigned opt;
    5136    struct option_set *option;
    5237    struct dhcpOfferedAddr *lease, static_lease;
    5338
    54     read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]);
    55 
    56     /* Start the log, sanitize fd's, and write a pid file */
    57     udhcp_start_log_and_pid("udhcpd", server_config.pidfile);
    58 
    59     if ((option = find_option(server_config.options, DHCP_LEASE_TIME))) {
     39    opt = getopt32(argv, "fS");
     40    argv += optind;
     41
     42    if (!(opt & 1)) { /* no -f */
     43        bb_daemonize_or_rexec(0, argv);
     44        logmode &= ~LOGMODE_STDIO;
     45    }
     46
     47    if (opt & 2) { /* -S */
     48        openlog(applet_name, LOG_PID, LOG_LOCAL0);
     49        logmode |= LOGMODE_SYSLOG;
     50    }
     51
     52    /* Would rather not do read_config before daemonization -
     53     * otherwise NOMMU machines will parse config twice */
     54    read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE);
     55
     56    /* Make sure fd 0,1,2 are open */
     57    bb_sanitize_stdio();
     58    /* Equivalent of doing a fflush after every \n */
     59    setlinebuf(stdout);
     60
     61    /* Create pidfile */
     62    write_pidfile(server_config.pidfile);
     63    /* if (!..) bb_perror_msg("cannot create pidfile %s", pidfile); */
     64
     65    bb_info_msg("%s (v%s) started", applet_name, BB_VER);
     66
     67    option = find_option(server_config.options, DHCP_LEASE_TIME);
     68    server_config.lease = LEASE_TIME;
     69    if (option) {
    6070        memcpy(&server_config.lease, option->data + 2, 4);
    6171        server_config.lease = ntohl(server_config.lease);
    6272    }
    63     else server_config.lease = LEASE_TIME;
    6473
    6574    /* Sanity check */
    66     num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
     75    num_ips = server_config.end_ip - server_config.start_ip + 1;
    6776    if (server_config.max_leases > num_ips) {
    68         LOG(LOG_ERR, "max_leases value (%lu) not sane, "
    69             "setting to %lu instead",
    70             server_config.max_leases, num_ips);
     77        bb_error_msg("max_leases=%u is too big, setting to %u",
     78            (unsigned)server_config.max_leases, num_ips);
    7179        server_config.max_leases = num_ips;
    7280    }
    7381
    74     leases = xzalloc(server_config.max_leases * sizeof(struct dhcpOfferedAddr));
     82    leases = xzalloc(server_config.max_leases * sizeof(*leases));
    7583    read_leases(server_config.lease_file);
    7684
    7785    if (read_interface(server_config.interface, &server_config.ifindex,
    78                &server_config.server, server_config.arp) < 0)
    79         return 1;
    80 
    81     if (!ENABLE_FEATURE_UDHCP_DEBUG)
    82         udhcp_background(server_config.pidfile); /* hold lock during fork. */
     86               &server_config.server, server_config.arp)) {
     87        retval = 1;
     88        goto ret;
     89    }
    8390
    8491    /* Setup the signal pipe */
    8592    udhcp_sp_setup();
    8693
    87     timeout_end = time(0) + server_config.auto_time;
    88     while(1) { /* loop until universe collapses */
    89 
    90         if (server_socket < 0)
    91             if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) {
    92                 LOG(LOG_ERR, "FATAL: couldn't create server socket, %m");
    93                 return 2;
    94             }
     94    timeout_end = monotonic_sec() + server_config.auto_time;
     95    while (1) { /* loop until universe collapses */
     96
     97        if (server_socket < 0) {
     98            server_socket = listen_socket(/*INADDR_ANY,*/ SERVER_PORT,
     99                    server_config.interface);
     100        }
    95101
    96102        max_sock = udhcp_sp_fd_set(&rfds, server_socket);
    97103        if (server_config.auto_time) {
    98             tv.tv_sec = timeout_end - time(0);
     104            tv.tv_sec = timeout_end - monotonic_sec();
    99105            tv.tv_usec = 0;
    100106        }
     107        retval = 0;
    101108        if (!server_config.auto_time || tv.tv_sec > 0) {
    102109            retval = select(max_sock + 1, &rfds, NULL, NULL,
    103110                    server_config.auto_time ? &tv : NULL);
    104         } else retval = 0; /* If we already timed out, fall through */
    105 
     111        }
    106112        if (retval == 0) {
    107113            write_leases();
    108             timeout_end = time(0) + server_config.auto_time;
    109             continue;
    110         } else if (retval < 0 && errno != EINTR) {
    111             DEBUG(LOG_INFO, "error on select");
     114            timeout_end = monotonic_sec() + server_config.auto_time;
     115            continue;
     116        }
     117        if (retval < 0 && errno != EINTR) {
     118            DEBUG("error on select");
    112119            continue;
    113120        }
     
    115122        switch (udhcp_sp_read(&rfds)) {
    116123        case SIGUSR1:
    117             LOG(LOG_INFO, "Received a SIGUSR1");
     124            bb_info_msg("Received a SIGUSR1");
    118125            write_leases();
    119126            /* why not just reset the timeout, eh */
    120             timeout_end = time(0) + server_config.auto_time;
     127            timeout_end = monotonic_sec() + server_config.auto_time;
    121128            continue;
    122129        case SIGTERM:
    123             LOG(LOG_INFO, "Received a SIGTERM");
    124             return 0;
     130            bb_info_msg("Received a SIGTERM");
     131            goto ret0;
    125132        case 0: break;      /* no signal */
    126133        default: continue;  /* signal or error (probably EINTR) */
    127134        }
    128135
    129         if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */
     136        bytes = udhcp_get_packet(&packet, server_socket); /* this waits for a packet - idle */
     137        if (bytes < 0) {
    130138            if (bytes == -1 && errno != EINTR) {
    131                 DEBUG(LOG_INFO, "error on read, %m, reopening socket");
     139                DEBUG("error on read, %s, reopening socket", strerror(errno));
    132140                close(server_socket);
    133141                server_socket = -1;
     
    136144        }
    137145
    138         if ((state = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
    139             DEBUG(LOG_ERR, "couldn't get option from packet, ignoring");
     146        state = get_option(&packet, DHCP_MESSAGE_TYPE);
     147        if (state == NULL) {
     148            bb_error_msg("cannot get option from packet, ignoring");
    140149            continue;
    141150        }
     
    144153        static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr);
    145154
    146         if(static_lease_ip)
    147         {
    148             printf("Found static lease: %x\n", static_lease_ip);
     155        if (static_lease_ip) {
     156            bb_info_msg("Found static lease: %x", static_lease_ip);
    149157
    150158            memcpy(&static_lease.chaddr, &packet.chaddr, 16);
     
    153161
    154162            lease = &static_lease;
    155 
    156         }
    157         else
    158         {
    159         lease = find_lease_by_chaddr(packet.chaddr);
     163        } else {
     164            lease = find_lease_by_chaddr(packet.chaddr);
    160165        }
    161166
    162167        switch (state[0]) {
    163168        case DHCPDISCOVER:
    164             DEBUG(LOG_INFO,"received DISCOVER");
     169            DEBUG("Received DISCOVER");
    165170
    166171            if (sendOffer(&packet) < 0) {
    167                 LOG(LOG_ERR, "send OFFER failed");
     172                bb_error_msg("send OFFER failed");
    168173            }
    169174            break;
    170175        case DHCPREQUEST:
    171             DEBUG(LOG_INFO, "received REQUEST");
     176            DEBUG("received REQUEST");
    172177
    173178            requested = get_option(&packet, DHCP_REQUESTED_IP);
     
    180185                if (server_id) {
    181186                    /* SELECTING State */
    182                     DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align));
    183                     if (server_id_align == server_config.server && requested &&
    184                         requested_align == lease->yiaddr) {
     187                    DEBUG("server_id = %08x", ntohl(server_id_align));
     188                    if (server_id_align == server_config.server && requested
     189                     && requested_align == lease->yiaddr
     190                    ) {
    185191                        sendACK(&packet, lease->yiaddr);
    186192                    }
     193                } else if (requested) {
     194                    /* INIT-REBOOT State */
     195                    if (lease->yiaddr == requested_align)
     196                        sendACK(&packet, lease->yiaddr);
     197                    else
     198                        sendNAK(&packet);
     199                } else if (lease->yiaddr == packet.ciaddr) {
     200                    /* RENEWING or REBINDING State */
     201                    sendACK(&packet, lease->yiaddr);
    187202                } else {
    188                     if (requested) {
    189                         /* INIT-REBOOT State */
    190                         if (lease->yiaddr == requested_align)
    191                             sendACK(&packet, lease->yiaddr);
    192                         else sendNAK(&packet);
    193                     } else {
    194                         /* RENEWING or REBINDING State */
    195                         if (lease->yiaddr == packet.ciaddr)
    196                             sendACK(&packet, lease->yiaddr);
    197                         else {
    198                             /* don't know what to do!!!! */
    199                             sendNAK(&packet);
    200                         }
    201                     }
     203                    /* don't know what to do!!!! */
     204                    sendNAK(&packet);
    202205                }
    203206
     
    208211            } else if (requested) {
    209212                /* INIT-REBOOT State */
    210                 if ((lease = find_lease_by_yiaddr(requested_align))) {
     213                lease = find_lease_by_yiaddr(requested_align);
     214                if (lease) {
    211215                    if (lease_expired(lease)) {
    212216                        /* probably best if we drop this lease */
    213217                        memset(lease->chaddr, 0, 16);
    214218                    /* make some contention for this address */
    215                     } else sendNAK(&packet);
    216                 } else if (requested_align < server_config.start ||
    217                        requested_align > server_config.end) {
    218                     sendNAK(&packet);
    219                 } /* else remain silent */
     219                    } else
     220                        sendNAK(&packet);
     221                } else {
     222                    uint32_t r = ntohl(requested_align);
     223                    if (r < server_config.start_ip
     224                         || r > server_config.end_ip
     225                    ) {
     226                        sendNAK(&packet);
     227                    }
     228                    /* else remain silent */
     229                }
    220230
    221231            } else {
    222                  /* RENEWING or REBINDING State */
     232                /* RENEWING or REBINDING State */
    223233            }
    224234            break;
    225235        case DHCPDECLINE:
    226             DEBUG(LOG_INFO,"received DECLINE");
     236            DEBUG("Received DECLINE");
    227237            if (lease) {
    228238                memset(lease->chaddr, 0, 16);
     
    231241            break;
    232242        case DHCPRELEASE:
    233             DEBUG(LOG_INFO,"received RELEASE");
    234             if (lease) lease->expires = time(0);
     243            DEBUG("Received RELEASE");
     244            if (lease)
     245                lease->expires = time(0);
    235246            break;
    236247        case DHCPINFORM:
    237             DEBUG(LOG_INFO,"received INFORM");
     248            DEBUG("Received INFORM");
    238249            send_inform(&packet);
    239250            break;
    240251        default:
    241             LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]);
    242         }
    243     }
    244 
    245     return 0;
     252            bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]);
     253        }
     254    }
     255 ret0:
     256    retval = 0;
     257 ret:
     258    /*if (server_config.pidfile) - server_config.pidfile is never NULL */
     259        remove_pidfile(server_config.pidfile);
     260    return retval;
    246261}
    247 
Note: See TracChangeset for help on using the changeset viewer.