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_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_mesg *ldp_mesg_create() { ldp_mesg *msg = (ldp_mesg *) mpls_malloc(sizeof(ldp_mesg)); if (!msg) { return NULL; } return msg; }
mpls_socket_handle mpls_socket_create_tcp(mpls_socket_mgr_handle handle) { struct mpls_socket *sock; sock = mpls_malloc(sizeof(struct mpls_socket)); memset(sock,0,sizeof(struct mpls_socket)); sock->fd = socket(AF_INET, SOCK_STREAM, 0); MPLS_ASSERT(sock->fd > -1); return sock; }
mpls_tree_handle mpls_tree_create(int depth) { struct mpls_tree *tree; tree = mpls_malloc(sizeof(struct mpls_tree)); if(tree) RB_INIT(tree); return tree; }
ldp_resource *ldp_resource_create() { ldp_resource *r = (ldp_resource *) mpls_malloc(sizeof(ldp_resource)); if (r) { memset(r, 0, sizeof(ldp_resource)); MPLS_REFCNT_INIT(r, 0); MPLS_LIST_ELEM_INIT(r, _global); r->index = _ldp_resource_get_next_index(); } return r; }
mpls_return_enum mpls_tree_insert(mpls_tree_handle tree, uint32_t key, int length, void *info) { struct mpls_tree_node *node; node = mpls_malloc(sizeof(struct mpls_tree_node)); node->key = key; node->length = length; node->info = info; if(RB_INSERT(mpls_tree, tree, node) != NULL) return MPLS_FAILURE; return MPLS_SUCCESS; }
mpls_socket_handle mpls_socket_tcp_accept(mpls_socket_mgr_handle handle, mpls_socket_handle socket, mpls_dest * from) { struct mpls_socket *sock = mpls_malloc(sizeof(struct mpls_socket)); struct sockaddr addr; int size = sizeof(addr); if ((sock->fd = accept(socket->fd,&addr,&size)) < 0) { return NULL; } _sockaddr2mpls_dest(&addr, from); return sock; }
mpls_socket_handle mpls_socket_create_udp(mpls_socket_mgr_handle handle) { struct mpls_socket *sock; u_char one = 1; sock = mpls_malloc(sizeof(struct mpls_socket)); memset(sock,0,sizeof(struct mpls_socket)); sock->fd = socket(AF_INET, SOCK_DGRAM, 0); MPLS_ASSERT(sock->fd > -1); if (setsockopt(sock->fd,SOL_IP,IP_PKTINFO,&one,sizeof(one)) < 0) { perror("PKTINFO"); mpls_free(sock); return NULL; } return sock; }
ldp_inlabel *ldp_inlabel_create() { ldp_inlabel *i = (ldp_inlabel *) mpls_malloc(sizeof(ldp_inlabel)); if (i) { memset(i, 0, sizeof(ldp_inlabel)); MPLS_REFCNT_INIT(i, 0); mpls_link_list_init(&i->session_root); mpls_link_list_init(&i->attr_root); MPLS_LIST_ELEM_INIT(i, _global); MPLS_LIST_ELEM_INIT(i, _outlabel); i->index = _ldp_inlabel_get_next_index(); i->info.label.type = MPLS_LABEL_TYPE_NONE; } return i; }
ldp_adj *ldp_adj_create(mpls_inet_addr * source, mpls_inet_addr * lsraddr, int labelspace, int remote_hellotime, mpls_inet_addr * remote_transport_address, uint32_t remote_csn) { ldp_adj *a = (ldp_adj *) mpls_malloc(sizeof(ldp_adj)); struct in_addr addr; if (lsraddr == NULL || source == NULL) return NULL; if (a) { memset(a, 0, sizeof(ldp_adj)); MPLS_REFCNT_INIT(a, 0); MPLS_LIST_ELEM_INIT(a, _global); MPLS_LIST_ELEM_INIT(a, _session); MPLS_LIST_ELEM_INIT(a, _entity); a->index = _ldp_adj_get_next_index(); /* these are operational values */ /* JLEU: where do I grab these values from */ /* these values are learned form the remote peer */ memcpy(&a->remote_source_address, source, sizeof(mpls_inet_addr)); memcpy(&a->remote_lsr_address, lsraddr, sizeof(mpls_inet_addr)); addr.s_addr = htonl(lsraddr->u.ipv4); LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, LDP_TRACE_FLAG_PERIODIC, "Adj(%d) created for 0x%08x/",a->index, addr); addr.s_addr = htonl(source->u.ipv4); LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, LDP_TRACE_FLAG_PERIODIC, "0x%08x\n", addr); if (remote_transport_address) { memcpy(&a->remote_transport_address, remote_transport_address, sizeof(mpls_inet_addr)); } else { memset(&a->remote_transport_address, 0, sizeof(mpls_inet_addr)); } a->remote_hellotime = remote_hellotime; a->remote_csn = remote_csn; a->state = MPLS_OPER_DOWN; a->role = LDP_NONE; } 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; }
mpls_socket_handle mpls_socket_create_raw(mpls_socket_mgr_handle handle, int proto) { struct mpls_socket *sock; u_char opt; size_t optlen; sock = mpls_malloc(sizeof(struct mpls_socket)); memset(sock, 0, sizeof(struct mpls_socket)); sock->fd = socket(AF_INET, SOCK_RAW, proto); MPLS_ASSERT(sock->fd > -1); opt = 1; optlen = sizeof(opt); if(setsockopt(sock->fd, IPPROTO_IP, IP_RECVDSTADDR, &opt, optlen) < 0) { perror("PKTINFO"); mpls_free(sock); return NULL; } return sock; }
mpls_socket_handle mpls_socket_create_udp(mpls_socket_mgr_handle handle) { struct mpls_socket *sock; ssize_t opt; size_t optlen; sock = mpls_malloc(sizeof(struct mpls_socket)); if(!sock) return NULL; memset(sock, 0, sizeof(struct mpls_socket)); sock->fd = socket(AF_INET, SOCK_DGRAM, 0); MPLS_ASSERT(sock->fd > -1); opt = 1; optlen = sizeof(opt); if(setsockopt(sock->fd, IPPROTO_IP, IP_RECVIF, &opt, optlen) < 0) { perror("IP_RECVIF"); mpls_free(sock); return NULL; } return sock; }
mpls_lock_handle mpls_lock_create(mpls_lock_key_type key) { int *i = mpls_malloc(sizeof(int)); *i = 0; return i; }