1 --- a/bgpd/bgp_aspath.c
2 +++ b/bgpd/bgp_aspath.c
3 @@ -614,6 +614,47 @@ aspath_private_as_check (struct aspath *
7 +/* AS path confed check. If aspath contains confed set or sequence then return 1. */
9 +aspath_confed_check (struct aspath *aspath)
13 + struct assegment *assegment;
19 + end = aspath->data + aspath->length;
23 + assegment = (struct assegment *) pnt;
24 + if (assegment->type == AS_CONFED_SET || assegment->type == AS_CONFED_SEQUENCE)
26 + pnt += (assegment->length * AS_VALUE_SIZE) + AS_HEADER_SIZE;
31 +/* Leftmost AS path segment confed check. If leftmost AS segment is of type
32 + AS_CONFED_SEQUENCE or AS_CONFED_SET then return 1. */
34 +aspath_left_confed_check (struct aspath *aspath)
36 + struct assegment *assegment;
41 + assegment = (struct assegment *) aspath->data;
42 + if (assegment->type == AS_CONFED_SEQUENCE || assegment->type == AS_CONFED_SET)
48 /* Merge as1 to as2. as2 should be uninterned aspath. */
50 aspath_merge (struct aspath *as1, struct aspath *as2)
51 @@ -671,6 +712,10 @@ aspath_prepend (struct aspath *as1, stru
55 + /* Delete any AS_CONFED_SEQUENCE segment from as2. */
56 + if (seg1->type == AS_SEQUENCE && seg2->type == AS_CONFED_SEQUENCE)
57 + as2 = aspath_delete_confed_seq (as2);
59 /* Compare last segment type of as1 and first segment type of as2. */
60 if (seg1->type != seg2->type)
61 return aspath_merge (as1, as2);
62 --- a/bgpd/bgp_aspath.h
63 +++ b/bgpd/bgp_aspath.h
64 @@ -76,4 +76,6 @@ unsigned int aspath_key_make (struct asp
65 int aspath_loop_check (struct aspath *, as_t);
66 int aspath_private_as_check (struct aspath *);
67 int aspath_firstas_check (struct aspath *, as_t);
68 +int aspath_confed_check (struct aspath *);
69 +int aspath_left_confed_check (struct aspath *);
70 unsigned long aspath_count ();
73 @@ -673,6 +673,17 @@ bgp_attr_aspath (struct peer *peer, bgp_
77 + /* Confederation sanity check. */
78 + if ((peer_sort (peer) == BGP_PEER_CONFED && ! aspath_left_confed_check (attr->aspath)) ||
79 + (peer_sort (peer) == BGP_PEER_EBGP && aspath_confed_check (attr->aspath)))
81 + zlog (peer->log, LOG_ERR, "Malformed AS path from %s", peer->host);
82 + bgp_notify_send (peer,
83 + BGP_NOTIFY_UPDATE_ERR,
84 + BGP_NOTIFY_UPDATE_MAL_AS_PATH);
90 /* First AS check for EBGP. */