Add support for offload/hardware mode.
This commit is contained in:
@@ -8,6 +8,7 @@ Additionally, if the host's NIC doesn't support XDP-native, the program will att
|
||||
The following command line arguments are supported:
|
||||
|
||||
* `--config -c` => Location to config file. Default => **/etc/xdpfw/xdpfw.conf**.
|
||||
* `--offload -o` => Tries to load the XDP program in hardware/offload mode.
|
||||
* `--list -l` => List all filtering rules scanned from config file.
|
||||
* `--help -h` => Print help menu for command line options.
|
||||
|
||||
|
||||
@@ -23,10 +23,12 @@
|
||||
static char *configFile;
|
||||
static int help = 0;
|
||||
static int list = 0;
|
||||
static int offload = 0;
|
||||
|
||||
const struct option opts[] =
|
||||
{
|
||||
{"config", required_argument, NULL, 'c'},
|
||||
{"offload", no_argument, &offload, 'o'},
|
||||
{"list", no_argument, &list, 'l'},
|
||||
{"help", no_argument, &help, 'h'},
|
||||
{NULL, 0, NULL, 0}
|
||||
@@ -55,6 +57,11 @@ void parse_command_line(int argc, char *argv[])
|
||||
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
offload = 1;
|
||||
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
list = 1;
|
||||
|
||||
@@ -193,6 +200,16 @@ static int xdp_attach(int ifindex, uint32_t *xdp_flags, int prog_fd)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (offload)
|
||||
{
|
||||
fprintf(stdout, "Trying to load in offload/hardware mode...\n");
|
||||
|
||||
*xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST | XDP_FLAGS_HW_MODE;
|
||||
|
||||
err = bpf_set_link_xdp_fd(ifindex, prog_fd, *xdp_flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = bpf_set_link_xdp_fd(ifindex, prog_fd, *xdp_flags);
|
||||
|
||||
if (err == -EEXIST && !(*xdp_flags & XDP_FLAGS_UPDATE_IF_NOEXIST))
|
||||
@@ -230,6 +247,7 @@ static int xdp_attach(int ifindex, uint32_t *xdp_flags, int prog_fd)
|
||||
|
||||
err = bpf_set_link_xdp_fd(ifindex, prog_fd, *xdp_flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (err < 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user