mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-04 06:32:57 +00:00
Merge pull request #2106 from qlyoung/zapi-msg
Split out ZAPI message creation / consumption from server implementation
This commit is contained in:
commit
934f5daf2e
@ -235,6 +235,40 @@ static void lm_zclient_init(char *lm_zserv_path)
|
||||
lm_zclient_connect(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release label chunks from a client.
|
||||
*
|
||||
* Called on client disconnection or reconnection. It only releases chunks
|
||||
* with empty keep value.
|
||||
*
|
||||
* @param proto Daemon protocol of client, to identify the owner
|
||||
* @param instance Instance, to identify the owner
|
||||
* @return Number of chunks released
|
||||
*/
|
||||
int release_daemon_label_chunks(struct zserv *client)
|
||||
{
|
||||
uint8_t proto = client->proto;
|
||||
uint16_t instance = client->instance;
|
||||
struct listnode *node;
|
||||
struct label_manager_chunk *lmc;
|
||||
int count = 0;
|
||||
int ret;
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) {
|
||||
if (lmc->proto == proto && lmc->instance == instance
|
||||
&& lmc->keep == 0) {
|
||||
ret = release_label_chunk(lmc->proto, lmc->instance,
|
||||
lmc->start, lmc->end);
|
||||
if (ret == 0)
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
zlog_debug("%s: Released %d label chunks", __func__, count);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init label manager (or proxy to an external one)
|
||||
*/
|
||||
@ -255,6 +289,8 @@ void label_manager_init(char *lm_zserv_path)
|
||||
|
||||
ibuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
|
||||
obuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
|
||||
|
||||
hook_register(zapi_client_close, release_daemon_label_chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -353,37 +389,6 @@ int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release label chunks from a client.
|
||||
*
|
||||
* Called on client disconnection or reconnection. It only releases chunks
|
||||
* with empty keep value.
|
||||
*
|
||||
* @param proto Daemon protocol of client, to identify the owner
|
||||
* @param instance Instance, to identify the owner
|
||||
* @return Number of chunks released
|
||||
*/
|
||||
int release_daemon_label_chunks(uint8_t proto, unsigned short instance)
|
||||
{
|
||||
struct listnode *node;
|
||||
struct label_manager_chunk *lmc;
|
||||
int count = 0;
|
||||
int ret;
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) {
|
||||
if (lmc->proto == proto && lmc->instance == instance
|
||||
&& lmc->keep == 0) {
|
||||
ret = release_label_chunk(lmc->proto, lmc->instance,
|
||||
lmc->start, lmc->end);
|
||||
if (ret == 0)
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
zlog_debug("%s: Released %d label chunks", __func__, count);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void label_manager_close()
|
||||
{
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "lib/linklist.h"
|
||||
#include "lib/thread.h"
|
||||
|
||||
#include "zebra/zserv.h"
|
||||
|
||||
#define NO_PROTO 0
|
||||
|
||||
/*
|
||||
@ -69,7 +71,7 @@ struct label_manager_chunk *assign_label_chunk(uint8_t proto,
|
||||
uint8_t keep, uint32_t size);
|
||||
int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
|
||||
uint32_t end);
|
||||
int release_daemon_label_chunks(uint8_t proto, unsigned short instance);
|
||||
int release_daemon_label_chunks(struct zserv *client);
|
||||
void label_manager_close(void);
|
||||
|
||||
#endif /* _LABEL_MANAGER_H */
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "vrf.h"
|
||||
#include "logicalrouter.h"
|
||||
#include "libfrr.h"
|
||||
#include "routemap.h"
|
||||
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/zserv.h"
|
||||
@ -49,6 +50,7 @@
|
||||
#include "zebra/zebra_mpls.h"
|
||||
#include "zebra/label_manager.h"
|
||||
#include "zebra/zebra_netns_notify.h"
|
||||
#include "zebra/zebra_rnh.h"
|
||||
|
||||
#define ZEBRA_PTM_SUPPORT
|
||||
|
||||
@ -371,6 +373,9 @@ int main(int argc, char **argv)
|
||||
/* Init label manager */
|
||||
label_manager_init(lblmgr_path);
|
||||
|
||||
/* RNH init */
|
||||
zebra_rnh_init();
|
||||
|
||||
frr_run(zebrad.master);
|
||||
|
||||
/* Not reached... */
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "zebra/redistribute.h"
|
||||
#include "zebra/debug.h"
|
||||
#include "zebra/router-id.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/zebra_memory.h"
|
||||
#include "zebra/zebra_vxlan.h"
|
||||
|
||||
|
@ -23,10 +23,12 @@
|
||||
#define _ZEBRA_REDISTRIBUTE_H
|
||||
|
||||
#include "table.h"
|
||||
#include "zserv.h"
|
||||
#include "vty.h"
|
||||
#include "vrf.h"
|
||||
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/rib.h"
|
||||
|
||||
/* ZAPI command handlers */
|
||||
extern void zebra_redistribute_add(ZAPI_HANDLER_ARGS);
|
||||
extern void zebra_redistribute_delete(ZAPI_HANDLER_ARGS);
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "vrf.h"
|
||||
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
#include "zebra/router-id.h"
|
||||
#include "zebra/redistribute.h"
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include "mpls.h"
|
||||
#include "vxlan.h"
|
||||
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/zebra_ns.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
#include "zebra/rt.h"
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "zebra/rtadv.h"
|
||||
#include "zebra/debug.h"
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/zebra_ns.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
|
||||
|
@ -71,6 +71,7 @@ zebra_zebra_SOURCES = \
|
||||
zebra/zebra_netns_id.c \
|
||||
zebra/zebra_netns_notify.c \
|
||||
zebra/table_manager.c \
|
||||
zebra/zapi_msg.c \
|
||||
# end
|
||||
|
||||
zebra/zebra_vty_clippy.c: $(CLIPPY_DEPS)
|
||||
@ -115,6 +116,7 @@ noinst_HEADERS += \
|
||||
zebra/zebra_netns_id.h \
|
||||
zebra/zebra_netns_notify.h \
|
||||
zebra/table_manager.h \
|
||||
zebra/zapi_msg.h \
|
||||
# end
|
||||
|
||||
zebra_zebra_irdp_la_SOURCES = \
|
||||
|
@ -16,12 +16,12 @@
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "zebra.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "zebra.h"
|
||||
#include "zserv.h"
|
||||
#include "lib/log.h"
|
||||
#include "lib/memory.h"
|
||||
#include "lib/table.h"
|
||||
@ -31,9 +31,10 @@
|
||||
#include "lib/libfrr.h"
|
||||
#include "lib/vrf.h"
|
||||
|
||||
#include "zebra_vrf.h"
|
||||
#include "label_manager.h" /* for NO_PROTO */
|
||||
#include "table_manager.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
#include "zebra/label_manager.h" /* for NO_PROTO */
|
||||
#include "zebra/table_manager.h"
|
||||
|
||||
/* routing table identifiers
|
||||
*
|
||||
@ -77,6 +78,7 @@ void table_manager_enable(ns_id_t ns_id)
|
||||
return;
|
||||
tbl_mgr.lc_list = list_new();
|
||||
tbl_mgr.lc_list->del = delete_table_chunk;
|
||||
hook_register(zapi_client_close, release_daemon_table_chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,12 +204,13 @@ int release_table_chunk(uint8_t proto, uint16_t instance, uint32_t start,
|
||||
* Called on client disconnection or reconnection. It only releases chunks
|
||||
* with empty keep value.
|
||||
*
|
||||
* @param proto Daemon protocol of client, to identify the owner
|
||||
* @param instance Instance, to identify the owner
|
||||
* @param client the client to release chunks from
|
||||
* @return Number of chunks released
|
||||
*/
|
||||
int release_daemon_table_chunks(uint8_t proto, uint16_t instance)
|
||||
int release_daemon_table_chunks(struct zserv *client)
|
||||
{
|
||||
uint8_t proto = client->proto;
|
||||
uint16_t instance = client->instance;
|
||||
struct listnode *node;
|
||||
struct table_manager_chunk *tmc;
|
||||
int count = 0;
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#include "lib/linklist.h"
|
||||
#include "lib/thread.h"
|
||||
#include "lib/ns.h"
|
||||
|
||||
#include "zebra/zserv.h"
|
||||
|
||||
/*
|
||||
* Table chunk struct
|
||||
@ -57,7 +60,7 @@ struct table_manager_chunk *assign_table_chunk(uint8_t proto, uint16_t instance,
|
||||
uint32_t size);
|
||||
int release_table_chunk(uint8_t proto, uint16_t instance, uint32_t start,
|
||||
uint32_t end);
|
||||
int release_daemon_table_chunks(uint8_t proto, uint16_t instance);
|
||||
int release_daemon_table_chunks(struct zserv *client);
|
||||
void table_manager_disable(ns_id_t ns_id);
|
||||
|
||||
#endif /* _TABLE_MANAGER_H */
|
||||
|
2961
zebra/zapi_msg.c
Normal file
2961
zebra/zapi_msg.c
Normal file
File diff suppressed because it is too large
Load Diff
88
zebra/zapi_msg.h
Normal file
88
zebra/zapi_msg.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Zebra API message creation & consumption.
|
||||
* Portions:
|
||||
* Copyright (C) 1997-1999 Kunihiro Ishiguro
|
||||
* Copyright (C) 2015-2018 Cumulus Networks, Inc.
|
||||
* et al.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; see the file COPYING; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "lib/if.h"
|
||||
#include "lib/vrf.h"
|
||||
#include "lib/zclient.h"
|
||||
#include "lib/pbr.h"
|
||||
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zebra_pbr.h"
|
||||
|
||||
/*
|
||||
* This is called to process inbound ZAPI messages.
|
||||
*
|
||||
* client
|
||||
* the client datastructure
|
||||
*
|
||||
* hdr
|
||||
* the message header
|
||||
*
|
||||
* msg
|
||||
* the message contents, without the header
|
||||
*
|
||||
* zvrf
|
||||
* the vrf
|
||||
*/
|
||||
extern void zserv_handle_commands(struct zserv *client, struct zmsghdr *hdr,
|
||||
struct stream *msg, struct zebra_vrf *zvrf);
|
||||
|
||||
extern int zsend_vrf_add(struct zserv *zclient, struct zebra_vrf *zvrf);
|
||||
extern int zsend_vrf_delete(struct zserv *zclient, struct zebra_vrf *zvrf);
|
||||
extern int zsend_interface_add(struct zserv *zclient, struct interface *ifp);
|
||||
extern int zsend_interface_delete(struct zserv *zclient, struct interface *ifp);
|
||||
extern int zsend_interface_addresses(struct zserv *zclient,
|
||||
struct interface *ifp);
|
||||
extern int zsend_interface_address(int cmd, struct zserv *zclient,
|
||||
struct interface *ifp,
|
||||
struct connected *ifc);
|
||||
extern void nbr_connected_add_ipv6(struct interface *ifp,
|
||||
struct in6_addr *address);
|
||||
extern void nbr_connected_delete_ipv6(struct interface *ifp,
|
||||
struct in6_addr *address);
|
||||
extern int zsend_interface_update(int cmd, struct zserv *client,
|
||||
struct interface *ifp);
|
||||
extern int zsend_redistribute_route(int cmd, struct zserv *zclient,
|
||||
struct prefix *p, struct prefix *src_p,
|
||||
struct route_entry *re);
|
||||
extern int zsend_router_id_update(struct zserv *zclient, struct prefix *p,
|
||||
vrf_id_t vrf_id);
|
||||
extern int zsend_interface_vrf_update(struct zserv *zclient,
|
||||
struct interface *ifp, vrf_id_t vrf_id);
|
||||
extern int zsend_interface_link_params(struct zserv *zclient,
|
||||
struct interface *ifp);
|
||||
extern int zsend_pw_update(struct zserv *client, struct zebra_pw *pw);
|
||||
extern int zsend_route_notify_owner(struct route_entry *re, struct prefix *p,
|
||||
enum zapi_route_notify_owner note);
|
||||
|
||||
extern void zsend_rule_notify_owner(struct zebra_pbr_rule *rule,
|
||||
enum zapi_rule_notify_owner note);
|
||||
extern void zsend_ipset_notify_owner(struct zebra_pbr_ipset *ipset,
|
||||
enum zapi_ipset_notify_owner note);
|
||||
extern void
|
||||
zsend_ipset_entry_notify_owner(struct zebra_pbr_ipset_entry *ipset,
|
||||
enum zapi_ipset_entry_notify_owner note);
|
||||
extern void zsend_iptable_notify_owner(struct zebra_pbr_iptable *iptable,
|
||||
enum zapi_iptable_notify_owner note);
|
||||
extern void zserv_nexthop_num_warn(const char *caller, const struct prefix *p,
|
||||
const unsigned int nexthop_num);
|
@ -1913,9 +1913,9 @@ int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
|
||||
/*
|
||||
* Cleanup any FECs registered by this client.
|
||||
*/
|
||||
int zebra_mpls_cleanup_fecs_for_client(struct zebra_vrf *zvrf,
|
||||
struct zserv *client)
|
||||
static int zebra_mpls_cleanup_fecs_for_client(struct zserv *client)
|
||||
{
|
||||
struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT);
|
||||
struct route_node *rn;
|
||||
zebra_fec_t *fec;
|
||||
struct listnode *node;
|
||||
@ -2915,4 +2915,6 @@ void zebra_mpls_init(void)
|
||||
|
||||
if (!mpls_processq_init(&zebrad))
|
||||
mpls_enabled = 1;
|
||||
|
||||
hook_register(zapi_client_close, zebra_mpls_cleanup_fecs_for_client);
|
||||
}
|
||||
|
@ -210,12 +210,6 @@ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p,
|
||||
int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
|
||||
struct zserv *client);
|
||||
|
||||
/*
|
||||
* Cleanup any FECs registered by this client.
|
||||
*/
|
||||
int zebra_mpls_cleanup_fecs_for_client(struct zebra_vrf *zvrf,
|
||||
struct zserv *client);
|
||||
|
||||
/*
|
||||
* Return FEC (if any) to which this label is bound.
|
||||
* Note: Only works for per-prefix binding and when the label is not
|
||||
|
@ -25,6 +25,9 @@
|
||||
#include <lib/ns.h>
|
||||
#include <lib/vrf.h>
|
||||
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
|
||||
#ifdef HAVE_NETLINK
|
||||
/* Socket interface to kernel */
|
||||
struct nlsock {
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "zebra/zebra_pbr.h"
|
||||
#include "zebra/rt.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
|
||||
/* definitions */
|
||||
|
||||
|
@ -91,6 +91,7 @@ static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt);
|
||||
void zebra_bfd_peer_replay_req(void);
|
||||
void zebra_ptm_send_status_req(void);
|
||||
void zebra_ptm_reset_status(int ptm_disable);
|
||||
static int zebra_ptm_bfd_client_deregister(struct zserv *client);
|
||||
|
||||
const char ZEBRA_PTM_SOCK_NAME[] = "\0/var/run/ptmd.socket";
|
||||
|
||||
@ -124,17 +125,12 @@ void zebra_ptm_init(void)
|
||||
ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_INITIAL;
|
||||
|
||||
ptm_cb.ptm_sock = -1;
|
||||
|
||||
hook_register(zapi_client_close, zebra_ptm_bfd_client_deregister);
|
||||
}
|
||||
|
||||
void zebra_ptm_finish(void)
|
||||
{
|
||||
int proto;
|
||||
|
||||
for (proto = 0; proto < ZEBRA_ROUTE_MAX; proto++)
|
||||
if (CHECK_FLAG(ptm_cb.client_flags[proto],
|
||||
ZEBRA_PTM_BFD_CLIENT_FLAG_REG))
|
||||
zebra_ptm_bfd_client_deregister(proto);
|
||||
|
||||
buffer_flush_all(ptm_cb.wb, ptm_cb.ptm_sock);
|
||||
|
||||
free(ptm_hdl);
|
||||
@ -1013,15 +1009,16 @@ stream_failure:
|
||||
}
|
||||
|
||||
/* BFD client deregister */
|
||||
void zebra_ptm_bfd_client_deregister(int proto)
|
||||
int zebra_ptm_bfd_client_deregister(struct zserv *client)
|
||||
{
|
||||
uint8_t proto = client->proto;
|
||||
void *out_ctxt;
|
||||
char tmp_buf[64];
|
||||
int data_len = ZEBRA_PTM_SEND_MAX_SOCKBUF;
|
||||
|
||||
if (proto != ZEBRA_ROUTE_OSPF && proto != ZEBRA_ROUTE_BGP
|
||||
&& proto != ZEBRA_ROUTE_OSPF6 && proto != ZEBRA_ROUTE_PIM)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
if (IS_ZEBRA_DEBUG_EVENT)
|
||||
zlog_err("bfd_client_deregister msg for client %s",
|
||||
@ -1031,7 +1028,7 @@ void zebra_ptm_bfd_client_deregister(int proto)
|
||||
ptm_cb.t_timer = NULL;
|
||||
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
|
||||
ptm_cb.reconnect_time, &ptm_cb.t_timer);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ptm_lib_init_msg(ptm_hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL, &out_ctxt);
|
||||
@ -1051,6 +1048,8 @@ void zebra_ptm_bfd_client_deregister(int proto)
|
||||
|
||||
zebra_ptm_send_message(ptm_cb.out_data, data_len);
|
||||
UNSET_FLAG(ptm_cb.client_flags[proto], ZEBRA_PTM_BFD_CLIENT_FLAG_REG);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zebra_ptm_get_enable_state(void)
|
||||
|
@ -29,6 +29,7 @@ extern const char ZEBRA_PTM_SOCK_NAME[];
|
||||
#define ZEBRA_PTM_BFD_CLIENT_FLAG_REG (1 << 1) /* client registered with BFD */
|
||||
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/interface.h"
|
||||
|
||||
/* Zebra ptm context block */
|
||||
struct zebra_ptm_cb {
|
||||
@ -74,5 +75,4 @@ void zebra_ptm_if_init(struct zebra_if *zebra_ifp);
|
||||
void zebra_ptm_if_set_ptm_state(struct interface *ifp,
|
||||
struct zebra_if *zebra_ifp);
|
||||
void zebra_ptm_if_write(struct vty *vty, struct zebra_if *zebra_ifp);
|
||||
void zebra_ptm_bfd_client_deregister(int proto);
|
||||
#endif
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "vty.h"
|
||||
#include "stream.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/zebra_ptm_redistribute.h"
|
||||
#include "zebra/zebra_memory.h"
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "zebra/debug.h"
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/zebra_rnh.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
#include "zebra/zebra_pw.h"
|
||||
@ -268,7 +269,7 @@ static int zebra_pw_check_reachability(struct zebra_pw *pw)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void zebra_pw_client_close(struct zserv *client)
|
||||
static int zebra_pw_client_close(struct zserv *client)
|
||||
{
|
||||
struct vrf *vrf;
|
||||
struct zebra_vrf *zvrf;
|
||||
@ -282,12 +283,16 @@ void zebra_pw_client_close(struct zserv *client)
|
||||
zebra_pw_del(zvrf, pw);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void zebra_pw_init(struct zebra_vrf *zvrf)
|
||||
{
|
||||
RB_INIT(zebra_pw_head, &zvrf->pseudowires);
|
||||
RB_INIT(zebra_static_pw_head, &zvrf->static_pseudowires);
|
||||
|
||||
hook_register(zapi_client_close, zebra_pw_client_close);
|
||||
}
|
||||
|
||||
void zebra_pw_exit(struct zebra_vrf *zvrf)
|
||||
|
@ -23,8 +23,11 @@
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "hook.h"
|
||||
#include "qobj.h"
|
||||
#include "lib/hook.h"
|
||||
#include "lib/qobj.h"
|
||||
#include "lib/pw.h"
|
||||
|
||||
#include "zebra/zebra_vrf.h"
|
||||
|
||||
#define PW_INSTALL_RETRY_INTERVAL 30
|
||||
|
||||
@ -67,7 +70,6 @@ void zebra_pw_change(struct zebra_pw *, ifindex_t, int, int, union g_addr *,
|
||||
struct zebra_pw *zebra_pw_find(struct zebra_vrf *, const char *);
|
||||
void zebra_pw_update(struct zebra_pw *);
|
||||
void zebra_pw_install_failure(struct zebra_pw *);
|
||||
void zebra_pw_client_close(struct zserv *);
|
||||
void zebra_pw_init(struct zebra_vrf *);
|
||||
void zebra_pw_exit(struct zebra_vrf *);
|
||||
void zebra_pw_vty_init(void);
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/rt.h"
|
||||
#include "zebra/zebra_ns.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
#include "zebra/redistribute.h"
|
||||
#include "zebra/zebra_routemap.h"
|
||||
@ -51,6 +50,7 @@
|
||||
#include "zebra/interface.h"
|
||||
#include "zebra/connected.h"
|
||||
#include "zebra/zebra_vxlan.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
|
||||
DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason),
|
||||
(rn, reason))
|
||||
|
@ -66,10 +66,16 @@ static int compare_state(struct route_entry *r1, struct route_entry *r2);
|
||||
static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type,
|
||||
vrf_id_t vrf_id);
|
||||
static void print_rnh(struct route_node *rn, struct vty *vty);
|
||||
static int zebra_client_cleanup_rnh(struct zserv *client);
|
||||
|
||||
int zebra_rnh_ip_default_route = 0;
|
||||
int zebra_rnh_ipv6_default_route = 0;
|
||||
|
||||
void zebra_rnh_init(void)
|
||||
{
|
||||
hook_register(zapi_client_close, zebra_client_cleanup_rnh);
|
||||
}
|
||||
|
||||
static inline struct route_table *get_rnh_table(vrf_id_t vrfid, int family,
|
||||
rnh_type_t type)
|
||||
{
|
||||
@ -945,34 +951,6 @@ void zebra_print_rnh_table(vrf_id_t vrfid, int af, struct vty *vty,
|
||||
print_rnh(rn, vty);
|
||||
}
|
||||
|
||||
int zebra_cleanup_rnh_client(vrf_id_t vrf_id, int family, struct zserv *client,
|
||||
rnh_type_t type)
|
||||
{
|
||||
struct route_table *ntable;
|
||||
struct route_node *nrn;
|
||||
struct rnh *rnh;
|
||||
|
||||
if (IS_ZEBRA_DEBUG_NHT)
|
||||
zlog_debug("%u: Client %s RNH cleanup for family %d type %d",
|
||||
vrf_id, zebra_route_string(client->proto), family,
|
||||
type);
|
||||
|
||||
ntable = get_rnh_table(vrf_id, family, type);
|
||||
if (!ntable) {
|
||||
zlog_debug("cleanup_rnh_client: rnh table not found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (nrn = route_top(ntable); nrn; nrn = route_next(nrn)) {
|
||||
if (!nrn->info)
|
||||
continue;
|
||||
|
||||
rnh = nrn->info;
|
||||
zebra_remove_rnh_client(rnh, client, type);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* free_state - free up the re structure associated with the rnh.
|
||||
*/
|
||||
@ -1202,3 +1180,61 @@ static void print_rnh(struct route_node *rn, struct vty *vty)
|
||||
vty_out(vty, " zebra[pseudowires]");
|
||||
vty_out(vty, "\n");
|
||||
}
|
||||
|
||||
static int zebra_cleanup_rnh_client(vrf_id_t vrf_id, int family,
|
||||
struct zserv *client, rnh_type_t type)
|
||||
{
|
||||
struct route_table *ntable;
|
||||
struct route_node *nrn;
|
||||
struct rnh *rnh;
|
||||
|
||||
if (IS_ZEBRA_DEBUG_NHT)
|
||||
zlog_debug("%u: Client %s RNH cleanup for family %d type %d",
|
||||
vrf_id, zebra_route_string(client->proto), family,
|
||||
type);
|
||||
|
||||
ntable = get_rnh_table(vrf_id, family, type);
|
||||
if (!ntable) {
|
||||
zlog_debug("cleanup_rnh_client: rnh table not found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (nrn = route_top(ntable); nrn; nrn = route_next(nrn)) {
|
||||
if (!nrn->info)
|
||||
continue;
|
||||
|
||||
rnh = nrn->info;
|
||||
zebra_remove_rnh_client(rnh, client, type);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Cleanup registered nexthops (across VRFs) upon client disconnect. */
|
||||
static int zebra_client_cleanup_rnh(struct zserv *client)
|
||||
{
|
||||
struct vrf *vrf;
|
||||
struct zebra_vrf *zvrf;
|
||||
|
||||
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
|
||||
zvrf = vrf->info;
|
||||
if (zvrf) {
|
||||
zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET, client,
|
||||
RNH_NEXTHOP_TYPE);
|
||||
zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET6,
|
||||
client, RNH_NEXTHOP_TYPE);
|
||||
zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET, client,
|
||||
RNH_IMPORT_CHECK_TYPE);
|
||||
zebra_cleanup_rnh_client(zvrf_id(zvrf), AF_INET6,
|
||||
client, RNH_IMPORT_CHECK_TYPE);
|
||||
if (client->proto == ZEBRA_ROUTE_LDP) {
|
||||
hash_iterate(zvrf->lsp_table,
|
||||
mpls_ldp_lsp_uninstall_all,
|
||||
zvrf->lsp_table);
|
||||
mpls_ldp_ftn_uninstall_all(zvrf, AFI_IP);
|
||||
mpls_ldp_ftn_uninstall_all(zvrf, AFI_IP6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ typedef enum { RNH_NEXTHOP_TYPE, RNH_IMPORT_CHECK_TYPE } rnh_type_t;
|
||||
extern int zebra_rnh_ip_default_route;
|
||||
extern int zebra_rnh_ipv6_default_route;
|
||||
|
||||
extern void zebra_rnh_init(void);
|
||||
|
||||
static inline int rnh_resolve_via_default(int family)
|
||||
{
|
||||
if (((family == AF_INET) && zebra_rnh_ip_default_route)
|
||||
@ -87,6 +89,4 @@ extern void zebra_evaluate_rnh(vrf_id_t vrfid, int family, int force,
|
||||
extern void zebra_print_rnh_table(vrf_id_t vrfid, int family, struct vty *vty,
|
||||
rnh_type_t);
|
||||
extern char *rnh_str(struct rnh *rnh, char *buf, int size);
|
||||
extern int zebra_cleanup_rnh_client(vrf_id_t vrf, int family,
|
||||
struct zserv *client, rnh_type_t type);
|
||||
#endif /*_ZEBRA_RNH_H */
|
||||
|
@ -22,6 +22,8 @@
|
||||
#ifndef __ZEBRA_ROUTEMAP_H__
|
||||
#define __ZEBRA_ROUTEMAP_H__
|
||||
|
||||
#include "lib/routemap.h"
|
||||
|
||||
extern void zebra_route_map_init(void);
|
||||
extern void zebra_routemap_config_write_protocol(struct vty *vty);
|
||||
extern char *zebra_get_import_table_route_map(afi_t afi, uint32_t table);
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "vty.h"
|
||||
|
||||
#include "zebra/debug.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
#include "zebra/zebra_rnh.h"
|
||||
|
3058
zebra/zserv.c
3058
zebra/zserv.c
File diff suppressed because it is too large
Load Diff
100
zebra/zserv.h
100
zebra/zserv.h
@ -1,17 +1,19 @@
|
||||
/* Zebra daemon server header.
|
||||
* Copyright (C) 1997, 98 Kunihiro Ishiguro
|
||||
/*
|
||||
* Zebra API server.
|
||||
* Portions:
|
||||
* Copyright (C) 1997-1999 Kunihiro Ishiguro
|
||||
* Copyright (C) 2015-2018 Cumulus Networks, Inc.
|
||||
* et al.
|
||||
*
|
||||
* This file is part of GNU Zebra.
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* GNU Zebra is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* GNU Zebra is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; see the file COPYING; if not, write to the Free Software
|
||||
@ -21,18 +23,22 @@
|
||||
#ifndef _ZEBRA_ZSERV_H
|
||||
#define _ZEBRA_ZSERV_H
|
||||
|
||||
#include "rib.h"
|
||||
#include "if.h"
|
||||
#include "workqueue.h"
|
||||
#include "vrf.h"
|
||||
#include "routemap.h"
|
||||
#include "vty.h"
|
||||
#include "zclient.h"
|
||||
#include "pbr.h"
|
||||
/* clang-format off */
|
||||
#include <stdint.h> /* for uint32_t, uint8_t */
|
||||
#include <time.h> /* for time_t */
|
||||
|
||||
#include "zebra/zebra_ns.h"
|
||||
#include "zebra/zebra_pw.h"
|
||||
//#include "zebra/zebra_pbr.h"
|
||||
#include "lib/route_types.h" /* for ZEBRA_ROUTE_MAX */
|
||||
#include "lib/zebra.h" /* for AFI_MAX */
|
||||
#include "lib/vrf.h" /* for vrf_bitmap_t */
|
||||
#include "lib/zclient.h" /* for redist_proto */
|
||||
#include "lib/stream.h" /* for stream, stream_fifo */
|
||||
#include "lib/thread.h" /* for thread, thread_master */
|
||||
#include "lib/linklist.h" /* for list */
|
||||
#include "lib/workqueue.h" /* for work_queue */
|
||||
#include "lib/hook.h" /* for DECLARE_HOOK, DECLARE_KOOH */
|
||||
|
||||
#include "zebra/zebra_vrf.h" /* for zebra_vrf */
|
||||
/* clang-format on */
|
||||
|
||||
/* Default port information. */
|
||||
#define ZEBRA_VTY_PORT 2601
|
||||
@ -85,7 +91,7 @@ struct zserv {
|
||||
|
||||
/* client's protocol */
|
||||
uint8_t proto;
|
||||
unsigned short instance;
|
||||
uint16_t instance;
|
||||
uint8_t is_synchronous;
|
||||
|
||||
/* Statistics */
|
||||
@ -138,6 +144,10 @@ struct zserv {
|
||||
struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
|
||||
struct zebra_vrf *zvrf
|
||||
|
||||
/* Hooks for client connect / disconnect */
|
||||
DECLARE_HOOK(zapi_client_connect, (struct zserv *client), (client));
|
||||
DECLARE_KOOH(zapi_client_close, (struct zserv *client), (client));
|
||||
|
||||
/* Zebra instance */
|
||||
struct zebra_t {
|
||||
/* Thread master */
|
||||
@ -164,48 +174,6 @@ extern unsigned int multipath_num;
|
||||
/* Prototypes. */
|
||||
extern void zserv_init(void);
|
||||
extern void zebra_zserv_socket_init(char *path);
|
||||
|
||||
extern int zsend_vrf_add(struct zserv *, struct zebra_vrf *);
|
||||
extern int zsend_vrf_delete(struct zserv *, struct zebra_vrf *);
|
||||
|
||||
extern int zsend_interface_add(struct zserv *, struct interface *);
|
||||
extern int zsend_interface_delete(struct zserv *, struct interface *);
|
||||
extern int zsend_interface_addresses(struct zserv *, struct interface *);
|
||||
extern int zsend_interface_address(int, struct zserv *, struct interface *,
|
||||
struct connected *);
|
||||
extern void nbr_connected_add_ipv6(struct interface *, struct in6_addr *);
|
||||
extern void nbr_connected_delete_ipv6(struct interface *, struct in6_addr *);
|
||||
extern int zsend_interface_update(int, struct zserv *, struct interface *);
|
||||
extern int zsend_redistribute_route(int, struct zserv *, struct prefix *,
|
||||
struct prefix *, struct route_entry *);
|
||||
extern int zsend_router_id_update(struct zserv *, struct prefix *, vrf_id_t);
|
||||
extern int zsend_interface_vrf_update(struct zserv *, struct interface *,
|
||||
vrf_id_t);
|
||||
|
||||
extern int zsend_interface_link_params(struct zserv *, struct interface *);
|
||||
extern int zsend_pw_update(struct zserv *, struct zebra_pw *);
|
||||
|
||||
extern int zsend_route_notify_owner(struct route_entry *re, struct prefix *p,
|
||||
enum zapi_route_notify_owner note);
|
||||
|
||||
struct zebra_pbr_ipset;
|
||||
struct zebra_pbr_ipset_entry;
|
||||
struct zebra_pbr_iptable;
|
||||
struct zebra_pbr_rule;
|
||||
extern void zsend_rule_notify_owner(struct zebra_pbr_rule *rule,
|
||||
enum zapi_rule_notify_owner note);
|
||||
extern void zsend_ipset_notify_owner(
|
||||
struct zebra_pbr_ipset *ipset,
|
||||
enum zapi_ipset_notify_owner note);
|
||||
extern void zsend_ipset_entry_notify_owner(
|
||||
struct zebra_pbr_ipset_entry *ipset,
|
||||
enum zapi_ipset_entry_notify_owner note);
|
||||
extern void zsend_iptable_notify_owner(
|
||||
struct zebra_pbr_iptable *iptable,
|
||||
enum zapi_iptable_notify_owner note);
|
||||
|
||||
extern void zserv_nexthop_num_warn(const char *, const struct prefix *,
|
||||
const unsigned int);
|
||||
extern int zebra_server_send_message(struct zserv *client, struct stream *msg);
|
||||
|
||||
extern struct zserv *zebra_find_client(uint8_t proto, unsigned short instance);
|
||||
|
Loading…
Reference in New Issue
Block a user