1 /*
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
19 #include "BpfHandler.h"
20
21 #include <android-base/logging.h>
22 #include <netdutils/Status.h>
23
24 #include "NetdUpdatablePublic.h"
25
26 static android::net::BpfHandler sBpfHandler;
27
libnetd_updatable_init(const char * cg2_path)28 int libnetd_updatable_init(const char* cg2_path) {
29 android::base::InitLogging(/*argv=*/nullptr);
30 LOG(INFO) << __func__ << ": Initializing";
31
32 android::netdutils::Status ret = sBpfHandler.init(cg2_path);
33 if (!android::netdutils::isOk(ret)) {
34 LOG(ERROR) << __func__ << ": Failed: (" << ret.code() << ") " << ret.msg();
35 abort();
36 }
37 return 0;
38 }
39
libnetd_updatable_tagSocket(int sockFd,uint32_t tag,uid_t chargeUid,uid_t realUid)40 int libnetd_updatable_tagSocket(int sockFd, uint32_t tag, uid_t chargeUid, uid_t realUid) {
41 return sBpfHandler.tagSocket(sockFd, tag, chargeUid, realUid);
42 }
43
libnetd_updatable_untagSocket(int sockFd)44 int libnetd_updatable_untagSocket(int sockFd) {
45 return sBpfHandler.untagSocket(sockFd);
46 }
47