fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcap/+/42836?usp=email )
Change subject: vty: clamp configured snaplen to the wire-framing limit ......................................................................
vty: clamp configured snaplen to the wire-framing limit
osmo-pcap carries each captured packet in a frame whose length field (struct osmo_pcap_data.len) is a uint16_t, so any snaplen above ~64 KiB cannot be transported and is silently clamped by the server when sizing its receive buffer (calc_data_max_len() caps at UINT16_MAX). The VTY, however, advertised libpcap's MAXIMUM_SNAPLEN (262144), misleading users into configuring values that never take effect.
Introduce OSMO_PCAP_MAX_SNAPLEN (65535) and, in both the client "pcap snaplen" and server "max-snaplen" handlers, warn and cap the value to it when a larger one is given. The command syntax keeps the <1-262144> range for backwards compatibility so existing configs still parse; the help text now documents the effective 64 KiB limit.
Related: SYS#8099 Related: 6d2f7c52 ("server: Limit rx buffer size to UINT16_MAX") Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com Change-Id: Ia56cad48e8cefe8ae103f2f7d2e037bf28438b71 --- M doc/manuals/chapters/client.adoc M doc/manuals/chapters/server.adoc M include/osmo-pcap/common.h M src/osmo_client_vty.c M src/osmo_server_vty.c 5 files changed, 43 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/36/42836/1
diff --git a/doc/manuals/chapters/client.adoc b/doc/manuals/chapters/client.adoc index d9885d1..87682c5 100644 --- a/doc/manuals/chapters/client.adoc +++ b/doc/manuals/chapters/client.adoc @@ -67,6 +67,12 @@ the captured interface (e.g. `ethtool -K <iface> gro off lro off gso off tso off`).
+NOTE:: Even though larger values are accepted for backwards compatibility, the +osmo-pcap wire framing limits the effective snapshot length to 64 KiB +(65535 bytes). Configuring a `snaplen` above 65535 is capped to 65535 with a +warning on the VTY. The server's `max-snaplen` must be greater than or equal to +the `snaplen` configured here. + Adding or removing new recording network devices during operation is not really supported, and a restart of osmo-pcap-client is expected for the new configuration to be properly set up. diff --git a/doc/manuals/chapters/server.adoc b/doc/manuals/chapters/server.adoc index 5d6ed32..f7a8290 100644 --- a/doc/manuals/chapters/server.adoc +++ b/doc/manuals/chapters/server.adoc @@ -39,7 +39,7 @@ base-path /var/lib/osmo-pcap-server <1> server ip 192.168.11.20 <2> server port 54321 <3> - max-snaplen 100000 <4> + max-snaplen 65535 <4> ---- <1> directory to which the pcap files are stored <2> IP address to which to bind/listen @@ -52,6 +52,11 @@ larger `max-snaplen` on the server than the `snaplen` used by some clients; each client's trace is recorded using that client's own snaplen.
+NOTE: Even though larger values are accepted for backwards compatibility, the +osmo-pcap wire framing limits the effective snapshot length to 64 KiB +(65535 bytes). Configuring a `max-snaplen` above 65535 is capped to 65535 with a +warning on the VTY. + The received packets are stored to a pcap file below the `base-path` using a filename encoding both the client name and the date/time at time of file creation.
diff --git a/include/osmo-pcap/common.h b/include/osmo-pcap/common.h index 5916c48..b976a20 100644 --- a/include/osmo-pcap/common.h +++ b/include/osmo-pcap/common.h @@ -62,6 +62,13 @@ #define MAXIMUM_SNAPLEN 262144 #endif
+/* osmo-pcap transports each captured packet inside a frame whose length field + * (struct osmo_pcap_data.len) is a uint16_t. Hence the largest snaplen that can + * actually be carried over the wire is bounded by UINT16_MAX, far below + * libpcap's MAXIMUM_SNAPLEN (262144). The server enforces the same ceiling when + * sizing its per-connection receive buffer (see calc_data_max_len()). */ +#define OSMO_PCAP_MAX_SNAPLEN 65535 + #define DEFAULT_SNAPLEN 9000
#endif diff --git a/src/osmo_client_vty.c b/src/osmo_client_vty.c index 127e52f..6bee983 100644 --- a/src/osmo_client_vty.c +++ b/src/osmo_client_vty.c @@ -198,9 +198,19 @@ DEFUN(cfg_client_snaplen, cfg_client_snaplen_cmd, "pcap snaplen <1-262144>", /* MAXIMUM_SNAPLEN */ - PCAP_STRING "snapshot length\n" "Bytes\n") + PCAP_STRING "snapshot length\n" + "Bytes (effectively limited to 64 KiB by the osmo-pcap wire framing)\n") { - pcap_client->snaplen = atoi(argv[0]); + int snaplen = atoi(argv[0]); + + if (snaplen > OSMO_PCAP_MAX_SNAPLEN) { + vty_out(vty, "%% snaplen %d exceeds the limit imposed by the " + "osmo-pcap wire framing, capping to %d%s", + snaplen, OSMO_PCAP_MAX_SNAPLEN, VTY_NEWLINE); + snaplen = OSMO_PCAP_MAX_SNAPLEN; + } + + pcap_client->snaplen = snaplen; return CMD_SUCCESS; }
diff --git a/src/osmo_server_vty.c b/src/osmo_server_vty.c index dfe9857..fcf1db1 100644 --- a/src/osmo_server_vty.c +++ b/src/osmo_server_vty.c @@ -373,9 +373,19 @@ DEFUN(cfg_server_max_snaplen, cfg_server_max_snaplen_cmd, "max-snaplen <1-262144>", /* MAXIMUM_SNAPLEN */ - "Maximum pcap snapshot length\n" "Bytes\n") + "Maximum pcap snapshot length\n" + "Bytes (effectively limited to 64 KiB by the osmo-pcap wire framing)\n") { - pcap_server->max_snaplen = atoi(argv[0]); + int snaplen = atoi(argv[0]); + + if (snaplen > OSMO_PCAP_MAX_SNAPLEN) { + vty_out(vty, "%% max-snaplen %d exceeds the limit imposed by the " + "osmo-pcap wire framing, capping to %d%s", + snaplen, OSMO_PCAP_MAX_SNAPLEN, VTY_NEWLINE); + snaplen = OSMO_PCAP_MAX_SNAPLEN; + } + + pcap_server->max_snaplen = snaplen; return CMD_SUCCESS; }