1
0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-11-23 13:22:36 +01:00

Add stub code for creating new plugins

This commit is contained in:
Pavel Odintsov 2015-01-26 12:10:35 +03:00
parent 4d55f61a31
commit ec393a51c2
4 changed files with 81 additions and 2 deletions

@ -47,12 +47,15 @@ endif()
# Our LPM library
add_library(patricia STATIC libpatricia/patricia.c)
# Our sFLOW plugin
# sFLOW plugin
add_library(sflow_plugin STATIC sflow_plugin/sflow_collector.cpp)
# Out netflow plugin
# netflow plugin
add_library(netflow_plugin STATIC netflow_plugin/netflow_collector.cpp)
# example plugin
add_library(example_plugin STATIC example_plugin/example_collector.cpp)
# Main tool
add_executable(fastnetmon fastnetmon.cpp)
@ -94,6 +97,7 @@ target_link_libraries(fastnetmon patricia)
# Our plugins
target_link_libraries(fastnetmon sflow_plugin)
target_link_libraries(fastnetmon netflow_plugin)
target_link_libraries(fastnetmon example_plugin)
if (ENABLE_PFRING_SUPPORT)
# Custom PF_RING

@ -0,0 +1,65 @@
// log4cpp logging facility
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/Priority.hh"
// For support uint32_t, uint16_t
#include <sys/types.h>
//#include <inttypes.h>
// For support: IPPROTO_TCP, IPPROTO_ICMP, IPPROTO_UDP
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "example_collector.h"
// Get log4cpp logger from main programm
extern log4cpp::Category& logger;
// This variable name should be uniq for every plugin!
process_packet_pointer example_process_func_ptr = NULL;
void start_example_collection(process_packet_pointer func_ptr) {
logger<< log4cpp::Priority::INFO<<"Example plugin started";
example_process_func_ptr = func_ptr;
// We should fill this structure for passing to FastNetMon
simple_packet current_packet;
current_packet.src_ip = 0;
current_packet.dst_ip = 0;
current_packet.ts.tv_sec = 0;
current_packet.ts.tv_usec = 0;
current_packet.flags = 0;
// There we store packet length or total length of aggregated stream
current_packet.length = 128;
// Number of received packets, it's not equal to 1 only for aggregated data like netflow
current_packet.number_of_packets = 1;
// If your data sampled
current_packet.sample_ratio = 1;
/* ICMP */
current_packet.protocol = IPPROTO_ICMP;
/* TCP */
current_packet.protocol = IPPROTO_TCP;
current_packet.source_port = 0;
current_packet.destination_port = 0;
/* UDP */
current_packet.protocol = IPPROTO_UDP;
current_packet.source_port = 0;
current_packet.destination_port = 0;
example_process_func_ptr(current_packet);
}

@ -0,0 +1,9 @@
#ifndef _EXAMPLE_PLUGIN_H
#define _EXAMPLE_PLUGIN_H
#include "../fastnetmon_types.h"
// This function should be implemented in plugin
void start_example_collection(process_packet_pointer func_ptr);
#endif

@ -28,6 +28,7 @@
// Plugins
#include "sflow_plugin/sflow_collector.h"
#include "netflow_plugin/netflow_collector.h"
#include "example_plugin/example_collector.h"
#include <algorithm>
#include <iostream>