Fix sll_protocol in DhcpClient packet socket
The broadcast socket address was created with a deprecated API that does
not set sll_protocol. This causes packets to be filtered incorrectly in
packet capture, typically with tcpdump.
This change only affects device with API > Q, since Q does not have the
proper API to set the protocol.
Also includes fixing the build path that was referencing apishim/current
(which does not exist) instead of apishim/30 (the correct directory).
SocketUtilsShim can be used on the system_current target with that fix.
See change: I07887b82e0e32aadb0cbb9f930f2b2fa3e277ca9
Bug: 133196453
Test: manual; on AOSP with the new build, packet capture has the right
protocol. When installed on a Q release build, behavior is
unchanged.
Change-Id: Iaafd0b3935473b1cfab61b49b2f107e71e01de2d
diff --git a/Android.bp b/Android.bp
index f17f1b1..35eaf6c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -59,7 +59,7 @@
srcs: [
"apishim/common/**/*.java",
"apishim/29/**/*.java",
- "apishim/current/**/*.java",
+ "apishim/30/**/*.java",
":net-module-utils-srcs",
],
}
diff --git a/apishim/30/com/android/networkstack/apishim/SocketUtilsShimImpl.java b/apishim/30/com/android/networkstack/apishim/SocketUtilsShimImpl.java
index 9516e7c..748878a 100644
--- a/apishim/30/com/android/networkstack/apishim/SocketUtilsShimImpl.java
+++ b/apishim/30/com/android/networkstack/apishim/SocketUtilsShimImpl.java
@@ -44,7 +44,6 @@
@Override
public SocketAddress makePacketSocketAddress(
int protocol, int ifIndex, @NonNull byte[] hwAddr) {
- // TODO: use new API (which takes protocol, ifIndex, hwAddr) once implemented
- return SocketUtils.makePacketSocketAddress(ifIndex, hwAddr);
+ return SocketUtils.makePacketSocketAddress(protocol, ifIndex, hwAddr);
}
}
diff --git a/src/android/net/dhcp/DhcpClient.java b/src/android/net/dhcp/DhcpClient.java
index 0d56d63..889bfce 100644
--- a/src/android/net/dhcp/DhcpClient.java
+++ b/src/android/net/dhcp/DhcpClient.java
@@ -82,6 +82,7 @@
import com.android.internal.util.TrafficStatsConstants;
import com.android.internal.util.WakeupMessage;
import com.android.networkstack.R;
+import com.android.networkstack.apishim.SocketUtilsShimImpl;
import java.io.FileDescriptor;
import java.io.IOException;
@@ -389,7 +390,8 @@
}
mHwAddr = mIface.macAddr.toByteArray();
- mInterfaceBroadcastAddr = makePacketSocketAddress(mIface.index, DhcpPacket.ETHER_BROADCAST);
+ mInterfaceBroadcastAddr = SocketUtilsShimImpl.newInstance().makePacketSocketAddress(
+ ETH_P_IP, mIface.index, DhcpPacket.ETHER_BROADCAST);
return true;
}