Skip to content

Commit fa4dca9

Browse files
committed
pceplib, pathd: Convert pceplib to use our ALLOC functions
Currently pceplib has this dual world where it tries to be able to use different memory managers. This is just wasteful extra coding and let's just remove it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
1 parent 52930b6 commit fa4dca9

42 files changed

Lines changed: 286 additions & 977 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/developer/pceplib.rst

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -370,27 +370,6 @@ PCEPlib PCC initialization and destruction functions:
370370

371371
The ``pceplib_infra_config`` struct has the following fields:
372372

373-
- **void *pceplib_infra_mt**
374-
- FRR Memory type pointer for infra related memory management
375-
376-
- **void *pceplib_messages_mt**
377-
- FRR Memory type pointer for PCEP messages related memory management
378-
379-
- **pceplib_malloc_func mfunc**
380-
- FRR malloc function pointer
381-
382-
- **pceplib_calloc_func cfunc**
383-
- FRR calloc function pointer
384-
385-
- **pceplib_realloc_func rfunc**
386-
- FRR realloc function pointer
387-
388-
- **pceplib_strdup_func sfunc**
389-
- FRR strdup function pointer
390-
391-
- **pceplib_free_func ffunc**
392-
- FRR free function pointer
393-
394373
- **void *external_infra_data**
395374
- FRR data used by FRR timers and sockets infrastructure
396375

pathd/path_pcep_lib.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include "pathd/path_pcep_lib.h"
1616
#include "pathd/path_pcep_debug.h"
1717

18-
DEFINE_MTYPE_STATIC(PATHD, PCEPLIB_INFRA, "PCEPlib Infrastructure");
19-
DEFINE_MTYPE_STATIC(PATHD, PCEPLIB_MESSAGES, "PCEPlib PCEP Messages");
20-
2118
#define CLASS_TYPE(CLASS, TYPE) (((CLASS) << 16) | (TYPE))
2219
#define DEFAULT_LSAP_SETUP_PRIO 4
2320
#define DEFAULT_LSAP_HOLDING_PRIO 4
@@ -103,23 +100,15 @@ int pcep_lib_initialize(struct frr_pthread *fpt)
103100

104101
/* Its ok that this object goes out of scope, as it
105102
* wont be stored, and its values will be copied */
106-
struct pceplib_infra_config infra = {
107-
/* Memory infrastructure */
108-
.pceplib_infra_mt = MTYPE_PCEPLIB_INFRA,
109-
.pceplib_messages_mt = MTYPE_PCEPLIB_MESSAGES,
110-
.malloc_func = (pceplib_malloc_func)qmalloc,
111-
.calloc_func = (pceplib_calloc_func)qcalloc,
112-
.realloc_func = (pceplib_realloc_func)qrealloc,
113-
.strdup_func = (pceplib_strdup_func)qstrdup,
114-
.free_func = (pceplib_free_func)qfree,
115-
/* Timers infrastructure */
116-
.external_infra_data = fpt,
117-
.socket_read_func = pcep_lib_pceplib_socket_read_cb,
118-
.socket_write_func = pcep_lib_pceplib_socket_write_cb,
119-
/* PCEP events */
120-
.pcep_event_func = pcep_lib_pceplib_event_cb,
121-
/* PCEPlib pthread creation callback */
122-
.pthread_create_func = pcep_lib_pthread_create_cb};
103+
struct pceplib_infra_config infra = { /* Timers infrastructure */
104+
.external_infra_data = fpt,
105+
.socket_read_func = pcep_lib_pceplib_socket_read_cb,
106+
.socket_write_func = pcep_lib_pceplib_socket_write_cb,
107+
/* PCEP events */
108+
.pcep_event_func = pcep_lib_pceplib_event_cb,
109+
/* PCEPlib pthread creation callback */
110+
.pthread_create_func = pcep_lib_pthread_create_cb
111+
};
123112
if (!initialize_pcc_infra(&infra)) {
124113
flog_err(EC_PATH_PCEP_PCC_INIT, "failed to initialize pceplib");
125114
return 1;

pceplib/pcep.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "config.h"
1616
#endif
1717

18+
#include "pcep_utils_memory.h"
19+
1820
#ifdef __linux__
1921

2022
#define ipv6_u __in6_u

pceplib/pcep_msg_messages.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ static struct pcep_message *
3333
pcep_msg_create_common_with_obj_list(enum pcep_message_types msg_type,
3434
double_linked_list *obj_list)
3535
{
36-
struct pcep_message *message =
37-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct pcep_message));
36+
struct pcep_message *message = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct pcep_message));
3837
memset(message, 0, sizeof(struct pcep_message));
39-
message->msg_header = pceplib_malloc(
40-
PCEPLIB_MESSAGES, sizeof(struct pcep_message_header));
38+
message->msg_header = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct pcep_message_header));
4139
memset(message->msg_header, 0, sizeof(struct pcep_message_header));
4240
message->msg_header->type = msg_type;
4341
message->msg_header->pcep_version = PCEP_MESSAGE_HEADER_VERSION;

