2 * Copyright (C) 2014-2016 Giuseppe Lettieri
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * netmap monitors can be used to do monitoring of network traffic
33 * on another adapter, when the latter adapter is working in netmap mode.
35 * Monitors offer to userspace the same interface as any other netmap port,
36 * with as many pairs of netmap rings as the monitored adapter.
37 * However, only the rx rings are actually used. Each monitor rx ring receives
38 * the traffic transiting on both the tx and rx corresponding rings in the
39 * monitored adapter. During registration, the user can choose if she wants
40 * to intercept tx only, rx only, or both tx and rx traffic.
42 * If the monitor is not able to cope with the stream of frames, excess traffic
45 * If the monitored adapter leaves netmap mode, the monitor has to be restarted.
47 * Monitors can be either zero-copy or copy-based.
49 * Copy monitors see the frames before they are consumed:
51 * - For tx traffic, this is when the application sends them, before they are
52 * passed down to the adapter.
54 * - For rx traffic, this is when they are received by the adapter, before
55 * they are sent up to the application, if any (note that, if no
56 * application is reading from a monitored ring, the ring will eventually
57 * fill up and traffic will stop).
59 * Zero-copy monitors only see the frames after they have been consumed:
61 * - For tx traffic, this is after the slots containing the frames have been
62 * marked as free. Note that this may happen at a considerably delay after
63 * frame transmission, since freeing of slots is often done lazily.
65 * - For rx traffic, this is after the consumer on the monitored adapter
66 * has released them. In most cases, the consumer is a userspace
67 * application which may have modified the frame contents.
69 * Several copy monitors may be active on any ring. Zero-copy monitors,
70 * instead, need exclusive access to each of the monitored rings. This may
71 * change in the future, if we implement zero-copy monitor chaining.
76 #if defined(__FreeBSD__)
77 #include <sys/cdefs.h> /* prerequisite */
79 #include <sys/types.h>
80 #include <sys/errno.h>
81 #include <sys/param.h> /* defines used in kernel.h */
82 #include <sys/kernel.h> /* types used in module initialization */
83 #include <sys/malloc.h>
86 #include <sys/rwlock.h>
87 #include <sys/selinfo.h>
88 #include <sys/sysctl.h>
89 #include <sys/socket.h> /* sockaddrs */
91 #include <net/if_var.h>
92 #include <machine/bus.h> /* bus_dmamap_* */
93 #include <sys/refcount.h>
100 #elif defined(__APPLE__)
102 #warning OSX support is only partial
103 #include "osx_glue.h"
105 #elif defined(_WIN32)
106 #include "win_glue.h"
109 #error Unsupported platform
111 #endif /* unsupported */
117 #include <net/netmap.h>
118 #include <dev/netmap/netmap_kern.h>
119 #include <dev/netmap/netmap_mem2.h>
123 #define NM_MONITOR_MAXSLOTS 4096
126 ********************************************************************
127 * functions common to both kind of monitors
128 ********************************************************************
131 /* nm_sync callback for the monitor's own tx rings.
132 * This makes no sense and always returns error
135 netmap_monitor_txsync(struct netmap_kring *kring, int flags)
137 RD(1, "%s %x", kring->name, flags);
141 /* nm_sync callback for the monitor's own rx rings.
142 * Note that the lock in netmap_zmon_parent_sync only protects
143 * writers among themselves. Synchronization between writers
144 * (i.e., netmap_zmon_parent_txsync and netmap_zmon_parent_rxsync)
145 * and readers (i.e., netmap_zmon_rxsync) relies on memory barriers.
148 netmap_monitor_rxsync(struct netmap_kring *kring, int flags)
150 ND("%s %x", kring->name, flags);
151 kring->nr_hwcur = kring->rcur;
156 /* nm_krings_create callbacks for monitors.
159 netmap_monitor_krings_create(struct netmap_adapter *na)
161 int error = netmap_krings_create(na, 0);
164 /* override the host rings callbacks */
165 na->tx_rings[na->num_tx_rings].nm_sync = netmap_monitor_txsync;
166 na->rx_rings[na->num_rx_rings].nm_sync = netmap_monitor_rxsync;
170 /* nm_krings_delete callback for monitors */
172 netmap_monitor_krings_delete(struct netmap_adapter *na)
174 netmap_krings_delete(na);
179 nm_txrx2flag(enum txrx t)
181 return (t == NR_RX ? NR_MONITOR_RX : NR_MONITOR_TX);
184 /* allocate the monitors array in the monitored kring */
186 nm_monitor_alloc(struct netmap_kring *kring, u_int n)
189 struct netmap_kring **nm;
191 if (n <= kring->max_monitors)
192 /* we already have more entries that requested */
195 len = sizeof(struct netmap_kring *) * n;
197 nm = realloc(kring->monitors, len, M_DEVBUF, M_NOWAIT | M_ZERO);
199 nm = realloc(kring->monitors, len, sizeof(struct netmap_kring *)*kring->max_monitors);
204 kring->monitors = nm;
205 kring->max_monitors = n;
210 /* deallocate the parent array in the parent adapter */
212 nm_monitor_dealloc(struct netmap_kring *kring)
214 if (kring->monitors) {
215 if (kring->n_monitors > 0) {
216 D("freeing not empty monitor array for %s (%d dangling monitors)!", kring->name,
219 free(kring->monitors, M_DEVBUF);
220 kring->monitors = NULL;
221 kring->max_monitors = 0;
222 kring->n_monitors = 0;
227 * monitors work by replacing the nm_sync() and possibly the
228 * nm_notify() callbacks in the monitored rings.
230 static int netmap_zmon_parent_txsync(struct netmap_kring *, int);
231 static int netmap_zmon_parent_rxsync(struct netmap_kring *, int);
232 static int netmap_monitor_parent_txsync(struct netmap_kring *, int);
233 static int netmap_monitor_parent_rxsync(struct netmap_kring *, int);
234 static int netmap_monitor_parent_notify(struct netmap_kring *, int);
237 /* add the monitor mkring to the list of monitors of kring.
238 * If this is the first monitor, intercept the callbacks
241 netmap_monitor_add(struct netmap_kring *mkring, struct netmap_kring *kring, int zcopy)
243 int error = NM_IRQ_COMPLETED;
245 /* sinchronize with concurrently running nm_sync()s */
246 nm_kr_stop(kring, NM_KR_LOCKED);
247 /* make sure the monitor array exists and is big enough */
248 error = nm_monitor_alloc(kring, kring->n_monitors + 1);
251 kring->monitors[kring->n_monitors] = mkring;
252 mkring->mon_pos = kring->n_monitors;
254 if (kring->n_monitors == 1) {
255 /* this is the first monitor, intercept callbacks */
256 ND("%s: intercept callbacks on %s", mkring->name, kring->name);
257 kring->mon_sync = kring->nm_sync;
258 /* zcopy monitors do not override nm_notify(), but
259 * we save the original one regardless, so that
260 * netmap_monitor_del() does not need to know the
263 kring->mon_notify = kring->nm_notify;
264 if (kring->tx == NR_TX) {
265 kring->nm_sync = (zcopy ? netmap_zmon_parent_txsync :
266 netmap_monitor_parent_txsync);
268 kring->nm_sync = (zcopy ? netmap_zmon_parent_rxsync :
269 netmap_monitor_parent_rxsync);
271 /* also intercept notify */
272 kring->nm_notify = netmap_monitor_parent_notify;
273 kring->mon_tail = kring->nr_hwtail;
284 /* remove the monitor mkring from the list of monitors of kring.
285 * If this is the last monitor, restore the original callbacks
288 netmap_monitor_del(struct netmap_kring *mkring, struct netmap_kring *kring)
290 /* sinchronize with concurrently running nm_sync()s */
291 nm_kr_stop(kring, NM_KR_LOCKED);
293 if (mkring->mon_pos != kring->n_monitors) {
294 kring->monitors[mkring->mon_pos] = kring->monitors[kring->n_monitors];
295 kring->monitors[mkring->mon_pos]->mon_pos = mkring->mon_pos;
297 kring->monitors[kring->n_monitors] = NULL;
298 if (kring->n_monitors == 0) {
299 /* this was the last monitor, restore callbacks and delete monitor array */
300 ND("%s: restoring sync on %s: %p", mkring->name, kring->name, kring->mon_sync);
301 kring->nm_sync = kring->mon_sync;
302 kring->mon_sync = NULL;
303 if (kring->tx == NR_RX) {
304 ND("%s: restoring notify on %s: %p",
305 mkring->name, kring->name, kring->mon_notify);
306 kring->nm_notify = kring->mon_notify;
307 kring->mon_notify = NULL;
309 nm_monitor_dealloc(kring);
315 /* This is called when the monitored adapter leaves netmap mode
316 * (see netmap_do_unregif).
317 * We need to notify the monitors that the monitored rings are gone.
318 * We do this by setting their mna->priv.np_na to NULL.
319 * Note that the rings are already stopped when this happens, so
320 * no monitor ring callback can be active.
323 netmap_monitor_stop(struct netmap_adapter *na)
330 for (i = 0; i < nma_get_nrings(na, t) + 1; i++) {
331 struct netmap_kring *kring = &NMR(na, t)[i];
334 for (j = 0; j < kring->n_monitors; j++) {
335 struct netmap_kring *mkring =
337 struct netmap_monitor_adapter *mna =
338 (struct netmap_monitor_adapter *)mkring->na;
339 /* forget about this adapter */
340 netmap_adapter_put(mna->priv.np_na);
341 mna->priv.np_na = NULL;
348 /* common functions for the nm_register() callbacks of both kind of
352 netmap_monitor_reg_common(struct netmap_adapter *na, int onoff, int zmon)
354 struct netmap_monitor_adapter *mna =
355 (struct netmap_monitor_adapter *)na;
356 struct netmap_priv_d *priv = &mna->priv;
357 struct netmap_adapter *pna = priv->np_na;
358 struct netmap_kring *kring, *mkring;
362 ND("%p: onoff %d", na, onoff);
365 /* parent left netmap mode, fatal */
366 D("%s: internal error", na->name);
370 if (mna->flags & nm_txrx2flag(t)) {
371 for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) {
372 kring = &NMR(pna, t)[i];
373 mkring = &na->rx_rings[i];
374 if (nm_kring_pending_on(mkring)) {
375 netmap_monitor_add(mkring, kring, zmon);
376 mkring->nr_mode = NKR_NETMAP_ON;
381 na->na_flags |= NAF_NETMAP_ON;
383 if (na->active_fds == 0)
384 na->na_flags &= ~NAF_NETMAP_ON;
386 if (mna->flags & nm_txrx2flag(t)) {
387 for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) {
388 mkring = &na->rx_rings[i];
389 if (nm_kring_pending_off(mkring)) {
390 mkring->nr_mode = NKR_NETMAP_OFF;
391 /* we cannot access the parent krings if the parent
392 * has left netmap mode. This is signaled by a NULL
396 kring = &NMR(pna, t)[i];
397 netmap_monitor_del(mkring, kring);
408 ****************************************************************
409 * functions specific for zero-copy monitors
410 ****************************************************************
414 * Common function for both zero-copy tx and rx nm_sync()
418 netmap_zmon_parent_sync(struct netmap_kring *kring, int flags, enum txrx tx)
420 struct netmap_kring *mkring = kring->monitors[0];
421 struct netmap_ring *ring = kring->ring, *mring;
423 int rel_slots, free_slots, busy, sent = 0;
425 u_int lim = kring->nkr_num_slots - 1,
426 mlim; // = mkring->nkr_num_slots - 1;
428 if (mkring == NULL) {
429 RD(5, "NULL monitor on %s", kring->name);
432 mring = mkring->ring;
433 mlim = mkring->nkr_num_slots - 1;
435 /* get the relased slots (rel_slots) */
437 beg = kring->nr_hwtail;
438 error = kring->mon_sync(kring, flags);
441 end = kring->nr_hwtail;
443 beg = kring->nr_hwcur;
447 rel_slots = end - beg;
449 rel_slots += kring->nkr_num_slots;
452 /* no released slots, but we still need
453 * to call rxsync if this is a rx ring
458 /* we need to lock the monitor receive ring, since it
459 * is the target of bot tx and rx traffic from the monitored
462 mtx_lock(&mkring->q_lock);
463 /* get the free slots available on the monitor ring */
464 i = mkring->nr_hwtail;
465 busy = i - mkring->nr_hwcur;
467 busy += mkring->nkr_num_slots;
468 free_slots = mlim - busy;
473 /* swap min(free_slots, rel_slots) slots */
474 if (free_slots < rel_slots) {
475 beg += (rel_slots - free_slots);
476 if (beg >= kring->nkr_num_slots)
477 beg -= kring->nkr_num_slots;
478 rel_slots = free_slots;
482 for ( ; rel_slots; rel_slots--) {
483 struct netmap_slot *s = &ring->slot[beg];
484 struct netmap_slot *ms = &mring->slot[i];
488 ms->buf_idx = s->buf_idx;
490 ND(5, "beg %d buf_idx %d", beg, tmp);
496 s->flags |= NS_BUF_CHANGED;
498 beg = nm_next(beg, lim);
499 i = nm_next(i, mlim);
503 mkring->nr_hwtail = i;
506 mtx_unlock(&mkring->q_lock);
509 /* notify the new frames to the monitor */
510 mkring->nm_notify(mkring, 0);
515 error = kring->mon_sync(kring, flags);
520 /* callback used to replace the nm_sync callback in the monitored tx rings */
522 netmap_zmon_parent_txsync(struct netmap_kring *kring, int flags)
524 ND("%s %x", kring->name, flags);
525 return netmap_zmon_parent_sync(kring, flags, NR_TX);
528 /* callback used to replace the nm_sync callback in the monitored rx rings */
530 netmap_zmon_parent_rxsync(struct netmap_kring *kring, int flags)
532 ND("%s %x", kring->name, flags);
533 return netmap_zmon_parent_sync(kring, flags, NR_RX);
538 netmap_zmon_reg(struct netmap_adapter *na, int onoff)
540 return netmap_monitor_reg_common(na, onoff, 1 /* zcopy */);
543 /* nm_dtor callback for monitors */
545 netmap_zmon_dtor(struct netmap_adapter *na)
547 struct netmap_monitor_adapter *mna =
548 (struct netmap_monitor_adapter *)na;
549 struct netmap_priv_d *priv = &mna->priv;
550 struct netmap_adapter *pna = priv->np_na;
552 netmap_adapter_put(pna);
556 ****************************************************************
557 * functions specific for copy monitors
558 ****************************************************************
562 netmap_monitor_parent_sync(struct netmap_kring *kring, u_int first_new, int new_slots)
566 for (j = 0; j < kring->n_monitors; j++) {
567 struct netmap_kring *mkring = kring->monitors[j];
569 int free_slots, busy, sent = 0, m;
570 u_int lim = kring->nkr_num_slots - 1;
571 struct netmap_ring *ring = kring->ring, *mring = mkring->ring;
572 u_int max_len = NETMAP_BUF_SIZE(mkring->na);
574 mlim = mkring->nkr_num_slots - 1;
576 /* we need to lock the monitor receive ring, since it
577 * is the target of bot tx and rx traffic from the monitored
580 mtx_lock(&mkring->q_lock);
581 /* get the free slots available on the monitor ring */
582 i = mkring->nr_hwtail;
583 busy = i - mkring->nr_hwcur;
585 busy += mkring->nkr_num_slots;
586 free_slots = mlim - busy;
591 /* copy min(free_slots, new_slots) slots */
594 if (free_slots < m) {
595 beg += (m - free_slots);
596 if (beg >= kring->nkr_num_slots)
597 beg -= kring->nkr_num_slots;
602 struct netmap_slot *s = &ring->slot[beg];
603 struct netmap_slot *ms = &mring->slot[i];
604 u_int copy_len = s->len;
605 char *src = NMB(kring->na, s),
606 *dst = NMB(mkring->na, ms);
608 if (unlikely(copy_len > max_len)) {
609 RD(5, "%s->%s: truncating %d to %d", kring->name,
610 mkring->name, copy_len, max_len);
614 memcpy(dst, src, copy_len);
618 beg = nm_next(beg, lim);
619 i = nm_next(i, mlim);
622 mkring->nr_hwtail = i;
624 mtx_unlock(&mkring->q_lock);
627 /* notify the new frames to the monitor */
628 mkring->nm_notify(mkring, 0);
633 /* callback used to replace the nm_sync callback in the monitored tx rings */
635 netmap_monitor_parent_txsync(struct netmap_kring *kring, int flags)
640 /* get the new slots */
641 first_new = kring->nr_hwcur;
642 new_slots = kring->rhead - first_new;
644 new_slots += kring->nkr_num_slots;
646 netmap_monitor_parent_sync(kring, first_new, new_slots);
647 return kring->mon_sync(kring, flags);
650 /* callback used to replace the nm_sync callback in the monitored rx rings */
652 netmap_monitor_parent_rxsync(struct netmap_kring *kring, int flags)
655 int new_slots, error;
657 /* get the new slots */
658 error = kring->mon_sync(kring, flags);
661 first_new = kring->mon_tail;
662 new_slots = kring->nr_hwtail - first_new;
664 new_slots += kring->nkr_num_slots;
666 netmap_monitor_parent_sync(kring, first_new, new_slots);
667 kring->mon_tail = kring->nr_hwtail;
671 /* callback used to replace the nm_notify() callback in the monitored rx rings */
673 netmap_monitor_parent_notify(struct netmap_kring *kring, int flags)
675 int (*notify)(struct netmap_kring*, int);
676 ND(5, "%s %x", kring->name, flags);
677 /* ?xsync callbacks have tryget called by their callers
678 * (NIOCREGIF and poll()), but here we have to call it
681 if (nm_kr_tryget(kring, 0, NULL)) {
682 /* in all cases, just skip the sync */
683 return NM_IRQ_COMPLETED;
685 if (kring->n_monitors > 0) {
686 netmap_monitor_parent_rxsync(kring, NAF_FORCE_READ);
687 notify = kring->mon_notify;
689 /* we are no longer monitoring this ring, so both
690 * mon_sync and mon_notify are NULL
692 notify = kring->nm_notify;
695 return notify(kring, flags);
700 netmap_monitor_reg(struct netmap_adapter *na, int onoff)
702 return netmap_monitor_reg_common(na, onoff, 0 /* no zcopy */);
706 netmap_monitor_dtor(struct netmap_adapter *na)
708 struct netmap_monitor_adapter *mna =
709 (struct netmap_monitor_adapter *)na;
710 struct netmap_priv_d *priv = &mna->priv;
711 struct netmap_adapter *pna = priv->np_na;
713 netmap_adapter_put(pna);
717 /* check if nmr is a request for a monitor adapter that we can satisfy */
719 netmap_get_monitor_na(struct nmreq *nmr, struct netmap_adapter **na, int create)
722 struct netmap_adapter *pna; /* parent adapter */
723 struct netmap_monitor_adapter *mna;
724 struct ifnet *ifp = NULL;
727 int zcopy = (nmr->nr_flags & NR_ZCOPY_MON);
728 char monsuff[10] = "";
730 if ((nmr->nr_flags & (NR_MONITOR_TX | NR_MONITOR_RX)) == 0) {
731 if (nmr->nr_flags & NR_ZCOPY_MON) {
732 /* the flag makes no sense unless you are
740 /* this is a request for a monitor adapter */
742 ND("flags %x", nmr->nr_flags);
744 mna = malloc(sizeof(*mna), M_DEVBUF, M_NOWAIT | M_ZERO);
750 /* first, try to find the adapter that we want to monitor
751 * We use the same nmr, after we have turned off the monitor flags.
752 * In this way we can potentially monitor everything netmap understands,
753 * except other monitors.
755 memcpy(&pnmr, nmr, sizeof(pnmr));
756 pnmr.nr_flags &= ~(NR_MONITOR_TX | NR_MONITOR_RX | NR_ZCOPY_MON);
757 error = netmap_get_na(&pnmr, &pna, &ifp, create);
759 D("parent lookup failed: %d", error);
763 ND("found parent: %s", pna->name);
765 if (!nm_netmap_on(pna)) {
766 /* parent not in netmap mode */
767 /* XXX we can wait for the parent to enter netmap mode,
768 * by intercepting its nm_register callback (2014-03-16)
770 D("%s not in netmap mode", pna->name);
775 /* grab all the rings we need in the parent */
776 mna->priv.np_na = pna;
777 error = netmap_interp_ringid(&mna->priv, nmr->nr_ringid, nmr->nr_flags);
782 if (mna->priv.np_qlast[NR_TX] - mna->priv.np_qfirst[NR_TX] == 1) {
783 snprintf(monsuff, 10, "-%d", mna->priv.np_qfirst[NR_TX]);
785 snprintf(mna->up.name, sizeof(mna->up.name), "%s%s/%s%s%s", pna->name,
788 (nmr->nr_flags & NR_MONITOR_RX) ? "r" : "",
789 (nmr->nr_flags & NR_MONITOR_TX) ? "t" : "");
792 /* zero copy monitors need exclusive access to the monitored rings */
794 if (! (nmr->nr_flags & nm_txrx2flag(t)))
796 for (i = mna->priv.np_qfirst[t]; i < mna->priv.np_qlast[t]; i++) {
797 struct netmap_kring *kring = &NMR(pna, t)[i];
798 if (kring->n_monitors > 0) {
800 D("ring %s already monitored by %s", kring->name,
801 kring->monitors[0]->name);
806 mna->up.nm_register = netmap_zmon_reg;
807 mna->up.nm_dtor = netmap_zmon_dtor;
808 /* to have zero copy, we need to use the same memory allocator
809 * as the monitored port
811 mna->up.nm_mem = pna->nm_mem;
812 mna->up.na_lut = pna->na_lut;
814 /* normal monitors are incompatible with zero copy ones */
816 if (! (nmr->nr_flags & nm_txrx2flag(t)))
818 for (i = mna->priv.np_qfirst[t]; i < mna->priv.np_qlast[t]; i++) {
819 struct netmap_kring *kring = &NMR(pna, t)[i];
820 if (kring->n_monitors > 0 &&
821 kring->monitors[0]->na->nm_register == netmap_zmon_reg)
829 mna->up.nm_rxsync = netmap_monitor_rxsync;
830 mna->up.nm_register = netmap_monitor_reg;
831 mna->up.nm_dtor = netmap_monitor_dtor;
834 /* the monitor supports the host rings iff the parent does */
835 mna->up.na_flags = (pna->na_flags & NAF_HOST_RINGS);
836 /* a do-nothing txsync: monitors cannot be used to inject packets */
837 mna->up.nm_txsync = netmap_monitor_txsync;
838 mna->up.nm_rxsync = netmap_monitor_rxsync;
839 mna->up.nm_krings_create = netmap_monitor_krings_create;
840 mna->up.nm_krings_delete = netmap_monitor_krings_delete;
841 mna->up.num_tx_rings = 1; // XXX we don't need it, but field can't be zero
842 /* we set the number of our rx_rings to be max(num_rx_rings, num_rx_rings)
845 mna->up.num_rx_rings = pna->num_rx_rings;
846 if (pna->num_tx_rings > pna->num_rx_rings)
847 mna->up.num_rx_rings = pna->num_tx_rings;
848 /* by default, the number of slots is the same as in
849 * the parent rings, but the user may ask for a different
852 mna->up.num_tx_desc = nmr->nr_tx_slots;
853 nm_bound_var(&mna->up.num_tx_desc, pna->num_tx_desc,
854 1, NM_MONITOR_MAXSLOTS, NULL);
855 mna->up.num_rx_desc = nmr->nr_rx_slots;
856 nm_bound_var(&mna->up.num_rx_desc, pna->num_rx_desc,
857 1, NM_MONITOR_MAXSLOTS, NULL);
858 error = netmap_attach_common(&mna->up);
860 D("attach_common error");
864 /* remember the traffic directions we have to monitor */
865 mna->flags = (nmr->nr_flags & (NR_MONITOR_TX | NR_MONITOR_RX));
868 netmap_adapter_get(*na);
870 /* keep the reference to the parent */
873 /* drop the reference to the ifp, if any */
880 netmap_unget_na(pna, ifp);
886 #endif /* WITH_MONITOR */