diff options
author | Vincent JARDIN <vincent.jardin@6wind.com> | 2017-10-08 18:20:12 +0200 |
---|---|---|
committer | Vincent JARDIN <vincent.jardin@6wind.com> | 2017-10-08 23:06:57 +0200 |
commit | 3981b5c7f3232086aecd35e56bbeb4b5116c8469 (patch) | |
tree | ad2a5bb75b4b5b831641a343cd34a99a534a4707 /ospf6d | |
parent | rfapi: avoid calling NULL() function. (diff) | |
download | frr-3981b5c7f3232086aecd35e56bbeb4b5116c8469.tar.xz frr-3981b5c7f3232086aecd35e56bbeb4b5116c8469.zip |
ospf6d: fix clang warning, NULL() calls
Avoid show() methods from being a NULL function when it is called.
Meanwhile, I did const'ify the handlers so only its debug field can be changed.
Signed-off-by: Vincent Jardin <vincent.jardin@6wind.com>
Diffstat (limited to 'ospf6d')
-rw-r--r-- | ospf6d/ospf6_abr.c | 22 | ||||
-rw-r--r-- | ospf6d/ospf6_asbr.c | 9 | ||||
-rw-r--r-- | ospf6d/ospf6_intra.c | 46 | ||||
-rw-r--r-- | ospf6d/ospf6_lsa.c | 68 | ||||
-rw-r--r-- | ospf6d/ospf6_lsa.h | 29 |
5 files changed, 109 insertions, 65 deletions
diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index 36528d063..d270b9547 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -1110,19 +1110,21 @@ void install_element_ospf6_debug_abr(void) } struct ospf6_lsa_handler inter_prefix_handler = { - OSPF6_LSTYPE_INTER_PREFIX, - "Inter-Prefix", - "IAP", - ospf6_inter_area_prefix_lsa_show, - ospf6_inter_area_prefix_lsa_get_prefix_str, + .lh_type = OSPF6_LSTYPE_INTER_PREFIX, + .lh_name = "Inter-Prefix", + .lh_short_name = "IAP", + .lh_show = ospf6_inter_area_prefix_lsa_show, + .lh_get_prefix_str = ospf6_inter_area_prefix_lsa_get_prefix_str, + .lh_debug = 0 }; struct ospf6_lsa_handler inter_router_handler = { - OSPF6_LSTYPE_INTER_ROUTER, - "Inter-Router", - "IAR", - ospf6_inter_area_router_lsa_show, - ospf6_inter_area_router_lsa_get_prefix_str, + .lh_type = OSPF6_LSTYPE_INTER_ROUTER, + .lh_name = "Inter-Router", + .lh_short_name = "IAR", + .lh_show = ospf6_inter_area_router_lsa_show, + .lh_get_prefix_str = ospf6_inter_area_router_lsa_get_prefix_str, + .lh_debug = 0 }; void ospf6_abr_init(void) diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index de20fbc3a..e3ceee243 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -1234,8 +1234,13 @@ DEFUN (show_ipv6_ospf6_redistribute, } struct ospf6_lsa_handler as_external_handler = { - OSPF6_LSTYPE_AS_EXTERNAL, "AS-External", "ASE", - ospf6_as_external_lsa_show, ospf6_as_external_lsa_get_prefix_str}; + .lh_type = OSPF6_LSTYPE_AS_EXTERNAL, + .lh_name = "AS-External", + .lh_short_name = "ASE", + .lh_show = ospf6_as_external_lsa_show, + .lh_get_prefix_str = ospf6_as_external_lsa_get_prefix_str, + .lh_debug = 0 +}; void ospf6_asbr_init(void) { diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index e4644bb09..a2caeccb8 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -1630,21 +1630,41 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) oa->name); } -struct ospf6_lsa_handler router_handler = {OSPF6_LSTYPE_ROUTER, "Router", "Rtr", - ospf6_router_lsa_show, - ospf6_router_lsa_get_nbr_id}; - -struct ospf6_lsa_handler network_handler = {OSPF6_LSTYPE_NETWORK, "Network", - "Net", ospf6_network_lsa_show, - ospf6_network_lsa_get_ar_id}; - -struct ospf6_lsa_handler link_handler = {OSPF6_LSTYPE_LINK, "Link", "Lnk", - ospf6_link_lsa_show, - ospf6_link_lsa_get_prefix_str}; +struct ospf6_lsa_handler router_handler = { + .lh_type = OSPF6_LSTYPE_ROUTER, + .lh_name = "Router", + .lh_short_name = "Rtr", + .lh_show = ospf6_router_lsa_show, + .lh_get_prefix_str = ospf6_router_lsa_get_nbr_id, + .lh_debug = 0 +}; + +struct ospf6_lsa_handler network_handler = { + .lh_type = OSPF6_LSTYPE_NETWORK, + .lh_name = "Network", + .lh_short_name = "Net", + .lh_show = ospf6_network_lsa_show, + .lh_get_prefix_str = ospf6_network_lsa_get_ar_id, + .lh_debug = 0 +}; + +struct ospf6_lsa_handler link_handler = { + .lh_type = OSPF6_LSTYPE_LINK, + .lh_name = "Link", + .lh_short_name = "Lnk", + .lh_show = ospf6_link_lsa_show, + .lh_get_prefix_str = ospf6_link_lsa_get_prefix_str, + .lh_debug = 0 +}; struct ospf6_lsa_handler intra_prefix_handler = { - OSPF6_LSTYPE_INTRA_PREFIX, "Intra-Prefix", "INP", - ospf6_intra_prefix_lsa_show, ospf6_intra_prefix_lsa_get_prefix_str}; + .lh_type = OSPF6_LSTYPE_INTRA_PREFIX, + .lh_name = "Intra-Prefix", + .lh_short_name = "INP", + .lh_show = ospf6_intra_prefix_lsa_show, + .lh_get_prefix_str = ospf6_intra_prefix_lsa_get_prefix_str, + .lh_debug = 0 +}; void ospf6_intra_init(void) { diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index a0dad9344..82f75b153 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -68,19 +68,25 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) return 0; } -struct ospf6_lsa_handler unknown_handler = { - OSPF6_LSTYPE_UNKNOWN, "Unknown", "Unk", ospf6_unknown_lsa_show, NULL}; +static struct ospf6_lsa_handler unknown_handler = { + .lh_type = OSPF6_LSTYPE_UNKNOWN, + .lh_name = "Unknown", + .lh_short_name = "Unk", + .lh_show = ospf6_unknown_lsa_show, + .lh_get_prefix_str = NULL, + .lh_debug = 0 /* No default debug */ +}; -void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler) +void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler) { /* type in handler is host byte order */ - int index = handler->type & OSPF6_LSTYPE_FCODE_MASK; - vector_set_index(ospf6_lsa_handler_vector, index, handler); + int index = handler->lh_type & OSPF6_LSTYPE_FCODE_MASK; + vector_set_index(ospf6_lsa_handler_vector, index, (void *)handler); } -struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) +const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) { - struct ospf6_lsa_handler *handler = NULL; + const struct ospf6_lsa_handler *handler = NULL; unsigned int index = ntohs(type) & OSPF6_LSTYPE_FCODE_MASK; if (index >= vector_active(ospf6_lsa_handler_vector)) @@ -97,11 +103,11 @@ struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) const char *ospf6_lstype_name(u_int16_t type) { static char buf[8]; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); if (handler && handler != &unknown_handler) - return handler->name; + return handler->lh_name; snprintf(buf, sizeof(buf), "0x%04hx", ntohs(type)); return buf; @@ -110,11 +116,11 @@ const char *ospf6_lstype_name(u_int16_t type) const char *ospf6_lstype_short_name(u_int16_t type) { static char buf[8]; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); if (handler && handler != &unknown_handler) - return handler->short_name; + return handler->lh_short_name; snprintf(buf, sizeof(buf), "0x%04hx", ntohs(type)); return buf; @@ -122,7 +128,7 @@ const char *ospf6_lstype_short_name(u_int16_t type) u_char ospf6_lstype_debug(u_int16_t type) { - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); return handler->debug; } @@ -369,7 +375,7 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa) { char adv_router[16], id[16]; int type; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; char buf[64], tmpbuf[80]; int cnt = 0; @@ -389,14 +395,14 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa) ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), (u_long)ntohl(lsa->header->seqnum), - handler->get_prefix_str(lsa, buf, sizeof(buf), 0)); + handler->lh_get_prefix_str(lsa, buf, sizeof(buf), 0)); } else if (type != OSPF6_LSTYPE_UNKNOWN) { sprintf(tmpbuf, "%-4s %-15s%-15s%4hu %8lx", ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), (u_long)ntohl(lsa->header->seqnum)); - while (handler->get_prefix_str(lsa, buf, sizeof(buf), cnt) + while (handler->lh_get_prefix_str(lsa, buf, sizeof(buf), cnt) != NULL) { vty_out(vty, "%s %30s\n", tmpbuf, buf); cnt++; @@ -465,7 +471,7 @@ void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa) void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) { char adv_router[64], id[64]; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; struct timeval now, res; char duration[64]; @@ -490,9 +496,13 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) vty_out(vty, "Duration: %s\n", duration); handler = ospf6_get_lsa_handler(lsa->header->type); - if (handler->show == NULL) - handler = &unknown_handler; - (*handler->show)(vty, lsa); + + if (handler->lh_show != NULL) + handler->lh_show(vty, lsa); + else { + assert(unknown_handler.lh_show != NULL); + unknown_handler.lh_show(vty, lsa); + } vty_out(vty, "\n"); } @@ -739,22 +749,22 @@ void ospf6_lsa_terminate(void) vector_free(ospf6_lsa_handler_vector); } -static char *ospf6_lsa_handler_name(struct ospf6_lsa_handler *h) +static char *ospf6_lsa_handler_name(const struct ospf6_lsa_handler *h) { static char buf[64]; unsigned int i; - unsigned int size = strlen(h->name); + unsigned int size = strlen(h->lh_name); - if (!strcmp(h->name, "unknown") && h->type != OSPF6_LSTYPE_UNKNOWN) { - snprintf(buf, sizeof(buf), "%#04hx", h->type); + if (!strcmp(h->lh_name, "unknown") && h->lh_type != OSPF6_LSTYPE_UNKNOWN) { + snprintf(buf, sizeof(buf), "%#04hx", h->lh_type); return buf; } for (i = 0; i < MIN(size, sizeof(buf)); i++) { - if (!islower((unsigned char)h->name[i])) - buf[i] = tolower((unsigned char)h->name[i]); + if (!islower((unsigned char)h->lh_name[i])) + buf[i] = tolower((unsigned char)h->lh_name[i]); else - buf[i] = h->name[i]; + buf[i] = h->lh_name[i]; } buf[size] = '\0'; return buf; @@ -791,7 +801,7 @@ DEFUN (debug_ospf6_lsa_type, strlen(argv[idx_lsa]->arg)) == 0) break; - if (!strcasecmp(argv[idx_lsa]->arg, handler->name)) + if (!strcasecmp(argv[idx_lsa]->arg, handler->lh_name)) break; handler = NULL; } @@ -844,7 +854,7 @@ DEFUN (no_debug_ospf6_lsa_type, strlen(argv[idx_lsa]->arg)) == 0) break; - if (!strcasecmp(argv[idx_lsa]->arg, handler->name)) + if (!strcasecmp(argv[idx_lsa]->arg, handler->lh_name)) break; } @@ -875,7 +885,7 @@ void install_element_ospf6_debug_lsa(void) int config_write_ospf6_debug_lsa(struct vty *vty) { u_int i; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { handler = vector_slot(ospf6_lsa_handler_vector, i); diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index ef63429fd..8b6303d23 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -137,18 +137,25 @@ struct ospf6_lsa { #define OSPF6_LSA_SEQWRAPPED 0x20 struct ospf6_lsa_handler { - u_int16_t type; /* host byte order */ - const char *name; - const char *short_name; - int (*show)(struct vty *, struct ospf6_lsa *); - char *(*get_prefix_str)(struct ospf6_lsa *, char *buf, int buflen, - int pos); + const struct { + u_int16_t type; /* host byte order */ + const char *name; + const char *short_name; + int (*show)(struct vty *, struct ospf6_lsa *); + char *(*get_prefix_str)(struct ospf6_lsa *, char *buf, int buflen, + int pos); + } s; +#define lh_type s.type +#define lh_name s.name +#define lh_short_name s.short_name +#define lh_show s.show +#define lh_get_prefix_str s.get_prefix_str u_char debug; +#define lh_debug debug }; -extern struct ospf6_lsa_handler unknown_handler; -#define OSPF6_LSA_IS_KNOWN(type) \ - (ospf6_get_lsa_handler(type) != &unknown_handler ? 1 : 0) +#define OSPF6_LSA_IS_KNOWN(t) \ + (ospf6_get_lsa_handler(t).lh_type != OSPF6_LSTYPE_UNKNOWN ? 1 : 0) extern vector ospf6_lsa_handler_vector; @@ -237,8 +244,8 @@ extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *); extern int ospf6_lsa_prohibited_duration(u_int16_t type, u_int32_t id, u_int32_t adv_router, void *scope); -extern void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler); -extern struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type); +extern void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler); +extern const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type); extern void ospf6_lsa_init(void); extern void ospf6_lsa_terminate(void); |