1 2/* 3 * ng_tee.c 4 * 5 * Copyright (c) 1996-1999 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 22 unchanged lines hidden (view full) --- 31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Author: Julian Elischer <julian@freebsd.org> 38 * |
39 * $FreeBSD: head/sys/netgraph/ng_tee.c 131155 2004-06-26 22:24:16Z julian $ |
40 * $Whistle: ng_tee.c,v 1.18 1999/11/01 09:24:52 julian Exp $ 41 */ 42 43/* 44 * This node is like the tee(1) command and is useful for ``snooping.'' 45 * It has 4 hooks: left, right, left2right, and right2left. Data 46 * entering from the right is passed to the left and duplicated on 47 * right2left, and data entering from the left is passed to the right --- 238 unchanged lines hidden (view full) --- 286ngt_rcvdata(hook_p hook, item_p item) 287{ 288 const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); 289 struct hookinfo *const hinfo = NG_HOOK_PRIVATE(hook); 290 struct hookinfo *dest; 291 struct hookinfo *dup; 292 int error = 0; 293 struct mbuf *m; |
294 295 m = NGI_M(item); |
296 /* Which hook? */ 297 if (hinfo == &sc->left) { 298 dup = &sc->left2right; 299 dest = &sc->right; 300 } else if (hinfo == &sc->right) { 301 dup = &sc->right2left; 302 dest = &sc->left; 303 } else if (hinfo == &sc->right2left) { --- 16 unchanged lines hidden (view full) --- 320 /* 321 * Don't make a copy if only the dup hook exists. 322 */ 323 if ((dup && dup->hook) && (dest->hook == NULL)) { 324 dest = dup; 325 dup = NULL; 326 } 327 |
328 /* Duplicate packet if requried */ |
329 if (dup && dup->hook) { 330 struct mbuf *m2; |
331 332 /* Copy packet (failure will not stop the original)*/ 333 m2 = m_dup(m, M_DONTWAIT); 334 if (m2) { |
335 /* Deliver duplicate */ 336 dup->stats.outOctets += m->m_pkthdr.len; 337 dup->stats.outFrames++; |
338 NG_SEND_DATA_ONLY(error, dup->hook, m2); |
339 } 340 } 341 /* Deliver frame out destination hook */ 342 if (dest->hook) { 343 dest->stats.outOctets += m->m_pkthdr.len; 344 dest->stats.outFrames++; 345 NG_FWD_ITEM_HOOK(error, item, dest->hook); 346 } else --- 52 unchanged lines hidden --- |