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

added metadata fields for M-NOTIFY #2733

Merged
merged 1 commit into from
Feb 17, 2025
Merged
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
3 changes: 3 additions & 0 deletions src/include/ndpi_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ struct ndpi_packet_struct {
struct ndpi_int_one_line_struct location_smart_speaker_audio;
struct ndpi_int_one_line_struct nt;
struct ndpi_int_one_line_struct nts;
struct ndpi_int_one_line_struct man;
struct ndpi_int_one_line_struct mx;
struct ndpi_int_one_line_struct st;

u_int16_t l3_packet_len;
u_int16_t payload_packet_len;
Expand Down
4 changes: 4 additions & 0 deletions src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,10 @@ struct ndpi_flow_struct {
char *nt;
char *nts;
char *server;
char *man;
char *mx;
char *st;
char *user_agent;
} ssdp;
} protos;

Expand Down
23 changes: 23 additions & 0 deletions src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6906,6 +6906,18 @@ void ndpi_free_flow_data(struct ndpi_flow_struct* flow) {

if(flow->protos.ssdp.method)
ndpi_free(flow->protos.ssdp.method);

if(flow->protos.ssdp.man)
ndpi_free(flow->protos.ssdp.man);

if(flow->protos.ssdp.mx)
ndpi_free(flow->protos.ssdp.mx);

if(flow->protos.ssdp.st)
ndpi_free(flow->protos.ssdp.st);

if(flow->protos.ssdp.user_agent)
ndpi_free(flow->protos.ssdp.user_agent);
}

if(flow->tls_quic.message[0].buffer)
Expand Down Expand Up @@ -8550,6 +8562,9 @@ static void ndpi_reset_packet_line_info(struct ndpi_packet_struct *packet) {
packet->location_smart_speaker_audio.ptr = NULL, packet->location_smart_speaker_audio.len = 0;
packet->nt.ptr = NULL, packet->nt.len = 0;
packet->nts.ptr = NULL, packet->nts.len = 0;
packet->man.ptr = NULL, packet->man.len = 0;
packet->mx.ptr = NULL, packet->mx.len = 0;
packet->st.ptr = NULL, packet->st.len = 0;
}

/* ********************************************************************************* */
Expand Down Expand Up @@ -9319,10 +9334,14 @@ static void parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_s
{ NULL, NULL} };
struct header_line headers_s[] = { { "Server:", &packet->server_line },
{ "SECURELOCATION.UPNP.ORG:", &packet->securelocation_upnp },
{ "ST", &packet->st },
{ NULL, NULL} };
struct header_line headers_l[] = { { "LOCATION:", &packet->location },
{ "LOCATION.SMARTSPEAKER.AUDIO:", &packet->location_smart_speaker_audio },
{ NULL, NULL}};
struct header_line headers_m[] = { { "MAN:", &packet->man },
{ "MX:", &packet->mx },
{ NULL, NULL}};
struct header_line headers_n[] = { { "NT:", &packet->nt },
{ "NTS:", &packet->nts },
{ NULL, NULL}};
Expand Down Expand Up @@ -9390,6 +9409,10 @@ static void parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_s
case 'L':
hs = headers_l;
break;
case 'm':
case 'M':
hs = headers_m;
break;
case 'n':
case 'N':
hs = headers_n;
Expand Down
16 changes: 16 additions & 0 deletions src/lib/ndpi_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,22 @@ int ndpi_dpi2json(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_serialize_string_string(serializer, "X-SONOS-HHSECURELOCATION", flow->protos.ssdp.sonos_securelocation);
}

if (flow->protos.ssdp.man) {
ndpi_serialize_string_string(serializer, "MAN", flow->protos.ssdp.man);
}

if (flow->protos.ssdp.mx) {
ndpi_serialize_string_string(serializer, "MX", flow->protos.ssdp.mx);
}

if (flow->protos.ssdp.st) {
ndpi_serialize_string_string(serializer, "ST", flow->protos.ssdp.st);
}

if (flow->protos.ssdp.user_agent) {
ndpi_serialize_string_string(serializer, "USER_AGENT", flow->protos.ssdp.user_agent);
}

ndpi_serialize_end_of_block(serializer);
break;

Expand Down
32 changes: 32 additions & 0 deletions src/lib/protocols/ssdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,38 @@ static void ssdp_parse_lines(struct ndpi_detection_module_struct
flow->protos.ssdp.server[packet->server_line.len] = '\0';
}
}

if (packet->man.ptr != NULL && packet->man.len > 0) {
flow->protos.ssdp.man = ndpi_malloc(packet->man.len + 1);
if (flow->protos.ssdp.man) {
memcpy(flow->protos.ssdp.man, packet->man.ptr, packet->man.len);
flow->protos.ssdp.man[packet->man.len] = '\0';
}
}

if (packet->mx.ptr != NULL && packet->mx.len > 0) {
flow->protos.ssdp.mx = ndpi_malloc(packet->mx.len + 1);
if (flow->protos.ssdp.mx) {
memcpy(flow->protos.ssdp.mx, packet->mx.ptr, packet->mx.len);
flow->protos.ssdp.mx[packet->mx.len] = '\0';
}
}

if (packet->st.ptr != NULL && packet->st.len > 0) {
flow->protos.ssdp.st = ndpi_malloc(packet->st.len + 1);
if (flow->protos.ssdp.st) {
memcpy(flow->protos.ssdp.st, packet->st.ptr, packet->st.len);
flow->protos.ssdp.st[packet->st.len] = '\0';
}
}

if (packet->user_agent_line.ptr != NULL && packet->user_agent_line.len > 0) {
flow->protos.ssdp.user_agent = ndpi_malloc(packet->user_agent_line.len + 1);
if (flow->protos.ssdp.user_agent) {
memcpy(flow->protos.ssdp.user_agent, packet->user_agent_line.ptr, packet->user_agent_line.len);
flow->protos.ssdp.user_agent[packet->user_agent_line.len] = '\0';
}
}
}

static void ndpi_int_ssdp_add_connection(struct ndpi_detection_module_struct
Expand Down
Loading