Merge changes Icfcc7ade,I1481cb8f,Ic2e8ca0d into main
* changes: Make RtNetlinkRouteMessage constructor visible for testing. Make StructRtMsg constructor visible for testing. Make NduseroptMessage constructor visible for testing.
This commit is contained in:
commit
f582074f69
3 changed files with 35 additions and 14 deletions
|
|
@ -20,6 +20,7 @@ import static android.system.OsConstants.AF_INET6;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
|
|
@ -63,6 +64,20 @@ public class NduseroptMessage extends NetlinkMessage {
|
|||
/** The IP address that sent the packet containing the option. */
|
||||
public final InetAddress srcaddr;
|
||||
|
||||
@VisibleForTesting
|
||||
public NduseroptMessage(@NonNull final StructNlMsgHdr header, byte family, int optslen,
|
||||
int ifindex, byte icmptype, byte icmpcode, @NonNull final NdOption option,
|
||||
final InetAddress srcaddr) {
|
||||
super(header);
|
||||
this.family = family;
|
||||
this.opts_len = optslen;
|
||||
this.ifindex = ifindex;
|
||||
this.icmp_type = icmptype;
|
||||
this.icmp_code = icmpcode;
|
||||
this.option = option;
|
||||
this.srcaddr = srcaddr;
|
||||
}
|
||||
|
||||
NduseroptMessage(@NonNull StructNlMsgHdr header, @NonNull ByteBuffer buf)
|
||||
throws UnknownHostException {
|
||||
super(header);
|
||||
|
|
|
|||
|
|
@ -19,10 +19,8 @@ package com.android.net.module.util.netlink;
|
|||
import static android.system.OsConstants.AF_INET;
|
||||
import static android.system.OsConstants.AF_INET6;
|
||||
|
||||
import static android.system.OsConstants.NETLINK_ROUTE;
|
||||
import static com.android.net.module.util.NetworkStackConstants.IPV4_ADDR_ANY;
|
||||
import static com.android.net.module.util.NetworkStackConstants.IPV6_ADDR_ANY;
|
||||
import static com.android.net.module.util.netlink.NetlinkConstants.hexify;
|
||||
import static com.android.net.module.util.netlink.NetlinkConstants.RTNL_FAMILY_IP6MR;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
|
@ -38,9 +36,6 @@ import java.net.Inet4Address;
|
|||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A NetlinkMessage subclass for rtnetlink route messages.
|
||||
|
|
@ -86,18 +81,27 @@ public class RtNetlinkRouteMessage extends NetlinkMessage {
|
|||
private long mSinceLastUseMillis; // Milliseconds since the route was used,
|
||||
// for resolved multicast routes
|
||||
|
||||
public RtNetlinkRouteMessage(StructNlMsgHdr header, StructRtMsg rtMsg) {
|
||||
|
||||
@VisibleForTesting
|
||||
public RtNetlinkRouteMessage(final StructNlMsgHdr header, final StructRtMsg rtMsg,
|
||||
final IpPrefix source, final IpPrefix destination, final InetAddress gateway,
|
||||
int iif, int oif, final StructRtaCacheInfo cacheInfo) {
|
||||
super(header);
|
||||
mRtmsg = rtMsg;
|
||||
mSource = null;
|
||||
mDestination = null;
|
||||
mGateway = null;
|
||||
mIifIndex = 0;
|
||||
mOifIndex = 0;
|
||||
mRtaCacheInfo = null;
|
||||
mSource = source;
|
||||
mDestination = destination;
|
||||
mGateway = gateway;
|
||||
mIifIndex = iif;
|
||||
mOifIndex = oif;
|
||||
mRtaCacheInfo = cacheInfo;
|
||||
mSinceLastUseMillis = -1;
|
||||
}
|
||||
|
||||
public RtNetlinkRouteMessage(StructNlMsgHdr header, StructRtMsg rtMsg) {
|
||||
this(header, rtMsg, null /* source */, null /* destination */, null /* gateway */,
|
||||
0 /* iif */, 0 /* oif */, null /* cacheInfo */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rtnetlink family.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package com.android.net.module.util.netlink;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.net.module.util.Struct;
|
||||
import com.android.net.module.util.Struct.Field;
|
||||
|
|
@ -57,8 +58,9 @@ public class StructRtMsg extends Struct {
|
|||
@Field(order = 8, type = Type.U32)
|
||||
public final long flags;
|
||||
|
||||
StructRtMsg(short family, short dstLen, short srcLen, short tos, short table, short protocol,
|
||||
short scope, short type, long flags) {
|
||||
@VisibleForTesting
|
||||
public StructRtMsg(short family, short dstLen, short srcLen, short tos, short table,
|
||||
short protocol, short scope, short type, long flags) {
|
||||
this.family = family;
|
||||
this.dstLen = dstLen;
|
||||
this.srcLen = srcLen;
|
||||
|
|
|
|||
Loading…
Reference in a new issue