Example #1
0
/*
 *  skplugin_err_t pmap_handle_filter_option(const char *opt_arg, void *cbdata)
 *
 *    Option handler for dynamically generated rwfilter options.
 */
static skplugin_err_t
pmap_handle_filter_option(
    const char         *opt_arg,
    void               *cbdata)
{
    directed_pmap_data_t *dir_data  = (directed_pmap_data_t *)cbdata;
    pmap_data_t          *pmap_data = dir_data->data;
    int                   new_filter;
    skplugin_callbacks_t  regdata;

    memset(&regdata, 0, sizeof(regdata));
    regdata.filter = pmap_filter_fn;

    if (ignore_prefix_map) {
        static int filter_registered = 0;

        /* register the filter but don't create the bitmap. we have to
         * register the filter in case this is the only filtering
         * option the user provided. */
        if (filter_registered) {
            return SKPLUGIN_OK;
        }

        return skpinRegFilter(NULL, &regdata, pmap_data);
    }

    /* If the source, dest, and any val_bitmaps are all null, this is
     * a new filter */
    new_filter = ((pmap_data->sdir.val_bitmap == NULL)
                  && (pmap_data->ddir.val_bitmap == NULL)
                  && (pmap_data->adir.val_bitmap == NULL));

    /* Add the arguments to the appropriate bitmap */
    if (pmapFilterSetupBitmap(&dir_data->val_bitmap, &dir_data->size_bitmap,
                              pmap_data->pmap, opt_arg, pmap_data->filepath))
    {
        return SKPLUGIN_ERR;
    }

    /* If this filter hasn't already been added, add it. */
    if (new_filter) {
        return skpinRegFilter(NULL, &regdata, pmap_data);
    }

    return SKPLUGIN_OK;
}
Example #2
0
/*
 *  status = optionsHandler(opt_arg, &index);
 *
 *    Handles options for the plugin.  'opt_arg' is the argument, or
 *    NULL if no argument was given.  'index' is the enum passed in
 *    when the option was registered.
 *
 *    Returns SKPLUGIN_OK on success, or SKPLUGIN_ERR if there was a
 *    problem.
 */
static skplugin_err_t
optionsHandler(
    const char         *opt_arg,
    void               *cbdata)
{
    skplugin_callbacks_t regdata;
    unsigned int opt_index = *((unsigned int*)cbdata);
    uint32_t opt_val;
    int rv;

    rv = skStringParseUint32(&opt_val, opt_arg, ADDRTYPE_NONROUTABLE,
                             ADDRTYPE_NONINTERNAL);
    if (rv != 0) {
        skAppPrintErr("Invalid %s '%s': %s",
                      plugin_options[opt_index].name, opt_arg,
                      skStringParseStrerror(rv));
        return SKPLUGIN_ERR;
    }

    switch (opt_index) {
      case ADDRTYPE_STYPE:
        if (stype != ADDRTYPE_UNSET) {
            skAppPrintErr("Invalid %s: Switch used multiple times",
                          plugin_options[opt_index].name);
            return SKPLUGIN_ERR;
        }
        stype = (addrtype_t)opt_val;
        break;

      case ADDRTYPE_DTYPE:
        if (dtype != ADDRTYPE_UNSET) {
            skAppPrintErr("Invalid %s: Switch used multiple times",
                          plugin_options[opt_index].name);
            return SKPLUGIN_ERR;
        }
        dtype = (addrtype_t)opt_val;
        break;

      default:
        return SKPLUGIN_ERR_FATAL;
    }

    memset(&regdata, 0, sizeof(regdata));
    regdata.init = addrtypeInit;
    regdata.cleanup = addrtypeCleanup;
    regdata.filter = addrtypeFilter;
    return skpinRegFilter(NULL, &regdata, cbdata);
}
Example #3
0
/* the registration function called by skplugin.c */
skplugin_err_t
SKPLUGIN_SETUP_FN(
    uint16_t            major_version,
    uint16_t            minor_version,
    void        UNUSED(*pi_data))
{
    skplugin_err_t rv;
    skplugin_callbacks_t regdata;

    /* Check API version */
    rv = skpinSimpleCheckVersion(major_version, minor_version,
                                 PLUGIN_API_VERSION_MAJOR,
                                 PLUGIN_API_VERSION_MINOR,
                                 skAppPrintErr);
    if (rv != SKPLUGIN_OK) {
        return rv;
    }

    /* Register the function to use for filtering */
    memset(&regdata, 0, sizeof(regdata));
    regdata.filter = check;
    return skpinRegFilter(NULL, &regdata, NULL);
}
Example #4
0
/*
 *  status = optionsHandler(opt_arg, &index);
 *
 *    Handles options for the plugin.  'opt_arg' is the argument, or
 *    NULL if no argument was given.  'index' is the enum passed in
 *    when the option was registered.
 *
 *    Returns SKPLUGIN_OK on success, or SKPLUGIN_ERR if there was a
 *    problem.
 */
static skplugin_err_t
optionsHandler(
    const char         *opt_arg,
    void               *cbdata)
{
    skplugin_callbacks_t regdata;
    plugin_options_enum opt_index = *((plugin_options_enum*)cbdata);
    static int filter_registered = 0;
    int rv;

    switch (opt_index) {
      case OPT_FLOWRATE_ZERO_DURATION:
        rv = skStringParseUint64(&zero_duration, opt_arg, 1, 0);
        if (rv) {
            goto PARSE_ERROR;
        }
        /* this argument is used by all applications; do not register
         * the plug-in as a filter */
        return SKPLUGIN_OK;

      case OPT_PAYLOAD_BYTES:
        rv = skStringParseRange64(&payload_bytes.min, &payload_bytes.max,
                                  opt_arg, 0, 0, SKUTILS_RANGE_SINGLE_OPEN);
        if (rv) {
            goto PARSE_ERROR;
        }
        payload_bytes.is_active = 1;
        break;

      case OPT_PAYLOAD_RATE:
        rv = skStringParseDoubleRange(&payload_rate.min, &payload_rate.max,
                                      opt_arg, 0.0, 0.0,
                                      SKUTILS_RANGE_SINGLE_OPEN);
        if (rv) {
            goto PARSE_ERROR;
        }
        payload_rate.is_active = 1;
        break;

      case OPT_PACKETS_PER_SECOND:
        rv = skStringParseDoubleRange(&pckt_rate.min, &pckt_rate.max,
                                      opt_arg, 0.0, 0.0,
                                      SKUTILS_RANGE_SINGLE_OPEN);
        if (rv) {
            goto PARSE_ERROR;
        }
        pckt_rate.is_active = 1;
        break;

      case OPT_BYTES_PER_SECOND:
        rv = skStringParseDoubleRange(&byte_rate.min, &byte_rate.max,
                                      opt_arg, 0.0, 0.0,
                                      SKUTILS_RANGE_SINGLE_OPEN);
        if (rv) {
            goto PARSE_ERROR;
        }
        byte_rate.is_active = 1;
        break;
    }

    if (filter_registered) {
        return SKPLUGIN_OK;
    }
    filter_registered = 1;

    memset(&regdata, 0, sizeof(regdata));
    regdata.filter = filter;
    return skpinRegFilter(NULL, &regdata, NULL);

  PARSE_ERROR:
    skAppPrintErr("Invalid %s '%s': %s",
                  plugin_options[opt_index].name, opt_arg,
                  skStringParseStrerror(rv));
    return SKPLUGIN_ERR;
}