From 83548e6690a4ad198e72c4140f22e9653127421f Mon Sep 17 00:00:00 2001 From: Sarup Dalwani Date: Sun, 17 Aug 2025 04:24:45 +0000 Subject: [PATCH] Refactor IngressDiscardKey to support generic IP addresses Updated IngressDiscardKey to use Type.IpAddress for its BPF destination address field (dstAddr) and java.net.InetAddress for its corresponding Java field Bug: 392509494 Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.BpfNetMapsTest Flag: EXEMPT refactor Change-Id: I24b3087c3c7f2ea25afe0f78729e01a7504e13cb --- .../module/util/bpf/IngressDiscardKey.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/common/src/com/android/net/module/util/bpf/IngressDiscardKey.java b/common/src/com/android/net/module/util/bpf/IngressDiscardKey.java index 9fefb521d9..b8c629457f 100644 --- a/common/src/com/android/net/module/util/bpf/IngressDiscardKey.java +++ b/common/src/com/android/net/module/util/bpf/IngressDiscardKey.java @@ -16,30 +16,17 @@ package com.android.net.module.util.bpf; -import com.android.net.module.util.InetAddressUtils; import com.android.net.module.util.Struct; -import java.net.Inet4Address; -import java.net.Inet6Address; import java.net.InetAddress; /** Key type for ingress discard map */ public class IngressDiscardKey extends Struct { - // The destination ip of the incoming packet. IPv4 uses IPv4-mapped IPv6 address. - @Field(order = 0, type = Type.Ipv6Address) - public final Inet6Address dstAddr; + @Field(order = 0, type = Type.IpAddress) + public final InetAddress dstAddr; - public IngressDiscardKey(final Inet6Address dstAddr) { + public IngressDiscardKey(final InetAddress dstAddr) { this.dstAddr = dstAddr; } - private static Inet6Address getInet6Address(final InetAddress addr) { - return (addr instanceof Inet4Address) - ? InetAddressUtils.v4MappedV6Address((Inet4Address) addr) - : (Inet6Address) addr; - } - - public IngressDiscardKey(final InetAddress dstAddr) { - this(getInet6Address(dstAddr)); - } }