Move qtaguid API out of libcutils

The qtaguid kernel module will be deprecated on devices running 4.9
kernel or above and we need to support both old and new module in
userspace. Netd is responsible for choosing which kernel module to use
and all the current qtaguid native implementation need to be hided
behind it. So the current qtaguid native API implementation will be
moved to a isolate library under system/core and only netd can access to
it. The libcutils qtaguid API will become a wrapper to send request to
netd module. This modification will make sure the apps that currently
using this native API will not be broken.

Bug: 30950746
Test: All cts and vts test related should not fail.
Change-Id: I9de98a25ed5dc71bbf520ee0aadd16d59025699a
This commit is contained in:
Chenbo Feng 2017-10-25 11:23:50 -07:00
parent dbef1eeb45
commit 5b11831aa1
3 changed files with 65 additions and 9 deletions

56
libqtaguid/Android.bp Normal file
View File

@ -0,0 +1,56 @@
//
// Copyright (C) 2017 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.
//
cc_library_headers {
name: "libqtaguid_headers",
vendor_available: false,
host_supported: false,
export_include_dirs: ["include"],
target: {
linux_bionic: {
enabled: true,
},
},
}
cc_library {
name: "libqtaguid",
vendor_available: false,
host_supported: false,
target: {
android: {
srcs: [
"qtaguid.c",
],
sanitize: {
misc_undefined: ["integer"],
},
},
},
shared_libs: ["liblog"],
header_libs: [
"libqtaguid_headers",
],
export_header_lib_headers: ["libqtaguid_headers"],
local_include_dirs: ["include"],
cflags: [
"-Werror",
"-Wall",
"-Wextra",
],
}

View File

@ -26,13 +26,13 @@
#include <string.h>
#include <unistd.h>
#include <log/log.h>
#include <cutils/qtaguid.h>
#include <log/log.h>
static const char* CTRL_PROCPATH = "/proc/net/xt_qtaguid/ctrl";
static const int CTRL_MAX_INPUT_LEN = 128;
static const char *GLOBAL_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/passive";
static const char *TAG_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/tag_tracking_passive";
static const char* GLOBAL_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/passive";
static const char* TAG_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/tag_tracking_passive";
/*
* One per proccess.
@ -55,7 +55,7 @@ void qtaguid_resTrack(void) {
* 0 on success.
* -errno on failure.
*/
static int write_ctrl(const char *cmd) {
static int write_ctrl(const char* cmd) {
int fd, res, savedErrno;
ALOGV("write_ctrl(%s)", cmd);
@ -79,7 +79,7 @@ static int write_ctrl(const char *cmd) {
return -savedErrno;
}
static int write_param(const char *param_path, const char *value) {
static int write_param(const char* param_path, const char* value) {
int param_fd;
int res;
@ -108,8 +108,8 @@ int qtaguid_tagSocket(int sockfd, int tag, uid_t uid) {
res = write_ctrl(lineBuf);
if (res < 0) {
ALOGI("Tagging socket %d with tag %" PRIx64 "(%d) for uid %d failed errno=%d",
sockfd, kTag, tag, uid, res);
ALOGI("Tagging socket %d with tag %" PRIx64 "(%d) for uid %d failed errno=%d", sockfd, kTag,
tag, uid, res);
}
return res;
@ -154,14 +154,14 @@ int qtaguid_deleteTagData(int tag, uid_t uid) {
res = write_ctrl(lineBuf);
if (res < 0) {
ALOGI("Deleting tag data with tag %" PRIx64 "/%d for uid %d failed with cnt=%d errno=%d",
kTag, tag, uid, cnt, errno);
kTag, tag, uid, cnt, errno);
}
return res;
}
int qtaguid_setPacifier(int on) {
const char *value;
const char* value;
value = on ? "Y" : "N";
if (write_param(GLOBAL_PACIFIER_PARAM, value) < 0) {