DEFINE_QOBJ_TYPE(affinity_maps);
DEFINE_QOBJ_TYPE(affinity_map);
-struct affinity_maps affinity_map_master = {NULL};
+struct affinity_maps affinity_map_master = {NULL, NULL, NULL, NULL};
static void affinity_map_free(struct affinity_map *map)
{
return map->name;
return NULL;
}
+
+bool affinity_map_check_use_hook(const char *affmap_name)
+{
+ if (affinity_map_master.check_use_hook)
+ return (*affinity_map_master.check_use_hook)(affmap_name);
+ return false;
+}
+
+bool affinity_map_check_update_hook(const char *affmap_name, uint16_t new_pos)
+{
+ if (affinity_map_master.check_update_hook)
+ return (*affinity_map_master.check_update_hook)(affmap_name,
+ new_pos);
+ return true;
+}
+
+void affinity_map_update_hook(const char *affmap_name, uint16_t new_pos)
+{
+ struct affinity_map *map;
+
+ if (!affinity_map_master.update_hook)
+ return;
+
+ map = affinity_map_get(affmap_name);
+
+ if (!map)
+ /* Affinity-map creation */
+ return;
+
+ (*affinity_map_master.update_hook)(affmap_name, map->bit_position,
+ new_pos);
+}
+
+
+void affinity_map_set_check_use_hook(bool (*func)(const char *affmap_name))
+{
+ affinity_map_master.check_use_hook = func;
+}
+
+void affinity_map_set_check_update_hook(bool (*func)(const char *affmap_name,
+ uint16_t new_pos))
+{
+ affinity_map_master.check_update_hook = func;
+}
+
+void affinity_map_set_update_hook(void (*func)(const char *affmap_name,
+ uint16_t old_pos,
+ uint16_t new_pos))
+{
+ affinity_map_master.update_hook = func;
+}
struct affinity_maps {
struct list *maps;
+ bool (*check_use_hook)(const char *affmap_name);
+ bool (*check_update_hook)(const char *affmap_name, uint16_t new_pos);
+ void (*update_hook)(const char *affmap_name, uint16_t old_pos,
+ uint16_t new_pos);
+
QOBJ_FIELDS;
};
DECLARE_QOBJ_TYPE(affinity_maps);
struct affinity_map *affinity_map_get(const char *name);
char *affinity_map_name_get(const int pos);
+bool affinity_map_check_use_hook(const char *affmap_name);
+bool affinity_map_check_update_hook(const char *affmap_name, uint16_t new_pos);
+void affinity_map_update_hook(const char *affmap_name, uint16_t new_pos);
+
+void affinity_map_set_check_use_hook(bool (*func)(const char *affmap_name));
+void affinity_map_set_check_update_hook(bool (*func)(const char *affmap_name,
+ uint16_t new_pos));
+void affinity_map_set_update_hook(void (*func)(const char *affmap_name,
+ uint16_t old_pos,
+ uint16_t new_pos));
+
void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
{
const char *name;
+ name = yang_dnode_get_string((const struct lyd_node *)args->dnode,
+ "./name");
+
switch (args->event) {
case NB_EV_VALIDATE:
+ if (!affinity_map_check_use_hook(name))
+ break;
+ snprintf(args->errmsg, args->errmsg_len,
+ "affinity-map %s is used", name);
+ return NB_ERR_VALIDATION;
case NB_EV_PREPARE:
case NB_EV_ABORT:
break;
case NB_EV_APPLY:
- name = yang_dnode_get_string(
- (const struct lyd_node *)args->dnode, "./name");
affinity_map_unset(name);
break;
}
switch (args->event) {
case NB_EV_VALIDATE:
map_name = affinity_map_name_get(pos);
- if (!map_name)
- return NB_OK;
- if (strncmp(map_name, name, AFFINITY_NAME_SIZE) == 0)
- return NB_ERR_NO_CHANGES;
- snprintf(args->errmsg, args->errmsg_len,
- "bit-position is used by %s.", map_name);
- return NB_ERR_VALIDATION;
+ if (map_name &&
+ strncmp(map_name, name, AFFINITY_NAME_SIZE) != 0) {
+ snprintf(args->errmsg, args->errmsg_len,
+ "bit-position is used by %s.", map_name);
+ return NB_ERR_VALIDATION;
+ }
+ if (!affinity_map_check_update_hook(name, pos)) {
+ snprintf(
+ args->errmsg, args->errmsg_len,
+ "affinity-map new bit-position > 31 but is used with standard admin-groups");
+ return NB_ERR_VALIDATION;
+ }
+ break;
case NB_EV_PREPARE:
case NB_EV_ABORT:
break;
case NB_EV_APPLY:
+ affinity_map_update_hook(name, pos);
affinity_map_set(name, pos);
break;
}
zebra/tc_netlink.c \
zebra/tc_socket.c \
zebra/zapi_msg.c \
+ zebra/zebra_affinitymap.c \
zebra/zebra_dplane.c \
zebra/zebra_errors.c \
zebra/zebra_gr.c \
zebra/table_manager.h \
zebra/tc_netlink.h \
zebra/zapi_msg.h \
+ zebra/zebra_affinitymap.h \
zebra/zebra_dplane.h \
zebra/zebra_errors.h \
zebra/zebra_evpn.h \
--- /dev/null
+/*
+ * zebra affinity-map.
+ *
+ * Copyright 2022 6WIND S.A.
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR 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.
+ *
+ * FRR 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 "lib/if.h"
+#include "lib/vrf.h"
+#include "zebra/redistribute.h"
+#include "zebra/zebra_affinitymap.h"
+
+static bool zebra_affinity_map_check_use(const char *affmap_name)
+{
+ char xpath[XPATH_MAXLEN];
+ struct interface *ifp;
+ struct vrf *vrf;
+
+ RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
+ FOR_ALL_INTERFACES (vrf, ifp) {
+ snprintf(xpath, sizeof(xpath),
+ "/frr-interface:lib/interface[name='%s']",
+ ifp->name);
+ if (!yang_dnode_exists(running_config->dnode, xpath))
+ continue;
+ snprintf(
+ xpath, sizeof(xpath),
+ "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinities[affinity='%s']",
+ ifp->name, affmap_name);
+ if (yang_dnode_exists(running_config->dnode, xpath))
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool zebra_affinity_map_check_update(const char *affmap_name,
+ uint16_t new_pos)
+{
+ char xpath[XPATH_MAXLEN];
+ struct interface *ifp;
+ struct vrf *vrf;
+
+ /* check whether the affinity-map new bit position is upper than 31
+ * but is used on an interface on which affinity-mode is standard.
+ * Return false if the change is not possible.
+ */
+ if (new_pos < 32)
+ return true;
+
+ RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
+ FOR_ALL_INTERFACES (vrf, ifp) {
+ snprintf(xpath, sizeof(xpath),
+ "/frr-interface:lib/interface[name='%s']",
+ ifp->name);
+ if (!yang_dnode_exists(running_config->dnode, xpath))
+ continue;
+ snprintf(
+ xpath, sizeof(xpath),
+ "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinities[affinity='%s']",
+ ifp->name, affmap_name);
+ if (!yang_dnode_exists(running_config->dnode, xpath))
+ continue;
+ if (yang_dnode_get_enum(
+ running_config->dnode,
+ "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinity-mode",
+ ifp->name) == AFFINITY_MODE_STANDARD)
+ return false;
+ }
+ }
+ return true;
+}
+
+static void zebra_affinity_map_update(const char *affmap_name, uint16_t old_pos,
+ uint16_t new_pos)
+{
+ struct if_link_params *iflp;
+ enum affinity_mode aff_mode;
+ char xpath[XPATH_MAXLEN];
+ struct interface *ifp;
+ struct vrf *vrf;
+
+ RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
+ FOR_ALL_INTERFACES (vrf, ifp) {
+ snprintf(xpath, sizeof(xpath),
+ "/frr-interface:lib/interface[name='%s']",
+ ifp->name);
+ if (!yang_dnode_exists(running_config->dnode, xpath))
+ continue;
+ snprintf(
+ xpath, sizeof(xpath),
+ "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinities[affinity='%s']",
+ ifp->name, affmap_name);
+ if (!yang_dnode_exists(running_config->dnode, xpath))
+ continue;
+ aff_mode = yang_dnode_get_enum(
+ running_config->dnode,
+ "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinity-mode",
+ ifp->name);
+ iflp = if_link_params_get(ifp);
+ if (aff_mode == AFFINITY_MODE_EXTENDED ||
+ aff_mode == AFFINITY_MODE_BOTH) {
+ admin_group_unset(&iflp->ext_admin_grp,
+ old_pos);
+ admin_group_set(&iflp->ext_admin_grp, new_pos);
+ }
+ if (aff_mode == AFFINITY_MODE_STANDARD ||
+ aff_mode == AFFINITY_MODE_BOTH) {
+ iflp->admin_grp &= ~(1 << old_pos);
+ if (new_pos < 32)
+ iflp->admin_grp |= 1 << new_pos;
+ if (iflp->admin_grp == 0)
+ UNSET_PARAM(iflp, LP_ADM_GRP);
+ }
+ if (if_is_operative(ifp))
+ zebra_interface_parameters_update(ifp);
+ }
+ }
+}
+
+void zebra_affinity_map_init(void)
+{
+ affinity_map_init();
+
+ affinity_map_set_check_use_hook(zebra_affinity_map_check_use);
+ affinity_map_set_check_update_hook(zebra_affinity_map_check_update);
+ affinity_map_set_update_hook(zebra_affinity_map_update);
+}
--- /dev/null
+/*
+ * Zebra affinity-map header
+ *
+ * Copyright 2022 6WIND S.A.
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR 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.
+ *
+ * FRR 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
+ */
+
+#ifndef __ZEBRA_AFFINITYMAP_H__
+#define __ZEBRA_AFFINITYMAP_H__
+
+#include "lib/affinitymap.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void zebra_affinity_map_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
#include "zebra/zebra_mpls.h"
#include "zebra/zebra_rnh.h"
#include "zebra/redistribute.h"
+#include "zebra/zebra_affinitymap.h"
#include "zebra/zebra_routemap.h"
#include "lib/json.h"
#include "lib/route_opaque.h"
/* Route-map */
zebra_route_map_init();
- affinity_map_init();
+ zebra_affinity_map_init();
install_node(&ip_node);
install_node(&protocol_node);