android_packages_modules_Co.../bpf/netd/NetdUpdatable.cpp
Maciej Żenczykowski 04ed60fa25 bpf: git mv netd bpf/netd (plus update visibility for new path)
Another step towards moving all bpf related stuff into a common directory.

In practice netd_updatable is only actually used for bpf...

The upcoming netbpfload UML test should be checking netd_updatable's
initialization succeeds (useful since that opens a bunch of maps
fetches some programs, and attaches them to a bunch of cgroup hooks).

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I65a0fbbf18bf0aa87938df691c0a9ebcca9a084c
2024-08-29 22:25:51 +00:00

46 lines
1.4 KiB
C++

/*
* Copyright (C) 2022 The Android Open Source Project
*
* 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.
*/
#define LOG_TAG "NetdUpdatable"
#include "BpfHandler.h"
#include <android-base/logging.h>
#include <netdutils/Status.h>
#include "NetdUpdatablePublic.h"
static android::net::BpfHandler sBpfHandler;
int libnetd_updatable_init(const char* cg2_path) {
android::base::InitLogging(/*argv=*/nullptr);
LOG(INFO) << __func__ << ": Initializing";
android::netdutils::Status ret = sBpfHandler.init(cg2_path);
if (!android::netdutils::isOk(ret)) {
LOG(ERROR) << __func__ << ": Failed: (" << ret.code() << ") " << ret.msg();
abort();
}
return 0;
}
int libnetd_updatable_tagSocket(int sockFd, uint32_t tag, uid_t chargeUid, uid_t realUid) {
return sBpfHandler.tagSocket(sockFd, tag, chargeUid, realUid);
}
int libnetd_updatable_untagSocket(int sockFd) {
return sBpfHandler.untagSocket(sockFd);
}