/* *=========================================================================== * ipcom_sysvar_tree_get *=========================================================================== * Description: * Parameters: * Returns: */ IP_STATIC Ipcom_sysvar_tree * ipcom_sysvar_tree_get(int vr) { #if IPCOM_VR_MAX > 1 if (vr == -1) vr = ipcom_proc_vr_get(); if (vr >= IPCOM_VR_MAX) return IP_NULL; #else vr = 0; #endif if (ipcom_sysvar.tree[vr].sysvars) ipcom_sysvar.tree[vr].referenced++; else { ipcom_sysvar.tree[vr].sysvars = ipcom_hash_new((Ipcom_hash_obj_func) ipcom_sysvar_hash_obj, (Ipcom_hash_key_func) ipcom_sysvar_hash_key, (Ipcom_hash_cmp_func) ipcom_sysvar_hash_cmp); if (ipcom_sysvar.tree[vr].sysvars == IP_NULL) return IP_NULL; ipcom_sysvar.tree[vr].vr = vr; ipcom_sysvar.tree[vr].referenced = 1; ipcom_sysvar_tree_initialize(&ipcom_sysvar.tree[vr]); } return &ipcom_sysvar.tree[vr]; }
/* *=========================================================================== * ipnet_vrrp_add_addr *=========================================================================== * Description: Adds a virtual router address. * Parameters: netif - The network interface the VRIP will be assigned to. * vrid - The VRID the address will be assigned to. * Returns: 0 = success, <0 = error code. * */ IP_GLOBAL int ipnet_vrrp_add_addr(Ipnet_netif *netif, Ip_u8 vrid, struct Ip_in_addr addr) { Ipnet_vrrp_addr_t *addr_entry; if (ipnet->vrrp_addrs == IP_NULL) { ipnet->vrrp_addrs = ipcom_hash_new((Ipcom_hash_obj_func) ipnet_vrrp_obj_hash, (Ipcom_hash_key_func) ipnet_vrrp_obj_hash, (Ipcom_hash_cmp_func) ipnet_vrrp_hash_cmp); if (ipnet->vrrp_addrs == IP_NULL) return -IP_ERRNO_ENOMEM; } addr_entry = ipnet_vrrp_get_addr_entry(netif, vrid); if (addr_entry == IP_NULL) { addr_entry = ipcom_malloc(sizeof(Ipnet_vrrp_addr_t)); if (addr_entry == IP_NULL) return -IP_ERRNO_ENOMEM; IPNET_IF_LOCK(netif); addr_entry->netif = netif; addr_entry->vrid = vrid; addr_entry->num_addrs = 1; addr_entry->addrs[0] = addr; } else { Ipnet_vrrp_addr_t *a; int i; i = ipnet_vrrp_addr_index(addr_entry, addr); if (i >= 0) return -IP_ERRNO_EEXIST; (void)ipcom_hash_remove(ipnet->vrrp_addrs, addr_entry); a = ipcom_realloc(addr_entry, sizeof(Ipnet_vrrp_addr_t) + addr_entry->num_addrs * sizeof(Ipnet_vrrp_addr_t)); if (a == IP_NULL) return -IP_ERRNO_ENOMEM; a->addrs[a->num_addrs++] = addr; addr_entry = a; } if (ipcom_hash_add(ipnet->vrrp_addrs, addr_entry) != IPCOM_SUCCESS) { ipcom_free(addr_entry); return -IP_ERRNO_ENOMEM; } IPCOM_LOG2(INFO, "VRRP: added address %s on %s", ipcom_inet_ntop(IP_AF_INET, &addr, ipnet->log_buf, sizeof(ipnet->log_buf)), netif->ipcom.name); return 0; }
/* *=========================================================================== * ipcom_env_init *=========================================================================== * Description: * Parameters: * Returns: */ IP_STATIC Ip_err ipcom_env_init(void *procptr) { Ipcom_proc *proc = procptr; ip_assert(proc != IP_NULL); (void)ipcom_mutex_create(&proc->env_mutex); proc->env_tree = ipcom_hash_new((Ipcom_hash_obj_func)ipcom_env_hash_obj, (Ipcom_hash_key_func)ipcom_env_hash_key, (Ipcom_hash_cmp_func)ipcom_env_hash_cmp); ip_assert(proc->env_tree != IP_NULL); return IPCOM_SUCCESS; }
/* *=========================================================================== * ipl2tp_start *=========================================================================== * Description: Start L2TP daemon. * Parameters: * Returns: * */ IP_PUBLIC Ip_err ipl2tp_start(void) { Ip_u16 pw_list[] = { IPL2TP_ATTR_PW_TYPE_ETHERNET, IPL2TP_ATTR_PW_TYPE_ETHERNET_VLAN }; Ipl2tp_attrobj attr = IP_NULL; Ipl2tp_attrobj tattr2 = IP_NULL; Ipl2tp_attrobj sattr2 = IP_NULL; Ipl2tp_attrobj tattr3 = IP_NULL; Ipl2tp_attrobj sattr3 = IP_NULL; Ip_u32 enable_v2; Ip_u32 enable_v3; ipl2tp_example_sessions = ipcom_hash_new((Ipcom_hash_obj_func)ipl2tp_example_obj_hash_key, (Ipcom_hash_key_func)ipl2tp_example_obj_hash_key, (Ipcom_hash_cmp_func)ipl2tp_example_cmp_key); ipcom_list_init(&ipl2tp_example_fds); /* Initialize */ ipl2tp_attr_strappend(&attr, IPL2TP_ATTR_SET_HOST_NAME, L2TP_HOST_NAME); ipl2tp_attr_pappend(&attr, IPL2TP_ATTR_SET_L2TP_WRITE_CALLBACK, (void *)ipl2tp_l2tp_write); ipl2tp_attr_iappend(&attr, IPL2TP_ATTR_SET_ENABLE_OUTGOING, IPL2TP_MIB_YES); #if L2TP_VERSION_2_ENABLE == TRUE enable_v2 = IPL2TP_MIB_YES; #else enable_v2 = IPL2TP_MIB_NO; #endif ipl2tp_attr_iappend(&attr, IPL2TP_ATTR_SET_ENABLE_L2TP_V2, enable_v2); #if L2TP_VERSION_3_ENABLE == TRUE enable_v3 = IPL2TP_MIB_YES; #else enable_v3 = IPL2TP_MIB_NO; #endif ipl2tp_attr_iappend(&attr, IPL2TP_ATTR_SET_ENABLE_L2TP_V3, enable_v3); ipl2tp_attr_pappend(&tattr2, IPL2TP_TATTR_SET_STATUS_CALLBACK, (void *)ipl2tp_example_tstatus_v2); ipl2tp_attr_pappend(&tattr3, IPL2TP_TATTR_SET_STATUS_CALLBACK, (void *)ipl2tp_example_tstatus_v3); ipl2tp_attr_vappend(&tattr3, IPL2TP_TATTR_SET_LOCAL_PSEUDOWIRE_CAPABILITIES_LIST, (void *)pw_list, sizeof(pw_list)); ipl2tp_attr_pappend(&sattr2, IPL2TP_SATTR_SET_STATUS_CALLBACK, (void *)ipl2tp_example_sstatus_v2); ipl2tp_attr_pappend(&sattr2, IPL2TP_SATTR_SET_DATA_CALLBACK, (void *)ipl2tp_ppp_data_cb); ipl2tp_attr_pappend(&sattr3, IPL2TP_SATTR_SET_STATUS_CALLBACK, (void *)ipl2tp_example_sstatus_v3); ipl2tp_attr_iappend(&sattr3, IPL2TP_SATTR_SET_PSEUDOWIRE_TYPE, IPL2TP_ATTR_PW_TYPE_ETHERNET_VLAN); ipl2tp_api_open(attr, tattr2, tattr3, sattr2, sattr3); ipl2tp_attr_delete(&attr); ipl2tp_attr_delete(&tattr2); ipl2tp_attr_delete(&sattr2); ipl2tp_attr_delete(&tattr3); ipl2tp_attr_delete(&sattr3); /* Spawn new daemon process */ return ipcom_proc_acreate("l2tps", ipl2tps, IP_NULL, IP_NULL); }