]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/bgp/bgp.h
Implementation of 4B ASN support for BGP
[thirdparty/bird.git] / proto / bgp / bgp.h
1 /*
2 * BIRD -- The Border Gateway Protocol
3 *
4 * (c) 2000 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #ifndef _BIRD_BGP_H_
10 #define _BIRD_BGP_H_
11
12 #include "nest/route.h"
13
14 struct linpool;
15 struct eattr;
16
17 struct bgp_config {
18 struct proto_config c;
19 u32 local_as, remote_as;
20 ip_addr remote_ip;
21 int multihop; /* Number of hops if multihop */
22 ip_addr multihop_via; /* Multihop: address to route to */
23 ip_addr source_addr; /* Source address to use */
24 int next_hop_self; /* Always set next hop to local IP address */
25 int compare_path_lengths; /* Use path lengths when selecting best route */
26 u32 default_local_pref; /* Default value for LOCAL_PREF attribute */
27 u32 default_med; /* Default value for MULTI_EXIT_DISC attribute */
28 unsigned connect_retry_time;
29 unsigned hold_time, initial_hold_time;
30 unsigned keepalive_time;
31 unsigned start_delay_time; /* Minimum delay between connects */
32 unsigned error_amnesia_time; /* Errors are forgotten after */
33 unsigned error_delay_time_min; /* Time to wait after an error is detected */
34 unsigned error_delay_time_max;
35 unsigned disable_after_error; /* Disable the protocol when error is detected */
36 };
37
38 struct bgp_conn {
39 struct bgp_proto *bgp;
40 struct birdsock *sk;
41 unsigned int state; /* State of connection state machine */
42 struct timer *connect_retry_timer;
43 struct timer *hold_timer;
44 struct timer *keepalive_timer;
45 int packets_to_send; /* Bitmap of packet types to be sent */
46 int notify_code, notify_subcode, notify_size;
47 byte *notify_data;
48 int error_flag; /* Error state, ignore all input */
49 int primary; /* This connection is primary */
50 u32 advertised_as; /* Temporary value for AS number received */
51 unsigned hold_time, keepalive_time; /* Times calculated from my and neighbor's requirements */
52 };
53
54 struct bgp_proto {
55 struct proto p;
56 struct bgp_config *cf; /* Shortcut to BGP configuration */
57 u32 local_as, remote_as;
58 int is_internal; /* Internal BGP connection (local_as == remote_as) */
59 int as4_support; /* Peer supports 4B AS numbers [RFC4893] */
60 u32 local_id; /* BGP identifier of this router */
61 u32 remote_id; /* BGP identifier of the neighbor */
62 struct bgp_conn *conn; /* Connection we have established */
63 struct bgp_conn outgoing_conn; /* Outgoing connection we're working with */
64 struct bgp_conn incoming_conn; /* Incoming connection we have neither accepted nor rejected yet */
65 struct object_lock *lock; /* Lock for neighbor connection */
66 ip_addr next_hop; /* Either the peer or multihop_via */
67 struct neighbor *neigh; /* Neighbor entry corresponding to next_hop */
68 ip_addr local_addr; /* Address of the local end of the link to next_hop */
69 struct bgp_bucket **bucket_hash; /* Hash table of attribute buckets */
70 unsigned int hash_size, hash_count, hash_limit;
71 struct fib prefix_fib; /* Prefixes to be sent */
72 list bucket_queue; /* Queue of buckets to send */
73 struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */
74 unsigned startup_delay; /* Time to delay protocol startup by due to errors */
75 bird_clock_t last_connect; /* Time of last connect attempt */
76 #ifdef IPV6
77 byte *mp_reach_start, *mp_unreach_start; /* Multiprotocol BGP attribute notes */
78 unsigned mp_reach_len, mp_unreach_len;
79 ip_addr local_link; /* Link-level version of local_addr */
80 #endif
81 };
82
83 struct bgp_prefix {
84 struct fib_node n; /* Node in prefix fib */
85 node bucket_node; /* Node in per-bucket list */
86 };
87
88 struct bgp_bucket {
89 node send_node; /* Node in send queue */
90 struct bgp_bucket *hash_next, *hash_prev; /* Node in bucket hash table */
91 unsigned hash; /* Hash over extended attributes */
92 list prefixes; /* Prefixes in this buckets */
93 ea_list eattrs[0]; /* Per-bucket extended attributes */
94 };
95
96 #define BGP_PORT 179
97 #define BGP_VERSION 4
98 #define BGP_HEADER_LENGTH 19
99 #define BGP_MAX_PACKET_LENGTH 4096
100 #define BGP_RX_BUFFER_SIZE 4096
101 #define BGP_TX_BUFFER_SIZE BGP_MAX_PACKET_LENGTH
102
103 extern struct linpool *bgp_linpool;
104
105 extern int bgp_as4_support;
106
107
108 void bgp_start_timer(struct timer *t, int value);
109 void bgp_check(struct bgp_config *c);
110 void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len);
111 void bgp_close_conn(struct bgp_conn *c);
112
113 #ifdef LOCAL_DEBUG
114 #define BGP_FORCE_DEBUG 1
115 #else
116 #define BGP_FORCE_DEBUG 0
117 #endif
118 #define BGP_TRACE(flags, msg, args...) do { if ((p->p.debug & flags) || BGP_FORCE_DEBUG) \
119 log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
120
121 /* attrs.c */
122
123 byte *bgp_attach_attr(struct ea_list **to, struct linpool *, unsigned attr, unsigned val);
124 struct rta *bgp_decode_attrs(struct bgp_conn *conn, byte *a, unsigned int len, struct linpool *pool, int mandatory);
125 int bgp_get_attr(struct eattr *e, byte *buf);
126 int bgp_rte_better(struct rte *, struct rte *);
127 void bgp_rt_notify(struct proto *, struct network *, struct rte *, struct rte *, struct ea_list *);
128 int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *);
129 void bgp_attr_init(struct bgp_proto *);
130 unsigned int bgp_encode_attrs(struct bgp_proto *p, byte *w, ea_list *attrs, int remains);
131 void bgp_free_bucket(struct bgp_proto *p, struct bgp_bucket *buck);
132 void bgp_get_route_info(struct rte *, byte *buf, struct ea_list *attrs);
133
134 /* packets.c */
135
136 void bgp_schedule_packet(struct bgp_conn *conn, int type);
137 void bgp_tx(struct birdsock *sk);
138 int bgp_rx(struct birdsock *sk, int size);
139 void bgp_log_error(struct bgp_proto *p, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len);
140
141 /* Packet types */
142
143 #define PKT_OPEN 0x01
144 #define PKT_UPDATE 0x02
145 #define PKT_NOTIFICATION 0x03
146 #define PKT_KEEPALIVE 0x04
147 #define PKT_SCHEDULE_CLOSE 0x1f /* Used internally to schedule socket close */
148
149 /* Attributes */
150
151 #define BAF_OPTIONAL 0x80
152 #define BAF_TRANSITIVE 0x40
153 #define BAF_PARTIAL 0x20
154 #define BAF_EXT_LEN 0x10
155
156 #define BA_ORIGIN 0x01 /* [RFC1771] */ /* WM */
157 #define BA_AS_PATH 0x02 /* WM */
158 #define BA_NEXT_HOP 0x03 /* WM */
159 #define BA_MULTI_EXIT_DISC 0x04 /* ON */
160 #define BA_LOCAL_PREF 0x05 /* WD */
161 #define BA_ATOMIC_AGGR 0x06 /* WD */
162 #define BA_AGGREGATOR 0x07 /* OT */
163 #define BA_COMMUNITY 0x08 /* [RFC1997] */ /* OT */
164 #define BA_ORIGINATOR_ID 0x09 /* [RFC1966] */ /* ON */
165 #define BA_CLUSTER_LIST 0x0a /* ON */
166 /* We don't support these: */
167 #define BA_DPA 0x0b /* ??? */
168 #define BA_ADVERTISER 0x0c /* [RFC1863] */
169 #define BA_RCID_PATH 0x0d
170 #define BA_MP_REACH_NLRI 0x0e /* [RFC2283] */
171 #define BA_MP_UNREACH_NLRI 0x0f
172 #define BA_EXTENDED_COMM 0x10 /* draft-ramachandra-bgp-ext-communities */
173 #define BA_AS4_PATH 0x11 /* [RFC4893] */
174 #define BA_AS4_AGGREGATOR 0x12
175
176 /* BGP states */
177
178 #define BS_IDLE 0
179 #define BS_CONNECT 1 /* Attempting to connect */
180 #define BS_ACTIVE 2 /* Waiting for connection retry & listening */
181 #define BS_OPENSENT 3
182 #define BS_OPENCONFIRM 4
183 #define BS_ESTABLISHED 5
184
185 /* Well-known communities */
186
187 #define BGP_COMM_NO_EXPORT 0xffffff01 /* Don't export outside local AS / confed. */
188 #define BGP_COMM_NO_ADVERTISE 0xffffff02 /* Don't export at all */
189 #define BGP_COMM_NO_EXPORT_SUBCONFED 0xffffff03 /* NO_EXPORT even in local confederation */
190
191 /* Origins */
192
193 #define ORIGIN_IGP 0
194 #define ORIGIN_EGP 1
195 #define ORIGIN_INCOMPLETE 2
196
197 /* Address families */
198
199 #define BGP_AF_IPV6 2
200
201 #endif