This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/titan.TestPorts.AF_PACKET/+/21664 )
Change subject: guard against race between socket(AF_PACKET) and bind()
......................................................................
guard against race between socket(AF_PACKET) and bind()
An AF_PACKET socket will immediately receive packets of _all_ interfaces
until it is bound to one specific interface. This introduces a race
condition between the socket() and the bind() syscall.
Let's use the ifindex passed for each packet in recvmsg() to drop
any packets received for other interfaces.
Change-Id: Icd0b23eb1d6f75ca3a05e5dd1a569fa389903fdf
---
M src/AF_PACKET_PT.cc
1 file changed, 10 insertions(+), 1 deletion(-)
Approvals:
laforge: Looks good to me, approved; Verified
diff --git a/src/AF_PACKET_PT.cc b/src/AF_PACKET_PT.cc
index 3f46216..aa2def6 100644
--- a/src/AF_PACKET_PT.cc
+++ b/src/AF_PACKET_PT.cc
@@ -118,14 +118,23 @@
return;
if (is_readable) {
+ struct sockaddr_ll sll;
+ socklen_t sll_len = sizeof(sll);
int rc;
- rc = read(fd, mRxBuf, sizeof(mRxBuf));
+ rc = recvfrom(fd, mRxBuf, sizeof(mRxBuf), 0, (struct sockaddr *)&sll, &sll_len);
if (rc < 0)
TTCN_error("Error reading from socket: %s", strerror(errno));
if (rc == 0)
TTCN_error("Dead socket: %s", strerror(errno));
+ /* ignore any packets that we might have received for a different interface, between
+ * the socket() and the bind() call */
+ if (sll.sll_ifindex != mIfindex)
+ return;
+
+ /* TODO: report the other meta-data fields like sll_pkttype via the port */
+
incoming_message(AF__PACKET__Unitdata(OCTETSTRING(rc, mRxBuf)));
}
}
--
To view, visit https://gerrit.osmocom.org/c/titan.TestPorts.AF_PACKET/+/21664
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: titan.TestPorts.AF_PACKET
Gerrit-Branch: master
Gerrit-Change-Id: Icd0b23eb1d6f75ca3a05e5dd1a569fa389903fdf
Gerrit-Change-Number: 21664
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201210/84fd7ebe/attachment.htm>