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

    r2725 r3232  
    3030//  { OPTION_IP | OPTION_LIST                 , 0x08 }, /* DHCP_COOKIE_SERVER */
    3131    { OPTION_IP | OPTION_LIST                 , 0x09 }, /* DHCP_LPR_SERVER    */
    32     { OPTION_STRING               | OPTION_REQ, 0x0c }, /* DHCP_HOST_NAME     */
     32    { OPTION_STRING_HOST          | OPTION_REQ, 0x0c }, /* DHCP_HOST_NAME     */
    3333    { OPTION_U16                              , 0x0d }, /* DHCP_BOOT_SIZE     */
    34     { OPTION_STRING               | OPTION_REQ, 0x0f }, /* DHCP_DOMAIN_NAME   */
     34    { OPTION_STRING_HOST          | OPTION_REQ, 0x0f }, /* DHCP_DOMAIN_NAME   */
    3535    { OPTION_IP                               , 0x10 }, /* DHCP_SWAP_SERVER   */
    3636    { OPTION_STRING                           , 0x11 }, /* DHCP_ROOT_PATH     */
    3737    { OPTION_U8                               , 0x17 }, /* DHCP_IP_TTL        */
    3838    { OPTION_U16                              , 0x1a }, /* DHCP_MTU           */
     39//TODO: why do we request DHCP_BROADCAST? Can't we assume that
     40//in the unlikely case it is different from typical N.N.255.255,
     41//server would let us know anyway?
    3942    { OPTION_IP                   | OPTION_REQ, 0x1c }, /* DHCP_BROADCAST     */
    4043    { OPTION_IP_PAIR | OPTION_LIST            , 0x21 }, /* DHCP_ROUTES        */
    41     { OPTION_STRING                           , 0x28 }, /* DHCP_NIS_DOMAIN    */
     44    { OPTION_STRING_HOST                      , 0x28 }, /* DHCP_NIS_DOMAIN    */
    4245    { OPTION_IP | OPTION_LIST                 , 0x29 }, /* DHCP_NIS_SERVER    */
    4346    { OPTION_IP | OPTION_LIST     | OPTION_REQ, 0x2a }, /* DHCP_NTP_SERVER    */
     
    4750    { OPTION_STRING                           , 0x38 }, /* DHCP_ERR_MESSAGE   */
    4851//TODO: must be combined with 'sname' and 'file' handling:
    49     { OPTION_STRING                           , 0x42 }, /* DHCP_TFTP_SERVER_NAME */
     52    { OPTION_STRING_HOST                      , 0x42 }, /* DHCP_TFTP_SERVER_NAME */
    5053    { OPTION_STRING                           , 0x43 }, /* DHCP_BOOT_FILE     */
    5154//TODO: not a string, but a set of LASCII strings:
     
    5558    { OPTION_SIP_SERVERS                      , 0x78 }, /* DHCP_SIP_SERVERS   */
    5659#endif
    57     { OPTION_STATIC_ROUTES                    , 0x79 }, /* DHCP_STATIC_ROUTES */
    58     { OPTION_STATIC_ROUTES                    , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */
     60    { OPTION_STATIC_ROUTES | OPTION_LIST      , 0x79 }, /* DHCP_STATIC_ROUTES */
     61#if ENABLE_FEATURE_UDHCP_8021Q
     62    { OPTION_U16                              , 0x84 }, /* DHCP_VLAN_ID       */
     63    { OPTION_U8                               , 0x85 }, /* DHCP_VLAN_PRIORITY */
     64#endif
     65    { OPTION_6RD                              , 0xd4 }, /* DHCP_6RD           */
     66    { OPTION_STATIC_ROUTES | OPTION_LIST      , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */
    5967    { OPTION_STRING                           , 0xfc }, /* DHCP_WPAD          */
    6068
     
    116124    "sipsrv" "\0"      /* DHCP_SIP_SERVERS    */
    117125#endif
    118 // doesn't work in udhcpd.conf since OPTION_STATIC_ROUTES
    119 // is not handled yet by "string->option" conversion code:
    120126    "staticroutes" "\0"/* DHCP_STATIC_ROUTES  */
     127#if ENABLE_FEATURE_UDHCP_8021Q
     128    "vlanid" "\0"      /* DHCP_VLAN_ID        */
     129    "vlanpriority" "\0"/* DHCP_VLAN_PRIORITY  */
     130#endif
     131    "ip6rd" "\0"       /* DHCP_6RD            */
    121132    "msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */
    122133    "wpad" "\0"        /* DHCP_WPAD           */
     
    136147//  [OPTION_BOOLEAN] = 1,
    137148    [OPTION_STRING] =  1,  /* ignored by udhcp_str2optset */
     149    [OPTION_STRING_HOST] = 1,  /* ignored by udhcp_str2optset */
    138150#if ENABLE_FEATURE_UDHCP_RFC3397
    139151    [OPTION_DNS_STRING] = 1,  /* ignored by both udhcp_str2optset and xmalloc_optname_optval */
     
    147159    /* Just like OPTION_STRING, we use minimum length here */
    148160    [OPTION_STATIC_ROUTES] = 5,
     161    [OPTION_6RD] =    22,  /* ignored by udhcp_str2optset */
    149162};
    150163
     
    324337    if (!lsa)
    325338        return 0;
    326     *(uint32_t*)arg = lsa->u.sin.sin_addr.s_addr;
     339    /* arg maybe unaligned */
     340    move_to_unaligned32((uint32_t*)arg, lsa->u.sin.sin_addr.s_addr);
    327341    free(lsa);
    328342    return 1;
     
    404418
    405419            existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
    406             if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING) {
     420            if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING
     421             || (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST
     422            ) {
    407423                /* add space separator between STRING options in a list */
    408424                existing->data[OPT_DATA + old_len] = ' ';
     
    421437{
    422438    struct option_set **opt_list = arg;
    423     char *opt, *val, *endptr;
     439    char *opt, *val;
    424440    char *str;
    425441    const struct dhcp_optflag *optflag;
     
    427443    unsigned optcode;
    428444    int retval, length;
    429     char buffer[8] ALIGNED(4);
     445    /* IP_PAIR needs 8 bytes, STATIC_ROUTES needs 9 max */
     446    char buffer[9] ALIGNED(4);
    430447    uint16_t *result_u16 = (uint16_t *) buffer;
    431448    uint32_t *result_u32 = (uint32_t *) buffer;
     
    468485            break;
    469486        case OPTION_STRING:
     487        case OPTION_STRING_HOST:
    470488#if ENABLE_FEATURE_UDHCP_RFC3397
    471489        case OPTION_DNS_STRING:
     
    484502//      }
    485503        case OPTION_U8:
    486             buffer[0] = strtoul(val, &endptr, 0);
    487             retval = (endptr[0] == '\0');
     504            buffer[0] = bb_strtou32(val, NULL, 0);
     505            retval = (errno == 0);
    488506            break;
    489507        /* htonX are macros in older libc's, using temp var
     
    491509        /* TODO: use bb_strtoX? */
    492510        case OPTION_U16: {
    493             unsigned long tmp = strtoul(val, &endptr, 0);
     511            uint32_t tmp = bb_strtou32(val, NULL, 0);
    494512            *result_u16 = htons(tmp);
    495             retval = (endptr[0] == '\0' /*&& tmp < 0x10000*/);
     513            retval = (errno == 0 /*&& tmp < 0x10000*/);
    496514            break;
    497515        }
    498516//      case OPTION_S16: {
    499 //          long tmp = strtol(val, &endptr, 0);
     517//          long tmp = bb_strtoi32(val, NULL, 0);
    500518//          *result_u16 = htons(tmp);
    501 //          retval = (endptr[0] == '\0');
     519//          retval = (errno == 0);
    502520//          break;
    503521//      }
    504522        case OPTION_U32: {
    505             unsigned long tmp = strtoul(val, &endptr, 0);
     523            uint32_t tmp = bb_strtou32(val, NULL, 0);
    506524            *result_u32 = htonl(tmp);
    507             retval = (endptr[0] == '\0');
     525            retval = (errno == 0);
    508526            break;
    509527        }
    510528        case OPTION_S32: {
    511             long tmp = strtol(val, &endptr, 0);
     529            int32_t tmp = bb_strtoi32(val, NULL, 0);
    512530            *result_u32 = htonl(tmp);
    513             retval = (endptr[0] == '\0');
     531            retval = (errno == 0);
     532            break;
     533        }
     534        case OPTION_STATIC_ROUTES: {
     535            /* Input: "a.b.c.d/m" */
     536            /* Output: mask(1 byte),pfx(0-4 bytes),gw(4 bytes) */
     537            unsigned mask;
     538            char *slash = strchr(val, '/');
     539            if (slash) {
     540                *slash = '\0';
     541                retval = udhcp_str2nip(val, buffer + 1);
     542                buffer[0] = mask = bb_strtou(slash + 1, NULL, 10);
     543                val = strtok(NULL, ", \t/-");
     544                if (!val || mask > 32 || errno)
     545                    retval = 0;
     546                if (retval) {
     547                    length = ((mask + 7) >> 3) + 5;
     548                    retval = udhcp_str2nip(val, buffer + (length - 4));
     549                }
     550            }
    514551            break;
    515552        }
     
    522559        if (retval)
    523560            attach_option(opt_list, optflag, opt, length);
    524     } while (retval && optflag->flags & OPTION_LIST);
     561    } while (retval && (optflag->flags & OPTION_LIST));
    525562
    526563    return retval;
    527564}
     565
     566/* note: ip is a pointer to an IPv6 in network order, possibly misaliged */
     567int FAST_FUNC sprint_nip6(char *dest, /*const char *pre,*/ const uint8_t *ip)
     568{
     569    char hexstrbuf[16 * 2];
     570    bin2hex(hexstrbuf, (void*)ip, 16);
     571    return sprintf(dest, /* "%s" */
     572        "%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s",
     573        /* pre, */
     574        hexstrbuf + 0 * 4,
     575        hexstrbuf + 1 * 4,
     576        hexstrbuf + 2 * 4,
     577        hexstrbuf + 3 * 4,
     578        hexstrbuf + 4 * 4,
     579        hexstrbuf + 5 * 4,
     580        hexstrbuf + 6 * 4,
     581        hexstrbuf + 7 * 4
     582    );
     583}
Note: See TracChangeset for help on using the changeset viewer.