Add tool: ngctl.

ngctl -- netgraph control utility.
The ngctl utility creates a new netgraph node of type socket which can be used to issue netgraph commands.
dev
logwang 2017-11-01 17:38:22 +08:00
parent bffb72754c
commit 3b2bd0f641
94 changed files with 16904 additions and 17 deletions

View File

@ -278,6 +278,7 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
struct ngm_mkpeer *const mkp = (struct ngm_mkpeer *) msg->data;
if (ng_findtype(mkp->type) == NULL) {
#ifndef FSTACK
char filename[NG_TYPESIZ + 3];
int fileid;
@ -298,6 +299,10 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
error = ENXIO;
goto release;
}
#else
error = ENOENT;
goto release;
#endif
}
}

View File

@ -42,8 +42,14 @@ HOST_CFLAGS = -O2 -frename-registers -funswitch-loops -fweb
else
HOST_CFLAGS = ${DEBUG}
endif
HOST_CFLAGS+= ${DPDK_CFLAGS}
HOST_CFLAGS+= ${CONF_CFLAGS}
ifdef FF_NETGRAPH
HOST_CFLAGS+= -DFF_NETGRAPH
endif
HOST_C= ${CC} -c $(HOST_CFLAGS) ${HOST_INCLUDES} ${WERROR} ${PROF} $<
@ -139,6 +145,12 @@ FF_SRCS+= \
ff_veth.c \
ff_route.c
ifdef FF_NETGRAPH
FF_SRCS+= \
ff_ng_base.c \
ff_ngctl.c
endif
FF_HOST_SRCS+= \
ff_host_interface.c \
ff_config.c \
@ -272,7 +284,6 @@ ifdef FF_NETGRAPH
NETGRAPH_SRCS += \
ng_async.c \
ng_atmllc.c \
ng_base.c \
ng_bridge.c \
ng_car.c \
ng_cisco.c \

View File

@ -111,7 +111,6 @@ int ff_gettimeofday(struct timeval *tv, struct timezone *tz);
extern int ff_fdisused(int fd);
/* route api begin */
enum FF_ROUTE_CTL {
FF_ROUTE_ADD,
@ -132,13 +131,31 @@ int ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag,
struct linux_sockaddr *dst, struct linux_sockaddr *gw,
struct linux_sockaddr *netmask);
/* route api end */
/* internal api begin */
/*
* This is used in handling ff_msg.
* Handle rtctl.
* The data is a pointer to struct rt_msghdr.
*/
int ff_rtioctl(int fib, void *data, unsigned *plen, unsigned maxlen);
/* route api end */
/*
* Handle ngctl.
*/
enum FF_NGCTL_CMD {
NGCTL_SOCKET,
NGCTL_BIND,
NGCTL_CONNECT,
NGCTL_SEND,
NGCTL_RECV,
NGCTL_CLOSE,
};
int ff_ngctl(int cmd, void *data);
/* internal api end */
#ifdef __cplusplus
}

View File

@ -43,3 +43,4 @@ ff_route_ctl
ff_rtioctl
ff_gettimeofday
ff_fdisused
ff_ngctl

View File

@ -1012,8 +1012,13 @@ done:
static inline void
handle_route_msg(struct ff_msg *msg, uint16_t proc_id)
{
msg->result = ff_rtioctl(msg->route.fib, msg->route.data,
int ret = ff_rtioctl(msg->route.fib, msg->route.data,
&msg->route.len, msg->route.maxlen);
if (ret < 0) {
msg->result = errno;
} else {
msg->result = 0;
}
rte_ring_enqueue(msg_ring[proc_id].ring[1], msg);
}
@ -1028,10 +1033,26 @@ handle_top_msg(struct ff_msg *msg, uint16_t proc_id)
rte_ring_enqueue(msg_ring[proc_id].ring[1], msg);
}
#ifdef FF_NETGRAPH
static inline void
handle_ngctl_msg(struct ff_msg *msg, uint16_t proc_id)
{
int ret = ff_ngctl(msg->ngctl.cmd, msg->ngctl.data);
if (ret < 0) {
msg->result = errno;
} else {
msg->result = 0;
msg->ngctl.ret = ret;
}
rte_ring_enqueue(msg_ring[proc_id].ring[1], msg);
}
#endif
static inline void
handle_default_msg(struct ff_msg *msg, uint16_t proc_id)
{
msg->result = EINVAL;
msg->result = ENOTSUP;
rte_ring_enqueue(msg_ring[proc_id].ring[1], msg);
}
@ -1051,6 +1072,11 @@ handle_msg(struct ff_msg *msg, uint16_t proc_id)
case FF_TOP:
handle_top_msg(msg, proc_id);
break;
#ifdef FF_NETGRAPH
case FF_NGCTL:
handle_ngctl_msg(msg, proc_id);
break;
#endif
default:
handle_default_msg(msg, proc_id);
break;

View File

@ -97,8 +97,8 @@ hashdestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask)
hashtbl = vhashtbl;
for (hp = hashtbl; hp <= &hashtbl[hashmask]; hp++)
if (!LIST_EMPTY(hp))
panic("hashdestroy: hash not empty");
KASSERT(LIST_EMPTY(hp), ("%s: hashtbl %p not empty "
"(malloc type %s)", __func__, hashtbl, type->ks_shortdesc));
free(hashtbl, type);
}

View File

@ -40,6 +40,7 @@ enum FF_MSG_TYPE {
FF_IOCTL,
FF_ROUTE,
FF_TOP,
FF_NGCTL,
};
struct ff_sysctl_args {
@ -71,6 +72,12 @@ struct ff_top_args {
unsigned long usr_tsc;
};
struct ff_ngctl_args {
int cmd;
int ret;
void *data;
};
#define MAX_MSG_BUF_SIZE 10240
/* structure of ipc msg */
@ -88,6 +95,7 @@ struct ff_msg {
struct ff_ioctl_args ioctl;
struct ff_route_args route;
struct ff_top_args top;
struct ff_ngctl_args ngctl;
};
} __attribute__((packed)) __rte_cache_aligned;

3876
lib/ff_ng_base.c Normal file

File diff suppressed because it is too large Load Diff

131
lib/ff_ngctl.c Normal file
View File

