Statistics
| Branch: | Revision:

iof-bird-daemon / proto / bgp / bgp.h @ 4847a894

History | View | Annotate | Download (7.84 KB)

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
  u32 rr_cluster_id;                        /* Route reflector cluster ID, if different from local ID */
29
  int rr_client;                        /* Whether neighbor is RR client of me */
30
  unsigned connect_retry_time;
31
  unsigned hold_time, initial_hold_time;
32
  unsigned keepalive_time;
33
  unsigned start_delay_time;                /* Minimum delay between connects */
34
  unsigned error_amnesia_time;                /* Errors are forgotten after */
35
  unsigned error_delay_time_min;        /* Time to wait after an error is detected */
36
  unsigned error_delay_time_max;
37
  unsigned disable_after_error;                /* Disable the protocol when error is detected */
38
  char *password;                        /* Password used for MD5 authentication */
39
};
40

    
41
struct bgp_conn {
42
  struct bgp_proto *bgp;
43
  struct birdsock *sk;
44
  unsigned int state;                        /* State of connection state machine */
45
  struct timer *connect_retry_timer;
46
  struct timer *hold_timer;
47
  struct timer *keepalive_timer;
48
  int packets_to_send;                        /* Bitmap of packet types to be sent */
49
  int notify_code, notify_subcode, notify_size;
50
  byte *notify_data;
51
  int error_flag;                        /* Error state, ignore all input */
52
  int primary;                                /* This connection is primary */
53
  u32 advertised_as;                        /* Temporary value for AS number received */
54
  unsigned hold_time, keepalive_time;        /* Times calculated from my and neighbor's requirements */
55
};
56

    
57
struct bgp_proto {
58
  struct proto p;
59
  struct bgp_config *cf;                /* Shortcut to BGP configuration */
60
  u32 local_as, remote_as;
61
  int is_internal;                        /* Internal BGP connection (local_as == remote_as) */
62
  int as4_support;                        /* Peer supports 4B AS numbers [RFC4893] */
63
  u32 local_id;                                /* BGP identifier of this router */
64
  u32 remote_id;                        /* BGP identifier of the neighbor */
65
  u32 rr_cluster_id;                        /* Route reflector cluster ID */
66
  int rr_client;                        /* Whether neighbor is RR client of me */
67
  struct bgp_conn *conn;                /* Connection we have established */
68
  struct bgp_conn outgoing_conn;        /* Outgoing connection we're working with */
69
  struct bgp_conn incoming_conn;        /* Incoming connection we have neither accepted nor rejected yet */
70
  struct object_lock *lock;                /* Lock for neighbor connection */
71
  ip_addr next_hop;                        /* Either the peer or multihop_via */
72
  struct neighbor *neigh;                /* Neighbor entry corresponding to next_hop */
73
  ip_addr local_addr;                        /* Address of the local end of the link to next_hop */
74
  struct bgp_bucket **bucket_hash;        /* Hash table of attribute buckets */
75
  unsigned int hash_size, hash_count, hash_limit;
76
  struct fib prefix_fib;                /* Prefixes to be sent */
77
  list bucket_queue;                        /* Queue of buckets to send */
78
  struct bgp_bucket *withdraw_bucket;        /* Withdrawn routes */
79
  unsigned startup_delay;                /* Time to delay protocol startup by due to errors */
80
  bird_clock_t last_connect;                /* Time of last connect attempt */
81
#ifdef IPV6
82
  byte *mp_reach_start, *mp_unreach_start; /* Multiprotocol BGP attribute notes */
83
  unsigned mp_reach_len, mp_unreach_len;
84
  ip_addr local_link;                        /* Link-level version of local_addr */
85
#endif
86
};
87

    
88
struct bgp_prefix {
89
  struct fib_node n;                        /* Node in prefix fib */
90
  node bucket_node;                        /* Node in per-bucket list */
91
};
92

    
93
struct bgp_bucket {
94
  node send_node;                        /* Node in send queue */
95
  struct bgp_bucket *hash_next, *hash_prev;        /* Node in bucket hash table */
96
  unsigned hash;                        /* Hash over extended attributes */
97
  list prefixes;                        /* Prefixes in this buckets */
98
  ea_list eattrs[0];                        /* Per-bucket extended attributes */
99
};
100

    
101
#define BGP_PORT                179
102
#define BGP_VERSION                4
103
#define BGP_HEADER_LENGTH        19
104
#define BGP_MAX_PACKET_LENGTH        4096
105
#define BGP_RX_BUFFER_SIZE        4096
106
#define BGP_TX_BUFFER_SIZE        BGP_MAX_PACKET_LENGTH
107

    
108
extern struct linpool *bgp_linpool;
109

    
110
extern int bgp_as4_support;
111

    
112

    
113
void bgp_start_timer(struct timer *t, int value);
114
void bgp_check(struct bgp_config *c);
115
void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len);
116
void bgp_close_conn(struct bgp_conn *c);
117

    
118
#ifdef LOCAL_DEBUG
119
#define BGP_FORCE_DEBUG 1
120
#else
121
#define BGP_FORCE_DEBUG 0
122
#endif
123
#define BGP_TRACE(flags, msg, args...) do { if ((p->p.debug & flags) || BGP_FORCE_DEBUG) \
124
        log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
