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
parent
bffb72754c
commit
3b2bd0f641
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
13
lib/Makefile
13
lib/Makefile
|
@ -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 \
|
||||
|
|
23
lib/ff_api.h
23
lib/ff_api.h
|
@ -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
|
||||
}
|
||||
|
|
|
@ -43,3 +43,4 @@ ff_route_ctl
|
|||
ff_rtioctl
|
||||
ff_gettimeofday
|
||||
ff_fdisused
|
||||
ff_ngctl
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||
}
|
||||
|
|
@ -729,5 +729,10 @@ flush:
|
|||
free(rtm, M_TEMP);
|
||||
}
|
||||
|
||||
if (error != 0) {
|
||||
ff_os_errno(error);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
|
@ -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
|
@ -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_ */
|
||||
|
|
@ -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_ */
|
|
@ -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_ */
|
|
@ -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_ */
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* ng_bridge.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 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$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_BRIDGE_H_
|
||||
#define _NETGRAPH_NG_BRIDGE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_BRIDGE_NODE_TYPE "bridge"
|
||||
#define NGM_BRIDGE_COOKIE 967239368
|
||||
|
||||
/* Hook names */
|
||||
#define NG_BRIDGE_HOOK_LINK_PREFIX "link" /* append decimal integer */
|
||||
#define NG_BRIDGE_HOOK_LINK_FMT "link%d" /* for use with printf(3) */
|
||||
|
||||
/* Maximum number of supported links */
|
||||
#define NG_BRIDGE_MAX_LINKS 32
|
||||
|
||||
/* Node configuration structure */
|
||||
struct ng_bridge_config {
|
||||
u_char ipfw[NG_BRIDGE_MAX_LINKS]; /* enable ipfw */
|
||||
u_char debugLevel; /* debug level */
|
||||
u_int32_t loopTimeout; /* link loopback mute time */
|
||||
u_int32_t maxStaleness; /* max host age before nuking */
|
||||
u_int32_t minStableAge; /* min time for a stable host */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_BRIDGE_CONFIG_TYPE_INFO(ainfo) { \
|
||||
{ "ipfw", (ainfo) }, \
|
||||
{ "debugLevel", &ng_parse_uint8_type }, \
|
||||
{ "loopTimeout", &ng_parse_uint32_type }, \
|
||||
{ "maxStaleness", &ng_parse_uint32_type }, \
|
||||
{ "minStableAge", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics structure (one for each link) */
|
||||
struct ng_bridge_link_stats {
|
||||
u_int64_t recvOctets; /* total octets rec'd on link */
|
||||
u_int64_t recvPackets; /* total pkts rec'd on link */
|
||||
u_int64_t recvMulticasts; /* multicast pkts rec'd on link */
|
||||
u_int64_t recvBroadcasts; /* broadcast pkts rec'd on link */
|
||||
u_int64_t recvUnknown; /* pkts rec'd with unknown dest addr */
|
||||
u_int64_t recvRunts; /* pkts rec'd less than 14 bytes */
|
||||
u_int64_t recvInvalid; /* pkts rec'd with bogus source addr */
|
||||
u_int64_t xmitOctets; /* total octets xmit'd on link */
|
||||
u_int64_t xmitPackets; /* total pkts xmit'd on link */
|
||||
u_int64_t xmitMulticasts; /* multicast pkts xmit'd on link */
|
||||
u_int64_t xmitBroadcasts; /* broadcast pkts xmit'd on link */
|
||||
u_int64_t loopDrops; /* pkts dropped due to loopback */
|
||||
u_int64_t loopDetects; /* number of loop detections */
|
||||
u_int64_t memoryFailures; /* times couldn't get mem or mbuf */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_BRIDGE_STATS_TYPE_INFO { \
|
||||
{ "recvOctets", &ng_parse_uint64_type }, \
|
||||
{ "recvPackets", &ng_parse_uint64_type }, \
|
||||
{ "recvMulticast", &ng_parse_uint64_type }, \
|
||||
{ "recvBroadcast", &ng_parse_uint64_type }, \
|
||||
{ "recvUnknown", &ng_parse_uint64_type }, \
|
||||
{ "recvRunts", &ng_parse_uint64_type }, \
|
||||
{ "recvInvalid", &ng_parse_uint64_type }, \
|
||||
{ "xmitOctets", &ng_parse_uint64_type }, \
|
||||
{ "xmitPackets", &ng_parse_uint64_type }, \
|
||||
{ "xmitMulticasts", &ng_parse_uint64_type }, \
|
||||
{ "xmitBroadcasts", &ng_parse_uint64_type }, \
|
||||
{ "loopDrops", &ng_parse_uint64_type }, \
|
||||
{ "loopDetects", &ng_parse_uint64_type }, \
|
||||
{ "memoryFailures", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure describing a single host */
|
||||
struct ng_bridge_host {
|
||||
u_char addr[6]; /* ethernet address */
|
||||
u_int16_t linkNum; /* link where addr can be found */
|
||||
u_int16_t age; /* seconds ago entry was created */
|
||||
u_int16_t staleness; /* seconds ago host last heard from */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_BRIDGE_HOST_TYPE_INFO(entype) { \
|
||||
{ "addr", (entype) }, \
|
||||
{ "linkNum", &ng_parse_uint16_type }, \
|
||||
{ "age", &ng_parse_uint16_type }, \
|
||||
{ "staleness", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure returned by NGM_BRIDGE_GET_TABLE */
|
||||
struct ng_bridge_host_ary {
|
||||
u_int32_t numHosts;
|
||||
struct ng_bridge_host hosts[];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_BRIDGE_HOST_ARY_TYPE_INFO(harytype) { \
|
||||
{ "numHosts", &ng_parse_uint32_type }, \
|
||||
{ "hosts", (harytype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph control messages */
|
||||
enum {
|
||||
NGM_BRIDGE_SET_CONFIG = 1, /* set node configuration */
|
||||
NGM_BRIDGE_GET_CONFIG, /* get node configuration */
|
||||
NGM_BRIDGE_RESET, /* reset (forget) all information */
|
||||
NGM_BRIDGE_GET_STATS, /* get link stats */
|
||||
NGM_BRIDGE_CLR_STATS, /* clear link stats */
|
||||
NGM_BRIDGE_GETCLR_STATS, /* atomically get & clear link stats */
|
||||
NGM_BRIDGE_GET_TABLE, /* get link table */
|
||||
NGM_BRIDGE_SET_PERSISTENT, /* set persistent mode */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_BRIDGE_H_ */
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/*-
|
||||
* Copyright (c) 2005 Nuno Antunes <nuno.antunes@gmail.com>
|
||||
* Copyright (c) 2007 Alexander Motin <mav@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 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 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_CAR_H_
|
||||
#define _NETGRAPH_NG_CAR_H_
|
||||
|
||||
#define NG_CAR_NODE_TYPE "car"
|
||||
#define NGM_CAR_COOKIE 1173648034
|
||||
|
||||
/* Hook names */
|
||||
#define NG_CAR_HOOK_UPPER "upper"
|
||||
#define NG_CAR_HOOK_LOWER "lower"
|
||||
|
||||
/* Per hook statistics counters */
|
||||
struct ng_car_hookstats {
|
||||
u_int64_t passed_pkts; /* Counter for passed packets */
|
||||
u_int64_t droped_pkts; /* Counter for droped packets */
|
||||
u_int64_t green_pkts; /* Counter for green packets */
|
||||
u_int64_t yellow_pkts; /* Counter for yellow packets */
|
||||
u_int64_t red_pkts; /* Counter for red packets */
|
||||
u_int64_t errors; /* Counter for operation errors */
|
||||
};
|
||||
#define NG_CAR_HOOKSTATS { \
|
||||
{ "passed", &ng_parse_uint64_type }, \
|
||||
{ "droped", &ng_parse_uint64_type }, \
|
||||
{ "green", &ng_parse_uint64_type }, \
|
||||
{ "yellow", &ng_parse_uint64_type }, \
|
||||
{ "red", &ng_parse_uint64_type }, \
|
||||
{ "errors", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Bulk statistics */
|
||||
struct ng_car_bulkstats {
|
||||
struct ng_car_hookstats upstream;
|
||||
struct ng_car_hookstats downstream;
|
||||
};
|
||||
#define NG_CAR_BULKSTATS(hstatstype) { \
|
||||
{ "upstream", (hstatstype) }, \
|
||||
{ "downstream", (hstatstype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Per hook configuration */
|
||||
struct ng_car_hookconf {
|
||||
u_int64_t cbs; /* Committed burst size (bytes) */
|
||||
u_int64_t ebs; /* Exceeded/Peak burst size (bytes) */
|
||||
u_int64_t cir; /* Committed information rate (bits/s) */
|
||||
u_int64_t pir; /* Peak information rate (bits/s) */
|
||||
u_int8_t green_action; /* Action for green packets */
|
||||
u_int8_t yellow_action; /* Action for yellow packets */
|
||||
u_int8_t red_action; /* Action for red packets */
|
||||
u_int8_t mode; /* single/double rate, ... */
|
||||
u_int8_t opt; /* color-aware or color-blind */
|
||||
};
|
||||
/* Keep this definition in sync with the above structure */
|
||||
#define NG_CAR_HOOKCONF { \
|
||||
{ "cbs", &ng_parse_uint64_type }, \
|
||||
{ "ebs", &ng_parse_uint64_type }, \
|
||||
{ "cir", &ng_parse_uint64_type }, \
|
||||
{ "pir", &ng_parse_uint64_type }, \
|
||||
{ "greenAction", &ng_parse_uint8_type }, \
|
||||
{ "yellowAction", &ng_parse_uint8_type }, \
|
||||
{ "redAction", &ng_parse_uint8_type }, \
|
||||
{ "mode", &ng_parse_uint8_type }, \
|
||||
{ "opt", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#define NG_CAR_CBS_MIN 8192
|
||||
#define NG_CAR_EBS_MIN 8192
|
||||
#define NG_CAR_CIR_DFLT 10240
|
||||
|
||||
/* possible actions (...Action) */
|
||||
enum {
|
||||
NG_CAR_ACTION_FORWARD = 1,
|
||||
NG_CAR_ACTION_DROP,
|
||||
NG_CAR_ACTION_MARK,
|
||||
NG_CAR_ACTION_SET_TOS
|
||||
};
|
||||
|
||||
/* operation modes (mode) */
|
||||
enum {
|
||||
NG_CAR_SINGLE_RATE = 0,
|
||||
NG_CAR_DOUBLE_RATE,
|
||||
NG_CAR_RED,
|
||||
NG_CAR_SHAPE
|
||||
};
|
||||
|
||||
/* mode options (opt) */
|
||||
#define NG_CAR_COLOR_AWARE 1
|
||||
#define NG_CAR_COUNT_PACKETS 2
|
||||
|
||||
/* Bulk config */
|
||||
struct ng_car_bulkconf {
|
||||
struct ng_car_hookconf upstream;
|
||||
struct ng_car_hookconf downstream;
|
||||
};
|
||||
#define NG_CAR_BULKCONF(hconftype) { \
|
||||
{ "upstream", (hconftype) }, \
|
||||
{ "downstream", (hconftype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Commands */
|
||||
enum {
|
||||
NGM_CAR_GET_STATS = 1, /* Get statistics */
|
||||
NGM_CAR_CLR_STATS, /* Clear statistics */
|
||||
NGM_CAR_GETCLR_STATS, /* Get and clear statistics */
|
||||
NGM_CAR_GET_CONF, /* Get bulk configuration */
|
||||
NGM_CAR_SET_CONF, /* Set bulk configuration */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_CAR_H_ */
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* ng_cisco.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_cisco.h,v 1.6 1999/01/25 01:21:48 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_CISCO_H_
|
||||
#define _NETGRAPH_NG_CISCO_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_CISCO_NODE_TYPE "cisco"
|
||||
#define NGM_CISCO_COOKIE 860707227
|
||||
|
||||
/* Hook names */
|
||||
#define NG_CISCO_HOOK_DOWNSTREAM "downstream"
|
||||
#define NG_CISCO_HOOK_INET "inet"
|
||||
#define NG_CISCO_HOOK_INET6 "inet6"
|
||||
#define NG_CISCO_HOOK_APPLETALK "atalk"
|
||||
#define NG_CISCO_HOOK_IPX "ipx"
|
||||
#define NG_CISCO_HOOK_DEBUG "debug"
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_CISCO_SET_IPADDR = 1, /* requires a struct ng_cisco_ipaddr */
|
||||
NGM_CISCO_GET_IPADDR, /* returns a struct ng_cisco_ipaddr */
|
||||
NGM_CISCO_GET_STATUS, /* returns a struct ng_cisco_stat */
|
||||
};
|
||||
|
||||
struct ng_cisco_ipaddr {
|
||||
struct in_addr ipaddr; /* IP address */
|
||||
struct in_addr netmask; /* Netmask */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_CISCO_IPADDR_TYPE_INFO { \
|
||||
{ "ipaddr", &ng_parse_ipaddr_type }, \
|
||||
{ "netmask", &ng_parse_ipaddr_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
struct ng_cisco_stats {
|
||||
uint32_t seqRetries; /* # unack'd retries */
|
||||
uint32_t keepAlivePeriod; /* in seconds */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_CISCO_STATS_TYPE_INFO { \
|
||||
{ "seqRetries", &ng_parse_uint32_type }, \
|
||||
{ "keepAlivePeriod", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#endif /* _NETGRAPH_NG_CISCO_H_ */
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*-
|
||||
* Copyright (c) 2006 Alexander Motin <mav@alkar.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 unmodified, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_DEFLATE_H_
|
||||
#define _NETGRAPH_NG_DEFLATE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_DEFLATE_NODE_TYPE "deflate"
|
||||
#define NGM_DEFLATE_COOKIE 1166642656
|
||||
|
||||
/* Hook names */
|
||||
#define NG_DEFLATE_HOOK_COMP "comp" /* compression hook */
|
||||
#define NG_DEFLATE_HOOK_DECOMP "decomp" /* decompression hook */
|
||||
|
||||
/* Config struct */
|
||||
struct ng_deflate_config {
|
||||
u_char enable; /* node enabled */
|
||||
u_char windowBits; /* log2(Window size) */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_DEFLATE_CONFIG_INFO { \
|
||||
{ "enable", &ng_parse_uint8_type }, \
|
||||
{ "windowBits", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics structure for one direction. */
|
||||
struct ng_deflate_stats {
|
||||
uint64_t FramesPlain;
|
||||
uint64_t FramesComp;
|
||||
uint64_t FramesUncomp;
|
||||
uint64_t InOctets;
|
||||
uint64_t OutOctets;
|
||||
uint64_t Errors;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_DEFLATE_STATS_INFO { \
|
||||
{ "FramesPlain",&ng_parse_uint64_type }, \
|
||||
{ "FramesComp", &ng_parse_uint64_type }, \
|
||||
{ "FramesUncomp", &ng_parse_uint64_type }, \
|
||||
{ "InOctets", &ng_parse_uint64_type }, \
|
||||
{ "OutOctets", &ng_parse_uint64_type }, \
|
||||
{ "Errors", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_DEFLATE_CONFIG = 1,
|
||||
NGM_DEFLATE_RESETREQ, /* sent either way! */
|
||||
NGM_DEFLATE_GET_STATS,
|
||||
NGM_DEFLATE_CLR_STATS,
|
||||
NGM_DEFLATE_GETCLR_STATS,
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_DEFLATE_H_ */
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*-
|
||||
* Copyright (c) 2002 Mark Santcroos <marks@ripe.net>
|
||||
*
|
||||
* 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_NG_DEVICE_H_
|
||||
#define _NETGRAPH_NG_DEVICE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_DEVICE_NODE_TYPE "device"
|
||||
#define NGM_DEVICE_COOKIE 1091129178
|
||||
#define NG_DEVICE_DEVNAME "ngd"
|
||||
|
||||
/* Netgraph control messages */
|
||||
enum {
|
||||
NGM_DEVICE_GET_DEVNAME,
|
||||
};
|
||||
|
||||
#if 0
|
||||
/* passing ioctl params */
|
||||
struct ngd_param_s {
|
||||
void * p;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* _NETGRAPH_NG_DEVICE_H_ */
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* ng_echo.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_echo.h,v 1.3 1999/01/20 00:22:12 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_ECHO_H_
|
||||
#define _NETGRAPH_NG_ECHO_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_ECHO_NODE_TYPE "echo"
|
||||
#define NGM_ECHO_COOKIE 884298942
|
||||
|
||||
#endif /* _NETGRAPH_NG_ECHO_H_ */
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* ng_eiface.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999-2001, Vitaly V Belekhov
|
||||
* 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 unmodified, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_EIFACE_H_
|
||||
#define _NETGRAPH_NG_EIFACE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_EIFACE_NODE_TYPE "eiface"
|
||||
#define NGM_EIFACE_COOKIE 948105892
|
||||
|
||||
/* Interface base name */
|
||||
#define NG_EIFACE_EIFACE_NAME "ngeth"
|
||||
|
||||
/* My hook names */
|
||||
#define NG_EIFACE_HOOK_ETHER "ether"
|
||||
|
||||
/* MTU bounds */
|
||||
#define NG_EIFACE_MTU_MIN 72
|
||||
#define NG_EIFACE_MTU_MAX ETHER_MAX_LEN_JUMBO
|
||||
#define NG_EIFACE_MTU_DEFAULT 1500
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_EIFACE_GET_IFNAME = 1, /* get the interface name */
|
||||
NGM_EIFACE_GET_IFADDRS, /* returns list of addresses */
|
||||
NGM_EIFACE_SET, /* set ethernet address */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_EIFACE_H_ */
|
|
@ -0,0 +1,90 @@
|
|||
/*-
|
||||
* ng_etf.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, FreeBSD Incorporated
|
||||
* 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 unmodified, 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.
|
||||
*
|
||||
* Author: Julian Elischer <julian@freebsd.org>
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_ETF_H_
|
||||
#define _NETGRAPH_NG_ETF_H_
|
||||
|
||||
/* Node type name. This should be unique among all netgraph node types */
|
||||
#define NG_ETF_NODE_TYPE "etf"
|
||||
|
||||
/* Node type cookie. Should also be unique. This value MUST change whenever
|
||||
an incompatible change is made to this header file, to insure consistency.
|
||||
The de facto method for generating cookies is to take the output of the
|
||||
date command: date -u +'%s' */
|
||||
#define NGM_ETF_COOKIE 983084516
|
||||
|
||||
/* Hook names */
|
||||
#define NG_ETF_HOOK_DOWNSTREAM "downstream"
|
||||
#define NG_ETF_HOOK_NOMATCH "nomatch"
|
||||
|
||||
/* Netgraph commands understood by this node type */
|
||||
enum {
|
||||
NGM_ETF_SET_FLAG = 1,
|
||||
NGM_ETF_GET_STATUS,
|
||||
NGM_ETF_SET_FILTER,
|
||||
|
||||
};
|
||||
|
||||
/* This structure is returned by the NGM_ETF_GET_STATUS command */
|
||||
struct ng_etfstat {
|
||||
u_int32_t packets_in; /* packets in from downstream */
|
||||
u_int32_t packets_out; /* packets out towards downstream */
|
||||
};
|
||||
|
||||
/*
|
||||
* This needs to be kept in sync with the above structure definition
|
||||
*/
|
||||
#define NG_ETF_STATS_TYPE_INFO { \
|
||||
{ "packets_in", &ng_parse_uint32_type }, \
|
||||
{ "packets_out", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* This structure is returned by the NGM_ETF_GET_STATUS command */
|
||||
struct ng_etffilter {
|
||||
char matchhook[NG_HOOKSIZ]; /* hook name */
|
||||
u_int16_t ethertype; /* this ethertype to this hook */
|
||||
};
|
||||
|
||||
/*
|
||||
* This needs to be kept in sync with the above structure definition
|
||||
*/
|
||||
#define NG_ETF_FILTER_TYPE_INFO { \
|
||||
{ "matchhook", &ng_parse_hookbuf_type }, \
|
||||
{ "ethertype", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#endif /* _NETGRAPH_NG_ETF_H_ */
|
|
@ -0,0 +1,73 @@
|
|||
|
||||
/*
|
||||
* ng_ether.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_ether.h,v 1.1 1999/02/02 03:17:22 julian Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_ETHER_H_
|
||||
#define _NETGRAPH_NG_ETHER_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_ETHER_NODE_TYPE "ether"
|
||||
#define NGM_ETHER_COOKIE 917786906
|
||||
|
||||
/* Hook names */
|
||||
#define NG_ETHER_HOOK_LOWER "lower" /* connection to raw device */
|
||||
#define NG_ETHER_HOOK_UPPER "upper" /* connection to upper layers */
|
||||
#define NG_ETHER_HOOK_DIVERT "divert" /* alias for lower */
|
||||
#define NG_ETHER_HOOK_ORPHAN "orphans" /* like lower, unknowns only */
|
||||
|
||||
/* Netgraph control messages */
|
||||
enum {
|
||||
NGM_ETHER_GET_IFNAME = 1, /* get the interface name */
|
||||
NGM_ETHER_GET_IFINDEX, /* get the interface global index # */
|
||||
NGM_ETHER_GET_ENADDR, /* get Ethernet address */
|
||||
NGM_ETHER_SET_ENADDR, /* set Ethernet address */
|
||||
NGM_ETHER_GET_PROMISC, /* get node's promiscuous mode bit */
|
||||
NGM_ETHER_SET_PROMISC, /* enable/disable promiscuous mode */
|
||||
NGM_ETHER_GET_AUTOSRC, /* get source address override */
|
||||
NGM_ETHER_SET_AUTOSRC, /* enable/disable src addr override */
|
||||
NGM_ETHER_ADD_MULTI, /* add multicast membership */
|
||||
NGM_ETHER_DEL_MULTI, /* delete multicast membership */
|
||||
NGM_ETHER_DETACH, /* our way to be shut down */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_ETHER_H_ */
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* ng_ether_echo.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_echo.h,v 1.3 1999/01/20 00:22:12 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_ETHER_ECHO_H_
|
||||
#define _NETGRAPH_NG_ETHER_ECHO_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_ETHER_ECHO_NODE_TYPE "ether_echo"
|
||||
#define NGM_ETHER_ECHO_COOKIE 1230155201
|
||||
|
||||
#endif /* _NETGRAPH_NG_ETHER_ECHO_H_ */
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* ng_frame_relay.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_frame_relay.h,v 1.7 1999/01/20 00:22:13 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_FRAME_RELAY_H_
|
||||
#define _NETGRAPH_NG_FRAME_RELAY_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_FRAMERELAY_NODE_TYPE "frame_relay"
|
||||
#define NGM_FRAMERELAY_COOKIE 872148478
|
||||
|
||||
/* Hook names */
|
||||
#define NG_FRAMERELAY_HOOK_DEBUG "debug"
|
||||
#define NG_FRAMERELAY_HOOK_DOWNSTREAM "downstream"
|
||||
#define NG_FRAMERELAY_HOOK_DLCI "dlci" /* really just the prefix */
|
||||
|
||||
#endif /* _NETGRAPH_NG_FRAME_RELAY_H_ */
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* ng_gif.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright 2001 The Aerospace Corporation. 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.
|
||||
* 3. The name of The Aerospace Corporation may not be used to endorse or
|
||||
* promote products derived from this software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``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 AEROSPACE CORPORATION 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.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_GIF_H_
|
||||
#define _NETGRAPH_NG_GIF_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_GIF_NODE_TYPE "gif"
|
||||
#define NGM_GIF_COOKIE 994115727
|
||||
|
||||
/* Hook names */
|
||||
#define NG_GIF_HOOK_LOWER "lower" /* connection to raw device */
|
||||
#define NG_GIF_HOOK_DIVERT "divert" /* alias for lower */
|
||||
#define NG_GIF_HOOK_ORPHAN "orphans" /* like lower, unknowns only */
|
||||
|
||||
/* Netgraph control messages */
|
||||
enum {
|
||||
NGM_GIF_GET_IFNAME = 1, /* get the interface name */
|
||||
NGM_GIF_GET_IFINDEX /* get the interface global index # */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_GIF_H_ */
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* ng_gif_demux.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright 2001 The Aerospace Corporation. 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.
|
||||
* 3. The name of The Aerospace Corporation may not be used to endorse or
|
||||
* promote products derived from this software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``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 AEROSPACE CORPORATION 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_NG_GIF_DEMUX_H_
|
||||
#define _NETGRAPH_NG_GIF_DEMUX_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_GIF_DEMUX_NODE_TYPE "gif_demux"
|
||||
#define NGM_GIF_DEMUX_COOKIE 995567329
|
||||
|
||||
/* Hook names */
|
||||
#define NG_GIF_DEMUX_HOOK_GIF "gif"
|
||||
#define NG_GIF_DEMUX_HOOK_INET "inet"
|
||||
#define NG_GIF_DEMUX_HOOK_INET6 "inet6"
|
||||
#define NG_GIF_DEMUX_HOOK_ATALK "atalk"
|
||||
#define NG_GIF_DEMUX_HOOK_IPX "ipx"
|
||||
#define NG_GIF_DEMUX_HOOK_ATM "atm"
|
||||
#define NG_GIF_DEMUX_HOOK_NATM "natm"
|
||||
|
||||
#endif /* _NETGRAPH_NG_GIF_DEMUX_H_ */
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* ng_hole.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_hole.h,v 1.3 1999/01/20 00:22:13 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_HOLE_H_
|
||||
#define _NETGRAPH_NG_HOLE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_HOLE_NODE_TYPE "hole"
|
||||
#define NGM_HOLE_COOKIE 915433206
|
||||
|
||||
/* Statistics structure for one hook. */
|
||||
struct ng_hole_hookstat {
|
||||
uint64_t frames;
|
||||
uint64_t octets;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_HOLE_HOOKSTAT_TYPE_INFO { \
|
||||
{ "frames", &ng_parse_uint64_type }, \
|
||||
{ "octets", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands. */
|
||||
enum {
|
||||
NGM_HOLE_GET_STATS = 1,
|
||||
NGM_HOLE_CLR_STATS,
|
||||
NGM_HOLE_GETCLR_STATS,
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_HOLE_H_ */
|
|
@ -0,0 +1,41 @@
|
|||
/*-
|
||||
* Copyright (c) 2004 Ruslan Ermilov
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_HUB_H_
|
||||
#define _NETGRAPH_NG_HUB_H_
|
||||
|
||||
/* Node type name and magic cookie. */
|
||||
#define NG_HUB_NODE_TYPE "hub"
|
||||
#define NGM_HUB_COOKIE 1082189597
|
||||
|
||||
/* Netgraph control messages */
|
||||
enum {
|
||||
NGM_HUB_SET_PERSISTENT = 1, /* set persistent mode */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_HUB_H_ */
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* ng_iface.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_iface.h,v 1.5 1999/01/20 00:22:13 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_IFACE_H_
|
||||
#define _NETGRAPH_NG_IFACE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_IFACE_NODE_TYPE "iface"
|
||||
#define NGM_IFACE_COOKIE 1108312559
|
||||
|
||||
/* Interface base name */
|
||||
#define NG_IFACE_IFACE_NAME "ng"
|
||||
|
||||
/* My hook names */
|
||||
#define NG_IFACE_HOOK_INET "inet"
|
||||
#define NG_IFACE_HOOK_INET6 "inet6"
|
||||
#define NG_IFACE_HOOK_ATM "atm"
|
||||
#define NG_IFACE_HOOK_NATM "natm"
|
||||
|
||||
/* MTU bounds */
|
||||
#define NG_IFACE_MTU_MIN 72
|
||||
#define NG_IFACE_MTU_MAX 65535
|
||||
#define NG_IFACE_MTU_DEFAULT 1500
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_IFACE_GET_IFNAME = 1,
|
||||
NGM_IFACE_POINT2POINT,
|
||||
NGM_IFACE_BROADCAST,
|
||||
NGM_IFACE_GET_IFINDEX,
|
||||
};
|
||||
|
||||
#define MTAG_NGIF NGM_IFACE_COOKIE
|
||||
#define MTAG_NGIF_CALLED 0 | MTAG_PERSISTENT
|
||||
|
||||
#endif /* _NETGRAPH_NG_IFACE_H_ */
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* ng_ip_input.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright 2001 The Aerospace Corporation. 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.
|
||||
* 3. The name of The Aerospace Corporation may not be used to endorse or
|
||||
* promote products derived from this software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "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 AEROSPACE CORPORATION 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.
|
||||
*
|
||||
* 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: Brooks Davis <brooks@FreeBSD.org>
|
||||
* Derived from: ng_hole.h
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_IP_INPUT_H_
|
||||
#define _NETGRAPH_NG_IP_INPUT_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_IP_INPUT_NODE_TYPE "ip_input"
|
||||
#define NGM_IP_INPUT_COOKIE 994874907
|
||||
|
||||
#endif /* _NETGRAPH_NG_IP_INPUT_H_ */
|
|
@ -0,0 +1,33 @@
|
|||
/*-
|
||||
* Copyright 2005, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NG_IPFW_H
|
||||
#define _NG_IPFW_H
|
||||
#define NG_IPFW_NODE_TYPE "ipfw"
|
||||
#define NGM_IPFW_COOKIE 1105988990
|
||||
#endif /* _NG_IPFW_H */
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* ng_ksocket.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_ksocket.h,v 1.1 1999/11/16 20:04:40 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_KSOCKET_H_
|
||||
#define _NETGRAPH_NG_KSOCKET_H_
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_KSOCKET_NODE_TYPE "ksocket"
|
||||
#define NGM_KSOCKET_COOKIE 942710669
|
||||
|
||||
/* For NGM_KSOCKET_SETOPT and NGM_KSOCKET_GETOPT control messages */
|
||||
struct ng_ksocket_sockopt {
|
||||
int32_t level; /* second arg of [gs]etsockopt() */
|
||||
int32_t name; /* third arg of [gs]etsockopt() */
|
||||
u_char value[]; /* fourth arg of [gs]etsockopt() */
|
||||
};
|
||||
|
||||
/* Max length socket option we can return via NGM_KSOCKET_GETOPT
|
||||
XXX This should not be necessary, we should dynamically size
|
||||
XXX the response. Until then.. */
|
||||
#define NG_KSOCKET_MAX_OPTLEN 1024
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_KSOCKET_SOCKOPT_INFO(svtype) { \
|
||||
{ "level", &ng_parse_int32_type }, \
|
||||
{ "name", &ng_parse_int32_type }, \
|
||||
{ "value", (svtype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* For NGM_KSOCKET_ACCEPT control message responses */
|
||||
struct ng_ksocket_accept {
|
||||
u_int32_t nodeid; /* node ID of connected ksocket */
|
||||
struct sockaddr addr; /* peer's address (variable length) */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NGM_KSOCKET_ACCEPT_INFO { \
|
||||
{ "nodeid", &ng_parse_hint32_type }, \
|
||||
{ "addr", &ng_ksocket_generic_sockaddr_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_KSOCKET_BIND = 1,
|
||||
NGM_KSOCKET_LISTEN,
|
||||
NGM_KSOCKET_ACCEPT,
|
||||
NGM_KSOCKET_CONNECT,
|
||||
NGM_KSOCKET_GETNAME,
|
||||
NGM_KSOCKET_GETPEERNAME,
|
||||
NGM_KSOCKET_SETOPT,
|
||||
NGM_KSOCKET_GETOPT,
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
/* Structure for sockaddr tag */
|
||||
struct sa_tag {
|
||||
struct m_tag tag;
|
||||
ng_ID_t id;
|
||||
struct sockaddr sa;
|
||||
};
|
||||
|
||||
/* Tag information ID's */
|
||||
#define NG_KSOCKET_TAG_SOCKADDR 1 /* data is struct sockaddr */
|
||||
|
||||
#endif /* _KERNEL */
|
||||
#endif /* _NETGRAPH_NG_KSOCKET_H_ */
|
|
@ -0,0 +1,196 @@
|
|||
/*-
|
||||
* Copyright (c) 2001-2002 Packet Design, LLC.
|
||||
* 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
|
||||
* Packet Design; provided, however, that:
|
||||
*
|
||||
* (i) Any and all reproductions of the source or object code
|
||||
* must include the copyright notice above and the following
|
||||
* disclaimer of warranties; and
|
||||
* (ii) No rights are granted, in any manner or form, to use
|
||||
* Packet Design trademarks, including the mark "PACKET DESIGN"
|
||||
* on advertising, endorsements, or otherwise except as such
|
||||
* appears in the above copyright notice or in the software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
|
||||
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN 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. PACKET DESIGN 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 PACKET DESIGN 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 PACKET DESIGN IS ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Author: Archie Cobbs <archie@freebsd.org>
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_L2TP_H_
|
||||
#define _NETGRAPH_NG_L2TP_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_L2TP_NODE_TYPE "l2tp"
|
||||
#define NGM_L2TP_COOKIE 1091515793
|
||||
|
||||
/* Hook names */
|
||||
#define NG_L2TP_HOOK_CTRL "ctrl" /* control channel hook */
|
||||
#define NG_L2TP_HOOK_LOWER "lower" /* hook to lower layers */
|
||||
|
||||
/* Session hooks: prefix plus hex session ID, e.g., "session_3e14" */
|
||||
#define NG_L2TP_HOOK_SESSION_P "session_" /* session data hook (prefix) */
|
||||
#define NG_L2TP_HOOK_SESSION_F "session_%04x" /* session data hook (format) */
|
||||
|
||||
/* Set initial sequence numbers to not yet enabled node. */
|
||||
struct ng_l2tp_seq_config {
|
||||
u_int16_t ns; /* sequence number to send next */
|
||||
u_int16_t nr; /* sequence number to be recved next */
|
||||
u_int16_t rack; /* last 'nr' received */
|
||||
u_int16_t xack; /* last 'nr' sent */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_L2TP_SEQ_CONFIG_TYPE_INFO { \
|
||||
{ "ns", &ng_parse_uint16_type }, \
|
||||
{ "nr", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Configuration for a node */
|
||||
struct ng_l2tp_config {
|
||||
u_char enabled; /* enables traffic flow */
|
||||
u_char match_id; /* tunnel id must match 'tunnel_id' */
|
||||
u_int16_t tunnel_id; /* local tunnel id */
|
||||
u_int16_t peer_id; /* peer's tunnel id */
|
||||
u_int16_t peer_win; /* peer's max recv window size */
|
||||
u_int16_t rexmit_max; /* max retransmits before failure */
|
||||
u_int16_t rexmit_max_to; /* max delay between retransmits */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_L2TP_CONFIG_TYPE_INFO { \
|
||||
{ "enabled", &ng_parse_uint8_type }, \
|
||||
{ "match_id", &ng_parse_uint8_type }, \
|
||||
{ "tunnel_id", &ng_parse_hint16_type }, \
|
||||
{ "peer_id", &ng_parse_hint16_type }, \
|
||||
{ "peer_win", &ng_parse_uint16_type }, \
|
||||
{ "rexmit_max", &ng_parse_uint16_type }, \
|
||||
{ "rexmit_max_to", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Configuration for a session hook */
|
||||
struct ng_l2tp_sess_config {
|
||||
u_int16_t session_id; /* local session id */
|
||||
u_int16_t peer_id; /* peer's session id */
|
||||
u_char control_dseq; /* whether we control data sequencing */
|
||||
u_char enable_dseq; /* whether to enable data sequencing */
|
||||
u_char include_length; /* whether to include length field */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_L2TP_SESS_CONFIG_TYPE_INFO { \
|
||||
{ "session_id", &ng_parse_hint16_type }, \
|
||||
{ "peer_id", &ng_parse_hint16_type }, \
|
||||
{ "control_dseq", &ng_parse_uint8_type }, \
|
||||
{ "enable_dseq", &ng_parse_uint8_type }, \
|
||||
{ "include_length", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics struct */
|
||||
struct ng_l2tp_stats {
|
||||
u_int32_t xmitPackets; /* number of packets xmit */
|
||||
u_int32_t xmitOctets; /* number of octets xmit */
|
||||
u_int32_t xmitZLBs; /* ack-only packets transmitted */
|
||||
u_int32_t xmitDrops; /* xmits dropped due to full window */
|
||||
u_int32_t xmitTooBig; /* ctrl pkts dropped because too big */
|
||||
u_int32_t xmitInvalid; /* ctrl packets with no session ID */
|
||||
u_int32_t xmitDataTooBig; /* data pkts dropped because too big */
|
||||
u_int32_t xmitRetransmits; /* retransmitted packets */
|
||||
u_int32_t recvPackets; /* number of packets rec'd */
|
||||
u_int32_t recvOctets; /* number of octets rec'd */
|
||||
u_int32_t recvRunts; /* too short packets rec'd */
|
||||
u_int32_t recvInvalid; /* invalid packets rec'd */
|
||||
u_int32_t recvWrongTunnel; /* packets rec'd with wrong tunnel id */
|
||||
u_int32_t recvUnknownSID; /* pkts rec'd with unknown session id */
|
||||
u_int32_t recvBadAcks; /* ctrl pkts rec'd with invalid 'nr' */
|
||||
u_int32_t recvOutOfOrder; /* out of order ctrl pkts rec'd */
|
||||
u_int32_t recvDuplicates; /* duplicate ctrl pkts rec'd */
|
||||
u_int32_t recvDataDrops; /* dup/out of order data pkts rec'd */
|
||||
u_int32_t recvZLBs; /* ack-only packets rec'd */
|
||||
u_int32_t memoryFailures; /* times we couldn't allocate memory */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_L2TP_STATS_TYPE_INFO { \
|
||||
{ "xmitPackets", &ng_parse_uint32_type }, \
|
||||
{ "xmitOctets", &ng_parse_uint32_type }, \
|
||||
{ "xmitZLBs", &ng_parse_uint32_type }, \
|
||||
{ "xmitDrops", &ng_parse_uint32_type }, \
|
||||
{ "xmitTooBig", &ng_parse_uint32_type }, \
|
||||
{ "xmitInvalid", &ng_parse_uint32_type }, \
|
||||
{ "xmitDataTooBig", &ng_parse_uint32_type }, \
|
||||
{ "xmitRetransmits", &ng_parse_uint32_type }, \
|
||||
{ "recvPackets", &ng_parse_uint32_type }, \
|
||||
{ "recvOctets", &ng_parse_uint32_type }, \
|
||||
{ "recvRunts", &ng_parse_uint32_type }, \
|
||||
{ "recvInvalid", &ng_parse_uint32_type }, \
|
||||
{ "recvWrongTunnel", &ng_parse_uint32_type }, \
|
||||
{ "recvUnknownSID", &ng_parse_uint32_type }, \
|
||||
{ "recvBadAcks", &ng_parse_uint32_type }, \
|
||||
{ "recvOutOfOrder", &ng_parse_uint32_type }, \
|
||||
{ "recvDuplicates", &ng_parse_uint32_type }, \
|
||||
{ "recvDataDrops", &ng_parse_uint32_type }, \
|
||||
{ "recvZLBs", &ng_parse_uint32_type }, \
|
||||
{ "memoryFailures", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Session statistics struct. */
|
||||
struct ng_l2tp_session_stats {
|
||||
u_int64_t xmitPackets; /* number of packets xmit */
|
||||
u_int64_t xmitOctets; /* number of octets xmit */
|
||||
u_int64_t recvPackets; /* number of packets received */
|
||||
u_int64_t recvOctets; /* number of octets received */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_L2TP_SESSION_STATS_TYPE_INFO { \
|
||||
{ "xmitPackets", &ng_parse_uint64_type }, \
|
||||
{ "xmitOctets", &ng_parse_uint64_type }, \
|
||||
{ "recvPackets", &ng_parse_uint64_type }, \
|
||||
{ "recvOctets", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_L2TP_SET_CONFIG = 1, /* supply a struct ng_l2tp_config */
|
||||
NGM_L2TP_GET_CONFIG, /* returns a struct ng_l2tp_config */
|
||||
NGM_L2TP_SET_SESS_CONFIG, /* supply struct ng_l2tp_sess_config */
|
||||
NGM_L2TP_GET_SESS_CONFIG, /* supply a session id (u_int16_t) */
|
||||
NGM_L2TP_GET_STATS, /* returns struct ng_l2tp_stats */
|
||||
NGM_L2TP_CLR_STATS, /* clears stats */
|
||||
NGM_L2TP_GETCLR_STATS, /* returns & clears stats */
|
||||
NGM_L2TP_GET_SESSION_STATS, /* returns session stats */
|
||||
NGM_L2TP_CLR_SESSION_STATS, /* clears session stats */
|
||||
NGM_L2TP_GETCLR_SESSION_STATS, /* returns & clears session stats */
|
||||
NGM_L2TP_ACK_FAILURE, /* sent *from* node after ack timeout */
|
||||
NGM_L2TP_SET_SEQ /* supply a struct ng_l2tp_seq_config */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_L2TP_H_ */
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* ng_lmi.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_lmi.h,v 1.9 1999/01/20 00:22:13 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_LMI_H_
|
||||
#define _NETGRAPH_NG_LMI_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_LMI_NODE_TYPE "lmi"
|
||||
#define NGM_LMI_COOKIE 867184133
|
||||
|
||||
/* My hook names */
|
||||
#define NG_LMI_HOOK_DEBUG "debug"
|
||||
#define NG_LMI_HOOK_ANNEXA "annexA"
|
||||
#define NG_LMI_HOOK_ANNEXD "annexD"
|
||||
#define NG_LMI_HOOK_GROUPOF4 "group4"
|
||||
#define NG_LMI_HOOK_AUTO0 "auto0"
|
||||
#define NG_LMI_HOOK_AUTO1023 "auto1023"
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_LMI_GET_STATUS = 1,
|
||||
};
|
||||
|
||||
#define NGM_LMI_STAT_ARYSIZE (1024/8)
|
||||
|
||||
struct nglmistat {
|
||||
u_char proto[12]; /* Active proto (same as hook name) */
|
||||
u_char hook[12]; /* Active hook */
|
||||
u_char fixed; /* Set to fixed LMI mode */
|
||||
u_char autod; /* Currently auto-detecting */
|
||||
u_char seen[NGM_LMI_STAT_ARYSIZE]; /* DLCIs ever seen */
|
||||
u_char up[NGM_LMI_STAT_ARYSIZE]; /* DLCIs currently up */
|
||||
};
|
||||
|
||||
/* Some default values */
|
||||
#define NG_LMI_KEEPALIVE_RATE 10 /* seconds per keepalive */
|
||||
#define NG_LMI_POLL_RATE 3 /* faster when AUTO polling */
|
||||
#define NG_LMI_SEQ_PER_FULL 5 /* keepalives per full status */
|
||||
#define NG_LMI_LMI_PRIORITY 64 /* priority for LMI data */
|
||||
|
||||
#endif /* _NETGRAPH_NG_LMI_H_ */
|
|
@ -0,0 +1,439 @@
|
|||
/*
|
||||
* ng_message.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_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_MESSAGE_H_
|
||||
#define _NETGRAPH_NG_MESSAGE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* ASCII string size limits */
|
||||
#define NG_TYPESIZ 32 /* max type name len (including null) */
|
||||
#define NG_HOOKSIZ 32 /* max hook name len (including null) */
|
||||
#define NG_NODESIZ 32 /* max node name len (including null) */
|
||||
#define NG_PATHSIZ 512 /* max path len (including null) */
|
||||
#define NG_CMDSTRSIZ 32 /* max command string (including null) */
|
||||
|
||||
#define NG_TEXTRESPONSE 1024 /* allow this length for a text response */
|
||||
|
||||
/* A netgraph message */
|
||||
struct ng_mesg {
|
||||
struct ng_msghdr {
|
||||
u_char version; /* == NGM_VERSION */
|
||||
u_char spare; /* pad to 4 bytes */
|
||||
u_int16_t spare2;
|
||||
u_int32_t arglen; /* length of data */
|
||||
u_int32_t cmd; /* command identifier */
|
||||
u_int32_t flags; /* message status */
|
||||
u_int32_t token; /* match with reply */
|
||||
u_int32_t typecookie; /* node's type cookie */
|
||||
u_char cmdstr[NG_CMDSTRSIZ]; /* cmd string + \0 */
|
||||
} header;
|
||||
char data[]; /* placeholder for actual data */
|
||||
};
|
||||
|
||||
/* This command is guaranteed to not alter data (or'd into the command). */
|
||||
#define NGM_READONLY 0x10000000
|
||||
/* This command is guaranteed to have a reply (or'd into the command). */
|
||||
#define NGM_HASREPLY 0x20000000
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_NG_MESG_INFO(dtype) { \
|
||||
{ "version", &ng_parse_uint8_type }, \
|
||||
{ "spare", &ng_parse_uint8_type }, \
|
||||
{ "spare2", &ng_parse_uint16_type }, \
|
||||
{ "arglen", &ng_parse_uint32_type }, \
|
||||
{ "cmd", &ng_parse_uint32_type }, \
|
||||
{ "flags", &ng_parse_hint32_type }, \
|
||||
{ "token", &ng_parse_uint32_type }, \
|
||||
{ "typecookie", &ng_parse_uint32_type }, \
|
||||
{ "cmdstr", &ng_parse_cmdbuf_type }, \
|
||||
{ "data", (dtype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/*
|
||||
* Netgraph message header compatibility field
|
||||
* Interfaces within the kernel are defined by a different
|
||||
* value (see NG_ABI_VERSION in netgraph.h)
|
||||
*/
|
||||
#define NG_VERSION 8
|
||||
|
||||
/* Flags field flags */
|
||||
#define NGF_ORIG 0x00000000 /* the msg is the original request */
|
||||
#define NGF_RESP 0x00000001 /* the message is a response */
|
||||
|
||||
/* Type of a unique node ID. */
|
||||
#define ng_ID_t uint32_t
|
||||
|
||||
/*
|
||||
* Here we describe the "generic" messages that all nodes inherently
|
||||
* understand. With the exception of NGM_TEXT_STATUS, these are handled
|
||||
* automatically by the base netgraph code.
|
||||
*/
|
||||
|
||||
/* Generic message type cookie */
|
||||
#define NGM_GENERIC_COOKIE 1137070366
|
||||
|
||||
/* Generic messages defined for this type cookie. */
|
||||
enum {
|
||||
NGM_SHUTDOWN = 1, /* Shut down node. */
|
||||
NGM_MKPEER = 2, /* Create and attach a peer node. */
|
||||
NGM_CONNECT = 3, /* Connect two nodes. */
|
||||
NGM_NAME = 4, /* Give a node a name. */
|
||||
NGM_RMHOOK = 5, /* Break a connection between two nodes. */
|
||||
|
||||
/* Get nodeinfo for target. */
|
||||
NGM_NODEINFO = (6|NGM_READONLY|NGM_HASREPLY),
|
||||
/* Get list of hooks on node. */
|
||||
NGM_LISTHOOKS = (7|NGM_READONLY|NGM_HASREPLY),
|
||||
/* List globally named nodes. */
|
||||
NGM_LISTNAMES = (8|NGM_READONLY|NGM_HASREPLY),
|
||||
/* List all nodes. */
|
||||
NGM_LISTNODES = (9|NGM_READONLY|NGM_HASREPLY),
|
||||
/* List installed node types. */
|
||||
NGM_LISTTYPES = (10|NGM_READONLY|NGM_HASREPLY),
|
||||
/* (optional) Get text status. */
|
||||
NGM_TEXT_STATUS = (11|NGM_READONLY|NGM_HASREPLY),
|
||||
/* Convert struct ng_mesg to ASCII. */
|
||||
NGM_BINARY2ASCII= (12|NGM_READONLY|NGM_HASREPLY),
|
||||
/* Convert ASCII to struct ng_mesg. */
|
||||
NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY),
|
||||
/* (optional) Get/set text config. */
|
||||
NGM_TEXT_CONFIG = 14,
|
||||
};
|
||||
|
||||
/*
|
||||
* Flow control and intra node control messages.
|
||||
* These are routed between nodes to allow flow control and to allow
|
||||
* events to be passed around the graph.
|
||||
* There will be some form of default handling for these but I
|
||||
* do not yet know what it is..
|
||||
*/
|
||||
|
||||
/* Generic message type cookie */
|
||||
#define NGM_FLOW_COOKIE 851672669 /* temp for debugging */
|
||||
|
||||
/* Upstream messages */
|
||||
#define NGM_LINK_IS_UP 32 /* e.g. carrier found - no data */
|
||||
#define NGM_LINK_IS_DOWN 33 /* carrier lost, includes queue state */
|
||||
#define NGM_HIGH_WATER_PASSED 34 /* includes queue state */
|
||||
#define NGM_LOW_WATER_PASSED 35 /* includes queue state */
|
||||
#define NGM_SYNC_QUEUE_STATE 36 /* sync response from sending packet */
|
||||
|
||||
/* Downstream messages */
|
||||
#define NGM_DROP_LINK 41 /* drop DTR, etc. - stay in the graph */
|
||||
#define NGM_RAISE_LINK 42 /* if you previously dropped it */
|
||||
#define NGM_FLUSH_QUEUE 43 /* no data */
|
||||
#define NGM_GET_BANDWIDTH (44|NGM_READONLY) /* either real or measured */
|
||||
#define NGM_SET_XMIT_Q_LIMITS 45 /* includes queue state */
|
||||
#define NGM_GET_XMIT_Q_LIMITS (46|NGM_READONLY) /* returns queue state */
|
||||
#define NGM_MICROMANAGE 47 /* We want sync. queue state
|
||||
reply for each packet sent */
|
||||
#define NGM_SET_FLOW_MANAGER 48 /* send flow control here */
|
||||
/* Structure used for NGM_MKPEER */
|
||||
struct ngm_mkpeer {
|
||||
char type[NG_TYPESIZ]; /* peer type */
|
||||
char ourhook[NG_HOOKSIZ]; /* hook name */
|
||||
char peerhook[NG_HOOKSIZ]; /* peer hook name */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_MKPEER_INFO() { \
|
||||
{ "type", &ng_parse_typebuf_type }, \
|
||||
{ "ourhook", &ng_parse_hookbuf_type }, \
|
||||
{ "peerhook", &ng_parse_hookbuf_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure used for NGM_CONNECT */
|
||||
struct ngm_connect {
|
||||
char path[NG_PATHSIZ]; /* peer path */
|
||||
char ourhook[NG_HOOKSIZ]; /* hook name */
|
||||
char peerhook[NG_HOOKSIZ]; /* peer hook name */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_CONNECT_INFO() { \
|
||||
{ "path", &ng_parse_pathbuf_type }, \
|
||||
{ "ourhook", &ng_parse_hookbuf_type }, \
|
||||
{ "peerhook", &ng_parse_hookbuf_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure used for NGM_NAME */
|
||||
struct ngm_name {
|
||||
char name[NG_NODESIZ]; /* node name */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_NAME_INFO() { \
|
||||
{ "name", &ng_parse_nodebuf_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure used for NGM_RMHOOK */
|
||||
struct ngm_rmhook {
|
||||
char ourhook[NG_HOOKSIZ]; /* hook name */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_RMHOOK_INFO() { \
|
||||
{ "hook", &ng_parse_hookbuf_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure used for NGM_NODEINFO */
|
||||
struct nodeinfo {
|
||||
char name[NG_NODESIZ]; /* node name (if any) */
|
||||
char type[NG_TYPESIZ]; /* peer type */
|
||||
ng_ID_t id; /* unique identifier */
|
||||
u_int32_t hooks; /* number of active hooks */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_NODEINFO_INFO() { \
|
||||
{ "name", &ng_parse_nodebuf_type }, \
|
||||
{ "type", &ng_parse_typebuf_type }, \
|
||||
{ "id", &ng_parse_hint32_type }, \
|
||||
{ "hooks", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure used for NGM_LISTHOOKS */
|
||||
struct linkinfo {
|
||||
char ourhook[NG_HOOKSIZ]; /* hook name */
|
||||
char peerhook[NG_HOOKSIZ]; /* peer hook */
|
||||
struct nodeinfo nodeinfo;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_LINKINFO_INFO(nitype) { \
|
||||
{ "ourhook", &ng_parse_hookbuf_type }, \
|
||||
{ "peerhook", &ng_parse_hookbuf_type }, \
|
||||
{ "nodeinfo", (nitype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
struct hooklist {
|
||||
struct nodeinfo nodeinfo; /* node information */
|
||||
struct linkinfo link[]; /* info about each hook */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_HOOKLIST_INFO(nitype,litype) { \
|
||||
{ "nodeinfo", (nitype) }, \
|
||||
{ "linkinfo", (litype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
|
||||
struct namelist {
|
||||
u_int32_t numnames;
|
||||
struct nodeinfo nodeinfo[];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_LISTNODES_INFO(niarraytype) { \
|
||||
{ "numnames", &ng_parse_uint32_type }, \
|
||||
{ "nodeinfo", (niarraytype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure used for NGM_LISTTYPES */
|
||||
struct typeinfo {
|
||||
char type_name[NG_TYPESIZ]; /* name of type */
|
||||
u_int32_t numnodes; /* number alive */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_TYPEINFO_INFO() { \
|
||||
{ "typename", &ng_parse_typebuf_type }, \
|
||||
{ "numnodes", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
struct typelist {
|
||||
u_int32_t numtypes;
|
||||
struct typeinfo typeinfo[];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_TYPELIST_INFO(tiarraytype) { \
|
||||
{ "numtypes", &ng_parse_uint32_type }, \
|
||||
{ "typeinfo", (tiarraytype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
struct ngm_bandwidth {
|
||||
u_int64_t nominal_in;
|
||||
u_int64_t seen_in;
|
||||
u_int64_t nominal_out;
|
||||
u_int64_t seen_out;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_BANDWIDTH_INFO() { \
|
||||
{ "nominal_in", &ng_parse_uint64_type }, \
|
||||
{ "seen_in", &ng_parse_uint64_type }, \
|
||||
{ "nominal_out", &ng_parse_uint64_type }, \
|
||||
{ "seen_out", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/*
|
||||
* Information about a node's 'output' queue.
|
||||
* This is NOT the netgraph input queueing mechanism,
|
||||
* but rather any queue the node may implement internally
|
||||
* This has to consider ALTQ if we are to work with it.
|
||||
* As far as I can see, ALTQ counts PACKETS, not bytes.
|
||||
* If ALTQ has several queues and one has passed a watermark
|
||||
* we should have the priority of that queue be real (and not -1)
|
||||
* XXX ALTQ stuff is just an idea.....
|
||||
*/
|
||||
struct ngm_queue_state {
|
||||
u_int queue_priority; /* maybe only low-pri is full. -1 = all*/
|
||||
u_int max_queuelen_bytes;
|
||||
u_int max_queuelen_packets;
|
||||
u_int low_watermark;
|
||||
u_int high_watermark;
|
||||
u_int current;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_QUEUE_INFO() { \
|
||||
{ "max_queuelen_bytes", &ng_parse_uint_type }, \
|
||||
{ "max_queuelen_packets", &ng_parse_uint_type }, \
|
||||
{ "high_watermark", &ng_parse_uint_type }, \
|
||||
{ "low_watermark", &ng_parse_uint_type }, \
|
||||
{ "current", &ng_parse_uint_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Tell a node who to send async flow control info to. */
|
||||
struct flow_manager {
|
||||
ng_ID_t id; /* unique identifier */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_GENERIC_FLOW_MANAGER_INFO() { \
|
||||
{ "id", &ng_parse_hint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* For netgraph nodes that are somehow associated with file descriptors
|
||||
* (e.g., a device that has a /dev entry and is also a netgraph node),
|
||||
* we define a generic ioctl for requesting the corresponding nodeinfo
|
||||
* structure and for assigning a name (if there isn't one already).
|
||||
*
|
||||
* For these to you need to also #include <sys/ioccom.h>.
|
||||
*/
|
||||
|
||||
#define NGIOCGINFO _IOR('N', 40, struct nodeinfo) /* get node info */
|
||||
#define NGIOCSETNAME _IOW('N', 41, struct ngm_name) /* set node name */
|
||||
|
||||
#ifdef _KERNEL
|
||||
/*
|
||||
* Allocate and initialize a netgraph message "msg" with "len"
|
||||
* extra bytes of argument. Sets "msg" to NULL if fails.
|
||||
* Does not initialize token.
|
||||
*/
|
||||
#define NG_MKMESSAGE(msg, cookie, cmdid, len, how) \
|
||||
do { \
|
||||
(msg) = malloc(sizeof(struct ng_mesg) \
|
||||
+ (len), M_NETGRAPH_MSG, (how) | M_ZERO); \
|
||||
if ((msg) == NULL) \
|
||||
break; \
|
||||
(msg)->header.version = NG_VERSION; \
|
||||
(msg)->header.typecookie = (cookie); \
|
||||
(msg)->header.cmd = (cmdid); \
|
||||
(msg)->header.arglen = (len); \
|
||||
strncpy((msg)->header.cmdstr, #cmdid, \
|
||||
sizeof((msg)->header.cmdstr) - 1); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Allocate and initialize a response "rsp" to a message "msg"
|
||||
* with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
|
||||
*/
|
||||
#define NG_MKRESPONSE(rsp, msg, len, how) \
|
||||
do { \
|
||||
(rsp) = malloc(sizeof(struct ng_mesg) \
|
||||
+ (len), M_NETGRAPH_MSG, (how) | M_ZERO); \
|
||||
if ((rsp) == NULL) \
|
||||
break; \
|
||||
(rsp)->header.version = NG_VERSION; \
|
||||
(rsp)->header.arglen = (len); \
|
||||
(rsp)->header.token = (msg)->header.token; \
|
||||
(rsp)->header.typecookie = (msg)->header.typecookie; \
|
||||
(rsp)->header.cmd = (msg)->header.cmd; \
|
||||
bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr, \
|
||||
sizeof((rsp)->header.cmdstr)); \
|
||||
(rsp)->header.flags |= NGF_RESP; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Make a copy of message. Sets "copy" to NULL if fails.
|
||||
*/
|
||||
#define NG_COPYMESSAGE(copy, msg, how) \
|
||||
do { \
|
||||
(copy) = malloc(sizeof(struct ng_mesg) \
|
||||
+ (msg)->header.arglen, M_NETGRAPH_MSG, (how) | M_ZERO); \
|
||||
if ((copy) == NULL) \
|
||||
break; \
|
||||
(copy)->header.version = NG_VERSION; \
|
||||
(copy)->header.arglen = (msg)->header.arglen; \
|
||||
(copy)->header.token = (msg)->header.token; \
|
||||
(copy)->header.typecookie = (msg)->header.typecookie; \
|
||||
(copy)->header.cmd = (msg)->header.cmd; \
|
||||
(copy)->header.flags = (msg)->header.flags; \
|
||||
bcopy((msg)->header.cmdstr, (copy)->header.cmdstr, \
|
||||
sizeof((copy)->header.cmdstr)); \
|
||||
if ((msg)->header.arglen > 0) \
|
||||
bcopy((msg)->data, (copy)->data, (msg)->header.arglen); \
|
||||
} while (0)
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* _NETGRAPH_NG_MESSAGE_H_ */
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* ng_mppc.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2000 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>
|
||||
*
|
||||
* $Whistle: ng_mppc.h,v 1.3 2000/02/12 01:17:22 archie Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_MPPC_H_
|
||||
#define _NETGRAPH_NG_MPPC_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_MPPC_NODE_TYPE "mppc"
|
||||
#define NGM_MPPC_COOKIE 942886745
|
||||
|
||||
/* Hook names */
|
||||
#define NG_MPPC_HOOK_COMP "comp" /* compression hook */
|
||||
#define NG_MPPC_HOOK_DECOMP "decomp" /* decompression hook */
|
||||
|
||||
/* Length of MPPE key */
|
||||
#define MPPE_KEY_LEN 16
|
||||
|
||||
/* Max expansion due to MPPC header and compression algorithm */
|
||||
#define MPPC_MAX_BLOWUP(n) ((n) * 9 / 8 + 26)
|
||||
|
||||
/* MPPC/MPPE PPP negotiation bits */
|
||||
#define MPPC_BIT 0x00000001 /* mppc compression bits */
|
||||
#define MPPE_40 0x00000020 /* use 40 bit key */
|
||||
#define MPPE_56 0x00000080 /* use 56 bit key */
|
||||
#define MPPE_128 0x00000040 /* use 128 bit key */
|
||||
#define MPPE_BITS 0x000000e0 /* mppe encryption bits */
|
||||
#define MPPE_STATELESS 0x01000000 /* use stateless mode */
|
||||
#define MPPC_VALID_BITS 0x010000e1 /* possibly valid bits */
|
||||
|
||||
/* Config struct (per-direction) */
|
||||
struct ng_mppc_config {
|
||||
u_char enable; /* enable */
|
||||
u_int32_t bits; /* config bits */
|
||||
u_char startkey[MPPE_KEY_LEN]; /* start key */
|
||||
};
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_MPPC_CONFIG_COMP = 1,
|
||||
NGM_MPPC_CONFIG_DECOMP,
|
||||
NGM_MPPC_RESETREQ, /* sent either way! */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_MPPC_H_ */
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
/*-
|
||||
* Copyright 2005, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define NG_NAT_NODE_TYPE "nat"
|
||||
#define NGM_NAT_COOKIE 1107718711
|
||||
|
||||
#define NG_NAT_HOOK_IN "in"
|
||||
#define NG_NAT_HOOK_OUT "out"
|
||||
|
||||
/* Arguments for NGM_NAT_SET_MODE message */
|
||||
struct ng_nat_mode {
|
||||
uint32_t flags;
|
||||
uint32_t mask;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_MODE_INFO { \
|
||||
{ "flags", &ng_parse_uint32_type }, \
|
||||
{ "mask", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#define NG_NAT_LOG 0x01
|
||||
#define NG_NAT_DENY_INCOMING 0x02
|
||||
#define NG_NAT_SAME_PORTS 0x04
|
||||
#define NG_NAT_UNREGISTERED_ONLY 0x10
|
||||
#define NG_NAT_RESET_ON_ADDR_CHANGE 0x20
|
||||
#define NG_NAT_PROXY_ONLY 0x40
|
||||
#define NG_NAT_REVERSE 0x80
|
||||
|
||||
#define NG_NAT_DESC_LENGTH 64
|
||||
#define NG_NAT_REDIRPROTO_ADDR (IPPROTO_MAX + 3) /* LibAlias' LINK_ADDR, also unused in in.h */
|
||||
|
||||
/* Arguments for NGM_NAT_REDIRECT_PORT message */
|
||||
struct ng_nat_redirect_port {
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
struct in_addr remote_addr;
|
||||
uint16_t local_port;
|
||||
uint16_t alias_port;
|
||||
uint16_t remote_port;
|
||||
uint8_t proto;
|
||||
char description[NG_NAT_DESC_LENGTH];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_REDIRECT_PORT_TYPE_INFO(desctype) { \
|
||||
{ "local_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "alias_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "remote_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "local_port", &ng_parse_uint16_type }, \
|
||||
{ "alias_port", &ng_parse_uint16_type }, \
|
||||
{ "remote_port", &ng_parse_uint16_type }, \
|
||||
{ "proto", &ng_parse_uint8_type }, \
|
||||
{ "description", (desctype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Arguments for NGM_NAT_REDIRECT_ADDR message */
|
||||
struct ng_nat_redirect_addr {
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
char description[NG_NAT_DESC_LENGTH];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_REDIRECT_ADDR_TYPE_INFO(desctype) { \
|
||||
{ "local_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "alias_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "description", (desctype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Arguments for NGM_NAT_REDIRECT_PROTO message */
|
||||
struct ng_nat_redirect_proto {
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
struct in_addr remote_addr;
|
||||
uint8_t proto;
|
||||
char description[NG_NAT_DESC_LENGTH];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_REDIRECT_PROTO_TYPE_INFO(desctype) { \
|
||||
{ "local_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "alias_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "remote_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "proto", &ng_parse_uint8_type }, \
|
||||
{ "description", (desctype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Arguments for NGM_NAT_ADD_SERVER message */
|
||||
struct ng_nat_add_server {
|
||||
uint32_t id;
|
||||
struct in_addr addr;
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_ADD_SERVER_TYPE_INFO { \
|
||||
{ "id", &ng_parse_uint32_type }, \
|
||||
{ "addr", &ng_parse_ipaddr_type }, \
|
||||
{ "port", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* List entry of array returned in NGM_NAT_LIST_REDIRECTS message */
|
||||
struct ng_nat_listrdrs_entry {
|
||||
uint32_t id; /* Anything except zero */
|
||||
struct in_addr local_addr;
|
||||
struct in_addr alias_addr;
|
||||
struct in_addr remote_addr;
|
||||
uint16_t local_port;
|
||||
uint16_t alias_port;
|
||||
uint16_t remote_port;
|
||||
uint16_t proto; /* Valid proto or NG_NAT_REDIRPROTO_ADDR */
|
||||
uint16_t lsnat; /* LSNAT servers count */
|
||||
char description[NG_NAT_DESC_LENGTH];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_LISTRDRS_ENTRY_TYPE_INFO(desctype) { \
|
||||
{ "id", &ng_parse_uint32_type }, \
|
||||
{ "local_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "alias_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "remote_addr", &ng_parse_ipaddr_type }, \
|
||||
{ "local_port", &ng_parse_uint16_type }, \
|
||||
{ "alias_port", &ng_parse_uint16_type }, \
|
||||
{ "remote_port", &ng_parse_uint16_type }, \
|
||||
{ "proto", &ng_parse_uint16_type }, \
|
||||
{ "lsnat", &ng_parse_uint16_type }, \
|
||||
{ "description", (desctype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure returned by NGM_NAT_LIST_REDIRECTS */
|
||||
struct ng_nat_list_redirects {
|
||||
uint32_t total_count;
|
||||
struct ng_nat_listrdrs_entry redirects[];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_LIST_REDIRECTS_TYPE_INFO(redirtype) { \
|
||||
{ "total_count", &ng_parse_uint32_type }, \
|
||||
{ "redirects", (redirtype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Structure returned by NGM_NAT_LIBALIAS_INFO */
|
||||
struct ng_nat_libalias_info {
|
||||
uint32_t icmpLinkCount;
|
||||
uint32_t udpLinkCount;
|
||||
uint32_t tcpLinkCount;
|
||||
uint32_t sctpLinkCount;
|
||||
uint32_t pptpLinkCount;
|
||||
uint32_t protoLinkCount;
|
||||
uint32_t fragmentIdLinkCount;
|
||||
uint32_t fragmentPtrLinkCount;
|
||||
uint32_t sockCount;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_NAT_LIBALIAS_INFO { \
|
||||
{ "icmpLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "udpLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "tcpLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "sctpLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "pptpLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "protoLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "fragmentIdLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "fragmentPtrLinkCount", &ng_parse_uint32_type }, \
|
||||
{ "sockCount", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
enum {
|
||||
NGM_NAT_SET_IPADDR = 1,
|
||||
NGM_NAT_SET_MODE,
|
||||
NGM_NAT_SET_TARGET,
|
||||
NGM_NAT_REDIRECT_PORT,
|
||||
NGM_NAT_REDIRECT_ADDR,
|
||||
NGM_NAT_REDIRECT_PROTO,
|
||||
NGM_NAT_REDIRECT_DYNAMIC,
|
||||
NGM_NAT_REDIRECT_DELETE,
|
||||
NGM_NAT_ADD_SERVER,
|
||||
NGM_NAT_LIST_REDIRECTS,
|
||||
NGM_NAT_PROXY_RULE,
|
||||
NGM_NAT_LIBALIAS_INFO,
|
||||
};
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* ng_one2many.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 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$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_ONE2MANY_H_
|
||||
#define _NETGRAPH_NG_ONE2MANY_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_ONE2MANY_NODE_TYPE "one2many"
|
||||
#define NGM_ONE2MANY_COOKIE 1100897444
|
||||
|
||||
/* Hook names */
|
||||
#define NG_ONE2MANY_HOOK_ONE "one"
|
||||
#define NG_ONE2MANY_HOOK_MANY_PREFIX "many" /* append decimal integer */
|
||||
#define NG_ONE2MANY_HOOK_MANY_FMT "many%d" /* for use with printf(3) */
|
||||
|
||||
/* Maximum number of supported "many" links */
|
||||
#define NG_ONE2MANY_MAX_LINKS 64
|
||||
|
||||
/* Link number used to indicate the "one" hook */
|
||||
#define NG_ONE2MANY_ONE_LINKNUM (-1)
|
||||
|
||||
/* Algorithms for outgoing packet distribution (XXX only one so far) */
|
||||
#define NG_ONE2MANY_XMIT_ROUNDROBIN 1 /* round-robin delivery */
|
||||
#define NG_ONE2MANY_XMIT_ALL 2 /* send packets to all many hooks */
|
||||
#define NG_ONE2MANY_XMIT_FAILOVER 3 /* send packets to first active "many" */
|
||||
|
||||
/* Algorithms for detecting link failure (XXX only one so far) */
|
||||
#define NG_ONE2MANY_FAIL_MANUAL 1 /* use enabledLinks[] array */
|
||||
#define NG_ONE2MANY_FAIL_NOTIFY 2 /* listen to flow control msgs */
|
||||
|
||||
/* Node configuration structure */
|
||||
struct ng_one2many_config {
|
||||
u_int32_t xmitAlg; /* how to distribute packets */
|
||||
u_int32_t failAlg; /* how to detect link failure */
|
||||
u_char enabledLinks[NG_ONE2MANY_MAX_LINKS];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_ONE2MANY_CONFIG_TYPE_INFO(atype) { \
|
||||
{ "xmitAlg", &ng_parse_uint32_type }, \
|
||||
{ "failAlg", &ng_parse_uint32_type }, \
|
||||
{ "enabledLinks", (atype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics structure (one for each link) */
|
||||
struct ng_one2many_link_stats {
|
||||
u_int64_t recvOctets; /* total octets rec'd on link */
|
||||
u_int64_t recvPackets; /* total pkts rec'd on link */
|
||||
u_int64_t xmitOctets; /* total octets xmit'd on link */
|
||||
u_int64_t xmitPackets; /* total pkts xmit'd on link */
|
||||
u_int64_t memoryFailures; /* times couldn't get mem or mbuf */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_ONE2MANY_LINK_STATS_TYPE_INFO { \
|
||||
{ "recvOctets", &ng_parse_uint64_type }, \
|
||||
{ "recvPackets", &ng_parse_uint64_type }, \
|
||||
{ "xmitOctets", &ng_parse_uint64_type }, \
|
||||
{ "xmitPackets", &ng_parse_uint64_type }, \
|
||||
{ "memoryFailures", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph control messages */
|
||||
enum {
|
||||
NGM_ONE2MANY_SET_CONFIG, /* set configuration */
|
||||
NGM_ONE2MANY_GET_CONFIG, /* get configuration */
|
||||
NGM_ONE2MANY_GET_STATS, /* get link stats */
|
||||
NGM_ONE2MANY_CLR_STATS, /* clear link stats */
|
||||
NGM_ONE2MANY_GETCLR_STATS, /* atomically get & clear link stats */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_ONE2MANY_H_ */
|
||||
|
|
@ -0,0 +1,540 @@
|
|||
/*
|
||||
* ng_parse.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 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>
|
||||
*
|
||||
* $Whistle: ng_parse.h,v 1.2 1999/11/29 01:43:48 archie Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_PARSE_H_
|
||||
#define _NETGRAPH_NG_PARSE_H_
|
||||
|
||||
/*
|
||||
|
||||
This defines a library of routines for converting between various C
|
||||
language types in binary form and ASCII strings. Types are user
|
||||
definable. Several pre-defined types are supplied, for some common
|
||||
C types: structures, variable and fixed length arrays, integer types,
|
||||
variable and fixed length strings, IP addresses, etc.
|
||||
|
||||
A netgraph node type may provide a list of types that correspond to
|
||||
the structures it expects to send and receive in the arguments field
|
||||
of a control message. This allows these messages to be converted
|
||||
between their native binary form and the corresponding ASCII form.
|
||||
|
||||
A future use of the ASCII form may be for inter-machine communication
|
||||
of control messages, because the ASCII form is machine independent
|
||||
whereas the native binary form is not.
|
||||
|
||||
Syntax
|
||||
------
|
||||
|
||||
Structures:
|
||||
|
||||
'{' [ <name>=<value> ... ] '}'
|
||||
|
||||
Omitted fields have their default values by implication.
|
||||
The order in which the fields are specified does not matter.
|
||||
|
||||
Arrays:
|
||||
|
||||
'[' [ [index=]<value> ... ] ']'
|
||||
|
||||
Element value may be specified with or without the "<index>=" prefix;
|
||||
If omitted, the index after the previous element is used.
|
||||
Omitted fields have their default values by implication.
|
||||
|
||||
Strings:
|
||||
|
||||
"foo bar blah\r\n"
|
||||
|
||||
That is, strings are specified just like C strings. The usual
|
||||
backslash escapes are accepted.
|
||||
|
||||
Other simple types (integers, IP addresses) have their obvious forms.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
Suppose we have a netgraph command that takes as an argument
|
||||
a 'struct foo' shown below. Here is an example of a possible
|
||||
value for the structure, and the corresponding ASCII encoding
|
||||
of that value:
|
||||
|
||||
Structure Binary value
|
||||
--------- ------------
|
||||
|
||||
struct foo {
|
||||
struct in_addr ip; 01 02 03 04
|
||||
int bar; 00 00 00 00
|
||||
char label[8]; 61 62 63 0a 00 00 00 00
|
||||
u_char alen; 03 00
|
||||
short ary[]; 05 00 00 00 0a 00
|
||||
};
|
||||
|
||||
ASCII value
|
||||
-----------
|
||||
|
||||
{ ip=1.2.3.4 label="abc\n" alen=3 ary=[ 5 2=10 ] }
|
||||
|
||||
Note that omitted fields and array elements get their default
|
||||
values ("bar" and ary[2]), and that the alignment is handled
|
||||
automatically (the extra 00 byte after "alen"). Also, since byte
|
||||
order and alignment are inherently machine dependent, so is this
|
||||
conversion process. The above example shows an x86 (little
|
||||
endian) encoding. Also the above example is tricky because the
|
||||
structure is variable length, depending on 'alen', the number of
|
||||
elements in the array 'ary'.
|
||||
|
||||
Here is how one would define a parse type for the above structure,
|
||||
subclassing the pre-defined types below. We construct the type in
|
||||
a 'bottom up' fashion, defining each field's type first, then the
|
||||
type for the whole structure ('//' comments used to avoid breakage).
|
||||
|
||||
// Super-type info for 'label' field
|
||||
struct ng_parse_fixedstring_info foo_label_info = { 8 };
|
||||
|
||||
// Parse type for 'label' field
|
||||
struct ng_parse_type foo_label_type = {
|
||||
&ng_parse_fixedstring_type // super-type
|
||||
&foo_label_info // super-type info
|
||||
};
|
||||
|
||||
#define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
|
||||
|
||||
// Function to compute the length of the array 'ary', which
|
||||
// is variable length, depending on the previous field 'alen'.
|
||||
// Upon entry 'buf' will be pointing at &ary[0].
|
||||
int
|
||||
foo_ary_getLength(const struct ng_parse_type *type,
|
||||
const u_char *start, const u_char *buf)
|
||||
{
|
||||
const struct foo *f;
|
||||
|
||||
f = (const struct foo *)(buf - OFFSETOF(struct foo, ary));
|
||||
return f->alen;
|
||||
}
|
||||
|
||||
// Super-type info for 'ary' field
|
||||
struct ng_parse_array_info foo_ary_info = {
|
||||
&ng_parse_int16_type, // element type
|
||||
&foo_ary_getLength // func to get array length
|
||||
}
|
||||
|
||||
// Parse type for 'ary' field
|
||||
struct ng_parse_type foo_ary_type = {
|
||||
&ng_parse_array_type, // super-type
|
||||
&foo_ary_info // super-type info
|
||||
};
|
||||
|
||||
// Super-type info for struct foo
|
||||
struct ng_parse_struct_field foo_fields[] = {
|
||||
{ "ip", &ng_parse_ipaddr_type },
|
||||
{ "bar", &ng_parse_int32_type },
|
||||
{ "label", &foo_label_type },
|
||||
{ "alen", &ng_parse_uint8_type },
|
||||
{ "ary", &foo_ary_type },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
// Parse type for struct foo
|
||||
struct ng_parse_type foo_type = {
|
||||
&ng_parse_struct_type, // super-type
|
||||
&foo_fields // super-type info
|
||||
};
|
||||
|
||||
To define a type, you can define it as a sub-type of a predefined
|
||||
type as shown above, possibly overriding some of the predefined
|
||||
type's methods, or define an entirely new syntax, with the restriction
|
||||
that the ASCII representation of your type's value must not contain
|
||||
any whitespace or any of these characters: { } [ ] = "
|
||||
|
||||
See ng_ksocket.c for an example of how to do this for 'struct sockaddr'.
|
||||
See ng_parse.c to see implementations of the pre-defined types below.
|
||||
|
||||
*/
|
||||
|
||||
/************************************************************************
|
||||
METHODS REQUIRED BY A TYPE
|
||||
************************************************************************/
|
||||
|
||||
/*
|
||||
* Three methods are required for a type. These may be given explicitly
|
||||
* or, if NULL, inherited from the super-type. The 'getDefault' method
|
||||
* is always optional; the others are required if there is no super-type.
|
||||
*/
|
||||
|
||||
struct ng_parse_type;
|
||||
|
||||
/*
|
||||
* Convert ASCII to binary according to the supplied type.
|
||||
*
|
||||
* The ASCII characters begin at offset *off in 'string'. The binary
|
||||
* representation is put into 'buf', which has at least *buflen bytes.
|
||||
* 'start' points to the first byte output by ng_parse() (ie, start <= buf).
|
||||
*
|
||||
* Upon return, *buflen contains the length of the new binary data, and
|
||||
* *off is updated to point just past the end of the parsed range of
|
||||
* characters, or, in the case of an error, to the offending character(s).
|
||||
*
|
||||
* Return values:
|
||||
* 0 Success; *buflen holds the length of the data
|
||||
* and *off points just past the last char parsed.
|
||||
* EALREADY Field specified twice
|
||||
* ENOENT Unknown field
|
||||
* E2BIG Array or character string overflow
|
||||
* ERANGE Output was longer than *buflen bytes
|
||||
* EINVAL Parse failure or other invalid content
|
||||
* ENOMEM Out of memory
|
||||
* EOPNOTSUPP Mandatory array/structure element missing
|
||||
*/
|
||||
typedef int ng_parse_t(const struct ng_parse_type *type, const char *string,
|
||||
int *off, const u_char *start,
|
||||
u_char *buf, int *buflen);
|
||||
|
||||
/*
|
||||
* Convert binary to ASCII according to the supplied type.
|
||||
*
|
||||
* The results are put into 'buf', which is at least buflen bytes long.
|
||||
* *off points to the current byte in 'data' and should be updated
|
||||
* before return to point just past the last byte unparsed.
|
||||
*
|
||||
* Returns:
|
||||
* 0 Success
|
||||
* ERANGE Output was longer than buflen bytes
|
||||
*/
|
||||
typedef int ng_unparse_t(const struct ng_parse_type *type,
|
||||
const u_char *data, int *off, char *buf, int buflen);
|
||||
|
||||
/*
|
||||
* Compute the default value according to the supplied type.
|
||||
*
|
||||
* Store the result in 'buf', which is at least *buflen bytes long.
|
||||
* Upon return *buflen contains the length of the output.
|
||||
*
|
||||
* Returns:
|
||||
* 0 Success
|
||||
* ERANGE Output was longer than *buflen bytes
|
||||
* EOPNOTSUPP Default value is not specified for this type
|
||||
*/
|
||||
typedef int ng_getDefault_t(const struct ng_parse_type *type,
|
||||
const u_char *start, u_char *buf, int *buflen);
|
||||
|
||||
/*
|
||||
* Return the alignment requirement of this type. Zero is same as one.
|
||||
*/
|
||||
typedef int ng_getAlign_t(const struct ng_parse_type *type);
|
||||
|
||||
/************************************************************************
|
||||
TYPE DEFINITION
|
||||
************************************************************************/
|
||||
|
||||
/*
|
||||
* This structure describes a type, which may be a sub-type of another
|
||||
* type by pointing to it with 'supertype' and possibly omitting methods.
|
||||
* Typically the super-type requires some type-specific info, which is
|
||||
* supplied by the 'info' field.
|
||||
*
|
||||
* The 'private' field is ignored by all of the pre-defined types.
|
||||
* Sub-types may use it as they see fit.
|
||||
*
|
||||
* The 'getDefault' method may always be omitted (even if there is no
|
||||
* super-type), which means the value for any item of this type must
|
||||
* always be explicitly given.
|
||||
*/
|
||||
struct ng_parse_type {
|
||||
const struct ng_parse_type *supertype; /* super-type, if any */
|
||||
const void *info; /* type-specific info */
|
||||
void *private; /* client private info */
|
||||
ng_parse_t *parse; /* parse method */
|
||||
ng_unparse_t *unparse; /* unparse method */
|
||||
ng_getDefault_t *getDefault; /* get default value method */
|
||||
ng_getAlign_t *getAlign; /* get alignment */
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
PRE-DEFINED TYPES
|
||||
************************************************************************/
|
||||
|
||||
/*
|
||||
* STRUCTURE TYPE
|
||||
*
|
||||
* This type supports arbitrary C structures. The normal field alignment
|
||||
* rules for the local machine are applied. Fields are always parsed in
|
||||
* field order, no matter what order they are listed in the ASCII string.
|
||||
*
|
||||
* Default value: Determined on a per-field basis
|
||||
* Additional info: struct ng_parse_struct_field *
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_struct_type;
|
||||
|
||||
/* Each field has a name, type, and optional alignment override. If the
|
||||
override is non-zero, the alignment is determined from the field type.
|
||||
Note: add an extra struct ng_parse_struct_field with name == NULL
|
||||
to indicate the end of the list. */
|
||||
struct ng_parse_struct_field {
|
||||
const char *name; /* field name */
|
||||
const struct ng_parse_type *type; /* field type */
|
||||
int alignment; /* override alignment */
|
||||
};
|
||||
|
||||
/*
|
||||
* FIXED LENGTH ARRAY TYPE
|
||||
*
|
||||
* This type supports fixed length arrays, having any element type.
|
||||
*
|
||||
* Default value: As returned by getDefault for each index
|
||||
* Additional info: struct ng_parse_fixedarray_info *
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_fixedarray_type;
|
||||
|
||||
/*
|
||||
* Get the default value for the element at index 'index'. This method
|
||||
* may be NULL, in which case the default value is computed from the
|
||||
* element type. Otherwise, it should fill in the default value at *buf
|
||||
* (having size *buflen) and update *buflen to the length of the filled-in
|
||||
* value before return. If there is not enough routine return ERANGE.
|
||||
*/
|
||||
typedef int ng_parse_array_getDefault_t(const struct ng_parse_type *type,
|
||||
int index, const u_char *start,
|
||||
u_char *buf, int *buflen);
|
||||
|
||||
struct ng_parse_fixedarray_info {
|
||||
const struct ng_parse_type *elementType;
|
||||
int length;
|
||||
ng_parse_array_getDefault_t *getDefault;
|
||||
};
|
||||
|
||||
/*
|
||||
* VARIABLE LENGTH ARRAY TYPE
|
||||
*
|
||||
* Same as fixed length arrays, except that the length is determined
|
||||
* by a function instead of a constant value.
|
||||
*
|
||||
* Default value: Same as with fixed length arrays
|
||||
* Additional info: struct ng_parse_array_info *
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_array_type;
|
||||
|
||||
/*
|
||||
* Return the length of the array. If the array is a field in a structure,
|
||||
* all prior fields are guaranteed to be filled in already. Upon entry,
|
||||
* 'start' is equal to the first byte parsed in this run, while 'buf' points
|
||||
* to the first element of the array to be filled in.
|
||||
*/
|
||||
typedef int ng_parse_array_getLength_t(const struct ng_parse_type *type,
|
||||
const u_char *start, const u_char *buf);
|
||||
|
||||
struct ng_parse_array_info {
|
||||
const struct ng_parse_type *elementType;
|
||||
ng_parse_array_getLength_t *getLength;
|
||||
ng_parse_array_getDefault_t *getDefault;
|
||||
};
|
||||
|
||||
/*
|
||||
* ARBITRARY LENGTH STRING TYPE
|
||||
*
|
||||
* For arbirary length, NUL-terminated strings.
|
||||
*
|
||||
* Default value: Empty string
|
||||
* Additional info: None required
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_string_type;
|
||||
|
||||
/*
|
||||
* BOUNDED LENGTH STRING TYPE
|
||||
*
|
||||
* These are strings that have a fixed-size buffer, and always include
|
||||
* a terminating NUL character.
|
||||
*
|
||||
* Default value: Empty string
|
||||
* Additional info: struct ng_parse_fixedstring_info *
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_fixedstring_type;
|
||||
|
||||
struct ng_parse_fixedstring_info {
|
||||
int bufSize; /* size of buffer (including NUL) */
|
||||
};
|
||||
|
||||
/*
|
||||
* EXPLICITLY SIZED STRING TYPE
|
||||
*
|
||||
* These are strings that have a two byte length field preceding them.
|
||||
* Parsed strings are NOT NUL-terminated.
|
||||
*
|
||||
* Default value: Empty string
|
||||
* Additional info: None
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_sizedstring_type;
|
||||
|
||||
/*
|
||||
* COMMONLY USED BOUNDED LENGTH STRING TYPES
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_nodebuf_type; /* NG_NODESIZ */
|
||||
extern const struct ng_parse_type ng_parse_hookbuf_type; /* NG_HOOKSIZ */
|
||||
extern const struct ng_parse_type ng_parse_pathbuf_type; /* NG_PATHSIZ */
|
||||
extern const struct ng_parse_type ng_parse_typebuf_type; /* NG_TYPESIZ */
|
||||
extern const struct ng_parse_type ng_parse_cmdbuf_type; /* NG_CMDSTRSIZ */
|
||||
|
||||
/*
|
||||
* INTEGER TYPES
|
||||
*
|
||||
* Default value: 0
|
||||
* Additional info: None required
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_int8_type;
|
||||
extern const struct ng_parse_type ng_parse_int16_type;
|
||||
extern const struct ng_parse_type ng_parse_int32_type;
|
||||
extern const struct ng_parse_type ng_parse_int64_type;
|
||||
|
||||
/* Same thing but unparse as unsigned quantities */
|
||||
extern const struct ng_parse_type ng_parse_uint8_type;
|
||||
extern const struct ng_parse_type ng_parse_uint16_type;
|
||||
extern const struct ng_parse_type ng_parse_uint32_type;
|
||||
extern const struct ng_parse_type ng_parse_uint64_type;
|
||||
|
||||
/* Same thing but unparse as hex quantities, e.g., "0xe7" */
|
||||
extern const struct ng_parse_type ng_parse_hint8_type;
|
||||
extern const struct ng_parse_type ng_parse_hint16_type;
|
||||
extern const struct ng_parse_type ng_parse_hint32_type;
|
||||
extern const struct ng_parse_type ng_parse_hint64_type;
|
||||
|
||||
/*
|
||||
* IP ADDRESS TYPE
|
||||
*
|
||||
* Default value: 0.0.0.0
|
||||
* Additional info: None required
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_ipaddr_type;
|
||||
|
||||
/*
|
||||
* ETHERNET ADDRESS TYPE
|
||||
*
|
||||
* Default value: None
|
||||
* Additional info: None required
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_enaddr_type;
|
||||
|
||||
/*
|
||||
* VARIABLE LENGTH BYTE ARRAY TYPE
|
||||
*
|
||||
* The bytes are displayed in hex. The ASCII form may be either an
|
||||
* array of bytes or a string constant, in which case the array is
|
||||
* zero-filled after the string bytes.
|
||||
*
|
||||
* Default value: All bytes are zero
|
||||
* Additional info: ng_parse_array_getLength_t *
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_bytearray_type;
|
||||
|
||||
/*
|
||||
* NETGRAPH CONTROL MESSAGE TYPE
|
||||
*
|
||||
* This is the parse type for a struct ng_mesg.
|
||||
*
|
||||
* Default value: All fields zero
|
||||
* Additional info: None required
|
||||
*/
|
||||
extern const struct ng_parse_type ng_parse_ng_mesg_type;
|
||||
|
||||
/************************************************************************
|
||||
CONVERSTION AND PARSING ROUTINES
|
||||
************************************************************************/
|
||||
|
||||
/* Tokens for parsing structs and arrays */
|
||||
enum ng_parse_token {
|
||||
T_LBRACE, /* '{' */
|
||||
T_RBRACE, /* '}' */
|
||||
T_LBRACKET, /* '[' */
|
||||
T_RBRACKET, /* ']' */
|
||||
T_EQUALS, /* '=' */
|
||||
T_STRING, /* string in double quotes */
|
||||
T_ERROR, /* error parsing string in double quotes */
|
||||
T_WORD, /* anything else containing no whitespace */
|
||||
T_EOF, /* end of string reached */
|
||||
};
|
||||
|
||||
/*
|
||||
* See typedef ng_parse_t for definition
|
||||
*/
|
||||
extern int ng_parse(const struct ng_parse_type *type, const char *string,
|
||||
int *off, u_char *buf, int *buflen);
|
||||
|
||||
/*
|
||||
* See typedef ng_unparse_t for definition (*off assumed to be zero).
|
||||
*/
|
||||
extern int ng_unparse(const struct ng_parse_type *type,
|
||||
const u_char *data, char *buf, int buflen);
|
||||
|
||||
/*
|
||||
* See typedef ng_getDefault_t for definition
|
||||
*/
|
||||
extern int ng_parse_getDefault(const struct ng_parse_type *type,
|
||||
u_char *buf, int *buflen);
|
||||
|
||||
/*
|
||||
* Parse a token: '*startp' is the offset to start looking. Upon
|
||||
* successful return, '*startp' equals the beginning of the token
|
||||
* and '*lenp' the length. If error, '*startp' points at the
|
||||
* offending character(s).
|
||||
*/
|
||||
extern enum ng_parse_token ng_parse_get_token(const char *s,
|
||||
int *startp, int *lenp);
|
||||
|
||||
/*
|
||||
* Like above, but specifically for getting a string token and returning
|
||||
* the string value. The string token must be enclosed in double quotes
|
||||
* and the normal C backslash escapes are recognized. The caller must
|
||||
* eventually free() the returned result. Returns NULL if token is
|
||||
* not a string token, or parse or other error. Otherwise, *lenp contains
|
||||
* the number of characters parsed, and *slenp (if not NULL) contains
|
||||
* the actual number of characters in the parsed string.
|
||||
*/
|
||||
extern char *ng_get_string_token(const char *s, int *startp,
|
||||
int *lenp, int *slenp);
|
||||
|
||||
/*
|
||||
* Convert a raw string into a doubly-quoted string including any
|
||||
* necessary backslash escapes. Caller must free the result.
|
||||
* Returns NULL if ENOMEM. Normally "slen" should equal strlen(s)
|
||||
* unless you want to encode NUL bytes.
|
||||
*/
|
||||
extern char *ng_encode_string(const char *s, int slen);
|
||||
|
||||
#endif /* _NETGRAPH_NG_PARSE_H_ */
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/*-
|
||||
* Copyright (C) 2010 by Maxim Ignatenko <gelraen.ua@gmail.com>
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_PATCH_H_
|
||||
#define _NETGRAPH_NG_PATCH_H_
|
||||
|
||||
/* Node type name. */
|
||||
#define NG_PATCH_NODE_TYPE "patch"
|
||||
|
||||
/* Node type cookie. */
|
||||
#define NGM_PATCH_COOKIE 1262445509
|
||||
|
||||
/* Hook names */
|
||||
#define NG_PATCH_HOOK_IN "in"
|
||||
#define NG_PATCH_HOOK_OUT "out"
|
||||
|
||||
/* Netgraph commands understood by this node type */
|
||||
enum {
|
||||
NGM_PATCH_SETCONFIG = 1,
|
||||
NGM_PATCH_GETCONFIG,
|
||||
NGM_PATCH_GET_STATS,
|
||||
NGM_PATCH_CLR_STATS,
|
||||
NGM_PATCH_GETCLR_STATS
|
||||
};
|
||||
|
||||
/* Patching modes */
|
||||
enum {
|
||||
NG_PATCH_MODE_SET = 1,
|
||||
NG_PATCH_MODE_ADD = 2,
|
||||
NG_PATCH_MODE_SUB = 3,
|
||||
NG_PATCH_MODE_MUL = 4,
|
||||
NG_PATCH_MODE_DIV = 5,
|
||||
NG_PATCH_MODE_NEG = 6,
|
||||
NG_PATCH_MODE_AND = 7,
|
||||
NG_PATCH_MODE_OR = 8,
|
||||
NG_PATCH_MODE_XOR = 9,
|
||||
NG_PATCH_MODE_SHL = 10,
|
||||
NG_PATCH_MODE_SHR = 11
|
||||
};
|
||||
|
||||
struct ng_patch_op {
|
||||
uint64_t value;
|
||||
uint32_t offset;
|
||||
uint16_t length; /* 1,2,4 or 8 (bytes) */
|
||||
uint16_t mode;
|
||||
};
|
||||
|
||||
#define NG_PATCH_OP_TYPE_INFO { \
|
||||
{ "value", &ng_parse_uint64_type }, \
|
||||
{ "offset", &ng_parse_uint32_type }, \
|
||||
{ "length", &ng_parse_uint16_type }, \
|
||||
{ "mode", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
struct ng_patch_config {
|
||||
uint32_t count;
|
||||
uint32_t csum_flags;
|
||||
struct ng_patch_op ops[];
|
||||
};
|
||||
|
||||
#define NG_PATCH_CONFIG_TYPE_INFO { \
|
||||
{ "count", &ng_parse_uint32_type }, \
|
||||
{ "csum_flags", &ng_parse_uint32_type }, \
|
||||
{ "ops", &ng_patch_confarr_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
struct ng_patch_stats {
|
||||
uint64_t received;
|
||||
uint64_t patched;
|
||||
uint64_t dropped;
|
||||
};
|
||||
|
||||
#define NG_PATCH_STATS_TYPE_INFO { \
|
||||
{ "received", &ng_parse_uint64_type }, \
|
||||
{ "patched", &ng_parse_uint64_type }, \
|
||||
{ "dropped", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#endif /* _NETGRAPH_NG_PATCH_H_ */
|
|
@ -0,0 +1,173 @@
|
|||
/*-
|
||||
* Copyright (c) 2004-2008 University of Zagreb
|
||||
* Copyright (c) 2007-2008 FreeBSD Foundation
|
||||
*
|
||||
* This software was developed by the University of Zagreb and the
|
||||
* FreeBSD Foundation under sponsorship by the Stichting NLnet and the
|
||||
* FreeBSD Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_PIPE_H_
|
||||
#define _NETGRAPH_PIPE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_PIPE_NODE_TYPE "pipe"
|
||||
#define NGM_PIPE_COOKIE 200708191
|
||||
|
||||
/* Hook names */
|
||||
#define NG_PIPE_HOOK_UPPER "upper"
|
||||
#define NG_PIPE_HOOK_LOWER "lower"
|
||||
|
||||
#define MAX_FSIZE 16384 /* Largest supported frame size, in bytes, for BER */
|
||||
#define MAX_OHSIZE 256 /* Largest supported dummy-framing size, in bytes */
|
||||
|
||||
/* Statistics structure for one hook */
|
||||
struct ng_pipe_hookstat {
|
||||
u_int64_t fwd_octets;
|
||||
u_int64_t fwd_frames;
|
||||
u_int64_t in_disc_octets;
|
||||
u_int64_t in_disc_frames;
|
||||
u_int64_t out_disc_octets;
|
||||
u_int64_t out_disc_frames;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PIPE_HOOKSTAT_INFO { \
|
||||
{ "FwdOctets", &ng_parse_uint64_type }, \
|
||||
{ "FwdFrames", &ng_parse_uint64_type }, \
|
||||
{ "queueDropOctets", &ng_parse_uint64_type }, \
|
||||
{ "queueDropFrames", &ng_parse_uint64_type }, \
|
||||
{ "delayDropOctets", &ng_parse_uint64_type }, \
|
||||
{ "delayDropFrames", &ng_parse_uint64_type }, \
|
||||
{ NULL }, \
|
||||
}
|
||||
|
||||
/* Statistics structure returned by NGM_PIPE_GET_STATS */
|
||||
struct ng_pipe_stats {
|
||||
struct ng_pipe_hookstat downstream;
|
||||
struct ng_pipe_hookstat upstream;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PIPE_STATS_INFO(hstype) { \
|
||||
{ "downstream", (hstype) }, \
|
||||
{ "upstream", (hstype) }, \
|
||||
{ NULL }, \
|
||||
}
|
||||
|
||||
/* Runtime structure for one hook */
|
||||
struct ng_pipe_hookrun {
|
||||
u_int32_t fifo_queues;
|
||||
u_int32_t qin_octets;
|
||||
u_int32_t qin_frames;
|
||||
u_int32_t qout_octets;
|
||||
u_int32_t qout_frames;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PIPE_HOOKRUN_INFO { \
|
||||
{ "queues", &ng_parse_uint32_type }, \
|
||||
{ "queuedOctets", &ng_parse_uint32_type }, \
|
||||
{ "queuedFrames", &ng_parse_uint32_type }, \
|
||||
{ "delayedOctets", &ng_parse_uint32_type }, \
|
||||
{ "delayedFrames", &ng_parse_uint32_type }, \
|
||||
{ NULL }, \
|
||||
}
|
||||
|
||||
/* Runtime structure returned by NGM_PIPE_GET_RUN */
|
||||
struct ng_pipe_run {
|
||||
struct ng_pipe_hookrun downstream;
|
||||
struct ng_pipe_hookrun upstream;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PIPE_RUN_INFO(hstype) { \
|
||||
{ "downstream", (hstype) }, \
|
||||
{ "upstream", (hstype) }, \
|
||||
{ NULL }, \
|
||||
}
|
||||
|
||||
/* Config structure for one hook */
|
||||
struct ng_pipe_hookcfg {
|
||||
u_int64_t bandwidth;
|
||||
u_int64_t ber;
|
||||
u_int32_t qin_size_limit;
|
||||
u_int32_t qout_size_limit;
|
||||
u_int32_t duplicate;
|
||||
u_int32_t fifo;
|
||||
u_int32_t drr;
|
||||
u_int32_t wfq;
|
||||
u_int32_t droptail;
|
||||
u_int32_t drophead;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PIPE_HOOKCFG_INFO { \
|
||||
{ "bandwidth", &ng_parse_uint64_type }, \
|
||||
{ "BER", &ng_parse_uint64_type }, \
|
||||
{ "queuelen", &ng_parse_uint32_type }, \
|
||||
{ "delaylen", &ng_parse_uint32_type }, \
|
||||
{ "duplicate", &ng_parse_uint32_type }, \
|
||||
{ "fifo", &ng_parse_uint32_type }, \
|
||||
{ "drr", &ng_parse_uint32_type }, \
|
||||
{ "wfq", &ng_parse_uint32_type }, \
|
||||
{ "droptail", &ng_parse_uint32_type }, \
|
||||
{ "drophead", &ng_parse_uint32_type }, \
|
||||
{ NULL }, \
|
||||
}
|
||||
|
||||
/* Config structure returned by NGM_PIPE_GET_CFG */
|
||||
struct ng_pipe_cfg {
|
||||
u_int64_t bandwidth;
|
||||
u_int64_t delay;
|
||||
u_int32_t header_offset;
|
||||
u_int32_t overhead;
|
||||
struct ng_pipe_hookcfg downstream;
|
||||
struct ng_pipe_hookcfg upstream;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PIPE_CFG_INFO(hstype) { \
|
||||
{ "bandwidth", &ng_parse_uint64_type }, \
|
||||
{ "delay", &ng_parse_uint64_type }, \
|
||||
{ "header_offset", &ng_parse_uint32_type }, \
|
||||
{ "overhead", &ng_parse_uint32_type }, \
|
||||
{ "downstream", (hstype) }, \
|
||||
{ "upstream", (hstype) }, \
|
||||
{ NULL }, \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_PIPE_GET_STATS=1, /* get stats */
|
||||
NGM_PIPE_CLR_STATS, /* clear stats */
|
||||
NGM_PIPE_GETCLR_STATS, /* atomically get and clear stats */
|
||||
NGM_PIPE_GET_RUN, /* get current runtime status */
|
||||
NGM_PIPE_GET_CFG, /* get configurable parameters */
|
||||
NGM_PIPE_SET_CFG, /* set configurable parameters */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_PIPE_H_ */
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
* ng_ppp.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996-2000 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_ppp.h,v 1.8 1999/01/25 02:40:02 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_PPP_H_
|
||||
#define _NETGRAPH_NG_PPP_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_PPP_NODE_TYPE "ppp"
|
||||
#define NGM_PPP_COOKIE 940897795
|
||||
|
||||
/* 64bit stats presence flag */
|
||||
#define NG_PPP_STATS64
|
||||
|
||||
/* Maximum number of supported links */
|
||||
#define NG_PPP_MAX_LINKS 16
|
||||
|
||||
/* Pseudo-link number representing the multi-link bundle */
|
||||
#define NG_PPP_BUNDLE_LINKNUM 0xffff
|
||||
|
||||
/* Max allowable link latency (miliseconds) and bandwidth (bytes/second/10) */
|
||||
#define NG_PPP_MAX_LATENCY 1000 /* 1 second */
|
||||
#define NG_PPP_MAX_BANDWIDTH 125000 /* 10 Mbits / second */
|
||||
|
||||
/* Hook names */
|
||||
#define NG_PPP_HOOK_BYPASS "bypass" /* unknown protocols */
|
||||
#define NG_PPP_HOOK_COMPRESS "compress" /* outgoing compression */
|
||||
#define NG_PPP_HOOK_DECOMPRESS "decompress" /* incoming decompression */
|
||||
#define NG_PPP_HOOK_ENCRYPT "encrypt" /* outgoing encryption */
|
||||
#define NG_PPP_HOOK_DECRYPT "decrypt" /* incoming decryption */
|
||||
#define NG_PPP_HOOK_VJC_IP "vjc_ip" /* VJC raw IP */
|
||||
#define NG_PPP_HOOK_VJC_COMP "vjc_vjcomp" /* VJC compressed TCP */
|
||||
#define NG_PPP_HOOK_VJC_UNCOMP "vjc_vjuncomp" /* VJC uncompressed TCP */
|
||||
#define NG_PPP_HOOK_VJC_VJIP "vjc_vjip" /* VJC uncompressed IP */
|
||||
#define NG_PPP_HOOK_INET "inet" /* IP packet data */
|
||||
#define NG_PPP_HOOK_ATALK "atalk" /* AppleTalk packet data */
|
||||
#define NG_PPP_HOOK_IPX "ipx" /* IPX packet data */
|
||||
#define NG_PPP_HOOK_IPV6 "ipv6" /* IPv6 packet data */
|
||||
|
||||
#define NG_PPP_HOOK_LINK_PREFIX "link" /* append decimal link number */
|
||||
|
||||
/* Compress hook operation modes */
|
||||
enum {
|
||||
NG_PPP_COMPRESS_NONE = 0, /* compression disabled */
|
||||
NG_PPP_COMPRESS_SIMPLE, /* original operation mode */
|
||||
NG_PPP_COMPRESS_FULL, /* compressor returns proto */
|
||||
};
|
||||
|
||||
/* Decompress hook operation modes */
|
||||
enum {
|
||||
NG_PPP_DECOMPRESS_NONE = 0, /* decompression disabled */
|
||||
NG_PPP_DECOMPRESS_SIMPLE, /* original operation mode */
|
||||
NG_PPP_DECOMPRESS_FULL, /* forward any packet to decompressor */
|
||||
};
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_PPP_SET_CONFIG = 1, /* takes struct ng_ppp_node_conf */
|
||||
NGM_PPP_GET_CONFIG, /* returns ng_ppp_node_conf */
|
||||
NGM_PPP_GET_MP_STATE, /* returns ng_ppp_mp_state */
|
||||
NGM_PPP_GET_LINK_STATS, /* takes link #, returns stats struct */
|
||||
NGM_PPP_CLR_LINK_STATS, /* takes link #, clears link stats */
|
||||
NGM_PPP_GETCLR_LINK_STATS, /* takes link #, returns & clrs stats */
|
||||
NGM_PPP_GET_LINK_STATS64, /* takes link #, returns stats64 struct */
|
||||
NGM_PPP_GETCLR_LINK_STATS64, /* takes link #, returns stats64 & clrs */
|
||||
};
|
||||
|
||||
/* Multi-link sequence number state (for debugging) */
|
||||
struct ng_ppp_mp_state {
|
||||
int32_t rseq[NG_PPP_MAX_LINKS]; /* highest rec'd MP seq # */
|
||||
int32_t mseq; /* min rseq[i] */
|
||||
int32_t xseq; /* next xmit MP seq # */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPP_MP_STATE_TYPE_INFO(atype) { \
|
||||
{ "rseq", (atype) }, \
|
||||
{ "mseq", &ng_parse_hint32_type }, \
|
||||
{ "xseq", &ng_parse_hint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Per-link config structure */
|
||||
struct ng_ppp_link_conf {
|
||||
u_char enableLink; /* enable this link */
|
||||
u_char enableProtoComp;/* enable protocol field compression */
|
||||
u_char enableACFComp; /* enable addr/ctrl field compression */
|
||||
u_int16_t mru; /* peer MRU */
|
||||
u_int32_t latency; /* link latency (in milliseconds) */
|
||||
u_int32_t bandwidth; /* link bandwidth (in bytes/sec/10) */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPP_LINK_TYPE_INFO { \
|
||||
{ "enableLink", &ng_parse_uint8_type }, \
|
||||
{ "enableProtoComp", &ng_parse_uint8_type }, \
|
||||
{ "enableACFComp", &ng_parse_uint8_type }, \
|
||||
{ "mru", &ng_parse_uint16_type }, \
|
||||
{ "latency", &ng_parse_uint32_type }, \
|
||||
{ "bandwidth", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Bundle config structure */
|
||||
struct ng_ppp_bund_conf {
|
||||
u_int16_t mrru; /* multilink peer MRRU */
|
||||
u_char enableMultilink; /* enable multilink */
|
||||
u_char recvShortSeq; /* recv multilink short seq # */
|
||||
u_char xmitShortSeq; /* xmit multilink short seq # */
|
||||
u_char enableRoundRobin; /* xmit whole packets */
|
||||
u_char enableIP; /* enable IP data flow */
|
||||
u_char enableIPv6; /* enable IPv6 data flow */
|
||||
u_char enableAtalk; /* enable AppleTalk data flow */
|
||||
u_char enableIPX; /* enable IPX data flow */
|
||||
u_char enableCompression; /* enable PPP compression */
|
||||
u_char enableDecompression; /* enable PPP decompression */
|
||||
u_char enableEncryption; /* enable PPP encryption */
|
||||
u_char enableDecryption; /* enable PPP decryption */
|
||||
u_char enableVJCompression; /* enable VJ compression */
|
||||
u_char enableVJDecompression; /* enable VJ decompression */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPP_BUND_TYPE_INFO { \
|
||||
{ "mrru", &ng_parse_uint16_type }, \
|
||||
{ "enableMultilink", &ng_parse_uint8_type }, \
|
||||
{ "recvShortSeq", &ng_parse_uint8_type }, \
|
||||
{ "xmitShortSeq", &ng_parse_uint8_type }, \
|
||||
{ "enableRoundRobin", &ng_parse_uint8_type }, \
|
||||
{ "enableIP", &ng_parse_uint8_type }, \
|
||||
{ "enableIPv6", &ng_parse_uint8_type }, \
|
||||
{ "enableAtalk", &ng_parse_uint8_type }, \
|
||||
{ "enableIPX", &ng_parse_uint8_type }, \
|
||||
{ "enableCompression", &ng_parse_uint8_type }, \
|
||||
{ "enableDecompression", &ng_parse_uint8_type }, \
|
||||
{ "enableEncryption", &ng_parse_uint8_type }, \
|
||||
{ "enableDecryption", &ng_parse_uint8_type }, \
|
||||
{ "enableVJCompression", &ng_parse_uint8_type }, \
|
||||
{ "enableVJDecompression", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Total node config structure */
|
||||
struct ng_ppp_node_conf {
|
||||
struct ng_ppp_bund_conf bund;
|
||||
struct ng_ppp_link_conf links[NG_PPP_MAX_LINKS];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPP_CONFIG_TYPE_INFO(bctype, arytype) { \
|
||||
{ "bund", (bctype) }, \
|
||||
{ "links", (arytype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics struct for a link (or the bundle if NG_PPP_BUNDLE_LINKNUM) */
|
||||
struct ng_ppp_link_stat {
|
||||
u_int32_t xmitFrames; /* xmit frames on link */
|
||||
u_int32_t xmitOctets; /* xmit octets on link */
|
||||
u_int32_t recvFrames; /* recv frames on link */
|
||||
u_int32_t recvOctets; /* recv octets on link */
|
||||
u_int32_t badProtos; /* frames rec'd with bogus protocol */
|
||||
u_int32_t runts; /* Too short MP fragments */
|
||||
u_int32_t dupFragments; /* MP frames with duplicate seq # */
|
||||
u_int32_t dropFragments; /* MP fragments we had to drop */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPP_STATS_TYPE_INFO { \
|
||||
{ "xmitFrames", &ng_parse_uint32_type }, \
|
||||
{ "xmitOctets", &ng_parse_uint32_type }, \
|
||||
{ "recvFrames", &ng_parse_uint32_type }, \
|
||||
{ "recvOctets", &ng_parse_uint32_type }, \
|
||||
{ "badProtos", &ng_parse_uint32_type }, \
|
||||
{ "runts", &ng_parse_uint32_type }, \
|
||||
{ "dupFragments", &ng_parse_uint32_type }, \
|
||||
{ "dropFragments", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics struct for a link (or the bundle if NG_PPP_BUNDLE_LINKNUM) */
|
||||
struct ng_ppp_link_stat64 {
|
||||
u_int64_t xmitFrames; /* xmit frames on link */
|
||||
u_int64_t xmitOctets; /* xmit octets on link */
|
||||
u_int64_t recvFrames; /* recv frames on link */
|
||||
u_int64_t recvOctets; /* recv octets on link */
|
||||
u_int64_t badProtos; /* frames rec'd with bogus protocol */
|
||||
u_int64_t runts; /* Too short MP fragments */
|
||||
u_int64_t dupFragments; /* MP frames with duplicate seq # */
|
||||
u_int64_t dropFragments; /* MP fragments we had to drop */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPP_STATS64_TYPE_INFO { \
|
||||
{ "xmitFrames", &ng_parse_uint64_type }, \
|
||||
{ "xmitOctets", &ng_parse_uint64_type }, \
|
||||
{ "recvFrames", &ng_parse_uint64_type }, \
|
||||
{ "recvOctets", &ng_parse_uint64_type }, \
|
||||
{ "badProtos", &ng_parse_uint64_type }, \
|
||||
{ "runts", &ng_parse_uint64_type }, \
|
||||
{ "dupFragments", &ng_parse_uint64_type }, \
|
||||
{ "dropFragments", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#endif /* _NETGRAPH_NG_PPP_H_ */
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* ng_pppoe.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_pppoe.h,v 1.7 1999/10/16 10:16:43 julian Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_PPPOE_H_
|
||||
#define _NETGRAPH_NG_PPPOE_H_
|
||||
|
||||
#ifndef __packed
|
||||
#define __packed __attribute__((__packed__))
|
||||
#endif
|
||||
|
||||
/********************************************************************
|
||||
* Netgraph hook constants etc.
|
||||
********************************************************************/
|
||||
/* Node type name. This should be unique among all netgraph node types */
|
||||
#define NG_PPPOE_NODE_TYPE "pppoe"
|
||||
|
||||
#define NGM_PPPOE_COOKIE 1089893072
|
||||
#define NGM_PPPOE_SETMAXP_COOKIE 1441624322
|
||||
|
||||
#define PPPOE_SERVICE_NAME_SIZE 64 /* for now */
|
||||
|
||||
/* Hook names */
|
||||
#define NG_PPPOE_HOOK_ETHERNET "ethernet"
|
||||
#define NG_PPPOE_HOOK_DEBUG "debug"
|
||||
|
||||
/* Mode names */
|
||||
#define NG_PPPOE_STANDARD "standard"
|
||||
#define NG_PPPOE_3COM "3Com"
|
||||
#define NG_PPPOE_NONSTANDARD NG_PPPOE_3COM
|
||||
#define NG_PPPOE_DLINK "D-Link"
|
||||
|
||||
/**********************************************************************
|
||||
* Netgraph commands understood by this node type.
|
||||
* FAIL, SUCCESS, CLOSE and ACNAME are sent by the node rather than received.
|
||||
********************************************************************/
|
||||
enum cmd {
|
||||
NGM_PPPOE_SET_FLAG = 1,
|
||||
NGM_PPPOE_CONNECT = 2, /* Client, Try find this service */
|
||||
NGM_PPPOE_LISTEN = 3, /* Server, Await a request for this service */
|
||||
NGM_PPPOE_OFFER = 4, /* Server, hook X should respond (*) */
|
||||
NGM_PPPOE_SUCCESS = 5, /* State machine connected */
|
||||
NGM_PPPOE_FAIL = 6, /* State machine could not connect */
|
||||
NGM_PPPOE_CLOSE = 7, /* Session closed down */
|
||||
NGM_PPPOE_SERVICE = 8, /* additional Service to advertise (in PADO) */
|
||||
NGM_PPPOE_ACNAME = 9, /* AC_NAME for informational purposes */
|
||||
NGM_PPPOE_GET_STATUS = 10, /* data in/out */
|
||||
NGM_PPPOE_SESSIONID = 11, /* Session_ID for informational purposes */
|
||||
NGM_PPPOE_SETMODE = 12, /* set to standard or compat modes */
|
||||
NGM_PPPOE_GETMODE = 13, /* see current mode */
|
||||
NGM_PPPOE_SETENADDR = 14, /* set Ethernet address */
|
||||
NGM_PPPOE_SETMAXP = 15 /* Set PPP-Max-Payload value */
|
||||
};
|
||||
|
||||
/***********************
|
||||
* Structures passed in the various netgraph command messages.
|
||||
***********************/
|
||||
/* This structure is returned by the NGM_PPPOE_GET_STATUS command */
|
||||
struct ngpppoestat {
|
||||
u_int packets_in; /* packets in from ethernet */
|
||||
u_int packets_out; /* packets out towards ethernet */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPPOESTAT_TYPE_INFO { \
|
||||
{ "packets_in", &ng_parse_uint_type }, \
|
||||
{ "packets_out", &ng_parse_uint_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/*
|
||||
* When this structure is accepted by the NGM_PPPOE_CONNECT command :
|
||||
* The data field is MANDATORY.
|
||||
* The session sends out a PADI request for the named service.
|
||||
*
|
||||
*
|
||||
* When this structure is accepted by the NGM_PPPOE_LISTEN command.
|
||||
* If no service is given this is assumed to accept ALL PADI requests.
|
||||
* This may at some time take a regexp expression, but not yet.
|
||||
* Matching PADI requests will be passed up the named hook.
|
||||
*
|
||||
*
|
||||
* When this structure is accepted by the NGM_PPPOE_OFFER command:
|
||||
* The AC-NAme field is set from that given and a PADI
|
||||
* packet is expected to arrive from the session control daemon, on the
|
||||
* named hook. The session will then issue the appropriate PADO
|
||||
* and begin negotiation.
|
||||
*/
|
||||
struct ngpppoe_init_data {
|
||||
char hook[NG_HOOKSIZ]; /* hook to monitor on */
|
||||
u_int16_t data_len; /* Length of the service name */
|
||||
char data[]; /* init data goes here */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPPOE_INIT_DATA_TYPE_INFO { \
|
||||
{ "hook", &ng_parse_hookbuf_type }, \
|
||||
{ "data", &ng_parse_sizedstring_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/*
|
||||
* This structure is used by the asychronous success and failure messages.
|
||||
* (to report which hook has failed or connected). The message is sent
|
||||
* to whoever requested the connection. (close may use this too).
|
||||
*/
|
||||
struct ngpppoe_sts {
|
||||
char hook[NG_HOOKSIZ]; /* hook associated with event session */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPPOE_STS_TYPE_INFO { \
|
||||
{ "hook", &ng_parse_hookbuf_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/*
|
||||
* This structure is used to send PPP-Max-Payload value from server to client.
|
||||
*/
|
||||
struct ngpppoe_maxp {
|
||||
char hook[NG_HOOKSIZ]; /* hook associated with event session */
|
||||
uint16_t data;
|
||||
};
|
||||
|
||||
/********************************************************************
|
||||
* Constants and definitions specific to pppoe
|
||||
********************************************************************/
|
||||
|
||||
#define PPPOE_TIMEOUT_LIMIT 64
|
||||
#define PPPOE_OFFER_TIMEOUT 16
|
||||
#define PPPOE_INITIAL_TIMEOUT 2
|
||||
|
||||
/* Codes to identify message types */
|
||||
#define PADI_CODE 0x09
|
||||
#define PADO_CODE 0x07
|
||||
#define PADR_CODE 0x19
|
||||
#define PADS_CODE 0x65
|
||||
#define PADT_CODE 0xa7
|
||||
|
||||
/* Tag identifiers */
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define PTT_EOL (0x0000)
|
||||
#define PTT_SRV_NAME (0x0101)
|
||||
#define PTT_AC_NAME (0x0102)
|
||||
#define PTT_HOST_UNIQ (0x0103)
|
||||
#define PTT_AC_COOKIE (0x0104)
|
||||
#define PTT_VENDOR (0x0105)
|
||||
#define PTT_RELAY_SID (0x0110)
|
||||
#define PTT_MAX_PAYL (0x0120) /* PPP-Max-Payload (RFC4638) */
|
||||
#define PTT_SRV_ERR (0x0201)
|
||||
#define PTT_SYS_ERR (0x0202)
|
||||
#define PTT_GEN_ERR (0x0203)
|
||||
|
||||
#define ETHERTYPE_PPPOE_DISC 0x8863 /* pppoe discovery packets */
|
||||
#define ETHERTYPE_PPPOE_SESS 0x8864 /* pppoe session packets */
|
||||
#define ETHERTYPE_PPPOE_3COM_DISC 0x3c12 /* pppoe discovery packets 3com? */
|
||||
#define ETHERTYPE_PPPOE_3COM_SESS 0x3c13 /* pppoe session packets 3com? */
|
||||
#else
|
||||
#define PTT_EOL (0x0000)
|
||||
#define PTT_SRV_NAME (0x0101)
|
||||
#define PTT_AC_NAME (0x0201)
|
||||
#define PTT_HOST_UNIQ (0x0301)
|
||||
#define PTT_AC_COOKIE (0x0401)
|
||||
#define PTT_VENDOR (0x0501)
|
||||
#define PTT_RELAY_SID (0x1001)
|
||||
#define PTT_MAX_PAYL (0x2001) /* PPP-Max-Payload (RFC4638) */
|
||||
#define PTT_SRV_ERR (0x0102)
|
||||
#define PTT_SYS_ERR (0x0202)
|
||||
#define PTT_GEN_ERR (0x0302)
|
||||
|
||||
#define ETHERTYPE_PPPOE_DISC 0x6388 /* pppoe discovery packets */
|
||||
#define ETHERTYPE_PPPOE_SESS 0x6488 /* pppoe session packets */
|
||||
#define ETHERTYPE_PPPOE_3COM_DISC 0x123c /* pppoe discovery packets 3com? */
|
||||
#define ETHERTYPE_PPPOE_3COM_SESS 0x133c /* pppoe session packets 3com? */
|
||||
#endif
|
||||
|
||||
struct pppoe_tag {
|
||||
u_int16_t tag_type;
|
||||
u_int16_t tag_len;
|
||||
}__packed;
|
||||
|
||||
struct pppoe_hdr{
|
||||
u_int8_t ver:4;
|
||||
u_int8_t type:4;
|
||||
u_int8_t code;
|
||||
u_int16_t sid;
|
||||
u_int16_t length;
|
||||
}__packed;
|
||||
|
||||
|
||||
struct pppoe_full_hdr {
|
||||
struct ether_header eh;
|
||||
struct pppoe_hdr ph;
|
||||
}__packed;
|
||||
|
||||
union packet {
|
||||
struct pppoe_full_hdr pkt_header;
|
||||
u_int8_t bytes[2048];
|
||||
};
|
||||
|
||||
struct datatag {
|
||||
struct pppoe_tag hdr;
|
||||
u_int8_t data[PPPOE_SERVICE_NAME_SIZE];
|
||||
};
|
||||
|
||||
struct maxptag {
|
||||
struct pppoe_tag hdr;
|
||||
uint16_t data;
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the order in which we will place tags in packets
|
||||
* this may be ignored
|
||||
*/
|
||||
/* for PADI */
|
||||
#define TAGI_SVC 0
|
||||
#define TAGI_HUNIQ 1
|
||||
/* for PADO */
|
||||
#define TAGO_ACNAME 0
|
||||
#define TAGO_SVC 1
|
||||
#define TAGO_COOKIE 2
|
||||
#define TAGO_HUNIQ 3
|
||||
/* for PADR */
|
||||
#define TAGR_SVC 0
|
||||
#define TAGR_HUNIQ 1
|
||||
#define TAGR_COOKIE 2
|
||||
/* for PADS */
|
||||
#define TAGS_ACNAME 0
|
||||
#define TAGS_SVC 1
|
||||
#define TAGS_COOKIE 2
|
||||
#define TAGS_HUNIQ 3
|
||||
/* for PADT */
|
||||
|
||||
#endif /* _NETGRAPH_NG_PPPOE_H_ */
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* ng_pptpgre.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 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_pptpgre.h,v 1.3 1999/12/08 00:11:36 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_PPTPGRE_H_
|
||||
#define _NETGRAPH_NG_PPTPGRE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_PPTPGRE_NODE_TYPE "pptpgre"
|
||||
#define NGM_PPTPGRE_COOKIE 1082548365
|
||||
|
||||
/* Hook names */
|
||||
#define NG_PPTPGRE_HOOK_UPPER "upper" /* to upper layers */
|
||||
#define NG_PPTPGRE_HOOK_LOWER "lower" /* to lower layers */
|
||||
|
||||
/* Session hooks: prefix plus hex session ID, e.g., "session_3e14" */
|
||||
#define NG_PPTPGRE_HOOK_SESSION_P "session_"
|
||||
#define NG_PPTPGRE_HOOK_SESSION_F "session_%04x"
|
||||
|
||||
/* Configuration for a session */
|
||||
struct ng_pptpgre_conf {
|
||||
u_char enabled; /* enables traffic flow */
|
||||
u_char enableDelayedAck;/* enables delayed acks */
|
||||
u_char enableAlwaysAck;/* always include ack with data */
|
||||
u_char enableWindowing;/* enable windowing algorithm */
|
||||
u_int16_t cid; /* my call id */
|
||||
u_int16_t peerCid; /* peer call id */
|
||||
u_int16_t recvWin; /* peer recv window size */
|
||||
u_int16_t peerPpd; /* peer packet processing delay
|
||||
(in units of 1/10 of a second) */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPTPGRE_CONF_TYPE_INFO { \
|
||||
{ "enabled", &ng_parse_uint8_type }, \
|
||||
{ "enableDelayedAck", &ng_parse_uint8_type }, \
|
||||
{ "enableAlwaysAck", &ng_parse_uint8_type }, \
|
||||
{ "enableWindowing", &ng_parse_uint8_type }, \
|
||||
{ "cid", &ng_parse_hint16_type }, \
|
||||
{ "peerCid", &ng_parse_hint16_type }, \
|
||||
{ "recvWin", &ng_parse_uint16_type }, \
|
||||
{ "peerPpd", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics struct */
|
||||
struct ng_pptpgre_stats {
|
||||
u_int32_t xmitPackets; /* number of GRE packets xmit */
|
||||
u_int32_t xmitOctets; /* number of GRE octets xmit */
|
||||
u_int32_t xmitLoneAcks; /* ack-only packets transmitted */
|
||||
u_int32_t xmitDrops; /* xmits dropped due to full window */
|
||||
u_int32_t xmitTooBig; /* xmits dropped because too big */
|
||||
u_int32_t recvPackets; /* number of GRE packets rec'd */
|
||||
u_int32_t recvOctets; /* number of GRE octets rec'd */
|
||||
u_int32_t recvRunts; /* too short packets rec'd */
|
||||
u_int32_t recvBadGRE; /* bogus packets rec'd (bad GRE hdr) */
|
||||
u_int32_t recvBadAcks; /* bogus ack's rec'd in GRE header */
|
||||
u_int32_t recvBadCID; /* pkts with unknown call ID rec'd */
|
||||
u_int32_t recvOutOfOrder; /* packets rec'd out of order */
|
||||
u_int32_t recvDuplicates; /* packets rec'd with duplicate seq # */
|
||||
u_int32_t recvLoneAcks; /* ack-only packets rec'd */
|
||||
u_int32_t recvAckTimeouts; /* times peer failed to ack in time */
|
||||
u_int32_t memoryFailures; /* times we couldn't allocate memory */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_PPTPGRE_STATS_TYPE_INFO { \
|
||||
{ "xmitPackets", &ng_parse_uint32_type }, \
|
||||
{ "xmitOctets", &ng_parse_uint32_type }, \
|
||||
{ "xmitLoneAcks", &ng_parse_uint32_type }, \
|
||||
{ "xmitDrops", &ng_parse_uint32_type }, \
|
||||
{ "xmitTooBig", &ng_parse_uint32_type }, \
|
||||
{ "recvPackets", &ng_parse_uint32_type }, \
|
||||
{ "recvOctets", &ng_parse_uint32_type }, \
|
||||
{ "recvRunts", &ng_parse_uint32_type }, \
|
||||
{ "recvBadGRE", &ng_parse_uint32_type }, \
|
||||
{ "recvBadAcks", &ng_parse_uint32_type }, \
|
||||
{ "recvBadCID", &ng_parse_uint32_type }, \
|
||||
{ "recvOutOfOrder", &ng_parse_uint32_type }, \
|
||||
{ "recvDuplicates", &ng_parse_uint32_type }, \
|
||||
{ "recvLoneAcks", &ng_parse_uint32_type }, \
|
||||
{ "recvAckTimeouts", &ng_parse_uint32_type }, \
|
||||
{ "memoryFailures", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_PPTPGRE_SET_CONFIG = 1, /* supply a struct ng_pptpgre_conf */
|
||||
NGM_PPTPGRE_GET_CONFIG, /* returns a struct ng_pptpgre_conf */
|
||||
NGM_PPTPGRE_GET_STATS, /* returns struct ng_pptpgre_stats */
|
||||
NGM_PPTPGRE_CLR_STATS, /* clears stats */
|
||||
NGM_PPTPGRE_GETCLR_STATS, /* returns & clears stats */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_PPTPGRE_H_ */
|
|
@ -0,0 +1,83 @@
|
|||
/*-
|
||||
* Copyright (c) 2006 Alexander Motin <mav@alkar.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 unmodified, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_PRED1_H_
|
||||
#define _NETGRAPH_NG_PRED1_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_PRED1_NODE_TYPE "pred1"
|
||||
#define NGM_PRED1_COOKIE 1166902612
|
||||
|
||||
/* Hook names */
|
||||
#define NG_PRED1_HOOK_COMP "comp" /* compression hook */
|
||||
#define NG_PRED1_HOOK_DECOMP "decomp" /* decompression hook */
|
||||
|
||||
/* Config struct */
|
||||
struct ng_pred1_config {
|
||||
u_char enable; /* node enabled */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_PRED1_CONFIG_INFO { \
|
||||
{ "enable", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics structure for one direction. */
|
||||
struct ng_pred1_stats {
|
||||
uint64_t FramesPlain;
|
||||
uint64_t FramesComp;
|
||||
uint64_t FramesUncomp;
|
||||
uint64_t InOctets;
|
||||
uint64_t OutOctets;
|
||||
uint64_t Errors;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_PRED1_STATS_INFO { \
|
||||
{ "FramesPlain",&ng_parse_uint64_type }, \
|
||||
{ "FramesComp", &ng_parse_uint64_type }, \
|
||||
{ "FramesUncomp", &ng_parse_uint64_type }, \
|
||||
{ "InOctets", &ng_parse_uint64_type }, \
|
||||
{ "OutOctets", &ng_parse_uint64_type }, \
|
||||
{ "Errors", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_PRED1_CONFIG = 1,
|
||||
NGM_PRED1_RESETREQ, /* sent either way! */
|
||||
NGM_PRED1_GET_STATS,
|
||||
NGM_PRED1_CLR_STATS,
|
||||
NGM_PRED1_GETCLR_STATS,
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_PRED1_H_ */
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* ng_rfc1490.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_rfc1490.h,v 1.7 1999/01/20 00:54:15 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_RFC1490_H_
|
||||
#define _NETGRAPH_NG_RFC1490_H_
|
||||
|
||||
/* Node type name */
|
||||
#define NG_RFC1490_NODE_TYPE "rfc1490"
|
||||
#define NGM_RFC1490_COOKIE 1086947474
|
||||
|
||||
/* Hook names */
|
||||
#define NG_RFC1490_HOOK_DOWNSTREAM "downstream"
|
||||
#define NG_RFC1490_HOOK_INET "inet"
|
||||
#define NG_RFC1490_HOOK_PPP "ppp"
|
||||
#define NG_RFC1490_HOOK_ETHERNET "ethernet"
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_RFC1490_SET_ENCAP, /* sets encapsulation method */
|
||||
NGM_RFC1490_GET_ENCAP, /* gets current encapsulation method */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_RFC1490_H_ */
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* ng_sample.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_sample.h,v 1.3 1999/01/20 00:22:14 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_SAMPLE_H_
|
||||
#define _NETGRAPH_NG_SAMPLE_H_
|
||||
|
||||
/* Node type name. This should be unique among all netgraph node types */
|
||||
#define NG_XXX_NODE_TYPE "sample"
|
||||
|
||||
/* Node type cookie. Should also be unique. This value MUST change whenever
|
||||
an incompatible change is made to this header file, to insure consistency.
|
||||
The de facto method for generating cookies is to take the output of the
|
||||
date command: date -u +'%s' */
|
||||
#define NGM_XXX_COOKIE 915491374
|
||||
|
||||
/* Number of active DLCI's we can handle */
|
||||
#define XXX_NUM_DLCIS 16
|
||||
|
||||
/* Hook names */
|
||||
#define NG_XXX_HOOK_DLCI_LEADIN "dlci"
|
||||
#define NG_XXX_HOOK_DOWNSTREAM "downstream"
|
||||
#define NG_XXX_HOOK_DEBUG "debug"
|
||||
|
||||
/* Netgraph commands understood by this node type */
|
||||
enum {
|
||||
NGM_XXX_SET_FLAG = 1,
|
||||
NGM_XXX_GET_STATUS,
|
||||
};
|
||||
|
||||
/* This structure is returned by the NGM_XXX_GET_STATUS command */
|
||||
struct ngxxxstat {
|
||||
u_int32_t packets_in; /* packets in from downstream */
|
||||
u_int32_t packets_out; /* packets out towards downstream */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is used to define the 'parse type' for a struct ngxxxstat, which
|
||||
* is bascially a description of how to convert a binary struct ngxxxstat
|
||||
* to an ASCII string and back. See ng_parse.h for more info.
|
||||
*
|
||||
* This needs to be kept in sync with the above structure definition
|
||||
*/
|
||||
#define NG_XXX_STATS_TYPE_INFO { \
|
||||
{ "packets_in", &ng_parse_uint32_type }, \
|
||||
{ "packets_out", &ng_parse_uint32_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#endif /* _NETGRAPH_NG_SAMPLE_H_ */
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* netgraph.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_socketvar.h,v 1.1 1999/01/20 21:35:39 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_SOCKETVAR_H_
|
||||
#define _NETGRAPH_NG_SOCKETVAR_H_
|
||||
|
||||
/* Netgraph protocol control block for each socket */
|
||||
struct ngpcb {
|
||||
struct socket *ng_socket; /* the socket */
|
||||
struct ngsock *sockdata; /* netgraph info */
|
||||
LIST_ENTRY(ngpcb) socks; /* linked list of sockets */
|
||||
int type; /* NG_CONTROL or NG_DATA */
|
||||
ng_ID_t node_id; /* a hint for netstat(1) to find the node */
|
||||
};
|
||||
#endif /* _NETGRAPH_NG_SOCKETVAR_H_ */
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* ng_source.h
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright 2002 Sandvine 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 Sandvine Inc.; 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 Sandvine Inc.
|
||||
* trademarks, including the mark "SANDVINE" on advertising, endorsements,
|
||||
* or otherwise except as such appears in the above copyright notice or in
|
||||
* the software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED BY SANDVINE "AS IS", AND TO THE MAXIMUM
|
||||
* EXTENT PERMITTED BY LAW, SANDVINE 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. SANDVINE 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 SANDVINE 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 SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* Author: Dave Chapeskie
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_SOURCE_H_
|
||||
#define _NETGRAPH_NG_SOURCE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_SOURCE_NODE_TYPE "source"
|
||||
#define NGM_SOURCE_COOKIE 1110646684
|
||||
|
||||
/* Hook names */
|
||||
#define NG_SOURCE_HOOK_INPUT "input"
|
||||
#define NG_SOURCE_HOOK_OUTPUT "output"
|
||||
|
||||
/* Statistics structure returned by NGM_SOURCE_GET_STATS */
|
||||
struct ng_source_stats {
|
||||
uint64_t outOctets;
|
||||
uint64_t outFrames;
|
||||
uint32_t queueOctets;
|
||||
uint32_t queueFrames;
|
||||
uint32_t maxPps;
|
||||
struct timeval startTime;
|
||||
struct timeval endTime;
|
||||
struct timeval elapsedTime;
|
||||
struct timeval lastTime;
|
||||
};
|
||||
|
||||
extern const struct ng_parse_type ng_source_timeval_type;
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_SOURCE_STATS_TYPE_INFO { \
|
||||
{ "outOctets", &ng_parse_uint64_type }, \
|
||||
{ "outFrames", &ng_parse_uint64_type }, \
|
||||
{ "queueOctets", &ng_parse_uint32_type }, \
|
||||
{ "queueFrames", &ng_parse_uint32_type }, \
|
||||
{ "maxPps", &ng_parse_uint32_type }, \
|
||||
{ "startTime", &ng_source_timeval_type }, \
|
||||
{ "endTime", &ng_source_timeval_type }, \
|
||||
{ "elapsedTime", &ng_source_timeval_type }, \
|
||||
{ "lastTime", &ng_source_timeval_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Packet embedding info for NGM_SOURCE_GET/SET_TIMESTAMP */
|
||||
struct ng_source_embed_info {
|
||||
uint16_t offset; /* offset from ethernet header */
|
||||
uint8_t flags;
|
||||
uint8_t spare;
|
||||
};
|
||||
#define NGM_SOURCE_EMBED_ENABLE 0x01 /* enable embedding */
|
||||
#define NGM_SOURCE_INC_CNT_PER_LIST 0x02 /* increment once per list */
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_SOURCE_EMBED_TYPE_INFO { \
|
||||
{ "offset", &ng_parse_hint16_type }, \
|
||||
{ "flags", &ng_parse_hint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Packet embedding info for NGM_SOURCE_GET/SET_COUNTER */
|
||||
#define NG_SOURCE_COUNTERS 4
|
||||
struct ng_source_embed_cnt_info {
|
||||
uint16_t offset; /* offset from ethernet header */
|
||||
uint8_t flags; /* as above */
|
||||
uint8_t width; /* in bytes (1, 2, 4) */
|
||||
uint32_t next_val;
|
||||
uint32_t min_val;
|
||||
uint32_t max_val;
|
||||
int32_t increment;
|
||||
uint8_t index; /* which counter (0..3) */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_SOURCE_EMBED_CNT_TYPE_INFO { \
|
||||
{ "offset", &ng_parse_hint16_type }, \
|
||||
{ "flags", &ng_parse_hint8_type }, \
|
||||
{ "width", &ng_parse_uint8_type }, \
|
||||
{ "next_val", &ng_parse_uint32_type }, \
|
||||
{ "min_val", &ng_parse_uint32_type }, \
|
||||
{ "max_val", &ng_parse_uint32_type }, \
|
||||
{ "increment", &ng_parse_int32_type }, \
|
||||
{ "index", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_SOURCE_GET_STATS = 1, /* get stats */
|
||||
NGM_SOURCE_CLR_STATS, /* clear stats */
|
||||
NGM_SOURCE_GETCLR_STATS, /* atomically get and clear stats */
|
||||
NGM_SOURCE_START, /* start sending queued data */
|
||||
NGM_SOURCE_STOP, /* stop sending queued data */
|
||||
NGM_SOURCE_CLR_DATA, /* clear the queued data */
|
||||
NGM_SOURCE_SETIFACE, /* configure downstream iface */
|
||||
NGM_SOURCE_SETPPS, /* rate-limiting packets per second */
|
||||
NGM_SOURCE_SET_TIMESTAMP, /* embed xmit timestamp */
|
||||
NGM_SOURCE_GET_TIMESTAMP,
|
||||
NGM_SOURCE_SET_COUNTER, /* embed counter */
|
||||
NGM_SOURCE_GET_COUNTER,
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_SOURCE_H_ */
|
|
@ -0,0 +1,45 @@
|
|||
/*-
|
||||
*
|
||||
* Copyright (c) 1999-2000, Vitaly V Belekhov
|
||||
* 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 unmodified, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NETGRAPH_NG_SPLIT_H_
|
||||
#define _NETGRAPH_NG_SPLIT_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_SPLIT_NODE_TYPE "split"
|
||||
#define NGM_SPLIT_COOKIE 949409402
|
||||
|
||||
/* My hook names */
|
||||
#define NG_SPLIT_HOOK_MIXED "mixed" /* Mixed stream (in/out) */
|
||||
#define NG_SPLIT_HOOK_OUT "out" /* Output to outhook (sending out) */
|
||||
#define NG_SPLIT_HOOK_IN "in" /* Input from inhook (receiving) */
|
||||
|
||||
#endif /* _NETGRAPH_NG_SPLIT_H_ */
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* ng_sppp.h Netgraph to Sppp module.
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (C) 2002-2004 Cronyx Engineering.
|
||||
* Copyright (C) 2002-2004 Roman Kurakin <rik@cronyx.ru>
|
||||
*
|
||||
* This software is distributed with NO WARRANTIES, not even the implied
|
||||
* warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* Authors grant any other persons or organisations a permission to use,
|
||||
* modify and redistribute this software in source and binary forms,
|
||||
* as long as this message is kept with the software, all derivative
|
||||
* works or modified versions.
|
||||
*
|
||||
* $FreeBSD$
|
||||
* Cronyx Id: ng_sppp.h,v 1.1.2.6 2004/03/01 15:17:21 rik Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_SPPP_H_
|
||||
#define _NETGRAPH_SPPP_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_SPPP_NODE_TYPE "sppp"
|
||||
#define NGM_SPPP_COOKIE 1040804655
|
||||
|
||||
/* Interface base name */
|
||||
#define NG_SPPP_IFACE_NAME "sppp"
|
||||
|
||||
/* My hook names */
|
||||
#define NG_SPPP_HOOK_DOWNSTREAM "downstream"
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_SPPP_GET_IFNAME = 1, /* returns struct ng_sppp_ifname */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_SPPP_H_ */
|
|
@ -0,0 +1,130 @@
|
|||
/*-
|
||||
* Copyright (c) 2006 Vadim Goncharov <vadimnuclight@tpu.ru>
|
||||
* 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 unmodified, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_TAG_H_
|
||||
#define _NETGRAPH_NG_TAG_H_
|
||||
|
||||
/* Node type name and magic cookie. */
|
||||
#define NG_TAG_NODE_TYPE "tag"
|
||||
#define NGM_TAG_COOKIE 1149771193
|
||||
|
||||
/*
|
||||
* The types of tag_cookie, tag_len and tag_id in structures below
|
||||
* must be the same as corresponding members m_tag_cookie, m_tag_len
|
||||
* and m_tag_id in struct m_tag (defined in <sys/mbuf.h>).
|
||||
*/
|
||||
|
||||
/* Tag match structure for every (input) hook. */
|
||||
struct ng_tag_hookin {
|
||||
char thisHook[NG_HOOKSIZ]; /* name of hook */
|
||||
char ifMatch[NG_HOOKSIZ]; /* match dest hook */
|
||||
char ifNotMatch[NG_HOOKSIZ]; /* !match dest hook */
|
||||
uint8_t strip; /* strip tag if found */
|
||||
uint32_t tag_cookie; /* ABI/Module ID */
|
||||
uint16_t tag_id; /* tag ID */
|
||||
uint16_t tag_len; /* length of data */
|
||||
uint8_t tag_data[0]; /* tag data */
|
||||
};
|
||||
|
||||
/* Tag set structure for every (output) hook. */
|
||||
struct ng_tag_hookout {
|
||||
char thisHook[NG_HOOKSIZ]; /* name of hook */
|
||||
uint32_t tag_cookie; /* ABI/Module ID */
|
||||
uint16_t tag_id; /* tag ID */
|
||||
uint16_t tag_len; /* length of data */
|
||||
uint8_t tag_data[0]; /* tag data */
|
||||
};
|
||||
|
||||
#define NG_TAG_HOOKIN_SIZE(taglen) \
|
||||
(sizeof(struct ng_tag_hookin) + (taglen))
|
||||
|
||||
#define NG_TAG_HOOKOUT_SIZE(taglen) \
|
||||
(sizeof(struct ng_tag_hookout) + (taglen))
|
||||
|
||||
/* Keep this in sync with the above structures definitions. */
|
||||
#define NG_TAG_HOOKIN_TYPE_INFO(tdtype) { \
|
||||
{ "thisHook", &ng_parse_hookbuf_type }, \
|
||||
{ "ifMatch", &ng_parse_hookbuf_type }, \
|
||||
{ "ifNotMatch", &ng_parse_hookbuf_type }, \
|
||||
{ "strip", &ng_parse_uint8_type }, \
|
||||
{ "tag_cookie", &ng_parse_uint32_type }, \
|
||||
{ "tag_id", &ng_parse_uint16_type }, \
|
||||
{ "tag_len", &ng_parse_uint16_type }, \
|
||||
{ "tag_data", (tdtype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#define NG_TAG_HOOKOUT_TYPE_INFO(tdtype) { \
|
||||
{ "thisHook", &ng_parse_hookbuf_type }, \
|
||||
{ "tag_cookie", &ng_parse_uint32_type }, \
|
||||
{ "tag_id", &ng_parse_uint16_type }, \
|
||||
{ "tag_len", &ng_parse_uint16_type }, \
|
||||
{ "tag_data", (tdtype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#ifdef NG_TAG_DEBUG
|
||||
|
||||
/* Statistics structure for one hook. */
|
||||
struct ng_tag_hookstat {
|
||||
uint64_t recvFrames;
|
||||
uint64_t recvOctets;
|
||||
uint64_t recvMatchFrames;
|
||||
uint64_t recvMatchOctets;
|
||||
uint64_t xmitFrames;
|
||||
uint64_t xmitOctets;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_TAG_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 } \
|
||||
}
|
||||
|
||||
#endif /* NG_TAG_DEBUG */
|
||||
|
||||
/* Netgraph commands. */
|
||||
enum {
|
||||
NGM_TAG_SET_HOOKIN = 1, /* supply a struct ng_tag_hookin */
|
||||
NGM_TAG_GET_HOOKIN, /* returns a struct ng_tag_hookin */
|
||||
NGM_TAG_SET_HOOKOUT, /* supply a struct ng_tag_hookout */
|
||||
NGM_TAG_GET_HOOKOUT, /* returns a struct ng_tag_hookout */
|
||||
#ifdef NG_TAG_DEBUG
|
||||
NGM_TAG_GET_STATS, /* supply name as char[NG_HOOKSIZ] */
|
||||
NGM_TAG_CLR_STATS, /* supply name as char[NG_HOOKSIZ] */
|
||||
NGM_TAG_GETCLR_STATS, /* supply name as char[NG_HOOKSIZ] */
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_TAG_H_ */
|
|
@ -0,0 +1,82 @@
|
|||
/*-
|
||||
* ng_tcpmss.h
|
||||
*
|
||||
* Copyright (c) 2004, Alexey Popov <lollypop@flexuser.ru>
|
||||
* 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 unmodified, 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_TCPMSS_H_
|
||||
#define _NETGRAPH_TCPMSS_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_TCPMSS_NODE_TYPE "tcpmss"
|
||||
#define NGM_TCPMSS_COOKIE 1097623478
|
||||
|
||||
/* Statistics structure for one hook. */
|
||||
struct ng_tcpmss_hookstat {
|
||||
uint64_t Octets;
|
||||
uint64_t Packets;
|
||||
uint16_t maxMSS;
|
||||
uint64_t SYNPkts;
|
||||
uint64_t FixedPkts;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_TCPMSS_HOOKSTAT_INFO { \
|
||||
{ "Octets", &ng_parse_uint64_type }, \
|
||||
{ "Packets", &ng_parse_uint64_type }, \
|
||||
{ "maxMSS", &ng_parse_uint16_type }, \
|
||||
{ "SYNPkts", &ng_parse_uint64_type }, \
|
||||
{ "FixedPkts", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
|
||||
/* Structure for NGM_TCPMSS_CONFIG. */
|
||||
struct ng_tcpmss_config {
|
||||
char inHook[NG_HOOKSIZ];
|
||||
char outHook[NG_HOOKSIZ];
|
||||
uint16_t maxMSS;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_TCPMSS_CONFIG_INFO { \
|
||||
{ "inHook", &ng_parse_hookbuf_type }, \
|
||||
{ "outHook", &ng_parse_hookbuf_type }, \
|
||||
{ "maxMSS", &ng_parse_uint16_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_TCPMSS_GET_STATS = 1, /* Get stats. */
|
||||
NGM_TCPMSS_CLR_STATS, /* Clear stats. */
|
||||
NGM_TCPMSS_GETCLR_STATS, /* "Atomically" get and clear stats. */
|
||||
NGM_TCPMSS_CONFIG /* Set configuration. */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_TCPMSS_H_ */
|
|
@ -0,0 +1,99 @@
|
|||
|
||||
/*
|
||||
* ng_tee.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_tee.h,v 1.2 1999/01/20 00:22:14 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_TEE_H_
|
||||
#define _NETGRAPH_NG_TEE_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_TEE_NODE_TYPE "tee"
|
||||
#define NGM_TEE_COOKIE 916107047
|
||||
|
||||
/* Hook names */
|
||||
#define NG_TEE_HOOK_RIGHT "right"
|
||||
#define NG_TEE_HOOK_LEFT "left"
|
||||
#define NG_TEE_HOOK_RIGHT2LEFT "right2left"
|
||||
#define NG_TEE_HOOK_LEFT2RIGHT "left2right"
|
||||
|
||||
/* Statistics structure for one hook */
|
||||
struct ng_tee_hookstat {
|
||||
u_int64_t inOctets;
|
||||
u_int64_t inFrames;
|
||||
u_int64_t outOctets;
|
||||
u_int64_t outFrames;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_TEE_HOOKSTAT_INFO { \
|
||||
{ "inOctets", &ng_parse_uint64_type }, \
|
||||
{ "inFrames", &ng_parse_uint64_type }, \
|
||||
{ "outOctets", &ng_parse_uint64_type }, \
|
||||
{ "outFrames", &ng_parse_uint64_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Statistics structure returned by NGM_TEE_GET_STATS */
|
||||
struct ng_tee_stats {
|
||||
struct ng_tee_hookstat right;
|
||||
struct ng_tee_hookstat left;
|
||||
struct ng_tee_hookstat right2left;
|
||||
struct ng_tee_hookstat left2right;
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_TEE_STATS_INFO(hstype) { \
|
||||
{ "right", (hstype) }, \
|
||||
{ "left", (hstype) }, \
|
||||
{ "right2left", (hstype) }, \
|
||||
{ "left2right", (hstype) }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_TEE_GET_STATS = 1, /* get stats */
|
||||
NGM_TEE_CLR_STATS, /* clear stats */
|
||||
NGM_TEE_GETCLR_STATS, /* atomically get and clear stats */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_TEE_H_ */
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
/*
|
||||
* ng_tty.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_tty.h,v 1.7 1999/01/20 00:22:15 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_TTY_H_
|
||||
#define _NETGRAPH_NG_TTY_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_TTY_NODE_TYPE "tty"
|
||||
#define NGM_TTY_COOKIE 1226109660
|
||||
|
||||
/* Default hot char */
|
||||
#define NG_TTY_DFL_HOTCHAR 0x7e /* PPP flag byte */
|
||||
|
||||
/* Hook names */
|
||||
#define NG_TTY_HOOK "hook"
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_TTY_GET_HOTCHAR = 1,
|
||||
NGM_TTY_SET_HOTCHAR,
|
||||
NGM_TTY_SET_TTY,
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_TTY_H_ */
|
|
@ -0,0 +1,88 @@
|
|||
|
||||
/*
|
||||
* ng_vjc.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_vjc.h,v 1.6 1999/01/25 02:40:22 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_VJC_H_
|
||||
#define _NETGRAPH_NG_VJC_H_
|
||||
|
||||
/* Node type name and magic cookie */
|
||||
#define NG_VJC_NODE_TYPE "vjc"
|
||||
#define NGM_VJC_COOKIE 868219210
|
||||
|
||||
/* Hook names */
|
||||
#define NG_VJC_HOOK_IP "ip" /* normal IP traffic */
|
||||
#define NG_VJC_HOOK_VJCOMP "vjcomp" /* compressed TCP */
|
||||
#define NG_VJC_HOOK_VJUNCOMP "vjuncomp" /* uncompressed TCP */
|
||||
#define NG_VJC_HOOK_VJIP "vjip" /* uncompressed IP */
|
||||
|
||||
/* Minimum and maximum number of compression channels */
|
||||
#define NG_VJC_MIN_CHANNELS 4
|
||||
#define NG_VJC_MAX_CHANNELS 16
|
||||
|
||||
/* Configure struct */
|
||||
struct ngm_vjc_config {
|
||||
u_char enableComp; /* Enable compression */
|
||||
u_char enableDecomp; /* Enable decompression */
|
||||
u_char maxChannel; /* Number of compression channels - 1 */
|
||||
u_char compressCID; /* OK to compress outgoing CID's */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition */
|
||||
#define NG_VJC_CONFIG_TYPE_INFO { \
|
||||
{ "enableComp", &ng_parse_uint8_type }, \
|
||||
{ "enableDecomp", &ng_parse_uint8_type }, \
|
||||
{ "maxChannel", &ng_parse_uint8_type }, \
|
||||
{ "compressCID", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
/* Netgraph commands */
|
||||
enum {
|
||||
NGM_VJC_SET_CONFIG, /* Supply a struct ngm_vjc_config */
|
||||
NGM_VJC_GET_CONFIG, /* Returns a struct ngm_vjc_config */
|
||||
NGM_VJC_GET_STATE, /* Returns current struct slcompress */
|
||||
NGM_VJC_CLR_STATS, /* Clears statistics counters */
|
||||
NGM_VJC_RECV_ERROR, /* Indicate loss of incoming frame */
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_VJC_H_ */
|
|
@ -0,0 +1,108 @@
|
|||
/*-
|
||||
* Copyright (c) 2003 IPNET Internet Communication Company
|
||||
* Copyright (c) 2011 - 2012 Rozhuk Ivan <rozhuk.im@gmail.com>
|
||||
* 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.
|
||||
*
|
||||
* Author: Ruslan Ermilov <ru@FreeBSD.org>
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_VLAN_H_
|
||||
#define _NETGRAPH_NG_VLAN_H_
|
||||
|
||||
/* Using "vlan" in addfilter and gettable messages. 2012.01 */
|
||||
#define NG_VLAN_USE_OLD_VLAN_NAME 1
|
||||
|
||||
/* Node type name and magic cookie. */
|
||||
#define NG_VLAN_NODE_TYPE "vlan"
|
||||
#define NGM_VLAN_COOKIE 1068486472
|
||||
|
||||
/* Hook names. */
|
||||
#define NG_VLAN_HOOK_DOWNSTREAM "downstream"
|
||||
#define NG_VLAN_HOOK_NOMATCH "nomatch"
|
||||
|
||||
/* Netgraph commands. */
|
||||
enum {
|
||||
NGM_VLAN_ADD_FILTER = 1,
|
||||
NGM_VLAN_DEL_FILTER,
|
||||
NGM_VLAN_GET_TABLE,
|
||||
NGM_VLAN_DEL_VID_FLT,
|
||||
NGM_VLAN_GET_DECAP,
|
||||
NGM_VLAN_SET_DECAP,
|
||||
NGM_VLAN_GET_ENCAP,
|
||||
NGM_VLAN_SET_ENCAP,
|
||||
NGM_VLAN_GET_ENCAP_PROTO,
|
||||
NGM_VLAN_SET_ENCAP_PROTO,
|
||||
};
|
||||
|
||||
#define VLAN_ENCAP_FROM_FILTER 0x00000001
|
||||
#define VLAN_ENCAP_FROM_NOMATCH 0x00000002
|
||||
|
||||
/* For NGM_VLAN_ADD_FILTER control message. */
|
||||
struct ng_vlan_filter {
|
||||
char hook_name[NG_HOOKSIZ];
|
||||
#ifdef NG_VLAN_USE_OLD_VLAN_NAME
|
||||
uint16_t vlan; /* VLAN - same as vid, oldname, deprecated. */
|
||||
#endif
|
||||
uint16_t vid; /* VID - VLAN Identifier. */
|
||||
uint8_t pcp; /* PCP - Priority Code Point. */
|
||||
uint8_t cfi; /* CFI - Canonical Format Indicator. */
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#ifdef NG_VLAN_USE_OLD_VLAN_NAME
|
||||
#define NG_VLAN_FILTER_FIELDS { \
|
||||
{ "hook", &ng_parse_hookbuf_type }, \
|
||||
{ "vlan", &ng_parse_uint16_type }, \
|
||||
{ "vid", &ng_parse_uint16_type }, \
|
||||
{ "pcp", &ng_parse_uint8_type }, \
|
||||
{ "cfi", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
#else
|
||||
#define NG_VLAN_FILTER_FIELDS { \
|
||||
{ "hook", &ng_parse_hookbuf_type }, \
|
||||
{ "vid", &ng_parse_uint16_type }, \
|
||||
{ "pcp", &ng_parse_uint8_type }, \
|
||||
{ "cfi", &ng_parse_uint8_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Structure returned by NGM_VLAN_GET_TABLE. */
|
||||
struct ng_vlan_table {
|
||||
u_int32_t n;
|
||||
struct ng_vlan_filter filter[];
|
||||
};
|
||||
|
||||
/* Keep this in sync with the above structure definition. */
|
||||
#define NG_VLAN_TABLE_FIELDS { \
|
||||
{ "n", &ng_parse_uint32_type }, \
|
||||
{ "filter", &ng_vlan_table_array_type }, \
|
||||
{ NULL } \
|
||||
}
|
||||
|
||||
#endif /* _NETGRAPH_NG_VLAN_H_ */
|
|
@ -0,0 +1,53 @@
|
|||
/* $NetBSD: stringlist.h,v 1.2 1997/01/17 06:11:36 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Christos Zoulas
|
||||
* 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 _STRINGLIST_H
|
||||
#define _STRINGLIST_H
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* Simple string list
|
||||
*/
|
||||
typedef struct _stringlist {
|
||||
char **sl_str;
|
||||
size_t sl_max;
|
||||
size_t sl_cur;
|
||||
} StringList;
|
||||
|
||||
__BEGIN_DECLS
|
||||
StringList *sl_init(void);
|
||||
int sl_add(StringList *, char *);
|
||||
void sl_free(StringList *, int);
|
||||
char *sl_find(StringList *, const char *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _STRINGLIST_H */
|
||||
|
|
@ -0,0 +1,353 @@
|
|||
/*-
|
||||
* Copyright (c) 1997-2000 Doug Rabson
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _SYS_LINKER_H_
|
||||
#define _SYS_LINKER_H_
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
#include <machine/elf.h>
|
||||
#include <sys/kobj.h>
|
||||
|
||||
#ifdef MALLOC_DECLARE
|
||||
MALLOC_DECLARE(M_LINKER);
|
||||
#endif
|
||||
|
||||
struct mod_depend;
|
||||
|
||||
/*
|
||||
* Object representing a file which has been loaded by the linker.
|
||||
*/
|
||||
typedef struct linker_file* linker_file_t;
|
||||
typedef TAILQ_HEAD(, linker_file) linker_file_list_t;
|
||||
|
||||
typedef caddr_t linker_sym_t; /* opaque symbol */
|
||||
typedef c_caddr_t c_linker_sym_t; /* const opaque symbol */
|
||||
typedef int (*linker_function_name_callback_t)(const char *, void *);
|
||||
|
||||
/*
|
||||
* expanded out linker_sym_t
|
||||
*/
|
||||
typedef struct linker_symval {
|
||||
const char* name;
|
||||
caddr_t value;
|
||||
size_t size;
|
||||
} linker_symval_t;
|
||||
|
||||
typedef int (*linker_function_nameval_callback_t)(linker_file_t, int, linker_symval_t *, void *);
|
||||
|
||||
struct common_symbol {
|
||||
STAILQ_ENTRY(common_symbol) link;
|
||||
char* name;
|
||||
caddr_t address;
|
||||
};
|
||||
|
||||
struct linker_file {
|
||||
KOBJ_FIELDS;
|
||||
int refs; /* reference count */
|
||||
int userrefs; /* kldload(2) count */
|
||||
int flags;
|
||||
#define LINKER_FILE_LINKED 0x1 /* file has been fully linked */
|
||||
TAILQ_ENTRY(linker_file) link; /* list of all loaded files */
|
||||
char* filename; /* file which was loaded */
|
||||
char* pathname; /* file name with full path */
|
||||
int id; /* unique id */
|
||||
caddr_t address; /* load address */
|
||||
size_t size; /* size of file */
|
||||
caddr_t ctors_addr; /* address of .ctors */
|
||||
size_t ctors_size; /* size of .ctors */
|
||||
int ndeps; /* number of dependencies */
|
||||
linker_file_t* deps; /* list of dependencies */
|
||||
STAILQ_HEAD(, common_symbol) common; /* list of common symbols */
|
||||
TAILQ_HEAD(, module) modules; /* modules in this file */
|
||||
TAILQ_ENTRY(linker_file) loaded; /* preload dependency support */
|
||||
int loadcnt; /* load counter value */
|
||||
|
||||
/*
|
||||
* Function Boundary Tracing (FBT) or Statically Defined Tracing (SDT)
|
||||
* fields.
|
||||
*/
|
||||
int nenabled; /* number of enabled probes. */
|
||||
int fbt_nentries; /* number of fbt entries created. */
|
||||
};
|
||||
|
||||
/*
|
||||
* Object implementing a class of file (a.out, elf, etc.)
|
||||
*/
|
||||
typedef struct linker_class *linker_class_t;
|
||||
typedef TAILQ_HEAD(, linker_class) linker_class_list_t;
|
||||
|
||||
struct linker_class {
|
||||
KOBJ_CLASS_FIELDS;
|
||||
TAILQ_ENTRY(linker_class) link; /* list of all file classes */
|
||||
};
|
||||
|
||||
/*
|
||||
* Function type used when iterating over the list of linker files.
|
||||
*/
|
||||
typedef int linker_predicate_t(linker_file_t, void *);
|
||||
|
||||
/*
|
||||
* The "file" for the kernel.
|
||||
*/
|
||||
extern linker_file_t linker_kernel_file;
|
||||
|
||||
/*
|
||||
* Obtain a reference to a module, loading it if required.
|
||||
*/
|
||||
int linker_reference_module(const char* _modname, struct mod_depend *_verinfo,
|
||||
linker_file_t* _result);
|
||||
|
||||
/*
|
||||
* Release a reference to a module, unloading it if there are no more
|
||||
* references. Note that one should either provide a module name and
|
||||
* optional version info or a linker file, but not both.
|
||||
*/
|
||||
int linker_release_module(const char *_modname, struct mod_depend *_verinfo,
|
||||
linker_file_t _file);
|
||||
|
||||
/*
|
||||
* Iterate over all of the currently loaded linker files calling the
|
||||
* predicate function while the function returns 0. Returns the value
|
||||
* returned by the last predicate function.
|
||||
*/
|
||||
int linker_file_foreach(linker_predicate_t *_predicate, void *_context);
|
||||
|
||||
/*
|
||||
* Lookup a symbol in a file. If deps is TRUE, look in dependencies
|
||||
* if not found in file.
|
||||
*/
|
||||
caddr_t linker_file_lookup_symbol(linker_file_t _file, const char* _name,
|
||||
int _deps);
|
||||
|
||||
/*
|
||||
* Lookup a linker set in a file. Return pointers to the first entry,
|
||||
* last + 1, and count of entries. Use: for (p = start; p < stop; p++) {}
|
||||
* void *start is really: "struct yoursetmember ***start;"
|
||||
*/
|
||||
int linker_file_lookup_set(linker_file_t _file, const char *_name,
|
||||
void *_start, void *_stop, int *_count);
|
||||
|
||||
/*
|
||||
* List all functions in a file.
|
||||
*/
|
||||
int linker_file_function_listall(linker_file_t,
|
||||
linker_function_nameval_callback_t, void *);
|
||||
|
||||
/*
|
||||
* Functions solely for use by the linker class handlers.
|
||||
*/
|
||||
int linker_add_class(linker_class_t _cls);
|
||||
int linker_file_unload(linker_file_t _file, int flags);
|
||||
int linker_load_dependencies(linker_file_t _lf);
|
||||
linker_file_t linker_make_file(const char* _filename, linker_class_t _cls);
|
||||
|
||||
/*
|
||||
* DDB Helpers, tuned specifically for ddb/db_kld.c
|
||||
*/
|
||||
int linker_ddb_lookup(const char *_symstr, c_linker_sym_t *_sym);
|
||||
int linker_ddb_search_symbol(caddr_t _value, c_linker_sym_t *_sym,
|
||||
long *_diffp);
|
||||
int linker_ddb_symbol_values(c_linker_sym_t _sym, linker_symval_t *_symval);
|
||||
int linker_ddb_search_symbol_name(caddr_t value, char *buf, u_int buflen,
|
||||
long *offset);
|
||||
|
||||
/*
|
||||
* stack(9) helper for situations where kernel locking is required.
|
||||
*/
|
||||
int linker_search_symbol_name(caddr_t value, char *buf, u_int buflen,
|
||||
long *offset);
|
||||
|
||||
|
||||
/* HWPMC helper */
|
||||
void *linker_hwpmc_list_objects(void);
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
/*
|
||||
* Module information subtypes
|
||||
*/
|
||||
#define MODINFO_END 0x0000 /* End of list */
|
||||
#define MODINFO_NAME 0x0001 /* Name of module (string) */
|
||||
#define MODINFO_TYPE 0x0002 /* Type of module (string) */
|
||||
#define MODINFO_ADDR 0x0003 /* Loaded address */
|
||||
#define MODINFO_SIZE 0x0004 /* Size of module */
|
||||
#define MODINFO_EMPTY 0x0005 /* Has been deleted */
|
||||
#define MODINFO_ARGS 0x0006 /* Parameters string */
|
||||
#define MODINFO_METADATA 0x8000 /* Module-specfic */
|
||||
|
||||
#define MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */
|
||||
#define MODINFOMD_ELFHDR 0x0002 /* ELF header */
|
||||
#define MODINFOMD_SSYM 0x0003 /* start of symbols */
|
||||
#define MODINFOMD_ESYM 0x0004 /* end of symbols */
|
||||
#define MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */
|
||||
/* These values are MD on these two platforms */
|
||||
#if !defined(__sparc64__) && !defined(__powerpc__)
|
||||
#define MODINFOMD_ENVP 0x0006 /* envp[] */
|
||||
#define MODINFOMD_HOWTO 0x0007 /* boothowto */
|
||||
#define MODINFOMD_KERNEND 0x0008 /* kernend */
|
||||
#endif
|
||||
#define MODINFOMD_SHDR 0x0009 /* section header table */
|
||||
#define MODINFOMD_CTORS_ADDR 0x000a /* address of .ctors */
|
||||
#define MODINFOMD_CTORS_SIZE 0x000b /* size of .ctors */
|
||||
#define MODINFOMD_FW_HANDLE 0x000c /* Firmware dependent handle */
|
||||
#define MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */
|
||||
|
||||
#define MODINFOMD_DEPLIST (0x4001 | MODINFOMD_NOCOPY) /* depends on */
|
||||
|
||||
#ifdef _KERNEL
|
||||
#define MD_FETCH(mdp, info, type) ({ \
|
||||
type *__p; \
|
||||
__p = (type *)preload_search_info((mdp), MODINFO_METADATA | (info)); \
|
||||
__p ? *__p : 0; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#define LINKER_HINTS_VERSION 1 /* linker.hints file version */
|
||||
#define LINKER_HINTS_MAX (1 << 20) /* Allow at most 1MB for linker.hints */
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
/*
|
||||
* Module lookup
|
||||
*/
|
||||
extern vm_offset_t preload_addr_relocate;
|
||||
extern caddr_t preload_metadata;
|
||||
|
||||
extern void * preload_fetch_addr(caddr_t _mod);
|
||||
extern size_t preload_fetch_size(caddr_t _mod);
|
||||
extern caddr_t preload_search_by_name(const char *_name);
|
||||
extern caddr_t preload_search_by_type(const char *_type);
|
||||
extern caddr_t preload_search_next_name(caddr_t _base);
|
||||
extern caddr_t preload_search_info(caddr_t _mod, int _inf);
|
||||
extern void preload_delete_name(const char *_name);
|
||||
extern void preload_bootstrap_relocate(vm_offset_t _offset);
|
||||
|
||||
#ifdef KLD_DEBUG
|
||||
|
||||
extern int kld_debug;
|
||||
#define KLD_DEBUG_FILE 1 /* file load/unload */
|
||||
#define KLD_DEBUG_SYM 2 /* symbol lookup */
|
||||
|
||||
#define KLD_DPF(cat, args) \
|
||||
do { \
|
||||
if (kld_debug & KLD_DEBUG_##cat) printf args; \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define KLD_DPF(cat, args)
|
||||
|
||||
#endif
|
||||
|
||||
typedef int elf_lookup_fn(linker_file_t, Elf_Size, int, Elf_Addr *);
|
||||
|
||||
/* Support functions */
|
||||
int elf_reloc(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
|
||||
int elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
|
||||
Elf_Addr elf_relocaddr(linker_file_t _lf, Elf_Addr addr);
|
||||
const Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx);
|
||||
const char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx);
|
||||
|
||||
typedef struct linker_ctf {
|
||||
const uint8_t *ctftab; /* Decompressed CTF data. */
|
||||
int ctfcnt; /* Number of CTF data bytes. */
|
||||
const Elf_Sym *symtab; /* Ptr to the symbol table. */
|
||||
int nsym; /* Number of symbols. */
|
||||
const char *strtab; /* Ptr to the string table. */
|
||||
int strcnt; /* Number of string bytes. */
|
||||
uint32_t **ctfoffp; /* Ptr to array of obj/fnc offsets. */
|
||||
uint32_t **typoffp; /* Ptr to array of type offsets. */
|
||||
long *typlenp; /* Ptr to number of type data entries. */
|
||||
} linker_ctf_t;
|
||||
|
||||
int linker_ctf_get(linker_file_t, linker_ctf_t *);
|
||||
|
||||
int elf_cpu_load_file(linker_file_t);
|
||||
int elf_cpu_unload_file(linker_file_t);
|
||||
|
||||
/* values for type */
|
||||
#define ELF_RELOC_REL 1
|
||||
#define ELF_RELOC_RELA 2
|
||||
|
||||
/*
|
||||
* This is version 1 of the KLD file status structure. It is identified
|
||||
* by its _size_ in the version field.
|
||||
*/
|
||||
struct kld_file_stat_1 {
|
||||
int version; /* set to sizeof(struct kld_file_stat_1) */
|
||||
char name[MAXPATHLEN];
|
||||
int refs;
|
||||
int id;
|
||||
caddr_t address; /* load address */
|
||||
size_t size; /* size in bytes */
|
||||
};
|
||||
#endif /* _KERNEL */
|
||||
|
||||
struct kld_file_stat {
|
||||
int version; /* set to sizeof(struct kld_file_stat) */
|
||||
char name[MAXPATHLEN];
|
||||
int refs;
|
||||
int id;
|
||||
caddr_t address; /* load address */
|
||||
size_t size; /* size in bytes */
|
||||
char pathname[MAXPATHLEN];
|
||||
};
|
||||
|
||||
struct kld_sym_lookup {
|
||||
int version; /* set to sizeof(struct kld_sym_lookup) */
|
||||
char *symname; /* Symbol name we are looking up */
|
||||
u_long symvalue;
|
||||
size_t symsize;
|
||||
};
|
||||
#define KLDSYM_LOOKUP 1
|
||||
|
||||
/*
|
||||
* Flags for kldunloadf() and linker_file_unload()
|
||||
*/
|
||||
#define LINKER_UNLOAD_NORMAL 0
|
||||
#define LINKER_UNLOAD_FORCE 1
|
||||
|
||||
#ifndef _KERNEL
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
int kldload(const char* _file);
|
||||
int kldunload(int _fileid);
|
||||
int kldunloadf(int _fileid, int flags);
|
||||
int kldfind(const char* _file);
|
||||
int kldnext(int _fileid);
|
||||
int kldstat(int _fileid, struct kld_file_stat* _stat);
|
||||
int kldfirstmod(int _fileid);
|
||||
int kldsym(int _fileid, int _cmd, void *_data);
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* !_SYS_LINKER_H_ */
|
|
@ -0,0 +1,383 @@
|
|||
/*
|
||||
* System call prototypes.
|
||||
*
|
||||
* DO NOT EDIT-- this file is automatically generated.
|
||||
* $FreeBSD$
|
||||
* created from FreeBSD: stable/11/sys/kern/syscalls.master 303854 2016-08-08 20:23:11Z bdrewery
|
||||
*/
|
||||
|
||||
#ifndef _SYS_SYSPROTO_H_
|
||||
#define _SYS_SYSPROTO_H_
|
||||
|
||||
struct proc;
|
||||
|
||||
struct thread;
|
||||
|
||||
#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
|
||||
0 : sizeof(register_t) - sizeof(t))
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define PADL_(t) 0
|
||||
#define PADR_(t) PAD_(t)
|
||||
#else
|
||||
#define PADL_(t) PAD_(t)
|
||||
#define PADR_(t) 0
|
||||
#endif
|
||||
|
||||
struct read_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)];
|
||||
char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)];
|
||||
};
|
||||
struct write_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)];
|
||||
char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)];
|
||||
};
|
||||
struct open_args {
|
||||
char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)];
|
||||
};
|
||||
struct close_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
};
|
||||
struct wait4_args {
|
||||
char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)];
|
||||
char status_l_[PADL_(int *)]; int * status; char status_r_[PADR_(int *)];
|
||||
char options_l_[PADL_(int)]; int options; char options_r_[PADR_(int)];
|
||||
char rusage_l_[PADL_(struct rusage *)]; struct rusage * rusage; char rusage_r_[PADR_(struct rusage *)];
|
||||
};
|
||||
struct recvmsg_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
};
|
||||
struct sendmsg_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
};
|
||||
struct recvfrom_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)];
|
||||
char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
char from_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict from; char from_r_[PADR_(struct sockaddr *__restrict)];
|
||||
char fromlenaddr_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict fromlenaddr; char fromlenaddr_r_[PADR_(__socklen_t *__restrict)];
|
||||
};
|
||||
struct accept_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char name_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict name; char name_r_[PADR_(struct sockaddr *__restrict)];
|
||||
char anamelen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict anamelen; char anamelen_r_[PADR_(__socklen_t *__restrict)];
|
||||
};
|
||||
struct getpeername_args {
|
||||
char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)];
|
||||
char asa_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict asa; char asa_r_[PADR_(struct sockaddr *__restrict)];
|
||||
char alen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict alen; char alen_r_[PADR_(__socklen_t *__restrict)];
|
||||
};
|
||||
struct getsockname_args {
|
||||
char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)];
|
||||
char asa_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict asa; char asa_r_[PADR_(struct sockaddr *__restrict)];
|
||||
char alen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict alen; char alen_r_[PADR_(__socklen_t *__restrict)];
|
||||
};
|
||||
struct access_args {
|
||||
char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
|
||||
char amode_l_[PADL_(int)]; int amode; char amode_r_[PADR_(int)];
|
||||
};
|
||||
struct ioctl_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char com_l_[PADL_(u_long)]; u_long com; char com_r_[PADR_(u_long)];
|
||||
char data_l_[PADL_(caddr_t)]; caddr_t data; char data_r_[PADR_(caddr_t)];
|
||||
};
|
||||
struct dup2_args {
|
||||
char from_l_[PADL_(u_int)]; u_int from; char from_r_[PADR_(u_int)];
|
||||
char to_l_[PADL_(u_int)]; u_int to; char to_r_[PADR_(u_int)];
|
||||
};
|
||||
struct fcntl_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)];
|
||||
char arg_l_[PADL_(long)]; long arg; char arg_r_[PADR_(long)];
|
||||
};
|
||||
struct select_args {
|
||||
char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)];
|
||||
char in_l_[PADL_(fd_set *)]; fd_set * in; char in_r_[PADR_(fd_set *)];
|
||||
char ou_l_[PADL_(fd_set *)]; fd_set * ou; char ou_r_[PADR_(fd_set *)];
|
||||
char ex_l_[PADL_(fd_set *)]; fd_set * ex; char ex_r_[PADR_(fd_set *)];
|
||||
char tv_l_[PADL_(struct timeval *)]; struct timeval * tv; char tv_r_[PADR_(struct timeval *)];
|
||||
};
|
||||
struct socket_args {
|
||||
char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)];
|
||||
char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)];
|
||||
char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)];
|
||||
};
|
||||
struct connect_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)];
|
||||
char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)];
|
||||
};
|
||||
struct bind_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)];
|
||||
char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)];
|
||||
};
|
||||
struct setsockopt_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char level_l_[PADL_(int)]; int level; char level_r_[PADR_(int)];
|
||||
char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)];
|
||||
char val_l_[PADL_(caddr_t)]; caddr_t val; char val_r_[PADR_(caddr_t)];
|
||||
char valsize_l_[PADL_(int)]; int valsize; char valsize_r_[PADR_(int)];
|
||||
};
|
||||
struct listen_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char backlog_l_[PADL_(int)]; int backlog; char backlog_r_[PADR_(int)];
|
||||
};
|
||||
struct getsockopt_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char level_l_[PADL_(int)]; int level; char level_r_[PADR_(int)];
|
||||
char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)];
|
||||
char val_l_[PADL_(caddr_t)]; caddr_t val; char val_r_[PADR_(caddr_t)];
|
||||
char avalsize_l_[PADL_(int *)]; int * avalsize; char avalsize_r_[PADR_(int *)];
|
||||
};
|
||||
struct readv_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)];
|
||||
char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
|
||||
};
|
||||
struct writev_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)];
|
||||
char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
|
||||
};
|
||||
struct sendto_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)];
|
||||
char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)];
|
||||
char tolen_l_[PADL_(int)]; int tolen; char tolen_r_[PADR_(int)];
|
||||
};
|
||||
struct shutdown_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)];
|
||||
};
|
||||
struct socketpair_args {
|
||||
char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)];
|
||||
char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)];
|
||||
char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)];
|
||||
char rsv_l_[PADL_(int *)]; int * rsv; char rsv_r_[PADR_(int *)];
|
||||
};
|
||||
struct setfib_args {
|
||||
char fibnum_l_[PADL_(int)]; int fibnum; char fibnum_r_[PADR_(int)];
|
||||
};
|
||||
struct sysctl_args {
|
||||
char name_l_[PADL_(int *)]; int * name; char name_r_[PADR_(int *)];
|
||||
char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)];
|
||||
char old_l_[PADL_(void *)]; void * old; char old_r_[PADR_(void *)];
|
||||
char oldlenp_l_[PADL_(size_t *)]; size_t * oldlenp; char oldlenp_r_[PADR_(size_t *)];
|
||||
char new_l_[PADL_(void *)]; void * new; char new_r_[PADR_(void *)];
|
||||
char newlen_l_[PADL_(size_t)]; size_t newlen; char newlen_r_[PADR_(size_t)];
|
||||
};
|
||||
struct poll_args {
|
||||
char fds_l_[PADL_(struct pollfd *)]; struct pollfd * fds; char fds_r_[PADR_(struct pollfd *)];
|
||||
char nfds_l_[PADL_(u_int)]; u_int nfds; char nfds_r_[PADR_(u_int)];
|
||||
char timeout_l_[PADL_(int)]; int timeout; char timeout_r_[PADR_(int)];
|
||||
};
|
||||
struct preadv_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)];
|
||||
char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
|
||||
char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)];
|
||||
};
|
||||
struct pwritev_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)];
|
||||
char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
|
||||
char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)];
|
||||
};
|
||||
struct kqueue_args {
|
||||
register_t dummy;
|
||||
};
|
||||
struct kevent_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char changelist_l_[PADL_(struct kevent *)]; struct kevent * changelist; char changelist_r_[PADR_(struct kevent *)];
|
||||
char nchanges_l_[PADL_(int)]; int nchanges; char nchanges_r_[PADR_(int)];
|
||||
char eventlist_l_[PADL_(struct kevent *)]; struct kevent * eventlist; char eventlist_r_[PADR_(struct kevent *)];
|
||||
char nevents_l_[PADL_(int)]; int nevents; char nevents_r_[PADR_(int)];
|
||||
char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)];
|
||||
};
|
||||
struct extattr_set_fd_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)];
|
||||
char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)];
|
||||
char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)];
|
||||
char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)];
|
||||
};
|
||||
struct extattr_get_fd_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)];
|
||||
char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)];
|
||||
char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)];
|
||||
char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)];
|
||||
};
|
||||
struct extattr_delete_fd_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)];
|
||||
char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)];
|
||||
};
|
||||
struct sendfile_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)];
|
||||
char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)];
|
||||
char hdtr_l_[PADL_(struct sf_hdtr *)]; struct sf_hdtr * hdtr; char hdtr_r_[PADR_(struct sf_hdtr *)];
|
||||
char sbytes_l_[PADL_(off_t *)]; off_t * sbytes; char sbytes_r_[PADR_(off_t *)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
};
|
||||
struct sctp_peeloff_args {
|
||||
char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)];
|
||||
char name_l_[PADL_(uint32_t)]; uint32_t name; char name_r_[PADR_(uint32_t)];
|
||||
};
|
||||
struct sctp_generic_sendmsg_args {
|
||||
char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)];
|
||||
char msg_l_[PADL_(caddr_t)]; caddr_t msg; char msg_r_[PADR_(caddr_t)];
|
||||
char mlen_l_[PADL_(int)]; int mlen; char mlen_r_[PADR_(int)];
|
||||
char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)];
|
||||
char tolen_l_[PADL_(__socklen_t)]; __socklen_t tolen; char tolen_r_[PADR_(__socklen_t)];
|
||||
char sinfo_l_[PADL_(struct sctp_sndrcvinfo *)]; struct sctp_sndrcvinfo * sinfo; char sinfo_r_[PADR_(struct sctp_sndrcvinfo *)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
};
|
||||
struct sctp_generic_sendmsg_iov_args {
|
||||
char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)];
|
||||
char iov_l_[PADL_(struct iovec *)]; struct iovec * iov; char iov_r_[PADR_(struct iovec *)];
|
||||
char iovlen_l_[PADL_(int)]; int iovlen; char iovlen_r_[PADR_(int)];
|
||||
char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)];
|
||||
char tolen_l_[PADL_(__socklen_t)]; __socklen_t tolen; char tolen_r_[PADR_(__socklen_t)];
|
||||
char sinfo_l_[PADL_(struct sctp_sndrcvinfo *)]; struct sctp_sndrcvinfo * sinfo; char sinfo_r_[PADR_(struct sctp_sndrcvinfo *)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
};
|
||||
struct sctp_generic_recvmsg_args {
|
||||
char sd_l_[PADL_(int)]; int sd; char sd_r_[PADR_(int)];
|
||||
char iov_l_[PADL_(struct iovec *)]; struct iovec * iov; char iov_r_[PADR_(struct iovec *)];
|
||||
char iovlen_l_[PADL_(int)]; int iovlen; char iovlen_r_[PADR_(int)];
|
||||
char from_l_[PADL_(struct sockaddr *)]; struct sockaddr * from; char from_r_[PADR_(struct sockaddr *)];
|
||||
char fromlenaddr_l_[PADL_(__socklen_t *)]; __socklen_t * fromlenaddr; char fromlenaddr_r_[PADR_(__socklen_t *)];
|
||||
char sinfo_l_[PADL_(struct sctp_sndrcvinfo *)]; struct sctp_sndrcvinfo * sinfo; char sinfo_r_[PADR_(struct sctp_sndrcvinfo *)];
|
||||
char msg_flags_l_[PADL_(int *)]; int * msg_flags; char msg_flags_r_[PADR_(int *)];
|
||||
};
|
||||
struct pread_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)];
|
||||
char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)];
|
||||
char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)];
|
||||
};
|
||||
struct pwrite_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)];
|
||||
char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)];
|
||||
char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)];
|
||||
};
|
||||
struct openat_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
|
||||
char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)];
|
||||
char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)];
|
||||
};
|
||||
struct pselect_args {
|
||||
char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)];
|
||||
char in_l_[PADL_(fd_set *)]; fd_set * in; char in_r_[PADR_(fd_set *)];
|
||||
char ou_l_[PADL_(fd_set *)]; fd_set * ou; char ou_r_[PADR_(fd_set *)];
|
||||
char ex_l_[PADL_(fd_set *)]; fd_set * ex; char ex_r_[PADR_(fd_set *)];
|
||||
char ts_l_[PADL_(const struct timespec *)]; const struct timespec * ts; char ts_r_[PADR_(const struct timespec *)];
|
||||
char sm_l_[PADL_(const sigset_t *)]; const sigset_t * sm; char sm_r_[PADR_(const sigset_t *)];
|
||||
};
|
||||
struct cap_ioctls_limit_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char cmds_l_[PADL_(const u_long *)]; const u_long * cmds; char cmds_r_[PADR_(const u_long *)];
|
||||
char ncmds_l_[PADL_(size_t)]; size_t ncmds; char ncmds_r_[PADR_(size_t)];
|
||||
};
|
||||
struct cap_ioctls_get_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char cmds_l_[PADL_(u_long *)]; u_long * cmds; char cmds_r_[PADR_(u_long *)];
|
||||
char maxcmds_l_[PADL_(size_t)]; size_t maxcmds; char maxcmds_r_[PADR_(size_t)];
|
||||
};
|
||||
struct cap_fcntls_limit_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char fcntlrights_l_[PADL_(uint32_t)]; uint32_t fcntlrights; char fcntlrights_r_[PADR_(uint32_t)];
|
||||
};
|
||||
struct cap_fcntls_get_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char fcntlrightsp_l_[PADL_(uint32_t *)]; uint32_t * fcntlrightsp; char fcntlrightsp_r_[PADR_(uint32_t *)];
|
||||
};
|
||||
struct bindat_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)];
|
||||
char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)];
|
||||
};
|
||||
struct connectat_args {
|
||||
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)];
|
||||
char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)];
|
||||
};
|
||||
struct accept4_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char name_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict name; char name_r_[PADR_(struct sockaddr *__restrict)];
|
||||
char anamelen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict anamelen; char anamelen_r_[PADR_(__socklen_t *__restrict)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
};
|
||||
struct ppoll_args {
|
||||
char fds_l_[PADL_(struct pollfd *)]; struct pollfd * fds; char fds_r_[PADR_(struct pollfd *)];
|
||||
char nfds_l_[PADL_(u_int)]; u_int nfds; char nfds_r_[PADR_(u_int)];
|
||||
char ts_l_[PADL_(const struct timespec *)]; const struct timespec * ts; char ts_r_[PADR_(const struct timespec *)];
|
||||
char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)];
|
||||
};
|
||||
int sys_read(struct thread *, struct read_args *);
|
||||
int sys_write(struct thread *, struct write_args *);
|
||||
int sys_open(struct thread *, struct open_args *);
|
||||
int sys_close(struct thread *, struct close_args *);
|
||||
int sys_recvmsg(struct thread *, struct recvmsg_args *);
|
||||
int sys_sendmsg(struct thread *, struct sendmsg_args *);
|
||||
int sys_recvfrom(struct thread *, struct recvfrom_args *);
|
||||
int sys_accept(struct thread *, struct accept_args *);
|
||||
int sys_getpeername(struct thread *, struct getpeername_args *);
|
||||
int sys_getsockname(struct thread *, struct getsockname_args *);
|
||||
int sys_access(struct thread *, struct access_args *);
|
||||
int sys_ioctl(struct thread *, struct ioctl_args *);
|
||||
int sys_dup2(struct thread *, struct dup2_args *);
|
||||
int sys_fcntl(struct thread *, struct fcntl_args *);
|
||||
int sys_select(struct thread *, struct select_args *);
|
||||
int sys_connect(struct thread *, struct connect_args *);
|
||||
int sys_bind(struct thread *, struct bind_args *);
|
||||
int sys_setsockopt(struct thread *, struct setsockopt_args *);
|
||||
int sys_listen(struct thread *, struct listen_args *);
|
||||
int sys_getsockopt(struct thread *, struct getsockopt_args *);
|
||||
int sys_readv(struct thread *, struct readv_args *);
|
||||
int sys_writev(struct thread *, struct writev_args *);
|
||||
int sys_shutdown(struct thread *, struct shutdown_args *);
|
||||
int sys_socketpair(struct thread *, struct socketpair_args *);
|
||||
int sys___sysctl(struct thread *, struct sysctl_args *);
|
||||
int sys_preadv(struct thread *, struct preadv_args *);
|
||||
int sys_pwritev(struct thread *, struct pwritev_args *);
|
||||
int sys_kqueue(struct thread *, struct kqueue_args *);
|
||||
int sys_kevent(struct thread *, struct kevent_args *);
|
||||
int sys_sendfile(struct thread *, struct sendfile_args *);
|
||||
int sys_sctp_peeloff(struct thread *, struct sctp_peeloff_args *);
|
||||
int sys_sctp_generic_sendmsg(struct thread *, struct sctp_generic_sendmsg_args *);
|
||||
int sys_sctp_generic_sendmsg_iov(struct thread *, struct sctp_generic_sendmsg_iov_args *);
|
||||
int sys_sctp_generic_recvmsg(struct thread *, struct sctp_generic_recvmsg_args *);
|
||||
int sys_pread(struct thread *, struct pread_args *);
|
||||
int sys_pwrite(struct thread *, struct pwrite_args *);
|
||||
int sys_openat(struct thread *, struct openat_args *);
|
||||
int sys_pselect(struct thread *, struct pselect_args *);
|
||||
int sys_bindat(struct thread *, struct bindat_args *);
|
||||
int sys_connectat(struct thread *, struct connectat_args *);
|
||||
int sys_accept4(struct thread *, struct accept4_args *);
|
||||
int sys_ppoll(struct thread *, struct ppoll_args *);
|
||||
|
||||
#undef PAD_
|
||||
#undef PADL_
|
||||
#undef PADR_
|
||||
|
||||
#endif /* !_SYS_SYSPROTO_H_ */
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 1994 Christos Zoulas
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef FSTACK
|
||||
#include "compat.h"
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <stringlist.h>
|
||||
|
||||
#define _SL_CHUNKSIZE 20
|
||||
|
||||
/*
|
||||
* sl_init(): Initialize a string list
|
||||
*/
|
||||
StringList *
|
||||
sl_init(void)
|
||||
{
|
||||
StringList *sl;
|
||||
|
||||
sl = malloc(sizeof(StringList));
|
||||
if (sl == NULL)
|
||||
err(1, "stringlist: %d, %s\n", errno, strerror(errno));
|
||||
|
||||
sl->sl_cur = 0;
|
||||
sl->sl_max = _SL_CHUNKSIZE;
|
||||
sl->sl_str = malloc(sl->sl_max * sizeof(char *));
|
||||
if (sl->sl_str == NULL)
|
||||
err(1, "stringlist: %d, %s\n", errno, strerror(errno));
|
||||
return sl;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* sl_add(): Add an item to the string list
|
||||
*/
|
||||
int
|
||||
sl_add(StringList *sl, char *name)
|
||||
{
|
||||
if (sl->sl_cur == sl->sl_max - 1) {
|
||||
sl->sl_max += _SL_CHUNKSIZE;
|
||||
sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *));
|
||||
if (sl->sl_str == NULL)
|
||||
return (-1);
|
||||
}
|
||||
sl->sl_str[sl->sl_cur++] = name;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* sl_free(): Free a stringlist
|
||||
*/
|
||||
void
|
||||
sl_free(StringList *sl, int all)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (sl == NULL)
|
||||
return;
|
||||
if (sl->sl_str) {
|
||||
if (all)
|
||||
for (i = 0; i < sl->sl_cur; i++)
|
||||
free(sl->sl_str[i]);
|
||||
free(sl->sl_str);
|
||||
}
|
||||
free(sl);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* sl_find(): Find a name in the string list
|
||||
*/
|
||||
char *
|
||||
sl_find(StringList *sl, const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sl->sl_cur; i++)
|
||||
if (strcmp(sl->sl_str[i], name) == 0)
|
||||
return sl->sl_str[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
# $FreeBSD$
|
||||
# $Whistle: Makefile,v 1.4 1999/01/17 03:41:02 julian Exp $
|
||||
|
||||
TOPDIR?=${CURDIR}/../..
|
||||
|
||||
ifeq ($(FF_DPDK),)
|
||||
FF_DPDK=${TOPDIR}/dpdk/x86_64-native-linuxapp-gcc
|
||||
endif
|
||||
|
||||
PACKAGE=lib${LIB}
|
||||
LIB= netgraph
|
||||
WARNS?= 3
|
||||
MAN= netgraph.3
|
||||
|
||||
SHLIB_MAJOR= 4
|
||||
|
||||
DPDK_CFLAGS= -g -Wall -Werror -include ${FF_DPDK}/include/rte_config.h
|
||||
DPDK_CFLAGS+= -march=native -DRTE_MACHINE_CPUFLAG_SSE -DRTE_MACHINE_CPUFLAG_SSE2 -DRTE_MACHINE_CPUFLAG_SSE3
|
||||
DPDK_CFLAGS+= -DRTE_MACHINE_CPUFLAG_SSSE3 -DRTE_MACHINE_CPUFLAG_SSE4_1 -DRTE_MACHINE_CPUFLAG_SSE4_2
|
||||
DPDK_CFLAGS+= -DRTE_COMPILE_TIME_CPUFLAGS=RTE_CPUFLAG_SSE,RTE_CPUFLAG_SSE2,RTE_CPUFLAG_SSE3,RTE_CPUFLAG_SSSE3,RTE_CPUFLAG_SSE4_1,RTE_CPUFLAG_SSE4_2
|
||||
DPDK_CFLAGS+= -I${FF_DPDK}/include
|
||||
|
||||
CFLAGS+= ${DPDK_CFLAGS}
|
||||
CFLAGS+= -I${TOPDIR}/lib
|
||||
|
||||
SRCS= sock.c msg.c debug.c compat.c
|
||||
INCS= netgraph.h
|
||||
|
||||
MLINKS+= netgraph.3 NgMkSockNode.3
|
||||
MLINKS+= netgraph.3 NgNameNode.3
|
||||
MLINKS+= netgraph.3 NgSendMsg.3
|
||||
MLINKS+= netgraph.3 NgSendAsciiMsg.3
|
||||
MLINKS+= netgraph.3 NgSendMsgReply.3
|
||||
MLINKS+= netgraph.3 NgRecvMsg.3
|
||||
MLINKS+= netgraph.3 NgAllocRecvMsg.3
|
||||
MLINKS+= netgraph.3 NgRecvAsciiMsg.3
|
||||
MLINKS+= netgraph.3 NgAllocRecvAsciiMsg.3
|
||||
MLINKS+= netgraph.3 NgSendData.3
|
||||
MLINKS+= netgraph.3 NgRecvData.3
|
||||
MLINKS+= netgraph.3 NgAllocRecvData.3
|
||||
MLINKS+= netgraph.3 NgSetDebug.3
|
||||
MLINKS+= netgraph.3 NgSetErrLog.3
|
||||
|
||||
include ${TOPDIR}/tools/lib.mk
|
||||
|
||||
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* 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/sysproto.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ff_api.h"
|
||||
#include "ff_ipc.h"
|
||||
#include "netgraph.h"
|
||||
|
||||
static int
|
||||
ngctl(int cmd, void *data, size_t len)
|
||||
{
|
||||
struct ff_msg *msg, *retmsg = NULL;
|
||||
|
||||
msg = ff_ipc_msg_alloc();
|
||||
if (msg == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len > msg->buf_len) {
|
||||
errno = EINVAL;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg->msg_type = FF_NGCTL;
|
||||
msg->ngctl.cmd = cmd;
|
||||
msg->ngctl.data = msg->buf_addr;
|
||||
|
||||
switch (cmd) {
|
||||
case NGCTL_SOCKET:
|
||||
case NGCTL_CLOSE:
|
||||
memcpy(msg->ngctl.data, data, len);
|
||||
break;
|
||||
case NGCTL_BIND:
|
||||
case NGCTL_CONNECT:
|
||||
{
|
||||
struct bind_args *src = (struct bind_args *)data;
|
||||
struct bind_args *dst = (struct bind_args *)(msg->ngctl.data);
|
||||
dst->s = src->s;
|
||||
dst->name = (char *)msg->buf_addr + sizeof(struct bind_args);
|
||||
dst->namelen = src->namelen;
|
||||
memcpy(dst->name, src->name, src->namelen);
|
||||
break;
|
||||
}
|
||||
case NGCTL_SEND:
|
||||
{
|
||||
struct sendto_args *src = (struct sendto_args *)data;
|
||||
struct sendto_args *dst = (struct sendto_args *)(msg->ngctl.data);
|
||||
dst->s = src->s;
|
||||
dst->buf = (char *)msg->buf_addr + sizeof(struct sendto_args);
|
||||
dst->len = src->len;
|
||||
dst->flags = src->flags;
|
||||
dst->to = dst->buf + src->len;
|
||||
dst->tolen = src->tolen;
|
||||
memcpy(dst->buf, src->buf, src->len);
|
||||
memcpy(dst->to, src->to, src->tolen);
|
||||
break;
|
||||
}
|
||||
case NGCTL_RECV:
|
||||
{
|
||||
struct recvfrom_args *src = (struct recvfrom_args *)data;
|
||||
struct recvfrom_args *dst = (struct recvfrom_args *)(msg->ngctl.data);
|
||||
dst->s = src->s;
|
||||
dst->buf = msg->buf_addr + sizeof(struct recvfrom_args);
|
||||
dst->len = src->len;
|
||||
dst->flags = src->flags;
|
||||
dst->from = (struct sockaddr *)dst->buf + src->len;
|
||||
dst->fromlenaddr = (socklen_t *)dst->buf + src->len + *(src->fromlenaddr);
|
||||
memcpy(dst->buf, src->buf, src->len);
|
||||
memcpy(dst->from, src->from, *(src->fromlenaddr));
|
||||
memcpy(dst->fromlenaddr, src->fromlenaddr, sizeof(socklen_t));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
errno = EINVAL;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = ff_ipc_send(msg);
|
||||
if (ret < 0) {
|
||||
errno = EPIPE;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
if (retmsg != NULL) {
|
||||
ff_ipc_msg_free(retmsg);
|
||||
}
|
||||
ret = ff_ipc_recv(&retmsg);
|
||||
if (ret < 0) {
|
||||
errno = EPIPE;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
} while (msg != retmsg);
|
||||
|
||||
if (retmsg->result != 0) {
|
||||
ret = -1;
|
||||
errno = retmsg->result;
|
||||
} else {
|
||||
ret = msg->ngctl.ret;
|
||||
|
||||
if (cmd == NGCTL_RECV) {
|
||||
struct recvfrom_args *dst = (struct recvfrom_args *)data;
|
||||
struct recvfrom_args *src = (struct recvfrom_args *)(msg->ngctl.data);
|
||||
memcpy(dst->buf, src->buf, src->len);
|
||||
memcpy(dst->from, src->from, *(src->fromlenaddr));
|
||||
memcpy(dst->fromlenaddr, src->fromlenaddr, sizeof(socklen_t));
|
||||
}
|
||||
}
|
||||
|
||||
ff_ipc_msg_free(msg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
ng_socket(int domain, int type, int protocol)
|
||||
{
|
||||
struct socket_args sa;
|
||||
sa.domain = domain;
|
||||
sa.type = type;
|
||||
sa.protocol = protocol;
|
||||
|
||||
return ngctl(NGCTL_SOCKET, (void *)&sa, sizeof(sa));
|
||||
}
|
||||
|
||||
int
|
||||
ng_bind(int sockfd, const struct sockaddr *addr,
|
||||
socklen_t addrlen)
|
||||
{
|
||||
size_t len;
|
||||
struct bind_args ba;
|
||||
|
||||
ba.s = sockfd;
|
||||
ba.name = (char *)addr;
|
||||
ba.namelen = addrlen;
|
||||
|
||||
len = sizeof(ba) + addrlen;
|
||||
|
||||
return ngctl(NGCTL_BIND, (void *)&ba, len);
|
||||
}
|
||||
|
||||
int
|
||||
ng_connect(int sockfd, const struct sockaddr *addr,
|
||||
socklen_t addrlen)
|
||||
{
|
||||
size_t len;
|
||||
struct connect_args ca;
|
||||
|
||||
ca.s = sockfd;
|
||||
ca.name = (char *)addr;
|
||||
ca.namelen = addrlen;
|
||||
|
||||
len = sizeof(ca) + addrlen;
|
||||
|
||||
return ngctl(NGCTL_CONNECT, (void *)&ca, len);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
ng_sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t addrlen)
|
||||
{
|
||||
size_t datalen;
|
||||
|
||||
struct sendto_args sa;
|
||||
sa.s = sockfd;
|
||||
sa.buf = (void *)buf;
|
||||
sa.len = len;
|
||||
sa.flags = flags;
|
||||
sa.to = (char *)dest_addr;
|
||||
sa.tolen = addrlen;
|
||||
|
||||
datalen = sizeof(sa) + len + addrlen;
|
||||
return ngctl(NGCTL_SEND, (void *)&sa, datalen);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
ng_recvfrom(int sockfd, void *buf, size_t len, int flags,
|
||||
struct sockaddr *src_addr, socklen_t *addrlen)
|
||||
{
|
||||
size_t datalen;
|
||||
|
||||
struct recvfrom_args ra;
|
||||
ra.s = sockfd;
|
||||
ra.buf = buf;
|
||||
ra.len = len;
|
||||
ra.flags = flags;
|
||||
ra.from = src_addr;
|
||||
ra.fromlenaddr = addrlen;
|
||||
|
||||
datalen = sizeof(ra) + len + (*addrlen) + sizeof(socklen_t);
|
||||
return ngctl(NGCTL_RECV, (void *)&ra, datalen);
|
||||
}
|
||||
|
||||
int
|
||||
ng_close(int fd)
|
||||
{
|
||||
struct close_args ca;
|
||||
ca.fd = fd;
|
||||
|
||||
return ngctl(NGCTL_CLOSE, (void *)&ca, sizeof(ca));
|
||||
}
|
||||
|
|
@ -0,0 +1,359 @@
|
|||
/*
|
||||
* debug.c
|
||||
*
|
||||
* 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@whistle.com>
|
||||
*
|
||||
* $Whistle: debug.c,v 1.24 1999/01/24 01:15:33 archie Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <net/bpf.h>
|
||||
|
||||
#include <netgraph/ng_message.h>
|
||||
#include <netgraph/ng_socket.h>
|
||||
|
||||
#include "netgraph.h"
|
||||
#include "internal.h"
|
||||
|
||||
#include <netgraph/ng_UI.h>
|
||||
#include <netgraph/ng_async.h>
|
||||
#include <netgraph/ng_atmllc.h>
|
||||
#include <netgraph/ng_bpf.h>
|
||||
#include <netgraph/ng_bridge.h>
|
||||
#include <netgraph/ng_car.h>
|
||||
#include <netgraph/ng_cisco.h>
|
||||
#include <netgraph/ng_deflate.h>
|
||||
#include <netgraph/ng_device.h>
|
||||
#include <netgraph/ng_echo.h>
|
||||
#include <netgraph/ng_eiface.h>
|
||||
#include <netgraph/ng_etf.h>
|
||||
#include <netgraph/ng_ether.h>
|
||||
#include <netgraph/ng_ether_echo.h>
|
||||
#include <netgraph/ng_frame_relay.h>
|
||||
#include <netgraph/ng_gif.h>
|
||||
#include <netgraph/ng_gif_demux.h>
|
||||
#include <netgraph/ng_hole.h>
|
||||
#include <netgraph/ng_hub.h>
|
||||
#include <netgraph/ng_iface.h>
|
||||
#include <netgraph/ng_ip_input.h>
|
||||
#include <netgraph/ng_ipfw.h>
|
||||
#include <netgraph/ng_ksocket.h>
|
||||
#include <netgraph/ng_l2tp.h>
|
||||
#include <netgraph/ng_lmi.h>
|
||||
#include <netgraph/ng_mppc.h>
|
||||
#include <netgraph/ng_nat.h>
|
||||
#include <netgraph/netflow/ng_netflow.h>
|
||||
#include <netgraph/ng_one2many.h>
|
||||
#include <netgraph/ng_patch.h>
|
||||
#include <netgraph/ng_pipe.h>
|
||||
#include <netgraph/ng_ppp.h>
|
||||
#include <netgraph/ng_pppoe.h>
|
||||
#include <netgraph/ng_pptpgre.h>
|
||||
#include <netgraph/ng_pred1.h>
|
||||
#include <netgraph/ng_rfc1490.h>
|
||||
#include <netgraph/ng_socket.h>
|
||||
#include <netgraph/ng_source.h>
|
||||
#include <netgraph/ng_split.h>
|
||||
#include <netgraph/ng_sppp.h>
|
||||
#include <netgraph/ng_tag.h>
|
||||
#include <netgraph/ng_tcpmss.h>
|
||||
#include <netgraph/ng_tee.h>
|
||||
#include <netgraph/ng_tty.h>
|
||||
#include <netgraph/ng_vjc.h>
|
||||
#include <netgraph/ng_vlan.h>
|
||||
#ifdef WHISTLE
|
||||
#include <machine/../isa/df_def.h>
|
||||
#include <machine/../isa/if_wfra.h>
|
||||
#include <machine/../isa/ipac.h>
|
||||
#include <netgraph/ng_df.h>
|
||||
#include <netgraph/ng_ipac.h>
|
||||
#include <netgraph/ng_tn.h>
|
||||
#endif
|
||||
|
||||
/* Global debug level */
|
||||
int _gNgDebugLevel = 0;
|
||||
|
||||
/* Debug printing functions */
|
||||
void (*_NgLog) (const char *fmt,...) = warn;
|
||||
void (*_NgLogx) (const char *fmt,...) = warnx;
|
||||
|
||||
/* Internal functions */
|
||||
static const char *NgCookie(int cookie);
|
||||
|
||||
/* Known typecookie list */
|
||||
struct ng_cookie {
|
||||
int cookie;
|
||||
const char *type;
|
||||
};
|
||||
|
||||
#define COOKIE(c) { NGM_ ## c ## _COOKIE, #c }
|
||||
|
||||
/* List of known cookies */
|
||||
static const struct ng_cookie cookies[] = {
|
||||
COOKIE(UI),
|
||||
COOKIE(ASYNC),
|
||||
COOKIE(ATMLLC),
|
||||
COOKIE(BPF),
|
||||
COOKIE(BRIDGE),
|
||||
COOKIE(CAR),
|
||||
COOKIE(CISCO),
|
||||
COOKIE(DEFLATE),
|
||||
COOKIE(DEVICE),
|
||||
COOKIE(ECHO),
|
||||
COOKIE(EIFACE),
|
||||
COOKIE(ETF),
|
||||
COOKIE(ETHER),
|
||||
COOKIE(ETHER_ECHO),
|
||||
COOKIE(FRAMERELAY),
|
||||
COOKIE(GIF),
|
||||
COOKIE(GIF_DEMUX),
|
||||
COOKIE(GENERIC),
|
||||
COOKIE(HOLE),
|
||||
COOKIE(HUB),
|
||||
COOKIE(IFACE),
|
||||
COOKIE(IP_INPUT),
|
||||
COOKIE(IPFW),
|
||||
COOKIE(KSOCKET),
|
||||
COOKIE(L2TP),
|
||||
COOKIE(LMI),
|
||||
COOKIE(MPPC),
|
||||
COOKIE(NAT),
|
||||
COOKIE(NETFLOW),
|
||||
COOKIE(ONE2MANY),
|
||||
COOKIE(PATCH),
|
||||
COOKIE(PIPE),
|
||||
COOKIE(PPP),
|
||||
COOKIE(PPPOE),
|
||||
COOKIE(PPTPGRE),
|
||||
COOKIE(PRED1),
|
||||
COOKIE(RFC1490),
|
||||
COOKIE(SOCKET),
|
||||
COOKIE(SOURCE),
|
||||
COOKIE(SPLIT),
|
||||
COOKIE(SPPP),
|
||||
COOKIE(TAG),
|
||||
COOKIE(TCPMSS),
|
||||
COOKIE(TEE),
|
||||
COOKIE(TTY),
|
||||
COOKIE(VJC),
|
||||
COOKIE(VLAN),
|
||||
#ifdef WHISTLE
|
||||
COOKIE(DF),
|
||||
COOKIE(IPAC),
|
||||
COOKIE(TN),
|
||||
COOKIE(WFRA),
|
||||
#endif
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* Set debug level, ie, verbosity, if "level" is non-negative.
|
||||
* Returns old debug level.
|
||||
*/
|
||||
int
|
||||
NgSetDebug(int level)
|
||||
{
|
||||
int old = _gNgDebugLevel;
|
||||
|
||||
if (level >= 0)
|
||||
_gNgDebugLevel = level;
|
||||
return (old);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set debug logging functions.
|
||||
*/
|
||||
void
|
||||
NgSetErrLog(void (*log) (const char *fmt,...),
|
||||
void (*logx) (const char *fmt,...))
|
||||
{
|
||||
_NgLog = log;
|
||||
_NgLogx = logx;
|
||||
}
|
||||
|
||||
/*
|
||||
* Display a netgraph sockaddr
|
||||
*/
|
||||
void
|
||||
_NgDebugSockaddr(const struct sockaddr_ng *sg)
|
||||
{
|
||||
NGLOGX("SOCKADDR: { fam=%d len=%d addr=\"%s\" }",
|
||||
sg->sg_family, sg->sg_len, sg->sg_data);
|
||||
}
|
||||
|
||||
#define ARGS_BUFSIZE 2048
|
||||
#define RECURSIVE_DEBUG_ADJUST 4
|
||||
|
||||
/*
|
||||
* Display a negraph message
|
||||
*/
|
||||
void
|
||||
_NgDebugMsg(const struct ng_mesg *msg, const char *path)
|
||||
{
|
||||
u_char buf[2 * sizeof(struct ng_mesg) + ARGS_BUFSIZE];
|
||||
struct ng_mesg *const req = (struct ng_mesg *)buf;
|
||||
struct ng_mesg *const bin = (struct ng_mesg *)req->data;
|
||||
int arglen, csock = -1;
|
||||
|
||||
/* Display header stuff */
|
||||
NGLOGX("NG_MESG :");
|
||||
NGLOGX(" vers %d", msg->header.version);
|
||||
NGLOGX(" arglen %u", msg->header.arglen);
|
||||
NGLOGX(" flags %x", msg->header.flags);
|
||||
NGLOGX(" token %u", msg->header.token);
|
||||
NGLOGX(" cookie %s (%u)",
|
||||
NgCookie(msg->header.typecookie), msg->header.typecookie);
|
||||
|
||||
/* At lower debugging levels, skip ASCII translation */
|
||||
if (_gNgDebugLevel <= 2)
|
||||
goto fail2;
|
||||
|
||||
/* If path is not absolute, don't bother trying to use relative
|
||||
address on a different socket for the ASCII translation */
|
||||
if (strchr(path, ':') == NULL)
|
||||
goto fail2;
|
||||
|
||||
/* Get a temporary socket */
|
||||
if (NgMkSockNode(NULL, &csock, NULL) < 0)
|
||||
goto fail;
|
||||
|
||||
/* Copy binary message into request message payload */
|
||||
arglen = msg->header.arglen;
|
||||
if (arglen > ARGS_BUFSIZE)
|
||||
arglen = ARGS_BUFSIZE;
|
||||
memcpy(bin, msg, sizeof(*msg) + arglen);
|
||||
bin->header.arglen = arglen;
|
||||
|
||||
/* Lower debugging to avoid infinite recursion */
|
||||
_gNgDebugLevel -= RECURSIVE_DEBUG_ADJUST;
|
||||
|
||||
/* Ask the node to translate the binary message to ASCII for us */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_BINARY2ASCII, bin, sizeof(*bin) + bin->header.arglen) < 0) {
|
||||
_gNgDebugLevel += RECURSIVE_DEBUG_ADJUST;
|
||||
goto fail;
|
||||
}
|
||||
if (NgRecvMsg(csock, req, sizeof(buf), NULL) < 0) {
|
||||
_gNgDebugLevel += RECURSIVE_DEBUG_ADJUST;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Restore debugging level */
|
||||
_gNgDebugLevel += RECURSIVE_DEBUG_ADJUST;
|
||||
|
||||
/* Display command string and arguments */
|
||||
NGLOGX(" cmd %s (%d)", bin->header.cmdstr, bin->header.cmd);
|
||||
NGLOGX(" args %s", bin->data);
|
||||
goto done;
|
||||
|
||||
fail:
|
||||
/* Just display binary version */
|
||||
NGLOGX(" [error decoding message: %s]", strerror(errno));
|
||||
fail2:
|
||||
NGLOGX(" cmd %d", msg->header.cmd);
|
||||
NGLOGX(" args (%d bytes)", msg->header.arglen);
|
||||
_NgDebugBytes((u_char *)msg->data, msg->header.arglen);
|
||||
|
||||
done:
|
||||
if (csock != -1)
|
||||
(void)close(csock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the name of the node type corresponding to the cookie
|
||||
*/
|
||||
static const char *
|
||||
NgCookie(int cookie)
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; cookies[k].cookie != 0; k++) {
|
||||
if (cookies[k].cookie == cookie)
|
||||
return cookies[k].type;
|
||||
}
|
||||
return "??";
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump bytes in hex
|
||||
*/
|
||||
void
|
||||
_NgDebugBytes(const u_char *ptr, int len)
|
||||
{
|
||||
char buf[100];
|
||||
int k, count;
|
||||
|
||||
#define BYPERLINE 16
|
||||
|
||||
for (count = 0; count < len; ptr += BYPERLINE, count += BYPERLINE) {
|
||||
|
||||
/* Do hex */
|
||||
snprintf(buf, sizeof(buf), "%04x: ", count);
|
||||
for (k = 0; k < BYPERLINE; k++, count++)
|
||||
if (count < len)
|
||||
snprintf(buf + strlen(buf),
|
||||
sizeof(buf) - strlen(buf), "%02x ", ptr[k]);
|
||||
else
|
||||
snprintf(buf + strlen(buf),
|
||||
sizeof(buf) - strlen(buf), " ");
|
||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
|
||||
count -= BYPERLINE;
|
||||
|
||||
/* Do ASCII */
|
||||
for (k = 0; k < BYPERLINE; k++, count++)
|
||||
if (count < len)
|
||||
snprintf(buf + strlen(buf),
|
||||
sizeof(buf) - strlen(buf),
|
||||
"%c", isprint(ptr[k]) ? ptr[k] : '.');
|
||||
else
|
||||
snprintf(buf + strlen(buf),
|
||||
sizeof(buf) - strlen(buf), " ");
|
||||
count -= BYPERLINE;
|
||||
|
||||
/* Print it */
|
||||
NGLOGX("%s", buf);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
|
||||
/*
|
||||
* internal.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@whistle.com>
|
||||
*
|
||||
* $FreeBSD$
|
||||
* $Whistle: internal.h,v 1.5 1999/01/20 00:57:22 archie Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <sys/linker.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
|
||||
/* the 'sockaddr overhead' for a netgraph address. This is everything before
|
||||
* the string that constitutes the address. */
|
||||
#define NGSA_OVERHEAD (offsetof(struct sockaddr_ng, sg_data))
|
||||
|
||||
extern int _gNgDebugLevel;
|
||||
|
||||
extern void (*_NgLog)(const char *fmt, ...);
|
||||
extern void (*_NgLogx)(const char *fmt, ...);
|
||||
|
||||
#define NGLOG (*_NgLog)
|
||||
#define NGLOGX (*_NgLogx)
|
||||
|
||||
extern void _NgDebugSockaddr(const struct sockaddr_ng *sg);
|
||||
extern void _NgDebugMsg(const struct ng_mesg *msg, const char *path);
|
||||
extern void _NgDebugBytes(const u_char *ptr, int size);
|
||||
|
||||
#ifdef FSTACK
|
||||
|
||||
#define socket(a,b,c) ng_socket(a,b,c)
|
||||
#define connect(a,b,c) ng_connect(a,b,c)
|
||||
#define bind(a,b,c) ng_bind(a,b,c)
|
||||
#define sendto(a,b,c,d,e,f) ng_sendto(a,b,c,d,e,f)
|
||||
#define recvfrom(a,b,c,d,e,f) ng_recvfrom(a,b,c,d,e,f)
|
||||
#define close(a) ng_close(a)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,397 @@
|
|||
/*
|
||||
* msg.c
|
||||
*
|
||||
* 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@whistle.com>
|
||||
*
|
||||
* $Whistle: msg.c,v 1.9 1999/01/20 00:57:23 archie Exp $
|
||||
*/
|
||||
|
||||
#ifdef FSTACK
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdarg.h>
|
||||
#include <netgraph/ng_message.h>
|
||||
#include <netgraph/ng_socket.h>
|
||||
|
||||
#include "netgraph.h"
|
||||
#include "internal.h"
|
||||
|
||||
/* Next message token value */
|
||||
static int gMsgId;
|
||||
|
||||
/* For delivering both messages and replies */
|
||||
static int NgDeliverMsg(int cs, const char *path,
|
||||
const struct ng_mesg *hdr, const void *args, size_t arglen);
|
||||
|
||||
/*
|
||||
* Send a message to a node using control socket node "cs".
|
||||
* Returns -1 if error and sets errno appropriately.
|
||||
* If successful, returns the message ID (token) used.
|
||||
*/
|
||||
int
|
||||
NgSendMsg(int cs, const char *path,
|
||||
int cookie, int cmd, const void *args, size_t arglen)
|
||||
{
|
||||
struct ng_mesg msg;
|
||||
|
||||
/* Prepare message header */
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.header.version = NG_VERSION;
|
||||
msg.header.typecookie = cookie;
|
||||
if (++gMsgId < 0)
|
||||
gMsgId = 1;
|
||||
msg.header.token = gMsgId;
|
||||
msg.header.flags = NGF_ORIG;
|
||||
msg.header.cmd = cmd;
|
||||
snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd);
|
||||
|
||||
/* Deliver message */
|
||||
if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0)
|
||||
return (-1);
|
||||
return (msg.header.token);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a message given in ASCII format. We first ask the node to translate
|
||||
* the command into binary, and then we send the binary.
|
||||
*/
|
||||
int
|
||||
NgSendAsciiMsg(int cs, const char *path, const char *fmt, ...)
|
||||
{
|
||||
struct ng_mesg *reply, *binary, *ascii;
|
||||
char *buf, *cmd, *args;
|
||||
va_list fmtargs;
|
||||
int token;
|
||||
|
||||
/* Parse out command and arguments */
|
||||
va_start(fmtargs, fmt);
|
||||
vasprintf(&buf, fmt, fmtargs);
|
||||
va_end(fmtargs);
|
||||
if (buf == NULL)
|
||||
return (-1);
|
||||
|
||||
/* Parse out command, arguments */
|
||||
for (cmd = buf; isspace(*cmd); cmd++)
|
||||
;
|
||||
for (args = cmd; *args != '\0' && !isspace(*args); args++)
|
||||
;
|
||||
if (*args != '\0') {
|
||||
while (isspace(*args))
|
||||
*args++ = '\0';
|
||||
}
|
||||
|
||||
/* Get a bigger buffer to hold inner message header plus arg string */
|
||||
if ((ascii = malloc(sizeof(struct ng_mesg)
|
||||
+ strlen(args) + 1)) == NULL) {
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
memset(ascii, 0, sizeof(*ascii));
|
||||
|
||||
/* Build inner header (only need cmdstr, arglen, and data fields) */
|
||||
strncpy((char *)ascii->header.cmdstr, cmd,
|
||||
sizeof(ascii->header.cmdstr) - 1);
|
||||
strcpy(ascii->data, args);
|
||||
ascii->header.arglen = strlen(ascii->data) + 1;
|
||||
free(buf);
|
||||
|
||||
/* Send node a request to convert ASCII to binary */
|
||||
if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE, NGM_ASCII2BINARY,
|
||||
(u_char *)ascii, sizeof(*ascii) + ascii->header.arglen) < 0) {
|
||||
free(ascii);
|
||||
return (-1);
|
||||
}
|
||||
free(ascii);
|
||||
|
||||
/* Get reply */
|
||||
if (NgAllocRecvMsg(cs, &reply, NULL) < 0)
|
||||
return (-1);
|
||||
|
||||
/* Now send binary version */
|
||||
binary = (struct ng_mesg *)reply->data;
|
||||
if (++gMsgId < 0)
|
||||
gMsgId = 1;
|
||||
binary->header.token = gMsgId;
|
||||
binary->header.version = NG_VERSION;
|
||||
if (NgDeliverMsg(cs,
|
||||
path, binary, binary->data, binary->header.arglen) < 0) {
|
||||
free(reply);
|
||||
return (-1);
|
||||
}
|
||||
token = binary->header.token;
|
||||
free(reply);
|
||||
return (token);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a message that is a reply to a previously received message.
|
||||
* Returns -1 and sets errno on error, otherwise returns zero.
|
||||
*/
|
||||
int
|
||||
NgSendReplyMsg(int cs, const char *path,
|
||||
const struct ng_mesg *msg, const void *args, size_t arglen)
|
||||
{
|
||||
struct ng_mesg rep;
|
||||
|
||||
/* Prepare message header */
|
||||
rep = *msg;
|
||||
rep.header.flags = NGF_RESP;
|
||||
|
||||
/* Deliver message */
|
||||
return (NgDeliverMsg(cs, path, &rep, args, arglen));
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a message to a node using control socket node "cs".
|
||||
* Returns -1 if error and sets errno appropriately, otherwise zero.
|
||||
*/
|
||||
static int
|
||||
NgDeliverMsg(int cs, const char *path,
|
||||
const struct ng_mesg *hdr, const void *args, size_t arglen)
|
||||
{
|
||||
u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD];
|
||||
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
|
||||
u_char *buf = NULL;
|
||||
struct ng_mesg *msg;
|
||||
int errnosv = 0;
|
||||
int rtn = 0;
|
||||
|
||||
/* Sanity check */
|
||||
if (args == NULL)
|
||||
arglen = 0;
|
||||
|
||||
/* Get buffer */
|
||||
if ((buf = malloc(sizeof(*msg) + arglen)) == NULL) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("malloc");
|
||||
rtn = -1;
|
||||
goto done;
|
||||
}
|
||||
msg = (struct ng_mesg *) buf;
|
||||
|
||||
/* Finalize message */
|
||||
*msg = *hdr;
|
||||
msg->header.arglen = arglen;
|
||||
memcpy(msg->data, args, arglen);
|
||||
|
||||
/* Prepare socket address */
|
||||
sg->sg_family = AF_NETGRAPH;
|
||||
/* XXX handle overflow */
|
||||
strlcpy(sg->sg_data, path, NG_PATHSIZ);
|
||||
sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
|
||||
|
||||
/* Debugging */
|
||||
if (_gNgDebugLevel >= 2) {
|
||||
NGLOGX("SENDING %s:",
|
||||
(msg->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE");
|
||||
_NgDebugSockaddr(sg);
|
||||
_NgDebugMsg(msg, sg->sg_data);
|
||||
}
|
||||
|
||||
/* Send it */
|
||||
if (sendto(cs, msg, sizeof(*msg) + arglen,
|
||||
0, (struct sockaddr *) sg, sg->sg_len) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("sendto(%s)", sg->sg_data);
|
||||
rtn = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
#ifndef FSTACK
|
||||
/* Wait for reply if there should be one. */
|
||||
if (msg->header.cmd & NGM_HASREPLY && !(msg->header.flags & NGF_RESP)) {
|
||||
struct pollfd rfds;
|
||||
int n;
|
||||
|
||||
rfds.fd = cs;
|
||||
rfds.events = POLLIN;
|
||||
rfds.revents = 0;
|
||||
n = poll(&rfds, 1, INFTIM);
|
||||
if (n == -1) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("poll");
|
||||
rtn = -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
done:
|
||||
/* Done */
|
||||
free(buf); /* OK if buf is NULL */
|
||||
errno = errnosv;
|
||||
return (rtn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Receive a control message.
|
||||
*
|
||||
* On error, this returns -1 and sets errno.
|
||||
* Otherwise, it returns the length of the received reply.
|
||||
*/
|
||||
int
|
||||
NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path)
|
||||
{
|
||||
u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD];
|
||||
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
|
||||
socklen_t sglen = sizeof(sgbuf);
|
||||
int len, errnosv;
|
||||
|
||||
/* Read reply */
|
||||
len = recvfrom(cs, rep, replen, 0, (struct sockaddr *) sg, &sglen);
|
||||
if (len < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("recvfrom");
|
||||
goto errout;
|
||||
}
|
||||
if (path != NULL)
|
||||
strlcpy(path, sg->sg_data, NG_PATHSIZ);
|
||||
|
||||
/* Debugging */
|
||||
if (_gNgDebugLevel >= 2) {
|
||||
NGLOGX("RECEIVED %s:",
|
||||
(rep->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE");
|
||||
_NgDebugSockaddr(sg);
|
||||
_NgDebugMsg(rep, sg->sg_data);
|
||||
}
|
||||
|
||||
/* Done */
|
||||
return (len);
|
||||
|
||||
errout:
|
||||
errno = errnosv;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Identical to NgRecvMsg() except buffer is dynamically allocated.
|
||||
*/
|
||||
int
|
||||
NgAllocRecvMsg(int cs, struct ng_mesg **rep, char *path)
|
||||
{
|
||||
int len;
|
||||
#ifndef FSTACK
|
||||
socklen_t optlen;
|
||||
|
||||
optlen = sizeof(len);
|
||||
if (getsockopt(cs, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 ||
|
||||
#else
|
||||
len = NGCTL_DEFAULT_RCVBUF;
|
||||
if (
|
||||
#endif
|
||||
(*rep = malloc(len)) == NULL)
|
||||
return (-1);
|
||||
if ((len = NgRecvMsg(cs, *rep, len, path)) < 0)
|
||||
free(*rep);
|
||||
return (len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Receive a control message and convert the arguments to ASCII
|
||||
*/
|
||||
int
|
||||
NgRecvAsciiMsg(int cs, struct ng_mesg *reply, size_t replen, char *path)
|
||||
{
|
||||
struct ng_mesg *msg, *ascii;
|
||||
int bufSize, errnosv;
|
||||
u_char *buf;
|
||||
|
||||
/* Allocate buffer */
|
||||
bufSize = 2 * sizeof(*reply) + replen;
|
||||
if ((buf = malloc(bufSize)) == NULL)
|
||||
return (-1);
|
||||
msg = (struct ng_mesg *)buf;
|
||||
ascii = (struct ng_mesg *)msg->data;
|
||||
|
||||
/* Get binary message */
|
||||
if (NgRecvMsg(cs, msg, bufSize, path) < 0)
|
||||
goto fail;
|
||||
memcpy(reply, msg, sizeof(*msg));
|
||||
|
||||
/* Ask originating node to convert the arguments to ASCII */
|
||||
if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE,
|
||||
NGM_BINARY2ASCII, msg, sizeof(*msg) + msg->header.arglen) < 0)
|
||||
goto fail;
|
||||
if (NgRecvMsg(cs, msg, bufSize, NULL) < 0)
|
||||
goto fail;
|
||||
|
||||
/* Copy result to client buffer */
|
||||
if (sizeof(*ascii) + ascii->header.arglen > replen) {
|
||||
errno = ERANGE;
|
||||
fail:
|
||||
errnosv = errno;
|
||||
free(buf);
|
||||
errno = errnosv;
|
||||
return (-1);
|
||||
}
|
||||
strncpy(reply->data, ascii->data, ascii->header.arglen);
|
||||
|
||||
/* Done */
|
||||
free(buf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Identical to NgRecvAsciiMsg() except buffer is dynamically allocated.
|
||||
*/
|
||||
int
|
||||
NgAllocRecvAsciiMsg(int cs, struct ng_mesg **reply, char *path)
|
||||
{
|
||||
int len;
|
||||
#ifndef FSTACK
|
||||
socklen_t optlen;
|
||||
|
||||
optlen = sizeof(len);
|
||||
if (getsockopt(cs, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 ||
|
||||
#else
|
||||
len = NGCTL_DEFAULT_RCVBUF;
|
||||
if (
|
||||
#endif
|
||||
(*reply = malloc(len)) == NULL)
|
||||
return (-1);
|
||||
if ((len = NgRecvAsciiMsg(cs, *reply, len, path)) < 0)
|
||||
free(*reply);
|
||||
return (len);
|
||||
}
|
|
@ -0,0 +1,398 @@
|
|||
.\" 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@whistle.com>
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\" $Whistle: netgraph.3,v 1.7 1999/01/25 07:14:06 archie Exp $
|
||||
.\"
|
||||
.Dd November 25, 2013
|
||||
.Dt NETGRAPH 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm NgMkSockNode ,
|
||||
.Nm NgNameNode ,
|
||||
.Nm NgSendMsg ,
|
||||
.Nm NgSendAsciiMsg ,
|
||||
.Nm NgSendMsgReply ,
|
||||
.Nm NgRecvMsg ,
|
||||
.Nm NgAllocRecvMsg ,
|
||||
.Nm NgRecvAsciiMsg ,
|
||||
.Nm NgAllocRecvAsciiMsg ,
|
||||
.Nm NgSendData ,
|
||||
.Nm NgRecvData ,
|
||||
.Nm NgAllocRecvData ,
|
||||
.Nm NgSetDebug ,
|
||||
.Nm NgSetErrLog
|
||||
.Nd netgraph user library
|
||||
.Sh LIBRARY
|
||||
.Lb libnetgraph
|
||||
.Sh SYNOPSIS
|
||||
.In netgraph/netgraph.h
|
||||
.Ft int
|
||||
.Fn NgMkSockNode "const char *name" "int *csp" "int *dsp"
|
||||
.Ft int
|
||||
.Fn NgNameNode "int cs" "const char *path" "const char *fmt" ...
|
||||
.Ft int
|
||||
.Fo NgSendMsg
|
||||
.Fa "int cs" "const char *path" "int cookie" "int cmd" "const void *arg"
|
||||
.Fa "size_t arglen"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fn NgSendAsciiMsg "int cs" "const char *path" "const char *fmt" ...
|
||||
.Ft int
|
||||
.Fo NgSendMsgReply
|
||||
.Fa "int cs" "const char *path" "struct ng_mesg *msg" "const void *arg"
|
||||
.Fa "size_t arglen"
|
||||
.Fc
|
||||
.Ft int
|
||||
.Fn NgRecvMsg "int cs" "struct ng_mesg *rep" "size_t replen" "char *path"
|
||||
.Ft int
|
||||
.Fn NgAllocRecvMsg "int cs" "struct ng_mesg **rep" "char *path"
|
||||
.Ft int
|
||||
.Fn NgRecvAsciiMsg "int cs" "struct ng_mesg *rep" "size_t replen" "char *path"
|
||||
.Ft int
|
||||
.Fn NgAllocRecvAsciiMsg "int cs" "struct ng_mesg **rep" "char *path"
|
||||
.Ft int
|
||||
.Fn NgSendData "int ds" "const char *hook" "const u_char *buf" "size_t len"
|
||||
.Ft int
|
||||
.Fn NgRecvData "int ds" "u_char *buf" "size_t len" "char *hook"
|
||||
.Ft int
|
||||
.Fn NgAllocRecvData "int ds" "u_char **buf" "char *hook"
|
||||
.Ft int
|
||||
.Fn NgSetDebug "int level"
|
||||
.Ft void
|
||||
.Fo NgSetErrLog
|
||||
.Fa "void \*[lp]*log\*[rp]\*[lp]const char *fmt, ...\*[rp]"
|
||||
.Fa "void \*[lp]*logx\*[rp]\*[lp]const char *fmt, ...\*[rp]"
|
||||
.Fc
|
||||
.Sh DESCRIPTION
|
||||
These functions facilitate user-mode program participation in the kernel
|
||||
.Xr netgraph 4
|
||||
graph-based networking system, by utilizing the netgraph
|
||||
.Vt socket
|
||||
node type (see
|
||||
.Xr ng_socket 4 ) .
|
||||
.Pp
|
||||
The
|
||||
.Fn NgMkSockNode
|
||||
function should be called first, to create a new
|
||||
.Vt socket
|
||||
type netgraph node with associated control and data sockets.
|
||||
If
|
||||
.Fa name
|
||||
is
|
||||
.No non- Ns Dv NULL ,
|
||||
the node will have that global name assigned to it.
|
||||
The
|
||||
.Fa csp
|
||||
and
|
||||
.Fa dsp
|
||||
arguments will be set to the newly opened control and data sockets
|
||||
associated with the node; either
|
||||
.Fa csp
|
||||
or
|
||||
.Fa dsp
|
||||
may be
|
||||
.Dv NULL
|
||||
if only one socket is desired.
|
||||
The
|
||||
.Fn NgMkSockNode
|
||||
function loads the
|
||||
.Vt socket
|
||||
node type KLD if it is not already loaded.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgNameNode
|
||||
function assigns a global name to the node addressed by
|
||||
.Fa path .
|
||||
.Pp
|
||||
The
|
||||
.Fn NgSendMsg
|
||||
function sends a binary control message from the
|
||||
.Vt socket
|
||||
node associated with control socket
|
||||
.Fa cs
|
||||
to the node addressed by
|
||||
.Fa path .
|
||||
The
|
||||
.Fa cookie
|
||||
indicates how to interpret
|
||||
.Fa cmd ,
|
||||
which indicates a specific command.
|
||||
Extra argument data (if any) is specified by
|
||||
.Fa arg
|
||||
and
|
||||
.Fa arglen .
|
||||
The
|
||||
.Fa cookie , cmd ,
|
||||
and argument data are defined by the header file corresponding
|
||||
to the type of the node being addressed.
|
||||
The unique, non-negative token value chosen for use in the message
|
||||
header is returned.
|
||||
This value is typically used to associate replies.
|
||||
.Pp
|
||||
Use
|
||||
.Fn NgSendMsgReply
|
||||
to send reply to a previously received control message.
|
||||
The original message header should be pointed to by
|
||||
.Fa msg .
|
||||
.Pp
|
||||
The
|
||||
.Fn NgSendAsciiMsg
|
||||
function performs the same function as
|
||||
.Fn NgSendMsg ,
|
||||
but adds support for
|
||||
.Tn ASCII
|
||||
encoding of control messages.
|
||||
The
|
||||
.Fn NgSendAsciiMsg
|
||||
function formats its input a la
|
||||
.Xr printf 3
|
||||
and then sends the resulting
|
||||
.Tn ASCII
|
||||
string to the node in a
|
||||
.Dv NGM_ASCII2BINARY
|
||||
control message.
|
||||
The node returns a binary version of the
|
||||
message, which is then sent back to the node just as with
|
||||
.Fn NgSendMsg .
|
||||
As with
|
||||
.Fn NgSendMsg ,
|
||||
the message token value is returned.
|
||||
Note that
|
||||
.Tn ASCII
|
||||
conversion may not be supported by all node types.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgRecvMsg
|
||||
function reads the next control message received by the node associated with
|
||||
control socket
|
||||
.Fa cs .
|
||||
The message and any extra argument data must fit in
|
||||
.Fa replen
|
||||
bytes.
|
||||
If
|
||||
.Fa path
|
||||
is
|
||||
.No non- Ns Dv NULL ,
|
||||
it must point to a buffer of at least
|
||||
.Dv NG_PATHSIZ
|
||||
bytes, which will be filled in (and
|
||||
.Dv NUL
|
||||
terminated) with the path to
|
||||
the node from which the message was received.
|
||||
.Pp
|
||||
The length of the control message is returned.
|
||||
A return value of zero indicates that the socket was closed.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgAllocRecvMsg
|
||||
function works exactly like
|
||||
.Fn NgRecvMsg ,
|
||||
except that the buffer for a message is dynamically allocated
|
||||
to guarantee that a message is not truncated.
|
||||
The size of the buffer is equal to the socket's receive buffer size.
|
||||
The caller is responsible for freeing the buffer when it is no longer required.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgRecvAsciiMsg
|
||||
function works exactly like
|
||||
.Fn NgRecvMsg ,
|
||||
except that after the message is received, any binary arguments
|
||||
are converted to
|
||||
.Tn ASCII
|
||||
by sending a
|
||||
.Dv NGM_BINARY2ASCII
|
||||
request back to the originating node.
|
||||
The result is the same as
|
||||
.Fn NgRecvMsg ,
|
||||
with the exception that the reply arguments field will contain a
|
||||
.Dv NUL Ns -terminated
|
||||
.Tn ASCII
|
||||
version of the arguments (and the reply
|
||||
header argument length field will be adjusted).
|
||||
.Pp
|
||||
The
|
||||
.Fn NgAllocRecvAsciiMsg
|
||||
function works exactly like
|
||||
.Fn NgRecvAsciiMsg ,
|
||||
except that the buffer for a message is dynamically allocated
|
||||
to guarantee that a message is not truncated.
|
||||
The size of the buffer is equal to the socket's receive buffer size.
|
||||
The caller is responsible for freeing the buffer when it is no longer required.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgSendData
|
||||
function writes a data packet out on the specified hook of the node
|
||||
corresponding to data socket
|
||||
.Fa ds .
|
||||
The node must already be connected to some other node via that hook.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgRecvData
|
||||
function reads the next data packet (of up to
|
||||
.Fa len
|
||||
bytes) received by the node corresponding to data socket
|
||||
.Fa ds
|
||||
and stores it in
|
||||
.Fa buf ,
|
||||
which must be large enough to hold the entire packet.
|
||||
If
|
||||
.Fa hook
|
||||
is
|
||||
.No non- Ns Dv NULL ,
|
||||
it must point to a buffer of at least
|
||||
.Dv NG_HOOKSIZ
|
||||
bytes, which will be filled in (and
|
||||
.Dv NUL
|
||||
terminated) with the name of
|
||||
the hook on which the data was received.
|
||||
.Pp
|
||||
The length of the packet is returned.
|
||||
A return value of zero indicates that the socket was closed.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgAllocRecvData
|
||||
function works exactly like
|
||||
.Fn NgRecvData ,
|
||||
except that the buffer for a data packet is dynamically allocated
|
||||
to guarantee that a data packet is not truncated.
|
||||
The size of the buffer is equal to the socket's receive buffer size.
|
||||
The caller is responsible for freeing the buffer when it is no longer required.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgSetDebug
|
||||
and
|
||||
.Fn NgSetErrLog
|
||||
functions are used for debugging.
|
||||
The
|
||||
.Fn NgSetDebug
|
||||
function sets the debug level (if non-negative), and returns the old setting.
|
||||
Higher debug levels result in more verbosity.
|
||||
The default is zero.
|
||||
All debug and error messages are logged via the functions
|
||||
specified in the most recent call to
|
||||
.Fn NgSetErrLog .
|
||||
The default logging functions are
|
||||
.Xr vwarn 3
|
||||
and
|
||||
.Xr vwarnx 3 .
|
||||
.Pp
|
||||
At debug level 3, the library attempts to display control message arguments
|
||||
in
|
||||
.Tn ASCII
|
||||
format; however, this results in additional messages being
|
||||
sent which may interfere with debugging.
|
||||
At even higher levels,
|
||||
even these additional messages will be displayed, etc.
|
||||
.Pp
|
||||
Note that
|
||||
.Xr select 2
|
||||
can be used on the data and the control sockets to detect the presence of
|
||||
incoming data and control messages, respectively.
|
||||
Data and control packets are always written and read atomically, i.e.,
|
||||
in one whole piece.
|
||||
.Pp
|
||||
User mode programs must be linked with the
|
||||
.Fl l Ns Li netgraph
|
||||
flag to link in this library.
|
||||
.Sh INITIALIZATION
|
||||
To enable netgraph in your kernel, either your kernel must be
|
||||
compiled with
|
||||
.Cd "options NETGRAPH"
|
||||
in the kernel configuration
|
||||
file, or else the
|
||||
.Xr netgraph 4
|
||||
and
|
||||
.Xr ng_socket 4
|
||||
KLD modules must have been loaded via
|
||||
.Xr kldload 8 .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn NgSetDebug
|
||||
function returns the previous debug setting.
|
||||
.Pp
|
||||
The
|
||||
.Fn NgSetErrLog
|
||||
function has no return value.
|
||||
.Pp
|
||||
All other functions return \-1 if there was an error and set
|
||||
.Va errno
|
||||
accordingly.
|
||||
.Pp
|
||||
A return value of zero from
|
||||
.Fn NgRecvMsg
|
||||
or
|
||||
.Fn NgRecvData
|
||||
indicates that the netgraph socket has been closed.
|
||||
.Pp
|
||||
For
|
||||
.Fn NgSendAsciiMsg
|
||||
and
|
||||
.Fn NgRecvAsciiMsg ,
|
||||
the following additional errors are possible:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er ENOSYS
|
||||
The node type does not know how to encode or decode the control message.
|
||||
.It Bq Er ERANGE
|
||||
The encoded or decoded arguments were too long for the supplied buffer.
|
||||
.It Bq Er ENOENT
|
||||
An unknown structure field was seen in an
|
||||
.Tn ASCII
|
||||
control message.
|
||||
.It Bq Er EALREADY
|
||||
The same structure field was specified twice in an
|
||||
.Tn ASCII
|
||||
control message.
|
||||
.It Bq Er EINVAL
|
||||
.Tn ASCII
|
||||
control message parse error or illegal value.
|
||||
.It Bq Er E2BIG
|
||||
ASCII control message array or fixed width string buffer overflow.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr select 2 ,
|
||||
.Xr socket 2 ,
|
||||
.Xr warnx 3 ,
|
||||
.Xr kld 4 ,
|
||||
.Xr netgraph 4 ,
|
||||
.Xr ng_socket 4
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm netgraph
|
||||
system was designed and first implemented at Whistle Communications, Inc.\& in
|
||||
a version of
|
||||
.Fx 2.2
|
||||
customized for the Whistle InterJet.
|
||||
.Sh AUTHORS
|
||||
.An Archie Cobbs Aq Mt archie@FreeBSD.org
|
|
@ -0,0 +1,93 @@
|
|||
|
||||
/*
|
||||
* netgraph.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@whistle.com>
|
||||
*
|
||||
* $FreeBSD$
|
||||
* $Whistle: netgraph.h,v 1.7 1999/01/20 00:57:23 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_H_
|
||||
#define _NETGRAPH_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netgraph/ng_message.h>
|
||||
|
||||
#ifdef FSTACK
|
||||
#ifndef __printflike
|
||||
#define __printflike(fmtarg, firstvararg)
|
||||
#endif
|
||||
|
||||
#define NGCTL_DEFAULT_RCVBUF 1024*8
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
int NgMkSockNode(const char *, int *, int *);
|
||||
int NgNameNode(int, const char *, const char *, ...) __printflike(3, 4);
|
||||
int NgSendMsg(int, const char *, int, int, const void *, size_t);
|
||||
int NgSendAsciiMsg(int, const char *, const char *, ...) __printflike(3, 4);
|
||||
int NgSendReplyMsg(int, const char *,
|
||||
const struct ng_mesg *, const void *, size_t);
|
||||
int NgRecvMsg(int, struct ng_mesg *, size_t, char *);
|
||||
int NgAllocRecvMsg(int, struct ng_mesg **, char *);
|
||||
int NgRecvAsciiMsg(int, struct ng_mesg *, size_t, char *);
|
||||
int NgAllocRecvAsciiMsg(int, struct ng_mesg **, char *);
|
||||
int NgSendData(int, const char *, const u_char *, size_t);
|
||||
int NgRecvData(int, u_char *, size_t, char *);
|
||||
int NgAllocRecvData(int, u_char **, char *);
|
||||
int NgSetDebug(int);
|
||||
void NgSetErrLog(void (*)(const char *fmt, ...),
|
||||
void (*)(const char *fmt, ...));
|
||||
|
||||
#ifdef FSTACK
|
||||
#include <sys/socket.h>
|
||||
|
||||
int ng_socket(int domain, int type, int protocol);
|
||||
int ng_connect(int sockfd, const struct sockaddr *addr,
|
||||
socklen_t addrlen);
|
||||
int ng_bind(int sockfd, const struct sockaddr *addr,
|
||||
socklen_t addrlen);
|
||||
ssize_t ng_sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t ng_recvfrom(int sockfd, void *buf, size_t len, int flags,
|
||||
struct sockaddr *src_addr, socklen_t *addrlen);
|
||||
int ng_close(int fd);
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,313 @@
|
|||
/*
|
||||
* sock.c
|
||||
*
|
||||
* 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@whistle.com>
|
||||
*
|
||||
* $Whistle: sock.c,v 1.12 1999/01/20 00:57:23 archie Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdarg.h>
|
||||
#include <netgraph/ng_message.h>
|
||||
#include <netgraph/ng_socket.h>
|
||||
|
||||
#include "netgraph.h"
|
||||
#include "internal.h"
|
||||
|
||||
/* The socket node type KLD */
|
||||
#define NG_SOCKET_KLD "ng_socket.ko"
|
||||
|
||||
/*
|
||||
* Create a socket type node and give it the supplied name.
|
||||
* Return data and control sockets corresponding to the node.
|
||||
* Returns -1 if error and sets errno.
|
||||
*/
|
||||
int
|
||||
NgMkSockNode(const char *name, int *csp, int *dsp)
|
||||
{
|
||||
char namebuf[NG_NODESIZ];
|
||||
int cs = -1; /* control socket */
|
||||
int ds = -1; /* data socket */
|
||||
int errnosv;
|
||||
|
||||
/* Empty name means no name */
|
||||
if (name && *name == 0)
|
||||
name = NULL;
|
||||
|
||||
/* Create control socket; this also creates the netgraph node.
|
||||
If we get an EAFNOSUPPORT then the socket node type is
|
||||
not loaded, so load it and try again. */
|
||||
if ((cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL)) < 0) {
|
||||
#ifndef FSTACK
|
||||
if (errno == EAFNOSUPPORT) {
|
||||
if (kldload(NG_SOCKET_KLD) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("can't load %s", NG_SOCKET_KLD);
|
||||
goto errout;
|
||||
}
|
||||
cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL);
|
||||
if (cs >= 0)
|
||||
goto gotNode;
|
||||
}
|
||||
#endif
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("socket");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
#ifndef FSTACK
|
||||
gotNode:
|
||||
#endif
|
||||
/* Assign the node the desired name, if any */
|
||||
if (name != NULL) {
|
||||
u_char sbuf[NG_NODESIZ + NGSA_OVERHEAD];
|
||||
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
|
||||
|
||||
/* Assign name */
|
||||
strlcpy(sg->sg_data, name, NG_NODESIZ);
|
||||
sg->sg_family = AF_NETGRAPH;
|
||||
sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
|
||||
if (bind(cs, (struct sockaddr *) sg, sg->sg_len) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("bind(%s)", sg->sg_data);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Save node name */
|
||||
strlcpy(namebuf, name, sizeof(namebuf));
|
||||
} else if (dsp != NULL) {
|
||||
union {
|
||||
u_char rbuf[sizeof(struct ng_mesg) +
|
||||
sizeof(struct nodeinfo)];
|
||||
struct ng_mesg res;
|
||||
} res;
|
||||
struct nodeinfo *const ni = (struct nodeinfo *) res.res.data;
|
||||
|
||||
/* Find out the node ID */
|
||||
if (NgSendMsg(cs, ".", NGM_GENERIC_COOKIE,
|
||||
NGM_NODEINFO, NULL, 0) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("send nodeinfo");
|
||||
goto errout;
|
||||
}
|
||||
if (NgRecvMsg(cs, &res.res, sizeof(res.rbuf), NULL) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("recv nodeinfo");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Save node "name" */
|
||||
snprintf(namebuf, sizeof(namebuf), "[%lx]", (u_long) ni->id);
|
||||
}
|
||||
|
||||
/* Create data socket if desired */
|
||||
if (dsp != NULL) {
|
||||
u_char sbuf[NG_NODESIZ + 1 + NGSA_OVERHEAD];
|
||||
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf;
|
||||
|
||||
/* Create data socket, initially just "floating" */
|
||||
if ((ds = socket(AF_NETGRAPH, SOCK_DGRAM, NG_DATA)) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("socket");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Associate the data socket with the node */
|
||||
snprintf(sg->sg_data, NG_NODESIZ + 1, "%s:", namebuf);
|
||||
sg->sg_family = AF_NETGRAPH;
|
||||
sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
|
||||
if (connect(ds, (struct sockaddr *) sg, sg->sg_len) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("connect(%s)", sg->sg_data);
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the socket(s) */
|
||||
if (csp)
|
||||
*csp = cs;
|
||||
else
|
||||
close(cs);
|
||||
if (dsp)
|
||||
*dsp = ds;
|
||||
return (0);
|
||||
|
||||
errout:
|
||||
/* Failed */
|
||||
if (cs >= 0)
|
||||
close(cs);
|
||||
if (ds >= 0)
|
||||
close(ds);
|
||||
errno = errnosv;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Assign a globally unique name to a node
|
||||
* Returns -1 if error and sets errno.
|
||||
*/
|
||||
int
|
||||
NgNameNode(int cs, const char *path, const char *fmt, ...)
|
||||
{
|
||||
struct ngm_name ngn;
|
||||
va_list args;
|
||||
|
||||
/* Build message arg */
|
||||
va_start(args, fmt);
|
||||
vsnprintf(ngn.name, sizeof(ngn.name), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
/* Send message */
|
||||
if (NgSendMsg(cs, path,
|
||||
NGM_GENERIC_COOKIE, NGM_NAME, &ngn, sizeof(ngn)) < 0) {
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOGX("%s: failed", __func__);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Done */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a packet from a data socket
|
||||
* Returns -1 if error and sets errno.
|
||||
*/
|
||||
int
|
||||
NgRecvData(int ds, u_char * buf, size_t len, char *hook)
|
||||
{
|
||||
u_char frombuf[NG_HOOKSIZ + NGSA_OVERHEAD];
|
||||
struct sockaddr_ng *const from = (struct sockaddr_ng *) frombuf;
|
||||
socklen_t fromlen = sizeof(frombuf);
|
||||
int rtn, errnosv;
|
||||
|
||||
/* Read packet */
|
||||
rtn = recvfrom(ds, buf, len, 0, (struct sockaddr *) from, &fromlen);
|
||||
if (rtn < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("recvfrom");
|
||||
errno = errnosv;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Copy hook name */
|
||||
if (hook != NULL)
|
||||
strlcpy(hook, from->sg_data, NG_HOOKSIZ);
|
||||
|
||||
/* Debugging */
|
||||
if (_gNgDebugLevel >= 2) {
|
||||
NGLOGX("READ %s from hook \"%s\" (%d bytes)",
|
||||
rtn ? "PACKET" : "EOF", from->sg_data, rtn);
|
||||
if (_gNgDebugLevel >= 3)
|
||||
_NgDebugBytes(buf, rtn);
|
||||
}
|
||||
|
||||
/* Done */
|
||||
return (rtn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Identical to NgRecvData() except buffer is dynamically allocated.
|
||||
*/
|
||||
int
|
||||
NgAllocRecvData(int ds, u_char **buf, char *hook)
|
||||
{
|
||||
int len;
|
||||
#ifndef FSTACK
|
||||
socklen_t optlen;
|
||||
|
||||
optlen = sizeof(len);
|
||||
if (getsockopt(ds, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 ||
|
||||
#else
|
||||
len = NGCTL_DEFAULT_RCVBUF;
|
||||
if (
|
||||
#endif
|
||||
(*buf = malloc(len)) == NULL)
|
||||
return (-1);
|
||||
if ((len = NgRecvData(ds, *buf, len, hook)) < 0)
|
||||
free(*buf);
|
||||
return (len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a packet to a data socket. The packet will be sent
|
||||
* out the corresponding node on the specified hook.
|
||||
* Returns -1 if error and sets errno.
|
||||
*/
|
||||
int
|
||||
NgSendData(int ds, const char *hook, const u_char * buf, size_t len)
|
||||
{
|
||||
u_char sgbuf[NG_HOOKSIZ + NGSA_OVERHEAD];
|
||||
struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
|
||||
int errnosv;
|
||||
|
||||
/* Set up destination hook */
|
||||
sg->sg_family = AF_NETGRAPH;
|
||||
strlcpy(sg->sg_data, hook, NG_HOOKSIZ);
|
||||
sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
|
||||
|
||||
/* Debugging */
|
||||
if (_gNgDebugLevel >= 2) {
|
||||
NGLOGX("WRITE PACKET to hook \"%s\" (%d bytes)", hook, len);
|
||||
_NgDebugSockaddr(sg);
|
||||
if (_gNgDebugLevel >= 3)
|
||||
_NgDebugBytes(buf, len);
|
||||
}
|
||||
|
||||
/* Send packet */
|
||||
if (sendto(ds, buf, len, 0, (struct sockaddr *) sg, sg->sg_len) < 0) {
|
||||
errnosv = errno;
|
||||
if (_gNgDebugLevel >= 1)
|
||||
NGLOG("sendto(%s)", sg->sg_data);
|
||||
errno = errnosv;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Done */
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -11,13 +11,7 @@ include ${TOPDIR}/tools/opts.mk
|
|||
|
||||
CLEANFILES+= nl_symbols.c nl_defs.h
|
||||
|
||||
CFLAGS+= -I${TOPDIR}/tools/libutil
|
||||
CFLAGS+= -I${TOPDIR}/tools/libmemstat
|
||||
CFLAGS+= -I${TOPDIR}/tools/libxo
|
||||
|
||||
LIBS+= -L${TOPDIR}/tools/libutil -lutil
|
||||
LIBS+= -L${TOPDIR}/tools/libmemstat -lmemstat
|
||||
LIBS+= -L${TOPDIR}/tools/libxo -lxo
|
||||
LIBADD=util memstat xo
|
||||
|
||||
WARNS?= 3
|
||||
CFLAGS+=-fno-strict-aliasing
|
||||
|
@ -46,7 +40,6 @@ endif
|
|||
|
||||
BINGRP= kmem
|
||||
BINMODE=2555
|
||||
LIBADD= kvm memstat xo util
|
||||
|
||||
ifneq (${MK_NETGRAPH_SUPPORT},"no")
|
||||
SRCS+= netgraph.c
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# $FreeBSD$
|
||||
# $Whistle: Makefile,v 1.3 1999/01/16 00:10:11 archie Exp $
|
||||
|
||||
TOPDIR?=${CURDIR}/../..
|
||||
|
||||
PROG= ngctl
|
||||
MAN= ngctl.8
|
||||
SRCS= main.c mkpeer.c config.c connect.c dot.c name.c show.c list.c \
|
||||
msg.c debug.c shutdown.c rmhook.c status.c types.c write.c
|
||||
WARNS?= 3
|
||||
|
||||
LIBADD= netgraph
|
||||
|
||||
include ${TOPDIR}/tools/prog.mk
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* config.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
#define NOCONFIG "<no config>"
|
||||
|
||||
static int ConfigCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd config_cmd = {
|
||||
ConfigCmd,
|
||||
"config <path> [arguments]",
|
||||
"get or set configuration of node at <path>",
|
||||
NULL,
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
ConfigCmd(int ac, char **av)
|
||||
{
|
||||
u_char sbuf[sizeof(struct ng_mesg) + NG_TEXTRESPONSE];
|
||||
struct ng_mesg *const resp = (struct ng_mesg *) sbuf;
|
||||
char *const status = (char *) resp->data;
|
||||
char *path;
|
||||
char buf[NG_TEXTRESPONSE];
|
||||
int nostat = 0, i;
|
||||
|
||||
/* Get arguments */
|
||||
if (ac < 2)
|
||||
return (CMDRTN_USAGE);
|
||||
path = av[1];
|
||||
|
||||
*buf = '\0';
|
||||
for (i = 2; i < ac; i++) {
|
||||
if (i != 2)
|
||||
strcat(buf, " ");
|
||||
strcat(buf, av[i]);
|
||||
}
|
||||
|
||||
/* Get node config summary */
|
||||
if (*buf != '\0')
|
||||
i = NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_TEXT_CONFIG, buf, strlen(buf) + 1);
|
||||
else
|
||||
i = NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_TEXT_CONFIG, NULL, 0);
|
||||
if (i < 0) {
|
||||
switch (errno) {
|
||||
case EINVAL:
|
||||
nostat = 1;
|
||||
break;
|
||||
default:
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (NgRecvMsg(csock, resp, sizeof(sbuf), NULL) < 0
|
||||
|| (resp->header.flags & NGF_RESP) == 0)
|
||||
nostat = 1;
|
||||
}
|
||||
|
||||
/* Show it */
|
||||
if (nostat)
|
||||
printf("No config available for \"%s\"\n", path);
|
||||
else
|
||||
printf("Config for \"%s\":\n%s\n", path, status);
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
/*
|
||||
* connect.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int ConnectCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd connect_cmd = {
|
||||
ConnectCmd,
|
||||
"connect [path] <relpath> <hook> <peerhook>",
|
||||
"Connects hook <peerhook> of the node at <relpath> to <hook>",
|
||||
"The connect command creates a link between the two nodes at"
|
||||
" \"path\" and \"relpath\" using hooks \"hook\" and \"peerhook\","
|
||||
" respectively. The \"relpath\", if not absolute, is specified"
|
||||
" relative to the node at \"path\"."
|
||||
" If \"path\" is omitted then \".\" is assumed.",
|
||||
{ "join" }
|
||||
};
|
||||
|
||||
static int
|
||||
ConnectCmd(int ac, char **av)
|
||||
{
|
||||
struct ngm_connect con;
|
||||
const char *path = ".";
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 5:
|
||||
path = av[1];
|
||||
ac--;
|
||||
av++;
|
||||
/* FALLTHROUGH */
|
||||
case 4:
|
||||
snprintf(con.path, sizeof(con.path), "%s", av[1]);
|
||||
snprintf(con.ourhook, sizeof(con.ourhook), "%s", av[2]);
|
||||
snprintf(con.peerhook, sizeof(con.peerhook), "%s", av[3]);
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Send message */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_CONNECT, &con, sizeof(con)) < 0) {
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
/*
|
||||
* debug.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int DebugCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd debug_cmd = {
|
||||
DebugCmd,
|
||||
"debug [level]",
|
||||
"Get/set debugging verbosity level",
|
||||
"Without any argument, this command displays the current"
|
||||
" debugging verbosity level. If the argument is ``+'' or ``-''"
|
||||
" the debug level is incremented or decremented; otherwise,"
|
||||
" it must be an absolute numerical level.",
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
DebugCmd(int ac, char **av)
|
||||
{
|
||||
int level;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 2:
|
||||
if (!strcmp(av[1], "+"))
|
||||
level = NgSetDebug(-1) + 1;
|
||||
else if (!strcmp(av[1], "-"))
|
||||
level = NgSetDebug(-1) - 1;
|
||||
else if ((level = atoi(av[1])) < 0)
|
||||
return (CMDRTN_USAGE);
|
||||
NgSetDebug(level);
|
||||
break;
|
||||
case 1:
|
||||
printf("Current debug level is %d\n", NgSetDebug(-1));
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
|
||||
/*
|
||||
* dot.c
|
||||
*
|
||||
* Copyright (c) 2004 Brian Fundakowski Feldman
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <inttypes.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
#define UNNAMED "\\<unnamed\\>"
|
||||
|
||||
static int DotCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd dot_cmd = {
|
||||
DotCmd,
|
||||
"dot [outputfile]",
|
||||
"Produce a GraphViz (.dot) of the entire netgraph.",
|
||||
"If no outputfile is specified, stdout will be assumed.",
|
||||
{ "graphviz", "confdot" }
|
||||
};
|
||||
|
||||
static int
|
||||
DotCmd(int ac, char **av)
|
||||
{
|
||||
struct ng_mesg *nlresp;
|
||||
struct namelist *nlist;
|
||||
FILE *f = stdout;
|
||||
int ch;
|
||||
u_int i;
|
||||
|
||||
/* Get options */
|
||||
optind = 1;
|
||||
while ((ch = getopt(ac, av, "")) != -1) {
|
||||
switch (ch) {
|
||||
case '?':
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ac -= optind;
|
||||
av += optind;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 1:
|
||||
f = fopen(av[0], "w");
|
||||
if (f == NULL) {
|
||||
warn("Could not open %s for writing", av[0]);
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
if (f != stdout)
|
||||
(void)fclose(f);
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Get list of nodes */
|
||||
if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, NGM_LISTNODES, NULL,
|
||||
0) < 0) {
|
||||
warn("send listnodes msg");
|
||||
goto error;
|
||||
}
|
||||
if (NgAllocRecvMsg(csock, &nlresp, NULL) < 0) {
|
||||
warn("recv listnodes msg");
|
||||
goto error;
|
||||
}
|
||||
|
||||
nlist = (struct namelist *)nlresp->data;
|
||||
fprintf(f, "graph netgraph {\n");
|
||||
/* TODO: implement rank = same or subgraphs at some point */
|
||||
fprintf(f, "\tedge [ weight = 1.0 ];\n");
|
||||
fprintf(f, "\tnode [ shape = record, fontsize = 12 ] {\n");
|
||||
for (i = 0; i < nlist->numnames; i++)
|
||||
fprintf(f, "\t\t\"%jx\" [ label = \"{%s:|{%s|[%jx]:}}\" ];\n",
|
||||
(uintmax_t)nlist->nodeinfo[i].id,
|
||||
nlist->nodeinfo[i].name[0] != '\0' ?
|
||||
nlist->nodeinfo[i].name : UNNAMED,
|
||||
nlist->nodeinfo[i].type, (uintmax_t)nlist->nodeinfo[i].id);
|
||||
fprintf(f, "\t};\n");
|
||||
|
||||
fprintf(f, "\tsubgraph cluster_disconnected {\n");
|
||||
fprintf(f, "\t\tbgcolor = pink;\n");
|
||||
for (i = 0; i < nlist->numnames; i++)
|
||||
if (nlist->nodeinfo[i].hooks == 0)
|
||||
fprintf(f, "\t\t\"%jx\";\n",
|
||||
(uintmax_t)nlist->nodeinfo[i].id);
|
||||
fprintf(f, "\t};\n");
|
||||
|
||||
for (i = 0; i < nlist->numnames; i++) {
|
||||
struct ng_mesg *hlresp;
|
||||
struct hooklist *hlist;
|
||||
struct nodeinfo *ninfo;
|
||||
char path[NG_PATHSIZ];
|
||||
u_int j;
|
||||
|
||||
(void)snprintf(path, sizeof(path), "[%jx]:",
|
||||
(uintmax_t)nlist->nodeinfo[i].id);
|
||||
|
||||
/* Get node info and hook list */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
|
||||
NULL, 0) < 0) {
|
||||
free(nlresp);
|
||||
warn("send listhooks msg");
|
||||
goto error;
|
||||
}
|
||||
if (NgAllocRecvMsg(csock, &hlresp, NULL) < 0) {
|
||||
free(nlresp);
|
||||
warn("recv listhooks msg");
|
||||
goto error;
|
||||
}
|
||||
|
||||
hlist = (struct hooklist *)hlresp->data;
|
||||
ninfo = &hlist->nodeinfo;
|
||||
if (ninfo->hooks == 0) {
|
||||
free(hlresp);
|
||||
continue;
|
||||
}
|
||||
|
||||
fprintf(f, "\tnode [ shape = octagon, fontsize = 10 ] {\n");
|
||||
for (j = 0; j < ninfo->hooks; j++)
|
||||
fprintf(f, "\t\t\"%jx.%s\" [ label = \"%s\" ];\n",
|
||||
(uintmax_t)nlist->nodeinfo[i].id,
|
||||
hlist->link[j].ourhook, hlist->link[j].ourhook);
|
||||
fprintf(f, "\t};\n");
|
||||
|
||||
fprintf(f, "\t{\n\t\tedge [ weight = 2.0, style = bold ];\n");
|
||||
for (j = 0; j < ninfo->hooks; j++)
|
||||
fprintf(f, "\t\t\"%jx\" -- \"%jx.%s\";\n",
|
||||
(uintmax_t)nlist->nodeinfo[i].id,
|
||||
(uintmax_t)nlist->nodeinfo[i].id,
|
||||
hlist->link[j].ourhook);
|
||||
fprintf(f, "\t};\n");
|
||||
|
||||
for (j = 0; j < ninfo->hooks; j++) {
|
||||
/* Only print the edges going in one direction. */
|
||||
if (hlist->link[j].nodeinfo.id > nlist->nodeinfo[i].id)
|
||||
continue;
|
||||
fprintf(f, "\t\"%jx.%s\" -- \"%jx.%s\";\n",
|
||||
(uintmax_t)nlist->nodeinfo[i].id,
|
||||
hlist->link[j].ourhook,
|
||||
(uintmax_t)hlist->link[j].nodeinfo.id,
|
||||
hlist->link[j].peerhook);
|
||||
}
|
||||
free(hlresp);
|
||||
}
|
||||
|
||||
fprintf(f, "}\n");
|
||||
|
||||
free(nlresp);
|
||||
if (f != stdout)
|
||||
(void)fclose(f);
|
||||
return (CMDRTN_OK);
|
||||
error:
|
||||
if (f != stdout)
|
||||
(void)fclose(f);
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
|
||||
/*
|
||||
* list.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
#define UNNAMED "<unnamed>"
|
||||
|
||||
static int ListCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd list_cmd = {
|
||||
ListCmd,
|
||||
"list [-ln]",
|
||||
"Show information about all nodes",
|
||||
"The list command shows information about every node that currently"
|
||||
" exists in the netgraph system. The optional -n argument limits"
|
||||
" this list to only those nodes with a global name assignment."
|
||||
" The optional -l argument provides verbose output that includes"
|
||||
" hook information as well.",
|
||||
{ "ls" }
|
||||
};
|
||||
|
||||
static int
|
||||
ListCmd(int ac, char **av)
|
||||
{
|
||||
struct ng_mesg *resp;
|
||||
struct namelist *nlist;
|
||||
struct nodeinfo *ninfo;
|
||||
int list_hooks = 0;
|
||||
int named_only = 0;
|
||||
int ch, rtn = CMDRTN_OK;
|
||||
|
||||
/* Get options */
|
||||
optind = 1;
|
||||
while ((ch = getopt(ac, av, "ln")) != -1) {
|
||||
switch (ch) {
|
||||
case 'l':
|
||||
list_hooks = 1;
|
||||
break;
|
||||
case 'n':
|
||||
named_only = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ac -= optind;
|
||||
av += optind;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Get list of nodes */
|
||||
if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE,
|
||||
named_only ? NGM_LISTNAMES : NGM_LISTNODES, NULL, 0) < 0) {
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
if (NgAllocRecvMsg(csock, &resp, NULL) < 0) {
|
||||
warn("recv msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
|
||||
/* Show each node */
|
||||
nlist = (struct namelist *) resp->data;
|
||||
printf("There are %d total %snodes:\n",
|
||||
nlist->numnames, named_only ? "named " : "");
|
||||
ninfo = nlist->nodeinfo;
|
||||
if (list_hooks) {
|
||||
char path[NG_PATHSIZ];
|
||||
char *argv[2] = { "show", path };
|
||||
|
||||
while (nlist->numnames > 0) {
|
||||
snprintf(path, sizeof(path),
|
||||
"[%lx]:", (u_long)ninfo->id);
|
||||
if ((rtn = (*show_cmd.func)(2, argv)) != CMDRTN_OK)
|
||||
break;
|
||||
ninfo++;
|
||||
nlist->numnames--;
|
||||
}
|
||||
} else {
|
||||
while (nlist->numnames > 0) {
|
||||
if (!*ninfo->name)
|
||||
snprintf(ninfo->name, sizeof(ninfo->name),
|
||||
"%s", UNNAMED);
|
||||
printf(" Name: %-15s Type: %-15s ID: %08x "
|
||||
"Num hooks: %d\n",
|
||||
ninfo->name, ninfo->type, ninfo->id, ninfo->hooks);
|
||||
ninfo++;
|
||||
nlist->numnames--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Done */
|
||||
free(resp);
|
||||
return (rtn);
|
||||
}
|
||||
|
|
@ -0,0 +1,709 @@
|
|||
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Whistle: main.c,v 1.12 1999/11/29 19:17:46 archie Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
#ifdef EDITLINE
|
||||
#include <signal.h>
|
||||
#include <histedit.h>
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <netgraph.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
#ifdef FSTACK
|
||||
#include "ff_ipc.h"
|
||||
#endif
|
||||
|
||||
#define PROMPT "+ "
|
||||
#define MAX_ARGS 512
|
||||
#define WHITESPACE " \t\r\n\v\f"
|
||||
#define DUMP_BYTES_PER_LINE 16
|
||||
|
||||
/* Internal functions */
|
||||
static int ReadFile(FILE *fp);
|
||||
#ifndef FSTACK
|
||||
static void ReadSockets(fd_set *);
|
||||
#endif
|
||||
static int DoParseCommand(const char *line);
|
||||
static int DoCommand(int ac, char **av);
|
||||
#ifndef FSTACK
|
||||
static int DoInteractive(void);
|
||||
#endif
|
||||
static const struct ngcmd *FindCommand(const char *string);
|
||||
static int MatchCommand(const struct ngcmd *cmd, const char *s);
|
||||
static void Usage(const char *msg);
|
||||
static int ReadCmd(int ac, char **av);
|
||||
static int HelpCmd(int ac, char **av);
|
||||
static int QuitCmd(int ac, char **av);
|
||||
#ifdef EDITLINE
|
||||
static volatile sig_atomic_t unblock;
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
#endif
|
||||
|
||||
/* List of commands */
|
||||
static const struct ngcmd *const cmds[] = {
|
||||
&config_cmd,
|
||||
&connect_cmd,
|
||||
&debug_cmd,
|
||||
&dot_cmd,
|
||||
&help_cmd,
|
||||
&list_cmd,
|
||||
&mkpeer_cmd,
|
||||
&msg_cmd,
|
||||
&name_cmd,
|
||||
&read_cmd,
|
||||
&rmhook_cmd,
|
||||
&show_cmd,
|
||||
&shutdown_cmd,
|
||||
&status_cmd,
|
||||
&types_cmd,
|
||||
&write_cmd,
|
||||
&quit_cmd,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Commands defined in this file */
|
||||
const struct ngcmd read_cmd = {
|
||||
ReadCmd,
|
||||
"read <filename>",
|
||||
"Read and execute commands from a file",
|
||||
NULL,
|
||||
{ "source", "." }
|
||||
};
|
||||
const struct ngcmd help_cmd = {
|
||||
HelpCmd,
|
||||
"help [command]",
|
||||
"Show command summary or get more help on a specific command",
|
||||
NULL,
|
||||
{ "?" }
|
||||
};
|
||||
const struct ngcmd quit_cmd = {
|
||||
QuitCmd,
|
||||
"quit",
|
||||
"Exit program",
|
||||
NULL,
|
||||
{ "exit" }
|
||||
};
|
||||
|
||||
/* Our control and data sockets */
|
||||
#ifndef FSTACK
|
||||
int csock, dsock;
|
||||
#else
|
||||
int csock = -1, dsock = -1;
|
||||
|
||||
void
|
||||
__attribute__((destructor)) close_ng_socks()
|
||||
{
|
||||
if (csock >= 0) {
|
||||
ng_close(csock);
|
||||
}
|
||||
|
||||
if (dsock >= 0) {
|
||||
ng_close(dsock);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* main()
|
||||
*/
|
||||
int
|
||||
main(int ac, char *av[])
|
||||
{
|
||||
char name[NG_NODESIZ];
|
||||
#ifndef FSTACK
|
||||
int interactive = isatty(0) && isatty(1);
|
||||
#endif
|
||||
FILE *fp = NULL;
|
||||
int ch, rtn = 0;
|
||||
|
||||
/* Set default node name */
|
||||
snprintf(name, sizeof(name), "ngctl%d", getpid());
|
||||
|
||||
/* Parse command line */
|
||||
#ifndef FSTACK
|
||||
while ((ch = getopt(ac, av, "df:n:")) != -1) {
|
||||
#else
|
||||
ff_ipc_init();
|
||||
while ((ch = getopt(ac, av, "df:n:p:")) != -1) {
|
||||
#endif
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
NgSetDebug(NgSetDebug(-1) + 1);
|
||||
break;
|
||||
case 'f':
|
||||
if (strcmp(optarg, "-") == 0)
|
||||
fp = stdin;
|
||||
else if ((fp = fopen(optarg, "r")) == NULL)
|
||||
err(EX_NOINPUT, "%s", optarg);
|
||||
break;
|
||||
case 'n':
|
||||
snprintf(name, sizeof(name), "%s", optarg);
|
||||
break;
|
||||
#ifdef FSTACK
|
||||
case 'p':
|
||||
ff_set_proc_id(atoi(optarg));
|
||||
break;
|
||||
#endif
|
||||
case '?':
|
||||
default:
|
||||
Usage((char *)NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ac -= optind;
|
||||
av += optind;
|
||||
|
||||
/* Create a new socket node */
|
||||
if (NgMkSockNode(name, &csock, &dsock) < 0)
|
||||
err(EX_OSERR, "can't create node");
|
||||
|
||||
/* Do commands as requested */
|
||||
if (ac == 0) {
|
||||
if (fp != NULL) {
|
||||
rtn = ReadFile(fp);
|
||||
#ifndef FSTACK
|
||||
} else if (interactive) {
|
||||
rtn = DoInteractive();
|
||||
#endif
|
||||
} else
|
||||
Usage("no command specified");
|
||||
} else {
|
||||
rtn = DoCommand(ac, av);
|
||||
}
|
||||
|
||||
/* Convert command return code into system exit code */
|
||||
switch (rtn) {
|
||||
case CMDRTN_OK:
|
||||
case CMDRTN_QUIT:
|
||||
rtn = 0;
|
||||
break;
|
||||
case CMDRTN_USAGE:
|
||||
rtn = EX_USAGE;
|
||||
break;
|
||||
case CMDRTN_ERROR:
|
||||
rtn = EX_OSERR;
|
||||
break;
|
||||
}
|
||||
return (rtn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process commands from a file
|
||||
*/
|
||||
static int
|
||||
ReadFile(FILE *fp)
|
||||
{
|
||||
char line[LINE_MAX];
|
||||
int num, rtn;
|
||||
|
||||
for (num = 1; fgets(line, sizeof(line), fp) != NULL; num++) {
|
||||
if (*line == '#')
|
||||
continue;
|
||||
if ((rtn = DoParseCommand(line)) != 0) {
|
||||
warnx("line %d: error in file", num);
|
||||
return (rtn);
|
||||
}
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
||||
#ifndef FSTACK
|
||||
#ifdef EDITLINE
|
||||
/* Signal handler for Monitor() thread. */
|
||||
static void
|
||||
Unblock(int signal __unused)
|
||||
{
|
||||
|
||||
unblock = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Thread that monitors csock and dsock while main thread
|
||||
* can be blocked in el_gets().
|
||||
*/
|
||||
static void *
|
||||
Monitor(void *v __unused)
|
||||
{
|
||||
struct sigaction act;
|
||||
const int maxfd = MAX(csock, dsock) + 1;
|
||||
|
||||
act.sa_handler = Unblock;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
sigaction(SIGUSR1, &act, NULL);
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
for (;;) {
|
||||
fd_set rfds;
|
||||
|
||||
/* See if any data or control messages are arriving. */
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(csock, &rfds);
|
||||
FD_SET(dsock, &rfds);
|
||||
unblock = 0;
|
||||
if (select(maxfd, &rfds, NULL, NULL, NULL) <= 0) {
|
||||
if (errno == EINTR) {
|
||||
if (unblock == 1)
|
||||
pthread_cond_wait(&cond, &mutex);
|
||||
continue;
|
||||
}
|
||||
err(EX_OSERR, "select");
|
||||
}
|
||||
ReadSockets(&rfds);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static char *
|
||||
Prompt(EditLine *el __unused)
|
||||
{
|
||||
|
||||
return (PROMPT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Here we start a thread, that will monitor the netgraph
|
||||
* sockets and catch any unexpected messages or data on them,
|
||||
* that can arrive while user edits his/her commands.
|
||||
*
|
||||
* Whenever we expect data on netgraph sockets, we send signal
|
||||
* to monitoring thread. The signal forces it to exit select()
|
||||
* system call and sleep on condvar until we wake it. While
|
||||
* monitoring thread sleeps, we can do our work with netgraph
|
||||
* sockets.
|
||||
*/
|
||||
static int
|
||||
DoInteractive(void)
|
||||
{
|
||||
pthread_t monitor;
|
||||
EditLine *el;
|
||||
History *hist;
|
||||
HistEvent hev = { 0, "" };
|
||||
|
||||
(*help_cmd.func)(0, NULL);
|
||||
pthread_create(&monitor, NULL, Monitor, NULL);
|
||||
el = el_init(getprogname(), stdin, stdout, stderr);
|
||||
if (el == NULL)
|
||||
return (CMDRTN_ERROR);
|
||||
el_set(el, EL_PROMPT, Prompt);
|
||||
el_set(el, EL_SIGNAL, 1);
|
||||
el_set(el, EL_EDITOR, "emacs");
|
||||
hist = history_init();
|
||||
if (hist == NULL)
|
||||
return (CMDRTN_ERROR);
|
||||
history(hist, &hev, H_SETSIZE, 100);
|
||||
history(hist, &hev, H_SETUNIQUE, 1);
|
||||
el_set(el, EL_HIST, history, (const char *)hist);
|
||||
el_source(el, NULL);
|
||||
|
||||
for (;;) {
|
||||
const char *buf;
|
||||
int count;
|
||||
|
||||
if ((buf = el_gets(el, &count)) == NULL) {
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
history(hist, &hev, H_ENTER, buf);
|
||||
pthread_kill(monitor, SIGUSR1);
|
||||
pthread_mutex_lock(&mutex);
|
||||
if (DoParseCommand(buf) == CMDRTN_QUIT) {
|
||||
pthread_mutex_unlock(&mutex);
|
||||
break;
|
||||
}
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
history_end(hist);
|
||||
el_end(el);
|
||||
pthread_cancel(monitor);
|
||||
|
||||
return (CMDRTN_QUIT);
|
||||
}
|
||||
|
||||
#else /* !EDITLINE */
|
||||
|
||||
/*
|
||||
* Interactive mode w/o libedit functionality.
|
||||
*/
|
||||
static int
|
||||
DoInteractive(void)
|
||||
{
|
||||
const int maxfd = MAX(csock, dsock) + 1;
|
||||
|
||||
(*help_cmd.func)(0, NULL);
|
||||
while (1) {
|
||||
struct timeval tv;
|
||||
fd_set rfds;
|
||||
|
||||
/* See if any data or control messages are arriving */
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(csock, &rfds);
|
||||
FD_SET(dsock, &rfds);
|
||||
memset(&tv, 0, sizeof(tv));
|
||||
if (select(maxfd, &rfds, NULL, NULL, &tv) <= 0) {
|
||||
|
||||
/* Issue prompt and wait for anything to happen */
|
||||
printf("%s", PROMPT);
|
||||
fflush(stdout);
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(0, &rfds);
|
||||
FD_SET(csock, &rfds);
|
||||
FD_SET(dsock, &rfds);
|
||||
if (select(maxfd, &rfds, NULL, NULL, NULL) < 0)
|
||||
err(EX_OSERR, "select");
|
||||
|
||||
/* If not user input, print a newline first */
|
||||
if (!FD_ISSET(0, &rfds))
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
ReadSockets(&rfds);
|
||||
|
||||
/* Get any user input */
|
||||
if (FD_ISSET(0, &rfds)) {
|
||||
char buf[LINE_MAX];
|
||||
|
||||
if (fgets(buf, sizeof(buf), stdin) == NULL) {
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
if (DoParseCommand(buf) == CMDRTN_QUIT)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (CMDRTN_QUIT);
|
||||
}
|
||||
#endif /* !EDITLINE */
|
||||
|
||||
/*
|
||||
* Read and process data on netgraph control and data sockets.
|
||||
*/
|
||||
static void
|
||||
ReadSockets(fd_set *rfds)
|
||||
{
|
||||
/* Display any incoming control message. */
|
||||
if (FD_ISSET(csock, rfds))
|
||||
MsgRead();
|
||||
|
||||
/* Display any incoming data packet. */
|
||||
if (FD_ISSET(dsock, rfds)) {
|
||||
char hook[NG_HOOKSIZ];
|
||||
u_char *buf;
|
||||
int rl;
|
||||
|
||||
/* Read packet from socket. */
|
||||
if ((rl = NgAllocRecvData(dsock, &buf, hook)) < 0)
|
||||
err(EX_OSERR, "reading hook \"%s\"", hook);
|
||||
if (rl == 0)
|
||||
errx(EX_OSERR, "EOF from hook \"%s\"?", hook);
|
||||
|
||||
/* Write packet to stdout. */
|
||||
printf("Rec'd data packet on hook \"%s\":\n", hook);
|
||||
DumpAscii(buf, rl);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Parse a command line and execute the command
|
||||
*/
|
||||
static int
|
||||
DoParseCommand(const char *line)
|
||||
{
|
||||
char *av[MAX_ARGS];
|
||||
int ac;
|
||||
|
||||
/* Parse line */
|
||||
for (ac = 0, av[0] = strtok((char *)line, WHITESPACE);
|
||||
ac < MAX_ARGS - 1 && av[ac];
|
||||
av[++ac] = strtok(NULL, WHITESPACE));
|
||||
|
||||
/* Do command */
|
||||
return (DoCommand(ac, av));
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute the command
|
||||
*/
|
||||
static int
|
||||
DoCommand(int ac, char **av)
|
||||
{
|
||||
const struct ngcmd *cmd;
|
||||
int rtn;
|
||||
|
||||
if (ac == 0 || *av[0] == 0)
|
||||
return (CMDRTN_OK);
|
||||
if ((cmd = FindCommand(av[0])) == NULL)
|
||||
return (CMDRTN_ERROR);
|
||||
if ((rtn = (*cmd->func)(ac, av)) == CMDRTN_USAGE)
|
||||
warnx("usage: %s", cmd->cmd);
|
||||
return (rtn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a command
|
||||
*/
|
||||
static const struct ngcmd *
|
||||
FindCommand(const char *string)
|
||||
{
|
||||
int k, found = -1;
|
||||
|
||||
for (k = 0; cmds[k] != NULL; k++) {
|
||||
if (MatchCommand(cmds[k], string)) {
|
||||
if (found != -1) {
|
||||
warnx("\"%s\": ambiguous command", string);
|
||||
return (NULL);
|
||||
}
|
||||
found = k;
|
||||
}
|
||||
}
|
||||
if (found == -1) {
|
||||
warnx("\"%s\": unknown command", string);
|
||||
return (NULL);
|
||||
}
|
||||
return (cmds[found]);
|
||||
}
|
||||
|
||||
/*
|
||||
* See if string matches a prefix of "cmd" (or an alias) case insensitively
|
||||
*/
|
||||
static int
|
||||
MatchCommand(const struct ngcmd *cmd, const char *s)
|
||||
{
|
||||
int a;
|
||||
|
||||
/* Try to match command, ignoring the usage stuff */
|
||||
if (strlen(s) <= strcspn(cmd->cmd, WHITESPACE)) {
|
||||
if (strncasecmp(s, cmd->cmd, strlen(s)) == 0)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Try to match aliases */
|
||||
for (a = 0; a < MAX_CMD_ALIAS && cmd->aliases[a] != NULL; a++) {
|
||||
if (strlen(cmd->aliases[a]) >= strlen(s)) {
|
||||
if (strncasecmp(s, cmd->aliases[a], strlen(s)) == 0)
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* No match */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* ReadCmd()
|
||||
*/
|
||||
static int
|
||||
ReadCmd(int ac, char **av)
|
||||
{
|
||||
FILE *fp;
|
||||
int rtn;
|
||||
|
||||
/* Open file */
|
||||
switch (ac) {
|
||||
case 2:
|
||||
if ((fp = fopen(av[1], "r")) == NULL) {
|
||||
warn("%s", av[1]);
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Process it */
|
||||
rtn = ReadFile(fp);
|
||||
fclose(fp);
|
||||
return (rtn);
|
||||
}
|
||||
|
||||
/*
|
||||
* HelpCmd()
|
||||
*/
|
||||
static int
|
||||
HelpCmd(int ac, char **av)
|
||||
{
|
||||
const struct ngcmd *cmd;
|
||||
int k;
|
||||
|
||||
switch (ac) {
|
||||
case 0:
|
||||
case 1:
|
||||
/* Show all commands */
|
||||
printf("Available commands:\n");
|
||||
for (k = 0; cmds[k] != NULL; k++) {
|
||||
char *s, buf[100];
|
||||
|
||||
cmd = cmds[k];
|
||||
snprintf(buf, sizeof(buf), "%s", cmd->cmd);
|
||||
for (s = buf; *s != '\0' && !isspace(*s); s++);
|
||||
*s = '\0';
|
||||
printf(" %-10s %s\n", buf, cmd->desc);
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
default:
|
||||
/* Show help on a specific command */
|
||||
if ((cmd = FindCommand(av[1])) != NULL) {
|
||||
printf("usage: %s\n", cmd->cmd);
|
||||
if (cmd->aliases[0] != NULL) {
|
||||
int a = 0;
|
||||
|
||||
printf("Aliases: ");
|
||||
while (1) {
|
||||
printf("%s", cmd->aliases[a++]);
|
||||
if (a == MAX_CMD_ALIAS
|
||||
|| cmd->aliases[a] == NULL) {
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
printf(", ");
|
||||
}
|
||||
}
|
||||
printf("Summary: %s\n", cmd->desc);
|
||||
if (cmd->help != NULL) {
|
||||
const char *s;
|
||||
char buf[65];
|
||||
int tot, len, done;
|
||||
|
||||
printf("Description:\n");
|
||||
for (s = cmd->help; *s != '\0'; s += len) {
|
||||
while (isspace(*s))
|
||||
s++;
|
||||
tot = snprintf(buf,
|
||||
sizeof(buf), "%s", s);
|
||||
len = strlen(buf);
|
||||
done = len == tot;
|
||||
if (!done) {
|
||||
while (len > 0
|
||||
&& !isspace(buf[len-1]))
|
||||
buf[--len] = '\0';
|
||||
}
|
||||
printf(" %s\n", buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* QuitCmd()
|
||||
*/
|
||||
static int
|
||||
QuitCmd(int ac __unused, char **av __unused)
|
||||
{
|
||||
return (CMDRTN_QUIT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump data in hex and ASCII form
|
||||
*/
|
||||
void
|
||||
DumpAscii(const u_char *buf, int len)
|
||||
{
|
||||
char ch, sbuf[100];
|
||||
int k, count;
|
||||
|
||||
for (count = 0; count < len; count += DUMP_BYTES_PER_LINE) {
|
||||
snprintf(sbuf, sizeof(sbuf), "%04x: ", count);
|
||||
for (k = 0; k < DUMP_BYTES_PER_LINE; k++) {
|
||||
if (count + k < len) {
|
||||
snprintf(sbuf + strlen(sbuf),
|
||||
sizeof(sbuf) - strlen(sbuf),
|
||||
"%02x ", buf[count + k]);
|
||||
} else {
|
||||
snprintf(sbuf + strlen(sbuf),
|
||||
sizeof(sbuf) - strlen(sbuf), " ");
|
||||
}
|
||||
}
|
||||
snprintf(sbuf + strlen(sbuf), sizeof(sbuf) - strlen(sbuf), " ");
|
||||
for (k = 0; k < DUMP_BYTES_PER_LINE; k++) {
|
||||
if (count + k < len) {
|
||||
ch = isprint(buf[count + k]) ?
|
||||
buf[count + k] : '.';
|
||||
snprintf(sbuf + strlen(sbuf),
|
||||
sizeof(sbuf) - strlen(sbuf), "%c", ch);
|
||||
} else {
|
||||
snprintf(sbuf + strlen(sbuf),
|
||||
sizeof(sbuf) - strlen(sbuf), " ");
|
||||
}
|
||||
}
|
||||
printf("%s\n", sbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Usage()
|
||||
*/
|
||||
static void
|
||||
Usage(const char *msg)
|
||||
{
|
||||
if (msg)
|
||||
warnx("%s", msg);
|
||||
fprintf(stderr,
|
||||
#ifndef FSTACK
|
||||
"usage: ngctl [-d] [-f file] [-n name] [command ...]\n");
|
||||
#else
|
||||
"usage: ngctl -p <f-stack proc_id> [-d] [-f file] [-n name] [command ...]\n");
|
||||
#endif
|
||||
exit(EX_USAGE);
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
/*
|
||||
* mkpeer.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int MkPeerCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd mkpeer_cmd = {
|
||||
MkPeerCmd,
|
||||
"mkpeer [path] <type> <hook> <peerhook>",
|
||||
"Create and connect a new node to the node at \"path\"",
|
||||
"The mkpeer command atomically creates a new node of type \"type\""
|
||||
" and connects it to the node at \"path\". The hooks used for the"
|
||||
" connection are \"hook\" on the original node and \"peerhook\""
|
||||
" on the new node."
|
||||
" If \"path\" is omitted then \".\" is assumed.",
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
MkPeerCmd(int ac, char **av)
|
||||
{
|
||||
struct ngm_mkpeer mkp;
|
||||
const char *path = ".";
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 5:
|
||||
path = av[1];
|
||||
ac--;
|
||||
av++;
|
||||
/* FALLTHROUGH */
|
||||
case 4:
|
||||
snprintf(mkp.type, sizeof(mkp.type), "%s", av[1]);
|
||||
snprintf(mkp.ourhook, sizeof(mkp.ourhook), "%s", av[2]);
|
||||
snprintf(mkp.peerhook, sizeof(mkp.peerhook), "%s", av[3]);
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Send message */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
|
||||
/*
|
||||
* msg.c
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*
|
||||
* $Whistle: msg.c,v 1.2 1999/11/29 23:38:35 archie Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int MsgCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd msg_cmd = {
|
||||
MsgCmd,
|
||||
"msg path command [args ... ]",
|
||||
"Send a netgraph control message to the node at \"path\"",
|
||||
"The msg command constructs a netgraph control message from the"
|
||||
" command name and ASCII arguments (if any) and sends that message"
|
||||
" to the node. It does this by first asking the node to convert"
|
||||
" the ASCII message into binary format, and resending the result.",
|
||||
{ "cmd" }
|
||||
};
|
||||
|
||||
static int
|
||||
MsgCmd(int ac, char **av)
|
||||
{
|
||||
char *buf;
|
||||
char *path, *cmdstr;
|
||||
int i, len;
|
||||
|
||||
/* Get arguments */
|
||||
if (ac < 3)
|
||||
return (CMDRTN_USAGE);
|
||||
path = av[1];
|
||||
cmdstr = av[2];
|
||||
|
||||
/* Put command and arguments back together as one string */
|
||||
for (len = 1, i = 3; i < ac; i++)
|
||||
len += strlen(av[i]) + 1;
|
||||
if ((buf = malloc(len)) == NULL) {
|
||||
warn("malloc");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
for (*buf = '\0', i = 3; i < ac; i++) {
|
||||
snprintf(buf + strlen(buf),
|
||||
len - strlen(buf), " %s", av[i]);
|
||||
}
|
||||
|
||||
/* Send it */
|
||||
if (NgSendAsciiMsg(csock, path, "%s%s", cmdstr, buf) < 0) {
|
||||
free(buf);
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
free(buf);
|
||||
|
||||
#ifndef FSTACK
|
||||
/* See if a synchronous reply awaits */
|
||||
{
|
||||
struct timeval tv;
|
||||
fd_set rfds;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(csock, &rfds);
|
||||
memset(&tv, 0, sizeof(tv));
|
||||
switch (select(csock + 1, &rfds, NULL, NULL, &tv)) {
|
||||
case -1:
|
||||
err(EX_OSERR, "select");
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
MsgRead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
MsgRead();
|
||||
#endif
|
||||
|
||||
/* Done */
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read and display the next incoming control message
|
||||
*/
|
||||
void
|
||||
MsgRead(void)
|
||||
{
|
||||
struct ng_mesg *m, *m2;
|
||||
struct ng_mesg *ascii;
|
||||
char path[NG_PATHSIZ];
|
||||
|
||||
/* Get incoming message (in binary form) */
|
||||
if (NgAllocRecvMsg(csock, &m, path) < 0) {
|
||||
warn("recv incoming message");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ask originating node to convert message to ASCII */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_BINARY2ASCII, m, sizeof(*m) + m->header.arglen) < 0
|
||||
|| NgAllocRecvMsg(csock, &m2, NULL) < 0) {
|
||||
printf("Rec'd %s %d from \"%s\":\n",
|
||||
(m->header.flags & NGF_RESP) != 0 ? "response" : "command",
|
||||
m->header.cmd, path);
|
||||
if (m->header.arglen == 0)
|
||||
printf("No arguments\n");
|
||||
else
|
||||
DumpAscii((const u_char *)m->data, m->header.arglen);
|
||||
free(m);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Display message in ASCII form */
|
||||
free(m);
|
||||
ascii = (struct ng_mesg *)m2->data;
|
||||
printf("Rec'd %s \"%s\" (%d) from \"%s\":\n",
|
||||
(ascii->header.flags & NGF_RESP) != 0 ? "response" : "command",
|
||||
ascii->header.cmdstr, ascii->header.cmd, path);
|
||||
if (*ascii->data != '\0')
|
||||
printf("Args:\t%s\n", ascii->data);
|
||||
else
|
||||
printf("No arguments\n");
|
||||
free(m2);
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
|
||||
/*
|
||||
* name.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <netgraph.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int NameCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd name_cmd = {
|
||||
NameCmd,
|
||||
"name <path> <name>",
|
||||
"Assign name <name> to the node at <path>",
|
||||
NULL,
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
NameCmd(int ac, char **av)
|
||||
{
|
||||
struct ngm_name name;
|
||||
char *path;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 3:
|
||||
path = av[1];
|
||||
snprintf(name.name, sizeof(name.name), "%s", av[2]);
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Send message */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_NAME, &name, sizeof(name)) < 0) {
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
.\" 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.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\" $Whistle: ngctl.8,v 1.6 1999/01/20 03:19:44 archie Exp $
|
||||
.\"
|
||||
.Dd January 19, 1999
|
||||
.Dt NGCTL 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ngctl
|
||||
.Nd netgraph control utility
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl d
|
||||
.Op Fl f Ar filename
|
||||
.Op Fl n Ar nodename
|
||||
.Op Ar command ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility creates a new netgraph node of type
|
||||
.Em socket
|
||||
which can be used to issue netgraph commands.
|
||||
If no
|
||||
.Fl f
|
||||
flag is given, no
|
||||
command is supplied on the command line, and standard input is a tty,
|
||||
.Nm
|
||||
will enter interactive mode.
|
||||
Otherwise
|
||||
.Nm
|
||||
will execute the supplied command(s) and exit immediately.
|
||||
.Pp
|
||||
Nodes can be created, removed, joined together, etc.
|
||||
.Tn ASCII
|
||||
formatted control messages can be sent to any node if that node
|
||||
supports binary/ASCII control message conversion.
|
||||
.Pp
|
||||
In interactive mode,
|
||||
.Nm
|
||||
will display any control messages and data packets received by the socket node.
|
||||
In the case of control messages, the message arguments are displayed in
|
||||
.Tn ASCII
|
||||
form if the originating node supports conversion.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl f Ar nodeinfo
|
||||
Read commands from the named file.
|
||||
A single dash represents the standard input.
|
||||
Blank lines and lines starting with a
|
||||
.Dq #
|
||||
are ignored.
|
||||
.It Fl n Ar nodename
|
||||
Assign
|
||||
.Em nodename
|
||||
to the newly created netgraph node.
|
||||
The default name is
|
||||
.Em ngctlXXX
|
||||
where XXX is the process ID number.
|
||||
.It Fl d
|
||||
Increase the debugging verbosity level.
|
||||
.El
|
||||
.Sh COMMANDS
|
||||
The currently supported commands in
|
||||
.Nm
|
||||
are:
|
||||
.Pp
|
||||
.Bd -literal -offset indent -compact
|
||||
config get or set configuration of node at <path>
|
||||
connect Connects hook <peerhook> of the node at <relpath> to <hook>
|
||||
debug Get/set debugging verbosity level
|
||||
dot Produce a GraphViz (.dot) of the entire netgraph.
|
||||
help Show command summary or get more help on a specific command
|
||||
list Show information about all nodes
|
||||
mkpeer Create and connect a new node to the node at "path"
|
||||
msg Send a netgraph control message to the node at "path"
|
||||
name Assign name <name> to the node at <path>
|
||||
read Read and execute commands from a file
|
||||
rmhook Disconnect hook "hook" of the node at "path"
|
||||
show Show information about the node at <path>
|
||||
shutdown Shutdown the node at <path>
|
||||
status Get human readable status information from the node at <path>
|
||||
types Show information about all installed node types
|
||||
write Send a data packet down the hook named by "hook".
|
||||
quit Exit program
|
||||
.Ed
|
||||
.Pp
|
||||
Some commands have aliases, e.g.,
|
||||
.Dq ls
|
||||
is the same as
|
||||
.Dq list .
|
||||
The
|
||||
.Dq help
|
||||
command displays the available
|
||||
commands, their usage and aliases, and a brief description.
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh SEE ALSO
|
||||
.Xr netgraph 3 ,
|
||||
.Xr netgraph 4 ,
|
||||
.Xr nghook 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm netgraph
|
||||
system was designed and first implemented at Whistle Communications, Inc.\& in
|
||||
a version of
|
||||
.Fx 2.2
|
||||
customized for the Whistle InterJet.
|
||||
.Sh AUTHORS
|
||||
.An Archie Cobbs Aq Mt archie@whistle.com
|
|
@ -0,0 +1,88 @@
|
|||
|
||||
/*
|
||||
* ngctl.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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifdef FSTACK
|
||||
#ifndef __unused
|
||||
#define __unused __attribute__((__unused__))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAX_CMD_ALIAS 8
|
||||
|
||||
/* Command descriptors */
|
||||
struct ngcmd {
|
||||
int (*func)(int ac, char **av); /* command function */
|
||||
const char *cmd; /* command usage */
|
||||
const char *desc; /* description */
|
||||
const char *help; /* help text */
|
||||
const char *aliases[MAX_CMD_ALIAS]; /* command aliases */
|
||||
};
|
||||
|
||||
/* Command return values */
|
||||
#define CMDRTN_OK 0
|
||||
#define CMDRTN_USAGE 1
|
||||
#define CMDRTN_ERROR 2
|
||||
#define CMDRTN_QUIT 3
|
||||
|
||||
/* Available commands */
|
||||
extern const struct ngcmd config_cmd;
|
||||
extern const struct ngcmd connect_cmd;
|
||||
extern const struct ngcmd debug_cmd;
|
||||
extern const struct ngcmd dot_cmd;
|
||||
extern const struct ngcmd help_cmd;
|
||||
extern const struct ngcmd list_cmd;
|
||||
extern const struct ngcmd mkpeer_cmd;
|
||||
extern const struct ngcmd msg_cmd;
|
||||
extern const struct ngcmd name_cmd;
|
||||
extern const struct ngcmd read_cmd;
|
||||
extern const struct ngcmd rmhook_cmd;
|
||||
extern const struct ngcmd show_cmd;
|
||||
extern const struct ngcmd shutdown_cmd;
|
||||
extern const struct ngcmd status_cmd;
|
||||
extern const struct ngcmd types_cmd;
|
||||
extern const struct ngcmd write_cmd;
|
||||
extern const struct ngcmd quit_cmd;
|
||||
|
||||
/* Data and control sockets */
|
||||
extern int csock, dsock;
|
||||
|
||||
/* Misc functions */
|
||||
extern void MsgRead(void);
|
||||
extern void DumpAscii(const u_char *buf, int len);
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
|
||||
/*
|
||||
* rmhook.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int RmHookCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd rmhook_cmd = {
|
||||
RmHookCmd,
|
||||
"rmhook [path] <hook>",
|
||||
"Disconnect hook \"hook\" of the node at \"path\"",
|
||||
"The rmhook command forces the node at \"path\" to break the link"
|
||||
" formed by its hook \"hook\", if connected."
|
||||
" If \"path\" is omitted then \".\" is assumed.",
|
||||
{ "disconnect" }
|
||||
};
|
||||
|
||||
static int
|
||||
RmHookCmd(int ac, char **av)
|
||||
{
|
||||
struct ngm_rmhook rmh;
|
||||
const char *path = ".";
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 3:
|
||||
path = av[1];
|
||||
ac--;
|
||||
av++;
|
||||
/* FALLTHROUGH */
|
||||
case 2:
|
||||
snprintf(rmh.ourhook, sizeof(rmh.ourhook), "%s", av[1]);
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Send message */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_RMHOOK, &rmh, sizeof(rmh)) < 0) {
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
|
||||
/*
|
||||
* show.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
#define FMT " %-15s %-15s %-12s %-15s %-15s\n"
|
||||
#define UNNAMED "<unnamed>"
|
||||
#define NOSTATUS "<no status>"
|
||||
|
||||
static int ShowCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd show_cmd = {
|
||||
ShowCmd,
|
||||
"show [-n] <path>",
|
||||
"Show information about the node at <path>",
|
||||
"If the -n flag is given, hooks are not listed.",
|
||||
{ "inquire", "info" }
|
||||
};
|
||||
|
||||
static int
|
||||
ShowCmd(int ac, char **av)
|
||||
{
|
||||
char *path;
|
||||
struct ng_mesg *resp;
|
||||
struct hooklist *hlist;
|
||||
struct nodeinfo *ninfo;
|
||||
int ch, no_hooks = 0;
|
||||
|
||||
/* Get options */
|
||||
optind = 1;
|
||||
while ((ch = getopt(ac, av, "n")) != -1) {
|
||||
switch (ch) {
|
||||
case 'n':
|
||||
no_hooks = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ac -= optind;
|
||||
av += optind;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 1:
|
||||
path = av[0];
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Get node info and hook list */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_LISTHOOKS, NULL, 0) < 0) {
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
if (NgAllocRecvMsg(csock, &resp, NULL) < 0) {
|
||||
warn("recv msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
|
||||
/* Show node information */
|
||||
hlist = (struct hooklist *) resp->data;
|
||||
ninfo = &hlist->nodeinfo;
|
||||
if (!*ninfo->name)
|
||||
snprintf(ninfo->name, sizeof(ninfo->name), "%s", UNNAMED);
|
||||
printf(" Name: %-15s Type: %-15s ID: %08x Num hooks: %d\n",
|
||||
ninfo->name, ninfo->type, ninfo->id, ninfo->hooks);
|
||||
if (!no_hooks && ninfo->hooks > 0) {
|
||||
u_int k;
|
||||
|
||||
printf(FMT, "Local hook", "Peer name",
|
||||
"Peer type", "Peer ID", "Peer hook");
|
||||
printf(FMT, "----------", "---------",
|
||||
"---------", "-------", "---------");
|
||||
for (k = 0; k < ninfo->hooks; k++) {
|
||||
struct linkinfo *const link = &hlist->link[k];
|
||||
struct nodeinfo *const peer = &hlist->link[k].nodeinfo;
|
||||
char idbuf[20];
|
||||
|
||||
if (!*peer->name) {
|
||||
snprintf(peer->name, sizeof(peer->name),
|
||||
"%s", UNNAMED);
|
||||
}
|
||||
snprintf(idbuf, sizeof(idbuf), "%08x", peer->id);
|
||||
printf(FMT, link->ourhook, peer->name,
|
||||
peer->type, idbuf, link->peerhook);
|
||||
}
|
||||
}
|
||||
free(resp);
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
/*
|
||||
* shutdown.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int ShutdownCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd shutdown_cmd = {
|
||||
ShutdownCmd,
|
||||
"shutdown <path>",
|
||||
"Shutdown the node at <path>",
|
||||
NULL,
|
||||
{ "kill", "rmnode" }
|
||||
};
|
||||
|
||||
static int
|
||||
ShutdownCmd(int ac, char **av)
|
||||
{
|
||||
char *path;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 2:
|
||||
path = av[1];
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Shutdown node */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_SHUTDOWN, NULL, 0) < 0) {
|
||||
warn("shutdown");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
|
||||
/*
|
||||
* status.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
#define NOSTATUS "<no status>"
|
||||
|
||||
static int StatusCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd status_cmd = {
|
||||
StatusCmd,
|
||||
"status <path>",
|
||||
"Get human readable status information from the node at <path>",
|
||||
NULL,
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
StatusCmd(int ac, char **av)
|
||||
{
|
||||
u_char sbuf[sizeof(struct ng_mesg) + NG_TEXTRESPONSE];
|
||||
struct ng_mesg *const resp = (struct ng_mesg *) sbuf;
|
||||
char *const status = (char *) resp->data;
|
||||
char *path;
|
||||
int nostat = 0;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 2:
|
||||
path = av[1];
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Get node status summary */
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
|
||||
NGM_TEXT_STATUS, NULL, 0) < 0) {
|
||||
switch (errno) {
|
||||
case EINVAL:
|
||||
nostat = 1;
|
||||
break;
|
||||
default:
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (NgRecvMsg(csock, resp, sizeof(sbuf), NULL) < 0
|
||||
|| (resp->header.flags & NGF_RESP) == 0)
|
||||
nostat = 1;
|
||||
}
|
||||
|
||||
/* Show it */
|
||||
if (nostat)
|
||||
printf("No status available for \"%s\"\n", path);
|
||||
else
|
||||
printf("Status for \"%s\":\n%s\n", path, status);
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
|
||||
/*
|
||||
* types.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <netgraph.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
static int TypesCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd types_cmd = {
|
||||
TypesCmd,
|
||||
"types",
|
||||
"Show information about all installed node types",
|
||||
NULL,
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
TypesCmd(int ac, char **av __unused)
|
||||
{
|
||||
struct ng_mesg *resp;
|
||||
struct typelist *tlist;
|
||||
int rtn = CMDRTN_OK;
|
||||
u_int k;
|
||||
|
||||
/* Get arguments */
|
||||
switch (ac) {
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Get list of types */
|
||||
if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE,
|
||||
NGM_LISTTYPES, NULL, 0) < 0) {
|
||||
warn("send msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
if (NgAllocRecvMsg(csock, &resp, NULL) < 0) {
|
||||
warn("recv msg");
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
|
||||
/* Show each type */
|
||||
tlist = (struct typelist *) resp->data;
|
||||
printf("There are %d total types:\n", tlist->numtypes);
|
||||
if (tlist->numtypes > 0) {
|
||||
printf("%15s Number of living nodes\n", "Type name");
|
||||
printf("%15s ----------------------\n", "---------");
|
||||
}
|
||||
for (k = 0; k < tlist->numtypes; k++) {
|
||||
struct typeinfo *const ti = &tlist->typeinfo[k];
|
||||
printf("%15s %5d\n", ti->type_name, ti->numnodes);
|
||||
}
|
||||
|
||||
/* Done */
|
||||
free(resp);
|
||||
return (rtn);
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
|
||||
/*
|
||||
* write.c
|
||||
*
|
||||
* Copyright (c) 2002 Archie L. Cobbs
|
||||
* 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 Archie L. Cobbs;
|
||||
* 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
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED BY ARCHIE L. COBBS AS IS", AND TO
|
||||
* THE MAXIMUM EXTENT PERMITTED BY LAW, ARCHIE L. COBBS 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.
|
||||
* ARCHIE L. COBBS 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 ARCHIE L. COBBS 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 ARCHIE L. COBBS IS ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <netgraph/ng_socket.h>
|
||||
|
||||
#include "ngctl.h"
|
||||
|
||||
#define BUF_SIZE 8192
|
||||
|
||||
static int WriteCmd(int ac, char **av);
|
||||
|
||||
const struct ngcmd write_cmd = {
|
||||
WriteCmd,
|
||||
"write hook < -f file | byte ... >",
|
||||
"Send a data packet down the hook named by \"hook\".",
|
||||
"The data may be contained in a file, or may be described directly"
|
||||
" on the command line by supplying a sequence of bytes.",
|
||||
{ "w" }
|
||||
};
|
||||
|
||||
static int
|
||||
WriteCmd(int ac, char **av)
|
||||
{
|
||||
u_int32_t sagbuf[64];
|
||||
struct sockaddr_ng *sag = (struct sockaddr_ng *)sagbuf;
|
||||
u_char buf[BUF_SIZE];
|
||||
const char *hook;
|
||||
FILE *fp;
|
||||
u_int len;
|
||||
int byte;
|
||||
int i;
|
||||
|
||||
/* Get arguments */
|
||||
if (ac < 3)
|
||||
return (CMDRTN_USAGE);
|
||||
hook = av[1];
|
||||
|
||||
/* Get data */
|
||||
if (strcmp(av[2], "-f") == 0) {
|
||||
if (ac != 4)
|
||||
return (CMDRTN_USAGE);
|
||||
if ((fp = fopen(av[3], "r")) == NULL) {
|
||||
warn("can't read file \"%s\"", av[3]);
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
if ((len = fread(buf, 1, sizeof(buf), fp)) == 0) {
|
||||
if (ferror(fp))
|
||||
warn("can't read file \"%s\"", av[3]);
|
||||
else
|
||||
warnx("file \"%s\" is empty", av[3]);
|
||||
fclose(fp);
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
fclose(fp);
|
||||
} else {
|
||||
for (i = 2, len = 0; i < ac && len < sizeof(buf); i++, len++) {
|
||||
if (sscanf(av[i], "%i", &byte) != 1
|
||||
|| (byte < -128 || byte > 255)) {
|
||||
warnx("invalid byte \"%s\"", av[i]);
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
buf[len] = (u_char)byte;
|
||||
}
|
||||
if (len == 0)
|
||||
return (CMDRTN_USAGE);
|
||||
}
|
||||
|
||||
/* Send data */
|
||||
sag->sg_len = 3 + strlen(hook);
|
||||
sag->sg_family = AF_NETGRAPH;
|
||||
strlcpy(sag->sg_data, hook, sizeof(sagbuf) - 2);
|
||||
if (sendto(dsock, buf, len,
|
||||
0, (struct sockaddr *)sag, sag->sg_len) == -1) {
|
||||
warn("writing to hook \"%s\"", hook);
|
||||
return (CMDRTN_ERROR);
|
||||
}
|
||||
|
||||
/* Done */
|
||||
return (CMDRTN_OK);
|
||||
}
|
||||
|
|
@ -60,6 +60,9 @@ CXXFLAGS+= ${FF_PROG_CFLAGS}
|
|||
|
||||
LIBS+= ${FF_PROG_LIBS}
|
||||
|
||||
CFLAGS+= $(foreach n,${LIBADD},-I${TOPDIR}/tools/lib${n})
|
||||
LIBS+= $(foreach n,${LIBADD},-L${TOPDIR}/tools/lib${n} -l${n})
|
||||
|
||||
CLEANFILES+= ${PROG} ${OBJS}
|
||||
|
||||
${PROG}: ${HEADERS} ${OBJS}
|
||||
|
|
Loading…
Reference in New Issue