Support getting fwmark for a network
NetworkStack will use the tcp info queried from kernel to
diagnose internet health. The diagnosis should only focus on
specific network, e.g. default network. NetworkStack needs a way
to filter the target network. The only identifier is the fwmark
value for each socket. The fwmark calculation may be modified
in native and may not sync with NetworkStack. Thus, NetworkStack
will need a way to get the netId mask and the network fwmark to
know the network information contained in the fwmark. Expose this
function to ensure the fwmark implementation is aligned wih netd.
Bug: 130325409
Test: cd system/netd; atest
Change-Id: I52fba39e041490016224beffb273693e64ce4338
diff --git a/server/Android.bp b/server/Android.bp
index 1bea8a0..e0d3545 100644
--- a/server/Android.bp
+++ b/server/Android.bp
@@ -30,6 +30,7 @@
// AIDL interface that callers can implement to receive networking events from netd.
"binder/android/net/INetdUnsolicitedEventListener.aidl",
"binder/android/net/InterfaceConfigurationParcel.aidl",
+ "binder/android/net/MarkMaskParcel.aidl",
"binder/android/net/TetherStatsParcel.aidl",
"binder/android/net/UidRangeParcel.aidl",
],
diff --git a/server/NetdNativeService.cpp b/server/NetdNativeService.cpp
index 9aec5e2..9e217f5 100644
--- a/server/NetdNativeService.cpp
+++ b/server/NetdNativeService.cpp
@@ -37,6 +37,7 @@
#include "BinderUtil.h"
#include "Controllers.h"
+#include "Fwmark.h"
#include "InterfaceController.h"
#include "NetdNativeService.h"
#include "NetdPermissions.h"
@@ -1188,5 +1189,15 @@
return binder::Status::ok();
}
+binder::Status NetdNativeService::getFwmarkForNetwork(int32_t netId, MarkMaskParcel* markMask) {
+ ENFORCE_NETWORK_STACK_PERMISSIONS();
+
+ Fwmark fwmark;
+ fwmark.netId = netId;
+ markMask->mask = FWMARK_NET_ID_MASK;
+ markMask->mark = fwmark.intValue;
+ return binder::Status::ok();
+}
+
} // namespace net
} // namespace android
diff --git a/server/NetdNativeService.h b/server/NetdNativeService.h
index 8f9c40f..72b85ef 100644
--- a/server/NetdNativeService.h
+++ b/server/NetdNativeService.h
@@ -250,6 +250,7 @@
const android::sp<android::net::INetdUnsolicitedEventListener>& listener) override;
binder::Status getOemNetd(android::sp<android::IBinder>* listener) override;
+ binder::Status getFwmarkForNetwork(int32_t netId, MarkMaskParcel* markmask);
private:
std::vector<uid_t> intsToUids(const std::vector<int32_t>& intUids);
diff --git a/server/binder/android/net/INetd.aidl b/server/binder/android/net/INetd.aidl
index fdea52e..ccdafc0 100644
--- a/server/binder/android/net/INetd.aidl
+++ b/server/binder/android/net/INetd.aidl
@@ -18,6 +18,7 @@
import android.net.INetdUnsolicitedEventListener;
import android.net.InterfaceConfigurationParcel;
+import android.net.MarkMaskParcel;
import android.net.TetherStatsParcel;
import android.net.UidRangeParcel;
@@ -1208,4 +1209,12 @@
*/
void tetherStartWithConfiguration(
boolean usingLegacyDnsProxy, in @utf8InCpp String[] dhcpRanges);
+
+ /**
+ * Get the fwmark and its net id mask for the given network id.
+ *
+ * @param netId the network to get the fwmark and mask for.
+ * @return A MarkMaskParcel of the given network id.
+ */
+ MarkMaskParcel getFwmarkForNetwork(int netId);
}
diff --git a/server/binder/android/net/MarkMaskParcel.aidl b/server/binder/android/net/MarkMaskParcel.aidl
new file mode 100644
index 0000000..932b7bf
--- /dev/null
+++ b/server/binder/android/net/MarkMaskParcel.aidl
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package android.net;
+
+/**
+ * Structure that stores a firewall mark and its mask.
+ *
+ * {@hide}
+ */
+parcelable MarkMaskParcel {
+ // The fwmark.
+ int mark;
+ // Net id mask of fwmark.
+ int mask;
+}