]> git.proxmox.com Git - mirror_frr.git/blob - lib/ldp_sync.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / ldp_sync.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * ldp_sync.c: LDP-SYNC handling routines
4 * Copyright (C) 2020 Volta Networks, Inc.
5 */
6
7 #include <zebra.h>
8
9 #include "command.h"
10 #include "memory.h"
11 #include "prefix.h"
12 #include "log.h"
13 #include "thread.h"
14 #include "stream.h"
15 #include "zclient.h"
16 #include "table.h"
17 #include "vty.h"
18 #include "ldp_sync.h"
19
20 /* Library code */
21 DEFINE_MTYPE_STATIC(LIB, LDP_SYNC_INFO, "LDP SYNC info");
22
23 /*
24 * ldp_sync_info_create - Allocate the LDP_SYNC information
25 */
26 struct ldp_sync_info *ldp_sync_info_create(void)
27 {
28 struct ldp_sync_info *ldp_sync_info;
29
30 ldp_sync_info = XCALLOC(MTYPE_LDP_SYNC_INFO,
31 sizeof(struct ldp_sync_info));
32 assert(ldp_sync_info);
33
34 ldp_sync_info->flags = 0;
35 ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT;
36 ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
37 ldp_sync_info->holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT;
38 ldp_sync_info->t_holddown = NULL;
39 return ldp_sync_info;
40 }
41
42 /*
43 * ldp_sync_info_free - Free the LDP_SYNC information.
44 */
45 void ldp_sync_info_free(struct ldp_sync_info **ldp_sync_info)
46 {
47 if (*ldp_sync_info)
48 XFREE(MTYPE_LDP_SYNC_INFO, *ldp_sync_info);
49 }
50
51 bool ldp_sync_if_is_enabled(struct ldp_sync_info *ldp_sync_info)
52 {
53 /* return true if LDP-SYNC is configured on this interface */
54 if (ldp_sync_info &&
55 ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED &&
56 ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP)
57 return true;
58
59 return false;
60 }
61
62 bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info)
63 {
64 /* Stop LDP-SYNC on this interface:
65 * if holddown timer is running stop it
66 * update state
67 */
68 if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) {
69 THREAD_OFF(ldp_sync_info->t_holddown);
70
71 if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP)
72 ldp_sync_info->state =
73 LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
74 return true;
75 }
76
77 return false;
78 }