From: Vasu Dasari <vdasari@gmail.com>
[mpls-ldp-portable.git] / rsvpte / rsvpte_if.c
blobb1ebb358cf598ae8c2428795baa0946cbfb3e495
1 /*
2 * Copyright (C) James R. Leu 2003
3 * jleu@mindspring.com
5 * This software is covered under the LGPL, for more
6 * info check out http://www.gnu.org/copyleft/lgpl.html
7 */
9 #include "rsvpte_struct.h"
10 #include "rsvpte_if.h"
12 #include "mpls_assert.h"
13 #include "mpls_mm_impl.h"
14 #include "mpls_socket_impl.h"
15 #include "mpls_timer_impl.h"
16 #include "mpls_ifmgr_impl.h"
17 #include "mpls_trace_impl.h"
19 uint32_t _rsvpte_if_next_index = 1;
21 rsvpte_if *rsvpte_if_create()
23 rsvpte_if *i = (rsvpte_if *) mpls_malloc(sizeof(rsvpte_if));
25 if (i) {
26 memset(i, 0, sizeof(rsvpte_if));
27 MPLS_REFCNT_INIT(i, 0);
28 MPLS_LIST_ELEM_INIT(i, _global);
29 i->label_space = -1;
30 i->index = _rsvpte_if_get_next_index();
31 i->oper_state = MPLS_OPER_DOWN;
32 i->admin_state = MPLS_ADMIN_DISABLE;
34 return i;
37 void rsvpte_if_delete(rsvpte_if * i)
39 LDP_PRINT(g->user_data,"if delete\n");
40 MPLS_REFCNT_ASSERT(i, 0);
41 mpls_free(i);
44 mpls_return_enum rsvpte_if_startup(rsvpte_global * g, rsvpte_if * i)
46 LDP_ENTER(g->user_data, "rsvpte_if_startup");
48 MPLS_ASSERT(i != NULL);
50 i->oper_state = MPLS_OPER_UP;
51 i->admin_state = MPLS_ADMIN_ENABLE;
53 LDP_EXIT(g->user_data, "rsvpte_if_startup");
55 return MPLS_SUCCESS;
58 * when a interface update comes in, it will search the global
59 * list of interfaces, and start up the interface then
61 i->oper_state = MPLS_OPER_DOWN;
63 LDP_EXIT(g->user_data, "rsvpte_if_startup-delayed");
65 return MPLS_SUCCESS;
68 mpls_return_enum rsvpte_if_shutdown(rsvpte_global * g, rsvpte_if * i)
70 MPLS_ASSERT(i != NULL);
72 LDP_ENTER(g->user_data, "rsvpte_if_shutdown");
74 i->oper_state = MPLS_OPER_DOWN;
75 i->admin_state = MPLS_ADMIN_DISABLE;
77 LDP_EXIT(g->user_data, "rsvpte_if_shutdown");
79 return MPLS_SUCCESS;
82 uint32_t _rsvpte_if_get_next_index()
84 uint32_t retval = _rsvpte_if_next_index;
86 _rsvpte_if_next_index++;
87 if (retval > _rsvpte_if_next_index) {
88 _rsvpte_if_next_index = 1;
90 return retval;
93 mpls_bool rsvpte_if_is_active(rsvpte_if * i)
95 MPLS_ASSERT(i);
96 if (i->oper_state == MPLS_OPER_UP)
97 return MPLS_BOOL_TRUE;
99 return MPLS_BOOL_FALSE;