summaryrefslogtreecommitdiffstats
path: root/isisd/isis_affinitymap.c
blob: 595091db2727dcc661d6a6d9bbfa3312b4661f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: GPL-2.0-or-later
/* IS-IS  affinity-map
 * Copyright 2023 6WIND S.A.
 */

#include <zebra.h>
#include "lib/if.h"
#include "lib/vrf.h"
#include "isisd/isisd.h"
#include "isisd/isis_affinitymap.h"

#ifndef FABRICD

static void isis_affinity_map_update(const char *affmap_name, uint16_t old_pos,
				     uint16_t new_pos)
{
	struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
	struct listnode *area_node, *fa_node;
	struct isis_area *area;
	struct flex_algo *fa;
	bool changed;

	if (!isis)
		return;

	for (ALL_LIST_ELEMENTS_RO(isis->area_list, area_node, area)) {
		changed = false;
		for (ALL_LIST_ELEMENTS_RO(area->flex_algos->flex_algos, fa_node,
					  fa)) {
			if (admin_group_get(&fa->admin_group_exclude_any,
					    old_pos)) {
				admin_group_unset(&fa->admin_group_exclude_any,
						  old_pos);
				admin_group_set(&fa->admin_group_exclude_any,
						new_pos);
				changed = true;
			}
			if (admin_group_get(&fa->admin_group_include_any,
					    old_pos)) {
				admin_group_unset(&fa->admin_group_include_any,
						  old_pos);
				admin_group_set(&fa->admin_group_include_any,
						new_pos);
				changed = true;
			}
			if (admin_group_get(&fa->admin_group_include_all,
					    old_pos)) {
				admin_group_unset(&fa->admin_group_include_all,
						  old_pos);
				admin_group_set(&fa->admin_group_include_all,
						new_pos);
				changed = true;
			}
		}
		if (changed)
			lsp_regenerate_schedule(area, area->is_type, 0);
	}
}

void isis_affinity_map_init(void)
{
	affinity_map_init();

	affinity_map_set_update_hook(isis_affinity_map_update);
}

#endif /* ifndef FABRICD */