Statistics
| Branch: | Revision:

iof-bird-daemon / proto / bgp / bgp.h @ 56a2bed4

History | View | Annotate | Download (5.4 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
  unsigned int 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
  int next_hop_self;                        /* Always set next hop to local IP address */
24
  int compare_path_lengths;                /* Use path lengths when selecting best route */
25
  u32 default_local_pref;                /* Default value for LOCAL_PREF attribute */
26
  u32 default_med;                        /* Default value for MULTI_EXIT_DISC attribute */
27
  unsigned connect_retry_time;
28
  unsigned hold_time, initial_hold_time;
29
  unsigned keepalive_time;
30
};
31

    
32
struct bgp_conn {
33
  struct bgp_proto *bgp;
34
  struct birdsock *sk;
35
  unsigned int state;                        /* State of connection state machine */
36
  struct timer *connect_retry_timer;
37
  struct timer *hold_timer;
38
  struct timer *keepalive_timer;
39
  int packets_to_send;                        /* Bitmap of packet types to be sent */
40
  int notify_code, notify_subcode, notify_arg, notify_arg_size;
41
  int error_flag;                        /* Error state, ignore all input */
42
  int primary;                                /* This connection is primary */
43
  unsigned hold_time, keepalive_time;        /* Times calculated from my and neighbor's requirements */
44
};
45

    
46
struct bgp_proto {
47
  struct proto p;
48
  struct bgp_config *cf;                /* Shortcut to BGP configuration */
49
  node bgp_node;                        /* Node in global BGP protocol list */
50
  unsigned local_as, remote_as;
51
  int is_internal;                        /* Internal BGP connection (local_as == remote_as) */
52
  u32 local_id;                                /* BGP identifier of this router */
53
  u32 remote_id;                        /* BGP identifier of the neighbor */
54
  struct bgp_conn *conn;                /* Connection we have established */
55
  struct bgp_conn outgoing_conn;        /* Outgoing connection we're working with */
56
  struct bgp_conn incoming_conn;        /* Incoming connection we have neither accepted nor rejected yet */
57
  struct object_lock *lock;                /* Lock for neighbor connection */
58
  ip_addr next_hop;                        /* Either the peer or multihop_via */
59
  struct neighbor *neigh;                /* Neighbor entry corresponding to next_hop */
60
  ip_addr local_addr;                        /* Address of the local end of the link to next_hop */
61
  struct bgp_bucket **bucket_hash;        /* Hash table of attribute buckets */
62
  unsigned int hash_size, hash_count, hash_limit;
63
  struct fib prefix_fib;                /* Prefixes to be sent */
64
  list bucket_queue;                        /* Queue of buckets to send */
65
  struct bgp_bucket *withdraw_bucket;        /* Withdrawn routes */
66
};
67

    
68
struct bgp_prefix {
69
  struct fib_node n;                        /* Node in prefix fib */
70
  node bucket_node;                        /* Node in per-bucket list */
71
};
72

    
73
struct bgp_bucket {
74
  node send_node;                        /* Node in send queue */
75
  struct bgp_bucket *hash_next, *hash_prev;        /* Node in bucket hash table */
76
  unsigned hash;                        /* Hash over extended attributes */
77
  list prefixes;                        /* Prefixes in this buckets */
78
  ea_list eattrs[0];                        /* Per-bucket extended attributes */
79
};
80

    
81
#define BGP_PORT                179
82
#define BGP_VERSION                4
83
#define BGP_HEADER_LENGTH        19
84
#define BGP_MAX_PACKET_LENGTH        4096
85
#define BGP_RX_BUFFER_SIZE        4096
86
#define BGP_TX_BUFFER_SIZE        BGP_MAX_PACKET_LENGTH
87

    
88
extern struct linpool *bgp_linpool;
89

    
90
void bgp_start_timer(struct timer *t, int value);
91
void bgp_check(struct bgp_config *c);
92
void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, unsigned data, unsigned len);
93
void bgp_close_conn(struct bgp_conn *c);
94

    
95
/* attrs.c */
96

    
97
struct rta *bgp_decode_attrs(struct bgp_conn *conn, byte *a, unsigned int len, struct linpool *pool);
98
int bgp_get_attr(struct eattr *e, byte *buf);
99
int bgp_rte_better(struct rte *, struct rte *);
100
void bgp_rt_notify(struct proto *, struct network *, struct rte *, struct rte *, struct ea_list *);
101
int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *);
102
void bgp_attr_init(struct bgp_proto *);
103
byte *bgp_encode_attrs(byte *w, struct bgp_bucket *buck);
104
void bgp_free_bucket(struct bgp_proto *p, struct bgp_bucket *buck);
105

    
106
/* packets.c */
107

    
108
void bgp_schedule_packet(struct bgp_conn *conn, int type);
109
void bgp_tx(struct birdsock *sk);
110
int bgp_rx(struct birdsock *sk, int size);
111

    
112
/* Packet types */
113

    
114
#define PKT_OPEN                0x01
115
#define PKT_UPDATE                0x02
116
#define PKT_NOTIFICATION        0x03
117
#define PKT_KEEPALIVE                0x04
118
#define PKT_SCHEDULE_CLOSE        0x1f        /* Used internally to schedule socket close */
119

    
120
/* Attributes */
121

    
122
#define BAF_OPTIONAL                0x80
123
#define BAF_TRANSITIVE                0x40
124
#define BAF_PARTIAL                0x20
125
#define BAF_EXT_LEN                0x10
126

    
127
#define BA_ORIGIN                0x01        /* [RFC1771] */                /* WM */
128
#define BA_AS_PATH                0x02                                /* WM */
129
#define BA_NEXT_HOP                0x03                                /* WM */
130
#define BA_MULTI_EXIT_DISC        0x04                                /* ON */
131
#define BA_LOCAL_PREF                0x05                                /* WD */
132
#define BA_ATOMIC_AGGR                0x06                                /* WD */
133
#define BA_AGGREGATOR                0x07                                /* OT */
134
#define BA_COMMUNITY                0x08        /* [RFC1997] */                /* OT */
135
#define BA_ORIGINATOR_ID        0x09        /* [RFC1966] */                /* ON */
136
#define BA_CLUSTER_LIST                0x0a                                /* ON */
137
/* We don't support these: */
138
#define BA_DPA                        0x0b        /* ??? */
139
#define BA_ADVERTISER                0x0c        /* [RFC1863] */
140
#define BA_RCID_PATH                0x0d
141
#define BA_MP_REACH_NLRI        0x0e        /* [RFC2283] */
142
#define BA_MP_UNREACH_NLRI        0x0f
143
#define BA_EXTENDED_COMM        0x10        /* draft-ramachandra-bgp-ext-communities */
144

    
145
/* BGP states */
146

    
147
#define BS_IDLE                        0
148
#define BS_CONNECT                1        /* Attempting to connect */
149
#define BS_ACTIVE                2        /* Waiting for connection retry & listening */
150
#define BS_OPENSENT                3
151
#define BS_OPENCONFIRM                4
152
#define BS_ESTABLISHED                5
153

    
154
#endif