Deleted Added
full compact
ng_source.c (153690) ng_source.c (154707)
1/*
2 * ng_source.c
3 */
4
5/*-
6 * Copyright (c) 2005 Gleb Smirnoff <glebius@FreeBSD.org>
7 * Copyright 2002 Sandvine Inc.
8 * All rights reserved.

--- 25 unchanged lines hidden (view full) ---

34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH
36 * DAMAGE.
37 *
38 * Author: Dave Chapeskie <dchapeskie@sandvine.com>
39 */
40
41#include <sys/cdefs.h>
1/*
2 * ng_source.c
3 */
4
5/*-
6 * Copyright (c) 2005 Gleb Smirnoff <glebius@FreeBSD.org>
7 * Copyright 2002 Sandvine Inc.
8 * All rights reserved.

--- 25 unchanged lines hidden (view full) ---

34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH
36 * DAMAGE.
37 *
38 * Author: Dave Chapeskie <dchapeskie@sandvine.com>
39 */
40
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: head/sys/netgraph/ng_source.c 153690 2005-12-23 19:14:38Z glebius $");
42__FBSDID("$FreeBSD: head/sys/netgraph/ng_source.c 154707 2006-01-23 10:28:04Z glebius $");
43
44/*
45 * This node is used for high speed packet geneneration. It queues
46 * all data recieved on its 'input' hook and when told to start via
47 * a control message it sends the packets out its 'output' hook. In
48 * this way this node can be preloaded with a packet stream which it
49 * can then send continuously as fast as possible.
50 *

--- 584 unchanged lines hidden (view full) ---

635 if (sc->packets == 0)
636 ng_source_stop(sc);
637 else
638 ng_callout(&sc->intr_ch, node, NULL, NG_SOURCE_INTR_TICKS,
639 ng_source_intr, sc, 0);
640}
641
642/*
43
44/*
45 * This node is used for high speed packet geneneration. It queues
46 * all data recieved on its 'input' hook and when told to start via
47 * a control message it sends the packets out its 'output' hook. In
48 * this way this node can be preloaded with a packet stream which it
49 * can then send continuously as fast as possible.
50 *

--- 584 unchanged lines hidden (view full) ---

635 if (sc->packets == 0)
636 ng_source_stop(sc);
637 else
638 ng_callout(&sc->intr_ch, node, NULL, NG_SOURCE_INTR_TICKS,
639 ng_source_intr, sc, 0);
640}
641
642/*
643 * Send packets out our output hook
643 * Send packets out our output hook.
644 */
645static int
644 */
645static int
646ng_source_send (sc_p sc, int tosend, int *sent_p)
646ng_source_send(sc_p sc, int tosend, int *sent_p)
647{
647{
648 struct ifqueue tmp_queue;
649 struct mbuf *m, *m2;
648 struct mbuf *m, *m2;
650 int sent = 0;
649 int sent;
651 int error = 0;
652
653 KASSERT(tosend >= 0, ("%s: negative tosend param", __func__));
654 KASSERT(sc->node->nd_flags & NG_SOURCE_ACTIVE,
655 ("%s: inactive node", __func__));
656
657 if ((uint64_t)tosend > sc->packets)
658 tosend = sc->packets;
659
650 int error = 0;
651
652 KASSERT(tosend >= 0, ("%s: negative tosend param", __func__));
653 KASSERT(sc->node->nd_flags & NG_SOURCE_ACTIVE,
654 ("%s: inactive node", __func__));
655
656 if ((uint64_t)tosend > sc->packets)
657 tosend = sc->packets;
658
660 /* Copy the required number of packets to a temporary queue */
661 bzero (&tmp_queue, sizeof (tmp_queue));
659 /* Go through the queue sending packets one by one. */
662 for (sent = 0; error == 0 && sent < tosend; ++sent) {
663 _IF_DEQUEUE(&sc->snd_queue, m);
664 if (m == NULL)
665 break;
666
660 for (sent = 0; error == 0 && sent < tosend; ++sent) {
661 _IF_DEQUEUE(&sc->snd_queue, m);
662 if (m == NULL)
663 break;
664
667 /* duplicate the packet */
665 /* Duplicate the packet. */
668 m2 = m_copypacket(m, M_DONTWAIT);
669 if (m2 == NULL) {
670 _IF_PREPEND(&sc->snd_queue, m);
671 error = ENOBUFS;
672 break;
673 }
674
675 /* Re-enqueue the original packet for us. */
676 _IF_ENQUEUE(&sc->snd_queue, m);
677
666 m2 = m_copypacket(m, M_DONTWAIT);
667 if (m2 == NULL) {
668 _IF_PREPEND(&sc->snd_queue, m);
669 error = ENOBUFS;
670 break;
671 }
672
673 /* Re-enqueue the original packet for us. */
674 _IF_ENQUEUE(&sc->snd_queue, m);
675
678 /* Queue the copy for sending at splimp. */
679 _IF_ENQUEUE(&tmp_queue, m2);
680 }
681
682 sent = 0;
683 for (;;) {
684 _IF_DEQUEUE(&tmp_queue, m2);
685 if (m2 == NULL)
676 sc->stats.outFrames++;
677 sc->stats.outOctets += m2->m_pkthdr.len;
678 NG_SEND_DATA_ONLY(error, sc->output, m2);
679 if (error)
686 break;
680 break;
687 if (error == 0) {
688 ++sent;
689 sc->stats.outFrames++;
690 sc->stats.outOctets += m2->m_pkthdr.len;
691 NG_SEND_DATA_ONLY(error, sc->output, m2);
692 if (error)
693 log(LOG_DEBUG, "%s: error=%d", __func__, error);
694 } else {
695 NG_FREE_M(m2);
696 }
697 }
698
699 sc->packets -= sent;
700 if (sent_p != NULL)
701 *sent_p = sent;
702 return (error);
703}
681 }
682
683 sc->packets -= sent;
684 if (sent_p != NULL)
685 *sent_p = sent;
686 return (error);
687}