Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.0.x: backport commit to not log empty IP addresses and ports - v1 #12292

Open
wants to merge 1 commit into
base: main-7.0.x
Choose a base branch
from
Open
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
22 changes: 17 additions & 5 deletions src/output-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,10 @@ void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddr
case IPPROTO_SCTP:
addr->sp = sp;
addr->dp = dp;
addr->log_port = true;
break;
default:
addr->log_port = false;
break;
}

Expand Down Expand Up @@ -880,11 +882,21 @@ JsonBuilder *CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir,
JsonAddrInfoInit(p, dir, &addr_info);
addr = &addr_info;
}
jb_set_string(js, "src_ip", addr->src_ip);
jb_set_uint(js, "src_port", addr->sp);
jb_set_string(js, "dest_ip", addr->dst_ip);
jb_set_uint(js, "dest_port", addr->dp);
jb_set_string(js, "proto", addr->proto);
if (addr->src_ip[0] != '\0') {
jb_set_string(js, "src_ip", addr->src_ip);
}
if (addr->log_port) {
jb_set_uint(js, "src_port", addr->sp);
}
if (addr->dst_ip[0] != '\0') {
jb_set_string(js, "dest_ip", addr->dst_ip);
}
if (addr->log_port) {
jb_set_uint(js, "dest_port", addr->dp);
}
if (addr->proto[0] != '\0') {
jb_set_string(js, "proto", addr->proto);
}

/* icmp */
switch (p->proto) {
Expand Down
2 changes: 2 additions & 0 deletions src/output-json.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ typedef struct JsonAddrInfo_ {
Port sp;
Port dp;
char proto[JSON_PROTO_LEN];
// Ports are logged only when provided by the transport protocol.
bool log_port;
} JsonAddrInfo;

extern const JsonAddrInfo json_addr_info_zero;
Expand Down
Loading