From: Victor Julien Date: Fri, 5 Nov 2021 12:50:18 +0000 (+0100) Subject: af-packet: only ref mpeer if needed in tpacket v2 X-Git-Tag: suricata-7.0.0-beta1~1161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a5b945c7be94c48532826b8d6ae6bfe799c067b;p=thirdparty%2Fsuricata.git af-packet: only ref mpeer if needed in tpacket v2 We only use it in autofp mode, for reference counting purposes. Removes 2 atomic operations per packet in the more common workers runmode. --- diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index c6d79966df..ac0b570a9b 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -679,6 +679,7 @@ finalize: if (active_runmode == NULL || strcmp("workers", active_runmode) != 0) { /* If we are using copy mode we need a lock */ aconf->flags |= AFP_SOCK_PROTECT; + aconf->flags |= AFP_NEED_PEER; } return aconf; } diff --git a/src/source-af-packet.c b/src/source-af-packet.c index eec02309bb..810c7cc072 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -779,8 +779,12 @@ static void AFPReadFromRingSetupPacket( p->ReleasePacket = AFPReleasePacket; p->afp_v.relptr = h.raw; - p->afp_v.mpeer = ptv->mpeer; - AFPRefSocket(ptv->mpeer); + if (ptv->flags & AFP_NEED_PEER) { + p->afp_v.mpeer = ptv->mpeer; + AFPRefSocket(ptv->mpeer); + } else { + p->afp_v.mpeer = NULL; + } p->afp_v.copy_mode = ptv->copy_mode; p->afp_v.peer = (p->afp_v.copy_mode == AFP_COPY_MODE_NONE) ? NULL : ptv->mpeer->peer; diff --git a/src/source-af-packet.h b/src/source-af-packet.h index e976b30650..de25ff2442 100644 --- a/src/source-af-packet.h +++ b/src/source-af-packet.h @@ -55,7 +55,7 @@ struct ebpf_timeout_config { #endif /* value for flags */ -// (1<<0) vacant +#define AFP_NEED_PEER (1 << 0) // (1<<1) vacant #define AFP_SOCK_PROTECT (1<<2) #define AFP_EMERGENCY_MODE (1<<3)