Skip to content

Commit 0a84b00

Browse files
committed
Introduce support for pcap traffic capturing of network traffic
1 parent c3a3e92 commit 0a84b00

17 files changed

+257
-3
lines changed

src/main/generated/io/vertx/core/dns/DnsClientOptionsConverter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class DnsClientOptionsConverter {
2020
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, DnsClientOptions obj) {
2121
for (java.util.Map.Entry<String, Object> member : json) {
2222
switch (member.getKey()) {
23+
case "activityLogFormat":
24+
if (member.getValue() instanceof String) {
25+
obj.setActivityLogFormat(io.netty.handler.logging.ByteBufFormat.valueOf((String)member.getValue()));
26+
}
27+
break;
2328
case "host":
2429
if (member.getValue() instanceof String) {
2530
obj.setHost((String)member.getValue());
@@ -54,6 +59,9 @@ public static void toJson(DnsClientOptions obj, JsonObject json) {
5459
}
5560

5661
public static void toJson(DnsClientOptions obj, java.util.Map<String, Object> json) {
62+
if (obj.getActivityLogFormat() != null) {
63+
json.put("activityLogFormat", obj.getActivityLogFormat().name());
64+
}
5765
if (obj.getHost() != null) {
5866
json.put("host", obj.getHost());
5967
}

src/main/generated/io/vertx/core/eventbus/EventBusOptionsConverter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, EventBu
2525
obj.setAcceptBacklog(((Number)member.getValue()).intValue());
2626
}
2727
break;
28+
case "activityLogFormat":
29+
if (member.getValue() instanceof String) {
30+
obj.setActivityLogFormat(io.netty.handler.logging.ByteBufFormat.valueOf((String)member.getValue()));
31+
}
32+
break;
2833
case "clientAuth":
2934
if (member.getValue() instanceof String) {
3035
obj.setClientAuth(io.vertx.core.http.ClientAuth.valueOf((String)member.getValue()));
@@ -129,6 +134,11 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, EventBu
129134
obj.setOpenSslEngineOptions(new io.vertx.core.net.OpenSSLEngineOptions((io.vertx.core.json.JsonObject)member.getValue()));
130135
}
131136
break;
137+
case "pcapCaptureFile":
138+
if (member.getValue() instanceof String) {
139+
obj.setPcapCaptureFile((String)member.getValue());
140+
}
141+
break;
132142
case "pemKeyCertOptions":
133143
if (member.getValue() instanceof JsonObject) {
134144
obj.setPemKeyCertOptions(new io.vertx.core.net.PemKeyCertOptions((io.vertx.core.json.JsonObject)member.getValue()));
@@ -269,6 +279,9 @@ static void toJson(EventBusOptions obj, JsonObject json) {
269279

270280
static void toJson(EventBusOptions obj, java.util.Map<String, Object> json) {
271281
json.put("acceptBacklog", obj.getAcceptBacklog());
282+
if (obj.getActivityLogFormat() != null) {
283+
json.put("activityLogFormat", obj.getActivityLogFormat().name());
284+
}
272285
if (obj.getClientAuth() != null) {
273286
json.put("clientAuth", obj.getClientAuth().name());
274287
}
@@ -319,6 +332,9 @@ static void toJson(EventBusOptions obj, java.util.Map<String, Object> json) {
319332
if (obj.getOpenSslEngineOptions() != null) {
320333
json.put("openSslEngineOptions", obj.getOpenSslEngineOptions().toJson());
321334
}
335+
if (obj.getPcapCaptureFile() != null) {
336+
json.put("pcapCaptureFile", obj.getPcapCaptureFile());
337+
}
322338
if (obj.getPemKeyCertOptions() != null) {
323339
json.put("pemKeyCertOptions", obj.getPemKeyCertOptions().toJson());
324340
}

src/main/generated/io/vertx/core/net/NetworkOptionsConverter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@ public class NetworkOptionsConverter {
2020
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, NetworkOptions obj) {
2121
for (java.util.Map.Entry<String, Object> member : json) {
2222
switch (member.getKey()) {
23+
case "activityLogFormat":
24+
if (member.getValue() instanceof String) {
25+
obj.setActivityLogFormat(io.netty.handler.logging.ByteBufFormat.valueOf((String)member.getValue()));
26+
}
27+
break;
2328
case "logActivity":
2429
if (member.getValue() instanceof Boolean) {
2530
obj.setLogActivity((Boolean)member.getValue());
2631
}
2732
break;
33+
case "pcapCaptureFile":
34+
if (member.getValue() instanceof String) {
35+
obj.setPcapCaptureFile((String)member.getValue());
36+
}
37+
break;
2838
case "receiveBufferSize":
2939
if (member.getValue() instanceof Number) {
3040
obj.setReceiveBufferSize(((Number)member.getValue()).intValue());
@@ -59,7 +69,13 @@ static void toJson(NetworkOptions obj, JsonObject json) {
5969
}
6070

6171
static void toJson(NetworkOptions obj, java.util.Map<String, Object> json) {
72+
if (obj.getActivityLogFormat() != null) {
73+
json.put("activityLogFormat", obj.getActivityLogFormat().name());
74+
}
6275
json.put("logActivity", obj.getLogActivity());
76+
if (obj.getPcapCaptureFile() != null) {
77+
json.put("pcapCaptureFile", obj.getPcapCaptureFile());
78+
}
6379
json.put("receiveBufferSize", obj.getReceiveBufferSize());
6480
json.put("reuseAddress", obj.isReuseAddress());
6581
json.put("reusePort", obj.isReusePort());

src/main/java/io/vertx/core/datagram/DatagramSocketOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public DatagramSocketOptions setReusePort(boolean reusePort) {
136136
return (DatagramSocketOptions) super.setReusePort(reusePort);
137137
}
138138

139+
@Override
140+
public DatagramSocketOptions setPcapCaptureFile(String pcapCaptureFile) {
141+
return (DatagramSocketOptions) super.setPcapCaptureFile(pcapCaptureFile);
142+
}
143+
139144
@Override
140145
public int getTrafficClass() {
141146
return super.getTrafficClass();

src/main/java/io/vertx/core/datagram/impl/DatagramSocketImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.vertx.core.buffer.Buffer;
3131
import io.vertx.core.datagram.DatagramSocket;
3232
import io.vertx.core.datagram.DatagramSocketOptions;
33+
import io.vertx.core.http.impl.VertxPcapWriteHandler;
3334
import io.vertx.core.impl.AddressResolver;
3435
import io.vertx.core.impl.Arguments;
3536
import io.vertx.core.impl.ContextInternal;
@@ -81,6 +82,9 @@ private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) {
8182
if (options.getLogActivity()) {
8283
channel.pipeline().addLast("logging", new LoggingHandler(options.getActivityLogFormat()));
8384
}
85+
if ((options.getPcapCaptureFile() != null) && !options.getPcapCaptureFile().isEmpty()) {
86+
channel.pipeline().addLast("pcapCapturing", new VertxPcapWriteHandler(options.getPcapCaptureFile()));
87+
}
8488
VertxMetrics metrics = vertx.metricsSPI();
8589
this.metrics = metrics != null ? metrics.createDatagramSocketMetrics(options) : null;
8690
this.channel = channel;

src/main/java/io/vertx/core/eventbus/EventBusOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ public EventBusOptions setReusePort(boolean reusePort) {
440440
return this;
441441
}
442442

443+
@Override
444+
public EventBusOptions setPcapCaptureFile(String pcapCaptureFile) {
445+
super.setPcapCaptureFile(pcapCaptureFile);
446+
return this;
447+
}
448+
443449
@Override
444450
public EventBusOptions setSendBufferSize(int sendBufferSize) {
445451
super.setSendBufferSize(sendBufferSize);

src/main/java/io/vertx/core/http/HttpClientOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ public HttpClientOptions setReusePort(boolean reusePort) {
413413
return this;
414414
}
415415

416+
@Override
417+
public HttpClientOptions setPcapCaptureFile(String pcapCaptureFile) {
418+
super.setPcapCaptureFile(pcapCaptureFile);
419+
return this;
420+
}
421+
416422
@Override
417423
public HttpClientOptions setTrafficClass(int trafficClass) {
418424
super.setTrafficClass(trafficClass);

src/main/java/io/vertx/core/http/HttpServerOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ public HttpServerOptions setReusePort(boolean reusePort) {
284284
return this;
285285
}
286286

287+
@Override
288+
public HttpServerOptions setPcapCaptureFile(String pcapCaptureFile) {
289+
super.setPcapCaptureFile(pcapCaptureFile);
290+
return this;
291+
}
292+
287293
@Override
288294
public HttpServerOptions setTrafficClass(int trafficClass) {
289295
super.setTrafficClass(trafficClass);

src/main/java/io/vertx/core/http/impl/HttpChannelConnector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import io.vertx.core.net.SocketAddress;
3434
import io.vertx.core.net.impl.NetClientImpl;
3535
import io.vertx.core.net.impl.NetSocketImpl;
36-
import io.vertx.core.net.impl.NetSocketInternal;
3736
import io.vertx.core.net.impl.VertxHandler;
3837
import io.vertx.core.spi.metrics.ClientMetrics;
3938
import io.vertx.core.spi.metrics.HttpClientMetrics;
@@ -59,6 +58,7 @@ public class HttpChannelConnector {
5958
private final HttpVersion version;
6059
private final SocketAddress peerAddress;
6160
private final SocketAddress server;
61+
private final boolean enablePcapCapture;
6262

6363
public HttpChannelConnector(HttpClientImpl client,
6464
NetClientImpl netClient,
@@ -79,6 +79,7 @@ public HttpChannelConnector(HttpClientImpl client,
7979
this.version = version;
8080
this.peerAddress = peerAddress;
8181
this.server = server;
82+
this.enablePcapCapture = (options.getPcapCaptureFile() != null) && !options.getPcapCaptureFile().isEmpty();
8283
}
8384

8485
public SocketAddress server() {
@@ -166,6 +167,9 @@ private void applyHttp1xConnectionOptions(ChannelPipeline pipeline) {
166167
if (options.getLogActivity()) {
167168
pipeline.addLast("logging", new LoggingHandler(options.getActivityLogFormat()));
168169
}
170+
if (enablePcapCapture) {
171+
pipeline.addLast("pcapCapturing", new VertxPcapWriteHandler(options.getPcapCaptureFile()));
172+
}
169173
pipeline.addLast("codec", new HttpClientCodec(
170174
options.getMaxInitialLineLength(),
171175
options.getMaxHeaderSize(),

src/main/java/io/vertx/core/http/impl/HttpServerWorker.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
import io.vertx.core.net.impl.HAProxyMessageCompletionHandler;
3636
import io.vertx.core.spi.metrics.HttpServerMetrics;
3737

38+
import java.io.File;
39+
import java.io.FileNotFoundException;
40+
import java.io.FileOutputStream;
41+
import java.io.UncheckedIOException;
3842
import java.nio.charset.StandardCharsets;
3943
import java.util.function.Supplier;
4044

@@ -55,6 +59,7 @@ public class HttpServerWorker implements Handler<Channel> {
5559
private final String serverOrigin;
5660
private final boolean logEnabled;
5761
private final boolean disableH2C;
62+
private final boolean enablePcapCapture;
5863
final Handler<HttpServerConnection> connectionHandler;
5964
private final Handler<Throwable> exceptionHandler;
6065

@@ -77,6 +82,7 @@ public HttpServerWorker(EventLoopContext context,
7782
this.serverOrigin = serverOrigin;
7883
this.logEnabled = options.getLogActivity();
7984
this.disableH2C = disableH2C;
85+
this.enablePcapCapture = (options.getPcapCaptureFile() != null) && !options.getPcapCaptureFile().isEmpty();
8086
this.connectionHandler = connectionHandler;
8187
this.exceptionHandler = exceptionHandler;
8288
}
@@ -252,6 +258,9 @@ private void configureHttp1OrH2C(ChannelPipeline pipeline) {
252258
if (logEnabled) {
253259
pipeline.addLast("logging", new LoggingHandler());
254260
}
261+
if (enablePcapCapture) {
262+
pipeline.addLast("pcapCapturing", new VertxPcapWriteHandler(options.getPcapCaptureFile()));
263+
}
255264
if (HttpServerImpl.USE_FLASH_POLICY_HANDLER) {
256265
pipeline.addLast("flashpolicy", new FlashPolicyHandler());
257266
}

0 commit comments

Comments
 (0)