Line | Count | Source |
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 "frrevent.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 | 8 | DEFINE_MTYPE_STATIC(LIB, LDP_SYNC_INFO, "LDP SYNC info"); |
22 | 8 | |
23 | 8 | /* |
24 | 8 | * ldp_sync_info_create - Allocate the LDP_SYNC information |
25 | 8 | */ |
26 | 8 | struct ldp_sync_info *ldp_sync_info_create(void) |
27 | 8 | { |
28 | 0 | struct ldp_sync_info *ldp_sync_info; |
29 | |
|
30 | 0 | ldp_sync_info = XCALLOC(MTYPE_LDP_SYNC_INFO, |
31 | 0 | sizeof(struct ldp_sync_info)); |
32 | 0 | assert(ldp_sync_info); |
33 | |
|
34 | 0 | ldp_sync_info->flags = 0; |
35 | 0 | ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT; |
36 | 0 | ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED; |
37 | 0 | ldp_sync_info->holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT; |
38 | 0 | ldp_sync_info->t_holddown = NULL; |
39 | 0 | return ldp_sync_info; |
40 | 0 | } |
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 | 0 | { |
47 | 0 | if (*ldp_sync_info) |
48 | 0 | XFREE(MTYPE_LDP_SYNC_INFO, *ldp_sync_info); |
49 | 0 | } |
50 | | |
51 | | bool ldp_sync_if_is_enabled(struct ldp_sync_info *ldp_sync_info) |
52 | 1 | { |
53 | | /* return true if LDP-SYNC is configured on this interface */ |
54 | 1 | if (ldp_sync_info && |
55 | 0 | ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED && |
56 | 0 | ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP) |
57 | 0 | return true; |
58 | | |
59 | 1 | return false; |
60 | 1 | } |
61 | | |
62 | | bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info) |
63 | 0 | { |
64 | | /* Stop LDP-SYNC on this interface: |
65 | | * if holddown timer is running stop it |
66 | | * update state |
67 | | */ |
68 | 0 | if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) { |
69 | 0 | EVENT_OFF(ldp_sync_info->t_holddown); |
70 | |
|
71 | 0 | if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP) |
72 | 0 | ldp_sync_info->state = |
73 | 0 | LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP; |
74 | 0 | return true; |
75 | 0 | } |
76 | | |
77 | 0 | return false; |
78 | 0 | } |