#define AS_HEADER_SIZE 2
/* Now FOUR octets are used for AS value. */
-#define AS_VALUE_SIZE sizeof (as_t)
+#define AS_VALUE_SIZE sizeof(as_t)
/* This is the old one */
-#define AS16_VALUE_SIZE sizeof (as16_t)
+#define AS16_VALUE_SIZE sizeof(as16_t)
/* Maximum protocol segment length value */
#define AS_SEGMENT_MAX 255
if (!seg)
return;
- if (seg->as)
- assegment_data_free(seg->as);
+ assegment_data_free(seg->as);
memset(seg, 0xfe, sizeof(struct assegment));
XFREE(MTYPE_AS_SEG, seg);
return false;
}
+/* Check if aspath has BGP_AS_ZERO */
+bool aspath_check_as_zero(struct aspath *aspath)
+{
+ struct assegment *seg = aspath->segments;
+ unsigned int i;
+
+ while (seg) {
+ for (i = 0; i < seg->length; i++)
+ if (seg->as[i] == BGP_AS_ZERO)
+ return true;
+ seg = seg->next;
+ }
+
+ return false;
+}
+
/* Estimate size aspath /might/ take if encoded into an
* ASPATH attribute.
*
}
/* Return 1 if there are any 4-byte ASes in the path */
-unsigned int aspath_has_as4(struct aspath *aspath)
+bool aspath_has_as4(struct aspath *aspath)
{
struct assegment *seg = aspath->segments;
unsigned int i;
while (seg) {
for (i = 0; i < seg->length; i++)
if (seg->as[i] > BGP_AS_MAX)
- return 1;
+ return true;
seg = seg->next;
}
- return 0;
+ return false;
}
/* Convert aspath structure to string expression. */
* on more, than 8 bits (otherwise it's a warning, bug
* #564).
*/
- || ((sizeof segh.length > 1)
+ || ((sizeof(segh.length) > 1)
&& (0x10 + segh.length > 0x10 + AS_SEGMENT_MAX))) {
if (head)
assegment_free_all(head);
/* When a BGP router receives an UPDATE with an MP_REACH_NLRI
attribute, check the leftmost AS number in the AS_PATH attribute is
or not the peer's AS number. */
-int aspath_firstas_check(struct aspath *aspath, as_t asno)
+bool aspath_firstas_check(struct aspath *aspath, as_t asno)
{
if ((aspath == NULL) || (aspath->segments == NULL))
- return 0;
+ return false;
if (aspath->segments && (aspath->segments->type == AS_SEQUENCE)
&& (aspath->segments->as[0] == asno))
- return 1;
+ return true;
- return 0;
+ return false;
}
unsigned int aspath_get_first_as(struct aspath *aspath)
}
/* When all of AS path is private AS return 1. */
-int aspath_private_as_check(struct aspath *aspath)
+bool aspath_private_as_check(struct aspath *aspath)
{
struct assegment *seg;
if (!(aspath && aspath->segments))
- return 0;
+ return false;
seg = aspath->segments;
for (i = 0; i < seg->length; i++) {
if (!BGP_AS_IS_PRIVATE(seg->as[i]))
- return 0;
+ return false;
}
seg = seg->next;
}
- return 1;
+ return true;
}
/* Return True if the entire ASPATH consist of the specified ASN */
-int aspath_single_asn_check(struct aspath *aspath, as_t asn)
+bool aspath_single_asn_check(struct aspath *aspath, as_t asn)
{
struct assegment *seg;
if (!(aspath && aspath->segments))
- return 0;
+ return false;
seg = aspath->segments;
for (i = 0; i < seg->length; i++) {
if (seg->as[i] != asn)
- return 0;
+ return false;
}
seg = seg->next;
}
- return 1;
+ return true;
}
/* Replace all instances of the target ASN with our own ASN */
/* AS path confed check. If aspath contains confed set or sequence then return
* 1. */
-int aspath_confed_check(struct aspath *aspath)
+bool aspath_confed_check(struct aspath *aspath)
{
struct assegment *seg;
if (!(aspath && aspath->segments))
- return 0;
+ return false;
seg = aspath->segments;
while (seg) {
if (seg->type == AS_CONFED_SET
|| seg->type == AS_CONFED_SEQUENCE)
- return 1;
+ return true;
seg = seg->next;
}
- return 0;
+ return false;
}
/* Leftmost AS path segment confed check. If leftmost AS segment is of type
AS_CONFED_SEQUENCE or AS_CONFED_SET then return 1. */
-int aspath_left_confed_check(struct aspath *aspath)
+bool aspath_left_confed_check(struct aspath *aspath)
{
if (!(aspath && aspath->segments))
- return 0;
+ return false;
if ((aspath->segments->type == AS_CONFED_SEQUENCE)
|| (aspath->segments->type == AS_CONFED_SET))
- return 1;
+ return true;
- return 0;
+ return false;
}
/* Merge as1 to as2. as2 should be uninterned aspath. */
/* Compare leftmost AS value for MED check. If as1's leftmost AS and
as2's leftmost AS is same return 1. */
-int aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2)
+bool aspath_cmp_left(const struct aspath *aspath1, const struct aspath *aspath2)
{
const struct assegment *seg1;
const struct assegment *seg2;
if (!(aspath1 && aspath2))
- return 0;
+ return false;
seg1 = aspath1->segments;
seg2 = aspath2->segments;
/* If both paths are originated in this AS then we do want to compare
* MED */
if (!seg1 && !seg2)
- return 1;
+ return true;
/* find first non-confed segments for each */
while (seg1 && ((seg1->type == AS_CONFED_SEQUENCE)
/* Check as1's */
if (!(seg1 && seg2 && (seg1->type == AS_SEQUENCE)
&& (seg2->type == AS_SEQUENCE)))
- return 0;
+ return false;
if (seg1->as[0] == seg2->as[0])
- return 1;
+ return true;
- return 0;
+ return false;
}
/* Truncate an aspath after a number of hops, and put the hops remaining
if (hops < seg->length) {
if (BGP_DEBUG(as4, AS4))
zlog_debug(
- "[AS4] AS4PATHmangle: AS_CONFED_SEQUENCE falls"
- " across 2/4 ASN boundary somewhere, broken..");
+ "[AS4] AS4PATHmangle: AS_CONFED_SEQUENCE falls across 2/4 ASN boundary somewhere, broken..");
hops = seg->length;
}
/* fallthru */