[packages] quagga: refresh patches
[openwrt/svn-archive/archive.git] / net / quagga / patches / 120-confed_errorhandle.patch
1 --- a/bgpd/bgp_aspath.c
2 +++ b/bgpd/bgp_aspath.c
3 @@ -614,6 +614,47 @@ 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 + caddr_t pnt;
12 + caddr_t end;
13 + struct assegment *assegment;
14 +
15 + if (aspath == NULL)
16 + return 0;
17 +
18 + pnt = aspath->data;
19 + end = aspath->data + aspath->length;
20 +
21 + while (pnt < end)
22 + {
23 + assegment = (struct assegment *) pnt;
24 + if (assegment->type == AS_CONFED_SET || assegment->type == AS_CONFED_SEQUENCE)
25 + return 1;
26 + pnt += (assegment->length * AS_VALUE_SIZE) + AS_HEADER_SIZE;
27 + }
28 + return 0;
29 +}
30 +
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. */
33 +int
34 +aspath_left_confed_check (struct aspath *aspath)
35 +{
36 + struct assegment *assegment;
37 +
38 + if (aspath == NULL)
39 + return 0;
40 +
41 + assegment = (struct assegment *) aspath->data;
42 + if (assegment->type == AS_CONFED_SEQUENCE || assegment->type == AS_CONFED_SET)
43 + return 1;
44 +
45 + return 0;
46 +}
47 +
48 /* Merge as1 to as2. as2 should be uninterned aspath. */
49 struct aspath *
50 aspath_merge (struct aspath *as1, struct aspath *as2)
51 @@ -671,6 +712,10 @@ aspath_prepend (struct aspath *as1, stru
52 if (seg1 == NULL)
53 return as2;
54
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);
58 +
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 ();
71 --- a/bgpd/bgp_attr.c
72 +++ b/bgpd/bgp_attr.c
73 @@ -673,6 +673,17 @@ bgp_attr_aspath (struct peer *peer, bgp_
74 return -1;
75 }
76
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)))
80 + {
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);
85 + return -1;
86 + }
87 +
88 bgp = peer->bgp;
89
90 /* First AS check for EBGP. */