pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39303?usp=email )
Change subject: server: Avoid lseek syscall on every packet write to pcap file
......................................................................
server: Avoid lseek syscall on every packet write to pcap file
Instead of requesting the current size to the OS, keep track of the
amount of bytes stored in conn->wr_offset, and check agains that value
when we want to write new data to the file.
This should remove quite a lot of oeverhead when lots of traffic is
being handled.
Change-Id: I437eaca982d65d0f06e7d24863875f85267f0e44
---
M include/osmo-pcap/osmo_pcap_server.h
M src/osmo_server_core.c
2 files changed, 22 insertions(+), 16 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/03/39303/1
diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h
index 9a44fce..5d21c64 100644
--- a/include/osmo-pcap/osmo_pcap_server.h
+++ b/include/osmo-pcap/osmo_pcap_server.h
@@ -87,6 +87,8 @@
int local_fd;
/* canonicalized absolute pathname of pcap file we write to */
char *curr_filename;
+ /* Current write offset of the file we write to (local_fd) */
+ off_t wr_offset;
/* pcap stuff */
enum osmo_pcap_fmt file_fmt;
diff --git a/src/osmo_server_core.c b/src/osmo_server_core.c
index b35d2b7..cc834a2 100644
--- a/src/osmo_server_core.c
+++ b/src/osmo_server_core.c
@@ -308,12 +308,17 @@
talloc_free(curr_filename_cpy_dname);
}
+static void close_local_fd(struct osmo_pcap_conn *conn)
+{
+ close(conn->local_fd);
+ conn->local_fd = -1;
+ conn->wr_offset = 0;
+}
+
void osmo_pcap_conn_close_trace(struct osmo_pcap_conn *conn)
{
- if (conn->local_fd >= 0) {
- close(conn->local_fd);
- conn->local_fd = -1;
- }
+ if (conn->local_fd >= 0)
+ close_local_fd(conn);
move_completed_trace_if_needed(conn);
@@ -342,7 +347,7 @@
/* Update conn->last_write if needed. This field is used to keep the last time
* period where we wrote to the pcap file. Once a new write period (based on
* rotation VTY config) is detected, the pcap file we write to is rotated. */
-static void update_last_write(struct osmo_pcap_conn *conn, time_t now)
+static void update_last_write(struct osmo_pcap_conn *conn, time_t now, size_t len)
{
time_t last = mktime(&conn->last_write);
@@ -352,6 +357,8 @@
* using the current one. */
if (now > last)
localtime_r(&now, &conn->last_write);
+
+ conn->wr_offset += len;
}
void osmo_pcap_conn_restart_trace(struct osmo_pcap_conn *conn)
@@ -365,7 +372,7 @@
/* omit any storing/creation of the file */
if (!conn->store) {
- update_last_write(conn, now);
+ update_last_write(conn, now, 0);
talloc_free(conn->curr_filename);
conn->curr_filename = NULL;
return;
@@ -395,28 +402,25 @@
conn->curr_filename, strerror(errno));
return;
}
+ conn->wr_offset = 0;
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;
+ close_local_fd(conn);
return;
}
-
- update_last_write(conn, now);
+ update_last_write(conn, now, rc);
}
/* Returns true if pcap was re-opened */
static bool check_restart_pcap_max_size(struct osmo_pcap_conn *conn, size_t data_len)
{
- off_t cur;
-
if (!pcap_server->max_size_enabled)
return false;
- cur = lseek(conn->local_fd, 0, SEEK_CUR);
- if (cur + data_len <= conn->server->max_size)
+ if (conn->wr_offset + data_len <= conn->server->max_size)
return false;
+
LOGP(DSERVER, LOGL_NOTICE, "Rolling over file for %s (max-size)\n", conn->name);
osmo_pcap_conn_restart_trace(conn);
return true;
@@ -554,7 +558,7 @@
zmq_send_client_data(conn, data, len);
if (!conn->store) {
- update_last_write(conn, now);
+ update_last_write(conn, now, 0);
return 0;
}
@@ -567,11 +571,11 @@
if (!check_restart_pcap_max_size(conn, len))
check_restart_pcap_localtime(conn, now);
- update_last_write(conn, now);
rc = write(conn->local_fd, data, len);
if (rc != len) {
LOGP(DSERVER, LOGL_ERROR, "Failed to write for %s\n", conn->name);
return -1;
}
+ update_last_write(conn, now, rc);
return 0;
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-pcap/+/39303?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: I437eaca982d65d0f06e7d24863875f85267f0e44
Gerrit-Change-Number: 39303
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Attention is currently required from: daniel, laforge, pespin.
osmith has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39287?usp=email )
Change subject: server: Support storing of pcapng format
......................................................................
Patch Set 5: Code-Review+1
--
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: comment
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I275d28ab418a1514fa9c5c7c20f3d831cc6af8bb
Gerrit-Change-Number: 39287
Gerrit-PatchSet: 5
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 13 Jan 2025 16:46:10 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: daniel, laforge, pespin.
osmith has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39265?usp=email )
Change subject: client: Support generation of pcapng file format
......................................................................
Patch Set 9: Code-Review+1
(1 comment)
File include/osmo-pcap/osmo_pcap_file.h:
https://gerrit.osmocom.org/c/osmo-pcap/+/39265/comment/f1e7c62d_b3620d38?us… :
PS8, Line 87: /* uint32_t block_total_length */
> Nope, it's fine, the field is duplicated at the end of block_body so that the file can be navigated […]
ah nice
--
To view, visit https://gerrit.osmocom.org/c/osmo-pcap/+/39265?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: I3c80518a1e53a1f77e1aca8dfa83f683f9516ad6
Gerrit-Change-Number: 39265
Gerrit-PatchSet: 9
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 13 Jan 2025 16:45:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: osmith <osmith(a)sysmocom.de>
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Attention is currently required from: csaba.sipos, fixeria, laforge.
pespin has posted comments on this change by csaba.sipos. ( https://gerrit.osmocom.org/c/osmo-bsc/+/39290?usp=email )
Change subject: nokia_site: introduce hopping control for Nokia *Site
......................................................................
Patch Set 7:
(2 comments)
File src/osmo-bsc/bts_vty.c:
https://gerrit.osmocom.org/c/osmo-bsc/+/39290/comment/f3af5b7f_a6e84c99?usp… :
PS6, Line 468: DEFUN_ATTR(cfg_bts_nokia_site_hopping_type,
> This is just a Nokia specific OML extension the BTS needs. […]
Done
https://gerrit.osmocom.org/c/osmo-bsc/+/39290/comment/5be16043_cfaa4e93?usp… :
PS6, Line 470: nokia_hopping
> Done
Unless that 0|1 numbering is a well know thing from nokia, I'd also favour to have proper string literal which are somehow self-descriptive as Vadim proposed.
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/39290?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: Idb1d269d2ee80d72ede2394125e8acedf0ee8b06
Gerrit-Change-Number: 39290
Gerrit-PatchSet: 7
Gerrit-Owner: csaba.sipos <metro4(a)freemail.hu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: csaba.sipos <metro4(a)freemail.hu>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 13 Jan 2025 16:18:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: csaba.sipos <metro4(a)freemail.hu>
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Comment-In-Reply-To: fixeria <vyanitskiy(a)sysmocom.de>
Attention is currently required from: daniel, laforge, osmith.
Hello Jenkins Builder, daniel, laforge, osmith,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39265?usp=email
to look at the new patch set (#9).
The following approvals got outdated and were removed:
Code-Review+1 by osmith, Verified+1 by Jenkins Builder
Change subject: client: Support generation of pcapng file format
......................................................................
client: Support generation of pcapng file format
Support transmitting traffic recordings in pcapng towards
osmo-pca-server based on VTY config. Old libpcap's file format
(.pcap) is still left as default to to keep backward compatibility
towards older osmo-pcap-server instances still running. Furthermore,
.pcap support is more extended than .pcapng since it's way older.
When pcapng file format is selected, osmo-pcap-client will use the same
osmo-pcap protocol used in pcap mode, but the payloads encoded in
messages will be in pcapng file format instead of pcap.
This means, for LINK_HDR message type it will encode a file header with
a payload consisting of 1 SHB + N IDB blocks (one for each network
interface being monitored).
Upon each packet recording received from the monitoring interface, it
will encode a LINK_DATA message containing a payload with a encoded
pcapng block.
This works mostly transparetly on the osmo-pcap-server side, since in
general it handles those payloads mostly transparently. Only some sanity
checks will need to be updated and improve there to account for the new
pcapng blocks. This in turn requires identifying pcap vs pcapng format
being recieved from the client, and also placing the proper file suffix
when creating the file. This will be done in a follow-up patch modyfing
the server side.
Related: SYS#5822
Change-Id: I3c80518a1e53a1f77e1aca8dfa83f683f9516ad6
---
M doc/manuals/chapters/client.adoc
M include/osmo-pcap/osmo_pcap_client.h
M include/osmo-pcap/osmo_pcap_file.h
M src/osmo_client_core.c
M src/osmo_client_network.c
M src/osmo_client_vty.c
M src/osmo_pcap_file.c
7 files changed, 534 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/65/39265/9
--
To view, visit https://gerrit.osmocom.org/c/osmo-pcap/+/39265?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I3c80518a1e53a1f77e1aca8dfa83f683f9516ad6
Gerrit-Change-Number: 39265
Gerrit-PatchSet: 9
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>
Attention is currently required from: daniel, laforge, osmith, pespin.
Hello Jenkins Builder, daniel, laforge, osmith,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39287?usp=email
to look at the new patch set (#5).
The following approvals got outdated and were removed:
Code-Review+1 by osmith, Verified+1 by Jenkins Builder
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, 333 insertions(+), 46 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/87/39287/5
--
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: newpatchset
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I275d28ab418a1514fa9c5c7c20f3d831cc6af8bb
Gerrit-Change-Number: 39287
Gerrit-PatchSet: 5
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>