@ -0,0 +1,131 @@
/*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON 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 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <netgraph/ng_message.h>
#include <netgraph/ng_socket.h>
#include "ff_api.h"
#include "ff_host_interface.h"
static int
ngctl_socket(struct socket_args *uap)
{
int error = sys_socket(curthread, uap);
if (error) {
ff_os_errno(error);
return -1;
}
return curthread->td_retval[0];
}
static int
ngctl_connect(struct connect_args *uap)
{
int error = sys_connect(curthread, uap);
if (error) {
ff_os_errno(error);
return (-1);
}
return (error);
}
static int
ngctl_bind(struct bind_args *uap)
{
int error = sys_bind(curthread, uap);
if (error) {
ff_os_errno(error);
return (-1);
}
return (error);
}
static int
ngctl_recvfrom(struct recvfrom_args *uap)
{
int error = sys_recvfrom(curthread, uap);
if (error) {
ff_os_errno(error);
return (-1);
}
return curthread->td_retval[0];
}
static int
ngctl_sendto(struct sendto_args *uap)
{
int error = sys_sendto(curthread, uap);
if (error) {
ff_os_errno(error);
return (-1);
}
return curthread->td_retval[0];
}
static int
ngctl_close(int sockfd)
{
int error = kern_close(curthread, sockfd);
if (error) {
ff_os_errno(error);
return (-1);
}
return (error);
}
int
ff_ngctl(int cmd, void *data)
{
switch(cmd) {
case NGCTL_SOCKET:
return ngctl_socket((struct socket_args *)data);
case NGCTL_CONNECT:
return ngctl_connect((struct connect_args *)data);
case NGCTL_BIND:
return ngctl_bind((struct bind_args *)data);
case NGCTL_SEND:
return ngctl_sendto((struct sendto_args *)data);
case NGCTL_RECV:
return ngctl_recvfrom((struct recvfrom_args *)data);
case NGCTL_CLOSE:
return ngctl_close(*(int *)data);
default:
break;
}
ff_os_errno(EINVAL);
return (-1);
}

View File

@ -729,5 +729,10 @@ flush:
free(rtm, M_TEMP);
}
if (error != 0) {
ff_os_errno(error);
return (-1);
}
return (error);
}

View File

@ -1,4 +1,4 @@
SUBDIRS=compat libutil libmemstat libxo sysctl ifconfig route top netstat
SUBDIRS=compat libutil libmemstat libxo libnetgraph sysctl ifconfig route top netstat
all:
for d in $(SUBDIRS); do ( cd $$d; $(MAKE) all ) ; done

View File

@ -0,0 +1,214 @@
/*-
* Copyright (c) 2010-2011 Alexander V. Chernikov <melifaro@ipfw.ru>
* Copyright (c) 2004 Gleb Smirnoff <glebius@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON 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 ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $SourceForge: netflow.h,v 1.8 2004/09/16 17:05:11 glebius Exp $
* $FreeBSD$
*/
/* netflow timeouts in seconds */
#define ACTIVE_TIMEOUT (30*60) /* maximum flow lifetime is 30 min */
#define INACTIVE_TIMEOUT 15
/*
* More info can be found in these Cisco documents:
*
* Cisco IOS NetFlow, White Papers.
* http://www.cisco.com/en/US/products/ps6601/prod_white_papers_list.html
*
* Cisco CNS NetFlow Collection Engine User Guide, 5.0.2, NetFlow Export
* Datagram Formats.
* http://www.cisco.com/en/US/products/sw/netmgtsw/ps1964/products_user_guide_chapter09186a00803f3147.html#wp26453
*
* Cisco Systems NetFlow Services Export Version 9
* http://www.ietf.org/rfc/rfc3954.txt
*
*/
#define NETFLOW_V1 1
#define NETFLOW_V5 5
#define NETFLOW_V9 9
struct netflow_v1_header
{
uint16_t version; /* NetFlow version */
uint16_t count; /* Number of records in flow */
uint32_t sys_uptime; /* System uptime */
uint32_t unix_secs; /* Current seconds since 0000 UTC 1970 */
uint32_t unix_nsecs; /* Remaining nanoseconds since 0000 UTC 1970 */
} __attribute__((__packed__));
struct netflow_v5_header
{
uint16_t version; /* NetFlow version */
uint16_t count; /* Number of records in flow */
uint32_t sys_uptime; /* System uptime */
uint32_t unix_secs; /* Current seconds since 0000 UTC 1970 */
uint32_t unix_nsecs; /* Remaining nanoseconds since 0000 UTC 1970 */
uint32_t flow_seq; /* Sequence number of the first record */
uint8_t engine_type; /* Type of flow switching engine (RP,VIP,etc.) */
uint8_t engine_id; /* Slot number of the flow switching engine */
uint16_t pad; /* Pad to word boundary */
} __attribute__((__packed__));
struct netflow_v9_header
{
uint16_t version; /* NetFlow version */
uint16_t count; /* Total number of records in packet */
uint32_t sys_uptime; /* System uptime */
uint32_t unix_secs; /* Current seconds since 0000 UTC 1970 */
uint32_t seq_num; /* Sequence number */
uint32_t source_id; /* Observation Domain id */
} __attribute__((__packed__));
struct netflow_v1_record
{
uint32_t src_addr; /* Source IP address */
uint32_t dst_addr; /* Destination IP address */
uint32_t next_hop; /* Next hop IP address */
uint16_t in_ifx; /* Source interface index */
uint16_t out_ifx; /* Destination interface index */
uint32_t packets; /* Number of packets in a flow */
uint32_t octets; /* Number of octets in a flow */
uint32_t first; /* System uptime at start of a flow */
uint32_t last; /* System uptime at end of a flow */
uint16_t s_port; /* Source port */
uint16_t d_port; /* Destination port */
uint16_t pad1; /* Pad to word boundary */
uint8_t prot; /* IP protocol */
uint8_t tos; /* IP type of service */
uint8_t flags; /* Cumulative OR of tcp flags */
uint8_t pad2; /* Pad to word boundary */
uint16_t pad3; /* Pad to word boundary */
uint8_t reserved[5]; /* Reserved for future use */
} __attribute__((__packed__));
struct netflow_v5_record
{
uint32_t src_addr; /* Source IP address */
uint32_t dst_addr; /* Destination IP address */
uint32_t next_hop; /* Next hop IP address */
uint16_t i_ifx; /* Source interface index */
uint16_t o_ifx; /* Destination interface index */
uint32_t packets; /* Number of packets in a flow */
uint32_t octets; /* Number of octets in a flow */
uint32_t first; /* System uptime at start of a flow */
uint32_t last; /* System uptime at end of a flow */
uint16_t s_port; /* Source port */
uint16_t d_port; /* Destination port */
uint8_t pad1; /* Pad to word boundary */
uint8_t flags; /* Cumulative OR of tcp flags */
uint8_t prot; /* IP protocol */
uint8_t tos; /* IP type of service */
uint16_t src_as; /* Src peer/origin Autonomous System */
uint16_t dst_as; /* Dst peer/origin Autonomous System */
uint8_t src_mask; /* Source route's mask bits */
uint8_t dst_mask; /* Destination route's mask bits */
uint16_t pad2; /* Pad to word boundary */
} __attribute__((__packed__));
#define NETFLOW_V1_MAX_RECORDS 24
#define NETFLOW_V5_MAX_RECORDS 30
#define NETFLOW_V1_MAX_SIZE (sizeof(netflow_v1_header)+ \
sizeof(netflow_v1_record)*NETFLOW_V1_MAX_RECORDS)
#define NETFLOW_V5_MAX_SIZE (sizeof(netflow_v5_header)+ \
sizeof(netflow_v5_record)*NETFLOW_V5_MAX_RECORDS)
struct netflow_v5_export_dgram {
struct netflow_v5_header header;
struct netflow_v5_record r[NETFLOW_V5_MAX_RECORDS];
} __attribute__((__packed__));
/* RFC3954 field definitions */
#define NETFLOW_V9_FIELD_IN_BYTES 1 /* Input bytes count for a flow. Default 4, can be 8 */
#define NETFLOW_V9_FIELD_IN_PKTS 2 /* Incoming counter with number of packets associated with an IP Flow. Default 4 */
#define NETFLOW_V9_FIELD_FLOWS 3 /* Number of Flows that were aggregated. Default 4 */
#define NETFLOW_V9_FIELD_PROTOCOL 4 /* IP protocol byte. 1 */
#define NETFLOW_V9_FIELD_TOS 5 /* Type of service byte setting when entering the incoming interface. 1 */
#define NETFLOW_V9_FIELD_TCP_FLAGS 6 /* TCP flags; cumulative of all the TCP flags seen in this Flow. 1 */
#define NETFLOW_V9_FIELD_L4_SRC_PORT 7 /* TCP/UDP source port number. 2 */
#define NETFLOW_V9_FIELD_IPV4_SRC_ADDR 8 /* IPv4 source address. 4 */
#define NETFLOW_V9_FIELD_SRC_MASK 9 /* The number of contiguous bits in the source subnet mask (i.e., the mask in slash notation). 1 */
#define NETFLOW_V9_FIELD_INPUT_SNMP 10 /* Input interface index. Default 2 */
#define NETFLOW_V9_FIELD_L4_DST_PORT 11 /* TCP/UDP destination port number. 2 */
#define NETFLOW_V9_FIELD_IPV4_DST_ADDR 12 /* IPv4 destination address. 4 */
#define NETFLOW_V9_FIELD_DST_MASK 13 /* The number of contiguous bits in the destination subnet mask (i.e., the mask in slash notation). 1 */
#define NETFLOW_V9_FIELD_OUTPUT_SNMP 14 /* Output interface index. Default 2 */
#define NETFLOW_V9_FIELD_IPV4_NEXT_HOP 15 /* IPv4 address of the next-hop router. 4 */
#define NETFLOW_V9_FIELD_SRC_AS 16 /* Source BGP autonomous system number. Default 2, can be 4 */
#define NETFLOW_V9_FIELD_DST_AS 17 /* Destination BGP autonomous system number. Default 2, can be 4 */
#define NETFLOW_V9_FIELD_BGP_IPV4_NEXT_HOP 18 /* Next-hop router's IP address in the BGP domain. 4 */
#define NETFLOW_V9_FIELD_MUL_DST_PKTS 19 /* IP multicast outgoing packet counter for packets associated with IP flow. Default 4 */
#define NETFLOW_V9_FIELD_MUL_DST_BYTES 20 /* IP multicast outgoing Octet (byte) counter for the number of bytes associated with IP flow. Default 4 */
#define NETFLOW_V9_FIELD_LAST_SWITCHED 21 /* sysUptime in msec at which the last packet of this Flow was switched. 4 */
#define NETFLOW_V9_FIELD_FIRST_SWITCHED 22 /* sysUptime in msec at which the first packet of this Flow was switched. 4 */
#define NETFLOW_V9_FIELD_OUT_BYTES 23 /* Outgoing counter for the number of bytes associated with an IP Flow. Default 4 */
#define NETFLOW_V9_FIELD_OUT_PKTS 24 /* Outgoing counter for the number of packets associated with an IP Flow. Default 4 */
#define NETFLOW_V9_FIELD_IPV6_SRC_ADDR 27 /* IPv6 source address. 16 */
#define NETFLOW_V9_FIELD_IPV6_DST_ADDR 28 /* IPv6 destination address. 16 */
#define NETFLOW_V9_FIELD_IPV6_SRC_MASK 29 /* Length of the IPv6 source mask in contiguous bits. 1 */
#define NETFLOW_V9_FIELD_IPV6_DST_MASK 30 /* Length of the IPv6 destination mask in contiguous bits. 1 */
#define NETFLOW_V9_FIELD_IPV6_FLOW_LABEL 31 /* IPv6 flow label as per RFC 2460 definition. 3 */
#define NETFLOW_V9_FIELD_ICMP_TYPE 32 /* Internet Control Message Protocol (ICMP) packet type; reported as ICMP Type * 256 + ICMP code. 2 */
#define NETFLOW_V9_FIELD_MUL_IGMP_TYPE 33 /* Internet Group Management Protocol (IGMP) packet type. 1 */
#define NETFLOW_V9_FIELD_SAMPLING_INTERVAL 34 /* When using sampled NetFlow, the rate at which packets are sampled; for example, a value of 100 indicates that one of every hundred packets is sampled. 4 */
#define NETFLOW_V9_FIELD_SAMPLING_ALGORITHM 35 /* For sampled NetFlow platform-wide: 0x01 deterministic sampling 0x02 random sampling. 1 */
#define NETFLOW_V9_FIELD_FLOW_ACTIVE_TIMEOUT 36 /* Timeout value (in seconds) for active flow entries in the NetFlow cache. 2 */
#define NETFLOW_V9_FIELD_FLOW_INACTIVE_TIMEOUT 37 /* Timeout value (in seconds) for inactive Flow entries in the NetFlow cache. 2 */
#define NETFLOW_V9_FIELD_ENGINE_TYPE 38 /* Type of Flow switching engine (route processor, linecard, etc...). 1 */
#define NETFLOW_V9_FIELD_ENGINE_ID 39 /* ID number of the Flow switching engine. 1 */
#define NETFLOW_V9_FIELD_TOTAL_BYTES_EXP 40 /* Counter with for the number of bytes exported by the Observation Domain. Default 4 */
#define NETFLOW_V9_FIELD_TOTAL_PKTS_EXP 41 /* Counter with for the number of packets exported by the Observation Domain. Default 4 */
#define NETFLOW_V9_FIELD_TOTAL_FLOWS_EXP 42 /* Counter with for the number of flows exported by the Observation Domain. Default 4 */
#define NETFLOW_V9_FIELD_MPLS_TOP_LABEL_TYPE 46 /* MPLS Top Label Type. 1 */
#define NETFLOW_V9_FIELD_MPLS_TOP_LABEL_IP_ADDR 47 /* Forwarding Equivalent Class corresponding to the MPLS Top Label. 4 */
#define NETFLOW_V9_FIELD_FLOW_SAMPLER_ID 48 /* Identifier shown in "show flow-sampler". 1 */
#define NETFLOW_V9_FIELD_FLOW_SAMPLER_MODE 49 /* The type of algorithm used for sampling data. 2 */
#define NETFLOW_V9_FIELD_FLOW_SAMPLER_RANDOM_INTERVAL 50 /* Packet interval at which to sample. 4. */
#define NETFLOW_V9_FIELD_DST_TOS 55 /* Type of Service byte setting when exiting outgoing interface. 1. */
#define NETFLOW_V9_FIELD_SRC_MAC 56 /* Source MAC Address. 6 */
#define NETFLOW_V9_FIELD_DST_MAC 57 /* Destination MAC Address. 6 */
#define NETFLOW_V9_FIELD_SRC_VLAN 58 /* Virtual LAN identifier associated with ingress interface. 2 */
#define NETFLOW_V9_FIELD_DST_VLAN 59 /* Virtual LAN identifier associated with egress interface. 2 */
#define NETFLOW_V9_FIELD_IP_PROTOCOL_VERSION 60 /* Internet Protocol Version. Set to 4 for IPv4, set to 6 for IPv6. If not present in the template, then version 4 is assumed. 1. */
#define NETFLOW_V9_FIELD_DIRECTION 61 /* Flow direction: 0 - ingress flow 1 - egress flow. 1 */
#define NETFLOW_V9_FIELD_IPV6_NEXT_HOP 62 /* IPv6 address of the next-hop router. 16 */
#define NETFLOW_V9_FIELD_BGP_IPV6_NEXT_HOP 63 /* Next-hop router in the BGP domain. 16 */
#define NETFLOW_V9_FIELD_IPV6_OPTION_HEADERS 64 /* Bit-encoded field identifying IPv6 option headers found in the flow */
#define NETFLOW_V9_FIELD_MPLS_LABEL_1 70 /* MPLS label at position 1 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_2 71 /* MPLS label at position 2 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_3 72 /* MPLS label at position 3 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_4 73 /* MPLS label at position 4 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_5 74 /* MPLS label at position 5 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_6 75 /* MPLS label at position 6 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_7 76 /* MPLS label at position 7 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_8 77 /* MPLS label at position 8 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_9 78 /* MPLS label at position 9 in the stack. 3 */
#define NETFLOW_V9_FIELD_MPLS_LABEL_10 79 /* MPLS label at position 10 in the stack. 3 */
#define NETFLOW_V9_MAX_RESERVED_FLOWSET 0xFF /* Clause 5.2 */

