Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,20 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {
allChannels.add(ctx.channel());
addCnxn(cnxn);
}

if (ctx.channel().pipeline().get(SslHandler.class) == null) {
SocketAddress remoteAddress = cnxn.getChannel().remoteAddress();
if (remoteAddress != null
&& !((InetSocketAddress) remoteAddress).getAddress().isLoopbackAddress()) {
LOG.trace("NettyChannelHandler channelActive: remote={} local={}", remoteAddress, cnxn.getChannel().localAddress());
zkServer.serverStats().incrementNonMTLSRemoteConnCount();
if (zkServer != null) {
SocketAddress remoteAddress = cnxn.getChannel().remoteAddress();
if (remoteAddress != null
&& !((InetSocketAddress) remoteAddress).getAddress().isLoopbackAddress()) {
LOG.trace("NettyChannelHandler channelActive: remote={} local={}", remoteAddress, cnxn.getChannel().localAddress());
zkServer.serverStats().incrementNonMTLSRemoteConnCount();
} else {
zkServer.serverStats().incrementNonMTLSLocalConnCount();
}
} else {
zkServer.serverStats().incrementNonMTLSLocalConnCount();
LOG.trace("Opened non-TLS connection from {} but zkServer is not running",
cnxn.getChannel().remoteAddress());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,22 @@ public void testNonMTLSLocalConn() throws IOException, InterruptedException, Kee
}
}

@SuppressWarnings("unchecked")
@Test
public void testNonMTLSRemoteConn() throws Exception {
LeaderZooKeeperServer zks = mock(LeaderZooKeeperServer.class);
when(zks.isRunning()).thenReturn(true);
ServerStats.Provider providerMock = mock(ServerStats.Provider.class);
when(zks.serverStats()).thenReturn(new ServerStats(providerMock));
testNonMTLSRemoteConn(zks);
}

@Test
public void testNonMTLSRemoteConnZookKeeperServerNotReady() throws Exception {
testNonMTLSRemoteConn(null);
}

@SuppressWarnings("unchecked")
private void testNonMTLSRemoteConn(ZooKeeperServer zks) throws Exception {
Channel channel = mock(Channel.class);
ChannelId id = mock(ChannelId.class);
ChannelFuture success = mock(ChannelFuture.class);
Expand All @@ -192,23 +205,18 @@ public void testNonMTLSRemoteConn() throws Exception {
when(channel.remoteAddress()).thenReturn(address);
when(channel.id()).thenReturn(id);
NettyServerCnxnFactory factory = new NettyServerCnxnFactory();
LeaderZooKeeperServer zks = mock(LeaderZooKeeperServer.class);
factory.setZooKeeperServer(zks);
Attribute atr = mock(Attribute.class);
Mockito.doReturn(atr).when(channel).attr(
Mockito.any()
);
doNothing().when(atr).set(Mockito.any());

when(zks.isRunning()).thenReturn(true);

ServerStats.Provider providerMock = mock(ServerStats.Provider.class);
when(zks.serverStats()).thenReturn(new ServerStats(providerMock));

factory.channelHandler.channelActive(context);

assertEquals(0, zks.serverStats().getNonMTLSLocalConnCount());
assertEquals(1, zks.serverStats().getNonMTLSRemoteConnCount());
if (zks != null) {
assertEquals(0, zks.serverStats().getNonMTLSLocalConnCount());
assertEquals(1, zks.serverStats().getNonMTLSRemoteConnCount());
}
}

@Test
Expand Down