diff options
-rw-r--r-- | bgpd/bgp_attr.h | 2 | ||||
-rw-r--r-- | bgpd/bgp_route.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_routemap.c | 15 | ||||
-rw-r--r-- | lib/zebra.h | 5 |
4 files changed, 15 insertions, 9 deletions
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 9c5bf879..e44ff3a3 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -27,6 +27,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #define CHECK_BITMAP(MAP, NUM) \ CHECK_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY)) +#define BGP_MED_MAX UINT32_MAX + /* BGP Attribute type range. */ #define BGP_ATTR_TYPE_RANGE 256 #define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 736b6be5..9259f5a6 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -146,7 +146,7 @@ bgp_med_value (struct attr *attr, struct bgp *bgp) else { if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST)) - return 4294967295ul; + return BGP_MED_MAX; else return 0; } diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index a2923fb1..a2635151 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -310,14 +310,13 @@ route_match_metric_compile (char *arg) { u_int32_t *med; char *endptr = NULL; + unsigned long tmpval; + tmpval = strtoul (arg, &endptr, 10); + if (*endptr != '\0' || tmpval == ULONG_MAX) + return NULL; med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); - *med = strtoul (arg, &endptr, 10); - if (*endptr != '\0' || *med == ULONG_MAX) - { - XFREE (MTYPE_ROUTE_MAP_COMPILED, med); - return NULL; - } + *med = tmpval; return med; } @@ -879,8 +878,8 @@ route_set_metric (void *rule, struct prefix *prefix, if (strncmp (metric, "+", 1) == 0) { - if (bgp_info->attr->med/2 + metric_val/2 > UINT32_MAX/2) - bgp_info->attr->med = UINT32_MAX-1; + if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2) + bgp_info->attr->med = BGP_MED_MAX - 1; else bgp_info->attr->med += metric_val; } diff --git a/lib/zebra.h b/lib/zebra.h index dc17730b..3193b6e2 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -178,6 +178,11 @@ typedef int socklen_t; #include <netinet6/nd6.h> #endif /* HAVE_NETINET6_ND6_H */ +/* Some systems do not define UINT32_MAX */ +#ifndef UINT32_MAX +#define UINT32_MAX 0xFFFFFFFFU +#endif /* UINT32_MAX */ + #ifdef HAVE_LIBUTIL_H #include <libutil.h> #endif /* HAVE_LIBUTIL_H */ |