]>
Commit | Line | Data |
---|---|---|
9a65cf35 LS |
1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | /* IS-IS affinity-map | |
3 | * Copyright 2023 6WIND S.A. | |
4 | */ | |
5 | ||
6 | #include <zebra.h> | |
7 | #include "lib/if.h" | |
8 | #include "lib/vrf.h" | |
9 | #include "isisd/isisd.h" | |
10 | #include "isisd/isis_affinitymap.h" | |
11 | ||
12 | #ifndef FABRICD | |
13 | ||
14 | static bool isis_affinity_map_check_use(const char *affmap_name) | |
15 | { | |
16 | struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT); | |
17 | struct isis_area *area; | |
18 | struct listnode *area_node, *fa_node; | |
19 | struct flex_algo *fa; | |
20 | struct affinity_map *map; | |
21 | uint16_t pos; | |
22 | ||
eb2010de LS |
23 | if (!isis) |
24 | return false; | |
25 | ||
9a65cf35 LS |
26 | map = affinity_map_get(affmap_name); |
27 | pos = map->bit_position; | |
28 | ||
29 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, area_node, area)) { | |
30 | for (ALL_LIST_ELEMENTS_RO(area->flex_algos->flex_algos, fa_node, | |
31 | fa)) { | |
32 | if (admin_group_get(&fa->admin_group_exclude_any, | |
33 | pos) || | |
34 | admin_group_get(&fa->admin_group_include_any, | |
35 | pos) || | |
36 | admin_group_get(&fa->admin_group_include_all, pos)) | |
37 | return true; | |
38 | } | |
39 | } | |
40 | return false; | |
41 | } | |
42 | ||
43 | static void isis_affinity_map_update(const char *affmap_name, uint16_t old_pos, | |
44 | uint16_t new_pos) | |
45 | { | |
46 | struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT); | |
47 | struct listnode *area_node, *fa_node; | |
48 | struct isis_area *area; | |
49 | struct flex_algo *fa; | |
50 | bool changed; | |
51 | ||
60f9275a LS |
52 | if (!isis) |
53 | return; | |
54 | ||
9a65cf35 LS |
55 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, area_node, area)) { |
56 | changed = false; | |
57 | for (ALL_LIST_ELEMENTS_RO(area->flex_algos->flex_algos, fa_node, | |
58 | fa)) { | |
59 | if (admin_group_get(&fa->admin_group_exclude_any, | |
60 | old_pos)) { | |
61 | admin_group_unset(&fa->admin_group_exclude_any, | |
62 | old_pos); | |
63 | admin_group_set(&fa->admin_group_exclude_any, | |
64 | new_pos); | |
65 | changed = true; | |
66 | } | |
67 | if (admin_group_get(&fa->admin_group_include_any, | |
68 | old_pos)) { | |
69 | admin_group_unset(&fa->admin_group_include_any, | |
70 | old_pos); | |
71 | admin_group_set(&fa->admin_group_include_any, | |
72 | new_pos); | |
73 | changed = true; | |
74 | } | |
75 | if (admin_group_get(&fa->admin_group_include_all, | |
76 | old_pos)) { | |
77 | admin_group_unset(&fa->admin_group_include_all, | |
78 | old_pos); | |
79 | admin_group_set(&fa->admin_group_include_all, | |
80 | new_pos); | |
81 | changed = true; | |
82 | } | |
83 | } | |
84 | if (changed) | |
85 | lsp_regenerate_schedule(area, area->is_type, 0); | |
86 | } | |
87 | } | |
88 | ||
89 | void isis_affinity_map_init(void) | |
90 | { | |
91 | affinity_map_init(); | |
92 | ||
93 | affinity_map_set_check_use_hook(isis_affinity_map_check_use); | |
94 | affinity_map_set_update_hook(isis_affinity_map_update); | |
95 | } | |
96 | ||
97 | #endif /* ifndef FABRICD */ |