2 * ustp - OpenWrt STP/RSTP/MSTP daemon
3 * Copyright (C) 2021 Felix Fietkau <nbd@nbd.name>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <libubox/avl-cmp.h>
17 #include <libubox/utils.h>
21 AVL_TREE(bridge_config
, avl_strcmp
, false, NULL
);
23 static uint32_t bridge_config_timestamp(void)
27 clock_gettime(CLOCK_MONOTONIC
, &ts
);
32 struct bridge_config
*
33 bridge_config_get(const char *name
, bool create
)
35 struct bridge_config
*cfg
;
38 cfg
= avl_find_element(&bridge_config
, name
, cfg
, node
);
45 cfg
= calloc_a(sizeof(*cfg
), &name_buf
, strlen(name
) + 1);
46 cfg
->node
.key
= strcpy(name_buf
, name
);
47 avl_insert(&bridge_config
, &cfg
->node
);
50 cfg
->timestamp
= bridge_config_timestamp();
55 void bridge_config_expire(void)
57 struct bridge_config
*cfg
, *tmp
;
60 ts
= bridge_config_timestamp();
61 avl_for_each_element_safe(&bridge_config
, cfg
, node
, tmp
) {
62 if (ts
- cfg
->timestamp
< 60)
65 avl_delete(&bridge_config
, &cfg
->node
);