Projects
osmocom:master
osmo-pcap
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 23
View file
osmo-pcap.spec
Changed
@@ -14,13 +14,13 @@ Name: osmo-pcap Requires: osmocom-master -Version: 0.5.0.15.b614 +Version: 0.5.0.24.16b3 Release: 0 Summary: Osmocom's PCAP client and server License: AGPL-3.0-or-later AND GPL-2.0-or-later Group: Productivity/Telephony/Servers URL: https://osmocom.org/projects/osmo-pcap -Source: osmo-pcap_0.5.0.15.b614.tar.xz +Source: osmo-pcap_0.5.0.24.16b3.tar.xz Source1: rpmlintrc BuildRequires: autoconf BuildRequires: automake >= 1.6
View file
commit_16b362caa6da3b98c698158c80e689570bca2e4d.txt
Added
View file
commit_b6147d577b22f40e93aa6a48b1f17ad192095979.txt
Deleted
View file
osmo-pcap_0.5.0.15.b614.dsc -> osmo-pcap_0.5.0.24.16b3.dsc
Changed
@@ -2,7 +2,7 @@ Source: osmo-pcap Binary: osmo-pcap-client, osmo-pcap-server, osmo-pcap-client-dbg, osmo-pcap-server-dbg Architecture: any -Version: 0.5.0.15.b614 +Version: 0.5.0.24.16b3 Maintainer: Osmocom team <openbsc@lists.osmocom.org> Homepage: https://osmocom.org/projects/osmo-pcap Standards-Version: 3.9.1 @@ -15,8 +15,8 @@ osmo-pcap-server deb net extra arch=any osmo-pcap-server-dbg deb net extra arch=any Checksums-Sha1: - 16c6400514d976e27c44297609acf1cfe0dc6ec9 55216 osmo-pcap_0.5.0.15.b614.tar.xz + 9d0af1c1b145a2295b3f034239170a1c2590d314 55812 osmo-pcap_0.5.0.24.16b3.tar.xz Checksums-Sha256: - 50cfff1db6a346fbe00cb3306e442692e906693f561bfaee31c0dc5688ceeb30 55216 osmo-pcap_0.5.0.15.b614.tar.xz + dc1175864e1291d592b2846fc9791c5f570e56ed8abab0d25b23b19b5f4e55dc 55812 osmo-pcap_0.5.0.24.16b3.tar.xz Files: - 65960dfd8197cd5f97aea49c0da479dc 55216 osmo-pcap_0.5.0.15.b614.tar.xz + c875aee9fcdd04df26c039178295e3c1 55812 osmo-pcap_0.5.0.24.16b3.tar.xz
View file
osmo-pcap_0.5.0.15.b614.tar.xz/.tarball-version -> osmo-pcap_0.5.0.24.16b3.tar.xz/.tarball-version
Changed
@@ -1 +1 @@ -0.5.0.15-b614 +0.5.0.24-16b3
View file
osmo-pcap_0.5.0.15.b614.tar.xz/debian/changelog -> osmo-pcap_0.5.0.24.16b3.tar.xz/debian/changelog
Changed
@@ -1,8 +1,8 @@ -osmo-pcap (0.5.0.15.b614) unstable; urgency=medium +osmo-pcap (0.5.0.24.16b3) unstable; urgency=medium * Automatically generated changelog entry for building the Osmocom master feed - -- Osmocom OBS scripts <info@osmocom.org> Tue, 24 Dec 2024 13:41:44 +0000 + -- Osmocom OBS scripts <info@osmocom.org> Tue, 24 Dec 2024 14:43:59 +0000 osmo-pcap (0.5.0) unstable; urgency=medium
View file
osmo-pcap_0.5.0.15.b614.tar.xz/include/osmo-pcap/osmo_pcap_client.h -> osmo-pcap_0.5.0.24.16b3.tar.xz/include/osmo-pcap/osmo_pcap_client.h
Changed
@@ -28,13 +28,12 @@ #include <osmocom/core/linuxlist.h> #include <osmocom/core/select.h> #include <osmocom/core/timer.h> +#include <osmocom/core/rate_ctr.h> #include <osmocom/core/write_queue.h> -struct rate_ctr_group; - #define WQUEUE_MAXLEN_DEFAULT 1000 -enum { +enum pcap_client_ctr { CLIENT_CTR_CONNECT, CLIENT_CTR_BYTES, CLIENT_CTR_PKTS, @@ -47,6 +46,15 @@ CLIENT_CTR_P_DROP, CLIENT_CTR_P_IFDROP, }; +extern const struct rate_ctr_group_desc pcap_client_ctr_group_desc; + +enum pcap_handle_ctr { + PH_CTR_PERR, + PH_CTR_P_RECV, + PH_CTR_P_DROP, + PH_CTR_P_IFDROP, +}; +extern const struct rate_ctr_group_desc pcap_handle_ctr_group_desc; enum osmo_pcap_protocol { PROTOCOL_OSMOPCAP, @@ -82,22 +90,30 @@ struct osmo_pcap_client *client; }; -struct osmo_pcap_client { - char *device; +struct osmo_pcap_handle { + struct llist_head entry; /* item in (struct osmo_pcap_client)->handles */ + struct osmo_pcap_client *client; /* back pointer */ + unsigned int idx; + char *devname; pcap_t *handle; - char errbufPCAP_ERRBUF_SIZE; - + struct osmo_fd fd; u_int last_ps_recv; u_int last_ps_drop; u_int last_ps_ifdrop; struct osmo_timer_list pcap_stat_timer; - struct bpf_program bpf; - char *filter_string; + /* statistics */ + struct rate_ctr_group *ctrg; +}; + +struct osmo_pcap_client { + struct llist_head handles; /* list of struct osmo_pcap_handle */ + unsigned int next_pcap_handle_idx; + + char *filter_string; int filter_itself; int gprs_filtering; int snaplen; - struct osmo_fd fd; struct osmo_pcap_client_conn *conn; struct llist_head conns; @@ -111,12 +127,14 @@ struct osmo_pcap_client *osmo_pcap_client_alloc(void *tall_ctx); int vty_client_init(void); -int osmo_client_capture(struct osmo_pcap_client *client, const char *device); +int osmo_client_start_capture(struct osmo_pcap_client *client); int osmo_client_filter(struct osmo_pcap_client *client, const char *filter); struct osmo_pcap_client_conn *osmo_client_find_or_create_conn(struct osmo_pcap_client *, const char *name); struct osmo_pcap_client_conn *osmo_client_find_conn(struct osmo_pcap_client *, const char *name); +struct osmo_pcap_handle *osmo_client_find_handle(struct osmo_pcap_client *client, const char *devname); + struct osmo_pcap_client_conn *osmo_client_conn_alloc(struct osmo_pcap_client *client, const char *name); void osmo_client_conn_free(struct osmo_pcap_client_conn *conn); void osmo_client_conn_send_data(struct osmo_pcap_client_conn *conn, @@ -125,3 +143,14 @@ void osmo_client_conn_connect(struct osmo_pcap_client_conn *conn); void osmo_client_conn_disconnect(struct osmo_pcap_client_conn *conn); void osmo_client_conn_reconnect(struct osmo_pcap_client_conn *conn); + + +struct osmo_pcap_handle *osmo_pcap_handle_alloc(struct osmo_pcap_client *client, const char *devname); +void osmo_pcap_handle_free(struct osmo_pcap_handle *ph); +int osmo_pcap_handle_start_capture(struct osmo_pcap_handle *ph); + +#define LOGCONN(conn, lvl, fmt, args...) \ + LOGP(DCLIENT, lvl, "CONN(%s,%s:%d) " fmt, (conn)->name, (conn)->srv_ip, (conn)->srv_port, ## args) + +#define LOGPH(ph, lvl, fmt, args...) \ + LOGP(DCLIENT, lvl, "PH(%u,%s) " fmt, (ph)->idx, (ph)->devname, ## args)
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/Makefile.am -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/Makefile.am
Changed
@@ -19,6 +19,7 @@ osmo_client_core.c \ osmo_client_vty.c \ osmo_client_network.c \ + osmo_client_stats.c \ osmo_tls.c \ $(NULL)
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/osmo_client_core.c -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_client_core.c
Changed
@@ -102,6 +102,7 @@ static int can_forward_packet( struct osmo_pcap_client *client, + struct osmo_pcap_handle *ph, struct pcap_pkthdr *hdr, const u_char *data) { @@ -116,7 +117,7 @@ if (!client->gprs_filtering) return 1; - ll_type = pcap_datalink(client->handle); + ll_type = pcap_datalink(ph->handle); switch (ll_type) { case DLT_EN10MB: offset = 14; @@ -125,8 +126,8 @@ offset = 16; break; default: - LOGP(DCLIENT, LOGL_ERROR, "LL type %d/%s not handled.\n", - ll_type, pcap_datalink_val_to_name(ll_type)); + LOGPH(ph, LOGL_ERROR, "LL type %d/%s not handled.\n", + ll_type, pcap_datalink_val_to_name(ll_type)); return 1; } @@ -154,18 +155,20 @@ static int pcap_read_cb(struct osmo_fd *fd, unsigned int what) { - struct osmo_pcap_client *client = fd->data; + struct osmo_pcap_handle *ph = fd->data; + struct osmo_pcap_client *client = ph->client; struct osmo_pcap_client_conn *conn; struct pcap_pkthdr hdr; const u_char *data; - data = pcap_next(client->handle, &hdr); + data = pcap_next(ph->handle, &hdr); if (!data) { - rate_ctr_inc(rate_ctr_group_get_ctr(client->ctrg, CLIENT_CTR_PERR)); + rate_ctr_inc2(ph->ctrg, PH_CTR_PERR); + rate_ctr_inc2(client->ctrg, CLIENT_CTR_PERR); return -1; } - if (!can_forward_packet(client, &hdr, data)) + if (!can_forward_packet(client, ph, &hdr, data)) return 0; llist_for_each_entry(conn, &client->conns, entry) @@ -197,148 +200,99 @@ return new_val - old_val; } -static void add_psbl_wrapped_ctr(struct osmo_pcap_client *client, - u_int *old_val, u_int new_val, int ctr) -{ - uint64_t inc; - - inc = get_psbl_wrapped_ctr(*old_val, new_val); - rate_ctr_add(rate_ctr_group_get_ctr(client->ctrg, ctr), inc); - *old_val = new_val; -} - -static void pcap_check_stats_cb(void *_client) +static void pcap_check_stats_cb(void *_ph) { struct pcap_stat stat; - struct osmo_pcap_client *client = _client; + struct osmo_pcap_handle *ph = _ph; + struct osmo_pcap_client *client = ph->client; int rc; + uint64_t inc; /* reschedule */ - osmo_timer_schedule(&client->pcap_stat_timer, 10, 0); + osmo_timer_schedule(&ph->pcap_stat_timer, 10, 0); memset(&stat, 0, sizeof(stat)); - rc = pcap_stats(client->handle, &stat); + rc = pcap_stats(ph->handle, &stat); if (rc != 0) { - LOGP(DCLIENT, LOGL_ERROR, "Failed to query pcap stats: %s\n", - pcap_geterr(client->handle)); - rate_ctr_inc(rate_ctr_group_get_ctr(client->ctrg, CLIENT_CTR_PERR)); + LOGPH(ph, LOGL_ERROR, "Failed to query pcap stats: %s\n", pcap_geterr(ph->handle)); + rate_ctr_inc2(ph->ctrg, PH_CTR_PERR); + rate_ctr_inc2(client->ctrg, CLIENT_CTR_PERR); return; } - add_psbl_wrapped_ctr(client, &client->last_ps_recv, stat.ps_recv, CLIENT_CTR_P_RECV); - add_psbl_wrapped_ctr(client, &client->last_ps_drop, stat.ps_drop, CLIENT_CTR_P_DROP); - add_psbl_wrapped_ctr(client, &client->last_ps_ifdrop, stat.ps_ifdrop, CLIENT_CTR_P_IFDROP); + inc = get_psbl_wrapped_ctr(ph->last_ps_recv, stat.ps_recv); + rate_ctr_add2(ph->ctrg, PH_CTR_P_RECV, inc); + rate_ctr_add2(client->ctrg, CLIENT_CTR_P_RECV, inc); + ph->last_ps_recv = stat.ps_recv; + + inc = get_psbl_wrapped_ctr(ph->last_ps_drop, stat.ps_drop); + rate_ctr_add2(ph->ctrg, PH_CTR_P_DROP, inc); + rate_ctr_add2(client->ctrg, CLIENT_CTR_P_DROP, inc); + ph->last_ps_drop = stat.ps_drop; + + inc = get_psbl_wrapped_ctr(ph->last_ps_ifdrop, stat.ps_ifdrop); + rate_ctr_add2(ph->ctrg, PH_CTR_P_IFDROP, inc); + rate_ctr_add2(client->ctrg, CLIENT_CTR_P_IFDROP, inc); + ph->last_ps_ifdrop = stat.ps_ifdrop; } -static int osmo_install_filter(struct osmo_pcap_client *client) +static int osmo_pcap_handle_install_filter(struct osmo_pcap_handle *ph) { int rc; - pcap_freecode(&client->bpf); + pcap_freecode(&ph->bpf); - if (!client->handle) { - LOGP(DCLIENT, LOGL_NOTICE, - "Filter will only be applied later.\n"); - return 1; + if (!ph->handle) { + LOGPH(ph, LOGL_NOTICE, "Filter will only be applied later\n"); + return 0; } - rc = pcap_compile(client->handle, &client->bpf, - client->filter_string, 1, PCAP_NETMASK_UNKNOWN); + rc = pcap_compile(ph->handle, &ph->bpf, + ph->client->filter_string, 1, PCAP_NETMASK_UNKNOWN); if (rc != 0) { - LOGP(DCLIENT, LOGL_ERROR, - "Failed to compile the filter: %s\n", - pcap_geterr(client->handle)); + LOGPH(ph, LOGL_ERROR, "Failed to compile the filter: %s\n", + pcap_geterr(ph->handle)); return rc; } - rc = pcap_setfilter(client->handle, &client->bpf); + rc = pcap_setfilter(ph->handle, &ph->bpf); if (rc != 0) { - LOGP(DCLIENT, LOGL_ERROR, - "Failed to set the filter on the interface: %s\n", - pcap_geterr(client->handle)); - pcap_freecode(&client->bpf); + LOGPH(ph, LOGL_ERROR, "Failed to set the filter on the interface: %s\n", pcap_geterr(ph->handle)); + pcap_freecode(&ph->bpf); return rc; } + LOGPH(ph, LOGL_INFO, "Filter applied\n"); return rc; } -static void free_all(struct osmo_pcap_client *client) -{ - if (!client->handle) - return; - - pcap_freecode(&client->bpf); - - if (client->fd.fd >= 0) { - osmo_fd_unregister(&client->fd); - client->fd.fd = -1; - } - - pcap_close(client->handle); - osmo_timer_del(&client->pcap_stat_timer); - client->handle = NULL; -} - -int osmo_client_capture(struct osmo_pcap_client *client, const char *device) +int osmo_client_start_capture(struct osmo_pcap_client *client) { + struct osmo_pcap_handle *ph; struct osmo_pcap_client_conn *conn; - int fd; - - talloc_free(client->device); - free_all(client); - - client->device = talloc_strdup(client, device); - if (!client->device) { - LOGP(DCLIENT, LOGL_ERROR, "Failed to copy string.\n"); - return 1; - } + int rc; - LOGP(DCLIENT, LOGL_INFO, "Opening device %s for capture with snaplen %zu\n", - client->device, (size_t) client->snaplen); - client->handle = pcap_open_live(client->device, client->snaplen, 0, - 1000, client->errbuf); - if (!client->handle) { - LOGP(DCLIENT, LOGL_ERROR, - "Failed to open the device: %s\n", client->errbuf); - return 2; + llist_for_each_entry(ph, &client->handles, entry) { + rc = osmo_pcap_handle_start_capture(ph); + if (rc < 0) + return rc; } - fd = pcap_fileno(client->handle); - if (fd == -1) { - LOGP(DCLIENT, LOGL_ERROR, - "No file descriptor provided.\n"); - free_all(client); - return 3; - } - - osmo_fd_setup(&client->fd, fd, OSMO_FD_READ, pcap_read_cb, client, 0); - if (osmo_fd_register(&client->fd) != 0) { - LOGP(DCLIENT, LOGL_ERROR, - "Failed to register the fd.\n"); - client->fd.fd = -1; - free_all(client); - return 4; - } - - client->pcap_stat_timer.data = client; - client->pcap_stat_timer.cb = pcap_check_stats_cb; - pcap_check_stats_cb(client); - llist_for_each_entry(conn, &client->conns, entry) osmo_client_conn_send_link(conn); - - if (client->filter_string) { - osmo_install_filter(client); - } - return 0; } int osmo_client_filter(struct osmo_pcap_client *client, const char *filter) { + struct osmo_pcap_handle *ph; + int rc = 0; talloc_free(client->filter_string); client->filter_string = talloc_strdup(client, filter); - return osmo_install_filter(client); + + llist_for_each_entry(ph, &client->handles, entry) + rc |= osmo_pcap_handle_install_filter(ph); + + return rc; } struct osmo_pcap_client *osmo_pcap_client_alloc(void *tall_ctx) @@ -348,11 +302,22 @@ if (!client) return NULL; - client->fd.fd = -1; client->snaplen = DEFAULT_SNAPLEN; + INIT_LLIST_HEAD(&client->handles); INIT_LLIST_HEAD(&client->conns); + /* initialize the stats interface */ + client->ctrg = rate_ctr_group_alloc(pcap_client, &pcap_client_ctr_group_desc, 0); + if (!client->ctrg) { + LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate rate ctr\n"); + goto ret_free; + } + return client; + +ret_free: + talloc_free(client); + return NULL; } void osmo_client_conn_free(struct osmo_pcap_client_conn *conn) @@ -407,3 +372,95 @@ conn = osmo_client_conn_alloc(client, name); return conn; } + +struct osmo_pcap_handle *osmo_client_find_handle(struct osmo_pcap_client *client, const char *devname) +{ + struct osmo_pcap_handle *ph; + + llist_for_each_entry(ph, &client->handles, entry) + if (strcmp(ph->devname, devname) == 0) + return ph; + return NULL; +} + +struct osmo_pcap_handle *osmo_pcap_handle_alloc(struct osmo_pcap_client *client, const char *devname) +{ + struct osmo_pcap_handle *ph; + + ph = talloc_zero(client, struct osmo_pcap_handle); + OSMO_ASSERT(ph); + + ph->devname = talloc_strdup(ph, devname); + OSMO_ASSERT(ph->devname); + + ph->client = client; + ph->idx = client->next_pcap_handle_idx++; + ph->fd.fd = -1; + + /* initialize the stats interface */ + ph->ctrg = rate_ctr_group_alloc(ph, &pcap_handle_ctr_group_desc, ph->idx); + OSMO_ASSERT(ph->ctrg); + rate_ctr_group_set_name(ph->ctrg, ph->devname); + + llist_add_tail(&ph->entry, &client->handles); + return ph; +} + +void osmo_pcap_handle_free(struct osmo_pcap_handle *ph) +{ + if (!ph) + return; + llist_del(&ph->entry); + + osmo_timer_del(&ph->pcap_stat_timer); + + pcap_freecode(&ph->bpf); + + if (ph->fd.fd >= 0) { + osmo_fd_unregister(&ph->fd); + ph->fd.fd = -1; + } + + if (ph->handle) { + pcap_close(ph->handle); + ph->handle = NULL; + } + + rate_ctr_group_free(ph->ctrg); + ph->ctrg = NULL; + + talloc_free(ph); +} + +int osmo_pcap_handle_start_capture(struct osmo_pcap_handle *ph) +{ + struct osmo_pcap_client *client = ph->client; + int fd; + char errbufPCAP_ERRBUF_SIZE; + + LOGPH(ph, LOGL_INFO, "Opening device for capture with snaplen %zu\n", (size_t) client->snaplen); + ph->handle = pcap_open_live(ph->devname, client->snaplen, 0, 1000, errbuf); + if (!ph->handle) { + LOGPH(ph, LOGL_ERROR, "Failed to open the device: %s\n", errbuf); + return -2; + } + + fd = pcap_fileno(ph->handle); + if (fd == -1) { + LOGPH(ph, LOGL_ERROR, "No file descriptor provided.\n"); + return -3; + } + + osmo_fd_setup(&ph->fd, fd, OSMO_FD_READ, pcap_read_cb, ph, 0); + if (osmo_fd_register(&ph->fd) != 0) { + LOGPH(ph, LOGL_ERROR, "Failed to register the fd.\n"); + return -4; + } + + osmo_timer_setup(&ph->pcap_stat_timer, pcap_check_stats_cb, ph); + pcap_check_stats_cb(ph); + + if (client->filter_string) + osmo_pcap_handle_install_filter(ph); + return 0; +}
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/osmo_client_main.c -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_client_main.c
Changed
@@ -52,29 +52,6 @@ void *tall_cli_ctx; struct osmo_pcap_client *pcap_client; - -static const struct rate_ctr_desc pcap_client_ctr_desc = { - CLIENT_CTR_CONNECT = { "server:connect", "Connects to the server" }, - CLIENT_CTR_BYTES = { "captured:bytes", "Captured bytes " }, - CLIENT_CTR_PKTS = { "captured:pkts", "Captured packets " }, - CLIENT_CTR_2BIG = { "bpf:too_big", "Captured data too big " }, - CLIENT_CTR_NOMEM = { "client:no_mem", "No memory available " }, - CLIENT_CTR_QERR = { "client:queue_err", "Can not queue data " }, - CLIENT_CTR_PERR = { "client:pcap_err", "libpcap error " }, - CLIENT_CTR_WERR = { "client:write_err", "Write error " }, - CLIENT_CTR_P_RECV = { "pcap:recv", "PCAP received packets " }, - CLIENT_CTR_P_DROP = { "pcap:drop", "PCAP dropped packets " }, - CLIENT_CTR_P_IFDROP = { "pcap:ifdrop", "iface dropped packets " }, -}; - -static const struct rate_ctr_group_desc pcap_client_ctr_group_desc = { - .group_name_prefix = "pcap:client", - .group_description = "PCAP Client statistics", - .num_ctr = ARRAY_SIZE(pcap_client_ctr_desc), - .ctr_desc = pcap_client_ctr_desc, - .class_id = OSMO_STATS_CLASS_GLOBAL, -}; - static struct vty_app_info vty_info = { .name = "OsmoPCAPClient", .version = PACKAGE_VERSION, @@ -261,13 +238,6 @@ exit(1); } - /* initialize the stats interface */ - pcap_client->ctrg = rate_ctr_group_alloc(pcap_client, &pcap_client_ctr_group_desc, 0); - if (!pcap_client->ctrg) { - LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate rate ctr\n"); - exit(1); - } - /* Default conn, always present. */ pcap_client->conn = osmo_client_conn_alloc(pcap_client, "default"); @@ -283,6 +253,11 @@ exit(1); } + rc = osmo_client_start_capture(pcap_client); + if (rc < 0) { + LOGP(DCLIENT, LOGL_ERROR, "Failed to start capturing on interfaces\n"); + exit(1); + } /* attempt to connect to the remote */ if (pcap_client->conn->srv_ip && pcap_client->conn->srv_port > 0)
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/osmo_client_network.c -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_client_network.c
Changed
@@ -59,9 +59,9 @@ static void write_data(struct osmo_pcap_client_conn *conn, struct msgb *msg) { if (osmo_wqueue_enqueue_quiet(&conn->wqueue, msg) != 0) { - LOGP(DCLIENT, LOGL_ERROR, "Failed to enqueue conn=%s (capacity: %u/%u)\n", - conn->name, conn->wqueue.current_length, conn->wqueue.max_length); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_QERR)); + LOGCONN(conn, LOGL_ERROR, "Failed to enqueue msg (capacity: %u/%u)\n", + conn->wqueue.current_length, conn->wqueue.max_length); + rate_ctr_inc2(conn->client->ctrg, CLIENT_CTR_QERR); msgb_free(msg); return; } @@ -75,8 +75,7 @@ rc = read(fd->fd, buf, sizeof(buf)); if (rc <= 0) { struct osmo_pcap_client_conn *conn = fd->data; - LOGP(DCLIENT, LOGL_ERROR, "Lost connection on read conn=%s\n", - conn->name); + LOGCONN(conn, LOGL_ERROR, "Lost connection on read\n"); lost_connection(conn); return -1; } @@ -91,9 +90,8 @@ rc = write(fd->fd, msg->data, msg->len); if (rc < 0) { struct osmo_pcap_client_conn *conn = fd->data; - LOGP(DCLIENT, LOGL_ERROR, "Lost connection on write to %s %s:%d.\n", - conn->name, conn->srv_ip, conn->srv_port); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_WERR)); + LOGCONN(conn, LOGL_ERROR, "Lost connection on write\n"); + rate_ctr_inc2(conn->client->ctrg, CLIENT_CTR_WERR); lost_connection(conn); return -1; } @@ -169,18 +167,18 @@ struct osmo_pcap_pkthdr *hdr; struct msgb *msg; int offset, ip_len; + struct osmo_pcap_handle *ph; if (in_hdr->len > in_hdr->caplen) { - LOGP(DCLIENT, LOGL_ERROR, - "Recording truncated packet, len %zu > snaplen %zu\n", + LOGCONN(conn, LOGL_ERROR, "Recording truncated packet, len %zu > snaplen %zu\n", (size_t) in_hdr->len, (size_t) in_hdr->caplen); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_2BIG)); + rate_ctr_inc2(conn->client->ctrg, CLIENT_CTR_2BIG); } msg = msgb_alloc(in_hdr->caplen + sizeof(*om_hdr) + sizeof(*hdr), "data-data"); if (!msg) { - LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate.\n"); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_NOMEM)); + LOGCONN(conn, LOGL_ERROR, "Failed to allocate\n"); + rate_ctr_inc2(conn->client->ctrg, CLIENT_CTR_NOMEM); return; } @@ -200,11 +198,17 @@ memcpy(msg->l3h, data, in_hdr->caplen); om_hdr->len = htons(msgb_l2len(msg)); - rate_ctr_add(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_BYTES), hdr->caplen); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_PKTS)); + rate_ctr_add2(conn->client->ctrg, CLIENT_CTR_BYTES, hdr->caplen); + rate_ctr_inc2(conn->client->ctrg, CLIENT_CTR_PKTS); break; case PROTOCOL_IPIP: - offset = get_iphdr_offset(pcap_datalink(conn->client->handle)); + /* TODO: support capturing from multiple interfaces here: */ + ph = llist_first_entry_or_null(&conn->client->handles, struct osmo_pcap_handle, entry); + if (!ph) { + msgb_free(msg); + return; + } + offset = get_iphdr_offset(pcap_datalink(ph->handle)); if (offset < 0) { msgb_free(msg); return; @@ -226,6 +230,7 @@ void osmo_client_conn_send_link(struct osmo_pcap_client_conn *conn) { + struct osmo_pcap_handle *ph; struct pcap_file_header *hdr; struct osmo_pcap_data *om_hdr; struct msgb *msg; @@ -234,9 +239,10 @@ if (conn->protocol == PROTOCOL_IPIP) return; - if (!conn->client->handle) { - LOGP(DCLIENT, LOGL_ERROR, - "No pcap_handle not sending link info to conn=%s\n", conn->name); + /* TODO: support capturing from multiple interfaces here: */ + ph = llist_first_entry_or_null(&conn->client->handles, struct osmo_pcap_handle, entry); + if (!ph || !ph->handle) { + LOGCONN(conn, LOGL_ERROR, "No pcap_handle not sending link info\n"); return; } @@ -258,7 +264,7 @@ hdr->thiszone = 0; hdr->sigfigs = 0; hdr->snaplen = conn->client->snaplen; - hdr->linktype = pcap_datalink(conn->client->handle); + hdr->linktype = pcap_datalink(ph->handle); write_data(conn, msg); } @@ -297,16 +303,14 @@ rc = osmo_sock_init2(AF_INET, sock_type, sock_proto, conn->source_ip, 0, conn->srv_ip, srv_port, OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT | OSMO_SOCK_F_NONBLOCK); if (rc < 0) { - LOGP(DCLIENT, LOGL_ERROR, - "Failed to connect conn=%s to %s:%d\n", - conn->name, conn->srv_ip, conn->srv_port); + LOGCONN(conn, LOGL_ERROR, "Failed to connect\n"); lost_connection(conn); return; } osmo_fd_setup(&conn->wqueue.bfd, rc, when, conn_cb, conn, 0); osmo_fd_register(&conn->wqueue.bfd); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->client->ctrg, CLIENT_CTR_CONNECT)); + rate_ctr_inc2(conn->client->ctrg, CLIENT_CTR_CONNECT); } void osmo_client_conn_reconnect(struct osmo_pcap_client_conn *conn)
View file
osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_client_stats.c
Added
@@ -0,0 +1,69 @@ +/* + * osmo-pcap-client code + * + * (C) 2024 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> + * (C) 2011-2016 by Holger Hans Peter Freyther <holger@moiji-mobile.com> + * (C) 2011 by On-Waves + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <osmocom/core/rate_ctr.h> +#include <osmocom/core/stats.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/utils.h> + +#include <osmo-pcap/common.h> +#include <osmo-pcap/osmo_pcap_client.h> + +#include "osmopcapconfig.h" + +static const struct rate_ctr_desc pcap_client_handle_ctr_desc = { + PH_CTR_PERR = { "pcap:err", "libpcap error " }, + PH_CTR_P_RECV = { "pcap:recv", "PCAP received packets " }, + PH_CTR_P_DROP = { "pcap:drop", "PCAP dropped packets " }, + PH_CTR_P_IFDROP = { "pcap:ifdrop", "iface dropped packets " }, +}; + +const struct rate_ctr_group_desc pcap_handle_ctr_group_desc = { + .group_name_prefix = "pcap:client:handle", + .group_description = "PCAP Client Handle statistics", + .num_ctr = ARRAY_SIZE(pcap_client_handle_ctr_desc), + .ctr_desc = pcap_client_handle_ctr_desc, + .class_id = OSMO_STATS_CLASS_PEER, +}; + +static const struct rate_ctr_desc pcap_client_ctr_desc = { + CLIENT_CTR_CONNECT = { "server:connect", "Connects to the server" }, + CLIENT_CTR_BYTES = { "captured:bytes", "Captured bytes " }, + CLIENT_CTR_PKTS = { "captured:pkts", "Captured packets " }, + CLIENT_CTR_2BIG = { "bpf:too_big", "Captured data too big " }, + CLIENT_CTR_NOMEM = { "client:no_mem", "No memory available " }, + CLIENT_CTR_QERR = { "client:queue_err", "Can not queue data " }, + CLIENT_CTR_PERR = { "client:pcap_err", "libpcap error " }, + CLIENT_CTR_WERR = { "client:write_err", "Write error " }, + CLIENT_CTR_P_RECV = { "pcap:recv", "PCAP received packets " }, + CLIENT_CTR_P_DROP = { "pcap:drop", "PCAP dropped packets " }, + CLIENT_CTR_P_IFDROP = { "pcap:ifdrop", "iface dropped packets " }, +}; + +const struct rate_ctr_group_desc pcap_client_ctr_group_desc = { + .group_name_prefix = "pcap:client", + .group_description = "PCAP Client statistics", + .num_ctr = ARRAY_SIZE(pcap_client_ctr_desc), + .ctr_desc = pcap_client_ctr_desc, + .class_id = OSMO_STATS_CLASS_GLOBAL, +};
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/osmo_client_vty.c -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_client_vty.c
Changed
@@ -126,11 +126,14 @@ static int config_write_client(struct vty *vty) { + struct osmo_pcap_handle *ph; + vty_out(vty, "client%s", VTY_NEWLINE); - if (pcap_client->device) + llist_for_each_entry(ph, &pcap_client->handles, entry) { vty_out(vty, " pcap device %s%s", - pcap_client->device, VTY_NEWLINE); + ph->devname, VTY_NEWLINE); + } if (pcap_client->snaplen != DEFAULT_SNAPLEN) vty_out(vty, " pcap snaplen %d%s", pcap_client->snaplen, VTY_NEWLINE); @@ -147,12 +150,28 @@ return CMD_SUCCESS; } +DEFUN(cfg_client_no_device, + cfg_client_no_device_cmd, + "no pcap device NAME", + NO_STR PCAP_STRING "the device to filter\n" "device name\n") +{ + struct osmo_pcap_handle *ph = osmo_client_find_handle(pcap_client, argv0); + if (!ph) { + vty_out(vty, "%% Device %s not found!%s", argv0, VTY_NEWLINE); + return CMD_WARNING; + } + osmo_pcap_handle_free(ph); + return CMD_SUCCESS; +} + DEFUN(cfg_client_device, cfg_client_device_cmd, "pcap device NAME", PCAP_STRING "the device to filter\n" "device name\n") { - osmo_client_capture(pcap_client, argv0); + struct osmo_pcap_handle *ph = osmo_client_find_handle(pcap_client, argv0); + if (!ph) + osmo_pcap_handle_alloc(pcap_client, argv0); return CMD_SUCCESS; } @@ -161,10 +180,6 @@ "pcap snaplen <1-262144>", /* MAXIMUM_SNAPLEN */ PCAP_STRING "snapshot length\n" "Bytes\n") { - if (pcap_client->handle) { - vty_out(vty, "'pcap snaplen' must be set before 'pcap device' to take effect!%s", VTY_NEWLINE); - return CMD_WARNING; - } pcap_client->snaplen = atoi(argv0); return CMD_SUCCESS; } @@ -544,6 +559,7 @@ install_node(&server_node, config_write_server); + install_element(CLIENT_NODE, &cfg_client_no_device_cmd); install_element(CLIENT_NODE, &cfg_client_device_cmd); install_element(CLIENT_NODE, &cfg_client_snaplen_cmd); install_element(CLIENT_NODE, &cfg_client_filter_cmd);
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/osmo_server_main.c -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_server_main.c
Changed
@@ -204,6 +204,28 @@ msgb_talloc_ctx_init(tall_srv_ctx, 0); } +static struct osmo_pcap_server *osmo_pcap_server_alloc(void *ctx) +{ + struct osmo_pcap_server *psrv = talloc_zero(ctx, struct osmo_pcap_server); + OSMO_ASSERT(psrv); + + psrv->ctrg = rate_ctr_group_alloc(psrv, &pcap_server_group_desc, 0); + OSMO_ASSERT(psrv->ctrg); + + INIT_LLIST_HEAD(&psrv->conn); + psrv->base_path = talloc_strdup(psrv, "./"); + OSMO_ASSERT(psrv->base_path); + psrv->permission_mask = 0440; + psrv->max_size = 1073741824; /* 1024^3, 1GB **/ + psrv->max_size_enabled = true; + psrv->max_snaplen = DEFAULT_SNAPLEN; + /* By default rotate daily: */ + psrv->rotate_localtime.enabled = true; + psrv->rotate_localtime.intv = TIME_INTERVAL_DAY; + psrv->rotate_localtime.modulus = 1; + return psrv; +} + int main(int argc, char **argv) { int rc; @@ -236,27 +258,7 @@ osmo_tls_init(); - pcap_server = talloc_zero(tall_srv_ctx, struct osmo_pcap_server); - if (!pcap_server) { - LOGP(DSERVER, LOGL_ERROR, "Failed to allocate osmo_pcap_server.\n"); - exit(1); - } - pcap_server->ctrg = rate_ctr_group_alloc(pcap_server, &pcap_server_group_desc, 0); - if (!pcap_server->ctrg) { - LOGP(DSERVER, LOGL_ERROR, "Failed to allocate rate counter.\n"); - exit(1); - } - - INIT_LLIST_HEAD(&pcap_server->conn); - pcap_server->base_path = talloc_strdup(pcap_server, "./"); - pcap_server->permission_mask = 0440; - pcap_server->max_size = 1073741824; /* 1024^3, 1GB **/ - pcap_server->max_size_enabled = true; - pcap_server->max_snaplen = DEFAULT_SNAPLEN; - /* By default rotate daily: */ - pcap_server->rotate_localtime.enabled = true; - pcap_server->rotate_localtime.intv = TIME_INTERVAL_DAY; - pcap_server->rotate_localtime.modulus = 1; + pcap_server = osmo_pcap_server_alloc(tall_srv_ctx); if (vty_read_config_file(config_file, NULL) < 0) { LOGP(DSERVER, LOGL_ERROR,
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/osmo_server_network.c -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_server_network.c
Changed
@@ -121,8 +121,8 @@ if (conn->curr_filename) { client_event(conn, "closingtracefile", conn->curr_filename); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->ctrg, PEER_CTR_PROTATE)); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->server->ctrg, SERVER_CTR_PROTATE)); + rate_ctr_inc2(conn->ctrg, PEER_CTR_PROTATE); + rate_ctr_inc2(conn->server->ctrg, SERVER_CTR_PROTATE); talloc_free(conn->curr_filename); conn->curr_filename = NULL; } @@ -568,12 +568,12 @@ conn->pend = sizeof(*conn->data); /* count the full packet we got */ - rate_ctr_inc(rate_ctr_group_get_ctr(conn->ctrg, PEER_CTR_PKTS)); - rate_ctr_inc(rate_ctr_group_get_ctr(conn->server->ctrg, SERVER_CTR_PKTS)); + rate_ctr_inc2(conn->ctrg, PEER_CTR_PKTS); + rate_ctr_inc2(conn->server->ctrg, SERVER_CTR_PKTS); /* count the bytes of it */ - rate_ctr_add(rate_ctr_group_get_ctr(conn->ctrg, PEER_CTR_BYTES), conn->data->len); - rate_ctr_add(rate_ctr_group_get_ctr(conn->server->ctrg, SERVER_CTR_BYTES), conn->data->len); + rate_ctr_add2(conn->ctrg, PEER_CTR_BYTES, conn->data->len); + rate_ctr_add2(conn->server->ctrg, SERVER_CTR_BYTES, conn->data->len); switch (conn->data->type) { case PKT_LINK_HDR: @@ -666,7 +666,7 @@ return; } - rate_ctr_inc(rate_ctr_group_get_ctr(client->ctrg, PEER_CTR_CONNECT)); + rate_ctr_inc2(client->ctrg, PEER_CTR_CONNECT); client->state = STATE_INITIAL; client->pend = sizeof(*client->data); @@ -711,7 +711,7 @@ server = fd->data; /* count any accept to see no clients */ - rate_ctr_inc(rate_ctr_group_get_ctr(server->ctrg, SERVER_CTR_CONNECT)); + rate_ctr_inc2(server->ctrg, SERVER_CTR_CONNECT); llist_for_each_entry(conn, &server->conn, entry) { if (conn->remote_addr.s_addr == addr.sin_addr.s_addr) { @@ -723,7 +723,7 @@ } } - rate_ctr_inc(rate_ctr_group_get_ctr(server->ctrg, SERVER_CTR_NOCLIENT)); + rate_ctr_inc2(server->ctrg, SERVER_CTR_NOCLIENT); /* * TODO: In the future start with a tls handshake and see if we know
View file
osmo-pcap_0.5.0.15.b614.tar.xz/src/osmo_server_vty.c -> osmo-pcap_0.5.0.24.16b3.tar.xz/src/osmo_server_vty.c
Changed
@@ -149,8 +149,7 @@ "base-path PATH", "Base path for log files\n" "Path\n") { - talloc_free(pcap_server->base_path); - pcap_server->base_path = talloc_strdup(pcap_server, argv0); + osmo_talloc_replace_string(pcap_server, &pcap_server->base_path, argv0); return CMD_SUCCESS; }
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.