1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
|
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* This file is part of the PCEPlib, a PCEP protocol library.
*
* Copyright (C) 2020 Volta Networks https://voltanet.io/
*
* Author : Brady Johnson <brady@voltanet.io>
*
*/
/*
* This is the implementation of a High Level PCEP message object API.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <unistd.h>
#include "pcep_msg_objects.h"
#include "pcep_msg_tlvs.h"
#include "pcep_utils_double_linked_list.h"
#include "pcep_utils_logging.h"
#include "pcep_utils_memory.h"
/* Internal common function used to create a pcep_object and populate the header
*/
static struct pcep_object_header *pcep_obj_create_common_with_tlvs(
uint8_t obj_length, enum pcep_object_classes object_class,
enum pcep_object_types object_type, double_linked_list *tlv_list)
{
uint8_t *buffer = pceplib_malloc(PCEPLIB_MESSAGES, obj_length);
memset(buffer, 0, obj_length);
/* The flag_p and flag_i flags will be set externally */
struct pcep_object_header *hdr = (struct pcep_object_header *)buffer;
hdr->object_class = object_class;
hdr->object_type = object_type;
hdr->tlv_list = tlv_list;
return hdr;
}
static struct pcep_object_header *
pcep_obj_create_common(uint8_t obj_length,
enum pcep_object_classes object_class,
enum pcep_object_types object_type)
{
return pcep_obj_create_common_with_tlvs(obj_length, object_class,
object_type, NULL);
}
struct pcep_object_open *pcep_obj_create_open(uint8_t keepalive,
uint8_t deadtimer, uint8_t sid,
double_linked_list *tlv_list)
{
struct pcep_object_open *open =
(struct pcep_object_open *)pcep_obj_create_common_with_tlvs(
sizeof(struct pcep_object_open), PCEP_OBJ_CLASS_OPEN,
PCEP_OBJ_TYPE_OPEN, tlv_list);
open->open_version =
PCEP_OBJECT_OPEN_VERSION; /* PCEP version. Current version is 1
/No flags are currently defined. */
open->open_keepalive =
keepalive; /* Maximum period of time between two consecutive
PCEP messages sent by the sender. */
open->open_deadtimer = deadtimer; /* Specifies the amount of time before
closing the session down. */
open->open_sid = sid; /* PCEP session number that identifies the current
session. */
return open;
}
struct pcep_object_rp *pcep_obj_create_rp(uint8_t priority, bool flag_r,
bool flag_b, bool flag_s,
bool flag_of, uint32_t reqid,
double_linked_list *tlv_list)
{
if (priority > OBJECT_RP_MAX_PRIORITY) {
pcep_log(
LOG_INFO,
"%s: Error creating RP object, invalid priority [%d], max priority [%d].",
__func__, priority, OBJECT_RP_MAX_PRIORITY);
return NULL;
}
struct pcep_object_rp *obj =
(struct pcep_object_rp *)pcep_obj_create_common_with_tlvs(
sizeof(struct pcep_object_rp), PCEP_OBJ_CLASS_RP,
PCEP_OBJ_TYPE_RP, tlv_list);
obj->priority = priority;
obj->flag_reoptimization = flag_r;
obj->flag_bidirectional = flag_b;
obj->flag_strict = flag_s;
obj->flag_of = flag_of;
obj->request_id = reqid;
return obj;
}
struct pcep_object_notify *
pcep_obj_create_notify(enum pcep_notification_types notification_type,
enum pcep_notification_values notification_value)
{
struct pcep_object_notify *obj =
(struct pcep_object_notify *)pcep_obj_create_common(
sizeof(struct pcep_object_notify), PCEP_OBJ_CLASS_NOTF,
PCEP_OBJ_TYPE_NOTF);
obj->notification_type = notification_type;
obj->notification_value = notification_value;
return obj;
}
struct pcep_object_nopath *
pcep_obj_create_nopath(uint8_t ni, bool flag_c,
enum pcep_nopath_tlv_err_codes error_code)
{
struct pcep_object_tlv_nopath_vector *tlv =
pcep_tlv_create_nopath_vector(error_code);
double_linked_list *tlv_list = dll_initialize();
dll_append(tlv_list, tlv);
struct pcep_object_nopath *obj =
(struct pcep_object_nopath *)pcep_obj_create_common_with_tlvs(
sizeof(struct pcep_object_nopath),
PCEP_OBJ_CLASS_NOPATH, PCEP_OBJ_TYPE_NOPATH, tlv_list);
obj->ni = ni;
obj->flag_c = flag_c;
obj->err_code = error_code;
return obj;
}
struct pcep_object_association_ipv4 *
pcep_obj_create_association_ipv4(bool r_flag, uint16_t association_type,
uint16_t association_id, struct in_addr src)
{
struct pcep_object_association_ipv4 *obj =
(struct pcep_object_association_ipv4 *)pcep_obj_create_common(
sizeof(struct pcep_object_association_ipv4),
PCEP_OBJ_CLASS_ASSOCIATION,
PCEP_OBJ_TYPE_ASSOCIATION_IPV4);
obj->R_flag = r_flag;
obj->association_type = association_type;
obj->association_id = association_id;
obj->src = src;
return obj;
}
struct pcep_object_association_ipv6 *
pcep_obj_create_association_ipv6(bool r_flag, uint16_t association_type,
uint16_t association_id, struct in6_addr src)
{
struct pcep_object_association_ipv6 *obj =
(struct pcep_object_association_ipv6 *)pcep_obj_create_common(
sizeof(struct pcep_object_association_ipv6),
PCEP_OBJ_CLASS_ASSOCIATION,
PCEP_OBJ_TYPE_ASSOCIATION_IPV6);
obj->R_flag = r_flag;
obj->association_type = association_type;
obj->association_id = association_id;
obj->src = src;
return obj;
}
struct pcep_object_endpoints_ipv4 *
pcep_obj_create_endpoint_ipv4(const struct in_addr *src_ipv4,
const struct in_addr *dst_ipv4)
{
if (src_ipv4 == NULL || dst_ipv4 == NULL) {
return NULL;
}
struct pcep_object_endpoints_ipv4 *obj =
(struct pcep_object_endpoints_ipv4 *)pcep_obj_create_common(
sizeof(struct pcep_object_endpoints_ipv4),
PCEP_OBJ_CLASS_ENDPOINTS, PCEP_OBJ_TYPE_ENDPOINT_IPV4);
obj->src_ipv4.s_addr = src_ipv4->s_addr;
obj->dst_ipv4.s_addr = dst_ipv4->s_addr;
return obj;
}
struct pcep_object_endpoints_ipv6 *
pcep_obj_create_endpoint_ipv6(const struct in6_addr *src_ipv6,
const struct in6_addr *dst_ipv6)
{
if (src_ipv6 == NULL || dst_ipv6 == NULL) {
return NULL;
}
struct pcep_object_endpoints_ipv6 *obj =
(struct pcep_object_endpoints_ipv6 *)pcep_obj_create_common(
sizeof(struct pcep_object_endpoints_ipv6),
PCEP_OBJ_CLASS_ENDPOINTS, PCEP_OBJ_TYPE_ENDPOINT_IPV6);
memcpy(&obj->src_ipv6, src_ipv6, sizeof(struct in6_addr));
memcpy(&obj->dst_ipv6, dst_ipv6, sizeof(struct in6_addr));
return obj;
}
struct pcep_object_bandwidth *pcep_obj_create_bandwidth(float bandwidth)
{
struct pcep_object_bandwidth *obj =
(struct pcep_object_bandwidth *)pcep_obj_create_common(
sizeof(struct pcep_object_bandwidth),
PCEP_OBJ_CLASS_BANDWIDTH, PCEP_OBJ_TYPE_BANDWIDTH_REQ);
obj->bandwidth = bandwidth;
return obj;
}
struct pcep_object_metric *pcep_obj_create_metric(enum pcep_metric_types type,
bool flag_b, bool flag_c,
float value)
{
struct pcep_object_metric *obj =
(struct pcep_object_metric *)pcep_obj_create_common(
sizeof(struct pcep_object_metric),
PCEP_OBJ_CLASS_METRIC, PCEP_OBJ_TYPE_METRIC);
obj->flag_b = flag_b;
obj->flag_c = flag_c;
obj->type = type;
obj->value = value;
return obj;
}
struct pcep_object_lspa *
pcep_obj_create_lspa(uint32_t exclude_any, uint32_t include_any,
uint32_t include_all, uint8_t setup_priority,
uint8_t holding_priority, bool flag_local_protection)
{
struct pcep_object_lspa *obj =
(struct pcep_object_lspa *)pcep_obj_create_common(
sizeof(struct pcep_object_lspa), PCEP_OBJ_CLASS_LSPA,
PCEP_OBJ_TYPE_LSPA);
obj->lspa_exclude_any = exclude_any;
obj->lspa_include_any = include_any;
obj->lspa_include_all = include_all;
obj->setup_priority = setup_priority;
obj->holding_priority = holding_priority;
obj->flag_local_protection = flag_local_protection;
return obj;
}
struct pcep_object_svec *
pcep_obj_create_svec(bool srlg, bool node, bool link,
double_linked_list *request_id_list)
{
if (request_id_list == NULL) {
return NULL;
}
struct pcep_object_svec *obj =
(struct pcep_object_svec *)pcep_obj_create_common(
sizeof(struct pcep_object_svec), PCEP_OBJ_CLASS_SVEC,
PCEP_OBJ_TYPE_SVEC);
obj->flag_srlg_diverse = srlg;
obj->flag_node_diverse = node;
obj->flag_link_diverse = link;
obj->request_id_list = request_id_list;
return obj;
}
struct pcep_object_error *
pcep_obj_create_error(enum pcep_error_type error_type,
enum pcep_error_value error_value)
{
struct pcep_object_error *obj =
(struct pcep_object_error *)pcep_obj_create_common(
sizeof(struct pcep_object_error), PCEP_OBJ_CLASS_ERROR,
PCEP_OBJ_TYPE_ERROR);
obj->error_type = error_type;
obj->error_value = error_value;
return obj;
}
struct pcep_object_close *pcep_obj_create_close(enum pcep_close_reason reason)
{
struct pcep_object_close *obj =
(struct pcep_object_close *)pcep_obj_create_common(
sizeof(struct pcep_object_close), PCEP_OBJ_CLASS_CLOSE,
PCEP_OBJ_TYPE_CLOSE);
obj->reason = reason;
return obj;
}
struct pcep_object_srp *pcep_obj_create_srp(bool lsp_remove,
uint32_t srp_id_number,
double_linked_list *tlv_list)
{
struct pcep_object_srp *obj =
(struct pcep_object_srp *)pcep_obj_create_common_with_tlvs(
sizeof(struct pcep_object_srp), PCEP_OBJ_CLASS_SRP,
PCEP_OBJ_TYPE_SRP, tlv_list);
obj->flag_lsp_remove = lsp_remove;
obj->srp_id_number = srp_id_number;
return obj;
}
struct pcep_object_lsp *
pcep_obj_create_lsp(uint32_t plsp_id, enum pcep_lsp_operational_status status,
bool c_flag, bool a_flag, bool r_flag, bool s_flag,
bool d_flag, double_linked_list *tlv_list)
{
/* The plsp_id is only 20 bits */
if (plsp_id > MAX_PLSP_ID) {
pcep_log(
LOG_INFO,
"%s: pcep_obj_create_lsp invalid plsp_id [%d] max value [%d]",
__func__, plsp_id, MAX_PLSP_ID);
return NULL;
}
/* The status is only 3 bits */
if (status > MAX_LSP_STATUS) {
pcep_log(
LOG_INFO,
"%s: pcep_obj_create_lsp invalid status [%d] max value [%d]",
__func__, plsp_id, MAX_PLSP_ID);
return NULL;
}
struct pcep_object_lsp *obj =
(struct pcep_object_lsp *)pcep_obj_create_common_with_tlvs(
sizeof(struct pcep_object_lsp), PCEP_OBJ_CLASS_LSP,
PCEP_OBJ_TYPE_LSP, tlv_list);
obj->plsp_id = plsp_id;
obj->operational_status = status;
obj->flag_c = c_flag;
obj->flag_a = a_flag;
obj->flag_r = r_flag;
obj->flag_s = s_flag;
obj->flag_d = d_flag;
return obj;
}
struct pcep_object_vendor_info *
pcep_obj_create_vendor_info(uint32_t enterprise_number,
uint32_t enterprise_spec_info)
{
struct pcep_object_vendor_info *obj =
(struct pcep_object_vendor_info *)pcep_obj_create_common(
sizeof(struct pcep_object_vendor_info),
PCEP_OBJ_CLASS_VENDOR_INFO, PCEP_OBJ_TYPE_VENDOR_INFO);
obj->enterprise_number = enterprise_number;
obj->enterprise_specific_info = enterprise_spec_info;
return obj;
}
struct pcep_object_inter_layer *
pcep_obj_create_inter_layer(bool flag_i, bool flag_m, bool flag_t)
{
struct pcep_object_inter_layer *obj =
(struct pcep_object_inter_layer *)pcep_obj_create_common(
sizeof(struct pcep_object_inter_layer),
PCEP_OBJ_CLASS_INTER_LAYER, PCEP_OBJ_TYPE_INTER_LAYER);
obj->flag_i = flag_i;
obj->flag_m = flag_m;
obj->flag_t = flag_t;
return obj;
}
struct pcep_object_switch_layer *
pcep_obj_create_switch_layer(double_linked_list *switch_layer_rows)
{
struct pcep_object_switch_layer *obj =
(struct pcep_object_switch_layer *)pcep_obj_create_common(
sizeof(struct pcep_object_switch_layer),
PCEP_OBJ_CLASS_SWITCH_LAYER,
PCEP_OBJ_TYPE_SWITCH_LAYER);
obj->switch_layer_rows = switch_layer_rows;
return obj;
}
struct pcep_object_req_adap_cap *
pcep_obj_create_req_adap_cap(enum pcep_switching_capability sw_cap,
enum pcep_lsp_encoding_type encoding)
{
struct pcep_object_req_adap_cap *obj =
(struct pcep_object_req_adap_cap *)pcep_obj_create_common(
sizeof(struct pcep_object_req_adap_cap),
PCEP_OBJ_CLASS_REQ_ADAP_CAP,
PCEP_OBJ_TYPE_REQ_ADAP_CAP);
obj->switching_capability = sw_cap;
obj->encoding = encoding;
return obj;
}
struct pcep_object_server_indication *
pcep_obj_create_server_indication(enum pcep_switching_capability sw_cap,
enum pcep_lsp_encoding_type encoding,
double_linked_list *tlv_list)
{
struct pcep_object_server_indication *obj =
(struct pcep_object_server_indication *)
pcep_obj_create_common_with_tlvs(
sizeof(struct pcep_object_server_indication),
PCEP_OBJ_CLASS_SERVER_IND,
PCEP_OBJ_TYPE_SERVER_IND, tlv_list);
obj->switching_capability = sw_cap;
obj->encoding = encoding;
return obj;
}
struct pcep_object_objective_function *
pcep_obj_create_objective_function(uint16_t of_code,
double_linked_list *tlv_list)
{
struct pcep_object_objective_function *obj =
(struct pcep_object_objective_function *)
pcep_obj_create_common_with_tlvs(
sizeof(struct pcep_object_objective_function),
PCEP_OBJ_CLASS_OF, PCEP_OBJ_TYPE_OF, tlv_list);
obj->of_code = of_code;
return obj;
}
/* Wrap a list of ro subobjects in a structure with an object header */
struct pcep_object_ro *pcep_obj_create_ero(double_linked_list *ero_list)
{
struct pcep_object_ro *ero =
(struct pcep_object_ro *)pcep_obj_create_common(
sizeof(struct pcep_object_ro), PCEP_OBJ_CLASS_ERO,
PCEP_OBJ_TYPE_ERO);
ero->sub_objects = ero_list;
return ero;
}
/* Wrap a list of ro subobjects in a structure with an object header */
struct pcep_object_ro *pcep_obj_create_iro(double_linked_list *iro_list)
{
struct pcep_object_ro *iro =
(struct pcep_object_ro *)pcep_obj_create_common(
sizeof(struct pcep_object_ro), PCEP_OBJ_CLASS_IRO,
PCEP_OBJ_TYPE_IRO);
iro->sub_objects = iro_list;
return iro;
}
/* Wrap a list of ro subobjects in a structure with an object header */
struct pcep_object_ro *pcep_obj_create_rro(double_linked_list *rro_list)
{
struct pcep_object_ro *rro =
(struct pcep_object_ro *)pcep_obj_create_common(
sizeof(struct pcep_object_ro), PCEP_OBJ_CLASS_RRO,
PCEP_OBJ_TYPE_RRO);
rro->sub_objects = rro_list;
return rro;
}
/*
* Route Object Sub-object creation functions
*/
static struct pcep_object_ro_subobj *
pcep_obj_create_ro_subobj_common(uint8_t subobj_size,
enum pcep_ro_subobj_types ro_subobj_type,
bool flag_subobj_loose_hop)
{
struct pcep_object_ro_subobj *ro_subobj =
pceplib_malloc(PCEPLIB_MESSAGES, subobj_size);
memset(ro_subobj, 0, subobj_size);
ro_subobj->flag_subobj_loose_hop = flag_subobj_loose_hop;
ro_subobj->ro_subobj_type = ro_subobj_type;
return ro_subobj;
}
struct pcep_ro_subobj_ipv4 *
pcep_obj_create_ro_subobj_ipv4(bool loose_hop, const struct in_addr *rro_ipv4,
uint8_t prefix_length, bool flag_local_prot)
{
if (rro_ipv4 == NULL) {
return NULL;
}
struct pcep_ro_subobj_ipv4 *obj =
(struct pcep_ro_subobj_ipv4 *)pcep_obj_create_ro_subobj_common(
sizeof(struct pcep_ro_subobj_ipv4), RO_SUBOBJ_TYPE_IPV4,
loose_hop);
obj->ip_addr.s_addr = rro_ipv4->s_addr;
obj->prefix_length = prefix_length;
obj->flag_local_protection = flag_local_prot;
return obj;
}
struct pcep_ro_subobj_ipv6 *
pcep_obj_create_ro_subobj_ipv6(bool loose_hop, const struct in6_addr *rro_ipv6,
uint8_t prefix_length, bool flag_local_prot)
{
if (rro_ipv6 == NULL) {
return NULL;
}
struct pcep_ro_subobj_ipv6 *obj =
(struct pcep_ro_subobj_ipv6 *)pcep_obj_create_ro_subobj_common(
sizeof(struct pcep_ro_subobj_ipv6), RO_SUBOBJ_TYPE_IPV6,
loose_hop);
obj->prefix_length = prefix_length;
obj->flag_local_protection = flag_local_prot;
memcpy(&obj->ip_addr, rro_ipv6, sizeof(struct in6_addr));
return obj;
}
struct pcep_ro_subobj_unnum *
pcep_obj_create_ro_subobj_unnum(struct in_addr *router_id, uint32_t if_id)
{
if (router_id == NULL) {
return NULL;
}
struct pcep_ro_subobj_unnum *obj =
(struct pcep_ro_subobj_unnum *)pcep_obj_create_ro_subobj_common(
sizeof(struct pcep_ro_subobj_unnum),
RO_SUBOBJ_TYPE_UNNUM, false);
obj->interface_id = if_id;
obj->router_id.s_addr = router_id->s_addr;
return obj;
}
struct pcep_ro_subobj_32label *
pcep_obj_create_ro_subobj_32label(bool flag_global_label, uint8_t class_type,
uint32_t label)
{
struct pcep_ro_subobj_32label *obj = (struct pcep_ro_subobj_32label *)
pcep_obj_create_ro_subobj_common(
sizeof(struct pcep_ro_subobj_32label),
RO_SUBOBJ_TYPE_LABEL, false);
obj->class_type = class_type;
obj->flag_global_label = flag_global_label;
obj->label = label;
return obj;
}
struct pcep_ro_subobj_asn *pcep_obj_create_ro_subobj_asn(uint16_t asn)
{
struct pcep_ro_subobj_asn *obj =
(struct pcep_ro_subobj_asn *)pcep_obj_create_ro_subobj_common(
sizeof(struct pcep_ro_subobj_asn), RO_SUBOBJ_TYPE_ASN,
false);
obj->asn = asn;
return obj;
}
/* Internal util function to create pcep_ro_subobj_sr sub-objects */
static struct pcep_ro_subobj_sr *
pcep_obj_create_ro_subobj_sr_common(enum pcep_sr_subobj_nai nai_type,
bool loose_hop, bool f_flag, bool s_flag,
bool c_flag_in, bool m_flag_in)
{
struct pcep_ro_subobj_sr *obj =
(struct pcep_ro_subobj_sr *)pcep_obj_create_ro_subobj_common(
sizeof(struct pcep_ro_subobj_sr), RO_SUBOBJ_TYPE_SR,
loose_hop);
/* Flag logic according to draft-ietf-pce-segment-routing-16 */
bool c_flag = c_flag_in;
bool m_flag = m_flag_in;
if (s_flag) {
c_flag = false;
m_flag = false;
}
if (m_flag == false) {
c_flag = false;
}
obj->nai_type = nai_type;
obj->flag_f = f_flag;
obj->flag_s = s_flag;
obj->flag_c = c_flag;
obj->flag_m = m_flag;
return obj;
}
struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_nonai(bool loose_hop,
uint32_t sid,
bool c_flag,
bool m_flag)
{
/* According to draft-ietf-pce-segment-routing-16#section-5.2.1
* If NT=0, the F bit MUST be 1, the S bit MUST be zero and the
* Length MUST be 8. */
struct pcep_ro_subobj_sr *obj = pcep_obj_create_ro_subobj_sr_common(
PCEP_SR_SUBOBJ_NAI_ABSENT, loose_hop, true, false, c_flag,
m_flag);
obj->sid = sid;
return obj;
}
struct pcep_ro_subobj_sr *
pcep_obj_create_ro_subobj_sr_ipv4_node(bool loose_hop, bool sid_absent,
bool c_flag, bool m_flag, uint32_t sid,
struct in_addr *ipv4_node_id)
{
if (ipv4_node_id == NULL) {
return NULL;
}
/* According to draft-ietf-pce-segment-routing-16#section-5.2.1
* If NT=1, the F bit MUST be zero. If the S bit is 1, the Length
* MUST be 8, otherwise the Length MUST be 12 */
struct pcep_ro_subobj_sr *obj = pcep_obj_create_ro_subobj_sr_common(
PCEP_SR_SUBOBJ_NAI_IPV4_NODE, loose_hop, false, sid_absent,
c_flag, m_flag);
if (!sid_absent) {
obj->sid = sid;
}
obj->nai_list = dll_initialize();
/* Since the IP has to be stored in the list, copy it so the caller
* doesn't have any restrictions about the type of memory used
* externally for the IP. This memory will be freed with the object is
* freed. */
struct in_addr *ipv4_node_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in_addr));
ipv4_node_id_copy->s_addr = ipv4_node_id->s_addr;
dll_append(obj->nai_list, ipv4_node_id_copy);
return obj;
}
struct pcep_ro_subobj_sr *
pcep_obj_create_ro_subobj_sr_ipv6_node(bool loose_hop, bool sid_absent,
bool c_flag, bool m_flag, uint32_t sid,
struct in6_addr *ipv6_node_id)
{
if (ipv6_node_id == NULL) {
return NULL;
}
/* According to draft-ietf-pce-segment-routing-16#section-5.2.1
* If NT=2, the F bit MUST be zero. If the S bit is 1, the Length
* MUST be 20, otherwise the Length MUST be 24. */
struct pcep_ro_subobj_sr *obj = pcep_obj_create_ro_subobj_sr_common(
PCEP_SR_SUBOBJ_NAI_IPV6_NODE, loose_hop, false, sid_absent,
c_flag, m_flag);
if (!sid_absent) {
obj->sid = sid;
}
obj->nai_list = dll_initialize();
struct in6_addr *ipv6_node_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
memcpy(ipv6_node_id_copy, ipv6_node_id, sizeof(struct in6_addr));
dll_append(obj->nai_list, ipv6_node_id_copy);
return obj;
}
struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_ipv4_adj(
bool loose_hop, bool sid_absent, bool c_flag, bool m_flag, uint32_t sid,
struct in_addr *local_ipv4, struct in_addr *remote_ipv4)
{
if (local_ipv4 == NULL || remote_ipv4 == NULL) {
return NULL;
}
/* According to draft-ietf-pce-segment-routing-16#section-5.2.1
* If NT=3, the F bit MUST be zero. If the S bit is 1, the Length
* MUST be 12, otherwise the Length MUST be 16 */
struct pcep_ro_subobj_sr *obj = pcep_obj_create_ro_subobj_sr_common(
PCEP_SR_SUBOBJ_NAI_IPV4_ADJACENCY, loose_hop, false, sid_absent,
c_flag, m_flag);
if (!sid_absent) {
obj->sid = sid;
}
obj->nai_list = dll_initialize();
struct in_addr *local_ipv4_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in_addr));
struct in_addr *remote_ipv4_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in_addr));
local_ipv4_copy->s_addr = local_ipv4->s_addr;
remote_ipv4_copy->s_addr = remote_ipv4->s_addr;
dll_append(obj->nai_list, local_ipv4_copy);
dll_append(obj->nai_list, remote_ipv4_copy);
return obj;
}
struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_ipv6_adj(
bool loose_hop, bool sid_absent, bool c_flag, bool m_flag, uint32_t sid,
struct in6_addr *local_ipv6, struct in6_addr *remote_ipv6)
{
if (local_ipv6 == NULL || remote_ipv6 == NULL) {
return NULL;
}
/* According to draft-ietf-pce-segment-routing-16#section-5.2.1
* If NT=4, the F bit MUST be zero. If the S bit is 1, the Length
* MUST be 36, otherwise the Length MUST be 40 */
struct pcep_ro_subobj_sr *obj = pcep_obj_create_ro_subobj_sr_common(
PCEP_SR_SUBOBJ_NAI_IPV6_ADJACENCY, loose_hop, false, sid_absent,
c_flag, m_flag);
if (!sid_absent) {
obj->sid = sid;
}
obj->nai_list = dll_initialize();
struct in6_addr *local_ipv6_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
struct in6_addr *remote_ipv6_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
memcpy(local_ipv6_copy, local_ipv6, sizeof(struct in6_addr));
memcpy(remote_ipv6_copy, remote_ipv6, sizeof(struct in6_addr));
dll_append(obj->nai_list, local_ipv6_copy);
dll_append(obj->nai_list, remote_ipv6_copy);
return obj;
}
struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_unnumbered_ipv4_adj(
bool loose_hop, bool sid_absent, bool c_flag, bool m_flag, uint32_t sid,
uint32_t local_node_id, uint32_t local_if_id, uint32_t remote_node_id,
uint32_t remote_if_id)
{
/* According to draft-ietf-pce-segment-routing-16#section-5.2.1
* If NT=5, the F bit MUST be zero. If the S bit is 1, the Length
* MUST be 20, otherwise the Length MUST be 24. */
struct pcep_ro_subobj_sr *obj = pcep_obj_create_ro_subobj_sr_common(
PCEP_SR_SUBOBJ_NAI_UNNUMBERED_IPV4_ADJACENCY, loose_hop, false,
sid_absent, c_flag, m_flag);
if (!sid_absent) {
obj->sid = sid;
}
obj->nai_list = dll_initialize();
uint32_t *local_node_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
*local_node_id_copy = local_node_id;
dll_append(obj->nai_list, local_node_id_copy);
uint32_t *local_if_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
*local_if_id_copy = local_if_id;
dll_append(obj->nai_list, local_if_id_copy);
uint32_t *remote_node_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
*remote_node_id_copy = remote_node_id;
dll_append(obj->nai_list, remote_node_id_copy);
uint32_t *remote_if_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
*remote_if_id_copy = remote_if_id;
dll_append(obj->nai_list, remote_if_id_copy);
return obj;
}
struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_linklocal_ipv6_adj(
bool loose_hop, bool sid_absent, bool c_flag, bool m_flag, uint32_t sid,
struct in6_addr *local_ipv6, uint32_t local_if_id,
struct in6_addr *remote_ipv6, uint32_t remote_if_id)
{
if (local_ipv6 == NULL || remote_ipv6 == NULL) {
return NULL;
}
/* According to draft-ietf-pce-segment-routing-16#section-5.2.1
* If NT=6, the F bit MUST be zero. If the S bit is 1, the Length
* MUST be 44, otherwise the Length MUST be 48 */
struct pcep_ro_subobj_sr *obj = pcep_obj_create_ro_subobj_sr_common(
PCEP_SR_SUBOBJ_NAI_LINK_LOCAL_IPV6_ADJACENCY, loose_hop, false,
sid_absent, c_flag, m_flag);
if (!sid_absent) {
obj->sid = sid;
}
obj->nai_list = dll_initialize();
struct in6_addr *local_ipv6_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
memcpy(local_ipv6_copy, local_ipv6, sizeof(struct in6_addr));
dll_append(obj->nai_list, local_ipv6_copy);
uint32_t *local_if_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
*local_if_id_copy = local_if_id;
dll_append(obj->nai_list, local_if_id_copy);
struct in6_addr *remote_ipv6_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
memcpy(remote_ipv6_copy, remote_ipv6, sizeof(struct in6_addr));
dll_append(obj->nai_list, remote_ipv6_copy);
uint32_t *remote_if_id_copy =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
*remote_if_id_copy = remote_if_id;
dll_append(obj->nai_list, remote_if_id_copy);
return obj;
}
|