2018-05-12 16:03:00 +00:00
|
|
|
/*
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* libtcp-portmon.h: tcp port monitoring library.
|
2005-10-31 05:17:06 +00:00
|
|
|
*
|
2007-08-10 20:09:43 +00:00
|
|
|
* Copyright (C) 2005-2007 Philip Kovacs pkovacs@users.sourceforge.net
|
2005-10-31 05:17:06 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-12-13 16:54:59 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
2008-02-20 20:30:45 +00:00
|
|
|
* USA. */
|
2005-10-31 05:17:06 +00:00
|
|
|
|
|
|
|
#ifndef LIBTCP_PORTMON_H
|
|
|
|
#define LIBTCP_PORTMON_H
|
|
|
|
|
2006-03-16 17:57:53 +00:00
|
|
|
#include <sys/socket.h>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include <sys/types.h>
|
2006-03-16 17:57:53 +00:00
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
2005-10-31 05:17:06 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2006-03-16 17:57:53 +00:00
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* connection deleted if unseen again after this # of refreshes */
|
|
|
|
#define TCP_CONNECTION_STARTING_AGE 1
|
2010-01-07 02:38:12 +00:00
|
|
|
#define BUILD_PORT_MONITORS_HASH_KEY_SIZE 12
|
2008-06-14 18:41:12 +00:00
|
|
|
#define MAX_PORT_MONITOR_CONNECTIONS_DEFAULT 256
|
2005-10-31 05:17:06 +00:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------
|
|
|
|
* IMPLEMENTATION INTERFACE
|
|
|
|
*
|
2008-02-20 20:30:45 +00:00
|
|
|
* Implementation-specific interface begins here. Clients should not
|
|
|
|
* manipulate these structures directly, nor call the defined helper
|
2005-10-31 05:17:06 +00:00
|
|
|
* functions. Use the "Client interface" functions defined at bottom.
|
|
|
|
* ------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* The inventory of peekable items within the port monitor. */
|
2008-02-20 20:30:45 +00:00
|
|
|
enum tcp_port_monitor_peekables {
|
2018-05-12 16:03:00 +00:00
|
|
|
COUNT = 0,
|
|
|
|
REMOTEIP,
|
|
|
|
REMOTEHOST,
|
|
|
|
REMOTEPORT,
|
|
|
|
REMOTESERVICE,
|
|
|
|
LOCALIP,
|
|
|
|
LOCALHOST,
|
|
|
|
LOCALPORT,
|
|
|
|
LOCALSERVICE
|
2006-12-09 05:40:08 +00:00
|
|
|
};
|
2005-10-31 05:17:06 +00:00
|
|
|
|
2009-12-09 21:41:29 +00:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
* A port monitor
|
2005-11-01 00:58:34 +00:00
|
|
|
*
|
2009-12-09 21:41:29 +00:00
|
|
|
* The definition of the struct is hidden because it contains
|
|
|
|
* C++-specific stuff and we want to #include this from C code.
|
|
|
|
* ------------------------------------------------------------ */
|
|
|
|
typedef struct _tcp_port_monitor_t tcp_port_monitor_t;
|
2005-10-31 05:17:06 +00:00
|
|
|
|
2009-12-09 21:41:29 +00:00
|
|
|
/* ------------------------------------------------------------
|
2005-10-31 05:17:06 +00:00
|
|
|
* A tcp port monitor collection
|
2009-12-09 21:41:29 +00:00
|
|
|
*
|
|
|
|
* The definition of the struct is hidden because it contains
|
|
|
|
* C++-specific stuff and we want to #include this from C code.
|
|
|
|
* ------------------------------------------------------------ */
|
|
|
|
typedef struct _tcp_port_monitor_collection_t tcp_port_monitor_collection_t;
|
2005-10-31 05:17:06 +00:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
2008-02-20 20:30:45 +00:00
|
|
|
* CLIENT INTERFACE
|
2005-10-31 05:17:06 +00:00
|
|
|
*
|
|
|
|
* Clients should call only those functions below this line.
|
|
|
|
* ---------------------------------------------------------------------- */
|
|
|
|
|
2005-11-11 20:46:42 +00:00
|
|
|
/* struct to hold monitor creation arguments */
|
|
|
|
typedef struct _tcp_port_monitor_args_t {
|
2018-05-12 16:03:00 +00:00
|
|
|
/* monitor supports tracking at most this many connections */
|
|
|
|
int max_port_monitor_connections;
|
2005-11-11 20:46:42 +00:00
|
|
|
} tcp_port_monitor_args_t;
|
|
|
|
|
2005-10-31 05:17:06 +00:00
|
|
|
/* ----------------------------------
|
|
|
|
* Client operations on port monitors
|
|
|
|
* ---------------------------------- */
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Clients use this function to get connection data from
|
|
|
|
* the indicated port monitor.
|
|
|
|
* The requested monitor value is copied into a client-supplied char buffer.
|
|
|
|
* Returns 0 on success, -1 otherwise. */
|
2018-05-12 16:03:00 +00:00
|
|
|
int peek_tcp_port_monitor(
|
|
|
|
const tcp_port_monitor_t *p_monitor,
|
|
|
|
/* (item of interest, from tcp_port_monitor_peekables enum) */
|
|
|
|
int item,
|
|
|
|
/* (0 to number of connections in monitor - 1) */
|
|
|
|
int connection_index,
|
|
|
|
/* buffer to receive requested value */
|
|
|
|
char *p_buffer,
|
|
|
|
/* size of p_buffer */
|
|
|
|
size_t buffer_size);
|
2005-10-31 05:17:06 +00:00
|
|
|
|
|
|
|
/* --------------------------------
|
|
|
|
* Client operations on collections
|
|
|
|
* -------------------------------- */
|
|
|
|
|
|
|
|
/* Create a monitor collection. Do this one first. */
|
2008-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_collection_t *create_tcp_port_monitor_collection(void);
|
2005-10-31 05:17:06 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* Destroy the monitor collection (and everything it contains).
|
|
|
|
* Do this one last. */
|
|
|
|
void destroy_tcp_port_monitor_collection(
|
2018-05-12 16:03:00 +00:00
|
|
|
tcp_port_monitor_collection_t *p_collection);
|
2005-10-31 05:17:06 +00:00
|
|
|
|
|
|
|
/* Updates the tcp statitics for all monitors within a collection */
|
|
|
|
void update_tcp_port_monitor_collection(
|
2018-05-12 16:03:00 +00:00
|
|
|
tcp_port_monitor_collection_t *p_collection);
|
2005-10-31 05:17:06 +00:00
|
|
|
|
2009-12-09 21:41:29 +00:00
|
|
|
/* Creation of reduntant monitors is silently ignored
|
2008-02-20 20:30:45 +00:00
|
|
|
* Returns 0 on success, -1 otherwise. */
|
2009-12-09 21:41:29 +00:00
|
|
|
int insert_new_tcp_port_monitor_into_collection(
|
2018-05-12 16:03:00 +00:00
|
|
|
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
|
|
|
|
in_port_t port_range_end, tcp_port_monitor_args_t *p_creation_args);
|
2005-10-31 05:17:06 +00:00
|
|
|
|
|
|
|
/* Clients need a way to find monitors */
|
2008-02-20 20:30:45 +00:00
|
|
|
tcp_port_monitor_t *find_tcp_port_monitor(
|
2018-05-12 16:03:00 +00:00
|
|
|
tcp_port_monitor_collection_t *p_collection, in_port_t port_range_begin,
|
|
|
|
in_port_t port_range_end);
|
2005-10-31 05:17:06 +00:00
|
|
|
|
|
|
|
#endif
|