Merge pull request #1828 from qlyoung/zapi-cleanup

zebra: giant zapi cleanup
This commit is contained in:
Renato Westphal 2018-03-12 22:43:05 -03:00 committed by GitHub
commit ecef81cea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1171 additions and 1145 deletions

View File

@ -322,6 +322,18 @@ stream_failure:
return 0;
}
bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr)
{
STREAM_GETW(zmsg, hdr->length);
STREAM_GETC(zmsg, hdr->marker);
STREAM_GETC(zmsg, hdr->version);
STREAM_GETL(zmsg, hdr->vrf_id);
STREAM_GETW(zmsg, hdr->command);
return true;
stream_failure:
return false;
}
/* Send simple Zebra message. */
static int zebra_message_send(struct zclient *zclient, int command,
vrf_id_t vrf_id)

View File

@ -237,14 +237,13 @@ struct zclient {
*/
#define ZAPI_MESSAGE_TABLEID 0x80
#define ZSERV_VERSION 5
/* Zserv protocol message header */
struct zserv_header {
struct zmsghdr {
uint16_t length;
uint8_t marker; /* corresponds to command field in old zserv
* always set to 255 in new zserv.
*/
/* Always set to 255 in new zserv */
uint8_t marker;
uint8_t version;
#define ZSERV_VERSION 5
vrf_id_t vrf_id;
uint16_t command;
};
@ -380,9 +379,11 @@ struct zclient_options {
/* Prototypes of zebra client service functions. */
extern struct zclient *zclient_new(struct thread_master *);
/* clang-format off */
#if CONFDATE > 20181101
CPP_NOTICE("zclient_new_notify can take over or zclient_new now");
#endif
/* clang-format on */
extern struct zclient_options zclient_options_default;
@ -449,9 +450,58 @@ extern int zclient_send_message(struct zclient *);
/* create header for command, length to be filled in by user later */
extern void zclient_create_header(struct stream *, uint16_t, vrf_id_t);
/*
* Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
* received data into the specified fields. If this is successful, read the
* rest of the packet into the provided stream.
*
* s
* The stream to read into
*
* sock
* The socket to read from
*
* size
* Parsed message size will be placed in the pointed-at integer
*
* marker
* Parsed marker will be placed in the pointed-at byte
*
* version
* Parsed version will be placed in the pointed-at byte
*
* vrf_id
* Parsed VRF ID will be placed in the pointed-at vrf_id_t
*
* cmd
* Parsed command number will be placed in the pointed-at integer
*
* Returns:
* -1 if:
* - insufficient data for header was read
* - a version mismatch was detected
* - a marker mismatch was detected
* - header size field specified more data than could be read
*/
extern int zclient_read_header(struct stream *s, int sock, u_int16_t *size,
u_char *marker, u_char *version,
vrf_id_t *vrf_id, u_int16_t *cmd);
/*
* Parse header from ZAPI message stream into struct zmsghdr.
* This function assumes the stream getp points at the first byte of the header.
* If the function is successful then the stream getp will point to the byte
* immediately after the last byte of the header.
*
* zmsg
* The stream containing the header
*
* hdr
* The header struct to parse into.
*
* Returns:
* true if parsing succeeded, false otherwise
*/
extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr);
extern void zclient_interface_set_master(struct zclient *client,
struct interface *master,
@ -468,10 +518,11 @@ extern struct interface *zebra_interface_vrf_update_read(struct stream *s,
extern void zebra_interface_if_set_value(struct stream *, struct interface *);
extern void zebra_router_id_update_read(struct stream *s, struct prefix *rid);
/* clang-format off */
#if CONFDATE > 20180823
CPP_NOTICE(
"zapi_ipv4_route, zapi_ipv6_route, zapi_ipv4_route_ipv6_nexthop as well as the zapi_ipv4 and zapi_ipv6 data structures should be removed now");
CPP_NOTICE("zapi_ipv4_route, zapi_ipv6_route, zapi_ipv4_route_ipv6_nexthop as well as the zapi_ipv4 and zapi_ipv6 data structures should be removed now");
#endif
/* clang-format on */
extern int zapi_ipv4_route(u_char, struct zclient *, struct prefix_ipv4 *,
struct zapi_ipv4 *) __attribute__((deprecated));

View File

@ -50,6 +50,8 @@ DEFINE_MTYPE_STATIC(LBL_MGR, LM_CHUNK, "Label Manager Chunk");
* it will be a proxy to relay messages to external label manager
* This zclient thus is to connect to it
*/
static struct stream *ibuf;
static struct stream *obuf;
static struct zclient *zclient;
bool lm_is_external;
@ -69,7 +71,7 @@ static int relay_response_back(struct zserv *zserv)
u_int16_t resp_cmd;
src = zclient->ibuf;
dst = zserv->obuf;
dst = obuf;
stream_reset(src);
@ -87,7 +89,7 @@ static int relay_response_back(struct zserv *zserv)
/* send response back */
stream_copy(dst, src);
ret = writen(zserv->sock, dst->data, stream_get_endp(dst));
ret = writen(zserv->sock, src->data, stream_get_endp(src));
if (ret <= 0) {
zlog_err("%s: Error sending Label Manager response back: %s",
__func__, strerror(errno));
@ -116,10 +118,10 @@ static int lm_zclient_read(struct thread *t)
static int reply_error(int cmd, struct zserv *zserv, vrf_id_t vrf_id)
{
int ret;
struct stream *s;
s = zserv->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, cmd, vrf_id);
@ -129,7 +131,10 @@ static int reply_error(int cmd, struct zserv *zserv, vrf_id_t vrf_id)
/* Write packet size. */
stream_putw_at(s, 0, stream_get_endp(s));
return writen(zserv->sock, s->data, stream_get_endp(s));
ret = writen(zserv->sock, s->data, stream_get_endp(s));
stream_free(s);
return ret;
}
/**
* Receive a request to get or release a label chunk and forward it to external
@ -161,7 +166,7 @@ int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
ret = relay_response_back(zserv);
/* Send request to external label manager */
src = zserv->ibuf;
src = ibuf;
dst = zclient->obuf;
stream_copy(dst, src);
@ -247,6 +252,9 @@ void label_manager_init(char *lm_zserv_path)
lm_is_external = true;
lm_zclient_init(lm_zserv_path);
}
ibuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
obuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
}
/**
@ -379,4 +387,6 @@ int release_daemon_chunks(u_char proto, u_short instance)
void label_manager_close()
{
list_delete_and_null(&lbl_mgr.lc_list);
stream_free(ibuf);
stream_free(obuf);
}

View File

@ -243,16 +243,15 @@ void redistribute_delete(struct prefix *p, struct prefix *src_p,
}
}
void zebra_redistribute_add(int command, struct zserv *client, int length,
struct zebra_vrf *zvrf)
void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
{
afi_t afi = 0;
int type = 0;
u_short instance;
STREAM_GETC(client->ibuf, afi);
STREAM_GETC(client->ibuf, type);
STREAM_GETW(client->ibuf, instance);
STREAM_GETC(msg, afi);
STREAM_GETC(msg, type);
STREAM_GETW(msg, instance);
if (afi == 0 || afi > AFI_MAX) {
zlog_warn("%s: Specified afi %d does not exist",
@ -287,16 +286,15 @@ stream_failure:
return;
}
void zebra_redistribute_delete(int command, struct zserv *client, int length,
struct zebra_vrf *zvrf)
void zebra_redistribute_delete(ZAPI_HANDLER_ARGS)
{
afi_t afi = 0;
int type = 0;
u_short instance;
STREAM_GETC(client->ibuf, afi);
STREAM_GETC(client->ibuf, type);
STREAM_GETW(client->ibuf, instance);
STREAM_GETC(msg, afi);
STREAM_GETC(msg, type);
STREAM_GETW(msg, instance);
if (afi == 0 || afi > AFI_MAX) {
zlog_warn("%s: Specified afi %d does not exist",
@ -325,15 +323,13 @@ stream_failure:
return;
}
void zebra_redistribute_default_add(int command, struct zserv *client,
int length, struct zebra_vrf *zvrf)
void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS)
{
vrf_bitmap_set(client->redist_default, zvrf_id(zvrf));
zebra_redistribute_default(client, zvrf_id(zvrf));
}
void zebra_redistribute_default_delete(int command, struct zserv *client,
int length, struct zebra_vrf *zvrf)
void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS)
{
vrf_bitmap_unset(client->redist_default, zvrf_id(zvrf));
}

View File

@ -27,15 +27,12 @@
#include "vty.h"
#include "vrf.h"
extern void zebra_redistribute_add(int, struct zserv *, int,
struct zebra_vrf *zvrf);
extern void zebra_redistribute_delete(int, struct zserv *, int,
struct zebra_vrf *zvrf);
extern void zebra_redistribute_default_add(int, struct zserv *, int,
struct zebra_vrf *zvrf);
extern void zebra_redistribute_default_delete(int, struct zserv *, int,
struct zebra_vrf *zvrf);
/* ZAPI command handlers */
extern void zebra_redistribute_add(ZAPI_HANDLER_ARGS);
extern void zebra_redistribute_delete(ZAPI_HANDLER_ARGS);
extern void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS);
extern void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS);
/* ----------------- */
extern void redistribute_update(struct prefix *, struct prefix *,
struct route_entry *, struct route_entry *);

