pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39150?usp=email )
Change subject: pcap-server: Move write checks to reopen pcap into helper functions ......................................................................
pcap-server: Move write checks to reopen pcap into helper functions
The logic there will be further extended, hence move the code as a preparatory patch.
Change-Id: Icc2a8e424b166863afa9f8704fd48d35528972df --- M src/osmo_server_network.c 1 file changed, 26 insertions(+), 10 deletions(-)
Approvals: osmith: Looks good to me, approved Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve
diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c index 41d0b3f..1ace77a 100644 --- a/src/osmo_server_network.c +++ b/src/osmo_server_network.c @@ -212,6 +212,30 @@ return 1; }
+/* Returns true if pcap was re-opened */ +static bool check_restart_pcap_max_size(struct osmo_pcap_conn *conn, const struct osmo_pcap_data *data) +{ + off_t cur; + + cur = lseek(conn->local_fd, 0, SEEK_CUR); + if (cur + data->len <= conn->server->max_size) + return false; + LOGP(DSERVER, LOGL_NOTICE, "Rolling over file for %s (max-size)\n", conn->name); + restart_pcap(conn); + return true; +} + +static bool check_restart_pcap_localtime(struct osmo_pcap_conn *conn, const struct tm *tm) +{ + if (conn->last_write.tm_mday == tm->tm_mday && + conn->last_write.tm_mon == tm->tm_mon && + conn->last_write.tm_year == tm->tm_year) + return false; + LOGP(DSERVER, LOGL_NOTICE, "Rolling over file for %s (localtime)\n", conn->name); + restart_pcap(conn); + return true; +} + /* * Check if we are past the limit or on a day change */ @@ -233,16 +257,8 @@ return -1; }
- off_t cur = lseek(conn->local_fd, 0, SEEK_CUR); - if (cur + data->len > conn->server->max_size) { - LOGP(DSERVER, LOGL_NOTICE, "Rolling over file for %s\n", conn->name); - restart_pcap(conn); - } else if (conn->last_write.tm_mday != tm->tm_mday || - conn->last_write.tm_mon != tm->tm_mon || - conn->last_write.tm_year != tm->tm_year) { - LOGP(DSERVER, LOGL_NOTICE, "Rolling over file for %s\n", conn->name); - restart_pcap(conn); - } + if (!check_restart_pcap_max_size(conn, data)) + check_restart_pcap_localtime(conn, tm);
conn->last_write = *tm; rc = write(conn->local_fd, &data->data[0], data->len);