6 * Copyright (c) 2005 Gleb Smirnoff <glebius@FreeBSD.org>
7 * Copyright 2002 Sandvine Inc.
10 * Subject to the following obligations and disclaimer of warranty, use and
11 * redistribution of this software, in source or object code forms, with or
12 * without modifications are expressly permitted by Sandvine Inc.; provided,
14 * 1. Any and all reproductions of the source or object code must include the
15 * copyright notice above and the following disclaimer of warranties; and
16 * 2. No rights are granted, in any manner or form, to use Sandvine Inc.
17 * trademarks, including the mark "SANDVINE" on advertising, endorsements,
18 * or otherwise except as such appears in the above copyright notice or in
21 * THIS SOFTWARE IS BEING PROVIDED BY SANDVINE "AS IS", AND TO THE MAXIMUM
22 * EXTENT PERMITTED BY LAW, SANDVINE MAKES NO REPRESENTATIONS OR WARRANTIES,
23 * EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
24 * ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 * PURPOSE, OR NON-INFRINGEMENT. SANDVINE DOES NOT WARRANT, GUARANTEE, OR
26 * MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE
27 * USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY
28 * OR OTHERWISE. IN NO EVENT SHALL SANDVINE BE LIABLE FOR ANY DAMAGES
29 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
30 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
31 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
38 * Author: Dave Chapeskie <dchapeskie@sandvine.com>
40 * $FreeBSD: src/sys/netgraph/ng_source.c,v 1.30 2007/03/02 14:36:19 emaste Exp $
44 * This node is used for high speed packet geneneration. It queues
45 * all data recieved on its 'input' hook and when told to start via
46 * a control message it sends the packets out its 'output' hook. In
47 * this way this node can be preloaded with a packet stream which it
48 * can then send continuously as fast as possible.
50 * Currently it just copies the mbufs as required. It could do various
51 * tricks to try and avoid this. Probably the best performance would
52 * be achieved by modifying the appropriate drivers to be told to
53 * self-re-enqueue packets (e.g. the if_bge driver could reuse the same
54 * transmit descriptors) under control of this node; perhaps via some
55 * flag in the mbuf or some such. The node could peek at an appropriate
56 * ifnet flag to see if such support is available for the connected
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/errno.h>
63 #include <sys/kernel.h>
64 #include <sys/malloc.h>
66 #include <sys/socket.h>
67 #include <sys/syslog.h>
69 #include <net/if_var.h>
70 #include "ng_message.h"
74 #include "ng_source.h"
76 #define NG_SOURCE_INTR_TICKS 1
77 #define NG_SOURCE_DRIVER_IFQ_MAXLEN (4*1024)
79 #define mtod_off(m,off,t) ((t)(mtod((m),caddr_t)+(off)))
86 struct ng_source_stats stats
;
87 struct ifqueue snd_queue
; /* packets to send */
88 struct mbuf
*last_packet
; /* last pkt in queue */
89 struct ifnet
*output_ifp
;
90 struct callout intr_ch
;
91 uint64_t packets
; /* packets to send */
93 struct ng_source_embed_info embed_timestamp
;
94 struct ng_source_embed_cnt_info embed_counter
[NG_SOURCE_COUNTERS
];
96 typedef struct privdata
*sc_p
;
99 #define NG_SOURCE_ACTIVE (NGF_TYPE1)
101 /* Netgraph methods */
102 static ng_constructor_t ng_source_constructor
;
103 static ng_rcvmsg_t ng_source_rcvmsg
;
104 static ng_shutdown_t ng_source_rmnode
;
105 static ng_newhook_t ng_source_newhook
;
106 static ng_connect_t ng_source_connect
;
107 static ng_rcvdata_t ng_source_rcvdata
;
108 static ng_disconnect_t ng_source_disconnect
;
110 /* Other functions */
111 static void ng_source_intr(node_p
, hook_p
, void *, int);
112 static void ng_source_clr_data (sc_p
);
113 static int ng_source_start (sc_p
, uint64_t);
114 static void ng_source_stop (sc_p
);
115 static int ng_source_send (sc_p
, int, int *);
116 static int ng_source_store_output_ifp(sc_p
, char *);
117 static void ng_source_packet_mod(sc_p
, struct mbuf
*,
118 int, int, caddr_t
, int);
119 static void ng_source_mod_counter(sc_p sc
,
120 struct ng_source_embed_cnt_info
*cnt
,
121 struct mbuf
*m
, int increment
);
122 static int ng_source_dup_mod(sc_p
, struct mbuf
*,
125 /* Parse type for timeval */
126 static const struct ng_parse_struct_field ng_source_timeval_type_fields
[] = {
127 { "tv_sec", &ng_parse_int32_type
},
128 { "tv_usec", &ng_parse_int32_type
},
131 const struct ng_parse_type ng_source_timeval_type
= {
132 &ng_parse_struct_type
,
133 &ng_source_timeval_type_fields
136 /* Parse type for struct ng_source_stats */
137 static const struct ng_parse_struct_field ng_source_stats_type_fields
[]
138 = NG_SOURCE_STATS_TYPE_INFO
;
139 static const struct ng_parse_type ng_source_stats_type
= {
140 &ng_parse_struct_type
,
141 &ng_source_stats_type_fields
144 /* Parse type for struct ng_source_embed_info */
145 static const struct ng_parse_struct_field ng_source_embed_type_fields
[] =
146 NG_SOURCE_EMBED_TYPE_INFO
;
147 static const struct ng_parse_type ng_source_embed_type
= {
148 &ng_parse_struct_type
,
149 &ng_source_embed_type_fields
152 /* Parse type for struct ng_source_embed_cnt_info */
153 static const struct ng_parse_struct_field ng_source_embed_cnt_type_fields
[] =
154 NG_SOURCE_EMBED_CNT_TYPE_INFO
;
155 static const struct ng_parse_type ng_source_embed_cnt_type
= {
156 &ng_parse_struct_type
,
157 &ng_source_embed_cnt_type_fields
160 /* List of commands and how to convert arguments to/from ASCII */
161 static const struct ng_cmdlist ng_source_cmds
[] = {
164 NGM_SOURCE_GET_STATS
,
167 &ng_source_stats_type
171 NGM_SOURCE_CLR_STATS
,
178 NGM_SOURCE_GETCLR_STATS
,
181 &ng_source_stats_type
187 &ng_parse_uint64_type
,
208 &ng_parse_string_type
,
215 &ng_parse_uint32_type
,
220 NGM_SOURCE_SET_TIMESTAMP
,
222 &ng_source_embed_type
,
227 NGM_SOURCE_GET_TIMESTAMP
,
230 &ng_source_embed_type
234 NGM_SOURCE_SET_COUNTER
,
236 &ng_source_embed_cnt_type
,
241 NGM_SOURCE_GET_COUNTER
,
243 &ng_parse_uint8_type
,
244 &ng_source_embed_cnt_type
249 /* Netgraph type descriptor */
250 static struct ng_type ng_source_typestruct
= {
251 .version
= NG_ABI_VERSION
,
252 .name
= NG_SOURCE_NODE_TYPE
,
253 .constructor
= ng_source_constructor
,
254 .rcvmsg
= ng_source_rcvmsg
,
255 .shutdown
= ng_source_rmnode
,
256 .newhook
= ng_source_newhook
,
257 .connect
= ng_source_connect
,
258 .rcvdata
= ng_source_rcvdata
,
259 .disconnect
= ng_source_disconnect
,
260 .cmdlist
= ng_source_cmds
,
262 NETGRAPH_INIT(source
, &ng_source_typestruct
);
264 static int ng_source_set_autosrc(sc_p
, uint32_t);
270 ng_source_constructor(node_p node
)
274 sc
= kmalloc(sizeof(*sc
), M_NETGRAPH
, M_WAITOK
| M_NULLOK
| M_ZERO
);
278 NG_NODE_SET_PRIVATE(node
, sc
);
280 sc
->snd_queue
.ifq_maxlen
= 2048; /* XXX not checked */
281 ng_callout_init(&sc
->intr_ch
);
290 ng_source_newhook(node_p node
, hook_p hook
, const char *name
)
292 sc_p sc
= NG_NODE_PRIVATE(node
);
294 if (strcmp(name
, NG_SOURCE_HOOK_INPUT
) == 0) {
296 } else if (strcmp(name
, NG_SOURCE_HOOK_OUTPUT
) == 0) {
298 sc
->output_ifp
= NULL
;
299 bzero(&sc
->stats
, sizeof(sc
->stats
));
307 * Hook has been added
310 ng_source_connect(hook_p hook
)
312 sc_p sc
= NG_NODE_PRIVATE(NG_HOOK_NODE(hook
));
317 * If this is "output" hook, then request information
318 * from our downstream.
320 if (hook
== sc
->output
) {
321 NG_MKMESSAGE(msg
, NGM_ETHER_COOKIE
, NGM_ETHER_GET_IFNAME
,
322 0, M_WAITOK
| M_NULLOK
);
327 * Our hook and peer hook have HK_INVALID flag set,
328 * so we can't use NG_SEND_MSG_HOOK() macro here.
330 NG_SEND_MSG_ID(dummy_error
, sc
->node
, msg
,
331 NG_NODE_ID(NG_PEER_NODE(sc
->output
)), NG_NODE_ID(sc
->node
));
338 * Receive a control message
341 ng_source_rcvmsg(node_p node
, item_p item
, hook_p lasthook
)
343 sc_p sc
= NG_NODE_PRIVATE(node
);
344 struct ng_mesg
*msg
, *resp
= NULL
;
347 NGI_GET_MSG(item
, msg
);
349 switch (msg
->header
.typecookie
) {
350 case NGM_SOURCE_COOKIE
:
351 if (msg
->header
.flags
& NGF_RESP
) {
355 switch (msg
->header
.cmd
) {
356 case NGM_SOURCE_GET_STATS
:
357 case NGM_SOURCE_CLR_STATS
:
358 case NGM_SOURCE_GETCLR_STATS
:
360 struct ng_source_stats
*stats
;
362 if (msg
->header
.cmd
!= NGM_SOURCE_CLR_STATS
) {
363 NG_MKRESPONSE(resp
, msg
,
364 sizeof(*stats
), M_WAITOK
| M_NULLOK
);
369 sc
->stats
.queueOctets
= sc
->queueOctets
;
370 sc
->stats
.queueFrames
= sc
->snd_queue
.ifq_len
;
371 if ((sc
->node
->nd_flags
& NG_SOURCE_ACTIVE
)
372 && !timevalisset(&sc
->stats
.endTime
)) {
373 getmicrotime(&sc
->stats
.elapsedTime
);
374 timevalsub(&sc
->stats
.elapsedTime
,
375 &sc
->stats
.startTime
);
377 stats
= (struct ng_source_stats
*)resp
->data
;
378 bcopy(&sc
->stats
, stats
, sizeof(* stats
));
380 if (msg
->header
.cmd
!= NGM_SOURCE_GET_STATS
)
381 bzero(&sc
->stats
, sizeof(sc
->stats
));
384 case NGM_SOURCE_START
:
388 if (msg
->header
.arglen
!= sizeof(uint64_t)) {
393 packets
= *(uint64_t *)msg
->data
;
395 error
= ng_source_start(sc
, packets
);
399 case NGM_SOURCE_STOP
:
402 case NGM_SOURCE_CLR_DATA
:
403 ng_source_clr_data(sc
);
405 case NGM_SOURCE_SETIFACE
:
407 char *ifname
= (char *)msg
->data
;
409 if (msg
->header
.arglen
< 2) {
414 ng_source_store_output_ifp(sc
, ifname
);
417 case NGM_SOURCE_SETPPS
:
421 if (msg
->header
.arglen
!= sizeof(uint32_t)) {
426 pps
= *(uint32_t *)msg
->data
;
428 sc
->stats
.maxPps
= pps
;
432 case NGM_SOURCE_SET_TIMESTAMP
:
434 struct ng_source_embed_info
*embed
;
436 if (msg
->header
.arglen
!= sizeof(*embed
)) {
440 embed
= (struct ng_source_embed_info
*)msg
->data
;
441 bcopy(embed
, &sc
->embed_timestamp
, sizeof(*embed
));
445 case NGM_SOURCE_GET_TIMESTAMP
:
447 struct ng_source_embed_info
*embed
;
449 NG_MKRESPONSE(resp
, msg
, sizeof(*embed
), M_WAITOK
);
454 embed
= (struct ng_source_embed_info
*)resp
->data
;
455 bcopy(&sc
->embed_timestamp
, embed
, sizeof(*embed
));
459 case NGM_SOURCE_SET_COUNTER
:
461 struct ng_source_embed_cnt_info
*embed
;
463 if (msg
->header
.arglen
!= sizeof(*embed
)) {
467 embed
= (struct ng_source_embed_cnt_info
*)msg
->data
;
468 if (embed
->index
>= NG_SOURCE_COUNTERS
||
469 !(embed
->width
== 1 || embed
->width
== 2 ||
470 embed
->width
== 4)) {
474 bcopy(embed
, &sc
->embed_counter
[embed
->index
],
479 case NGM_SOURCE_GET_COUNTER
:
481 uint8_t index
= *(uint8_t *)msg
->data
;
482 struct ng_source_embed_cnt_info
*embed
;
484 if (index
>= NG_SOURCE_COUNTERS
) {
488 NG_MKRESPONSE(resp
, msg
, sizeof(*embed
), M_WAITOK
);
493 embed
= (struct ng_source_embed_cnt_info
*)resp
->data
;
494 bcopy(&sc
->embed_counter
[index
], embed
, sizeof(*embed
));
503 case NGM_ETHER_COOKIE
:
504 if (!(msg
->header
.flags
& NGF_RESP
)) {
508 switch (msg
->header
.cmd
) {
509 case NGM_ETHER_GET_IFNAME
:
511 char *ifname
= (char *)msg
->data
;
513 if (msg
->header
.arglen
< 2) {
518 if (ng_source_store_output_ifp(sc
, ifname
) == 0)
519 ng_source_set_autosrc(sc
, 0);
532 /* Take care of synchronous response, if any. */
533 NG_RESPOND_MSG(error
, node
, item
, resp
);
534 /* Free the message and return. */
540 * Receive data on a hook
542 * If data comes in the input hook, enqueue it on the send queue.
543 * If data comes in the output hook, discard it.
546 ng_source_rcvdata(hook_p hook
, item_p item
)
548 sc_p sc
= NG_NODE_PRIVATE(NG_HOOK_NODE(hook
));
556 if (hook
== sc
->output
) {
561 KASSERT(hook
== sc
->input
, ("%s: no hook!", __func__
));
563 /* Enqueue packet. */
564 /* XXX should we check IF_QFULL() ? */
565 _IF_ENQUEUE(&sc
->snd_queue
, m
);
566 sc
->queueOctets
+= m
->m_pkthdr
.len
;
573 * Shutdown processing
576 ng_source_rmnode(node_p node
)
578 sc_p sc
= NG_NODE_PRIVATE(node
);
581 ng_source_clr_data(sc
);
582 NG_NODE_SET_PRIVATE(node
, NULL
);
584 kfree(sc
, M_NETGRAPH
);
593 ng_source_disconnect(hook_p hook
)
597 sc
= NG_NODE_PRIVATE(NG_HOOK_NODE(hook
));
598 KASSERT(sc
!= NULL
, ("%s: null node private", __func__
));
599 if (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook
)) == 0 || hook
== sc
->output
)
600 ng_rmnode_self(NG_HOOK_NODE(hook
));
605 * Set sc->output_ifp to point to the the struct ifnet of the interface
606 * reached via our output hook.
609 ng_source_store_output_ifp(sc_p sc
, char *ifname
)
616 ifp
= ifunit(ifname
);
620 kprintf("%s: can't find interface %d\n", __func__
, if_index
);
623 sc
->output_ifp
= ifp
;
626 /* XXX mucking with a drivers ifqueue size is ugly but we need it
627 * to queue a lot of packets to get close to line rate on a gigabit
628 * interface with small packets.
629 * XXX we should restore the original value at stop or disconnect
631 s
= splimp(); /* XXX is this required? */
632 if (ifp
->if_snd
.ifq_maxlen
< NG_SOURCE_DRIVER_IFQ_MAXLEN
) {
633 kprintf("ng_source: changing ifq_maxlen from %d to %d\n",
634 ifp
->if_snd
.ifq_maxlen
, NG_SOURCE_DRIVER_IFQ_MAXLEN
);
635 ifq_set_maxlen(&ifp
->if_snd
, NG_SOURCE_DRIVER_IFQ_MAXLEN
);
644 * Set the attached ethernet node's ethernet source address override flag.
647 ng_source_set_autosrc(sc_p sc
, uint32_t flag
)
652 NG_MKMESSAGE(msg
, NGM_ETHER_COOKIE
, NGM_ETHER_SET_AUTOSRC
,
653 sizeof (uint32_t), M_WAITOK
| M_NULLOK
);
657 *(uint32_t *)msg
->data
= flag
;
658 NG_SEND_MSG_HOOK(error
, sc
->node
, msg
, sc
->output
, 0);
663 * Clear out the data we've queued
666 ng_source_clr_data (sc_p sc
)
671 _IF_DEQUEUE(&sc
->snd_queue
, m
);
677 sc
->last_packet
= NULL
;
681 * Start sending queued data out the output hook
684 ng_source_start(sc_p sc
, uint64_t packets
)
686 if (sc
->output_ifp
== NULL
) {
687 kprintf("ng_source: start without iface configured\n");
691 if (sc
->node
->nd_flags
& NG_SOURCE_ACTIVE
)
694 sc
->node
->nd_flags
|= NG_SOURCE_ACTIVE
;
696 sc
->packets
= packets
;
697 timevalclear(&sc
->stats
.elapsedTime
);
698 timevalclear(&sc
->stats
.endTime
);
699 getmicrotime(&sc
->stats
.startTime
);
700 getmicrotime(&sc
->stats
.lastTime
);
701 ng_callout(&sc
->intr_ch
, sc
->node
, NULL
, 0,
702 ng_source_intr
, sc
, 0);
708 * Stop sending queued data out the output hook
711 ng_source_stop(sc_p sc
)
713 ng_uncallout(&sc
->intr_ch
, sc
->node
);
714 sc
->node
->nd_flags
&= ~NG_SOURCE_ACTIVE
;
715 getmicrotime(&sc
->stats
.endTime
);
716 sc
->stats
.elapsedTime
= sc
->stats
.endTime
;
717 timevalsub(&sc
->stats
.elapsedTime
, &sc
->stats
.startTime
);
721 * While active called every NG_SOURCE_INTR_TICKS ticks.
722 * Sends as many packets as the interface connected to our
723 * output hook is able to enqueue.
726 ng_source_intr(node_p node
, hook_p hook
, void *arg1
, int arg2
)
728 sc_p sc
= (sc_p
)arg1
;
731 KASSERT(sc
!= NULL
, ("%s: null node private", __func__
));
733 if (sc
->packets
== 0 || sc
->output
== NULL
734 || (sc
->node
->nd_flags
& NG_SOURCE_ACTIVE
) == 0) {
739 if (sc
->output_ifp
!= NULL
) {
740 struct ifaltq_subqueue
*ifsq
=
741 ifq_get_subq_default(&sc
->output_ifp
->if_snd
);
743 packets
= ifq
->ifq_maxlen
- ifq
->ifq_len
;
745 packets
= sc
->snd_queue
.ifq_len
;
747 if (sc
->stats
.maxPps
!= 0) {
748 struct timeval now
, elapsed
;
754 timevalsub(&elapsed
, &sc
->stats
.lastTime
);
755 usec
= elapsed
.tv_sec
* 1000000 + elapsed
.tv_usec
;
756 maxpkt
= (uint64_t)sc
->stats
.maxPps
* usec
/ 1000000;
757 sc
->stats
.lastTime
= now
;
758 if (packets
> maxpkt
)
762 ng_source_send(sc
, packets
, NULL
);
763 if (sc
->packets
== 0)
766 ng_callout(&sc
->intr_ch
, node
, NULL
, NG_SOURCE_INTR_TICKS
,
767 ng_source_intr
, sc
, 0);
771 * Send packets out our output hook.
774 ng_source_send(sc_p sc
, int tosend
, int *sent_p
)
780 KASSERT(tosend
>= 0, ("%s: negative tosend param", __func__
));
781 KASSERT(sc
->node
->nd_flags
& NG_SOURCE_ACTIVE
,
782 ("%s: inactive node", __func__
));
784 if ((uint64_t)tosend
> sc
->packets
)
785 tosend
= sc
->packets
;
787 /* Go through the queue sending packets one by one. */
788 for (sent
= 0; error
== 0 && sent
< tosend
; ++sent
) {
789 _IF_DEQUEUE(&sc
->snd_queue
, m
);
793 /* Duplicate and modify the packet. */
794 error
= ng_source_dup_mod(sc
, m
, &m2
);
796 if (error
== ENOBUFS
)
797 _IF_PREPEND(&sc
->snd_queue
, m
);
799 _IF_ENQUEUE(&sc
->snd_queue
, m
);
803 /* Re-enqueue the original packet for us. */
804 _IF_ENQUEUE(&sc
->snd_queue
, m
);
806 sc
->stats
.outFrames
++;
807 sc
->stats
.outOctets
+= m2
->m_pkthdr
.len
;
808 NG_SEND_DATA_ONLY(error
, sc
->output
, m2
);
820 * Modify packet in 'm' by changing 'len' bytes starting at 'offset'
823 * The packet data in 'm' must be in a contiguous buffer in a single mbuf.
826 ng_source_packet_mod(sc_p sc
, struct mbuf
*m
, int offset
, int len
, caddr_t cp
,
832 /* Can't modify beyond end of packet. */
833 /* TODO: Pad packet for this case. */
834 if (offset
+ len
> m
->m_len
)
837 bcopy(cp
, mtod_off(m
, offset
, caddr_t
), len
);
841 ng_source_mod_counter(sc_p sc
, struct ng_source_embed_cnt_info
*cnt
,
842 struct mbuf
*m
, int increment
)
847 val
= htonl(cnt
->next_val
);
848 cp
= (caddr_t
)&val
+ sizeof(val
) - cnt
->width
;
849 ng_source_packet_mod(sc
, m
, cnt
->offset
, cnt
->width
, cp
, cnt
->flags
);
852 cnt
->next_val
+= increment
;
854 if (increment
> 0 && cnt
->next_val
> cnt
->max_val
) {
855 cnt
->next_val
= cnt
->min_val
- 1 +
856 (cnt
->next_val
- cnt
->max_val
);
857 if (cnt
->next_val
> cnt
->max_val
)
858 cnt
->next_val
= cnt
->max_val
;
859 } else if (increment
< 0 && cnt
->next_val
< cnt
->min_val
) {
860 cnt
->next_val
= cnt
->max_val
+ 1 +
861 (cnt
->next_val
- cnt
->min_val
);
862 if (cnt
->next_val
< cnt
->min_val
)
863 cnt
->next_val
= cnt
->max_val
;
869 ng_source_dup_mod(sc_p sc
, struct mbuf
*m0
, struct mbuf
**m_ptr
)
872 struct ng_source_embed_cnt_info
*cnt
;
873 struct ng_source_embed_info
*ts
;
878 /* Are we going to modify packets? */
879 modify
= sc
->embed_timestamp
.flags
& NGM_SOURCE_EMBED_ENABLE
;
880 for (i
= 0; !modify
&& i
< NG_SOURCE_COUNTERS
; ++i
)
881 modify
= sc
->embed_counter
[i
].flags
& NGM_SOURCE_EMBED_ENABLE
;
883 /* Duplicate the packet. */
885 m
= m_dup(m0
, M_NOWAIT
);
887 m
= m_copypacket(m0
, M_NOWAIT
);
897 /* Modify the copied packet for sending. */
898 KASSERT(M_WRITABLE(m
), ("%s: packet not writable", __func__
));
900 for (i
= 0; i
< NG_SOURCE_COUNTERS
; ++i
) {
901 cnt
= &sc
->embed_counter
[i
];
902 if (cnt
->flags
& NGM_SOURCE_EMBED_ENABLE
) {
903 if ((cnt
->flags
& NGM_SOURCE_INC_CNT_PER_LIST
) == 0 ||
904 sc
->last_packet
== m0
)
905 increment
= cnt
->increment
;
908 ng_source_mod_counter(sc
, cnt
, m
, increment
);
912 ts
= &sc
->embed_timestamp
;
913 if (ts
->flags
& NGM_SOURCE_EMBED_ENABLE
) {
916 now
.tv_sec
= htonl(now
.tv_sec
);
917 now
.tv_usec
= htonl(now
.tv_usec
);
918 ng_source_packet_mod(sc
, m
, ts
->offset
, sizeof (now
),
919 (caddr_t
)&now
, ts
->flags
);