forked from Mirror/frr
lib,zebra: add affinity-map configuration hooks
Add affinity-map hooks to check the utilization of affinity-map in link-params before its deletion and to update link-params when the affinity-map bit-position is updated. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
parent
fa1b95c3ec
commit
ae251b8684
|
@ -47,7 +47,7 @@ DEFINE_MTYPE_STATIC(LIB, AFFINITY_MAP_INDEX, "Affinity map index");
|
||||||
DEFINE_QOBJ_TYPE(affinity_maps);
|
DEFINE_QOBJ_TYPE(affinity_maps);
|
||||||
DEFINE_QOBJ_TYPE(affinity_map);
|
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)
|
static void affinity_map_free(struct affinity_map *map)
|
||||||
{
|
{
|
||||||
|
@ -120,3 +120,54 @@ char *affinity_map_name_get(int pos)
|
||||||
return map->name;
|
return map->name;
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -50,6 +50,11 @@ DECLARE_QOBJ_TYPE(affinity_map);
|
||||||
struct affinity_maps {
|
struct affinity_maps {
|
||||||
struct list *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;
|
QOBJ_FIELDS;
|
||||||
};
|
};
|
||||||
DECLARE_QOBJ_TYPE(affinity_maps);
|
DECLARE_QOBJ_TYPE(affinity_maps);
|
||||||
|
@ -61,6 +66,17 @@ void affinity_map_unset(const char *name);
|
||||||
struct affinity_map *affinity_map_get(const char *name);
|
struct affinity_map *affinity_map_get(const char *name);
|
||||||
char *affinity_map_name_get(const int pos);
|
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,
|
void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode,
|
||||||
bool show_defaults);
|
bool show_defaults);
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,20 @@ static int lib_affinity_map_destroy(struct nb_cb_destroy_args *args)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
|
name = yang_dnode_get_string((const struct lyd_node *)args->dnode,
|
||||||
|
"./name");
|
||||||
|
|
||||||
switch (args->event) {
|
switch (args->event) {
|
||||||
case NB_EV_VALIDATE:
|
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_PREPARE:
|
||||||
case NB_EV_ABORT:
|
case NB_EV_ABORT:
|
||||||
break;
|
break;
|
||||||
case NB_EV_APPLY:
|
case NB_EV_APPLY:
|
||||||
name = yang_dnode_get_string(
|
|
||||||
(const struct lyd_node *)args->dnode, "./name");
|
|
||||||
affinity_map_unset(name);
|
affinity_map_unset(name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -74,17 +80,24 @@ static int lib_affinity_map_value_modify(struct nb_cb_modify_args *args)
|
||||||
switch (args->event) {
|
switch (args->event) {
|
||||||
case NB_EV_VALIDATE:
|
case NB_EV_VALIDATE:
|
||||||
map_name = affinity_map_name_get(pos);
|
map_name = affinity_map_name_get(pos);
|
||||||
if (!map_name)
|
if (map_name &&
|
||||||
return NB_OK;
|
strncmp(map_name, name, AFFINITY_NAME_SIZE) != 0) {
|
||||||
if (strncmp(map_name, name, AFFINITY_NAME_SIZE) == 0)
|
snprintf(args->errmsg, args->errmsg_len,
|
||||||
return NB_ERR_NO_CHANGES;
|
"bit-position is used by %s.", map_name);
|
||||||
snprintf(args->errmsg, args->errmsg_len,
|
return NB_ERR_VALIDATION;
|
||||||
"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_PREPARE:
|
||||||
case NB_EV_ABORT:
|
case NB_EV_ABORT:
|
||||||
break;
|
break;
|
||||||
case NB_EV_APPLY:
|
case NB_EV_APPLY:
|
||||||
|
affinity_map_update_hook(name, pos);
|
||||||
affinity_map_set(name, pos);
|
affinity_map_set(name, pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ zebra_zebra_SOURCES = \
|
||||||
zebra/tc_netlink.c \
|
zebra/tc_netlink.c \
|
||||||
zebra/tc_socket.c \
|
zebra/tc_socket.c \
|
||||||
zebra/zapi_msg.c \
|
zebra/zapi_msg.c \
|
||||||
|
zebra/zebra_affinitymap.c \
|
||||||
zebra/zebra_dplane.c \
|
zebra/zebra_dplane.c \
|
||||||
zebra/zebra_errors.c \
|
zebra/zebra_errors.c \
|
||||||
zebra/zebra_gr.c \
|
zebra/zebra_gr.c \
|
||||||
|
@ -145,6 +146,7 @@ noinst_HEADERS += \
|
||||||
zebra/table_manager.h \
|
zebra/table_manager.h \
|
||||||
zebra/tc_netlink.h \
|
zebra/tc_netlink.h \
|
||||||
zebra/zapi_msg.h \
|
zebra/zapi_msg.h \
|
||||||
|
zebra/zebra_affinitymap.h \
|
||||||
zebra/zebra_dplane.h \
|
zebra/zebra_dplane.h \
|
||||||
zebra/zebra_errors.h \
|
zebra/zebra_errors.h \
|
||||||
zebra/zebra_evpn.h \
|
zebra/zebra_evpn.h \
|
||||||
|
|
144
zebra/zebra_affinitymap.c
Normal file
144
zebra/zebra_affinitymap.c
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
38
zebra/zebra_affinitymap.h
Normal file
38
zebra/zebra_affinitymap.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* 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
|
|
@ -42,6 +42,7 @@
|
||||||
#include "zebra/zebra_mpls.h"
|
#include "zebra/zebra_mpls.h"
|
||||||
#include "zebra/zebra_rnh.h"
|
#include "zebra/zebra_rnh.h"
|
||||||
#include "zebra/redistribute.h"
|
#include "zebra/redistribute.h"
|
||||||
|
#include "zebra/zebra_affinitymap.h"
|
||||||
#include "zebra/zebra_routemap.h"
|
#include "zebra/zebra_routemap.h"
|
||||||
#include "lib/json.h"
|
#include "lib/json.h"
|
||||||
#include "lib/route_opaque.h"
|
#include "lib/route_opaque.h"
|
||||||
|
@ -4497,7 +4498,7 @@ void zebra_vty_init(void)
|
||||||
/* Route-map */
|
/* Route-map */
|
||||||
zebra_route_map_init();
|
zebra_route_map_init();
|
||||||
|
|
||||||
affinity_map_init();
|
zebra_affinity_map_init();
|
||||||
|
|
||||||
install_node(&ip_node);
|
install_node(&ip_node);
|
||||||
install_node(&protocol_node);
|
install_node(&protocol_node);
|
||||||
|
|
Loading…
Reference in a new issue