Implement BGP confederationerror handling (RFC5065, Par. 5) Signed-off-by: Vasilis...
[openwrt/svn-archive/archive.git] / net / quagga / patches / 120-confed_errorhandle.patch
1 diff -Nur quagga-0.98.6/bgpd/bgp_aspath.c quagga-0.98.6-patched/bgpd/bgp_aspath.c
2 --- quagga-0.98.6/bgpd/bgp_aspath.c 2005-06-15 14:53:50.000000000 +0300
3 +++ quagga-0.98.6-patched/bgpd/bgp_aspath.c 2007-11-24 03:20:02.000000000 +0200
4 @@ -614,6 +614,47 @@
5 return 1;
6 }
7
8 +/* AS path confed check. If aspath contains confed set or sequence then return 1. */
9 +int
10 +aspath_confed_check (struct aspath *aspath)
11 +{
12 + caddr_t pnt;
13 + caddr_t end;
14 + struct assegment *assegment;
15 +
16 + if (aspath == NULL)
17 + return 0;
18 +
19 + pnt = aspath->data;
20 + end = aspath->data + aspath->length;
21 +
22 + while (pnt < end)
23 + {
24 + assegment = (struct assegment *) pnt;
25 + if (assegment->type == AS_CONFED_SET || assegment->type == AS_CONFED_SEQUENCE)
26 + return 1;
27 + pnt += (assegment->length * AS_VALUE_SIZE) + AS_HEADER_SIZE;
28 + }
29 + return 0;
30 +}
31 +
32 +/* Leftmost AS path segment confed check. If leftmost AS segment is of type
33 + AS_CONFED_SEQUENCE or AS_CONFED_SET then return 1. */
34 +int
35 +aspath_left_confed_check (struct aspath *aspath)
36 +{
37 + struct assegment *assegment;
38 +
39 + if (aspath == NULL)
40 + return 0;
41 +
42 + assegment = (struct assegment *) aspath->data;
43 + if (assegment->type == AS_CONFED_SEQUENCE || assegment->type == AS_CONFED_SET)
44 + return 1;
45 +
46 + return 0;
47 +}
48 +
49 /* Merge as1 to as2. as2 should be uninterned aspath. */
50 struct aspath *
51 aspath_merge (struct aspath *as1, struct aspath *as2)
52 @@ -671,6 +712,10 @@
53 if (seg1 == NULL)
54 return as2;
55
56 + /* Delete any AS_CONFED_SEQUENCE segment from as2. */
57 + if (seg1->type == AS_SEQUENCE && seg2->type == AS_CONFED_SEQUENCE)
58 + as2 = aspath_delete_confed_seq (as2);
59 +
60 /* Compare last segment type of as1 and first segment type of as2. */
61 if (seg1->type != seg2->type)
62 return aspath_merge (as1, as2);
63 diff -Nur quagga-0.98.6/bgpd/bgp_aspath.h quagga-0.98.6-patched/bgpd/bgp_aspath.h
64 --- quagga-0.98.6/bgpd/bgp_aspath.h 2005-06-15 14:53:50.000000000 +0300
65 +++ quagga-0.98.6-patched/bgpd/bgp_aspath.h 2007-11-24 03:21:24.000000000 +0200
66 @@ -76,4 +76,6 @@
67 int aspath_loop_check (struct aspath *, as_t);
68 int aspath_private_as_check (struct aspath *);
69 int aspath_firstas_check (struct aspath *, as_t);
70 +int aspath_confed_check (struct aspath *);
71 +int aspath_left_confed_check (struct aspath *);
72 unsigned long aspath_count ();
73 diff -Nur quagga-0.98.6/bgpd/bgp_attr.c quagga-0.98.6-patched/bgpd/bgp_attr.c
74 --- quagga-0.98.6/bgpd/bgp_attr.c 2006-05-03 01:37:47.000000000 +0300
75 +++ quagga-0.98.6-patched/bgpd/bgp_attr.c 2007-11-24 03:09:56.000000000 +0200
76 @@ -673,6 +673,17 @@
77 return -1;
78 }
79
80 + /* Confederation sanity check. */
81 + if ((peer_sort (peer) == BGP_PEER_CONFED && ! aspath_left_confed_check (attr->aspath)) ||
82 + (peer_sort (peer) == BGP_PEER_EBGP && aspath_confed_check (attr->aspath)))
83 + {
84 + zlog (peer->log, LOG_ERR, "Malformed AS path from %s", peer->host);
85 + bgp_notify_send (peer,
86 + BGP_NOTIFY_UPDATE_ERR,
87 + BGP_NOTIFY_UPDATE_MAL_AS_PATH);
88 + return -1;
89 + }
90 +
91 bgp = peer->bgp;
92
93 /* First AS check for EBGP. */