diff --git a/services/hilogd/include/domain_list.h b/services/hilogd/include/domain_list.h new file mode 100644 index 0000000000000000000000000000000000000000..48312e2d2447f8c29551f31d251c933c64cb488e --- /dev/null +++ b/services/hilogd/include/domain_list.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DOMAIN_LIST_H +#define DOMAIN_LIST_H +#include +#include + +// Must be in order for binary_search +// Last two digits can vary +constexpr std::array domainWhiteList{ + 0xd000000, + 0xd000100, + 0xd000700, + 0xd000f00, // Domain for testing + 0xd001000, + 0xd001100, + 0xd001400, + 0xd001500, + 0xd001600, + 0xd001800, + 0xd001b00, + 0xd002500, + 0xd002900, + 0xd002b00, + 0xd002f00, + 0xd003b00, + 0xd008800 +}; + +constexpr uint32_t DOMAIN_WHITELIST_MATCH = 0xdffff00; + +#endif \ No newline at end of file diff --git a/services/hilogd/log_collector.cpp b/services/hilogd/log_collector.cpp index ee69bcbe5eb0b364643da2c2ae599684db44430a..af01dc54f20f199bcb238fd662420f6b9b35c11c 100644 --- a/services/hilogd/log_collector.cpp +++ b/services/hilogd/log_collector.cpp @@ -16,6 +16,7 @@ #include "log_collector.h" #include "log_kmsg.h" #include "flow_control_init.h" +#include "domain_list.h" #include #include @@ -24,11 +25,17 @@ #include #include #include +#include namespace OHOS { namespace HiviewDFX { using namespace std; +static bool DomainWritable(const uint32_t domain) +{ + return std::binary_search(domainWhiteList.cbegin(), domainWhiteList.cend(), (domain & DOMAIN_WHITELIST_MATCH)); +} + void LogCollector::InsertDropInfo(const HilogMsg &msg, int droppedCount) { string dropLog = to_string(droppedCount) + " line(s) dropped!"; @@ -76,6 +83,8 @@ void LogCollector::onDataRecv(const ucred& cred, std::vector& data) #ifdef __RECV_MSG_WITH_UCRED_ msg->pid = cred.pid; #endif + // Drop if not in domain whitelist + if (!DomainWritable(msg->domain)) return; // Domain flow control int ret = FlowCtrlDomain(msg); if (ret < 0) {