Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Sep 2021 14:10:41 GMT
From:      Vincenzo Maffione <vmaffione@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: d61f95996174 - stable/13 - netmap: monitor: add a flag to distinguish packet direction
Message-ID:  <202109261410.18QEAfsE072186@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by vmaffione:

URL: https://cgit.FreeBSD.org/src/commit/?id=d61f95996174d3068357f176532d5fdc946269af

commit d61f95996174d3068357f176532d5fdc946269af
Author:     Vincenzo Maffione <vmaffione@FreeBSD.org>
AuthorDate: 2021-03-29 16:32:54 +0000
Commit:     Vincenzo Maffione <vmaffione@FreeBSD.org>
CommitDate: 2021-09-26 14:00:04 +0000

    netmap: monitor: add a flag to distinguish packet direction
    
    The netmap monitor intercepts any TX/RX packets on the monitored
    port. However, before this change there was no way to tell
    whether an intercepted packet was being transmitted or received
    on the monitored port.
    A TXMON flag in the netmap slot has been added for this purpose.
    
    (cherry picked from commit 660a47cb991d5a7ca69cd8dd9c09a5288d49e405)
---
 sys/dev/netmap/netmap_monitor.c | 8 ++++++--
 sys/net/netmap.h                | 5 +++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/sys/dev/netmap/netmap_monitor.c b/sys/dev/netmap/netmap_monitor.c
index 1f5ff65b3b81..9e5d57f7ff0f 100644
--- a/sys/dev/netmap/netmap_monitor.c
+++ b/sys/dev/netmap/netmap_monitor.c
@@ -38,6 +38,8 @@
  * the traffic transiting on both the tx and rx corresponding rings in the
  * monitored adapter. During registration, the user can choose if she wants
  * to intercept tx only, rx only, or both tx and rx traffic.
+ * The slots containing traffic intercepted in the tx direction will have
+ * the NS_TXMON flag set.
  *
  * If the monitor is not able to cope with the stream of frames, excess traffic
  * will be dropped.
@@ -590,6 +592,7 @@ netmap_zmon_parent_sync(struct netmap_kring *kring, int flags, enum txrx tx)
 	u_int beg, end, i;
 	u_int lim = kring->nkr_num_slots - 1,
 	      mlim; // = mkring->nkr_num_slots - 1;
+	uint16_t txmon = kring->tx == NR_TX ? NS_TXMON : 0;
 
 	if (mkring == NULL) {
 		nm_prlim(5, "NULL monitor on %s", kring->name);
@@ -659,7 +662,7 @@ netmap_zmon_parent_sync(struct netmap_kring *kring, int flags, enum txrx tx)
 		ms->len = s->len;
 		s->len = tmp;
 
-		ms->flags = s->flags;
+		ms->flags = (s->flags & ~NS_TXMON) | txmon;
 		s->flags |= NS_BUF_CHANGED;
 
 		beg = nm_next(beg, lim);
@@ -726,6 +729,7 @@ static void
 netmap_monitor_parent_sync(struct netmap_kring *kring, u_int first_new, int new_slots)
 {
 	u_int j;
+	uint16_t txmon = kring->tx == NR_TX ? NS_TXMON : 0;
 
 	for (j = 0; j < kring->n_monitors; j++) {
 		struct netmap_kring *mkring = kring->monitors[j];
@@ -777,7 +781,7 @@ netmap_monitor_parent_sync(struct netmap_kring *kring, u_int first_new, int new_
 
 			memcpy(dst, src, copy_len);
 			ms->len = copy_len;
-			ms->flags = s->flags;
+			ms->flags = (s->flags & ~NS_TXMON) | txmon;
 			sent++;
 
 			beg = nm_next(beg, lim);
diff --git a/sys/net/netmap.h b/sys/net/netmap.h
index c040683651d0..4d091ccc635d 100644
--- a/sys/net/netmap.h
+++ b/sys/net/netmap.h
@@ -219,6 +219,11 @@ struct netmap_slot {
 	 * The 'len' field refers to the individual fragment.
 	 */
 
+#define NS_TXMON	0x0040
+	/* (monitor ports only) the packet comes from the TX
+	 * ring of the monitored port
+	 */
+
 #define	NS_PORT_SHIFT	8
 #define	NS_PORT_MASK	(0xff << NS_PORT_SHIFT)
 	/*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109261410.18QEAfsE072186>