125

    
126
/* attrs.c */
127

    
128
void bgp_attach_attr(struct ea_list **to, struct linpool *pool, unsigned attr, uintptr_t val);
129
byte *bgp_attach_attr_wa(struct ea_list **to, struct linpool *pool, unsigned attr, unsigned len);
130
struct rta *bgp_decode_attrs(struct bgp_conn *conn, byte *a, unsigned int len, struct linpool *pool, int mandatory);
131
int bgp_get_attr(struct eattr *e, byte *buf);
132
int bgp_rte_better(struct rte *, struct rte *);
133
void bgp_rt_notify(struct proto *, struct network *, struct rte *, struct rte *, struct ea_list *);
134
int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *);
135
void bgp_attr_init(struct bgp_proto *);
136
unsigned int bgp_encode_attrs(struct bgp_proto *p, byte *w, ea_list *attrs, int remains);
137
void bgp_free_bucket(struct bgp_proto *p, struct bgp_bucket *buck);
138
void bgp_get_route_info(struct rte *, byte *buf, struct ea_list *attrs);
139

    
140
inline static void bgp_attach_attr_ip(struct ea_list **to, struct linpool *pool, unsigned attr, ip_addr a)
141
{ *(ip_addr *) bgp_attach_attr_wa(to, pool, attr, sizeof(ip_addr)) = a; }
142

    
143
/* packets.c */
144

    
145
void bgp_schedule_packet(struct bgp_conn *conn, int type);
146
void bgp_tx(struct birdsock *sk);
147
int bgp_rx(struct birdsock *sk, int size);
148
void bgp_log_error(struct bgp_proto *p, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len);
149

    
150
/* Packet types */
151

    
152
#define PKT_OPEN                0x01
153
#define PKT_UPDATE                0x02
154
#define PKT_NOTIFICATION        0x03
155
#define PKT_KEEPALIVE                0x04
156
#define PKT_SCHEDULE_CLOSE        0x1f        /* Used internally to schedule socket close */
157

    
158
/* Attributes */
159

    
160
#define BAF_OPTIONAL                0x80
161
#define BAF_TRANSITIVE                0x40
162
#define BAF_PARTIAL                0x20
163
#define BAF_EXT_LEN                0x10
164

    
165
#define BA_ORIGIN                0x01        /* [RFC1771] */                /* WM */
166
#define BA_AS_PATH                0x02                                /* WM */
167
#define BA_NEXT_HOP                0x03                                /* WM */
168
#define BA_MULTI_EXIT_DISC        0x04                                /* ON */
169
#define BA_LOCAL_PREF                0x05                                /* WD */
170
#define BA_ATOMIC_AGGR                0x06                                /* WD */
171
#define BA_AGGREGATOR                0x07                                /* OT */
172
#define BA_COMMUNITY                0x08        /* [RFC1997] */                /* OT */
173
#define BA_ORIGINATOR_ID        0x09        /* [RFC1966] */                /* ON */
174
#define BA_CLUSTER_LIST                0x0a                                /* ON */
175
/* We don't support these: */
176
#define BA_DPA                        0x0b        /* ??? */
177
#define BA_ADVERTISER                0x0c        /* [RFC1863] */
178
#define BA_RCID_PATH                0x0d
179
#define BA_MP_REACH_NLRI        0x0e        /* [RFC2283] */
180
#define BA_MP_UNREACH_NLRI        0x0f
181
#define BA_EXTENDED_COMM        0x10        /* draft-ramachandra-bgp-ext-communities */
182
#define BA_AS4_PATH             0x11    /* [RFC4893] */
183
#define BA_AS4_AGGREGATOR       0x12
184

    
185
/* BGP states */
186

    
187
#define BS_IDLE                        0
188
#define BS_CONNECT                1        /* Attempting to connect */
189
#define BS_ACTIVE                2        /* Waiting for connection retry & listening */
190
#define BS_OPENSENT                3
191
#define BS_OPENCONFIRM                4
192
#define BS_ESTABLISHED                5
193

    
194
/* Well-known communities */
195

    
196
#define BGP_COMM_NO_EXPORT                0xffffff01        /* Don't export outside local AS / confed. */
197
#define BGP_COMM_NO_ADVERTISE                0xffffff02        /* Don't export at all */
198
#define BGP_COMM_NO_EXPORT_SUBCONFED        0xffffff03        /* NO_EXPORT even in local confederation */
199

    
200
/* Origins */
201

    
202
#define ORIGIN_IGP                0
203
#define ORIGIN_EGP                1
204
#define ORIGIN_INCOMPLETE        2
205

    
206
/* Address families */
207

    
208
#define BGP_AF_IPV6                2
209

    
210
#endif