Line data Source code
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 */
34 22 : DEFINE_MTYPE_STATIC(LIB, LDP_SYNC_INFO, "LDP SYNC info");
35 :
36 : /*
37 : * ldp_sync_info_create - Allocate the LDP_SYNC information
38 : */
39 0 : struct ldp_sync_info *ldp_sync_info_create(void)
40 : {
41 0 : struct ldp_sync_info *ldp_sync_info;
42 :
43 0 : ldp_sync_info = XCALLOC(MTYPE_LDP_SYNC_INFO,
44 : sizeof(struct ldp_sync_info));
45 0 : assert(ldp_sync_info);
46 :
47 0 : ldp_sync_info->flags = 0;
48 0 : ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT;
49 0 : ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
50 0 : ldp_sync_info->holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT;
51 0 : ldp_sync_info->t_holddown = NULL;
52 0 : return ldp_sync_info;
53 : }
54 :
55 : /*
56 : * ldp_sync_info_free - Free the LDP_SYNC information.
57 : */
58 0 : void ldp_sync_info_free(struct ldp_sync_info **ldp_sync_info)
59 : {
60 0 : if (*ldp_sync_info)
61 0 : XFREE(MTYPE_LDP_SYNC_INFO, *ldp_sync_info);
62 0 : }
63 :
64 0 : 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 0 : if (ldp_sync_info &&
68 0 : ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED &&
69 : ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP)
70 0 : return true;
71 :
72 : return false;
73 : }
74 :
75 0 : 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 0 : if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) {
82 0 : THREAD_OFF(ldp_sync_info->t_holddown);
83 :
84 0 : if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP)
85 0 : ldp_sync_info->state =
86 : LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
87 0 : return true;
88 : }
89 :
90 : return false;
91 : }
|