get rid of needless use of NONEXISTENT_COOKIE which is simply 0
The random grab bag of stuff in BpfUtils.h is weird, and I'm trying to trim it down. Since this is coming from the kernel, 0 meaning error / no socket is actually kernel api and thus guaranteed. IMHO if (!cookie) is also clearer to read. Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I433dfca5695a04a42d632b7e0c2434db26c4ed00
This commit is contained in:
parent
11dee200f9
commit
d3fe154610
2 changed files with 3 additions and 4 deletions
|
|
@ -32,7 +32,6 @@ namespace android {
|
|||
namespace net {
|
||||
|
||||
using base::unique_fd;
|
||||
using bpf::NONEXISTENT_COOKIE;
|
||||
using bpf::getSocketCookie;
|
||||
using bpf::retrieveProgram;
|
||||
using netdutils::Status;
|
||||
|
|
@ -185,7 +184,7 @@ int BpfHandler::tagSocket(int sockFd, uint32_t tag, uid_t chargeUid, uid_t realU
|
|||
}
|
||||
|
||||
uint64_t sock_cookie = getSocketCookie(sockFd);
|
||||
if (sock_cookie == NONEXISTENT_COOKIE) return -errno;
|
||||
if (!sock_cookie) return -errno;
|
||||
|
||||
UidTagValue newKey = {.uid = (uint32_t)chargeUid, .tag = tag};
|
||||
|
||||
|
|
@ -249,7 +248,7 @@ int BpfHandler::tagSocket(int sockFd, uint32_t tag, uid_t chargeUid, uid_t realU
|
|||
|
||||
int BpfHandler::untagSocket(int sockFd) {
|
||||
uint64_t sock_cookie = getSocketCookie(sockFd);
|
||||
if (sock_cookie == NONEXISTENT_COOKIE) return -errno;
|
||||
if (!sock_cookie) return -errno;
|
||||
|
||||
if (!mCookieTagMap.isValid()) return -EPERM;
|
||||
base::Result<void> res = mCookieTagMap.deleteValue(sock_cookie);
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@ static jlong com_android_server_connectivity_ClatCoordinator_getSocketCookie(
|
|||
}
|
||||
|
||||
uint64_t sock_cookie = bpf::getSocketCookie(sockFd);
|
||||
if (sock_cookie == bpf::NONEXISTENT_COOKIE) {
|
||||
if (!sock_cookie) {
|
||||
throwIOException(env, "get socket cookie failed", errno);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue