X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ospfd%2Fospf_apiserver.c;h=d0ee8187229535f9c1f060b6028fdc388da94e33;hb=d45a375af223087cc5b1ad82ad2d0d23e52802a9;hp=36bd49125bde333763b3e9e23135c2a51f68610e;hpb=4e262455a252c700f81df75fb8107d112062bba8;p=mirror_frr.git diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index 36bd49125..d0ee81872 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -54,6 +54,7 @@ #include "ospfd/ospf_route.h" #include "ospfd/ospf_ase.h" #include "ospfd/ospf_zebra.h" +#include "ospfd/ospf_errors.h" #include "ospfd/ospf_api.h" #include "ospfd/ospf_apiserver.h" @@ -152,7 +153,8 @@ int ospf_apiserver_init(void) NULL, /* ospf_apiserver_lsa_refresher */ ospf_apiserver_lsa_update, ospf_apiserver_lsa_delete); if (rc != 0) { - zlog_warn( + flog_warn( + EC_OSPF_OPAQUE_REGISTRATION, "ospf_apiserver_init: Failed to register opaque type [0/0]"); } @@ -180,14 +182,14 @@ void ospf_apiserver_term(void) /* Free client list itself */ if (apiserver_list) - list_delete_and_null(&apiserver_list); + list_delete(&apiserver_list); /* Free wildcard list */ /* XXX */ } -static struct ospf_apiserver *lookup_apiserver(u_char lsa_type, - u_char opaque_type) +static struct ospf_apiserver *lookup_apiserver(uint8_t lsa_type, + uint8_t opaque_type) { struct listnode *n1, *n2; struct registered_opaque_type *r; @@ -766,8 +768,8 @@ static int ospf_apiserver_send_msg(struct ospf_apiserver *apiserv, return 0; } -int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, u_int32_t seqnr, - u_char rc) +int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, uint32_t seqnr, + uint8_t rc) { struct msg *msg = new_msg_reply(seqnr, rc); int ret; @@ -831,7 +833,7 @@ int ospf_apiserver_handle_msg(struct ospf_apiserver *apiserv, struct msg *msg) */ int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserv, - u_char lsa_type, u_char opaque_type) + uint8_t lsa_type, uint8_t opaque_type) { struct registered_opaque_type *regtype; int (*originator_func)(void *arg); @@ -867,7 +869,8 @@ int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserv, NULL /* ospf_apiserver_lsa_delete */); if (rc != 0) { - zlog_warn("Failed to register opaque type [%d/%d]", lsa_type, + flog_warn(EC_OSPF_OPAQUE_REGISTRATION, + "Failed to register opaque type [%d/%d]", lsa_type, opaque_type); return OSPF_API_OPAQUETYPEINUSE; } @@ -895,7 +898,7 @@ int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserv, } int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserv, - u_char lsa_type, u_char opaque_type) + uint8_t lsa_type, uint8_t opaque_type) { struct listnode *node, *nnode; struct registered_opaque_type *regtype; @@ -934,8 +937,8 @@ int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserv, static int apiserver_is_opaque_type_registered(struct ospf_apiserver *apiserv, - u_char lsa_type, - u_char opaque_type) + uint8_t lsa_type, + uint8_t opaque_type) { struct listnode *node, *nnode; struct registered_opaque_type *regtype; @@ -957,8 +960,8 @@ int ospf_apiserver_handle_register_opaque_type(struct ospf_apiserver *apiserv, struct msg *msg) { struct msg_register_opaque_type *rmsg; - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; int rc = 0; /* Extract parameters from register opaque type message */ @@ -1135,8 +1138,8 @@ int ospf_apiserver_handle_unregister_opaque_type(struct ospf_apiserver *apiserv, struct msg *msg) { struct msg_unregister_opaque_type *umsg; - u_char ltype; - u_char otype; + uint8_t ltype; + uint8_t otype; int rc = 0; /* Extract parameters from unregister opaque type message */ @@ -1163,7 +1166,7 @@ int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv, { struct msg_register_event *rmsg; int rc; - u_int32_t seqnum; + uint32_t seqnum; rmsg = (struct msg_register_event *)STREAM_DATA(msg->s); @@ -1176,13 +1179,11 @@ int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv, apiserv->filter = XMALLOC(MTYPE_OSPF_APISERVER_MSGFILTER, ntohs(msg->hdr.msglen)); - if (apiserv->filter) { - /* copy it over. */ - memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen)); - rc = OSPF_API_OK; - } else { - rc = OSPF_API_NOMEMORY; - } + + /* copy it over. */ + memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen)); + rc = OSPF_API_OK; + /* Send a reply back to client with return code */ rc = ospf_apiserver_send_reply(apiserv, seqnum, rc); return rc; @@ -1212,7 +1213,7 @@ static int apiserver_sync_callback(struct ospf_lsa *lsa, void *p_arg, param = (struct param_t *)p_arg; apiserv = param->apiserv; - seqnum = (u_int32_t)int_arg; + seqnum = (uint32_t)int_arg; /* Check origin in filter. */ if ((param->filter->origin == ANY_ORIGIN) @@ -1260,14 +1261,14 @@ int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv, struct msg *msg) { struct listnode *node, *nnode; - u_int32_t seqnum; + uint32_t seqnum; int rc = 0; struct msg_sync_lsdb *smsg; struct ospf_apiserver_param_t { struct ospf_apiserver *apiserv; struct lsa_filter_type *filter; } param; - u_int16_t mask; + uint16_t mask; struct route_node *rn; struct ospf_lsa *lsa; struct ospf *ospf; @@ -1290,13 +1291,13 @@ int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv, /* Iterate over all areas. */ for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) { int i; - u_int32_t *area_id = NULL; + uint32_t *area_id = NULL; /* Compare area_id with area_ids in sync request. */ if ((i = smsg->filter.num_areas) > 0) { /* Let area_id point to the list of area IDs, * which is at the end of smsg->filter. */ - area_id = (u_int32_t *)(&smsg->filter + 1); + area_id = (uint32_t *)(&smsg->filter + 1); while (i) { if (*area_id == area->area_id.s_addr) { break; @@ -1379,8 +1380,8 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, struct stream *s; struct lsa_header *newlsa; struct ospf_lsa *new = NULL; - u_char options = 0x0; - u_int16_t length; + uint8_t options = 0x0; + uint16_t length; struct ospf *ospf; @@ -1419,7 +1420,7 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, ospf->router_id); /* Set opaque-LSA body fields. */ - stream_put(s, ((u_char *)protolsa) + sizeof(struct lsa_header), + stream_put(s, ((uint8_t *)protolsa) + sizeof(struct lsa_header), ntohs(protolsa->length) - sizeof(struct lsa_header)); /* Determine length of LSA. */ @@ -1427,19 +1428,7 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, newlsa->length = htons(length); /* Create OSPF LSA. */ - if ((new = ospf_lsa_new()) == NULL) { - zlog_warn("ospf_apiserver_opaque_lsa_new: ospf_lsa_new() ?"); - stream_free(s); - return NULL; - } - - if ((new->data = ospf_lsa_data_new(length)) == NULL) { - zlog_warn( - "ospf_apiserver_opaque_lsa_new: ospf_lsa_data_new() ?"); - ospf_lsa_unlock(&new); - stream_free(s); - return NULL; - } + new = ospf_lsa_new_and_data(length); new->area = area; new->oi = oi; @@ -1676,7 +1665,8 @@ int ospf_apiserver_originate1(struct ospf_lsa *lsa) /* Install this LSA into LSDB. */ if (ospf_lsa_install(ospf, lsa->oi, lsa) == NULL) { - zlog_warn("ospf_apiserver_originate1: ospf_lsa_install failed"); + flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, + "ospf_apiserver_originate1: ospf_lsa_install failed"); return -1; } @@ -1741,6 +1731,8 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa) struct ospf_lsa *new = NULL; struct ospf *ospf; + assert(lsa); + ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); assert(ospf); @@ -1751,6 +1743,7 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa) dump_lsa_key(lsa)); lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */ + goto out; } if (IS_LSA_MAXAGE(lsa)) { @@ -1784,7 +1777,8 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa) /* Install LSA into LSDB. */ if (ospf_lsa_install(ospf, new->oi, new) == NULL) { - zlog_warn( + flog_warn( + EC_OSPF_LSA_INSTALL_FAILURE, "ospf_apiserver_lsa_refresher: ospf_lsa_install failed"); ospf_lsa_unlock(&new); goto out; @@ -1904,8 +1898,8 @@ static int apiserver_flush_opaque_type_callback(struct ospf_lsa *lsa, { struct param_t { struct ospf_apiserver *apiserv; - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; } * param; /* Sanity check */ @@ -1927,12 +1921,12 @@ static int apiserver_flush_opaque_type_callback(struct ospf_lsa *lsa, type or a connection to an application closes and all those opaque LSAs need to be flushed the LSDB. */ void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv, - u_char lsa_type, u_char opaque_type) + uint8_t lsa_type, uint8_t opaque_type) { struct param_t { struct ospf_apiserver *apiserv; - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; } param; struct listnode *node, *nnode; struct ospf *ospf; @@ -2076,7 +2070,7 @@ void ospf_apiserver_show_info(struct vty *vty, struct ospf_lsa *lsa) { struct opaque_lsa { struct lsa_header header; - u_char data[1]; /* opaque data have variable length. This is + uint8_t data[1]; /* opaque data have variable length. This is start address */ }; @@ -2355,7 +2349,7 @@ void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr) msg_free(msg); } -static void apiserver_clients_lsa_change_notify(u_char msgtype, +static void apiserver_clients_lsa_change_notify(uint8_t msgtype, struct ospf_lsa *lsa) { struct msg *msg; @@ -2390,8 +2384,8 @@ static void apiserver_clients_lsa_change_notify(u_char msgtype, /* Now send message to all clients with a matching filter */ for (ALL_LIST_ELEMENTS(apiserver_list, node, nnode, apiserv)) { struct lsa_filter_type *filter; - u_int16_t mask; - u_int32_t *area; + uint16_t mask; + uint32_t *area; int i; /* Check filter for this client. */ @@ -2408,7 +2402,7 @@ static void apiserver_clients_lsa_change_notify(u_char msgtype, } if (i > 0) { - area = (u_int32_t *)(filter + 1); + area = (uint32_t *)(filter + 1); while (i) { if (*area == area_id.s_addr) { break; @@ -2444,7 +2438,7 @@ static void apiserver_clients_lsa_change_notify(u_char msgtype, */ -static int apiserver_notify_clients_lsa(u_char msgtype, struct ospf_lsa *lsa) +static int apiserver_notify_clients_lsa(uint8_t msgtype, struct ospf_lsa *lsa) { struct msg *msg; /* default area for AS-External and Opaque11 LSAs */