diff options
author | Chenbo Feng | 2017-10-25 14:31:43 -0500 |
---|---|---|
committer | Chenbo Feng | 2017-11-09 20:02:22 -0600 |
commit | baede73bd92d8d0ae11e42c438fe2ca7f209e2c4 (patch) | |
tree | 1292ea60ea414c0b7f714f761b0b064c51bc2d09 /libqtaguid | |
parent | 5b11831aa1d54550dee5f9c3d48cedd27871955f (diff) | |
download | platform-system-core-baede73bd92d8d0ae11e42c438fe2ca7f209e2c4.tar.gz platform-system-core-baede73bd92d8d0ae11e42c438fe2ca7f209e2c4.tar.xz platform-system-core-baede73bd92d8d0ae11e42c438fe2ca7f209e2c4.zip |
Redirect qtaguid native call to netd fwmark client
In order to replace qtaguid module with new eBPF network monitoring
module. We firstly move the current qtaguid userspace implementation
into netd and hide the detail from other processes. The current API will
talk to netd fwmark client to pass down the qtaguid related request from
high level framework and netd will use the proper method to complete the
request.
Test: Current TrafficStats CTS tests should not fail.
Bug: 30950746
Change-Id: Ie90c28f3594ab2877746b2372a1b6944768bfb18
Diffstat (limited to 'libqtaguid')
-rw-r--r-- | libqtaguid/include/qtaguid/qtaguid.h | 20 | ||||
-rw-r--r-- | libqtaguid/qtaguid.c | 47 |
2 files changed, 15 insertions, 52 deletions
diff --git a/libqtaguid/include/qtaguid/qtaguid.h b/libqtaguid/include/qtaguid/qtaguid.h index 803fe0d9a..72285e532 100644 --- a/libqtaguid/include/qtaguid/qtaguid.h +++ b/libqtaguid/include/qtaguid/qtaguid.h | |||
@@ -14,8 +14,8 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef __CUTILS_QTAGUID_H | 17 | #ifndef __LEGACY_QTAGUID_H |
18 | #define __CUTILS_QTAGUID_H | 18 | #define __LEGACY_QTAGUID_H |
19 | 19 | ||
20 | #include <stdint.h> | 20 | #include <stdint.h> |
21 | #include <sys/types.h> | 21 | #include <sys/types.h> |
@@ -30,19 +30,19 @@ extern "C" { | |||
30 | * by calling qtaguid_untagSocket() before closing it, otherwise the qtaguid | 30 | * by calling qtaguid_untagSocket() before closing it, otherwise the qtaguid |
31 | * module will keep a reference to it even after close. | 31 | * module will keep a reference to it even after close. |
32 | */ | 32 | */ |
33 | extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid); | 33 | extern int legacy_tagSocket(int sockfd, int tag, uid_t uid); |
34 | 34 | ||
35 | /* | 35 | /* |
36 | * Untag a network socket before closing. | 36 | * Untag a network socket before closing. |
37 | */ | 37 | */ |
38 | extern int qtaguid_untagSocket(int sockfd); | 38 | extern int legacy_untagSocket(int sockfd); |
39 | 39 | ||
40 | /* | 40 | /* |
41 | * For the given uid, switch counter sets. | 41 | * For the given uid, switch counter sets. |
42 | * The kernel only keeps a limited number of sets. | 42 | * The kernel only keeps a limited number of sets. |
43 | * 2 for now. | 43 | * 2 for now. |
44 | */ | 44 | */ |
45 | extern int qtaguid_setCounterSet(int counterSetNum, uid_t uid); | 45 | extern int legacy_setCounterSet(int counterSetNum, uid_t uid); |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * Delete all tag info that relates to the given tag an uid. | 48 | * Delete all tag info that relates to the given tag an uid. |
@@ -53,16 +53,10 @@ extern int qtaguid_setCounterSet(int counterSetNum, uid_t uid); | |||
53 | * Unless it is part of the happy AID_NET_BW_ACCT group. | 53 | * Unless it is part of the happy AID_NET_BW_ACCT group. |
54 | * In which case it can clobber everything. | 54 | * In which case it can clobber everything. |
55 | */ | 55 | */ |
56 | extern int qtaguid_deleteTagData(int tag, uid_t uid); | 56 | extern int legacy_deleteTagData(int tag, uid_t uid); |
57 | |||
58 | /* | ||
59 | * Enable/disable qtaguid functionnality at a lower level. | ||
60 | * When pacified, the kernel will accept commands but do nothing. | ||
61 | */ | ||
62 | extern int qtaguid_setPacifier(int on); | ||
63 | 57 | ||
64 | #ifdef __cplusplus | 58 | #ifdef __cplusplus |
65 | } | 59 | } |
66 | #endif | 60 | #endif |
67 | 61 | ||
68 | #endif /* __CUTILS_QTAG_UID_H */ | 62 | #endif /* __LEGACY_QTAGUID_H */ |
diff --git a/libqtaguid/qtaguid.c b/libqtaguid/qtaguid.c index af9fbfa7d..cd38bad77 100644 --- a/libqtaguid/qtaguid.c +++ b/libqtaguid/qtaguid.c | |||
@@ -26,13 +26,11 @@ | |||
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <unistd.h> | 27 | #include <unistd.h> |
28 | 28 | ||
29 | #include <cutils/qtaguid.h> | ||
30 | #include <log/log.h> | 29 | #include <log/log.h> |
30 | #include <qtaguid/qtaguid.h> | ||
31 | 31 | ||
32 | static const char* CTRL_PROCPATH = "/proc/net/xt_qtaguid/ctrl"; | 32 | static const char* CTRL_PROCPATH = "/proc/net/xt_qtaguid/ctrl"; |
33 | static const int CTRL_MAX_INPUT_LEN = 128; | 33 | static const int CTRL_MAX_INPUT_LEN = 128; |
34 | static const char* GLOBAL_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/passive"; | ||
35 | static const char* TAG_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/tag_tracking_passive"; | ||
36 | 34 | ||
37 | /* | 35 | /* |
38 | * One per proccess. | 36 | * One per proccess. |
@@ -46,7 +44,7 @@ static int resTrackFd = -1; | |||
46 | pthread_once_t resTrackInitDone = PTHREAD_ONCE_INIT; | 44 | pthread_once_t resTrackInitDone = PTHREAD_ONCE_INIT; |
47 | 45 | ||
48 | /* Only call once per process. */ | 46 | /* Only call once per process. */ |
49 | void qtaguid_resTrack(void) { | 47 | void legacy_resTrack(void) { |
50 | resTrackFd = TEMP_FAILURE_RETRY(open("/dev/xt_qtaguid", O_RDONLY | O_CLOEXEC)); | 48 | resTrackFd = TEMP_FAILURE_RETRY(open("/dev/xt_qtaguid", O_RDONLY | O_CLOEXEC)); |
51 | } | 49 | } |
52 | 50 | ||
@@ -79,28 +77,12 @@ static int write_ctrl(const char* cmd) { | |||
79 | return -savedErrno; | 77 | return -savedErrno; |
80 | } | 78 | } |
81 | 79 | ||
82 | static int write_param(const char* param_path, const char* value) { | 80 | int legacy_tagSocket(int sockfd, int tag, uid_t uid) { |
83 | int param_fd; | ||
84 | int res; | ||
85 | |||
86 | param_fd = TEMP_FAILURE_RETRY(open(param_path, O_WRONLY | O_CLOEXEC)); | ||
87 | if (param_fd < 0) { | ||
88 | return -errno; | ||
89 | } | ||
90 | res = TEMP_FAILURE_RETRY(write(param_fd, value, strlen(value))); | ||
91 | if (res < 0) { | ||
92 | return -errno; | ||
93 | } | ||
94 | close(param_fd); | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | int qtaguid_tagSocket(int sockfd, int tag, uid_t uid) { | ||
99 | char lineBuf[CTRL_MAX_INPUT_LEN]; | 81 | char lineBuf[CTRL_MAX_INPUT_LEN]; |
100 | int res; | 82 | int res; |
101 | uint64_t kTag = ((uint64_t)tag << 32); | 83 | uint64_t kTag = ((uint64_t)tag << 32); |
102 | 84 | ||
103 | pthread_once(&resTrackInitDone, qtaguid_resTrack); | 85 | pthread_once(&resTrackInitDone, legacy_resTrack); |
104 | 86 | ||
105 | snprintf(lineBuf, sizeof(lineBuf), "t %d %" PRIu64 " %d", sockfd, kTag, uid); | 87 | snprintf(lineBuf, sizeof(lineBuf), "t %d %" PRIu64 " %d", sockfd, kTag, uid); |
106 | 88 | ||
@@ -115,7 +97,7 @@ int qtaguid_tagSocket(int sockfd, int tag, uid_t uid) { | |||
115 | return res; | 97 | return res; |
116 | } | 98 | } |
117 | 99 | ||
118 | int qtaguid_untagSocket(int sockfd) { | 100 | int legacy_untagSocket(int sockfd) { |
119 | char lineBuf[CTRL_MAX_INPUT_LEN]; | 101 | char lineBuf[CTRL_MAX_INPUT_LEN]; |
120 | int res; | 102 | int res; |
121 | 103 | ||
@@ -130,7 +112,7 @@ int qtaguid_untagSocket(int sockfd) { | |||
130 | return res; | 112 | return res; |
131 | } | 113 | } |
132 | 114 | ||
133 | int qtaguid_setCounterSet(int counterSetNum, uid_t uid) { | 115 | int legacy_setCounterSet(int counterSetNum, uid_t uid) { |
134 | char lineBuf[CTRL_MAX_INPUT_LEN]; | 116 | char lineBuf[CTRL_MAX_INPUT_LEN]; |
135 | int res; | 117 | int res; |
136 | 118 | ||
@@ -141,14 +123,14 @@ int qtaguid_setCounterSet(int counterSetNum, uid_t uid) { | |||
141 | return res; | 123 | return res; |
142 | } | 124 | } |
143 | 125 | ||
144 | int qtaguid_deleteTagData(int tag, uid_t uid) { | 126 | int legacy_deleteTagData(int tag, uid_t uid) { |
145 | char lineBuf[CTRL_MAX_INPUT_LEN]; | 127 | char lineBuf[CTRL_MAX_INPUT_LEN]; |
146 | int cnt = 0, res = 0; | 128 | int cnt = 0, res = 0; |
147 | uint64_t kTag = (uint64_t)tag << 32; | 129 | uint64_t kTag = (uint64_t)tag << 32; |
148 | 130 | ||
149 | ALOGV("Deleting tag data with tag %" PRIx64 "{%d,0} for uid %d", kTag, tag, uid); | 131 | ALOGV("Deleting tag data with tag %" PRIx64 "{%d,0} for uid %d", kTag, tag, uid); |
150 | 132 | ||
151 | pthread_once(&resTrackInitDone, qtaguid_resTrack); | 133 | pthread_once(&resTrackInitDone, legacy_resTrack); |
152 | 134 | ||
153 | snprintf(lineBuf, sizeof(lineBuf), "d %" PRIu64 " %d", kTag, uid); | 135 | snprintf(lineBuf, sizeof(lineBuf), "d %" PRIu64 " %d", kTag, uid); |
154 | res = write_ctrl(lineBuf); | 136 | res = write_ctrl(lineBuf); |
@@ -159,16 +141,3 @@ int qtaguid_deleteTagData(int tag, uid_t uid) { | |||
159 | 141 | ||
160 | return res; | 142 | return res; |
161 | } | 143 | } |
162 | |||
163 | int qtaguid_setPacifier(int on) { | ||
164 | const char* value; | ||
165 | |||
166 | value = on ? "Y" : "N"; | ||
167 | if (write_param(GLOBAL_PACIFIER_PARAM, value) < 0) { | ||
168 | return -errno; | ||
169 | } | ||
170 | if (write_param(TAG_PACIFIER_PARAM, value) < 0) { | ||
171 | return -errno; | ||
172 | } | ||
173 | return 0; | ||
174 | } | ||