Example #1
0
/**
 * Match against the Radix tree
 *
 * @param mpi provider instance
 * @param flags extra flags
 * @param data the data to search in
 * @param dlen length of the the data to search in
 * @param ctx it will be used to return user data
 *
 * @return status of the operation
 */
static ib_status_t modradix_match(ib_provider_inst_t *mpi,
                                 ib_flags_t flags,
                                 const uint8_t *data,
                                 size_t dlen,
                                 void *ctx)
{
    IB_FTRACE_INIT(modradix_match);
    ib_status_t rc;
    modradix_provider_data_t *dt = mpi->data;

    if (dt == NULL) {
        IB_FTRACE_RET_STATUS(IB_EINVAL);
    }

    ib_log_debug(mpi->pr->ib, 4, "Matching AGAINST Radix tree %x",
                     dt->radix_tree);

    ib_radix_t *radix_tree = dt->radix_tree;

    ib_radix_prefix_t *pre = NULL;

    rc = ib_radix_ip_to_prefix((const char *)data, &pre, mpi->mp); 

    if (rc != IB_OK) {
        IB_FTRACE_RET_STATUS(rc);
    }

    void *result = NULL;

    rc = ib_radix_match_closest(radix_tree, pre, &result);
    if (rc == IB_OK) {
        modradix_content_t *mrc = (modradix_content_t *)result;
        if (mrc->callback != NULL && mrc->data != NULL) {
            *(void **)ctx = result;
            IB_FTRACE_RET_STATUS(mrc->callback(mrc->data));
        }
        else if (mrc->data != NULL) {
            if (ctx!= NULL) {
                *(void **)ctx = result;
            }
            IB_FTRACE_RET_STATUS(IB_OK);
        }
        else {
            IB_FTRACE_RET_STATUS(IB_ENOENT);
        }
    }

    IB_FTRACE_RET_STATUS(rc);
}
Example #2
0
/**
 * Match against the BinRadix tree considering data as a binary IP address
 * This is the main difference with the other radix matcher (where data is
 * considered ascii)
 *
 * @param mpi provider instance
 * @param flags extra flags
 * @param data the data to search in
 * @param dlen length of the the data to search in
 *
 * @return status of the operation
 */
static ib_status_t modbinradix_match(ib_provider_inst_t *mpi,
                                 ib_flags_t flags,
                                 const uint8_t *data,
                                 size_t dlen,
                                 void *ctx)
{
    IB_FTRACE_INIT();
    ib_status_t rc;
    modbinradix_provider_data_t *dt = mpi->data;

    if (dt == NULL) {
        IB_FTRACE_RET_STATUS(IB_EINVAL);
    }

    ib_log_debug(mpi->pr->ib, "Matching AGAINST BinRadix tree %x",
                     dt->binradix_tree);

    ib_radix_t *binradix_tree = dt->binradix_tree;

    ib_radix_prefix_t *pre = NULL;

    /* Create the prefix directly. Data should be a binary ip address already */
    rc = ib_radix_prefix_create(&pre, (uint8_t *)data, (uint8_t)dlen * 8,
                                mpi->mp);
    if (rc != IB_OK) {
        IB_FTRACE_RET_STATUS(rc);
    }

    void *result = NULL;

    rc = ib_radix_match_closest(binradix_tree, pre, &result);
    if (rc == IB_OK) {
        modbinradix_content_t *mrc = (modbinradix_content_t *)result;
        if (mrc->callback != NULL && mrc->data != NULL) {
            *(void **)ctx = result;
            IB_FTRACE_RET_STATUS(mrc->callback(mrc->data));
        }
        else if (mrc->data != NULL) {
            *(void **)ctx = result;
            IB_FTRACE_RET_STATUS(IB_OK);
        }
        else {
            IB_FTRACE_RET_STATUS(IB_ENOENT);
        }
    }

    IB_FTRACE_RET_STATUS(rc);
}