]>
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; | |
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 */ |
48e842cc | 23 | int next_hop_self; /* Always set next hop to local IP address */ |
3fdbafb6 MM |
24 | unsigned connect_retry_time; |
25 | unsigned hold_time, initial_hold_time; | |
26 | unsigned keepalive_time; | |
c01e3741 MM |
27 | }; |
28 | ||
29 | struct bgp_conn { | |
30 | struct bgp_proto *bgp; | |
31 | struct birdsock *sk; | |
72a6ef11 | 32 | unsigned int state; /* State of connection state machine */ |
c01e3741 MM |
33 | struct timer *connect_retry_timer; |
34 | struct timer *hold_timer; | |
35 | struct timer *keepalive_timer; | |
3fdbafb6 MM |
36 | int packets_to_send; /* Bitmap of packet types to be sent */ |
37 | int notify_code, notify_subcode, notify_arg, notify_arg_size; | |
38 | int error_flag; /* Error state, ignore all input */ | |
b552ecc4 | 39 | int primary; /* This connection is primary */ |
3fdbafb6 | 40 | unsigned hold_time, keepalive_time; /* Times calculated from my and neighbor's requirements */ |
2638249d MM |
41 | }; |
42 | ||
43 | struct bgp_proto { | |
44 | struct proto p; | |
c01e3741 MM |
45 | struct bgp_config *cf; /* Shortcut to BGP configuration */ |
46 | node bgp_node; /* Node in global BGP protocol list */ | |
3fdbafb6 | 47 | unsigned local_as, remote_as; |
c01e3741 MM |
48 | int is_internal; /* Internal BGP connection (local_as == remote_as) */ |
49 | u32 local_id; /* BGP identifier of this router */ | |
50 | u32 remote_id; /* BGP identifier of the neighbor */ | |
b552ecc4 MM |
51 | struct bgp_conn *conn; /* Connection we have established */ |
52 | struct bgp_conn outgoing_conn; /* Outgoing connection we're working with */ | |
c01e3741 MM |
53 | struct bgp_conn incoming_conn; /* Incoming connection we have neither accepted nor rejected yet */ |
54 | struct object_lock *lock; /* Lock for neighbor connection */ | |
48e842cc MM |
55 | ip_addr next_hop; /* Either the peer or multihop_via */ |
56 | struct neighbor *neigh; /* Neighbor entry corresponding to next_hop */ | |
57 | ip_addr local_addr; /* Address of the local end of the link to next_hop */ | |
c2b28c99 | 58 | struct bgp_bucket **bucket_hash; /* Hash table of attribute buckets */ |
ae8f5584 | 59 | unsigned int hash_size, hash_count, hash_limit; |
c2b28c99 MM |
60 | struct fib prefix_fib; /* Prefixes to be sent */ |
61 | list bucket_queue; /* Queue of buckets to send */ | |
62 | struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */ | |
63 | }; | |
64 | ||
65 | struct bgp_prefix { | |
66 | struct fib_node n; /* Node in prefix fib */ | |
67 | node bucket_node; /* Node in per-bucket list */ | |
68 | }; | |
69 | ||
70 | struct bgp_bucket { | |
71 | struct bgp_bucket *hash_next, *hash_prev; /* Node in bucket hash table */ | |
72 | node send_node; /* Node in send queue */ | |
73 | unsigned hash; /* Hash over extended attributes */ | |
74 | list prefixes; /* Prefixes in this buckets */ | |
75 | ea_list eattrs[0]; /* Per-bucket extended attributes */ | |
2638249d MM |
76 | }; |
77 | ||
72a6ef11 MM |
78 | #define BGP_PORT 179 |
79 | #define BGP_VERSION 4 | |
80 | #define BGP_HEADER_LENGTH 19 | |
81 | #define BGP_MAX_PACKET_LENGTH 4096 | |
82 | #define BGP_RX_BUFFER_SIZE 4096 | |
83 | #define BGP_TX_BUFFER_SIZE BGP_MAX_PACKET_LENGTH | |
2638249d | 84 | |
973399ae MM |
85 | extern struct linpool *bgp_linpool; |
86 | ||
3fdbafb6 | 87 | void bgp_start_timer(struct timer *t, int value); |
2638249d | 88 | void bgp_check(struct bgp_config *c); |
3fdbafb6 | 89 | void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, unsigned data, unsigned len); |
b552ecc4 | 90 | void bgp_close_conn(struct bgp_conn *c); |
2638249d | 91 | |
c01e3741 MM |
92 | /* attrs.c */ |
93 | ||
c00d31be | 94 | struct rta *bgp_decode_attrs(struct bgp_conn *conn, byte *a, unsigned int len, struct linpool *pool); |
10be74da | 95 | int bgp_get_attr(struct eattr *e, byte *buf); |
ef2c708d MM |
96 | int bgp_rte_better(struct rte *, struct rte *); |
97 | void bgp_rt_notify(struct proto *, struct network *, struct rte *, struct rte *, struct ea_list *); | |
98 | int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *); | |
ae8f5584 | 99 | void bgp_attr_init(struct bgp_proto *); |
c00d31be | 100 | |
c01e3741 MM |
101 | /* packets.c */ |
102 | ||
72a6ef11 MM |
103 | void bgp_schedule_packet(struct bgp_conn *conn, int type); |
104 | void bgp_tx(struct birdsock *sk); | |
105 | int bgp_rx(struct birdsock *sk, int size); | |
106 | ||
c01e3741 MM |
107 | /* Packet types */ |
108 | ||
109 | #define PKT_OPEN 0x01 | |
110 | #define PKT_UPDATE 0x02 | |
111 | #define PKT_NOTIFICATION 0x03 | |
112 | #define PKT_KEEPALIVE 0x04 | |
72a6ef11 | 113 | #define PKT_SCHEDULE_CLOSE 0x1f /* Used internally to schedule socket close */ |
c01e3741 MM |
114 | |
115 | /* Attributes */ | |
116 | ||
117 | #define BAF_OPTIONAL 0x80 | |
118 | #define BAF_TRANSITIVE 0x40 | |
119 | #define BAF_PARTIAL 0x20 | |
120 | #define BAF_EXT_LEN 0x10 | |
121 | ||
122 | #define BA_ORIGIN 0x01 /* [RFC1771] */ /* WM */ | |
123 | #define BA_AS_PATH 0x02 /* WM */ | |
124 | #define BA_NEXT_HOP 0x03 /* WM */ | |
125 | #define BA_MULTI_EXIT_DISC 0x04 /* ON */ | |
c00d31be | 126 | #define BA_LOCAL_PREF 0x05 /* WD */ |
c01e3741 MM |
127 | #define BA_ATOMIC_AGGR 0x06 /* WD */ |
128 | #define BA_AGGREGATOR 0x07 /* OT */ | |
129 | #define BA_COMMUNITY 0x08 /* [RFC1997] */ /* OT */ | |
130 | #define BA_ORIGINATOR_ID 0x09 /* [RFC1966] */ /* ON */ | |
131 | #define BA_CLUSTER_LIST 0x0a /* ON */ | |
132 | /* We don't support these: */ | |
133 | #define BA_DPA 0x0b /* ??? */ | |
134 | #define BA_ADVERTISER 0x0c /* [RFC1863] */ | |
135 | #define BA_RCID_PATH 0x0d | |
136 | #define BA_MP_REACH_NLRI 0x0e /* [RFC2283] */ | |
137 | #define BA_MP_UNREACH_NLRI 0x0f | |
138 | #define BA_EXTENDED_COMM 0x10 /* draft-ramachandra-bgp-ext-communities */ | |
139 | ||
c00d31be MM |
140 | #define BGP_PATH_AS_SET 1 /* Types of path segments */ |
141 | #define BGP_PATH_AS_SEQUENCE 2 | |
142 | ||
c01e3741 MM |
143 | /* BGP states */ |
144 | ||
145 | #define BS_IDLE 0 | |
146 | #define BS_CONNECT 1 /* Attempting to connect */ | |
147 | #define BS_ACTIVE 2 /* Waiting for connection retry & listening */ | |
148 | #define BS_OPENSENT 3 | |
149 | #define BS_OPENCONFIRM 4 | |
150 | #define BS_ESTABLISHED 5 | |
151 | ||
2638249d | 152 | #endif |