| Ken Chen | 1647f60 | 2021-10-05 21:55:22 +0800 | [diff] [blame] | 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 |  | 
| Maciej Żenczykowski | 4938d40 | 2022-08-14 14:36:20 +0000 | [diff] [blame] | 19 | #include "BpfHandler.h" | 
| Ken Chen | 1647f60 | 2021-10-05 21:55:22 +0800 | [diff] [blame] | 20 |  | 
|  | 21 | #include <android-base/logging.h> | 
|  | 22 | #include <netdutils/Status.h> | 
|  | 23 |  | 
|  | 24 | #include "NetdUpdatablePublic.h" | 
|  | 25 |  | 
| Maciej Żenczykowski | 4938d40 | 2022-08-14 14:36:20 +0000 | [diff] [blame] | 26 | static android::net::BpfHandler sBpfHandler; | 
|  | 27 |  | 
| Ken Chen | 1647f60 | 2021-10-05 21:55:22 +0800 | [diff] [blame] | 28 | int libnetd_updatable_init(const char* cg2_path) { | 
|  | 29 | android::base::InitLogging(/*argv=*/nullptr); | 
|  | 30 | LOG(INFO) << __func__ << ": Initializing"; | 
|  | 31 |  | 
| Maciej Żenczykowski | 4938d40 | 2022-08-14 14:36:20 +0000 | [diff] [blame] | 32 | android::netdutils::Status ret = sBpfHandler.init(cg2_path); | 
| Ken Chen | 1647f60 | 2021-10-05 21:55:22 +0800 | [diff] [blame] | 33 | if (!android::netdutils::isOk(ret)) { | 
| Maciej Żenczykowski | ff845a6 | 2023-12-22 09:37:30 +0000 | [diff] [blame] | 34 | LOG(ERROR) << __func__ << ": Failed: (" << ret.code() << ") " << ret.msg(); | 
|  | 35 | abort(); | 
| Ken Chen | 1647f60 | 2021-10-05 21:55:22 +0800 | [diff] [blame] | 36 | } | 
|  | 37 | return 0; | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | int libnetd_updatable_tagSocket(int sockFd, uint32_t tag, uid_t chargeUid, uid_t realUid) { | 
| Maciej Żenczykowski | 4938d40 | 2022-08-14 14:36:20 +0000 | [diff] [blame] | 41 | return sBpfHandler.tagSocket(sockFd, tag, chargeUid, realUid); | 
| Ken Chen | 1647f60 | 2021-10-05 21:55:22 +0800 | [diff] [blame] | 42 | } | 
|  | 43 |  | 
|  | 44 | int libnetd_updatable_untagSocket(int sockFd) { | 
| Maciej Żenczykowski | 4938d40 | 2022-08-14 14:36:20 +0000 | [diff] [blame] | 45 | return sBpfHandler.untagSocket(sockFd); | 
| Ken Chen | 1647f60 | 2021-10-05 21:55:22 +0800 | [diff] [blame] | 46 | } |