summaryrefslogtreecommitdiff
path: root/include/kvm_websocket.hpp
AgeCommit message (Collapse)AuthorFilesLines
2024-04-11Fix buffer_copyEd Tanous1-4/+4
boost::asio::buffer_copy returns an integer of the number of values copied. Some static analysis tools mark that value as nodiscard, although it should never fail. Audit all uses of buffer_copy, and make sure that they're using the return value. In theory this should have no change on the behavior. Change-Id: I6af39b5347954c2932cf3d4e48e96ff9ae01583a Signed-off-by: Ed Tanous <ed@tanous.net>
2023-10-24clang-format: copy latest and re-formatPatrick Williams1-28/+28
clang-format-17 has some backwards incompatible changes that require additional settings for best compatibility and re-running the formatter. Copy the latest .clang-format from the docs repository and reformat the repository. Change-Id: I2f9540cf0d545a2da4d6289fc87b754f684bc9a7 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-08-24kvm_websocket: Fix crash on dangling referenceXinnan Xie1-7/+19
Kvm_websocket captures the this pointer in the handler lambda of the socket. When the callback is called, if the object has been destructed, there will be a crash problem. This is fixed by using weak_from_this in the callback, if the object was destructed, the callback just returns without doing anything. Tested: 1. Open two kvm sessions in WebUI, and keep refreshing in one of the pages, there is a small chance of coredump happening. Debug infomation shows: ``` bmcweb[5331]: DEBUG: doRead. conn:0x28d19a0. this: 0x284d470 bmcweb[5331]: DEBUG: doRead. conn:0x28d19a0. this: 0x284d470 bmcweb[5331]: DEBUG: doRead. conn:0x28d19a0. this: 0x284d470 bmcweb[5331]: DEBUG: doRead. conn:0x28d19a0. this: 0x284d470 bmcweb[5331]: DEBUG: doRead. conn:0x28d19a0. this: 0x284d470 bmcweb[5331]: DEBUG: onclose. conn:0x28d19a0 bmcweb[5331]: DEBUG: doRead. conn:0x2876648. this: 0x284d470 systemd[1]: bmeweb.service: Main process exited, code=dumped, status=11/SEGV systemd[1]: bmcweb.service: Failed with result 'core-dump systemd[1]: Started Start bmweb server. ``` 2. After this fix no coredump occurred. Change-Id: I7bba9b67c470def90ddb1e471a0ac95edd6165e5 Signed-off-by: Xinnan Xie <xiexinnan@bytedance.com>
2023-07-20Replace logging with std::formatEd Tanous1-30/+29
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-05-25Fix some includesEd Tanous1-1/+1
System includes should be included with <>, in-tree includes should be included with "". This was found manually, with the help of the following grep statement[1]. git grep -o -h "#include .*" | sort | uniq Tested: Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I1a6b2a5ba35ccbbb61c67b7c4b036a2d7b3a36a3
2023-01-18Fix a boatload of #includesEd Tanous1-2/+3
Most of these missing includes were found by running clang-tidy on all files, including headers. The existing scripts just run clang-tidy on source files, which doesn't catch most of these. Tested: Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ic741fbb2cc9e5e92955fd5a1b778a482830e80e8
2023-01-17Add check for globalsEd Tanous1-3/+4
We don't follow this cpp core guidelines rule well. This is something that we should aspire to cleaning up in the future, but for the moment, lets turn the rule on in clang-tidy to stop the bleeding, add ignores for the things that we know need some better abstractions, and work on these over time. Most of this commit is just adding NOLINTNEXTLINE exceptions for all of our globals. There was one case in the sensor code where clang correctly noted that those globals weren't actually const, which got missed because of the use of auto. Tested: CI should be good enough for this. Passes clang-tidy. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ieda08fee69a3b209d4b3e9771809a6c41524f066
2022-06-01Try to fix the lambda formatting issueEd Tanous1-43/+43
clang-tidy has a setting, LambdaBodyIndentation, which it says: "For callback-heavy code, it may improve readability to have the signature indented two levels and to use OuterScope." bmcweb is very callback heavy code. Try to enable it and see if that improves things. There are many cases where the length of a lambda call will change, and reindent the entire lambda function. This is really bad for code reviews, as it's difficult to see the lines changed. This commit should resolve it. This does have the downside of reindenting a lot of functions, which is unfortunate, but probably worth it in the long run. All changes except for the .clang-format file were made by the robot. Tested: Code compiles, whitespace changes only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
2022-03-29Remove AsyncResp from openHandlerzhanghch051-2/+1
This change, moving the openHandler back to only supporting websocket disconnects and not 404s.Because AsyncResp is removed from openHandler. Tested: (from previous commit) Opened KVM in webui-vue and it works. Signed-off-by: zhanghaicheng <zhanghch05@inspur.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I793f05836aeccdc275b7aaaeede41b3a2c276595
2022-02-17Prepare for clang-tidy-14Ed Tanous1-2/+2
clang-tidy 14 now detects some more stuff that it couldn't before. These are all pretty reasonable and things that we enforce today. All changes were made by the robot. Tested: Code compiles and unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I880d714c97adc38a190472766fb922fbfb30e82a
2022-01-12Enable bugprone widening checks in clangEd Tanous1-2/+2
Most of the errors we hit are simply places we need to explicitly increase the width of the integer. Luckily, these are few and far between. Tested: Code compiles, unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I617d87f3970ae773e0767bb2f20118fca2e71daa
2021-11-16Revert "Remove AsyncResp from openHandler"Gunnar Mills1-1/+2
This reverts commit 0f3d3a01aed4040ef73a977a958ecdf4f68111f6. Seeing bumps fail. Change-Id: Ida7b1bae48abbed2e00a5259e8f94b64168d4788 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
2021-11-16Remove AsyncResp from openHandlerzhanghch051-2/+1
This change, moving the openHandler back to only supporting websocket disconnects and not 404s.Because AsyncResp is removed from openHandler. Tested: Opened KVM in webui-vue and it works. Signed-off-by: zhanghaicheng <zhanghch05@inspur.com> Change-Id: I90811f4ab91ad41cb298877f76252dce80932b2b
2021-06-16Remove ambiguous privileges constructorEd Tanous1-1/+1
There are a number of endpoints that assume that a given routes privileges are governed by a single set of privileges, instead of multiple sets ORed together. To handle this, there were two overloads of the privileges() method, one that took a vector of Privileges, and one that took an initializer_list of const char*. Unfortunately, this leads some code in AccountService to pick the wrong overload when it's called like this .privileges( {{"ConfigureUsers"}, {"ConfigureManager"}, {"ConfigureSelf"}}) This is supposed to be "User must have ConfigureUsers, or ConfigureManager, or ConfigureSelf". Currently, because it selects the wrong overload, it computes to "User must have ConfigureUsers AND ConfigureManager AND ConfigureSelf. The double braces are supposed to cause this to form a vector of Privileges, but it appears that the initializer list gets consumed, and the single invocation of initializer list is called. Interestingly, trying to put in a privileges overload of intializer_list<initializer_list<const char*>> causes the compilation to fail with an ambiguous call error, which is what I would've expected to see previously in this case, but alas, I'm only a novice when it comes to how the C++ standard works in these edge cases. This is likely due in part to the fact that they were templates of an unused template param (seemingly copied from the previous method) and SFINAE rules around templates. This commit functionally removes one of the privileges overloads, and adds a second set of braces to every privileges call that previously had a single set of braces. Previous code will not compile now, which is IMO a good thing. This likely popped up in the Node class removal, because the Node class explicitly constructs a vector of Privilege objects, ensuing it can hit the right overload Tested: Ran Redfish service validator Tested the specific use case outlined on discord with: Creating a new user with operator privilege: ``` redfishtool -S Always -u root -p 0penBmc -vvvvvvvvv -r 192.168.7.2 AccountService adduser foo mysuperPass1 Operator ``` Then attempting to list accounts: ``` curl -vvvv --insecure --user foo:mysuperPass1 https://192.168.7.2/redfish/v1/AccountService/Accounts/foo ``` Which succeeded and returned the account in question. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I83e62b70e97f56dc57d43b9081f333a02fe85495
2020-10-23fix include namesEd Tanous1-2/+2
cppcheck isn't smart enough to recognize these are c++ headers, not c headers. Considering we're already inconsistent about our naming, it's easier to just be consistent, and move the last few files to use .hpp instead of .h. Tested: Code builds, no changes. Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: Ic348d695f8527fa4a0ded53f433e1558c319db40
2020-10-15Lots of performance improvementsEd Tanous1-1/+1
(In the voice of the kid from sixth sense) I see string copies... Apparently there are a lot of places we make unnecessary copies. This fixes all of them. Not sure how to split this up into smaller patches, or if it even needs split up. It seems pretty easy to review to me, because basically every diff is identical. Change-Id: I22b4ae4f96f7e4082d2bc701098a04f7bed95369 Signed-off-by: Ed Tanous <ed@tanous.net> Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
2020-09-29Fix naming conventionsEd Tanous1-1/+1
Lots of code has been checked in that doesn't match the naming conventions. Lets fix that. Tested: Code compiles. Variable/function renames only. Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: I6bd107811d0b724f1fad990016113cdf035b604b
2020-08-17Enable unused variable warnings and resolveEd Tanous1-4/+5
This commit enables the "unused variables" warning in clang. Throughout this, it did point out several issues that would've been functional bugs, so I think it was worthwhile. It also cleaned up several unused variable from old constructs that no longer exist. Tested: Built with clang. Code no longer emits warnings. Downloaded bmcweb to system and pulled up the webui, observed webui loads and logs in properly. Change-Id: I51505f4222cc147d6f2b87b14d7e2ac4a74cafa8 Signed-off-by: Ed Tanous <ed@tanous.net>
2020-08-17Enable clang warningsEd Tanous1-5/+5
This commit enables clang warnings, and fixes all warnings that were found. Most of these fall into a couple categories: Variable shadow issues were fixed by renaming variables unused parameter warnings were resolved by either checking error codes that had been ignored, or removing the name of the variable from the scope. Other various warnings were fixed in the best way I was able to come up with. Note, the redfish Node class is especially insidious, as it causes all imlementers to have variables for parameters, regardless of whether or not they are used. Deprecating the Node class is on my list of things to do, as it adds extra overhead, and in general isn't a useful abstraction. For now, I have simply fixed all the handlers. Tested: Added the current meta-clang meta layer into bblayers.conf, and added TOOLCHAIN_pn-bmcweb = "clang" to my local.conf Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: Ia75b94010359170159c703e535d1c1af182fe700
2020-08-17Remove middlewaresEd Tanous1-2/+1
Middlewares, while kinda cool from an academic standpoint, make our build times even worse than they already are. Given that we only really use 1 real middleware today (token auth) and it needs to move into the parser mode anyway (for security limiting buffer sizes), we might as well use this as an opportunity to delete some code. Some other things that happen: 1. Persistent data now moves out of the crow namespace 2. App is no longer a template 3. All request_routes implementations no longer become templates. This should be a decent (unmeasured) win on compile times. This commit was part of a commit previously called "various cleanups". This separates ONLY the middleware deletion part of that. Note, this also deletes about 400 lines of hard to understand code. Change-Id: I4c19e25491a153a2aa2e4ef46fc797bcb5b3581a Signed-off-by: Ed Tanous <ed@tanous.net>
2020-07-10Codespell spelling fixesGunnar Mills1-1/+1
These spelling errors were found using https://github.com/codespell-project/codespell Tested: Built and ran against validator. Signed-off-by: Gunnar Mills <gmills@us.ibm.com> Change-Id: I214fe102550295578cfdf0fc58305897d261ce55
2020-02-20Fix KVM page to display the KVM sessionJohnathan Mantey1-1/+1
Launching a KVM session on the KVM page stopped working. The websocket connection request began returning connection failure error codes. This change fixes the asynchronous connection request to allow it to succeed, and in turn display the KVM session. Tested: Connect to BMC using Chrome (FC31), selected Control->KVM sidebar. Witnessed the KVM session started, and interacted with the SUT while it was in UEFI. Connect to BMC using Chrome (Windows 10), selected Control->KVM sidebar. Witnessed the KVM session started, and interacted with the SUT while it was in UEFI. Events performed from the Windows browser were duplicated in the FC31 browser. Change-Id: Ib3721990dce2e2ba71235371d903fbf508075077 Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
2019-11-21Implement nbd-proxy as a part of bmcwebIwona Klimaszewska1-1/+3
Nbd-proxy is responsible for exposing websocket endpoint in bmcweb. It matches WS endpoints with unix socket paths using configuration exposed on D-Bus by Virtual-Media. Virtual-Media is then notified about unix socket availability through mount/unmount D-Bus methods. Currently, this feature is disabled by default. Tested: Integrated with initial version of Virtual-Media. Change-Id: I9c572e9841b16785727e5676fea1bb63b0311c63 Signed-off-by: Iwona Klimaszewska <iwona.klimaszewska@intel.com> Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
2019-10-21Add "requires" handlers to all non-trivial routesEd Tanous1-0/+1
This commit is the result of an audit to add user levels to the various components that need them. As written: KVM requires admin privilege Virtual media requires admin privilege image upload requires admin privilege /subscribe API requies Login privilege Signed-off-by: Ed Tanous <ed.tanous@intel.com> Change-Id: I6384f23769a5ac23f653519656721da7373f088f
2019-10-18Make references to crow less obviousEd Tanous1-2/+2
Recently, a number of people in the community have made the (admittedly easy) mistake that we use a significant portion of crow. Today, we use crow for the router, and the "app" structure, and even those have been significantly modified to meet the bmc needs. All other components have been replaced with Boost beast. This commit removes the crow mentions from the Readme, and moves the crow folder to "http" to camouflage it a little. No code content has changed. Tested: Code compiles. No functional change made to any executable code. Signed-off-by: Ed Tanous <ed.tanous@intel.com> Change-Id: Iceb57b26306cc8bdcfc77f3874246338864fd118
2019-10-11Fix a bunch of warningsEd Tanous1-1/+1
using the list of warnings from here: https://github.com/lefticus/cppbestpractices/blob/e73393f25a85f83fed7399d8b65cb117d00b2231/02-Use_the_Tools_Available.md#L100 Seems like a good place to start, and would improve things a bit type-wise. This patchset attempts to correct all the issues in one shot. Tested: It builds. Will test various subsystems that have been touched Signed-off-by: Ed Tanous <ed.tanous@intel.com> Change-Id: I588c26440e5a97f718a0f0ea74cc84107d53aa1e
2019-09-24Add concurrent KVM sessions supportJae Hyun Yoo1-131/+135
Currently, bmcweb allows just one KVM session. To make it support multiple concurrent KVM sessions, this commit adds KVM session class implementation. It limits the number of sessions to 4 to secure the connection quality. Tested: Up to 4 concurrent KVM sessions worked. Change-Id: I37342ba2e30f840131d6287b4249a298aa17a1f1 Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
2019-05-02bmcweb: /s/boost::beast::string_view/std::string_view/gAdriana Kobylak1-1/+1
Follow-on to https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/18891 Tested: Checked that the host console and virtual media endpoints still worked as expected. Change-Id: Ifdc5f21f3668bdf9bd24189504aaeb17b232c921 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
2019-03-29update ASIO interfacesEd Tanous1-1/+6
This commit does 2 things. 1. Upgrades and prepares bmcweb for boost 1.70. 2. Allows us to compile with BOOST_AIO_NO_DEPRECATED Tested: Compiled against 1.69 and 1.70. All changes should be no-op. Change-Id: I557ecd840fe2b88c0fa01978a1b666b40ccccca4 Signed-off-by: Ed Tanous <ed.tanous@intel.com>
2019-03-18Refine KVM websock proxyJae Hyun Yoo1-26/+30
This commit simplifies input buffer delivering logic by removing a doWrite() call from readDone(). Input events can be delivered through websocket's onmessage handler only and it's enough. Also, it fixes a suspicious weak point of commit/consume pair on outputBuffer. Change-Id: I5b777993a9d6f05375da0422b168c25dacb1b9f9 Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
2019-02-21Implement KVM websocket proxy in bmcwebEd Tanous1-0/+173
This patchset implements a KVM websocket proxy designed to interoperate with phosphor-webui and KVM. in short, IP address 127.0.0.1:5900 is proxied to the websocket. This allows someone to connect from a browser session. Requires patchset here for the phosphor-webui side: https://gerrit.openbmc-project.xyz/#/c/openbmc/phosphor-webui/+/10268/ and requires the kvm patches here: https://gerrit.openbmc-project.xyz/#/c/openbmc/meta-phosphor/+/13536/ Tested By: Launched webui, observed KVM. Moved mouse, and typed on keyboard, changes appeared on host system. Change-Id: I407488f4b16be208b188a0abc19954a0243af173 Signed-off-by: Ed Tanous <ed.tanous@intel.com>