View File

@ -0,0 +1,542 @@
/*-
* Copyright (c) 2010-2011 Alexander V. Chernikov <melifaro@ipfw.ru>
* Copyright (c) 2004-2005 Gleb Smirnoff <glebius@FreeBSD.org>
* Copyright (c) 2001-2003 Roman V. Palagin <romanp@unshadow.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON 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 ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $SourceForge: ng_netflow.h,v 1.26 2004/09/04 15:44:55 glebius Exp $
* $FreeBSD$
*/
#ifndef _NG_NETFLOW_H_
#define _NG_NETFLOW_H_
#define NG_NETFLOW_NODE_TYPE "netflow"
#define NGM_NETFLOW_COOKIE 1365756954
#define NGM_NETFLOW_V9_COOKIE 1349865386
#define NG_NETFLOW_MAXIFACES USHRT_MAX
/* Hook names */
#define NG_NETFLOW_HOOK_DATA "iface"
#define NG_NETFLOW_HOOK_OUT "out"
#define NG_NETFLOW_HOOK_EXPORT "export"
#define NG_NETFLOW_HOOK_EXPORT9 "export9"
/* This define effectively disable (v5) netflow export hook! */
/* #define COUNTERS_64 */
/* Netgraph commands understood by netflow node */
enum {
NGM_NETFLOW_INFO = 1|NGM_READONLY|NGM_HASREPLY, /* get node info */
NGM_NETFLOW_IFINFO = 2|NGM_READONLY|NGM_HASREPLY, /* get iface info */
NGM_NETFLOW_SHOW = 3|NGM_READONLY|NGM_HASREPLY, /* show ip cache flow */
NGM_NETFLOW_SETDLT = 4, /* set data-link type */
NGM_NETFLOW_SETIFINDEX = 5, /* set interface index */
NGM_NETFLOW_SETTIMEOUTS = 6, /* set active/inactive flow timeouts */
NGM_NETFLOW_SETCONFIG = 7, /* set flow generation options */
NGM_NETFLOW_SETTEMPLATE = 8, /* set v9 flow template periodic */
NGM_NETFLOW_SETMTU = 9, /* set outgoing interface MTU */
NGM_NETFLOW_V9INFO = 10|NGM_READONLY|NGM_HASREPLY, /* get v9 info */
};
/* This structure is returned by the NGM_NETFLOW_INFO message */
struct ng_netflow_info {
uint64_t nfinfo_bytes; /* accounted IPv4 bytes */
uint64_t nfinfo_packets; /* accounted IPv4 packets */
uint64_t nfinfo_bytes6; /* accounted IPv6 bytes */
uint64_t nfinfo_packets6; /* accounted IPv6 packets */
uint64_t nfinfo_sbytes; /* skipped IPv4 bytes */
uint64_t nfinfo_spackets; /* skipped IPv4 packets */
uint64_t nfinfo_sbytes6; /* skipped IPv6 bytes */
uint64_t nfinfo_spackets6; /* skipped IPv6 packets */
uint64_t nfinfo_act_exp; /* active expiries */
uint64_t nfinfo_inact_exp; /* inactive expiries */
uint32_t nfinfo_used; /* used cache records */
uint32_t nfinfo_used6; /* used IPv6 cache records */
uint32_t nfinfo_alloc_failed; /* failed allocations */
uint32_t nfinfo_export_failed; /* failed exports */
uint32_t nfinfo_export9_failed; /* failed exports */
uint32_t nfinfo_realloc_mbuf; /* reallocated mbufs */
uint32_t nfinfo_alloc_fibs; /* fibs allocated */
uint32_t nfinfo_inact_t; /* flow inactive timeout */
uint32_t nfinfo_act_t; /* flow active timeout */
};
/* Parse the info structure */
#define NG_NETFLOW_INFO_TYPE { \
{ "IPv4 bytes", &ng_parse_uint64_type },\
{ "IPv4 packets", &ng_parse_uint64_type },\
{ "IPv6 bytes", &ng_parse_uint64_type },\
{ "IPv6 packets", &ng_parse_uint64_type },\
{ "IPv4 skipped bytes", &ng_parse_uint64_type },\
{ "IPv4 skipped packets", &ng_parse_uint64_type },\
{ "IPv6 skipped bytes", &ng_parse_uint64_type },\
{ "IPv6 skipped packets", &ng_parse_uint64_type },\
{ "Active expiries", &ng_parse_uint64_type },\
{ "Inactive expiries", &ng_parse_uint64_type },\
{ "IPv4 records used", &ng_parse_uint32_type },\
{ "IPv6 records used", &ng_parse_uint32_type },\
{ "Failed allocations", &ng_parse_uint32_type },\
{ "V5 failed exports", &ng_parse_uint32_type },\
{ "V9 failed exports", &ng_parse_uint32_type },\
{ "mbuf reallocations", &ng_parse_uint32_type },\
{ "fibs allocated", &ng_parse_uint32_type },\
{ "Inactive timeout", &ng_parse_uint32_type },\
{ "Active timeout", &ng_parse_uint32_type },\
{ NULL } \
}
/* This structure is returned by the NGM_NETFLOW_IFINFO message */
struct ng_netflow_ifinfo {
uint32_t ifinfo_packets; /* number of packets for this iface */
uint8_t ifinfo_dlt; /* Data Link Type, DLT_XXX */
#define MAXDLTNAMELEN 20
uint16_t ifinfo_index; /* connected iface index */
uint32_t conf;
};
/* This structure is passed to NGM_NETFLOW_SETDLT message */
struct ng_netflow_setdlt {
uint16_t iface; /* which iface dlt change */
uint8_t dlt; /* DLT_XXX from bpf.h */
};
/* This structure is passed to NGM_NETFLOW_SETIFINDEX */
struct ng_netflow_setifindex {
uint16_t iface; /* which iface index change */
uint16_t index; /* new index */
};
/* This structure is passed to NGM_NETFLOW_SETTIMEOUTS */
struct ng_netflow_settimeouts {
uint32_t inactive_timeout; /* flow inactive timeout */
uint32_t active_timeout; /* flow active timeout */
};
#define NG_NETFLOW_CONF_INGRESS 0x01 /* Account on ingress */
#define NG_NETFLOW_CONF_EGRESS 0x02 /* Account on egress */
#define NG_NETFLOW_CONF_ONCE 0x04 /* Add tag to account only once */
#define NG_NETFLOW_CONF_THISONCE 0x08 /* Account once in current node */
#define NG_NETFLOW_CONF_NOSRCLOOKUP 0x10 /* No radix lookup on src */
#define NG_NETFLOW_CONF_NODSTLOOKUP 0x20 /* No radix lookup on dst */
#define NG_NETFLOW_IS_FRAG 0x01
#define NG_NETFLOW_FLOW_FLAGS (NG_NETFLOW_CONF_NOSRCLOOKUP|\
NG_NETFLOW_CONF_NODSTLOOKUP)
/* This structure is passed to NGM_NETFLOW_SETCONFIG */
struct ng_netflow_setconfig {
uint16_t iface; /* which iface config change */
uint32_t conf; /* new config */
};
/* This structure is passed to NGM_NETFLOW_SETTEMPLATE */
struct ng_netflow_settemplate {
uint16_t time; /* max time between announce */
uint16_t packets; /* max packets between announce */
};
/* This structure is passed to NGM_NETFLOW_SETMTU */
struct ng_netflow_setmtu {
uint16_t mtu; /* MTU for packet */
};
/* This structure is used in NGM_NETFLOW_SHOW request/response */
struct ngnf_show_header {
u_char version; /* IPv4 or IPv6 */
uint32_t hash_id; /* current hash index */
uint32_t list_id; /* current record number in hash */
uint32_t nentries; /* number of records in response */
};
/* This structure is used in NGM_NETFLOW_V9INFO message */
struct ng_netflow_v9info {
uint16_t templ_packets; /* v9 template packets */
uint16_t templ_time; /* v9 template time */
uint16_t mtu; /* v9 MTU */
};
/* XXXGL
* Somewhere flow_rec6 is casted to flow_rec, and flow6_entry_data is
* casted to flow_entry_data. After casting, fle->r.fib is accessed.
* So beginning of these structs up to fib should be kept common.
*/
/* This is unique data, which identifies flow */
struct flow_rec {
uint16_t flow_type;
uint16_t fib;
struct in_addr r_src;
struct in_addr r_dst;
union {
struct {
uint16_t s_port; /* source TCP/UDP port */
uint16_t d_port; /* destination TCP/UDP port */
} dir;
uint32_t both;
} ports;
union {
struct {
u_char prot; /* IP protocol */
u_char tos; /* IP TOS */
uint16_t i_ifx; /* input interface index */
} i;
uint32_t all;
} misc;
};
/* This is unique data, which identifies flow */
struct flow6_rec {
uint16_t flow_type;
uint16_t fib;
union {
struct in_addr r_src;
struct in6_addr r_src6;
} src;
union {
struct in_addr r_dst;
struct in6_addr r_dst6;
} dst;
union {
struct {
uint16_t s_port; /* source TCP/UDP port */
uint16_t d_port; /* destination TCP/UDP port */
} dir;
uint32_t both;
} ports;
union {
struct {
u_char prot; /* IP protocol */
u_char tos; /* IP TOS */
uint16_t i_ifx; /* input interface index */
} i;
uint32_t all;
} misc;
};
#define r_ip_p misc.i.prot
#define r_tos misc.i.tos
#define r_i_ifx misc.i.i_ifx
#define r_misc misc.all
#define r_ports ports.both
#define r_sport ports.dir.s_port
#define r_dport ports.dir.d_port
/* A flow entry which accumulates statistics */
struct flow_entry_data {
uint16_t version; /* Protocol version */
struct flow_rec r;
struct in_addr next_hop;
uint16_t fle_o_ifx; /* output interface index */
#define fle_i_ifx r.misc.i.i_ifx
uint8_t dst_mask; /* destination route mask bits */
uint8_t src_mask; /* source route mask bits */
u_long packets;
u_long bytes;
long first; /* uptime on first packet */
long last; /* uptime on last packet */
u_char tcp_flags; /* cumulative OR */
};
struct flow6_entry_data {
uint16_t version; /* Protocol version */
struct flow6_rec r;
union {
struct in_addr next_hop;
struct in6_addr next_hop6;
} n;
uint16_t fle_o_ifx; /* output interface index */
#define fle_i_ifx r.misc.i.i_ifx
uint8_t dst_mask; /* destination route mask bits */
uint8_t src_mask; /* source route mask bits */
u_long packets;
u_long bytes;
long first; /* uptime on first packet */
long last; /* uptime on last packet */
u_char tcp_flags; /* cumulative OR */
};
/*
* How many flow records we will transfer at once
* without overflowing socket receive buffer
*/
#define NREC_AT_ONCE 1000
#define NREC6_AT_ONCE (NREC_AT_ONCE * sizeof(struct flow_entry_data) / \
sizeof(struct flow6_entry_data))
#define NGRESP_SIZE (sizeof(struct ngnf_show_header) + (NREC_AT_ONCE * \
sizeof(struct flow_entry_data)))
#define SORCVBUF_SIZE (NGRESP_SIZE + 2 * sizeof(struct ng_mesg))
/* Everything below is for kernel */
#ifdef _KERNEL
struct flow_entry {
TAILQ_ENTRY(flow_entry) fle_hash; /* entries in hash slot */
struct flow_entry_data f;
};
struct flow6_entry {
TAILQ_ENTRY(flow_entry) fle_hash; /* entries in hash slot */
struct flow6_entry_data f;
};
/* Parsing declarations */
/* Parse the ifinfo structure */
#define NG_NETFLOW_IFINFO_TYPE { \
{ "packets", &ng_parse_uint32_type },\
{ "data link type", &ng_parse_uint8_type }, \
{ "index", &ng_parse_uint16_type },\
{ "conf", &ng_parse_uint32_type },\
{ NULL } \
}
/* Parse the setdlt structure */
#define NG_NETFLOW_SETDLT_TYPE { \
{ "iface", &ng_parse_uint16_type }, \
{ "dlt", &ng_parse_uint8_type }, \
{ NULL } \
}
/* Parse the setifindex structure */
#define NG_NETFLOW_SETIFINDEX_TYPE { \
{ "iface", &ng_parse_uint16_type }, \
{ "index", &ng_parse_uint16_type }, \
{ NULL } \
}
/* Parse the settimeouts structure */
#define NG_NETFLOW_SETTIMEOUTS_TYPE { \
{ "inactive", &ng_parse_uint32_type }, \
{ "active", &ng_parse_uint32_type }, \
{ NULL } \
}
/* Parse the setifindex structure */
#define NG_NETFLOW_SETCONFIG_TYPE { \
{ "iface", &ng_parse_uint16_type }, \
{ "conf", &ng_parse_uint32_type }, \
{ NULL } \
}
/* Parse the settemplate structure */
#define NG_NETFLOW_SETTEMPLATE_TYPE { \
{ "time", &ng_parse_uint16_type }, \
{ "packets", &ng_parse_uint16_type }, \
{ NULL } \
}
/* Parse the setmtu structure */
#define NG_NETFLOW_SETMTU_TYPE { \
{ "mtu", &ng_parse_uint16_type }, \
{ NULL } \
}
/* Parse the v9info structure */
#define NG_NETFLOW_V9INFO_TYPE { \
{ "v9 template packets", &ng_parse_uint16_type },\
{ "v9 template time", &ng_parse_uint16_type },\
{ "v9 MTU", &ng_parse_uint16_type },\
{ NULL } \
}
/* Private hook data */
struct ng_netflow_iface {
hook_p hook; /* NULL when disconnected */
hook_p out; /* NULL when no bypass hook */
struct ng_netflow_ifinfo info;
};
typedef struct ng_netflow_iface *iface_p;
typedef struct ng_netflow_ifinfo *ifinfo_p;
struct netflow_export_item {
item_p item;
item_p item9;
struct netflow_v9_packet_opt *item9_opt;
};
/* Structure contatining fib-specific data */
struct fib_export {
uint32_t fib; /* kernel fib id */
/* Various data used for export */
struct netflow_export_item exp;
struct mtx export_mtx; /* exp.item mutex */
struct mtx export9_mtx; /* exp.item9 mutex */
uint32_t flow_seq; /* current V5 flow sequence */
uint32_t flow9_seq; /* current V9 flow sequence */
uint32_t domain_id; /* Observartion domain id */
/* Netflow V9 counters */
uint32_t templ_last_ts; /* unixtime of last template announce */
uint32_t templ_last_pkt; /* packet count on last announce */
uint32_t sent_packets; /* packets sent by exporter; */
/* Current packet specific options */
struct netflow_v9_packet_opt *export9_opt;
};
typedef struct fib_export *fib_export_p;
/* Structure describing our flow engine */
struct netflow {
node_p node; /* link to the node itself */
hook_p export; /* export data goes there */
hook_p export9; /* Netflow V9 export data goes there */
struct callout exp_callout; /* expiry periodic job */
/*
* Flow entries are allocated in uma(9) zone zone. They are
* indexed by hash hash. Each hash element consist of tailqueue
* head and mutex to protect this element.
*/
#define CACHESIZE (65536*16)
#define CACHELOWAT (CACHESIZE * 3/4)
#define CACHEHIGHWAT (CACHESIZE * 9/10)
uma_zone_t zone;
struct flow_hash_entry *hash;
/*
* NetFlow data export
*
* export_item is a data item, it has an mbuf with cluster
* attached to it. A thread detaches export_item from priv
* and works with it. If the export is full it is sent, and
* a new one is allocated. Before exiting thread re-attaches
* its current item back to priv. If there is item already,
* current incomplete datagram is sent.
* export_mtx is used for attaching/detaching.
*/
/* IPv6 support */
#ifdef INET6
uma_zone_t zone6;
struct flow_hash_entry *hash6;
#endif
/* Statistics. */
counter_u64_t nfinfo_bytes; /* accounted IPv4 bytes */
counter_u64_t nfinfo_packets; /* accounted IPv4 packets */
counter_u64_t nfinfo_bytes6; /* accounted IPv6 bytes */
counter_u64_t nfinfo_packets6; /* accounted IPv6 packets */
counter_u64_t nfinfo_sbytes; /* skipped IPv4 bytes */
counter_u64_t nfinfo_spackets; /* skipped IPv4 packets */
counter_u64_t nfinfo_sbytes6; /* skipped IPv6 bytes */
counter_u64_t nfinfo_spackets6; /* skipped IPv6 packets */
counter_u64_t nfinfo_act_exp; /* active expiries */
counter_u64_t nfinfo_inact_exp; /* inactive expiries */
uint32_t nfinfo_alloc_failed; /* failed allocations */
uint32_t nfinfo_export_failed; /* failed exports */
uint32_t nfinfo_export9_failed; /* failed exports */
uint32_t nfinfo_realloc_mbuf; /* reallocated mbufs */
uint32_t nfinfo_alloc_fibs; /* fibs allocated */
uint32_t nfinfo_inact_t; /* flow inactive timeout */
uint32_t nfinfo_act_t; /* flow active timeout */
/* Multiple FIB support */
fib_export_p *fib_data; /* vector to per-fib data */
uint16_t maxfibs; /* number of allocated fibs */
/* Netflow v9 configuration options */
/*
* RFC 3954 clause 7.3
* "Both options MUST be configurable by the user on the Exporter."
*/
uint16_t templ_time; /* time between sending templates */
uint16_t templ_packets; /* packets between sending templates */
#define NETFLOW_V9_MAX_FLOWSETS 2
u_char flowsets_count; /* current flowsets used */
/* Count of records in each flowset */
u_char flowset_records[NETFLOW_V9_MAX_FLOWSETS - 1];
uint16_t mtu; /* export interface MTU */
/* Pointers to pre-compiled flowsets */
struct netflow_v9_flowset_header
*v9_flowsets[NETFLOW_V9_MAX_FLOWSETS - 1];
struct ng_netflow_iface ifaces[NG_NETFLOW_MAXIFACES];
};
typedef struct netflow *priv_p;
/* Header of a small list in hash cell */
struct flow_hash_entry {
struct mtx mtx;
TAILQ_HEAD(fhead, flow_entry) head;
};
#define ERROUT(x) { error = (x); goto done; }
#define MTAG_NETFLOW 1221656444
#define MTAG_NETFLOW_CALLED 0
#define m_pktlen(m) ((m)->m_pkthdr.len)
#define IP6VERSION 6
#define priv_to_fib(priv, fib) (priv)->fib_data[(fib)]
/*
* Cisco uses milliseconds for uptime. Bad idea, since it overflows
* every 48+ days. But we will do same to keep compatibility. This macro
* does overflowable multiplication to 1000.
*/
#define MILLIUPTIME(t) (((t) << 9) + /* 512 */ \
((t) << 8) + /* 256 */ \
((t) << 7) + /* 128 */ \
((t) << 6) + /* 64 */ \
((t) << 5) + /* 32 */ \
((t) << 3)) /* 8 */
/* Prototypes for netflow.c */
void ng_netflow_cache_init(priv_p);
void ng_netflow_cache_flush(priv_p);
int ng_netflow_fib_init(priv_p priv, int fib);
void ng_netflow_copyinfo(priv_p, struct ng_netflow_info *);
void ng_netflow_copyv9info(priv_p, struct ng_netflow_v9info *);
timeout_t ng_netflow_expire;
int ng_netflow_flow_add(priv_p, fib_export_p, struct ip *, caddr_t,
uint8_t, uint8_t, unsigned int);
int ng_netflow_flow6_add(priv_p, fib_export_p, struct ip6_hdr *, caddr_t,
uint8_t, uint8_t, unsigned int);
int ng_netflow_flow_show(priv_p, struct ngnf_show_header *req,
struct ngnf_show_header *resp);
void ng_netflow_v9_cache_init(priv_p);
void ng_netflow_v9_cache_flush(priv_p);
item_p get_export9_dgram(priv_p, fib_export_p,
struct netflow_v9_packet_opt **);
void return_export9_dgram(priv_p, fib_export_p, item_p,
struct netflow_v9_packet_opt *, int);
int export9_add(item_p, struct netflow_v9_packet_opt *,
struct flow_entry *);
int export9_send(priv_p, fib_export_p, item_p,
struct netflow_v9_packet_opt *, int);
#endif /* _KERNEL */
#endif /* _NG_NETFLOW_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,56 @@
/*
* ng_UI.h
*/
/*-
* Copyright (c) 1996-1999 Whistle Communications, 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: Julian Elischer <julian@freebsd.org>
*
* $FreeBSD$
* $Whistle: ng_UI.h,v 1.6 1999/01/20 00:54:15 archie Exp $
*/
#ifndef _NETGRAPH_NG_UI_H_
#define _NETGRAPH_NG_UI_H_
/* Node type name and cookie */
#define NG_UI_NODE_TYPE "UI"
#define NGM_UI_COOKIE 884639499
/* Hook names */
#define NG_UI_HOOK_DOWNSTREAM "downstream"
#define NG_UI_HOOK_UPSTREAM "upstream"
#endif /* _NETGRAPH_NG_UI_H_ */

