/* *=========================================================================== * ipnet_cmd_qc_parse_bit_string *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ip_bool ipnet_cmd_qc_parse_bit_string(const char *bit_str, Ip_u32 *pattern, Ip_u8 *pattern_len) { char *ctx; char *bit; char *dup_bit_str = ipcom_strdup(bit_str); if (dup_bit_str == IP_NULL) { ipcom_printf("Failed to duplicate string '%s'"IP_LF, bit_str); return IP_FALSE; } *pattern = 0; *pattern_len = 0; bit = ipcom_strtok_r(dup_bit_str, ",", &ctx); if (bit == IP_NULL) { ipcom_free(dup_bit_str); ipcom_printf("Invalid format of the pattern, must be a comma separated list of 0 and 1"IP_LF); return IP_FALSE; } while (bit != IP_NULL) { if (ipcom_atoi(bit)) IP_BIT_SET(*pattern, 1 << *pattern_len); ++*pattern_len; bit = ipcom_strtok_r(IP_NULL, ",", &ctx); } ipcom_free(dup_bit_str); return IP_TRUE; }
/**************************************************************************** * * example_do_command - Execute a DHCPS command * * This routine execute a DHCPS command containing the parameters we're * interested in adding to the configuration. * * .IP <format> * The format string * * .IP <...> * The arguments for the format string * * RETURNS: * N/A * * NOMANUAL */ IP_STATIC void example_do_command(const char *format, ...) { va_list vargs; char *cmd; int argc; char **argv = IP_NULL; if ((cmd = ipcom_malloc(256)) != IP_NULL) { va_start(vargs, format); ipcom_vsnprintf(cmd, 256, format, vargs); va_end(vargs); IPCOM_LOG1(INFO,"DHCP Executing '%s'", cmd); if(ipcom_parse_argstr(cmd, (int*)&argc, &argv) != IPCOM_SUCCESS) { IPCOM_LOG1(ERR,"failed to parse command '%s'", cmd); goto out; } if(ipdhcps_cmd_dhcps(argc, argv) != IPCOM_SUCCESS) { IPCOM_LOG1(ERR,"failed to execute command '%s'", cmd); goto out; } out: if (argv != IP_NULL) ipcom_free(argv); if (cmd) ipcom_free(cmd); } }
/* *=========================================================================== * ipcom_shellalias_remove *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC int ipcom_shellalias_remove(const char *name) { struct Ipcom_shellalias_alias *alias = ipcom_shellalias_find(name); /* We did locate it */ if (alias != IP_NULL) { /* Remove it from the list */ ipcom_list_remove(&alias->next); /* Free any allocated name */ ipcom_free(alias->name); /* Free the command */ ipcom_free(alias->cmd); /* Kill the vector */ ipcom_free(alias->argv); /* Free the structure */ ipcom_free(alias); /* Found it */ return IPCOM_SUCCESS; } /* No such entry */ return -IP_ERRNO_ENOENT; }
/* *=========================================================================== * ipcom_buffer_free *=========================================================================== * Description: Frees any memory used for the buffer. * Parameters: * Returns: * */ IP_PUBLIC void ipcom_buffer_free(Ipcom_buffer *buffer) { #ifdef IP_DEBUG ipcom_memset(buffer->buf, 0xdd, buffer->alloc); #endif ip_assert( buffer->buf && buffer ); ipcom_free(buffer->buf); ipcom_free(buffer); }
/* *=========================================================================== * netsysctlname2oid *=========================================================================== * Description: * Parameters: ctl - * name - * pNewName - * nameLen - * Returns: * */ IP_PUBLIC int netsysctlname2oid(Ipnet_cmd_sysctl *ctl, char* name, int* pNewName, int* nameLen) { #ifdef IPCOM_USE_INET int i; if(ctl == IP_NULL) { ctl = ipnet_sysctl_inet_table; pNewName[(*nameLen)++] = IP_IPPROTO_IP; } /* if you want to support trunk node, pls change this function */ while (ctl->comp != IP_NULL) { if (IP_BIT_ISSET(ctl->argument, IPNET_CMD_SYSCTL_NETIF_NO)) { if (ipcom_strcasecmp(name, ctl->comp) == 0) { for (i = 0; ctl->ctl[i] != -1; i++); pNewName[(*nameLen)++] = ctl->ctl[i ? i-1 : i]; } } /* Do the netifs */ if (IP_BIT_ISSET(ctl->argument, IPNET_CMD_SYSCTL_NETIF_YES)) { /* Dump the arguments */ char **argv = ipnet_cmd_sysctl_dump_netif(); if (argv) { for (i = 0; argv[i] != IP_NULL; i++) { if(ipcom_strcasecmp(name, argv[i])==0) { name += ipcom_strlen(argv[i]) + 1; pNewName[(*nameLen)++] = i; netsysctlname2oid(ipnet_sysctl_inet_table, name, pNewName, nameLen); } ipcom_free(argv[i]); } ipcom_free(argv); } } ctl++; } #endif return 0; }
IP_STATIC void ipcom_ifaddrs_free(struct Ip_ifaddrs *ifa) { if(ifa->ifa_name != IP_NULL) ipcom_free(ifa->ifa_name); if(ifa->ifa_addr != IP_NULL) ipcom_free(ifa->ifa_addr); if(ifa->ifa_netmask != IP_NULL) ipcom_free(ifa->ifa_netmask); if(ifa->ifa_broadaddr != IP_NULL) ipcom_free(ifa->ifa_broadaddr); ipcom_free(ifa); }
/* *=========================================================================== * ipdnsc_hostent_create *=========================================================================== * Description: Creates a hostent structure with empty alias and address * lists * Parameters: type - the type of hostent structure * Returns: pointer to the newly created hostent structure */ IP_GLOBAL struct Ip_hostent* ipdnsc_hostent_create(Ip_s32 type) { struct Ip_hostent *he; /* Allocate the host entry structure */ he = ipcom_malloc(sizeof(*he)); if (he == IP_NULL) { return IP_NULL; } ipcom_memset(he, 0, sizeof(*he)); /* Set the type and length fields */ he->h_addrtype = type; if (type == IP_AF_INET) { he->h_length = IPDNSC_INADDRSZ; } else if (type == IP_AF_INET6) { he->h_length = IPDNSC_IN6ADDRSZ; } else { ipcom_free(he); return IP_NULL; } /* Allocate memory for the alias list */ he->h_aliases = ipcom_malloc(sizeof(char *)); if (he->h_aliases == IP_NULL) { ipcom_free(he); return IP_NULL; } he->h_aliases[0] = IP_NULL; /* Allocate memory for the address list */ he->h_addr_list = ipcom_malloc(sizeof(char *)); if (he->h_addr_list == IP_NULL) { ipcom_free(he->h_aliases); ipcom_free(he); return IP_NULL; } he->h_addr_list[0] = IP_NULL; return he; }
/* *=========================================================================== * ipdnsc_hostent_insert_name *=========================================================================== * Description: Inserts a host name in a hostent structure * Parameters: he - pointer to the hostent structure * name - the name to insert * Returns: 0 for OK, -1 for fail. */ IP_GLOBAL Ip_s32 ipdnsc_hostent_insert_name(struct Ip_hostent *he, char *name) { if (he == IP_NULL) return -1; if (ipcom_strlen(name) > (IPDNSC_MAXNAME-1)) return -1; /* Free the memory for the current name if any */ if (he != IP_NULL && he->h_name != IP_NULL) { ipcom_free(he->h_name); } /* Allocate storage for the host name */ he->h_name = ipcom_malloc(ipcom_strlen(name)+1); if (he->h_name == IP_NULL) { return -1; } /* Copy the host name */ ipcom_strcpy(he->h_name, name); return 0; }
/* *=========================================================================== * ipnet_if_mib_handler_ifNumber *=========================================================================== * Description: MIB handler for ifNumber * Parameters: See file 'ipsnmp.h' * Returns: IPSNMP_ERROR_XXX * */ IP_STATIC Ip_s32 ipnet_if_mib_handler_ifNumber(Ip_s32 cmd, char *id, Ipsnmp_varbind *vb, Ip_s32 magic, struct Ipsnmp_node_object *nodeobj) { Ip_s32 ret = -1, ifNumber = 0; char *iid; (void)id; (void)vb; if (cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT) { iid = ipsnmp_create_iid_integer(nodeobj->id, 0); if (iid == IP_NULL) return IPSNMP_ERROR_GENERROR; ifNumber = IPNET_NETIF_NUM_ATTACHED; ret = (Ip_s32) ipsnmp_util_put_integer(magic, iid, ifNumber); ipcom_free(iid); } return ret; }
/****************************************************************************** * * ipdhcps_example_start_hook - example dhcps startup callback routine * * This is an example implementation of the callback routine that is called * by the DHCP server startup. * * RETURNS: * 0 if success or -1 if failure * * NOMANUAL */ IP_GLOBAL int ipdhcps_example_start_hook (void) { #ifdef IPDHCPS_USE_EXAMPLE /* Restore lease database */ example_restore_lease_db (); ipcom_tmo_request (&lease_dump_tmo, example_lease_dump_tmo_func, &lease_dump_tmo, 10*60*60*1000); #endif /* IPDHCPS_USE_EXAMPLE */ #if defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE) { char *cfgfile = ipcom_sysvar_get("ipdhcps.iscfile", IP_NULL, IP_NULL); if (cfgfile) { ret = example_isc_config(cfgfile); ipcom_free(cfgfile); } } #endif return 0; }
/**************************************************************************** * * example_restore_lease_db - restore DHCP Server lease database * * This is an example on how the contents of the IPDHCPS lease database can * be restored by initializing it with data stored in a file system. * * RETURNS: * 0 if success, -1 if failed. * * NOMANUAL */ IP_STATIC int example_restore_lease_db(void) { int retval = -1; IP_FILE *fd = IP_NULL; struct Ip_stat statbuf; void *buf = IP_NULL; if(ipcom_stat("/home/jonas/dumpfile", &statbuf) == -1) goto leave; if((fd = ipcom_fopen("/home/jonas/dumpfile", "r")) == 0) goto leave; if((buf = ipcom_malloc(statbuf.st_size)) == IP_NULL) goto leave; if(ipcom_fread(buf, statbuf.st_size, 1, fd) <= 0) goto leave; ipdhcps_lease_db_restore(buf); retval = 0; leave: if(fd) ipcom_fclose(fd); if(buf != IP_NULL) ipcom_free(buf); return retval; }
/* *=========================================================================== * 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; }
/**************************************************************************** * * example_dump_lease_db - dump DHCP server lease database * * This is an example on how to save the current contents of the IPDHCPS * lease database to a file system. The routine is adapted for a UNIX file * system. * * RETURNS: * 0 if success or -1 if failure * * NOMANUAL */ IP_STATIC int example_dump_lease_db(void) { int retval = -1; void *buf = IP_NULL; IP_FILE *fd = IP_NULL; int n; if((n = ipdhcps_lease_db_dump(&buf)) < 0) goto leave; if((fd = ipcom_fopen("/home/jonas/dumpfile","w+")) == 0) goto leave; if((ipcom_fwrite(buf, n, 1, fd)) <= 0) goto leave; retval = 0; leave: if(fd) ipcom_fclose(fd); if(buf != IP_NULL) ipcom_free(buf); return retval; }
/* *=========================================================================== * ipcom_sysvar_release *=========================================================================== * Description: * Parameters: * Returns: */ IP_STATIC void ipcom_sysvar_free(Ipcom_sysvar_entry *sysvar, Ipcom_sysvar_tree *tree) { /* Remove the sys entry */ ipcom_hash_remove(tree->sysvars, sysvar); ipcom_free(sysvar); }
/* *=========================================================================== * ipcom_buffer_new *=========================================================================== * Description: * Parameters: * Returns: * */ Ipcom_buffer* ipcom_buffer_new(Ip_s32 size) { Ipcom_buffer *buffer; buffer = ipcom_malloc(sizeof(Ipcom_buffer)); if(!buffer) { IPCOM_LOG0(ERR, "ipcom_buffer_new() :: out of memory"); return IP_NULL; } buffer->buf = ipcom_malloc(size); if(buffer->buf == IP_NULL) { IPCOM_LOG0(ERR, "ipcom_buffer_new() :: out of memory"); ipcom_free(buffer); return IP_NULL; } buffer->alloc = size; buffer->offset = 0; buffer->end = 0; #ifdef IP_DEBUG ipcom_memset(buffer->buf, 0xcc, size); #endif return buffer; }
/* *=========================================================================== * ipnet_nat_proxy_dns_remove_transaction *=========================================================================== * Description: Remove a transaction from the list. * Parameters: trans - pointer to the transaction. * Returns: nothing. */ IP_STATIC void ipnet_nat_proxy_dns_remove_transaction(Ipnet_nat_dns_transaction *trans) { ipnet_nat_proxy_timeout_cancel(trans->tmo); ipcom_list_remove(&trans->list); ipcom_free(trans); }
/***************************************************************************** * * example_concatenate_tokens - Concatenate all options on this line * * .IP <tok> * The tokenizer buffer * * RETURNS: * A dynamically allocated memory buffer containing all the tokenized options * on success, IP_NULL otherwise. * * NOMANUAL */ IP_STATIC char * example_concatenate_tokens(example_token_buffer_t *tok) { char *value; char *conc = ipcom_malloc(256); if (conc != IP_NULL) { int no_values = 0; conc[0] = '\0'; while ((value = example_get_token(tok, IP_FALSE)) != IP_NULL) { if (ipcom_strcasecmp(value, ";") == 0) break; no_values++; ipcom_strncat(conc, value, 256); ipcom_strncat(conc, " ", 256); } /* No semicolon or no values */ if (no_values == 0 || value == IP_NULL) { ipcom_free(conc); return IP_NULL; } return conc; } return IP_NULL; }
/* *=========================================================================== * 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; }
/* *=========================================================================== * 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; }
/* *=========================================================================== * ipdnsc_hostent_insert_alias *=========================================================================== * Description: Inserts an alias name in a hostent structure * Parameters: he - pointer to the hostent structure * name - the name to insert * Returns: 0 for OK, -1 for fail. */ IP_GLOBAL Ip_s32 ipdnsc_hostent_insert_alias(struct Ip_hostent *he, char *name) { Ip_s32 num_alias, i=0; char **tmp; if (ipcom_strlen(name) > (IPDNSC_MAXNAME-1)) return -1; /* Find out the current number of aliases */ num_alias = ipdnsc_hostent_alias_count(he); /* Allocate memory for the another alias list entry */ tmp = ipcom_realloc(he->h_aliases, (num_alias+1) * sizeof(char *)); if(tmp == IP_NULL) return -1; he->h_aliases = tmp; /* Allocate memory for the alias */ he->h_aliases[num_alias-1] = ipcom_malloc(ipcom_strlen(name)+1); if (he->h_aliases[num_alias-1] == IP_NULL) { /* We have to free to whole list here */ while (he->h_aliases[i] != IP_NULL) { ipcom_free(he->h_aliases[i]); i++; } /* Free the alias list */ ipcom_free(he->h_aliases); he->h_aliases = IP_NULL; return -1; } /* Set the alias */ ipcom_strcpy(he->h_aliases[num_alias-1], name); /* Null terminate the list */ he->h_aliases[num_alias] = IP_NULL; return 0; }
/* *=========================================================================== * ipcom_sysvar_release *=========================================================================== * Description: * Parameters: * Returns: */ IP_STATIC void ipcom_sysvar_release(Ipcom_sysvar_tree *tree, Ipcom_sysvar_entry *sysvar) { if (--sysvar->refcount == 0) { tree->modified = IP_TRUE; ipcom_hash_remove(tree->sysvars, sysvar); ipcom_free(sysvar); } }
/* *=========================================================================== * ipnet_nat_proxy_dns_transaction_timeout *=========================================================================== * Description: Timeout handler for DNS transactions timeouts * Parameters: cookie - a cookie that is set when the timeout is added. * Returns: nothing. */ IP_STATIC void ipnet_nat_proxy_dns_transaction_timeout(void *cookie) { Ipnet_nat_dns_transaction *trans = cookie; IPCOM_LOG4(DEBUG, "ipnet_nat_proxy_dns_transaction_timeout() :: expired transaction:" "id=%d port=%d addr=0x%08x type=%d", trans->id, trans->srcport, trans->dstaddr, trans->type); ipcom_list_remove(&trans->list); ipcom_free(trans); }
/* *=========================================================================== * ipnet_pkt_queue_mbc_destroy *=========================================================================== * Description: Frees all contained queues. * Parameters: q - A MBC based queue. * Returns: * */ IP_STATIC void ipnet_pkt_queue_mbc_destroy(Ipnet_pkt_queue_mbc *q) { Ip_u32 band; for (band = 0; band < q->number_of_bands; band++) ipnet_pkt_queue_delete(q->bands[band]); ipcom_free(q->bands); if (q->classifier) ipnet_classifier_delete(q->classifier); }
/* *=========================================================================== * ipdnsc_hostent_insert_addr *=========================================================================== * Description: Inserts an address in a hostent structure * Parameters: he - pointer to the hostent structure * addr - the addr to insert * Returns: 0 for OK, -1 for fail. */ IP_GLOBAL Ip_s32 ipdnsc_hostent_insert_addr(struct Ip_hostent *he, char *addr) { Ip_s32 num_addr, i=0; char **tmp; /* Find out the current number of addresses */ num_addr = ipdnsc_hostent_addr_count(he); /* Allocate memory for the another address list entry */ tmp = ipcom_realloc(he->h_addr_list, (num_addr+1) * sizeof(char *)); if(tmp == IP_NULL) return -1; he->h_addr_list = tmp; /* Allocate memory for the address */ he->h_addr_list[num_addr-1] = ipcom_malloc(he->h_length); if (he->h_addr_list[num_addr-1] == IP_NULL) { /* We have to free to whole list here */ while (he->h_addr_list[i] != IP_NULL) { ipcom_free(he->h_addr_list[i]); i++; } /* Free the address list */ ipcom_free(he->h_addr_list); he->h_addr_list = IP_NULL; return -1; } /* Set the address */ ipcom_memcpy(he->h_addr_list[num_addr-1], addr, he->h_length); /* Null terminate the list */ he->h_addr_list[num_addr] = IP_NULL; return 0; }
/* *=========================================================================== * ipcom_minlock_delete *=========================================================================== * Description: * Parameters: * Returns: * */ IP_PUBLIC Ip_err ipcom_minlock_delete(Ipcom_spinlock *sl_handle) { #ifdef IPCOM_USE_SMP spinlockIsrNd_t *sl = (spinlockIsrNd_t*) *sl_handle; ipcom_free(sl); #endif *sl_handle = IPCOM_SPINLOCK_INVALID; return IPCOM_SUCCESS; }
ZBUF_ID zbufSockRecvfrom ( int s, /* socket to receive from */ int flags, /* flags to underlying protocols */ int * pLen, /* number of bytes requested/returned */ struct sockaddr *from, /* where to copy sender's addr */ int * pFromLen /* value/result length of <from> */ ) { ZBUF_ID zbufId; /* zbuf returned to user */ ZBUF_SEG zbufSeg = NULL; /* received zbuf chain */ int status; /* recvfrom() return status */ char* buf = NULL; int so_type; socklen_t optlen = sizeof(int); if (-1 == getsockopt(s, (int)SOL_SOCKET, (int)SO_TYPE, (char*)&so_type, (int*)&optlen)) return (ZBUF_ID)NULL; ZBUF_ID_CREATE(zbufId); /* create ID for recv data */ if (zbufId == (ZBUF_ID)NULL) return (ZBUF_ID)NULL; if (so_type == SOCK_DGRAM) { if((status = recvfrom(s, (char*)&zbufSeg, *pLen, flags | IP_MSG_ZBUF, from, pFromLen)) < 0) goto cleanup; } else { ip_assert(so_type == SOCK_STREAM); buf = ipcom_malloc(*pLen); if (buf == NULL) goto cleanup; if ((status = recvfrom(s, buf, *pLen, flags | IP_MSG_ZBUF, from, pFromLen)) < 0) goto cleanup; if ((zbufSeg = zbufInsertBuf(zbufId, NULL, 0, buf, status, simple_free, 0)) == NULL) goto cleanup; } ZBUF_SETSEG(zbufId, zbufSeg); *pLen = status; return zbufId; cleanup: if (zbufId) ZBUF_ID_DELETE_EMPTY(zbufId); if (buf) ipcom_free(buf); return (ZBUF_ID)NULL; }
/* *=========================================================================== * ipcom_spinlock_delete *=========================================================================== * Description: * Parameters: * Returns: * */ IP_PUBLIC Ip_err ipcom_spinlock_delete(Ipcom_spinlock *sl_handle) { #ifdef IPCOM_USE_SMP Ipcom_vxworks_spinlock_t *sl = (Ipcom_vxworks_spinlock_t*) *sl_handle; Ip_err ret; ret = semDelete(sl->sem); *sl_handle = IPCOM_SPINLOCK_INVALID; ipcom_free(sl); return (ret == OK) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED; #else *sl_handle = IPCOM_SPINLOCK_INVALID; return IPCOM_SUCCESS; #endif }
/* *=========================================================================== * ipcom_shell_remove_cmd *=========================================================================== * Description: Remove a command from the list of available ipcom_shell commands * Parameters: name : the command to remove * Returns: IPCOM_SUCCESS : ok * IPCOM_ERR_NOT_FOUND : the command does not exist * */ IP_PUBLIC Ip_err ipcom_shell_remove_cmd(const char *name, Ipcom_shell_cmd_type hook) { Ipcom_shell_cmd *cmd; (void)hook; /* First check if present */ cmd = ipcom_shell_find_cmd(name); if (cmd == IP_NULL) return IPCOM_ERR_NOT_FOUND; ipcom_list_remove(&cmd->cmd_list); ipcom_free(cmd); return IPCOM_SUCCESS; }
/* *=========================================================================== * ipnet_config_run_boot_cmd *=========================================================================== * Description: Configures one route entry. * Parameters: * Returns: * */ IP_STATIC int ipnet_config_run_boot_cmd(const char *conf) { char *option_org; char *option; char *argv[20]; char *arg; int argc = 0; int ret = -IP_ERRNO_EINVAL; option_org = option = ipcom_strdup(conf); if (option == IP_NULL) return -IP_ERRNO_ENOMEM; while (IP_NULL != (arg = ipcom_strtok_r(option, " \t", &option))) { if (argc == 1) argv[argc++] = "-silent"; argv[argc++] = arg; if (argc >= (int) (sizeof(argv) / sizeof(*argv))) { IPCOM_LOG1(ERR, "Too many arguments in command %s", conf); IP_PANIC(); } } argv[argc] = IP_NULL; if (argc > 2) { if (ipcom_strcmp(argv[0], "route") == 0) ret = ipnet_config_cmd_route(argc, argv); else if (ipcom_strcmp(argv[0], "ifconfig") == 0) ret = ipnet_config_cmd_ifconfig(argc, argv); else if (ipcom_strcmp(argv[0], "qc") == 0) ret = ipnet_config_cmd_qc(argc, argv); #if defined(IPNET_USE_NAT) && !defined(IP_PORT_LKM) && !defined(IP_PORT_VXWORKS) else if (ipcom_strcmp(argv[0], "nat") == 0) ret = ipnet_cmd_nat(argc, argv); #endif } ipcom_free(option_org); return ret; }
/* *=========================================================================== * ipnet_ip_forward_mib_handler_ipCidrRouteNumber *=========================================================================== * Description: MIB handler for ipCidrRouteNumber * Parameters: See file 'ipsnmp.h' * Returns: IPSNMP_ERROR_XXX * */ IP_STATIC Ip_s32 ipnet_ip_forward_mib_handler_ipCidrRouteNumber(Ip_s32 cmd, char *id, Ipsnmp_varbind *vb, Ip_s32 magic, struct Ipsnmp_node_object *nodeobj) { Ip_s32 ret = -1; Ip_u32 ipCidrRouteNumber; char *iid; Ipcom_route *rtab; (void)id; (void)vb; if (cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT) { iid = ipsnmp_create_iid_integer(nodeobj->id, 0); if (iid == IP_NULL) return IPSNMP_ERROR_GENERROR; if (ipnet_route_get_rtab(IP_AF_INET, 0, IPCOM_ROUTE_TABLE_DEFAULT, &rtab) < 0) return IPSNMP_ERROR_GENERROR; routewalk.cmd = cmd; routewalk.id = IP_NULL; routewalk.buf = IP_NULL; routewalk.best = IP_NULL; routewalk.bestrt = IP_NULL; routewalk.count_only = IP_TRUE; count = 0; /* For now handle only the default route table */ ipcom_route_walk_tree(rtab, (Ip_bool(*)(Ipcom_route_entry *, void *)) ipnet_ip_mib_cb_ipCidrRouteTable, &routewalk); ipCidrRouteNumber = count; ret = ipsnmp_util_put_gauge32(magic, iid, ipCidrRouteNumber); ipcom_free(iid); } return ret; }