pceplib/pcep_msg_messages_encoding.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ void pcep_encode_message(struct pcep_message *message,
106106
net_order_length = htons(message_length);
107107
memcpy(message_buffer + 2, &net_order_length,
108108
sizeof(net_order_length));
109-
message->encoded_message =
110-
pceplib_malloc(PCEPLIB_MESSAGES, message_length);
109+
message->encoded_message = XMALLOC(MTYPE_PCEPLIB_MESSAGES, message_length);
111110
memcpy(message->encoded_message, message_buffer,
112111
message_length);
113112
message->encoded_message_length = message_length;
@@ -130,8 +129,7 @@ void pcep_encode_message(struct pcep_message *message,
130129

131130
net_order_length = htons(message_length);
132131
memcpy(message_buffer + 2, &net_order_length, sizeof(net_order_length));
133-
message->encoded_message =
134-
pceplib_malloc(PCEPLIB_MESSAGES, message_length);
132+
message->encoded_message = XMALLOC(MTYPE_PCEPLIB_MESSAGES, message_length);
135133
memcpy(message->encoded_message, message_buffer, message_length);
136134
message->encoded_message_length = message_length;
137135
}
@@ -296,16 +294,14 @@ struct pcep_message *pcep_decode_message(const uint8_t *msg_buf)
296294
return NULL;
297295
}
298296

299-
struct pcep_message *msg =
300-
pceplib_calloc(PCEPLIB_MESSAGES, sizeof(struct pcep_message));
297+
struct pcep_message *msg = XCALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct pcep_message));
301298

302-
msg->msg_header = pceplib_malloc(PCEPLIB_MESSAGES,
303-
sizeof(struct pcep_message_header));
299+
msg->msg_header = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct pcep_message_header));
304300
msg->msg_header->pcep_version = msg_version;
305301
msg->msg_header->type = msg_type;
306302

307303
msg->obj_list = dll_initialize();
308-
msg->encoded_message = pceplib_malloc(PCEPLIB_MESSAGES, msg_length);
304+
msg->encoded_message = XMALLOC(MTYPE_PCEPLIB_MESSAGES, msg_length);
309305
memcpy(msg->encoded_message, msg_buf, msg_length);
310306
msg->encoded_message_length = msg_length;
311307

@@ -338,14 +334,14 @@ struct pcep_message *pcep_decode_message(const uint8_t *msg_buf)
338334

339335
struct pcep_versioning *create_default_pcep_versioning(void)
340336
{
341-
struct pcep_versioning *versioning =
342-
pceplib_malloc(PCEPLIB_INFRA, sizeof(struct pcep_versioning));
337+
struct pcep_versioning *versioning = XMALLOC(MTYPE_PCEPLIB_INFRA,
338+
sizeof(struct pcep_versioning));
343339
memset(versioning, 0, sizeof(struct pcep_versioning));
344340

345341
return versioning;
346342
}
347343

348344
void destroy_pcep_versioning(struct pcep_versioning *versioning)
349345
{
350-
pceplib_free(PCEPLIB_INFRA, versioning);
346+
XFREE(MTYPE_PCEPLIB_INFRA, versioning);
351347
}

pceplib/pcep_msg_objects.c

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static struct pcep_object_header *pcep_obj_create_common_with_tlvs(
3434
uint8_t obj_length, enum pcep_object_classes object_class,
3535
enum pcep_object_types object_type, double_linked_list *tlv_list)
3636
{
37-
uint8_t *buffer = pceplib_malloc(PCEPLIB_MESSAGES, obj_length);
37+
uint8_t *buffer = XMALLOC(MTYPE_PCEPLIB_MESSAGES, obj_length);
3838
memset(buffer, 0, obj_length);
3939

4040
/* The flag_p and flag_i flags will be set externally */
@@ -503,8 +503,7 @@ pcep_obj_create_ro_subobj_common(uint8_t subobj_size,
503503
enum pcep_ro_subobj_types ro_subobj_type,
504504
bool flag_subobj_loose_hop)
505505
{
506-
struct pcep_object_ro_subobj *ro_subobj =
507-
pceplib_malloc(PCEPLIB_MESSAGES, subobj_size);
506+
struct pcep_object_ro_subobj *ro_subobj = XMALLOC(MTYPE_PCEPLIB_MESSAGES, subobj_size);
508507
memset(ro_subobj, 0, subobj_size);
509508
ro_subobj->flag_subobj_loose_hop = flag_subobj_loose_hop;
510509
ro_subobj->ro_subobj_type = ro_subobj_type;
@@ -665,8 +664,7 @@ pcep_obj_create_ro_subobj_sr_ipv4_node(bool loose_hop, bool sid_absent,
665664
* doesn't have any restrictions about the type of memory used
666665
* externally for the IP. This memory will be freed with the object is
667666
* freed. */
668-
struct in_addr *ipv4_node_id_copy =
669-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in_addr));
667+
struct in_addr *ipv4_node_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct in_addr));
670668
ipv4_node_id_copy->s_addr = ipv4_node_id->s_addr;
671669
dll_append(obj->nai_list, ipv4_node_id_copy);
672670

