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