]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: ISC |
8429abe0 RW |
2 | /* $OpenBSD$ */ |
3 | ||
4 | /* | |
5 | * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org> | |
6 | * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> | |
7 | * Copyright (c) 2004 Esben Norby <norby@openbsd.org> | |
8 | * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> | |
8429abe0 RW |
9 | */ |
10 | ||
11 | #ifndef _LDPD_H_ | |
12 | #define _LDPD_H_ | |
13 | ||
cd85bc2e | 14 | #include "queue.h" |
eac6e3f0 RW |
15 | #include "openbsd-tree.h" |
16 | #include "imsg.h" | |
24a58196 | 17 | #include "frrevent.h" |
4af8997d | 18 | #include "qobj.h" |
26519d8c | 19 | #include "prefix.h" |
45a8eba9 | 20 | #include "filter.h" |
e4a82008 | 21 | #include "vty.h" |
6833ae01 | 22 | #include "pw.h" |
87b5f1b7 | 23 | #include "zclient.h" |
8429abe0 RW |
24 | |
25 | #include "ldp.h" | |
e1894ff7 | 26 | #include "lib/ldp_sync.h" |
8429abe0 RW |
27 | |
28 | #define CONF_FILE "/etc/ldpd.conf" | |
8429abe0 RW |
29 | #define LDPD_USER "_ldpd" |
30 | ||
28e8294c RW |
31 | #define LDPD_FD_ASYNC 3 |
32 | #define LDPD_FD_SYNC 4 | |
33 | ||
8429abe0 RW |
34 | #define LDPD_OPT_VERBOSE 0x00000001 |
35 | #define LDPD_OPT_VERBOSE2 0x00000002 | |
36 | #define LDPD_OPT_NOACTION 0x00000004 | |
37 | ||
38 | #define TCP_MD5_KEY_LEN 80 | |
8429abe0 RW |
39 | |
40 | #define RT_BUF_SIZE 16384 | |
41 | #define MAX_RTSOCK_BUF 128 * 1024 | |
42 | #define LDP_BACKLOG 128 | |
43 | ||
44 | #define F_LDPD_INSERTED 0x0001 | |
45 | #define F_CONNECTED 0x0002 | |
46 | #define F_STATIC 0x0004 | |
47 | #define F_DYNAMIC 0x0008 | |
48 | #define F_REJECT 0x0010 | |
49 | #define F_BLACKHOLE 0x0020 | |
50 | #define F_REDISTRIBUTED 0x0040 | |
51 | ||
52 | struct evbuf { | |
eac6e3f0 | 53 | struct msgbuf wbuf; |
e6685141 DS |
54 | struct event *ev; |
55 | void (*handler)(struct event *); | |
eac6e3f0 | 56 | void *arg; |
8429abe0 RW |
57 | }; |
58 | ||
59 | struct imsgev { | |
60 | struct imsgbuf ibuf; | |
e6685141 DS |
61 | void (*handler_write)(struct event *); |
62 | struct event *ev_write; | |
63 | void (*handler_read)(struct event *); | |
64 | struct event *ev_read; | |
8429abe0 RW |
65 | }; |
66 | ||
67 | enum imsg_type { | |
68 | IMSG_NONE, | |
69 | IMSG_CTL_RELOAD, | |
70 | IMSG_CTL_SHOW_INTERFACE, | |
71 | IMSG_CTL_SHOW_DISCOVERY, | |
bc0eb287 | 72 | IMSG_CTL_SHOW_DISCOVERY_DTL, |
eac6e3f0 RW |
73 | IMSG_CTL_SHOW_DISC_IFACE, |
74 | IMSG_CTL_SHOW_DISC_TNBR, | |
75 | IMSG_CTL_SHOW_DISC_ADJ, | |
8429abe0 | 76 | IMSG_CTL_SHOW_NBR, |
eac6e3f0 RW |
77 | IMSG_CTL_SHOW_NBR_DISC, |
78 | IMSG_CTL_SHOW_NBR_END, | |
8429abe0 | 79 | IMSG_CTL_SHOW_LIB, |
0f7b5df9 RW |
80 | IMSG_CTL_SHOW_LIB_BEGIN, |
81 | IMSG_CTL_SHOW_LIB_SENT, | |
82 | IMSG_CTL_SHOW_LIB_RCVD, | |
83 | IMSG_CTL_SHOW_LIB_END, | |
8429abe0 RW |
84 | IMSG_CTL_SHOW_L2VPN_PW, |
85 | IMSG_CTL_SHOW_L2VPN_BINDING, | |
e1894ff7 | 86 | IMSG_CTL_SHOW_LDP_SYNC, |
8429abe0 RW |
87 | IMSG_CTL_CLEAR_NBR, |
88 | IMSG_CTL_FIB_COUPLE, | |
89 | IMSG_CTL_FIB_DECOUPLE, | |
90 | IMSG_CTL_KROUTE, | |
91 | IMSG_CTL_KROUTE_ADDR, | |
92 | IMSG_CTL_IFINFO, | |
93 | IMSG_CTL_END, | |
94 | IMSG_CTL_LOG_VERBOSE, | |
95 | IMSG_KLABEL_CHANGE, | |
96 | IMSG_KLABEL_DELETE, | |
87b5f1b7 RW |
97 | IMSG_KPW_ADD, |
98 | IMSG_KPW_DELETE, | |
99 | IMSG_KPW_SET, | |
100 | IMSG_KPW_UNSET, | |
8429abe0 RW |
101 | IMSG_IFSTATUS, |
102 | IMSG_NEWADDR, | |
103 | IMSG_DELADDR, | |
eac6e3f0 | 104 | IMSG_RTRID_UPDATE, |
8429abe0 RW |
105 | IMSG_LABEL_MAPPING, |
106 | IMSG_LABEL_MAPPING_FULL, | |
107 | IMSG_LABEL_REQUEST, | |
108 | IMSG_LABEL_RELEASE, | |
109 | IMSG_LABEL_WITHDRAW, | |
110 | IMSG_LABEL_ABORT, | |
111 | IMSG_REQUEST_ADD, | |
112 | IMSG_REQUEST_ADD_END, | |
113 | IMSG_MAPPING_ADD, | |
114 | IMSG_MAPPING_ADD_END, | |
115 | IMSG_RELEASE_ADD, | |
116 | IMSG_RELEASE_ADD_END, | |
117 | IMSG_WITHDRAW_ADD, | |
118 | IMSG_WITHDRAW_ADD_END, | |
119 | IMSG_ADDRESS_ADD, | |
120 | IMSG_ADDRESS_DEL, | |
121 | IMSG_NOTIFICATION, | |
122 | IMSG_NOTIFICATION_SEND, | |
123 | IMSG_NEIGHBOR_UP, | |
124 | IMSG_NEIGHBOR_DOWN, | |
125 | IMSG_NETWORK_ADD, | |
8cb1fc45 | 126 | IMSG_NETWORK_UPDATE, |
8429abe0 RW |
127 | IMSG_SOCKET_IPC, |
128 | IMSG_SOCKET_NET, | |
129 | IMSG_CLOSE_SOCKETS, | |
130 | IMSG_REQUEST_SOCKETS, | |
131 | IMSG_SETUP_SOCKETS, | |
132 | IMSG_RECONF_CONF, | |
133 | IMSG_RECONF_IFACE, | |
134 | IMSG_RECONF_TNBR, | |
135 | IMSG_RECONF_NBRP, | |
136 | IMSG_RECONF_L2VPN, | |
137 | IMSG_RECONF_L2VPN_IF, | |
138 | IMSG_RECONF_L2VPN_PW, | |
eac6e3f0 RW |
139 | IMSG_RECONF_L2VPN_IPW, |
140 | IMSG_RECONF_END, | |
141 | IMSG_DEBUG_UPDATE, | |
45a8eba9 | 142 | IMSG_LOG, |
274f5abf | 143 | IMSG_ACL_CHECK, |
87b5f1b7 | 144 | IMSG_INIT, |
2d1aa1e8 | 145 | IMSG_PW_UPDATE, |
146 | IMSG_FILTER_UPDATE, | |
e1894ff7 KS |
147 | IMSG_NBR_SHUTDOWN, |
148 | IMSG_LDP_SYNC_IF_STATE_REQUEST, | |
077d336a RW |
149 | IMSG_LDP_SYNC_IF_STATE_UPDATE, |
150 | IMSG_RLFA_REG, | |
151 | IMSG_RLFA_UNREG_ALL, | |
152 | IMSG_RLFA_LABELS, | |
f9a4d683 | 153 | IMSG_AGENTX_ENABLED, |
274f5abf RW |
154 | }; |
155 | ||
156 | struct ldpd_init { | |
157 | char user[256]; | |
158 | char group[256]; | |
159 | char ctl_sock_path[MAXPATHLEN]; | |
160 | char zclient_serv_path[MAXPATHLEN]; | |
d7c0a89a | 161 | unsigned short instance; |
8429abe0 RW |
162 | }; |
163 | ||
2d1aa1e8 | 164 | struct ldp_access { |
165 | char name[ACL_NAMSIZ]; | |
2d1aa1e8 | 166 | }; |
167 | ||
8429abe0 RW |
168 | union ldpd_addr { |
169 | struct in_addr v4; | |
170 | struct in6_addr v6; | |
171 | }; | |
172 | ||
173 | #define IN6_IS_SCOPE_EMBED(a) \ | |
174 | ((IN6_IS_ADDR_LINKLOCAL(a)) || \ | |
175 | (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \ | |
176 | (IN6_IS_ADDR_MC_INTFACELOCAL(a))) | |
177 | ||
178 | /* interface states */ | |
179 | #define IF_STA_DOWN 0x01 | |
180 | #define IF_STA_ACTIVE 0x02 | |
181 | ||
182 | /* targeted neighbor states */ | |
183 | #define TNBR_STA_DOWN 0x01 | |
184 | #define TNBR_STA_ACTIVE 0x02 | |
185 | ||
186 | /* interface types */ | |
187 | enum iface_type { | |
188 | IF_TYPE_POINTOPOINT, | |
189 | IF_TYPE_BROADCAST | |
190 | }; | |
191 | ||
192 | /* neighbor states */ | |
193 | #define NBR_STA_PRESENT 0x0001 | |
194 | #define NBR_STA_INITIAL 0x0002 | |
195 | #define NBR_STA_OPENREC 0x0004 | |
196 | #define NBR_STA_OPENSENT 0x0008 | |
197 | #define NBR_STA_OPER 0x0010 | |
198 | #define NBR_STA_SESSION (NBR_STA_INITIAL | NBR_STA_OPENREC | \ | |
199 | NBR_STA_OPENSENT | NBR_STA_OPER) | |
200 | ||
201 | /* neighbor events */ | |
202 | enum nbr_event { | |
203 | NBR_EVT_NOTHING, | |
204 | NBR_EVT_MATCH_ADJ, | |
205 | NBR_EVT_CONNECT_UP, | |
206 | NBR_EVT_CLOSE_SESSION, | |
207 | NBR_EVT_INIT_RCVD, | |
208 | NBR_EVT_KEEPALIVE_RCVD, | |
209 | NBR_EVT_PDU_RCVD, | |
210 | NBR_EVT_PDU_SENT, | |
211 | NBR_EVT_INIT_SENT | |
212 | }; | |
213 | ||
214 | /* neighbor actions */ | |
215 | enum nbr_action { | |
216 | NBR_ACT_NOTHING, | |
217 | NBR_ACT_RST_KTIMEOUT, | |
218 | NBR_ACT_SESSION_EST, | |
219 | NBR_ACT_RST_KTIMER, | |
220 | NBR_ACT_CONNECT_SETUP, | |
221 | NBR_ACT_PASSIVE_INIT, | |
222 | NBR_ACT_KEEPALIVE_SEND, | |
223 | NBR_ACT_CLOSE_SESSION | |
224 | }; | |
225 | ||
e1894ff7 KS |
226 | /* LDP IGP Sync states */ |
227 | #define LDP_SYNC_STA_UNKNOWN 0x0000 | |
228 | #define LDP_SYNC_STA_NOT_ACH 0x0001 | |
229 | #define LDP_SYNC_STA_ACH 0x0002 | |
230 | ||
231 | /* LDP IGP Sync events */ | |
232 | enum ldp_sync_event { | |
233 | LDP_SYNC_EVT_NOTHING, | |
234 | LDP_SYNC_EVT_LDP_SYNC_START, | |
235 | LDP_SYNC_EVT_LDP_SYNC_COMPLETE, | |
236 | LDP_SYNC_EVT_CONFIG_LDP_OFF, | |
237 | LDP_SYNC_EVT_ADJ_DEL, | |
238 | LDP_SYNC_EVT_ADJ_NEW, | |
239 | LDP_SYNC_EVT_SESSION_CLOSE, | |
240 | LDP_SYNC_EVT_CONFIG_LDP_ON, | |
241 | LDP_SYNC_EVT_IFACE_SHUTDOWN | |
242 | }; | |
243 | ||
244 | /* LDP IGP Sync actions */ | |
245 | enum ldp_sync_action { | |
246 | LDP_SYNC_ACT_NOTHING, | |
247 | LDP_SYNC_ACT_IFACE_START_SYNC, | |
248 | LDP_SYNC_ACT_LDP_START_SYNC, | |
249 | LDP_SYNC_ACT_LDP_COMPLETE_SYNC, | |
250 | LDP_SYNC_ACT_CONFIG_LDP_OFF, | |
251 | LDP_SYNC_ACT_IFACE_SHUTDOWN | |
252 | }; | |
253 | ||
057d48bd RW |
254 | /* forward declarations */ |
255 | RB_HEAD(global_adj_head, adj); | |
256 | RB_HEAD(nbr_adj_head, adj); | |
257 | RB_HEAD(ia_adj_head, adj); | |
8429abe0 RW |
258 | |
259 | struct map { | |
260 | uint8_t type; | |
261 | uint32_t msg_id; | |
262 | union { | |
263 | struct { | |
264 | uint16_t af; | |
265 | union ldpd_addr prefix; | |
266 | uint8_t prefixlen; | |
267 | } prefix; | |
268 | struct { | |
269 | uint16_t type; | |
270 | uint32_t pwid; | |
271 | uint32_t group_id; | |
272 | uint16_t ifmtu; | |
273 | } pwid; | |
d4afb819 RW |
274 | struct { |
275 | uint8_t type; | |
276 | union { | |
277 | uint16_t prefix_af; | |
aba50a83 | 278 | uint16_t pw_type; |
d4afb819 RW |
279 | } u; |
280 | } twcard; | |
8429abe0 RW |
281 | } fec; |
282 | struct { | |
283 | uint32_t status_code; | |
284 | uint32_t msg_id; | |
285 | uint16_t msg_type; | |
286 | } st; | |
287 | uint32_t label; | |
288 | uint32_t requestid; | |
289 | uint32_t pw_status; | |
290 | uint8_t flags; | |
291 | }; | |
292 | #define F_MAP_REQ_ID 0x01 /* optional request message id present */ | |
293 | #define F_MAP_STATUS 0x02 /* status */ | |
294 | #define F_MAP_PW_CWORD 0x04 /* pseudowire control word */ | |
295 | #define F_MAP_PW_ID 0x08 /* pseudowire connection id */ | |
296 | #define F_MAP_PW_IFMTU 0x10 /* pseudowire interface parameter */ | |
297 | #define F_MAP_PW_STATUS 0x20 /* pseudowire status */ | |
298 | ||
299 | struct notify_msg { | |
300 | uint32_t status_code; | |
301 | uint32_t msg_id; /* network byte order */ | |
302 | uint16_t msg_type; /* network byte order */ | |
303 | uint32_t pw_status; | |
304 | struct map fec; | |
8819fc38 RW |
305 | struct { |
306 | uint16_t type; | |
307 | uint16_t length; | |
308 | char *data; | |
309 | } rtlvs; | |
8429abe0 RW |
310 | uint8_t flags; |
311 | }; | |
312 | #define F_NOTIF_PW_STATUS 0x01 /* pseudowire status tlv present */ | |
313 | #define F_NOTIF_FEC 0x02 /* fec tlv present */ | |
8819fc38 | 314 | #define F_NOTIF_RETURNED_TLVS 0x04 /* returned tlvs present */ |
8429abe0 RW |
315 | |
316 | struct if_addr { | |
317 | LIST_ENTRY(if_addr) entry; | |
318 | int af; | |
319 | union ldpd_addr addr; | |
320 | uint8_t prefixlen; | |
321 | union ldpd_addr dstbrd; | |
322 | }; | |
323 | LIST_HEAD(if_addr_head, if_addr); | |
324 | ||
325 | struct iface_af { | |
326 | struct iface *iface; | |
327 | int af; | |
328 | int enabled; | |
329 | int state; | |
057d48bd | 330 | struct ia_adj_head adj_tree; |
8429abe0 | 331 | time_t uptime; |
e6685141 | 332 | struct event *hello_timer; |
8429abe0 RW |
333 | uint16_t hello_holdtime; |
334 | uint16_t hello_interval; | |
335 | }; | |
336 | ||
e1894ff7 KS |
337 | struct iface_ldp_sync { |
338 | int state; | |
e6685141 | 339 | struct event *wait_for_sync_timer; |
e1894ff7 KS |
340 | }; |
341 | ||
8429abe0 | 342 | struct iface { |
7d3d7491 | 343 | RB_ENTRY(iface) entry; |
3682bd90 | 344 | char name[INTERFACE_NAMSIZ]; |
6cd8093d | 345 | ifindex_t ifindex; |
8429abe0 RW |
346 | struct if_addr_head addr_list; |
347 | struct in6_addr linklocal; | |
348 | enum iface_type type; | |
988ded8d | 349 | int operative; |
8429abe0 RW |
350 | struct iface_af ipv4; |
351 | struct iface_af ipv6; | |
e1894ff7 | 352 | struct iface_ldp_sync ldp_sync; |
96244aca | 353 | QOBJ_FIELDS; |
8429abe0 | 354 | }; |
7d3d7491 RW |
355 | RB_HEAD(iface_head, iface); |
356 | RB_PROTOTYPE(iface_head, iface, entry, iface_compare); | |
96244aca | 357 | DECLARE_QOBJ_TYPE(iface); |
8429abe0 RW |
358 | |
359 | /* source of targeted hellos */ | |
360 | struct tnbr { | |
7989cdba | 361 | RB_ENTRY(tnbr) entry; |
e6685141 | 362 | struct event *hello_timer; |
8429abe0 RW |
363 | struct adj *adj; |
364 | int af; | |
365 | union ldpd_addr addr; | |
366 | int state; | |
8429abe0 | 367 | uint16_t pw_count; |
077d336a | 368 | uint32_t rlfa_count; |
8429abe0 | 369 | uint8_t flags; |
96244aca | 370 | QOBJ_FIELDS; |
8429abe0 | 371 | }; |
7989cdba RW |
372 | RB_HEAD(tnbr_head, tnbr); |
373 | RB_PROTOTYPE(tnbr_head, tnbr, entry, tnbr_compare); | |
96244aca | 374 | DECLARE_QOBJ_TYPE(tnbr); |
8429abe0 RW |
375 | #define F_TNBR_CONFIGURED 0x01 |
376 | #define F_TNBR_DYNAMIC 0x02 | |
377 | ||
378 | enum auth_method { | |
379 | AUTH_NONE, | |
380 | AUTH_MD5SIG | |
381 | }; | |
382 | ||
383 | /* neighbor specific parameters */ | |
384 | struct nbr_params { | |
76c4abd1 | 385 | RB_ENTRY(nbr_params) entry; |
8429abe0 RW |
386 | struct in_addr lsr_id; |
387 | uint16_t keepalive; | |
388 | int gtsm_enabled; | |
389 | uint8_t gtsm_hops; | |
390 | struct { | |
391 | enum auth_method method; | |
392 | char md5key[TCP_MD5_KEY_LEN]; | |
393 | uint8_t md5key_len; | |
394 | } auth; | |
395 | uint8_t flags; | |
96244aca | 396 | QOBJ_FIELDS; |
8429abe0 | 397 | }; |
76c4abd1 RW |
398 | RB_HEAD(nbrp_head, nbr_params); |
399 | RB_PROTOTYPE(nbrp_head, nbr_params, entry, nbr_params_compare); | |
96244aca | 400 | DECLARE_QOBJ_TYPE(nbr_params); |
8429abe0 RW |
401 | #define F_NBRP_KEEPALIVE 0x01 |
402 | #define F_NBRP_GTSM 0x02 | |
403 | #define F_NBRP_GTSM_HOPS 0x04 | |
404 | ||
0f7b5df9 RW |
405 | struct ldp_stats { |
406 | uint32_t kalive_sent; | |
407 | uint32_t kalive_rcvd; | |
408 | uint32_t addr_sent; | |
409 | uint32_t addr_rcvd; | |
410 | uint32_t addrwdraw_sent; | |
411 | uint32_t addrwdraw_rcvd; | |
412 | uint32_t notif_sent; | |
413 | uint32_t notif_rcvd; | |
414 | uint32_t capability_sent; | |
415 | uint32_t capability_rcvd; | |
416 | uint32_t labelmap_sent; | |
417 | uint32_t labelmap_rcvd; | |
418 | uint32_t labelreq_sent; | |
419 | uint32_t labelreq_rcvd; | |
420 | uint32_t labelwdraw_sent; | |
421 | uint32_t labelwdraw_rcvd; | |
422 | uint32_t labelrel_sent; | |
423 | uint32_t labelrel_rcvd; | |
424 | uint32_t labelabreq_sent; | |
425 | uint32_t labelabreq_rcvd; | |
d4d6e7d8 KS |
426 | uint32_t unknown_tlv; |
427 | uint32_t unknown_msg; | |
f9a4d683 | 428 | |
0f7b5df9 RW |
429 | }; |
430 | ||
d4d6e7d8 KS |
431 | struct ldp_entity_stats { |
432 | uint32_t session_attempts; | |
433 | uint32_t session_rejects_hello; | |
434 | uint32_t session_rejects_ad; | |
435 | uint32_t session_rejects_max_pdu; | |
436 | uint32_t session_rejects_lr; | |
437 | uint32_t bad_ldp_id; | |
438 | uint32_t bad_pdu_len; | |
439 | uint32_t bad_msg_len; | |
440 | uint32_t bad_tlv_len; | |
441 | uint32_t malformed_tlv; | |
442 | uint32_t keepalive_timer_exp; | |
443 | uint32_t shutdown_rcv_notify; | |
444 | uint32_t shutdown_send_notify; | |
445 | }; | |
446 | ||
8429abe0 | 447 | struct l2vpn_if { |
029c1958 | 448 | RB_ENTRY(l2vpn_if) entry; |
8429abe0 | 449 | struct l2vpn *l2vpn; |
3682bd90 | 450 | char ifname[INTERFACE_NAMSIZ]; |
6cd8093d | 451 | ifindex_t ifindex; |
988ded8d | 452 | int operative; |
9bff8057 | 453 | uint8_t mac[ETH_ALEN]; |
96244aca | 454 | QOBJ_FIELDS; |
8429abe0 | 455 | }; |
029c1958 RW |
456 | RB_HEAD(l2vpn_if_head, l2vpn_if); |
457 | RB_PROTOTYPE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare); | |
96244aca | 458 | DECLARE_QOBJ_TYPE(l2vpn_if); |
8429abe0 RW |
459 | |
460 | struct l2vpn_pw { | |
20bacaeb | 461 | RB_ENTRY(l2vpn_pw) entry; |
8429abe0 RW |
462 | struct l2vpn *l2vpn; |
463 | struct in_addr lsr_id; | |
464 | int af; | |
465 | union ldpd_addr addr; | |
466 | uint32_t pwid; | |
3682bd90 | 467 | char ifname[INTERFACE_NAMSIZ]; |
6cd8093d | 468 | ifindex_t ifindex; |
3c5b5220 | 469 | bool enabled; |
8429abe0 RW |
470 | uint32_t remote_group; |
471 | uint16_t remote_mtu; | |
87b5f1b7 | 472 | uint32_t local_status; |
8429abe0 RW |
473 | uint32_t remote_status; |
474 | uint8_t flags; | |
6bbdd9e9 | 475 | uint8_t reason; |
96244aca | 476 | QOBJ_FIELDS; |
8429abe0 | 477 | }; |
20bacaeb RW |
478 | RB_HEAD(l2vpn_pw_head, l2vpn_pw); |
479 | RB_PROTOTYPE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare); | |
96244aca | 480 | DECLARE_QOBJ_TYPE(l2vpn_pw); |
8429abe0 RW |
481 | #define F_PW_STATUSTLV_CONF 0x01 /* status tlv configured */ |
482 | #define F_PW_STATUSTLV 0x02 /* status tlv negotiated */ | |
483 | #define F_PW_CWORD_CONF 0x04 /* control word configured */ | |
484 | #define F_PW_CWORD 0x08 /* control word negotiated */ | |
87b5f1b7 | 485 | #define F_PW_STATIC_NBR_ADDR 0x10 /* static neighbor address configured */ |
8429abe0 | 486 | |
6bbdd9e9 | 487 | #define F_PW_NO_ERR 0x00 /* no error reported */ |
488 | #define F_PW_LOCAL_NOT_FWD 0x01 /* locally can't forward over PW */ | |
489 | #define F_PW_REMOTE_NOT_FWD 0x02 /* remote end of PW reported fwd error*/ | |
490 | #define F_PW_NO_REMOTE_LABEL 0x03 /* have not recvd label from peer */ | |
491 | #define F_PW_MTU_MISMATCH 0x04 /* mtu mismatch between peers */ | |
492 | ||
8429abe0 | 493 | struct l2vpn { |
90d7e7bd | 494 | RB_ENTRY(l2vpn) entry; |
8429abe0 RW |
495 | char name[L2VPN_NAME_LEN]; |
496 | int type; | |
497 | int pw_type; | |
498 | int mtu; | |
3682bd90 | 499 | char br_ifname[INTERFACE_NAMSIZ]; |
6cd8093d | 500 | ifindex_t br_ifindex; |
029c1958 | 501 | struct l2vpn_if_head if_tree; |
20bacaeb RW |
502 | struct l2vpn_pw_head pw_tree; |
503 | struct l2vpn_pw_head pw_inactive_tree; | |
96244aca | 504 | QOBJ_FIELDS; |
8429abe0 | 505 | }; |
90d7e7bd RW |
506 | RB_HEAD(l2vpn_head, l2vpn); |
507 | RB_PROTOTYPE(l2vpn_head, l2vpn, entry, l2vpn_compare); | |
96244aca | 508 | DECLARE_QOBJ_TYPE(l2vpn); |
8429abe0 RW |
509 | #define L2VPN_TYPE_VPWS 1 |
510 | #define L2VPN_TYPE_VPLS 2 | |
511 | ||
512 | /* ldp_conf */ | |
54ca644b | 513 | extern enum ldpd_process { |
8429abe0 RW |
514 | PROC_MAIN, |
515 | PROC_LDP_ENGINE, | |
516 | PROC_LDE_ENGINE | |
517 | } ldpd_process; | |
518 | ||
fa68f9da RW |
519 | static const char * const log_procnames[] = { |
520 | "parent", | |
521 | "ldpe", | |
522 | "lde" | |
523 | }; | |
524 | ||
8429abe0 RW |
525 | enum socket_type { |
526 | LDP_SOCKET_DISC, | |
527 | LDP_SOCKET_EDISC, | |
528 | LDP_SOCKET_SESSION | |
529 | }; | |
530 | ||
531 | enum hello_type { | |
532 | HELLO_LINK, | |
533 | HELLO_TARGETED | |
534 | }; | |
535 | ||
536 | struct ldpd_af_conf { | |
537 | uint16_t keepalive; | |
eac6e3f0 RW |
538 | uint16_t lhello_holdtime; |
539 | uint16_t lhello_interval; | |
8429abe0 RW |
540 | uint16_t thello_holdtime; |
541 | uint16_t thello_interval; | |
542 | union ldpd_addr trans_addr; | |
45a8eba9 RW |
543 | char acl_thello_accept_from[ACL_NAMSIZ]; |
544 | char acl_label_allocate_for[ACL_NAMSIZ]; | |
545 | char acl_label_advertise_to[ACL_NAMSIZ]; | |
546 | char acl_label_advertise_for[ACL_NAMSIZ]; | |
547 | char acl_label_expnull_for[ACL_NAMSIZ]; | |
548 | char acl_label_accept_from[ACL_NAMSIZ]; | |
549 | char acl_label_accept_for[ACL_NAMSIZ]; | |
8429abe0 RW |
550 | int flags; |
551 | }; | |
552 | #define F_LDPD_AF_ENABLED 0x0001 | |
553 | #define F_LDPD_AF_THELLO_ACCEPT 0x0002 | |
554 | #define F_LDPD_AF_EXPNULL 0x0004 | |
555 | #define F_LDPD_AF_NO_GTSM 0x0008 | |
45a8eba9 | 556 | #define F_LDPD_AF_ALLOCHOSTONLY 0x0010 |
8429abe0 RW |
557 | |
558 | struct ldpd_conf { | |
559 | struct in_addr rtr_id; | |
560 | struct ldpd_af_conf ipv4; | |
561 | struct ldpd_af_conf ipv6; | |
7d3d7491 | 562 | struct iface_head iface_tree; |
7989cdba | 563 | struct tnbr_head tnbr_tree; |
76c4abd1 | 564 | struct nbrp_head nbrp_tree; |
90d7e7bd | 565 | struct l2vpn_head l2vpn_tree; |
eac6e3f0 RW |
566 | uint16_t lhello_holdtime; |
567 | uint16_t lhello_interval; | |
568 | uint16_t thello_holdtime; | |
569 | uint16_t thello_interval; | |
8429abe0 | 570 | uint16_t trans_pref; |
e1894ff7 | 571 | uint16_t wait_for_sync_interval; |
8429abe0 | 572 | int flags; |
f9a4d683 | 573 | time_t config_change_time; |
d4d6e7d8 | 574 | struct ldp_entity_stats stats; |
96244aca | 575 | QOBJ_FIELDS; |
8429abe0 | 576 | }; |
96244aca | 577 | DECLARE_QOBJ_TYPE(ldpd_conf); |
8429abe0 RW |
578 | #define F_LDPD_NO_FIB_UPDATE 0x0001 |
579 | #define F_LDPD_DS_CISCO_INTEROP 0x0002 | |
eac6e3f0 | 580 | #define F_LDPD_ENABLED 0x0004 |
aff1743c | 581 | #define F_LDPD_ORDERED_CONTROL 0x0008 |
ff5279ba | 582 | #define F_LDPD_ALLOW_BROKEN_LSP 0x0010 |
8429abe0 RW |
583 | |
584 | struct ldpd_af_global { | |
e6685141 DS |
585 | struct event *disc_ev; |
586 | struct event *edisc_ev; | |
8429abe0 RW |
587 | int ldp_disc_socket; |
588 | int ldp_edisc_socket; | |
589 | int ldp_session_socket; | |
590 | }; | |
591 | ||
592 | struct ldpd_global { | |
593 | int cmd_opts; | |
eac6e3f0 | 594 | struct in_addr rtr_id; |
8429abe0 RW |
595 | struct ldpd_af_global ipv4; |
596 | struct ldpd_af_global ipv6; | |
597 | uint32_t conf_seqnum; | |
598 | int pfkeysock; | |
599 | struct if_addr_head addr_list; | |
057d48bd | 600 | struct global_adj_head adj_tree; |
8429abe0 RW |
601 | struct in_addr mcast_addr_v4; |
602 | struct in6_addr mcast_addr_v6; | |
603 | TAILQ_HEAD(, pending_conn) pending_conns; | |
604 | }; | |
605 | ||
606 | /* kroute */ | |
607 | struct kroute { | |
608 | int af; | |
609 | union ldpd_addr prefix; | |
610 | uint8_t prefixlen; | |
611 | union ldpd_addr nexthop; | |
612 | uint32_t local_label; | |
613 | uint32_t remote_label; | |
6cd8093d | 614 | ifindex_t ifindex; |
e132dea0 RW |
615 | uint8_t route_type; |
616 | uint8_t route_instance; | |
8429abe0 RW |
617 | uint16_t flags; |
618 | }; | |
619 | ||
8429abe0 | 620 | struct kaddr { |
3682bd90 | 621 | char ifname[INTERFACE_NAMSIZ]; |
6cd8093d | 622 | ifindex_t ifindex; |
8429abe0 RW |
623 | int af; |
624 | union ldpd_addr addr; | |
625 | uint8_t prefixlen; | |
626 | union ldpd_addr dstbrd; | |
627 | }; | |
628 | ||
629 | struct kif { | |
3682bd90 | 630 | char ifname[INTERFACE_NAMSIZ]; |
6cd8093d | 631 | ifindex_t ifindex; |
8429abe0 | 632 | int flags; |
988ded8d | 633 | int operative; |
9bff8057 | 634 | uint8_t mac[ETH_ALEN]; |
8429abe0 | 635 | int mtu; |
8429abe0 RW |
636 | }; |
637 | ||
45a8eba9 RW |
638 | struct acl_check { |
639 | char acl[ACL_NAMSIZ]; | |
640 | int af; | |
641 | union ldpd_addr addr; | |
642 | uint8_t prefixlen; | |
643 | }; | |
644 | ||
8429abe0 RW |
645 | /* control data structures */ |
646 | struct ctl_iface { | |
647 | int af; | |
3682bd90 | 648 | char name[INTERFACE_NAMSIZ]; |
6cd8093d | 649 | ifindex_t ifindex; |
8429abe0 | 650 | int state; |
8429abe0 | 651 | enum iface_type type; |
8429abe0 RW |
652 | uint16_t hello_holdtime; |
653 | uint16_t hello_interval; | |
654 | time_t uptime; | |
655 | uint16_t adj_cnt; | |
656 | }; | |
657 | ||
eac6e3f0 | 658 | struct ctl_disc_if { |
3682bd90 | 659 | char name[INTERFACE_NAMSIZ]; |
eac6e3f0 RW |
660 | int active_v4; |
661 | int active_v6; | |
662 | int no_adj; | |
663 | }; | |
664 | ||
665 | struct ctl_disc_tnbr { | |
666 | int af; | |
667 | union ldpd_addr addr; | |
668 | int no_adj; | |
669 | }; | |
670 | ||
8429abe0 RW |
671 | struct ctl_adj { |
672 | int af; | |
673 | struct in_addr id; | |
674 | enum hello_type type; | |
3682bd90 | 675 | char ifname[INTERFACE_NAMSIZ]; |
8429abe0 RW |
676 | union ldpd_addr src_addr; |
677 | uint16_t holdtime; | |
0f7b5df9 | 678 | uint16_t holdtime_remaining; |
8429abe0 | 679 | union ldpd_addr trans_addr; |
0f7b5df9 | 680 | int ds_tlv; |
8429abe0 RW |
681 | }; |
682 | ||
683 | struct ctl_nbr { | |
684 | int af; | |
685 | struct in_addr id; | |
686 | union ldpd_addr laddr; | |
eac6e3f0 | 687 | in_port_t lport; |
8429abe0 | 688 | union ldpd_addr raddr; |
eac6e3f0 | 689 | in_port_t rport; |
0f7b5df9 | 690 | enum auth_method auth_method; |
eac6e3f0 | 691 | uint16_t holdtime; |
8429abe0 RW |
692 | time_t uptime; |
693 | int nbr_state; | |
0f7b5df9 | 694 | struct ldp_stats stats; |
99cfc17f | 695 | int flags; |
f9a4d683 KS |
696 | uint16_t max_pdu_len; |
697 | uint16_t hold_time_remaining; | |
8429abe0 RW |
698 | }; |
699 | ||
700 | struct ctl_rt { | |
701 | int af; | |
702 | union ldpd_addr prefix; | |
703 | uint8_t prefixlen; | |
704 | struct in_addr nexthop; /* lsr-id */ | |
705 | uint32_t local_label; | |
706 | uint32_t remote_label; | |
707 | uint8_t flags; | |
708 | uint8_t in_use; | |
0f7b5df9 | 709 | int no_downstream; |
8429abe0 RW |
710 | }; |
711 | ||
712 | struct ctl_pw { | |
713 | uint16_t type; | |
eac6e3f0 | 714 | char l2vpn_name[L2VPN_NAME_LEN]; |
3682bd90 | 715 | char ifname[INTERFACE_NAMSIZ]; |
8429abe0 RW |
716 | uint32_t pwid; |
717 | struct in_addr lsr_id; | |
718 | uint32_t local_label; | |
719 | uint32_t local_gid; | |
720 | uint16_t local_ifmtu; | |
eac6e3f0 | 721 | uint8_t local_cword; |
8429abe0 RW |
722 | uint32_t remote_label; |
723 | uint32_t remote_gid; | |
724 | uint16_t remote_ifmtu; | |
eac6e3f0 | 725 | uint8_t remote_cword; |
8429abe0 | 726 | uint32_t status; |
6bbdd9e9 | 727 | uint8_t reason; |
8429abe0 RW |
728 | }; |
729 | ||
e1894ff7 | 730 | struct ctl_ldp_sync { |
3682bd90 | 731 | char name[INTERFACE_NAMSIZ]; |
e1894ff7 KS |
732 | ifindex_t ifindex; |
733 | bool in_sync; | |
734 | bool timer_running; | |
735 | uint16_t wait_time; | |
736 | uint16_t wait_time_remaining; | |
737 | struct in_addr peer_ldp_id; | |
738 | }; | |
739 | ||
56b8a8d2 | 740 | extern struct ldpd_conf *ldpd_conf, *vty_conf; |
8429abe0 | 741 | extern struct ldpd_global global; |
274f5abf | 742 | extern struct ldpd_init init; |
8429abe0 RW |
743 | |
744 | /* parse.y */ | |
745 | struct ldpd_conf *parse_config(char *); | |
746 | int cmdline_symset(char *); | |
747 | ||
748 | /* kroute.c */ | |
87b5f1b7 | 749 | void pw2zpw(struct l2vpn_pw *, struct zapi_pw *); |
8429abe0 RW |
750 | void kif_redistribute(const char *); |
751 | int kr_change(struct kroute *); | |
752 | int kr_delete(struct kroute *); | |
87b5f1b7 RW |
753 | int kmpw_add(struct zapi_pw *); |
754 | int kmpw_del(struct zapi_pw *); | |
755 | int kmpw_set(struct zapi_pw *); | |
756 | int kmpw_unset(struct zapi_pw *); | |
8429abe0 RW |
757 | |
758 | /* util.c */ | |
759 | uint8_t mask2prefixlen(in_addr_t); | |
760 | uint8_t mask2prefixlen6(struct sockaddr_in6 *); | |
761 | in_addr_t prefixlen2mask(uint8_t); | |
762 | struct in6_addr *prefixlen2mask6(uint8_t); | |
763 | void ldp_applymask(int, union ldpd_addr *, | |
764 | const union ldpd_addr *, int); | |
765 | int ldp_addrcmp(int, const union ldpd_addr *, | |
766 | const union ldpd_addr *); | |
767 | int ldp_addrisset(int, const union ldpd_addr *); | |
768 | int ldp_prefixcmp(int, const union ldpd_addr *, | |
769 | const union ldpd_addr *, uint8_t); | |
770 | int bad_addr_v4(struct in_addr); | |
771 | int bad_addr_v6(struct in6_addr *); | |
772 | int bad_addr(int, union ldpd_addr *); | |
773 | void embedscope(struct sockaddr_in6 *); | |
774 | void recoverscope(struct sockaddr_in6 *); | |
775 | void addscope(struct sockaddr_in6 *, uint32_t); | |
776 | void clearscope(struct in6_addr *); | |
4149ef7c A |
777 | void addr2sa(int af, const union ldpd_addr *, uint16_t, |
778 | union sockunion *su); | |
eac6e3f0 RW |
779 | void sa2addr(struct sockaddr *, int *, union ldpd_addr *, |
780 | in_port_t *); | |
781 | socklen_t sockaddr_len(struct sockaddr *); | |
8429abe0 RW |
782 | |
783 | /* ldpd.c */ | |
e6685141 | 784 | void ldp_write_handler(struct event *thread); |
8429abe0 RW |
785 | void main_imsg_compose_ldpe(int, pid_t, void *, uint16_t); |
786 | void main_imsg_compose_lde(int, pid_t, void *, uint16_t); | |
eac6e3f0 RW |
787 | int main_imsg_compose_both(enum imsg_type, void *, |
788 | uint16_t); | |
8429abe0 | 789 | void imsg_event_add(struct imsgev *); |
eac6e3f0 RW |
790 | int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, |
791 | pid_t, int, void *, uint16_t); | |
8429abe0 RW |
792 | void evbuf_enqueue(struct evbuf *, struct ibuf *); |
793 | void evbuf_event_add(struct evbuf *); | |
e6685141 | 794 | void evbuf_init(struct evbuf *, int, void (*)(struct event *), void *); |
8429abe0 | 795 | void evbuf_clear(struct evbuf *); |
45a8eba9 RW |
796 | int ldp_acl_request(struct imsgev *, char *, int, |
797 | union ldpd_addr *, uint8_t); | |
798 | void ldp_acl_reply(struct imsgev *, struct acl_check *); | |
8429abe0 RW |
799 | struct ldpd_af_conf *ldp_af_conf_get(struct ldpd_conf *, int); |
800 | struct ldpd_af_global *ldp_af_global_get(struct ldpd_global *, int); | |
801 | int ldp_is_dual_stack(struct ldpd_conf *); | |
eac6e3f0 | 802 | in_addr_t ldp_rtr_id_get(struct ldpd_conf *); |
e4a82008 | 803 | int ldp_config_apply(struct vty *, struct ldpd_conf *); |
eac6e3f0 | 804 | void ldp_clear_config(struct ldpd_conf *); |
8429abe0 RW |
805 | void merge_config(struct ldpd_conf *, struct ldpd_conf *); |
806 | struct ldpd_conf *config_new_empty(void); | |
807 | void config_clear(struct ldpd_conf *); | |
808 | ||
bbee85d2 RW |
809 | /* ldp_vty_conf.c */ |
810 | /* NOTE: the parameters' names should be preserved because of codegen */ | |
7d3d7491 | 811 | struct iface *iface_new_api(struct ldpd_conf *conf, |
bbee85d2 | 812 | const char *name); |
7d3d7491 RW |
813 | void iface_del_api(struct ldpd_conf *conf, |
814 | struct iface *iface); | |
7989cdba | 815 | struct tnbr *tnbr_new_api(struct ldpd_conf *conf, int af, |
bbee85d2 | 816 | union ldpd_addr *addr); |
7989cdba | 817 | void tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr); |
76c4abd1 | 818 | struct nbr_params *nbrp_new_api(struct ldpd_conf *conf, |
bbee85d2 | 819 | struct in_addr lsr_id); |
76c4abd1 RW |
820 | void nbrp_del_api(struct ldpd_conf *conf, |
821 | struct nbr_params *nbrp); | |
90d7e7bd RW |
822 | struct l2vpn *l2vpn_new_api(struct ldpd_conf *conf, const char *name); |
823 | void l2vpn_del_api(struct ldpd_conf *conf, | |
824 | struct l2vpn *l2vpn); | |
bbee85d2 RW |
825 | struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, |
826 | struct l2vpn *l2vpn, const char *ifname); | |
029c1958 RW |
827 | void l2vpn_if_del_api(struct l2vpn *l2vpn, |
828 | struct l2vpn_if *lif); | |
bbee85d2 RW |
829 | struct l2vpn_pw *l2vpn_pw_new_api(struct ldpd_conf *conf, |
830 | struct l2vpn *l2vpn, const char *ifname); | |
20bacaeb RW |
831 | void l2vpn_pw_del_api(struct l2vpn *l2vpn, |
832 | struct l2vpn_pw *pw); | |
bbee85d2 | 833 | |
8429abe0 RW |
834 | /* socket.c */ |
835 | int ldp_create_socket(int, enum socket_type); | |
eac6e3f0 RW |
836 | void sock_set_nonblock(int); |
837 | void sock_set_cloexec(int); | |
8429abe0 RW |
838 | void sock_set_recvbuf(int); |
839 | int sock_set_reuse(int, int); | |
840 | int sock_set_bindany(int, int); | |
eac6e3f0 | 841 | int sock_set_md5sig(int, int, union ldpd_addr *, const char *); |
8429abe0 | 842 | int sock_set_ipv4_tos(int, int); |
eac6e3f0 | 843 | int sock_set_ipv4_pktinfo(int, int); |
6cd8093d | 844 | int sock_set_ipv4_recvdstaddr(int fd, ifindex_t ifindex); |
8429abe0 RW |
845 | int sock_set_ipv4_recvif(int, int); |
846 | int sock_set_ipv4_minttl(int, int); | |
847 | int sock_set_ipv4_ucast_ttl(int fd, int); | |
848 | int sock_set_ipv4_mcast_ttl(int, uint8_t); | |
849 | int sock_set_ipv4_mcast(struct iface *); | |
850 | int sock_set_ipv4_mcast_loop(int); | |
851 | int sock_set_ipv6_dscp(int, int); | |
852 | int sock_set_ipv6_pktinfo(int, int); | |
853 | int sock_set_ipv6_minhopcount(int, int); | |
854 | int sock_set_ipv6_ucast_hops(int, int); | |
855 | int sock_set_ipv6_mcast_hops(int, int); | |
856 | int sock_set_ipv6_mcast(struct iface *); | |
857 | int sock_set_ipv6_mcast_loop(int); | |
858 | ||
fa68f9da RW |
859 | /* logmsg.h */ |
860 | struct in6_addr; | |
861 | union ldpd_addr; | |
862 | struct hello_source; | |
863 | struct fec; | |
864 | ||
865 | const char *log_sockaddr(void *); | |
866 | const char *log_in6addr(const struct in6_addr *); | |
6cd8093d DS |
867 | const char *log_in6addr_scope(const struct in6_addr *addr, |
868 | ifindex_t ifidx); | |
fa68f9da RW |
869 | const char *log_addr(int, const union ldpd_addr *); |
870 | char *log_label(uint32_t); | |
871 | const char *log_time(time_t); | |
872 | char *log_hello_src(const struct hello_source *); | |
873 | const char *log_map(const struct map *); | |
874 | const char *log_fec(const struct fec *); | |
875 | const char *af_name(int); | |
876 | const char *socket_name(int); | |
877 | const char *nbr_state_name(int); | |
878 | const char *if_state_name(int); | |
879 | const char *if_type_name(enum iface_type); | |
880 | const char *msg_name(uint16_t); | |
881 | const char *status_code_name(uint32_t); | |
882 | const char *pw_type_name(uint16_t); | |
6bbdd9e9 | 883 | const char *pw_error_code(uint8_t); |
fa68f9da | 884 | |
eac6e3f0 | 885 | /* quagga */ |
cd9d0537 | 886 | extern struct event_loop *master; |
372b8bd3 | 887 | extern char ctl_sock_path[MAXPATHLEN]; |
eac6e3f0 RW |
888 | |
889 | /* ldp_zebra.c */ | |
cd9d0537 | 890 | void ldp_zebra_init(struct event_loop *m); |
64dffe25 | 891 | void ldp_zebra_destroy(void); |
e1894ff7 | 892 | int ldp_sync_zebra_send_state_update(struct ldp_igp_sync_if_state *); |
077d336a RW |
893 | int ldp_zebra_send_rlfa_labels(struct zapi_rlfa_response * |
894 | rlfa_labels); | |
eac6e3f0 | 895 | |
ce510d2e FR |
896 | void ldp_zebra_regdereg_zebra_info(bool want_register); |
897 | ||
eac6e3f0 RW |
898 | /* compatibility */ |
899 | #ifndef __OpenBSD__ | |
900 | #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) | |
901 | #define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 | |
902 | #define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ | |
903 | (IN6_IS_ADDR_MULTICAST(a) && \ | |
904 | (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_INTFACELOCAL)) | |
905 | #endif | |
8429abe0 | 906 | |
cd9d0537 | 907 | DECLARE_HOOK(ldp_register_mib, (struct event_loop * tm), (tm)); |
f9a4d683 KS |
908 | |
909 | extern void ldp_agentx_enabled(void); | |
910 | ||
8429abe0 | 911 | #endif /* _LDPD_H_ */ |