📄 ldp_attr.c
字号:
case MPLS_PREFIX_FEC: case MPLS_HOSTADR_FEC: if (a->fecTlv.fecElArray[i].addressEl.addressFam != b->fecTlv.fecElArray[i].addressEl.addressFam || a->fecTlv.fecElArray[i].addressEl.preLen != b->fecTlv.fecElArray[i].addressEl.preLen || a->fecTlv.fecElArray[i].addressEl.address != b->fecTlv.fecElArray[i].addressEl.address) { return MPLS_BOOL_FALSE; } break; default: MPLS_ASSERT(0); } } } else { return MPLS_BOOL_FALSE; } } if (flag & LDP_ATTR_MSGID) { if (a->lblMsgIdTlvExists && b->lblMsgIdTlvExists) { if (a->lblMsgIdTlv.msgId != b->lblMsgIdTlv.msgId) { return MPLS_BOOL_FALSE; } } else { return MPLS_BOOL_FALSE; } } if (flag & LDP_ATTR_LSPID) { if (a->lspidTlvExists && b->lspidTlvExists) { if (a->lspidTlv.localCrlspId != b->lspidTlv.localCrlspId || a->lspidTlv.routerId != b->lspidTlv.routerId) { return MPLS_BOOL_FALSE; } } else { return MPLS_BOOL_FALSE; } } if (flag & LDP_ATTR_TRAFFIC) { } return MPLS_BOOL_TRUE;}mpls_return_enum ldp_attr_insert_upstream2(ldp_global * g, ldp_session * s, ldp_attr * a, ldp_fec *f){ ldp_fs *fs = NULL; mpls_return_enum retval; MPLS_ASSERT(g && s && a && (a->in_tree == MPLS_BOOL_FALSE) && f); /* find the upstream fs for this session */ if ((fs = _ldp_fec_find_fs_us(f, s, MPLS_BOOL_TRUE)) == NULL) { /* this session isn't in the list and cannot be added */ return MPLS_FAILURE; } ldp_attr_add_session(a, s); ldp_attr_add_fec(a, f); retval = _ldp_fs_add_attr(fs, a); a->in_tree = MPLS_BOOL_TRUE; return retval;}mpls_return_enum ldp_attr_insert_upstream(ldp_global * g, ldp_session * s, ldp_attr * a){ ldp_fec *fnode = NULL; MPLS_ASSERT(g && s && a && (a->in_tree == MPLS_BOOL_FALSE)); if ((fnode = _ldp_attr_get_fec(g, a, MPLS_BOOL_TRUE)) == NULL) { /* we couldn't get/add a node from/to the tree! */ return MPLS_FAILURE; } return ldp_attr_insert_upstream2(g, s, a, fnode);}mpls_return_enum ldp_attr_insert_downstream2(ldp_global * g, ldp_session * s, ldp_attr * a, ldp_fec *f){ ldp_fs *fs = NULL; mpls_return_enum retval; MPLS_ASSERT(g && s && a && (a->in_tree == MPLS_BOOL_FALSE) && f); /* find the downstream fs for this session */ if ((fs = _ldp_fec_find_fs_ds(f, s, MPLS_BOOL_TRUE)) == NULL) { /* this session isn't in the list and cannot be added */ return MPLS_FAILURE; } ldp_attr_add_session(a, s); ldp_attr_add_fec(a, f); retval = _ldp_fs_add_attr(fs, a); a->in_tree = MPLS_BOOL_TRUE; return retval;}mpls_return_enum ldp_attr_insert_downstream(ldp_global * g, ldp_session * s, ldp_attr * a){ ldp_fec *fnode = NULL; MPLS_ASSERT(g && s && a && (a->in_tree == MPLS_BOOL_FALSE)); if ((fnode = _ldp_attr_get_fec(g, a, MPLS_BOOL_TRUE)) == NULL) { /* we couldn't get/add a node from/to the tree! */ return MPLS_FAILURE; } return ldp_attr_insert_downstream2(g, s, a, fnode);}ldp_attr_list *ldp_attr_find_upstream_all2(ldp_global * g, ldp_session * s, ldp_fec * f){ ldp_fs *fs = NULL; MPLS_ASSERT(f && g); if (!s) { return NULL; } /* find the upstream fs for this session */ if ((fs = _ldp_fec_find_fs_us(f, s, MPLS_BOOL_FALSE)) == NULL) { /* this session isn't in the list */ return NULL; } return &fs->attr_root;}ldp_attr_list *ldp_attr_find_upstream_all(ldp_global * g, ldp_session * s, mpls_fec * f){ ldp_fec *fnode = NULL; MPLS_ASSERT(f && g); if (!s) { return NULL; } if ((fnode = _ldp_attr_get_fec2(g, f, MPLS_BOOL_FALSE)) == NULL) { /* we couldn't get the node from the tree! */ return NULL; } return ldp_attr_find_upstream_all2(g, s, fnode);}ldp_attr_list *ldp_attr_find_downstream_all2(ldp_global * g, ldp_session * s, ldp_fec * f){ ldp_fs *fs = NULL; MPLS_ASSERT(f && g); if (!s) { return NULL; } /* find the downstream fs for this session */ if ((fs = _ldp_fec_find_fs_ds(f, s, MPLS_BOOL_FALSE)) == NULL) { /* this session isn't in the list */ return NULL; } return &fs->attr_root;}ldp_attr_list *ldp_attr_find_downstream_all(ldp_global * g, ldp_session * s, mpls_fec * f){ ldp_fec *fnode = NULL; MPLS_ASSERT(f && g); if (!s) { return NULL; } if ((fnode = _ldp_attr_get_fec2(g, f, MPLS_BOOL_FALSE)) == NULL) { /* we couldn't get the node from the tree! */ return NULL; } return ldp_attr_find_downstream_all2(g, s, fnode);}void ldp_attr_delete_upstream(ldp_global * g, ldp_session * s, ldp_attr * a){ ldp_fec *fnode = NULL; ldp_fs *fs = NULL; MPLS_ASSERT(a->in_tree == MPLS_BOOL_TRUE); MPLS_REFCNT_HOLD(a); /* find the fec node in the tree */ if ((fnode = _ldp_attr_get_fec(g, a, MPLS_BOOL_FALSE))) { /* find the upstream fs for this session, on the fec */ if ((fs = _ldp_fec_find_fs_us(fnode, s, MPLS_BOOL_FALSE))) { /* remove this attr from the fs, if this was the last * attr on the fs, then remove the fs from the fec node */ if (_ldp_fs_del_attr(g, fs, a) == MPLS_BOOL_TRUE) { _ldp_fec_del_fs_us(fnode, fs); } } } ldp_attr_del_session(g, a); ldp_attr_del_fec(g, a); a->in_tree = MPLS_BOOL_FALSE; MPLS_REFCNT_RELEASE2(g, a, ldp_attr_delete);}void ldp_attr_delete_downstream(ldp_global * g, ldp_session * s, ldp_attr * a){ ldp_fec *fnode = NULL; ldp_fs *fs = NULL; MPLS_ASSERT(a->in_tree == MPLS_BOOL_TRUE); MPLS_REFCNT_HOLD(a); /* see ldp_attr_delete_upstream for more info */ if ((fnode = _ldp_attr_get_fec(g, a, MPLS_BOOL_FALSE))) { if ((fs = _ldp_fec_find_fs_ds(fnode, s, MPLS_BOOL_FALSE))) { if (_ldp_fs_del_attr(g, fs, a) == MPLS_BOOL_TRUE) { _ldp_fec_del_fs_ds(fnode, fs); } } } ldp_attr_del_session(g, a); ldp_attr_del_fec(g, a); a->in_tree = MPLS_BOOL_FALSE; MPLS_REFCNT_RELEASE2(g, a, ldp_attr_delete);}void ldp_attr2mpls_label_struct(ldp_attr * a, mpls_label_struct * l){ if (a->genLblTlvExists) { l->type = MPLS_LABEL_TYPE_GENERIC; l->u.gen = a->genLblTlv.label; } else if (a->atmLblTlvExists) { l->type = MPLS_LABEL_TYPE_ATM; l->u.atm.vpi = a->atmLblTlv.flags.flags.vpi; l->u.atm.vci = a->atmLblTlv.vci; } else if (a->frLblTlvExists) { l->type = MPLS_LABEL_TYPE_FR; l->u.fr.len = a->frLblTlv.flags.flags.len; l->u.fr.dlci = a->frLblTlv.flags.flags.dlci; } else { MPLS_ASSERT(0); }}void mpls_label_struct2ldp_attr(mpls_label_struct * l, ldp_attr * a){ switch (l->type) { case MPLS_LABEL_TYPE_GENERIC: a->genLblTlvExists = 1; a->atmLblTlvExists = 0; a->frLblTlvExists = 0; a->genLblTlv.label = l->u.gen; break; case MPLS_LABEL_TYPE_ATM: a->genLblTlvExists = 0; a->atmLblTlvExists = 1; a->frLblTlvExists = 0; a->atmLblTlv.flags.flags.vpi = l->u.atm.vpi; a->atmLblTlv.vci = l->u.atm.vci; case MPLS_LABEL_TYPE_FR: a->genLblTlvExists = 0; a->atmLblTlvExists = 0; a->frLblTlvExists = 1; a->frLblTlv.flags.flags.len = l->u.fr.len; a->frLblTlv.flags.flags.dlci = l->u.fr.dlci; default: MPLS_ASSERT(0); }}#if 0void ldp_attr2ldp_attr(ldp_attr * src, ldp_attr * dst, u_int32 flag){ if (flag & LDP_ATTR_FEC) { memcpy(&dst->fecTlv, &src->fecTlv, sizeof(mplsLdpFecTlv_t)); dst->fecTlvExists = src->fecTlvExists; } if (flag & LDP_ATTR_LABEL) { memcpy(&dst->genLblTlv, &src->genLblTlv, sizeof(mplsLdpGenLblTlv_t)); memcpy(&dst->atmLblTlv, &src->atmLblTlv, sizeof(mplsLdpAtmLblTlv_t)); memcpy(&dst->frLblTlv, &src->frLblTlv, sizeof(mplsLdpFrLblTlv_t)); dst->genLblTlvExists = src->genLblTlvExists dst->atmLblTlvExists = src->atmLblTlvExists dst->frLblTlvExists = src->frLblTlvExists} if (flag & LDP_ATTR_HOPCOUNT) { memcpy(&dst->hopCountTlv, &src->hopCountTlv, sizeof(mplsLdpHopTlv_t)); dst->hopCountTlvExists = src->hopCountTlvExists; } if (flag & LDP_ATTR_PATH) { memcpy(&dst->pathVecTlv, &src->pathVecTlv, sizeof(mplsLdpPathTlv_t)); dst->pathVecTlvExists = src->pathVecTlvExists; } if (flag & LDP_ATTR_MSGID) { memcpy(&dst->lblMsgIdTlv, &src->lblMsgIdTlv, sizeof(mplsLdpLblMsgIdTlv_t)); dst->lblMsgIdTlvExists = src->lblMsgIdTlvExists; } if (flag & LDP_ATTR_LSPID) { memcpy(&dst->lspidTlv, &src->lspidTlv, sizeof(mplsLdpLspIdTlv_t)); dst->lspidTlvExists = src->lspidTlvExists; } if (flag & LDP_ATTR_TRAFFIC) { memcpy(&dst->trafficTlv, &src->trafficTlv, sizeof(mplsLdpTrafficTlv_t)); dst->trafficTlvExists = src->trafficTlvExists; }}#endifldp_fec *_ldp_attr_get_fec2(ldp_global * g, mpls_fec * f, mpls_bool flag){ ldp_fec *fnode = NULL; if (!(fnode = ldp_fec_find(g,f))) { if (flag == MPLS_BOOL_FALSE) { return NULL; } /* this FEC doesn't exist in the tree yet, create one ... */ if (!(fnode = ldp_fec_create(g, f))) { /* insert failed */ return NULL; } } return fnode;}static ldp_fec *_ldp_attr_get_fec(ldp_global * g, ldp_attr * a, mpls_bool flag){ mpls_fec fec; /* get FEC from attr */ fec_tlv2mpls_fec(&a->fecTlv, 0, &fec); return _ldp_attr_get_fec2(g, &fec, flag);}static ldp_fs *_ldp_fec_add_fs_ds(ldp_fec * fec, ldp_session * s){ ldp_fs *fs = _ldp_fec_find_fs_ds(fec, s, MPLS_BOOL_FALSE); if (fs == NULL) { fs = _ldp_fs_create(s); if (fs == NULL) { return NULL; } MPLS_LIST_ADD_HEAD(&fec->fs_root_ds, fs, _fec, ldp_fs); } return fs;}static ldp_fs *_ldp_fec_add_fs_us(ldp_fec * fec, ldp_session * s){ ldp_fs *fs = _ldp_fec_find_fs_us(fec, s, MPLS_BOOL_FALSE); if (fs == NULL) { fs = _ldp_fs_create(s); if (fs == NULL) { return NULL; } MPLS_LIST_ADD_HEAD(&fec->fs_root_us, fs, _fec, ldp_fs); } return fs;}static ldp_fs *_ldp_fec_find_fs_us(ldp_fec * fec, ldp_session * s, mpls_bool flag){ ldp_fs *fs = MPLS_LIST_HEAD(&fec->fs_root_us); while (fs != NULL) { if (fs->session->index == s->index) { return fs; } fs = MPLS_LIST_NEXT(&fec->fs_root_us, fs, _fec); } if (flag == MPLS_BOOL_FALSE) { return NULL; } return _ldp_fec_add_fs_us(fec, s);}static ldp_fs *_ldp_fec_find_fs_ds(ldp_fec * fec, ldp_session * s, mpls_bool flag){ ldp_fs *fs = MPLS_LIST_HEAD(&fec->fs_root_ds); while (fs != NULL) { if (fs->session->index == s->index) { return fs; } fs = MPLS_LIST_NEXT(&fec->fs_root_ds, fs, _fec); } if (flag == MPLS_BOOL_FALSE) { return NULL; } return _ldp_fec_add_fs_ds(fec, s);}static void _ldp_fec_del_fs_us(ldp_fec * fec, ldp_fs * fs){ if (fs == NULL) { return; } MPLS_LIST_REMOVE(&fec->fs_root_us, fs, _fec); _ldp_fs_delete(fs);}static void _ldp_fec_del_fs_ds(ldp_fec * fec, ldp_fs * fs){ if (fs == NULL) { return; } MPLS_LIST_REMOVE(&fec->fs_root_ds, fs, _fec); _ldp_fs_delete(fs);}static ldp_fs *_ldp_fs_create(ldp_session * s){ ldp_fs *fs = (ldp_fs *) mpls_malloc(sizeof(ldp_fs)); if (fs != NULL) { memset(fs, 0, sizeof(ldp_fs)); MPLS_LIST_INIT(&fs->attr_root, ldp_attr); MPLS_LIST_ELEM_INIT(fs, _fec); if (s != NULL) { MPLS_REFCNT_HOLD(s); fs->session = s; } } return fs;}static void _ldp_fs_delete(ldp_fs * fs){ LDP_PRINT(NULL, "fs delete %p", fs); if (fs->session != NULL) { MPLS_REFCNT_RELEASE(fs->session, ldp_session_delete); } mpls_free(fs);}static ldp_attr *_ldp_fs_find_attr(ldp_fs * fs, ldp_attr * a){ ldp_attr *ptr = MPLS_LIST_HEAD(&fs->attr_root); while (ptr != NULL) { if (ldp_attr_is_equal(a, ptr, LDP_ATTR_LABEL | LDP_ATTR_FEC) == MPLS_BOOL_TRUE) { return ptr; } ptr = MPLS_LIST_NEXT(&fs->attr_root, ptr, _fs); } return NULL;}static mpls_return_enum _ldp_fs_add_attr(ldp_fs * fs, ldp_attr * a){ ldp_attr *ptr = _ldp_fs_find_attr(fs, a); MPLS_ASSERT(ptr == NULL); MPLS_REFCNT_HOLD(a); MPLS_LIST_ADD_HEAD(&fs->attr_root, a, _fs, ldp_attr); return MPLS_SUCCESS;}static mpls_bool _ldp_fs_del_attr(ldp_global *g, ldp_fs * fs, ldp_attr * a){ ldp_attr *ptr = _ldp_fs_find_attr(fs, a); if (ptr != NULL) { MPLS_LIST_REMOVE(&fs->attr_root, ptr, _fs); MPLS_REFCNT_RELEASE2(g, ptr, ldp_attr_delete); } if (MPLS_LIST_HEAD(&fs->attr_root) == NULL) return MPLS_BOOL_TRUE; return MPLS_BOOL_FALSE;}ldp_attr *ldp_attr_find_upstream_map_in_labelspace(ldp_fec *f, int labelspace){ ldp_fs *fs = MPLS_LIST_HEAD(&f->fs_root_us); while (fs) { ldp_attr *attr = MPLS_LIST_HEAD(&fs->attr_root); while (attr) { if (attr->state == LDP_LSP_STATE_MAP_SENT) { if (attr->session->cfg_label_space == labelspace) { return attr; } } attr = MPLS_LIST_NEXT(&fs->attr_root, attr, _fs); } fs = MPLS_LIST_NEXT(&f->fs_root_us, fs, _fec); } return NULL;}static uint32_t _ldp_attr_get_next_index(){ uint32_t retval = _ldp_attr_next_index; _ldp_attr_next_index++; if (retval > _ldp_attr_next_index) { _ldp_attr_next_index = 1; } return retval;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -