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/libiproute/rt_names.c

    r2725 r3621  
    1111#include "rt_names.h"
    1212
     13#define CONFDIR          CONFIG_FEATURE_IP_ROUTE_DIR
     14
    1315typedef struct rtnl_tab_t {
    1416    const char *cached_str;
    1517    unsigned cached_result;
    16     const char *tab[256];
     18    /* upstream version switched to a hash table and removed
     19     * id < 256 limit. For now bbox bumps this array size from 256
     20     * to 1024. If you plan to change this to a hash table,
     21     * consider merging several hash tables we have (for example,
     22     * awk has resizable one!
     23     */
     24#define RT_TABLE_MAX 1023
     25    const char *tab[RT_TABLE_MAX+1];
    1726} rtnl_tab_t;
    1827
     
    2029{
    2130    char *token[2];
    22     parser_t *parser = config_open2(file, fopen_for_read);
    23 
     31    char fullname[sizeof(CONFDIR"/rt_dsfield") + 8];
     32    parser_t *parser;
     33
     34    sprintf(fullname, CONFDIR"/rt_%s", file);
     35    parser = config_open2(fullname, fopen_for_read);
    2436    while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
    2537        unsigned id = bb_strtou(token[0], NULL, 0);
    26         if (id > 256) {
     38        if (id > RT_TABLE_MAX) {
    2739            bb_error_msg("database %s is corrupted at line %d",
    2840                file, parser->lineno);
     
    4355    }
    4456
    45     for (i = 0; i < 256; i++) {
     57    for (i = 0; i <= RT_TABLE_MAX; i++) {
    4658        if (tab->tab[i]
    4759         && strcmp(tab->tab[i], arg) == 0
     
    5567
    5668    i = bb_strtou(arg, NULL, base);
    57     if (i > 255)
     69    if (i > RT_TABLE_MAX)
    5870        return -1;
    5971    *id = i;
     
    8698    rtnl_rtprot_tab = xzalloc(sizeof(*rtnl_rtprot_tab));
    8799    memcpy(rtnl_rtprot_tab->tab, init_tab, sizeof(init_tab));
    88     rtnl_tab_initialize("/etc/iproute2/rt_protos", rtnl_rtprot_tab->tab);
    89 }
    90 
    91 const char* FAST_FUNC rtnl_rtprot_n2a(int id, char *buf)
    92 {
    93     if (id < 0 || id >= 256) {
    94         sprintf(buf, "%d", id);
    95         return buf;
     100    rtnl_tab_initialize("protos", rtnl_rtprot_tab->tab);
     101}
     102
     103#if 0 /* UNUSED */
     104const char* FAST_FUNC rtnl_rtprot_n2a(int id)
     105{
     106    if (id < 0 || id > RT_TABLE_MAX) {
     107        return itoa(id);
    96108    }
    97109
     
    100112    if (rtnl_rtprot_tab->tab[id])
    101113        return rtnl_rtprot_tab->tab[id];
    102     /* buf is SPRINT_BSIZE big */
    103     sprintf(buf, "%d", id);
    104     return buf;
    105 }
     114    return itoa(id);
     115}
     116#endif
    106117
    107118int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg)
     
    124135    rtnl_rtscope_tab->tab[253] = "link";
    125136    rtnl_rtscope_tab->tab[200] = "site";
    126     rtnl_tab_initialize("/etc/iproute2/rt_scopes", rtnl_rtscope_tab->tab);
    127 }
    128 
    129 const char* FAST_FUNC rtnl_rtscope_n2a(int id, char *buf)
    130 {
    131     if (id < 0 || id >= 256) {
    132         sprintf(buf, "%d", id);
    133         return buf;
     137    rtnl_tab_initialize("scopes", rtnl_rtscope_tab->tab);
     138}
     139
     140const char* FAST_FUNC rtnl_rtscope_n2a(int id)
     141{
     142    if (id < 0 || id > RT_TABLE_MAX) {
     143        return itoa(id);
    134144    }
    135145
     
    138148    if (rtnl_rtscope_tab->tab[id])
    139149        return rtnl_rtscope_tab->tab[id];
    140     /* buf is SPRINT_BSIZE big */
    141     sprintf(buf, "%d", id);
    142     return buf;
     150    return itoa(id);
    143151}
    144152
     
    157165    rtnl_rtrealm_tab = xzalloc(sizeof(*rtnl_rtrealm_tab));
    158166    rtnl_rtrealm_tab->tab[0] = "unknown";
    159     rtnl_tab_initialize("/etc/iproute2/rt_realms", rtnl_rtrealm_tab->tab);
     167    rtnl_tab_initialize("realms", rtnl_rtrealm_tab->tab);
    160168}
    161169
     
    167175
    168176#if ENABLE_FEATURE_IP_RULE
    169 const char* FAST_FUNC rtnl_rtrealm_n2a(int id, char *buf)
    170 {
    171     if (id < 0 || id >= 256) {
    172         sprintf(buf, "%d", id);
    173         return buf;
     177const char* FAST_FUNC rtnl_rtrealm_n2a(int id)
     178{
     179    if (id < 0 || id > RT_TABLE_MAX) {
     180        return itoa(id);
    174181    }
    175182
     
    178185    if (rtnl_rtrealm_tab->tab[id])
    179186        return rtnl_rtrealm_tab->tab[id];
    180     /* buf is SPRINT_BSIZE big */
    181     sprintf(buf, "%d", id);
    182     return buf;
     187    return itoa(id);
    183188}
    184189#endif
     
    192197    rtnl_rtdsfield_tab = xzalloc(sizeof(*rtnl_rtdsfield_tab));
    193198    rtnl_rtdsfield_tab->tab[0] = "0";
    194     rtnl_tab_initialize("/etc/iproute2/rt_dsfield", rtnl_rtdsfield_tab->tab);
    195 }
    196 
    197 const char* FAST_FUNC rtnl_dsfield_n2a(int id, char *buf)
    198 {
    199     if (id < 0 || id >= 256) {
    200         sprintf(buf, "%d", id);
    201         return buf;
     199    rtnl_tab_initialize("dsfield", rtnl_rtdsfield_tab->tab);
     200}
     201
     202const char* FAST_FUNC rtnl_dsfield_n2a(int id)
     203{
     204    if (id < 0 || id > RT_TABLE_MAX) {
     205        return itoa(id);
    202206    }
    203207
     
    206210    if (rtnl_rtdsfield_tab->tab[id])
    207211        return rtnl_rtdsfield_tab->tab[id];
    208     /* buf is SPRINT_BSIZE big */
    209     sprintf(buf, "0x%02x", id);
    210     return buf;
     212    return itoa(id);
    211213}
    212214
     
    223225static void rtnl_rttable_initialize(void)
    224226{
    225     if (rtnl_rtdsfield_tab) return;
     227    if (rtnl_rttable_tab)
     228        return;
     229
    226230    rtnl_rttable_tab = xzalloc(sizeof(*rtnl_rttable_tab));
    227231    rtnl_rttable_tab->tab[0] = "unspec";
     
    229233    rtnl_rttable_tab->tab[254] = "main";
    230234    rtnl_rttable_tab->tab[253] = "default";
    231     rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab->tab);
    232 }
    233 
    234 const char* FAST_FUNC rtnl_rttable_n2a(int id, char *buf)
    235 {
    236     if (id < 0 || id >= 256) {
    237         sprintf(buf, "%d", id);
    238         return buf;
     235    rtnl_tab_initialize("tables", rtnl_rttable_tab->tab);
     236}
     237
     238const char* FAST_FUNC rtnl_rttable_n2a(int id)
     239{
     240    if (id < 0 || id > RT_TABLE_MAX) {
     241        return itoa(id);
    239242    }
    240243
     
    243246    if (rtnl_rttable_tab->tab[id])
    244247        return rtnl_rttable_tab->tab[id];
    245     /* buf is SPRINT_BSIZE big */
    246     sprintf(buf, "%d", id);
    247     return buf;
     248    return itoa(id);
    248249}
    249250
Note: See TracChangeset for help on using the changeset viewer.