View File

@ -0,0 +1,110 @@
/*
* ng_async.h
*/
/*-
* Copyright (c) 1996-1999 Whistle Communications, 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: Archie Cobbs <archie@freebsd.org>
*
* $FreeBSD$
* $Whistle: ng_async.h,v 1.5 1999/01/25 01:17:14 archie Exp $
*/
#ifndef _NETGRAPH_NG_ASYNC_H_
#define _NETGRAPH_NG_ASYNC_H_
/* Type name and cookie */
#define NG_ASYNC_NODE_TYPE "async"
#define NGM_ASYNC_COOKIE 886473717
/* Hook names */
#define NG_ASYNC_HOOK_SYNC "sync" /* Sync frames */
#define NG_ASYNC_HOOK_ASYNC "async" /* Async-encoded frames */
/* Maximum receive size bounds (for both sync and async sides) */
#define NG_ASYNC_MIN_MRU 1
#define NG_ASYNC_MAX_MRU 8192
#define NG_ASYNC_DEFAULT_MRU 1600
/* Frame statistics */
struct ng_async_stat {
u_int32_t syncOctets;
u_int32_t syncFrames;
u_int32_t syncOverflows;
u_int32_t asyncOctets;
u_int32_t asyncFrames;
u_int32_t asyncRunts;
u_int32_t asyncOverflows;
u_int32_t asyncBadCheckSums;
};
/* Keep this in sync with the above structure definition */
#define NG_ASYNC_STATS_TYPE_INFO { \
{ "syncOctets", &ng_parse_uint32_type }, \
{ "syncFrames", &ng_parse_uint32_type }, \
{ "syncOverflows", &ng_parse_uint32_type }, \
{ "asyncOctets", &ng_parse_uint32_type }, \
{ "asyncFrames", &ng_parse_uint32_type }, \
{ "asyncRunts", &ng_parse_uint32_type }, \
{ "asyncOverflows", &ng_parse_uint32_type }, \
{ "asyncBadCheckSums",&ng_parse_uint32_type }, \
{ NULL } \
}
/* Configuration for this node */
struct ng_async_cfg {
u_char enabled; /* Turn encoding on/off */
u_int16_t amru; /* Max receive async frame length */
u_int16_t smru; /* Max receive sync frame length */
u_int32_t accm; /* ACCM encoding */
};
/* Keep this in sync with the above structure definition */
#define NG_ASYNC_CONFIG_TYPE_INFO { \
{ "enabled", &ng_parse_int8_type }, \
{ "amru", &ng_parse_uint16_type }, \
{ "smru", &ng_parse_uint16_type }, \
{ "accm", &ng_parse_hint32_type }, \
{ NULL } \
}
/* Commands */
enum {
NGM_ASYNC_CMD_GET_STATS = 1, /* returns struct ng_async_stat */
NGM_ASYNC_CMD_CLR_STATS,
NGM_ASYNC_CMD_SET_CONFIG, /* takes struct ng_async_cfg */
NGM_ASYNC_CMD_GET_CONFIG, /* returns struct ng_async_cfg */
};
#endif /* _NETGRAPH_NG_ASYNC_H_ */

