/* *=========================================================================== * ipcom_shell_add_cmd *=========================================================================== * Description: Add a command to the list of available ipcom_shell commands * Parameters: name : command's name * usage : usage string * description : description of command * hook : function to that executes the command * priority : na * stack_size : the stack to be used by the process that * executes the hook. * * Returns: IPCOM_SUCCESS : ok * IPCOM_ERR_DUPLICATE : command already exists * IPCOM_ERR_NO_MEMORY : out of memory * * */ IP_PUBLIC Ip_err ipcom_shell_add_cmd(const char *name, const char *usage, const char *description, Ipcom_shell_cmd_type hook, Ip_s32 priority, Ip_s32 stack_size) { Ipcom_shell_cmd *cmd; static Ipcom_once_t once = IPCOM_ONCE_INIT; Ip_err err; err = ipcom_once(&once, ipcom_shellcmd_init, IP_NULL); if (err != IPCOM_SUCCESS) return err; /* First check if present */ cmd = ipcom_shell_find_cmd(name); if (cmd != IP_NULL) return IPCOM_ERR_DUPLICATE; /*!!allow duplicates for overlay. */ /* Add a new entry to the list */ cmd = (Ipcom_shell_cmd *)ipcom_malloc(sizeof(Ipcom_shell_cmd)); if (cmd == IP_NULL) return IPCOM_ERR_NO_MEMORY; ipcom_memset(cmd, 0, sizeof(Ipcom_shell_cmd)); ipcom_strncpy(cmd->name, name, sizeof(cmd->name)-1); ipcom_strncpy(cmd->usage, usage, sizeof(cmd->usage)-1); ipcom_strncpy(cmd->description, description, sizeof(cmd->description)-1); cmd->hook = hook; if (priority == 0 || priority == IPCOM_SHELL_PRIO_SAME) cmd->priority = ipcom_proc_getprio(ipcom_getpid()); else cmd->priority = priority; cmd->stack_size = stack_size; ipcom_list_insert_last(&ipcom_shell_cmd_head, &cmd->cmd_list); #if defined(WRS_IPNET) && defined(IP_PORT_VXWORKS) && (IP_PORT_VXWORKS >= 65) (void)ipcom_vxshell_add_cmd(name, usage, description, hook, priority, stack_size); #endif return IPCOM_SUCCESS; }
IP_PUBLIC int ipcom_strerror_r(int errnum, char * buf, Ip_size_t buflen) { char * name; int n; if (buf == NULL) return -1; #if IP_PORT_VXWORKS >= 60 name = ipcom_strerror_int_vxworks(errnum); #else name = ipcom_strerror_int(errnum); #endif if (name) { ipcom_strncpy(buf, name, buflen); buf[buflen-1] = '\0'; n = ipcom_strlen(name); } else { #ifdef IP_PORT_VXWORKS n = ipcom_snprintf(buf, buflen, "errno = %#x", errnum); #else n = ipcom_snprintf(buf, buflen, "Unknown error: %d", 0xffff & errnum); #endif } return (n < buflen) ? 0 : IP_ERRNO_ERANGE; }
/* *=========================================================================== * ipnet_nat_proxy_dns_add_transaction *=========================================================================== * Description: Add a DNS transaction to the list of active transactions. * Parameters: type - DNS query type * dns_hdr - pointer to the DNS protocol header. * param - pointer to NAT proxy parameters. * Returns: pointer to the transaction or IP_NULL if failed to add. */ IP_STATIC Ipnet_nat_dns_transaction * ipnet_nat_proxy_dns_add_transaction(int type, Ipnet_nat_dns_hdr *dns_hdr, Ipnet_nat_proxy_param *param, Ip_u8 *ptrname) { Ipnet_nat_dns_transaction *trans; /* Check that there is room for another transaction */ if(ipnet_nat_proxy_dns_list.size >= IPNET_NAT_DNS_TRANS_MAX_ENTRIES) return IP_NULL; trans = ipcom_malloc(sizeof(*trans)); if (trans == IP_NULL) return IP_NULL; ipcom_memset(trans, 0, sizeof(*trans)); trans->id = (Ip_u16)IP_GET_NTOHS(&dns_hdr->id); trans->srcport = param->tuple.private_port; trans->dstaddr = param->tuple.public_addr; trans->type = type; if (ptrname != IP_NULL) ipcom_strncpy((char *)trans->ptrname, (char *)ptrname, sizeof(trans->ptrname)-1); ipcom_list_insert_last(&ipnet_nat_proxy_dns_list, &trans->list); /* Add the timeout */ if (ipnet_nat_proxy_timeout_schedule(IPNET_NAT_DNS_TRANS_TIMEOUT, ipnet_nat_proxy_dns_transaction_timeout, trans, &trans->tmo) < 0) { ipcom_list_remove(&trans->list); ipcom_free(trans); return IP_NULL; } return trans; }
/* *=========================================================================== * ipcom_drv_ppp_if_init *=========================================================================== * Description: * Parameters: * Returns: * */ IP_PUBLIC int ipcom_drv_ppp_if_init(const char *ifname, const char *devname, int unit) { Ipcom_netif *netif; Ipcom_pdrv_ppp *pdrv; Ipcom_drv_ppp_link *plink; /* Allocate memory for the network interface structure */ netif = ipcom_if_malloc(IP_IFT_PPP); if (netif == IP_NULL) return IPCOM_ERR_FAILED; /* Set up the driver downcall function pointers */ netif->drv_ioctl = ipcom_drv_ppp_ioctl; netif->drv_output = ipcom_drv_ppp_output; /* Set interface name */ ipcom_strncpy(netif->name, ifname, sizeof(netif->name) - 1); /* Allocate and init memory for the driver structure */ pdrv = ipcom_malloc(sizeof(*pdrv)); if (pdrv == IP_NULL) goto fail; ipcom_memset(pdrv, 0, sizeof(*pdrv)); netif->pdrv = pdrv; plink = &pdrv->plink[unit]; if (devname == IP_NULL) { char value[64]; Ip_size_t value_size = sizeof(value); devname = ipcom_sysvar_get_conf("devname", value, &value_size, IP_NULL, ifname); } if (devname != IP_NULL) plink->devname = ipcom_strdup(devname); plink->sv[0] = plink->sv[1] = -1; /* Initialize PPP link */ plink->index = unit; plink->netif = netif; plink->out_q_nr = 0; plink->fd = -1; plink->baudrate = ipcom_sysvar_get_conf_as_int("ipppp.baudrate", IP_NULL, netif->name); if (plink->baudrate <= 0) plink->baudrate = IPCOM_DRV_PPP_BAUDRATE; /* Attach the interface. */ if (ipcom_if_attach(netif) < 0) goto fail; /* Success. */ return IPCOM_SUCCESS; fail: if (pdrv != IP_NULL) ipcom_free(pdrv); ipcom_if_free(netif); return IPCOM_ERR_FAILED; }
/* *=========================================================================== * ipcom_getenv *=========================================================================== * Description: * Parameters: * Returns: * */ IP_PUBLIC char * ipcom_getenv(const char *name) { #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM Ip_err retval; Ipcom_proc *proc; Ipcom_env_entry *env; char *value = IP_NULL; proc = ipcom_proc_self(); ip_assert(proc != IP_NULL); retval = ipcom_once(&proc->env_once, ipcom_env_init, proc); if (retval != IPCOM_SUCCESS) { IP_PANIC(); return IP_NULL; } ipcom_mutex_lock(proc->env_mutex); env = ipcom_hash_get(proc->env_tree, name); if (env != IP_NULL) value = (char *)env->value; ipcom_mutex_unlock(proc->env_mutex); return value; #elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && (defined(IP_PORT_OSE) || defined(IP_PORT_OSE5)) char *env; static char buf[256]; env = get_env(current_process(), name); if (env != IP_NULL) { ipcom_strncpy(buf, env, sizeof(buf)); free_buf((union SIGNAL **)&env); return (char *)buf; } return IP_NULL; #elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE return getenv(name); #elif defined(IPCOM_USE_SYSVAR) && IPCOM_VR_MAX == 1 static char buf[256]; Ip_size_t buf_size = sizeof(buf); return ipcom_sysvar_get(name, buf, &buf_size); #else return IP_NULL; #endif /* #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM */ }
/* *=========================================================================== * ipcom_drv_ppp_create_cb *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC int ipcom_drv_ppp_create_cb(const char *name, const char *value, int flags, void *cookie) { char ifname[IP_IFNAMSIZ]; char *strptr; (void)flags; (void)cookie; if (ipcom_strstr(name, ".devname") == IP_NULL) return 0; /* Copy out interface name */ ipcom_strncpy(ifname, name + 9, sizeof(ifname) - 1); strptr = ipcom_strchr(ifname, '.'); if (strptr == IP_NULL) return 0; *strptr = '\0'; /* Initialize PPP interface */ (void)ipcom_drv_ppp_if_init(ifname, value, 0); return 0; }