diff options
Diffstat (limited to 'ripd/rip_routemap.c')
| -rw-r--r-- | ripd/rip_routemap.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/ripd/rip_routemap.c b/ripd/rip_routemap.c index 7255df5e67..7d39023b38 100644 --- a/ripd/rip_routemap.c +++ b/ripd/rip_routemap.c @@ -36,8 +36,8 @@ struct rip_metric_modifier { enum { metric_increment, metric_decrement, metric_absolute } type; - - u_char metric; + bool used; + u_int8_t metric; }; /* Hook function for updating route_map assignment. */ @@ -365,6 +365,9 @@ static route_map_result_t route_set_metric(void *rule, struct prefix *prefix, mod = rule; rinfo = object; + if (!mod->used) + return RMAP_OKAY; + if (mod->type == metric_increment) rinfo->metric_out += mod->metric; else if (mod->type == metric_decrement) @@ -387,43 +390,49 @@ static void *route_set_metric_compile(const char *arg) { int len; const char *pnt; - int type; long metric; char *endptr = NULL; struct rip_metric_modifier *mod; + mod = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, + sizeof(struct rip_metric_modifier)); + mod->used = false; + len = strlen(arg); pnt = arg; if (len == 0) - return NULL; + return mod; /* Examine first character. */ if (arg[0] == '+') { - type = metric_increment; + mod->type = metric_increment; pnt++; } else if (arg[0] == '-') { - type = metric_decrement; + mod->type = metric_decrement; pnt++; } else - type = metric_absolute; + mod->type = metric_absolute; /* Check beginning with digit string. */ if (*pnt < '0' || *pnt > '9') - return NULL; + return mod; /* Convert string to integer. */ metric = strtol(pnt, &endptr, 10); - if (metric == LONG_MAX || *endptr != '\0') - return NULL; - if (metric < 0 || metric > RIP_METRIC_INFINITY) - return NULL; + if (*endptr != '\0' || mod->metric < 0) { + metric = 0; + return mod; + } + if (metric > RIP_METRIC_INFINITY) { + zlog_info("%s: Metric specified: %ld is greater than RIP_METRIC_INFINITY, using INFINITY instead", + __PRETTY_FUNCTION__, metric); + mod->metric = RIP_METRIC_INFINITY; + } else + mod->metric = metric; - mod = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, - sizeof(struct rip_metric_modifier)); - mod->type = type; - mod->metric = metric; + mod->used = true; return mod; } |
