]>
Commit | Line | Data |
---|---|---|
ae251b86 LS |
1 | /* |
2 | * zebra affinity-map. | |
3 | * | |
4 | * Copyright 2022 6WIND S.A. | |
5 | * | |
6 | * This file is part of Free Range Routing (FRR). | |
7 | * | |
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 | |
11 | * later version. | |
12 | * | |
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. | |
17 | * | |
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 | |
21 | */ | |
22 | ||
23 | #include <zebra.h> | |
24 | #include "lib/if.h" | |
25 | #include "lib/vrf.h" | |
26 | #include "zebra/redistribute.h" | |
27 | #include "zebra/zebra_affinitymap.h" | |
28 | ||
29 | static bool zebra_affinity_map_check_use(const char *affmap_name) | |
30 | { | |
31 | char xpath[XPATH_MAXLEN]; | |
32 | struct interface *ifp; | |
33 | struct vrf *vrf; | |
34 | ||
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']", | |
39 | ifp->name); | |
40 | if (!yang_dnode_exists(running_config->dnode, xpath)) | |
41 | continue; | |
42 | snprintf( | |
43 | xpath, sizeof(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)) | |
47 | return true; | |
48 | } | |
49 | } | |
50 | return false; | |
51 | } | |
52 | ||
53 | static bool zebra_affinity_map_check_update(const char *affmap_name, | |
54 | uint16_t new_pos) | |
55 | { | |
56 | char xpath[XPATH_MAXLEN]; | |
57 | struct interface *ifp; | |
58 | struct vrf *vrf; | |
59 | ||
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. | |
63 | */ | |
64 | if (new_pos < 32) | |
65 | return true; | |
66 | ||
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']", | |
71 | ifp->name); | |
72 | if (!yang_dnode_exists(running_config->dnode, xpath)) | |
73 | continue; | |
74 | snprintf( | |
75 | xpath, sizeof(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)) | |
79 | continue; | |
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) | |
84 | return false; | |
85 | } | |
86 | } | |
87 | return true; | |
88 | } | |
89 | ||
90 | static void zebra_affinity_map_update(const char *affmap_name, uint16_t old_pos, | |
91 | uint16_t new_pos) | |
92 | { | |
93 | struct if_link_params *iflp; | |
94 | enum affinity_mode aff_mode; | |
95 | char xpath[XPATH_MAXLEN]; | |
96 | struct interface *ifp; | |
97 | struct vrf *vrf; | |
98 | ||
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']", | |
103 | ifp->name); | |
104 | if (!yang_dnode_exists(running_config->dnode, xpath)) | |
105 | continue; | |
106 | snprintf( | |
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)) | |
111 | continue; | |
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", | |
115 | ifp->name); | |
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, | |
120 | old_pos); | |
121 | admin_group_set(&iflp->ext_admin_grp, new_pos); | |
122 | } | |
123 | if (aff_mode == AFFINITY_MODE_STANDARD || | |
124 | aff_mode == AFFINITY_MODE_BOTH) { | |
125 | iflp->admin_grp &= ~(1 << old_pos); | |
126 | if (new_pos < 32) | |
127 | iflp->admin_grp |= 1 << new_pos; | |
128 | if (iflp->admin_grp == 0) | |
129 | UNSET_PARAM(iflp, LP_ADM_GRP); | |
130 | } | |
131 | if (if_is_operative(ifp)) | |
132 | zebra_interface_parameters_update(ifp); | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
137 | void zebra_affinity_map_init(void) | |
138 | { | |
139 | affinity_map_init(); | |
140 | ||
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); | |
144 | } |