diff options
author | Donald Sharp <donaldsharp72@gmail.com> | 2022-06-23 19:52:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-23 19:52:09 +0200 |
commit | f4cb4b4126da63c490938863afdcbc232d10af31 (patch) | |
tree | 814054eeeaef83ec4fcbf4e372779f854ac47d26 /ospfd | |
parent | Merge pull request #11463 from rgirada/ospf_coverity (diff) | |
parent | tests: add ospf api router ID topotest (diff) | |
download | frr-f4cb4b4126da63c490938863afdcbc232d10af31.tar.xz frr-f4cb4b4126da63c490938863afdcbc232d10af31.zip |
Merge pull request #11460 from LabNConsulting/chopps/ospfapi-routerid
Chopps/ospfapi routerid
Diffstat (limited to 'ospfd')
-rw-r--r-- | ospfd/ospf_api.c | 9 | ||||
-rw-r--r-- | ospfd/ospf_api.h | 11 | ||||
-rw-r--r-- | ospfd/ospf_apiserver.c | 37 | ||||
-rw-r--r-- | ospfd/ospf_apiserver.h | 4 | ||||
-rw-r--r-- | ospfd/ospfd.c | 5 |
5 files changed, 66 insertions, 0 deletions
diff --git a/ospfd/ospf_api.c b/ospfd/ospf_api.c index 99bc6c0b0..8636db450 100644 --- a/ospfd/ospf_api.c +++ b/ospfd/ospf_api.c @@ -1,6 +1,7 @@ /* * API message handling module for OSPF daemon and client. * Copyright (C) 2001, 2002 Ralph Keller + * Copyright (c) 2022, LabN Consulting, L.L.C. * * This file is part of GNU Zebra. * @@ -682,4 +683,12 @@ struct msg *new_msg_reachable_change(uint32_t seqnum, uint16_t nadd, return msg_new(MSG_REACHABLE_CHANGE, nmsg, seqnum, len); } +struct msg *new_msg_router_id_change(uint32_t seqnum, struct in_addr router_id) +{ + struct msg_router_id_change rmsg = {.router_id = router_id}; + + return msg_new(MSG_ROUTER_ID_CHANGE, &rmsg, seqnum, + sizeof(struct msg_router_id_change)); +} + #endif /* SUPPORT_OSPF_API */ diff --git a/ospfd/ospf_api.h b/ospfd/ospf_api.h index 50b0c21c7..51c8c52ce 100644 --- a/ospfd/ospf_api.h +++ b/ospfd/ospf_api.h @@ -1,6 +1,7 @@ /* * API message handling module for OSPF daemon and client. * Copyright (C) 2001, 2002 Ralph Keller + * Copyright (c) 2022, LabN Consulting, L.L.C. * * This file is part of GNU Zebra. * @@ -118,6 +119,7 @@ extern void msg_fifo_free(struct msg_fifo *fifo); #define MSG_SYNC_REACHABLE 7 #define MSG_SYNC_ISM 8 #define MSG_SYNC_NSM 9 +#define MSG_SYNC_ROUTER_ID 19 /* Messages from OSPF daemon. */ #define MSG_REPLY 10 @@ -129,6 +131,7 @@ extern void msg_fifo_free(struct msg_fifo *fifo); #define MSG_ISM_CHANGE 16 #define MSG_NSM_CHANGE 17 #define MSG_REACHABLE_CHANGE 18 +#define MSG_ROUTER_ID_CHANGE 20 struct msg_register_opaque_type { uint8_t lsatype; @@ -260,6 +263,10 @@ struct msg_reachable_change { struct in_addr router_ids[]; /* add followed by remove */ }; +struct msg_router_id_change { + struct in_addr router_id; /* this systems router id */ +}; + /* We make use of a union to define a structure that covers all possible API messages. This allows us to find out how much memory needs to be reserved for the largest API message. */ @@ -279,6 +286,7 @@ struct apimsg { struct msg_nsm_change nsm_change; struct msg_lsa_change_notify lsa_change_notify; struct msg_reachable_change reachable_change; + struct msg_router_id_change router_id_change; } u; }; @@ -338,6 +346,9 @@ extern struct msg *new_msg_reachable_change(uint32_t seqnum, uint16_t nadd, struct in_addr *add, uint16_t nremove, struct in_addr *remove); + +extern struct msg *new_msg_router_id_change(uint32_t seqnr, + struct in_addr router_id); /* string printing functions */ extern const char *ospf_api_errname(int errcode); extern const char *ospf_api_typename(int msgtype); diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index 7c3fef453..9d73c3dfe 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -1,6 +1,7 @@ /* * Server side of OSPF API. * Copyright (C) 2001, 2002 Ralph Keller + * Copyright (c) 2022, LabN Consulting, L.L.C. * * This file is part of GNU Zebra. * @@ -727,6 +728,7 @@ static int ospf_apiserver_send_msg(struct ospf_apiserver *apiserv, case MSG_ISM_CHANGE: case MSG_NSM_CHANGE: case MSG_REACHABLE_CHANGE: + case MSG_ROUTER_ID_CHANGE: fifo = apiserv->out_async_fifo; fd = apiserv->fd_async; event = OSPF_APISERVER_ASYNC_WRITE; @@ -809,6 +811,9 @@ int ospf_apiserver_handle_msg(struct ospf_apiserver *apiserv, struct msg *msg) case MSG_SYNC_NSM: rc = ospf_apiserver_handle_sync_nsm(apiserv, msg); break; + case MSG_SYNC_ROUTER_ID: + rc = ospf_apiserver_handle_sync_router_id(apiserv, msg); + break; default: zlog_warn("ospf_apiserver_handle_msg: Unknown message type: %d", msg->hdr.msgtype); @@ -1479,6 +1484,23 @@ int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv, } +int ospf_apiserver_handle_sync_router_id(struct ospf_apiserver *apiserv, + struct msg *msg) +{ + struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); + uint32_t seqnum = msg_get_seq(msg); + struct msg *m; + int _rc, rc = 0; + + m = new_msg_router_id_change(seqnum, ospf->router_id); + rc = ospf_apiserver_send_msg(apiserv, m); + msg_free(m); + + /* Send a reply back to client with return code */ + _rc = ospf_apiserver_send_reply(apiserv, seqnum, rc); + return rc ? rc : _rc; +} + /* ----------------------------------------------------------- * Following are functions to originate or update LSA * from an application. @@ -2679,4 +2701,19 @@ void ospf_apiserver_notify_reachable(struct route_table *ort, } +void ospf_apiserver_clients_notify_router_id_change(struct in_addr router_id) +{ + struct msg *msg; + + msg = new_msg_router_id_change(0, router_id); + if (!msg) { + zlog_warn("%s: new_msg_router_id_change failed", __func__); + return; + } + + ospf_apiserver_clients_notify_all(msg); + msg_free(msg); +} + + #endif /* SUPPORT_OSPF_API */ diff --git a/ospfd/ospf_apiserver.h b/ospfd/ospf_apiserver.h index 7d728ead9..e28202e46 100644 --- a/ospfd/ospf_apiserver.h +++ b/ospfd/ospf_apiserver.h @@ -125,6 +125,8 @@ extern void ospf_apiserver_clients_notify_new_if(struct ospf_interface *oi); extern void ospf_apiserver_clients_notify_del_if(struct ospf_interface *oi); extern void ospf_apiserver_clients_notify_ism_change(struct ospf_interface *oi); extern void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr); +extern void +ospf_apiserver_clients_notify_router_id_change(struct in_addr router_id); extern int ospf_apiserver_is_ready_type9(struct ospf_interface *oi); extern int ospf_apiserver_is_ready_type10(struct ospf_area *area); @@ -157,6 +159,8 @@ extern int ospf_apiserver_handle_sync_ism(struct ospf_apiserver *apiserv, struct msg *msg); extern int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv, struct msg *msg); +extern int ospf_apiserver_handle_sync_router_id(struct ospf_apiserver *apiserv, + struct msg *msg); extern void ospf_apiserver_notify_reachable(struct route_table *ort, struct route_table *nrt); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 337456ecd..33872950a 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -61,6 +61,7 @@ #include "ospfd/ospf_ase.h" #include "ospfd/ospf_ldp_sync.h" #include "ospfd/ospf_gr.h" +#include "ospfd/ospf_apiserver.h" DEFINE_QOBJ_TYPE(ospf); @@ -241,6 +242,10 @@ void ospf_process_refresh_data(struct ospf *ospf, bool reset) } ospf_external_lsa_rid_change(ospf); + +#ifdef SUPPORT_OSPF_API + ospf_apiserver_clients_notify_router_id_change(router_id); +#endif } ospf->inst_shutdown = 0; |