blob: 8b9e5a759c589c74de9e3bd4cc6de40a0f7f9f53 [file] [log] [blame]
Ken Chen1647f602021-10-05 21:55:22 +08001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "NetdUpdatable"
18
Maciej Żenczykowski4938d402022-08-14 14:36:20 +000019#include "BpfHandler.h"
Ken Chen1647f602021-10-05 21:55:22 +080020
21#include <android-base/logging.h>
22#include <netdutils/Status.h>
23
24#include "NetdUpdatablePublic.h"
25
Maciej Żenczykowski4938d402022-08-14 14:36:20 +000026static android::net::BpfHandler sBpfHandler;
27
Ken Chen1647f602021-10-05 21:55:22 +080028int libnetd_updatable_init(const char* cg2_path) {
29 android::base::InitLogging(/*argv=*/nullptr);
30 LOG(INFO) << __func__ << ": Initializing";
31
Maciej Żenczykowski4938d402022-08-14 14:36:20 +000032 android::netdutils::Status ret = sBpfHandler.init(cg2_path);
Ken Chen1647f602021-10-05 21:55:22 +080033 if (!android::netdutils::isOk(ret)) {
Ken Chend6ea75a2023-11-28 23:29:47 +080034 LOG(ERROR) << __func__ << ": Failed. " << ret.code() << " " << ret.msg();
Ken Chen1647f602021-10-05 21:55:22 +080035 return -ret.code();
36 }
37 return 0;
38}
39
40int libnetd_updatable_tagSocket(int sockFd, uint32_t tag, uid_t chargeUid, uid_t realUid) {
Maciej Żenczykowski4938d402022-08-14 14:36:20 +000041 return sBpfHandler.tagSocket(sockFd, tag, chargeUid, realUid);
Ken Chen1647f602021-10-05 21:55:22 +080042}
43
44int libnetd_updatable_untagSocket(int sockFd) {
Maciej Żenczykowski4938d402022-08-14 14:36:20 +000045 return sBpfHandler.untagSocket(sockFd);
Ken Chen1647f602021-10-05 21:55:22 +080046}