[packages] quagga-unstable: Implement BGP confederation error handling (RFC5065,...
[openwrt/svn-archive/archive.git] / net / quagga-unstable / patches / 120-confed_errorhandle.patch
1 --- a/bgpd/bgp_aspath.c
2 +++ b/bgpd/bgp_aspath.c
3 @@ -1122,6 +1122,42 @@ aspath_private_as_check (struct aspath *
4 return 1;
5 }
6
7 +/* AS path confed check. If aspath contains confed set or sequence then return 1. */
8 +int
9 +aspath_confed_check (struct aspath *aspath)
10 +{
11 + struct assegment *seg;
12 +
13 + if ( !(aspath && aspath->segments) )
14 + return 0;
15 +
16 + seg = aspath->segments;
17 +
18 + while (seg)
19 + {
20 + if (seg->type == AS_CONFED_SET || seg->type == AS_CONFED_SEQUENCE)
21 + return 1;
22 + seg = seg->next;
23 + }
24 + return 0;
25 +}
26 +
27 +/* Leftmost AS path segment confed check. If leftmost AS segment is of type
28 + AS_CONFED_SEQUENCE or AS_CONFED_SET then return 1. */
29 +int
30 +aspath_left_confed_check (struct aspath *aspath)
31 +{
32 +
33 + if ( !(aspath && aspath->segments) )
34 + return 0;
35 +
36 + if ( (aspath->segments->type == AS_CONFED_SEQUENCE)
37 + || (aspath->segments->type == AS_CONFED_SET) )
38 + return 1;
39 +
40 + return 0;
41 +}
42 +
43 /* Merge as1 to as2. as2 should be uninterned aspath. */
44 static struct aspath *
45 aspath_merge (struct aspath *as1, struct aspath *as2)
46 --- a/bgpd/bgp_aspath.h
47 +++ b/bgpd/bgp_aspath.h
48 @@ -88,6 +88,8 @@ extern unsigned int aspath_key_make (voi
49 extern int aspath_loop_check (struct aspath *, as_t);
50 extern int aspath_private_as_check (struct aspath *);
51 extern int aspath_firstas_check (struct aspath *, as_t);
52 +extern int aspath_confed_check (struct aspath *);
53 +extern int aspath_left_confed_check (struct aspath *);
54 extern unsigned long aspath_count (void);
55 extern unsigned int aspath_count_hops (struct aspath *);
56 extern unsigned int aspath_count_confeds (struct aspath *);
57 --- a/bgpd/bgp_attr.c
58 +++ b/bgpd/bgp_attr.c
59 @@ -872,6 +872,17 @@ static int bgp_attr_aspath_check( struct
60
61 bgp = peer->bgp;
62
63 + /* Confederation sanity check. */
64 + if ((peer_sort (peer) == BGP_PEER_CONFED && ! aspath_left_confed_check (attr->aspath)) ||
65 + (peer_sort (peer) == BGP_PEER_EBGP && aspath_confed_check (attr->aspath)))
66 + {
67 + zlog (peer->log, LOG_ERR, "Malformed AS path from %s", peer->host);
68 + bgp_notify_send (peer,
69 + BGP_NOTIFY_UPDATE_ERR,
70 + BGP_NOTIFY_UPDATE_MAL_AS_PATH);
71 + return -1;
72 + }
73 +
74 /* First AS check for EBGP. */
75 if (bgp != NULL && bgp_flag_check (bgp, BGP_FLAG_ENFORCE_FIRST_AS))
76 {