-/* $OpenBSD: flowspec.c,v 1.1 2023/04/17 08:02:21 claudio Exp $ */
+/* $OpenBSD: flowspec.c,v 1.2 2023/04/17 20:54:57 claudio Exp $ */
/*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
/*
* Compare two IPv4 flowspec prefix components.
- * Returns 1 if first prefix is preferred, -1 if second, 0 if equal.
+ * Returns -1 if first prefix is preferred, 1 if second, 0 if equal.
*/
static int
flowspec_cmp_prefix4(const uint8_t *abuf, int ablen, const uint8_t *bbuf,
/* lowest IP value has precedence */
cmp = memcmp(a, b, sizeof(a));
if (cmp < 0)
- return 1;
- if (cmp > 0)
return -1;
+ if (cmp > 0)
+ return 1;
/* if common prefix, more specific route has precedence */
if (alen > blen)
- return 1;
- if (alen < blen)
return -1;
+ if (alen < blen)
+ return 1;
return 0;
}
/* lowest offset has precedence */
if (abuf[2] < bbuf[2])
- return 1;
- if (abuf[2] > bbuf[2])
return -1;
+ if (abuf[2] > bbuf[2])
+ return 1;
/* calculate actual pattern size (len - offset) */
alen = abuf[1] - abuf[2];
/* lowest IP value has precedence */
cmp = memcmp(a, b, sizeof(a));
if (cmp < 0)
- return 1;
- if (cmp > 0)
return -1;
+ if (cmp > 0)
+ return 1;
/* if common prefix, more specific route has precedence */
if (alen > blen)
- return 1;
- if (alen < blen)
return -1;
+ if (alen < blen)
+ return 1;
return 0;
}
/*
* Compare two valid flowspec NLRI objects according to RFC 8955 & 8956.
- * Returns 1 if the first object has preference, -1 if not, and 0 if the
+ * Returns -1 if the first object has preference, 1 if not, and 0 if the
* two objects are equal.
*/
int
/* If types differ, lowest type wins. */
if (atype < btype)
- return 1;
- if (atype > btype)
return -1;
+ if (atype > btype)
+ return 1;
switch (atype) {
case FLOWSPEC_TYPE_DEST:
* string has precedence.
*/
if (cmp < 0)
- return 1;
- if (cmp > 0)
return -1;
+ if (cmp > 0)
+ return 1;
/*
* Longest component wins when common prefix is equal.
* This is not really possible because EOL encoding will
* it (and it is cheap).
*/
if (acomplen > bcomplen)
- return 1;
- if (acomplen < bcomplen)
return -1;
+ if (acomplen < bcomplen)
+ return 1;
break;
}
a += acomplen;
/* Rule with more components wins */
if (alen > 0 && blen <= 0)
- return 1;
- if (alen <= 0 && blen > 0)
return -1;
+ if (alen <= 0 && blen > 0)
+ return 1;
}
return 0;
}