--- embedaddon/mpd/src/ngfunc.c 2012/02/21 23:32:47 1.1.1.1 +++ embedaddon/mpd/src/ngfunc.c 2013/07/22 08:44:29 1.1.1.2 @@ -44,8 +44,8 @@ #endif #ifdef USE_NG_NETFLOW #include -#if NGM_NETFLOW_COOKIE >= 1309868867 #include +#if NGM_NETFLOW_COOKIE >= 1309868867 #include #endif #endif @@ -460,8 +460,10 @@ NgFuncSendQuery(const char *path, int cookie, int cmd, } /* Send message */ - if (NgSendMsg(gNgStatSock, path, cookie, cmd, args, arglen) < 0) + if (NgSendMsg(gNgStatSock, path, cookie, cmd, args, arglen) < 0) { + Perror("NgFuncSendQuery: can't send message"); return (-1); + } /* Read message */ if (NgRecvMsg(gNgStatSock, rbuf, replen, raddr) < 0) { @@ -825,6 +827,116 @@ NetflowSetCommand(Context ctx, int ac, char *av[], voi } return (0); +} + +/* + * ShowNetflow() + * + * Show state of a Netflow + */ + +int +ShowNetflow(Context ctx, int ac, char *av[], void *arg) +{ + struct u_addr addr; + in_port_t port; + char buf[64]; + char path[NG_PATHSIZ]; + union { + u_char buf[sizeof(struct ng_mesg) + sizeof(struct ng_netflow_info)]; + struct ng_mesg reply; + } u; + struct ng_netflow_info *const ni = \ + (struct ng_netflow_info *)(void *)u.reply.data; +#ifdef NGM_NETFLOW_V9_COOKIE + union { + u_char buf[sizeof(struct ng_mesg) + sizeof(struct ng_netflow_v9info)]; + struct ng_mesg reply; + } uv9; + struct ng_netflow_v9info *const niv9 = \ + (struct ng_netflow_v9info *)(void *)uv9.reply.data; +#endif /* NGM_NETFLOW_V9_COOKIE */ + + if (gNetflowNodeID>0) { + snprintf(path, sizeof(path), "[%x]:", gNetflowNodeID); + if (NgFuncSendQuery(path, NGM_NETFLOW_COOKIE, NGM_NETFLOW_INFO, + NULL, 0, &u.reply, sizeof(u), NULL) < 0) + return(-7); +#ifdef NGM_NETFLOW_V9_COOKIE + if (NgFuncSendQuery(path, NGM_NETFLOW_COOKIE, NGM_NETFLOW_V9INFO, + NULL, 0, &uv9.reply, sizeof(uv9), NULL) < 0) + return(-7); +#endif /* NGM_NETFLOW_V9_COOKIE */ + } + + Printf("Netflow status:\r\n"); + Printf("\tNode created : %s\r\n", gNetflowNodeID ? "Yes" : "No"); + Printf("Netflow settings:\r\n"); + Printf("\tNode name : %s\r\n", gNetflowNodeName); + Printf("\tInitial hook : %d\r\n", gNetflowIface); + Printf("\tTimeouts, sec:\r\n"); + Printf("\t Active : %d\r\n", + (gNetflowNodeID>0) ? ni->nfinfo_act_t : + (gNetflowActive ? gNetflowActive : ACTIVE_TIMEOUT)); + Printf("\t Inactive : %d\r\n", + (gNetflowNodeID>0) ? ni->nfinfo_inact_t : + (gNetflowInactive ? gNetflowInactive : INACTIVE_TIMEOUT)); + sockaddrtou_addr(&gNetflowExport, &addr, &port); + Printf("\tExport address : %s port %d\r\n", + u_addrtoa(&addr, buf, sizeof(buf)), (int)port); + sockaddrtou_addr(&gNetflowSource, &addr, &port); + Printf("\tSource address : %s port %d\r\n", + u_addrtoa(&addr, buf, sizeof(buf)), (int)port); +#if NGM_NETFLOW_COOKIE >= 1309868867 + Printf("\tExport version : v%d\r\n", gNetflowVer); + Printf("Netflow v9 configuration:\r\n"); + Printf("\tTemplate:\r\n"); +#ifdef NGM_NETFLOW_V9_COOKIE + Printf("\t Time : %d\r\n", + (gNetflowNodeID>0) ? niv9->templ_time : + (gNetflowTime ? gNetflowTime : NETFLOW_V9_MAX_TIME_TEMPL)); + Printf("\t Packets : %d\r\n", + (gNetflowNodeID>0) ? niv9->templ_packets : + (gNetflowPackets ? gNetflowPackets : NETFLOW_V9_MAX_PACKETS_TEMPL)); + Printf("\tNetflow v9 MTU : %d\r\n", + (gNetflowNodeID>0) ? niv9->mtu : + (gNetflowMTU ? gNetflowMTU : BASE_MTU)); +#else + Printf("\t Time : %d\r\n", + gNetflowTime ? gNetflowTime : NETFLOW_V9_MAX_TIME_TEMPL); + Printf("\t Packets : %d\r\n", + gNetflowPackets ? gNetflowPackets : NETFLOW_V9_MAX_PACKETS_TEMPL); + Printf("\tNetflow v9 MTU : %d\r\n", + gNetflowMTU ? gNetflowMTU : BASE_MTU); +#endif /* NGM_NETFLOW_V9_COOKIE */ +#endif + if (gNetflowNodeID>0) { + Printf("Traffic stats:\r\n"); + Printf("\tAccounted IPv4 octets : %llu\r\n", (unsigned long long)ni->nfinfo_bytes); + Printf("\tAccounted IPv4 packets : %d\r\n", ni->nfinfo_packets); +#if NGM_NETFLOW_COOKIE >= 1309868867 + Printf("\tAccounted IPv6 octets : %llu\r\n", (unsigned long long)ni->nfinfo_bytes6); + Printf("\tAccounted IPv6 packets : %d\r\n", ni->nfinfo_packets6); + Printf("\tSkipped IPv4 octets : %llu\r\n", (unsigned long long)ni->nfinfo_sbytes); + Printf("\tSkipped IPv4 packets : %d\r\n", ni->nfinfo_spackets); + Printf("\tSkipped IPv6 octets : %llu\r\n", (unsigned long long)ni->nfinfo_sbytes6); + Printf("\tSkipped IPv6 packets : %d\r\n", ni->nfinfo_spackets6); +#endif + Printf("\tUsed IPv4 cache records: %d\r\n", ni->nfinfo_used); +#if NGM_NETFLOW_COOKIE >= 1309868867 + Printf("\tUsed IPv6 cache records: %d\r\n", ni->nfinfo_used6); +#endif + Printf("\tFailed allocations : %d\r\n", ni->nfinfo_alloc_failed); + Printf("\tFailed v5 export : %d\r\n", ni->nfinfo_export_failed); +#if NGM_NETFLOW_COOKIE >= 1309868867 + Printf("\tFailed v9 export : %d\r\n", ni->nfinfo_export9_failed); + Printf("\tRallocated mbufs : %d\r\n", ni->nfinfo_realloc_mbuf); + Printf("\tFibs allocated : %d\r\n", ni->nfinfo_alloc_fibs); +#endif + Printf("\tActive expiries : %d\r\n", ni->nfinfo_act_exp); + Printf("\tInactive expiries : %d\r\n", ni->nfinfo_inact_exp); + } + return(0); } #endif /* USE_NG_NETFLOW */