View File

@ -801,8 +801,7 @@ static void ipv6_nd_suppress_ra_set(struct interface *ifp,
* if the operator has explicitly enabled RA. The enable request can also
* specify a RA interval (in seconds).
*/
void zebra_interface_radv_set(struct zserv *client, u_short length,
struct zebra_vrf *zvrf, int enable)
static void zebra_interface_radv_set(ZAPI_HANDLER_ARGS, int enable)
{
struct stream *s;
ifindex_t ifindex;
@ -810,7 +809,7 @@ void zebra_interface_radv_set(struct zserv *client, u_short length,
struct zebra_if *zif;
int ra_interval;
s = client->ibuf;
s = msg;
/* Get interface index and RA interval. */
STREAM_GETL(s, ifindex);
@ -859,6 +858,15 @@ stream_failure:
return;
}
void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS)
{
zebra_interface_radv_set(client, hdr, msg, zvrf, 0);
}
void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS)
{
zebra_interface_radv_set(client, hdr, msg, zvrf, 1);
}
DEFUN (ipv6_nd_suppress_ra,
ipv6_nd_suppress_ra_cmd,
"ipv6 nd suppress-ra",

View File

@ -103,7 +103,8 @@ typedef enum {
extern void rtadv_init(struct zebra_ns *);
extern void rtadv_terminate(struct zebra_ns *);
extern void rtadv_cmd_init(void);
extern void zebra_interface_radv_set(struct zserv *client, u_short length,
struct zebra_vrf *zvrf, int enable);
extern void zebra_interface_radv_disable(ZAPI_HANDLER_ARGS);
extern void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS);
#endif /* _ZEBRA_RTADV_H */

View File

@ -455,8 +455,7 @@ static int fec_send(zebra_fec_t *fec, struct zserv *client)
rn = fec->rn;
/* Get output stream. */
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, ZEBRA_FEC_UPDATE, VRF_DEFAULT);
@ -464,7 +463,7 @@ static int fec_send(zebra_fec_t *fec, struct zserv *client)
stream_put_prefix(s, &rn->p);
stream_putl(s, fec->label);
stream_putw_at(s, 0, stream_get_endp(s));
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
/*

View File

@ -32,17 +32,16 @@
#include "zebra/rt.h"
#include "zebra/debug.h"
int zebra_ipmr_route_stats(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_ipmr_route_stats(ZAPI_HANDLER_ARGS)
{
struct mcast_route_data mroute;
struct stream *s;
int suc = -1;
memset(&mroute, 0, sizeof(mroute));
STREAM_GET(&mroute.sg.src, client->ibuf, 4);
STREAM_GET(&mroute.sg.grp, client->ibuf, 4);
STREAM_GETL(client->ibuf, mroute.ifindex);
STREAM_GET(&mroute.sg.src, msg, 4);
STREAM_GET(&mroute.sg.grp, msg, 4);
STREAM_GETL(msg, mroute.ifindex);
if (IS_ZEBRA_DEBUG_KERNEL) {
char sbuf[40];
@ -57,7 +56,7 @@ int zebra_ipmr_route_stats(struct zserv *client, u_short length,
suc = kernel_get_ipmr_sg_stats(zvrf, &mroute);
stream_failure:
s = client->obuf;
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
stream_reset(s);
@ -68,6 +67,5 @@ stream_failure:
stream_putl(s, suc);
stream_putw_at(s, 0, stream_get_endp(s));
zebra_server_send_message(client);
return 0;
zebra_server_send_message(client, s);
}

View File

@ -22,13 +22,14 @@
#ifndef __ZEBRA_MROUTE_H__
#define __ZEBRA_MROUTE_H__
#include "zebra/zserv.h"
struct mcast_route_data {
struct prefix_sg sg;
unsigned int ifindex;
unsigned long long lastused;
};
int zebra_ipmr_route_stats(struct zserv *client, u_short length,
struct zebra_vrf *zvf);
void zebra_ipmr_route_stats(ZAPI_HANDLER_ARGS);
#endif

View File

@ -661,8 +661,7 @@ int zebra_ptm_sock_read(struct thread *thread)
}
/* BFD peer/dst register/update */
int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
int command, struct zebra_vrf *zvrf)
void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS)
{
struct stream *s;
struct prefix src_p;
@ -680,20 +679,20 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
int data_len = ZEBRA_PTM_SEND_MAX_SOCKBUF;
unsigned int pid;
if (command == ZEBRA_BFD_DEST_UPDATE)
if (hdr->command == ZEBRA_BFD_DEST_UPDATE)
client->bfd_peer_upd8_cnt++;
else
client->bfd_peer_add_cnt++;
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("bfd_dst_register msg from client %s: length=%d",
zebra_route_string(client->proto), length);
zebra_route_string(client->proto), hdr->length);
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return -1;
return;
}
ptm_lib_init_msg(ptm_hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL, &out_ctxt);
@ -703,7 +702,7 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_CLIENT_FIELD,
tmp_buf);
s = client->ibuf;
s = msg;
STREAM_GETL(s, pid);
sprintf(tmp_buf, "%d", pid);
@ -816,16 +815,14 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
ptm_cb.out_data);
zebra_ptm_send_message(ptm_cb.out_data, data_len);
return 0;
return;
stream_failure:
ptm_lib_cleanup_msg(ptm_hdl, out_ctxt);
return 0;
}
/* BFD peer/dst deregister */
int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS)
{
struct stream *s;
struct prefix src_p;
@ -843,13 +840,13 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("bfd_dst_deregister msg from client %s: length=%d",
zebra_route_string(client->proto), length);
zebra_route_string(client->proto), hdr->length);
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return -1;
return;
}
ptm_lib_init_msg(ptm_hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL, &out_ctxt);
@ -861,7 +858,7 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
ptm_lib_append_msg(ptm_hdl, out_ctxt, ZEBRA_PTM_BFD_CLIENT_FIELD,
tmp_buf);
s = client->ibuf;
s = msg;
STREAM_GETL(s, pid);
sprintf(tmp_buf, "%d", pid);
@ -948,15 +945,14 @@ int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
zebra_ptm_send_message(ptm_cb.out_data, data_len);
return 0;
return;
stream_failure:
ptm_lib_cleanup_msg(ptm_hdl, out_ctxt);
return 0;
}
/* BFD client register */
int zebra_ptm_bfd_client_register(struct zserv *client, u_short length)
void zebra_ptm_bfd_client_register(ZAPI_HANDLER_ARGS)
{
struct stream *s;
unsigned int pid;
@ -968,16 +964,16 @@ int zebra_ptm_bfd_client_register(struct zserv *client, u_short length)
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("bfd_client_register msg from client %s: length=%d",
zebra_route_string(client->proto), length);
zebra_route_string(client->proto), hdr->length);
s = client->ibuf;
s = msg;
STREAM_GETL(s, pid);
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
thread_add_timer(zebrad.master, zebra_ptm_connect, NULL,
ptm_cb.reconnect_time, &ptm_cb.t_timer);
return -1;
return;
}
ptm_lib_init_msg(ptm_hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL, &out_ctxt);
@ -1003,7 +999,7 @@ int zebra_ptm_bfd_client_register(struct zserv *client, u_short length)
SET_FLAG(ptm_cb.client_flags[client->proto],
ZEBRA_PTM_BFD_CLIENT_FLAG_REG);
return 0;
return;
stream_failure:
/*
@ -1013,7 +1009,7 @@ stream_failure:
* if (out_ctxt)
* ptm_lib_cleanup_msg(ptm_hdl, out_ctxt);
*/
return 0;
return;
}
/* BFD client deregister */

