From c1657d2669cb8be9cd0d0b2e6d1c7080b63422a0 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Tue, 19 Jul 2022 14:59:23 +0200 Subject: [PATCH] pathd: use a define to store the the length of endpoint string The endpoint string is a 46 byte length buffer. Use a single place to store the length of that buffer. Signed-off-by: Philippe Guibert --- lib/ipaddr.h | 2 ++ pathd/path_cli.c | 4 ++-- pathd/pathd.c | 40 ++++++++++++++++++++++++++-------------- pathd/pathd.h | 2 ++ 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/ipaddr.h b/lib/ipaddr.h index d7ab358afe..43b3028200 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -61,6 +61,8 @@ struct ipaddr { #define IPADDRSZ(p) \ (IS_IPADDR_V4((p)) ? sizeof(struct in_addr) : sizeof(struct in6_addr)) +#define IPADDR_STRING_SIZE 46 + static inline int ipaddr_family(const struct ipaddr *ip) { switch (ip->ipa_type) { diff --git a/pathd/path_cli.c b/pathd/path_cli.c index 7510f2ad05..b88453c68f 100644 --- a/pathd/path_cli.c +++ b/pathd/path_cli.c @@ -126,7 +126,7 @@ DEFPY(show_srte_policy, ttable_rowseps(tt, 0, BOTTOM, true, '-'); RB_FOREACH (policy, srte_policy_head, &srte_policies) { - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; char binding_sid[16] = "-"; ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); @@ -173,7 +173,7 @@ DEFPY(show_srte_policy_detail, vty_out(vty, "\n"); RB_FOREACH (policy, srte_policy_head, &srte_policies) { struct srte_candidate *candidate; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; char binding_sid[16] = "-"; char *segment_list_info; static char undefined_info[] = "(undefined)"; diff --git a/pathd/pathd.c b/pathd/pathd.c index 7e3802c734..5ede1de2ff 100644 --- a/pathd/pathd.c +++ b/pathd/pathd.c @@ -578,7 +578,7 @@ void srte_policy_apply_changes(struct srte_policy *policy) struct srte_candidate *candidate, *safe; struct srte_candidate *old_best_candidate; struct srte_candidate *new_best_candidate; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); @@ -734,7 +734,7 @@ void srte_candidate_set_bandwidth(struct srte_candidate *candidate, float bandwidth, bool required) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG( @@ -762,7 +762,8 @@ void srte_lsp_set_bandwidth(struct srte_lsp *lsp, float bandwidth, { struct srte_candidate *candidate = lsp->candidate; struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG( "SR-TE(%s, %u): candidate %s %slsp bandwidth set to %f B/s", @@ -783,7 +784,8 @@ void srte_lsp_set_bandwidth(struct srte_lsp *lsp, float bandwidth, void srte_candidate_unset_bandwidth(struct srte_candidate *candidate) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG("SR-TE(%s, %u): candidate %s config bandwidth unset", endpoint, policy->color, candidate->name); @@ -805,7 +807,8 @@ void srte_lsp_unset_bandwidth(struct srte_lsp *lsp) { struct srte_candidate *candidate = lsp->candidate; struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG("SR-TE(%s, %u): candidate %s lsp bandwidth unset", endpoint, policy->color, candidate->name); @@ -833,7 +836,8 @@ void srte_candidate_set_metric(struct srte_candidate *candidate, bool is_computed) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG( "SR-TE(%s, %u): candidate %s %sconfig metric %s (%u) set to %f (is-bound: %s; is_computed: %s)", @@ -867,7 +871,8 @@ void srte_lsp_set_metric(struct srte_lsp *lsp, { struct srte_candidate *candidate = lsp->candidate; struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG( "SR-TE(%s, %u): candidate %s %slsp metric %s (%u) set to %f (is-bound: %s; is_computed: %s)", @@ -902,7 +907,8 @@ void srte_candidate_unset_metric(struct srte_candidate *candidate, enum srte_candidate_metric_type type) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG( "SR-TE(%s, %u): candidate %s config metric %s (%u) unset", @@ -927,7 +933,8 @@ void srte_lsp_unset_metric(struct srte_lsp *lsp, { struct srte_candidate *candidate = lsp->candidate; struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG( "SR-TE(%s, %u): candidate %s lsp metric %s (%u) unset", @@ -956,7 +963,8 @@ void srte_candidate_set_objfun(struct srte_candidate *candidate, bool required, enum objfun_type type) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); candidate->objfun = type; @@ -977,7 +985,8 @@ void srte_candidate_set_objfun(struct srte_candidate *candidate, bool required, void srte_candidate_unset_objfun(struct srte_candidate *candidate) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); UNSET_FLAG(candidate->flags, F_CANDIDATE_HAS_OBJFUN); @@ -1029,7 +1038,8 @@ void srte_candidate_set_affinity_filter(struct srte_candidate *candidate, uint32_t filter) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); assert(type > AFFINITY_FILTER_UNDEFINED); @@ -1054,7 +1064,8 @@ void srte_candidate_unset_affinity_filter(struct srte_candidate *candidate, enum affinity_filter_type type) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); assert(type > AFFINITY_FILTER_UNDEFINED); @@ -1110,7 +1121,8 @@ srte_segment_entry_find(struct srte_segment_list *segment_list, uint32_t index) void srte_candidate_status_update(struct srte_candidate *candidate, int status) { struct srte_policy *policy = candidate->policy; - char endpoint[46]; + char endpoint[ENDPOINT_STR_LENGTH]; + ipaddr2str(&policy->endpoint, endpoint, sizeof(endpoint)); PATH_POLICY_DEBUG("SR-TE(%s, %u): zebra updated status to %d", endpoint, policy->color, status); diff --git a/pathd/pathd.h b/pathd/pathd.h index 7ad20044c3..bb2e63c04b 100644 --- a/pathd/pathd.h +++ b/pathd/pathd.h @@ -330,6 +330,8 @@ struct srte_candidate { RB_HEAD(srte_candidate_head, srte_candidate); RB_PROTOTYPE(srte_candidate_head, srte_candidate, entry, srte_candidate_compare) +#define ENDPOINT_STR_LENGTH IPADDR_STRING_SIZE + struct srte_policy { RB_ENTRY(srte_policy) entry; -- 2.39.5