Merge "Rename method connectSocketToNetlink to connectToKernel" into main
This commit is contained in:
@@ -900,7 +900,7 @@ public class AutomaticOnOffKeepaliveTracker {
|
|||||||
public FileDescriptor createConnectedNetlinkSocket()
|
public FileDescriptor createConnectedNetlinkSocket()
|
||||||
throws ErrnoException, SocketException {
|
throws ErrnoException, SocketException {
|
||||||
final FileDescriptor fd = NetlinkUtils.createNetLinkInetDiagSocket();
|
final FileDescriptor fd = NetlinkUtils.createNetLinkInetDiagSocket();
|
||||||
NetlinkUtils.connectSocketToNetlink(fd);
|
NetlinkUtils.connectToKernel(fd);
|
||||||
Os.setsockoptTimeval(fd, SOL_SOCKET, SO_SNDTIMEO,
|
Os.setsockoptTimeval(fd, SOL_SOCKET, SO_SNDTIMEO,
|
||||||
StructTimeval.fromMillis(IO_TIMEOUT_MS));
|
StructTimeval.fromMillis(IO_TIMEOUT_MS));
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class NetlinkMonitor extends PacketReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Os.bind(fd, makeNetlinkSocketAddress(0, mBindGroups));
|
Os.bind(fd, makeNetlinkSocketAddress(0, mBindGroups));
|
||||||
NetlinkUtils.connectSocketToNetlink(fd);
|
NetlinkUtils.connectToKernel(fd);
|
||||||
|
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
final SocketAddress nlAddr = Os.getsockname(fd);
|
final SocketAddress nlAddr = Os.getsockname(fd);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import static com.android.net.module.util.netlink.NetlinkConstants.stringForProt
|
|||||||
import static com.android.net.module.util.netlink.NetlinkUtils.DEFAULT_RECV_BUFSIZE;
|
import static com.android.net.module.util.netlink.NetlinkUtils.DEFAULT_RECV_BUFSIZE;
|
||||||
import static com.android.net.module.util.netlink.NetlinkUtils.IO_TIMEOUT_MS;
|
import static com.android.net.module.util.netlink.NetlinkUtils.IO_TIMEOUT_MS;
|
||||||
import static com.android.net.module.util.netlink.NetlinkUtils.TCP_ALIVE_STATE_FILTER;
|
import static com.android.net.module.util.netlink.NetlinkUtils.TCP_ALIVE_STATE_FILTER;
|
||||||
import static com.android.net.module.util.netlink.NetlinkUtils.connectSocketToNetlink;
|
import static com.android.net.module.util.netlink.NetlinkUtils.connectToKernel;
|
||||||
import static com.android.net.module.util.netlink.StructNlMsgHdr.NLM_F_DUMP;
|
import static com.android.net.module.util.netlink.StructNlMsgHdr.NLM_F_DUMP;
|
||||||
import static com.android.net.module.util.netlink.StructNlMsgHdr.NLM_F_REQUEST;
|
import static com.android.net.module.util.netlink.StructNlMsgHdr.NLM_F_REQUEST;
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ public class InetDiagMessage extends NetlinkMessage {
|
|||||||
FileDescriptor fd = null;
|
FileDescriptor fd = null;
|
||||||
try {
|
try {
|
||||||
fd = NetlinkUtils.netlinkSocketForProto(NETLINK_INET_DIAG);
|
fd = NetlinkUtils.netlinkSocketForProto(NETLINK_INET_DIAG);
|
||||||
NetlinkUtils.connectSocketToNetlink(fd);
|
connectToKernel(fd);
|
||||||
uid = lookupUid(protocol, local, remote, fd);
|
uid = lookupUid(protocol, local, remote, fd);
|
||||||
} catch (ErrnoException | SocketException | IllegalArgumentException
|
} catch (ErrnoException | SocketException | IllegalArgumentException
|
||||||
| InterruptedIOException e) {
|
| InterruptedIOException e) {
|
||||||
@@ -426,8 +426,8 @@ public class InetDiagMessage extends NetlinkMessage {
|
|||||||
try {
|
try {
|
||||||
dumpFd = NetlinkUtils.createNetLinkInetDiagSocket();
|
dumpFd = NetlinkUtils.createNetLinkInetDiagSocket();
|
||||||
destroyFd = NetlinkUtils.createNetLinkInetDiagSocket();
|
destroyFd = NetlinkUtils.createNetLinkInetDiagSocket();
|
||||||
connectSocketToNetlink(dumpFd);
|
connectToKernel(dumpFd);
|
||||||
connectSocketToNetlink(destroyFd);
|
connectToKernel(destroyFd);
|
||||||
|
|
||||||
for (int family : List.of(AF_INET, AF_INET6)) {
|
for (int family : List.of(AF_INET, AF_INET6)) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class NetlinkUtils {
|
|||||||
final FileDescriptor fd = netlinkSocketForProto(nlProto);
|
final FileDescriptor fd = netlinkSocketForProto(nlProto);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connectSocketToNetlink(fd);
|
connectToKernel(fd);
|
||||||
sendMessage(fd, msg, 0, msg.length, IO_TIMEOUT_MS);
|
sendMessage(fd, msg, 0, msg.length, IO_TIMEOUT_MS);
|
||||||
receiveNetlinkAck(fd);
|
receiveNetlinkAck(fd);
|
||||||
} catch (InterruptedIOException e) {
|
} catch (InterruptedIOException e) {
|
||||||
@@ -244,7 +244,7 @@ public class NetlinkUtils {
|
|||||||
* @throws ErrnoException if the {@code fd} could not connect to kernel successfully
|
* @throws ErrnoException if the {@code fd} could not connect to kernel successfully
|
||||||
* @throws SocketException if there is an error accessing a socket.
|
* @throws SocketException if there is an error accessing a socket.
|
||||||
*/
|
*/
|
||||||
public static void connectSocketToNetlink(FileDescriptor fd)
|
public static void connectToKernel(@NonNull FileDescriptor fd)
|
||||||
throws ErrnoException, SocketException {
|
throws ErrnoException, SocketException {
|
||||||
Os.connect(fd, makeNetlinkSocketAddress(0, 0));
|
Os.connect(fd, makeNetlinkSocketAddress(0, 0));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class NetlinkUtilsTest {
|
|||||||
final FileDescriptor fd = NetlinkUtils.netlinkSocketForProto(NETLINK_ROUTE);
|
final FileDescriptor fd = NetlinkUtils.netlinkSocketForProto(NETLINK_ROUTE);
|
||||||
assertNotNull(fd);
|
assertNotNull(fd);
|
||||||
|
|
||||||
NetlinkUtils.connectSocketToNetlink(fd);
|
NetlinkUtils.connectToKernel(fd);
|
||||||
|
|
||||||
final NetlinkSocketAddress localAddr = (NetlinkSocketAddress) Os.getsockname(fd);
|
final NetlinkSocketAddress localAddr = (NetlinkSocketAddress) Os.getsockname(fd);
|
||||||
assertNotNull(localAddr);
|
assertNotNull(localAddr);
|
||||||
@@ -153,7 +153,7 @@ public class NetlinkUtilsTest {
|
|||||||
final FileDescriptor fd = NetlinkUtils.netlinkSocketForProto(NETLINK_ROUTE);
|
final FileDescriptor fd = NetlinkUtils.netlinkSocketForProto(NETLINK_ROUTE);
|
||||||
assertNotNull(fd);
|
assertNotNull(fd);
|
||||||
|
|
||||||
NetlinkUtils.connectSocketToNetlink(fd);
|
NetlinkUtils.connectToKernel(fd);
|
||||||
|
|
||||||
final NetlinkSocketAddress localAddr = (NetlinkSocketAddress) Os.getsockname(fd);
|
final NetlinkSocketAddress localAddr = (NetlinkSocketAddress) Os.getsockname(fd);
|
||||||
assertNotNull(localAddr);
|
assertNotNull(localAddr);
|
||||||
|
|||||||
Reference in New Issue
Block a user