@@ -693,8 +691,8 @@ pcep_obj_create_ro_subobj_sr_ipv6_node(bool loose_hop, bool sid_absent,
693691
obj->sid = sid;
694692
}
695693
obj->nai_list = dll_initialize();
696-
struct in6_addr *ipv6_node_id_copy =
697-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
694+
struct in6_addr *ipv6_node_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES,
695+
sizeof(struct in6_addr));
698696
memcpy(ipv6_node_id_copy, ipv6_node_id, sizeof(struct in6_addr));
699697
dll_append(obj->nai_list, ipv6_node_id_copy);
700698

@@ -720,10 +718,8 @@ struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_ipv4_adj(
720718
obj->sid = sid;
721719
}
722720
obj->nai_list = dll_initialize();
723-
struct in_addr *local_ipv4_copy =
724-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in_addr));
725-
struct in_addr *remote_ipv4_copy =
726-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in_addr));
721+
struct in_addr *local_ipv4_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct in_addr));
722+
struct in_addr *remote_ipv4_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct in_addr));
727723
local_ipv4_copy->s_addr = local_ipv4->s_addr;
728724
remote_ipv4_copy->s_addr = remote_ipv4->s_addr;
729725
dll_append(obj->nai_list, local_ipv4_copy);
@@ -751,10 +747,9 @@ struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_ipv6_adj(
751747
obj->sid = sid;
752748
}
753749
obj->nai_list = dll_initialize();
754-
struct in6_addr *local_ipv6_copy =
755-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
756-
struct in6_addr *remote_ipv6_copy =
757-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
750+
struct in6_addr *local_ipv6_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct in6_addr));
751+
struct in6_addr *remote_ipv6_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES,
752+
sizeof(struct in6_addr));
758753
memcpy(local_ipv6_copy, local_ipv6, sizeof(struct in6_addr));
759754
memcpy(remote_ipv6_copy, remote_ipv6, sizeof(struct in6_addr));
760755
dll_append(obj->nai_list, local_ipv6_copy);
@@ -780,23 +775,19 @@ struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_unnumbered_ipv4_adj(
780775
}
781776

782777
obj->nai_list = dll_initialize();
783-
uint32_t *local_node_id_copy =
784-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
778+
uint32_t *local_node_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(uint32_t));
785779
*local_node_id_copy = local_node_id;
786780
dll_append(obj->nai_list, local_node_id_copy);
787781

788-
uint32_t *local_if_id_copy =
789-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
782+
uint32_t *local_if_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(uint32_t));
790783
*local_if_id_copy = local_if_id;
791784
dll_append(obj->nai_list, local_if_id_copy);
792785

793-
uint32_t *remote_node_id_copy =
794-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
786+
uint32_t *remote_node_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(uint32_t));
795787
*remote_node_id_copy = remote_node_id;
796788
dll_append(obj->nai_list, remote_node_id_copy);
797789

798-
uint32_t *remote_if_id_copy =
799-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
790+
uint32_t *remote_if_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(uint32_t));
800791
*remote_if_id_copy = remote_if_id;
801792
dll_append(obj->nai_list, remote_if_id_copy);
802793

@@ -823,23 +814,20 @@ struct pcep_ro_subobj_sr *pcep_obj_create_ro_subobj_sr_linklocal_ipv6_adj(
823814
obj->sid = sid;
824815
}
825816
obj->nai_list = dll_initialize();
826-
struct in6_addr *local_ipv6_copy =
827-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
817+
struct in6_addr *local_ipv6_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(struct in6_addr));
828818
memcpy(local_ipv6_copy, local_ipv6, sizeof(struct in6_addr));
829819
dll_append(obj->nai_list, local_ipv6_copy);
830820

831-
uint32_t *local_if_id_copy =
832-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
821+
uint32_t *local_if_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(uint32_t));
833822
*local_if_id_copy = local_if_id;
834823
dll_append(obj->nai_list, local_if_id_copy);
835824

836-
struct in6_addr *remote_ipv6_copy =
837-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct in6_addr));
825+
struct in6_addr *remote_ipv6_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES,
826+
sizeof(struct in6_addr));
838827
memcpy(remote_ipv6_copy, remote_ipv6, sizeof(struct in6_addr));
839828
dll_append(obj->nai_list, remote_ipv6_copy);
840829

841-
uint32_t *remote_if_id_copy =
842-
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
830+
uint32_t *remote_if_id_copy = XMALLOC(MTYPE_PCEPLIB_MESSAGES, sizeof(uint32_t));
843831
*remote_if_id_copy = remote_if_id;
844832
dll_append(obj->nai_list, remote_if_id_copy);
845833

0 commit comments

Comments
 (0)