Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/networking/udhcp/dhcpd.c

    r3232 r3621  
    2323
    2424//usage:#define udhcpd_trivial_usage
    25 //usage:       "[-fS]" IF_FEATURE_UDHCP_PORT(" [-P N]") " [CONFFILE]"
     25//usage:       "[-fS] [-I ADDR]" IF_FEATURE_UDHCP_PORT(" [-P N]") " [CONFFILE]"
    2626//usage:#define udhcpd_full_usage "\n\n"
    2727//usage:       "DHCP server\n"
    2828//usage:     "\n    -f  Run in foreground"
    2929//usage:     "\n    -S  Log to syslog too"
     30//usage:     "\n    -I ADDR Local address"
     31//usage:     "\n    -a MSEC Timeout for ARP ping (default 2000)"
    3032//usage:    IF_FEATURE_UDHCP_PORT(
    3133//usage:     "\n    -P N    Use port N (default 67)"
     
    6062     || dhcp_pkt->ciaddr == 0
    6163    ) {
    62         log1("Broadcasting packet to client");
     64        log1("broadcasting packet to client");
    6365        ciaddr = INADDR_BROADCAST;
    6466        chaddr = MAC_BCAST_ADDR;
    6567    } else {
    66         log1("Unicasting packet to client ciaddr");
     68        log1("unicasting packet to client ciaddr");
    6769        ciaddr = dhcp_pkt->ciaddr;
    6870        chaddr = dhcp_pkt->chaddr;
     
    7880static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
    7981{
    80     log1("Forwarding packet to relay");
     82    log1("forwarding packet to relay");
    8183
    8284    udhcp_send_kernel_packet(dhcp_pkt,
     
    148150        uint32_t static_lease_nip,
    149151        struct dyn_lease *lease,
    150         uint8_t *requested_ip_opt)
     152        uint8_t *requested_ip_opt,
     153        unsigned arpping_ms)
    151154{
    152155    struct dhcp_packet packet;
     
    187190        else {
    188191            /* Otherwise, find a free IP */
    189             packet.yiaddr = find_free_or_expired_nip(oldpacket->chaddr);
     192            packet.yiaddr = find_free_or_expired_nip(oldpacket->chaddr, arpping_ms);
    190193        }
    191194
     
    212215
    213216    addr.s_addr = packet.yiaddr;
    214     bb_info_msg("Sending OFFER of %s", inet_ntoa(addr));
     217    bb_error_msg("sending OFFER of %s", inet_ntoa(addr));
    215218    /* send_packet emits error message itself if it detects failure */
    216219    send_packet(&packet, /*force_bcast:*/ 0);
     
    224227    init_packet(&packet, oldpacket, DHCPNAK);
    225228
    226     log1("Sending NAK");
     229    log1("sending %s", "NAK");
    227230    send_packet(&packet, /*force_bcast:*/ 1);
    228231}
     
    245248
    246249    addr.s_addr = yiaddr;
    247     bb_info_msg("Sending ACK to %s", inet_ntoa(addr));
     250    bb_error_msg("sending ACK to %s", inet_ntoa(addr));
    248251    send_packet(&packet, /*force_bcast:*/ 0);
    249252
     
    303306    unsigned opt;
    304307    struct option_set *option;
     308    char *str_I = str_I;
     309    const char *str_a = "2000";
     310    unsigned arpping_ms;
    305311    IF_FEATURE_UDHCP_PORT(char *str_P;)
    306312
    307 #if ENABLE_FEATURE_UDHCP_PORT
    308     SERVER_PORT = 67;
    309     CLIENT_PORT = 68;
    310 #endif
     313    setup_common_bufsiz();
     314
     315    IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;)
     316    IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;)
    311317
    312318#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
    313319    opt_complementary = "vv";
    314320#endif
    315     opt = getopt32(argv, "fSv"
    316         IF_FEATURE_UDHCP_PORT("P:", &str_P)
     321    opt = getopt32(argv, "fSI:va:"
     322        IF_FEATURE_UDHCP_PORT("P:")
     323        , &str_I
     324        , &str_a
     325        IF_FEATURE_UDHCP_PORT(, &str_P)
    317326        IF_UDHCP_VERBOSE(, &dhcp_verbose)
    318327        );
     
    327336        logmode |= LOGMODE_SYSLOG;
    328337    }
     338    if (opt & 4) { /* -I */
     339        len_and_sockaddr *lsa = xhost_and_af2sockaddr(str_I, 0, AF_INET);
     340        server_config.server_nip = lsa->u.sin.sin_addr.s_addr;
     341        free(lsa);
     342    }
    329343#if ENABLE_FEATURE_UDHCP_PORT
    330     if (opt & 8) { /* -P */
     344    if (opt & 32) { /* -P */
    331345        SERVER_PORT = xatou16(str_P);
    332346        CLIENT_PORT = SERVER_PORT + 1;
    333347    }
    334348#endif
     349    arpping_ms = xatou(str_a);
     350
    335351    /* Would rather not do read_config before daemonization -
    336352     * otherwise NOMMU machines will parse config twice */
     
    346362    /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */
    347363
    348     bb_info_msg("%s (v"BB_VER") started", applet_name);
     364    bb_error_msg("started, v"BB_VER);
    349365
    350366    option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME);
     
    368384    if (udhcp_read_interface(server_config.interface,
    369385            &server_config.ifindex,
    370             &server_config.server_nip,
     386            (server_config.server_nip == 0 ? &server_config.server_nip : NULL),
    371387            server_config.server_mac)
    372388    ) {
     
    398414        max_sock = udhcp_sp_fd_set(&rfds, server_socket);
    399415        if (server_config.auto_time) {
    400             tv.tv_sec = timeout_end - monotonic_sec();
     416            /* cast to signed is essential if tv_sec is wider than int */
     417            tv.tv_sec = (int)(timeout_end - monotonic_sec());
    401418            tv.tv_usec = 0;
    402419        }
     
    411428        }
    412429        if (retval < 0 && errno != EINTR) {
    413             log1("Error on select");
     430            log1("error on select");
    414431            continue;
    415432        }
     
    417434        switch (udhcp_sp_read(&rfds)) {
    418435        case SIGUSR1:
    419             bb_info_msg("Received SIGUSR1");
     436            bb_error_msg("received %s", "SIGUSR1");
    420437            write_leases();
    421438            /* why not just reset the timeout, eh */
    422439            goto continue_with_autotime;
    423440        case SIGTERM:
    424             bb_info_msg("Received SIGTERM");
     441            bb_error_msg("received %s", "SIGTERM");
    425442            write_leases();
    426443            goto ret0;
     
    435452            /* bytes can also be -2 ("bad packet data") */
    436453            if (bytes == -1 && errno != EINTR) {
    437                 log1("Read error: %s, reopening socket", strerror(errno));
     454                log1("read error: %s, reopening socket", strerror(errno));
    438455                close(server_socket);
    439456                server_socket = -1;
     
    470487        static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr);
    471488        if (static_lease_nip) {
    472             bb_info_msg("Found static lease: %x", static_lease_nip);
     489            bb_error_msg("found static lease: %x", static_lease_nip);
    473490            memcpy(&fake_lease.lease_mac, &packet.chaddr, 6);
    474491            fake_lease.lease_nip = static_lease_nip;
     
    488505
    489506        case DHCPDISCOVER:
    490             log1("Received DISCOVER");
    491 
    492             send_offer(&packet, static_lease_nip, lease, requested_ip_opt);
     507            log1("received %s", "DISCOVER");
     508
     509            send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms);
    493510            break;
    494511
    495512        case DHCPREQUEST:
    496             log1("Received REQUEST");
     513            log1("received %s", "REQUEST");
    497514/* RFC 2131:
    498515
     
    619636             * ciaddr must be 0 (we do not check this)
    620637             */
    621             log1("Received DECLINE");
     638            log1("received %s", "DECLINE");
    622639            if (server_id_opt
    623640             && requested_ip_opt
     
    639656             * ciaddr must be filled in
    640657             */
    641             log1("Received RELEASE");
     658            log1("received %s", "RELEASE");
    642659            if (server_id_opt
    643660             && lease  /* chaddr matches this lease */
     
    649666
    650667        case DHCPINFORM:
    651             log1("Received INFORM");
     668            log1("received %s", "INFORM");
    652669            send_inform(&packet);
    653670            break;
Note: See TracChangeset for help on using the changeset viewer.