/* * ng_utp.h, v 1.0.1545 */ /*- * Copyright (c) 2012 Rozhuk Ivan , Inc. * All rights reserved. * * Subject to the following obligations and disclaimer of warranty, use and * redistribution of this software, in source or object code forms, with or * without modifications are expressly permitted by Whistle Communications; * provided, however, that: * 1. Any and all reproductions of the source or object code must include the * copyright notice above and the following disclaimer of warranties; and * 2. No rights are granted, in any manner or form, to use Whistle * Communications, Inc. trademarks, including the mark "WHISTLE * COMMUNICATIONS" on advertising, endorsements, or otherwise except as * such appears in the above copyright notice or in the software. * * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * Author: Rozhuk Ivan * * $FreeBSD */ #ifndef _NETGRAPH_NG_UTP_H_ #define _NETGRAPH_NG_UTP_H_ /* Node type name and magic cookie. */ #define NG_UTP_NODE_TYPE "utp" #define NGM_UTP_COOKIE 43646790 #define NGM_UTP_DEMO_MODE 1 /* Commands. */ enum { NGM_UTP_GET_NODE_CFG = 1, /* Get node config. */ NGM_UTP_SET_NODE_CFG, /* Set node config. */ NGM_UTP_GET_NODE_STATUS, /* Get node status. */ NGM_UTP_GET_NODE_STAT, /* Get node statistics. */ NGM_UTP_CLR_NODE_STAT, /* Clear node statistics. */ NGM_UTP_GETCLR_NODE_STAT, /* Get and clear node statistics. */ NGM_UTP_FLUSH_CONN4, /* Flush IPv4 connections. */ NGM_UTP_FLUSH_CONN6, /* Flush IPv6 connections. */ NGM_UTP_GET_CONN_TABLE4, /* Get IPv4 connections table list. */ NGM_UTP_GET_CONN_TABLE6, /* Get IPv6 connections table list. */ NGM_UTP_ADD_FILTER, /* Add filter. */ NGM_UTP_GET_FILTER, /* Get filter setings. */ NGM_UTP_DEL_FILTER, /* Del filter. */ NGM_UTP_GET_FILTER_STATS, /* Get filter statistics. */ NGM_UTP_CLR_FILTER_STATS, /* Clear filter statistics. */ NGM_UTP_GETCLR_FILTER_STATS, /* Get and clear filter statistics. */ NGM_UTP_LIST_FILTERS, /* Show all filters. */ }; /* NODE config structure */ typedef struct ng_utp_nodecfg_s { uint32_t ip_conns_max; uint32_t utp_conns_max; uint32_t conn_ack_timeout; uint32_t conn_idle_timeout; } ng_utp_nodecfg_t; /* Keep this in sync with the above structure definition. */ #define NG_UTP_NODE_CFG_TYPE_INFO { \ { "ip_conns_max", &ng_parse_uint32_type }, \ { "utp_conns_max", &ng_parse_uint32_type }, \ { "conn_ack_timeout", &ng_parse_uint32_type }, \ { "conn_idle_timeout", &ng_parse_uint32_type }, \ { NULL } \ } /* Defaults. */ #define NG_UTP_MAX_HOST_CONNS 1000 #define NG_UTP_MAX_UTP_CONNS (NG_UTP_MAX_HOST_CONNS * 4) #define NG_UTP_CONN_ACK_TIMEOUT 30 /* */ #define NG_UTP_CONN_IDLE_TIMEOUT 60 /* */ /* NODE Status structure */ typedef struct ng_utp_nodestatus_s { uint64_t ipv4_conns; /* IPv4 conns. */ uint64_t ipv6_conns; /* IPv6 conns. */ uint64_t ip_conns_total; /* Total ip conns. */ uint64_t ip_conns_max; /* Return actual max num of ip conns. */ uint64_t utpv0_conns; /* utp v0 conns. */ uint64_t utpv1_conns; /* utp v1 conns. */ uint64_t utp_conns_total;/* Total utp conns. */ uint64_t utp_conns_max; /* Return actual max num of utp conns. */ uint64_t mem_ip_conns; /* Memory used for ip conns. */ uint64_t mem_utp_conns; /* Memory used for utp conns. */ uint64_t mem_total; /* Total memory used for conns. */ } ng_utp_nodestatus_t; /* Keep this in sync with the above structure definition. */ #define NG_UTP_NODE_STATUS_TYPE_INFO { \ { "ipv4_conns", &ng_parse_uint64_type }, \ { "ipv6_conns", &ng_parse_uint64_type }, \ { "ip_conns_total", &ng_parse_uint64_type }, \ { "ip_conns_max", &ng_parse_uint64_type }, \ { "utpv0_conns", &ng_parse_uint64_type }, \ { "utpv1_conns", &ng_parse_uint64_type }, \ { "utp_conns_total", &ng_parse_uint64_type }, \ { "utp_conns_max", &ng_parse_uint64_type }, \ { "mem_ip_conns", &ng_parse_uint64_type }, \ { "mem_utp_conns", &ng_parse_uint64_type }, \ { "mem_total", &ng_parse_uint64_type }, \ { NULL } \ } /* NODE Statistics structure */ typedef struct ng_utp_nodestat_s { volatile uint64_t ipv4_conns; /* total RST pkts generated and xmit'd on link */ volatile uint64_t ipv6_conns; /* total RST pkts generated and xmit'd on link */ volatile uint64_t ip_conns_total;/* total RST pkts generated and xmit'd on link */ volatile uint64_t utpv0_conns; /* total RST pkts generated and xmit'd on link */ volatile uint64_t utpv1_conns; /* total RST pkts generated and xmit'd on link */ volatile uint64_t utp_conns_total;/* total RST pkts generated and xmit'd on link */ volatile uint64_t memoryFailures;/* times couldn't get mem or mbuf */ } ng_utp_nodestat_t; /* Keep this in sync with the above structure definition. */ #define NG_UTP_NODE_STAT_TYPE_INFO { \ { "ipv4_conns", &ng_parse_uint64_type }, \ { "ipv6_conns", &ng_parse_uint64_type }, \ { "ip_conns_total", &ng_parse_uint64_type }, \ { "utpv0_conns", &ng_parse_uint64_type }, \ { "utpv1_conns", &ng_parse_uint64_type }, \ { "utp_conns_total", &ng_parse_uint64_type }, \ { "memoryFailures", &ng_parse_uint64_type }, \ { NULL } \ } /* For NGM_UTP_ADD_FILTER control message. */ typedef struct ng_utp_add_filter_s { uint16_t l3_proto; /* IP v4 or v6 or 0 for ethernet */ uint16_t action; /* pass / mark & bypass / drop / send rst */ uint32_t flags; /* Mark L2/L3... */ uint8_t label_l2; /* pass_mark case: L2 - Priority Code Point. */ uint8_t label_l3; /* pass_mark case: L3 ip_tos/Traffic Class code (rfc2474) */ char h0[NG_HOOKSIZ]; char h1[NG_HOOKSIZ]; } ng_utp_add_filter_t; #define UTP_FLT_ACCTION_PASS 0 /* Default. */ #define UTP_FLT_ACCTION_PASS_MARK 1 /* See: UTP_FLT_FLAG_MARK_* */ #define UTP_FLT_ACCTION_DROP 2 #define UTP_FLT_ACCTION_SND_RST 3 /* Transform to RST and send. */ /* Hook ctrl flags. */ #define UTP_FLT_FLAG_FORCE_QUEUE_H0 0x00000001 /* Set NG_HOOK_FORCE_QUEUE for h0. */ #define UTP_FLT_FLAG_FORCE_QUEUE_H1 0x00000002 /* Set NG_HOOK_FORCE_QUEUE for h1. */ /* No forward */ #define UTP_FLT_FLAG_NO_PASS 0x00000004 /* Send only generated RST pkts. */ /* Mark flags. */ #define UTP_FLT_FLAG_MARK_L2 0x00000010 /* L2: set PCP. */ #define UTP_FLT_FLAG_MARK_L3 0x00000020 /* L3: set DSCP. */ /* Check summ ctrl flags. */ #define UTP_FLT_FLAG_CSUM_IP_CHK 0x00000100 /* Check summ IP on receive. */ #define UTP_FLT_FLAG_CSUM_UDP_CHK 0x00000200 /* Check summ UDP on receive. */ #define UTP_FLT_FLAG_CSUM_UDP_NO_CSUMM 0x00000400 /* No check summ UDP on gen RST. */ /* Keep this in sync with the above structure definition. */ #define NG_UTP_ADD_FILTER_FIELDS { \ { "l3_proto", &ng_parse_hint16_type }, \ { "action", &ng_parse_uint16_type }, \ { "flags", &ng_parse_hint32_type }, \ { "label_l2", &ng_parse_hint8_type }, \ { "label_l3", &ng_parse_hint8_type }, \ { "h0", &ng_parse_hookbuf_type }, \ { "h1", &ng_parse_hookbuf_type }, \ { NULL } \ } /* Statistics structure */ typedef struct ng_utp_filterstats_s { volatile uint64_t Octets; /* Total octets rec'd on link */ volatile uint64_t Packets; /* Total pkts rec'd on link */ volatile uint64_t IPv4_Packets; /* Total IPv4 pkts rec'd on link */ volatile uint64_t IPv6_Packets; /* Total IPv6 pkts rec'd on link */ volatile uint64_t MatchedPackets; /* Total matched pkts */ volatile uint64_t BypassPackets; /* Destined for unsupported protocol */ volatile uint64_t DroppedPackets; /* Destined for unsupported protocol */ volatile uint64_t recvErrors; /* Input errors on interface - no M_PKTHDR */ volatile uint64_t xmitErrors; /* Output errors on interface - ng send errors */ } ng_utp_filterstats_t; /* Keep this in sync with the above structure definition. */ #define NG_UTP_HOOK_STATS_TYPE_INFO { \ { "Octets", &ng_parse_uint64_type }, \ { "Packets", &ng_parse_uint64_type }, \ { "IPv4_Packets", &ng_parse_uint64_type }, \ { "IPv6_Packets", &ng_parse_uint64_type }, \ { "MatchedPackets", &ng_parse_uint64_type }, \ { "BypassPackets", &ng_parse_uint64_type }, \ { "DroppedPackets", &ng_parse_uint64_type }, \ { "recvErrors", &ng_parse_uint64_type }, \ { "xmitErrors", &ng_parse_uint64_type }, \ { NULL } \ } typedef struct ng_utp_conn_tbl_entry4_s { u_char saddr[4]; /* L3 src IP v4 addr. */ u_char daddr[4]; /* L3 dst IP v4 addr. */ uint16_t sport; /* L4 src port. */ uint16_t dport; /* L4 dst port. */ uint32_t conns_count; /* Ports count. */ uint32_t lifetime; /* Session lifetime (seconds). */ uint32_t idle; /* Session idle (seconds). */ } ng_utp_conn_tbl_entry4_t; /* Keep this in sync with the above structure definition. */ #define NG_UTP_CONN_TBL_ENTRY4_TYPE_INFO { \ { "\nsaddr", &ng_parse_ipaddr_type }, \ { "daddr", &ng_parse_ipaddr_type }, \ { "sport", &ng_parse_uint16_type }, \ { "dport", &ng_parse_uint16_type }, \ { "conns", &ng_parse_uint32_type }, \ { "lifetime", &ng_parse_uint32_type }, \ { "idle", &ng_parse_uint32_type }, \ { NULL } \ } /* Structure returned by NGM_UTP_GET_CONN_TABLE4. */ typedef struct ng_utp_conn_tbl4_list_s { uint32_t count; ng_utp_conn_tbl_entry4_t conn_entryes[]; } ng_utp_conn_tbl4_list_t; /* Keep this in sync with the above structure definition. */ #define NG_UTP_CONN_TBL4_LIST_TYPE_INFO(connentrytype) { \ { "count", &ng_parse_uint32_type }, \ { "conn_entryes", (connentrytype) }, \ { NULL } \ } #endif /* _NETGRAPH_NG_UTP_H_ */