Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

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

    r2725 r3232  
    2121 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2222 */
     23
     24//usage:#define udhcpd_trivial_usage
     25//usage:       "[-fS]" IF_FEATURE_UDHCP_PORT(" [-P N]") " [CONFFILE]"
     26//usage:#define udhcpd_full_usage "\n\n"
     27//usage:       "DHCP server\n"
     28//usage:     "\n    -f  Run in foreground"
     29//usage:     "\n    -S  Log to syslog too"
     30//usage:    IF_FEATURE_UDHCP_PORT(
     31//usage:     "\n    -P N    Use port N (default 67)"
     32//usage:    )
     33
    2334#include <syslog.h>
    2435#include "common.h"
     
    134145/* We got a DHCP DISCOVER. Send an OFFER. */
    135146/* NOINLINE: limit stack usage in caller */
    136 static NOINLINE void send_offer(struct dhcp_packet *oldpacket, uint32_t static_lease_nip, struct dyn_lease *lease)
     147static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
     148        uint32_t static_lease_nip,
     149        struct dyn_lease *lease,
     150        uint8_t *requested_ip_opt)
    137151{
    138152    struct dhcp_packet packet;
     
    148162        /* We have no static lease for client's chaddr */
    149163        uint32_t req_nip;
    150         uint8_t *req_ip_opt;
    151164        const char *p_host_name;
    152165
     
    159172        }
    160173        /* Or: if client has requested an IP */
    161         else if ((req_ip_opt = udhcp_get_option(oldpacket, DHCP_REQUESTED_IP)) != NULL
     174        else if (requested_ip_opt != NULL
    162175         /* (read IP) */
    163          && (move_from_unaligned32(req_nip, req_ip_opt), 1)
     176         && (move_from_unaligned32(req_nip, requested_ip_opt), 1)
    164177         /* and the IP is in the lease range */
    165178         && ntohl(req_nip) >= server_config.start_ip
     
    284297int udhcpd_main(int argc UNUSED_PARAM, char **argv)
    285298{
    286     fd_set rfds;
    287299    int server_socket = -1, retval, max_sock;
    288     struct dhcp_packet packet;
    289300    uint8_t *state;
    290     uint32_t static_lease_nip;
    291301    unsigned timeout_end;
    292302    unsigned num_ips;
    293303    unsigned opt;
    294304    struct option_set *option;
    295     struct dyn_lease *lease, fake_lease;
    296305    IF_FEATURE_UDHCP_PORT(char *str_P;)
    297306
     
    306315    opt = getopt32(argv, "fSv"
    307316        IF_FEATURE_UDHCP_PORT("P:", &str_P)
    308 #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
    309         , &dhcp_verbose
    310 #endif
     317        IF_UDHCP_VERBOSE(, &dhcp_verbose)
    311318        );
    312319    if (!(opt & 1)) { /* no -f */
     
    371378    udhcp_sp_setup();
    372379
     380 continue_with_autotime:
    373381    timeout_end = monotonic_sec() + server_config.auto_time;
    374382    while (1) { /* loop until universe collapses */
     383        fd_set rfds;
     384        struct dhcp_packet packet;
    375385        int bytes;
    376386        struct timeval tv;
    377387        uint8_t *server_id_opt;
    378         uint8_t *requested_opt;
     388        uint8_t *requested_ip_opt;
    379389        uint32_t requested_nip = requested_nip; /* for compiler */
     390        uint32_t static_lease_nip;
     391        struct dyn_lease *lease, fake_lease;
    380392
    381393        if (server_socket < 0) {
     
    396408        if (retval == 0) {
    397409            write_leases();
    398             timeout_end = monotonic_sec() + server_config.auto_time;
    399             continue;
     410            goto continue_with_autotime;
    400411        }
    401412        if (retval < 0 && errno != EINTR) {
     
    409420            write_leases();
    410421            /* why not just reset the timeout, eh */
    411             timeout_end = monotonic_sec() + server_config.auto_time;
    412             continue;
     422            goto continue_with_autotime;
    413423        case SIGTERM:
    414424            bb_info_msg("Received SIGTERM");
     425            write_leases();
    415426            goto ret0;
    416427        case 0: /* no signal: read a packet */
     
    442453            bb_error_msg("no or bad message type option, ignoring packet");
    443454            continue;
     455        }
     456
     457        /* Get SERVER_ID if present */
     458        server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
     459        if (server_id_opt) {
     460            uint32_t server_id_network_order;
     461            move_from_unaligned32(server_id_network_order, server_id_opt);
     462            if (server_id_network_order != server_config.server_nip) {
     463                /* client talks to somebody else */
     464                log1("server ID doesn't match, ignoring");
     465                continue;
     466            }
    444467        }
    445468
     
    456479        }
    457480
    458         /* Get REQUESTED_IP and SERVER_ID if present */
    459         server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
    460         if (server_id_opt) {
    461             uint32_t server_id_net;
    462             move_from_unaligned32(server_id_net, server_id_opt);
    463             if (server_id_net != server_config.server_nip) {
    464                 /* client talks to somebody else */
    465                 log1("server ID doesn't match, ignoring");
    466                 continue;
    467             }
    468         }
    469         requested_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
    470         if (requested_opt) {
    471             move_from_unaligned32(requested_nip, requested_opt);
     481        /* Get REQUESTED_IP if present */
     482        requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
     483        if (requested_ip_opt) {
     484            move_from_unaligned32(requested_nip, requested_ip_opt);
    472485        }
    473486
     
    477490            log1("Received DISCOVER");
    478491
    479             send_offer(&packet, static_lease_nip, lease);
     492            send_offer(&packet, static_lease_nip, lease, requested_ip_opt);
    480493            break;
    481494
     
    568581   administrative authority to do so.
    569582*/
    570             if (!requested_opt) {
     583            if (!requested_ip_opt) {
    571584                requested_nip = packet.ciaddr;
    572585                if (requested_nip == 0) {
     
    581594                break;
    582595            }
    583             if (server_id_opt) {
    584                 /* client was talking specifically to us.
    585                  * "No, we don't have this IP for you". */
     596            /* No lease for this MAC, or lease IP != requested IP */
     597
     598            if (server_id_opt    /* client is in SELECTING state */
     599             || requested_ip_opt /* client is in INIT-REBOOT state */
     600            ) {
     601                /* "No, we don't have this IP for you" */
    586602                send_NAK(&packet);
    587             }
     603            } /* else: client is in RENEWING or REBINDING, do not answer */
     604
    588605            break;
    589606
     
    604621            log1("Received DECLINE");
    605622            if (server_id_opt
    606              && requested_opt
     623             && requested_ip_opt
    607624             && lease  /* chaddr matches this lease */
    608625             && requested_nip == lease->lease_nip
Note: See TracChangeset for help on using the changeset viewer.