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/files.c

    r3232 r3621  
    5858    const char *keyword;
    5959    int (*handler)(const char *line, void *var) FAST_FUNC;
    60     void *var;
     60    unsigned ofs;
    6161    const char *def;
    6262};
    6363
     64#define OFS(field) offsetof(struct server_config_t, field)
     65
    6466static const struct config_keyword keywords[] = {
    6567    /* keyword        handler           variable address               default */
    66     {"start"        , udhcp_str2nip   , &server_config.start_ip     , "192.168.0.20"},
    67     {"end"          , udhcp_str2nip   , &server_config.end_ip       , "192.168.0.254"},
    68     {"interface"    , read_str        , &server_config.interface    , "eth0"},
     68    {"start"        , udhcp_str2nip   , OFS(start_ip     ), "192.168.0.20"},
     69    {"end"          , udhcp_str2nip   , OFS(end_ip       ), "192.168.0.254"},
     70    {"interface"    , read_str        , OFS(interface    ), "eth0"},
    6971    /* Avoid "max_leases value not sane" warning by setting default
    7072     * to default_end_ip - default_start_ip + 1: */
    71     {"max_leases"   , read_u32        , &server_config.max_leases   , "235"},
    72     {"auto_time"    , read_u32        , &server_config.auto_time    , "7200"},
    73     {"decline_time" , read_u32        , &server_config.decline_time , "3600"},
    74     {"conflict_time", read_u32        , &server_config.conflict_time, "3600"},
    75     {"offer_time"   , read_u32        , &server_config.offer_time   , "60"},
    76     {"min_lease"    , read_u32        , &server_config.min_lease_sec, "60"},
    77     {"lease_file"   , read_str        , &server_config.lease_file   , LEASES_FILE},
    78     {"pidfile"      , read_str        , &server_config.pidfile      , "/var/run/udhcpd.pid"},
    79     {"siaddr"       , udhcp_str2nip   , &server_config.siaddr_nip   , "0.0.0.0"},
     73    {"max_leases"   , read_u32        , OFS(max_leases   ), "235"},
     74    {"auto_time"    , read_u32        , OFS(auto_time    ), "7200"},
     75    {"decline_time" , read_u32        , OFS(decline_time ), "3600"},
     76    {"conflict_time", read_u32        , OFS(conflict_time), "3600"},
     77    {"offer_time"   , read_u32        , OFS(offer_time   ), "60"},
     78    {"min_lease"    , read_u32        , OFS(min_lease_sec), "60"},
     79    {"lease_file"   , read_str        , OFS(lease_file   ), LEASES_FILE},
     80    {"pidfile"      , read_str        , OFS(pidfile      ), "/var/run/udhcpd.pid"},
     81    {"siaddr"       , udhcp_str2nip   , OFS(siaddr_nip   ), "0.0.0.0"},
    8082    /* keywords with no defaults must be last! */
    81     {"option"       , udhcp_str2optset, &server_config.options      , ""},
    82     {"opt"          , udhcp_str2optset, &server_config.options      , ""},
    83     {"notify_file"  , read_str        , &server_config.notify_file  , NULL},
    84     {"sname"        , read_str        , &server_config.sname        , NULL},
    85     {"boot_file"    , read_str        , &server_config.boot_file    , NULL},
    86     {"static_lease" , read_staticlease, &server_config.static_leases, ""},
     83    {"option"       , udhcp_str2optset, OFS(options      ), ""},
     84    {"opt"          , udhcp_str2optset, OFS(options      ), ""},
     85    {"notify_file"  , read_str        , OFS(notify_file  ), NULL},
     86    {"sname"        , read_str        , OFS(sname        ), NULL},
     87    {"boot_file"    , read_str        , OFS(boot_file    ), NULL},
     88    {"static_lease" , read_staticlease, OFS(static_leases), ""},
    8789};
    8890enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
     
    9698
    9799    for (i = 0; i < KWS_WITH_DEFAULTS; i++)
    98         keywords[i].handler(keywords[i].def, keywords[i].var);
     100        keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
    99101
    100102    parser = config_open(file);
     
    102104        for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
    103105            if (strcasecmp(token[0], k->keyword) == 0) {
    104                 if (!k->handler(token[1], k->var)) {
     106                if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
    105107                    bb_error_msg("can't parse line %u in %s",
    106108                            parser->lineno, file);
    107109                    /* reset back to the default value */
    108                     k->handler(k->def, k->var);
     110                    k->handler(k->def, (char*)&server_config + k->ofs);
    109111                }
    110112                break;
     
    190192
    191193    while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
    192 //FIXME: what if it matches some static lease?
    193194        uint32_t y = ntohl(lease.lease_nip);
    194195        if (y >= server_config.start_ip && y <= server_config.end_ip) {
    195196            signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
     197            uint32_t static_nip;
     198
    196199            if (expires <= 0)
     200                /* We keep expired leases: add_lease() will add
     201                 * a lease with 0 seconds remaining.
     202                 * Fewer IP address changes this way for mass reboot scenario.
     203                 */
     204                expires = 0;
     205
     206            /* Check if there is a different static lease for this IP or MAC */
     207            static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac);
     208            if (static_nip) {
     209                /* NB: we do not add lease even if static_nip == lease.lease_nip.
     210                 */
    197211                continue;
     212            }
     213            if (is_nip_reserved(server_config.static_leases, lease.lease_nip))
     214                continue;
     215
    198216            /* NB: add_lease takes "relative time", IOW,
    199217             * lease duration, not lease deadline. */
     
    211229        }
    212230    }
    213     log1("Read %d leases", i);
     231    log1("read %d leases", i);
    214232 ret:
    215233    close(fd);
Note: See TracChangeset for help on using the changeset viewer.