modernize backfire 10.03 so it can be operational again
[openwrt-10.03/.git] / package / quagga / patches-upstream / 300-fix_MRT.patch
1 From fc1c1cc5e2800431e1ca59c938b1329c2365ad60 Mon Sep 17 00:00:00 2001
2 From: Colin Petrie <cpetrie@ripe.net>
3 Date: Wed, 11 May 2016 09:56:58 +0000
4 Subject: bgpd: fix MRT table dumps for locally-originated routes
5
6 I've been working on a small patch to correct an issue in the BGP MRT
7 table dump code. It's a quick'n'easy fix initially, and I'd appreciate
8 any feedback on making it better :)
9
10 Issue:
11
12 When the BGP table dump code runs, it generates the peer_index_table.
13 This walks the list of peers, and dumps out their IP, ASN, address
14 family, etc. It also sets the peer index number in the peer struct.
15
16 Then the code walks the RIB, and for each prefix, writes out RIB
17 entries, that refer to the peer index number.
18
19 However, when it finds prefixes that are locally originated, the
20 associated peer is the 'self' peer, which wasn't in the list of peers,
21 never gets an index number assigned, but because it is calloc'd, the
22 index number is set to 0.
23
24 End result: locally-originated routes are associated with whichever peer
25 happens to be first in the list of remote peers in the index table :)
26
27 Example (from one of our route collectors) - these are two of our
28 originated prefixes (bgpdump output):
29 TABLE_DUMP2|1457568002|B|12.0.1.63|7018|84.205.80.0/24||IGP|193.0.4.28|0|0||NAG|64512
30 10.255.255.255|
31 TABLE_DUMP2|1457568006|B|12.0.1.63|7018|2001:7fb:ff00::/48||IGP|::|0|0||NAG||
32
33 The prefixes are announced by us (note it has an empty AS PATH (the
34 field after the prefix)) but also looks like it was received from AS7018
35 (12.0.1.63). In fact, the AS7018 peer just happens to be the first peer
36 in the index table.
37
38 Fix:
39
40 The simplest fix (which is also the method adopted by both OpenBGPd and
41 the BIRD mrtdump branch) is to create an empty placeholder 'peer' at the
42 start of the peer index table, for all the routes which are locally
43 originated to refer to.
44
45 I've attached a patch for this.
46 Here's a resulting bgpdump output after the patch:
47 TABLE_DUMP2|1458828539|B|0.0.0.0|0|93.175.150.0/24||IGP|0.0.0.0|0|0||NAG||
48 Now it is more obvious that the prefix is locally originated.
49
50 There are more complicated potential ways of fixing it
51 1) skip the local routes when dumping the RIB. This leads to questions
52 about what an MRT table dump *should* contain :)
53 2) include the 'self' peer in the list of peers used to generate the
54 index table.
55 etc etc.
56
57 But I'm quite happy with my 'create a fake peer, and associate local
58 routes with it' method :)
59
60 Your thoughts and feedback are welcome!
61
62 Regards,
63
64 Colin Petrie
65 Systems Engineer
66 RIPE NCC RIS Project
67 Tested-by: NetDEF CI System <cisystem@netdef.org>
68 ---
69 --- a/bgpd/bgp_dump.c
70 +++ b/bgpd/bgp_dump.c
71 @@ -226,7 +226,7 @@ bgp_dump_routes_index_table(struct bgp *
72  {
73    struct peer *peer;
74    struct listnode *node;
75 -  uint16_t peerno = 0;
76 +  uint16_t peerno = 1;
77    struct stream *obuf;
78  
79    obuf = bgp_dump_obuf;
80 @@ -250,8 +250,18 @@ bgp_dump_routes_index_table(struct bgp *
81        stream_putw(obuf, 0);
82      }
83  
84 -  /* Peer count */
85 -  stream_putw (obuf, listcount(bgp->peer));
86 +  /* Peer count ( plus one extra internal peer ) */
87 +  stream_putw (obuf, listcount(bgp->peer) + 1);
88 +
89 +  /* Populate fake peer at index 0, for locally originated routes */
90 +  /* Peer type (IPv4) */
91 +  stream_putc (obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4+TABLE_DUMP_V2_PEER_INDEX_TABLE_IP);
92 +  /* Peer BGP ID (0.0.0.0) */
93 +  stream_putl (obuf, 0);
94 +  /* Peer IP address (0.0.0.0) */
95 +  stream_putl (obuf, 0);
96 +  /* Peer ASN (0) */
97 +  stream_putl (obuf, 0);
98  
99    /* Walk down all peers */
100    for(ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer))