summaryrefslogtreecommitdiff
path: root/http/routing
AgeCommit message (Collapse)AuthorFilesLines
2026-04-29Make request non constEd Tanous6-13/+12
In preparation for allowing handlers to "steal" the input (thus saving memory), make the router pass a non-const Request down the pipeline. Tested: Redfish service validator passes. No functional changes. Change-Id: Ic2f44081bc7b6a0e4a82c6ac498eb040574e79be Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-10-03Fix the corrupted Trie routing treeMyung Bae1-6/+13
The routing table may potentially become corrupted during the routing table construction as the vector element pointer becomes invalid if the vector is resized [1]. http/routing/trie.hpp#L241: ``` ContainedType& node = nodes[idx]; size_t* param = &node.stringParamChild; if (str1 == "<path>") { param = &node.pathParamChild; } if (*param == 0U) { L249: *param = newNode(); // <--- } idx = *param; ``` Here, `newNodes()` at L249 may resize the vector of `nodes[]` and thus the reference of `nodes[idx]` becomes invalid and thus the previously saved the pointer of `param` is invalid. The similar issue is also at sub_route_trie construction [5]. This problem may be shown during CI/valgrind test depending on the order of route setups in [2]. For example, for the commit 39574 [3], if `requestsRoutesAssembly()` is added earlier than `requestRoutesProcessorCollection()`, it causes CI/valgrind test fails [3]. The error looks like [4]. [1] https://github.com/openbmc/bmcweb/blob/master/http/routing/trie.hpp#L241 [2] https://github.com/openbmc/bmcweb/blob/master/redfish-core/src/redfish.cpp [3] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/39574 [4] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/39574/comment/15e652e0_f8881ffc/ [5] https://github.com/openbmc/bmcweb/blob/master/redfish-core/include/sub_route_trie.hpp#L160 Tested: - CI with https://gerrit.openbmc.org/c/openbmc/bmcweb/+/39574 passes after rebase of having earlier `requestsRoutesAssembly()`. - Redfish Service Validator passes Change-Id: I349777dfab65f2d41eb5db25796d82322b3c36cc Signed-off-by: Myung Bae <myungbae@us.ibm.com>
2025-08-26Remove namespace in http layerEd Tanous3-12/+11
Within this namespace, we don't need to call crow, we are already in the crow namespace. Tested: Code compiles. Change-Id: Ida57624ef1157f98f2719b5c3af536aebaca601e Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-04-03OEM Route Handling Infrastructurerohitpai2-2/+3
Goal of the MR is to provide infrastructure support in bmcweb to manage the OEM fragment handling separately. OEM schema are vendor defined and per DMTF resource we could have multiple vendor defined OEM schema to be enabled. The feature allows registration of route handler per schema per OEM namespace. Example ``` REDFISH_SUB_ROUTE<"/redfish/v1/Managers/<str>/#/Oem/OpenBmc">(service, HttpVerb::Get)(oemOpenBmcCallback); REDFISH_SUB_ROUTE<"/redfish/v1/Managers/<str>/#/Oem/Nvidia">(service, HttpVerb::Get)(oemNidiaCallback); ``` We can have separate vendor defined route handlers per resource. Each of these route handlers can populate their own vendor specific OEM data. The OEM code can be better organized and enabled/disabled as per the platform needs. The current MR has the code changes related to handling GET requests alone. The feature only supports requests where the response payload is JSON. Tests - All UT cases passes - New UT added for RF OEM router passes - Service Validator passes on qemu - GET Response on Manager/bmc resource contains the OEM fragment ``` curl -c cjar -b cjar -k -X GET https://127.0.0.1:2443/redfish/v1/Managers/bmc { "@odata.id": "/redfish/v1/Managers/bmc", "@odata.type": "#Manager.v1_14_0.Manager", "Oem": { "OpenBmc": { "@odata.id": "/redfish/v1/Managers/bmc#/Oem/OpenBmc", "@odata.type": "#OpenBMCManager.v1_0_0.Manager", "Certificates": { "@odata.id": "/redfish/v1/Managers/bmc/Truststore/Certificates" } } }, "UUID": "40575e98-90d7-4c10-9eb5-8d8a7156c9b9" } ``` Change-Id: Ic82aa5fe760eda31e2792fbdfb6884ac3ea613dc Signed-off-by: Rohit PAI <rohitpai77@gmail.com>
2025-04-03Use Node as template parameter for creating TriesRohit PAI1-40/+43
Abstracting Node can help us extend Tries for other use case like sub routes management Tested 1. Service Validator passes Change-Id: I4703af9f30107ce2bc3685683a5fd5b669341d35 Signed-off-by: Rohit PAI <ropai@nvidia.com>
2025-04-03Move router trie to its own fileEd Tanous1-0/+327
Just as the title says. Trie is useful outside of just the router (for making other routers.) Change-Id: I961927f2cea44ee78f32337e64741edad9dc542f Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-02-27Break out sse into a compile unitEd Tanous2-36/+71
Verify similar to beb96b0 Break out websockets Break out the SSE functions into a separate compile unit. This allows the SSE sockets in beast to be compiled separately, which significantly reduces the overall compile time by a few seconds. Code is identical with the exceptions of minor header definitions to convert header-only to compile unit. Change-Id: I5aae4f17cbd2badf75b3e0bb644a2309f6300663 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-02-12Break out websocketsEd Tanous2-23/+48
When running clang build analyzer it shows that one of the largest templates in the Redfish compile unit (which is also the slowest compile unit) is actually the beast websocket instantiations, taking about 6 seconds to compile on their own. Luckily, the websocket layer is already split into Websocket and WebsocketImpl classes that we inherited from crow. Unfortunately, crow puts these two classes into the same file. So. 1. Move the WebSocketImpl class into its own header. 2. Move the websocket() upgrade routes in the websocket routing rule into their own compile unit to take advantage of only needing WebsocketImpl in this compile unit. Tested: Drops build time by several seconds depending on what other level of optimizations are present (1:15 -> 1:00) [1] https://github.com/aras-p/ClangBuildAnalyzer Change-Id: Ia0445eae4a793bb4ccb28136f30d2a05662c529c Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-02-04clang-format: update latest spec and reformatPatrick Williams1-4/+4
Copy the latest format file from the docs repository and apply. Change-Id: I2f0b9d0fb6e01ed36a2f34c750ba52de3b6d15d1 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2025-01-31Fix includesEd Tanous6-9/+38
Clang-tidy misc-include-cleaner appears to now be enforcing significantly more headers than previously. That is overall a good thing, but forces us to fix some issues. This commit is largely just taking the clang-recommended fixes and checking them in. Subsequent patches will fix the more unique issues. Note, that a number of new ignores are added into the .clang-tidy file. These can be cleaned up over time as they're understood. The majority are places where boost includes a impl/x.hpp and x.hpp, but expects you to use the later. include-cleaner opts for the impl, but it isn't clear why. Change-Id: Id3fdd7ee6df6c33b2fd35626898523048dd51bfb Signed-off-by: Ed Tanous <etanous@nvidia.com> Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
2025-01-20Use SPDX identifiersEd Tanous6-0/+12
SPDX identifiers are simpler, and reduce the amount of cruft we have in code files. They are recommended by linux foundation, and therefore we should do as they allow. This patchset does not intend to modify any intent on any existing copyrights or licenses, only to standardize their inclusion. [1] https://www.linuxfoundation.org/blog/blog/copyright-notices-in-open-source-software-projects Change-Id: I935c7c0156caa78fc368c929cebd0f068031e830 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-01-13Clang-tidy updates for 19Ed Tanous1-0/+5
Update to add new checks that are now available to us. Fix the minor issues we have. A few of our checks that we previously had enabled have been renamed, so remove those from the file as well. Change-Id: Idbbfc3cb7ba42ac780e557554d7ae8ab190e7551 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-07-30Add SSE filter param supportEd Tanous1-5/+6
The Redfish spec require filtering of SSE entries to be supported. This commit rearranges the code, and implements SSE sorting as well as support for Last-Event-Id. To do this it adds a dependency on boost circular_buffer. Tested: SSE connections succeed. Show filtered results. Change-Id: I7aeb266fc40471519674c7b65cd5cc4625019e68 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-06-05Make SSE passEd Tanous4-7/+29
Redfish protocol validator is failing SSE. This is due to a clause in the Redfish specification that requires a "json" error to be returned when the SSE URI is hit with a standard request. In what exists today, we return 4XX (method not allowed) but because this is handled by the HTTP layer, it's not possible to return the correct Redfish payloads for when that 4XX happens within the Redfish tree, because there is in fact a route that matches, that route just doesn't support the type that we need. This commit rearranges the router such that there are now 4 classes of rules. 1. "verb" rules. These are GET/POST/PATCH type, and they are stored using the existing PerMethod array index. 2. "upgrade" rules. These are for websocket or SSE routes that we expect to upgrade to another route 3. 404 routes. These are called in the case where no route exists with that given URI pattern, and no routes exist in the table for any verb. 4. 405 method not allowed. These are called in the case where routes exist in the tree for some method, but not for the method the user requested. To accomplish this, some minor refactors are implemented to separate out the 4xx handlers to be their own variables, rather than just existing at an index at the end of the verb table. This in turn means that getRouteByIndex now changes to allow getting the route by PerMethod instance, rather than index. Tested: unit tests pass (okish coverage) Redfish protocol validator passes (with the exception of #277, which fails identically before and after). SSE tests now pass. Redfish service validator passes. Change-Id: I555c50f392cb12ecbc39fbadbae6a3d50f4d1b23 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-04-20Change ssl stream implementationsEd Tanous3-8/+9
Boost beast ssl_stream is just a wrapper around asio ssl_stream, and aims to optimize the case where we're writing small payloads (one or two bytes.) which needs to be optimized in SSL. bmcweb never writes one or two bytes, we almost always write the full payload of what we received, so there's no reason to take the binary size overhead, and additional boost headers that this implementation requires. Tested: This drops the on-target binary size by 2.6% Redfish service validator passes. Change-Id: Ie1ae6f197f8e5ed70cf4abc6be9b1b382c42d64d Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-18Clean up BMCWEB_ENABLE_SSLEd Tanous3-9/+2
This macro came originally from CROW_ENABLE_SSL, and was used as a macro to optionally compile without openssl being required. OpenSSL has been pulled into many other dependencies, and has been functionally required to be included for a long time, so there's no reason to hold onto this macro. Remove most uses of the macro, and for the couple functional places the macro is used, transition to a constexpr if to enable the TLS paths. This allows a large simplification of code in some places. Tested: Redfish service validator passes. Change-Id: Iebd46a68e5e417b6031479e24be3c21bef782f4c Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-01Fix SSE socketsEd Tanous1-4/+4
Redfish protocol validatator has SSE tests that expose some bad coding practies in SSE handlers, namely, that there are several cases where we don't check for nullptr. Fix them. This appears to have been introduced in: https://gerrit.openbmc.org/c/openbmc/bmcweb/+/41319 Tested: Redfish service validator passes more tests. Change-Id: Id980725f007d044b7d120dbe0f4b625865cab6ba Signed-off-by: Ed Tanous <ed@tanous.net>
2024-03-18Add unit test for SSEEd Tanous1-4/+4
Writing this test exposed some bugs in SSE that got merged. sendSSEHeader was never called, leading to a connection that starts and immediately closes with no error code. This issue has been corrected in code, such that the sockets start. To allow for unit tests, the io_service needs to be passed into the class, previously, the SSE connection was pulling the io_context from the DBus connection, which is odd, given that the SSE connection has no other dependencies on DBus. Unit tests should help keep it working. Tested: Unit tests pass. Change-Id: I48080d2a94b6349989f556cd1c7b103bad498526 Signed-off-by: Ed Tanous <ed@tanous.net>
2023-10-16Remove extra variables in websocketsEd Tanous1-6/+6
These variables don't need propagated to handlers. Any usage of them is incorrect. This makes Websocket once again a pure virtual class, which is desired. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id1ecc3911fc502d436a3e6aa29024628fc51aff4
2023-07-20Replace logging with std::formatEd Tanous1-2/+2
std::format is a much more modern logging solution, and gives us a lot more flexibility, and better compile times when doing logging. Unfortunately, given its level of compile time checks, it needs to be a method, instead of the stream style logging we had before. This requires a pretty substantial change. Fortunately, this change can be largely automated, via the script included in this commit under scripts/replace_logs.py. This is to aid people in moving their patchsets over to the new form in the short period where old patches will be based on the old logging. The intention is that this script eventually goes away. The old style logging (stream based) looked like. BMCWEB_LOG_DEBUG << "Foo " << foo; The new equivalent of the above would be: BMCWEB_LOG_DEBUG("Foo {}", foo); In the course of doing this, this also cleans up several ignored linter errors, including macro usage, and array to pointer deconstruction. Note, This patchset does remove the timestamp from the log message. In practice, this was duplicated between journald and bmcweb, and there's no need for both to exist. One design decision of note is the addition of logPtr. Because the compiler can't disambiguate between const char* and const MyThing*, it's necessary to add an explicit cast to void*. This is identical to how fmt handled it. Tested: compiled with logging meson_option enabled, and launched bmcweb Saw the usual logging, similar to what was present before: ``` [Error include/webassets.hpp:60] Unable to find or open /usr/share/www/ static file hosting disabled [Debug include/persistent_data.hpp:133] Restored Session Timeout: 1800 [Debug redfish-core/include/event_service_manager.hpp:671] Old eventService config not exist [Info src/webserver_main.cpp:59] Starting webserver on port 18080 [Error redfish-core/include/event_service_manager.hpp:1301] inotify_add_watch failed for redfish log file. [Info src/webserver_main.cpp:137] Start Hostname Monitor Service... ``` Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: I86a46aa2454be7fe80df608cb7e5573ca4029ec8
2023-06-30Remove FunctionTraitsEd Tanous1-30/+6
This class is no longer really used or needed, and previously was largely replaced with boost::callable_traits. This moves the last usage of arg_t over to callable_traits. Tested: Redfish service validator passes This series of commits drops ~5 seconds from the bmcweb compile times in my testing. Change-Id: I2d0ac728d282e876232f5379f3bd6ff1ddede2ba Signed-off-by: Ed Tanous <edtanous@google.com>
2023-06-28Simplify the routerEd Tanous2-154/+59
There's a lot of complexity left in the router. The recent decision to only support string arguments means that this can be significantly cleaned up. In some cases, this is done to simply expand the variadic template and handle all parameter cases up to 5 (which should be the max we ever see). While this might seem like it's not very DRY friendly (Don't repeat yourself) this is significantly better than what we had, which was very tough to deciper. Tested: Redfish service validator passes Change-Id: Ic72e54cffd7b9f4a85e6c9d143c45fa20530a2cd Signed-off-by: Ed Tanous <edtanous@google.com>
2023-06-09Break up router into separate filesEd Tanous6-0/+680
The router is a giant behemoth. Start breaking it down into pieces. Tested: Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I9d04f53a58ffce3ecbd88dded1aa6e9648d2a762