This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "".
The branch, master has been updated via 6a30a1beb7ec2182239ea3ba1ef71a6f9a944df9 (commit) via a643bfe4210827d43dde0e6d69097decc2fa77d0 (commit) via 03490694085060aec7de6d21ef674f461adcf373 (commit) from e2786e3ed30405b16da8080e2b0ed11b0fd52fc7 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 6a30a1beb7ec2182239ea3ba1ef71a6f9a944df9 Author: Matias Elo matias.elo@nokia.com Date: Mon May 27 10:19:17 2019 +0300
linux-gen: pcapng: limit internal symbol visibility to odp library
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com
diff --git a/platform/linux-generic/include/odp_pcapng.h b/platform/linux-generic/include/odp_pcapng.h index 8e0e624e8..b88427238 100644 --- a/platform/linux-generic/include/odp_pcapng.h +++ b/platform/linux-generic/include/odp_pcapng.h @@ -1,56 +1,29 @@ /* Copyright (c) 2018, Linaro Limited + * Copyright (c) 2019, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */
-#include <sys/types.h> +#ifndef ODP_PCAPNG_H_ +#define ODP_PCAPNG_H_
-#include <odp_packet_io_internal.h> - -#define PCAPNG_BLOCK_TYPE_EPB 0x00000006UL -#define PCAPNG_BLOCK_TYPE_SHB 0x0A0D0D0AUL -#define PCAPNG_BLOCK_TYPE_IDB 0x00000001UL -#define PCAPNG_ENDIAN_MAGIC 0x1A2B3C4DUL -#define PCAPNG_DATA_ALIGN 4 -#define PCAPNG_LINKTYPE_ETHERNET 0x1 +#ifdef __cplusplus +extern "C" { +#endif
-/* inotify */ -#define INOTIFY_BUF_LEN (16 * (sizeof(struct inotify_event))) -#define PCAPNG_WATCH_DIR "/var/run/odp/" +#include <odp/api/packet.h> +#include <odp_packet_io_internal.h>
-/* pcapng: enhanced packet block file encoding */ -typedef struct ODP_PACKED pcapng_section_hdr_block_s { - uint32_t block_type; - uint32_t block_total_length; - uint32_t magic; - uint16_t version_major; - uint16_t version_minor; - int64_t section_len; - uint32_t block_total_length2; -} pcapng_section_hdr_block_t; +#include <stdint.h>
-typedef struct pcapng_interface_description_block { - uint32_t block_type; - uint32_t block_total_length; - uint16_t linktype; - uint16_t reserved; - uint32_t snaplen; - uint32_t block_total_length2; -} pcapng_interface_description_block_t; +int _odp_pcapng_start(pktio_entry_t *entry); +void _odp_pcapng_stop(pktio_entry_t *entry); +int _odp_pcapng_write_pkts(pktio_entry_t *entry, int qidx, + const odp_packet_t packets[], int num);
-typedef struct pcapng_enhanced_packet_block_s { - uint32_t block_type; - uint32_t block_total_length; - uint32_t interface_idx; - uint32_t timestamp_high; - uint32_t timestamp_low; - uint32_t captured_len; - uint32_t packet_len; -} pcapng_enhanced_packet_block_t; +#ifdef __cplusplus +} +#endif
-int pcapng_prepare(pktio_entry_t *entry); -void pcapng_destroy(pktio_entry_t *entry); -int write_pcapng_hdr(pktio_entry_t *entry, int qidx); -int write_pcapng_pkts(pktio_entry_t *entry, int qidx, - const odp_packet_t packets[], int num); +#endif /* ODP_PCAPNG_H_ */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 097618a3e..1bf0469e7 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -530,8 +530,8 @@ int odp_pktio_start(odp_pktio_t hdl) entry->s.name, entry->s.num_in_queue, entry->s.num_out_queue);
if (_ODP_PCAPNG) { - if (pcapng_prepare(entry)) - ODP_ERR("pcap init failed, won't capture\n"); + if (_odp_pcapng_start(entry)) + ODP_ERR("pcapng start failed, won't capture\n"); }
return res; @@ -559,7 +559,7 @@ static int _pktio_stop(pktio_entry_t *entry) entry->s.state = PKTIO_STATE_STOPPED;
if (_ODP_PCAPNG) - pcapng_destroy(entry); + _odp_pcapng_stop(entry);
return res; } @@ -1758,7 +1758,7 @@ static inline void _odp_dump_pcapng_pkts(pktio_entry_t *entry, int qidx, const odp_packet_t packets[], int num) { if (odp_unlikely(entry->s.pcapng.state[qidx] == PCAPNG_WR_PKT)) - write_pcapng_pkts(entry, qidx, packets, num); + _odp_pcapng_write_pkts(entry, qidx, packets, num); }
int odp_pktin_recv(odp_pktin_queue_t queue, odp_packet_t packets[], int num) diff --git a/platform/linux-generic/odp_pcapng.c b/platform/linux-generic/odp_pcapng.c index cf7cd978e..b6d91fbc8 100644 --- a/platform/linux-generic/odp_pcapng.c +++ b/platform/linux-generic/odp_pcapng.c @@ -28,6 +28,47 @@ #include <sys/inotify.h> #include <sys/select.h>
+#define PCAPNG_BLOCK_TYPE_EPB 0x00000006UL +#define PCAPNG_BLOCK_TYPE_SHB 0x0A0D0D0AUL +#define PCAPNG_BLOCK_TYPE_IDB 0x00000001UL +#define PCAPNG_ENDIAN_MAGIC 0x1A2B3C4DUL +#define PCAPNG_DATA_ALIGN 4 +#define PCAPNG_LINKTYPE_ETHERNET 0x1 + +/* inotify */ +#define INOTIFY_BUF_LEN (16 * (sizeof(struct inotify_event))) +#define PCAPNG_WATCH_DIR "/var/run/odp/" + +/* pcapng: enhanced packet block file encoding */ +typedef struct ODP_PACKED pcapng_section_hdr_block_s { + uint32_t block_type; + uint32_t block_total_length; + uint32_t magic; + uint16_t version_major; + uint16_t version_minor; + int64_t section_len; + uint32_t block_total_length2; +} pcapng_section_hdr_block_t; + +typedef struct pcapng_interface_description_block { + uint32_t block_type; + uint32_t block_total_length; + uint16_t linktype; + uint16_t reserved; + uint32_t snaplen; + uint32_t block_total_length2; +} pcapng_interface_description_block_t; + +typedef struct pcapng_enhanced_packet_block_s { + uint32_t block_type; + uint32_t block_total_length; + uint32_t interface_idx; + uint32_t timestamp_high; + uint32_t timestamp_low; + uint32_t captured_len; + uint32_t packet_len; +} pcapng_enhanced_packet_block_t; + typedef struct ODP_ALIGNED_CACHE { odp_shm_t shm; pktio_entry_t *entry[ODP_CONFIG_PKTIO_ENTRIES]; @@ -41,6 +82,8 @@ typedef struct ODP_ALIGNED_CACHE {
static pcapng_global_t *pcapng_gbl;
+int write_pcapng_hdr(pktio_entry_t *entry, int qidx); + int _odp_pcapng_init_global(void) { odp_shm_t shm; @@ -241,7 +284,7 @@ static int get_fifo_max_size(void) return ret; }
-int pcapng_prepare(pktio_entry_t *entry) +int _odp_pcapng_start(pktio_entry_t *entry) { int ret = -1, fd; pthread_attr_t attr; @@ -342,12 +385,12 @@ int pcapng_prepare(pktio_entry_t *entry) out_destroy: odp_spinlock_unlock(&pcapng_gbl->lock);
- pcapng_destroy(entry); + _odp_pcapng_stop(entry);
return ret; }
-void pcapng_destroy(pktio_entry_t *entry) +void _odp_pcapng_stop(pktio_entry_t *entry) { int ret; unsigned int i; @@ -465,8 +508,8 @@ static ssize_t write_fifo(int fd, struct iovec *iov, int iovcnt) return len; }
-int write_pcapng_pkts(pktio_entry_t *entry, int qidx, - const odp_packet_t packets[], int num) +int _odp_pcapng_write_pkts(pktio_entry_t *entry, int qidx, + const odp_packet_t packets[], int num) { int i = 0; struct iovec packet_iov[3 * num];
commit a643bfe4210827d43dde0e6d69097decc2fa77d0 Author: Matias Elo matias.elo@nokia.com Date: Fri May 24 17:32:36 2019 +0300
linux-gen: pcapng: support simultaneous capture from multiple devices
Previously, one could capture traffic only from the first started pktio device.
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com Reported-by: Jari Mustajärvi jari.mustajarvi@nokia-bell-labs.com
diff --git a/platform/linux-generic/include/odp_global_data.h b/platform/linux-generic/include/odp_global_data.h index a12d12973..fdb057b3e 100644 --- a/platform/linux-generic/include/odp_global_data.h +++ b/platform/linux-generic/include/odp_global_data.h @@ -65,10 +65,6 @@ struct odp_global_data_ro_t { /* Modifiable global data. Memory region is shared and synchronized amongst all * worker processes. */ struct odp_global_data_rw_t { - int inotify_pcapng_fd; - int inotify_watch_fd; - pthread_t inotify_thread; - int inotify_pcapng_is_running; odp_bool_t dpdk_initialized; odp_bool_t inline_timers; }; diff --git a/platform/linux-generic/include/odp_init_internal.h b/platform/linux-generic/include/odp_init_internal.h index 57ea79f98..204f44838 100644 --- a/platform/linux-generic/include/odp_init_internal.h +++ b/platform/linux-generic/include/odp_init_internal.h @@ -25,6 +25,9 @@ int odp_thread_init_local(odp_thread_type_t type); int odp_thread_term_local(void); int odp_thread_term_global(void);
+int _odp_pcapng_init_global(void); +int _odp_pcapng_term_global(void); + int odp_pool_init_global(void); int odp_pool_init_local(void); int odp_pool_term_global(void); diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 4954d5f04..097618a3e 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -1,4 +1,5 @@ /* Copyright (c) 2013-2018, Linaro Limited + * Copyright (c) 2019, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -97,6 +98,13 @@ int odp_pktio_init_global(void) } }
+ if (_ODP_PCAPNG) { + if (_odp_pcapng_init_global()) { + ODP_ERR("Failed to initialize pcapng\n"); + return -1; + } + } + return 0; }
@@ -1277,6 +1285,12 @@ int odp_pktio_term_global(void) pktio_if); }
+ if (_ODP_PCAPNG) { + ret = _odp_pcapng_term_global(); + if (ret) + ODP_ERR("Failed to terminate pcapng\n"); + } + ret = odp_shm_free(odp_shm_lookup("_odp_pktio_entries")); if (ret != 0) ODP_ERR("shm free failed for _odp_pktio_entries"); diff --git a/platform/linux-generic/odp_pcapng.c b/platform/linux-generic/odp_pcapng.c index e1f7ac08f..cf7cd978e 100644 --- a/platform/linux-generic/odp_pcapng.c +++ b/platform/linux-generic/odp_pcapng.c @@ -1,4 +1,5 @@ /* Copyright (c) 2018, Linaro Limited + * Copyright (c) 2019, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -8,11 +9,14 @@
#if defined(_ODP_PCAPNG) && _ODP_PCAPNG == 1
+#include <odp_pcapng.h> +#include <odp/api/plat/packet_inlines.h> +#include <odp/api/shared_memory.h> +#include <odp_init_internal.h> #include <odp_macros_internal.h> #include <odp_packet_io_internal.h> -#include <odp/api/plat/packet_inlines.h> #include <odp_posix_extensions.h> -#include <odp_pcapng.h> +#include <odp/api/spinlock.h>
#include <errno.h> #include <fcntl.h> @@ -24,6 +28,50 @@ #include <sys/inotify.h> #include <sys/select.h>
+typedef struct ODP_ALIGNED_CACHE { + odp_shm_t shm; + pktio_entry_t *entry[ODP_CONFIG_PKTIO_ENTRIES]; + int num_entries; + pthread_t inotify_thread; + int inotify_fd; + int inotify_watch_fd; + int inotify_is_running; + odp_spinlock_t lock; +} pcapng_global_t; + +static pcapng_global_t *pcapng_gbl; + +int _odp_pcapng_init_global(void) +{ + odp_shm_t shm; + + shm = odp_shm_reserve("_odp_pcapng_gbl", sizeof(pcapng_global_t), + ODP_PAGE_SIZE, 0); + if (shm == ODP_SHM_INVALID) + return -1; + + pcapng_gbl = odp_shm_addr(shm); + + memset(pcapng_gbl, 0, sizeof(pcapng_global_t)); + pcapng_gbl->shm = shm; + + odp_spinlock_init(&pcapng_gbl->lock); + + return 0; +} + +int _odp_pcapng_term_global(void) +{ + int ret = 0; + + if (odp_shm_free(pcapng_gbl->shm)) { + ODP_ERR("shm free failed"); + ret = -1; + } + + return ret; +} + static void pcapng_drain_fifo(int fd) { char buffer[4096]; @@ -108,42 +156,66 @@ static int get_qidx_from_fifo(pktio_entry_t *entry, char *name) return -1; }
+static pktio_entry_t *pktio_from_event(struct inotify_event *event) +{ + int i; + + odp_spinlock_lock(&pcapng_gbl->lock); + + for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; i++) { + pktio_entry_t *entry = pcapng_gbl->entry[i]; + + if (entry == NULL) + continue; + + if (get_qidx_from_fifo(entry, event->name) != -1) { + odp_spinlock_unlock(&pcapng_gbl->lock); + return entry; + } + } + + odp_spinlock_unlock(&pcapng_gbl->lock); + + return NULL; +} + static void *inotify_update(void *arg) { - pktio_entry_t *entry = (pktio_entry_t *)arg; struct timeval time; ssize_t rdlen; int offset; char buffer[INOTIFY_BUF_LEN]; fd_set rfds; + int inotify_fd = *(int *)arg;
while (1) { offset = 0; FD_ZERO(&rfds); - FD_SET(odp_global_rw->inotify_pcapng_fd, &rfds); + FD_SET(inotify_fd, &rfds); time.tv_sec = 2; time.tv_usec = 0; - select(odp_global_rw->inotify_pcapng_fd + 1, &rfds, NULL, - NULL, &time); - if (FD_ISSET(odp_global_rw->inotify_pcapng_fd, &rfds)) { - rdlen = read(odp_global_rw->inotify_pcapng_fd, - buffer, INOTIFY_BUF_LEN); + select(inotify_fd + 1, &rfds, NULL, NULL, &time); + if (FD_ISSET(inotify_fd, &rfds)) { + rdlen = read(inotify_fd, buffer, INOTIFY_BUF_LEN); while (offset < rdlen) { int qidx; struct inotify_event *event = (struct inotify_event *)(void *) &buffer[offset]; + pktio_entry_t *entry;
- qidx = get_qidx_from_fifo(entry, event->name); - if (qidx == -1) { - offset += sizeof(struct inotify_event) + + offset += sizeof(struct inotify_event) + event->len; + + entry = pktio_from_event(event); + if (entry == NULL) + continue; + + qidx = get_qidx_from_fifo(entry, event->name); + if (qidx == -1) continue; - }
inotify_event_handle(entry, qidx, event); - offset += sizeof(struct inotify_event) + - event->len; } } } @@ -222,24 +294,30 @@ int pcapng_prepare(pktio_entry_t *entry) entry->s.pcapng.fd[i] = fd; }
+ odp_spinlock_lock(&pcapng_gbl->lock); + /* already running from a previous pktio */ - if (odp_global_rw->inotify_pcapng_is_running == 1) + if (pcapng_gbl->inotify_is_running == 1) { + pcapng_gbl->entry[odp_pktio_index(entry->s.handle)] = entry; + pcapng_gbl->num_entries++; + odp_spinlock_unlock(&pcapng_gbl->lock); return 0; + }
- odp_global_rw->inotify_pcapng_fd = -1; - odp_global_rw->inotify_watch_fd = -1; + pcapng_gbl->inotify_fd = -1; + pcapng_gbl->inotify_watch_fd = -1;
- odp_global_rw->inotify_pcapng_fd = inotify_init(); - if (odp_global_rw->inotify_pcapng_fd == -1) { + pcapng_gbl->inotify_fd = inotify_init(); + if (pcapng_gbl->inotify_fd == -1) { ODP_ERR("can't init inotify. pcap disabled\n"); goto out_destroy; }
- odp_global_rw->inotify_watch_fd = - inotify_add_watch(odp_global_rw->inotify_pcapng_fd, - PCAPNG_WATCH_DIR, IN_CLOSE | IN_OPEN); + pcapng_gbl->inotify_watch_fd = inotify_add_watch(pcapng_gbl->inotify_fd, + PCAPNG_WATCH_DIR, + IN_CLOSE | IN_OPEN);
- if (odp_global_rw->inotify_watch_fd == -1) { + if (pcapng_gbl->inotify_watch_fd == -1) { ODP_ERR("can't register inotify for %s. pcap disabled\n", strerror(errno)); goto out_destroy; @@ -247,16 +325,23 @@ int pcapng_prepare(pktio_entry_t *entry)
/* create a thread to poll inotify triggers */ pthread_attr_init(&attr); - ret = pthread_create(&odp_global_rw->inotify_thread, &attr, - inotify_update, entry); - if (ret) + ret = pthread_create(&pcapng_gbl->inotify_thread, &attr, inotify_update, + &pcapng_gbl->inotify_fd); + if (ret) { ODP_ERR("can't start inotify thread. pcap disabled\n"); - else - odp_global_rw->inotify_pcapng_is_running = 1; + } else { + pcapng_gbl->entry[odp_pktio_index(entry->s.handle)] = entry; + pcapng_gbl->num_entries++; + pcapng_gbl->inotify_is_running = 1; + } + + odp_spinlock_unlock(&pcapng_gbl->lock);
return ret;
out_destroy: + odp_spinlock_unlock(&pcapng_gbl->lock); + pcapng_destroy(entry);
return ret; @@ -269,24 +354,36 @@ void pcapng_destroy(pktio_entry_t *entry) unsigned int max_queue = MAX(entry->s.num_in_queue, entry->s.num_out_queue);
- if (odp_global_rw->inotify_pcapng_is_running == 1) { - ret = pthread_cancel(odp_global_rw->inotify_thread); + odp_spinlock_lock(&pcapng_gbl->lock); + + pcapng_gbl->entry[odp_pktio_index(entry->s.handle)] = NULL; + pcapng_gbl->num_entries--; + + if (pcapng_gbl->inotify_is_running == 1 && + pcapng_gbl->num_entries == 0) { + ret = pthread_cancel(pcapng_gbl->inotify_thread); if (ret) ODP_ERR("can't cancel inotify thread %s\n", strerror(errno)); + pcapng_gbl->inotify_is_running = 0; }
- /* fd's will be -1 in case of any failure */ - ret = inotify_rm_watch(odp_global_rw->inotify_pcapng_fd, - odp_global_rw->inotify_watch_fd); - if (ret) - ODP_ERR("can't deregister inotify %s\n", strerror(errno)); + if (pcapng_gbl->num_entries == 0) { + /* fd's will be -1 in case of any failure */ + ret = inotify_rm_watch(pcapng_gbl->inotify_fd, + pcapng_gbl->inotify_watch_fd); + if (ret) + ODP_ERR("can't deregister inotify %s\n", + strerror(errno)); + + if (pcapng_gbl->inotify_fd != -1) + close(pcapng_gbl->inotify_fd);
- if (odp_global_rw->inotify_pcapng_fd != -1) - close(odp_global_rw->inotify_pcapng_fd); + if (pcapng_gbl->inotify_watch_fd != -1) + close(pcapng_gbl->inotify_watch_fd); + }
- if (odp_global_rw->inotify_watch_fd != -1) - close(odp_global_rw->inotify_watch_fd); + odp_spinlock_unlock(&pcapng_gbl->lock);
for (i = 0; i < max_queue; i++) { char pcapng_name[128];
commit 03490694085060aec7de6d21ef674f461adcf373 Author: Matias Elo matias.elo@nokia.com Date: Fri May 24 12:57:06 2019 +0300
linux-gen: pcapng: set pipe read permissions
Make pipe readable by other processes.
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-by: Petri Savolainen petri.savolainen@nokia.com Reported-by: Jari Mustajärvi jari.mustajarvi@nokia-bell-labs.com
diff --git a/platform/linux-generic/odp_pcapng.c b/platform/linux-generic/odp_pcapng.c index 21fa7b2c5..e1f7ac08f 100644 --- a/platform/linux-generic/odp_pcapng.c +++ b/platform/linux-generic/odp_pcapng.c @@ -199,6 +199,10 @@ int pcapng_prepare(pktio_entry_t *entry) continue; }
+ if (chmod(pcapng_path, S_IRUSR | S_IRGRP)) + ODP_ERR("Failed to change file permission for %s %s\n", + pcapng_path, strerror(errno)); + fd = open(pcapng_path, O_RDWR | O_NONBLOCK); if (fd == -1) { ODP_ERR("Fail to open fifo\n");
-----------------------------------------------------------------------
Summary of changes: platform/linux-generic/include/odp_global_data.h | 4 - platform/linux-generic/include/odp_init_internal.h | 3 + platform/linux-generic/include/odp_pcapng.h | 61 ++---- platform/linux-generic/odp_packet_io.c | 22 +- platform/linux-generic/odp_pcapng.c | 234 +++++++++++++++++---- 5 files changed, 227 insertions(+), 97 deletions(-)
hooks/post-receive