From 4b97fd7e46e57622eb5345151479ac3ed9f568e4 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 27 Mar 2023 20:08:54 -0700 Subject: [PATCH] [ip6] combine `PassToHost()` calls in `Ip6::HandleDatagram()` (#8908) This commit simplifies `Ip6::HandleDatagram()` by combining the two places where we call `PassToHost()` into one. It simplifies how we perform the three actions `receive`, `forwardHost`, and `forwardThread`. --- src/core/net/ip6.cpp | 56 +++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index e94f2b876..b7e76998a 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1201,56 +1201,38 @@ start: } } - // Never forward reassembled frames as they were already delivered - // as fragments. - if (aIsReassembled) - { - forwardHost = false; - } - aMessage.SetOffset(sizeof(header)); // Process IPv6 Extension Headers nextHeader = static_cast(header.GetNextHeader()); SuccessOrExit(error = HandleExtensionHeaders(aMessage, aOrigin, messageInfo, header, nextHeader, receive)); - // Process IPv6 Payload - if (receive) + if (receive && (nextHeader == kProtoIp6)) { - if (nextHeader == kProtoIp6) - { - // Remove encapsulating header and start over. - aMessage.RemoveHeader(aMessage.GetOffset()); - Get().LogMessage(MeshForwarder::kMessageReceive, aMessage); - goto start; - } - - if (!aIsReassembled) - { - error = PassToHost(aMessage, aOrigin, messageInfo, nextHeader, - /* aApplyFilter */ !forwardHost, Message::kCopyToUse); - - if ((error == kErrorNone || error == kErrorNoRoute) && forwardHost) - { - forwardHost = false; - } - } - - error = HandlePayload(header, aMessage, messageInfo, nextHeader, - (forwardThread || forwardHost ? Message::kCopyToUse : Message::kTakeCustody)); - - // Need to free the message if we did not pass its - // ownership in the call to `HandlePayload()` - shouldFreeMessage = forwardThread || forwardHost; + // Remove encapsulating header and start over. + aMessage.RemoveHeader(aMessage.GetOffset()); + Get().LogMessage(MeshForwarder::kMessageReceive, aMessage); + goto start; } - if (forwardHost) + if ((forwardHost || receive) && !aIsReassembled) { - error = PassToHost(aMessage, aOrigin, messageInfo, nextHeader, /* aApplyFilter */ false, - forwardThread ? Message::kCopyToUse : Message::kTakeCustody); + error = PassToHost(aMessage, aOrigin, messageInfo, nextHeader, + /* aApplyFilter */ !forwardHost, + (receive || forwardThread) ? Message::kCopyToUse : Message::kTakeCustody); // Need to free the message if we did not pass its // ownership in the call to `PassToHost()` + shouldFreeMessage = (receive || forwardThread); + } + + if (receive) + { + error = HandlePayload(header, aMessage, messageInfo, nextHeader, + forwardThread ? Message::kCopyToUse : Message::kTakeCustody); + + // Need to free the message if we did not pass its + // ownership in the call to `HandlePayload()` shouldFreeMessage = forwardThread; }