#include #include #include #include #include #include #include #include #include #include #include "sys/io-pkt.h" #include "nw_datastruct.h" #include static int in_bytes = 0; static int out_bytes = 0; static int input_hook(void *arg, struct mbuf **m, struct ifnet *ifp, int dir) { in_bytes += (*m)->m_len; return 0; } static int deinit_module(); static int iface_hook(void *arg, struct mbuf **m, struct ifnet *ifp, int dir) { if ( (int)m == PFIL_IFNET_ATTACH) { log(LOG_INFO, "Interface attached\n"); log(LOG_INFO, "%d bytes in, %d bytes out\n", in_bytes, out_bytes); } else if ((int)m == PFIL_IFNET_DETACH) { log(LOG_INFO,"Interface detached "); log(LOG_INFO, "%d bytes in ", in_bytes); log(LOG_INFO, "%d bytes out\n", out_bytes); deinit_module(); } return 0; } static int ifacecfg_hook(void *arg, struct mbuf **m, struct ifnet *ifp, int dir) { log(LOG_INFO, "Iface cfg hook called with 0x%08X\n", (int)(m)); return 0; } extern struct pfil_head eth_input_pfil_hook; static int deinit_module(void) { struct pfil_head *pfh_inet; pfil_remove_hook(input_hook, NULL, PFIL_IN | PFIL_WAITOK, ð_input_pfil_hook); pfh_inet = pfil_head_get(PFIL_TYPE_IFNET, 0); if (pfh_inet == NULL) { return ESRCH; } pfil_remove_hook(ifacecfg_hook, NULL, PFIL_IFNET, pfh_inet); pfil_remove_hook(iface_hook, NULL, PFIL_IFNET | PFIL_WAITOK, pfh_inet); log(LOG_INFO, "Unloaded pfil hook\n" ); return 0; } int pfil_entry(void *dll_hdl, struct _iopkt_self *iopkt, char *options) { struct pfil_head *pfh_inet; pfh_inet = ð_input_pfil_hook; pfil_add_hook(input_hook, NULL, PFIL_IN | PFIL_WAITOK, ð_input_pfil_hook); pfh_inet = pfil_head_get(PFIL_TYPE_IFNET,0); if (pfh_inet == NULL) { return ESRCH; } pfil_add_hook(iface_hook, NULL, PFIL_IFNET, pfh_inet); pfil_add_hook(ifacecfg_hook, NULL, PFIL_IFADDR, pfh_inet); log(LOG_INFO, "Loaded pfil hook\n" ); return 0; } struct _iopkt_lsm_entry IOPKT_LSM_ENTRY_SYM(pfil) = IOPKT_LSM_ENTRY_SYM_INIT(pfil_entry);