2 * BIRD -- The Border Gateway Protocol
4 * (c) 2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
12 #include "nest/route.h"
18 struct proto_config c
;
19 u32 local_as
, remote_as
;
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 int enable_as4
; /* Enable local support for 4B AS numbers [RFC4893] */
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 */
31 int rs_client
; /* Whether neighbor is RS client of me */
32 unsigned connect_retry_time
;
33 unsigned hold_time
, initial_hold_time
;
34 unsigned keepalive_time
;
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 */
40 char *password
; /* Password used for MD5 authentication */
44 struct bgp_proto
*bgp
;
46 unsigned int state
; /* State of connection state machine */
47 struct timer
*connect_retry_timer
;
48 struct timer
*hold_timer
;
49 struct timer
*keepalive_timer
;
50 int packets_to_send
; /* Bitmap of packet types to be sent */
51 int notify_code
, notify_subcode
, notify_size
;
53 int error_flag
; /* Error state, ignore all input */
54 int primary
; /* This connection is primary */
55 u32 advertised_as
; /* Temporary value for AS number received */
56 unsigned hold_time
, keepalive_time
; /* Times calculated from my and neighbor's requirements */
61 struct bgp_config
*cf
; /* Shortcut to BGP configuration */
62 u32 local_as
, remote_as
;
63 int is_internal
; /* Internal BGP connection (local_as == remote_as) */
64 int as4_support
; /* Peer supports 4B AS numbers [RFC4893] */
65 int as4_session
; /* Session uses 4B AS numbers in AS_PATH (both sides support it) */
66 u32 local_id
; /* BGP identifier of this router */
67 u32 remote_id
; /* BGP identifier of the neighbor */
68 u32 rr_cluster_id
; /* Route reflector cluster ID */
69 int rr_client
; /* Whether neighbor is RR client of me */
70 int rs_client
; /* Whether neighbor is RS client of me */
71 struct bgp_conn
*conn
; /* Connection we have established */
72 struct bgp_conn outgoing_conn
; /* Outgoing connection we're working with */
73 struct bgp_conn incoming_conn
; /* Incoming connection we have neither accepted nor rejected yet */
74 struct object_lock
*lock
; /* Lock for neighbor connection */
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 */
78 struct bgp_bucket
**bucket_hash
; /* Hash table of attribute buckets */
79 unsigned int hash_size
, hash_count
, hash_limit
;
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 */
83 unsigned startup_delay
; /* Time to delay protocol startup by due to errors */
84 bird_clock_t last_connect
; /* Time of last connect attempt */
86 byte
*mp_reach_start
, *mp_unreach_start
; /* Multiprotocol BGP attribute notes */
87 unsigned mp_reach_len
, mp_unreach_len
;
88 ip_addr local_link
; /* Link-level version of local_addr */
93 struct fib_node n
; /* Node in prefix fib */
94 node bucket_node
; /* Node in per-bucket list */
98 node send_node
; /* Node in send queue */
99 struct bgp_bucket
*hash_next
, *hash_prev
; /* Node in bucket hash table */
100 unsigned hash
; /* Hash over extended attributes */
101 list prefixes
; /* Prefixes in this buckets */
102 ea_list eattrs
[0]; /* Per-bucket extended attributes */
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
112 extern struct linpool
*bgp_linpool
;
114 extern int bgp_as4_support
;
117 void bgp_start_timer(struct timer
*t
, int value
);
118 void bgp_check(struct bgp_config
*c
);
119 void bgp_error(struct bgp_conn
*c
, unsigned code
, unsigned subcode
, byte
*data
, int len
);
120 void bgp_close_conn(struct bgp_conn
*c
);
123 #define BGP_FORCE_DEBUG 1
125 #define BGP_FORCE_DEBUG 0
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)
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
);
134 struct rta
*bgp_decode_attrs(struct bgp_conn
*conn
, byte
*a
, unsigned int len
, struct linpool
*pool
, int mandatory
);
135 int bgp_get_attr(struct eattr
*e
, byte
*buf
, int buflen
);
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
*);
139 void bgp_attr_init(struct bgp_proto
*);
140 unsigned int bgp_encode_attrs(struct bgp_proto
*p
, byte
*w
, ea_list
*attrs
, int remains
);
141 void bgp_free_bucket(struct bgp_proto
*p
, struct bgp_bucket
*buck
);
142 void bgp_get_route_info(struct rte
*, byte
*buf
, struct ea_list
*attrs
);
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
; }
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
);
152 void bgp_log_error(struct bgp_proto
*p
, char *msg
, unsigned code
, unsigned subcode
, byte
*data
, unsigned len
);
156 #define PKT_OPEN 0x01
157 #define PKT_UPDATE 0x02
158 #define PKT_NOTIFICATION 0x03
159 #define PKT_KEEPALIVE 0x04
160 #define PKT_SCHEDULE_CLOSE 0x1f /* Used internally to schedule socket close */
164 #define BAF_OPTIONAL 0x80
165 #define BAF_TRANSITIVE 0x40
166 #define BAF_PARTIAL 0x20
167 #define BAF_EXT_LEN 0x10
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 */
173 #define BA_LOCAL_PREF 0x05 /* WD */
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 */
186 #define BA_AS4_PATH 0x11 /* [RFC4893] */
187 #define BA_AS4_AGGREGATOR 0x12
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
198 /* Well-known communities */
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 */
208 #define ORIGIN_INCOMPLETE 2
210 /* Address families */
212 #define BGP_AF_IPV6 2