+// SPDX-License-Identifier: GPL-2.0-or-later
/* Zebra's client library.
* Copyright (C) 1999 Kunihiro Ishiguro
* Copyright (C) 2005 Andrew J. Schorr
- *
- * This file is part of GNU Zebra.
- *
- * 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.
- *
- * 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 <zebra.h>
#include "vrf_int.h"
#include "if.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "zclient.h"
#include "memory.h"
#include "table.h"
static int zclient_debug;
/* Allocate zclient structure. */
-struct zclient *zclient_new(struct thread_master *master,
+struct zclient *zclient_new(struct event_loop *master,
struct zclient_options *opt,
zclient_handler *const *handlers, size_t n_handlers)
{
zlog_debug("zclient %p stopped", zclient);
/* Stop threads. */
- THREAD_OFF(zclient->t_read);
- THREAD_OFF(zclient->t_connect);
- THREAD_OFF(zclient->t_write);
+ EVENT_OFF(zclient->t_read);
+ EVENT_OFF(zclient->t_connect);
+ EVENT_OFF(zclient->t_write);
/* Reset streams. */
stream_reset(zclient->ibuf);
return ZCLIENT_SEND_FAILURE;
}
-static void zclient_flush_data(struct thread *thread)
+static void zclient_flush_data(struct event *thread)
{
- struct zclient *zclient = THREAD_ARG(thread);
+ struct zclient *zclient = EVENT_ARG(thread);
zclient->t_write = NULL;
if (zclient->sock < 0)
return;
case BUFFER_PENDING:
zclient->t_write = NULL;
- thread_add_write(zclient->master, zclient_flush_data, zclient,
- zclient->sock, &zclient->t_write);
+ event_add_write(zclient->master, zclient_flush_data, zclient,
+ zclient->sock, &zclient->t_write);
break;
case BUFFER_EMPTY:
if (zclient->zebra_buffer_write_ready)
__func__, zclient->sock);
return zclient_failed(zclient);
case BUFFER_EMPTY:
- THREAD_OFF(zclient->t_write);
+ EVENT_OFF(zclient->t_write);
return ZCLIENT_SEND_SUCCESS;
case BUFFER_PENDING:
- thread_add_write(zclient->master, zclient_flush_data, zclient,
- zclient->sock, &zclient->t_write);
+ event_add_write(zclient->master, zclient_flush_data, zclient,
+ zclient->sock, &zclient->t_write);
return ZCLIENT_SEND_BUFFERED;
}
/* This function is a wrapper function for calling zclient_start from
timer or event thread. */
-static void zclient_connect(struct thread *t)
+static void zclient_connect(struct event *t)
{
struct zclient *zclient;
- zclient = THREAD_ARG(t);
+ zclient = EVENT_ARG(t);
zclient->t_connect = NULL;
if (zclient_debug)
static int link_params_set_value(struct stream *s, struct interface *ifp)
{
- uint8_t link_params_enabled;
+ uint8_t link_params_enabled, nb_ext_adm_grp;
struct if_link_params *iflp;
- uint32_t bwclassnum;
+ uint32_t bwclassnum, bitmap_data;
iflp = if_link_params_get(ifp);
__func__, bwclassnum, MAX_CLASS_TYPE);
}
STREAM_GETL(s, iflp->admin_grp);
+
+ /* Extended Administrative Group */
+ admin_group_clear(&iflp->ext_admin_grp);
+ STREAM_GETC(s, nb_ext_adm_grp);
+ for (size_t i = 0; i < nb_ext_adm_grp; i++) {
+ STREAM_GETL(s, bitmap_data);
+ admin_group_bulk_set(&iflp->ext_admin_grp, bitmap_data, i);
+ }
+
STREAM_GETL(s, iflp->rmt_as);
iflp->rmt_ip.s_addr = stream_get_ipv4(s);
bool *changed)
{
struct if_link_params *iflp;
- struct if_link_params iflp_prev;
+ struct if_link_params iflp_prev = {0};
ifindex_t ifindex;
- bool iflp_prev_set;
+ bool iflp_prev_set = false;
STREAM_GETL(s, ifindex);
return NULL;
}
- if (if_link_params_get(ifp)) {
+ iflp = if_link_params_get(ifp);
+
+ if (iflp) {
iflp_prev_set = true;
- memcpy(&iflp_prev, ifp->link_params, sizeof(iflp_prev));
- } else
- iflp_prev_set = false;
+ admin_group_init(&iflp_prev.ext_admin_grp);
+ if_link_params_copy(&iflp_prev, iflp);
+ }
/* read the link_params from stream
* Free ifp->link_params if the stream has no params
if (link_params_set_value(s, ifp) != 0)
goto stream_failure;
- if (changed == NULL)
- return ifp;
+ if (changed != NULL) {
+ iflp = if_link_params_get(ifp);
- iflp = if_link_params_get(ifp);
-
- if (iflp_prev_set && iflp) {
- if (memcmp(&iflp_prev, iflp, sizeof(iflp_prev)))
- *changed = true;
- else
+ if (iflp_prev_set && iflp) {
+ if (if_link_params_cmp(&iflp_prev, iflp))
+ *changed = false;
+ else
+ *changed = true;
+ } else if (!iflp_prev_set && !iflp)
*changed = false;
- } else if (!iflp_prev_set && !iflp)
- *changed = false;
- else
- *changed = true;
+ else
+ *changed = true;
+ }
+
+ if (iflp_prev_set)
+ admin_group_term(&iflp_prev.ext_admin_grp);
return ifp;
stream_failure:
+ if (iflp_prev_set)
+ admin_group_term(&iflp_prev.ext_admin_grp);
return NULL;
}
size_t zebra_interface_link_params_write(struct stream *s,
struct interface *ifp)
{
- size_t w;
+ size_t w, nb_ext_adm_grp;
struct if_link_params *iflp;
int i;
+
if (s == NULL || ifp == NULL)
return 0;
w += stream_putf(s, iflp->unrsv_bw[i]);
w += stream_putl(s, iflp->admin_grp);
+
+ /* Extended Administrative Group */
+ nb_ext_adm_grp = admin_group_nb_words(&iflp->ext_admin_grp);
+ w += stream_putc(s, nb_ext_adm_grp);
+ for (size_t i = 0; i < nb_ext_adm_grp; i++)
+ stream_putl(s, admin_group_get_offset(&iflp->ext_admin_grp, i));
+
w += stream_putl(s, iflp->rmt_as);
w += stream_put_in_addr(s, &iflp->rmt_ip);
};
/* Zebra client message read function. */
-static void zclient_read(struct thread *thread)
+static void zclient_read(struct event *thread)
{
size_t already;
uint16_t length, command;
struct zclient *zclient;
/* Get socket to zebra. */
- zclient = THREAD_ARG(thread);
+ zclient = EVENT_ARG(thread);
zclient->t_read = NULL;
/* Read zebra header (if we don't have it already). */
{
switch (event) {
case ZCLIENT_SCHEDULE:
- thread_add_event(zclient->master, zclient_connect, zclient, 0,
- &zclient->t_connect);
+ event_add_event(zclient->master, zclient_connect, zclient, 0,
+ &zclient->t_connect);
break;
case ZCLIENT_CONNECT:
if (zclient_debug)
zlog_debug(
"zclient connect failures: %d schedule interval is now %d",
zclient->fail, zclient->fail < 3 ? 10 : 60);
- thread_add_timer(zclient->master, zclient_connect, zclient,
- zclient->fail < 3 ? 10 : 60,
- &zclient->t_connect);
+ event_add_timer(zclient->master, zclient_connect, zclient,
+ zclient->fail < 3 ? 10 : 60,
+ &zclient->t_connect);
break;
case ZCLIENT_READ:
zclient->t_read = NULL;
- thread_add_read(zclient->master, zclient_read, zclient,
- zclient->sock, &zclient->t_read);
+ event_add_read(zclient->master, zclient_read, zclient,
+ zclient->sock, &zclient->t_read);
break;
}
}