/* *=========================================================================== * ipnet_sysctl_route_dump *=========================================================================== * Description: Dumps all routes entries. * Parameters: oldp - buffer to where the route entries will be copied * oldlenp - [in] the length of 'oldp' buffer * [out] the number of bytes copied to 'oldp' buffer or * the number of bytes needed (if 'oldp' is IP_NULL). * domain - the domain to return routes for (0=all domains) * flags - the IPNET_RTF_xxx flags that must be set in the returned * entries. * Returns: 0 == success, <0 == error code. * */ IP_STATIC int ipnet_sysctl_route_dump(Ip_u16 vr, void *oldp, Ip_size_t *oldlenp, int domain, Ip_u32 flags) { Ipnet_sysctl_route_data data; data.buf = oldp; if (oldp == IP_NULL) data.buf_len = 0; else data.buf_len = *oldlenp; data.bytes_written = 0; data.flags = flags; data.soerrno = 0; data.domain = domain; data.vr = vr; if (ipnet->rtabs != IP_NULL) ipcom_hash_for_each(ipnet->rtabs, (Ipcom_hash_foreach_cb_func) ipnet_sysctl_for_each_rtab_cb, &data); if (oldlenp) *oldlenp = data.bytes_written; return data.soerrno; }
/* *=========================================================================== * ipcom_sysvar_tree *=========================================================================== * Description: * Parameters: * Returns: */ IP_STATIC void ipcom_sysvar_tree_done(Ipcom_sysvar_tree *tree) { if (tree == IP_NULL) return; /* If we're killing the last reference, to deal finalization */ if (tree->referenced == 1) { /* Did it kill the tree? */ if (ipcom_sysvar_tree_finalize(tree)) { ipcom_hash_for_each(tree->sysvars, (Ipcom_hash_foreach_cb_func)ipcom_sysvar_free, tree); ipcom_hash_delete(tree->sysvars); tree->sysvars = IP_NULL; } } /* Decrease AFTER, since finalize may invoke sysvar calls as well */ tree->referenced--; }
/* *=========================================================================== * ipcom_proc_copyenv *=========================================================================== * Description: * Parameters: * Returns: * */ IP_GLOBAL void ipcom_proc_copyenv(Ipcom_proc *proc_c) { Ipcom_proc *proc_p; Ip_err retval; proc_p = ipcom_proc_self(); ip_assert(proc_p != IP_NULL); ip_assert(proc_c != IP_NULL); if (proc_p->env_tree == IP_NULL) /* Parent process has no environment variables */ return; /* Create child environment semaphore and tree */ retval = ipcom_once(&proc_c->env_once, ipcom_env_init, proc_c); if (retval != IPCOM_SUCCESS) { IP_PANIC(); return; } ipcom_mutex_lock(proc_p->env_mutex); ipcom_hash_for_each(proc_p->env_tree, (Ipcom_hash_foreach_cb_func) ipcom_env_clone, proc_c->env_tree); ipcom_mutex_unlock(proc_p->env_mutex); }
/* *=========================================================================== * ipcom_clearenv *=========================================================================== * Description: * Parameters: * Returns: * */ IP_GLOBAL void ipcom_proc_clearenv(Ipcom_proc *proc) { ip_assert(proc != IP_NULL); ipcom_mutex_lock(proc->env_mutex); /* Remove all environment variable entries */ ipcom_hash_for_each(proc->env_tree, (Ipcom_hash_foreach_cb_func) ipcom_env_delete, proc->env_tree); ipcom_mutex_unlock(proc->env_mutex); }
/* *========================================================================== * ipnet_rtnetlink_route_dump_family *=========================================================================== * Description: Get interface info via NETLINK * Parameters: data - Message payload. * len - Length of message. * cb - NETLINK callback entry * * Returns: 0 - Success * <0 - Failure * */ IP_GLOBAL int ipnet_rtnetlink_route_dump_family(Ipnet_netlink_mem_t *mem, struct Ip_nlmsghdr *nlmsg, int family, Ip_ptrdiff_t *args) { Ipnet_rtnetlink_route_family_t param; Ip_ptrdiff_t *done = &args[0]; Ip_ptrdiff_t *s_vr = &args[1]; Ip_ptrdiff_t *s_table = &args[2]; Ip_ptrdiff_t *s_rtm = &args[3]; Ip_ptrdiff_t *s_continue = &args[4]; param.nlmsg = nlmsg; param.table = 0; param.family = family; param.mem = mem; if (*done) goto exit_out; param.state.aborted = 0; param.state.done = done; param.state.rt = s_rtm; param.state.table = s_table; param.state.vr = s_vr; param.state.cont = *s_continue; /* */ ipcom_hash_for_each(ipnet->rtabs, (Ipcom_hash_foreach_cb_func)ipnet_rtnetlink_route_foreach_vr_family, ¶m); /* Are we aborted? */ *s_continue = param.state.aborted; /* If not aborted; we're done */ if (!param.state.aborted) *done = 1; exit_out: return param.mem->used; }
/* *=========================================================================== * ipcom_sysvar_for_each *=========================================================================== * Description: * Parameters: * Returns: */ IP_PUBLIC Ip_err ipcom_sysvar_for_each(const char *name, Ipcom_sysvar_for_each cb_func, void *cookie) { Ipcom_sysvar_entry *sysvar; Ipcom_sysvar_tree *tree; Ip_size_t namelen = 0; Ip_err retval; Ipcom_pqueue *pq; retval = ipcom_once(&ipcom_sysvar_once, ipcom_sysvar_init, IP_NULL); if (retval != IPCOM_SUCCESS) return retval; if (name) { namelen = ipcom_strlen(name); if (name[namelen-1] == '*') namelen--; /* ignore trailing wildcard sign */ } pq = ipcom_pqueue_new((Ipcom_pqueue_cmp_func)ipcom_sysvar_pqueue_cmp, ipcom_pqueue_nop_store_index); if (pq == IP_NULL) return IPCOM_ERR_NO_MEMORY; IPCOM_CODE_LOCK(); tree = ipcom_sysvar_tree_get(-1); if (tree == IP_NULL) { ipcom_pqueue_delete(pq); IPCOM_CODE_UNLOCK(); return IPCOM_ERR_NO_MEMORY; } /* Add all sysvars to the priority queue so they can be extracted sorted in lexicographical order */ ipcom_hash_for_each(tree->sysvars, (Ipcom_hash_foreach_cb_func)ipcom_sysvar_pqueue_insert_cb, pq); while (IP_NULL != (sysvar = ipcom_pqueue_remove_next(pq))) { if (name == IP_NULL || ipcom_strncmp(sysvar->name, name, namelen) == 0) { IPCOM_CODE_UNLOCK(); (void)cb_func(sysvar->name, sysvar->value, sysvar->flags, cookie); IPCOM_CODE_LOCK(); } ipcom_sysvar_release(tree, sysvar); } ipcom_pqueue_delete(pq); ipcom_sysvar_tree_done(tree); IPCOM_CODE_UNLOCK(); #ifdef IP_PORT_OSE5_DISABLED return ipcom_sysvar_for_each_ose5(name, cb_func, cookie); #else return IPCOM_SUCCESS; #endif }