View File

@ -28,6 +28,8 @@ extern const char ZEBRA_PTM_SOCK_NAME[];
#define ZEBRA_PTM_BFD_CLIENT_FLAG_REG (1 << 1) /* client registered with BFD */
#include "zebra/zserv.h"
/* Zebra ptm context block */
struct zebra_ptm_cb {
int ptm_sock; /* ptm file descriptor. */
@ -62,12 +64,12 @@ int zebra_ptm_connect(struct thread *t);
void zebra_ptm_write(struct vty *vty);
int zebra_ptm_get_enable_state(void);
int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length,
int command, struct zebra_vrf *zvrf);
int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
/* ZAPI message handlers */
void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS);
void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS);
void zebra_ptm_bfd_client_register(ZAPI_HANDLER_ARGS);
void zebra_ptm_show_status(struct vty *vty, struct interface *ifp);
int zebra_ptm_bfd_client_register(struct zserv *client, u_short length);
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);

View File

@ -38,8 +38,7 @@ static int zsend_interface_bfd_update(int cmd, struct zserv *client,
if (!client->ifinfo)
return 0;
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, cmd, vrf_id);
if (ifp)
@ -66,7 +65,7 @@ static int zsend_interface_bfd_update(int cmd, struct zserv *client,
stream_putw_at(s, 0, stream_get_endp(s));
client->if_bfd_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
void zebra_interface_bfd_update(struct interface *ifp, struct prefix *dp,
@ -93,8 +92,7 @@ static int zsend_bfd_peer_replay(int cmd, struct zserv *client)
{
struct stream *s;
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, cmd, VRF_DEFAULT);
@ -102,7 +100,7 @@ static int zsend_bfd_peer_replay(int cmd, struct zserv *client)
stream_putw_at(s, 0, stream_get_endp(s));
client->bfd_peer_replay_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
void zebra_bfd_peer_replay_req(void)

View File

@ -995,8 +995,7 @@ static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type,
re = rnh->state;
/* Get output stream. */
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, cmd, vrf_id);
@ -1063,7 +1062,7 @@ static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type,
client->nh_last_upd_time = monotime(NULL);
client->last_write_cmd = cmd;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
static void print_nh(struct nexthop *nexthop, struct vty *vty)

View File

@ -1157,8 +1157,7 @@ static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
if (!client)
return 0;
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, cmd, VRF_DEFAULT);
stream_putl(s, vni);
@ -1195,7 +1194,7 @@ static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
else
client->macipdel_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
/*
@ -2565,8 +2564,7 @@ static int zvni_send_add_to_client(zebra_vni_t *zvni)
if (!client)
return 0;
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, ZEBRA_VNI_ADD, VRF_DEFAULT);
stream_putl(s, zvni->vni);
@ -2583,7 +2581,7 @@ static int zvni_send_add_to_client(zebra_vni_t *zvni)
zebra_route_string(client->proto));
client->vniadd_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
/*
@ -2599,7 +2597,7 @@ static int zvni_send_del_to_client(vni_t vni)
if (!client)
return 0;
s = client->obuf;
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
stream_reset(s);
zclient_create_header(s, ZEBRA_VNI_DEL, VRF_DEFAULT);
@ -2613,7 +2611,7 @@ static int zvni_send_del_to_client(vni_t vni)
zebra_route_string(client->proto));
client->vnidel_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
/*
@ -3550,8 +3548,7 @@ static int zl3vni_send_add_to_client(zebra_l3vni_t *zl3vni)
memset(&rmac, 0, sizeof(struct ethaddr));
zl3vni_get_rmac(zl3vni, &rmac);
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, ZEBRA_L3VNI_ADD, zl3vni_vrf_id(zl3vni));
stream_putl(s, zl3vni->vni);
@ -3574,7 +3571,7 @@ static int zl3vni_send_add_to_client(zebra_l3vni_t *zl3vni)
zebra_route_string(client->proto));
client->l3vniadd_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
/*
@ -3590,8 +3587,7 @@ static int zl3vni_send_del_to_client(zebra_l3vni_t *zl3vni)
if (!client)
return 0;
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, ZEBRA_L3VNI_DEL, zl3vni_vrf_id(zl3vni));
stream_putl(s, zl3vni->vni);
@ -3605,7 +3601,7 @@ static int zl3vni_send_del_to_client(zebra_l3vni_t *zl3vni)
zebra_route_string(client->proto));
client->l3vnidel_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t *zl3vni)
@ -3723,8 +3719,7 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p,
if (!client)
return 0;
s = client->obuf;
stream_reset(s);
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
zclient_create_header(s, cmd, vrf_id);
stream_put(s, p, sizeof(struct prefix));
@ -3743,7 +3738,7 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p,
else
client->prefixdel_cnt++;
return zebra_server_send_message(client);
return zebra_server_send_message(client, s);
}
/* re-add remote rmac if needed */
@ -4863,8 +4858,7 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp,
/*
* Handle message from client to delete a remote MACIP for a VNI.
*/
int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS)
{
struct stream *s;
vni_t vni;
@ -4884,9 +4878,9 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length,
memset(&ip, 0, sizeof(struct ipaddr));
memset(&vtep_ip, 0, sizeof(struct in_addr));
s = client->ibuf;
s = msg;
while (l < length) {
while (l < hdr->length) {
/* Obtain each remote MACIP and process. */
/* Message contains VNI, followed by MAC followed by IP (if any)
* followed by remote VTEP IP.
@ -5008,7 +5002,7 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length,
}
stream_failure:
return 0;
return;
}
/*
@ -5016,8 +5010,7 @@ stream_failure:
* could be just the add of a MAC address or the add of a neighbor
* (IP+MAC).
*/
int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS)
{
struct stream *s;
vni_t vni;
@ -5045,12 +5038,12 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length,
zlog_warn(
"%s: EVPN Not turned on yet we have received a remote_macip add zapi callback",
__PRETTY_FUNCTION__);
return -1;
return;
}
s = client->ibuf;
s = msg;
while (l < length) {
while (l < hdr->length) {
/* Obtain each remote MACIP and process. */
/* Message contains VNI, followed by MAC followed by IP (if any)
* followed by remote VTEP IP.
@ -5159,7 +5152,7 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length,
prefix_mac2str(&macaddr, buf,
sizeof(buf)),
vni, inet_ntoa(vtep_ip));
return -1;
return;
}
/* Is this MAC created for a MACIP? */
@ -5212,7 +5205,7 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length,
prefix_mac2str(&macaddr, buf,
sizeof(buf)),
vni, inet_ntoa(vtep_ip));
return -1;
return;
}
} else if (memcmp(&n->emac, &macaddr, sizeof(macaddr))
@ -5240,7 +5233,7 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length,
}
stream_failure:
return 0;
return;
}
/*
@ -5543,8 +5536,7 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
/*
* Handle message from client to delete a remote VTEP for a VNI.
*/
int zebra_vxlan_remote_vtep_del(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_vxlan_remote_vtep_del(ZAPI_HANDLER_ARGS)
{
struct stream *s;
u_short l = 0;
@ -5559,18 +5551,18 @@ int zebra_vxlan_remote_vtep_del(struct zserv *client, u_short length,
zlog_warn(
"%s: EVPN is not enabled yet we have received a vtep del command",
__PRETTY_FUNCTION__);
return -1;
return;
}
if (zvrf_id(zvrf) != VRF_DEFAULT) {
zlog_err("Recv MACIP DEL for non-default VRF %u",
zvrf_id(zvrf));
return -1;
return;
}
s = client->ibuf;
s = msg;
while (l < length) {
while (l < hdr->length) {
/* Obtain each remote VTEP and process. */
STREAM_GETL(s, vni);
l += 4;
@ -5623,14 +5615,13 @@ int zebra_vxlan_remote_vtep_del(struct zserv *client, u_short length,
}
stream_failure:
return 0;
return;
}
/*
* Handle message from client to add a remote VTEP for a VNI.
*/
int zebra_vxlan_remote_vtep_add(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_vxlan_remote_vtep_add(ZAPI_HANDLER_ARGS)
{
struct stream *s;
u_short l = 0;
@ -5644,18 +5635,18 @@ int zebra_vxlan_remote_vtep_add(struct zserv *client, u_short length,
zlog_warn(
"%s: EVPN not enabled yet we received a vtep_add zapi call",
__PRETTY_FUNCTION__);
return -1;
return;
}
if (zvrf_id(zvrf) != VRF_DEFAULT) {
zlog_err("Recv MACIP ADD for non-default VRF %u",
zvrf_id(zvrf));
return -1;
return;
}
s = client->ibuf;
s = msg;
while (l < length) {
while (l < hdr->length) {
/* Obtain each remote VTEP and process. */
STREAM_GETL(s, vni);
l += 4;
@ -5705,7 +5696,7 @@ int zebra_vxlan_remote_vtep_add(struct zserv *client, u_short length,
}
stream_failure:
return 0;
return;
}
/*
@ -6512,8 +6503,7 @@ int zebra_vxlan_vrf_delete(struct zebra_vrf *zvrf)
* Handle message from client to enable/disable advertisement of g/w macip
* routes
*/
int zebra_vxlan_advertise_subnet(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS)
{
struct stream *s;
int advertise;
@ -6527,19 +6517,19 @@ int zebra_vxlan_advertise_subnet(struct zserv *client, u_short length,
if (zvrf_id(zvrf) != VRF_DEFAULT) {
zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
zvrf_id(zvrf));
return -1;
return;
}
s = client->ibuf;
s = msg;
advertise = stream_getc(s);
vni = stream_get3(s);
zvni = zvni_lookup(vni);
if (!zvni)
return 0;
return;
if (zvni->advertise_subnet == advertise)
return 0;
return;
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug("EVPN subnet Adv %s on VNI %d , currently %s",
@ -6551,35 +6541,32 @@ int zebra_vxlan_advertise_subnet(struct zserv *client, u_short length,
ifp = zvni->vxlan_if;
if (!ifp)
return 0;
return;
zif = ifp->info;
/* If down or not mapped to a bridge, we're done. */
if (!if_is_operative(ifp) || !zif->brslave_info.br_if)
return 0;
return;
zl2_info = zif->l2info.vxl;
vlan_if =
zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if);
if (!vlan_if)
return 0;
return;
if (zvni->advertise_subnet)
zvni_advertise_subnet(zvni, vlan_if, 1);
else
zvni_advertise_subnet(zvni, vlan_if, 0);
return 0;
}
/*
* Handle message from client to enable/disable advertisement of g/w macip
* routes
*/
int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS)
{
struct stream *s;
int advertise;
@ -6590,10 +6577,10 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length,
if (zvrf_id(zvrf) != VRF_DEFAULT) {
zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
zvrf_id(zvrf));
return -1;
return;
}
s = client->ibuf;
s = msg;
STREAM_GETC(s, advertise);
STREAM_GET(&vni, s, 3);
@ -6606,7 +6593,7 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length,
: "disabled");
if (zvrf->advertise_gw_macip == advertise)
return 0;
return;
zvrf->advertise_gw_macip = advertise;
@ -6625,7 +6612,7 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length,
zvni = zvni_lookup(vni);
if (!zvni)
return 0;
return;
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
@ -6635,26 +6622,26 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length,
: "disabled");
if (zvni->advertise_gw_macip == advertise)
return 0;
return;
zvni->advertise_gw_macip = advertise;
ifp = zvni->vxlan_if;
if (!ifp)
return 0;
return;
zif = ifp->info;
/* If down or not mapped to a bridge, we're done. */
if (!if_is_operative(ifp) || !zif->brslave_info.br_if)
return 0;
return;
zl2_info = zif->l2info.vxl;
vlan_if = zvni_map_to_svi(zl2_info.access_vlan,
zif->brslave_info.br_if);
if (!vlan_if)
return 0;
return;
if (advertise_gw_macip_enabled(zvni)) {
/* Add primary SVI MAC-IP */
@ -6676,7 +6663,7 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length,
}
stream_failure:
return 0;
return;
}
@ -6686,8 +6673,7 @@ stream_failure:
* when disabled, the entries should be deleted and remote VTEPs and MACs
* uninstalled from the kernel.
*/
int zebra_vxlan_advertise_all_vni(struct zserv *client, u_short length,
struct zebra_vrf *zvrf)
void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS)
{
struct stream *s = NULL;
int advertise = 0;
@ -6695,10 +6681,10 @@ int zebra_vxlan_advertise_all_vni(struct zserv *client, u_short length,
if (zvrf_id(zvrf) != VRF_DEFAULT) {
zlog_err("EVPN VNI Adv for non-default VRF %u", zvrf_id(zvrf));
return -1;
return;
}
s = client->ibuf;
s = msg;
STREAM_GETC(s, advertise);
if (IS_ZEBRA_DEBUG_VXLAN)
@ -6707,7 +6693,7 @@ int zebra_vxlan_advertise_all_vni(struct zserv *client, u_short length,
is_evpn_enabled() ? "enabled" : "disabled");
if (zvrf->advertise_all_vni == advertise)
return 0;
return;
zvrf->advertise_all_vni = advertise;
if (is_evpn_enabled()) {
@ -6732,13 +6718,13 @@ int zebra_vxlan_advertise_all_vni(struct zserv *client, u_short length,
/* cleanup all l3vnis */
zns = zebra_ns_lookup(NS_DEFAULT);
if (!zns)
return -1;
return;
hash_iterate(zns->l3vni_table, zl3vni_cleanup_all, NULL);
}
stream_failure:
return 0;
return;
}
/*

View File

@ -33,6 +33,7 @@
#include "lib/json.h"
#include "zebra/zebra_vrf.h"
#include "zebra/zserv.h"
/* Is EVPN enabled? */
#define EVPN_ENABLED(zvrf) (zvrf)->advertise_all_vni
@ -51,6 +52,15 @@ static inline int is_evpn_enabled()
#define VNI_STR_LEN 32
/* ZAPI message handlers */
extern void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS);
extern void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS);
extern void zebra_vxlan_remote_vtep_add(ZAPI_HANDLER_ARGS);
extern void zebra_vxlan_remote_vtep_del(ZAPI_HANDLER_ARGS);
extern void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS);
extern void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS);
extern void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS);
extern int is_l3vni_for_prefix_routes_only(vni_t vni);
extern ifindex_t get_l3vni_svi_ifindex(vrf_id_t vrf_id);
extern int zebra_vxlan_vrf_delete(struct zebra_vrf *zvrf);
@ -117,10 +127,6 @@ extern int zebra_vxlan_local_neigh_add_update(
extern int zebra_vxlan_local_neigh_del(struct interface *ifp,
struct interface *link_if,
struct ipaddr *ip);
extern int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
extern int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
extern int zebra_vxlan_local_mac_add_update(struct interface *ifp,
struct interface *br_if,
struct ethaddr *mac, vlanid_t vid,
@ -140,16 +146,6 @@ extern int zebra_vxlan_if_down(struct interface *ifp);
extern int zebra_vxlan_if_add(struct interface *ifp);
extern int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags);
extern int zebra_vxlan_if_del(struct interface *ifp);
extern int zebra_vxlan_remote_vtep_add(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
extern int zebra_vxlan_remote_vtep_del(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
extern int zebra_vxlan_advertise_subnet(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
extern int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
extern int zebra_vxlan_advertise_all_vni(struct zserv *client, u_short length,
struct zebra_vrf *zvrf);
extern int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, vni_t vni,
char *err, int err_str_sz,
int filter, int add);

File diff suppressed because it is too large Load Diff

View File

@ -47,8 +47,12 @@ struct zserv {
int sock;
/* Input/output buffer to the client. */
struct stream *ibuf;
struct stream *obuf;
struct stream_fifo *ibuf_fifo;
struct stream_fifo *obuf_fifo;
/* Private I/O buffers */
struct stream *ibuf_work;
struct stream *obuf_work;
/* Buffer of data waiting to be written to client. */
struct buffer *wb;
@ -129,6 +133,10 @@ struct zserv {
int last_write_cmd;
};
#define ZAPI_HANDLER_ARGS \
struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
struct zebra_vrf *zvrf
/* Zebra instance */
struct zebra_t {
/* Thread master */
@ -185,7 +193,7 @@ extern void zsend_rule_notify_owner(struct zebra_pbr_rule *rule,
extern void zserv_nexthop_num_warn(const char *, const struct prefix *,
const unsigned int);
extern int zebra_server_send_message(struct zserv *client);
extern int zebra_server_send_message(struct zserv *client, struct stream *msg);
extern struct zserv *zebra_find_client(u_char proto, u_short instance);