ospfd: add router id support to ospf api

Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
Christian Hopps 2022-06-22 18:10:13 -04:00
parent 2d088d8d53
commit 44038c7ae3
5 changed files with 66 additions and 0 deletions

View File

@ -1,6 +1,7 @@
/* /*
* API message handling module for OSPF daemon and client. * API message handling module for OSPF daemon and client.
* Copyright (C) 2001, 2002 Ralph Keller * Copyright (C) 2001, 2002 Ralph Keller
* Copyright (c) 2022, LabN Consulting, L.L.C.
* *
* This file is part of GNU Zebra. * 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); 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 */ #endif /* SUPPORT_OSPF_API */

View File

@ -1,6 +1,7 @@
/* /*
* API message handling module for OSPF daemon and client. * API message handling module for OSPF daemon and client.
* Copyright (C) 2001, 2002 Ralph Keller * Copyright (C) 2001, 2002 Ralph Keller
* Copyright (c) 2022, LabN Consulting, L.L.C.
* *
* This file is part of GNU Zebra. * 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_REACHABLE 7
#define MSG_SYNC_ISM 8 #define MSG_SYNC_ISM 8
#define MSG_SYNC_NSM 9 #define MSG_SYNC_NSM 9
#define MSG_SYNC_ROUTER_ID 19
/* Messages from OSPF daemon. */ /* Messages from OSPF daemon. */
#define MSG_REPLY 10 #define MSG_REPLY 10
@ -129,6 +131,7 @@ extern void msg_fifo_free(struct msg_fifo *fifo);
#define MSG_ISM_CHANGE 16 #define MSG_ISM_CHANGE 16
#define MSG_NSM_CHANGE 17 #define MSG_NSM_CHANGE 17
#define MSG_REACHABLE_CHANGE 18 #define MSG_REACHABLE_CHANGE 18
#define MSG_ROUTER_ID_CHANGE 20
struct msg_register_opaque_type { struct msg_register_opaque_type {
uint8_t lsatype; uint8_t lsatype;
@ -260,6 +263,10 @@ struct msg_reachable_change {
struct in_addr router_ids[]; /* add followed by remove */ 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 /* 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 possible API messages. This allows us to find out how much memory
needs to be reserved for the largest API message. */ needs to be reserved for the largest API message. */
@ -279,6 +286,7 @@ struct apimsg {
struct msg_nsm_change nsm_change; struct msg_nsm_change nsm_change;
struct msg_lsa_change_notify lsa_change_notify; struct msg_lsa_change_notify lsa_change_notify;
struct msg_reachable_change reachable_change; struct msg_reachable_change reachable_change;
struct msg_router_id_change router_id_change;
} u; } u;
}; };
@ -338,6 +346,9 @@ extern struct msg *new_msg_reachable_change(uint32_t seqnum, uint16_t nadd,
struct in_addr *add, struct in_addr *add,
uint16_t nremove, uint16_t nremove,
struct in_addr *remove); struct in_addr *remove);
extern struct msg *new_msg_router_id_change(uint32_t seqnr,
struct in_addr router_id);
/* string printing functions */ /* string printing functions */
extern const char *ospf_api_errname(int errcode); extern const char *ospf_api_errname(int errcode);
extern const char *ospf_api_typename(int msgtype); extern const char *ospf_api_typename(int msgtype);

View File

@ -1,6 +1,7 @@
/* /*
* Server side of OSPF API. * Server side of OSPF API.
* Copyright (C) 2001, 2002 Ralph Keller * Copyright (C) 2001, 2002 Ralph Keller
* Copyright (c) 2022, LabN Consulting, L.L.C.
* *
* This file is part of GNU Zebra. * 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_ISM_CHANGE:
case MSG_NSM_CHANGE: case MSG_NSM_CHANGE:
case MSG_REACHABLE_CHANGE: case MSG_REACHABLE_CHANGE:
case MSG_ROUTER_ID_CHANGE:
fifo = apiserv->out_async_fifo; fifo = apiserv->out_async_fifo;
fd = apiserv->fd_async; fd = apiserv->fd_async;
event = OSPF_APISERVER_ASYNC_WRITE; 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: case MSG_SYNC_NSM:
rc = ospf_apiserver_handle_sync_nsm(apiserv, msg); rc = ospf_apiserver_handle_sync_nsm(apiserv, msg);
break; break;
case MSG_SYNC_ROUTER_ID:
rc = ospf_apiserver_handle_sync_router_id(apiserv, msg);
break;
default: default:
zlog_warn("ospf_apiserver_handle_msg: Unknown message type: %d", zlog_warn("ospf_apiserver_handle_msg: Unknown message type: %d",
msg->hdr.msgtype); 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 * Following are functions to originate or update LSA
* from an application. * 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 */ #endif /* SUPPORT_OSPF_API */

View File

@ -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_del_if(struct ospf_interface *oi);
extern void ospf_apiserver_clients_notify_ism_change(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_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_type9(struct ospf_interface *oi);
extern int ospf_apiserver_is_ready_type10(struct ospf_area *area); 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); struct msg *msg);
extern int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv, extern int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv,
struct msg *msg); 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, extern void ospf_apiserver_notify_reachable(struct route_table *ort,
struct route_table *nrt); struct route_table *nrt);

View File

@ -61,6 +61,7 @@
#include "ospfd/ospf_ase.h" #include "ospfd/ospf_ase.h"
#include "ospfd/ospf_ldp_sync.h" #include "ospfd/ospf_ldp_sync.h"
#include "ospfd/ospf_gr.h" #include "ospfd/ospf_gr.h"
#include "ospfd/ospf_apiserver.h"
DEFINE_QOBJ_TYPE(ospf); DEFINE_QOBJ_TYPE(ospf);
@ -241,6 +242,10 @@ void ospf_process_refresh_data(struct ospf *ospf, bool reset)
} }
ospf_external_lsa_rid_change(ospf); ospf_external_lsa_rid_change(ospf);
#ifdef SUPPORT_OSPF_API
ospf_apiserver_clients_notify_router_id_change(router_id);
#endif
} }
ospf->inst_shutdown = 0; ospf->inst_shutdown = 0;