diff -urNb mpd-3.18/src/iface.c mpd-3.18.patched/src/iface.c --- mpd-3.18/src/iface.c Tue May 04 22:12:28 2004 +++ mpd-3.18.patched/src/iface.c Wed Jan 19 03:08:04 2005 @@ -28,6 +28,7 @@ #include #include #include +#include /* * DEFINITIONS @@ -279,7 +280,12 @@ /* Reset bpf node statistics */ memset(&iface->idleStats, 0, sizeof(iface->idleStats)); + if (gEnableTee) { + snprintf(path, sizeof(path), "%s:%s.%s", iface->ifname, + NG_IFACE_HOOK_INET, NG_TEE_HOOK_RIGHT); + } else { snprintf(path, sizeof(path), "%s:%s", iface->ifname, NG_IFACE_HOOK_INET); + } if (NgSendMsg(bund->csock, path, NGM_BPF_COOKIE, NGM_BPF_CLR_STATS, BPF_HOOK_IFACE, sizeof(BPF_HOOK_IFACE)) < 0) Log(LG_ERR, ("[%s] can't clear %s stats: %s", @@ -832,7 +838,12 @@ /* Get updated bpf node traffic statistics */ oldStats = iface->idleStats; + if (gEnableTee) { + snprintf(path, sizeof(path), "%s:%s.%s", iface->ifname, + NG_IFACE_HOOK_INET, NG_TEE_HOOK_RIGHT); + } else { snprintf(path, sizeof(path), "%s:%s", iface->ifname, NG_IFACE_HOOK_INET); + } if (NgSendMsg(bund->csock, path, NGM_BPF_COOKIE, NGM_BPF_GET_STATS, BPF_HOOK_IFACE, sizeof(BPF_HOOK_IFACE)) < 0) { Log(LG_ERR, ("[%s] can't get %s stats: %s", diff -urNb mpd-3.18/src/main.c mpd-3.18.patched/src/main.c --- mpd-3.18/src/main.c Tue May 04 22:12:28 2004 +++ mpd-3.18.patched/src/main.c Wed Jan 19 02:48:52 2005 @@ -64,6 +64,8 @@ "Show version information" }, { 0, 'h', "help", "", "Show usage information" }, + { 0, 't', "tee", "", + "Insert ng_tee into netgraph" }, }; #define OPTLIST_SIZE (sizeof(OptList) / sizeof(*OptList)) @@ -81,6 +83,7 @@ Bund *gBundles; int gNumLinks; int gNumBundles; + int gEnableTee = FALSE; const char *gConfigFile = CONF_FILE; const char *gConfDirectory = PATH_CONF_DIR; @@ -514,6 +517,9 @@ exit(EX_NORMAL); case 'h': Usage(EX_NORMAL); + case 't': + gEnableTee = TRUE; + return(0); default: assert(0); } diff -urNb mpd-3.18/src/ngfunc.c mpd-3.18.patched/src/ngfunc.c --- mpd-3.18/src/ngfunc.c Tue May 04 22:12:28 2004 +++ mpd-3.18.patched/src/ngfunc.c Wed Jan 19 02:46:30 2005 @@ -28,6 +28,7 @@ #include #include #include +#include /* * DEFINITIONS @@ -249,15 +250,35 @@ goto fail; } + /* Add a tee node between bpf and interface if configured */ + if(gEnableTee) { + snprintf(path, sizeof(path), "%s.%s", MPD_HOOK_PPP, NG_PPP_HOOK_INET); + snprintf(mp.type, sizeof(mp.type), "%s", NG_TEE_NODE_TYPE); + snprintf(mp.ourhook, sizeof(mp.ourhook), "%s", BPF_HOOK_IFACE); + snprintf(mp.peerhook, sizeof(mp.peerhook), "%s", NG_TEE_HOOK_RIGHT); + if (NgSendMsg(b->csock, path, + NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) { + Log(LG_ERR, ("[%s] can't create %s node: %s", + b->name, NG_TEE_NODE_TYPE, strerror(errno))); + goto fail; + } + snprintf(path, sizeof(path), "%s.%s.%s", MPD_HOOK_PPP, + NG_PPP_HOOK_INET, BPF_HOOK_IFACE); + snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ifname); + snprintf(cn.ourhook, sizeof(cn.ourhook), "%s", NG_TEE_HOOK_LEFT); + snprintf(cn.peerhook, sizeof(cn.peerhook), "%s", NG_IFACE_HOOK_INET); + } else { /* Connect the other side of the bpf node to the iface node */ snprintf(path, sizeof(path), "%s.%s", MPD_HOOK_PPP, NG_PPP_HOOK_INET); snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ifname); snprintf(cn.ourhook, sizeof(cn.ourhook), "%s", BPF_HOOK_IFACE); snprintf(cn.peerhook, sizeof(cn.peerhook), "%s", NG_IFACE_HOOK_INET); + } + if (NgSendMsg(b->csock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) { Log(LG_ERR, ("[%s] can't connect %s and %s: %s", - b->name, BPF_HOOK_IFACE, NG_IFACE_HOOK_INET, strerror(errno))); + b->name, cn.ourhook, NG_IFACE_HOOK_INET, strerror(errno))); goto fail; } @@ -473,7 +494,12 @@ char path[NG_PATHLEN + 1]; /* Get absolute path to bpf node */ + if (gEnableTee) { + snprintf(path, sizeof(path), "%s:%s.%s", b->iface.ifname, + NG_IFACE_HOOK_INET, NG_TEE_HOOK_RIGHT); + } else { snprintf(path, sizeof(path), "%s:%s", b->iface.ifname, NG_IFACE_HOOK_INET); + } /* First, configure the hook on the interface node side of the BPF node */ memset(&u, 0, sizeof(u)); @@ -606,6 +632,11 @@ bund = bund_save; lnk = lnk_save; if (ppp) { + if (gEnableTee) { + snprintf(path, sizeof(path), "%s.%s.%s", MPD_HOOK_PPP, + NG_PPP_HOOK_INET, BPF_HOOK_IFACE); + NgFuncShutdownNode(b, b->name, path); + } snprintf(path, sizeof(path), "%s.%s", MPD_HOOK_PPP, NG_PPP_HOOK_INET); NgFuncShutdownNode(b, b->name, path); NgFuncShutdownNode(b, b->name, MPD_HOOK_PPP); diff -urNb mpd-3.18/src/ppp.h mpd-3.18.patched/src/ppp.h --- mpd-3.18/src/ppp.h Tue May 04 22:12:28 2004 +++ mpd-3.18.patched/src/ppp.h Wed Jan 19 02:49:48 2005 @@ -84,6 +84,7 @@ extern int gNumLinks; /* Total number of links */ extern int gNumBundles; /* Total number of bundles */ + extern int gEnableTee; /* Insert ng_tee into netgraph */ extern Bund bund; /* Current bundle */ extern Link lnk; /* Current link */