ldp_fec *ldp_fec_create(ldp_global *g, mpls_fec *f) { ldp_fec *fec = (ldp_fec *) mpls_malloc(sizeof(ldp_fec)); if (fec != NULL) { memset(fec, 0, sizeof(ldp_fec)); /* * note: this is init to 1 for a reason! * We're placing it in the global list, so this is our refcnt * when this refcnt gets to zero, it will be removed from the * global list and deleted */ /* * TESTING: jleu 6/7/2004, since I want the FEC to be cleaned up * when it no longer has a nexthop, addr, or label, the only things that * should increment the ref are those (nh, addr, label etc), not global * nor inserting into the tree. I also added this comment in * _ldp_global_add_fec() MPLS_REFCNT_INIT(fec, 1); */ MPLS_LIST_ELEM_INIT(fec, _global); MPLS_LIST_ELEM_INIT(fec, _inlabel); MPLS_LIST_ELEM_INIT(fec, _outlabel); MPLS_LIST_ELEM_INIT(fec, _fec); MPLS_LIST_INIT(&fec->nh_root, ldp_nexthop); MPLS_LIST_INIT(&fec->fs_root_us, ldp_fs); MPLS_LIST_INIT(&fec->fs_root_ds, ldp_fs); fec->index = _ldp_fec_get_next_index(); mpls_fec2ldp_fec(f,fec); _ldp_global_add_fec(g, fec); ldp_fec_insert(g, fec); } return fec; }
ldp_attr *ldp_attr_create(ldp_global *g, mpls_fec * fec) { ldp_attr *a = (ldp_attr *) mpls_malloc(sizeof(ldp_attr)); if (a != NULL) { memset(a, 0, sizeof(ldp_attr)); MPLS_LIST_ELEM_INIT(a, _session); MPLS_LIST_ELEM_INIT(a, _global); MPLS_LIST_ELEM_INIT(a, _fs); MPLS_LIST_INIT(&a->us_attr_root, ldp_attr); MPLS_REFCNT_INIT(a, 0); a->index = _ldp_attr_get_next_index(); a->in_tree = MPLS_BOOL_FALSE; a->ingress = MPLS_BOOL_FALSE; a->filtered = MPLS_BOOL_FALSE; if (fec != NULL) { mpls_fec2fec_tlv(fec, &a->fecTlv, 0); a->fecTlv.numberFecElements = 1; a->fecTlvExists = 1; } _ldp_global_add_attr(g, a); } return a; }
ldp_nexthop *ldp_nexthop_create(ldp_global *g, mpls_nexthop *n) { ldp_nexthop *nh = (ldp_nexthop *) mpls_malloc(sizeof(ldp_nexthop)); if (nh != NULL) { memset(nh, 0, sizeof(ldp_nexthop)); MPLS_REFCNT_INIT(nh, 0); MPLS_LIST_INIT(&nh->outlabel_root, ldp_outlabel); MPLS_LIST_ELEM_INIT(nh, _fec); MPLS_LIST_ELEM_INIT(nh, _addr); MPLS_LIST_ELEM_INIT(nh, _if); MPLS_LIST_ELEM_INIT(nh, _outlabel); nh->index = _ldp_nexthop_get_next_index(); mpls_nexthop2ldp_nexthop(n, nh); _ldp_global_add_nexthop(g, nh); } return nh; }