clat: just always set mark unconditionally
Setting SO_MARK to MARK_UNSET, ie. 0, is harmless,
since the default for a brand new socket is already 0.
Setsockopt(SOL_SOCKET, SO_MARK) requires NET_RAW or NET_ADMIN,
while socket(AF_INET6, SOCK_RAW) already requires NET_RAW,
so we should already have the permission.
This allows us to get rid of an extra #define MARK_UNSET definition.
Additionally in practice mark should never be 0 anyway,
since we desire the socket to be flagged as having PERMISSION_SYSTEM
(if it's not routing will break if upstream device is on a restricted
network).
See ClatCoordinator.java getFwMark() for the mark we actually pass in,
which is guaranteed to have at least 4 bits (16,17,18,19) set.
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I834f4f1d331bfa88f56593c9cc1abef15d94d185
diff --git a/service/jni/com_android_server_connectivity_ClatCoordinator.cpp b/service/jni/com_android_server_connectivity_ClatCoordinator.cpp
index 18d2311..2c56d6c 100644
--- a/service/jni/com_android_server_connectivity_ClatCoordinator.cpp
+++ b/service/jni/com_android_server_connectivity_ClatCoordinator.cpp
@@ -36,9 +36,6 @@
#include "libclat/clatutils.h"
#include "nativehelper/scoped_utf_chars.h"
-// Sync from system/netd/include/netid_client.h
-#define MARK_UNSET 0u
-
// Sync from system/netd/server/NetdConstants.h
#define __INT_STRLEN(i) sizeof(#i)
#define _INT_STRLEN(i) __INT_STRLEN(i)
@@ -197,7 +194,7 @@
}
// TODO: check the mark validation
- if (mark != MARK_UNSET && setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
+ if (setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
throwIOException(env, "could not set mark on raw socket", errno);
close(sock);
return -1;