4 * Copyright 2022 6WIND S.A.
6 * This file is part of Free Range Routing (FRR).
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "zebra/redistribute.h"
27 #include "zebra/zebra_affinitymap.h"
29 static bool zebra_affinity_map_check_use(const char *affmap_name
)
31 char xpath
[XPATH_MAXLEN
];
32 struct interface
*ifp
;
35 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
36 FOR_ALL_INTERFACES (vrf
, ifp
) {
37 snprintf(xpath
, sizeof(xpath
),
38 "/frr-interface:lib/interface[name='%s']",
40 if (!yang_dnode_exists(running_config
->dnode
, xpath
))
44 "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinities[affinity='%s']",
45 ifp
->name
, affmap_name
);
46 if (yang_dnode_exists(running_config
->dnode
, xpath
))
53 static bool zebra_affinity_map_check_update(const char *affmap_name
,
56 char xpath
[XPATH_MAXLEN
];
57 struct interface
*ifp
;
60 /* check whether the affinity-map new bit position is upper than 31
61 * but is used on an interface on which affinity-mode is standard.
62 * Return false if the change is not possible.
67 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
68 FOR_ALL_INTERFACES (vrf
, ifp
) {
69 snprintf(xpath
, sizeof(xpath
),
70 "/frr-interface:lib/interface[name='%s']",
72 if (!yang_dnode_exists(running_config
->dnode
, xpath
))
76 "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinities[affinity='%s']",
77 ifp
->name
, affmap_name
);
78 if (!yang_dnode_exists(running_config
->dnode
, xpath
))
80 if (yang_dnode_get_enum(
81 running_config
->dnode
,
82 "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinity-mode",
83 ifp
->name
) == AFFINITY_MODE_STANDARD
)
90 static void zebra_affinity_map_update(const char *affmap_name
, uint16_t old_pos
,
93 struct if_link_params
*iflp
;
94 enum affinity_mode aff_mode
;
95 char xpath
[XPATH_MAXLEN
];
96 struct interface
*ifp
;
99 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
100 FOR_ALL_INTERFACES (vrf
, ifp
) {
101 snprintf(xpath
, sizeof(xpath
),
102 "/frr-interface:lib/interface[name='%s']",
104 if (!yang_dnode_exists(running_config
->dnode
, xpath
))
107 xpath
, sizeof(xpath
),
108 "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinities[affinity='%s']",
109 ifp
->name
, affmap_name
);
110 if (!yang_dnode_exists(running_config
->dnode
, xpath
))
112 aff_mode
= yang_dnode_get_enum(
113 running_config
->dnode
,
114 "/frr-interface:lib/interface[name='%s']/frr-zebra:zebra/link-params/affinity-mode",
116 iflp
= if_link_params_get(ifp
);
117 if (aff_mode
== AFFINITY_MODE_EXTENDED
||
118 aff_mode
== AFFINITY_MODE_BOTH
) {
119 admin_group_unset(&iflp
->ext_admin_grp
,
121 admin_group_set(&iflp
->ext_admin_grp
, new_pos
);
123 if (aff_mode
== AFFINITY_MODE_STANDARD
||
124 aff_mode
== AFFINITY_MODE_BOTH
) {
125 iflp
->admin_grp
&= ~(1 << old_pos
);
127 iflp
->admin_grp
|= 1 << new_pos
;
128 if (iflp
->admin_grp
== 0)
129 UNSET_PARAM(iflp
, LP_ADM_GRP
);
131 if (if_is_operative(ifp
))
132 zebra_interface_parameters_update(ifp
);
137 void zebra_affinity_map_init(void)
141 affinity_map_set_check_use_hook(zebra_affinity_map_check_use
);
142 affinity_map_set_check_update_hook(zebra_affinity_map_check_update
);
143 affinity_map_set_update_hook(zebra_affinity_map_update
);