Mailing List Archive

A better "med" patch
Since my original med patch appears to have touched off a bit of
controversy, I figured I should try again.

I'll let someone with more cross-platform ability than I decide the
correct includes, etc to put into bgp_attr.h. For some reason I only
have access to Red Hat Linux boxes here at work.

Maybe we should go with
#define BGP_MED_MAX 0xFFFFFFFFU
but I'll let someone else make that call.

Fortunatly, there weren't many places where "med" is used in the
source, so this took less time than anyone expected. :-)

-- JF

--- quagga-0.96.3/bgpd/#bgp_attr.h~ 2003-10-09 17:15:56.000000000 -0400
+++ quagga-0.96.3/bgpd/bgp_attr.h 2003-10-09 17:15:56.000000000 -0400
@@ -40,6 +40,14 @@
/* BGP attribute header must bigger than 2. */
#define BGP_ATTR_MIN_LEN 2 /* Attribute flag and type. */

+/* quiet excessive arguing on the quagga-dev mailing list */
+#ifndef UINT32_MAX
+/* Note that this is incorrect on 1s-complement systems */
+#define UINT32_MAX ~0U
+#endif
+
+#define BGP_MED_MAX UINT32_MAX
+
/* BGP attribute structure. */
struct attr
{
--- quagga-0.96.3/bgpd/#bgp_route.c~ 2003-10-09 17:15:56.000000000 -0400
+++ quagga-0.96.3/bgpd/bgp_route.c 2003-10-09 17:15:56.000000000 -0400
@@ -146,7 +146,7 @@
else
{
if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
- return 4294967295ul;
+ return BGP_MED_MAX;
else
return 0;
}
--- quagga-0.96.3/bgpd/#bgp_routemap.c~ 2003-10-09 17:15:56.000000000 -0400
+++ quagga-0.96.3/bgpd/bgp_routemap.c 2003-10-09 17:19:58.000000000 -0400
@@ -310,14 +310,13 @@
{
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 @@

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;
}
Re: A better "med" patch [ In reply to ]
On Fri, 10 Oct 2003, Jay Fenlason wrote:

> Since my original med patch appears to have touched off a bit of
> controversy, I figured I should try again.
>
> I'll let someone with more cross-platform ability than I decide the
> correct includes, etc to put into bgp_attr.h. For some reason I only
> have access to Red Hat Linux boxes here at work.

:)

So the RedHat FreeBSD project is stalled is it?

> Maybe we should go with #define BGP_MED_MAX 0xFFFFFFFFU but I'll
> let someone else make that call.
>
> Fortunatly, there weren't many places where "med" is used in the
> source, so this took less time than anyone expected. :-)

cheers jay.

I even have access to a FreeBSD box now, thanks to Ted, so hopefully
the next quagga release /will/ compile on FreeBSD.

> -- JF

regards,
--
Paul Jakma paul@clubi.ie paul@jakma.org Key ID: 64A2FF6A
warning: do not ever send email to spam@dishone.st
Fortune:
The road to ruin is always in good repair, and the travellers pay the
expense of it.
-- Josh Billings