lists.osmocom.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
List overview
Download
gerrit-log
January 2025
----- 2025 -----
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
gerrit-log@lists.osmocom.org
1 participants
1491 discussions
Start a n
N
ew thread
[S] Change in osmo-pcap[master]: Makefile.am: proper format and reorder source file lists
by pespin
pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39286?usp=email
) Change subject: Makefile.am: proper format and reorder source file lists ...................................................................... Makefile.am: proper format and reorder source file lists Change-Id: Ie39bd0348f4f329539c1d9dabc8fa87f3e4bbefe --- M include/osmo-pcap/Makefile.am M src/Makefile.am 2 files changed, 8 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/86/39286/1 diff --git a/include/osmo-pcap/Makefile.am b/include/osmo-pcap/Makefile.am index b71e70c..e377b6a 100644 --- a/include/osmo-pcap/Makefile.am +++ b/include/osmo-pcap/Makefile.am @@ -1 +1,7 @@ -noinst_HEADERS = common.h osmo_pcap_client.h osmo_pcap_server.h wireformat.h osmo_tls.h +noinst_HEADERS = \ + common.h \ + osmo_pcap_client.h \ + osmo_pcap_server.h \ + osmo_tls.h \ + wireformat.h \ + $(NULL) diff --git a/src/Makefile.am b/src/Makefile.am index b35227c..00c9ce9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,9 +17,9 @@ osmo_client_main.c \ osmo_common.c \ osmo_client_core.c \ - osmo_client_vty.c \ osmo_client_network.c \ osmo_client_stats.c \ + osmo_client_vty.c \ osmo_tls.c \ $(NULL) -- To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39286?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange Gerrit-Project: osmo-pcap Gerrit-Branch: master Gerrit-Change-Id: Ie39bd0348f4f329539c1d9dabc8fa87f3e4bbefe Gerrit-Change-Number: 39286 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
5 months, 2 weeks
1
0
0
0
[S] Change in osmo-pcap[master]: Cleanup and reorder includes in header files
by pespin
pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39285?usp=email
) Change subject: Cleanup and reorder includes in header files ...................................................................... Cleanup and reorder includes in header files Put all includes in same order of dependencies. Include stdint.h instead of inttypes.h since that's the file actually containing the standard int types. Change-Id: I0467d3c3a2687a7990c0db7371d0c89f97e8400a --- M include/osmo-pcap/osmo_pcap_client.h M include/osmo-pcap/osmo_pcap_server.h M include/osmo-pcap/osmo_tls.h M include/osmo-pcap/wireformat.h 4 files changed, 14 insertions(+), 15 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/85/39285/1 diff --git a/include/osmo-pcap/osmo_pcap_client.h b/include/osmo-pcap/osmo_pcap_client.h index 09a4674..442244e 100644 --- a/include/osmo-pcap/osmo_pcap_client.h +++ b/include/osmo-pcap/osmo_pcap_client.h @@ -21,8 +21,6 @@ */ #pragma once -#include "osmo_tls.h" - #include <inttypes.h> #include <pcap.h> @@ -32,6 +30,8 @@ #include <osmocom/core/rate_ctr.h> #include <osmocom/core/write_queue.h> +#include <osmo-pcap/osmo_tls.h> + #define WQUEUE_MAXLEN_DEFAULT 1000 enum pcap_client_ctr { diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h index 988ac96..da39d99 100644 --- a/include/osmo-pcap/osmo_pcap_server.h +++ b/include/osmo-pcap/osmo_pcap_server.h @@ -21,21 +21,20 @@ */ #pragma once -#include "wireformat.h" -#include "osmo_tls.h" - -#include <osmocom/core/select.h> -#include <osmocom/core/linuxlist.h> -#include <osmocom/core/write_queue.h> - +#include <stdbool.h> +#include <time.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <pcap.h> -#include <stdbool.h> -#include <time.h> +#include <osmocom/core/select.h> +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/write_queue.h> + +#include <osmo-pcap/wireformat.h> +#include <osmo-pcap/osmo_tls.h> struct rate_ctr_group; struct rate_ctr_group_desc; diff --git a/include/osmo-pcap/osmo_tls.h b/include/osmo-pcap/osmo_tls.h index 1b15168..716604e 100644 --- a/include/osmo-pcap/osmo_tls.h +++ b/include/osmo-pcap/osmo_tls.h @@ -20,12 +20,12 @@ */ #pragma once -#include <gnutls/gnutls.h> -#include <gnutls/abstract.h> - #include <stdbool.h> #include <stdint.h> +#include <gnutls/gnutls.h> +#include <gnutls/abstract.h> + struct osmo_fd; struct osmo_wqueue; struct osmo_pcap_client_conn; diff --git a/include/osmo-pcap/wireformat.h b/include/osmo-pcap/wireformat.h index 3838830..40b5b0e 100644 --- a/include/osmo-pcap/wireformat.h +++ b/include/osmo-pcap/wireformat.h @@ -21,7 +21,7 @@ */ #pragma once -#include <inttypes.h> +#include <stdint.h> #include <pcap.h> enum OsmoPcapDataType { -- To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39285?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange Gerrit-Project: osmo-pcap Gerrit-Branch: master Gerrit-Change-Id: I0467d3c3a2687a7990c0db7371d0c89f97e8400a Gerrit-Change-Number: 39285 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
5 months, 2 weeks
1
0
0
0
[L] Change in osmo-pcap[master]: server: Support storing of pcapng format
by pespin
pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39287?usp=email
) Change subject: server: Support storing of pcapng format ...................................................................... server: Support storing of pcapng format Improve existing logic doing validation on payload data and generalize the file_hdr field to account for the possibily of receiving recordings in pcapng format. This requires, during LINK_HDR when file header is received, discering whether the recording is being done in pcap vs pcapng, (and in pcapng figuring out the endianness of the file) and then applying validation based on that knowledge. With that knowledge, osmo-pcap-server can now store the pcap(ng) file using the proper suffix for the file. Related: SYS#5822 Change-Id: I275d28ab418a1514fa9c5c7c20f3d831cc6af8bb --- M include/osmo-pcap/osmo_pcap_file.h M include/osmo-pcap/osmo_pcap_server.h M src/Makefile.am M src/osmo_pcap_file.c M src/osmo_server_network.c M tests/rotate_localtime/Makefile.am 6 files changed, 335 insertions(+), 48 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/87/39287/1 diff --git a/include/osmo-pcap/osmo_pcap_file.h b/include/osmo-pcap/osmo_pcap_file.h index a12df89..3daad99 100644 --- a/include/osmo-pcap/osmo_pcap_file.h +++ b/include/osmo-pcap/osmo_pcap_file.h @@ -29,6 +29,8 @@ OSMO_PCAP_FMT_PCAPNG, }; +int osmo_pcap_file_discover_fmt(const uint8_t *data, size_t data_len, enum osmo_pcap_fmt *result_fmt); + /*********************************************************** * Libpcap File Format (.pcap) *
https://wiki.wireshark.org/Development/LibpcapFileFormat
@@ -123,6 +125,11 @@ /* ... Options ... */ } __attribute__((packed)); +int osmo_pcapng_file_is_swapped(const uint8_t *data, size_t data_len); +uint16_t osmo_pcapng_file_read_uint16(const uint8_t *data, bool endian_swapped); +uint32_t osmo_pcapng_file_read_uint32(const uint8_t *data, bool endian_swapped); +uint64_t osmo_pcapng_file_read_uint64(const uint8_t *data, bool endian_swapped); + /* Helper APIs to encode blocks: */ struct osmo_pcapng_file_shb_pars { diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h index da39d99..f44781a 100644 --- a/include/osmo-pcap/osmo_pcap_server.h +++ b/include/osmo-pcap/osmo_pcap_server.h @@ -35,6 +35,7 @@ #include <osmo-pcap/wireformat.h> #include <osmo-pcap/osmo_tls.h> +#include <osmo-pcap/osmo_pcap_file.h> struct rate_ctr_group; struct rate_ctr_group_desc; @@ -88,7 +89,10 @@ char *curr_filename; /* pcap stuff */ - struct pcap_file_header file_hdr; + enum osmo_pcap_fmt file_fmt; + bool pcapng_endian_swapped; + uint8_t *file_hdr; + uint32_t file_hdr_len; /* last time */ struct tm last_write; diff --git a/src/Makefile.am b/src/Makefile.am index bb70d21..0fb16a2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,6 +35,7 @@ osmo_pcap_server_SOURCES = \ osmo_server_main.c \ osmo_common.c \ + osmo_pcap_file.c \ osmo_server_vty.c \ osmo_server_network.c \ osmo_server_stats.c \ diff --git a/src/osmo_pcap_file.c b/src/osmo_pcap_file.c index ddd32ed..8e59a37 100644 --- a/src/osmo_pcap_file.c +++ b/src/osmo_pcap_file.c @@ -29,6 +29,40 @@ #include <osmo-pcap/common.h> #include <osmo-pcap/wireformat.h> +/* Find out whether data contains a start of a .pcap or .pcapng file. + * Returns 0 on success, negative on error. */ +int osmo_pcap_file_discover_fmt(const uint8_t *data, size_t data_len, enum osmo_pcap_fmt *result_fmt) +{ + const struct pcapng_block_header *bh; + const struct pcapng_section_header_block *shb; + + /* Check for .pcap: */ + if (data_len >= sizeof(struct pcap_file_header) && + ((struct pcap_file_header *)data)->magic == OSMO_PCAP_FILE_MAGIC) { + *result_fmt = OSMO_PCAP_FMT_PCAP; + return 0; + } + + /* Check for .pcapng: */ + if (data_len < sizeof(struct pcapng_block_header) + + sizeof(struct pcapng_section_header_block) + + sizeof(uint32_t)) + return -1; + + bh = (const struct pcapng_block_header *)data; + /* BLOCK_TYPE_SHB has the same value regardless of byte order */ + if (bh->block_type != BLOCK_TYPE_SHB) + return -1; + + shb = (const struct pcapng_section_header_block *)&bh->block_body[0]; + if (shb->magic != OSMO_PCAPNG_FILE_MAGIC && + shb->magic != OSMO_PCAPNG_FILE_MAGIC_SWAPPED) + return -2; + + *result_fmt = OSMO_PCAP_FMT_PCAPNG; + return 0; +} + /*********************************************************** * Libpcap File Format (.pcap) *
https://wiki.wireshark.org/Development/LibpcapFileFormat
@@ -179,6 +213,64 @@ return sizeof(*opth); } +static int osmo_pcapng_file_shb_is_swapped(const struct pcapng_section_header_block *shb) +{ + if (shb->magic == OSMO_PCAPNG_FILE_MAGIC_SWAPPED) + return 1; + if (shb->magic == OSMO_PCAPNG_FILE_MAGIC) + return 0; + return -1; +} + +/* 1: true, 0: false, negative: error */ +int osmo_pcapng_file_is_swapped(const uint8_t *data, size_t data_len) +{ + const struct pcapng_block_header *bh = (const struct pcapng_block_header *)data; + const struct pcapng_section_header_block *shb; + + if (data_len < sizeof(struct pcapng_block_header) + + sizeof(struct pcapng_section_header_block) + + sizeof(uint32_t)) + return -1; + + /* BLOCK_TYPE_SHB has the same value regardless of byte order */ + if (bh->block_type != BLOCK_TYPE_SHB) + return -1; + + shb = (const struct pcapng_section_header_block *)&bh->block_body[0]; + return osmo_pcapng_file_shb_is_swapped(shb); +} + +uint16_t osmo_pcapng_file_read_uint16(const uint8_t *data, bool endian_swapped) +{ + uint16_t val; + + memcpy(&val, data, sizeof(val)); + if (!endian_swapped) + return val; + return (val >> 8) | (val << 8); +} + +uint32_t osmo_pcapng_file_read_uint32(const uint8_t *data, bool endian_swapped) +{ + uint32_t val; + + memcpy(&val, data, sizeof(val)); + if (!endian_swapped) + return val; + return __builtin_bswap32(val); +} + +uint64_t osmo_pcapng_file_read_uint64(const uint8_t *data, bool endian_swapped) +{ + uint64_t val; + + memcpy(&val, data, sizeof(val)); + if (!endian_swapped) + return val; + return __builtin_bswap64(val); +} + /* Get required length to store a given record (packet) */ unsigned int osmo_pcapng_file_shb_size(const struct osmo_pcapng_file_shb_pars *pars) { diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c index 64d772a..0a0763b 100644 --- a/src/osmo_server_network.c +++ b/src/osmo_server_network.c @@ -108,7 +108,7 @@ talloc_free(event_name); pcap_zmq_send(conn->server->zmq_publ, - &conn->file_hdr, sizeof(conn->file_hdr), + conn->file_hdr, conn->file_hdr_len, ZMQ_SNDMORE); pcap_zmq_send(conn->server->zmq_publ, &data->data[0], data->len, @@ -268,10 +268,11 @@ conn->server->base_path, strerror(errno)); return; } - conn->curr_filename = talloc_asprintf(conn, "%s/trace-%s-%d%.2d%.2d_%.2d%.2d%.2d.pcap", + conn->curr_filename = talloc_asprintf(conn, "%s/trace-%s-%d%.2d%.2d_%.2d%.2d%.2d.%s", real_base_path, conn->name, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + tm.tm_hour, tm.tm_min, tm.tm_sec, + conn->file_fmt == OSMO_PCAP_FMT_PCAP ? "pcap" : "pcapng"); free(real_base_path); if (!conn->curr_filename) { LOGP(DSERVER, LOGL_ERROR, "Failed to assemble filename for %s.\n", conn->name); @@ -285,8 +286,8 @@ return; } - rc = write(conn->local_fd, &conn->file_hdr, sizeof(conn->file_hdr)); - if (rc != sizeof(conn->file_hdr)) { + rc = write(conn->local_fd, conn->file_hdr, conn->file_hdr_len); + if (rc != conn->file_hdr_len) { LOGP(DSERVER, LOGL_ERROR, "Failed to write the header: %d\n", errno); close(conn->local_fd); conn->local_fd = -1; @@ -296,27 +297,116 @@ update_last_write(conn, now); } -/* returns >0 on success, <= 0 on failure (closes conn) */ -static int rx_link_hdr(struct osmo_pcap_conn *conn, struct osmo_pcap_data *data) +static int validate_link_hdr_pcap(const struct osmo_pcap_conn *conn, const struct osmo_pcap_data *data) { struct pcap_file_header *hdr; hdr = (struct pcap_file_header *) &data->data[0]; - + if (data->len < sizeof(struct pcap_file_header)) { + LOGP(DSERVER, LOGL_ERROR, + "Implausible llink_hdr length: %u < %zu\n", + data->len, sizeof(struct pcap_file_header)); + return -1; + } if (hdr->snaplen > conn->server->max_snaplen) { LOGP(DSERVER, LOGL_ERROR, - "The recvd pcap_file_header contains too big snaplen %zu > %zu\n", - (size_t) hdr->snaplen, (size_t) conn->server->max_snaplen); + "The recvd pcap_file_header contains too big snaplen %zu > %zu\n", + (size_t) hdr->snaplen, (size_t) conn->server->max_snaplen); + return -1; + } + return 0; +} + +static int validate_link_hdr_pcapng(const struct osmo_pcap_conn *conn, const struct osmo_pcap_data *data) +{ + + const struct pcapng_block_header *bh = (const struct pcapng_block_header *)&data->data[0]; + const size_t pcapnb_bh_min_len = sizeof(struct pcapng_block_header) + sizeof(uint32_t); + uint32_t block_total_length, block_type; + + if (data->len < pcapnb_bh_min_len) { + LOGP(DSERVER, LOGL_ERROR, "Implausible data length: %u < %zu\n", + data->len, pcapnb_bh_min_len); return -1; } + block_total_length = osmo_pcapng_file_read_uint32((uint8_t *)&bh->block_total_length, conn->pcapng_endian_swapped); + if (block_total_length & 0x00000003) { + LOGP(DSERVER, LOGL_ERROR, "Implausible pcapng block total length not multiple of 4: %u\n", + block_total_length); + return -1; + } + + /* We have a SHB block + N IDB blocks here, so it most probably won't be equal + * since we are only checking the 1st SHB block here: */ + if (block_total_length > data->len) { + LOGP(DSERVER, LOGL_ERROR, "Implausible pcapng block total length: %u > %u\n", + block_total_length, data->len); + return -1; + } + + block_type = osmo_pcapng_file_read_uint32((uint8_t *)&bh->block_type, conn->pcapng_endian_swapped); + if (block_type != BLOCK_TYPE_SHB) { + LOGP(DSERVER, LOGL_DEBUG, "Implausible pcapng Block Header type %u vs exp %u\n", + block_type, BLOCK_TYPE_SHB); + return -1; + } + + /* TODO: validate each idb->snaplen in data->data to be <= conn->server->max_snaplen */ + + return 0; +} + +static int validate_link_hdr(const struct osmo_pcap_conn *conn, const struct osmo_pcap_data *data) +{ + + /* Validation checks: */ + switch (conn->file_fmt) { + case OSMO_PCAP_FMT_PCAP: + return validate_link_hdr_pcap(conn, data); + case OSMO_PCAP_FMT_PCAPNG: + return validate_link_hdr_pcapng(conn, data); + default: + OSMO_ASSERT(0); + } +} + +/* returns >0 on success, <= 0 on failure (closes conn) */ +static int rx_link_hdr(struct osmo_pcap_conn *conn, struct osmo_pcap_data *data) +{ + int rc; + + rc = osmo_pcap_file_discover_fmt(data->data, data->len, &conn->file_fmt); + if (rc < 0) + return rc; + + if (conn->file_fmt == OSMO_PCAP_FMT_PCAPNG) { + rc = osmo_pcapng_file_is_swapped(data->data, data->len); + if (rc < 0) { + LOGP(DSERVER, LOGL_ERROR, "Unable to figure out pcapng file endianness\n"); + return rc; + } + conn->pcapng_endian_swapped = !!rc; + } + + /* Validation checks: */ + if ((rc = validate_link_hdr(conn, data)) < 0) + return rc; + if (conn->store && conn->local_fd < 0) { /* First received link hdr in conn */ - conn->file_hdr = *hdr; + talloc_free(conn->file_hdr); + conn->file_hdr = talloc_size(conn, data->len); + memcpy(conn->file_hdr, data->data, data->len); + conn->file_hdr_len = data->len; restart_pcap(conn); - } else if (memcmp(&conn->file_hdr, hdr, sizeof(*hdr)) != 0) { + } else if (conn->file_hdr_len != data->len || + memcmp(&conn->file_hdr, data->data, data->len) != 0) { /* Client changed the link hdr in conn */ - conn->file_hdr = *hdr; + talloc_free(conn->file_hdr); + conn->file_hdr = talloc_size(conn, data->len); + memcpy(conn->file_hdr, data->data, data->len); + conn->file_hdr_len = data->len; restart_pcap(conn); } @@ -460,12 +550,95 @@ return true; } +static int validate_link_data_pcap(const struct osmo_pcap_conn *conn, const struct osmo_pcap_data *data) +{ + unsigned int min_len, max_len; + + min_len = sizeof(struct osmo_pcap_pkthdr); + max_len = conn->server->max_snaplen + sizeof(struct osmo_pcap_pkthdr); + if (data->len < min_len || data->len > max_len) { + LOGP(DSERVER, LOGL_ERROR, "Implausible data length: %u < %u <= %u\n", + min_len, data->len, max_len); + return -1; + } + return 0; +} + +/* pcapng: validate size of payload (pkt) in EPB doesn't go through snaplen. */ +static int validate_link_data_pcapng(const struct osmo_pcap_conn *conn, const struct osmo_pcap_data *data) +{ + + const struct pcapng_block_header *bh = (const struct pcapng_block_header *)&data->data[0]; + const struct pcapng_enhanced_packet_block *epb; + const size_t pcapnb_bh_min_len = sizeof(struct pcapng_block_header) + sizeof(uint32_t); + uint32_t block_total_length, block_type, captured_len; + + if (data->len < pcapnb_bh_min_len) { + LOGP(DSERVER, LOGL_ERROR, "Implausible data length: %u < %zu\n", + data->len, pcapnb_bh_min_len); + return -1; + } + + block_total_length = osmo_pcapng_file_read_uint32((uint8_t *)&bh->block_total_length, conn->pcapng_endian_swapped); + if (block_total_length & 0x00000003) { + LOGP(DSERVER, LOGL_ERROR, "Implausible pcapng block total length not multiple of 4: %u\n", + block_total_length); + return -1; + } + + if (block_total_length != data->len) { + LOGP(DSERVER, LOGL_ERROR, "Implausible pcapng block total length: %u != %u\n", + block_total_length, data->len); + return -1; + } + + block_type = osmo_pcapng_file_read_uint32((uint8_t *)&bh->block_type, conn->pcapng_endian_swapped); + switch (block_type) { + case BLOCK_TYPE_EPB: + if (data->len < pcapnb_bh_min_len + sizeof(struct pcapng_enhanced_packet_block)) { + LOGP(DSERVER, LOGL_ERROR, "Implausible data length: %u < %zu\n", + data->len, pcapnb_bh_min_len + sizeof(struct pcapng_enhanced_packet_block)); + return -1; + } + epb = (struct pcapng_enhanced_packet_block *)&bh->block_body[0]; + captured_len = osmo_pcapng_file_read_uint32((uint8_t *)&epb->captured_len, conn->pcapng_endian_swapped); + if (captured_len > conn->server->max_snaplen) { + LOGP(DSERVER, LOGL_ERROR, "Implausible pcapng EPB captured length: %u > %u\n", + captured_len, conn->server->max_snaplen); + return -1; + } + break; + default: + LOGP(DSERVER, LOGL_DEBUG, "Unexpected pcapng Block Header type %u\n", block_type); + /* Other types exist which we don't specifically support right now, but which may + * be sent by newer osmo-pcap-client. Allow storing it without further checks. */ + break; + } + return 0; +} + +static int validate_link_data(const struct osmo_pcap_conn *conn, const struct osmo_pcap_data *data) +{ + /* Validation checks: */ + switch (conn->file_fmt) { + case OSMO_PCAP_FMT_PCAP: + return validate_link_data_pcap(conn, data); + case OSMO_PCAP_FMT_PCAPNG: + return validate_link_data_pcapng(conn, data); + default: + OSMO_ASSERT(0); + } +} + /* returns >0 on success, <= 0 on failure (closes conn) */ static int rx_link_data(struct osmo_pcap_conn *conn, struct osmo_pcap_data *data) { time_t now = time(NULL); int rc; + if ((rc = validate_link_data(conn, data)) < 0) + return rc; + zmq_send_client_data(conn, data); if (!conn->store) { @@ -499,6 +672,42 @@ talloc_free(conn); } +static inline size_t calc_data_max_len(const struct osmo_pcap_server *server) +{ + size_t data_max_len; + + /* Some safe value regarding variable size options in a given pcapng block... */ + const size_t pcapng_max_len_opt = 4096; + const size_t pcapng_max_iface_len = 256; + + /* Maximum of the 2 types of .pcap blocks: */ + data_max_len = OSMO_MAX(sizeof(struct pcap_file_header), + sizeof(struct osmo_pcap_pkthdr) + server->max_snaplen); + + /* pcapng SHB: */ + const size_t pcapng_shb_max_len = sizeof(struct pcapng_block_header) + + sizeof(struct pcapng_section_header_block) + + pcapng_max_len_opt + + sizeof(uint32_t); + /* pcapng IDB: */ + const size_t pcapng_idb_max_len = sizeof(struct pcapng_block_header) + + sizeof(struct pcapng_iface_descr_block) + + pcapng_max_len_opt + + sizeof(uint32_t); + /* hdr_link for pcapng (SHB + N*IDB) */ + const size_t pcapg_hdr_link_max_len = pcapng_shb_max_len + // SHB + (pcapng_max_iface_len * pcapng_idb_max_len); // N * IDB + data_max_len = OSMO_MAX(data_max_len, pcapg_hdr_link_max_len); + + /* pcapng EPB: */ + const size_t pcapng_epb_max_len = sizeof(struct pcapng_block_header) + + sizeof(struct pcapng_enhanced_packet_block) + + pcapng_max_len_opt + + sizeof(uint32_t); + data_max_len = OSMO_MAX(data_max_len, pcapng_epb_max_len + server->max_snaplen); + return data_max_len; +} + static struct osmo_pcap_conn *osmo_pcap_conn_alloc(struct osmo_pcap_server *server, const char *name) { @@ -512,8 +721,7 @@ return NULL; } - conn->data_max_len = OSMO_MAX(sizeof(struct pcap_file_header), - sizeof(struct osmo_pcap_pkthdr) + server->max_snaplen); + conn->data_max_len = calc_data_max_len(server); conn->data = talloc_zero_size(conn, sizeof(struct osmo_pcap_data) + conn->data_max_len); /* a bit nasty. we do not work with ids but names */ desc = talloc_zero(conn, struct rate_ctr_group_desc); @@ -586,36 +794,6 @@ return do_read_tls(conn, buf, size); } -static bool pcap_data_valid(struct osmo_pcap_conn *conn) -{ - unsigned int min_len, max_len; - switch ((enum OsmoPcapDataType) conn->data->type) { - case PKT_LINK_HDR: - if (conn->data->len != sizeof(struct pcap_file_header)) { - LOGP(DSERVER, LOGL_ERROR, - "Implausible llink_hdr length: %u != %zu\n", - conn->data->len, sizeof(struct osmo_pcap_pkthdr)); - return false; - } - break; - case PKT_LINK_DATA: - min_len = sizeof(struct osmo_pcap_pkthdr); - max_len = conn->server->max_snaplen + sizeof(struct osmo_pcap_pkthdr); - if (conn->data->len < min_len || conn->data->len > max_len) { - LOGP(DSERVER, LOGL_ERROR, - "Implausible data length: %u < %u <= %u\n", - min_len, conn->data->len, max_len); - return false; - } - break; - default: - LOGP(DSERVER, LOGL_ERROR, "Unknown data type %" PRIx8 "\n", - conn->data->type); - return false; - } - return true; -} - /* Read segment header, struct osmo_pcap_data (without payload) * returns >0 on success, <= 0 on failure (closes conn) */ static int read_cb_initial(struct osmo_pcap_conn *conn) @@ -640,8 +818,11 @@ conn->data->len = ntohs(conn->data->len); - if (!pcap_data_valid(conn)) + if (conn->data->len > conn->data_max_len) { + LOGP(DSERVER, LOGL_ERROR, "Implausible data length: %u > %zu (snaplen %u)\n", + conn->data->len, conn->data_max_len, conn->server->max_snaplen); return -1; + } conn->state = STATE_DATA; conn->pend = conn->data->len; @@ -766,7 +947,8 @@ { close_connection(client); - memset(&client->file_hdr, 0, sizeof(client->file_hdr)); + TALLOC_FREE(client->file_hdr); + client->file_hdr_len = 0; client->rem_wq.bfd.fd = new_fd; if (osmo_fd_register(&client->rem_wq.bfd) != 0) { LOGP(DSERVER, LOGL_ERROR, "Failed to register fd.\n"); diff --git a/tests/rotate_localtime/Makefile.am b/tests/rotate_localtime/Makefile.am index fca9ff8..265e4fe 100644 --- a/tests/rotate_localtime/Makefile.am +++ b/tests/rotate_localtime/Makefile.am @@ -28,6 +28,7 @@ $(NULL) rotate_localtime_test_LDADD = \ + $(top_builddir)/src/osmo_pcap_file.o \ $(top_builddir)/src/osmo_server_network.o \ $(top_builddir)/src/osmo_server_stats.o \ $(top_builddir)/src/osmo_tls.o \ -- To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39287?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange Gerrit-Project: osmo-pcap Gerrit-Branch: master Gerrit-Change-Id: I275d28ab418a1514fa9c5c7c20f3d831cc6af8bb Gerrit-Change-Number: 39287 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
5 months, 2 weeks
1
0
0
0
[S] Change in osmo-bsc[master]: nokia_site: change RSL bootstrap logic
by pespin
Attention is currently required from: csaba.sipos. pespin has posted comments on this change by csaba.sipos. (
https://gerrit.osmocom.org/c/osmo-bsc/+/39277?usp=email
) Change subject: nokia_site: change RSL bootstrap logic ...................................................................... Patch Set 2: Code-Review+2 -- To view, visit
https://gerrit.osmocom.org/c/osmo-bsc/+/39277?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I7319a64f069d239a582547bc422058ff5848d2e2 Gerrit-Change-Number: 39277 Gerrit-PatchSet: 2 Gerrit-Owner: csaba.sipos <metro4(a)freemail.hu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: csaba.sipos <metro4(a)freemail.hu> Gerrit-Comment-Date: Fri, 10 Jan 2025 14:40:27 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
5 months, 2 weeks
1
0
0
0
[S] Change in osmo-bsc[master]: nokia_site: change RSL bootstrap logic
by pespin
Attention is currently required from: csaba.sipos. pespin has posted comments on this change by csaba.sipos. (
https://gerrit.osmocom.org/c/osmo-bsc/+/39277?usp=email
) Change subject: nokia_site: change RSL bootstrap logic ...................................................................... Patch Set 2: Code-Review+1 -- To view, visit
https://gerrit.osmocom.org/c/osmo-bsc/+/39277?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I7319a64f069d239a582547bc422058ff5848d2e2 Gerrit-Change-Number: 39277 Gerrit-PatchSet: 2 Gerrit-Owner: csaba.sipos <metro4(a)freemail.hu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: csaba.sipos <metro4(a)freemail.hu> Gerrit-Comment-Date: Fri, 10 Jan 2025 14:40:04 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
5 months, 2 weeks
1
0
0
0
[XS] Change in ...pyosmocom[master]: Bump version to 0.0.8
by dexter
dexter has uploaded this change for review. (
https://gerrit.osmocom.org/c/python/pyosmocom/+/39284?usp=email
) Change subject: Bump version to 0.0.8 ...................................................................... Bump version to 0.0.8 Change-Id: I08afa4d29e2fe5fe18179b109d513d870b87d156 --- M debian/changelog M pyproject.toml 2 files changed, 8 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/84/39284/1 diff --git a/debian/changelog b/debian/changelog index 8e82dca..4bff797 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +pyosmocom (0.0.8) unstable; urgency=medium + + * construct: add length steps to StripTrailerAdapter + * construct: allow stripping of leading zeros with StripHeaderAdapter + + -- Philipp Maier <pmaier(a)sysmocom.de> Fri, 10 Jan 2025 14:47:19 +0100 + pyosmocom (0.0.7) unstable; urgency=medium [ Jean-Pierre Marcotte ] diff --git a/pyproject.toml b/pyproject.toml index 41e677a..37b54ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ [project] name = "pyosmocom" -version = "0.0.7" +version = "0.0.8" dependencies = [ "gsm0338", "construct >= 2.9.51" -- To view, visit
https://gerrit.osmocom.org/c/python/pyosmocom/+/39284?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange Gerrit-Project: python/pyosmocom Gerrit-Branch: master Gerrit-Change-Id: I08afa4d29e2fe5fe18179b109d513d870b87d156 Gerrit-Change-Number: 39284 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
5 months, 2 weeks
1
0
0
0
[S] Change in osmo-ttcn3-hacks[master]: SGSN: f_cellid_to_RAI: fix spaces vs tabs
by laforge
laforge has submitted this change. (
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/39253?usp=email
) ( 2 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: SGSN: f_cellid_to_RAI: fix spaces vs tabs ...................................................................... SGSN: f_cellid_to_RAI: fix spaces vs tabs Change-Id: Ic1927729dd0d205f1bd866423c8dfdf91caf597d --- M sgsn/SGSN_Tests.ttcn 1 file changed, 11 insertions(+), 11 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved laforge: Looks good to me, approved diff --git a/sgsn/SGSN_Tests.ttcn b/sgsn/SGSN_Tests.ttcn index 99e53f5..62856ff 100644 --- a/sgsn/SGSN_Tests.ttcn +++ b/sgsn/SGSN_Tests.ttcn @@ -207,17 +207,17 @@ /* mcc_mnc is encoded as of 24.008 10.5.5.15 */ var BcdMccMnc mcc_mnc := cell_id.ra_id.lai.mcc_mnc; - var RoutingAreaIdentificationV ret := { - mccDigit1 := mcc_mnc[0], - mccDigit2 := mcc_mnc[1], - mccDigit3 := mcc_mnc[2], - mncDigit3 := mcc_mnc[3], - mncDigit1 := mcc_mnc[4], - mncDigit2 := mcc_mnc[5], - lac := int2oct(cell_id.ra_id.lai.lac, 2), - rac := int2oct(cell_id.ra_id.rac, 1) - } - return ret; + var RoutingAreaIdentificationV ret := { + mccDigit1 := mcc_mnc[0], + mccDigit2 := mcc_mnc[1], + mccDigit3 := mcc_mnc[2], + mncDigit3 := mcc_mnc[3], + mncDigit1 := mcc_mnc[4], + mncDigit2 := mcc_mnc[5], + lac := int2oct(cell_id.ra_id.lai.lac, 2), + rac := int2oct(cell_id.ra_id.rac, 1) + } + return ret; }; private function f_BssgpCellId_to_GTP_CellId(in BssgpCellId cell_id) return GTP_CellId -- To view, visit
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/39253?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: Ic1927729dd0d205f1bd866423c8dfdf91caf597d Gerrit-Change-Number: 39253 Gerrit-PatchSet: 3 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
5 months, 2 weeks
1
0
0
0
[S] Change in osmo-bsc[master]: nokia_site: change RSL bootstrap logic
by laforge
Attention is currently required from: csaba.sipos. laforge has posted comments on this change by csaba.sipos. (
https://gerrit.osmocom.org/c/osmo-bsc/+/39277?usp=email
) Change subject: nokia_site: change RSL bootstrap logic ...................................................................... Patch Set 2: Code-Review+1 -- To view, visit
https://gerrit.osmocom.org/c/osmo-bsc/+/39277?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: I7319a64f069d239a582547bc422058ff5848d2e2 Gerrit-Change-Number: 39277 Gerrit-PatchSet: 2 Gerrit-Owner: csaba.sipos <metro4(a)freemail.hu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: csaba.sipos <metro4(a)freemail.hu> Gerrit-Comment-Date: Fri, 10 Jan 2025 13:26:18 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
5 months, 2 weeks
1
0
0
0
[XS] Change in osmo-pcap[master]: server: Rename func client_data() -> zmq_send_client_data()
by laforge
Attention is currently required from: pespin. laforge has posted comments on this change by pespin. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39283?usp=email
) Change subject: server: Rename func client_data() -> zmq_send_client_data() ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39283?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment Gerrit-Project: osmo-pcap Gerrit-Branch: master Gerrit-Change-Id: I1b22046464cf969fb5d74b6c2580aaec1feffefa Gerrit-Change-Number: 39283 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Fri, 10 Jan 2025 13:09:31 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
5 months, 2 weeks
1
0
0
0
[XS] Change in osmo-pcap[master]: cosmetic: server: Fix typo in comment
by laforge
Attention is currently required from: pespin. laforge has posted comments on this change by pespin. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39282?usp=email
) Change subject: cosmetic: server: Fix typo in comment ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39282?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment Gerrit-Project: osmo-pcap Gerrit-Branch: master Gerrit-Change-Id: I03aa0137d5470717104f27cb55d4bde802d00a95 Gerrit-Change-Number: 39282 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Fri, 10 Jan 2025 13:09:21 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
5 months, 2 weeks
1
0
0
0
← Newer
1
...
113
114
115
116
117
118
119
...
150
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Results per page:
10
25
50
100
200