⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldp_cfg.c

📁 实现了MPLS中的标签分发协议(LDP 3036 )的基本功能
💻 C
📖 第 1 页 / 共 5 页
字号:
      case LDP_INDIRECT:        ldp_entity_del_peer(entity);        break;      default:        MPLS_ASSERT(0);    }    _ldp_global_del_entity(global, entity);    retval = MPLS_SUCCESS;    goto ldp_cfg_entity_set_end;  }  if (flag & LDP_ENTITY_CFG_SUB_INDEX) {    if (entity->sub_index != 0) {      /* unlink the old sub object */      switch (entity->entity_type) {        case LDP_DIRECT:          ldp_entity_del_if(global, entity);          break;        case LDP_INDIRECT:          ldp_entity_del_peer(entity);          break;        default:          MPLS_ASSERT(0);      }    }    /* link the new sub object */    switch (e->entity_type) {      case LDP_DIRECT:        {          ldp_if *iff = NULL;          if (ldp_global_find_if_index(global, e->sub_index,              &iff) != MPLS_SUCCESS) {            LDP_PRINT(global->user_data,              "ldp_cfg_entity_set: no such interface\n");            if (flag & LDP_CFG_ADD) {              _ldp_global_del_entity(global, entity);            }            goto ldp_cfg_entity_set_end;          }          ldp_entity_add_if(entity, iff);          break;        }      case LDP_INDIRECT:        {          ldp_peer *peer = NULL;          if (ldp_global_find_peer_index(global, e->sub_index, &peer) !=            MPLS_SUCCESS) {            LDP_PRINT(global->user_data, "ldp_cfg_entity_set: no such peer\n");            if (flag & LDP_CFG_ADD) {              _ldp_global_del_entity(global, entity);            }            goto ldp_cfg_entity_set_end;          }          ldp_entity_add_peer(entity, peer);          break;        }      default:        MPLS_ASSERT(0);    }  }  if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {    if (e->transport_address.type == MPLS_FAMILY_NONE) {      entity->inherit_flag |= LDP_ENTITY_CFG_TRANS_ADDR;    } else {      entity->inherit_flag &= ~LDP_ENTITY_CFG_TRANS_ADDR;    }    memcpy(&entity->transport_address, &e->transport_address,      sizeof(mpls_inet_addr));;  }  if (flag & LDP_ENTITY_CFG_PROTO_VER) {    entity->protocol_version = e->protocol_version;  }  if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {    entity->remote_tcp_port = e->remote_tcp_port;  }  if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {    entity->remote_udp_port = e->remote_udp_port;  }  if (flag & LDP_ENTITY_CFG_MAX_PDU) {    entity->max_pdu = e->max_pdu;  }  if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {    if (e->transport_address.type == MPLS_FAMILY_NONE) {      entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_TIMER;    } else {      entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER;    }    entity->keepalive_timer = e->keepalive_timer;  }  if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {    if (e->transport_address.type == MPLS_FAMILY_NONE) {      entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;    } else {      entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;    }    entity->keepalive_interval = e->keepalive_interval;  }  if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {    if (e->transport_address.type == MPLS_FAMILY_NONE) {      entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_TIMER;    } else {      entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_TIMER;    }    entity->hellotime_timer = e->hellotime_timer;  }  if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {    if (e->transport_address.type == MPLS_FAMILY_NONE) {      entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_INTERVAL;    } else {      entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL;    }    entity->hellotime_interval = e->hellotime_interval;  }  if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {    entity->session_setup_count = e->session_setup_count;  }  if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {    entity->session_backoff_timer = e->session_backoff_timer;  }  if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {    entity->label_distribution_mode = e->label_distribution_mode;  }  if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {    entity->path_vector_limit = e->path_vector_limit;  }  if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {    entity->hop_count_limit = e->hop_count_limit;  }  if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {    entity->label_request_count = e->label_request_count;  }  if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {    entity->label_request_timer = e->label_request_timer;  }  if (flag & LDP_ENTITY_CFG_TYPE) {    entity->entity_type = e->entity_type;  }  if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {    if (ldp_entity_is_active(entity) == MPLS_BOOL_TRUE &&      e->admin_state == MPLS_ADMIN_DISABLE) {      if (ldp_entity_shutdown(global, entity, 0) == MPLS_FAILURE) {        goto ldp_cfg_entity_set_end;      }    } else if (ldp_entity_is_active(entity) == MPLS_BOOL_FALSE &&      e->admin_state == MPLS_ADMIN_ENABLE && ldp_entity_is_ready(entity) == MPLS_BOOL_TRUE) {      if (ldp_entity_startup(global, entity) == MPLS_FAILURE) {        goto ldp_cfg_entity_set_end;      }    } else {      LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity not ready\n");      goto ldp_cfg_entity_set_end;    }  }  if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {    entity->inherit_flag = e->inherit_flag;  }  global->configuration_sequence_number++;  retval = MPLS_SUCCESS;ldp_cfg_entity_set_end:  mpls_lock_release(global->global_lock); /* UNLOCK */  LDP_EXIT(global->user_data, "ldp_cfg_entity_set");  return retval;}mpls_return_enum ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle,  ldp_entity * e){  ldp_global *g = (ldp_global *) handle;  mpls_bool this_one = MPLS_BOOL_FALSE;  mpls_return_enum r = MPLS_FAILURE;  ldp_adj *adj_next = NULL;  ldp_adj *adj = NULL;  ldp_entity *entity = NULL;  LDP_ENTER(g->user_data, "ldp_cfg_entity_adj_getnext");  /* if an adj_index of zero is sent, get the index of   * the first adj in the list   */  if (!e->adj_index) {    this_one = MPLS_BOOL_TRUE;  }  mpls_lock_get(g->global_lock); /* LOCK */  if (ldp_global_find_entity_index(g, e->index, &entity) == MPLS_SUCCESS) {    adj = MPLS_LIST_HEAD(&entity->adj_root);    while (adj) {      if (this_one == MPLS_BOOL_TRUE) {        adj_next = adj;        break;      }      /* since the entities are sort in the list ... */      if (adj->index > e->adj_index) {        break;      } else if (adj->index == e->adj_index) {        this_one = MPLS_BOOL_TRUE;      }      adj = MPLS_LIST_NEXT(&entity->adj_root, adj, _entity);    }  }  mpls_lock_release(g->global_lock); /* UNLOCK */  if (adj_next) {    e->adj_index = adj_next->index;    r = MPLS_SUCCESS;  }  LDP_EXIT(g->user_data, "ldp_cfg_entity_adj_getnext");  return r;}/******************* INTERFACE **********************/mpls_return_enum ldp_cfg_if_get(mpls_cfg_handle handle, ldp_if * i, uint32_t flag){  ldp_global *global = (ldp_global *) handle;  ldp_if *iff = NULL;  mpls_return_enum retval = MPLS_FAILURE;  MPLS_ASSERT(global !=NULL && i != NULL);  LDP_ENTER(global->user_data, "ldp_cfg_if_get");  mpls_lock_get(global->global_lock); /* LOCK */  if (flag & LDP_IF_CFG_BY_INDEX) {    ldp_global_find_if_index(global, i->index, &iff);  } else {    iff = ldp_global_find_if_handle(global, i->handle);  }  if (!iff)      goto ldp_cfg_if_get_end;  if (flag & LDP_IF_CFG_LABEL_SPACE) {    i->label_space = iff->label_space;  }  if (flag & LDP_IF_CFG_ENTITY_INDEX) {    i->entity_index = iff->entity ? iff->entity->index : 0;  }  if (flag & LDP_IF_CFG_OPER_STATE) {    i->oper_state = iff->oper_state;  }  if (flag & LDP_IF_CFG_HANDLE) {    memcpy(&i->handle, &iff->handle, sizeof(mpls_if_handle));  }  retval = MPLS_SUCCESS;ldp_cfg_if_get_end:  mpls_lock_release(global->global_lock); /* UNLOCK */  LDP_EXIT(global->user_data, "ldp_cfg_if_get");  return retval;}mpls_return_enum ldp_cfg_if_getnext(mpls_cfg_handle handle, ldp_if * i,  uint32_t flag){  ldp_global *g = (ldp_global *) handle;  ldp_if *iff = NULL;  mpls_return_enum r = MPLS_FAILURE;  mpls_bool done = MPLS_BOOL_FALSE;  int index;  LDP_ENTER(g->user_data, "ldp_cfg_if_getnext");  if (i->index == 0) {    index = 1;  } else {    index = i->index + 1;  }  mpls_lock_get(g->global_lock); /* LOCK */  while (done == MPLS_BOOL_FALSE) {    switch ((r = ldp_global_find_if_index(g, index, &iff))) {      case MPLS_SUCCESS:      case MPLS_END_OF_LIST:        done = MPLS_BOOL_TRUE;        break;      case MPLS_FAILURE:        break;      default:        MPLS_ASSERT(0);    }    index++;  }  mpls_lock_release(g->global_lock); /* UNLOCK */  if (r == MPLS_SUCCESS) {    i->index = iff->index;    LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");    return ldp_cfg_if_get(g, i, flag);  }  LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");  return r;}mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i,  uint32_t flag){  ldp_global *global = (ldp_global *) handle;  ldp_if *iff = NULL;  mpls_return_enum retval = MPLS_FAILURE;  MPLS_ASSERT(global !=NULL && i != NULL);  LDP_ENTER(global->user_data, "ldp_cfg_if_test");  mpls_lock_get(global->global_lock); /* LOCK */  if (!(flag & LDP_CFG_ADD)) {    ldp_global_find_if_index(global, i->index, &iff);  } else {    retval = MPLS_SUCCESS;    goto ldp_cfg_if_test_end;  }  if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&    (flag & LDP_IF_CFG_WHEN_DOWN))) {    goto ldp_cfg_if_test_end;  }  if (flag & LDP_CFG_DEL) {    if (iff->entity != NULL) {      goto ldp_cfg_if_test_end;    }  }  retval = MPLS_SUCCESS;ldp_cfg_if_test_end:  mpls_lock_release(global->global_lock); /* UNLOCK */  LDP_EXIT(global->user_data, "ldp_cfg_if_test");  return retval;}mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t flag){  ldp_global *global = (ldp_global*)handle;  ldp_if *iff = NULL;  ldp_addr *ap;  ldp_nexthop *np;  mpls_return_enum retval = MPLS_FAILURE;  MPLS_ASSERT(global !=NULL && i != NULL);  LDP_ENTER(global->user_data, "ldp_cfg_if_set");  mpls_lock_get(global->global_lock); /* LOCK */  if (flag & LDP_CFG_ADD) {    /* duplicate interface handles are not allowed */    /* ADDs require a valid interface handle */    if (((iff = ldp_global_find_if_handle(global, i->handle)) != NULL) ||      (mpls_if_handle_verify(global->ifmgr_handle, i->handle) ==      MPLS_BOOL_FALSE) || ((iff = ldp_if_create(global)) == NULL)) {      goto ldp_cfg_if_set_end;    }    /* copy the handle from the user */    iff->handle = i->handle;    /* search for addrs and nexthops that are waiting for this interface */    ap = MPLS_LIST_HEAD(&global->addr);    while (ap) {      if (ap->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(ap, _if))) {        ldp_if_add_addr(iff, ap);      }      ap = MPLS_LIST_NEXT(&global->addr, ap, _global);    }    np = MPLS_LIST_HEAD(&global->nexthop);    while (np) {      if ((np->info.type & MPLS_NH_IF) &&	(np->info.if_handle == iff->handle) && (!MPLS_LIST_IN_LIST(np, _if))) {        ldp_if_add_nexthop(iff, np);      }      np = MPLS_LIST_NEXT(&global->nexthop, np, _global);    }    /* send the newly created index back to the user */    i->index = iff->index;    MPLS_REFCNT_HOLD(iff);  } else {    if (flag & LDP_IF_CFG_BY_INDEX) {      ldp_global_find_if_index(global, i->index, &iff);    } else {      iff = ldp_global_find_if_handle(global, i->handle);    }  }  /*   * if we can't find this interface or if the interface is active and   * we are trying to change propertises that can not be changed on a   * active interface   */  if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&    (flag & LDP_IF_CFG_WHEN_DOWN))) {    goto ldp_cfg_if_set_end;  }  if (flag & LDP_IF_CFG_LABEL_SPACE) {    iff->label_space = i->label_space;  }  if (flag & LDP_CFG_DEL) {    /*     * if this interface is still attached to a entity that it is not ready     * to be removed     */    if (iff->entity != NULL) {      goto ldp_cfg_if_set_end;    }    np = MPLS_LIST_HEAD(&iff->nh_root);    while ((np = MPLS_LIST_HEAD(&iff->nh_root))) {      ldp_if_del_nexthop(global, iff, np);    }    ap = MPLS_LIST_HEAD(&iff->addr_root);    while ((ap = MPLS_LIST_HEAD(&iff->addr_root))) {      ldp_if_del_addr(global, iff, ap);    }    MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete);  }  global->configuration_sequence_number++;  retval = MPLS_SUCCESS;ldp_cfg_if_set_end:  mpls_lock_release(global->global_lock); /* UNLOCK */  LDP_EXIT(global->user_data, "ldp_cfg_if_set");  return retval;}/******************* ATTR **********************/mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,  uint32_t flag){  ldp_global *global = (ldp_global *) handle;  ldp_attr *attr = NULL;  mpls_return_enum retval = MPLS_FAILURE;  MPLS_ASSERT(global !=NULL && a != NULL);  LDP_ENTER(global->user_data, "ldp_cfg_attr_get");  mpls_lock_get(global->global_lock); /* LOCK */  if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)      goto ldp_cfg_attr_get_end;  if (flag & LDP_ATTR_CFG_STATE) {    a->state = attr->state;  }  if (flag & LDP_ATTR_CFG_FEC) {    ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);  }  if (flag & LDP_ATTR_CFG_LABEL) {    ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);  }  if (flag & LDP_ATTR_CFG_HOP_COUNT) {    ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);  }  if (flag & LDP_ATTR_CFG_PATH) {    ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);  }  if (flag & LDP_ATTR_CFG_SESSION_INDEX) {    a->session_index = (attr->session) ? (attr->session->index) : 0;  }  if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {    a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -