Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[preview] disable offloading v5 #2162

Closed
wants to merge 9 commits into from
11 changes: 8 additions & 3 deletions src/runmode-af-packet.c
Expand Up @@ -427,10 +427,15 @@ void *ParseAFPConfig(const char *iface)
switch (ltype) {
case LINKTYPE_ETHERNET:
/* af-packet can handle csum offloading */
if (GetIfaceOffloading(iface, 0, 1) == 1) {
SCLogWarning(SC_ERR_AFP_CREATE,
"Using AF_PACKET with offloading activated leads to capture problems");
if (LiveGetOffload() == 0) {
if (GetIfaceOffloading(iface, 0, 1) == 1) {
SCLogWarning(SC_ERR_AFP_CREATE,
"Using AF_PACKET with offloading activated leads to capture problems");
}
} else {
DisableIfaceOffloading(LiveGetDevice(iface), 0, 1);
}
break;
case -1:
default:
break;
Expand Down
7 changes: 7 additions & 0 deletions src/runmode-netmap.c
Expand Up @@ -207,6 +207,13 @@ static int ParseNetmapSettings(NetmapIfaceSettings *ns, const char *iface,
ns->threads = 1;
}

/* netmap needs all offloading to be disabled */
if (LiveGetOffload() == 0) {
(void)GetIfaceOffloading(ns->iface, 1, 1);
} else {
DisableIfaceOffloading(LiveGetDevice(ns->iface), 1, 1);
}

return 0;
}

Expand Down
3 changes: 0 additions & 3 deletions src/source-netmap.c
Expand Up @@ -293,9 +293,6 @@ static int NetmapOpen(char *ifname, int promisc, NetmapDevice **pdevice, int ver
}
}

/* netmap needs all offloading to be disabled */
(void)GetIfaceOffloading(ifname, 1, 1);

/* not found, create new record */
pdev = SCMalloc(sizeof(*pdev));
if (unlikely(pdev == NULL)) {
Expand Down
6 changes: 6 additions & 0 deletions src/source-pcap.c
Expand Up @@ -395,6 +395,12 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data)

SCLogInfo("using interface %s", (char *)pcapconfig->iface);

if (LiveGetOffload() == 0) {
(void)GetIfaceOffloading((char *)pcapconfig->iface, 1, 1);
} else {
DisableIfaceOffloading(ptv->livedev, 1, 1);
}

ptv->checksum_mode = pcapconfig->checksum_mode;
if (ptv->checksum_mode == CHECKSUM_VALIDATION_AUTO) {
SCLogInfo("Running in 'auto' checksum mode. Detection of interface state will require "
Expand Down
23 changes: 22 additions & 1 deletion src/util-device.c
Expand Up @@ -18,6 +18,7 @@
#include "suricata-common.h"
#include "conf.h"
#include "util-device.h"
#include "util-ioctl.h"

#define MAX_DEVNAME 10

Expand All @@ -39,6 +40,23 @@ static int live_devices_stats = 1;
static int LiveSafeDeviceName(const char *devname,
char *newdevname, size_t destlen);

static int g_live_devices_disable_offloading = 1;

void LiveSetOffloadDisable(void)
{
g_live_devices_disable_offloading = 1;
}

void LiveSetOffloadWarn(void)
{
g_live_devices_disable_offloading = 0;
}

int LiveGetOffload(void)
{
return g_live_devices_disable_offloading;
}

/**
* \brief Add a pcap device for monitoring
*
Expand All @@ -49,7 +67,7 @@ static int LiveSafeDeviceName(const char *devname,
*/
int LiveRegisterDevice(const char *dev)
{
LiveDevice *pd = SCMalloc(sizeof(LiveDevice));
LiveDevice *pd = SCCalloc(1, sizeof(LiveDevice));
if (unlikely(pd == NULL)) {
return -1;
}
Expand Down Expand Up @@ -264,6 +282,9 @@ int LiveDeviceListClean()
100 * (SC_ATOMIC_GET(pd->drop) * 1.0) / SC_ATOMIC_GET(pd->pkts),
SC_ATOMIC_GET(pd->invalid_checksums));
}

RestoreIfaceOffloading(pd);

if (pd->dev)
SCFree(pd->dev);
SC_ATOMIC_DESTROY(pd->pkts);
Expand Down
16 changes: 15 additions & 1 deletion src/util-device.h
Expand Up @@ -21,6 +21,19 @@
#include "queue.h"
#include "unix-manager.h"

#define OFFLOAD_FLAG_SG (1<<0)
#define OFFLOAD_FLAG_TSO (1<<1)
#define OFFLOAD_FLAG_GSO (1<<2)
#define OFFLOAD_FLAG_GRO (1<<3)
#define OFFLOAD_FLAG_LRO (1<<4)
#define OFFLOAD_FLAG_RXCSUM (1<<5)
#define OFFLOAD_FLAG_TXCSUM (1<<6)
#define OFFLOAD_FLAG_TOE (1<<7)

void LiveSetOffloadDisable(void);
void LiveSetOffloadWarn(void);
int LiveGetOffload(void);

#define MAX_DEVNAME 10

/** storage for live device names */
Expand All @@ -32,8 +45,9 @@ typedef struct LiveDevice_ {
SC_ATOMIC_DECLARE(uint64_t, drop);
SC_ATOMIC_DECLARE(uint64_t, invalid_checksums);
TAILQ_ENTRY(LiveDevice_) next;
} LiveDevice;

uint32_t offload_orig; /**< original offload settings to restore @exit */
} LiveDevice;

int LiveRegisterDevice(const char *dev);
int LiveGetDeviceCount(void);
Expand Down