]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/bgp/bgp.h
More BGP. This time it connects, but the state machine still isn't complete.
[thirdparty/bird.git] / proto / bgp / bgp.h
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 struct bgp_config {
13 struct proto_config c;
14 unsigned int local_as, remote_as;
15 ip_addr remote_ip;
16 int multihop; /* Number of hops if multihop */
17 unsigned connect_retry_time;
18 unsigned hold_time, initial_hold_time;
19 unsigned keepalive_time;
20 };
21
22 struct bgp_conn {
23 struct bgp_proto *bgp;
24 struct birdsock *sk;
25 unsigned int state; /* State of connection state machine */
26 struct timer *connect_retry_timer;
27 struct timer *hold_timer;
28 struct timer *keepalive_timer;
29 int packets_to_send; /* Bitmap of packet types to be sent */
30 int notify_code, notify_subcode, notify_arg, notify_arg_size;
31 int error_flag; /* Error state, ignore all input */
32 unsigned hold_time, keepalive_time; /* Times calculated from my and neighbor's requirements */
33 };
34
35 struct bgp_proto {
36 struct proto p;
37 struct bgp_config *cf; /* Shortcut to BGP configuration */
38 node bgp_node; /* Node in global BGP protocol list */
39 unsigned local_as, remote_as;
40 int is_internal; /* Internal BGP connection (local_as == remote_as) */
41 u32 local_id; /* BGP identifier of this router */
42 u32 remote_id; /* BGP identifier of the neighbor */
43 struct bgp_conn conn; /* Our primary connection */
44 struct bgp_conn incoming_conn; /* Incoming connection we have neither accepted nor rejected yet */
45 struct object_lock *lock; /* Lock for neighbor connection */
46 };
47
48 #define BGP_PORT 179
49 #define BGP_VERSION 4
50 #define BGP_HEADER_LENGTH 19
51 #define BGP_MAX_PACKET_LENGTH 4096
52 #define BGP_RX_BUFFER_SIZE 4096
53 #define BGP_TX_BUFFER_SIZE BGP_MAX_PACKET_LENGTH
54
55 void bgp_start_timer(struct timer *t, int value);
56 void bgp_check(struct bgp_config *c);
57 void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, unsigned data, unsigned len);
58 void bgp_close_conn(struct bgp_conn *conn);
59
60 /* attrs.c */
61
62 /* packets.c */
63
64 void bgp_schedule_packet(struct bgp_conn *conn, int type);
65 void bgp_tx(struct birdsock *sk);
66 int bgp_rx(struct birdsock *sk, int size);
67
68 /* Packet types */
69
70 #define PKT_OPEN 0x01
71 #define PKT_UPDATE 0x02
72 #define PKT_NOTIFICATION 0x03
73 #define PKT_KEEPALIVE 0x04
74 #define PKT_SCHEDULE_CLOSE 0x1f /* Used internally to schedule socket close */
75
76 /* Attributes */
77
78 #define BAF_OPTIONAL 0x80
79 #define BAF_TRANSITIVE 0x40
80 #define BAF_PARTIAL 0x20
81 #define BAF_EXT_LEN 0x10
82
83 #define BA_ORIGIN 0x01 /* [RFC1771] */ /* WM */
84 #define BA_AS_PATH 0x02 /* WM */
85 #define BA_NEXT_HOP 0x03 /* WM */
86 #define BA_MULTI_EXIT_DISC 0x04 /* ON */
87 #define BA_LOCAL_PREF 0x05 /* WM */
88 #define BA_ATOMIC_AGGR 0x06 /* WD */
89 #define BA_AGGREGATOR 0x07 /* OT */
90 #define BA_COMMUNITY 0x08 /* [RFC1997] */ /* OT */
91 #define BA_ORIGINATOR_ID 0x09 /* [RFC1966] */ /* ON */
92 #define BA_CLUSTER_LIST 0x0a /* ON */
93 /* We don't support these: */
94 #define BA_DPA 0x0b /* ??? */
95 #define BA_ADVERTISER 0x0c /* [RFC1863] */
96 #define BA_RCID_PATH 0x0d
97 #define BA_MP_REACH_NLRI 0x0e /* [RFC2283] */
98 #define BA_MP_UNREACH_NLRI 0x0f
99 #define BA_EXTENDED_COMM 0x10 /* draft-ramachandra-bgp-ext-communities */
100
101 /* BGP states */
102
103 #define BS_IDLE 0
104 #define BS_CONNECT 1 /* Attempting to connect */
105 #define BS_ACTIVE 2 /* Waiting for connection retry & listening */
106 #define BS_OPENSENT 3
107 #define BS_OPENCONFIRM 4
108 #define BS_ESTABLISHED 5
109
110 #endif