From 5b11831aa1d54550dee5f9c3d48cedd27871955f Mon Sep 17 00:00:00 2001 From: Chenbo Feng Date: Wed, 25 Oct 2017 11:23:50 -0700 Subject: [PATCH] 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 --- libqtaguid/Android.bp | 56 +++++++++++++++++++ .../include/qtaguid}/qtaguid.h | 0 {libcutils => libqtaguid}/qtaguid.c | 18 +++--- 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 libqtaguid/Android.bp rename {libcutils/include/cutils => libqtaguid/include/qtaguid}/qtaguid.h (100%) rename {libcutils => libqtaguid}/qtaguid.c (92%) diff --git a/libqtaguid/Android.bp b/libqtaguid/Android.bp new file mode 100644 index 000000000..de632caa2 --- /dev/null +++ b/libqtaguid/Android.bp @@ -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", + ], +} diff --git a/libcutils/include/cutils/qtaguid.h b/libqtaguid/include/qtaguid/qtaguid.h similarity index 100% rename from libcutils/include/cutils/qtaguid.h rename to libqtaguid/include/qtaguid/qtaguid.h diff --git a/libcutils/qtaguid.c b/libqtaguid/qtaguid.c similarity index 92% rename from libcutils/qtaguid.c rename to libqtaguid/qtaguid.c index 22b83253f..af9fbfa7d 100644 --- a/libcutils/qtaguid.c +++ b/libqtaguid/qtaguid.c @@ -26,13 +26,13 @@ #include #include -#include #include +#include 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) {