This file should have been deleted what ldp-portable was
[mpls-ldp-portable.git] / lsr / lsr_if.c
blob571669f1b4965b09d1d8cc7e165c646c6a976e50
2 /*
3 * Copyright (C) James R. Leu 2002
4 * jleu@mindspring.com
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
8 */
10 #include "lsr_struct.h"
11 #include "lsr_if.h"
12 #include "lsr_outsegment.h"
14 #include "mpls_assert.h"
15 #include "mpls_mm_impl.h"
16 #include "mpls_trace_impl.h"
18 uint32_t _lsr_if_next_index = 1;
20 lsr_if *lsr_if_create()
22 lsr_if *i = (lsr_if *) mpls_malloc(sizeof(lsr_if));
24 if (i) {
25 memset(i, 0, sizeof(lsr_if));
26 MPLS_REFCNT_INIT(i, 0);
27 MPLS_LIST_ELEM_INIT(i, _global);
28 MPLS_LIST_INIT(&i->outsegment_root,lsr_outsegment);
29 i->index = _lsr_if_get_next_index();
30 i->oper_state = MPLS_OPER_DOWN;
32 return i;
35 void lsr_if_delete(lsr_if * i)
37 // LSR_PRINT(g->user_data,"if delete\n");
38 MPLS_REFCNT_ASSERT(i, 0);
39 mpls_free(i);
42 uint32_t _lsr_if_get_next_index()
44 uint32_t retval = _lsr_if_next_index;
46 _lsr_if_next_index++;
47 if (retval > _lsr_if_next_index) {
48 _lsr_if_next_index = 1;
50 return retval;
53 mpls_return_enum lsr_if_add_outsegment(lsr_if *iff, lsr_outsegment *o) {
54 if (iff && o) {
55 MPLS_REFCNT_HOLD(o);
56 MPLS_LIST_ADD_HEAD(&iff->outsegment_root, o, _if, lsr_outsegment);
57 _lsr_outsegment_add_if(o, iff);
58 return MPLS_SUCCESS;
60 return MPLS_FAILURE;
63 mpls_return_enum lsr_if_del_outsegment(lsr_if *iff, lsr_outsegment *o) {
64 if (iff && o) {
65 MPLS_LIST_REMOVE(&iff->outsegment_root, o, _if);
66 _lsr_outsegment_del_if(o);
67 MPLS_REFCNT_RELEASE(o, lsr_outsegment_delete);
68 return MPLS_SUCCESS;
70 return MPLS_FAILURE;