diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CommunityIdProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CommunityIdProcessor.java index f37fcf46979dc..926710a87832a 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CommunityIdProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CommunityIdProcessor.java @@ -229,11 +229,11 @@ private static Flow buildFlow( switch (flow.protocol.getType()) { case Tcp, Udp, Sctp -> { flow.sourcePort = parseIntFromObjectOrString(sourcePort.get(), "source port"); - if (flow.sourcePort < 1 || flow.sourcePort > 65535) { + if (flow.sourcePort < 0 || flow.sourcePort > 65535) { throw new IllegalArgumentException("invalid source port [" + sourcePort.get() + "]"); } flow.destinationPort = parseIntFromObjectOrString(destinationPort.get(), "destination port"); - if (flow.destinationPort < 1 || flow.destinationPort > 65535) { + if (flow.destinationPort < 0 || flow.destinationPort > 65535) { throw new IllegalArgumentException("invalid destination port [" + destinationPort.get() + "]"); } } @@ -268,7 +268,7 @@ static byte[] toUint16(int num) { */ private static int parseIntFromObjectOrString(Object o, String fieldName) { if (o == null) { - return 0; + return -1; } else if (o instanceof Number number) { return number.intValue(); } else if (o instanceof String string) { diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CommunityIdProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CommunityIdProcessorTests.java index 72771275743b0..be39a0a802020 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CommunityIdProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CommunityIdProcessorTests.java @@ -83,7 +83,7 @@ public void testBeatsInvalidSourceIp() { public void testBeatsInvalidSourcePort() { @SuppressWarnings("unchecked") var source = (Map) event.get("source"); - source.put("port", 0); + source.put("port", -1); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testProcessor(event, null)); assertThat(e.getMessage(), containsString("invalid source port")); } @@ -302,9 +302,9 @@ public void testInvalidPort() { event = buildEvent(); @SuppressWarnings("unchecked") var source = (Map) event.get("source"); - source.put("port", 0); + source.put("port", -1); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testProcessor(event, null)); - assertThat(e.getMessage(), containsString("invalid source port [0]")); + assertThat(e.getMessage(), containsString("invalid source port [-1]")); event = buildEvent(); @SuppressWarnings("unchecked") @@ -316,9 +316,9 @@ public void testInvalidPort() { event = buildEvent(); @SuppressWarnings("unchecked") var source3 = (Map) event.get("destination"); - source3.put("port", 0); + source3.put("port", -1); e = expectThrows(IllegalArgumentException.class, () -> testProcessor(event, null)); - assertThat(e.getMessage(), containsString("invalid destination port [0]")); + assertThat(e.getMessage(), containsString("invalid destination port [-1]")); event = buildEvent(); @SuppressWarnings("unchecked")