File: opts.c

package info (click to toggle)
bpfilter 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,076 kB
  • sloc: ansic: 30,397; sh: 1,383; cpp: 959; python: 495; yacc: 385; lex: 194; makefile: 9
file content (52 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
 */

#include "opts.h"

#include <linux/limits.h>

#include <argp.h>

#include "core/helper.h"

static struct
{
    char bpfilter_path[PATH_MAX];
} _bf_opts = {
    .bpfilter_path = "bpfilter",
};

static struct argp_option _bf_e2e_options[] = {
    {"bpfilter", 'b', "BPFILTER", 0,
     "Path to the bpfilter daemon binary. Defaults to 'bpfilter' in PATH", 0},
    {0},
};

static error_t _bf_e2e_argp_cb(int key, char *arg, struct argp_state *state)
{
    UNUSED(state);

    switch (key) {
    case 'b':
        bf_strncpy(_bf_opts.bpfilter_path, PATH_MAX, arg);
        break;
    default:
        return ARGP_ERR_UNKNOWN;
    }

    return 0;
}

int bft_e2e_parse_args(int argc, char *argv[])
{
    struct argp argp = { _bf_e2e_options, _bf_e2e_argp_cb, NULL, NULL, 0, NULL, NULL};

    return -argp_parse(&argp, argc, argv, 0, 0, NULL);
}

const char *bft_e2e_bpfilter_path(void)
{
    return _bf_opts.bpfilter_path;
}