]>
Commit | Line | Data |
---|---|---|
74971473 JG |
1 | /* |
2 | * This file is part of the PCEPlib, a PCEP protocol library. | |
3 | * | |
4 | * Copyright (C) 2020 Volta Networks https://voltanet.io/ | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public License | |
17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
18 | * | |
19 | * Author : Brady Johnson <brady@voltanet.io> | |
20 | * | |
21 | */ | |
22 | ||
23 | #include <pthread.h> | |
24 | #include <stdbool.h> | |
25 | #include <stdio.h> | |
26 | #include <string.h> | |
27 | ||
28 | #include "pcep_msg_encoding.h" | |
29 | #include "pcep_session_logic.h" | |
30 | #include "pcep_session_logic_internals.h" | |
31 | #include "pcep_timers.h" | |
32 | #include "pcep_utils_logging.h" | |
33 | #include "pcep_utils_memory.h" | |
34 | ||
35 | #define TIMER_OPEN_KEEP_ALIVE_SECONDS 1 | |
36 | ||
37 | /* Session Logic Handle managed in pcep_session_logic.c */ | |
38 | extern pcep_event_queue *session_logic_event_queue_; | |
39 | void send_keep_alive(pcep_session *session); | |
40 | void send_pcep_error_with_object(pcep_session *session, | |
41 | enum pcep_error_type error_type, | |
42 | enum pcep_error_value error_value, | |
43 | struct pcep_object_header *object); | |
44 | void reset_dead_timer(pcep_session *session); | |
45 | bool verify_pcep_open_object(pcep_session *session, | |
46 | struct pcep_object_open *open_object); | |
47 | void send_reconciled_pcep_open(pcep_session *session, | |
48 | struct pcep_message *error_msg); | |
49 | bool handle_pcep_update(pcep_session *session, struct pcep_message *upd_msg); | |
50 | bool handle_pcep_initiate(pcep_session *session, struct pcep_message *init_msg); | |
51 | bool check_and_send_open_keep_alive(pcep_session *session); | |
52 | void log_pcc_pce_connection(pcep_session *session); | |
53 | bool handle_pcep_open(pcep_session *session, struct pcep_message *open_msg); | |
54 | ||
55 | /* | |
56 | * util functions called by the state handling below | |
57 | */ | |
58 | ||
59 | void send_keep_alive(pcep_session *session) | |
60 | { | |
61 | struct pcep_message *keep_alive_msg = pcep_msg_create_keepalive(); | |
62 | ||
63 | pcep_log( | |
64 | LOG_INFO, | |
65 | "%s: [%ld-%ld] pcep_session_logic send keep_alive message for session [%d]", | |
66 | __func__, time(NULL), pthread_self(), session->session_id); | |
67 | ||
68 | session_send_message(session, keep_alive_msg); | |
69 | ||
70 | /* The keep alive timer will be (re)set once the message | |
71 | * is sent in session_logic_message_sent_handler() */ | |
72 | } | |
73 | ||
74 | ||
75 | /* Send an error message with the corrected or offending object */ | |
76 | void send_pcep_error_with_object(pcep_session *session, | |
77 | enum pcep_error_type error_type, | |
78 | enum pcep_error_value error_value, | |
79 | struct pcep_object_header *object) | |
80 | { | |
81 | double_linked_list *obj_list = dll_initialize(); | |
82 | dll_append(obj_list, object); | |
83 | struct pcep_message *error_msg = pcep_msg_create_error_with_objects( | |
84 | error_type, error_value, obj_list); | |
85 | ||
86 | pcep_log( | |
87 | LOG_INFO, | |
88 | "%s: [%ld-%ld] pcep_session_logic send error message with object [%d][%d] for session [%d]", | |
89 | __func__, time(NULL), pthread_self(), error_type, error_value, | |
90 | session->session_id); | |
91 | ||
92 | session_send_message(session, error_msg); | |
93 | } | |
94 | ||
95 | ||
96 | void send_pcep_error(pcep_session *session, enum pcep_error_type error_type, | |
97 | enum pcep_error_value error_value) | |
98 | { | |
99 | struct pcep_message *error_msg = | |
100 | pcep_msg_create_error(error_type, error_value); | |
101 | ||
102 | pcep_log( | |
103 | LOG_INFO, | |
104 | "%s: [%ld-%ld] pcep_session_logic send error message [%d][%d] for session [%d]", | |
105 | __func__, time(NULL), pthread_self(), error_type, error_value, | |
106 | session->session_id); | |
107 | ||
108 | session_send_message(session, error_msg); | |
109 | } | |
110 | ||
111 | ||
112 | void reset_dead_timer(pcep_session *session) | |
113 | { | |
114 | /* Default to configured dead_timer if its not set yet or set to 0 by | |
115 | * the PCE */ | |
116 | int dead_timer_seconds = | |
117 | (session->pcc_config.dead_timer_pce_negotiated_seconds == 0) | |
118 | ? session->pcc_config.dead_timer_seconds | |
119 | : session->pcc_config.dead_timer_pce_negotiated_seconds; | |
120 | ||
121 | if (session->timer_id_dead_timer == TIMER_ID_NOT_SET) { | |
122 | session->timer_id_dead_timer = | |
123 | create_timer(dead_timer_seconds, session); | |
124 | pcep_log( | |
125 | LOG_INFO, | |
126 | "%s: [%ld-%ld] pcep_session_logic set dead timer [%d secs] id [%d] for session [%d]", | |
127 | __func__, time(NULL), pthread_self(), | |
128 | dead_timer_seconds, session->timer_id_dead_timer, | |
129 | session->session_id); | |
130 | } else { | |
131 | pcep_log( | |
132 | LOG_INFO, | |
133 | "%s: [%ld-%ld] pcep_session_logic reset dead timer [%d secs] id [%d] for session [%d]", | |
134 | __func__, time(NULL), pthread_self(), | |
135 | dead_timer_seconds, session->timer_id_dead_timer, | |
136 | session->session_id); | |
137 | reset_timer(session->timer_id_dead_timer); | |
138 | } | |
139 | } | |
140 | ||
141 | ||
142 | void enqueue_event(pcep_session *session, pcep_event_type event_type, | |
143 | struct pcep_message *message) | |
144 | { | |
145 | if (event_type == MESSAGE_RECEIVED && message == NULL) { | |
146 | pcep_log( | |
147 | LOG_WARNING, | |
148 | "%s: enqueue_event cannot enqueue a NULL message session [%d]", | |
149 | __func__, session->session_id); | |
150 | return; | |
151 | } | |
152 | ||
153 | pcep_event *event = pceplib_malloc(PCEPLIB_INFRA, sizeof(pcep_event)); | |
154 | memset(event, 0, sizeof(pcep_event)); | |
155 | ||
156 | event->session = session; | |
157 | event->event_type = event_type; | |
158 | event->event_time = time(NULL); | |
159 | event->message = message; | |
160 | ||
161 | pthread_mutex_lock(&session_logic_event_queue_->event_queue_mutex); | |
162 | if (session_logic_event_queue_->event_callback != NULL) { | |
163 | session_logic_event_queue_->event_callback( | |
164 | session_logic_event_queue_->event_callback_data, event); | |
165 | } else { | |
166 | queue_enqueue(session_logic_event_queue_->event_queue, event); | |
167 | } | |
168 | pthread_mutex_unlock(&session_logic_event_queue_->event_queue_mutex); | |
169 | } | |
170 | ||
171 | /* Verify the received PCEP Open object parameters are acceptable. If not, | |
172 | * update the unacceptable value(s) with an acceptable value so it can be sent | |
173 | * back to the sender. */ | |
174 | bool verify_pcep_open_object(pcep_session *session, | |
175 | struct pcep_object_open *open_object) | |
176 | { | |
177 | int retval = true; | |
178 | ||
179 | if (open_object->open_keepalive | |
180 | < session->pcc_config.min_keep_alive_seconds) { | |
181 | pcep_log( | |
182 | LOG_INFO, | |
183 | "%s: Rejecting unsupported Open Keep Alive value [%d] min [%d]", | |
184 | __func__, open_object->open_keepalive, | |
185 | session->pcc_config.min_keep_alive_seconds); | |
186 | open_object->open_keepalive = | |
187 | session->pcc_config.min_keep_alive_seconds; | |
188 | retval = false; | |
189 | } else if (open_object->open_keepalive | |
190 | > session->pcc_config.max_keep_alive_seconds) { | |
191 | pcep_log( | |
192 | LOG_INFO, | |
193 | "%s: Rejecting unsupported Open Keep Alive value [%d] max [%d]", | |
194 | __func__, open_object->open_keepalive, | |
195 | session->pcc_config.max_keep_alive_seconds); | |
196 | open_object->open_keepalive = | |
197 | session->pcc_config.max_keep_alive_seconds; | |
198 | retval = false; | |
199 | } | |
200 | ||
201 | if (open_object->open_deadtimer | |
202 | < session->pcc_config.min_dead_timer_seconds) { | |
203 | pcep_log(LOG_INFO, | |
204 | "%s: Rejecting unsupported Open Dead Timer value [%d]", | |
205 | __func__, open_object->open_deadtimer); | |
206 | open_object->open_deadtimer = | |
207 | session->pcc_config.min_dead_timer_seconds; | |
208 | retval = false; | |
209 | } else if (open_object->open_deadtimer | |
210 | > session->pcc_config.max_dead_timer_seconds) { | |
211 | pcep_log(LOG_INFO, | |
212 | "%s: Rejecting unsupported Open Dead Timer value [%d]", | |
213 | __func__, open_object->open_deadtimer); | |
214 | open_object->open_deadtimer = | |
215 | session->pcc_config.max_dead_timer_seconds; | |
216 | retval = false; | |
217 | } | |
218 | ||
219 | /* Check for Open Object TLVs */ | |
220 | if (pcep_object_has_tlvs((struct pcep_object_header *)open_object) | |
221 | == false) { | |
222 | /* There are no TLVs, all done */ | |
223 | return retval; | |
224 | } | |
225 | ||
226 | double_linked_list_node *tlv_node = open_object->header.tlv_list->head; | |
227 | while (tlv_node != NULL) { | |
228 | struct pcep_object_tlv_header *tlv = tlv_node->data; | |
229 | tlv_node = tlv_node->next_node; | |
230 | ||
231 | /* Supported Open Object TLVs */ | |
232 | switch (tlv->type) { | |
233 | case PCEP_OBJ_TLV_TYPE_LSP_DB_VERSION: | |
234 | case PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE_CAPABILITY: | |
235 | case PCEP_OBJ_TLV_TYPE_SPEAKER_ENTITY_ID: | |
236 | case PCEP_OBJ_TLV_TYPE_STATEFUL_PCE_CAPABILITY: | |
237 | case PCEP_OBJ_TLV_TYPE_SR_PCE_CAPABILITY: | |
238 | break; | |
239 | ||
240 | default: | |
241 | /* TODO how to handle unrecognized TLV ?? */ | |
242 | pcep_log( | |
243 | LOG_INFO, | |
244 | "%s: Unhandled OPEN Object TLV type: %d, length %d", | |
245 | __func__, tlv->type, tlv->encoded_tlv_length); | |
246 | break; | |
247 | } | |
248 | ||
249 | /* Verify the STATEFUL-PCE-CAPABILITY TLV */ | |
250 | if (tlv->type == PCEP_OBJ_TLV_TYPE_STATEFUL_PCE_CAPABILITY) { | |
251 | struct pcep_object_tlv_stateful_pce_capability | |
252 | *pce_cap_tlv = | |
253 | (struct | |
254 | pcep_object_tlv_stateful_pce_capability | |
255 | *)tlv; | |
256 | ||
257 | /* If the U flag is set, then the PCE is | |
258 | * capable of updating LSP parameters */ | |
259 | if (pce_cap_tlv->flag_u_lsp_update_capability) { | |
260 | if (session->pce_config | |
261 | .support_stateful_pce_lsp_update | |
262 | == false) { | |
263 | /* Turn off the U bit, as it is not | |
264 | * supported */ | |
265 | pcep_log( | |
266 | LOG_INFO, | |
267 | "%s: Rejecting unsupported Open STATEFUL-PCE-CAPABILITY TLV U flag", | |
268 | __func__); | |
269 | pce_cap_tlv | |
270 | ->flag_u_lsp_update_capability = | |
271 | false; | |
272 | retval = false; | |
273 | } else { | |
274 | session->stateful_pce = true; | |
275 | pcep_log( | |
276 | LOG_INFO, | |
277 | "%s: Setting PCEP session [%d] STATEFUL to support LSP updates", | |
278 | __func__, session->session_id); | |
279 | } | |
280 | } | |
281 | /* TODO the rest of the flags are not implemented yet */ | |
282 | else if (pce_cap_tlv->flag_s_include_db_version) { | |
283 | pcep_log( | |
284 | LOG_INFO, | |
285 | "%s: Ignoring Open STATEFUL-PCE-CAPABILITY TLV S Include DB Version flag", | |
286 | __func__); | |
287 | } else if ( | |
288 | pce_cap_tlv | |
289 | ->flag_i_lsp_instantiation_capability) { | |
290 | pcep_log( | |
291 | LOG_INFO, | |
292 | "%s: Ignoring Open STATEFUL-PCE-CAPABILITY TLV I LSP Instantiation Capability flag", | |
293 | __func__); | |
294 | } else if (pce_cap_tlv->flag_t_triggered_resync) { | |
295 | pcep_log( | |
296 | LOG_INFO, | |
297 | "%s: Ignoring Open STATEFUL-PCE-CAPABILITY TLV T Triggered Resync flag", | |
298 | __func__); | |
299 | } else if (pce_cap_tlv->flag_d_delta_lsp_sync) { | |
300 | pcep_log( | |
301 | LOG_INFO, | |
302 | "%s: Ignoring Open STATEFUL-PCE-CAPABILITY TLV D Delta LSP Sync flag", | |
303 | __func__); | |
304 | } else if (pce_cap_tlv->flag_f_triggered_initial_sync) { | |
305 | pcep_log( | |
306 | LOG_INFO, | |
307 | "%s: Ignoring Open STATEFUL-PCE-CAPABILITY TLV F Triggered Initial Sync flag", | |
308 | __func__); | |
309 | } | |
310 | } else if (tlv->type == PCEP_OBJ_TLV_TYPE_LSP_DB_VERSION) { | |
311 | if (session->pce_config.support_include_db_version | |
312 | == false) { | |
313 | pcep_log( | |
314 | LOG_INFO, | |
315 | "%s: Rejecting unsupported Open LSP DB VERSION TLV", | |
316 | __func__); | |
317 | /* Remove this TLV from the list */ | |
318 | dll_delete_node(open_object->header.tlv_list, | |
319 | tlv_node); | |
320 | retval = false; | |
321 | } | |
322 | } | |
323 | } | |
324 | ||
325 | return retval; | |
326 | } | |
327 | ||
328 | ||
329 | bool handle_pcep_open(pcep_session *session, struct pcep_message *open_msg) | |
330 | { | |
331 | /* Open Message validation and errors according to: | |
332 | * https://tools.ietf.org/html/rfc5440#section-7.15 */ | |
333 | ||
334 | if (session->session_state != SESSION_STATE_PCEP_CONNECTING | |
335 | && session->session_state != SESSION_STATE_INITIALIZED) { | |
336 | pcep_log( | |
337 | LOG_INFO, | |
338 | "%s: Received unexpected OPEN, current session state [%d, replying with error]", | |
339 | __func__, session->session_state); | |
340 | send_pcep_error(session, | |
341 | PCEP_ERRT_ATTEMPT_TO_ESTABLISH_2ND_PCEP_SESSION, | |
342 | PCEP_ERRV_RECVD_INVALID_OPEN_MSG); | |
343 | return false; | |
344 | } | |
345 | ||
346 | if (session->pce_open_received == true | |
347 | && session->pce_open_rejected == false) { | |
348 | pcep_log(LOG_INFO, | |
349 | "%s: Received duplicate OPEN, replying with error", | |
350 | __func__); | |
351 | send_pcep_error(session, | |
352 | PCEP_ERRT_ATTEMPT_TO_ESTABLISH_2ND_PCEP_SESSION, | |
353 | PCEP_ERRV_RECVD_INVALID_OPEN_MSG); | |
354 | return false; | |
355 | } | |
356 | ||
357 | struct pcep_object_open *open_object = | |
358 | (struct pcep_object_open *)pcep_obj_get(open_msg->obj_list, | |
359 | PCEP_OBJ_CLASS_OPEN); | |
360 | if (open_object == NULL) { | |
361 | pcep_log( | |
362 | LOG_INFO, | |
363 | "%s: Received OPEN message with no OPEN object, replying with error", | |
364 | __func__); | |
365 | send_pcep_error(session, PCEP_ERRT_SESSION_FAILURE, | |
366 | PCEP_ERRV_RECVD_INVALID_OPEN_MSG); | |
367 | return false; | |
368 | } | |
369 | ||
370 | /* Check for additional Open Msg objects */ | |
371 | if (open_msg->obj_list->num_entries > 1) { | |
372 | pcep_log( | |
373 | LOG_INFO, | |
374 | "%s: Found additional unsupported objects in the Open message, replying with error", | |
375 | __func__); | |
376 | send_pcep_error(session, PCEP_ERRT_SESSION_FAILURE, | |
377 | PCEP_ERRV_RECVD_INVALID_OPEN_MSG); | |
378 | return false; | |
379 | } | |
380 | ||
381 | session->pce_open_received = true; | |
382 | ||
383 | /* Verify the open object parameters and TLVs */ | |
384 | if (verify_pcep_open_object(session, open_object) == false) { | |
385 | enqueue_event(session, PCC_RCVD_INVALID_OPEN, NULL); | |
386 | if (session->pce_open_rejected) { | |
387 | /* The Open message was already rejected once, so | |
388 | * according to the spec, send an error message and | |
389 | * close the TCP connection. */ | |
390 | pcep_log( | |
391 | LOG_INFO, | |
392 | "%s: Received 2 consecutive unsupported Open messages, closing the connection.", | |
393 | __func__); | |
394 | send_pcep_error( | |
395 | session, PCEP_ERRT_SESSION_FAILURE, | |
396 | PCEP_ERRV_RECVD_SECOND_OPEN_MSG_UNACCEPTABLE); | |
397 | socket_comm_session_close_tcp_after_write( | |
398 | session->socket_comm_session); | |
399 | session->session_state = SESSION_STATE_INITIALIZED; | |
400 | enqueue_event(session, PCC_CONNECTION_FAILURE, NULL); | |
401 | } else { | |
402 | session->pce_open_rejected = true; | |
403 | /* Clone the object here, since the encapsulating | |
404 | * message will be deleted in handle_socket_comm_event() | |
405 | * most likely before this error message is sent */ | |
406 | struct pcep_object_open *cloned_open_object = | |
407 | pceplib_malloc(PCEPLIB_MESSAGES, | |
408 | sizeof(struct pcep_object_open)); | |
409 | memcpy(cloned_open_object, open_object, | |
410 | sizeof(struct pcep_object_open)); | |
411 | open_object->header.tlv_list = NULL; | |
412 | cloned_open_object->header.encoded_object = NULL; | |
413 | cloned_open_object->header.encoded_object_length = 0; | |
414 | send_pcep_error_with_object( | |
415 | session, PCEP_ERRT_SESSION_FAILURE, | |
416 | PCEP_ERRV_UNACCEPTABLE_OPEN_MSG_NEG, | |
417 | &cloned_open_object->header); | |
418 | } | |
419 | ||
420 | return false; | |
421 | } | |
422 | ||
423 | /* | |
424 | * Open Message accepted | |
425 | * Sending the keep-alive response will be managed the function caller | |
426 | */ | |
427 | ||
428 | session->timer_id_open_keep_alive = | |
429 | create_timer(TIMER_OPEN_KEEP_ALIVE_SECONDS, session); | |
430 | session->pcc_config.dead_timer_pce_negotiated_seconds = | |
431 | (int)open_object->open_deadtimer; | |
432 | /* Cancel the timer so we can change the dead_timer value */ | |
433 | cancel_timer(session->timer_id_dead_timer); | |
434 | session->timer_id_dead_timer = TIMER_ID_NOT_SET; | |
435 | reset_dead_timer(session); | |
436 | ||
437 | return true; | |
438 | } | |
439 | ||
440 | ||
441 | /* The original PCEP Open message sent to the PCE was rejected, | |
442 | * try to reconcile the differences and re-send a new Open. */ | |
443 | void send_reconciled_pcep_open(pcep_session *session, | |
444 | struct pcep_message *error_msg) | |
445 | { | |
446 | struct pcep_message *open_msg = create_pcep_open(session); | |
447 | ||
448 | struct pcep_object_open *error_open_obj = | |
449 | (struct pcep_object_open *)pcep_obj_get(error_msg->obj_list, | |
450 | PCEP_OBJ_CLASS_OPEN); | |
451 | if (error_open_obj == NULL) { | |
452 | /* Nothing to reconcile, send the same Open message again */ | |
453 | pcep_log( | |
454 | LOG_INFO, | |
455 | "%s: No Open object received in Error, sending the same Open message", | |
456 | __func__); | |
457 | session_send_message(session, open_msg); | |
458 | return; | |
459 | } | |
460 | ||
461 | struct pcep_object_open *open_obj = | |
462 | (struct pcep_object_open *)pcep_obj_get(open_msg->obj_list, | |
463 | PCEP_OBJ_CLASS_OPEN); | |
464 | ||
465 | if (error_open_obj->open_deadtimer | |
466 | != session->pce_config.dead_timer_seconds) { | |
467 | if (error_open_obj->open_deadtimer | |
468 | >= session->pce_config.min_dead_timer_seconds | |
469 | && error_open_obj->open_deadtimer | |
470 | <= session->pce_config.max_dead_timer_seconds) { | |
471 | open_obj->open_deadtimer = | |
472 | error_open_obj->open_deadtimer; | |
473 | session->pcc_config.dead_timer_pce_negotiated_seconds = | |
474 | error_open_obj->open_deadtimer; | |
475 | pcep_log( | |
476 | LOG_INFO, | |
477 | "%s: Open deadtimer value [%d] rejected, using PCE value [%d]", | |
478 | __func__, | |
479 | session->pcc_config.dead_timer_seconds, | |
480 | session->pcc_config | |
481 | .dead_timer_pce_negotiated_seconds); | |
482 | /* Reset the timer with the new value */ | |
483 | cancel_timer(session->timer_id_dead_timer); | |
484 | session->timer_id_dead_timer = TIMER_ID_NOT_SET; | |
485 | reset_dead_timer(session); | |
486 | } else { | |
487 | pcep_log( | |
488 | LOG_INFO, | |
489 | "%s: Can not reconcile Open with suggested deadtimer [%d]", | |
490 | __func__, error_open_obj->open_deadtimer); | |
491 | } | |
492 | } | |
493 | ||
494 | if (error_open_obj->open_keepalive | |
495 | != session->pce_config.keep_alive_seconds) { | |
496 | if (error_open_obj->open_keepalive | |
497 | >= session->pce_config.min_keep_alive_seconds | |
498 | && error_open_obj->open_keepalive | |
499 | <= session->pce_config.max_keep_alive_seconds) { | |
500 | open_obj->open_keepalive = | |
501 | error_open_obj->open_keepalive; | |
502 | session->pcc_config | |
503 | .keep_alive_pce_negotiated_timer_seconds = | |
504 | error_open_obj->open_keepalive; | |
505 | pcep_log( | |
506 | LOG_INFO, | |
507 | "%s: Open keep alive value [%d] rejected, using PCE value [%d]", | |
508 | __func__, | |
509 | session->pcc_config.keep_alive_seconds, | |
510 | session->pcc_config | |
511 | .keep_alive_pce_negotiated_timer_seconds); | |
512 | /* Cancel the timer, the timer will be set again with | |
513 | * the new value when this open message is sent */ | |
514 | cancel_timer(session->timer_id_keep_alive); | |
515 | session->timer_id_keep_alive = TIMER_ID_NOT_SET; | |
516 | } else { | |
517 | pcep_log( | |
518 | LOG_INFO, | |
519 | "%s: Can not reconcile Open with suggested keepalive [%d]", | |
520 | __func__, error_open_obj->open_keepalive); | |
521 | } | |
522 | } | |
523 | ||
524 | /* TODO reconcile the TLVs */ | |
525 | ||
526 | session_send_message(session, open_msg); | |
527 | reset_timer(session->timer_id_open_keep_alive); | |
528 | } | |
529 | ||
530 | ||
531 | bool handle_pcep_update(pcep_session *session, struct pcep_message *upd_msg) | |
532 | { | |
533 | /* Update Message validation and errors according to: | |
534 | * https://tools.ietf.org/html/rfc8231#section-6.2 */ | |
535 | ||
536 | if (upd_msg->obj_list == NULL) { | |
537 | pcep_log(LOG_INFO, | |
538 | "%s: Invalid PcUpd message: Message has no objects", | |
539 | __func__); | |
540 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
541 | PCEP_ERRV_SRP_OBJECT_MISSING); | |
542 | return false; | |
543 | } | |
544 | ||
545 | /* Verify the mandatory objects are present */ | |
546 | struct pcep_object_header *obj = | |
547 | pcep_obj_get(upd_msg->obj_list, PCEP_OBJ_CLASS_SRP); | |
548 | if (obj == NULL) { | |
549 | pcep_log(LOG_INFO, | |
550 | "%s: Invalid PcUpd message: Missing SRP object", | |
551 | __func__); | |
552 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
553 | PCEP_ERRV_SRP_OBJECT_MISSING); | |
554 | return false; | |
555 | } | |
556 | ||
557 | obj = pcep_obj_get(upd_msg->obj_list, PCEP_OBJ_CLASS_LSP); | |
558 | if (obj == NULL) { | |
559 | pcep_log(LOG_INFO, | |
560 | "%s: Invalid PcUpd message: Missing LSP object", | |
561 | __func__); | |
562 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
563 | PCEP_ERRV_LSP_OBJECT_MISSING); | |
564 | return false; | |
565 | } | |
566 | ||
567 | obj = pcep_obj_get(upd_msg->obj_list, PCEP_OBJ_CLASS_ERO); | |
568 | if (obj == NULL) { | |
569 | pcep_log(LOG_INFO, | |
570 | "%s: Invalid PcUpd message: Missing ERO object", | |
571 | __func__); | |
572 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
573 | PCEP_ERRV_ERO_OBJECT_MISSING); | |
574 | return false; | |
575 | } | |
576 | ||
577 | /* Verify the objects are are in the correct order */ | |
578 | double_linked_list_node *node = upd_msg->obj_list->head; | |
579 | struct pcep_object_srp *srp_object = | |
580 | (struct pcep_object_srp *)node->data; | |
581 | if (srp_object->header.object_class != PCEP_OBJ_CLASS_SRP) { | |
582 | pcep_log( | |
583 | LOG_INFO, | |
584 | "%s: Invalid PcUpd message: First object must be an SRP, found [%d]", | |
585 | __func__, srp_object->header.object_class); | |
586 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
587 | PCEP_ERRV_SRP_OBJECT_MISSING); | |
588 | return false; | |
589 | } | |
590 | ||
591 | node = node->next_node; | |
592 | struct pcep_object_lsp *lsp_object = | |
593 | (struct pcep_object_lsp *)node->data; | |
594 | if (lsp_object->header.object_class != PCEP_OBJ_CLASS_LSP) { | |
595 | pcep_log( | |
596 | LOG_INFO, | |
597 | "%s: Invalid PcUpd message: Second object must be an LSP, found [%d]", | |
598 | __func__, lsp_object->header.object_class); | |
599 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
600 | PCEP_ERRV_LSP_OBJECT_MISSING); | |
601 | return false; | |
602 | } | |
603 | ||
604 | node = node->next_node; | |
605 | struct pcep_object_ro *ero_object = node->data; | |
606 | if (ero_object->header.object_class != PCEP_OBJ_CLASS_ERO) { | |
607 | pcep_log( | |
608 | LOG_INFO, | |
609 | "%s: Invalid PcUpd message: Third object must be an ERO, found [%d]", | |
610 | __func__, ero_object->header.object_class); | |
611 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
612 | PCEP_ERRV_ERO_OBJECT_MISSING); | |
613 | return false; | |
614 | } | |
615 | ||
616 | return true; | |
617 | } | |
618 | ||
619 | bool handle_pcep_initiate(pcep_session *session, struct pcep_message *init_msg) | |
620 | { | |
621 | /* Instantiate Message validation and errors according to: | |
622 | * https://tools.ietf.org/html/rfc8281#section-5 */ | |
623 | ||
624 | if (init_msg->obj_list == NULL) { | |
625 | pcep_log( | |
626 | LOG_INFO, | |
627 | "%s: Invalid PcInitiate message: Message has no objects", | |
628 | __func__); | |
629 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
630 | PCEP_ERRV_SRP_OBJECT_MISSING); | |
631 | return false; | |
632 | } | |
633 | ||
634 | /* Verify the mandatory objects are present */ | |
635 | struct pcep_object_header *obj = | |
636 | pcep_obj_get(init_msg->obj_list, PCEP_OBJ_CLASS_SRP); | |
637 | if (obj == NULL) { | |
638 | pcep_log(LOG_INFO, | |
639 | "%s: Invalid PcInitiate message: Missing SRP object", | |
640 | __func__); | |
641 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
642 | PCEP_ERRV_SRP_OBJECT_MISSING); | |
643 | return false; | |
644 | } | |
645 | ||
646 | obj = pcep_obj_get(init_msg->obj_list, PCEP_OBJ_CLASS_LSP); | |
647 | if (obj == NULL) { | |
648 | pcep_log(LOG_INFO, | |
649 | "%s: Invalid PcInitiate message: Missing LSP object", | |
650 | __func__); | |
651 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
652 | PCEP_ERRV_LSP_OBJECT_MISSING); | |
653 | return false; | |
654 | } | |
655 | ||
656 | /* Verify the objects are are in the correct order */ | |
657 | double_linked_list_node *node = init_msg->obj_list->head; | |
658 | struct pcep_object_srp *srp_object = | |
659 | (struct pcep_object_srp *)node->data; | |
660 | if (srp_object->header.object_class != PCEP_OBJ_CLASS_SRP) { | |
661 | pcep_log( | |
662 | LOG_INFO, | |
663 | "%s: Invalid PcInitiate message: First object must be an SRP, found [%d]", | |
664 | __func__, srp_object->header.object_class); | |
665 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
666 | PCEP_ERRV_SRP_OBJECT_MISSING); | |
667 | return false; | |
668 | } | |
669 | ||
670 | node = node->next_node; | |
671 | struct pcep_object_lsp *lsp_object = | |
672 | (struct pcep_object_lsp *)node->data; | |
673 | if (lsp_object->header.object_class != PCEP_OBJ_CLASS_LSP) { | |
674 | pcep_log( | |
675 | LOG_INFO, | |
676 | "%s: Invalid PcInitiate message: Second object must be an LSP, found [%d]", | |
677 | __func__, lsp_object->header.object_class); | |
678 | send_pcep_error(session, PCEP_ERRT_MANDATORY_OBJECT_MISSING, | |
679 | PCEP_ERRV_LSP_OBJECT_MISSING); | |
680 | return false; | |
681 | } | |
682 | ||
683 | /* There may be more optional objects */ | |
684 | return true; | |
685 | } | |
686 | ||
687 | void increment_unknown_message(pcep_session *session) | |
688 | { | |
689 | /* https://tools.ietf.org/html/rfc5440#section-6.9 | |
690 | * If a PCC/PCE receives unrecognized messages at a rate equal or | |
691 | * greater than MAX-UNKNOWN-MESSAGES unknown message requests per | |
692 | * minute, the PCC/PCE MUST send a PCEP CLOSE message */ | |
693 | ||
694 | time_t *unknown_message_time = | |
695 | pceplib_malloc(PCEPLIB_INFRA, sizeof(time_t)); | |
696 | *unknown_message_time = time(NULL); | |
697 | time_t expire_time = *unknown_message_time + 60; | |
698 | queue_enqueue(session->num_unknown_messages_time_queue, | |
699 | unknown_message_time); | |
700 | ||
701 | /* Purge any entries older than 1 minute. The oldest entries are at the | |
702 | * queue head */ | |
703 | queue_node *time_node = session->num_unknown_messages_time_queue->head; | |
704 | while (time_node != NULL) { | |
705 | if (*((time_t *)time_node->data) > expire_time) { | |
706 | pceplib_free( | |
707 | PCEPLIB_INFRA, | |
708 | queue_dequeue( | |
709 | session->num_unknown_messages_time_queue)); | |
710 | time_node = | |
711 | session->num_unknown_messages_time_queue->head; | |
712 | } else { | |
713 | time_node = NULL; | |
714 | } | |
715 | } | |
716 | ||
717 | if ((int)session->num_unknown_messages_time_queue->num_entries | |
718 | >= session->pcc_config.max_unknown_messages) { | |
719 | pcep_log( | |
720 | LOG_INFO, | |
721 | "%s: [%ld-%ld] Max unknown messages reached [%d] closing session [%d]", | |
722 | __func__, time(NULL), pthread_self(), | |
723 | session->pcc_config.max_unknown_messages, | |
724 | session->session_id); | |
725 | ||
726 | close_pcep_session_with_reason(session, | |
727 | PCEP_CLOSE_REASON_UNREC_MSG); | |
728 | enqueue_event(session, PCC_RCVD_MAX_UNKOWN_MSGS, NULL); | |
729 | } | |
730 | } | |
731 | ||
732 | bool check_and_send_open_keep_alive(pcep_session *session) | |
733 | { | |
734 | if (session->pce_open_received == true | |
735 | && session->pce_open_rejected == false | |
736 | && session->pce_open_keep_alive_sent == false) { | |
737 | /* Send the PCE Open keep-alive response if it hasnt been sent | |
738 | * yet */ | |
739 | cancel_timer(session->timer_id_open_keep_alive); | |
740 | session->timer_id_open_keep_alive = TIMER_ID_NOT_SET; | |
741 | send_keep_alive(session); | |
742 | session->pce_open_keep_alive_sent = true; | |
743 | ||
744 | return true; | |
745 | } | |
746 | ||
747 | return false; | |
748 | } | |
749 | ||
750 | void log_pcc_pce_connection(pcep_session *session) | |
751 | { | |
752 | if (session->socket_comm_session == NULL) { | |
753 | /* This only happens in UT */ | |
754 | return; | |
755 | } | |
756 | ||
757 | char src_ip_buf[40] = {0}, dst_ip_buf[40] = {0}; | |
758 | uint16_t src_port, dst_port; | |
759 | ||
760 | if (session->socket_comm_session->is_ipv6) { | |
761 | inet_ntop(AF_INET6, | |
762 | &session->socket_comm_session->src_sock_addr | |
763 | .src_sock_addr_ipv6.sin6_addr, | |
764 | src_ip_buf, sizeof(src_ip_buf)); | |
765 | inet_ntop(AF_INET6, | |
766 | &session->socket_comm_session->dest_sock_addr | |
767 | .dest_sock_addr_ipv6.sin6_addr, | |
768 | dst_ip_buf, sizeof(dst_ip_buf)); | |
769 | src_port = htons(session->socket_comm_session->src_sock_addr | |
770 | .src_sock_addr_ipv6.sin6_port); | |
771 | dst_port = htons(session->socket_comm_session->dest_sock_addr | |
772 | .dest_sock_addr_ipv6.sin6_port); | |
773 | } else { | |
774 | inet_ntop(AF_INET, | |
775 | &session->socket_comm_session->src_sock_addr | |
776 | .src_sock_addr_ipv4.sin_addr, | |
777 | src_ip_buf, sizeof(src_ip_buf)); | |
778 | inet_ntop(AF_INET, | |
779 | &session->socket_comm_session->dest_sock_addr | |
780 | .dest_sock_addr_ipv4.sin_addr, | |
781 | dst_ip_buf, sizeof(dst_ip_buf)); | |
782 | src_port = htons(session->socket_comm_session->src_sock_addr | |
783 | .src_sock_addr_ipv4.sin_port); | |
784 | dst_port = htons(session->socket_comm_session->dest_sock_addr | |
785 | .dest_sock_addr_ipv4.sin_port); | |
786 | } | |
787 | ||
788 | pcep_log( | |
789 | LOG_INFO, | |
790 | "%s: [%ld-%ld] Successful PCC [%s:%d] connection to PCE [%s:%d] session [%d] fd [%d]", | |
791 | __func__, time(NULL), pthread_self(), src_ip_buf, src_port, | |
792 | dst_ip_buf, dst_port, session->session_id, | |
793 | session->socket_comm_session->socket_fd); | |
794 | } | |
795 | ||
796 | /* | |
797 | * these functions are called by session_logic_loop() from | |
798 | * pcep_session_logic_loop.c these functions are executed in the | |
799 | * session_logic_loop thread, and the mutex is locked before calling these | |
800 | * functions, so they are thread safe. | |
801 | */ | |
802 | ||
803 | /* state machine handling for expired timers */ | |
804 | void handle_timer_event(pcep_session_event *event) | |
805 | { | |
806 | if (event == NULL) { | |
807 | pcep_log(LOG_INFO, "%s: handle_timer_event NULL event", | |
808 | __func__); | |
809 | return; | |
810 | } | |
811 | ||
812 | pcep_session *session = event->session; | |
813 | ||
814 | pcep_log( | |
815 | LOG_INFO, | |
816 | "%s: [%ld-%ld] pcep_session_logic handle_timer_event: session [%d] event timer_id [%d] " | |
817 | "session timers [OKW, OKA, DT, KA] [%d, %d, %d, %d]", | |
818 | __func__, time(NULL), pthread_self(), session->session_id, | |
819 | event->expired_timer_id, session->timer_id_open_keep_wait, | |
820 | session->timer_id_open_keep_alive, session->timer_id_dead_timer, | |
821 | session->timer_id_keep_alive); | |
822 | ||
823 | /* | |
824 | * these timer expirations are independent of the session state | |
825 | */ | |
826 | if (event->expired_timer_id == session->timer_id_dead_timer) { | |
827 | session->timer_id_dead_timer = TIMER_ID_NOT_SET; | |
828 | increment_event_counters(session, | |
829 | PCEP_EVENT_COUNTER_ID_TIMER_DEADTIMER); | |
830 | close_pcep_session_with_reason(session, | |
831 | PCEP_CLOSE_REASON_DEADTIMER); | |
832 | enqueue_event(session, PCE_DEAD_TIMER_EXPIRED, NULL); | |
833 | return; | |
834 | } else if (event->expired_timer_id == session->timer_id_keep_alive) { | |
835 | session->timer_id_keep_alive = TIMER_ID_NOT_SET; | |
836 | increment_event_counters(session, | |
837 | PCEP_EVENT_COUNTER_ID_TIMER_KEEPALIVE); | |
838 | send_keep_alive(session); | |
839 | return; | |
840 | } | |
841 | ||
842 | /* | |
843 | * handle timers that depend on the session state | |
844 | */ | |
845 | switch (session->session_state) { | |
846 | case SESSION_STATE_PCEP_CONNECTING: | |
847 | if (event->expired_timer_id | |
848 | == session->timer_id_open_keep_wait) { | |
849 | /* close the TCP session */ | |
850 | pcep_log( | |
851 | LOG_INFO, | |
852 | "%s: handle_timer_event open_keep_wait timer expired for session [%d]", | |
853 | __func__, session->session_id); | |
854 | increment_event_counters( | |
855 | session, | |
856 | PCEP_EVENT_COUNTER_ID_TIMER_OPENKEEPWAIT); | |
857 | socket_comm_session_close_tcp_after_write( | |
858 | session->socket_comm_session); | |
859 | session->session_state = SESSION_STATE_INITIALIZED; | |
860 | session->timer_id_open_keep_wait = TIMER_ID_NOT_SET; | |
861 | enqueue_event(session, PCE_OPEN_KEEP_WAIT_TIMER_EXPIRED, | |
862 | NULL); | |
863 | } | |
864 | ||
865 | if (event->expired_timer_id | |
866 | == session->timer_id_open_keep_alive) { | |
867 | increment_event_counters( | |
868 | session, | |
869 | PCEP_EVENT_COUNTER_ID_TIMER_OPENKEEPALIVE); | |
870 | session->timer_id_open_keep_alive = TIMER_ID_NOT_SET; | |
871 | if (check_and_send_open_keep_alive(session) == true) { | |
872 | if (session->pcc_open_accepted == true | |
873 | && session->session_state | |
874 | != SESSION_STATE_PCEP_CONNECTED) { | |
875 | log_pcc_pce_connection(session); | |
876 | session->session_state = | |
877 | SESSION_STATE_PCEP_CONNECTED; | |
878 | increment_event_counters( | |
879 | session, | |
880 | PCEP_EVENT_COUNTER_ID_PCE_CONNECT); | |
881 | enqueue_event(session, | |
882 | PCC_CONNECTED_TO_PCE, | |
883 | NULL); | |
884 | } | |
885 | } | |
886 | return; | |
887 | } | |
888 | break; | |
889 | ||
890 | case SESSION_STATE_INITIALIZED: | |
891 | case SESSION_STATE_PCEP_CONNECTED: | |
892 | default: | |
893 | pcep_log( | |
894 | LOG_INFO, | |
895 | "%s: handle_timer_event unrecognized state transition, timer_id [%d] state [%d] session [%d]", | |
896 | __func__, event->expired_timer_id, | |
897 | session->session_state, session->session_id); | |
898 | break; | |
899 | } | |
900 | } | |
901 | ||
902 | /* State machine handling for received messages. | |
903 | * This event was created in session_logic_msg_ready_handler() in | |
904 | * pcep_session_logic_loop.c */ | |
905 | void handle_socket_comm_event(pcep_session_event *event) | |
906 | { | |
907 | if (event == NULL) { | |
908 | pcep_log(LOG_INFO, "%s: handle_socket_comm_event NULL event", | |
909 | __func__); | |
910 | return; | |
911 | } | |
912 | ||
913 | pcep_session *session = event->session; | |
914 | ||
915 | pcep_log( | |
916 | LOG_INFO, | |
917 | "%s: [%ld-%ld] pcep_session_logic handle_socket_comm_event: session [%d] num messages [%d] socket_closed [%d]", | |
918 | __func__, time(NULL), pthread_self(), session->session_id, | |
919 | (event->received_msg_list == NULL | |
920 | ? -1 | |
921 | : (int)event->received_msg_list->num_entries), | |
922 | event->socket_closed); | |
923 | ||
924 | /* | |
925 | * independent of the session state | |
926 | */ | |
927 | if (event->socket_closed) { | |
928 | pcep_log( | |
929 | LOG_INFO, | |
930 | "%s: handle_socket_comm_event socket closed for session [%d]", | |
931 | __func__, session->session_id); | |
932 | socket_comm_session_close_tcp(session->socket_comm_session); | |
933 | enqueue_event(session, PCE_CLOSED_SOCKET, NULL); | |
934 | if (session->session_state == SESSION_STATE_PCEP_CONNECTING) { | |
935 | enqueue_event(session, PCC_CONNECTION_FAILURE, NULL); | |
936 | } | |
937 | session->session_state = SESSION_STATE_INITIALIZED; | |
938 | increment_event_counters(session, | |
939 | PCEP_EVENT_COUNTER_ID_PCE_DISCONNECT); | |
940 | return; | |
941 | } | |
942 | ||
943 | reset_dead_timer(session); | |
944 | ||
945 | if (event->received_msg_list == NULL) { | |
946 | return; | |
947 | } | |
948 | ||
949 | /* Message received on socket */ | |
950 | double_linked_list_node *msg_node; | |
951 | for (msg_node = event->received_msg_list->head; msg_node != NULL; | |
952 | msg_node = msg_node->next_node) { | |
953 | bool message_enqueued = false; | |
954 | struct pcep_message *msg = | |
955 | (struct pcep_message *)msg_node->data; | |
956 | pcep_log(LOG_INFO, "%s: \t %s message", __func__, | |
957 | get_message_type_str(msg->msg_header->type)); | |
958 | ||
959 | increment_message_rx_counters(session, msg); | |
960 | ||
961 | switch (msg->msg_header->type) { | |
962 | case PCEP_TYPE_OPEN: | |
963 | /* handle_pcep_open() checks session state, and for | |
964 | * duplicate erroneous open messages, and replies with | |
965 | * error messages as needed. It also sets | |
966 | * pce_open_received. */ | |
967 | if (handle_pcep_open(session, msg) == true) { | |
968 | /* PCE Open Message Accepted */ | |
969 | enqueue_event(session, MESSAGE_RECEIVED, msg); | |
970 | message_enqueued = true; | |
971 | session->pce_open_accepted = true; | |
972 | session->pce_open_rejected = false; | |
973 | if (session->pcc_open_accepted) { | |
974 | /* If both the PCC and PCE Opens are | |
975 | * accepted, then the session is | |
976 | * connected */ | |
977 | ||
978 | check_and_send_open_keep_alive(session); | |
979 | log_pcc_pce_connection(session); | |
980 | session->session_state = | |
981 | SESSION_STATE_PCEP_CONNECTED; | |
982 | increment_event_counters( | |
983 | session, | |
984 | PCEP_EVENT_COUNTER_ID_PCE_CONNECT); | |
985 | enqueue_event(session, | |
986 | PCC_CONNECTED_TO_PCE, | |
987 | NULL); | |
988 | } | |
989 | } | |
990 | break; | |
991 | ||
992 | case PCEP_TYPE_KEEPALIVE: | |
993 | if (session->session_state | |
994 | == SESSION_STATE_PCEP_CONNECTING) { | |
995 | /* PCC Open Message Accepted */ | |
996 | cancel_timer(session->timer_id_open_keep_wait); | |
997 | session->timer_id_open_keep_wait = | |
998 | TIMER_ID_NOT_SET; | |
999 | session->pcc_open_accepted = true; | |
1000 | session->pcc_open_rejected = false; | |
1001 | check_and_send_open_keep_alive(session); | |
1002 | ||
1003 | if (session->pce_open_accepted) { | |
1004 | /* If both the PCC and PCE Opens are | |
1005 | * accepted, then the session is | |
1006 | * connected */ | |
1007 | log_pcc_pce_connection(session); | |
1008 | session->session_state = | |
1009 | SESSION_STATE_PCEP_CONNECTED; | |
1010 | increment_event_counters( | |
1011 | session, | |
1012 | PCEP_EVENT_COUNTER_ID_PCC_CONNECT); | |
1013 | enqueue_event(session, | |
1014 | PCC_CONNECTED_TO_PCE, | |
1015 | NULL); | |
1016 | } | |
1017 | } | |
1018 | /* The dead_timer was already reset above, so nothing | |
1019 | * extra to do here */ | |
1020 | break; | |
1021 | ||
1022 | case PCEP_TYPE_PCREP: | |
1023 | enqueue_event(session, MESSAGE_RECEIVED, msg); | |
1024 | message_enqueued = true; | |
1025 | break; | |
1026 | ||
1027 | case PCEP_TYPE_CLOSE: | |
1028 | session->session_state = SESSION_STATE_INITIALIZED; | |
1029 | socket_comm_session_close_tcp( | |
1030 | session->socket_comm_session); | |
1031 | /* TODO should we also enqueue the message, so they can | |
1032 | * see the reasons?? */ | |
1033 | enqueue_event(session, PCE_SENT_PCEP_CLOSE, NULL); | |
1034 | /* TODO could this duplicate the disconnect counter with | |
1035 | * socket close ?? */ | |
1036 | increment_event_counters( | |
1037 | session, PCEP_EVENT_COUNTER_ID_PCE_DISCONNECT); | |
1038 | break; | |
1039 | ||
1040 | case PCEP_TYPE_PCREQ: | |
1041 | /* The PCC does not support receiving PcReq messages */ | |
1042 | send_pcep_error(session, | |
1043 | PCEP_ERRT_CAPABILITY_NOT_SUPPORTED, | |
1044 | PCEP_ERRV_UNASSIGNED); | |
1045 | break; | |
1046 | ||
1047 | case PCEP_TYPE_REPORT: | |
1048 | /* The PCC does not support receiving Report messages */ | |
1049 | send_pcep_error(session, | |
1050 | PCEP_ERRT_CAPABILITY_NOT_SUPPORTED, | |
1051 | PCEP_ERRV_UNASSIGNED); | |
1052 | break; | |
1053 | ||
1054 | case PCEP_TYPE_UPDATE: | |
1055 | /* Should reply with a PcRpt */ | |
1056 | if (handle_pcep_update(session, msg) == true) { | |
1057 | enqueue_event(session, MESSAGE_RECEIVED, msg); | |
1058 | message_enqueued = true; | |
1059 | } | |
1060 | break; | |
1061 | ||
1062 | case PCEP_TYPE_INITIATE: | |
1063 | /* Should reply with a PcRpt */ | |
1064 | if (handle_pcep_initiate(session, msg) == true) { | |
1065 | enqueue_event(session, MESSAGE_RECEIVED, msg); | |
1066 | message_enqueued = true; | |
1067 | } | |
1068 | break; | |
1069 | ||
1070 | case PCEP_TYPE_PCNOTF: | |
1071 | enqueue_event(session, MESSAGE_RECEIVED, msg); | |
1072 | message_enqueued = true; | |
1073 | break; | |
1074 | ||
1075 | case PCEP_TYPE_ERROR: | |
1076 | if (msg->obj_list != NULL | |
1077 | && msg->obj_list->num_entries > 0) { | |
1078 | struct pcep_object_header *obj_hdr = | |
1079 | pcep_obj_get(msg->obj_list, | |
1080 | PCEP_OBJ_CLASS_ERROR); | |
1081 | if (obj_hdr != NULL) { | |
1082 | struct pcep_object_error *error_obj = | |
1083 | (struct pcep_object_error *) | |
1084 | obj_hdr; | |
1085 | pcep_log( | |
1086 | LOG_DEBUG, | |
1087 | "%s: Error object [type, value] = [%s, %s]", | |
1088 | __func__, | |
1089 | get_error_type_str( | |
1090 | error_obj->error_type), | |
1091 | get_error_value_str( | |
1092 | error_obj->error_type, | |
1093 | error_obj | |
1094 | ->error_value)); | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | if (session->session_state | |
1099 | == SESSION_STATE_PCEP_CONNECTING) { | |
1100 | /* A PCC_CONNECTION_FAILURE event will be sent | |
1101 | * when the socket is closed, if the state is | |
1102 | * SESSION_STATE_PCEP_CONNECTING, in case the | |
1103 | * PCE allows more than 2 failed open messages. | |
1104 | */ | |
1105 | pcep_log(LOG_INFO, | |
1106 | "%s: PCC Open message rejected by PCE", | |
1107 | __func__); | |
1108 | session->pcc_open_rejected = true; | |
1109 | send_reconciled_pcep_open(session, msg); | |
1110 | enqueue_event(session, PCC_SENT_INVALID_OPEN, | |
1111 | NULL); | |
1112 | } | |
1113 | enqueue_event(session, MESSAGE_RECEIVED, msg); | |
1114 | message_enqueued = true; | |
1115 | break; | |
1116 | ||
1117 | default: | |
1118 | pcep_log(LOG_INFO, "%s: \t UnSupported message", | |
1119 | __func__); | |
1120 | send_pcep_error(session, | |
1121 | PCEP_ERRT_CAPABILITY_NOT_SUPPORTED, | |
1122 | PCEP_ERRV_UNASSIGNED); | |
1123 | increment_unknown_message(session); | |
1124 | break; | |
1125 | } | |
1126 | ||
1127 | /* if the message was enqueued, dont free it yet */ | |
1128 | if (message_enqueued == false) { | |
1129 | pcep_msg_free_message(msg); | |
1130 | } | |
1131 | } | |
1132 | dll_destroy(event->received_msg_list); | |
1133 | } |