3 * Copyright (C) James R. Leu 2003
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
10 #include "ldp_struct.h"
14 #include "ldp_session.h"
15 #include "ldp_outlabel.h"
16 #include "mpls_assert.h"
17 #include "mpls_compare.h"
18 #include "mpls_mm_impl.h"
19 #include "mpls_tree_impl.h"
20 #include "mpls_policy_impl.h"
21 #include "mpls_trace_impl.h"
26 #include "mpls_mpls_impl.h"
29 static uint32_t _ldp_nexthop_next_index
= 1;
30 static uint32_t _ldp_nexthop_get_next_index();
32 ldp_nexthop
*ldp_nexthop_for_fec_session(ldp_fec
*fec
, ldp_session
*s
)
34 ldp_nexthop
*nh
= MPLS_LIST_HEAD(&fec
->nh_root
);
37 sp
= ldp_session_for_nexthop(nh
);
38 if (s
->index
== sp
->index
) {
41 nh
= MPLS_LIST_NEXT(&fec
->nh_root
, nh
, _fec
);
46 ldp_nexthop
*ldp_nexthop_create()
48 ldp_nexthop
*nh
= (ldp_nexthop
*) mpls_malloc(sizeof(ldp_nexthop
));
51 memset(nh
, 0, sizeof(ldp_nexthop
));
52 MPLS_REFCNT_INIT(nh
, 0);
53 MPLS_LIST_ELEM_INIT(nh
, _fec
);
54 MPLS_LIST_ELEM_INIT(nh
, _addr
);
55 MPLS_LIST_ELEM_INIT(nh
, _if
);
56 MPLS_LIST_ELEM_INIT(nh
, _outlabel
);
57 nh
->index
= _ldp_nexthop_get_next_index();
62 void ldp_nexthop_delete(ldp_nexthop
*nh
)
67 void ldp_nexthop_add_if(ldp_nexthop
* nh
, ldp_if
* i
)
74 void ldp_nexthop_del_if(ldp_nexthop
* nh
)
77 MPLS_REFCNT_RELEASE(nh
->iff
, ldp_if_delete
);
81 void ldp_nexthop_add_addr(ldp_nexthop
* nh
, ldp_addr
* a
)
88 void ldp_nexthop_del_addr(ldp_nexthop
* nh
)
91 MPLS_REFCNT_RELEASE(nh
->addr
, ldp_addr_delete
);
95 void ldp_nexthop_add_outlabel(ldp_nexthop
* nh
, ldp_outlabel
* o
)
102 void ldp_nexthop_del_outlabel(ldp_nexthop
* nh
)
105 MPLS_REFCNT_RELEASE(nh
->outlabel
, ldp_outlabel_delete
);
109 void mpls_nexthop2ldp_nexthop(mpls_nexthop
*mnh
, ldp_nexthop
*lnh
)
111 lnh
->type
= mnh
->type
;
112 memcpy(mnh
, &lnh
->info
, sizeof(mpls_nexthop
));
115 static uint32_t _ldp_nexthop_get_next_index()
117 uint32_t retval
= _ldp_nexthop_next_index
;
119 _ldp_nexthop_next_index
++;
120 if (retval
> _ldp_nexthop_next_index
) {
121 _ldp_nexthop_next_index
= 1;