]>
Commit | Line | Data |
---|---|---|
24e7c5c8 KS |
1 | /* |
2 | * ldp_sync.c: LDP-SYNC handling routines | |
3 | * Copyright (C) 2020 Volta Networks, Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the Free | |
7 | * Software Foundation; either version 2 of the License, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
20 | #include <zebra.h> | |
21 | ||
22 | #include "command.h" | |
23 | #include "memory.h" | |
24 | #include "prefix.h" | |
25 | #include "log.h" | |
26 | #include "thread.h" | |
27 | #include "stream.h" | |
28 | #include "zclient.h" | |
29 | #include "table.h" | |
30 | #include "vty.h" | |
31 | #include "ldp_sync.h" | |
32 | ||
33 | /* Library code */ | |
bf8d3d6a | 34 | DEFINE_MTYPE_STATIC(LIB, LDP_SYNC_INFO, "LDP SYNC info"); |
24e7c5c8 KS |
35 | |
36 | /* | |
37 | * ldp_sync_info_create - Allocate the LDP_SYNC information | |
38 | */ | |
39 | struct ldp_sync_info *ldp_sync_info_create(void) | |
40 | { | |
41 | struct ldp_sync_info *ldp_sync_info; | |
42 | ||
43 | ldp_sync_info = XCALLOC(MTYPE_LDP_SYNC_INFO, | |
44 | sizeof(struct ldp_sync_info)); | |
45 | assert(ldp_sync_info); | |
46 | ||
47 | ldp_sync_info->flags = 0; | |
48 | ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT; | |
49 | ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED; | |
50 | ldp_sync_info->holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT; | |
51 | ldp_sync_info->t_holddown = NULL; | |
52 | return ldp_sync_info; | |
53 | } | |
54 | ||
55 | /* | |
56 | * ldp_sync_info_free - Free the LDP_SYNC information. | |
57 | */ | |
58 | void ldp_sync_info_free(struct ldp_sync_info **ldp_sync_info) | |
59 | { | |
60 | if (*ldp_sync_info) | |
61 | XFREE(MTYPE_LDP_SYNC_INFO, *ldp_sync_info); | |
62 | } | |
63 | ||
64 | bool ldp_sync_if_is_enabled(struct ldp_sync_info *ldp_sync_info) | |
65 | { | |
66 | /* return true if LDP-SYNC is configured on this interface */ | |
67 | if (ldp_sync_info && | |
68 | ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED && | |
69 | ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP) | |
70 | return true; | |
71 | ||
72 | return false; | |
73 | } | |
74 | ||
75 | bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info) | |
76 | { | |
77 | /* Stop LDP-SYNC on this interface: | |
78 | * if holddown timer is running stop it | |
79 | * update state | |
80 | */ | |
81 | if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) { | |
50478845 | 82 | THREAD_OFF(ldp_sync_info->t_holddown); |
28ef0ee1 | 83 | |
24e7c5c8 KS |
84 | if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP) |
85 | ldp_sync_info->state = | |
86 | LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP; | |
87 | return true; | |
88 | } | |
89 | ||
90 | return false; | |
91 | } |