]> git.ipfire.org Git - thirdparty/bird.git/blame - proto/bgp/bgp.h
Added as_path_get_first().
[thirdparty/bird.git] / proto / bgp / bgp.h
CommitLineData
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 14struct linpool;
10be74da 15struct eattr;
c00d31be 16
2638249d
MM
17struct bgp_config {
18 struct proto_config c;
19 unsigned int local_as, remote_as;
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 */
3fdbafb6
MM
28 unsigned connect_retry_time;
29 unsigned hold_time, initial_hold_time;
30 unsigned keepalive_time;
6fd766c1
MM
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 */
c01e3741
MM
36};
37
38struct bgp_conn {
39 struct bgp_proto *bgp;
40 struct birdsock *sk;
72a6ef11 41 unsigned int state; /* State of connection state machine */
c01e3741
MM
42 struct timer *connect_retry_timer;
43 struct timer *hold_timer;
44 struct timer *keepalive_timer;
3fdbafb6 45 int packets_to_send; /* Bitmap of packet types to be sent */
efcece2d
MM
46 int notify_code, notify_subcode, notify_size;
47 byte *notify_data;
3fdbafb6 48 int error_flag; /* Error state, ignore all input */
b552ecc4 49 int primary; /* This connection is primary */
3fdbafb6 50 unsigned hold_time, keepalive_time; /* Times calculated from my and neighbor's requirements */
2638249d
MM
51};
52
53struct bgp_proto {
54 struct proto p;
c01e3741 55 struct bgp_config *cf; /* Shortcut to BGP configuration */
3fdbafb6 56 unsigned local_as, remote_as;
c01e3741
MM
57 int is_internal; /* Internal BGP connection (local_as == remote_as) */
58 u32 local_id; /* BGP identifier of this router */
59 u32 remote_id; /* BGP identifier of the neighbor */
b552ecc4
MM
60 struct bgp_conn *conn; /* Connection we have established */
61 struct bgp_conn outgoing_conn; /* Outgoing connection we're working with */
c01e3741
MM
62 struct bgp_conn incoming_conn; /* Incoming connection we have neither accepted nor rejected yet */
63 struct object_lock *lock; /* Lock for neighbor connection */
48e842cc
MM
64 ip_addr next_hop; /* Either the peer or multihop_via */
65 struct neighbor *neigh; /* Neighbor entry corresponding to next_hop */
66 ip_addr local_addr; /* Address of the local end of the link to next_hop */
c2b28c99 67 struct bgp_bucket **bucket_hash; /* Hash table of attribute buckets */
ae8f5584 68 unsigned int hash_size, hash_count, hash_limit;
c2b28c99
MM
69 struct fib prefix_fib; /* Prefixes to be sent */
70 list bucket_queue; /* Queue of buckets to send */
71 struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */
6fd766c1
MM
72 unsigned startup_delay; /* Time to delay protocol startup by due to errors */
73 bird_clock_t last_connect; /* Time of last connect attempt */
1c1da87b
MM
74#ifdef IPV6
75 byte *mp_reach_start, *mp_unreach_start; /* Multiprotocol BGP attribute notes */
76 unsigned mp_reach_len, mp_unreach_len;
77#endif
c2b28c99
MM
78};
79
80struct bgp_prefix {
81 struct fib_node n; /* Node in prefix fib */
82 node bucket_node; /* Node in per-bucket list */
83};
84
85struct bgp_bucket {
c2b28c99 86 node send_node; /* Node in send queue */
f421cfdd 87 struct bgp_bucket *hash_next, *hash_prev; /* Node in bucket hash table */
c2b28c99
MM
88 unsigned hash; /* Hash over extended attributes */
89 list prefixes; /* Prefixes in this buckets */
90 ea_list eattrs[0]; /* Per-bucket extended attributes */
2638249d
MM
91};
92
72a6ef11
MM
93#define BGP_PORT 179
94#define BGP_VERSION 4
95#define BGP_HEADER_LENGTH 19
96#define BGP_MAX_PACKET_LENGTH 4096
97#define BGP_RX_BUFFER_SIZE 4096
98#define BGP_TX_BUFFER_SIZE BGP_MAX_PACKET_LENGTH
2638249d 99
973399ae
MM
100extern struct linpool *bgp_linpool;
101
3fdbafb6 102void bgp_start_timer(struct timer *t, int value);
2638249d 103void bgp_check(struct bgp_config *c);
efcece2d 104void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len);
b552ecc4 105void bgp_close_conn(struct bgp_conn *c);
2638249d 106
85368cd4
MM
107#ifdef LOCAL_DEBUG
108#define BGP_FORCE_DEBUG 1
109#else
110#define BGP_FORCE_DEBUG 0
111#endif
112#define BGP_TRACE(flags, msg, args...) do { if ((p->p.debug & flags) || BGP_FORCE_DEBUG) \
113 log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
114
c01e3741
MM
115/* attrs.c */
116
cf3d6470 117byte *bgp_attach_attr(struct ea_list **to, struct linpool *, unsigned attr, unsigned val);
2a9e064d 118struct rta *bgp_decode_attrs(struct bgp_conn *conn, byte *a, unsigned int len, struct linpool *pool, int mandatory);
10be74da 119int bgp_get_attr(struct eattr *e, byte *buf);
ef2c708d
MM
120int bgp_rte_better(struct rte *, struct rte *);
121void bgp_rt_notify(struct proto *, struct network *, struct rte *, struct rte *, struct ea_list *);
122int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *);
ae8f5584 123void bgp_attr_init(struct bgp_proto *);
cf3d6470 124unsigned int bgp_encode_attrs(byte *w, struct ea_list *attrs, int remains);
f421cfdd 125void bgp_free_bucket(struct bgp_proto *p, struct bgp_bucket *buck);
c00d31be 126
c01e3741
MM
127/* packets.c */
128
72a6ef11
MM
129void bgp_schedule_packet(struct bgp_conn *conn, int type);
130void bgp_tx(struct birdsock *sk);
131int bgp_rx(struct birdsock *sk, int size);
efcece2d 132void bgp_log_error(struct bgp_proto *p, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len);
72a6ef11 133
c01e3741
MM
134/* Packet types */
135
136#define PKT_OPEN 0x01
137#define PKT_UPDATE 0x02
138#define PKT_NOTIFICATION 0x03
139#define PKT_KEEPALIVE 0x04
72a6ef11 140#define PKT_SCHEDULE_CLOSE 0x1f /* Used internally to schedule socket close */
c01e3741
MM
141
142/* Attributes */
143
144#define BAF_OPTIONAL 0x80
145#define BAF_TRANSITIVE 0x40
146#define BAF_PARTIAL 0x20
147#define BAF_EXT_LEN 0x10
148
149#define BA_ORIGIN 0x01 /* [RFC1771] */ /* WM */
150#define BA_AS_PATH 0x02 /* WM */
151#define BA_NEXT_HOP 0x03 /* WM */
152#define BA_MULTI_EXIT_DISC 0x04 /* ON */
c00d31be 153#define BA_LOCAL_PREF 0x05 /* WD */
c01e3741
MM
154#define BA_ATOMIC_AGGR 0x06 /* WD */
155#define BA_AGGREGATOR 0x07 /* OT */
156#define BA_COMMUNITY 0x08 /* [RFC1997] */ /* OT */
157#define BA_ORIGINATOR_ID 0x09 /* [RFC1966] */ /* ON */
158#define BA_CLUSTER_LIST 0x0a /* ON */
159/* We don't support these: */
160#define BA_DPA 0x0b /* ??? */
161#define BA_ADVERTISER 0x0c /* [RFC1863] */
162#define BA_RCID_PATH 0x0d
163#define BA_MP_REACH_NLRI 0x0e /* [RFC2283] */
164#define BA_MP_UNREACH_NLRI 0x0f
165#define BA_EXTENDED_COMM 0x10 /* draft-ramachandra-bgp-ext-communities */
166
167/* BGP states */
168
169#define BS_IDLE 0
170#define BS_CONNECT 1 /* Attempting to connect */
171#define BS_ACTIVE 2 /* Waiting for connection retry & listening */
172#define BS_OPENSENT 3
173#define BS_OPENCONFIRM 4
174#define BS_ESTABLISHED 5
175
bd2d8190
MM
176/* Well-known communities */
177
178#define BGP_COMM_NO_EXPORT 0xffffff01 /* Don't export outside local AS / confed. */
179#define BGP_COMM_NO_ADVERTISE 0xffffff02 /* Don't export at all */
180#define BGP_COMM_NO_EXPORT_SUBCONFED 0xffffff03 /* NO_EXPORT even in local confederation */
181
cea63664
MM
182/* Origins */
183
184#define ORIGIN_IGP 0
185#define ORIGIN_EGP 1
186#define ORIGIN_INCOMPLETE 2
187
1c1da87b
MM
188/* Address families */
189
190#define BGP_AF_IPV6 2
191
2638249d 192#endif