コード例 #1
0
/*
 *===========================================================================
 *                    ipnet_gre_setup
 *===========================================================================
 * Description: Setup the GRE tunnel.
 * Parameters:  netif - A GRE tunnel interface.
 * Returns:     0 = success, <0 = error code.
 *
 */
IP_GLOBAL int
ipnet_gre_setup(Ipnet_netif *netif)
{
#ifdef IPNET_USE_RFC2890
    Ipnet_gre_t *gre;

    gre = netif->ipcom.pdrv = ipcom_calloc(1, sizeof(Ipnet_gre_t));
    if (gre == IP_NULL)
        goto errout;

    gre->reassembly_queue
        = ipcom_pqueue_new((Ipcom_pqueue_cmp_func) ipnet_gre_seq_cmp,
                           ipcom_pqueue_nop_store_index);

    return 0;
 errout:
    ipnet_gre_destroy(netif);
    IPCOM_LOG0(CRIT, "Failed to create GRE tunnel due to unsifficient memory");
    return -IP_ERRNO_ENOMEM;
#else
    IPCOM_UNUSED_ARG(netif);
    return 0;
#endif /* IPNET_USE_RFC2890 */
}
コード例 #2
0
ファイル: ipcom_sysvar.c プロジェクト: rgmabs19357/Huawei-
/*
 *===========================================================================
 *                    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
}