2 /* $Id: bgp.h,v 1.5 2005/06/04 15:42:35 bodea Exp $ */
7 #define BGP_MAX_PACKET_SIZE 4096
8 #define BGP_HOLD_TIME 180 /* seconds before peer times us out */
9 #define BGP_KEEPALIVE_TIME 60 /* seconds between messages */
10 #define BGP_STATE_TIME 60 /* state transition timeout in seconds */
11 #define BGP_MAX_RETRY 42 /* maximum number of times to retry */
12 #define BGP_RETRY_BACKOFF 60 /* number of seconds between retries,
15 #define BGP_METRIC 1 /* multi_exit_disc */
16 #define BGP_LOCAL_PREF 100 /* local preference value */
22 } __attribute__ ((packed
));
25 #define BGP_MSG_OPEN 1
26 #define BGP_MSG_UPDATE 2
27 #define BGP_MSG_NOTIFICATION 3
28 #define BGP_MSG_KEEPALIVE 4
31 struct bgp_header header
;
32 char data
[BGP_MAX_PACKET_SIZE
- sizeof(struct bgp_header
)]; /* variable */
33 } __attribute__ ((packed
));
35 struct bgp_data_open
{
42 #define BGP_DATA_OPEN_SIZE 10 /* size of struct excluding opt_params */
43 char opt_params
[sizeof(((struct bgp_packet
*)0)->data
) - BGP_DATA_OPEN_SIZE
]; /* variable */
44 } __attribute__ ((packed
));
46 struct bgp_opt_param
{
49 #define BGP_MAX_OPT_PARAM_SIZE 256
50 char value
[BGP_MAX_OPT_PARAM_SIZE
];
51 } __attribute__ ((packed
));
53 #define BGP_PARAM_TYPE_CAPABILITY 2
54 struct bgp_capability
{
57 #define BGP_MAX_CAPABILITY_SIZE 256
58 char value
[BGP_MAX_CAPABILITY_SIZE
];
59 } __attribute__ ((packed
));
61 /* RFC4760 Multiprotocol extension */
62 #define BGP_CAP_CODE_MP 1
64 struct bgp_mp_cap_param
{
65 uint16_t afi
; /* sa_family_t */
66 uint8_t reserved
; /* SHOULD be 0 */
68 } __attribute__ ((packed
));
70 /* bgp_mp_cap_param.safi */
71 #define BGP_MP_SAFI_UNICAST 1
72 #define BGP_MP_SAFI_MULTICAST 2
74 struct bgp_ip_prefix
{
76 uint32_t prefix
; /* variable */
77 } __attribute__ ((packed
));
79 #define BGP_IP_PREFIX_SIZE(p) (1 + ((p).len / 8) + ((p).len % 8 != 0))
81 struct bgp_path_attr
{
87 char value
[29]; /* semi-random size, adequate for l2tpns */
88 } __attribute__ ((packed
)) s
; /* short */
92 } __attribute__ ((packed
)) e
; /* extended */
93 } data
; /* variable */
94 } __attribute__ ((packed
));
96 /* bgp_path_attr.flags (bitfields) */
97 #define BGP_PATH_ATTR_FLAG_OPTIONAL (1 << 7)
98 #define BGP_PATH_ATTR_FLAG_TRANS (1 << 6)
99 #define BGP_PATH_ATTR_FLAG_PARTIAL (1 << 5)
100 #define BGP_PATH_ATTR_FLAG_EXTLEN (1 << 4)
102 /* bgp_path_attr.code, ...value */
103 #define BGP_PATH_ATTR_CODE_ORIGIN 1 /* well-known, mandatory */
104 # define BGP_PATH_ATTR_CODE_ORIGIN_IGP 0
105 # define BGP_PATH_ATTR_CODE_ORIGIN_EGP 1
106 # define BGP_PATH_ATTR_CODE_ORIGIN_INCOMPLETE 2
107 #define BGP_PATH_ATTR_CODE_AS_PATH 2 /* well-known, mandatory */
108 # define BGP_PATH_ATTR_CODE_AS_PATH_AS_SET 1
109 # define BGP_PATH_ATTR_CODE_AS_PATH_AS_SEQUENCE 2
110 #define BGP_PATH_ATTR_CODE_NEXT_HOP 3 /* well-known, mandatory */
111 #define BGP_PATH_ATTR_CODE_MULTI_EXIT_DISC 4 /* optional, non-transitive */
112 #define BGP_PATH_ATTR_CODE_LOCAL_PREF 5 /* well-known, discretionary */
113 #define BGP_PATH_ATTR_CODE_ATOMIC_AGGREGATE 6 /* well-known, discretionary */
114 #define BGP_PATH_ATTR_CODE_AGGREGATOR 7 /* optional, transitive */
115 #define BGP_PATH_ATTR_CODE_COMMUNITIES 8 /* optional, transitive (RFC1997) */
117 #define BGP_PATH_ATTR_SIZE(p) ((((p).flags & BGP_PATH_ATTR_FLAG_EXTLEN) \
118 ? ((p).data.e.len + 1) : (p).data.s.len) + 3)
120 /* well known COMMUNITIES */
121 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01 /* don't advertise outside confederation */
122 #define BGP_COMMUNITY_NO_ADVERTISE 0xffffff02 /* don't advertise to any peer */
123 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 /* don't advertise to any other AS */
125 struct bgp_data_notification
{
127 uint8_t error_subcode
;
128 char data
[sizeof(((struct bgp_packet
*)0)->data
) - 2]; /* variable */
129 } __attribute__ ((packed
));
131 /* bgp_data_notification.error_code, .error_subcode */
132 #define BGP_ERR_UNSPEC 0
133 #define BGP_ERR_HEADER 1
134 # define BGP_ERR_HDR_NOT_SYNC 1
135 # define BGP_ERR_HDR_BAD_LEN 2
136 # define BGP_ERR_HDR_BAD_TYPE 3
137 #define BGP_ERR_OPEN 2
138 # define BGP_ERR_OPN_VERSION 1
139 # define BGP_ERR_OPN_BAD_AS 2
140 # define BGP_ERR_OPN_BAD_IDENT 3
141 # define BGP_ERR_OPN_UNSUP_PARAM 4
142 # define BGP_ERR_OPN_AUTH_FAILURE 5
143 # define BGP_ERR_OPN_HOLD_TIME 6
144 # define BGP_ERR_OPN_UNSUP_CAP 7
145 #define BGP_ERR_UPDATE 3
146 # define BGP_ERR_UPD_BAD_ATTR_LIST 1
147 # define BGP_ERR_UPD_UNKN_WK_ATTR 2
148 # define BGP_ERR_UPD_MISS_WK_ATTR 3
149 # define BGP_ERR_UPD_BAD_ATTR_FLAG 4
150 # define BGP_ERR_UPD_BAD_ATTR_LEN 5
151 # define BGP_ERR_UPD_BAD_ORIGIN 6
152 # define BGP_ERR_UPD_ROUTING_LOOP 7
153 # define BGP_ERR_UPD_BAD_NEXT_HOP 8
154 # define BGP_ERR_UPD_BAD_OPT_ATTR 9
155 # define BGP_ERR_UPD_BAD_NETWORK 10
156 # define BGP_ERR_UPD_BAD_AS_PATH 11
157 #define BGP_ERR_HOLD_TIMER_EXP 4
158 #define BGP_ERR_FSM 5
159 #define BGP_ERR_CEASE 6
162 Disabled
, /* initial, or failed */
163 Idle
, /* trying to connect */
164 Connect
, /* connect issued */
165 Active
, /* connected, waiting to send OPEN */
166 OpenSent
, /* OPEN sent, waiting for peer OPEN */
167 OpenConfirm
, /* KEEPALIVE sent, waiting for peer KEEPALIVE */
168 Established
, /* established */
171 struct bgp_route_list
{
172 struct bgp_ip_prefix dest
;
173 struct bgp_route_list
*next
;
177 struct bgp_packet packet
; /* BGP packet */
178 size_t done
; /* bytes sent/recvd */
183 char name
[32]; /* peer name */
184 in_addr_t addr
; /* peer address */
185 int as
; /* AS number */
187 enum bgp_state state
; /* FSM state */
188 enum bgp_state next_state
; /* next state after outbuf cleared */
189 time_t state_time
; /* time of last state change */
190 time_t keepalive_time
; /* time to send next keepalive */
191 time_t retry_time
; /* time for connection retry */
192 int retry_count
; /* connection retry count */
193 int init_keepalive
; /* initial keepalive time */
194 int init_hold
; /* initial hold time */
195 int keepalive
; /* negotiated keepalive time */
196 int hold
; /* negotiated hold time */
197 time_t expire_time
; /* time next peer packet expected */
198 int routing
; /* propagate routes */
199 int update_routes
; /* UPDATE required */
200 struct bgp_route_list
*routes
; /* routes known by this peer */
201 struct bgp_buf
*outbuf
; /* pending output */
202 struct bgp_buf
*inbuf
; /* pending input */
203 int cli_flag
; /* updates requested from CLI */
204 char *path_attrs
; /* path attrs to send in UPDATE message */
205 int path_attr_len
; /* length of path attrs */
206 int path_attr_len_without_nexthop
; /* length of path attrs without NEXT_HOP */
207 uint32_t events
; /* events to poll */
208 struct event_data edata
; /* poll data */
209 int handle_ipv6_routes
; /* can handle IPv6 routes advertisements */
212 /* bgp_peer.cli_flag */
213 #define BGP_CLI_SUSPEND 1
214 #define BGP_CLI_ENABLE 2
215 #define BGP_CLI_RESTART 3
217 extern struct bgp_peer
*bgp_peers
;
218 extern int bgp_configured
;
221 int bgp_setup(int as
);
222 int bgp_start(struct bgp_peer
*peer
, char *name
, int as
, int keepalive
,
223 int hold
, int enable
);
225 void bgp_stop(struct bgp_peer
*peer
);
226 void bgp_halt(struct bgp_peer
*peer
);
227 int bgp_restart(struct bgp_peer
*peer
);
228 int bgp_add_route(in_addr_t ip
, in_addr_t mask
);
229 int bgp_del_route(in_addr_t ip
, in_addr_t mask
);
230 void bgp_enable_routing(int enable
);
231 int bgp_set_poll(void);
232 int bgp_process(uint32_t events
[]);
233 char const *bgp_state_str(enum bgp_state state
);
235 extern char const *cvs_id_bgp
;
237 #endif /* __BGP_H__ */