View File

@ -0,0 +1,45 @@
/*-
* Copyright (c) 2003-2004 Benno Rice <benno@FreeBSD.org>
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON 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 ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _NETGRAPH_ATMLLC_H_
#define _NETGRAPH_ATMLLC_H_
/* Node type name and magic cookie. */
#define NG_ATMLLC_NODE_TYPE "atmllc"
#define NGM_ATMLLC_COOKIE 1065246274
/* Hook names. */
#define NG_ATMLLC_HOOK_ATM "atm"
#define NG_ATMLLC_HOOK_ETHER "ether"
#define NG_ATMLLC_HOOK_802_4 "ieee8024"
#define NG_ATMLLC_HOOK_802_5 "ieee8025"
#define NG_ATMLLC_HOOK_802_6 "ieee8026"
#define NG_ATMLLC_HOOK_FDDI "fddi"
#define NG_ATMLLC_HOOK_BPDU "bpdu"
#endif /* _NETGRAPH_ATMLLC_H_ */

View File

@ -0,0 +1,103 @@
/*
* ng_bpf.h
*/
/*-
* Copyright (c) 1996-1999 Whistle Communications, 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: Archie Cobbs <archie@freebsd.org>
*
* $FreeBSD$
* $Whistle: ng_bpf.h,v 1.3 1999/12/03 20:30:23 archie Exp $
*/
#ifndef _NETGRAPH_NG_BPF_H_
#define _NETGRAPH_NG_BPF_H_
/* Node type name and magic cookie */
#define NG_BPF_NODE_TYPE "bpf"
#define NGM_BPF_COOKIE 944100792
/* Program structure for one hook */
struct ng_bpf_hookprog {
char thisHook[NG_HOOKSIZ]; /* name of hook */
char ifMatch[NG_HOOKSIZ]; /* match dest hook */
char ifNotMatch[NG_HOOKSIZ]; /* !match dest hook */
int32_t bpf_prog_len; /* #insns in program */
struct bpf_insn bpf_prog[]; /* bpf program */
};
#define NG_BPF_HOOKPROG_SIZE(numInsn) \
(sizeof(struct ng_bpf_hookprog) + (numInsn) * sizeof(struct bpf_insn))
/* Keep this in sync with the above structure definition */
#define NG_BPF_HOOKPROG_TYPE_INFO(bptype) { \
{ "thisHook", &ng_parse_hookbuf_type }, \
{ "ifMatch", &ng_parse_hookbuf_type }, \
{ "ifNotMatch", &ng_parse_hookbuf_type }, \
{ "bpf_prog_len", &ng_parse_int32_type }, \
{ "bpf_prog", (bptype) }, \
{ NULL } \
}
/* Statistics structure for one hook */
struct ng_bpf_hookstat {
u_int64_t recvFrames;
u_int64_t recvOctets;
u_int64_t recvMatchFrames;
u_int64_t recvMatchOctets;
u_int64_t xmitFrames;
u_int64_t xmitOctets;
};
/* Keep this in sync with the above structure definition */
#define NG_BPF_HOOKSTAT_TYPE_INFO { \
{ "recvFrames", &ng_parse_uint64_type }, \
{ "recvOctets", &ng_parse_uint64_type }, \
{ "recvMatchFrames", &ng_parse_uint64_type }, \
{ "recvMatchOctets", &ng_parse_uint64_type }, \
{ "xmitFrames", &ng_parse_uint64_type }, \
{ "xmitOctets", &ng_parse_uint64_type }, \
{ NULL } \
}
/* Netgraph commands */
enum {
NGM_BPF_SET_PROGRAM = 1, /* supply a struct ng_bpf_hookprog */
NGM_BPF_GET_PROGRAM, /* returns a struct ng_bpf_hookprog */
NGM_BPF_GET_STATS, /* supply name as char[NG_HOOKSIZ] */
NGM_BPF_CLR_STATS, /* supply name as char[NG_HOOKSIZ] */
NGM_BPF_GETCLR_STATS, /* supply name as char[NG_HOOKSIZ] */
};
#endif /* _NETGRAPH_NG_BPF_H_ */