/*
 *===========================================================================
 *                     ipnet_timeout_to_string
 *===========================================================================
 * Description: Adds a element to string function for timeouts that uses
 *              the specified timeout handler.
 * Parameters:  handler - The timeout handler the element is using.
 *              to_str  - The to string handler for the element.
 * Returns:
 *
 */
IP_GLOBAL void
ipnet_timeout_to_string(Ipnet_timeout_handler handler,
                        Ipnet_timeout_to_string_f to_str)
{
    ipnet->tmo_map = ipcom_realloc(ipnet->tmo_map,
                                   ++ipnet->tmo_map_size * sizeof(*ipnet->tmo_map));
    ipnet->tmo_map[ipnet->tmo_map_size - 1].key         = handler;
    ipnet->tmo_map[ipnet->tmo_map_size - 1].to_str_func = to_str;
}
コード例 #2
0
/*
 *===========================================================================
 *                      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;
}
コード例 #3
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;

}
コード例 #4
0
/*
 *===========================================================================
 *                    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;

}
コード例 #5
0
ファイル: ipcom_buffer.c プロジェクト: rgmabs19357/Huawei-
/*
 *===========================================================================
 *                    ipcom_buffer_append_space
 *===========================================================================
 * Description: Appends space to the buffer, expanding the buffer if necessary.
 *              This does not actually copy the data into the buffer, but
 *              instead returns a pointer to the allocated region.
 * Parameters:
 * Returns:
 *
 */
IP_PUBLIC Ip_err
ipcom_buffer_append_space(Ipcom_buffer *buffer, Ip_u8 **datap, Ip_u32 len)
{
    /* If the buffer is empty, start using it from the beginning. */
    if (buffer->offset == buffer->end)
    {
        buffer->offset = 0;
        buffer->end = 0;
    }
restart:
    /* If there is enough space to store all data, store it now. */
    if (buffer->end + len <= buffer->alloc)
    {
        *datap = buffer->buf + buffer->end;
        buffer->end += len;
        return IPCOM_SUCCESS;
    }
    /*
    * If the buffer is quite empty, but all data is at the end, move the
    * data to the beginning and retry.
    */
    if (buffer->offset > buffer->alloc / 2)
    {
        ipcom_memmove(buffer->buf, buffer->buf + buffer->offset,
            buffer->end - buffer->offset);
        buffer->end -= buffer->offset;
        buffer->offset = 0;
        goto restart;
    }
    /* Increase the size of the buffer and retry. */
    buffer->alloc += buffer->alloc*2;
    buffer->buf = ipcom_realloc(buffer->buf, buffer->alloc);
    if( !buffer->buf )
        return IPCOM_ERR_FAILED;
    goto restart;
}