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

📄 ldp_session.c

📁 Linux平台下
💻 C
📖 第 1 页 / 共 2 页
字号:
    mpls_timer_stop(g->timer_handle, s->initial_distribution_timer);    mpls_timer_delete(g->timer_handle, s->initial_distribution_timer);    MPLS_REFCNT_RELEASE(s, ldp_session_delete);    s->initial_distribution_timer = (mpls_timer_handle) 0;  }  /*   * get rid of the socket   */  if (mpls_socket_handle_verify(g->socket_handle, s->socket) ==    MPLS_BOOL_TRUE) {    mpls_socket_readlist_del(g->socket_handle, s->socket);    mpls_socket_close(g->socket_handle, s->socket);  }  /*   * get rid of out cached keepalive   */  if (s->keepalive != NULL) {    ldp_mesg_delete(s->keepalive);    s->keepalive = NULL;  }  ldp_session_backoff_stop(g,s);  attr = MPLS_LIST_HEAD(&g->attr);  while (attr != NULL) {    nattr = MPLS_LIST_NEXT(&g->attr, attr, _global);    if (attr->session && attr->session->index == s->index) {      /*       * ldp_attr_remove_complete removed everythig associated with the attr.       * in and out labels, and cross connects as well       */      ldp_attr_remove_complete(g, attr, complete);    }    attr = nattr;  }  /*   * clean up the addrs we created   */  while ((a = (ldp_addr*)mpls_link_list_head_data(&s->addr_root))) {    ldp_session_del_addr(g, s, a);  }  /*   * if we have an adj AND we are shuting down for a protocol reason, start a   * backoff timer, so we can try again in the near future   */  if ((complete == MPLS_BOOL_TRUE) || (s->oper_role != LDP_ACTIVE)) {    while ((ap = MPLS_LIST_HEAD(&s->adj_root))) {      ldp_adj_del_session(ap, s);    }    if (s->on_global == MPLS_BOOL_TRUE) {      _ldp_global_del_session(g, s);    }  } else {    if (s->oper_role == LDP_ACTIVE) {      ldp_session_backoff_start(g, s);    }  }  /*   * it is safe to release this refcnt now, if it is the last one, the   * session will be deleted (this will be the last one in the case of   * 'complete' == MPLS_BOOL_TRUE   */  MPLS_REFCNT_RELEASE(s, ldp_session_delete);  LDP_EXIT(g->user_data, "ldp_session_shutdown");}mpls_return_enum ldp_session_maintain_timer(ldp_global * g, ldp_session * s,  int flag){  mpls_return_enum result = MPLS_FAILURE;  LDP_ENTER(g->user_data, "ldp_session_maintain_timer");  /*   * all session keepalive maintainance comes through here (SEND and RECV)   */  if (flag == LDP_KEEPALIVE_RECV) {    mpls_timer_stop(g->timer_handle, s->keepalive_recv_timer);    result = mpls_timer_start(g->timer_handle, s->keepalive_recv_timer,      MPLS_TIMER_ONESHOT);  } else {    mpls_timer_stop(g->timer_handle, s->keepalive_send_timer);    result = mpls_timer_start(g->timer_handle, s->keepalive_send_timer,      MPLS_TIMER_REOCCURRING);  }  LDP_EXIT(g->user_data, "ldp_session_maintain_timer");  return result;}void ldp_session_add_outlabel(ldp_session * s, ldp_outlabel * o){  MPLS_ASSERT(s && o);  MPLS_REFCNT_HOLD(o);  MPLS_LIST_ADD_HEAD(&s->outlabel_root, o, _session, ldp_outlabel);  _ldp_outlabel_add_session(o, s);}void ldp_session_del_outlabel(ldp_global * g,ldp_session * s, ldp_outlabel * o){  MPLS_ASSERT(s && o);  MPLS_LIST_REMOVE(&s->outlabel_root, o, _session);  _ldp_outlabel_del_session(o);  MPLS_REFCNT_RELEASE2(g, o, ldp_outlabel_delete);}mpls_return_enum ldp_session_add_inlabel(ldp_global * g,ldp_session * s, ldp_inlabel * i){  MPLS_ASSERT(s && i);  MPLS_REFCNT_HOLD(i);  if (mpls_link_list_add_tail(&s->inlabel_root, i) == MPLS_SUCCESS) {    if (_ldp_inlabel_add_session(i, s) == MPLS_SUCCESS) {      return MPLS_SUCCESS;    }    mpls_link_list_remove_data(&s->inlabel_root, i);  }  MPLS_REFCNT_RELEASE2(g, i, ldp_inlabel_delete);  return MPLS_FAILURE;}void ldp_session_del_inlabel(ldp_global * g,ldp_session * s, ldp_inlabel * i){  MPLS_ASSERT(s && i);  mpls_link_list_remove_data(&s->inlabel_root, i);  _ldp_inlabel_del_session(i, s);  MPLS_REFCNT_RELEASE2(g, i, ldp_inlabel_delete)}void _ldp_session_add_attr(ldp_session * s, ldp_attr * a){  MPLS_ASSERT(s && a);  MPLS_REFCNT_HOLD(a);  MPLS_LIST_ADD_HEAD(&s->attr_root, a, _session, ldp_attr);}void _ldp_session_del_attr(ldp_global *g, ldp_session * s, ldp_attr * a){  MPLS_ASSERT(s && a);  MPLS_LIST_REMOVE(&s->attr_root, a, _session);  MPLS_REFCNT_RELEASE2(g, a, ldp_attr_delete);}mpls_return_enum ldp_session_add_addr(ldp_global *g, ldp_session * s,  ldp_addr * a){  struct mpls_link_list_node *lln;  struct mpls_link_list_node *llnp;  ldp_addr *data;  MPLS_ASSERT(s && a);  MPLS_REFCNT_HOLD(a);  lln = mpls_link_list_node_create(a);  if (lln) {    if (_ldp_addr_add_session(a, s) == MPLS_SUCCESS) {      MPLS_LINK_LIST_LOOP(&s->addr_root, data, llnp) {        if (data->index > a->index) {          mpls_link_list_add_node_before(&s->addr_root, llnp, lln);          return MPLS_SUCCESS;        }      }      mpls_link_list_add_node_tail(&s->addr_root, lln);      return MPLS_SUCCESS;    }    mpls_link_list_node_delete(lln);  }  MPLS_REFCNT_RELEASE2(g, a, ldp_addr_delete);  return MPLS_FAILURE;}void ldp_session_del_addr(ldp_global *g, ldp_session * s, ldp_addr * a) {  MPLS_ASSERT(s && a);  mpls_link_list_remove_data(&s->addr_root, a);  _ldp_addr_del_session(a, s);  MPLS_REFCNT_RELEASE2(g, a, ldp_addr_delete);}void _ldp_session_add_adj(ldp_session * s, ldp_adj * a){  ldp_adj *ap = NULL;  struct in_addr lsr_address;  MPLS_ASSERT(s && a);  MPLS_REFCNT_HOLD(a);  s->cfg_remote_in_ttl_less_domain = a->entity->remote_in_ttl_less_domain;  s->cfg_distribution_mode = a->entity->label_distribution_mode;  s->cfg_loop_detection_mode = a->entity->loop_detection_mode;  s->cfg_label_request_count = a->entity->label_request_count;  s->cfg_label_request_timer = a->entity->label_request_timer;  s->cfg_label_space = ldp_entity_label_space(a->entity);  s->cfg_path_vector_limit = a->entity->path_vector_limit;  s->cfg_hop_count_limit = a->entity->hop_count_limit;  s->cfg_peer_tcp_port = a->entity->remote_tcp_port;  s->cfg_keepalive = a->entity->keepalive_timer;  s->cfg_max_pdu = a->entity->max_pdu;  lsr_address.s_addr = htonl(a->remote_lsr_address.u.ipv4);  sprintf(s->session_name, "%s:%d", inet_ntoa(lsr_address),    a->remote_label_space);  s->oper_role = a->role;  ap = MPLS_LIST_HEAD(&s->adj_root);  while (ap) {    if (ap->index > a->index) {      MPLS_LIST_INSERT_BEFORE(&s->adj_root, ap, a, _session);      return;    }    ap = MPLS_LIST_NEXT(&s->adj_root, ap, _session);  }  MPLS_LIST_ADD_TAIL(&s->adj_root, a, _session, ldp_adj);}void _ldp_session_del_adj(ldp_session * s, ldp_adj * a){  MPLS_ASSERT(s && a);  MPLS_LIST_REMOVE(&s->adj_root, a, _session);  MPLS_REFCNT_RELEASE(a, ldp_adj_delete);}uint32_t _ldp_session_get_next_index(){  uint32_t retval = _ldp_session_next_index;  _ldp_session_next_index++;  if (retval > _ldp_session_next_index) {    _ldp_session_next_index = 1;  }  return retval;}mpls_return_enum ldp_session_find_raddr_index(ldp_session * s, uint32_t index,  ldp_addr ** addr){  struct mpls_link_list_node *lln;  ldp_addr *a = NULL;  if (s && index > 0) {    /* because we sort our inserts by index, this lets us know       if we've "walked" past the end of the list */    if (mpls_link_list_isempty(&s->addr_root)) {      *addr = NULL;      return MPLS_END_OF_LIST;    }    if ((a = (ldp_addr*)mpls_link_list_tail_data(&s->addr_root))) {      if (a->index < index) {        *addr = NULL;        return MPLS_END_OF_LIST;      }    }    MPLS_LINK_LIST_LOOP(&s->addr_root, a, lln) {      if (a->index == index) {        *addr = a;        return MPLS_SUCCESS;      }    }  }  *addr = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_session_backoff_stop(ldp_global * g, ldp_session * s){  LDP_ENTER(g->user_data, "ldp_session_backoff_stop");  s->backoff = 0;  if (mpls_timer_handle_verify(g->timer_handle, s->backoff_timer) ==    MPLS_BOOL_TRUE) {    mpls_timer_stop(g->timer_handle, s->backoff_timer);    mpls_timer_delete(g->timer_handle, s->backoff_timer);    s->backoff_timer = (mpls_timer_handle) 0;    MPLS_REFCNT_RELEASE(s, ldp_session_delete);  }  LDP_EXIT(g->user_data, "ldp_session_backoff_stop");  return MPLS_SUCCESS;}mpls_return_enum ldp_session_backoff_start(ldp_global * g, ldp_session * s){  mpls_bool valid;  MPLS_ASSERT(s);  LDP_ENTER(g->user_data, "ldp_session_backoff_start");  valid = mpls_timer_handle_verify(g->timer_handle,s->backoff_timer);  MPLS_ASSERT(valid == MPLS_BOOL_FALSE);  s->backoff += g->backoff_step;#if 0 /* if the above assert shouldn't be made this code should be executed */  {    /* this should never happen, but if so */    mpls_timer_stop(g->timer_handle, s->backoff_timer);    mpls_timer_delete(g->timer_handle, s->backoff_timer);    s->backoff_timer = (mpls_timer_handle) 0;    MPLS_REFCNT_RELEASE(s, ldp_session_delete);  }  if (!s) {              /* if we deleted session due to the above RELEASE */    LDP_EXIT(g->user_data, "ldp_session_backoff_start-error");    return MPLS_FAILURE;  }#endif  MPLS_REFCNT_HOLD(s);  s->backoff_timer = mpls_timer_create(g->timer_handle, MPLS_UNIT_SEC,    s->backoff, (void *)s, g, ldp_session_backoff_callback);  if (mpls_timer_handle_verify(g->timer_handle, s->backoff_timer) ==    MPLS_BOOL_FALSE) {    MPLS_REFCNT_RELEASE(s, ldp_session_delete);    LDP_EXIT(g->user_data, "ldp_session_backoff_start-error");    return MPLS_FAILURE;  }  if (mpls_timer_start(g->timer_handle, s->backoff_timer,    MPLS_TIMER_ONESHOT) != MPLS_SUCCESS) {    mpls_timer_delete(g->timer_handle, s->backoff_timer);    MPLS_REFCNT_RELEASE(s, ldp_session_delete);    LDP_EXIT(g->user_data, "ldp_session_backoff_start-error");    return MPLS_FAILURE;  }  LDP_EXIT(g->user_data, "ldp_session_backoff_start");  return MPLS_SUCCESS;}ldp_session *ldp_session_for_nexthop(ldp_nexthop *nh){  MPLS_ASSERT(nh);  LDP_ENTER(g->user_data, "ldp_session_for_nexthop: 0x%04d", nh->info.type);  if (nh->info.type & MPLS_NH_IP) {    LDP_PRINT(g->user_data, "ldp_session_for_nexthop-addr: %p %p %p\n",      nh, nh->addr, nh->addr->session);    if (nh->addr->session) {      LDP_EXIT(g->user_data, "ldp_session_for_nexthop-addr: %p",	nh->addr->session);      return nh->addr->session;    }  }  if (nh->info.type & MPLS_NH_IF) {    ldp_session *s = NULL;    if (nh->iff && (s = mpls_link_list_head_data(&nh->iff->session_root))) {      LDP_EXIT(g->user_data, "ldp_session_for_nexthop-iff");      return s;    }  }  if (nh->info.type & MPLS_NH_OUTSEGMENT) {    MPLS_ASSERT(0);  }  LDP_EXIT(g->user_data, "ldp_session_for_nexthop-none");  return NULL;}

⌨️ 快捷键说明

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