From: Eric Leblond Date: Sun, 10 Feb 2019 22:31:32 +0000 (+0100) Subject: af-packet: fix the start when XDP is pinned X-Git-Tag: suricata-5.0.0-rc1~377 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fdcb127e9a3aa97a49f82eb674576bb8adb8c9b;p=thirdparty%2Fsuricata.git af-packet: fix the start when XDP is pinned --- diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 59ccb82a8e..aadd65fe38 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -387,7 +387,8 @@ static void *ParseAFPConfig(const char *iface) } #ifdef HAVE_PACKET_EBPF - if (ConfGetChildValueBoolWithDefault(if_root, if_default, "pinned-maps", (int *)&boolval) != 1) { + boolval = false; + if (ConfGetChildValueBoolWithDefault(if_root, if_default, "pinned-maps", (int *)&boolval) == 1) { if (boolval) { SCLogConfig("Using pinned maps on iface %s", aconf->iface); @@ -514,35 +515,40 @@ static void *ParseAFPConfig(const char *iface) int ret = EBPFLoadFile(aconf->iface, aconf->xdp_filter_file, "xdp", &aconf->xdp_filter_fd, &aconf->ebpf_t_config); - if (ret != 0) { - SCLogWarning(SC_ERR_INVALID_VALUE, - "Error when loading XDP filter file"); - } else { - ret = EBPFSetupXDP(aconf->iface, aconf->xdp_filter_fd, aconf->xdp_mode); - if (ret != 0) { + switch (ret) { + case 1: + SCLogInfo("Loaded pinned maps from sysfs"); + break; + case -1: SCLogWarning(SC_ERR_INVALID_VALUE, - "Error when setting up XDP"); - } else { - /* Try to get the xdp-cpu-redirect key */ - const char *cpuset; - if (ConfGetChildValueWithDefault(if_root, if_default, - "xdp-cpu-redirect", &cpuset) == 1) { - SCLogConfig("Setting up CPU map XDP"); - ConfNode *node = ConfGetChildWithDefault(if_root, if_default, "xdp-cpu-redirect"); - if (node == NULL) { - SCLogError(SC_ERR_INVALID_VALUE, "Should not be there"); - } else { - EBPFBuildCPUSet(node, aconf->iface); - } + "Error when loading XDP filter file"); + break; + case 0: + ret = EBPFSetupXDP(aconf->iface, aconf->xdp_filter_fd, aconf->xdp_mode); + if (ret != 0) { + SCLogWarning(SC_ERR_INVALID_VALUE, + "Error when setting up XDP"); } else { + /* Try to get the xdp-cpu-redirect key */ + const char *cpuset; + if (ConfGetChildValueWithDefault(if_root, if_default, + "xdp-cpu-redirect", &cpuset) == 1) { + SCLogConfig("Setting up CPU map XDP"); + ConfNode *node = ConfGetChildWithDefault(if_root, if_default, "xdp-cpu-redirect"); + if (node == NULL) { + SCLogError(SC_ERR_INVALID_VALUE, "Should not be there"); + } else { + EBPFBuildCPUSet(node, aconf->iface); + } + } else { /* It will just set CPU count to 0 */ EBPFBuildCPUSet(NULL, aconf->iface); + } + } + /* we have a peer and we use bypass so we can set up XDP iface redirect */ + if (aconf->out_iface) { + EBPFSetPeerIface(aconf->iface, aconf->out_iface); } - } - /* we have a peer and we use bypass so we can set up XDP iface redirect */ - if (aconf->out_iface) { - EBPFSetPeerIface(aconf->iface, aconf->out_iface); - } } #else SCLogError(SC_ERR_UNIMPLEMENTED, "XDP support is not built-in");