Add tool: ifconfig.
Changes: Remove directory `ipc`, and add a new directory `compat`. Directory `compat` includes some FreeBSD source files to be compatible with Linux. Port FreeBSD ifconfig to F-Stack.dev
parent
b40d69985a
commit
df6ad73146
|
@ -9,11 +9,10 @@ ifeq ($(FF_DPDK),)
|
|||
endif
|
||||
|
||||
LIBS+= -L${FF_PATH}/lib -L${FF_DPDK}/lib -Wl,--whole-archive,-lfstack,--no-whole-archive
|
||||
LIBS+= -g -Wl,--no-as-needed -fvisibility=default -pthread -lm -lrt
|
||||
LIBS+= -Wl,--whole-archive -lrte_pmd_vmxnet3_uio -lrte_pmd_i40e -lrte_pmd_ixgbe -lrte_pmd_e1000 -lrte_pmd_ring
|
||||
LIBS+= -Wl,--whole-archive -lrte_hash -lrte_kvargs -Wl,-lrte_mbuf -lethdev -lrte_eal -Wl,-lrte_mempool
|
||||
LIBS+= -lrte_ring -lrte_cmdline -lrte_cfgfile -lrte_kni -lrte_timer -Wl,-lrte_pmd_virtio
|
||||
LIBS+= -Wl,--no-whole-archive -lrt -lm -ldl -lcrypto
|
||||
LIBS+= -Wl,--no-whole-archive -lrt -lm -ldl -lcrypto -pthread
|
||||
|
||||
TARGET="helloworld"
|
||||
all:
|
||||
|
|
|
@ -232,14 +232,19 @@ MACHINE_SRCS+= \
|
|||
|
||||
NET_SRCS+= \
|
||||
bpf.c \
|
||||
bridgestp.c \
|
||||
if.c \
|
||||
if_bridge.c \
|
||||
if_clone.c \
|
||||
if_dead.c \
|
||||
if_ethersubr.c \
|
||||
if_loop.c \
|
||||
if_llatbl.c \
|
||||
in_fib.c \
|
||||
in_gif.c \
|
||||
ip_reass.c \
|
||||
if_vlan.c \
|
||||
if_vxlan.c \
|
||||
netisr.c \
|
||||
pfil.c \
|
||||
radix.c \
|
||||
|
@ -252,12 +257,14 @@ NET_SRCS+= \
|
|||
NETINET_SRCS+= \
|
||||
ip_carp.c \
|
||||
if_ether.c \
|
||||
if_gif.c \
|
||||
igmp.c \
|
||||
in.c \
|
||||
in_mcast.c \
|
||||
in_pcb.c \
|
||||
in_proto.c \
|
||||
in_rmx.c \
|
||||
ip_ecn.c \
|
||||
ip_encap.c \
|
||||
ip_fastfwd.c \
|
||||
ip_icmp.c \
|
||||
|
|
|
@ -526,6 +526,7 @@ ff_msg_init(struct rte_mempool *mp,
|
|||
void *obj, __attribute__((unused)) unsigned i)
|
||||
{
|
||||
struct ff_msg *msg = (struct ff_msg *)obj;
|
||||
msg->msg_type = FF_UNKNOWN;
|
||||
msg->buf_addr = (char *)msg + sizeof(struct ff_msg);
|
||||
msg->buf_len = mp->elt_size - sizeof(struct ff_msg);
|
||||
}
|
||||
|
@ -979,6 +980,30 @@ handle_sysctl_msg(struct ff_msg *msg, uint16_t proc_id)
|
|||
rte_ring_enqueue(msg_ring[proc_id].ring[1], msg);
|
||||
}
|
||||
|
||||
static inline void
|
||||
handle_ioctl_msg(struct ff_msg *msg, uint16_t proc_id)
|
||||
{
|
||||
int fd, ret;
|
||||
fd = ff_socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
ret = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = ff_ioctl(fd, msg->ioctl.cmd, msg->ioctl.data);
|
||||
|
||||
ff_close(fd);
|
||||
|
||||
done:
|
||||
if (ret < 0) {
|
||||
msg->result = errno;
|
||||
} else {
|
||||
msg->result = 0;
|
||||
}
|
||||
|
||||
rte_ring_enqueue(msg_ring[proc_id].ring[1], msg);
|
||||
}
|
||||
|
||||
static inline void
|
||||
handle_default_msg(struct ff_msg *msg, uint16_t proc_id)
|
||||
{
|
||||
|
@ -993,6 +1018,9 @@ handle_msg(struct ff_msg *msg, uint16_t proc_id)
|
|||
case FF_SYSCTL:
|
||||
handle_sysctl_msg(msg, proc_id);
|
||||
break;
|
||||
case FF_IOCTL:
|
||||
handle_ioctl_msg(msg, proc_id);
|
||||
break;
|
||||
default:
|
||||
handle_default_msg(msg, proc_id);
|
||||
break;
|
||||
|
|
|
@ -1095,3 +1095,8 @@ sched_unbind(struct thread* td)
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
getcredhostid(struct ucred *cred, unsigned long *hostid)
|
||||
{
|
||||
*hostid = 0;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,12 @@ _cv_wait(struct cv *cvp, struct lock_object *lock)
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
_cv_wait_unlock(struct cv *cvp, struct lock_object *lock)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
_cv_wait_sig(struct cv *cvp, struct lock_object *lock)
|
||||
{
|
||||
|
|
|
@ -33,10 +33,11 @@
|
|||
#define FF_MSG_RING_OUT "ff_msg_ring_out_"
|
||||
#define FF_MSG_POOL "ff_msg_pool"
|
||||
|
||||
/* MSG TYPE: sysctl, sysctlbyname, etc.. */
|
||||
/* MSG TYPE: sysctl, ioctl, etc.. */
|
||||
enum FF_MSG_TYPE {
|
||||
FF_UNKNOWN = 0,
|
||||
FF_SYSCTL,
|
||||
FF_IOCTL,
|
||||
};
|
||||
|
||||
struct ff_sysctl_args {
|
||||
|
@ -48,6 +49,11 @@ struct ff_sysctl_args {
|
|||
size_t newlen;
|
||||
};
|
||||
|
||||
struct ff_ioctl_args {
|
||||
unsigned long cmd;
|
||||
void *data;
|
||||
};
|
||||
|
||||
#define MAX_MSG_BUF_SIZE 10240
|
||||
|
||||
/* structure of ipc msg */
|
||||
|
@ -62,6 +68,7 @@ struct ff_msg {
|
|||
|
||||
union {
|
||||
struct ff_sysctl_args sysctl;
|
||||
struct ff_ioctl_args ioctl;
|
||||
};
|
||||
} __attribute__((packed)) __rte_cache_aligned;
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ linux2freebsd_ioctl(unsigned long request)
|
|||
case LINUX_TIOCPKT_IOCTL:
|
||||
return TIOCPKT_IOCTL;
|
||||
default:
|
||||
return (-1);
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS=ipc sysctl
|
||||
SUBDIRS=compat sysctl ifconfig
|
||||
|
||||
all:
|
||||
for d in $(SUBDIRS); do ( cd $$d; $(MAKE) all ) ; done
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
# Introduction
|
||||
|
||||
Directory `ipc` implements an ipc library using dpdk `rte_ring`, can be used to communicate with F-Stack processes.
|
||||
Directory `compat` implements an ipc library using dpdk `rte_ring` and ports some source files compatible with FreeBSD and Linux.
|
||||
|
||||
All other directories are useful tools ported from FreeBSD.
|
||||
|
||||
# ipc
|
||||
|
||||
This is a simple implemention using dpdk `rte_ring`.
|
||||
```
|
||||
ff_ipc_msg_alloc: get msg structure from rte_mempool.
|
||||
ff_ipc_msg_free: put msg to rte_mempool.
|
||||
ff_ipc_send: enqueue msg to rte_ring.
|
||||
ff_ipc_recv: dequeue msg from rte_ring.
|
||||
```
|
||||
|
||||
Since F-Stack is multi-process architecture and every process has an independent stack, so we must communicate with every F-Stack process.
|
||||
Each tool add an option `-p`(Which F-Stack process to communicate with, default 0), except that, it is same with the original FreeBSD.
|
||||
|
||||
Note that these tools must be executed serially.
|
||||
|
||||
# sysctl
|
||||
Usage:
|
||||
|
@ -22,12 +14,30 @@ Usage:
|
|||
sysctl -p <f-stack proc_id> [-bdehiNnoqTtWx] [ -B <bufsize> ] [-f filename] name[=value] ...
|
||||
sysctl -p <f-stack proc_id> [-bdehNnoqTtWx] [ -B <bufsize> ] -a
|
||||
```
|
||||
For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?sysctl).
|
||||
|
||||
# ifconfig
|
||||
Usage:
|
||||
```
|
||||
-p Which F-Stack process to communicate with, default 0.
|
||||
ifconfig -p <f-stack proc_id> [-f type:format] %sinterface address_family
|
||||
[address [dest_address]] [parameters]
|
||||
ifconfig -p <f-stack proc_id> interface create
|
||||
ifconfig -p <f-stack proc_id> -a %s[-d] [-m] [-u] [-v] [address_family]
|
||||
ifconfig -p <f-stack proc_id> -l [-d] [-u] [address_family]
|
||||
ifconfig -p <f-stack proc_id> %s[-d] [-m] [-u] [-v]
|
||||
```
|
||||
|
||||
Except this option, it is same with the original FreeBSD sysctl, see [Manual page](https://www.freebsd.org/cgi/man.cgi?sysctl).
|
||||
Unsupported interfaces or parameters:
|
||||
```
|
||||
inet6
|
||||
MAC(Mandatory Access Control)
|
||||
media
|
||||
SFP/SFP+
|
||||
IEEE80211 Wireless
|
||||
pfsync
|
||||
LAGG LACP
|
||||
jail
|
||||
```
|
||||
For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?ifconfig).
|
||||
|
||||
# how to implement a custom tool for communicating with F-Stack process
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@ ifeq ($(FF_DPDK),)
|
|||
FF_DPDK=${TOPDIR}/dpdk/x86_64-native-linuxapp-gcc
|
||||
endif
|
||||
|
||||
TARGET=libfstack_ipc.a
|
||||
TARGET=libffcompat.a
|
||||
|
||||
#DEBUG=-O0 -gdwarf-2 -g3
|
||||
|
||||
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
|
||||
|
@ -12,10 +14,10 @@ DPDK_CFLAGS+= -DRTE_MACHINE_CPUFLAG_SSSE3 -DRTE_MACHINE_CPUFLAG_SSE4_1 -DRTE_MAC
|
|||
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
|
||||
CFLAGS+= ${DPDK_CFLAGS} -I${CURDIR}/include
|
||||
CFLAGS+= -I${TOPDIR}/lib -D__BSD_VISIBLE -DFSTACK
|
||||
|
||||
SRCS=ff_ipc.c
|
||||
SRCS=$(wildcard *.c)
|
||||
OBJS=$(patsubst %.c,%.o,${SRCS})
|
||||
|
||||
all: ${TARGET}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _FF_COMPAT_H
|
||||
#define _FF_COMPAT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *reallocf(void *ptr, size_t size);
|
||||
|
||||
int feature_present(const char *feature);
|
||||
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
|
||||
size_t strlcpy(char * __restrict dst, const char * __restrict src,
|
||||
size_t siz);
|
||||
|
||||
long long strtonum(const char *numstr, long long minval,
|
||||
long long maxval, const char **errstrp);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,69 @@
|
|||
/*-
|
||||
* Copyright (c) 2008 Yahoo!, Inc.
|
||||
* All rights reserved.
|
||||
* Written by: John Baldwin <jhb@FreeBSD.org>
|
||||
*
|
||||
* 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. Neither the name of the author nor the names of any co-contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FSTACK
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
#else
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* Returns true if the named feature is present in the currently
|
||||
* running kernel. A feature's presence is indicated by an integer
|
||||
* sysctl node called kern.feature.<feature> that is non-zero.
|
||||
*/
|
||||
int
|
||||
feature_present(const char *feature)
|
||||
{
|
||||
char *mib;
|
||||
size_t len;
|
||||
int i;
|
||||
|
||||
if (asprintf(&mib, "kern.features.%s", feature) < 0)
|
||||
return (0);
|
||||
len = sizeof(i);
|
||||
if (sysctlbyname(mib, &i, &len, NULL, 0) < 0) {
|
||||
free(mib);
|
||||
return (0);
|
||||
}
|
||||
free(mib);
|
||||
if (len != sizeof(i))
|
||||
return (0);
|
||||
return (i != 0);
|
||||
}
|
|
@ -39,6 +39,18 @@ static int inited;
|
|||
|
||||
static struct rte_mempool *message_pool;
|
||||
|
||||
uint16_t ff_proc_id = 0;
|
||||
|
||||
void
|
||||
ff_set_proc_id(int pid)
|
||||
{
|
||||
if (pid < 0 || pid > 65535) {
|
||||
printf("Invalid F-Stack proccess id\n");
|
||||
exit(1);
|
||||
}
|
||||
ff_proc_id = pid;
|
||||
}
|
||||
|
||||
static int
|
||||
ff_ipc_init(void)
|
||||
{
|
||||
|
@ -47,9 +59,10 @@ ff_ipc_init(void)
|
|||
}
|
||||
|
||||
char *dpdk_argv[] = {
|
||||
"-c1", "-n4",
|
||||
"ff-ipc", "-c1", "-n4",
|
||||
"--proc-type=secondary",
|
||||
"--log-level=3",
|
||||
/* RTE_LOG_ERR */
|
||||
"--log-level=5",
|
||||
};
|
||||
|
||||
int ret = rte_eal_init(sizeof(dpdk_argv)/sizeof(dpdk_argv[0]), dpdk_argv);
|
||||
|
@ -100,7 +113,7 @@ ff_ipc_msg_free(struct ff_msg *msg)
|
|||
}
|
||||
|
||||
int
|
||||
ff_ipc_send(const struct ff_msg *msg, uint16_t proc_id)
|
||||
ff_ipc_send(const struct ff_msg *msg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -111,7 +124,7 @@ ff_ipc_send(const struct ff_msg *msg, uint16_t proc_id)
|
|||
|
||||
char name[RTE_RING_NAMESIZE];
|
||||
snprintf(name, RTE_RING_NAMESIZE, "%s%u",
|
||||
FF_MSG_RING_IN, proc_id);
|
||||
FF_MSG_RING_IN, ff_proc_id);
|
||||
struct rte_ring *ring = rte_ring_lookup(name);
|
||||
if (ring == NULL) {
|
||||
printf("lookup message ring:%s failed!\n", name);
|
||||
|
@ -128,7 +141,7 @@ ff_ipc_send(const struct ff_msg *msg, uint16_t proc_id)
|
|||
}
|
||||
|
||||
int
|
||||
ff_ipc_recv(struct ff_msg **msg, uint16_t proc_id)
|
||||
ff_ipc_recv(struct ff_msg **msg)
|
||||
{
|
||||
int ret, i;
|
||||
if (inited == 0) {
|
||||
|
@ -138,7 +151,7 @@ ff_ipc_recv(struct ff_msg **msg, uint16_t proc_id)
|
|||
|
||||
char name[RTE_RING_NAMESIZE];
|
||||
snprintf(name, RTE_RING_NAMESIZE, "%s%u",
|
||||
FF_MSG_RING_OUT, proc_id);
|
||||
FF_MSG_RING_OUT, ff_proc_id);
|
||||
struct rte_ring *ring = rte_ring_lookup(name);
|
||||
if (ring == NULL) {
|
||||
printf("lookup message ring:%s failed!\n", name);
|
||||
|
@ -159,106 +172,3 @@ ff_ipc_recv(struct ff_msg **msg, uint16_t proc_id)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
sysctl_ipc(uint16_t proc_id, int *name, unsigned namelen, void *old,
|
||||
size_t *oldlenp, const void *new, size_t newlen)
|
||||
{
|
||||
struct ff_msg *msg, *retmsg = NULL;
|
||||
|
||||
if (old != NULL && oldlenp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg = ff_ipc_msg_alloc();
|
||||
if (msg == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t oldlen = 0;
|
||||
if (oldlenp) {
|
||||
oldlen = *oldlenp;
|
||||
}
|
||||
|
||||
if (namelen + oldlen + newlen > msg->buf_len) {
|
||||
errno = EINVAL;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *buf_addr = msg->buf_addr;
|
||||
|
||||
msg->msg_type = FF_SYSCTL;
|
||||
msg->sysctl.name = (int *)buf_addr;
|
||||
msg->sysctl.namelen = namelen;
|
||||
memcpy(msg->sysctl.name, name, namelen*sizeof(int));
|
||||
|
||||
buf_addr += namelen*sizeof(int);
|
||||
|
||||
if (new != NULL && newlen != 0) {
|
||||
msg->sysctl.new = buf_addr;
|
||||
msg->sysctl.newlen = newlen;
|
||||
memcpy(msg->sysctl.new, new, newlen);
|
||||
|
||||
buf_addr += newlen;
|
||||
} else {
|
||||
msg->sysctl.new = NULL;
|
||||
msg->sysctl.newlen = 0;
|
||||
}
|
||||
|
||||
if (oldlenp != NULL) {
|
||||
msg->sysctl.oldlenp = (size_t *)buf_addr;
|
||||
memcpy(msg->sysctl.oldlenp, oldlenp, sizeof(size_t));
|
||||
buf_addr += sizeof(size_t);
|
||||
|
||||
if (old != NULL) {
|
||||
msg->sysctl.old = (void *)buf_addr;
|
||||
memcpy(msg->sysctl.old, old, *oldlenp);
|
||||
buf_addr += *oldlenp;
|
||||
} else {
|
||||
msg->sysctl.old = NULL;
|
||||
}
|
||||
} else {
|
||||
msg->sysctl.oldlenp = NULL;
|
||||
msg->sysctl.old = NULL;
|
||||
}
|
||||
|
||||
int ret = ff_ipc_send(msg, proc_id);
|
||||
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, proc_id);
|
||||
if (ret < 0) {
|
||||
errno = EPIPE;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
} while (msg != retmsg);
|
||||
|
||||
if (retmsg->result == 0) {
|
||||
ret = 0;
|
||||
if (oldlenp && retmsg->sysctl.oldlenp) {
|
||||
*oldlenp = *retmsg->sysctl.oldlenp;
|
||||
}
|
||||
|
||||
if (old && retmsg->sysctl.old && oldlenp) {
|
||||
memcpy(old, retmsg->sysctl.old, *oldlenp);
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
errno = retmsg->result;
|
||||
}
|
||||
|
||||
ff_ipc_msg_free(msg);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -29,13 +29,13 @@
|
|||
|
||||
#include "ff_msg.h"
|
||||
|
||||
/* Set F-Stack proccess id to communicate with */
|
||||
void ff_set_proc_id(int pid);
|
||||
|
||||
struct ff_msg *ff_ipc_msg_alloc(void);
|
||||
int ff_ipc_msg_free(struct ff_msg *msg);
|
||||
|
||||
int ff_ipc_send(const struct ff_msg *msg, uint16_t proc_id);
|
||||
int ff_ipc_recv(struct ff_msg **msg, uint16_t proc_id);
|
||||
|
||||
int sysctl_ipc(uint16_t proc_id, int *name, unsigned namelen, void *old,
|
||||
size_t *oldlenp, const void *new, size_t newlen);
|
||||
int ff_ipc_send(const struct ff_msg *msg);
|
||||
int ff_ipc_recv(struct ff_msg **msg);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,122 @@
|
|||
/* $KAME: getaddrinfo.c,v 1.15 2000/07/09 04:37:24 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT 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 <stdlib.h>
|
||||
|
||||
#include "netinet/in.h"
|
||||
#include "arpa/inet.h"
|
||||
#include "sys/socket.h"
|
||||
#include "netdb.h"
|
||||
|
||||
/* Just conver numeric hostname to int and not do anything else. */
|
||||
int
|
||||
getaddrinfo(const char *hostname, const char *servername,
|
||||
const struct addrinfo *hints, struct addrinfo **res)
|
||||
{
|
||||
if (hostname == NULL)
|
||||
return EAI_NONAME;
|
||||
|
||||
*res = NULL;
|
||||
struct addrinfo *ai;
|
||||
|
||||
ai = malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr));
|
||||
if (ai == NULL)
|
||||
return EAI_MEMORY;
|
||||
|
||||
ai->ai_next = NULL;
|
||||
ai->ai_canonname = NULL;
|
||||
ai->ai_addr = (struct sockaddr *)ai+1;
|
||||
|
||||
struct sockaddr_in *si = (struct sockaddr_in *)ai->ai_addr;
|
||||
si->sin_len = ai->ai_addrlen = sizeof(struct sockaddr);
|
||||
si->sin_family = ai->ai_family = AF_INET;
|
||||
/* si->sin_port ? */
|
||||
|
||||
if (hints != NULL) {
|
||||
si->sin_family = ai->ai_family = hints->ai_family;
|
||||
ai->ai_socktype = hints->ai_socktype;
|
||||
}
|
||||
|
||||
if (inet_pton(AF_INET, hostname, &si->sin_addr.s_addr) != 1) {
|
||||
freeaddrinfo(ai);
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
*res = ai;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
freeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
struct addrinfo *next;
|
||||
|
||||
do {
|
||||
next = ai->ai_next;
|
||||
if (ai->ai_canonname)
|
||||
free(ai->ai_canonname);
|
||||
/* no need to free(ai->ai_addr) */
|
||||
free(ai);
|
||||
ai = next;
|
||||
} while (ai);
|
||||
}
|
||||
|
||||
/* Entries EAI_ADDRFAMILY (1) and EAI_NODATA (7) are obsoleted, but left */
|
||||
/* for backward compatibility with userland code prior to 2553bis-02 */
|
||||
static const char *ai_errlist[] = {
|
||||
"Success", /* 0 */
|
||||
"Address family for hostname not supported", /* 1 */
|
||||
"Temporary failure in name resolution", /* EAI_AGAIN */
|
||||
"Invalid value for ai_flags", /* EAI_BADFLAGS */
|
||||
"Non-recoverable failure in name resolution", /* EAI_FAIL */
|
||||
"ai_family not supported", /* EAI_FAMILY */
|
||||
"Memory allocation failure", /* EAI_MEMORY */
|
||||
"No address associated with hostname", /* 7 */
|
||||
"hostname nor servname provided, or not known", /* EAI_NONAME */
|
||||
"servname not supported for ai_socktype", /* EAI_SERVICE */
|
||||
"ai_socktype not supported", /* EAI_SOCKTYPE */
|
||||
"System error returned in errno", /* EAI_SYSTEM */
|
||||
"Invalid value for hints", /* EAI_BADHINTS */
|
||||
"Resolved protocol is unknown", /* EAI_PROTOCOL */
|
||||
"Argument buffer overflow", /* EAI_OVERFLOW */
|
||||
};
|
||||
|
||||
const char *
|
||||
gai_strerror(int ecode)
|
||||
{
|
||||
if (ecode >= 0 && ecode < EAI_MAX)
|
||||
return ai_errlist[ecode];
|
||||
return "Unknown error";
|
||||
}
|
|
@ -0,0 +1,348 @@
|
|||
/* $KAME: getifaddrs.c,v 1.9 2001/08/20 02:31:20 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995, 1999
|
||||
* Berkeley Software Design, Inc. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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.
|
||||
*
|
||||
* BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp
|
||||
*/
|
||||
/*
|
||||
* NOTE: SIOCGIFCONF case is not LP64 friendly. it also does not perform
|
||||
* try-and-error for region size.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#ifdef NET_RT_IFLIST
|
||||
#include <sys/param.h>
|
||||
#include <net/route.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <net/if_dl.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef FSTACK
|
||||
#include "un-namespace.h"
|
||||
#endif
|
||||
|
||||
#if !defined(AF_LINK)
|
||||
#define SA_LEN(sa) sizeof(struct sockaddr)
|
||||
#endif
|
||||
|
||||
#if !defined(SA_LEN)
|
||||
#define SA_LEN(sa) (sa)->sa_len
|
||||
#endif
|
||||
|
||||
#define SALIGN (sizeof(long) - 1)
|
||||
#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1))
|
||||
|
||||
#ifndef ALIGNBYTES
|
||||
/*
|
||||
* On systems with a routing socket, ALIGNBYTES should match the value
|
||||
* that the kernel uses when building the messages.
|
||||
*/
|
||||
#define ALIGNBYTES (sizeof(long long) - 1)
|
||||
#endif
|
||||
#ifndef ALIGN
|
||||
#define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
|
||||
#endif
|
||||
|
||||
#define MAX_SYSCTL_TRY 5
|
||||
|
||||
int
|
||||
getifaddrs(struct ifaddrs **pif)
|
||||
{
|
||||
int icnt = 1;
|
||||
int dcnt = 0;
|
||||
int ncnt = 0;
|
||||
int ntry = 0;
|
||||
int mib[6];
|
||||
size_t needed;
|
||||
char *buf;
|
||||
char *next;
|
||||
struct ifaddrs *cif;
|
||||
char *p, *p0;
|
||||
struct rt_msghdr *rtm;
|
||||
struct if_msghdrl *ifm;
|
||||
struct ifa_msghdrl *ifam;
|
||||
struct sockaddr_dl *dl;
|
||||
struct sockaddr *sa;
|
||||
struct ifaddrs *ifa, *ift;
|
||||
struct if_data *if_data;
|
||||
u_short idx = 0;
|
||||
int i;
|
||||
size_t len, alen;
|
||||
char *data;
|
||||
char *names;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_ROUTE;
|
||||
mib[2] = 0; /* protocol */
|
||||
mib[3] = 0; /* wildcard address family */
|
||||
mib[4] = NET_RT_IFLISTL;/* extra fields for extensible msghdr structs */
|
||||
mib[5] = 0; /* no flags */
|
||||
do {
|
||||
/*
|
||||
* We'll try to get addresses several times in case that
|
||||
* the number of addresses is unexpectedly increased during
|
||||
* the two sysctl calls. This should rarely happen, but we'll
|
||||
* try to do our best for applications that assume success of
|
||||
* this library (which should usually be the case).
|
||||
* Portability note: since FreeBSD does not add margin of
|
||||
* memory at the first sysctl, the possibility of failure on
|
||||
* the second sysctl call is a bit higher.
|
||||
*/
|
||||
|
||||
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
|
||||
return (-1);
|
||||
if ((buf = malloc(needed)) == NULL)
|
||||
return (-1);
|
||||
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
|
||||
if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) {
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
} while (buf == NULL);
|
||||
|
||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)(void *)next;
|
||||
if (rtm->rtm_version != RTM_VERSION)
|
||||
continue;
|
||||
switch (rtm->rtm_type) {
|
||||
case RTM_IFINFO:
|
||||
ifm = (struct if_msghdrl *)(void *)rtm;
|
||||
if (ifm->ifm_addrs & RTA_IFP) {
|
||||
idx = ifm->ifm_index;
|
||||
++icnt;
|
||||
if_data = IF_MSGHDRL_IFM_DATA(ifm);
|
||||
dcnt += if_data->ifi_datalen;
|
||||
dl = (struct sockaddr_dl *)IF_MSGHDRL_RTA(ifm);
|
||||
dcnt += SA_RLEN((struct sockaddr *)(void*)dl) +
|
||||
ALIGNBYTES;
|
||||
ncnt += dl->sdl_nlen + 1;
|
||||
} else
|
||||
idx = 0;
|
||||
break;
|
||||
|
||||
case RTM_NEWADDR:
|
||||
ifam = (struct ifa_msghdrl *)(void *)rtm;
|
||||
if (idx && ifam->ifam_index != idx)
|
||||
abort(); /* this cannot happen */
|
||||
|
||||
#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD)
|
||||
if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0)
|
||||
break;
|
||||
p = (char *)IFA_MSGHDRL_RTA(ifam);
|
||||
++icnt;
|
||||
if_data = IFA_MSGHDRL_IFAM_DATA(ifam);
|
||||
dcnt += if_data->ifi_datalen + ALIGNBYTES;
|
||||
|
||||
/* Scan to look for length of address */
|
||||
alen = 0;
|
||||
for (p0 = p, i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
|
||||
== 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
if (i == RTAX_IFA) {
|
||||
alen = len;
|
||||
break;
|
||||
}
|
||||
p += len;
|
||||
}
|
||||
for (p = p0, i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
|
||||
== 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
if (i == RTAX_NETMASK && SA_LEN(sa) == 0)
|
||||
dcnt += alen;
|
||||
else
|
||||
dcnt += len;
|
||||
p += len;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (icnt + dcnt + ncnt == 1) {
|
||||
*pif = NULL;
|
||||
free(buf);
|
||||
return (0);
|
||||
}
|
||||
data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt);
|
||||
if (data == NULL) {
|
||||
free(buf);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
ifa = (struct ifaddrs *)(void *)data;
|
||||
data += sizeof(struct ifaddrs) * icnt;
|
||||
names = data + dcnt;
|
||||
|
||||
memset(ifa, 0, sizeof(struct ifaddrs) * icnt);
|
||||
ift = ifa;
|
||||
|
||||
idx = 0;
|
||||
cif = NULL;
|
||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)(void *)next;
|
||||
if (rtm->rtm_version != RTM_VERSION)
|
||||
continue;
|
||||
switch (rtm->rtm_type) {
|
||||
case RTM_IFINFO:
|
||||
ifm = (struct if_msghdrl *)(void *)rtm;
|
||||
if ((ifm->ifm_addrs & RTA_IFP) == 0) {
|
||||
idx = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
idx = ifm->ifm_index;
|
||||
dl = (struct sockaddr_dl *)IF_MSGHDRL_RTA(ifm);
|
||||
|
||||
cif = ift;
|
||||
ift->ifa_name = names;
|
||||
ift->ifa_flags = (int)ifm->ifm_flags;
|
||||
memcpy(names, dl->sdl_data, (size_t)dl->sdl_nlen);
|
||||
names[dl->sdl_nlen] = 0;
|
||||
names += dl->sdl_nlen + 1;
|
||||
|
||||
ift->ifa_addr = (struct sockaddr *)(void *)data;
|
||||
memcpy(data, dl, (size_t)SA_LEN((struct sockaddr *)
|
||||
(void *)dl));
|
||||
data += SA_RLEN((struct sockaddr *)(void *)dl);
|
||||
|
||||
if_data = IF_MSGHDRL_IFM_DATA(ifm);
|
||||
/* ifm_data needs to be aligned */
|
||||
ift->ifa_data = data = (void *)ALIGN(data);
|
||||
memcpy(data, if_data, if_data->ifi_datalen);
|
||||
data += if_data->ifi_datalen;
|
||||
|
||||
ift = (ift->ifa_next = ift + 1);
|
||||
break;
|
||||
|
||||
case RTM_NEWADDR:
|
||||
ifam = (struct ifa_msghdrl *)(void *)rtm;
|
||||
if (idx && ifam->ifam_index != idx)
|
||||
abort(); /* this cannot happen */
|
||||
|
||||
if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0)
|
||||
break;
|
||||
ift->ifa_name = cif->ifa_name;
|
||||
ift->ifa_flags = cif->ifa_flags;
|
||||
ift->ifa_data = NULL;
|
||||
|
||||
p = (char *)IFA_MSGHDRL_RTA(ifam);
|
||||
/* Scan to look for length of address */
|
||||
alen = 0;
|
||||
for (p0 = p, i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
|
||||
== 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
if (i == RTAX_IFA) {
|
||||
alen = len;
|
||||
break;
|
||||
}
|
||||
p += len;
|
||||
}
|
||||
for (p = p0, i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
|
||||
== 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
switch (i) {
|
||||
case RTAX_IFA:
|
||||
ift->ifa_addr =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
case RTAX_NETMASK:
|
||||
ift->ifa_netmask =
|
||||
(struct sockaddr *)(void *)data;
|
||||
if (SA_LEN(sa) == 0) {
|
||||
memset(data, 0, alen);
|
||||
data += alen;
|
||||
break;
|
||||
}
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
case RTAX_BRD:
|
||||
ift->ifa_broadaddr =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
}
|
||||
p += len;
|
||||
}
|
||||
|
||||
if_data = IFA_MSGHDRL_IFAM_DATA(ifam);
|
||||
/* ifam_data needs to be aligned */
|
||||
ift->ifa_data = data = (void *)ALIGN(data);
|
||||
memcpy(data, if_data, if_data->ifi_datalen);
|
||||
data += if_data->ifi_datalen;
|
||||
|
||||
ift = (ift->ifa_next = ift + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
if (--ift >= ifa) {
|
||||
ift->ifa_next = NULL;
|
||||
*pif = ifa;
|
||||
} else {
|
||||
*pif = NULL;
|
||||
free(ifa);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
freeifaddrs(struct ifaddrs *ifp)
|
||||
{
|
||||
|
||||
free(ifp);
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/* $KAME: if_nametoindex.c,v 1.6 2000/11/24 08:18:54 itojun Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 2000
|
||||
* Berkeley Software Design, Inc. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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.
|
||||
*
|
||||
* BSDI Id: if_nametoindex.c,v 2.3 2000/04/17 22:38:05 dab Exp
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "namespace.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#ifndef FSTACK
|
||||
#include "un-namespace.h"
|
||||
#endif
|
||||
|
||||
#ifdef FSTACK
|
||||
#include "compat.h"
|
||||
|
||||
#define _socket(a, b, c) 0
|
||||
#define _ioctl(a, b, c) ioctl((a), (b), (c))
|
||||
#define _close(s)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* From RFC 2553:
|
||||
*
|
||||
* 4.1 Name-to-Index
|
||||
*
|
||||
*
|
||||
* The first function maps an interface name into its corresponding
|
||||
* index.
|
||||
*
|
||||
* #include <net/if.h>
|
||||
*
|
||||
* unsigned int if_nametoindex(const char *ifname);
|
||||
*
|
||||
* If the specified interface name does not exist, the return value is
|
||||
* 0, and errno is set to ENXIO. If there was a system error (such as
|
||||
* running out of memory), the return value is 0 and errno is set to the
|
||||
* proper value (e.g., ENOMEM).
|
||||
*/
|
||||
|
||||
unsigned int
|
||||
if_nametoindex(const char *ifname)
|
||||
{
|
||||
int s;
|
||||
struct ifreq ifr;
|
||||
struct ifaddrs *ifaddrs, *ifa;
|
||||
unsigned int ni;
|
||||
|
||||
s = _socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (s != -1) {
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||
if (_ioctl(s, SIOCGIFINDEX, &ifr) != -1) {
|
||||
_close(s);
|
||||
return (ifr.ifr_index);
|
||||
}
|
||||
_close(s);
|
||||
}
|
||||
|
||||
if (getifaddrs(&ifaddrs) < 0)
|
||||
return(0);
|
||||
|
||||
ni = 0;
|
||||
|
||||
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr &&
|
||||
ifa->ifa_addr->sa_family == AF_LINK &&
|
||||
strcmp(ifa->ifa_name, ifname) == 0) {
|
||||
ni = LLINDEX((struct sockaddr_dl*)ifa->ifa_addr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(ifaddrs);
|
||||
if (!ni)
|
||||
errno = ENXIO;
|
||||
return(ni);
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* ++Copyright++ 1983, 1993
|
||||
* -
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
/*%
|
||||
* @(#)inet.h 8.1 (Berkeley) 6/2/93
|
||||
* $Id: inet.h,v 1.3 2005/04/27 04:56:16 sra Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_ARPA_INET_H_
|
||||
#define _COMPAT_ARPA_INET_H_
|
||||
|
||||
/* External definitions for functions in inet(3). */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/_types.h>
|
||||
|
||||
#define INET_ADDRSTRLEN 16
|
||||
#define INET6_ADDRSTRLEN 46
|
||||
|
||||
#ifndef _UINT16_T_DECLARED
|
||||
typedef __uint16_t uint16_t;
|
||||
#define _UINT16_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _UINT32_T_DECLARED
|
||||
typedef __uint32_t uint32_t;
|
||||
#define _UINT32_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _IN_ADDR_T_DECLARED
|
||||
typedef uint32_t in_addr_t;
|
||||
#define _IN_ADDR_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _IN_PORT_T_DECLARED
|
||||
typedef uint16_t in_port_t;
|
||||
#define _IN_PORT_T_DECLARED
|
||||
#endif
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
#ifndef _SIZE_T_DECLARED
|
||||
typedef __size_t size_t;
|
||||
#define _SIZE_T_DECLARED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXX socklen_t is used by a POSIX.1-2001 interface, but not required by
|
||||
* POSIX.1-2001.
|
||||
*/
|
||||
#ifndef _SOCKLEN_T_DECLARED
|
||||
typedef __socklen_t socklen_t;
|
||||
#define _SOCKLEN_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _STRUCT_IN_ADDR_DECLARED
|
||||
struct in_addr {
|
||||
in_addr_t s_addr;
|
||||
};
|
||||
#define _STRUCT_IN_ADDR_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _BYTEORDER_PROTOTYPED
|
||||
#define _BYTEORDER_PROTOTYPED
|
||||
extern uint32_t htonl(uint32_t);
|
||||
extern uint16_t htons(uint16_t);
|
||||
extern uint32_t ntohl(uint32_t);
|
||||
extern uint16_t ntohs(uint16_t);
|
||||
#endif
|
||||
|
||||
in_addr_t inet_addr(const char *);
|
||||
/*const*/ char *inet_ntoa(struct in_addr);
|
||||
const char *inet_ntop(int, const void * __restrict, char * __restrict,
|
||||
socklen_t);
|
||||
int inet_pton(int, const char * __restrict, void * __restrict);
|
||||
|
||||
int inet_aton(const char *, struct in_addr *);
|
||||
|
||||
#endif /* !_ARPA_INET_H_ */
|
||||
|
||||
/*! \file */
|
|
@ -0,0 +1,61 @@
|
|||
/* $FreeBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995, 1999
|
||||
* Berkeley Software Design, Inc. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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.
|
||||
*
|
||||
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_IFADDRS_H_
|
||||
#define _COMPAT_IFADDRS_H_
|
||||
|
||||
struct ifaddrs {
|
||||
struct ifaddrs *ifa_next;
|
||||
char *ifa_name;
|
||||
unsigned int ifa_flags;
|
||||
struct sockaddr *ifa_addr;
|
||||
struct sockaddr *ifa_netmask;
|
||||
struct sockaddr *ifa_dstaddr;
|
||||
void *ifa_data;
|
||||
};
|
||||
|
||||
/*
|
||||
* This may have been defined in <net/if.h>. Note that if <net/if.h> is
|
||||
* to be included it must be included before this header file.
|
||||
*/
|
||||
#ifndef ifa_broadaddr
|
||||
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
|
||||
#endif
|
||||
|
||||
struct ifmaddrs {
|
||||
struct ifmaddrs *ifma_next;
|
||||
struct sockaddr *ifma_name;
|
||||
struct sockaddr *ifma_addr;
|
||||
struct sockaddr *ifma_lladdr;
|
||||
};
|
||||
|
||||
extern int getifaddrs(struct ifaddrs **);
|
||||
extern void freeifaddrs(struct ifaddrs *);
|
||||
extern int getifmaddrs(struct ifmaddrs **);
|
||||
extern void freeifmaddrs(struct ifmaddrs *);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,392 @@
|
|||
/*
|
||||
* Fundamental constants relating to ethernet.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _NET_ETHERNET_H_
|
||||
#define _NET_ETHERNET_H_
|
||||
|
||||
/*
|
||||
* Some basic Ethernet constants.
|
||||
*/
|
||||
#define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
|
||||
#define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
|
||||
#define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */
|
||||
#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
|
||||
#define ETHER_MIN_LEN 64 /* minimum frame len, including CRC */
|
||||
#define ETHER_MAX_LEN 1518 /* maximum frame len, including CRC */
|
||||
#define ETHER_MAX_LEN_JUMBO 9018 /* max jumbo frame len, including CRC */
|
||||
|
||||
#define ETHER_VLAN_ENCAP_LEN 4 /* len of 802.1Q VLAN encapsulation */
|
||||
/*
|
||||
* Mbuf adjust factor to force 32-bit alignment of IP header.
|
||||
* Drivers should do m_adj(m, ETHER_ALIGN) when setting up a
|
||||
* receive so the upper layers get the IP header properly aligned
|
||||
* past the 14-byte Ethernet header.
|
||||
*/
|
||||
#define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */
|
||||
|
||||
/*
|
||||
* Compute the maximum frame size based on ethertype (i.e. possible
|
||||
* encapsulation) and whether or not an FCS is present.
|
||||
*/
|
||||
#define ETHER_MAX_FRAME(ifp, etype, hasfcs) \
|
||||
((ifp)->if_mtu + ETHER_HDR_LEN + \
|
||||
((hasfcs) ? ETHER_CRC_LEN : 0) + \
|
||||
(((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0))
|
||||
|
||||
/*
|
||||
* Ethernet-specific mbuf flags.
|
||||
*/
|
||||
#define M_HASFCS M_PROTO5 /* FCS included at end of frame */
|
||||
|
||||
/*
|
||||
* Ethernet CRC32 polynomials (big- and little-endian verions).
|
||||
*/
|
||||
#define ETHER_CRC_POLY_LE 0xedb88320
|
||||
#define ETHER_CRC_POLY_BE 0x04c11db6
|
||||
|
||||
/*
|
||||
* A macro to validate a length with
|
||||
*/
|
||||
#define ETHER_IS_VALID_LEN(foo) \
|
||||
((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
|
||||
|
||||
/*
|
||||
* Structure of a 10Mb/s Ethernet header.
|
||||
*/
|
||||
struct ether_header {
|
||||
u_char ether_dhost[ETHER_ADDR_LEN];
|
||||
u_char ether_shost[ETHER_ADDR_LEN];
|
||||
u_short ether_type;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
/*
|
||||
* Structure of a 48-bit Ethernet address.
|
||||
*/
|
||||
struct ether_addr {
|
||||
u_char octet[ETHER_ADDR_LEN];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
|
||||
|
||||
/*
|
||||
* 802.1q Virtual LAN header.
|
||||
*/
|
||||
struct ether_vlan_header {
|
||||
uint8_t evl_dhost[ETHER_ADDR_LEN];
|
||||
uint8_t evl_shost[ETHER_ADDR_LEN];
|
||||
uint16_t evl_encap_proto;
|
||||
uint16_t evl_tag;
|
||||
uint16_t evl_proto;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
#define EVL_VLID_MASK 0x0FFF
|
||||
#define EVL_PRI_MASK 0xE000
|
||||
#define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK)
|
||||
#define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7)
|
||||
#define EVL_CFIOFTAG(tag) (((tag) >> 12) & 1)
|
||||
#define EVL_MAKETAG(vlid, pri, cfi) \
|
||||
((((((pri) & 7) << 1) | ((cfi) & 1)) << 12) | ((vlid) & EVL_VLID_MASK))
|
||||
|
||||
/*
|
||||
* NOTE: 0x0000-0x05DC (0..1500) are generally IEEE 802.3 length fields.
|
||||
* However, there are some conflicts.
|
||||
*/
|
||||
|
||||
#define ETHERTYPE_8023 0x0004 /* IEEE 802.3 packet */
|
||||
/* 0x0101 .. 0x1FF Experimental */
|
||||
#define ETHERTYPE_PUP 0x0200 /* Xerox PUP protocol - see 0A00 */
|
||||
#define ETHERTYPE_PUPAT 0x0200 /* PUP Address Translation - see 0A01 */
|
||||
#define ETHERTYPE_SPRITE 0x0500 /* ??? */
|
||||
/* 0x0400 Nixdorf */
|
||||
#define ETHERTYPE_NS 0x0600 /* XNS */
|
||||
#define ETHERTYPE_NSAT 0x0601 /* XNS Address Translation (3Mb only) */
|
||||
#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */
|
||||
#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */
|
||||
#define ETHERTYPE_IP 0x0800 /* IP protocol */
|
||||
#define ETHERTYPE_X75 0x0801 /* X.75 Internet */
|
||||
#define ETHERTYPE_NBS 0x0802 /* NBS Internet */
|
||||
#define ETHERTYPE_ECMA 0x0803 /* ECMA Internet */
|
||||
#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */
|
||||
#define ETHERTYPE_X25 0x0805 /* X.25 Level 3 */
|
||||
#define ETHERTYPE_ARP 0x0806 /* Address resolution protocol */
|
||||
#define ETHERTYPE_NSCOMPAT 0x0807 /* XNS Compatibility */
|
||||
#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */
|
||||
/* 0x081C Symbolics Private */
|
||||
/* 0x0888 - 0x088A Xyplex */
|
||||
#define ETHERTYPE_UBDEBUG 0x0900 /* Ungermann-Bass network debugger */
|
||||
#define ETHERTYPE_IEEEPUP 0x0A00 /* Xerox IEEE802.3 PUP */
|
||||
#define ETHERTYPE_IEEEPUPAT 0x0A01 /* Xerox IEEE802.3 PUP Address Translation */
|
||||
#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */
|
||||
#define ETHERTYPE_VINESLOOP 0x0BAE /* Banyan VINES Loopback */
|
||||
#define ETHERTYPE_VINESECHO 0x0BAF /* Banyan VINES Echo */
|
||||
|
||||
/* 0x1000 - 0x100F Berkeley Trailer */
|
||||
/*
|
||||
* The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
|
||||
* (type-ETHERTYPE_TRAIL)*512 bytes of data followed
|
||||
* by an ETHER type (as given above) and then the (variable-length) header.
|
||||
*/
|
||||
#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
|
||||
#define ETHERTYPE_NTRAILER 16
|
||||
|
||||
#define ETHERTYPE_DCA 0x1234 /* DCA - Multicast */
|
||||
#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */
|
||||
#define ETHERTYPE_DOGFIGHT 0x1989 /* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */
|
||||
#define ETHERTYPE_RCL 0x1995 /* Datapoint Corporation (RCL lan protocol) */
|
||||
|
||||
/* The following 3C0x types
|
||||
are unregistered: */
|
||||
#define ETHERTYPE_NBPVCD 0x3C00 /* 3Com NBP virtual circuit datagram (like XNS SPP) not registered */
|
||||
#define ETHERTYPE_NBPSCD 0x3C01 /* 3Com NBP System control datagram not registered */
|
||||
#define ETHERTYPE_NBPCREQ 0x3C02 /* 3Com NBP Connect request (virtual cct) not registered */
|
||||
#define ETHERTYPE_NBPCRSP 0x3C03 /* 3Com NBP Connect response not registered */
|
||||
#define ETHERTYPE_NBPCC 0x3C04 /* 3Com NBP Connect complete not registered */
|
||||
#define ETHERTYPE_NBPCLREQ 0x3C05 /* 3Com NBP Close request (virtual cct) not registered */
|
||||
#define ETHERTYPE_NBPCLRSP 0x3C06 /* 3Com NBP Close response not registered */
|
||||
#define ETHERTYPE_NBPDG 0x3C07 /* 3Com NBP Datagram (like XNS IDP) not registered */
|
||||
#define ETHERTYPE_NBPDGB 0x3C08 /* 3Com NBP Datagram broadcast not registered */
|
||||
#define ETHERTYPE_NBPCLAIM 0x3C09 /* 3Com NBP Claim NetBIOS name not registered */
|
||||
#define ETHERTYPE_NBPDLTE 0x3C0A /* 3Com NBP Delete NetBIOS name not registered */
|
||||
#define ETHERTYPE_NBPRAS 0x3C0B /* 3Com NBP Remote adaptor status request not registered */
|
||||
#define ETHERTYPE_NBPRAR 0x3C0C /* 3Com NBP Remote adaptor response not registered */
|
||||
#define ETHERTYPE_NBPRST 0x3C0D /* 3Com NBP Reset not registered */
|
||||
|
||||
#define ETHERTYPE_PCS 0x4242 /* PCS Basic Block Protocol */
|
||||
#define ETHERTYPE_IMLBLDIAG 0x424C /* Information Modes Little Big LAN diagnostic */
|
||||
#define ETHERTYPE_DIDDLE 0x4321 /* THD - Diddle */
|
||||
#define ETHERTYPE_IMLBL 0x4C42 /* Information Modes Little Big LAN */
|
||||
#define ETHERTYPE_SIMNET 0x5208 /* BBN Simnet Private */
|
||||
#define ETHERTYPE_DECEXPER 0x6000 /* DEC Unassigned, experimental */
|
||||
#define ETHERTYPE_MOPDL 0x6001 /* DEC MOP dump/load */
|
||||
#define ETHERTYPE_MOPRC 0x6002 /* DEC MOP remote console */
|
||||
#define ETHERTYPE_DECnet 0x6003 /* DEC DECNET Phase IV route */
|
||||
#define ETHERTYPE_DN ETHERTYPE_DECnet /* libpcap, tcpdump */
|
||||
#define ETHERTYPE_LAT 0x6004 /* DEC LAT */
|
||||
#define ETHERTYPE_DECDIAG 0x6005 /* DEC diagnostic protocol (at interface initialization?) */
|
||||
#define ETHERTYPE_DECCUST 0x6006 /* DEC customer protocol */
|
||||
#define ETHERTYPE_SCA 0x6007 /* DEC LAVC, SCA */
|
||||
#define ETHERTYPE_AMBER 0x6008 /* DEC AMBER */
|
||||
#define ETHERTYPE_DECMUMPS 0x6009 /* DEC MUMPS */
|
||||
/* 0x6010 - 0x6014 3Com Corporation */
|
||||
#define ETHERTYPE_TRANSETHER 0x6558 /* Trans Ether Bridging (RFC1701)*/
|
||||
#define ETHERTYPE_RAWFR 0x6559 /* Raw Frame Relay (RFC1701) */
|
||||
#define ETHERTYPE_UBDL 0x7000 /* Ungermann-Bass download */
|
||||
#define ETHERTYPE_UBNIU 0x7001 /* Ungermann-Bass NIUs */
|
||||
#define ETHERTYPE_UBDIAGLOOP 0x7002 /* Ungermann-Bass diagnostic/loopback */
|
||||
#define ETHERTYPE_UBNMC 0x7003 /* Ungermann-Bass ??? (NMC to/from UB Bridge) */
|
||||
#define ETHERTYPE_UBBST 0x7005 /* Ungermann-Bass Bridge Spanning Tree */
|
||||
#define ETHERTYPE_OS9 0x7007 /* OS/9 Microware */
|
||||
#define ETHERTYPE_OS9NET 0x7009 /* OS/9 Net? */
|
||||
/* 0x7020 - 0x7029 LRT (England) (now Sintrom) */
|
||||
#define ETHERTYPE_RACAL 0x7030 /* Racal-Interlan */
|
||||
#define ETHERTYPE_PRIMENTS 0x7031 /* Prime NTS (Network Terminal Service) */
|
||||
#define ETHERTYPE_CABLETRON 0x7034 /* Cabletron */
|
||||
#define ETHERTYPE_CRONUSVLN 0x8003 /* Cronus VLN */
|
||||
#define ETHERTYPE_CRONUS 0x8004 /* Cronus Direct */
|
||||
#define ETHERTYPE_HP 0x8005 /* HP Probe */
|
||||
#define ETHERTYPE_NESTAR 0x8006 /* Nestar */
|
||||
#define ETHERTYPE_ATTSTANFORD 0x8008 /* AT&T/Stanford (local use) */
|
||||
#define ETHERTYPE_EXCELAN 0x8010 /* Excelan */
|
||||
#define ETHERTYPE_SG_DIAG 0x8013 /* SGI diagnostic type */
|
||||
#define ETHERTYPE_SG_NETGAMES 0x8014 /* SGI network games */
|
||||
#define ETHERTYPE_SG_RESV 0x8015 /* SGI reserved type */
|
||||
#define ETHERTYPE_SG_BOUNCE 0x8016 /* SGI bounce server */
|
||||
#define ETHERTYPE_APOLLODOMAIN 0x8019 /* Apollo DOMAIN */
|
||||
#define ETHERTYPE_TYMSHARE 0x802E /* Tymeshare */
|
||||
#define ETHERTYPE_TIGAN 0x802F /* Tigan, Inc. */
|
||||
#define ETHERTYPE_REVARP 0x8035 /* Reverse addr resolution protocol */
|
||||
#define ETHERTYPE_AEONIC 0x8036 /* Aeonic Systems */
|
||||
#define ETHERTYPE_IPXNEW 0x8037 /* IPX (Novell Netware?) */
|
||||
#define ETHERTYPE_LANBRIDGE 0x8038 /* DEC LANBridge */
|
||||
#define ETHERTYPE_DSMD 0x8039 /* DEC DSM/DDP */
|
||||
#define ETHERTYPE_ARGONAUT 0x803A /* DEC Argonaut Console */
|
||||
#define ETHERTYPE_VAXELN 0x803B /* DEC VAXELN */
|
||||
#define ETHERTYPE_DECDNS 0x803C /* DEC DNS Naming Service */
|
||||
#define ETHERTYPE_ENCRYPT 0x803D /* DEC Ethernet Encryption */
|
||||
#define ETHERTYPE_DECDTS 0x803E /* DEC Distributed Time Service */
|
||||
#define ETHERTYPE_DECLTM 0x803F /* DEC LAN Traffic Monitor */
|
||||
#define ETHERTYPE_DECNETBIOS 0x8040 /* DEC PATHWORKS DECnet NETBIOS Emulation */
|
||||
#define ETHERTYPE_DECLAST 0x8041 /* DEC Local Area System Transport */
|
||||
/* 0x8042 DEC Unassigned */
|
||||
#define ETHERTYPE_PLANNING 0x8044 /* Planning Research Corp. */
|
||||
/* 0x8046 - 0x8047 AT&T */
|
||||
#define ETHERTYPE_DECAM 0x8048 /* DEC Availability Manager for Distributed Systems DECamds (but someone at DEC says not) */
|
||||
#define ETHERTYPE_EXPERDATA 0x8049 /* ExperData */
|
||||
#define ETHERTYPE_VEXP 0x805B /* Stanford V Kernel exp. */
|
||||
#define ETHERTYPE_VPROD 0x805C /* Stanford V Kernel prod. */
|
||||
#define ETHERTYPE_ES 0x805D /* Evans & Sutherland */
|
||||
#define ETHERTYPE_LITTLE 0x8060 /* Little Machines */
|
||||
#define ETHERTYPE_COUNTERPOINT 0x8062 /* Counterpoint Computers */
|
||||
/* 0x8065 - 0x8066 Univ. of Mass @ Amherst */
|
||||
#define ETHERTYPE_VEECO 0x8067 /* Veeco Integrated Auto. */
|
||||
#define ETHERTYPE_GENDYN 0x8068 /* General Dynamics */
|
||||
#define ETHERTYPE_ATT 0x8069 /* AT&T */
|
||||
#define ETHERTYPE_AUTOPHON 0x806A /* Autophon */
|
||||
#define ETHERTYPE_COMDESIGN 0x806C /* ComDesign */
|
||||
#define ETHERTYPE_COMPUGRAPHIC 0x806D /* Compugraphic Corporation */
|
||||
/* 0x806E - 0x8077 Landmark Graphics Corp. */
|
||||
#define ETHERTYPE_MATRA 0x807A /* Matra */
|
||||
#define ETHERTYPE_DDE 0x807B /* Dansk Data Elektronik */
|
||||
#define ETHERTYPE_MERIT 0x807C /* Merit Internodal (or Univ of Michigan?) */
|
||||
/* 0x807D - 0x807F Vitalink Communications */
|
||||
#define ETHERTYPE_VLTLMAN 0x8080 /* Vitalink TransLAN III Management */
|
||||
/* 0x8081 - 0x8083 Counterpoint Computers */
|
||||
/* 0x8088 - 0x808A Xyplex */
|
||||
#define ETHERTYPE_ATALK 0x809B /* AppleTalk */
|
||||
#define ETHERTYPE_AT ETHERTYPE_ATALK /* old NetBSD */
|
||||
#define ETHERTYPE_APPLETALK ETHERTYPE_ATALK /* HP-UX */
|
||||
/* 0x809C - 0x809E Datability */
|
||||
#define ETHERTYPE_SPIDER 0x809F /* Spider Systems Ltd. */
|
||||
/* 0x80A3 Nixdorf */
|
||||
/* 0x80A4 - 0x80B3 Siemens Gammasonics Inc. */
|
||||
/* 0x80C0 - 0x80C3 DCA (Digital Comm. Assoc.) Data Exchange Cluster */
|
||||
/* 0x80C4 - 0x80C5 Banyan Systems */
|
||||
#define ETHERTYPE_PACER 0x80C6 /* Pacer Software */
|
||||
#define ETHERTYPE_APPLITEK 0x80C7 /* Applitek Corporation */
|
||||
/* 0x80C8 - 0x80CC Intergraph Corporation */
|
||||
/* 0x80CD - 0x80CE Harris Corporation */
|
||||
/* 0x80CF - 0x80D2 Taylor Instrument */
|
||||
/* 0x80D3 - 0x80D4 Rosemount Corporation */
|
||||
#define ETHERTYPE_SNA 0x80D5 /* IBM SNA Services over Ethernet */
|
||||
#define ETHERTYPE_VARIAN 0x80DD /* Varian Associates */
|
||||
/* 0x80DE - 0x80DF TRFS (Integrated Solutions Transparent Remote File System) */
|
||||
/* 0x80E0 - 0x80E3 Allen-Bradley */
|
||||
/* 0x80E4 - 0x80F0 Datability */
|
||||
#define ETHERTYPE_RETIX 0x80F2 /* Retix */
|
||||
#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */
|
||||
/* 0x80F4 - 0x80F5 Kinetics */
|
||||
#define ETHERTYPE_APOLLO 0x80F7 /* Apollo Computer */
|
||||
#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging (XXX conflicts) */
|
||||
/* 0x80FF - 0x8101 Wellfleet Communications (XXX conflicts) */
|
||||
#define ETHERTYPE_BOFL 0x8102 /* Wellfleet; BOFL (Breath OF Life) pkts [every 5-10 secs.] */
|
||||
#define ETHERTYPE_WELLFLEET 0x8103 /* Wellfleet Communications */
|
||||
/* 0x8107 - 0x8109 Symbolics Private */
|
||||
#define ETHERTYPE_TALARIS 0x812B /* Talaris */
|
||||
#define ETHERTYPE_WATERLOO 0x8130 /* Waterloo Microsystems Inc. (XXX which?) */
|
||||
#define ETHERTYPE_HAYES 0x8130 /* Hayes Microcomputers (XXX which?) */
|
||||
#define ETHERTYPE_VGLAB 0x8131 /* VG Laboratory Systems */
|
||||
/* 0x8132 - 0x8137 Bridge Communications */
|
||||
#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */
|
||||
#define ETHERTYPE_NOVELL 0x8138 /* Novell, Inc. */
|
||||
/* 0x8139 - 0x813D KTI */
|
||||
#define ETHERTYPE_MUMPS 0x813F /* M/MUMPS data sharing */
|
||||
#define ETHERTYPE_AMOEBA 0x8145 /* Vrije Universiteit (NL) Amoeba 4 RPC (obsolete) */
|
||||
#define ETHERTYPE_FLIP 0x8146 /* Vrije Universiteit (NL) FLIP (Fast Local Internet Protocol) */
|
||||
#define ETHERTYPE_VURESERVED 0x8147 /* Vrije Universiteit (NL) [reserved] */
|
||||
#define ETHERTYPE_LOGICRAFT 0x8148 /* Logicraft */
|
||||
#define ETHERTYPE_NCD 0x8149 /* Network Computing Devices */
|
||||
#define ETHERTYPE_ALPHA 0x814A /* Alpha Micro */
|
||||
#define ETHERTYPE_SNMP 0x814C /* SNMP over Ethernet (see RFC1089) */
|
||||
/* 0x814D - 0x814E BIIN */
|
||||
#define ETHERTYPE_TEC 0x814F /* Technically Elite Concepts */
|
||||
#define ETHERTYPE_RATIONAL 0x8150 /* Rational Corp */
|
||||
/* 0x8151 - 0x8153 Qualcomm */
|
||||
/* 0x815C - 0x815E Computer Protocol Pty Ltd */
|
||||
/* 0x8164 - 0x8166 Charles River Data Systems */
|
||||
#define ETHERTYPE_XTP 0x817D /* Protocol Engines XTP */
|
||||
#define ETHERTYPE_SGITW 0x817E /* SGI/Time Warner prop. */
|
||||
#define ETHERTYPE_HIPPI_FP 0x8180 /* HIPPI-FP encapsulation */
|
||||
#define ETHERTYPE_STP 0x8181 /* Scheduled Transfer STP, HIPPI-ST */
|
||||
/* 0x8182 - 0x8183 Reserved for HIPPI-6400 */
|
||||
/* 0x8184 - 0x818C SGI prop. */
|
||||
#define ETHERTYPE_MOTOROLA 0x818D /* Motorola */
|
||||
#define ETHERTYPE_NETBEUI 0x8191 /* PowerLAN NetBIOS/NetBEUI (PC) */
|
||||
/* 0x819A - 0x81A3 RAD Network Devices */
|
||||
/* 0x81B7 - 0x81B9 Xyplex */
|
||||
/* 0x81CC - 0x81D5 Apricot Computers */
|
||||
/* 0x81D6 - 0x81DD Artisoft Lantastic */
|
||||
/* 0x81E6 - 0x81EF Polygon */
|
||||
/* 0x81F0 - 0x81F2 Comsat Labs */
|
||||
/* 0x81F3 - 0x81F5 SAIC */
|
||||
/* 0x81F6 - 0x81F8 VG Analytical */
|
||||
/* 0x8203 - 0x8205 QNX Software Systems Ltd. */
|
||||
/* 0x8221 - 0x8222 Ascom Banking Systems */
|
||||
/* 0x823E - 0x8240 Advanced Encryption Systems */
|
||||
/* 0x8263 - 0x826A Charles River Data Systems */
|
||||
/* 0x827F - 0x8282 Athena Programming */
|
||||
/* 0x829A - 0x829B Inst Ind Info Tech */
|
||||
/* 0x829C - 0x82AB Taurus Controls */
|
||||
/* 0x82AC - 0x8693 Walker Richer & Quinn */
|
||||
#define ETHERTYPE_ACCTON 0x8390 /* Accton Technologies (unregistered) */
|
||||
#define ETHERTYPE_TALARISMC 0x852B /* Talaris multicast */
|
||||
#define ETHERTYPE_KALPANA 0x8582 /* Kalpana */
|
||||
/* 0x8694 - 0x869D Idea Courier */
|
||||
/* 0x869E - 0x86A1 Computer Network Tech */
|
||||
/* 0x86A3 - 0x86AC Gateway Communications */
|
||||
#define ETHERTYPE_SECTRA 0x86DB /* SECTRA */
|
||||
#define ETHERTYPE_IPV6 0x86DD /* IP protocol version 6 */
|
||||
#define ETHERTYPE_DELTACON 0x86DE /* Delta Controls */
|
||||
#define ETHERTYPE_ATOMIC 0x86DF /* ATOMIC */
|
||||
/* 0x86E0 - 0x86EF Landis & Gyr Powers */
|
||||
/* 0x8700 - 0x8710 Motorola */
|
||||
#define ETHERTYPE_RDP 0x8739 /* Control Technology Inc. RDP Without IP */
|
||||
#define ETHERTYPE_MICP 0x873A /* Control Technology Inc. Mcast Industrial Ctrl Proto. */
|
||||
/* 0x873B - 0x873C Control Technology Inc. Proprietary */
|
||||
#define ETHERTYPE_TCPCOMP 0x876B /* TCP/IP Compression (RFC1701) */
|
||||
#define ETHERTYPE_IPAS 0x876C /* IP Autonomous Systems (RFC1701) */
|
||||
#define ETHERTYPE_SECUREDATA 0x876D /* Secure Data (RFC1701) */
|
||||
#define ETHERTYPE_FLOWCONTROL 0x8808 /* 802.3x flow control packet */
|
||||
#define ETHERTYPE_SLOW 0x8809 /* 802.3ad link aggregation (LACP) */
|
||||
#define ETHERTYPE_PPP 0x880B /* PPP (obsolete by PPPoE) */
|
||||
#define ETHERTYPE_HITACHI 0x8820 /* Hitachi Cable (Optoelectronic Systems Laboratory) */
|
||||
#define ETHERTYPE_TEST 0x8822 /* Network Conformance Testing */
|
||||
#define ETHERTYPE_MPLS 0x8847 /* MPLS Unicast */
|
||||
#define ETHERTYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */
|
||||
#define ETHERTYPE_AXIS 0x8856 /* Axis Communications AB proprietary bootstrap/config */
|
||||
#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
|
||||
#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
|
||||
#define ETHERTYPE_LANPROBE 0x8888 /* HP LanProbe test? */
|
||||
#define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */
|
||||
#define ETHERTYPE_LOOPBACK 0x9000 /* Loopback: used to test interfaces */
|
||||
#define ETHERTYPE_LBACK ETHERTYPE_LOOPBACK /* DEC MOP loopback */
|
||||
#define ETHERTYPE_XNSSM 0x9001 /* 3Com (Formerly Bridge Communications), XNS Systems Management */
|
||||
#define ETHERTYPE_TCPSM 0x9002 /* 3Com (Formerly Bridge Communications), TCP/IP Systems Management */
|
||||
#define ETHERTYPE_BCLOOP 0x9003 /* 3Com (Formerly Bridge Communications), loopback detection */
|
||||
#define ETHERTYPE_DEBNI 0xAAAA /* DECNET? Used by VAX 6220 DEBNI */
|
||||
#define ETHERTYPE_SONIX 0xFAF5 /* Sonix Arpeggio */
|
||||
#define ETHERTYPE_VITAL 0xFF00 /* BBN VITAL-LanBridge cache wakeups */
|
||||
/* 0xFF00 - 0xFFOF ISC Bunker Ramo */
|
||||
|
||||
#define ETHERTYPE_MAX 0xFFFF /* Maximum valid ethernet type, reserved */
|
||||
|
||||
/*
|
||||
* The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
|
||||
* (type-ETHERTYPE_TRAIL)*512 bytes of data followed
|
||||
* by an ETHER type (as given above) and then the (variable-length) header.
|
||||
*/
|
||||
#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
|
||||
#define ETHERTYPE_NTRAILER 16
|
||||
|
||||
#define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
|
||||
#define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
|
||||
#define ETHERMTU_JUMBO (ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
|
||||
/*
|
||||
* The ETHER_BPF_MTAP macro should be used by drivers which support hardware
|
||||
* offload for VLAN tag processing. It will check the mbuf to see if it has
|
||||
* M_VLANTAG set, and if it does, will pass the packet along to
|
||||
* ether_vlan_mtap. This function will re-insert VLAN tags for the duration
|
||||
* of the tap, so they show up properly for network analyzers.
|
||||
*/
|
||||
#define ETHER_BPF_MTAP(_ifp, _m) do { \
|
||||
if (bpf_peers_present((_ifp)->if_bpf)) { \
|
||||
M_ASSERTVALID(_m); \
|
||||
if (((_m)->m_flags & M_VLANTAG) != 0) \
|
||||
ether_vlan_mtap((_ifp)->if_bpf, (_m), NULL, 0); \
|
||||
else \
|
||||
bpf_mtap((_ifp)->if_bpf, (_m)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
struct ether_addr *ether_aton(const char *);
|
||||
struct ether_addr *ether_aton_r(const char *, struct ether_addr *);
|
||||
int ether_hostton(const char *, struct ether_addr *);
|
||||
int ether_line(const char *, struct ether_addr *, char *);
|
||||
char *ether_ntoa(const struct ether_addr *);
|
||||
char *ether_ntoa_r(const struct ether_addr *, char *);
|
||||
int ether_ntohost(char *, const struct ether_addr *);
|
||||
|
||||
#endif /* !_NET_ETHERNET_H_ */
|
|
@ -0,0 +1,524 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)if.h 8.1 (Berkeley) 6/10/93
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_H_
|
||||
#define _NET_IF_H_
|
||||
|
||||
#include <sys/time.h>
|
||||
#include "sys/socket.h"
|
||||
|
||||
/*
|
||||
* Length of interface external name, including terminating '\0'.
|
||||
* Note: this is the same size as a generic device's external name.
|
||||
*/
|
||||
#define IF_NAMESIZE 16
|
||||
#define IFNAMSIZ IF_NAMESIZE
|
||||
#define IF_MAXUNIT 0x7fff /* historical value */
|
||||
|
||||
/*
|
||||
* Structure used to query names of interface cloners.
|
||||
*/
|
||||
|
||||
struct if_clonereq {
|
||||
int ifcr_total; /* total cloners (out) */
|
||||
int ifcr_count; /* room for this many in user buffer */
|
||||
char *ifcr_buffer; /* buffer for cloner names */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure describing information about an interface
|
||||
* which may be of interest to management entities.
|
||||
*/
|
||||
struct if_data {
|
||||
/* generic interface information */
|
||||
uint8_t ifi_type; /* ethernet, tokenring, etc */
|
||||
uint8_t ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
|
||||
uint8_t ifi_addrlen; /* media address length */
|
||||
uint8_t ifi_hdrlen; /* media header length */
|
||||
uint8_t ifi_link_state; /* current link state */
|
||||
uint8_t ifi_vhid; /* carp vhid */
|
||||
uint16_t ifi_datalen; /* length of this data struct */
|
||||
uint32_t ifi_mtu; /* maximum transmission unit */
|
||||
uint32_t ifi_metric; /* routing metric (external only) */
|
||||
uint64_t ifi_baudrate; /* linespeed */
|
||||
/* volatile statistics */
|
||||
uint64_t ifi_ipackets; /* packets received on interface */
|
||||
uint64_t ifi_ierrors; /* input errors on interface */
|
||||
uint64_t ifi_opackets; /* packets sent on interface */
|
||||
uint64_t ifi_oerrors; /* output errors on interface */
|
||||
uint64_t ifi_collisions; /* collisions on csma interfaces */
|
||||
uint64_t ifi_ibytes; /* total number of octets received */
|
||||
uint64_t ifi_obytes; /* total number of octets sent */
|
||||
uint64_t ifi_imcasts; /* packets received via multicast */
|
||||
uint64_t ifi_omcasts; /* packets sent via multicast */
|
||||
uint64_t ifi_iqdrops; /* dropped on input */
|
||||
uint64_t ifi_oqdrops; /* dropped on output */
|
||||
uint64_t ifi_noproto; /* destined for unsupported protocol */
|
||||
uint64_t ifi_hwassist; /* HW offload capabilities, see IFCAP */
|
||||
|
||||
/* Unions are here to make sizes MI. */
|
||||
union { /* uptime at attach or stat reset */
|
||||
time_t tt;
|
||||
uint64_t ph;
|
||||
} __ifi_epoch;
|
||||
#define ifi_epoch __ifi_epoch.tt
|
||||
union { /* time of last administrative change */
|
||||
struct timeval tv;
|
||||
struct {
|
||||
uint64_t ph1;
|
||||
uint64_t ph2;
|
||||
} ph;
|
||||
} __ifi_lastchange;
|
||||
#define ifi_lastchange __ifi_lastchange.tv
|
||||
};
|
||||
|
||||
/*-
|
||||
* Interface flags are of two types: network stack owned flags, and driver
|
||||
* owned flags. Historically, these values were stored in the same ifnet
|
||||
* flags field, but with the advent of fine-grained locking, they have been
|
||||
* broken out such that the network stack is responsible for synchronizing
|
||||
* the stack-owned fields, and the device driver the device-owned fields.
|
||||
* Both halves can perform lockless reads of the other half's field, subject
|
||||
* to accepting the involved races.
|
||||
*
|
||||
* Both sets of flags come from the same number space, and should not be
|
||||
* permitted to conflict, as they are exposed to user space via a single
|
||||
* field.
|
||||
*
|
||||
* The following symbols identify read and write requirements for fields:
|
||||
*
|
||||
* (i) if_flags field set by device driver before attach, read-only there
|
||||
* after.
|
||||
* (n) if_flags field written only by the network stack, read by either the
|
||||
* stack or driver.
|
||||
* (d) if_drv_flags field written only by the device driver, read by either
|
||||
* the stack or driver.
|
||||
*/
|
||||
#define IFF_UP 0x1 /* (n) interface is up */
|
||||
#define IFF_BROADCAST 0x2 /* (i) broadcast address valid */
|
||||
#define IFF_DEBUG 0x4 /* (n) turn on debugging */
|
||||
#define IFF_LOOPBACK 0x8 /* (i) is a loopback net */
|
||||
#define IFF_POINTOPOINT 0x10 /* (i) is a point-to-point link */
|
||||
/* 0x20 was IFF_SMART */
|
||||
#define IFF_DRV_RUNNING 0x40 /* (d) resources allocated */
|
||||
#define IFF_NOARP 0x80 /* (n) no address resolution protocol */
|
||||
#define IFF_PROMISC 0x100 /* (n) receive all packets */
|
||||
#define IFF_ALLMULTI 0x200 /* (n) receive all multicast packets */
|
||||
#define IFF_DRV_OACTIVE 0x400 /* (d) tx hardware queue is full */
|
||||
#define IFF_SIMPLEX 0x800 /* (i) can't hear own transmissions */
|
||||
#define IFF_LINK0 0x1000 /* per link layer defined bit */
|
||||
#define IFF_LINK1 0x2000 /* per link layer defined bit */
|
||||
#define IFF_LINK2 0x4000 /* per link layer defined bit */
|
||||
#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
|
||||
#define IFF_MULTICAST 0x8000 /* (i) supports multicast */
|
||||
#define IFF_CANTCONFIG 0x10000 /* (i) unconfigurable using ioctl(2) */
|
||||
#define IFF_PPROMISC 0x20000 /* (n) user-requested promisc mode */
|
||||
#define IFF_MONITOR 0x40000 /* (n) user-requested monitor mode */
|
||||
#define IFF_STATICARP 0x80000 /* (n) static ARP */
|
||||
#define IFF_DYING 0x200000 /* (n) interface is winding down */
|
||||
#define IFF_RENAMING 0x400000 /* (n) interface is being renamed */
|
||||
/*
|
||||
* Old names for driver flags so that user space tools can continue to use
|
||||
* the old (portable) names.
|
||||
*/
|
||||
#ifndef _KERNEL
|
||||
#define IFF_RUNNING IFF_DRV_RUNNING
|
||||
#define IFF_OACTIVE IFF_DRV_OACTIVE
|
||||
#endif
|
||||
|
||||
/* flags set internally only: */
|
||||
#define IFF_CANTCHANGE \
|
||||
(IFF_BROADCAST|IFF_POINTOPOINT|IFF_DRV_RUNNING|IFF_DRV_OACTIVE|\
|
||||
IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC|\
|
||||
IFF_DYING|IFF_CANTCONFIG)
|
||||
|
||||
/*
|
||||
* Values for if_link_state.
|
||||
*/
|
||||
#define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
|
||||
#define LINK_STATE_DOWN 1 /* link is down */
|
||||
#define LINK_STATE_UP 2 /* link is up */
|
||||
|
||||
/*
|
||||
* Some convenience macros used for setting ifi_baudrate.
|
||||
* XXX 1000 vs. 1024? --thorpej@netbsd.org
|
||||
*/
|
||||
#define IF_Kbps(x) ((uintmax_t)(x) * 1000) /* kilobits/sec. */
|
||||
#define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */
|
||||
#define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */
|
||||
|
||||
/*
|
||||
* Capabilities that interfaces can advertise.
|
||||
*
|
||||
* struct ifnet.if_capabilities
|
||||
* contains the optional features & capabilities a particular interface
|
||||
* supports (not only the driver but also the detected hw revision).
|
||||
* Capabilities are defined by IFCAP_* below.
|
||||
* struct ifnet.if_capenable
|
||||
* contains the enabled (either by default or through ifconfig) optional
|
||||
* features & capabilities on this interface.
|
||||
* Capabilities are defined by IFCAP_* below.
|
||||
* struct if_data.ifi_hwassist in mbuf CSUM_ flag form, controlled by above
|
||||
* contains the enabled optional feature & capabilites that can be used
|
||||
* individually per packet and are specified in the mbuf pkthdr.csum_flags
|
||||
* field. IFCAP_* and CSUM_* do not match one to one and CSUM_* may be
|
||||
* more detailed or differenciated than IFCAP_*.
|
||||
* Hwassist features are defined CSUM_* in sys/mbuf.h
|
||||
*
|
||||
* Capabilities that cannot be arbitrarily changed with ifconfig/ioctl
|
||||
* are listed in IFCAP_CANTCHANGE, similar to IFF_CANTCHANGE.
|
||||
* This is not strictly necessary because the common code never
|
||||
* changes capabilities, and it is left to the individual driver
|
||||
* to do the right thing. However, having the filter here
|
||||
* avoids replication of the same code in all individual drivers.
|
||||
*/
|
||||
#define IFCAP_RXCSUM 0x00001 /* can offload checksum on RX */
|
||||
#define IFCAP_TXCSUM 0x00002 /* can offload checksum on TX */
|
||||
#define IFCAP_NETCONS 0x00004 /* can be a network console */
|
||||
#define IFCAP_VLAN_MTU 0x00008 /* VLAN-compatible MTU */
|
||||
#define IFCAP_VLAN_HWTAGGING 0x00010 /* hardware VLAN tag support */
|
||||
#define IFCAP_JUMBO_MTU 0x00020 /* 9000 byte MTU supported */
|
||||
#define IFCAP_POLLING 0x00040 /* driver supports polling */
|
||||
#define IFCAP_VLAN_HWCSUM 0x00080 /* can do IFCAP_HWCSUM on VLANs */
|
||||
#define IFCAP_TSO4 0x00100 /* can do TCP Segmentation Offload */
|
||||
#define IFCAP_TSO6 0x00200 /* can do TCP6 Segmentation Offload */
|
||||
#define IFCAP_LRO 0x00400 /* can do Large Receive Offload */
|
||||
#define IFCAP_WOL_UCAST 0x00800 /* wake on any unicast frame */
|
||||
#define IFCAP_WOL_MCAST 0x01000 /* wake on any multicast frame */
|
||||
#define IFCAP_WOL_MAGIC 0x02000 /* wake on any Magic Packet */
|
||||
#define IFCAP_TOE4 0x04000 /* interface can offload TCP */
|
||||
#define IFCAP_TOE6 0x08000 /* interface can offload TCP6 */
|
||||
#define IFCAP_VLAN_HWFILTER 0x10000 /* interface hw can filter vlan tag */
|
||||
#define IFCAP_POLLING_NOCOUNT 0x20000 /* polling ticks cannot be fragmented */
|
||||
#define IFCAP_VLAN_HWTSO 0x40000 /* can do IFCAP_TSO on VLANs */
|
||||
#define IFCAP_LINKSTATE 0x80000 /* the runtime link state is dynamic */
|
||||
#define IFCAP_NETMAP 0x100000 /* netmap mode supported/enabled */
|
||||
#define IFCAP_RXCSUM_IPV6 0x200000 /* can offload checksum on IPv6 RX */
|
||||
#define IFCAP_TXCSUM_IPV6 0x400000 /* can offload checksum on IPv6 TX */
|
||||
#define IFCAP_HWSTATS 0x800000 /* manages counters internally */
|
||||
|
||||
#define IFCAP_HWCSUM_IPV6 (IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6)
|
||||
|
||||
#define IFCAP_HWCSUM (IFCAP_RXCSUM | IFCAP_TXCSUM)
|
||||
#define IFCAP_TSO (IFCAP_TSO4 | IFCAP_TSO6)
|
||||
#define IFCAP_WOL (IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC)
|
||||
#define IFCAP_TOE (IFCAP_TOE4 | IFCAP_TOE6)
|
||||
|
||||
#define IFCAP_CANTCHANGE (IFCAP_NETMAP)
|
||||
|
||||
#define IFQ_MAXLEN 50
|
||||
#define IFNET_SLOWHZ 1 /* granularity is 1 second */
|
||||
|
||||
/*
|
||||
* Message format for use in obtaining information about interfaces
|
||||
* from getkerninfo and the routing socket
|
||||
* For the new, extensible interface see struct if_msghdrl below.
|
||||
*/
|
||||
struct if_msghdr {
|
||||
u_short ifm_msglen; /* to skip over non-understood messages */
|
||||
u_char ifm_version; /* future binary compatibility */
|
||||
u_char ifm_type; /* message type */
|
||||
int ifm_addrs; /* like rtm_addrs */
|
||||
int ifm_flags; /* value of if_flags */
|
||||
u_short ifm_index; /* index for associated ifp */
|
||||
struct if_data ifm_data;/* statistics and other data about if */
|
||||
};
|
||||
|
||||
/*
|
||||
* The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL. It is
|
||||
* extensible after ifm_data_off or within ifm_data. Both the if_msghdr and
|
||||
* if_data now have a member field detailing the struct length in addition to
|
||||
* the routing message length. Macros are provided to find the start of
|
||||
* ifm_data and the start of the socket address strucutres immediately following
|
||||
* struct if_msghdrl given a pointer to struct if_msghdrl.
|
||||
*/
|
||||
#define IF_MSGHDRL_IFM_DATA(_l) \
|
||||
(struct if_data *)((char *)(_l) + (_l)->ifm_data_off)
|
||||
#define IF_MSGHDRL_RTA(_l) \
|
||||
(void *)((uintptr_t)(_l) + (_l)->ifm_len)
|
||||
struct if_msghdrl {
|
||||
u_short ifm_msglen; /* to skip over non-understood messages */
|
||||
u_char ifm_version; /* future binary compatibility */
|
||||
u_char ifm_type; /* message type */
|
||||
int ifm_addrs; /* like rtm_addrs */
|
||||
int ifm_flags; /* value of if_flags */
|
||||
u_short ifm_index; /* index for associated ifp */
|
||||
u_short _ifm_spare1; /* spare space to grow if_index, see if_var.h */
|
||||
u_short ifm_len; /* length of if_msghdrl incl. if_data */
|
||||
u_short ifm_data_off; /* offset of if_data from beginning */
|
||||
struct if_data ifm_data;/* statistics and other data about if */
|
||||
};
|
||||
|
||||
/*
|
||||
* Message format for use in obtaining information about interface addresses
|
||||
* from getkerninfo and the routing socket
|
||||
* For the new, extensible interface see struct ifa_msghdrl below.
|
||||
*/
|
||||
struct ifa_msghdr {
|
||||
u_short ifam_msglen; /* to skip over non-understood messages */
|
||||
u_char ifam_version; /* future binary compatibility */
|
||||
u_char ifam_type; /* message type */
|
||||
int ifam_addrs; /* like rtm_addrs */
|
||||
int ifam_flags; /* value of ifa_flags */
|
||||
u_short ifam_index; /* index for associated ifp */
|
||||
int ifam_metric; /* value of ifa_ifp->if_metric */
|
||||
};
|
||||
|
||||
/*
|
||||
* The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL. It is
|
||||
* extensible after ifam_metric or within ifam_data. Both the ifa_msghdrl and
|
||||
* if_data now have a member field detailing the struct length in addition to
|
||||
* the routing message length. Macros are provided to find the start of
|
||||
* ifm_data and the start of the socket address strucutres immediately following
|
||||
* struct ifa_msghdrl given a pointer to struct ifa_msghdrl.
|
||||
*/
|
||||
#define IFA_MSGHDRL_IFAM_DATA(_l) \
|
||||
(struct if_data *)((char *)(_l) + (_l)->ifam_data_off)
|
||||
#define IFA_MSGHDRL_RTA(_l) \
|
||||
(void *)((uintptr_t)(_l) + (_l)->ifam_len)
|
||||
struct ifa_msghdrl {
|
||||
u_short ifam_msglen; /* to skip over non-understood messages */
|
||||
u_char ifam_version; /* future binary compatibility */
|
||||
u_char ifam_type; /* message type */
|
||||
int ifam_addrs; /* like rtm_addrs */
|
||||
int ifam_flags; /* value of ifa_flags */
|
||||
u_short ifam_index; /* index for associated ifp */
|
||||
u_short _ifam_spare1; /* spare space to grow if_index, see if_var.h */
|
||||
u_short ifam_len; /* length of ifa_msghdrl incl. if_data */
|
||||
u_short ifam_data_off; /* offset of if_data from beginning */
|
||||
int ifam_metric; /* value of ifa_ifp->if_metric */
|
||||
struct if_data ifam_data;/* statistics and other data about if or
|
||||
* address */
|
||||
};
|
||||
|
||||
/*
|
||||
* Message format for use in obtaining information about multicast addresses
|
||||
* from the routing socket
|
||||
*/
|
||||
struct ifma_msghdr {
|
||||
u_short ifmam_msglen; /* to skip over non-understood messages */
|
||||
u_char ifmam_version; /* future binary compatibility */
|
||||
u_char ifmam_type; /* message type */
|
||||
int ifmam_addrs; /* like rtm_addrs */
|
||||
int ifmam_flags; /* value of ifa_flags */
|
||||
u_short ifmam_index; /* index for associated ifp */
|
||||
};
|
||||
|
||||
/*
|
||||
* Message format announcing the arrival or departure of a network interface.
|
||||
*/
|
||||
struct if_announcemsghdr {
|
||||
u_short ifan_msglen; /* to skip over non-understood messages */
|
||||
u_char ifan_version; /* future binary compatibility */
|
||||
u_char ifan_type; /* message type */
|
||||
u_short ifan_index; /* index for associated ifp */
|
||||
char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
u_short ifan_what; /* what type of announcement */
|
||||
};
|
||||
|
||||
#define IFAN_ARRIVAL 0 /* interface arrival */
|
||||
#define IFAN_DEPARTURE 1 /* interface departure */
|
||||
|
||||
/*
|
||||
* Buffer with length to be used in SIOCGIFDESCR/SIOCSIFDESCR requests
|
||||
*/
|
||||
struct ifreq_buffer {
|
||||
size_t length;
|
||||
void *buffer;
|
||||
};
|
||||
|
||||
/*
|
||||
* Interface request structure used for socket
|
||||
* ioctl's. All interface ioctl's must have parameter
|
||||
* definitions which begin with ifr_name. The
|
||||
* remainder may be interface specific.
|
||||
*/
|
||||
struct ifreq {
|
||||
char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
union {
|
||||
struct sockaddr ifru_addr;
|
||||
struct sockaddr ifru_dstaddr;
|
||||
struct sockaddr ifru_broadaddr;
|
||||
struct ifreq_buffer ifru_buffer;
|
||||
short ifru_flags[2];
|
||||
short ifru_index;
|
||||
int ifru_jid;
|
||||
int ifru_metric;
|
||||
int ifru_mtu;
|
||||
int ifru_phys;
|
||||
int ifru_media;
|
||||
caddr_t ifru_data;
|
||||
int ifru_cap[2];
|
||||
u_int ifru_fib;
|
||||
u_char ifru_vlan_pcp;
|
||||
} ifr_ifru;
|
||||
#define ifr_addr ifr_ifru.ifru_addr /* address */
|
||||
#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
|
||||
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
|
||||
#define ifr_buffer ifr_ifru.ifru_buffer /* user supplied buffer with its length */
|
||||
#define ifr_flags ifr_ifru.ifru_flags[0] /* flags (low 16 bits) */
|
||||
#define ifr_flagshigh ifr_ifru.ifru_flags[1] /* flags (high 16 bits) */
|
||||
#define ifr_jid ifr_ifru.ifru_jid /* jail/vnet */
|
||||
#define ifr_metric ifr_ifru.ifru_metric /* metric */
|
||||
#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
|
||||
#define ifr_phys ifr_ifru.ifru_phys /* physical wire */
|
||||
#define ifr_media ifr_ifru.ifru_media /* physical media */
|
||||
#define ifr_data ifr_ifru.ifru_data /* for use by interface */
|
||||
#define ifr_reqcap ifr_ifru.ifru_cap[0] /* requested capabilities */
|
||||
#define ifr_curcap ifr_ifru.ifru_cap[1] /* current capabilities */
|
||||
#define ifr_index ifr_ifru.ifru_index /* interface index */
|
||||
#define ifr_fib ifr_ifru.ifru_fib /* interface fib */
|
||||
#define ifr_vlan_pcp ifr_ifru.ifru_vlan_pcp /* VLAN priority */
|
||||
};
|
||||
|
||||
#define _SIZEOF_ADDR_IFREQ(ifr) \
|
||||
((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
|
||||
(sizeof(struct ifreq) - sizeof(struct sockaddr) + \
|
||||
(ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
|
||||
|
||||
struct ifaliasreq {
|
||||
char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
struct sockaddr ifra_addr;
|
||||
struct sockaddr ifra_broadaddr;
|
||||
struct sockaddr ifra_mask;
|
||||
int ifra_vhid;
|
||||
};
|
||||
|
||||
/* 9.x compat */
|
||||
struct oifaliasreq {
|
||||
char ifra_name[IFNAMSIZ];
|
||||
struct sockaddr ifra_addr;
|
||||
struct sockaddr ifra_broadaddr;
|
||||
struct sockaddr ifra_mask;
|
||||
};
|
||||
|
||||
struct ifmediareq {
|
||||
char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
int ifm_current; /* current media options */
|
||||
int ifm_mask; /* don't care mask */
|
||||
int ifm_status; /* media status */
|
||||
int ifm_active; /* active options */
|
||||
int ifm_count; /* # entries in ifm_ulist array */
|
||||
int *ifm_ulist; /* media words */
|
||||
};
|
||||
|
||||
struct ifdrv {
|
||||
char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
unsigned long ifd_cmd;
|
||||
size_t ifd_len;
|
||||
void *ifd_data;
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure used to retrieve aux status data from interfaces.
|
||||
* Kernel suppliers to this interface should respect the formatting
|
||||
* needed by ifconfig(8): each line starts with a TAB and ends with
|
||||
* a newline. The canonical example to copy and paste is in if_tun.c.
|
||||
*/
|
||||
|
||||
#define IFSTATMAX 800 /* 10 lines of text */
|
||||
struct ifstat {
|
||||
char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
char ascii[IFSTATMAX + 1];
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure used in SIOCGIFCONF request.
|
||||
* Used to retrieve interface configuration
|
||||
* for machine (useful for programs which
|
||||
* must know all networks accessible).
|
||||
*/
|
||||
struct ifconf {
|
||||
int ifc_len; /* size of associated buffer */
|
||||
union {
|
||||
caddr_t ifcu_buf;
|
||||
struct ifreq *ifcu_req;
|
||||
} ifc_ifcu;
|
||||
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
|
||||
#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
|
||||
};
|
||||
|
||||
/*
|
||||
* interface groups
|
||||
*/
|
||||
|
||||
#define IFG_ALL "all" /* group contains all interfaces */
|
||||
/* XXX: will we implement this? */
|
||||
#define IFG_EGRESS "egress" /* if(s) default route(s) point to */
|
||||
|
||||
struct ifg_req {
|
||||
union {
|
||||
char ifgrqu_group[IFNAMSIZ];
|
||||
char ifgrqu_member[IFNAMSIZ];
|
||||
} ifgrq_ifgrqu;
|
||||
#define ifgrq_group ifgrq_ifgrqu.ifgrqu_group
|
||||
#define ifgrq_member ifgrq_ifgrqu.ifgrqu_member
|
||||
};
|
||||
|
||||
/*
|
||||
* Used to lookup groups for an interface
|
||||
*/
|
||||
struct ifgroupreq {
|
||||
char ifgr_name[IFNAMSIZ];
|
||||
u_int ifgr_len;
|
||||
union {
|
||||
char ifgru_group[IFNAMSIZ];
|
||||
struct ifg_req *ifgru_groups;
|
||||
} ifgr_ifgru;
|
||||
#define ifgr_group ifgr_ifgru.ifgru_group
|
||||
#define ifgr_groups ifgr_ifgru.ifgru_groups
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure used to request i2c data
|
||||
* from interface transceivers.
|
||||
*/
|
||||
struct ifi2creq {
|
||||
uint8_t dev_addr; /* i2c address (0xA0, 0xA2) */
|
||||
uint8_t offset; /* read offset */
|
||||
uint8_t len; /* read length */
|
||||
uint8_t spare0;
|
||||
uint32_t spare1;
|
||||
uint8_t data[8]; /* read buffer */
|
||||
};
|
||||
|
||||
struct if_nameindex {
|
||||
unsigned int if_index; /* 1, 2, ... */
|
||||
char *if_name; /* null terminated name: "le0", ... */
|
||||
};
|
||||
|
||||
void if_freenameindex(struct if_nameindex *);
|
||||
char *if_indextoname(unsigned int, char *);
|
||||
struct if_nameindex *if_nameindex(void);
|
||||
unsigned int if_nametoindex(const char *);
|
||||
|
||||
#endif /* !_NET_IF_H_ */
|
|
@ -0,0 +1,266 @@
|
|||
/* $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
||||
* 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) 1999, 2000 Jason L. Wright (jason@thought.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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Jason L. Wright
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Data structure and control definitions for bridge interfaces.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
|
||||
* bridge interface itself is keyed off the ifdrv structure.
|
||||
*/
|
||||
#define BRDGADD 0 /* add bridge member (ifbreq) */
|
||||
#define BRDGDEL 1 /* delete bridge member (ifbreq) */
|
||||
#define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */
|
||||
#define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */
|
||||
#define BRDGSCACHE 4 /* set cache size (ifbrparam) */
|
||||
#define BRDGGCACHE 5 /* get cache size (ifbrparam) */
|
||||
#define BRDGGIFS 6 /* get member list (ifbifconf) */
|
||||
#define BRDGRTS 7 /* get address list (ifbaconf) */
|
||||
#define BRDGSADDR 8 /* set static address (ifbareq) */
|
||||
#define BRDGSTO 9 /* set cache timeout (ifbrparam) */
|
||||
#define BRDGGTO 10 /* get cache timeout (ifbrparam) */
|
||||
#define BRDGDADDR 11 /* delete address (ifbareq) */
|
||||
#define BRDGFLUSH 12 /* flush address cache (ifbreq) */
|
||||
|
||||
#define BRDGGPRI 13 /* get priority (ifbrparam) */
|
||||
#define BRDGSPRI 14 /* set priority (ifbrparam) */
|
||||
#define BRDGGHT 15 /* get hello time (ifbrparam) */
|
||||
#define BRDGSHT 16 /* set hello time (ifbrparam) */
|
||||
#define BRDGGFD 17 /* get forward delay (ifbrparam) */
|
||||
#define BRDGSFD 18 /* set forward delay (ifbrparam) */
|
||||
#define BRDGGMA 19 /* get max age (ifbrparam) */
|
||||
#define BRDGSMA 20 /* set max age (ifbrparam) */
|
||||
#define BRDGSIFPRIO 21 /* set if priority (ifbreq) */
|
||||
#define BRDGSIFCOST 22 /* set if path cost (ifbreq) */
|
||||
#define BRDGADDS 23 /* add bridge span member (ifbreq) */
|
||||
#define BRDGDELS 24 /* delete bridge span member (ifbreq) */
|
||||
#define BRDGPARAM 25 /* get bridge STP params (ifbropreq) */
|
||||
#define BRDGGRTE 26 /* get cache drops (ifbrparam) */
|
||||
#define BRDGGIFSSTP 27 /* get member STP params list
|
||||
* (ifbpstpconf) */
|
||||
#define BRDGSPROTO 28 /* set protocol (ifbrparam) */
|
||||
#define BRDGSTXHC 29 /* set tx hold count (ifbrparam) */
|
||||
#define BRDGSIFAMAX 30 /* set max interface addrs (ifbreq) */
|
||||
|
||||
/*
|
||||
* Generic bridge control request.
|
||||
*/
|
||||
struct ifbreq {
|
||||
char ifbr_ifsname[IFNAMSIZ]; /* member if name */
|
||||
uint32_t ifbr_ifsflags; /* member if flags */
|
||||
uint32_t ifbr_stpflags; /* member if STP flags */
|
||||
uint32_t ifbr_path_cost; /* member if STP cost */
|
||||
uint8_t ifbr_portno; /* member if port number */
|
||||
uint8_t ifbr_priority; /* member if STP priority */
|
||||
uint8_t ifbr_proto; /* member if STP protocol */
|
||||
uint8_t ifbr_role; /* member if STP role */
|
||||
uint8_t ifbr_state; /* member if STP state */
|
||||
uint32_t ifbr_addrcnt; /* member if addr number */
|
||||
uint32_t ifbr_addrmax; /* member if addr max */
|
||||
uint32_t ifbr_addrexceeded; /* member if addr violations */
|
||||
uint8_t pad[32];
|
||||
};
|
||||
|
||||
/* BRDGGIFFLAGS, BRDGSIFFLAGS */
|
||||
#define IFBIF_LEARNING 0x0001 /* if can learn */
|
||||
#define IFBIF_DISCOVER 0x0002 /* if sends packets w/ unknown dest. */
|
||||
#define IFBIF_STP 0x0004 /* if participates in spanning tree */
|
||||
#define IFBIF_SPAN 0x0008 /* if is a span port */
|
||||
#define IFBIF_STICKY 0x0010 /* if learned addresses stick */
|
||||
#define IFBIF_BSTP_EDGE 0x0020 /* member stp edge port */
|
||||
#define IFBIF_BSTP_AUTOEDGE 0x0040 /* member stp autoedge enabled */
|
||||
#define IFBIF_BSTP_PTP 0x0080 /* member stp point to point */
|
||||
#define IFBIF_BSTP_AUTOPTP 0x0100 /* member stp autoptp enabled */
|
||||
#define IFBIF_BSTP_ADMEDGE 0x0200 /* member stp admin edge enabled */
|
||||
#define IFBIF_BSTP_ADMCOST 0x0400 /* member stp admin path cost */
|
||||
#define IFBIF_PRIVATE 0x0800 /* if is a private segment */
|
||||
|
||||
#define IFBIFBITS "\020\001LEARNING\002DISCOVER\003STP\004SPAN" \
|
||||
"\005STICKY\014PRIVATE\006EDGE\007AUTOEDGE\010PTP" \
|
||||
"\011AUTOPTP"
|
||||
#define IFBIFMASK ~(IFBIF_BSTP_EDGE|IFBIF_BSTP_AUTOEDGE|IFBIF_BSTP_PTP| \
|
||||
IFBIF_BSTP_AUTOPTP|IFBIF_BSTP_ADMEDGE| \
|
||||
IFBIF_BSTP_ADMCOST) /* not saved */
|
||||
|
||||
/* BRDGFLUSH */
|
||||
#define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
|
||||
#define IFBF_FLUSHALL 0x01 /* flush all addresses */
|
||||
|
||||
/*
|
||||
* Interface list structure.
|
||||
*/
|
||||
struct ifbifconf {
|
||||
uint32_t ifbic_len; /* buffer size */
|
||||
union {
|
||||
caddr_t ifbicu_buf;
|
||||
struct ifbreq *ifbicu_req;
|
||||
} ifbic_ifbicu;
|
||||
#define ifbic_buf ifbic_ifbicu.ifbicu_buf
|
||||
#define ifbic_req ifbic_ifbicu.ifbicu_req
|
||||
};
|
||||
|
||||
/*
|
||||
* Bridge address request.
|
||||
*/
|
||||
struct ifbareq {
|
||||
char ifba_ifsname[IFNAMSIZ]; /* member if name */
|
||||
unsigned long ifba_expire; /* address expire time */
|
||||
uint8_t ifba_flags; /* address flags */
|
||||
uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
|
||||
uint16_t ifba_vlan; /* vlan id */
|
||||
};
|
||||
|
||||
#define IFBAF_TYPEMASK 0x03 /* address type mask */
|
||||
#define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
|
||||
#define IFBAF_STATIC 0x01 /* static address */
|
||||
#define IFBAF_STICKY 0x02 /* sticky address */
|
||||
|
||||
#define IFBAFBITS "\020\1STATIC\2STICKY"
|
||||
|
||||
/*
|
||||
* Address list structure.
|
||||
*/
|
||||
struct ifbaconf {
|
||||
uint32_t ifbac_len; /* buffer size */
|
||||
union {
|
||||
caddr_t ifbacu_buf;
|
||||
struct ifbareq *ifbacu_req;
|
||||
} ifbac_ifbacu;
|
||||
#define ifbac_buf ifbac_ifbacu.ifbacu_buf
|
||||
#define ifbac_req ifbac_ifbacu.ifbacu_req
|
||||
};
|
||||
|
||||
/*
|
||||
* Bridge parameter structure.
|
||||
*/
|
||||
struct ifbrparam {
|
||||
union {
|
||||
uint32_t ifbrpu_int32;
|
||||
uint16_t ifbrpu_int16;
|
||||
uint8_t ifbrpu_int8;
|
||||
} ifbrp_ifbrpu;
|
||||
};
|
||||
#define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */
|
||||
#define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */
|
||||
#define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */
|
||||
#define ifbrp_proto ifbrp_ifbrpu.ifbrpu_int8 /* bridge protocol */
|
||||
#define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_int8 /* bpdu tx holdcount */
|
||||
#define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */
|
||||
#define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */
|
||||
#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
|
||||
#define ifbrp_cexceeded ifbrp_ifbrpu.ifbrpu_int32 /* # of cache dropped
|
||||
* adresses */
|
||||
/*
|
||||
* Bridge current operational parameters structure.
|
||||
*/
|
||||
struct ifbropreq {
|
||||
uint8_t ifbop_holdcount;
|
||||
uint8_t ifbop_maxage;
|
||||
uint8_t ifbop_hellotime;
|
||||
uint8_t ifbop_fwddelay;
|
||||
uint8_t ifbop_protocol;
|
||||
uint16_t ifbop_priority;
|
||||
uint16_t ifbop_root_port;
|
||||
uint32_t ifbop_root_path_cost;
|
||||
uint64_t ifbop_bridgeid;
|
||||
uint64_t ifbop_designated_root;
|
||||
uint64_t ifbop_designated_bridge;
|
||||
struct timeval ifbop_last_tc_time;
|
||||
};
|
||||
|
||||
/*
|
||||
* Bridge member operational STP params structure.
|
||||
*/
|
||||
struct ifbpstpreq {
|
||||
uint8_t ifbp_portno; /* bp STP port number */
|
||||
uint32_t ifbp_fwd_trans; /* bp STP fwd transitions */
|
||||
uint32_t ifbp_design_cost; /* bp STP designated cost */
|
||||
uint32_t ifbp_design_port; /* bp STP designated port */
|
||||
uint64_t ifbp_design_bridge; /* bp STP designated bridge */
|
||||
uint64_t ifbp_design_root; /* bp STP designated root */
|
||||
};
|
||||
|
||||
/*
|
||||
* Bridge STP ports list structure.
|
||||
*/
|
||||
struct ifbpstpconf {
|
||||
uint32_t ifbpstp_len; /* buffer size */
|
||||
union {
|
||||
caddr_t ifbpstpu_buf;
|
||||
struct ifbpstpreq *ifbpstpu_req;
|
||||
} ifbpstp_ifbpstpu;
|
||||
#define ifbpstp_buf ifbpstp_ifbpstpu.ifbpstpu_buf
|
||||
#define ifbpstp_req ifbpstp_ifbpstpu.ifbpstpu_req
|
||||
};
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)if_dl.h 8.1 (Berkeley) 6/10/93
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_DL_H_
|
||||
#define _NET_IF_DL_H_
|
||||
|
||||
/*
|
||||
* A Link-Level Sockaddr may specify the interface in one of two
|
||||
* ways: either by means of a system-provided index number (computed
|
||||
* anew and possibly differently on every reboot), or by a human-readable
|
||||
* string such as "il0" (for managerial convenience).
|
||||
*
|
||||
* Census taking actions, such as something akin to SIOCGCONF would return
|
||||
* both the index and the human name.
|
||||
*
|
||||
* High volume transactions (such as giving a link-level ``from'' address
|
||||
* in a recvfrom or recvmsg call) may be likely only to provide the indexed
|
||||
* form, (which requires fewer copy operations and less space).
|
||||
*
|
||||
* The form and interpretation of the link-level address is purely a matter
|
||||
* of convention between the device driver and its consumers; however, it is
|
||||
* expected that all drivers for an interface of a given if_type will agree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Structure of a Link-Level sockaddr:
|
||||
*/
|
||||
struct sockaddr_dl {
|
||||
u_char sdl_len; /* Total length of sockaddr */
|
||||
u_char sdl_family; /* AF_LINK */
|
||||
u_short sdl_index; /* if != 0, system given index for interface */
|
||||
u_char sdl_type; /* interface type */
|
||||
u_char sdl_nlen; /* interface name length, no trailing 0 reqd. */
|
||||
u_char sdl_alen; /* link level address length */
|
||||
u_char sdl_slen; /* link layer selector length */
|
||||
char sdl_data[46]; /* minimum work area, can be larger;
|
||||
contains both if name and ll address */
|
||||
};
|
||||
|
||||
#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
|
||||
#define CLLADDR(s) ((c_caddr_t)((s)->sdl_data + (s)->sdl_nlen))
|
||||
#define LLINDEX(s) ((s)->sdl_index)
|
||||
|
||||
struct ifnet;
|
||||
struct sockaddr_dl *link_alloc_sdl(size_t, int);
|
||||
void link_free_sdl(struct sockaddr *sa);
|
||||
struct sockaddr_dl *link_init_sdl(struct ifnet *, struct sockaddr *, u_char);
|
||||
|
||||
void link_addr(const char *, struct sockaddr_dl *);
|
||||
char *link_ntoa(const struct sockaddr_dl *);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,42 @@
|
|||
/* $FreeBSD$ */
|
||||
/* $KAME: if_gif.h,v 1.17 2000/09/11 11:36:41 sumikawa Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* 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. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT 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.
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_GIF_H_
|
||||
#define _NET_IF_GIF_H_
|
||||
|
||||
#define GIFGOPTS _IOWR('i', 150, struct ifreq)
|
||||
#define GIFSOPTS _IOW('i', 151, struct ifreq)
|
||||
|
||||
#define GIF_IGNORE_SOURCE 0x0002
|
||||
#define GIF_OPTMASK (GIF_IGNORE_SOURCE)
|
||||
|
||||
#endif /* _NET_IF_GIF_H_ */
|
|
@ -0,0 +1,53 @@
|
|||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 2014 Andrey V. Elsukov <ae@FreeBSD.org>
|
||||
* All rights reserved
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Heiko W.Rupp <hwr@pilhuhn.de>
|
||||
*
|
||||
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
*
|
||||
* $NetBSD: if_gre.h,v 1.13 2003/11/10 08:51:52 wiz Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_GRE_H_
|
||||
#define _NET_IF_GRE_H_
|
||||
|
||||
#define GRESADDRS _IOW('i', 101, struct ifreq)
|
||||
#define GRESADDRD _IOW('i', 102, struct ifreq)
|
||||
#define GREGADDRS _IOWR('i', 103, struct ifreq)
|
||||
#define GREGADDRD _IOWR('i', 104, struct ifreq)
|
||||
#define GRESPROTO _IOW('i' , 105, struct ifreq)
|
||||
#define GREGPROTO _IOWR('i', 106, struct ifreq)
|
||||
|
||||
#define GREGKEY _IOWR('i', 107, struct ifreq)
|
||||
#define GRESKEY _IOW('i', 108, struct ifreq)
|
||||
#define GREGOPTS _IOWR('i', 109, struct ifreq)
|
||||
#define GRESOPTS _IOW('i', 110, struct ifreq)
|
||||
|
||||
#define GRE_ENABLE_CSUM 0x0001
|
||||
#define GRE_ENABLE_SEQ 0x0002
|
||||
#define GRE_OPTMASK (GRE_ENABLE_CSUM|GRE_ENABLE_SEQ)
|
||||
|
||||
#endif /* _NET_IF_GRE_H_ */
|
|
@ -0,0 +1,244 @@
|
|||
/*-
|
||||
* Copyright (c) 2001 Michael Shalayeff
|
||||
* 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 OR HIS RELATIVES 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 MIND, 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) 2008 David Gwynne <dlg@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $OpenBSD: if_pfsync.h,v 1.35 2008/06/29 08:42:15 mcbride Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NET_IF_PFSYNC_H_
|
||||
#define _NET_IF_PFSYNC_H_
|
||||
|
||||
#define PFSYNC_VERSION 5
|
||||
#define PFSYNC_DFLTTL 255
|
||||
|
||||
#define PFSYNC_ACT_CLR 0 /* clear all states */
|
||||
#define PFSYNC_ACT_INS 1 /* insert state */
|
||||
#define PFSYNC_ACT_INS_ACK 2 /* ack of insterted state */
|
||||
#define PFSYNC_ACT_UPD 3 /* update state */
|
||||
#define PFSYNC_ACT_UPD_C 4 /* "compressed" update state */
|
||||
#define PFSYNC_ACT_UPD_REQ 5 /* request "uncompressed" state */
|
||||
#define PFSYNC_ACT_DEL 6 /* delete state */
|
||||
#define PFSYNC_ACT_DEL_C 7 /* "compressed" delete state */
|
||||
#define PFSYNC_ACT_INS_F 8 /* insert fragment */
|
||||
#define PFSYNC_ACT_DEL_F 9 /* delete fragments */
|
||||
#define PFSYNC_ACT_BUS 10 /* bulk update status */
|
||||
#define PFSYNC_ACT_TDB 11 /* TDB replay counter update */
|
||||
#define PFSYNC_ACT_EOF 12 /* end of frame */
|
||||
#define PFSYNC_ACT_MAX 13
|
||||
|
||||
/*
|
||||
* A pfsync frame is built from a header followed by several sections which
|
||||
* are all prefixed with their own subheaders. Frames must be terminated with
|
||||
* an EOF subheader.
|
||||
*
|
||||
* | ... |
|
||||
* | IP header |
|
||||
* +============================+
|
||||
* | pfsync_header |
|
||||
* +----------------------------+
|
||||
* | pfsync_subheader |
|
||||
* +----------------------------+
|
||||
* | first action fields |
|
||||
* | ... |
|
||||
* +----------------------------+
|
||||
* | pfsync_subheader |
|
||||
* +----------------------------+
|
||||
* | second action fields |
|
||||
* | ... |
|
||||
* +----------------------------+
|
||||
* | EOF pfsync_subheader |
|
||||
* +----------------------------+
|
||||
* | HMAC |
|
||||
* +============================+
|
||||
*/
|
||||
|
||||
/*
|
||||
* Frame header
|
||||
*/
|
||||
|
||||
struct pfsync_header {
|
||||
u_int8_t version;
|
||||
u_int8_t _pad;
|
||||
u_int16_t len;
|
||||
u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH];
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* Frame region subheader
|
||||
*/
|
||||
|
||||
struct pfsync_subheader {
|
||||
u_int8_t action;
|
||||
u_int8_t _pad;
|
||||
u_int16_t count;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* CLR
|
||||
*/
|
||||
|
||||
struct pfsync_clr {
|
||||
char ifname[IFNAMSIZ];
|
||||
u_int32_t creatorid;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* INS, UPD, DEL
|
||||
*/
|
||||
|
||||
/* these use struct pfsync_state in pfvar.h */
|
||||
|
||||
/*
|
||||
* INS_ACK
|
||||
*/
|
||||
|
||||
struct pfsync_ins_ack {
|
||||
u_int64_t id;
|
||||
u_int32_t creatorid;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* UPD_C
|
||||
*/
|
||||
|
||||
struct pfsync_upd_c {
|
||||
u_int64_t id;
|
||||
struct pfsync_state_peer src;
|
||||
struct pfsync_state_peer dst;
|
||||
u_int32_t creatorid;
|
||||
u_int32_t expire;
|
||||
u_int8_t timeout;
|
||||
u_int8_t _pad[3];
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* UPD_REQ
|
||||
*/
|
||||
|
||||
struct pfsync_upd_req {
|
||||
u_int64_t id;
|
||||
u_int32_t creatorid;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* DEL_C
|
||||
*/
|
||||
|
||||
struct pfsync_del_c {
|
||||
u_int64_t id;
|
||||
u_int32_t creatorid;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* INS_F, DEL_F
|
||||
*/
|
||||
|
||||
/* not implemented (yet) */
|
||||
|
||||
/*
|
||||
* BUS
|
||||
*/
|
||||
|
||||
struct pfsync_bus {
|
||||
u_int32_t creatorid;
|
||||
u_int32_t endtime;
|
||||
u_int8_t status;
|
||||
#define PFSYNC_BUS_START 1
|
||||
#define PFSYNC_BUS_END 2
|
||||
u_int8_t _pad[3];
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* TDB
|
||||
*/
|
||||
|
||||
struct pfsync_tdb {
|
||||
u_int32_t spi;
|
||||
union sockaddr_union dst;
|
||||
u_int32_t rpl;
|
||||
u_int64_t cur_bytes;
|
||||
u_int8_t sproto;
|
||||
u_int8_t updates;
|
||||
u_int8_t _pad[2];
|
||||
} __packed;
|
||||
|
||||
#define PFSYNC_HDRLEN sizeof(struct pfsync_header)
|
||||
|
||||
struct pfsyncstats {
|
||||
u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */
|
||||
u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */
|
||||
u_int64_t pfsyncs_badif; /* not the right interface */
|
||||
u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */
|
||||
u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */
|
||||
u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */
|
||||
u_int64_t pfsyncs_badact; /* bad action */
|
||||
u_int64_t pfsyncs_badlen; /* data length does not match */
|
||||
u_int64_t pfsyncs_badauth; /* bad authentication */
|
||||
u_int64_t pfsyncs_stale; /* stale state */
|
||||
u_int64_t pfsyncs_badval; /* bad values */
|
||||
u_int64_t pfsyncs_badstate; /* insert/lookup failed */
|
||||
|
||||
u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */
|
||||
u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */
|
||||
u_int64_t pfsyncs_onomem; /* no memory for an mbuf */
|
||||
u_int64_t pfsyncs_oerrors; /* ip output error */
|
||||
|
||||
u_int64_t pfsyncs_iacts[PFSYNC_ACT_MAX];
|
||||
u_int64_t pfsyncs_oacts[PFSYNC_ACT_MAX];
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC
|
||||
*/
|
||||
struct pfsyncreq {
|
||||
char pfsyncr_syncdev[IFNAMSIZ];
|
||||
struct in_addr pfsyncr_syncpeer;
|
||||
int pfsyncr_maxupdates;
|
||||
int pfsyncr_defer;
|
||||
};
|
||||
|
||||
#define SIOCSETPFSYNC _IOW('i', 247, struct ifreq)
|
||||
#define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq)
|
||||
|
||||
#endif /* _NET_IF_PFSYNC_H_ */
|
|
@ -0,0 +1,273 @@
|
|||
/*-
|
||||
* Copyright (c) 1989, 1993, 1994
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)if_types.h 8.3 (Berkeley) 4/28/95
|
||||
* $FreeBSD$
|
||||
* $NetBSD: if_types.h,v 1.16 2000/04/19 06:30:53 itojun Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_TYPES_H_
|
||||
#define _NET_IF_TYPES_H_
|
||||
|
||||
/*
|
||||
* Interface types for benefit of parsing media address headers.
|
||||
* This list is derived from the SNMP list of ifTypes, originally
|
||||
* documented in RFC1573, now maintained as:
|
||||
*
|
||||
* http://www.iana.org/assignments/smi-numbers
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
IFT_OTHER = 0x1, /* none of the following */
|
||||
IFT_1822 = 0x2, /* old-style arpanet imp */
|
||||
IFT_HDH1822 = 0x3, /* HDH arpanet imp */
|
||||
IFT_X25DDN = 0x4, /* x25 to imp */
|
||||
IFT_X25 = 0x5, /* PDN X25 interface (RFC877) */
|
||||
IFT_ETHER = 0x6, /* Ethernet CSMA/CD */
|
||||
IFT_ISO88023 = 0x7, /* CMSA/CD */
|
||||
IFT_ISO88024 = 0x8, /* Token Bus */
|
||||
IFT_ISO88025 = 0x9, /* Token Ring */
|
||||
IFT_ISO88026 = 0xa, /* MAN */
|
||||
IFT_STARLAN = 0xb,
|
||||
IFT_P10 = 0xc, /* Proteon 10MBit ring */
|
||||
IFT_P80 = 0xd, /* Proteon 80MBit ring */
|
||||
IFT_HY = 0xe, /* Hyperchannel */
|
||||
IFT_FDDI = 0xf,
|
||||
IFT_LAPB = 0x10,
|
||||
IFT_SDLC = 0x11,
|
||||
IFT_T1 = 0x12,
|
||||
IFT_CEPT = 0x13, /* E1 - european T1 */
|
||||
IFT_ISDNBASIC = 0x14,
|
||||
IFT_ISDNPRIMARY = 0x15,
|
||||
IFT_PTPSERIAL = 0x16, /* Proprietary PTP serial */
|
||||
IFT_PPP = 0x17, /* RFC 1331 */
|
||||
IFT_LOOP = 0x18, /* loopback */
|
||||
IFT_EON = 0x19, /* ISO over IP */
|
||||
IFT_XETHER = 0x1a, /* obsolete 3MB experimental ethernet */
|
||||
IFT_NSIP = 0x1b, /* XNS over IP */
|
||||
IFT_SLIP = 0x1c, /* IP over generic TTY */
|
||||
IFT_ULTRA = 0x1d, /* Ultra Technologies */
|
||||
IFT_DS3 = 0x1e, /* Generic T3 */
|
||||
IFT_SIP = 0x1f, /* SMDS */
|
||||
IFT_FRELAY = 0x20, /* Frame Relay DTE only */
|
||||
IFT_RS232 = 0x21,
|
||||
IFT_PARA = 0x22, /* parallel-port */
|
||||
IFT_ARCNET = 0x23,
|
||||
IFT_ARCNETPLUS = 0x24,
|
||||
IFT_ATM = 0x25, /* ATM cells */
|
||||
IFT_MIOX25 = 0x26,
|
||||
IFT_SONET = 0x27, /* SONET or SDH */
|
||||
IFT_X25PLE = 0x28,
|
||||
IFT_ISO88022LLC = 0x29,
|
||||
IFT_LOCALTALK = 0x2a,
|
||||
IFT_SMDSDXI = 0x2b,
|
||||
IFT_FRELAYDCE = 0x2c, /* Frame Relay DCE */
|
||||
IFT_V35 = 0x2d,
|
||||
IFT_HSSI = 0x2e,
|
||||
IFT_HIPPI = 0x2f,
|
||||
IFT_MODEM = 0x30, /* Generic Modem */
|
||||
IFT_AAL5 = 0x31, /* AAL5 over ATM */
|
||||
IFT_SONETPATH = 0x32,
|
||||
IFT_SONETVT = 0x33,
|
||||
IFT_SMDSICIP = 0x34, /* SMDS InterCarrier Interface */
|
||||
IFT_PROPVIRTUAL = 0x35, /* Proprietary Virtual/internal */
|
||||
IFT_PROPMUX = 0x36, /* Proprietary Multiplexing */
|
||||
IFT_IEEE80212 = 0x37, /* 100BaseVG */
|
||||
IFT_FIBRECHANNEL = 0x38, /* Fibre Channel */
|
||||
IFT_HIPPIINTERFACE = 0x39, /* HIPPI interfaces */
|
||||
IFT_FRAMERELAYINTERCONNECT = 0x3a, /* Obsolete, use 0x20 either 0x2c */
|
||||
IFT_AFLANE8023 = 0x3b, /* ATM Emulated LAN for 802.3 */
|
||||
IFT_AFLANE8025 = 0x3c, /* ATM Emulated LAN for 802.5 */
|
||||
IFT_CCTEMUL = 0x3d, /* ATM Emulated circuit */
|
||||
IFT_FASTETHER = 0x3e, /* Fast Ethernet (100BaseT) */
|
||||
IFT_ISDN = 0x3f, /* ISDN and X.25 */
|
||||
IFT_V11 = 0x40, /* CCITT V.11/X.21 */
|
||||
IFT_V36 = 0x41, /* CCITT V.36 */
|
||||
IFT_G703AT64K = 0x42, /* CCITT G703 at 64Kbps */
|
||||
IFT_G703AT2MB = 0x43, /* Obsolete see DS1-MIB */
|
||||
IFT_QLLC = 0x44, /* SNA QLLC */
|
||||
IFT_FASTETHERFX = 0x45, /* Fast Ethernet (100BaseFX) */
|
||||
IFT_CHANNEL = 0x46, /* channel */
|
||||
IFT_IEEE80211 = 0x47, /* radio spread spectrum */
|
||||
IFT_IBM370PARCHAN = 0x48, /* IBM System 360/370 OEMI Channel */
|
||||
IFT_ESCON = 0x49, /* IBM Enterprise Systems Connection */
|
||||
IFT_DLSW = 0x4a, /* Data Link Switching */
|
||||
IFT_ISDNS = 0x4b, /* ISDN S/T interface */
|
||||
IFT_ISDNU = 0x4c, /* ISDN U interface */
|
||||
IFT_LAPD = 0x4d, /* Link Access Protocol D */
|
||||
IFT_IPSWITCH = 0x4e, /* IP Switching Objects */
|
||||
IFT_RSRB = 0x4f, /* Remote Source Route Bridging */
|
||||
IFT_ATMLOGICAL = 0x50, /* ATM Logical Port */
|
||||
IFT_DS0 = 0x51, /* Digital Signal Level 0 */
|
||||
IFT_DS0BUNDLE = 0x52, /* group of ds0s on the same ds1 */
|
||||
IFT_BSC = 0x53, /* Bisynchronous Protocol */
|
||||
IFT_ASYNC = 0x54, /* Asynchronous Protocol */
|
||||
IFT_CNR = 0x55, /* Combat Net Radio */
|
||||
IFT_ISO88025DTR = 0x56, /* ISO 802.5r DTR */
|
||||
IFT_EPLRS = 0x57, /* Ext Pos Loc Report Sys */
|
||||
IFT_ARAP = 0x58, /* Appletalk Remote Access Protocol */
|
||||
IFT_PROPCNLS = 0x59, /* Proprietary Connectionless Protocol*/
|
||||
IFT_HOSTPAD = 0x5a, /* CCITT-ITU X.29 PAD Protocol */
|
||||
IFT_TERMPAD = 0x5b, /* CCITT-ITU X.3 PAD Facility */
|
||||
IFT_FRAMERELAYMPI = 0x5c, /* Multiproto Interconnect over FR */
|
||||
IFT_X213 = 0x5d, /* CCITT-ITU X213 */
|
||||
IFT_ADSL = 0x5e, /* Asymmetric Digital Subscriber Loop */
|
||||
IFT_RADSL = 0x5f, /* Rate-Adapt. Digital Subscriber Loop*/
|
||||
IFT_SDSL = 0x60, /* Symmetric Digital Subscriber Loop */
|
||||
IFT_VDSL = 0x61, /* Very H-Speed Digital Subscrib. Loop*/
|
||||
IFT_ISO88025CRFPINT = 0x62, /* ISO 802.5 CRFP */
|
||||
IFT_MYRINET = 0x63, /* Myricom Myrinet */
|
||||
IFT_VOICEEM = 0x64, /* voice recEive and transMit */
|
||||
IFT_VOICEFXO = 0x65, /* voice Foreign Exchange Office */
|
||||
IFT_VOICEFXS = 0x66, /* voice Foreign Exchange Station */
|
||||
IFT_VOICEENCAP = 0x67, /* voice encapsulation */
|
||||
IFT_VOICEOVERIP = 0x68, /* voice over IP encapsulation */
|
||||
IFT_ATMDXI = 0x69, /* ATM DXI */
|
||||
IFT_ATMFUNI = 0x6a, /* ATM FUNI */
|
||||
IFT_ATMIMA = 0x6b, /* ATM IMA */
|
||||
IFT_PPPMULTILINKBUNDLE = 0x6c, /* PPP Multilink Bundle */
|
||||
IFT_IPOVERCDLC = 0x6d, /* IBM ipOverCdlc */
|
||||
IFT_IPOVERCLAW = 0x6e, /* IBM Common Link Access to Workstn */
|
||||
IFT_STACKTOSTACK = 0x6f, /* IBM stackToStack */
|
||||
IFT_VIRTUALIPADDRESS = 0x70, /* IBM VIPA */
|
||||
IFT_MPC = 0x71, /* IBM multi-protocol channel support */
|
||||
IFT_IPOVERATM = 0x72, /* IBM ipOverAtm */
|
||||
IFT_ISO88025FIBER = 0x73, /* ISO 802.5j Fiber Token Ring */
|
||||
IFT_TDLC = 0x74, /* IBM twinaxial data link control */
|
||||
IFT_GIGABITETHERNET = 0x75, /* Gigabit Ethernet */
|
||||
IFT_HDLC = 0x76, /* HDLC */
|
||||
IFT_LAPF = 0x77, /* LAP F */
|
||||
IFT_V37 = 0x78, /* V.37 */
|
||||
IFT_X25MLP = 0x79, /* Multi-Link Protocol */
|
||||
IFT_X25HUNTGROUP = 0x7a, /* X25 Hunt Group */
|
||||
IFT_TRANSPHDLC = 0x7b, /* Transp HDLC */
|
||||
IFT_INTERLEAVE = 0x7c, /* Interleave channel */
|
||||
IFT_FAST = 0x7d, /* Fast channel */
|
||||
IFT_IP = 0x7e, /* IP (for APPN HPR in IP networks) */
|
||||
IFT_DOCSCABLEMACLAYER = 0x7f, /* CATV Mac Layer */
|
||||
IFT_DOCSCABLEDOWNSTREAM = 0x80, /* CATV Downstream interface */
|
||||
IFT_DOCSCABLEUPSTREAM = 0x81, /* CATV Upstream interface */
|
||||
IFT_A12MPPSWITCH = 0x82, /* Avalon Parallel Processor */
|
||||
IFT_TUNNEL = 0x83, /* Encapsulation interface */
|
||||
IFT_COFFEE = 0x84, /* coffee pot */
|
||||
IFT_CES = 0x85, /* Circiut Emulation Service */
|
||||
IFT_ATMSUBINTERFACE = 0x86, /* (x) ATM Sub Interface */
|
||||
IFT_L2VLAN = 0x87, /* Layer 2 Virtual LAN using 802.1Q */
|
||||
IFT_L3IPVLAN = 0x88, /* Layer 3 Virtual LAN - IP Protocol */
|
||||
IFT_L3IPXVLAN = 0x89, /* Layer 3 Virtual LAN - IPX Prot. */
|
||||
IFT_DIGITALPOWERLINE = 0x8a, /* IP over Power Lines */
|
||||
IFT_MEDIAMAILOVERIP = 0x8b, /* (xxx) Multimedia Mail over IP */
|
||||
IFT_DTM = 0x8c, /* Dynamic synchronous Transfer Mode */
|
||||
IFT_DCN = 0x8d, /* Data Communications Network */
|
||||
IFT_IPFORWARD = 0x8e, /* IP Forwarding Interface */
|
||||
IFT_MSDSL = 0x8f, /* Multi-rate Symmetric DSL */
|
||||
IFT_IEEE1394 = 0x90, /* IEEE1394 High Performance SerialBus*/
|
||||
IFT_IFGSN = 0x91, /* HIPPI-6400 */
|
||||
IFT_DVBRCCMACLAYER = 0x92, /* DVB-RCC MAC Layer */
|
||||
IFT_DVBRCCDOWNSTREAM = 0x93, /* DVB-RCC Downstream Channel */
|
||||
IFT_DVBRCCUPSTREAM = 0x94, /* DVB-RCC Upstream Channel */
|
||||
IFT_ATMVIRTUAL = 0x95, /* ATM Virtual Interface */
|
||||
IFT_MPLSTUNNEL = 0x96, /* MPLS Tunnel Virtual Interface */
|
||||
IFT_SRP = 0x97, /* Spatial Reuse Protocol */
|
||||
IFT_VOICEOVERATM = 0x98, /* Voice over ATM */
|
||||
IFT_VOICEOVERFRAMERELAY = 0x99, /* Voice Over Frame Relay */
|
||||
IFT_IDSL = 0x9a, /* Digital Subscriber Loop over ISDN */
|
||||
IFT_COMPOSITELINK = 0x9b, /* Avici Composite Link Interface */
|
||||
IFT_SS7SIGLINK = 0x9c, /* SS7 Signaling Link */
|
||||
IFT_PROPWIRELESSP2P = 0x9d, /* Prop. P2P wireless interface */
|
||||
IFT_FRFORWARD = 0x9e, /* Frame forward Interface */
|
||||
IFT_RFC1483 = 0x9f, /* Multiprotocol over ATM AAL5 */
|
||||
IFT_USB = 0xa0, /* USB Interface */
|
||||
IFT_IEEE8023ADLAG = 0xa1, /* IEEE 802.3ad Link Aggregate*/
|
||||
IFT_BGPPOLICYACCOUNTING = 0xa2, /* BGP Policy Accounting */
|
||||
IFT_FRF16MFRBUNDLE = 0xa3, /* FRF.16 Multilik Frame Relay*/
|
||||
IFT_H323GATEKEEPER = 0xa4, /* H323 Gatekeeper */
|
||||
IFT_H323PROXY = 0xa5, /* H323 Voice and Video Proxy */
|
||||
IFT_MPLS = 0xa6, /* MPLS */
|
||||
IFT_MFSIGLINK = 0xa7, /* Multi-frequency signaling link */
|
||||
IFT_HDSL2 = 0xa8, /* High Bit-Rate DSL, 2nd gen. */
|
||||
IFT_SHDSL = 0xa9, /* Multirate HDSL2 */
|
||||
IFT_DS1FDL = 0xaa, /* Facility Data Link (4Kbps) on a DS1*/
|
||||
IFT_POS = 0xab, /* Packet over SONET/SDH Interface */
|
||||
IFT_DVBASILN = 0xac, /* DVB-ASI Input */
|
||||
IFT_DVBASIOUT = 0xad, /* DVB-ASI Output */
|
||||
IFT_PLC = 0xae, /* Power Line Communications */
|
||||
IFT_NFAS = 0xaf, /* Non-Facility Associated Signaling */
|
||||
IFT_TR008 = 0xb0, /* TROO8 */
|
||||
IFT_GR303RDT = 0xb1, /* Remote Digital Terminal */
|
||||
IFT_GR303IDT = 0xb2, /* Integrated Digital Terminal */
|
||||
IFT_ISUP = 0xb3, /* ISUP */
|
||||
IFT_PROPDOCSWIRELESSMACLAYER = 0xb4, /* prop/Wireless MAC Layer */
|
||||
IFT_PROPDOCSWIRELESSDOWNSTREAM = 0xb5, /* prop/Wireless Downstream */
|
||||
IFT_PROPDOCSWIRELESSUPSTREAM = 0xb6, /* prop/Wireless Upstream */
|
||||
IFT_HIPERLAN2 = 0xb7, /* HIPERLAN Type 2 Radio Interface */
|
||||
IFT_PROPBWAP2MP = 0xb8, /* PropBroadbandWirelessAccess P2MP*/
|
||||
IFT_SONETOVERHEADCHANNEL = 0xb9, /* SONET Overhead Channel */
|
||||
IFT_DIGITALWRAPPEROVERHEADCHANNEL = 0xba, /* Digital Wrapper Overhead */
|
||||
IFT_AAL2 = 0xbb, /* ATM adaptation layer 2 */
|
||||
IFT_RADIOMAC = 0xbc, /* MAC layer over radio links */
|
||||
IFT_ATMRADIO = 0xbd, /* ATM over radio links */
|
||||
IFT_IMT = 0xbe, /* Inter-Machine Trunks */
|
||||
IFT_MVL = 0xbf, /* Multiple Virtual Lines DSL */
|
||||
IFT_REACHDSL = 0xc0, /* Long Reach DSL */
|
||||
IFT_FRDLCIENDPT = 0xc1, /* Frame Relay DLCI End Point */
|
||||
IFT_ATMVCIENDPT = 0xc2, /* ATM VCI End Point */
|
||||
IFT_OPTICALCHANNEL = 0xc3, /* Optical Channel */
|
||||
IFT_OPTICALTRANSPORT = 0xc4, /* Optical Transport */
|
||||
IFT_INFINIBAND = 0xc7, /* Infiniband */
|
||||
IFT_BRIDGE = 0xd1, /* Transparent bridge interface */
|
||||
IFT_STF = 0xd7, /* 6to4 interface */
|
||||
|
||||
/*
|
||||
* Not based on IANA assignments. Conflicting with IANA assignments.
|
||||
* We should make them negative probably.
|
||||
* This requires changes to struct if_data.
|
||||
*/
|
||||
IFT_GIF = 0xf0, /* Generic tunnel interface */
|
||||
IFT_PVC = 0xf1, /* Unused */
|
||||
IFT_ENC = 0xf4, /* Encapsulating interface */
|
||||
IFT_PFLOG = 0xf6, /* PF packet filter logging */
|
||||
IFT_PFSYNC = 0xf7, /* PF packet filter synchronization */
|
||||
} ifType;
|
||||
|
||||
/*
|
||||
* Some (broken) software uses #ifdef IFT_TYPE to check whether
|
||||
* an operating systems supports certain interface type. Lack of
|
||||
* ifdef leads to a piece of functionality compiled out.
|
||||
*/
|
||||
#ifndef BURN_BRIDGES
|
||||
#define IFT_BRIDGE IFT_BRIDGE
|
||||
#define IFT_PPP IFT_PPP
|
||||
#define IFT_PROPVIRTUAL IFT_PROPVIRTUAL
|
||||
#define IFT_L2VLAN IFT_L2VLAN
|
||||
#define IFT_L3IPVLAN IFT_L3IPVLAN
|
||||
#define IFT_IEEE1394 IFT_IEEE1394
|
||||
#define IFT_INFINIBAND IFT_INFINIBAND
|
||||
#endif
|
||||
|
||||
#endif /* !_NET_IF_TYPES_H_ */
|
|
@ -0,0 +1,94 @@
|
|||
/*-
|
||||
* Copyright 1998 Massachusetts Institute of Technology
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby
|
||||
* granted, provided that both the above copyright notice and this
|
||||
* permission notice appear in all copies, that both the above
|
||||
* copyright notice and this permission notice appear in all
|
||||
* supporting documentation, and that the name of M.I.T. not be used
|
||||
* in advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission. M.I.T. makes
|
||||
* no representations about the suitability of this software for any
|
||||
* purpose. It is provided "as is" without express or implied
|
||||
* warranty.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
|
||||
* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
|
||||
* SHALL M.I.T. 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 _NET_IF_VLAN_VAR_H_
|
||||
#define _NET_IF_VLAN_VAR_H_ 1
|
||||
|
||||
/* Set the VLAN ID in an mbuf packet header non-destructively. */
|
||||
#define EVL_APPLY_VLID(m, vlid) \
|
||||
do { \
|
||||
if ((m)->m_flags & M_VLANTAG) { \
|
||||
(m)->m_pkthdr.ether_vtag &= EVL_VLID_MASK; \
|
||||
(m)->m_pkthdr.ether_vtag |= (vlid); \
|
||||
} else { \
|
||||
(m)->m_pkthdr.ether_vtag = (vlid); \
|
||||
(m)->m_flags |= M_VLANTAG; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Set the priority ID in an mbuf packet header non-destructively. */
|
||||
#define EVL_APPLY_PRI(m, pri) \
|
||||
do { \
|
||||
if ((m)->m_flags & M_VLANTAG) { \
|
||||
uint16_t __vlantag = (m)->m_pkthdr.ether_vtag; \
|
||||
(m)->m_pkthdr.ether_vtag |= EVL_MAKETAG( \
|
||||
EVL_VLANOFTAG(__vlantag), (pri), \
|
||||
EVL_CFIOFTAG(__vlantag)); \
|
||||
} else { \
|
||||
(m)->m_pkthdr.ether_vtag = \
|
||||
EVL_MAKETAG(0, (pri), 0); \
|
||||
(m)->m_flags |= M_VLANTAG; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* sysctl(3) tags, for compatibility purposes */
|
||||
#define VLANCTL_PROTO 1
|
||||
#define VLANCTL_MAX 2
|
||||
|
||||
/*
|
||||
* Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls.
|
||||
*/
|
||||
struct vlanreq {
|
||||
char vlr_parent[IFNAMSIZ];
|
||||
u_short vlr_tag;
|
||||
};
|
||||
#define SIOCSETVLAN SIOCSIFGENERIC
|
||||
#define SIOCGETVLAN SIOCGIFGENERIC
|
||||
|
||||
#define SIOCGVLANPCP _IOWR('i', 152, struct ifreq) /* Get VLAN PCP */
|
||||
#define SIOCSVLANPCP _IOW('i', 153, struct ifreq) /* Set VLAN PCP */
|
||||
|
||||
/*
|
||||
* Names for 802.1q priorities ("802.1p"). Notice that in this scheme,
|
||||
* (0 < 1), allowing default 0-tagged traffic to take priority over background
|
||||
* tagged traffic.
|
||||
*/
|
||||
#define IEEE8021Q_PCP_BK 1 /* Background (lowest) */
|
||||
#define IEEE8021Q_PCP_BE 0 /* Best effort (default) */
|
||||
#define IEEE8021Q_PCP_EE 2 /* Excellent effort */
|
||||
#define IEEE8021Q_PCP_CA 3 /* Critical applications */
|
||||
#define IEEE8021Q_PCP_VI 4 /* Video, < 100ms latency */
|
||||
#define IEEE8021Q_PCP_VO 5 /* Video, < 10ms latency */
|
||||
#define IEEE8021Q_PCP_IC 6 /* Internetwork control */
|
||||
#define IEEE8021Q_PCP_NC 7 /* Network control (highest) */
|
||||
|
||||
|
||||
#endif /* _NET_IF_VLAN_VAR_H_ */
|
|
@ -0,0 +1,148 @@
|
|||
/*-
|
||||
* Copyright (c) 2014, Bryan Venteicher <bryanv@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 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 ``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 _NET_IF_VXLAN_H_
|
||||
#define _NET_IF_VXLAN_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
struct vxlan_header {
|
||||
uint32_t vxlh_flags;
|
||||
uint32_t vxlh_vni;
|
||||
};
|
||||
|
||||
#define VXLAN_HDR_FLAGS_VALID_VNI 0x08000000
|
||||
#define VXLAN_HDR_VNI_SHIFT 8
|
||||
|
||||
#define VXLAN_VNI_MAX (1 << 24)
|
||||
#define VXLAN_VNI_MASK (VXLAN_VNI_MAX - 1)
|
||||
|
||||
/*
|
||||
* The port assigned by IANA is 4789, but some early implementations
|
||||
* (like Linux) use 8472 instead. If not specified, we default to
|
||||
* the IANA port.
|
||||
*/
|
||||
#define VXLAN_PORT 4789
|
||||
#define VXLAN_LEGACY_PORT 8472
|
||||
|
||||
struct ifvxlanparam {
|
||||
uint64_t vxlp_with;
|
||||
|
||||
#define VXLAN_PARAM_WITH_VNI 0x0001
|
||||
#define VXLAN_PARAM_WITH_LOCAL_ADDR4 0x0002
|
||||
#define VXLAN_PARAM_WITH_LOCAL_ADDR6 0x0004
|
||||
#define VXLAN_PARAM_WITH_REMOTE_ADDR4 0x0008
|
||||
#define VXLAN_PARAM_WITH_REMOTE_ADDR6 0x0010
|
||||
#define VXLAN_PARAM_WITH_LOCAL_PORT 0x0020
|
||||
#define VXLAN_PARAM_WITH_REMOTE_PORT 0x0040
|
||||
#define VXLAN_PARAM_WITH_PORT_RANGE 0x0080
|
||||
#define VXLAN_PARAM_WITH_FTABLE_TIMEOUT 0x0100
|
||||
#define VXLAN_PARAM_WITH_FTABLE_MAX 0x0200
|
||||
#define VXLAN_PARAM_WITH_MULTICAST_IF 0x0400
|
||||
#define VXLAN_PARAM_WITH_TTL 0x0800
|
||||
#define VXLAN_PARAM_WITH_LEARN 0x1000
|
||||
|
||||
uint32_t vxlp_vni;
|
||||
struct in_addr vxlp_local_in4;
|
||||
struct in6_addr vxlp_local_in6;
|
||||
struct in_addr vxlp_remote_in4;
|
||||
struct in6_addr vxlp_remote_in6;
|
||||
uint16_t vxlp_local_port;
|
||||
uint16_t vxlp_remote_port;
|
||||
uint16_t vxlp_min_port;
|
||||
uint16_t vxlp_max_port;
|
||||
char vxlp_mc_ifname[IFNAMSIZ];
|
||||
uint32_t vxlp_ftable_timeout;
|
||||
uint32_t vxlp_ftable_max;
|
||||
uint8_t vxlp_ttl;
|
||||
uint8_t vxlp_learn;
|
||||
};
|
||||
|
||||
union vxlan_sockaddr {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in in4;
|
||||
struct sockaddr_in6 in6;
|
||||
};
|
||||
|
||||
#define VXLAN_SOCKADDR_IS_IPV4(_vxsin) ((_vxsin)->sa.sa_family == AF_INET)
|
||||
#define VXLAN_SOCKADDR_IS_IPV6(_vxsin) ((_vxsin)->sa.sa_family == AF_INET6)
|
||||
#define VXLAN_SOCKADDR_IS_IPV46(_vxsin) \
|
||||
(VXLAN_SOCKADDR_IS_IPV4(_vxsin) || VXLAN_SOCKADDR_IS_IPV6(_vxsin))
|
||||
|
||||
#define VXLAN_CMD_GET_CONFIG 0
|
||||
#define VXLAN_CMD_SET_VNI 1
|
||||
#define VXLAN_CMD_SET_LOCAL_ADDR 2
|
||||
#define VXLAN_CMD_SET_REMOTE_ADDR 4
|
||||
#define VXLAN_CMD_SET_LOCAL_PORT 5
|
||||
#define VXLAN_CMD_SET_REMOTE_PORT 6
|
||||
#define VXLAN_CMD_SET_PORT_RANGE 7
|
||||
#define VXLAN_CMD_SET_FTABLE_TIMEOUT 8
|
||||
#define VXLAN_CMD_SET_FTABLE_MAX 9
|
||||
#define VXLAN_CMD_SET_MULTICAST_IF 10
|
||||
#define VXLAN_CMD_SET_TTL 11
|
||||
#define VXLAN_CMD_SET_LEARN 12
|
||||
#define VXLAN_CMD_FTABLE_ENTRY_ADD 13
|
||||
#define VXLAN_CMD_FTABLE_ENTRY_REM 14
|
||||
#define VXLAN_CMD_FLUSH 15
|
||||
|
||||
struct ifvxlancfg {
|
||||
uint32_t vxlc_vni;
|
||||
union vxlan_sockaddr vxlc_local_sa;
|
||||
union vxlan_sockaddr vxlc_remote_sa;
|
||||
uint32_t vxlc_mc_ifindex;
|
||||
uint32_t vxlc_ftable_cnt;
|
||||
uint32_t vxlc_ftable_max;
|
||||
uint32_t vxlc_ftable_timeout;
|
||||
uint16_t vxlc_port_min;
|
||||
uint16_t vxlc_port_max;
|
||||
uint8_t vxlc_learn;
|
||||
uint8_t vxlc_ttl;
|
||||
};
|
||||
|
||||
struct ifvxlancmd {
|
||||
uint32_t vxlcmd_flags;
|
||||
#define VXLAN_CMD_FLAG_FLUSH_ALL 0x0001
|
||||
#define VXLAN_CMD_FLAG_LEARN 0x0002
|
||||
|
||||
uint32_t vxlcmd_vni;
|
||||
uint32_t vxlcmd_ftable_timeout;
|
||||
uint32_t vxlcmd_ftable_max;
|
||||
uint16_t vxlcmd_port;
|
||||
uint16_t vxlcmd_port_min;
|
||||
uint16_t vxlcmd_port_max;
|
||||
uint8_t vxlcmd_mac[ETHER_ADDR_LEN];
|
||||
uint8_t vxlcmd_ttl;
|
||||
union vxlan_sockaddr vxlcmd_sa;
|
||||
char vxlcmd_ifname[IFNAMSIZ];
|
||||
};
|
||||
|
||||
#endif /* _NET_IF_VXLAN_H_ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,164 @@
|
|||
/*-
|
||||
* Copyright (c) 1988, 1989, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)radix.h 8.2 (Berkeley) 10/31/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _RADIX_H_
|
||||
#define _RADIX_H_
|
||||
|
||||
/*
|
||||
* Radix search tree node layout.
|
||||
*/
|
||||
|
||||
struct radix_node {
|
||||
struct radix_mask *rn_mklist; /* list of masks contained in subtree */
|
||||
struct radix_node *rn_parent; /* parent */
|
||||
short rn_bit; /* bit offset; -1-index(netmask) */
|
||||
char rn_bmask; /* node: mask for bit test*/
|
||||
u_char rn_flags; /* enumerated next */
|
||||
#define RNF_NORMAL 1 /* leaf contains normal route */
|
||||
#define RNF_ROOT 2 /* leaf is root leaf for tree */
|
||||
#define RNF_ACTIVE 4 /* This node is alive (for rtfree) */
|
||||
union {
|
||||
struct { /* leaf only data: */
|
||||
caddr_t rn_Key; /* object of search */
|
||||
caddr_t rn_Mask; /* netmask, if present */
|
||||
struct radix_node *rn_Dupedkey;
|
||||
} rn_leaf;
|
||||
struct { /* node only data: */
|
||||
int rn_Off; /* where to start compare */
|
||||
struct radix_node *rn_L;/* progeny */
|
||||
struct radix_node *rn_R;/* progeny */
|
||||
} rn_node;
|
||||
} rn_u;
|
||||
#ifdef RN_DEBUG
|
||||
int rn_info;
|
||||
struct radix_node *rn_twin;
|
||||
struct radix_node *rn_ybro;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
|
||||
#define rn_key rn_u.rn_leaf.rn_Key
|
||||
#define rn_mask rn_u.rn_leaf.rn_Mask
|
||||
#define rn_offset rn_u.rn_node.rn_Off
|
||||
#define rn_left rn_u.rn_node.rn_L
|
||||
#define rn_right rn_u.rn_node.rn_R
|
||||
|
||||
/*
|
||||
* Annotations to tree concerning potential routes applying to subtrees.
|
||||
*/
|
||||
|
||||
struct radix_mask {
|
||||
short rm_bit; /* bit offset; -1-index(netmask) */
|
||||
char rm_unused; /* cf. rn_bmask */
|
||||
u_char rm_flags; /* cf. rn_flags */
|
||||
struct radix_mask *rm_mklist; /* more masks to try */
|
||||
union {
|
||||
caddr_t rmu_mask; /* the mask */
|
||||
struct radix_node *rmu_leaf; /* for normal routes */
|
||||
} rm_rmu;
|
||||
int rm_refs; /* # of references to this struct */
|
||||
};
|
||||
|
||||
#define rm_mask rm_rmu.rmu_mask
|
||||
#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
|
||||
|
||||
struct radix_head;
|
||||
|
||||
typedef int walktree_f_t(struct radix_node *, void *);
|
||||
typedef struct radix_node *rn_matchaddr_f_t(void *v,
|
||||
struct radix_head *head);
|
||||
typedef struct radix_node *rn_addaddr_f_t(void *v, void *mask,
|
||||
struct radix_head *head, struct radix_node nodes[]);
|
||||
typedef struct radix_node *rn_deladdr_f_t(void *v, void *mask,
|
||||
struct radix_head *head);
|
||||
typedef struct radix_node *rn_lookup_f_t(void *v, void *mask,
|
||||
struct radix_head *head);
|
||||
typedef int rn_walktree_t(struct radix_head *head, walktree_f_t *f,
|
||||
void *w);
|
||||
typedef int rn_walktree_from_t(struct radix_head *head,
|
||||
void *a, void *m, walktree_f_t *f, void *w);
|
||||
typedef void rn_close_t(struct radix_node *rn, struct radix_head *head);
|
||||
|
||||
struct radix_mask_head;
|
||||
|
||||
struct radix_head {
|
||||
struct radix_node *rnh_treetop;
|
||||
struct radix_mask_head *rnh_masks; /* Storage for our masks */
|
||||
};
|
||||
|
||||
struct radix_node_head {
|
||||
struct radix_head rh;
|
||||
rn_matchaddr_f_t *rnh_matchaddr; /* longest match for sockaddr */
|
||||
rn_addaddr_f_t *rnh_addaddr; /* add based on sockaddr*/
|
||||
rn_deladdr_f_t *rnh_deladdr; /* remove based on sockaddr */
|
||||
rn_lookup_f_t *rnh_lookup; /* exact match for sockaddr */
|
||||
rn_walktree_t *rnh_walktree; /* traverse tree */
|
||||
rn_walktree_from_t *rnh_walktree_from; /* traverse tree below a */
|
||||
rn_close_t *rnh_close; /*do something when the last ref drops*/
|
||||
struct radix_node rnh_nodes[3]; /* empty tree for common case */
|
||||
#ifdef _KERNEL
|
||||
struct rwlock rnh_lock; /* locks entire radix tree */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct radix_mask_head {
|
||||
struct radix_head head;
|
||||
struct radix_node mask_nodes[3];
|
||||
};
|
||||
|
||||
void rn_inithead_internal(struct radix_head *rh, struct radix_node *base_nodes,
|
||||
int off);
|
||||
|
||||
#ifndef _KERNEL
|
||||
#define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
|
||||
#define R_Zalloc(p, t, n) (p = (t) calloc(1,(unsigned int)(n)))
|
||||
#define R_Free(p) free((char *)p);
|
||||
#else
|
||||
#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_NOWAIT))
|
||||
#define R_Zalloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_NOWAIT | M_ZERO))
|
||||
#define R_Free(p) free((caddr_t)p, M_RTABLE);
|
||||
|
||||
#define RADIX_NODE_HEAD_LOCK_INIT(rnh) \
|
||||
rw_init_flags(&(rnh)->rnh_lock, "radix node head", 0)
|
||||
#define RADIX_NODE_HEAD_LOCK(rnh) rw_wlock(&(rnh)->rnh_lock)
|
||||
#define RADIX_NODE_HEAD_UNLOCK(rnh) rw_wunlock(&(rnh)->rnh_lock)
|
||||
#define RADIX_NODE_HEAD_RLOCK(rnh) rw_rlock(&(rnh)->rnh_lock)
|
||||
#define RADIX_NODE_HEAD_RUNLOCK(rnh) rw_runlock(&(rnh)->rnh_lock)
|
||||
#define RADIX_NODE_HEAD_LOCK_TRY_UPGRADE(rnh) rw_try_upgrade(&(rnh)->rnh_lock)
|
||||
|
||||
|
||||
#define RADIX_NODE_HEAD_DESTROY(rnh) rw_destroy(&(rnh)->rnh_lock)
|
||||
#define RADIX_NODE_HEAD_LOCK_ASSERT(rnh) rw_assert(&(rnh)->rnh_lock, RA_LOCKED)
|
||||
#define RADIX_NODE_HEAD_WLOCK_ASSERT(rnh) rw_assert(&(rnh)->rnh_lock, RA_WLOCKED)
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* _RADIX_H_ */
|
|
@ -0,0 +1,336 @@
|
|||
/*-
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)route.h 8.4 (Berkeley) 1/9/95
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_ROUTE_H_
|
||||
#define _NET_ROUTE_H_
|
||||
|
||||
/*
|
||||
* Kernel resident routing tables.
|
||||
*
|
||||
* The routing tables are initialized when interface addresses
|
||||
* are set by making entries for all directly connected interfaces.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Struct route consiste of a destination address,
|
||||
* a route entry pointer, link-layer prepend data pointer along
|
||||
* with its length.
|
||||
*/
|
||||
struct route {
|
||||
struct rtentry *ro_rt;
|
||||
struct llentry *ro_lle;
|
||||
/*
|
||||
* ro_prepend and ro_plen are only used for bpf to pass in a
|
||||
* preformed header. They are not cacheable.
|
||||
*/
|
||||
char *ro_prepend;
|
||||
uint16_t ro_plen;
|
||||
uint16_t ro_flags;
|
||||
uint16_t ro_mtu; /* saved ro_rt mtu */
|
||||
uint16_t spare;
|
||||
struct sockaddr ro_dst;
|
||||
};
|
||||
|
||||
#define RT_L2_ME_BIT 2 /* dst L2 addr is our address */
|
||||
#define RT_MAY_LOOP_BIT 3 /* dst may require loop copy */
|
||||
#define RT_HAS_HEADER_BIT 4 /* mbuf already have its header prepended */
|
||||
|
||||
#define RT_CACHING_CONTEXT 0x1 /* XXX: not used anywhere */
|
||||
#define RT_NORTREF 0x2 /* doesn't hold reference on ro_rt */
|
||||
#define RT_L2_ME (1 << RT_L2_ME_BIT) /* 0x0004 */
|
||||
#define RT_MAY_LOOP (1 << RT_MAY_LOOP_BIT) /* 0x0008 */
|
||||
#define RT_HAS_HEADER (1 << RT_HAS_HEADER_BIT) /* 0x0010 */
|
||||
|
||||
#define RT_REJECT 0x0020 /* Destination is reject */
|
||||
#define RT_BLACKHOLE 0x0040 /* Destination is blackhole */
|
||||
#define RT_HAS_GW 0x0080 /* Destination has GW */
|
||||
#define RT_LLE_CACHE 0x0100 /* Cache link layer */
|
||||
|
||||
struct rt_metrics {
|
||||
u_long rmx_locks; /* Kernel must leave these values alone */
|
||||
u_long rmx_mtu; /* MTU for this path */
|
||||
u_long rmx_hopcount; /* max hops expected */
|
||||
u_long rmx_expire; /* lifetime for route, e.g. redirect */
|
||||
u_long rmx_recvpipe; /* inbound delay-bandwidth product */
|
||||
u_long rmx_sendpipe; /* outbound delay-bandwidth product */
|
||||
u_long rmx_ssthresh; /* outbound gateway buffer limit */
|
||||
u_long rmx_rtt; /* estimated round trip time */
|
||||
u_long rmx_rttvar; /* estimated rtt variance */
|
||||
u_long rmx_pksent; /* packets sent using this route */
|
||||
u_long rmx_weight; /* route weight */
|
||||
u_long rmx_filler[3]; /* will be used for T/TCP later */
|
||||
};
|
||||
|
||||
/*
|
||||
* rmx_rtt and rmx_rttvar are stored as microseconds;
|
||||
* RTTTOPRHZ(rtt) converts to a value suitable for use
|
||||
* by a protocol slowtimo counter.
|
||||
*/
|
||||
#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
|
||||
#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
|
||||
|
||||
/* lle state is exported in rmx_state rt_metrics field */
|
||||
#define rmx_state rmx_weight
|
||||
|
||||
/*
|
||||
* Keep a generation count of routing table, incremented on route addition,
|
||||
* so we can invalidate caches. This is accessed without a lock, as precision
|
||||
* is not required.
|
||||
*/
|
||||
typedef volatile u_int rt_gen_t; /* tree generation (for adds) */
|
||||
#define RT_GEN(fibnum, af) rt_tables_get_gen(fibnum, af)
|
||||
|
||||
#define RT_DEFAULT_FIB 0 /* Explicitly mark fib=0 restricted cases */
|
||||
#define RT_ALL_FIBS -1 /* Announce event for every fib */
|
||||
|
||||
#include "net/radix.h"
|
||||
|
||||
#if defined(_KERNEL) || defined(_WANT_RTENTRY)
|
||||
struct rtentry {
|
||||
struct radix_node rt_nodes[2]; /* tree glue, and other values */
|
||||
/*
|
||||
* XXX struct rtentry must begin with a struct radix_node (or two!)
|
||||
* because the code does some casts of a 'struct radix_node *'
|
||||
* to a 'struct rtentry *'
|
||||
*/
|
||||
#define rt_key(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_key)))
|
||||
#define rt_mask(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_mask)))
|
||||
struct sockaddr *rt_gateway; /* value */
|
||||
struct ifnet *rt_ifp; /* the answer: interface to use */
|
||||
struct ifaddr *rt_ifa; /* the answer: interface address to use */
|
||||
int rt_flags; /* up/down?, host/net */
|
||||
int rt_refcnt; /* # held references */
|
||||
u_int rt_fibnum; /* which FIB */
|
||||
u_long rt_mtu; /* MTU for this path */
|
||||
u_long rt_weight; /* absolute weight */
|
||||
u_long rt_expire; /* lifetime for route, e.g. redirect */
|
||||
#define rt_endzero rt_pksent
|
||||
counter_u64_t rt_pksent; /* packets sent using this route */
|
||||
struct mtx rt_mtx; /* mutex for routing entry */
|
||||
struct rtentry *rt_chain; /* pointer to next rtentry to delete */
|
||||
};
|
||||
#endif /* _KERNEL || _WANT_RTENTRY */
|
||||
|
||||
#define RTF_UP 0x1 /* route usable */
|
||||
#define RTF_GATEWAY 0x2 /* destination is a gateway */
|
||||
#define RTF_HOST 0x4 /* host entry (net otherwise) */
|
||||
#define RTF_REJECT 0x8 /* host or net unreachable */
|
||||
#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
|
||||
#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
|
||||
#define RTF_DONE 0x40 /* message confirmed */
|
||||
/* 0x80 unused, was RTF_DELCLONE */
|
||||
/* 0x100 unused, was RTF_CLONING */
|
||||
#define RTF_XRESOLVE 0x200 /* external daemon resolves name */
|
||||
#define RTF_LLINFO 0x400 /* DEPRECATED - exists ONLY for backward
|
||||
compatibility */
|
||||
#define RTF_LLDATA 0x400 /* used by apps to add/del L2 entries */
|
||||
#define RTF_STATIC 0x800 /* manually added */
|
||||
#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
|
||||
#define RTF_PROTO2 0x4000 /* protocol specific routing flag */
|
||||
#define RTF_PROTO1 0x8000 /* protocol specific routing flag */
|
||||
/* 0x10000 unused, was RTF_PRCLONING */
|
||||
/* 0x20000 unused, was RTF_WASCLONED */
|
||||
#define RTF_PROTO3 0x40000 /* protocol specific routing flag */
|
||||
#define RTF_FIXEDMTU 0x80000 /* MTU was explicitly specified */
|
||||
#define RTF_PINNED 0x100000 /* route is immutable */
|
||||
#define RTF_LOCAL 0x200000 /* route represents a local address */
|
||||
#define RTF_BROADCAST 0x400000 /* route represents a bcast address */
|
||||
#define RTF_MULTICAST 0x800000 /* route represents a mcast address */
|
||||
/* 0x8000000 and up unassigned */
|
||||
#define RTF_STICKY 0x10000000 /* always route dst->src */
|
||||
|
||||
#define RTF_RNH_LOCKED 0x40000000 /* unused */
|
||||
|
||||
#define RTF_GWFLAG_COMPAT 0x80000000 /* a compatibility bit for interacting
|
||||
with existing routing apps */
|
||||
|
||||
/* Mask of RTF flags that are allowed to be modified by RTM_CHANGE. */
|
||||
#define RTF_FMASK \
|
||||
(RTF_PROTO1 | RTF_PROTO2 | RTF_PROTO3 | RTF_BLACKHOLE | \
|
||||
RTF_REJECT | RTF_STATIC | RTF_STICKY)
|
||||
|
||||
/*
|
||||
* fib_ nexthop API flags.
|
||||
*/
|
||||
|
||||
/* Consumer-visible nexthop info flags */
|
||||
#define NHF_REJECT 0x0010 /* RTF_REJECT */
|
||||
#define NHF_BLACKHOLE 0x0020 /* RTF_BLACKHOLE */
|
||||
#define NHF_REDIRECT 0x0040 /* RTF_DYNAMIC|RTF_MODIFIED */
|
||||
#define NHF_DEFAULT 0x0080 /* Default route */
|
||||
#define NHF_BROADCAST 0x0100 /* RTF_BROADCAST */
|
||||
#define NHF_GATEWAY 0x0200 /* RTF_GATEWAY */
|
||||
|
||||
/* Nexthop request flags */
|
||||
#define NHR_IFAIF 0x01 /* Return ifa_ifp interface */
|
||||
#define NHR_REF 0x02 /* For future use */
|
||||
|
||||
/* Control plane route request flags */
|
||||
#define NHR_COPY 0x100 /* Copy rte data */
|
||||
|
||||
#ifdef _KERNEL
|
||||
/* rte<>ro_flags translation */
|
||||
static inline void
|
||||
rt_update_ro_flags(struct route *ro)
|
||||
{
|
||||
int rt_flags = ro->ro_rt->rt_flags;
|
||||
|
||||
ro->ro_flags &= ~ (RT_REJECT|RT_BLACKHOLE|RT_HAS_GW);
|
||||
|
||||
ro->ro_flags |= (rt_flags & RTF_REJECT) ? RT_REJECT : 0;
|
||||
ro->ro_flags |= (rt_flags & RTF_BLACKHOLE) ? RT_BLACKHOLE : 0;
|
||||
ro->ro_flags |= (rt_flags & RTF_GATEWAY) ? RT_HAS_GW : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Routing statistics.
|
||||
*/
|
||||
struct rtstat {
|
||||
short rts_badredirect; /* bogus redirect calls */
|
||||
short rts_dynamic; /* routes created by redirects */
|
||||
short rts_newgateway; /* routes modified by redirects */
|
||||
short rts_unreach; /* lookups which failed */
|
||||
short rts_wildcard; /* lookups satisfied by a wildcard */
|
||||
};
|
||||
/*
|
||||
* Structures for routing messages.
|
||||
*/
|
||||
struct rt_msghdr {
|
||||
u_short rtm_msglen; /* to skip over non-understood messages */
|
||||
u_char rtm_version; /* future binary compatibility */
|
||||
u_char rtm_type; /* message type */
|
||||
u_short rtm_index; /* index for associated ifp */
|
||||
int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
|
||||
int rtm_addrs; /* bitmask identifying sockaddrs in msg */
|
||||
pid_t rtm_pid; /* identify sender */
|
||||
int rtm_seq; /* for sender to identify action */
|
||||
int rtm_errno; /* why failed */
|
||||
int rtm_fmask; /* bitmask used in RTM_CHANGE message */
|
||||
u_long rtm_inits; /* which metrics we are initializing */
|
||||
struct rt_metrics rtm_rmx; /* metrics themselves */
|
||||
};
|
||||
|
||||
#define RTM_VERSION 5 /* Up the ante and ignore older versions */
|
||||
|
||||
/*
|
||||
* Message types.
|
||||
*/
|
||||
#define RTM_ADD 0x1 /* Add Route */
|
||||
#define RTM_DELETE 0x2 /* Delete Route */
|
||||
#define RTM_CHANGE 0x3 /* Change Metrics or flags */
|
||||
#define RTM_GET 0x4 /* Report Metrics */
|
||||
#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
|
||||
#define RTM_REDIRECT 0x6 /* Told to use different route */
|
||||
#define RTM_MISS 0x7 /* Lookup failed on this address */
|
||||
#define RTM_LOCK 0x8 /* fix specified metrics */
|
||||
/* 0x9 */
|
||||
/* 0xa */
|
||||
#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
|
||||
#define RTM_NEWADDR 0xc /* address being added to iface */
|
||||
#define RTM_DELADDR 0xd /* address being removed from iface */
|
||||
#define RTM_IFINFO 0xe /* iface going up/down etc. */
|
||||
#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
|
||||
#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */
|
||||
#define RTM_IFANNOUNCE 0x11 /* iface arrival/departure */
|
||||
#define RTM_IEEE80211 0x12 /* IEEE80211 wireless event */
|
||||
|
||||
/*
|
||||
* Bitmask values for rtm_inits and rmx_locks.
|
||||
*/
|
||||
#define RTV_MTU 0x1 /* init or lock _mtu */
|
||||
#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
|
||||
#define RTV_EXPIRE 0x4 /* init or lock _expire */
|
||||
#define RTV_RPIPE 0x8 /* init or lock _recvpipe */
|
||||
#define RTV_SPIPE 0x10 /* init or lock _sendpipe */
|
||||
#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
|
||||
#define RTV_RTT 0x40 /* init or lock _rtt */
|
||||
#define RTV_RTTVAR 0x80 /* init or lock _rttvar */
|
||||
#define RTV_WEIGHT 0x100 /* init or lock _weight */
|
||||
|
||||
/*
|
||||
* Bitmask values for rtm_addrs.
|
||||
*/
|
||||
#define RTA_DST 0x1 /* destination sockaddr present */
|
||||
#define RTA_GATEWAY 0x2 /* gateway sockaddr present */
|
||||
#define RTA_NETMASK 0x4 /* netmask sockaddr present */
|
||||
#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
|
||||
#define RTA_IFP 0x10 /* interface name sockaddr present */
|
||||
#define RTA_IFA 0x20 /* interface addr sockaddr present */
|
||||
#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
|
||||
#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
|
||||
|
||||
/*
|
||||
* Index offsets for sockaddr array for alternate internal encoding.
|
||||
*/
|
||||
#define RTAX_DST 0 /* destination sockaddr present */
|
||||
#define RTAX_GATEWAY 1 /* gateway sockaddr present */
|
||||
#define RTAX_NETMASK 2 /* netmask sockaddr present */
|
||||
#define RTAX_GENMASK 3 /* cloning mask sockaddr present */
|
||||
#define RTAX_IFP 4 /* interface name sockaddr present */
|
||||
#define RTAX_IFA 5 /* interface addr sockaddr present */
|
||||
#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
|
||||
#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
|
||||
#define RTAX_MAX 8 /* size of array to allocate */
|
||||
|
||||
typedef int rt_filter_f_t(const struct rtentry *, void *);
|
||||
|
||||
struct rt_addrinfo {
|
||||
int rti_addrs; /* Route RTF_ flags */
|
||||
int rti_flags; /* Route RTF_ flags */
|
||||
struct sockaddr *rti_info[RTAX_MAX]; /* Sockaddr data */
|
||||
struct ifaddr *rti_ifa; /* value of rt_ifa addr */
|
||||
struct ifnet *rti_ifp; /* route interface */
|
||||
rt_filter_f_t *rti_filter; /* filter function */
|
||||
void *rti_filterdata; /* filter paramenters */
|
||||
u_long rti_mflags; /* metrics RTV_ flags */
|
||||
u_long rti_spare; /* Will be used for fib */
|
||||
struct rt_metrics *rti_rmx; /* Pointer to route metrics */
|
||||
};
|
||||
|
||||
/*
|
||||
* This macro returns the size of a struct sockaddr when passed
|
||||
* through a routing socket. Basically we round up sa_len to
|
||||
* a multiple of sizeof(long), with a minimum of sizeof(long).
|
||||
* The check for a NULL pointer is just a convenience, probably never used.
|
||||
* The case sa_len == 0 should only apply to empty structures.
|
||||
*/
|
||||
#define SA_SIZE(sa) \
|
||||
( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \
|
||||
sizeof(long) : \
|
||||
1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
|
||||
|
||||
#define sa_equal(a, b) ( \
|
||||
(((const struct sockaddr *)(a))->sa_len == ((const struct sockaddr *)(b))->sa_len) && \
|
||||
(bcmp((a), (b), ((const struct sockaddr *)(b))->sa_len) == 0))
|
||||
|
||||
#endif
|
|
@ -0,0 +1,230 @@
|
|||
/*-
|
||||
* Copyright (c) 1980, 1983, 1988, 1993
|
||||
* The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)netdb.h 8.1 (Berkeley) 6/2/93
|
||||
* From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETDB_H_
|
||||
#define _NETDB_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef _IN_ADDR_T_DECLARED
|
||||
typedef __uint32_t in_addr_t;
|
||||
#define _IN_ADDR_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _IN_PORT_T_DECLARED
|
||||
typedef __uint16_t in_port_t;
|
||||
#define _IN_PORT_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _SIZE_T_DECLARED
|
||||
typedef __size_t size_t;
|
||||
#define _SIZE_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _SOCKLEN_T_DECLARED
|
||||
typedef __socklen_t socklen_t;
|
||||
#define _SOCKLEN_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _UINT32_T_DECLARED
|
||||
typedef __uint32_t uint32_t;
|
||||
#define _UINT32_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_HEQUIV
|
||||
# define _PATH_HEQUIV "/etc/hosts.equiv"
|
||||
#endif
|
||||
#define _PATH_HOSTS "/etc/hosts"
|
||||
#define _PATH_NETWORKS "/etc/networks"
|
||||
#define _PATH_PROTOCOLS "/etc/protocols"
|
||||
#define _PATH_SERVICES "/etc/services"
|
||||
#define _PATH_SERVICES_DB "/var/db/services.db"
|
||||
|
||||
#define h_errno (*__h_errno())
|
||||
|
||||
/*
|
||||
* Structures returned by network data base library. All addresses are
|
||||
* supplied in host order, and returned in network order (suitable for
|
||||
* use in system calls).
|
||||
*/
|
||||
struct hostent {
|
||||
char *h_name; /* official name of host */
|
||||
char **h_aliases; /* alias list */
|
||||
int h_addrtype; /* host address type */
|
||||
int h_length; /* length of address */
|
||||
char **h_addr_list; /* list of addresses from name server */
|
||||
#define h_addr h_addr_list[0] /* address, for backward compatibility */
|
||||
};
|
||||
|
||||
struct netent {
|
||||
char *n_name; /* official name of net */
|
||||
char **n_aliases; /* alias list */
|
||||
int n_addrtype; /* net address type */
|
||||
uint32_t n_net; /* network # */
|
||||
};
|
||||
|
||||
struct servent {
|
||||
char *s_name; /* official service name */
|
||||
char **s_aliases; /* alias list */
|
||||
int s_port; /* port # */
|
||||
char *s_proto; /* protocol to use */
|
||||
};
|
||||
|
||||
struct protoent {
|
||||
char *p_name; /* official protocol name */
|
||||
char **p_aliases; /* alias list */
|
||||
int p_proto; /* protocol # */
|
||||
};
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
|
||||
int ai_family; /* AF_xxx */
|
||||
int ai_socktype; /* SOCK_xxx */
|
||||
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||
socklen_t ai_addrlen; /* length of ai_addr */
|
||||
char *ai_canonname; /* canonical name for hostname */
|
||||
struct sockaddr *ai_addr; /* binary address */
|
||||
struct addrinfo *ai_next; /* next structure in linked list */
|
||||
};
|
||||
|
||||
#define IPPORT_RESERVED 1024
|
||||
|
||||
/*
|
||||
* Error return codes from gethostbyname() and gethostbyaddr()
|
||||
* (left in h_errno).
|
||||
*/
|
||||
|
||||
#define NETDB_INTERNAL -1 /* see errno */
|
||||
#define NETDB_SUCCESS 0 /* no problem */
|
||||
#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
|
||||
#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
|
||||
#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
||||
#define NO_DATA 4 /* Valid name, no data record of requested type */
|
||||
#define NO_ADDRESS NO_DATA /* no address, look for MX record */
|
||||
|
||||
/*
|
||||
* Error return codes from getaddrinfo()
|
||||
*/
|
||||
#if 0
|
||||
/* obsoleted */
|
||||
#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
|
||||
#endif
|
||||
#define EAI_AGAIN 2 /* temporary failure in name resolution */
|
||||
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
|
||||
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
|
||||
#define EAI_FAMILY 5 /* ai_family not supported */
|
||||
#define EAI_MEMORY 6 /* memory allocation failure */
|
||||
#if 0
|
||||
/* obsoleted */
|
||||
#define EAI_NODATA 7 /* no address associated with hostname */
|
||||
#endif
|
||||
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
|
||||
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
|
||||
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
|
||||
#define EAI_SYSTEM 11 /* system error returned in errno */
|
||||
#define EAI_BADHINTS 12 /* invalid value for hints */
|
||||
#define EAI_PROTOCOL 13 /* resolved protocol is unknown */
|
||||
#define EAI_OVERFLOW 14 /* argument buffer overflow */
|
||||
#define EAI_MAX 15
|
||||
|
||||
/*
|
||||
* Flag values for getaddrinfo()
|
||||
*/
|
||||
#define AI_PASSIVE 0x00000001 /* get address to use bind() */
|
||||
#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
|
||||
#define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */
|
||||
#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */
|
||||
/* valid flags for addrinfo (not a standard def, apps should not use it) */
|
||||
#define AI_MASK \
|
||||
(AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
|
||||
AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED)
|
||||
|
||||
#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
|
||||
#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
|
||||
#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
|
||||
#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
|
||||
/* special recommended flags for getipnodebyname */
|
||||
#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
|
||||
|
||||
/*
|
||||
* Constants for getnameinfo()
|
||||
*/
|
||||
#define NI_MAXHOST 1025
|
||||
#define NI_MAXSERV 32
|
||||
|
||||
/*
|
||||
* Flag values for getnameinfo()
|
||||
*/
|
||||
#define NI_NOFQDN 0x00000001
|
||||
#define NI_NUMERICHOST 0x00000002
|
||||
#define NI_NAMEREQD 0x00000004
|
||||
#define NI_NUMERICSERV 0x00000008
|
||||
#define NI_DGRAM 0x00000010
|
||||
#if 0 /* obsolete */
|
||||
#define NI_WITHSCOPEID 0x00000020
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Scope delimit character
|
||||
*/
|
||||
#define SCOPE_DELIMITER '%'
|
||||
|
||||
int getaddrinfo(const char *, const char *,
|
||||
const struct addrinfo *, struct addrinfo **);
|
||||
void freeaddrinfo(struct addrinfo *);
|
||||
const char *gai_strerror(int ecode);
|
||||
|
||||
#endif /* !_NETDB_H_ */
|
|
@ -0,0 +1,611 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1986, 1990, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)in.h 8.3 (Berkeley) 1/3/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_NETINET_IN_H_
|
||||
#define _COMPAT_NETINET_IN_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/_types.h>
|
||||
|
||||
/* Protocols common to RFC 1700, POSIX, and X/Open. */
|
||||
#define IPPROTO_IP 0 /* dummy for IP */
|
||||
#define IPPROTO_ICMP 1 /* control message protocol */
|
||||
#define IPPROTO_TCP 6 /* tcp */
|
||||
#define IPPROTO_UDP 17 /* user datagram protocol */
|
||||
|
||||
#define INADDR_ANY ((in_addr_t)0x00000000)
|
||||
#define INADDR_BROADCAST ((in_addr_t)0xffffffff) /* must be masked */
|
||||
|
||||
#ifndef _UINT8_T_DECLARED
|
||||
typedef __uint8_t uint8_t;
|
||||
#define _UINT8_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _UINT16_T_DECLARED
|
||||
typedef __uint16_t uint16_t;
|
||||
#define _UINT16_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _UINT32_T_DECLARED
|
||||
typedef __uint32_t uint32_t;
|
||||
#define _UINT32_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _IN_ADDR_T_DECLARED
|
||||
typedef uint32_t in_addr_t;
|
||||
#define _IN_ADDR_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _IN_PORT_T_DECLARED
|
||||
typedef uint16_t in_port_t;
|
||||
#define _IN_PORT_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _SA_FAMILY_T_DECLARED
|
||||
typedef __sa_family_t sa_family_t;
|
||||
#define _SA_FAMILY_T_DECLARED
|
||||
#endif
|
||||
|
||||
/* Internet address (a structure for historical reasons). */
|
||||
#ifndef _STRUCT_IN_ADDR_DECLARED
|
||||
struct in_addr {
|
||||
in_addr_t s_addr;
|
||||
};
|
||||
#define _STRUCT_IN_ADDR_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _SOCKLEN_T_DECLARED
|
||||
typedef __socklen_t socklen_t;
|
||||
#define _SOCKLEN_T_DECLARED
|
||||
#endif
|
||||
|
||||
#include <sys/_sockaddr_storage.h>
|
||||
|
||||
/* Socket address, internet style. */
|
||||
struct sockaddr_in {
|
||||
uint8_t sin_len;
|
||||
sa_family_t sin_family;
|
||||
in_port_t sin_port;
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
};
|
||||
|
||||
#ifndef _BYTEORDER_PROTOTYPED
|
||||
#define _BYTEORDER_PROTOTYPED
|
||||
extern uint32_t htonl(uint32_t);
|
||||
extern uint16_t htons(uint16_t);
|
||||
extern uint32_t ntohl(uint32_t);
|
||||
extern uint16_t ntohs(uint16_t);
|
||||
#endif
|
||||
|
||||
#if __POSIX_VISIBLE >= 200112
|
||||
#define IPPROTO_IPV6 41 /* IP6 header */
|
||||
#define IPPROTO_RAW 255 /* raw IP packet */
|
||||
#define INET_ADDRSTRLEN 16
|
||||
#endif
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* Constants and structures defined by the internet system,
|
||||
* Per RFC 790, September 1981, and numerous additions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Protocols (RFC 1700)
|
||||
*/
|
||||
#define IPPROTO_HOPOPTS 0 /* IP6 hop-by-hop options */
|
||||
#define IPPROTO_IGMP 2 /* group mgmt protocol */
|
||||
#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
|
||||
#define IPPROTO_IPV4 4 /* IPv4 encapsulation */
|
||||
#define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */
|
||||
#define IPPROTO_ST 7 /* Stream protocol II */
|
||||
#define IPPROTO_EGP 8 /* exterior gateway protocol */
|
||||
#define IPPROTO_PIGP 9 /* private interior gateway */
|
||||
#define IPPROTO_RCCMON 10 /* BBN RCC Monitoring */
|
||||
#define IPPROTO_NVPII 11 /* network voice protocol*/
|
||||
#define IPPROTO_PUP 12 /* pup */
|
||||
#define IPPROTO_ARGUS 13 /* Argus */
|
||||
#define IPPROTO_EMCON 14 /* EMCON */
|
||||
#define IPPROTO_XNET 15 /* Cross Net Debugger */
|
||||
#define IPPROTO_CHAOS 16 /* Chaos*/
|
||||
#define IPPROTO_MUX 18 /* Multiplexing */
|
||||
#define IPPROTO_MEAS 19 /* DCN Measurement Subsystems */
|
||||
#define IPPROTO_HMP 20 /* Host Monitoring */
|
||||
#define IPPROTO_PRM 21 /* Packet Radio Measurement */
|
||||
#define IPPROTO_IDP 22 /* xns idp */
|
||||
#define IPPROTO_TRUNK1 23 /* Trunk-1 */
|
||||
#define IPPROTO_TRUNK2 24 /* Trunk-2 */
|
||||
#define IPPROTO_LEAF1 25 /* Leaf-1 */
|
||||
#define IPPROTO_LEAF2 26 /* Leaf-2 */
|
||||
#define IPPROTO_RDP 27 /* Reliable Data */
|
||||
#define IPPROTO_IRTP 28 /* Reliable Transaction */
|
||||
#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */
|
||||
#define IPPROTO_BLT 30 /* Bulk Data Transfer */
|
||||
#define IPPROTO_NSP 31 /* Network Services */
|
||||
#define IPPROTO_INP 32 /* Merit Internodal */
|
||||
#define IPPROTO_SEP 33 /* Sequential Exchange */
|
||||
#define IPPROTO_3PC 34 /* Third Party Connect */
|
||||
#define IPPROTO_IDPR 35 /* InterDomain Policy Routing */
|
||||
#define IPPROTO_XTP 36 /* XTP */
|
||||
#define IPPROTO_DDP 37 /* Datagram Delivery */
|
||||
#define IPPROTO_CMTP 38 /* Control Message Transport */
|
||||
#define IPPROTO_TPXX 39 /* TP++ Transport */
|
||||
#define IPPROTO_IL 40 /* IL transport protocol */
|
||||
#define IPPROTO_SDRP 42 /* Source Demand Routing */
|
||||
#define IPPROTO_ROUTING 43 /* IP6 routing header */
|
||||
#define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */
|
||||
#define IPPROTO_IDRP 45 /* InterDomain Routing*/
|
||||
#define IPPROTO_RSVP 46 /* resource reservation */
|
||||
#define IPPROTO_GRE 47 /* General Routing Encap. */
|
||||
#define IPPROTO_MHRP 48 /* Mobile Host Routing */
|
||||
#define IPPROTO_BHA 49 /* BHA */
|
||||
#define IPPROTO_ESP 50 /* IP6 Encap Sec. Payload */
|
||||
#define IPPROTO_AH 51 /* IP6 Auth Header */
|
||||
#define IPPROTO_INLSP 52 /* Integ. Net Layer Security */
|
||||
#define IPPROTO_SWIPE 53 /* IP with encryption */
|
||||
#define IPPROTO_NHRP 54 /* Next Hop Resolution */
|
||||
#define IPPROTO_MOBILE 55 /* IP Mobility */
|
||||
#define IPPROTO_TLSP 56 /* Transport Layer Security */
|
||||
#define IPPROTO_SKIP 57 /* SKIP */
|
||||
#define IPPROTO_ICMPV6 58 /* ICMP6 */
|
||||
#define IPPROTO_NONE 59 /* IP6 no next header */
|
||||
#define IPPROTO_DSTOPTS 60 /* IP6 destination option */
|
||||
#define IPPROTO_AHIP 61 /* any host internal protocol */
|
||||
#define IPPROTO_CFTP 62 /* CFTP */
|
||||
#define IPPROTO_HELLO 63 /* "hello" routing protocol */
|
||||
#define IPPROTO_SATEXPAK 64 /* SATNET/Backroom EXPAK */
|
||||
#define IPPROTO_KRYPTOLAN 65 /* Kryptolan */
|
||||
#define IPPROTO_RVD 66 /* Remote Virtual Disk */
|
||||
#define IPPROTO_IPPC 67 /* Pluribus Packet Core */
|
||||
#define IPPROTO_ADFS 68 /* Any distributed FS */
|
||||
#define IPPROTO_SATMON 69 /* Satnet Monitoring */
|
||||
#define IPPROTO_VISA 70 /* VISA Protocol */
|
||||
#define IPPROTO_IPCV 71 /* Packet Core Utility */
|
||||
#define IPPROTO_CPNX 72 /* Comp. Prot. Net. Executive */
|
||||
#define IPPROTO_CPHB 73 /* Comp. Prot. HeartBeat */
|
||||
#define IPPROTO_WSN 74 /* Wang Span Network */
|
||||
#define IPPROTO_PVP 75 /* Packet Video Protocol */
|
||||
#define IPPROTO_BRSATMON 76 /* BackRoom SATNET Monitoring */
|
||||
#define IPPROTO_ND 77 /* Sun net disk proto (temp.) */
|
||||
#define IPPROTO_WBMON 78 /* WIDEBAND Monitoring */
|
||||
#define IPPROTO_WBEXPAK 79 /* WIDEBAND EXPAK */
|
||||
#define IPPROTO_EON 80 /* ISO cnlp */
|
||||
#define IPPROTO_VMTP 81 /* VMTP */
|
||||
#define IPPROTO_SVMTP 82 /* Secure VMTP */
|
||||
#define IPPROTO_VINES 83 /* Banyon VINES */
|
||||
#define IPPROTO_TTP 84 /* TTP */
|
||||
#define IPPROTO_IGP 85 /* NSFNET-IGP */
|
||||
#define IPPROTO_DGP 86 /* dissimilar gateway prot. */
|
||||
#define IPPROTO_TCF 87 /* TCF */
|
||||
#define IPPROTO_IGRP 88 /* Cisco/GXS IGRP */
|
||||
#define IPPROTO_OSPFIGP 89 /* OSPFIGP */
|
||||
#define IPPROTO_SRPC 90 /* Strite RPC protocol */
|
||||
#define IPPROTO_LARP 91 /* Locus Address Resoloution */
|
||||
#define IPPROTO_MTP 92 /* Multicast Transport */
|
||||
#define IPPROTO_AX25 93 /* AX.25 Frames */
|
||||
#define IPPROTO_IPEIP 94 /* IP encapsulated in IP */
|
||||
#define IPPROTO_MICP 95 /* Mobile Int.ing control */
|
||||
#define IPPROTO_SCCSP 96 /* Semaphore Comm. security */
|
||||
#define IPPROTO_ETHERIP 97 /* Ethernet IP encapsulation */
|
||||
#define IPPROTO_ENCAP 98 /* encapsulation header */
|
||||
#define IPPROTO_APES 99 /* any private encr. scheme */
|
||||
#define IPPROTO_GMTP 100 /* GMTP*/
|
||||
#define IPPROTO_IPCOMP 108 /* payload compression (IPComp) */
|
||||
#define IPPROTO_SCTP 132 /* SCTP */
|
||||
#define IPPROTO_MH 135 /* IPv6 Mobility Header */
|
||||
#define IPPROTO_UDPLITE 136 /* UDP-Lite */
|
||||
#define IPPROTO_HIP 139 /* IP6 Host Identity Protocol */
|
||||
#define IPPROTO_SHIM6 140 /* IP6 Shim6 Protocol */
|
||||
/* 101-254: Partly Unassigned */
|
||||
#define IPPROTO_PIM 103 /* Protocol Independent Mcast */
|
||||
#define IPPROTO_CARP 112 /* CARP */
|
||||
#define IPPROTO_PGM 113 /* PGM */
|
||||
#define IPPROTO_MPLS 137 /* MPLS-in-IP */
|
||||
#define IPPROTO_PFSYNC 240 /* PFSYNC */
|
||||
#define IPPROTO_RESERVED_253 253 /* Reserved */
|
||||
#define IPPROTO_RESERVED_254 254 /* Reserved */
|
||||
/* 255: Reserved */
|
||||
/* BSD Private, local use, namespace incursion, no longer used */
|
||||
#define IPPROTO_OLD_DIVERT 254 /* OLD divert pseudo-proto */
|
||||
#define IPPROTO_MAX 256
|
||||
|
||||
/* last return value of *_input(), meaning "all job for this pkt is done". */
|
||||
#define IPPROTO_DONE 257
|
||||
|
||||
/* Only used internally, so can be outside the range of valid IP protocols. */
|
||||
#define IPPROTO_DIVERT 258 /* divert pseudo-protocol */
|
||||
#define IPPROTO_SEND 259 /* SeND pseudo-protocol */
|
||||
|
||||
/*
|
||||
* Defined to avoid confusion. The master value is defined by
|
||||
* PROTO_SPACER in sys/protosw.h.
|
||||
*/
|
||||
#define IPPROTO_SPACER 32767 /* spacer for loadable protos */
|
||||
|
||||
/*
|
||||
* Local port number conventions:
|
||||
*
|
||||
* When a user does a bind(2) or connect(2) with a port number of zero,
|
||||
* a non-conflicting local port address is chosen.
|
||||
* The default range is IPPORT_HIFIRSTAUTO through
|
||||
* IPPORT_HILASTAUTO, although that is settable by sysctl.
|
||||
*
|
||||
* A user may set the IPPROTO_IP option IP_PORTRANGE to change this
|
||||
* default assignment range.
|
||||
*
|
||||
* The value IP_PORTRANGE_DEFAULT causes the default behavior.
|
||||
*
|
||||
* The value IP_PORTRANGE_HIGH changes the range of candidate port numbers
|
||||
* into the "high" range. These are reserved for client outbound connections
|
||||
* which do not want to be filtered by any firewalls.
|
||||
*
|
||||
* The value IP_PORTRANGE_LOW changes the range to the "low" are
|
||||
* that is (by convention) restricted to privileged processes. This
|
||||
* convention is based on "vouchsafe" principles only. It is only secure
|
||||
* if you trust the remote host to restrict these ports.
|
||||
*
|
||||
* The default range of ports and the high range can be changed by
|
||||
* sysctl(3). (net.inet.ip.port{hi,low}{first,last}_auto)
|
||||
*
|
||||
* Changing those values has bad security implications if you are
|
||||
* using a stateless firewall that is allowing packets outside of that
|
||||
* range in order to allow transparent outgoing connections.
|
||||
*
|
||||
* Such a firewall configuration will generally depend on the use of these
|
||||
* default values. If you change them, you may find your Security
|
||||
* Administrator looking for you with a heavy object.
|
||||
*
|
||||
* For a slightly more orthodox text view on this:
|
||||
*
|
||||
* ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers
|
||||
*
|
||||
* port numbers are divided into three ranges:
|
||||
*
|
||||
* 0 - 1023 Well Known Ports
|
||||
* 1024 - 49151 Registered Ports
|
||||
* 49152 - 65535 Dynamic and/or Private Ports
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ports < IPPORT_RESERVED are reserved for
|
||||
* privileged processes (e.g. root). (IP_PORTRANGE_LOW)
|
||||
*/
|
||||
#define IPPORT_RESERVED 1024
|
||||
|
||||
/*
|
||||
* Default local port range, used by IP_PORTRANGE_DEFAULT
|
||||
*/
|
||||
#define IPPORT_EPHEMERALFIRST 10000
|
||||
#define IPPORT_EPHEMERALLAST 65535
|
||||
|
||||
/*
|
||||
* Dynamic port range, used by IP_PORTRANGE_HIGH.
|
||||
*/
|
||||
#define IPPORT_HIFIRSTAUTO 49152
|
||||
#define IPPORT_HILASTAUTO 65535
|
||||
|
||||
/*
|
||||
* Scanning for a free reserved port return a value below IPPORT_RESERVED,
|
||||
* but higher than IPPORT_RESERVEDSTART. Traditionally the start value was
|
||||
* 512, but that conflicts with some well-known-services that firewalls may
|
||||
* have a fit if we use.
|
||||
*/
|
||||
#define IPPORT_RESERVEDSTART 600
|
||||
|
||||
#define IPPORT_MAX 65535
|
||||
|
||||
/*
|
||||
* Definitions of bits in internet address integers.
|
||||
* On subnets, the decomposition of addresses to host and net parts
|
||||
* is done according to subnet mask, not the masks here.
|
||||
*/
|
||||
#define IN_CLASSA(i) (((in_addr_t)(i) & 0x80000000) == 0)
|
||||
#define IN_CLASSA_NET 0xff000000
|
||||
#define IN_CLASSA_NSHIFT 24
|
||||
#define IN_CLASSA_HOST 0x00ffffff
|
||||
#define IN_CLASSA_MAX 128
|
||||
|
||||
#define IN_CLASSB(i) (((in_addr_t)(i) & 0xc0000000) == 0x80000000)
|
||||
#define IN_CLASSB_NET 0xffff0000
|
||||
#define IN_CLASSB_NSHIFT 16
|
||||
#define IN_CLASSB_HOST 0x0000ffff
|
||||
#define IN_CLASSB_MAX 65536
|
||||
|
||||
#define IN_CLASSC(i) (((in_addr_t)(i) & 0xe0000000) == 0xc0000000)
|
||||
#define IN_CLASSC_NET 0xffffff00
|
||||
#define IN_CLASSC_NSHIFT 8
|
||||
#define IN_CLASSC_HOST 0x000000ff
|
||||
|
||||
#define IN_CLASSD(i) (((in_addr_t)(i) & 0xf0000000) == 0xe0000000)
|
||||
#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
|
||||
#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
|
||||
#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
|
||||
#define IN_MULTICAST(i) IN_CLASSD(i)
|
||||
|
||||
#define IN_EXPERIMENTAL(i) (((in_addr_t)(i) & 0xf0000000) == 0xf0000000)
|
||||
#define IN_BADCLASS(i) (((in_addr_t)(i) & 0xf0000000) == 0xf0000000)
|
||||
|
||||
#define IN_LINKLOCAL(i) (((in_addr_t)(i) & 0xffff0000) == 0xa9fe0000)
|
||||
#define IN_LOOPBACK(i) (((in_addr_t)(i) & 0xff000000) == 0x7f000000)
|
||||
#define IN_ZERONET(i) (((in_addr_t)(i) & 0xff000000) == 0)
|
||||
|
||||
#define IN_PRIVATE(i) ((((in_addr_t)(i) & 0xff000000) == 0x0a000000) || \
|
||||
(((in_addr_t)(i) & 0xfff00000) == 0xac100000) || \
|
||||
(((in_addr_t)(i) & 0xffff0000) == 0xc0a80000))
|
||||
|
||||
#define IN_LOCAL_GROUP(i) (((in_addr_t)(i) & 0xffffff00) == 0xe0000000)
|
||||
|
||||
#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i))
|
||||
|
||||
#define INADDR_LOOPBACK ((in_addr_t)0x7f000001)
|
||||
#ifndef _KERNEL
|
||||
#define INADDR_NONE ((in_addr_t)0xffffffff) /* -1 return */
|
||||
#endif
|
||||
|
||||
#define INADDR_UNSPEC_GROUP ((in_addr_t)0xe0000000) /* 224.0.0.0 */
|
||||
#define INADDR_ALLHOSTS_GROUP ((in_addr_t)0xe0000001) /* 224.0.0.1 */
|
||||
#define INADDR_ALLRTRS_GROUP ((in_addr_t)0xe0000002) /* 224.0.0.2 */
|
||||
#define INADDR_ALLRPTS_GROUP ((in_addr_t)0xe0000016) /* 224.0.0.22, IGMPv3 */
|
||||
#define INADDR_CARP_GROUP ((in_addr_t)0xe0000012) /* 224.0.0.18 */
|
||||
#define INADDR_PFSYNC_GROUP ((in_addr_t)0xe00000f0) /* 224.0.0.240 */
|
||||
#define INADDR_ALLMDNS_GROUP ((in_addr_t)0xe00000fb) /* 224.0.0.251 */
|
||||
#define INADDR_MAX_LOCAL_GROUP ((in_addr_t)0xe00000ff) /* 224.0.0.255 */
|
||||
|
||||
#define IN_LOOPBACKNET 127 /* official! */
|
||||
|
||||
#define IN_RFC3021_MASK ((in_addr_t)0xfffffffe)
|
||||
|
||||
/*
|
||||
* Options for use with [gs]etsockopt at the IP level.
|
||||
* First word of comment is data type; bool is stored in int.
|
||||
*/
|
||||
#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */
|
||||
#define IP_HDRINCL 2 /* int; header is included with data */
|
||||
#define IP_TOS 3 /* int; IP type of service and preced. */
|
||||
#define IP_TTL 4 /* int; IP time to live */
|
||||
#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */
|
||||
#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */
|
||||
#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */
|
||||
#define IP_SENDSRCADDR IP_RECVDSTADDR /* cmsg_type to set src addr */
|
||||
#define IP_RETOPTS 8 /* ip_opts; set/get IP options */
|
||||
#define IP_MULTICAST_IF 9 /* struct in_addr *or* struct ip_mreqn;
|
||||
* set/get IP multicast i/f */
|
||||
#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */
|
||||
#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */
|
||||
#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */
|
||||
#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */
|
||||
#define IP_MULTICAST_VIF 14 /* set/get IP mcast virt. iface */
|
||||
#define IP_RSVP_ON 15 /* enable RSVP in kernel */
|
||||
#define IP_RSVP_OFF 16 /* disable RSVP in kernel */
|
||||
#define IP_RSVP_VIF_ON 17 /* set RSVP per-vif socket */
|
||||
#define IP_RSVP_VIF_OFF 18 /* unset RSVP per-vif socket */
|
||||
#define IP_PORTRANGE 19 /* int; range to choose for unspec port */
|
||||
#define IP_RECVIF 20 /* bool; receive reception if w/dgram */
|
||||
/* for IPSEC */
|
||||
#define IP_IPSEC_POLICY 21 /* int; set/get security policy */
|
||||
/* unused; was IP_FAITH */
|
||||
#define IP_ONESBCAST 23 /* bool: send all-ones broadcast */
|
||||
#define IP_BINDANY 24 /* bool: allow bind to any address */
|
||||
#define IP_BINDMULTI 25 /* bool: allow multiple listeners on a tuple */
|
||||
#define IP_RSS_LISTEN_BUCKET 26 /* int; set RSS listen bucket */
|
||||
|
||||
/*
|
||||
* Options for controlling the firewall and dummynet.
|
||||
* Historical options (from 40 to 64) will eventually be
|
||||
* replaced by only two options, IP_FW3 and IP_DUMMYNET3.
|
||||
*/
|
||||
#define IP_FW_TABLE_ADD 40 /* add entry */
|
||||
#define IP_FW_TABLE_DEL 41 /* delete entry */
|
||||
#define IP_FW_TABLE_FLUSH 42 /* flush table */
|
||||
#define IP_FW_TABLE_GETSIZE 43 /* get table size */
|
||||
#define IP_FW_TABLE_LIST 44 /* list table contents */
|
||||
|
||||
#define IP_FW3 48 /* generic ipfw v.3 sockopts */
|
||||
#define IP_DUMMYNET3 49 /* generic dummynet v.3 sockopts */
|
||||
|
||||
#define IP_FW_ADD 50 /* add a firewall rule to chain */
|
||||
#define IP_FW_DEL 51 /* delete a firewall rule from chain */
|
||||
#define IP_FW_FLUSH 52 /* flush firewall rule chain */
|
||||
#define IP_FW_ZERO 53 /* clear single/all firewall counter(s) */
|
||||
#define IP_FW_GET 54 /* get entire firewall rule chain */
|
||||
#define IP_FW_RESETLOG 55 /* reset logging counters */
|
||||
|
||||
#define IP_FW_NAT_CFG 56 /* add/config a nat rule */
|
||||
#define IP_FW_NAT_DEL 57 /* delete a nat rule */
|
||||
#define IP_FW_NAT_GET_CONFIG 58 /* get configuration of a nat rule */
|
||||
#define IP_FW_NAT_GET_LOG 59 /* get log of a nat rule */
|
||||
|
||||
#define IP_DUMMYNET_CONFIGURE 60 /* add/configure a dummynet pipe */
|
||||
#define IP_DUMMYNET_DEL 61 /* delete a dummynet pipe from chain */
|
||||
#define IP_DUMMYNET_FLUSH 62 /* flush dummynet */
|
||||
#define IP_DUMMYNET_GET 64 /* get entire dummynet pipes */
|
||||
|
||||
#define IP_RECVTTL 65 /* bool; receive IP TTL w/dgram */
|
||||
#define IP_MINTTL 66 /* minimum TTL for packet or drop */
|
||||
#define IP_DONTFRAG 67 /* don't fragment packet */
|
||||
#define IP_RECVTOS 68 /* bool; receive IP TOS w/dgram */
|
||||
|
||||
/* IPv4 Source Filter Multicast API [RFC3678] */
|
||||
#define IP_ADD_SOURCE_MEMBERSHIP 70 /* join a source-specific group */
|
||||
#define IP_DROP_SOURCE_MEMBERSHIP 71 /* drop a single source */
|
||||
#define IP_BLOCK_SOURCE 72 /* block a source */
|
||||
#define IP_UNBLOCK_SOURCE 73 /* unblock a source */
|
||||
|
||||
/* The following option is private; do not use it from user applications. */
|
||||
#define IP_MSFILTER 74 /* set/get filter list */
|
||||
|
||||
/* Protocol Independent Multicast API [RFC3678] */
|
||||
#define MCAST_JOIN_GROUP 80 /* join an any-source group */
|
||||
#define MCAST_LEAVE_GROUP 81 /* leave all sources for group */
|
||||
#define MCAST_JOIN_SOURCE_GROUP 82 /* join a source-specific group */
|
||||
#define MCAST_LEAVE_SOURCE_GROUP 83 /* leave a single source */
|
||||
#define MCAST_BLOCK_SOURCE 84 /* block a source */
|
||||
#define MCAST_UNBLOCK_SOURCE 85 /* unblock a source */
|
||||
|
||||
/* Flow and RSS definitions */
|
||||
#define IP_FLOWID 90 /* get flow id for the given socket/inp */
|
||||
#define IP_FLOWTYPE 91 /* get flow type (M_HASHTYPE) */
|
||||
#define IP_RSSBUCKETID 92 /* get RSS flowid -> bucket mapping */
|
||||
#define IP_RECVFLOWID 93 /* bool; receive IP flowid/flowtype w/ datagram */
|
||||
#define IP_RECVRSSBUCKETID 94 /* bool; receive IP RSS bucket id w/ datagram */
|
||||
|
||||
/*
|
||||
* Defaults and limits for options
|
||||
*/
|
||||
#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */
|
||||
#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
|
||||
|
||||
/*
|
||||
* The imo_membership vector for each socket is now dynamically allocated at
|
||||
* run-time, bounded by USHRT_MAX, and is reallocated when needed, sized
|
||||
* according to a power-of-two increment.
|
||||
*/
|
||||
#define IP_MIN_MEMBERSHIPS 31
|
||||
#define IP_MAX_MEMBERSHIPS 4095
|
||||
#define IP_MAX_SOURCE_FILTER 1024 /* XXX to be unused */
|
||||
|
||||
/*
|
||||
* Default resource limits for IPv4 multicast source filtering.
|
||||
* These may be modified by sysctl.
|
||||
*/
|
||||
#define IP_MAX_GROUP_SRC_FILTER 512 /* sources per group */
|
||||
#define IP_MAX_SOCK_SRC_FILTER 128 /* sources per socket/group */
|
||||
#define IP_MAX_SOCK_MUTE_FILTER 128 /* XXX no longer used */
|
||||
|
||||
/*
|
||||
* Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
|
||||
*/
|
||||
struct ip_mreq {
|
||||
struct in_addr imr_multiaddr; /* IP multicast address of group */
|
||||
struct in_addr imr_interface; /* local IP address of interface */
|
||||
};
|
||||
|
||||
/*
|
||||
* Modified argument structure for IP_MULTICAST_IF, obtained from Linux.
|
||||
* This is used to specify an interface index for multicast sends, as
|
||||
* the IPv4 legacy APIs do not support this (unless IP_SENDIF is available).
|
||||
*/
|
||||
struct ip_mreqn {
|
||||
struct in_addr imr_multiaddr; /* IP multicast address of group */
|
||||
struct in_addr imr_address; /* local IP address of interface */
|
||||
int imr_ifindex; /* Interface index; cast to uint32_t */
|
||||
};
|
||||
|
||||
/*
|
||||
* Argument structure for IPv4 Multicast Source Filter APIs. [RFC3678]
|
||||
*/
|
||||
struct ip_mreq_source {
|
||||
struct in_addr imr_multiaddr; /* IP multicast address of group */
|
||||
struct in_addr imr_sourceaddr; /* IP address of source */
|
||||
struct in_addr imr_interface; /* local IP address of interface */
|
||||
};
|
||||
|
||||
/*
|
||||
* Argument structures for Protocol-Independent Multicast Source
|
||||
* Filter APIs. [RFC3678]
|
||||
*/
|
||||
struct group_req {
|
||||
uint32_t gr_interface; /* interface index */
|
||||
struct sockaddr_storage gr_group; /* group address */
|
||||
};
|
||||
|
||||
struct group_source_req {
|
||||
uint32_t gsr_interface; /* interface index */
|
||||
struct sockaddr_storage gsr_group; /* group address */
|
||||
struct sockaddr_storage gsr_source; /* source address */
|
||||
};
|
||||
|
||||
#ifndef __MSFILTERREQ_DEFINED
|
||||
#define __MSFILTERREQ_DEFINED
|
||||
/*
|
||||
* The following structure is private; do not use it from user applications.
|
||||
* It is used to communicate IP_MSFILTER/IPV6_MSFILTER information between
|
||||
* the RFC 3678 libc functions and the kernel.
|
||||
*/
|
||||
struct __msfilterreq {
|
||||
uint32_t msfr_ifindex; /* interface index */
|
||||
uint32_t msfr_fmode; /* filter mode for group */
|
||||
uint32_t msfr_nsrcs; /* # of sources in msfr_srcs */
|
||||
struct sockaddr_storage msfr_group; /* group address */
|
||||
struct sockaddr_storage *msfr_srcs; /* pointer to the first member
|
||||
* of a contiguous array of
|
||||
* sources to filter in full.
|
||||
*/
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Filter modes; also used to represent per-socket filter mode internally.
|
||||
*/
|
||||
#define MCAST_UNDEFINED 0 /* fmode: not yet defined */
|
||||
#define MCAST_INCLUDE 1 /* fmode: include these source(s) */
|
||||
#define MCAST_EXCLUDE 2 /* fmode: exclude these source(s) */
|
||||
|
||||
/*
|
||||
* Argument for IP_PORTRANGE:
|
||||
* - which range to search when port is unspecified at bind() or connect()
|
||||
*/
|
||||
#define IP_PORTRANGE_DEFAULT 0 /* default range */
|
||||
#define IP_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
|
||||
#define IP_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
|
||||
|
||||
/*
|
||||
* Identifiers for IP sysctl nodes
|
||||
*/
|
||||
#define IPCTL_FORWARDING 1 /* act as router */
|
||||
#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */
|
||||
#define IPCTL_DEFTTL 3 /* default TTL */
|
||||
#ifdef notyet
|
||||
#define IPCTL_DEFMTU 4 /* default MTU */
|
||||
#endif
|
||||
/* IPCTL_RTEXPIRE 5 deprecated */
|
||||
/* IPCTL_RTMINEXPIRE 6 deprecated */
|
||||
/* IPCTL_RTMAXCACHE 7 deprecated */
|
||||
#define IPCTL_SOURCEROUTE 8 /* may perform source routes */
|
||||
#define IPCTL_DIRECTEDBROADCAST 9 /* may re-broadcast received packets */
|
||||
#define IPCTL_INTRQMAXLEN 10 /* max length of netisr queue */
|
||||
#define IPCTL_INTRQDROPS 11 /* number of netisr q drops */
|
||||
#define IPCTL_STATS 12 /* ipstat structure */
|
||||
#define IPCTL_ACCEPTSOURCEROUTE 13 /* may accept source routed packets */
|
||||
#define IPCTL_FASTFORWARDING 14 /* use fast IP forwarding code */
|
||||
/* 15, unused, was: IPCTL_KEEPFAITH */
|
||||
#define IPCTL_GIF_TTL 16 /* default TTL for gif encap packet */
|
||||
|
||||
#endif /* __BSD_VISIBLE */
|
||||
|
||||
/* INET6 stuff */
|
||||
#define __KAME_NETINET_IN_H_INCLUDED_
|
||||
#include <netinet6/in6.h>
|
||||
#undef __KAME_NETINET_IN_H_INCLUDED_
|
||||
|
||||
#endif /* !_NETINET_IN_H_*/
|
|
@ -0,0 +1,48 @@
|
|||
/*-
|
||||
* Copyright (c) 1985, 1986, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)in_var.h 8.2 (Berkeley) 1/9/95
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NETINET_IN_VAR_H_
|
||||
#define _NETINET_IN_VAR_H_
|
||||
|
||||
/*
|
||||
* Argument structure for SIOCAIFADDR.
|
||||
*/
|
||||
struct in_aliasreq {
|
||||
char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||
struct sockaddr_in ifra_addr;
|
||||
struct sockaddr_in ifra_broadaddr;
|
||||
#define ifra_dstaddr ifra_broadaddr
|
||||
struct sockaddr_in ifra_mask;
|
||||
int ifra_vhid;
|
||||
};
|
||||
|
||||
#endif /* _NETINET_IN_VAR_H_ */
|
|
@ -0,0 +1,138 @@
|
|||
/* $FreeBSD$ */
|
||||
/* $OpenBSD: ip_carp.h,v 1.8 2004/07/29 22:12:15 mcbride Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Michael Shalayeff. All rights reserved.
|
||||
* Copyright (c) 2003 Ryan McBride. 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 OR HIS RELATIVES 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 MIND, 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.
|
||||
*/
|
||||
|
||||
#ifndef _IP_CARP_H
|
||||
#define _IP_CARP_H
|
||||
|
||||
/*
|
||||
* The CARP header layout is as follows:
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |Version| Type | VirtualHostID | AdvSkew | Auth Len |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Reserved | AdvBase | Checksum |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Counter (1) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Counter (2) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | SHA-1 HMAC (1) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | SHA-1 HMAC (2) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | SHA-1 HMAC (3) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | SHA-1 HMAC (4) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | SHA-1 HMAC (5) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
*/
|
||||
|
||||
struct carp_header {
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
u_int8_t carp_type:4,
|
||||
carp_version:4;
|
||||
#endif
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
u_int8_t carp_version:4,
|
||||
carp_type:4;
|
||||
#endif
|
||||
u_int8_t carp_vhid; /* virtual host id */
|
||||
u_int8_t carp_advskew; /* advertisement skew */
|
||||
u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */
|
||||
u_int8_t carp_pad1; /* reserved */
|
||||
u_int8_t carp_advbase; /* advertisement interval */
|
||||
u_int16_t carp_cksum;
|
||||
u_int32_t carp_counter[2];
|
||||
unsigned char carp_md[20]; /* SHA1 HMAC */
|
||||
} __packed;
|
||||
|
||||
#ifdef CTASSERT
|
||||
CTASSERT(sizeof(struct carp_header) == 36);
|
||||
#endif
|
||||
|
||||
#define CARP_DFLTTL 255
|
||||
|
||||
/* carp_version */
|
||||
#define CARP_VERSION 2
|
||||
|
||||
/* carp_type */
|
||||
#define CARP_ADVERTISEMENT 0x01
|
||||
|
||||
#define CARP_KEY_LEN 20 /* a sha1 hash of a passphrase */
|
||||
|
||||
/* carp_advbase */
|
||||
#define CARP_DFLTINTV 1
|
||||
|
||||
/*
|
||||
* Statistics.
|
||||
*/
|
||||
struct carpstats {
|
||||
uint64_t carps_ipackets; /* total input packets, IPv4 */
|
||||
uint64_t carps_ipackets6; /* total input packets, IPv6 */
|
||||
uint64_t carps_badif; /* wrong interface */
|
||||
uint64_t carps_badttl; /* TTL is not CARP_DFLTTL */
|
||||
uint64_t carps_hdrops; /* packets shorter than hdr */
|
||||
uint64_t carps_badsum; /* bad checksum */
|
||||
uint64_t carps_badver; /* bad (incl unsupp) version */
|
||||
uint64_t carps_badlen; /* data length does not match */
|
||||
uint64_t carps_badauth; /* bad authentication */
|
||||
uint64_t carps_badvhid; /* bad VHID */
|
||||
uint64_t carps_badaddrs; /* bad address list */
|
||||
|
||||
uint64_t carps_opackets; /* total output packets, IPv4 */
|
||||
uint64_t carps_opackets6; /* total output packets, IPv6 */
|
||||
uint64_t carps_onomem; /* no memory for an mbuf */
|
||||
uint64_t carps_ostates; /* total state updates sent */
|
||||
|
||||
uint64_t carps_preempt; /* if enabled, preemptions */
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration structure for SIOCSVH SIOCGVH
|
||||
*/
|
||||
struct carpreq {
|
||||
int carpr_count;
|
||||
int carpr_vhid;
|
||||
#define CARP_MAXVHID 255
|
||||
int carpr_state;
|
||||
#define CARP_STATES "INIT", "BACKUP", "MASTER"
|
||||
#define CARP_MAXSTATE 2
|
||||
int carpr_advskew;
|
||||
#define CARP_MAXSKEW 240
|
||||
int carpr_advbase;
|
||||
unsigned char carpr_key[CARP_KEY_LEN];
|
||||
};
|
||||
#define SIOCSVH _IOWR('i', 245, struct ifreq)
|
||||
#define SIOCGVH _IOWR('i', 246, struct ifreq)
|
||||
|
||||
#endif /* _IP_CARP_H */
|
|
@ -0,0 +1,493 @@
|
|||
/*-
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* 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. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT 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.
|
||||
*
|
||||
* $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1990, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)in.h 8.3 (Berkeley) 1/3/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef __KAME_NETINET_IN_H_INCLUDED_
|
||||
#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
|
||||
#endif
|
||||
|
||||
#ifndef _NETINET6_IN6_H_
|
||||
#define _NETINET6_IN6_H_
|
||||
|
||||
/*
|
||||
* Identification of the network protocol stack
|
||||
* for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
|
||||
* has the table of implementation/integration differences.
|
||||
*/
|
||||
#define __KAME__
|
||||
#define __KAME_VERSION "FreeBSD"
|
||||
|
||||
/*
|
||||
* IPv6 port allocation rules should mirror the IPv4 rules and are controlled
|
||||
* by the net.inet.ip.portrange sysctl tree. The following defines exist
|
||||
* for compatibility with userland applications that need them.
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
#define IPV6PORT_RESERVED 1024
|
||||
#define IPV6PORT_ANONMIN 49152
|
||||
#define IPV6PORT_ANONMAX 65535
|
||||
#define IPV6PORT_RESERVEDMIN 600
|
||||
#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* IPv6 address
|
||||
*/
|
||||
struct in6_addr {
|
||||
union {
|
||||
uint8_t __u6_addr8[16];
|
||||
uint16_t __u6_addr16[8];
|
||||
uint32_t __u6_addr32[4];
|
||||
} __u6_addr; /* 128-bit IP6 address */
|
||||
};
|
||||
|
||||
#define s6_addr __u6_addr.__u6_addr8
|
||||
|
||||
#define INET6_ADDRSTRLEN 46
|
||||
|
||||
/*
|
||||
* XXX missing POSIX.1-2001 macro IPPROTO_IPV6.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Socket address for IPv6
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
#define SIN6_LEN
|
||||
#endif
|
||||
|
||||
struct sockaddr_in6 {
|
||||
uint8_t sin6_len; /* length of this struct */
|
||||
sa_family_t sin6_family; /* AF_INET6 */
|
||||
in_port_t sin6_port; /* Transport layer port # */
|
||||
uint32_t sin6_flowinfo; /* IP6 flow information */
|
||||
struct in6_addr sin6_addr; /* IP6 address */
|
||||
uint32_t sin6_scope_id; /* scope zone index */
|
||||
};
|
||||
|
||||
/*
|
||||
* Definition of some useful macros to handle IP6 addresses
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
#define IN6ADDR_ANY_INIT \
|
||||
{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
|
||||
#define IN6ADDR_LOOPBACK_INIT \
|
||||
{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
|
||||
#define IN6ADDR_NODELOCAL_ALLNODES_INIT \
|
||||
{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
|
||||
#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \
|
||||
{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
|
||||
#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
|
||||
{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
|
||||
#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
|
||||
{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
|
||||
#define IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \
|
||||
{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}}
|
||||
#endif
|
||||
|
||||
extern const struct in6_addr in6addr_any;
|
||||
extern const struct in6_addr in6addr_loopback;
|
||||
#if __BSD_VISIBLE
|
||||
extern const struct in6_addr in6addr_nodelocal_allnodes;
|
||||
extern const struct in6_addr in6addr_linklocal_allnodes;
|
||||
extern const struct in6_addr in6addr_linklocal_allrouters;
|
||||
extern const struct in6_addr in6addr_linklocal_allv2routers;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Unspecified
|
||||
*/
|
||||
#define IN6_IS_ADDR_UNSPECIFIED(a) \
|
||||
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[2] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[3] == 0)
|
||||
|
||||
/*
|
||||
* Loopback
|
||||
*/
|
||||
#define IN6_IS_ADDR_LOOPBACK(a) \
|
||||
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[2] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[3] == ntohl(1))
|
||||
|
||||
/*
|
||||
* IPv4 compatible
|
||||
*/
|
||||
#define IN6_IS_ADDR_V4COMPAT(a) \
|
||||
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[2] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[3] != 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[3] != ntohl(1))
|
||||
|
||||
/*
|
||||
* Mapped
|
||||
*/
|
||||
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
||||
(a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
|
||||
|
||||
/*
|
||||
* Unicast Scope
|
||||
* Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
|
||||
*/
|
||||
#define IN6_IS_ADDR_LINKLOCAL(a) \
|
||||
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
|
||||
#define IN6_IS_ADDR_SITELOCAL(a) \
|
||||
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
|
||||
|
||||
/*
|
||||
* Multicast
|
||||
*/
|
||||
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
|
||||
|
||||
#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
|
||||
|
||||
#define IN6_IS_ADDR_MC_NODELOCAL(a) \
|
||||
(IN6_IS_ADDR_MULTICAST(a) && \
|
||||
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
|
||||
#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
|
||||
(IN6_IS_ADDR_MULTICAST(a) && \
|
||||
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
|
||||
#define IN6_IS_ADDR_MC_SITELOCAL(a) \
|
||||
(IN6_IS_ADDR_MULTICAST(a) && \
|
||||
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
|
||||
#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
|
||||
(IN6_IS_ADDR_MULTICAST(a) && \
|
||||
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
|
||||
#define IN6_IS_ADDR_MC_GLOBAL(a) \
|
||||
(IN6_IS_ADDR_MULTICAST(a) && \
|
||||
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
|
||||
|
||||
/*
|
||||
* IP6 route structure
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
struct route_in6 {
|
||||
struct rtentry *ro_rt;
|
||||
struct llentry *ro_lle;
|
||||
/*
|
||||
* ro_prepend and ro_plen are only used for bpf to pass in a
|
||||
* preformed header. They are not cacheable.
|
||||
*/
|
||||
char *ro_prepend;
|
||||
uint16_t ro_plen;
|
||||
uint16_t ro_flags;
|
||||
uint16_t ro_mtu; /* saved ro_rt mtu */
|
||||
uint16_t spare;
|
||||
struct sockaddr_in6 ro_dst;
|
||||
};
|
||||
#endif
|
||||
|
||||
#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */
|
||||
#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */
|
||||
#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */
|
||||
#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */
|
||||
#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */
|
||||
#define IPV6_JOIN_GROUP 12 /* ipv6_mreq; join a group membership */
|
||||
#define IPV6_LEAVE_GROUP 13 /* ipv6_mreq; leave a group membership */
|
||||
#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */
|
||||
#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */
|
||||
|
||||
#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */
|
||||
#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */
|
||||
#define IPV6_BINDV6ONLY IPV6_V6ONLY
|
||||
|
||||
#if 1 /* IPSEC */
|
||||
#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */
|
||||
#endif /* IPSEC */
|
||||
|
||||
/* 29; unused; was IPV6_FAITH */
|
||||
#if 1 /* IPV6FIREWALL */
|
||||
#define IPV6_FW_ADD 30 /* add a firewall rule to chain */
|
||||
#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */
|
||||
#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */
|
||||
#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */
|
||||
#define IPV6_FW_GET 34 /* get entire firewall rule chain */
|
||||
#endif
|
||||
|
||||
/* new socket options introduced in RFC3542 */
|
||||
#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */
|
||||
|
||||
#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */
|
||||
#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */
|
||||
#define IPV6_RECVRTHDR 38 /* bool; recv routing header */
|
||||
#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */
|
||||
#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */
|
||||
|
||||
#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */
|
||||
#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */
|
||||
|
||||
#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt),
|
||||
4 bytes int; MTU notification (cmsg) */
|
||||
#if 0 /*obsoleted during 2292bis -> 3542*/
|
||||
#define IPV6_REACHCONF 45 /* no data; ND reachability confirm
|
||||
(cmsg only/not in of RFC3542) */
|
||||
#endif
|
||||
|
||||
/* more new socket options introduced in RFC3542 */
|
||||
#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */
|
||||
#define IPV6_HOPLIMIT 47 /* int; send hop limit */
|
||||
#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
|
||||
#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
|
||||
#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
|
||||
#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
|
||||
#if 0
|
||||
#define IPV6_PKTOPTIONS 52 /* buf/cmsghdr; set/get IPv6 options */
|
||||
/* obsoleted by RFC3542 */
|
||||
#endif
|
||||
|
||||
#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
|
||||
|
||||
#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */
|
||||
|
||||
#define IPV6_TCLASS 61 /* int; send traffic class value */
|
||||
#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
|
||||
|
||||
#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary addresses as
|
||||
* the source address.
|
||||
*/
|
||||
|
||||
#define IPV6_BINDANY 64 /* bool: allow bind to any address */
|
||||
|
||||
#define IPV6_BINDMULTI 65 /* bool; allow multibind to same addr/port */
|
||||
#define IPV6_RSS_LISTEN_BUCKET 66 /* int; set RSS listen bucket */
|
||||
#define IPV6_FLOWID 67 /* int; flowid of given socket */
|
||||
#define IPV6_FLOWTYPE 68 /* int; flowtype of given socket */
|
||||
#define IPV6_RSSBUCKETID 69 /* int; RSS bucket ID of given socket */
|
||||
#define IPV6_RECVFLOWID 70 /* bool; receive IP6 flowid/flowtype w/ datagram */
|
||||
#define IPV6_RECVRSSBUCKETID 71 /* bool; receive IP6 RSS bucket id w/ datagram */
|
||||
|
||||
/*
|
||||
* The following option is private; do not use it from user applications.
|
||||
* It is deliberately defined to the same value as IP_MSFILTER.
|
||||
*/
|
||||
#define IPV6_MSFILTER 74 /* struct __msfilterreq;
|
||||
* set/get multicast source filter list.
|
||||
*/
|
||||
|
||||
/* to define items, should talk with KAME guys first, for *BSD compatibility */
|
||||
|
||||
#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
|
||||
#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
|
||||
#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
|
||||
|
||||
/*
|
||||
* Defaults and limits for options
|
||||
*/
|
||||
#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
|
||||
#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
|
||||
|
||||
/*
|
||||
* The im6o_membership vector for each socket is now dynamically allocated at
|
||||
* run-time, bounded by USHRT_MAX, and is reallocated when needed, sized
|
||||
* according to a power-of-two increment.
|
||||
*/
|
||||
#define IPV6_MIN_MEMBERSHIPS 31
|
||||
#define IPV6_MAX_MEMBERSHIPS 4095
|
||||
|
||||
/*
|
||||
* Default resource limits for IPv6 multicast source filtering.
|
||||
* These may be modified by sysctl.
|
||||
*/
|
||||
#define IPV6_MAX_GROUP_SRC_FILTER 512 /* sources per group */
|
||||
#define IPV6_MAX_SOCK_SRC_FILTER 128 /* sources per socket/group */
|
||||
|
||||
/*
|
||||
* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
|
||||
*/
|
||||
struct ipv6_mreq {
|
||||
struct in6_addr ipv6mr_multiaddr;
|
||||
unsigned int ipv6mr_interface;
|
||||
};
|
||||
|
||||
/*
|
||||
* IPV6_PKTINFO: Packet information(RFC2292 sec 5)
|
||||
*/
|
||||
struct in6_pktinfo {
|
||||
struct in6_addr ipi6_addr; /* src/dst IPv6 address */
|
||||
unsigned int ipi6_ifindex; /* send/recv interface index */
|
||||
};
|
||||
|
||||
/*
|
||||
* Control structure for IPV6_RECVPATHMTU socket option.
|
||||
*/
|
||||
struct ip6_mtuinfo {
|
||||
struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */
|
||||
uint32_t ip6m_mtu;
|
||||
};
|
||||
|
||||
/*
|
||||
* Argument for IPV6_PORTRANGE:
|
||||
* - which range to search when port is unspecified at bind() or connect()
|
||||
*/
|
||||
#define IPV6_PORTRANGE_DEFAULT 0 /* default range */
|
||||
#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
|
||||
#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* Definitions for inet6 sysctl operations.
|
||||
*
|
||||
* Third level is protocol number.
|
||||
* Fourth level is desired variable within that protocol.
|
||||
*/
|
||||
#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */
|
||||
|
||||
/*
|
||||
* Names for IP sysctl objects
|
||||
*/
|
||||
#define IPV6CTL_FORWARDING 1 /* act as router */
|
||||
#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/
|
||||
#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */
|
||||
#ifdef notyet
|
||||
#define IPV6CTL_DEFMTU 4 /* default MTU */
|
||||
#endif
|
||||
#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */
|
||||
#define IPV6CTL_STATS 6 /* stats */
|
||||
#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */
|
||||
#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */
|
||||
#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */
|
||||
#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */
|
||||
#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */
|
||||
#define IPV6CTL_ACCEPT_RTADV 12
|
||||
/* 13; unused; was: IPV6CTL_KEEPFAITH */
|
||||
#define IPV6CTL_LOG_INTERVAL 14
|
||||
#define IPV6CTL_HDRNESTLIMIT 15
|
||||
#define IPV6CTL_DAD_COUNT 16
|
||||
#define IPV6CTL_AUTO_FLOWLABEL 17
|
||||
#define IPV6CTL_DEFMCASTHLIM 18
|
||||
#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */
|
||||
#define IPV6CTL_KAME_VERSION 20
|
||||
#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */
|
||||
#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */
|
||||
#if 0 /* obsolete */
|
||||
#define IPV6CTL_MAPPED_ADDR 23
|
||||
#endif
|
||||
#define IPV6CTL_V6ONLY 24
|
||||
/* IPV6CTL_RTEXPIRE 25 deprecated */
|
||||
/* IPV6CTL_RTMINEXPIRE 26 deprecated */
|
||||
/* IPV6CTL_RTMAXCACHE 27 deprecated */
|
||||
|
||||
#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */
|
||||
#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */
|
||||
#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */
|
||||
#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */
|
||||
#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */
|
||||
#define IPV6CTL_PREFER_TEMPADDR 37 /* prefer temporary addr as src */
|
||||
#define IPV6CTL_ADDRCTLPOLICY 38 /* get/set address selection policy */
|
||||
#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */
|
||||
|
||||
#define IPV6CTL_MAXFRAGS 41 /* max fragments */
|
||||
#if 0
|
||||
#define IPV6CTL_IFQ 42 /* ip6intrq node */
|
||||
#define IPV6CTL_ISATAPRTR 43 /* isatap router */
|
||||
#endif
|
||||
#define IPV6CTL_MCAST_PMTU 44 /* enable pMTU discovery for multicast? */
|
||||
|
||||
/* New entries should be added here from current IPV6CTL_MAXID value. */
|
||||
/* to define items, should talk with KAME guys first, for *BSD compatibility */
|
||||
#define IPV6CTL_STEALTH 45
|
||||
|
||||
#define ICMPV6CTL_ND6_ONLINKNSRFC4861 47
|
||||
#define IPV6CTL_NO_RADR 48 /* No defroute from RA */
|
||||
#define IPV6CTL_NORBIT_RAIF 49 /* Disable R-bit in NA on RA
|
||||
* receiving IF. */
|
||||
#define IPV6CTL_RFC6204W3 50 /* Accept defroute even when forwarding
|
||||
enabled */
|
||||
#define IPV6CTL_MAXID 51
|
||||
#endif /* __BSD_VISIBLE */
|
||||
|
||||
/*
|
||||
* Since both netinet/ and netinet6/ call into netipsec/ and netpfil/,
|
||||
* the protocol specific mbuf flags are shared between them.
|
||||
*/
|
||||
#define M_FASTFWD_OURS M_PROTO1 /* changed dst to local */
|
||||
#define M_IP6_NEXTHOP M_PROTO2 /* explicit ip nexthop */
|
||||
#define M_IP_NEXTHOP M_PROTO2 /* explicit ip nexthop */
|
||||
#define M_SKIP_FIREWALL M_PROTO3 /* skip firewall processing */
|
||||
#define M_AUTHIPHDR M_PROTO4
|
||||
#define M_DECRYPTED M_PROTO5
|
||||
#define M_LOOP M_PROTO6
|
||||
#define M_AUTHIPDGM M_PROTO7
|
||||
#define M_RTALERT_MLD M_PROTO8
|
||||
#ifndef _SIZE_T_DECLARED
|
||||
typedef __size_t size_t;
|
||||
#define _SIZE_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _SOCKLEN_T_DECLARED
|
||||
typedef __socklen_t socklen_t;
|
||||
#define _SOCKLEN_T_DECLARED
|
||||
#endif
|
||||
|
||||
#endif /* !_NETINET6_IN6_H_ */
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* Copyright (c) 2001 Daniel Hartmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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 HOLDERS 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.
|
||||
*
|
||||
* $OpenBSD: pfvar.h,v 1.282 2009/01/29 15:12:28 pyr Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_PF_H_
|
||||
#define _NET_PF_H_
|
||||
|
||||
#define PF_TCPS_PROXY_SRC ((TCP_NSTATES)+0)
|
||||
#define PF_TCPS_PROXY_DST ((TCP_NSTATES)+1)
|
||||
|
||||
#define PF_MD5_DIGEST_LENGTH 16
|
||||
#ifdef MD5_DIGEST_LENGTH
|
||||
#if PF_MD5_DIGEST_LENGTH != MD5_DIGEST_LENGTH
|
||||
#error
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum { PF_INOUT, PF_IN, PF_OUT, PF_FWD };
|
||||
enum { PF_PASS, PF_DROP, PF_SCRUB, PF_NOSCRUB, PF_NAT, PF_NONAT,
|
||||
PF_BINAT, PF_NOBINAT, PF_RDR, PF_NORDR, PF_SYNPROXY_DROP, PF_DEFER };
|
||||
enum { PF_RULESET_SCRUB, PF_RULESET_FILTER, PF_RULESET_NAT,
|
||||
PF_RULESET_BINAT, PF_RULESET_RDR, PF_RULESET_MAX };
|
||||
enum { PF_OP_NONE, PF_OP_IRG, PF_OP_EQ, PF_OP_NE, PF_OP_LT,
|
||||
PF_OP_LE, PF_OP_GT, PF_OP_GE, PF_OP_XRG, PF_OP_RRG };
|
||||
enum { PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC, PF_DEBUG_NOISY };
|
||||
enum { PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
|
||||
PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
|
||||
PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
|
||||
enum { PF_GET_NONE, PF_GET_CLR_CNTR };
|
||||
enum { PF_SK_WIRE, PF_SK_STACK, PF_SK_BOTH };
|
||||
|
||||
/*
|
||||
* Note about PFTM_*: real indices into pf_rule.timeout[] come before
|
||||
* PFTM_MAX, special cases afterwards. See pf_state_expires().
|
||||
*/
|
||||
enum { PFTM_TCP_FIRST_PACKET, PFTM_TCP_OPENING, PFTM_TCP_ESTABLISHED,
|
||||
PFTM_TCP_CLOSING, PFTM_TCP_FIN_WAIT, PFTM_TCP_CLOSED,
|
||||
PFTM_UDP_FIRST_PACKET, PFTM_UDP_SINGLE, PFTM_UDP_MULTIPLE,
|
||||
PFTM_ICMP_FIRST_PACKET, PFTM_ICMP_ERROR_REPLY,
|
||||
PFTM_OTHER_FIRST_PACKET, PFTM_OTHER_SINGLE,
|
||||
PFTM_OTHER_MULTIPLE, PFTM_FRAG, PFTM_INTERVAL,
|
||||
PFTM_ADAPTIVE_START, PFTM_ADAPTIVE_END, PFTM_SRC_NODE,
|
||||
PFTM_TS_DIFF, PFTM_MAX, PFTM_PURGE, PFTM_UNLINKED };
|
||||
|
||||
/* PFTM default values */
|
||||
#define PFTM_TCP_FIRST_PACKET_VAL 120 /* First TCP packet */
|
||||
#define PFTM_TCP_OPENING_VAL 30 /* No response yet */
|
||||
#define PFTM_TCP_ESTABLISHED_VAL 24*60*60/* Established */
|
||||
#define PFTM_TCP_CLOSING_VAL 15 * 60 /* Half closed */
|
||||
#define PFTM_TCP_FIN_WAIT_VAL 45 /* Got both FINs */
|
||||
#define PFTM_TCP_CLOSED_VAL 90 /* Got a RST */
|
||||
#define PFTM_UDP_FIRST_PACKET_VAL 60 /* First UDP packet */
|
||||
#define PFTM_UDP_SINGLE_VAL 30 /* Unidirectional */
|
||||
#define PFTM_UDP_MULTIPLE_VAL 60 /* Bidirectional */
|
||||
#define PFTM_ICMP_FIRST_PACKET_VAL 20 /* First ICMP packet */
|
||||
#define PFTM_ICMP_ERROR_REPLY_VAL 10 /* Got error response */
|
||||
#define PFTM_OTHER_FIRST_PACKET_VAL 60 /* First packet */
|
||||
#define PFTM_OTHER_SINGLE_VAL 30 /* Unidirectional */
|
||||
#define PFTM_OTHER_MULTIPLE_VAL 60 /* Bidirectional */
|
||||
#define PFTM_FRAG_VAL 30 /* Fragment expire */
|
||||
#define PFTM_INTERVAL_VAL 10 /* Expire interval */
|
||||
#define PFTM_SRC_NODE_VAL 0 /* Source tracking */
|
||||
#define PFTM_TS_DIFF_VAL 30 /* Allowed TS diff */
|
||||
|
||||
enum { PF_NOPFROUTE, PF_FASTROUTE, PF_ROUTETO, PF_DUPTO, PF_REPLYTO };
|
||||
enum { PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS,
|
||||
PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX };
|
||||
#define PF_POOL_IDMASK 0x0f
|
||||
enum { PF_POOL_NONE, PF_POOL_BITMASK, PF_POOL_RANDOM,
|
||||
PF_POOL_SRCHASH, PF_POOL_ROUNDROBIN };
|
||||
enum { PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, PF_ADDR_DYNIFTL,
|
||||
PF_ADDR_TABLE, PF_ADDR_URPFFAILED,
|
||||
PF_ADDR_RANGE };
|
||||
#define PF_POOL_TYPEMASK 0x0f
|
||||
#define PF_POOL_STICKYADDR 0x20
|
||||
#define PF_WSCALE_FLAG 0x80
|
||||
#define PF_WSCALE_MASK 0x0f
|
||||
|
||||
#define PF_LOG 0x01
|
||||
#define PF_LOG_ALL 0x02
|
||||
#define PF_LOG_SOCKET_LOOKUP 0x04
|
||||
|
||||
/* Reasons code for passing/dropping a packet */
|
||||
#define PFRES_MATCH 0 /* Explicit match of a rule */
|
||||
#define PFRES_BADOFF 1 /* Bad offset for pull_hdr */
|
||||
#define PFRES_FRAG 2 /* Dropping following fragment */
|
||||
#define PFRES_SHORT 3 /* Dropping short packet */
|
||||
#define PFRES_NORM 4 /* Dropping by normalizer */
|
||||
#define PFRES_MEMORY 5 /* Dropped due to lacking mem */
|
||||
#define PFRES_TS 6 /* Bad TCP Timestamp (RFC1323) */
|
||||
#define PFRES_CONGEST 7 /* Congestion (of ipintrq) */
|
||||
#define PFRES_IPOPTIONS 8 /* IP option */
|
||||
#define PFRES_PROTCKSUM 9 /* Protocol checksum invalid */
|
||||
#define PFRES_BADSTATE 10 /* State mismatch */
|
||||
#define PFRES_STATEINS 11 /* State insertion failure */
|
||||
#define PFRES_MAXSTATES 12 /* State limit */
|
||||
#define PFRES_SRCLIMIT 13 /* Source node/conn limit */
|
||||
#define PFRES_SYNPROXY 14 /* SYN proxy */
|
||||
#define PFRES_MAPFAILED 15 /* pf_map_addr() failed */
|
||||
#define PFRES_MAX 16 /* total+1 */
|
||||
|
||||
#define PFRES_NAMES { \
|
||||
"match", \
|
||||
"bad-offset", \
|
||||
"fragment", \
|
||||
"short", \
|
||||
"normalize", \
|
||||
"memory", \
|
||||
"bad-timestamp", \
|
||||
"congestion", \
|
||||
"ip-option", \
|
||||
"proto-cksum", \
|
||||
"state-mismatch", \
|
||||
"state-insert", \
|
||||
"state-limit", \
|
||||
"src-limit", \
|
||||
"synproxy", \
|
||||
"map-failed", \
|
||||
NULL \
|
||||
}
|
||||
|
||||
/* Counters for other things we want to keep track of */
|
||||
#define LCNT_STATES 0 /* states */
|
||||
#define LCNT_SRCSTATES 1 /* max-src-states */
|
||||
#define LCNT_SRCNODES 2 /* max-src-nodes */
|
||||
#define LCNT_SRCCONN 3 /* max-src-conn */
|
||||
#define LCNT_SRCCONNRATE 4 /* max-src-conn-rate */
|
||||
#define LCNT_OVERLOAD_TABLE 5 /* entry added to overload table */
|
||||
#define LCNT_OVERLOAD_FLUSH 6 /* state entries flushed */
|
||||
#define LCNT_MAX 7 /* total+1 */
|
||||
|
||||
#define LCNT_NAMES { \
|
||||
"max states per rule", \
|
||||
"max-src-states", \
|
||||
"max-src-nodes", \
|
||||
"max-src-conn", \
|
||||
"max-src-conn-rate", \
|
||||
"overload table insertion", \
|
||||
"overload flush states", \
|
||||
NULL \
|
||||
}
|
||||
|
||||
/* state operation counters */
|
||||
#define FCNT_STATE_SEARCH 0
|
||||
#define FCNT_STATE_INSERT 1
|
||||
#define FCNT_STATE_REMOVALS 2
|
||||
#define FCNT_MAX 3
|
||||
|
||||
/* src_node operation counters */
|
||||
#define SCNT_SRC_NODE_SEARCH 0
|
||||
#define SCNT_SRC_NODE_INSERT 1
|
||||
#define SCNT_SRC_NODE_REMOVALS 2
|
||||
#define SCNT_MAX 3
|
||||
|
||||
#define PF_TABLE_NAME_SIZE 32
|
||||
#define PF_QNAME_SIZE 64
|
||||
|
||||
struct pf_status {
|
||||
uint64_t counters[PFRES_MAX];
|
||||
uint64_t lcounters[LCNT_MAX];
|
||||
uint64_t fcounters[FCNT_MAX];
|
||||
uint64_t scounters[SCNT_MAX];
|
||||
uint64_t pcounters[2][2][3];
|
||||
uint64_t bcounters[2][2];
|
||||
uint32_t running;
|
||||
uint32_t states;
|
||||
uint32_t src_nodes;
|
||||
uint32_t since;
|
||||
uint32_t debug;
|
||||
uint32_t hostid;
|
||||
char ifname[IFNAMSIZ];
|
||||
uint8_t pf_chksum[PF_MD5_DIGEST_LENGTH];
|
||||
};
|
||||
|
||||
#endif /* _NET_PF_H_ */
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Copyright (c) 2001 Daniel Hartmeier
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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 HOLDERS 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.
|
||||
*
|
||||
* $OpenBSD: pfvar.h,v 1.282 2009/01/29 15:12:28 pyr Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_PF_ALTQ_H_
|
||||
#define _NET_PF_ALTQ_H_
|
||||
|
||||
struct cbq_opts {
|
||||
u_int minburst;
|
||||
u_int maxburst;
|
||||
u_int pktsize;
|
||||
u_int maxpktsize;
|
||||
u_int ns_per_byte;
|
||||
u_int maxidle;
|
||||
int minidle;
|
||||
u_int offtime;
|
||||
int flags;
|
||||
};
|
||||
|
||||
struct codel_opts {
|
||||
u_int target;
|
||||
u_int interval;
|
||||
int ecn;
|
||||
};
|
||||
|
||||
struct priq_opts {
|
||||
int flags;
|
||||
};
|
||||
|
||||
struct hfsc_opts {
|
||||
/* real-time service curve */
|
||||
u_int rtsc_m1; /* slope of the 1st segment in bps */
|
||||
u_int rtsc_d; /* the x-projection of m1 in msec */
|
||||
u_int rtsc_m2; /* slope of the 2nd segment in bps */
|
||||
/* link-sharing service curve */
|
||||
u_int lssc_m1;
|
||||
u_int lssc_d;
|
||||
u_int lssc_m2;
|
||||
/* upper-limit service curve */
|
||||
u_int ulsc_m1;
|
||||
u_int ulsc_d;
|
||||
u_int ulsc_m2;
|
||||
int flags;
|
||||
};
|
||||
|
||||
/*
|
||||
* XXX this needs some work
|
||||
*/
|
||||
struct fairq_opts {
|
||||
u_int nbuckets;
|
||||
u_int hogs_m1;
|
||||
int flags;
|
||||
|
||||
/* link sharing service curve */
|
||||
u_int lssc_m1;
|
||||
u_int lssc_d;
|
||||
u_int lssc_m2;
|
||||
};
|
||||
|
||||
struct pf_altq {
|
||||
char ifname[IFNAMSIZ];
|
||||
|
||||
void *altq_disc; /* discipline-specific state */
|
||||
TAILQ_ENTRY(pf_altq) entries;
|
||||
|
||||
/* scheduler spec */
|
||||
uint8_t scheduler; /* scheduler type */
|
||||
uint16_t tbrsize; /* tokenbucket regulator size */
|
||||
uint32_t ifbandwidth; /* interface bandwidth */
|
||||
|
||||
/* queue spec */
|
||||
char qname[PF_QNAME_SIZE]; /* queue name */
|
||||
char parent[PF_QNAME_SIZE]; /* parent name */
|
||||
uint32_t parent_qid; /* parent queue id */
|
||||
uint32_t bandwidth; /* queue bandwidth */
|
||||
uint8_t priority; /* priority */
|
||||
uint8_t local_flags; /* dynamic interface */
|
||||
#define PFALTQ_FLAG_IF_REMOVED 0x01
|
||||
|
||||
uint16_t qlimit; /* queue size limit */
|
||||
uint16_t flags; /* misc flags */
|
||||
union {
|
||||
struct cbq_opts cbq_opts;
|
||||
struct codel_opts codel_opts;
|
||||
struct priq_opts priq_opts;
|
||||
struct hfsc_opts hfsc_opts;
|
||||
struct fairq_opts fairq_opts;
|
||||
} pq_u;
|
||||
|
||||
uint32_t qid; /* return value */
|
||||
};
|
||||
|
||||
#endif /* _NET_PF_ALTQ_H_ */
|
|
@ -0,0 +1,41 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1986, 1993, 1994
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)uio.h 8.5 (Berkeley) 2/22/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYS__IOVEC_H_
|
||||
#define _COMPAT_SYS__IOVEC_H_
|
||||
|
||||
struct iovec {
|
||||
void *iov_base; /* Base address. */
|
||||
size_t iov_len; /* Length. */
|
||||
};
|
||||
|
||||
#endif /* !_COMPAT_SYS__IOVEC_H_ */
|
|
@ -0,0 +1,54 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)socket.h 8.4 (Berkeley) 2/21/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYS__SOCKADDR_STORAGE_H_
|
||||
#define _COMPAT_SYS__SOCKADDR_STORAGE_H_
|
||||
|
||||
/*
|
||||
* RFC 2553: protocol-independent placeholder for socket addresses
|
||||
*/
|
||||
#define _SS_MAXSIZE 128U
|
||||
#define _SS_ALIGNSIZE (sizeof(__int64_t))
|
||||
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) - \
|
||||
sizeof(sa_family_t))
|
||||
#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) - \
|
||||
sizeof(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE)
|
||||
|
||||
struct sockaddr_storage {
|
||||
unsigned char ss_len; /* address length */
|
||||
sa_family_t ss_family; /* address family */
|
||||
char __ss_pad1[_SS_PAD1SIZE];
|
||||
__int64_t __ss_align; /* force desired struct alignment */
|
||||
char __ss_pad2[_SS_PAD2SIZE];
|
||||
};
|
||||
|
||||
#endif /* !_COMPAT_SYS__SOCKADDR_STORAGE_H_ */
|
|
@ -0,0 +1,86 @@
|
|||
/*-
|
||||
* Copyright (c) 2002 Mike Barcroft <mike@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 _COMPAT_SYS__TYPES_H_
|
||||
#define _COMPAT_SYS__TYPES_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* Standard type definitions.
|
||||
*/
|
||||
typedef __int64_t __blkcnt_t; /* file block count */
|
||||
typedef __int32_t __clockid_t; /* clock_gettime()... */
|
||||
typedef __uint32_t __fflags_t; /* file flags */
|
||||
typedef __uint64_t __fsblkcnt_t;
|
||||
typedef __uint64_t __fsfilcnt_t;
|
||||
typedef __uint32_t __gid_t;
|
||||
typedef __int32_t __lwpid_t; /* Thread ID (a.k.a. LWP) */
|
||||
typedef int __accmode_t; /* access permissions */
|
||||
typedef int __nl_item;
|
||||
typedef __int64_t __off_t; /* file offset */
|
||||
typedef __int64_t __off64_t; /* file offset (alias) */
|
||||
typedef __int32_t __pid_t; /* process [group] */
|
||||
typedef __uint8_t __sa_family_t;
|
||||
typedef __uint32_t __socklen_t;
|
||||
typedef long __suseconds_t; /* microseconds (signed) */
|
||||
typedef struct __mq *__mqd_t; /* mq_open()... */
|
||||
typedef __uint32_t __uid_t;
|
||||
typedef unsigned int __useconds_t; /* microseconds (unsigned) */
|
||||
typedef int __cpuwhich_t; /* which parameter for cpuset. */
|
||||
typedef int __cpulevel_t; /* level parameter for cpuset. */
|
||||
typedef int __cpusetid_t; /* cpuset identifier. */
|
||||
|
||||
/*
|
||||
* Unusual type definitions.
|
||||
*/
|
||||
/*
|
||||
* rune_t is declared to be an ``int'' instead of the more natural
|
||||
* ``unsigned long'' or ``long''. Two things are happening here. It is not
|
||||
* unsigned so that EOF (-1) can be naturally assigned to it and used. Also,
|
||||
* it looks like 10646 will be a 31 bit standard. This means that if your
|
||||
* ints cannot hold 32 bits, you will be in trouble. The reason an int was
|
||||
* chosen over a long is that the is*() and to*() routines take ints (says
|
||||
* ANSI C), but they use __ct_rune_t instead of int.
|
||||
*
|
||||
* NOTE: rune_t is not covered by ANSI nor other standards, and should not
|
||||
* be instantiated outside of lib/libc/locale. Use wchar_t. wint_t and
|
||||
* rune_t must be the same type. Also, wint_t should be able to hold all
|
||||
* members of the largest character set plus one extra value (WEOF), and
|
||||
* must be at least 16 bits.
|
||||
*/
|
||||
typedef int __ct_rune_t; /* arg type for ctype funcs */
|
||||
typedef __ct_rune_t __rune_t; /* rune_t (see above) */
|
||||
typedef __ct_rune_t __wint_t; /* wint_t (see above) */
|
||||
|
||||
|
||||
typedef __uint32_t __fixpt_t; /* fixed point number */
|
||||
|
||||
#endif /* !_COMPAT_SYS__TYPES_H_ */
|
|
@ -0,0 +1,34 @@
|
|||
/*-
|
||||
* Copyright (c) 2012 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 __SYS_COUNTER_H__
|
||||
#define __SYS_COUNTER_H__
|
||||
|
||||
typedef uint64_t *counter_u64_t;
|
||||
|
||||
#endif /* ! __SYS_COUNTER_H__ */
|
|
@ -0,0 +1,67 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1986, 1990, 1993, 1994
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)ioccom.h 8.2 (Berkeley) 3/28/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYS_IOCCOM_H_
|
||||
#define _COMPAT_SYS_IOCCOM_H_
|
||||
|
||||
/*
|
||||
* Ioctl's have the command encoded in the lower word, and the size of
|
||||
* any in or out parameters in the upper word. The high 3 bits of the
|
||||
* upper word are used to encode the in/out status of the parameter.
|
||||
*/
|
||||
#define IOCPARM_SHIFT 13 /* number of bits for ioctl size */
|
||||
#define IOCPARM_MASK ((1 << IOCPARM_SHIFT) - 1) /* parameter length mask */
|
||||
#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
|
||||
#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
|
||||
#define IOCGROUP(x) (((x) >> 8) & 0xff)
|
||||
|
||||
#define IOCPARM_MAX (1 << IOCPARM_SHIFT) /* max size of ioctl */
|
||||
#define IOC_VOID 0x20000000 /* no parameters */
|
||||
#define IOC_OUT 0x40000000 /* copy out parameters */
|
||||
#define IOC_IN 0x80000000 /* copy in parameters */
|
||||
#define IOC_INOUT (IOC_IN|IOC_OUT)
|
||||
#define IOC_DIRMASK (IOC_VOID|IOC_OUT|IOC_IN)
|
||||
|
||||
#define _IOC(inout,group,num,len) ((unsigned long) \
|
||||
((inout) | (((len) & IOCPARM_MASK) << 16) | ((group) << 8) | (num)))
|
||||
#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0)
|
||||
#define _IOWINT(g,n) _IOC(IOC_VOID, (g), (n), sizeof(int))
|
||||
#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
|
||||
#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
|
||||
/* this should be _IORW, but stdio got there first */
|
||||
#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
|
||||
|
||||
int ioctl_va(int fd, unsigned long request, void *data, int argc, ...);
|
||||
|
||||
#define ioctl(a, b, c) ioctl_va((a), (b), (c), 0)
|
||||
|
||||
#endif /* !_COMPAT_SYS_IOCCOM_H_ */
|
|
@ -0,0 +1,44 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1986, 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
* 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)ioctl.h 8.6 (Berkeley) 3/28/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYS_IOCTL_H_
|
||||
#define _COMPAT_SYS_IOCTL_H_
|
||||
|
||||
#include "sys/ioccom.h"
|
||||
#include "sys/sockio.h"
|
||||
|
||||
#endif /* !_COMPAT_SYS_IOCTL_H_ */
|
|
@ -0,0 +1,753 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)queue.h 8.5 (Berkeley) 8/20/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _SYS_QUEUE_H_
|
||||
#define _SYS_QUEUE_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/*
|
||||
* This file defines four types of data structures: singly-linked lists,
|
||||
* singly-linked tail queues, lists and tail queues.
|
||||
*
|
||||
* A singly-linked list is headed by a single forward pointer. The elements
|
||||
* are singly linked for minimum space and pointer manipulation overhead at
|
||||
* the expense of O(n) removal for arbitrary elements. New elements can be
|
||||
* added to the list after an existing element or at the head of the list.
|
||||
* Elements being removed from the head of the list should use the explicit
|
||||
* macro for this purpose for optimum efficiency. A singly-linked list may
|
||||
* only be traversed in the forward direction. Singly-linked lists are ideal
|
||||
* for applications with large datasets and few or no removals or for
|
||||
* implementing a LIFO queue.
|
||||
*
|
||||
* A singly-linked tail queue is headed by a pair of pointers, one to the
|
||||
* head of the list and the other to the tail of the list. The elements are
|
||||
* singly linked for minimum space and pointer manipulation overhead at the
|
||||
* expense of O(n) removal for arbitrary elements. New elements can be added
|
||||
* to the list after an existing element, at the head of the list, or at the
|
||||
* end of the list. Elements being removed from the head of the tail queue
|
||||
* should use the explicit macro for this purpose for optimum efficiency.
|
||||
* A singly-linked tail queue may only be traversed in the forward direction.
|
||||
* Singly-linked tail queues are ideal for applications with large datasets
|
||||
* and few or no removals or for implementing a FIFO queue.
|
||||
*
|
||||
* A list is headed by a single forward pointer (or an array of forward
|
||||
* pointers for a hash table header). The elements are doubly linked
|
||||
* so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before
|
||||
* or after an existing element or at the head of the list. A list
|
||||
* may be traversed in either direction.
|
||||
*
|
||||
* A tail queue is headed by a pair of pointers, one to the head of the
|
||||
* list and the other to the tail of the list. The elements are doubly
|
||||
* linked so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before or
|
||||
* after an existing element, at the head of the list, or at the end of
|
||||
* the list. A tail queue may be traversed in either direction.
|
||||
*
|
||||
* For details on the use of these macros, see the queue(3) manual page.
|
||||
*
|
||||
*
|
||||
* SLIST LIST STAILQ TAILQ
|
||||
* _HEAD + + + +
|
||||
* _CLASS_HEAD + + + +
|
||||
* _HEAD_INITIALIZER + + + +
|
||||
* _ENTRY + + + +
|
||||
* _CLASS_ENTRY + + + +
|
||||
* _INIT + + + +
|
||||
* _EMPTY + + + +
|
||||
* _FIRST + + + +
|
||||
* _NEXT + + + +
|
||||
* _PREV - + - +
|
||||
* _LAST - - + +
|
||||
* _FOREACH + + + +
|
||||
* _FOREACH_FROM + + + +
|
||||
* _FOREACH_SAFE + + + +
|
||||
* _FOREACH_FROM_SAFE + + + +
|
||||
* _FOREACH_REVERSE - - - +
|
||||
* _FOREACH_REVERSE_FROM - - - +
|
||||
* _FOREACH_REVERSE_SAFE - - - +
|
||||
* _FOREACH_REVERSE_FROM_SAFE - - - +
|
||||
* _INSERT_HEAD + + + +
|
||||
* _INSERT_BEFORE - + - +
|
||||
* _INSERT_AFTER + + + +
|
||||
* _INSERT_TAIL - - + +
|
||||
* _CONCAT - - + +
|
||||
* _REMOVE_AFTER + - + -
|
||||
* _REMOVE_HEAD + - + -
|
||||
* _REMOVE + + + +
|
||||
* _SWAP + + + +
|
||||
*
|
||||
*/
|
||||
#ifdef QUEUE_MACRO_DEBUG
|
||||
/* Store the last 2 places the queue element or head was altered */
|
||||
struct qm_trace {
|
||||
unsigned long lastline;
|
||||
unsigned long prevline;
|
||||
const char *lastfile;
|
||||
const char *prevfile;
|
||||
};
|
||||
|
||||
#define TRACEBUF struct qm_trace trace;
|
||||
#define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL } ,
|
||||
#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
|
||||
#define QMD_SAVELINK(name, link) void **name = (void *)&(link)
|
||||
|
||||
#define QMD_TRACE_HEAD(head) do { \
|
||||
(head)->trace.prevline = (head)->trace.lastline; \
|
||||
(head)->trace.prevfile = (head)->trace.lastfile; \
|
||||
(head)->trace.lastline = __LINE__; \
|
||||
(head)->trace.lastfile = __FILE__; \
|
||||
} while (0)
|
||||
|
||||
#define QMD_TRACE_ELEM(elem) do { \
|
||||
(elem)->trace.prevline = (elem)->trace.lastline; \
|
||||
(elem)->trace.prevfile = (elem)->trace.lastfile; \
|
||||
(elem)->trace.lastline = __LINE__; \
|
||||
(elem)->trace.lastfile = __FILE__; \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
#define QMD_TRACE_ELEM(elem)
|
||||
#define QMD_TRACE_HEAD(head)
|
||||
#define QMD_SAVELINK(name, link)
|
||||
#define TRACEBUF
|
||||
#define TRACEBUF_INITIALIZER
|
||||
#define TRASHIT(x)
|
||||
#endif /* QUEUE_MACRO_DEBUG */
|
||||
|
||||
#ifdef __cplusplus
|
||||
/*
|
||||
* In C++ there can be structure lists and class lists:
|
||||
*/
|
||||
#define QUEUE_TYPEOF(type) type
|
||||
#else
|
||||
#define QUEUE_TYPEOF(type) struct type
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Singly-linked List declarations.
|
||||
*/
|
||||
#define SLIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *slh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define SLIST_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *slh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define SLIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define SLIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *sle_next; /* next element */ \
|
||||
}
|
||||
|
||||
#define SLIST_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *sle_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Singly-linked List functions.
|
||||
*/
|
||||
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
|
||||
|
||||
#define SLIST_FIRST(head) ((head)->slh_first)
|
||||
|
||||
#define SLIST_FOREACH(var, head, field) \
|
||||
for ((var) = SLIST_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = SLIST_NEXT((var), field))
|
||||
|
||||
#define SLIST_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = SLIST_NEXT((var), field))
|
||||
|
||||
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = SLIST_FIRST((head)); \
|
||||
(var) && ((tvar) = SLIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \
|
||||
(var) && ((tvar) = SLIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
|
||||
for ((varp) = &SLIST_FIRST((head)); \
|
||||
((var) = *(varp)) != NULL; \
|
||||
(varp) = &SLIST_NEXT((var), field))
|
||||
|
||||
#define SLIST_INIT(head) do { \
|
||||
SLIST_FIRST((head)) = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
|
||||
SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
|
||||
SLIST_NEXT((slistelm), field) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_INSERT_HEAD(head, elm, field) do { \
|
||||
SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
|
||||
SLIST_FIRST((head)) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
|
||||
|
||||
#define SLIST_REMOVE(head, elm, type, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.sle_next); \
|
||||
if (SLIST_FIRST((head)) == (elm)) { \
|
||||
SLIST_REMOVE_HEAD((head), field); \
|
||||
} \
|
||||
else { \
|
||||
QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \
|
||||
while (SLIST_NEXT(curelm, field) != (elm)) \
|
||||
curelm = SLIST_NEXT(curelm, field); \
|
||||
SLIST_REMOVE_AFTER(curelm, field); \
|
||||
} \
|
||||
TRASHIT(*oldnext); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE_AFTER(elm, field) do { \
|
||||
SLIST_NEXT(elm, field) = \
|
||||
SLIST_NEXT(SLIST_NEXT(elm, field), field); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE_HEAD(head, field) do { \
|
||||
SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_SWAP(head1, head2, type) do { \
|
||||
QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \
|
||||
SLIST_FIRST(head1) = SLIST_FIRST(head2); \
|
||||
SLIST_FIRST(head2) = swap_first; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Singly-linked Tail queue declarations.
|
||||
*/
|
||||
#define STAILQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *stqh_first;/* first element */ \
|
||||
struct type **stqh_last;/* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define STAILQ_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *stqh_first; /* first element */ \
|
||||
class type **stqh_last; /* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define STAILQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).stqh_first }
|
||||
|
||||
#define STAILQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *stqe_next; /* next element */ \
|
||||
}
|
||||
|
||||
#define STAILQ_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *stqe_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Singly-linked Tail queue functions.
|
||||
*/
|
||||
#define STAILQ_CONCAT(head1, head2) do { \
|
||||
if (!STAILQ_EMPTY((head2))) { \
|
||||
*(head1)->stqh_last = (head2)->stqh_first; \
|
||||
(head1)->stqh_last = (head2)->stqh_last; \
|
||||
STAILQ_INIT((head2)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
|
||||
|
||||
#define STAILQ_FIRST(head) ((head)->stqh_first)
|
||||
|
||||
#define STAILQ_FOREACH(var, head, field) \
|
||||
for((var) = STAILQ_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = STAILQ_NEXT((var), field))
|
||||
|
||||
#define STAILQ_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = STAILQ_NEXT((var), field))
|
||||
|
||||
#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = STAILQ_FIRST((head)); \
|
||||
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \
|
||||
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define STAILQ_INIT(head) do { \
|
||||
STAILQ_FIRST((head)) = NULL; \
|
||||
(head)->stqh_last = &STAILQ_FIRST((head)); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
|
||||
if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
STAILQ_NEXT((tqelm), field) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||
if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
STAILQ_FIRST((head)) = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
|
||||
STAILQ_NEXT((elm), field) = NULL; \
|
||||
*(head)->stqh_last = (elm); \
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_LAST(head, type, field) \
|
||||
(STAILQ_EMPTY((head)) ? NULL : \
|
||||
__containerof((head)->stqh_last, \
|
||||
QUEUE_TYPEOF(type), field.stqe_next))
|
||||
|
||||
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
|
||||
|
||||
#define STAILQ_REMOVE(head, elm, type, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \
|
||||
if (STAILQ_FIRST((head)) == (elm)) { \
|
||||
STAILQ_REMOVE_HEAD((head), field); \
|
||||
} \
|
||||
else { \
|
||||
QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \
|
||||
while (STAILQ_NEXT(curelm, field) != (elm)) \
|
||||
curelm = STAILQ_NEXT(curelm, field); \
|
||||
STAILQ_REMOVE_AFTER(head, curelm, field); \
|
||||
} \
|
||||
TRASHIT(*oldnext); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_REMOVE_AFTER(head, elm, field) do { \
|
||||
if ((STAILQ_NEXT(elm, field) = \
|
||||
STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \
|
||||
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_REMOVE_HEAD(head, field) do { \
|
||||
if ((STAILQ_FIRST((head)) = \
|
||||
STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
|
||||
(head)->stqh_last = &STAILQ_FIRST((head)); \
|
||||
} while (0)
|
||||
|
||||
#define STAILQ_SWAP(head1, head2, type) do { \
|
||||
QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \
|
||||
QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \
|
||||
STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \
|
||||
(head1)->stqh_last = (head2)->stqh_last; \
|
||||
STAILQ_FIRST(head2) = swap_first; \
|
||||
(head2)->stqh_last = swap_last; \
|
||||
if (STAILQ_EMPTY(head1)) \
|
||||
(head1)->stqh_last = &STAILQ_FIRST(head1); \
|
||||
if (STAILQ_EMPTY(head2)) \
|
||||
(head2)->stqh_last = &STAILQ_FIRST(head2); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
* List declarations.
|
||||
*/
|
||||
#define LIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *lh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define LIST_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *lh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define LIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define LIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *le_next; /* next element */ \
|
||||
struct type **le_prev; /* address of previous next element */ \
|
||||
}
|
||||
|
||||
#define LIST_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *le_next; /* next element */ \
|
||||
class type **le_prev; /* address of previous next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* List functions.
|
||||
*/
|
||||
|
||||
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||
#define QMD_LIST_CHECK_HEAD(head, field) do { \
|
||||
if (LIST_FIRST((head)) != NULL && \
|
||||
LIST_FIRST((head))->field.le_prev != \
|
||||
&LIST_FIRST((head))) \
|
||||
panic("Bad list head %p first->prev != head", (head)); \
|
||||
} while (0)
|
||||
|
||||
#define QMD_LIST_CHECK_NEXT(elm, field) do { \
|
||||
if (LIST_NEXT((elm), field) != NULL && \
|
||||
LIST_NEXT((elm), field)->field.le_prev != \
|
||||
&((elm)->field.le_next)) \
|
||||
panic("Bad link elm %p next->prev != elm", (elm)); \
|
||||
} while (0)
|
||||
|
||||
#define QMD_LIST_CHECK_PREV(elm, field) do { \
|
||||
if (*(elm)->field.le_prev != (elm)) \
|
||||
panic("Bad link elm %p prev->next != elm", (elm)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define QMD_LIST_CHECK_HEAD(head, field)
|
||||
#define QMD_LIST_CHECK_NEXT(elm, field)
|
||||
#define QMD_LIST_CHECK_PREV(elm, field)
|
||||
#endif /* (_KERNEL && INVARIANTS) */
|
||||
|
||||
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
|
||||
|
||||
#define LIST_FIRST(head) ((head)->lh_first)
|
||||
|
||||
#define LIST_FOREACH(var, head, field) \
|
||||
for ((var) = LIST_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = LIST_NEXT((var), field))
|
||||
|
||||
#define LIST_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : LIST_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = LIST_NEXT((var), field))
|
||||
|
||||
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = LIST_FIRST((head)); \
|
||||
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define LIST_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : LIST_FIRST((head))); \
|
||||
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define LIST_INIT(head) do { \
|
||||
LIST_FIRST((head)) = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
|
||||
QMD_LIST_CHECK_NEXT(listelm, field); \
|
||||
if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
|
||||
LIST_NEXT((listelm), field)->field.le_prev = \
|
||||
&LIST_NEXT((elm), field); \
|
||||
LIST_NEXT((listelm), field) = (elm); \
|
||||
(elm)->field.le_prev = &LIST_NEXT((listelm), field); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
QMD_LIST_CHECK_PREV(listelm, field); \
|
||||
(elm)->field.le_prev = (listelm)->field.le_prev; \
|
||||
LIST_NEXT((elm), field) = (listelm); \
|
||||
*(listelm)->field.le_prev = (elm); \
|
||||
(listelm)->field.le_prev = &LIST_NEXT((elm), field); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_HEAD(head, elm, field) do { \
|
||||
QMD_LIST_CHECK_HEAD((head), field); \
|
||||
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
|
||||
LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
|
||||
LIST_FIRST((head)) = (elm); \
|
||||
(elm)->field.le_prev = &LIST_FIRST((head)); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
|
||||
|
||||
#define LIST_PREV(elm, head, type, field) \
|
||||
((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \
|
||||
__containerof((elm)->field.le_prev, \
|
||||
QUEUE_TYPEOF(type), field.le_next))
|
||||
|
||||
#define LIST_REMOVE(elm, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.le_next); \
|
||||
QMD_SAVELINK(oldprev, (elm)->field.le_prev); \
|
||||
QMD_LIST_CHECK_NEXT(elm, field); \
|
||||
QMD_LIST_CHECK_PREV(elm, field); \
|
||||
if (LIST_NEXT((elm), field) != NULL) \
|
||||
LIST_NEXT((elm), field)->field.le_prev = \
|
||||
(elm)->field.le_prev; \
|
||||
*(elm)->field.le_prev = LIST_NEXT((elm), field); \
|
||||
TRASHIT(*oldnext); \
|
||||
TRASHIT(*oldprev); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_SWAP(head1, head2, type, field) do { \
|
||||
QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \
|
||||
LIST_FIRST((head1)) = LIST_FIRST((head2)); \
|
||||
LIST_FIRST((head2)) = swap_tmp; \
|
||||
if ((swap_tmp = LIST_FIRST((head1))) != NULL) \
|
||||
swap_tmp->field.le_prev = &LIST_FIRST((head1)); \
|
||||
if ((swap_tmp = LIST_FIRST((head2))) != NULL) \
|
||||
swap_tmp->field.le_prev = &LIST_FIRST((head2)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Tail queue declarations.
|
||||
*/
|
||||
#define TAILQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *tqh_first; /* first element */ \
|
||||
struct type **tqh_last; /* addr of last next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
#define TAILQ_CLASS_HEAD(name, type) \
|
||||
struct name { \
|
||||
class type *tqh_first; /* first element */ \
|
||||
class type **tqh_last; /* addr of last next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
#define TAILQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).tqh_first, TRACEBUF_INITIALIZER }
|
||||
|
||||
#define TAILQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *tqe_next; /* next element */ \
|
||||
struct type **tqe_prev; /* address of previous next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
#define TAILQ_CLASS_ENTRY(type) \
|
||||
struct { \
|
||||
class type *tqe_next; /* next element */ \
|
||||
class type **tqe_prev; /* address of previous next element */ \
|
||||
TRACEBUF \
|
||||
}
|
||||
|
||||
/*
|
||||
* Tail queue functions.
|
||||
*/
|
||||
#if (defined(_KERNEL) && defined(INVARIANTS))
|
||||
#define QMD_TAILQ_CHECK_HEAD(head, field) do { \
|
||||
if (!TAILQ_EMPTY(head) && \
|
||||
TAILQ_FIRST((head))->field.tqe_prev != \
|
||||
&TAILQ_FIRST((head))) \
|
||||
panic("Bad tailq head %p first->prev != head", (head)); \
|
||||
} while (0)
|
||||
|
||||
#define QMD_TAILQ_CHECK_TAIL(head, field) do { \
|
||||
if (*(head)->tqh_last != NULL) \
|
||||
panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \
|
||||
} while (0)
|
||||
|
||||
#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \
|
||||
if (TAILQ_NEXT((elm), field) != NULL && \
|
||||
TAILQ_NEXT((elm), field)->field.tqe_prev != \
|
||||
&((elm)->field.tqe_next)) \
|
||||
panic("Bad link elm %p next->prev != elm", (elm)); \
|
||||
} while (0)
|
||||
|
||||
#define QMD_TAILQ_CHECK_PREV(elm, field) do { \
|
||||
if (*(elm)->field.tqe_prev != (elm)) \
|
||||
panic("Bad link elm %p prev->next != elm", (elm)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define QMD_TAILQ_CHECK_HEAD(head, field)
|
||||
#define QMD_TAILQ_CHECK_TAIL(head, headname)
|
||||
#define QMD_TAILQ_CHECK_NEXT(elm, field)
|
||||
#define QMD_TAILQ_CHECK_PREV(elm, field)
|
||||
#endif /* (_KERNEL && INVARIANTS) */
|
||||
|
||||
#define TAILQ_CONCAT(head1, head2, field) do { \
|
||||
if (!TAILQ_EMPTY(head2)) { \
|
||||
*(head1)->tqh_last = (head2)->tqh_first; \
|
||||
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
|
||||
(head1)->tqh_last = (head2)->tqh_last; \
|
||||
TAILQ_INIT((head2)); \
|
||||
QMD_TRACE_HEAD(head1); \
|
||||
QMD_TRACE_HEAD(head2); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
|
||||
|
||||
#define TAILQ_FIRST(head) ((head)->tqh_first)
|
||||
|
||||
#define TAILQ_FOREACH(var, head, field) \
|
||||
for ((var) = TAILQ_FIRST((head)); \
|
||||
(var); \
|
||||
(var) = TAILQ_NEXT((var), field))
|
||||
|
||||
#define TAILQ_FOREACH_FROM(var, head, field) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \
|
||||
(var); \
|
||||
(var) = TAILQ_NEXT((var), field))
|
||||
|
||||
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
|
||||
for ((var) = TAILQ_FIRST((head)); \
|
||||
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \
|
||||
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
|
||||
for ((var) = TAILQ_LAST((head), headname); \
|
||||
(var); \
|
||||
(var) = TAILQ_PREV((var), headname, field))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \
|
||||
(var); \
|
||||
(var) = TAILQ_PREV((var), headname, field))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
|
||||
for ((var) = TAILQ_LAST((head), headname); \
|
||||
(var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \
|
||||
for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \
|
||||
(var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
|
||||
(var) = (tvar))
|
||||
|
||||
#define TAILQ_INIT(head) do { \
|
||||
TAILQ_FIRST((head)) = NULL; \
|
||||
(head)->tqh_last = &TAILQ_FIRST((head)); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_NEXT(listelm, field); \
|
||||
if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
|
||||
TAILQ_NEXT((elm), field)->field.tqe_prev = \
|
||||
&TAILQ_NEXT((elm), field); \
|
||||
else { \
|
||||
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
} \
|
||||
TAILQ_NEXT((listelm), field) = (elm); \
|
||||
(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
QMD_TRACE_ELEM(&(listelm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_PREV(listelm, field); \
|
||||
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
|
||||
TAILQ_NEXT((elm), field) = (listelm); \
|
||||
*(listelm)->field.tqe_prev = (elm); \
|
||||
(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
QMD_TRACE_ELEM(&(listelm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_HEAD(head, field); \
|
||||
if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
|
||||
TAILQ_FIRST((head))->field.tqe_prev = \
|
||||
&TAILQ_NEXT((elm), field); \
|
||||
else \
|
||||
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
|
||||
TAILQ_FIRST((head)) = (elm); \
|
||||
(elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
|
||||
QMD_TAILQ_CHECK_TAIL(head, field); \
|
||||
TAILQ_NEXT((elm), field) = NULL; \
|
||||
(elm)->field.tqe_prev = (head)->tqh_last; \
|
||||
*(head)->tqh_last = (elm); \
|
||||
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_LAST(head, headname) \
|
||||
(*(((struct headname *)((head)->tqh_last))->tqh_last))
|
||||
|
||||
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
|
||||
|
||||
#define TAILQ_PREV(elm, headname, field) \
|
||||
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
|
||||
|
||||
#define TAILQ_REMOVE(head, elm, field) do { \
|
||||
QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \
|
||||
QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \
|
||||
QMD_TAILQ_CHECK_NEXT(elm, field); \
|
||||
QMD_TAILQ_CHECK_PREV(elm, field); \
|
||||
if ((TAILQ_NEXT((elm), field)) != NULL) \
|
||||
TAILQ_NEXT((elm), field)->field.tqe_prev = \
|
||||
(elm)->field.tqe_prev; \
|
||||
else { \
|
||||
(head)->tqh_last = (elm)->field.tqe_prev; \
|
||||
QMD_TRACE_HEAD(head); \
|
||||
} \
|
||||
*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
|
||||
TRASHIT(*oldnext); \
|
||||
TRASHIT(*oldprev); \
|
||||
QMD_TRACE_ELEM(&(elm)->field); \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_SWAP(head1, head2, type, field) do { \
|
||||
QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \
|
||||
QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \
|
||||
(head1)->tqh_first = (head2)->tqh_first; \
|
||||
(head1)->tqh_last = (head2)->tqh_last; \
|
||||
(head2)->tqh_first = swap_first; \
|
||||
(head2)->tqh_last = swap_last; \
|
||||
if ((swap_first = (head1)->tqh_first) != NULL) \
|
||||
swap_first->field.tqe_prev = &(head1)->tqh_first; \
|
||||
else \
|
||||
(head1)->tqh_last = &(head1)->tqh_first; \
|
||||
if ((swap_first = (head2)->tqh_first) != NULL) \
|
||||
swap_first->field.tqe_prev = &(head2)->tqh_first; \
|
||||
else \
|
||||
(head2)->tqh_last = &(head2)->tqh_first; \
|
||||
} while (0)
|
||||
|
||||
#endif /* !_SYS_QUEUE_H_ */
|
|
@ -0,0 +1,604 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)socket.h 8.4 (Berkeley) 2/21/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYS_SOCKET_H_
|
||||
#define _COMPAT_SYS_SOCKET_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/_types.h>
|
||||
#include <sys/_iovec.h>
|
||||
|
||||
/*
|
||||
* Definitions related to sockets: types, address families, options.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Data types.
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
#ifndef _GID_T_DECLARED
|
||||
typedef __gid_t gid_t;
|
||||
#define _GID_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _OFF_T_DECLARED
|
||||
typedef __off_t off_t;
|
||||
#define _OFF_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _PID_T_DECLARED
|
||||
typedef __pid_t pid_t;
|
||||
#define _PID_T_DECLARED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _SA_FAMILY_T_DECLARED
|
||||
typedef __sa_family_t sa_family_t;
|
||||
#define _SA_FAMILY_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _SOCKLEN_T_DECLARED
|
||||
typedef __socklen_t socklen_t;
|
||||
#define _SOCKLEN_T_DECLARED
|
||||
#endif
|
||||
|
||||
#ifndef _SSIZE_T_DECLARED
|
||||
typedef __ssize_t ssize_t;
|
||||
#define _SSIZE_T_DECLARED
|
||||
#endif
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
#ifndef _UID_T_DECLARED
|
||||
typedef __uid_t uid_t;
|
||||
#define _UID_T_DECLARED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _UINT32_T_DECLARED
|
||||
typedef __uint32_t uint32_t;
|
||||
#define _UINT32_T_DECLARED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Types
|
||||
*/
|
||||
#define SOCK_STREAM 1 /* stream socket */
|
||||
#define SOCK_DGRAM 2 /* datagram socket */
|
||||
#define SOCK_RAW 3 /* raw-protocol interface */
|
||||
#if __BSD_VISIBLE
|
||||
#define SOCK_RDM 4 /* reliably-delivered message */
|
||||
#endif
|
||||
#define SOCK_SEQPACKET 5 /* sequenced packet stream */
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* Creation flags, OR'ed into socket() and socketpair() type argument.
|
||||
*/
|
||||
#define SOCK_CLOEXEC 0x10000000
|
||||
#define SOCK_NONBLOCK 0x20000000
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Option flags per-socket.
|
||||
*/
|
||||
#define SO_DEBUG 0x0001 /* turn on debugging info recording */
|
||||
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
|
||||
#define SO_REUSEADDR 0x0004 /* allow local address reuse */
|
||||
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
|
||||
#define SO_DONTROUTE 0x0010 /* just use interface addresses */
|
||||
#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
|
||||
#if __BSD_VISIBLE
|
||||
#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
|
||||
#endif
|
||||
#define SO_LINGER 0x0080 /* linger on close if data present */
|
||||
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
|
||||
#if __BSD_VISIBLE
|
||||
#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
|
||||
#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
|
||||
#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
|
||||
#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
|
||||
#define SO_BINTIME 0x2000 /* timestamp received dgram traffic */
|
||||
#endif
|
||||
#define SO_NO_OFFLOAD 0x4000 /* socket cannot be offloaded */
|
||||
#define SO_NO_DDP 0x8000 /* disable direct data placement */
|
||||
|
||||
/*
|
||||
* Additional options, not kept in so_options.
|
||||
*/
|
||||
#define SO_SNDBUF 0x1001 /* send buffer size */
|
||||
#define SO_RCVBUF 0x1002 /* receive buffer size */
|
||||
#define SO_SNDLOWAT 0x1003 /* send low-water mark */
|
||||
#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
|
||||
#define SO_SNDTIMEO 0x1005 /* send timeout */
|
||||
#define SO_RCVTIMEO 0x1006 /* receive timeout */
|
||||
#define SO_ERROR 0x1007 /* get error status and clear */
|
||||
#define SO_TYPE 0x1008 /* get socket type */
|
||||
#if __BSD_VISIBLE
|
||||
#define SO_LABEL 0x1009 /* socket's MAC label */
|
||||
#define SO_PEERLABEL 0x1010 /* socket's peer's MAC label */
|
||||
#define SO_LISTENQLIMIT 0x1011 /* socket's backlog limit */
|
||||
#define SO_LISTENQLEN 0x1012 /* socket's complete queue length */
|
||||
#define SO_LISTENINCQLEN 0x1013 /* socket's incomplete queue length */
|
||||
#define SO_SETFIB 0x1014 /* use this FIB to route */
|
||||
#define SO_USER_COOKIE 0x1015 /* user cookie (dummynet etc.) */
|
||||
#define SO_PROTOCOL 0x1016 /* get socket protocol (Linux name) */
|
||||
#define SO_PROTOTYPE SO_PROTOCOL /* alias for SO_PROTOCOL (SunOS name) */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Space reserved for new socket options added by third-party vendors.
|
||||
* This range applies to all socket option levels. New socket options
|
||||
* in FreeBSD should always use an option value less than SO_VENDOR.
|
||||
*/
|
||||
#if __BSD_VISIBLE
|
||||
#define SO_VENDOR 0x80000000
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structure used for manipulating linger option.
|
||||
*/
|
||||
struct linger {
|
||||
int l_onoff; /* option on/off */
|
||||
int l_linger; /* linger time */
|
||||
};
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
struct accept_filter_arg {
|
||||
char af_name[16];
|
||||
char af_arg[256-16];
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Level number for (get/set)sockopt() to apply to socket itself.
|
||||
*/
|
||||
#define SOL_SOCKET 0xffff /* options for socket level */
|
||||
|
||||
/*
|
||||
* Address families.
|
||||
*/
|
||||
#define AF_UNSPEC 0 /* unspecified */
|
||||
#if __BSD_VISIBLE
|
||||
#define AF_LOCAL AF_UNIX /* local to host (pipes, portals) */
|
||||
#endif
|
||||
#define AF_UNIX 1 /* standardized name for AF_LOCAL */
|
||||
#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
|
||||
#if __BSD_VISIBLE
|
||||
#define AF_IMPLINK 3 /* arpanet imp addresses */
|
||||
#define AF_PUP 4 /* pup protocols: e.g. BSP */
|
||||
#define AF_CHAOS 5 /* mit CHAOS protocols */
|
||||
#define AF_NETBIOS 6 /* SMB protocols */
|
||||
#define AF_ISO 7 /* ISO protocols */
|
||||
#define AF_OSI AF_ISO
|
||||
#define AF_ECMA 8 /* European computer manufacturers */
|
||||
#define AF_DATAKIT 9 /* datakit protocols */
|
||||
#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
|
||||
#define AF_SNA 11 /* IBM SNA */
|
||||
#define AF_DECnet 12 /* DECnet */
|
||||
#define AF_DLI 13 /* DEC Direct data link interface */
|
||||
#define AF_LAT 14 /* LAT */
|
||||
#define AF_HYLINK 15 /* NSC Hyperchannel */
|
||||
#define AF_APPLETALK 16 /* Apple Talk */
|
||||
#define AF_ROUTE 17 /* Internal Routing Protocol */
|
||||
#define AF_LINK 18 /* Link layer interface */
|
||||
#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
|
||||
#define AF_COIP 20 /* connection-oriented IP, aka ST II */
|
||||
#define AF_CNT 21 /* Computer Network Technology */
|
||||
#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
|
||||
#define AF_IPX 23 /* Novell Internet Protocol */
|
||||
#define AF_SIP 24 /* Simple Internet Protocol */
|
||||
#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
|
||||
#define AF_ISDN 26 /* Integrated Services Digital Network*/
|
||||
#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
|
||||
#define pseudo_AF_KEY 27 /* Internal key-management function */
|
||||
#endif
|
||||
#define AF_INET6 28 /* IPv6 */
|
||||
#if __BSD_VISIBLE
|
||||
#define AF_NATM 29 /* native ATM access */
|
||||
#define AF_ATM 30 /* ATM */
|
||||
#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers
|
||||
* in interface output routine
|
||||
*/
|
||||
#define AF_NETGRAPH 32 /* Netgraph sockets */
|
||||
#define AF_SLOW 33 /* 802.3ad slow protocol */
|
||||
#define AF_SCLUSTER 34 /* Sitara cluster protocol */
|
||||
#define AF_ARP 35
|
||||
#define AF_BLUETOOTH 36 /* Bluetooth sockets */
|
||||
#define AF_IEEE80211 37 /* IEEE 802.11 protocol */
|
||||
#define AF_INET_SDP 40 /* OFED Socket Direct Protocol ipv4 */
|
||||
#define AF_INET6_SDP 42 /* OFED Socket Direct Protocol ipv6 */
|
||||
#define AF_MAX 42
|
||||
/*
|
||||
* When allocating a new AF_ constant, please only allocate
|
||||
* even numbered constants for FreeBSD until 134 as odd numbered AF_
|
||||
* constants 39-133 are now reserved for vendors.
|
||||
*/
|
||||
#define AF_VENDOR00 39
|
||||
#define AF_VENDOR01 41
|
||||
#define AF_VENDOR02 43
|
||||
#define AF_VENDOR03 45
|
||||
#define AF_VENDOR04 47
|
||||
#define AF_VENDOR05 49
|
||||
#define AF_VENDOR06 51
|
||||
#define AF_VENDOR07 53
|
||||
#define AF_VENDOR08 55
|
||||
#define AF_VENDOR09 57
|
||||
#define AF_VENDOR10 59
|
||||
#define AF_VENDOR11 61
|
||||
#define AF_VENDOR12 63
|
||||
#define AF_VENDOR13 65
|
||||
#define AF_VENDOR14 67
|
||||
#define AF_VENDOR15 69
|
||||
#define AF_VENDOR16 71
|
||||
#define AF_VENDOR17 73
|
||||
#define AF_VENDOR18 75
|
||||
#define AF_VENDOR19 77
|
||||
#define AF_VENDOR20 79
|
||||
#define AF_VENDOR21 81
|
||||
#define AF_VENDOR22 83
|
||||
#define AF_VENDOR23 85
|
||||
#define AF_VENDOR24 87
|
||||
#define AF_VENDOR25 89
|
||||
#define AF_VENDOR26 91
|
||||
#define AF_VENDOR27 93
|
||||
#define AF_VENDOR28 95
|
||||
#define AF_VENDOR29 97
|
||||
#define AF_VENDOR30 99
|
||||
#define AF_VENDOR31 101
|
||||
#define AF_VENDOR32 103
|
||||
#define AF_VENDOR33 105
|
||||
#define AF_VENDOR34 107
|
||||
#define AF_VENDOR35 109
|
||||
#define AF_VENDOR36 111
|
||||
#define AF_VENDOR37 113
|
||||
#define AF_VENDOR38 115
|
||||
#define AF_VENDOR39 117
|
||||
#define AF_VENDOR40 119
|
||||
#define AF_VENDOR41 121
|
||||
#define AF_VENDOR42 123
|
||||
#define AF_VENDOR43 125
|
||||
#define AF_VENDOR44 127
|
||||
#define AF_VENDOR45 129
|
||||
#define AF_VENDOR46 131
|
||||
#define AF_VENDOR47 133
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Structure used by kernel to store most
|
||||
* addresses.
|
||||
*/
|
||||
struct sockaddr {
|
||||
unsigned char sa_len; /* total length */
|
||||
sa_family_t sa_family; /* address family */
|
||||
char sa_data[14]; /* actually longer; address value */
|
||||
};
|
||||
#if __BSD_VISIBLE
|
||||
#define SOCK_MAXADDRLEN 255 /* longest possible addresses */
|
||||
|
||||
/*
|
||||
* Structure used by kernel to pass protocol
|
||||
* information in raw sockets.
|
||||
*/
|
||||
struct sockproto {
|
||||
unsigned short sp_family; /* address family */
|
||||
unsigned short sp_protocol; /* protocol */
|
||||
};
|
||||
#endif
|
||||
|
||||
#include <sys/_sockaddr_storage.h>
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* Protocol families, same as address families for now.
|
||||
*/
|
||||
#define PF_UNSPEC AF_UNSPEC
|
||||
#define PF_LOCAL AF_LOCAL
|
||||
#define PF_UNIX PF_LOCAL /* backward compatibility */
|
||||
#define PF_INET AF_INET
|
||||
#define PF_IMPLINK AF_IMPLINK
|
||||
#define PF_PUP AF_PUP
|
||||
#define PF_CHAOS AF_CHAOS
|
||||
#define PF_NETBIOS AF_NETBIOS
|
||||
#define PF_ISO AF_ISO
|
||||
#define PF_OSI AF_ISO
|
||||
#define PF_ECMA AF_ECMA
|
||||
#define PF_DATAKIT AF_DATAKIT
|
||||
#define PF_CCITT AF_CCITT
|
||||
#define PF_SNA AF_SNA
|
||||
#define PF_DECnet AF_DECnet
|
||||
#define PF_DLI AF_DLI
|
||||
#define PF_LAT AF_LAT
|
||||
#define PF_HYLINK AF_HYLINK
|
||||
#define PF_APPLETALK AF_APPLETALK
|
||||
#define PF_ROUTE AF_ROUTE
|
||||
#define PF_LINK AF_LINK
|
||||
#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
|
||||
#define PF_COIP AF_COIP
|
||||
#define PF_CNT AF_CNT
|
||||
#define PF_SIP AF_SIP
|
||||
#define PF_IPX AF_IPX
|
||||
#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
|
||||
#define PF_PIP pseudo_AF_PIP
|
||||
#define PF_ISDN AF_ISDN
|
||||
#define PF_KEY pseudo_AF_KEY
|
||||
#define PF_INET6 AF_INET6
|
||||
#define PF_NATM AF_NATM
|
||||
#define PF_ATM AF_ATM
|
||||
#define PF_NETGRAPH AF_NETGRAPH
|
||||
#define PF_SLOW AF_SLOW
|
||||
#define PF_SCLUSTER AF_SCLUSTER
|
||||
#define PF_ARP AF_ARP
|
||||
#define PF_BLUETOOTH AF_BLUETOOTH
|
||||
#define PF_IEEE80211 AF_IEEE80211
|
||||
#define PF_INET_SDP AF_INET_SDP
|
||||
#define PF_INET6_SDP AF_INET6_SDP
|
||||
|
||||
#define PF_MAX AF_MAX
|
||||
|
||||
/*
|
||||
* Definitions for network related sysctl, CTL_NET.
|
||||
*
|
||||
* Second level is protocol family.
|
||||
* Third level is protocol number.
|
||||
*
|
||||
* Further levels are defined by the individual families.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PF_ROUTE - Routing table
|
||||
*
|
||||
* Three additional levels are defined:
|
||||
* Fourth: address family, 0 is wildcard
|
||||
* Fifth: type of info, defined below
|
||||
* Sixth: flag(s) to mask with for NET_RT_FLAGS
|
||||
*/
|
||||
#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
|
||||
#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
|
||||
#define NET_RT_IFLIST 3 /* survey interface list */
|
||||
#define NET_RT_IFMALIST 4 /* return multicast address list */
|
||||
#define NET_RT_IFLISTL 5 /* Survey interface list, using 'l'en
|
||||
* versions of msghdr structs. */
|
||||
#endif /* __BSD_VISIBLE */
|
||||
|
||||
/*
|
||||
* Maximum queue length specifiable by listen.
|
||||
*/
|
||||
#define SOMAXCONN 128
|
||||
|
||||
/*
|
||||
* Message header for recvmsg and sendmsg calls.
|
||||
* Used value-result for recvmsg, value only for sendmsg.
|
||||
*/
|
||||
struct msghdr {
|
||||
void *msg_name; /* optional address */
|
||||
socklen_t msg_namelen; /* size of address */
|
||||
struct iovec *msg_iov; /* scatter/gather array */
|
||||
int msg_iovlen; /* # elements in msg_iov */
|
||||
void *msg_control; /* ancillary data, see below */
|
||||
socklen_t msg_controllen; /* ancillary data buffer len */
|
||||
int msg_flags; /* flags on received message */
|
||||
};
|
||||
|
||||
#define MSG_OOB 0x1 /* process out-of-band data */
|
||||
#define MSG_PEEK 0x2 /* peek at incoming message */
|
||||
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
|
||||
#define MSG_EOR 0x8 /* data completes record */
|
||||
#define MSG_TRUNC 0x10 /* data discarded before delivery */
|
||||
#define MSG_CTRUNC 0x20 /* control data lost before delivery */
|
||||
#define MSG_WAITALL 0x40 /* wait for full request or error */
|
||||
#if __POSIX_VISIBLE >= 200809
|
||||
#define MSG_NOSIGNAL 0x20000 /* do not generate SIGPIPE on EOF */
|
||||
#endif
|
||||
#if __BSD_VISIBLE
|
||||
#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
|
||||
#define MSG_EOF 0x100 /* data completes connection */
|
||||
#define MSG_NOTIFICATION 0x2000 /* SCTP notification */
|
||||
#define MSG_NBIO 0x4000 /* FIONBIO mode, used by fifofs */
|
||||
#define MSG_COMPAT 0x8000 /* used in sendit() */
|
||||
#define MSG_CMSG_CLOEXEC 0x40000 /* make received fds close-on-exec */
|
||||
#define MSG_WAITFORONE 0x80000 /* for recvmmsg() */
|
||||
#endif
|
||||
#ifdef _KERNEL
|
||||
#define MSG_SOCALLBCK 0x10000 /* for use by socket callbacks - soreceive (TCP) */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Header for ancillary data objects in msg_control buffer.
|
||||
* Used for additional information with/about a datagram
|
||||
* not expressible by flags. The format is a sequence
|
||||
* of message elements headed by cmsghdr structures.
|
||||
*/
|
||||
struct cmsghdr {
|
||||
socklen_t cmsg_len; /* data byte count, including hdr */
|
||||
int cmsg_level; /* originating protocol */
|
||||
int cmsg_type; /* protocol-specific type */
|
||||
/* followed by u_char cmsg_data[]; */
|
||||
};
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* While we may have more groups than this, the cmsgcred struct must
|
||||
* be able to fit in an mbuf and we have historically supported a
|
||||
* maximum of 16 groups.
|
||||
*/
|
||||
#define CMGROUP_MAX 16
|
||||
|
||||
/*
|
||||
* Credentials structure, used to verify the identity of a peer
|
||||
* process that has sent us a message. This is allocated by the
|
||||
* peer process but filled in by the kernel. This prevents the
|
||||
* peer from lying about its identity. (Note that cmcred_groups[0]
|
||||
* is the effective GID.)
|
||||
*/
|
||||
struct cmsgcred {
|
||||
pid_t cmcred_pid; /* PID of sending process */
|
||||
uid_t cmcred_uid; /* real UID of sending process */
|
||||
uid_t cmcred_euid; /* effective UID of sending process */
|
||||
gid_t cmcred_gid; /* real GID of sending process */
|
||||
short cmcred_ngroups; /* number or groups */
|
||||
gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
|
||||
};
|
||||
|
||||
/*
|
||||
* Socket credentials.
|
||||
*/
|
||||
struct sockcred {
|
||||
uid_t sc_uid; /* real user id */
|
||||
uid_t sc_euid; /* effective user id */
|
||||
gid_t sc_gid; /* real group id */
|
||||
gid_t sc_egid; /* effective group id */
|
||||
int sc_ngroups; /* number of supplemental groups */
|
||||
gid_t sc_groups[1]; /* variable length */
|
||||
};
|
||||
|
||||
/*
|
||||
* Compute size of a sockcred structure with groups.
|
||||
*/
|
||||
#define SOCKCREDSIZE(ngrps) \
|
||||
(sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
|
||||
|
||||
#endif /* __BSD_VISIBLE */
|
||||
|
||||
/* given pointer to struct cmsghdr, return pointer to data */
|
||||
#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
|
||||
_ALIGN(sizeof(struct cmsghdr)))
|
||||
|
||||
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
|
||||
#define CMSG_NXTHDR(mhdr, cmsg) \
|
||||
((char *)(cmsg) == (char *)0 ? CMSG_FIRSTHDR(mhdr) : \
|
||||
((char *)(cmsg) + _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len) + \
|
||||
_ALIGN(sizeof(struct cmsghdr)) > \
|
||||
(char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
|
||||
(struct cmsghdr *)0 : \
|
||||
(struct cmsghdr *)(void *)((char *)(cmsg) + \
|
||||
_ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len)))
|
||||
|
||||
/*
|
||||
* RFC 2292 requires to check msg_controllen, in case that the kernel returns
|
||||
* an empty list for some reasons.
|
||||
*/
|
||||
#define CMSG_FIRSTHDR(mhdr) \
|
||||
((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
|
||||
(struct cmsghdr *)(mhdr)->msg_control : \
|
||||
(struct cmsghdr *)0)
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/* RFC 2292 additions */
|
||||
#define CMSG_SPACE(l) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
|
||||
#define CMSG_LEN(l) (_ALIGN(sizeof(struct cmsghdr)) + (l))
|
||||
#endif
|
||||
|
||||
#ifdef _KERNEL
|
||||
#define CMSG_ALIGN(n) _ALIGN(n)
|
||||
#endif
|
||||
|
||||
/* "Socket"-level control message types: */
|
||||
#define SCM_RIGHTS 0x01 /* access rights (array of int) */
|
||||
#if __BSD_VISIBLE
|
||||
#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
|
||||
#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
|
||||
#define SCM_BINTIME 0x04 /* timestamp (struct bintime) */
|
||||
#endif
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* 4.3 compat sockaddr, move to compat file later
|
||||
*/
|
||||
struct osockaddr {
|
||||
unsigned short sa_family; /* address family */
|
||||
char sa_data[14]; /* up to 14 bytes of direct address */
|
||||
};
|
||||
|
||||
/*
|
||||
* 4.3-compat message header (move to compat file later).
|
||||
*/
|
||||
struct omsghdr {
|
||||
char *msg_name; /* optional address */
|
||||
int msg_namelen; /* size of address */
|
||||
struct iovec *msg_iov; /* scatter/gather array */
|
||||
int msg_iovlen; /* # elements in msg_iov */
|
||||
char *msg_accrights; /* access rights sent/received */
|
||||
int msg_accrightslen;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* howto arguments for shutdown(2), specified by Posix.1g.
|
||||
*/
|
||||
#define SHUT_RD 0 /* shut down the reading side */
|
||||
#define SHUT_WR 1 /* shut down the writing side */
|
||||
#define SHUT_RDWR 2 /* shut down both sides */
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/* for SCTP */
|
||||
/* we cheat and use the SHUT_XX defines for these */
|
||||
#define PRU_FLUSH_RD SHUT_RD
|
||||
#define PRU_FLUSH_WR SHUT_WR
|
||||
#define PRU_FLUSH_RDWR SHUT_RDWR
|
||||
#endif
|
||||
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
/*
|
||||
* sendfile(2) header/trailer struct
|
||||
*/
|
||||
struct sf_hdtr {
|
||||
struct iovec *headers; /* pointer to an array of header struct iovec's */
|
||||
int hdr_cnt; /* number of header iovec's */
|
||||
struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
|
||||
int trl_cnt; /* number of trailer iovec's */
|
||||
};
|
||||
|
||||
/*
|
||||
* Sendfile-specific flag(s)
|
||||
*/
|
||||
#define SF_NODISKIO 0x00000001
|
||||
#define SF_MNOWAIT 0x00000002 /* obsolete */
|
||||
#define SF_SYNC 0x00000004
|
||||
#define SF_NOCACHE 0x00000010
|
||||
#define SF_FLAGS(rh, flags) (((rh) << 16) | (flags))
|
||||
|
||||
#ifdef _KERNEL
|
||||
#define SF_READAHEAD(flags) ((flags) >> 16)
|
||||
#endif /* _KERNEL */
|
||||
|
||||
/*
|
||||
* Sendmmsg/recvmmsg specific structure(s)
|
||||
*/
|
||||
struct mmsghdr {
|
||||
struct msghdr msg_hdr; /* message header */
|
||||
ssize_t msg_len; /* message length */
|
||||
};
|
||||
#endif /* __BSD_VISIBLE */
|
||||
|
||||
|
||||
#endif /* !_COMPAT_SYS_SOCKET_H_ */
|
|
@ -0,0 +1,136 @@
|
|||
/*-
|
||||
* Copyright (c) 1982, 1986, 1990, 1993, 1994
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*
|
||||
* @(#)sockio.h 8.1 (Berkeley) 3/28/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SOCKIO_H_
|
||||
#define _COMPAT_SOCKIO_H_
|
||||
|
||||
#include "sys/ioccom.h"
|
||||
|
||||
/* Socket ioctl's. */
|
||||
#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
|
||||
#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
|
||||
#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
|
||||
#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
|
||||
#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
|
||||
#define SIOCSPGRP _IOW('s', 8, int) /* set process group */
|
||||
#define SIOCGPGRP _IOR('s', 9, int) /* get process group */
|
||||
|
||||
/* SIOCADDRT _IOW('r', 10, struct ortentry) 4.3BSD */
|
||||
/* SIOCDELRT _IOW('r', 11, struct ortentry) 4.3BSD */
|
||||
#define SIOCGETVIFCNT _IOWR('r', 15, struct sioc_vif_req)/* get vif pkt cnt */
|
||||
#define SIOCGETSGCNT _IOWR('r', 16, struct sioc_sg_req) /* get s,g pkt cnt */
|
||||
|
||||
#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
|
||||
/* OSIOCGIFADDR _IOWR('i', 13, struct ifreq) 4.3BSD */
|
||||
#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */
|
||||
#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
|
||||
/* OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) 4.3BSD */
|
||||
#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */
|
||||
#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
|
||||
#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */
|
||||
/* OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) 4.3BSD */
|
||||
#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */
|
||||
#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */
|
||||
/* OSIOCGIFCONF _IOWR('i', 20, struct ifconf) 4.3BSD */
|
||||
#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */
|
||||
/* OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) 4.3BSD */
|
||||
#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */
|
||||
#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */
|
||||
#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
|
||||
#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
|
||||
#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
|
||||
#define OSIOCAIFADDR _IOW('i', 26, struct oifaliasreq) /* FreeBSD 9.x */
|
||||
/* SIOCALIFADDR _IOW('i', 27, struct if_laddrreq) KAME */
|
||||
/* SIOCGLIFADDR _IOWR('i', 28, struct if_laddrreq) KAME */
|
||||
/* SIOCDLIFADDR _IOW('i', 29, struct if_laddrreq) KAME */
|
||||
#define SIOCSIFCAP _IOW('i', 30, struct ifreq) /* set IF features */
|
||||
#define SIOCGIFCAP _IOWR('i', 31, struct ifreq) /* get IF features */
|
||||
#define SIOCGIFINDEX _IOWR('i', 32, struct ifreq) /* get IF index */
|
||||
#define SIOCGIFMAC _IOWR('i', 38, struct ifreq) /* get IF MAC label */
|
||||
#define SIOCSIFMAC _IOW('i', 39, struct ifreq) /* set IF MAC label */
|
||||
#define SIOCSIFNAME _IOW('i', 40, struct ifreq) /* set IF name */
|
||||
#define SIOCSIFDESCR _IOW('i', 41, struct ifreq) /* set ifnet descr */
|
||||
#define SIOCGIFDESCR _IOWR('i', 42, struct ifreq) /* get ifnet descr */
|
||||
#define SIOCAIFADDR _IOW('i', 43, struct ifaliasreq)/* add/chg IF alias */
|
||||
|
||||
#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
|
||||
#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
|
||||
#define SIOCGIFMTU _IOWR('i', 51, struct ifreq) /* get IF mtu */
|
||||
#define SIOCSIFMTU _IOW('i', 52, struct ifreq) /* set IF mtu */
|
||||
#define SIOCGIFPHYS _IOWR('i', 53, struct ifreq) /* get IF wire */
|
||||
#define SIOCSIFPHYS _IOW('i', 54, struct ifreq) /* set IF wire */
|
||||
#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
|
||||
#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
|
||||
|
||||
#define SIOCSIFGENERIC _IOW('i', 57, struct ifreq) /* generic IF set op */
|
||||
#define SIOCGIFGENERIC _IOWR('i', 58, struct ifreq) /* generic IF get op */
|
||||
|
||||
#define SIOCGIFSTATUS _IOWR('i', 59, struct ifstat) /* get IF status */
|
||||
#define SIOCSIFLLADDR _IOW('i', 60, struct ifreq) /* set linklevel addr */
|
||||
#define SIOCGI2C _IOWR('i', 61, struct ifreq) /* get I2C data */
|
||||
|
||||
#define SIOCSIFPHYADDR _IOW('i', 70, struct ifaliasreq) /* set gif address */
|
||||
#define SIOCGIFPSRCADDR _IOWR('i', 71, struct ifreq) /* get gif psrc addr */
|
||||
#define SIOCGIFPDSTADDR _IOWR('i', 72, struct ifreq) /* get gif pdst addr */
|
||||
#define SIOCDIFPHYADDR _IOW('i', 73, struct ifreq) /* delete gif addrs */
|
||||
/* SIOCSLIFPHYADDR _IOW('i', 74, struct if_laddrreq) KAME */
|
||||
/* SIOCGLIFPHYADDR _IOWR('i', 75, struct if_laddrreq) KAME */
|
||||
|
||||
#define SIOCGPRIVATE_0 _IOWR('i', 80, struct ifreq) /* device private 0 */
|
||||
#define SIOCGPRIVATE_1 _IOWR('i', 81, struct ifreq) /* device private 1 */
|
||||
|
||||
#define SIOCSIFVNET _IOWR('i', 90, struct ifreq) /* move IF jail/vnet */
|
||||
#define SIOCSIFRVNET _IOWR('i', 91, struct ifreq) /* reclaim vnet IF */
|
||||
|
||||
#define SIOCGIFFIB _IOWR('i', 92, struct ifreq) /* get IF fib */
|
||||
#define SIOCSIFFIB _IOW('i', 93, struct ifreq) /* set IF fib */
|
||||
|
||||
#define SIOCGTUNFIB _IOWR('i', 94, struct ifreq) /* get tunnel fib */
|
||||
#define SIOCSTUNFIB _IOW('i', 95, struct ifreq) /* set tunnel fib */
|
||||
|
||||
#define SIOCSDRVSPEC _IOW('i', 123, struct ifdrv) /* set driver-specific
|
||||
parameters */
|
||||
#define SIOCGDRVSPEC _IOWR('i', 123, struct ifdrv) /* get driver-specific
|
||||
parameters */
|
||||
|
||||
#define SIOCIFCREATE _IOWR('i', 122, struct ifreq) /* create clone if */
|
||||
#define SIOCIFCREATE2 _IOWR('i', 124, struct ifreq) /* create clone if */
|
||||
#define SIOCIFDESTROY _IOW('i', 121, struct ifreq) /* destroy clone if */
|
||||
#define SIOCIFGCLONERS _IOWR('i', 120, struct if_clonereq) /* get cloners */
|
||||
|
||||
#define SIOCAIFGROUP _IOW('i', 135, struct ifgroupreq) /* add an ifgroup */
|
||||
#define SIOCGIFGROUP _IOWR('i', 136, struct ifgroupreq) /* get ifgroups */
|
||||
#define SIOCDIFGROUP _IOW('i', 137, struct ifgroupreq) /* delete ifgroup */
|
||||
#define SIOCGIFGMEMB _IOWR('i', 138, struct ifgroupreq) /* get members */
|
||||
#define SIOCGIFXMEDIA _IOWR('i', 139, struct ifmediareq) /* get net xmedia */
|
||||
|
||||
#endif /* !_COMPAT_SOCKIO_H_ */
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copied from FreeBSD's header files.
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYS_SYSCTL_H
|
||||
#define _COMPAT_SYS_SYSCTL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/*
|
||||
* Definitions for sysctl call. The sysctl call uses a hierarchical name
|
||||
* for objects that can be examined or modified. The name is expressed as
|
||||
* a sequence of integers. Like a file path name, the meaning of each
|
||||
* component depends on its place in the hierarchy. The top-level and kern
|
||||
* identifiers are defined here, and other identifiers are defined in the
|
||||
* respective subsystem header files.
|
||||
*/
|
||||
|
||||
#define CTL_MAXNAME 24 /* largest number of components supported */
|
||||
|
||||
/*
|
||||
* Each subsystem defined by sysctl defines a list of variables
|
||||
* for that subsystem. Each name is either a node with further
|
||||
* levels defined below it, or it is a leaf of some particular
|
||||
* type given below. Each sysctl level defines a set of name/type
|
||||
* pairs to be used by sysctl(8) in manipulating the subsystem.
|
||||
*/
|
||||
struct ctlname {
|
||||
char *ctl_name; /* subsystem name */
|
||||
int ctl_type; /* type of name */
|
||||
};
|
||||
|
||||
#define CTLTYPE 0xf /* mask for the type */
|
||||
#define CTLTYPE_NODE 1 /* name is a node */
|
||||
#define CTLTYPE_INT 2 /* name describes an integer */
|
||||
#define CTLTYPE_STRING 3 /* name describes a string */
|
||||
#define CTLTYPE_S64 4 /* name describes a signed 64-bit number */
|
||||
#define CTLTYPE_OPAQUE 5 /* name describes a structure */
|
||||
#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
|
||||
#define CTLTYPE_UINT 6 /* name describes an unsigned integer */
|
||||
#define CTLTYPE_LONG 7 /* name describes a long */
|
||||
#define CTLTYPE_ULONG 8 /* name describes an unsigned long */
|
||||
#define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */
|
||||
#define CTLTYPE_U8 0xa /* name describes an unsigned 8-bit number */
|
||||
#define CTLTYPE_U16 0xb /* name describes an unsigned 16-bit number */
|
||||
#define CTLTYPE_S8 0xc /* name describes a signed 8-bit number */
|
||||
#define CTLTYPE_S16 0xd /* name describes a signed 16-bit number */
|
||||
#define CTLTYPE_S32 0xe /* name describes a signed 32-bit number */
|
||||
#define CTLTYPE_U32 0xf /* name describes an unsigned 32-bit number */
|
||||
|
||||
#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
|
||||
#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
|
||||
#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
|
||||
#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
|
||||
#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
|
||||
#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */
|
||||
#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */
|
||||
#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */
|
||||
#define CTLMASK_SECURE 0x00F00000 /* Secure level */
|
||||
#define CTLFLAG_TUN 0x00080000 /* Default value is loaded from getenv() */
|
||||
#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN)
|
||||
#define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN)
|
||||
#define CTLFLAG_MPSAFE 0x00040000 /* Handler is MP safe */
|
||||
#define CTLFLAG_VNET 0x00020000 /* Prisons with vnet can fiddle */
|
||||
#define CTLFLAG_DYING 0x00010000 /* Oid is being removed */
|
||||
#define CTLFLAG_CAPRD 0x00008000 /* Can be read in capability mode */
|
||||
#define CTLFLAG_CAPWR 0x00004000 /* Can be written in capability mode */
|
||||
#define CTLFLAG_STATS 0x00002000 /* Statistics, not a tuneable */
|
||||
#define CTLFLAG_NOFETCH 0x00001000 /* Don't fetch tunable from getenv() */
|
||||
#define CTLFLAG_CAPRW (CTLFLAG_CAPRD|CTLFLAG_CAPWR)
|
||||
|
||||
/*
|
||||
* Secure level. Note that CTLFLAG_SECURE == CTLFLAG_SECURE1.
|
||||
*
|
||||
* Secure when the securelevel is raised to at least N.
|
||||
*/
|
||||
#define CTLSHIFT_SECURE 20
|
||||
#define CTLFLAG_SECURE1 (CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE))
|
||||
#define CTLFLAG_SECURE2 (CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE))
|
||||
#define CTLFLAG_SECURE3 (CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE))
|
||||
|
||||
/*
|
||||
* USE THIS instead of a hardwired number from the categories below
|
||||
* to get dynamically assigned sysctl entries using the linker-set
|
||||
* technology. This is the way nearly all new sysctl variables should
|
||||
* be implemented.
|
||||
* e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
|
||||
*/
|
||||
#define OID_AUTO (-1)
|
||||
|
||||
/*
|
||||
* The starting number for dynamically-assigned entries. WARNING!
|
||||
* ALL static sysctl entries should have numbers LESS than this!
|
||||
*/
|
||||
#define CTL_AUTO_START 0x100
|
||||
|
||||
/*
|
||||
* Top-level identifiers
|
||||
*/
|
||||
#define CTL_UNSPEC 0 /* unused */
|
||||
#define CTL_KERN 1 /* "high kernel": proc, limits */
|
||||
#define CTL_VM 2 /* virtual memory */
|
||||
#define CTL_VFS 3 /* filesystem, mount type is next */
|
||||
#define CTL_NET 4 /* network, see socket.h */
|
||||
#define CTL_DEBUG 5 /* debugging parameters */
|
||||
#define CTL_HW 6 /* generic cpu/io */
|
||||
#define CTL_MACHDEP 7 /* machine dependent */
|
||||
#define CTL_USER 8 /* user-level */
|
||||
#define CTL_P1003_1B 9 /* POSIX 1003.1B */
|
||||
|
||||
/*
|
||||
* CTL_KERN identifiers
|
||||
*/
|
||||
#define KERN_OSTYPE 1 /* string: system version */
|
||||
#define KERN_OSRELEASE 2 /* string: system release */
|
||||
#define KERN_OSREV 3 /* int: system revision */
|
||||
#define KERN_VERSION 4 /* string: compile time info */
|
||||
#define KERN_MAXVNODES 5 /* int: max vnodes */
|
||||
#define KERN_MAXPROC 6 /* int: max processes */
|
||||
#define KERN_MAXFILES 7 /* int: max open files */
|
||||
#define KERN_ARGMAX 8 /* int: max arguments to exec */
|
||||
#define KERN_SECURELVL 9 /* int: system security level */
|
||||
#define KERN_HOSTNAME 10 /* string: hostname */
|
||||
#define KERN_HOSTID 11 /* int: host identifier */
|
||||
#define KERN_CLOCKRATE 12 /* struct: struct clockrate */
|
||||
#define KERN_VNODE 13 /* struct: vnode structures */
|
||||
#define KERN_PROC 14 /* struct: process entries */
|
||||
#define KERN_FILE 15 /* struct: file entries */
|
||||
#define KERN_PROF 16 /* node: kernel profiling info */
|
||||
#define KERN_POSIX1 17 /* int: POSIX.1 version */
|
||||
#define KERN_NGROUPS 18 /* int: # of supplemental group ids */
|
||||
#define KERN_JOB_CONTROL 19 /* int: is job control available */
|
||||
#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
|
||||
#define KERN_BOOTTIME 21 /* struct: time kernel was booted */
|
||||
#define KERN_NISDOMAINNAME 22 /* string: YP domain name */
|
||||
#define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */
|
||||
#define KERN_OSRELDATE 24 /* int: kernel release date */
|
||||
#define KERN_NTP_PLL 25 /* node: NTP PLL control */
|
||||
#define KERN_BOOTFILE 26 /* string: name of booted kernel */
|
||||
#define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */
|
||||
#define KERN_MAXPROCPERUID 28 /* int: max processes per uid */
|
||||
#define KERN_DUMPDEV 29 /* struct cdev *: device to dump on */
|
||||
#define KERN_IPC 30 /* node: anything related to IPC */
|
||||
#define KERN_DUMMY 31 /* unused */
|
||||
#define KERN_PS_STRINGS 32 /* int: address of PS_STRINGS */
|
||||
#define KERN_USRSTACK 33 /* int: address of USRSTACK */
|
||||
#define KERN_LOGSIGEXIT 34 /* int: do we log sigexit procs? */
|
||||
#define KERN_IOV_MAX 35 /* int: value of UIO_MAXIOV */
|
||||
#define KERN_HOSTUUID 36 /* string: host UUID identifier */
|
||||
#define KERN_ARND 37 /* int: from arc4rand() */
|
||||
/*
|
||||
* KERN_PROC subtypes
|
||||
*/
|
||||
#define KERN_PROC_ALL 0 /* everything */
|
||||
#define KERN_PROC_PID 1 /* by process id */
|
||||
#define KERN_PROC_PGRP 2 /* by process group id */
|
||||
#define KERN_PROC_SESSION 3 /* by session of pid */
|
||||
#define KERN_PROC_TTY 4 /* by controlling tty */
|
||||
#define KERN_PROC_UID 5 /* by effective uid */
|
||||
#define KERN_PROC_RUID 6 /* by real uid */
|
||||
#define KERN_PROC_ARGS 7 /* get/set arguments/proctitle */
|
||||
#define KERN_PROC_PROC 8 /* only return procs */
|
||||
#define KERN_PROC_SV_NAME 9 /* get syscall vector name */
|
||||
#define KERN_PROC_RGID 10 /* by real group id */
|
||||
#define KERN_PROC_GID 11 /* by effective group id */
|
||||
#define KERN_PROC_PATHNAME 12 /* path to executable */
|
||||
#define KERN_PROC_OVMMAP 13 /* Old VM map entries for process */
|
||||
#define KERN_PROC_OFILEDESC 14 /* Old file descriptors for process */
|
||||
#define KERN_PROC_KSTACK 15 /* Kernel stacks for process */
|
||||
#define KERN_PROC_INC_THREAD 0x10 /*
|
||||
* modifier for pid, pgrp, tty,
|
||||
* uid, ruid, gid, rgid and proc
|
||||
* This effectively uses 16-31
|
||||
*/
|
||||
#define KERN_PROC_VMMAP 32 /* VM map entries for process */
|
||||
#define KERN_PROC_FILEDESC 33 /* File descriptors for process */
|
||||
#define KERN_PROC_GROUPS 34 /* process groups */
|
||||
#define KERN_PROC_ENV 35 /* get environment */
|
||||
#define KERN_PROC_AUXV 36 /* get ELF auxiliary vector */
|
||||
#define KERN_PROC_RLIMIT 37 /* process resource limits */
|
||||
#define KERN_PROC_PS_STRINGS 38 /* get ps_strings location */
|
||||
#define KERN_PROC_UMASK 39 /* process umask */
|
||||
#define KERN_PROC_OSREL 40 /* osreldate for process binary */
|
||||
#define KERN_PROC_SIGTRAMP 41 /* signal trampoline location */
|
||||
#define KERN_PROC_CWD 42 /* process current working directory */
|
||||
#define KERN_PROC_NFDS 43 /* number of open file descriptors */
|
||||
|
||||
/*
|
||||
* KERN_IPC identifiers
|
||||
*/
|
||||
#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */
|
||||
#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */
|
||||
#define KIPC_SOMAXCONN 3 /* int: max length of connection q */
|
||||
#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */
|
||||
#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */
|
||||
#define KIPC_MAX_HDR 6 /* int: max total length of headers */
|
||||
#define KIPC_MAX_DATALEN 7 /* int: max length of data? */
|
||||
|
||||
/*
|
||||
* CTL_HW identifiers
|
||||
*/
|
||||
#define HW_MACHINE 1 /* string: machine class */
|
||||
#define HW_MODEL 2 /* string: specific machine model */
|
||||
#define HW_NCPU 3 /* int: number of cpus */
|
||||
#define HW_BYTEORDER 4 /* int: machine byte order */
|
||||
#define HW_PHYSMEM 5 /* int: total memory */
|
||||
#define HW_USERMEM 6 /* int: non-kernel memory */
|
||||
#define HW_PAGESIZE 7 /* int: software page size */
|
||||
#define HW_DISKNAMES 8 /* strings: disk drive names */
|
||||
#define HW_DISKSTATS 9 /* struct: diskstats[] */
|
||||
#define HW_FLOATINGPT 10 /* int: has HW floating point? */
|
||||
#define HW_MACHINE_ARCH 11 /* string: machine architecture */
|
||||
#define HW_REALMEM 12 /* int: 'real' memory */
|
||||
|
||||
/*
|
||||
* CTL_USER definitions
|
||||
*/
|
||||
#define USER_CS_PATH 1 /* string: _CS_PATH */
|
||||
#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */
|
||||
#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */
|
||||
#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */
|
||||
#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */
|
||||
#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */
|
||||
#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */
|
||||
#define USER_LINE_MAX 8 /* int: LINE_MAX */
|
||||
#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */
|
||||
#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */
|
||||
#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */
|
||||
#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */
|
||||
#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */
|
||||
#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */
|
||||
#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */
|
||||
#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */
|
||||
#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */
|
||||
#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */
|
||||
#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */
|
||||
#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */
|
||||
|
||||
#define CTL_P1003_1B_ASYNCHRONOUS_IO 1 /* boolean */
|
||||
#define CTL_P1003_1B_MAPPED_FILES 2 /* boolean */
|
||||
#define CTL_P1003_1B_MEMLOCK 3 /* boolean */
|
||||
#define CTL_P1003_1B_MEMLOCK_RANGE 4 /* boolean */
|
||||
#define CTL_P1003_1B_MEMORY_PROTECTION 5 /* boolean */
|
||||
#define CTL_P1003_1B_MESSAGE_PASSING 6 /* boolean */
|
||||
#define CTL_P1003_1B_PRIORITIZED_IO 7 /* boolean */
|
||||
#define CTL_P1003_1B_PRIORITY_SCHEDULING 8 /* boolean */
|
||||
#define CTL_P1003_1B_REALTIME_SIGNALS 9 /* boolean */
|
||||
#define CTL_P1003_1B_SEMAPHORES 10 /* boolean */
|
||||
#define CTL_P1003_1B_FSYNC 11 /* boolean */
|
||||
#define CTL_P1003_1B_SHARED_MEMORY_OBJECTS 12 /* boolean */
|
||||
#define CTL_P1003_1B_SYNCHRONIZED_IO 13 /* boolean */
|
||||
#define CTL_P1003_1B_TIMERS 14 /* boolean */
|
||||
#define CTL_P1003_1B_AIO_LISTIO_MAX 15 /* int */
|
||||
#define CTL_P1003_1B_AIO_MAX 16 /* int */
|
||||
#define CTL_P1003_1B_AIO_PRIO_DELTA_MAX 17 /* int */
|
||||
#define CTL_P1003_1B_DELAYTIMER_MAX 18 /* int */
|
||||
#define CTL_P1003_1B_MQ_OPEN_MAX 19 /* int */
|
||||
#define CTL_P1003_1B_PAGESIZE 20 /* int */
|
||||
#define CTL_P1003_1B_RTSIG_MAX 21 /* int */
|
||||
#define CTL_P1003_1B_SEM_NSEMS_MAX 22 /* int */
|
||||
#define CTL_P1003_1B_SEM_VALUE_MAX 23 /* int */
|
||||
#define CTL_P1003_1B_SIGQUEUE_MAX 24 /* int */
|
||||
#define CTL_P1003_1B_TIMER_MAX 25 /* int */
|
||||
|
||||
#define CTL_P1003_1B_MAXID 26
|
||||
|
||||
int sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
|
||||
int sysctlbyname(const char *, void *, size_t *, const void *, size_t);
|
||||
int sysctlnametomib(const char *, int *, size_t *);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,801 @@
|
|||
/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */
|
||||
/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_TREE_H_
|
||||
#define _SYS_TREE_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/*
|
||||
* This file defines data structures for different types of trees:
|
||||
* splay trees and red-black trees.
|
||||
*
|
||||
* A splay tree is a self-organizing data structure. Every operation
|
||||
* on the tree causes a splay to happen. The splay moves the requested
|
||||
* node to the root of the tree and partly rebalances it.
|
||||
*
|
||||
* This has the benefit that request locality causes faster lookups as
|
||||
* the requested nodes move to the top of the tree. On the other hand,
|
||||
* every lookup causes memory writes.
|
||||
*
|
||||
* The Balance Theorem bounds the total access time for m operations
|
||||
* and n inserts on an initially empty tree as O((m + n)lg n). The
|
||||
* amortized cost for a sequence of m accesses to a splay tree is O(lg n);
|
||||
*
|
||||
* A red-black tree is a binary search tree with the node color as an
|
||||
* extra attribute. It fulfills a set of conditions:
|
||||
* - every search path from the root to a leaf consists of the
|
||||
* same number of black nodes,
|
||||
* - each red node (except for the root) has a black parent,
|
||||
* - each leaf node is black.
|
||||
*
|
||||
* Every operation on a red-black tree is bounded as O(lg n).
|
||||
* The maximum height of a red-black tree is 2lg (n+1).
|
||||
*/
|
||||
|
||||
#define SPLAY_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *sph_root; /* root of the tree */ \
|
||||
}
|
||||
|
||||
#define SPLAY_INITIALIZER(root) \
|
||||
{ NULL }
|
||||
|
||||
#define SPLAY_INIT(root) do { \
|
||||
(root)->sph_root = NULL; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define SPLAY_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *spe_left; /* left element */ \
|
||||
struct type *spe_right; /* right element */ \
|
||||
}
|
||||
|
||||
#define SPLAY_LEFT(elm, field) (elm)->field.spe_left
|
||||
#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right
|
||||
#define SPLAY_ROOT(head) (head)->sph_root
|
||||
#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL)
|
||||
|
||||
/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */
|
||||
#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \
|
||||
SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \
|
||||
SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
|
||||
(head)->sph_root = tmp; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \
|
||||
SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \
|
||||
SPLAY_LEFT(tmp, field) = (head)->sph_root; \
|
||||
(head)->sph_root = tmp; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define SPLAY_LINKLEFT(head, tmp, field) do { \
|
||||
SPLAY_LEFT(tmp, field) = (head)->sph_root; \
|
||||
tmp = (head)->sph_root; \
|
||||
(head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define SPLAY_LINKRIGHT(head, tmp, field) do { \
|
||||
SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
|
||||
tmp = (head)->sph_root; \
|
||||
(head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \
|
||||
SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \
|
||||
SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\
|
||||
SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \
|
||||
SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
/* Generates prototypes and inline functions */
|
||||
|
||||
#define SPLAY_PROTOTYPE(name, type, field, cmp) \
|
||||
void name##_SPLAY(struct name *, struct type *); \
|
||||
void name##_SPLAY_MINMAX(struct name *, int); \
|
||||
struct type *name##_SPLAY_INSERT(struct name *, struct type *); \
|
||||
struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \
|
||||
\
|
||||
/* Finds the node with the same key as elm */ \
|
||||
static __inline struct type * \
|
||||
name##_SPLAY_FIND(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
if (SPLAY_EMPTY(head)) \
|
||||
return(NULL); \
|
||||
name##_SPLAY(head, elm); \
|
||||
if ((cmp)(elm, (head)->sph_root) == 0) \
|
||||
return (head->sph_root); \
|
||||
return (NULL); \
|
||||
} \
|
||||
\
|
||||
static __inline struct type * \
|
||||
name##_SPLAY_NEXT(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
name##_SPLAY(head, elm); \
|
||||
if (SPLAY_RIGHT(elm, field) != NULL) { \
|
||||
elm = SPLAY_RIGHT(elm, field); \
|
||||
while (SPLAY_LEFT(elm, field) != NULL) { \
|
||||
elm = SPLAY_LEFT(elm, field); \
|
||||
} \
|
||||
} else \
|
||||
elm = NULL; \
|
||||
return (elm); \
|
||||
} \
|
||||
\
|
||||
static __inline struct type * \
|
||||
name##_SPLAY_MIN_MAX(struct name *head, int val) \
|
||||
{ \
|
||||
name##_SPLAY_MINMAX(head, val); \
|
||||
return (SPLAY_ROOT(head)); \
|
||||
}
|
||||
|
||||
/* Main splay operation.
|
||||
* Moves node close to the key of elm to top
|
||||
*/
|
||||
#define SPLAY_GENERATE(name, type, field, cmp) \
|
||||
struct type * \
|
||||
name##_SPLAY_INSERT(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
if (SPLAY_EMPTY(head)) { \
|
||||
SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \
|
||||
} else { \
|
||||
int __comp; \
|
||||
name##_SPLAY(head, elm); \
|
||||
__comp = (cmp)(elm, (head)->sph_root); \
|
||||
if(__comp < 0) { \
|
||||
SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\
|
||||
SPLAY_RIGHT(elm, field) = (head)->sph_root; \
|
||||
SPLAY_LEFT((head)->sph_root, field) = NULL; \
|
||||
} else if (__comp > 0) { \
|
||||
SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\
|
||||
SPLAY_LEFT(elm, field) = (head)->sph_root; \
|
||||
SPLAY_RIGHT((head)->sph_root, field) = NULL; \
|
||||
} else \
|
||||
return ((head)->sph_root); \
|
||||
} \
|
||||
(head)->sph_root = (elm); \
|
||||
return (NULL); \
|
||||
} \
|
||||
\
|
||||
struct type * \
|
||||
name##_SPLAY_REMOVE(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
struct type *__tmp; \
|
||||
if (SPLAY_EMPTY(head)) \
|
||||
return (NULL); \
|
||||
name##_SPLAY(head, elm); \
|
||||
if ((cmp)(elm, (head)->sph_root) == 0) { \
|
||||
if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \
|
||||
(head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\
|
||||
} else { \
|
||||
__tmp = SPLAY_RIGHT((head)->sph_root, field); \
|
||||
(head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\
|
||||
name##_SPLAY(head, elm); \
|
||||
SPLAY_RIGHT((head)->sph_root, field) = __tmp; \
|
||||
} \
|
||||
return (elm); \
|
||||
} \
|
||||
return (NULL); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
name##_SPLAY(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
struct type __node, *__left, *__right, *__tmp; \
|
||||
int __comp; \
|
||||
\
|
||||
SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
|
||||
__left = __right = &__node; \
|
||||
\
|
||||
while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \
|
||||
if (__comp < 0) { \
|
||||
__tmp = SPLAY_LEFT((head)->sph_root, field); \
|
||||
if (__tmp == NULL) \
|
||||
break; \
|
||||
if ((cmp)(elm, __tmp) < 0){ \
|
||||
SPLAY_ROTATE_RIGHT(head, __tmp, field); \
|
||||
if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
|
||||
break; \
|
||||
} \
|
||||
SPLAY_LINKLEFT(head, __right, field); \
|
||||
} else if (__comp > 0) { \
|
||||
__tmp = SPLAY_RIGHT((head)->sph_root, field); \
|
||||
if (__tmp == NULL) \
|
||||
break; \
|
||||
if ((cmp)(elm, __tmp) > 0){ \
|
||||
SPLAY_ROTATE_LEFT(head, __tmp, field); \
|
||||
if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
|
||||
break; \
|
||||
} \
|
||||
SPLAY_LINKRIGHT(head, __left, field); \
|
||||
} \
|
||||
} \
|
||||
SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
|
||||
} \
|
||||
\
|
||||
/* Splay with either the minimum or the maximum element \
|
||||
* Used to find minimum or maximum element in tree. \
|
||||
*/ \
|
||||
void name##_SPLAY_MINMAX(struct name *head, int __comp) \
|
||||
{ \
|
||||
struct type __node, *__left, *__right, *__tmp; \
|
||||
\
|
||||
SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
|
||||
__left = __right = &__node; \
|
||||
\
|
||||
while (1) { \
|
||||
if (__comp < 0) { \
|
||||
__tmp = SPLAY_LEFT((head)->sph_root, field); \
|
||||
if (__tmp == NULL) \
|
||||
break; \
|
||||
if (__comp < 0){ \
|
||||
SPLAY_ROTATE_RIGHT(head, __tmp, field); \
|
||||
if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
|
||||
break; \
|
||||
} \
|
||||
SPLAY_LINKLEFT(head, __right, field); \
|
||||
} else if (__comp > 0) { \
|
||||
__tmp = SPLAY_RIGHT((head)->sph_root, field); \
|
||||
if (__tmp == NULL) \
|
||||
break; \
|
||||
if (__comp > 0) { \
|
||||
SPLAY_ROTATE_LEFT(head, __tmp, field); \
|
||||
if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
|
||||
break; \
|
||||
} \
|
||||
SPLAY_LINKRIGHT(head, __left, field); \
|
||||
} \
|
||||
} \
|
||||
SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
|
||||
}
|
||||
|
||||
#define SPLAY_NEGINF -1
|
||||
#define SPLAY_INF 1
|
||||
|
||||
#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y)
|
||||
#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y)
|
||||
#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y)
|
||||
#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y)
|
||||
#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \
|
||||
: name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF))
|
||||
#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \
|
||||
: name##_SPLAY_MIN_MAX(x, SPLAY_INF))
|
||||
|
||||
#define SPLAY_FOREACH(x, name, head) \
|
||||
for ((x) = SPLAY_MIN(name, head); \
|
||||
(x) != NULL; \
|
||||
(x) = SPLAY_NEXT(name, head, x))
|
||||
|
||||
/* Macros that define a red-black tree */
|
||||
#define RB_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *rbh_root; /* root of the tree */ \
|
||||
}
|
||||
|
||||
#define RB_INITIALIZER(root) \
|
||||
{ NULL }
|
||||
|
||||
#define RB_INIT(root) do { \
|
||||
(root)->rbh_root = NULL; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define RB_BLACK 0
|
||||
#define RB_RED 1
|
||||
#define RB_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *rbe_left; /* left element */ \
|
||||
struct type *rbe_right; /* right element */ \
|
||||
struct type *rbe_parent; /* parent element */ \
|
||||
int rbe_color; /* node color */ \
|
||||
}
|
||||
|
||||
#define RB_LEFT(elm, field) (elm)->field.rbe_left
|
||||
#define RB_RIGHT(elm, field) (elm)->field.rbe_right
|
||||
#define RB_PARENT(elm, field) (elm)->field.rbe_parent
|
||||
#define RB_COLOR(elm, field) (elm)->field.rbe_color
|
||||
#define RB_ROOT(head) (head)->rbh_root
|
||||
#define RB_EMPTY(head) (RB_ROOT(head) == NULL)
|
||||
|
||||
#define RB_SET(elm, parent, field) do { \
|
||||
RB_PARENT(elm, field) = parent; \
|
||||
RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \
|
||||
RB_COLOR(elm, field) = RB_RED; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define RB_SET_BLACKRED(black, red, field) do { \
|
||||
RB_COLOR(black, field) = RB_BLACK; \
|
||||
RB_COLOR(red, field) = RB_RED; \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#ifndef RB_AUGMENT
|
||||
#define RB_AUGMENT(x) do {} while (0)
|
||||
#endif
|
||||
|
||||
#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \
|
||||
(tmp) = RB_RIGHT(elm, field); \
|
||||
if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \
|
||||
RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \
|
||||
} \
|
||||
RB_AUGMENT(elm); \
|
||||
if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \
|
||||
if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
|
||||
RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
|
||||
else \
|
||||
RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
|
||||
} else \
|
||||
(head)->rbh_root = (tmp); \
|
||||
RB_LEFT(tmp, field) = (elm); \
|
||||
RB_PARENT(elm, field) = (tmp); \
|
||||
RB_AUGMENT(tmp); \
|
||||
if ((RB_PARENT(tmp, field))) \
|
||||
RB_AUGMENT(RB_PARENT(tmp, field)); \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
|
||||
(tmp) = RB_LEFT(elm, field); \
|
||||
if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \
|
||||
RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \
|
||||
} \
|
||||
RB_AUGMENT(elm); \
|
||||
if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \
|
||||
if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
|
||||
RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
|
||||
else \
|
||||
RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
|
||||
} else \
|
||||
(head)->rbh_root = (tmp); \
|
||||
RB_RIGHT(tmp, field) = (elm); \
|
||||
RB_PARENT(elm, field) = (tmp); \
|
||||
RB_AUGMENT(tmp); \
|
||||
if ((RB_PARENT(tmp, field))) \
|
||||
RB_AUGMENT(RB_PARENT(tmp, field)); \
|
||||
} while (/*CONSTCOND*/ 0)
|
||||
|
||||
/* Generates prototypes and inline functions */
|
||||
#define RB_PROTOTYPE(name, type, field, cmp) \
|
||||
RB_PROTOTYPE_INTERNAL(name, type, field, cmp,)
|
||||
#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \
|
||||
RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static)
|
||||
#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \
|
||||
RB_PROTOTYPE_INSERT_COLOR(name, type, attr); \
|
||||
RB_PROTOTYPE_REMOVE_COLOR(name, type, attr); \
|
||||
RB_PROTOTYPE_INSERT(name, type, attr); \
|
||||
RB_PROTOTYPE_REMOVE(name, type, attr); \
|
||||
RB_PROTOTYPE_FIND(name, type, attr); \
|
||||
RB_PROTOTYPE_NFIND(name, type, attr); \
|
||||
RB_PROTOTYPE_NEXT(name, type, attr); \
|
||||
RB_PROTOTYPE_PREV(name, type, attr); \
|
||||
RB_PROTOTYPE_MINMAX(name, type, attr);
|
||||
#define RB_PROTOTYPE_INSERT_COLOR(name, type, attr) \
|
||||
attr void name##_RB_INSERT_COLOR(struct name *, struct type *)
|
||||
#define RB_PROTOTYPE_REMOVE_COLOR(name, type, attr) \
|
||||
attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *)
|
||||
#define RB_PROTOTYPE_REMOVE(name, type, attr) \
|
||||
attr struct type *name##_RB_REMOVE(struct name *, struct type *)
|
||||
#define RB_PROTOTYPE_INSERT(name, type, attr) \
|
||||
attr struct type *name##_RB_INSERT(struct name *, struct type *)
|
||||
#define RB_PROTOTYPE_FIND(name, type, attr) \
|
||||
attr struct type *name##_RB_FIND(struct name *, struct type *)
|
||||
#define RB_PROTOTYPE_NFIND(name, type, attr) \
|
||||
attr struct type *name##_RB_NFIND(struct name *, struct type *)
|
||||
#define RB_PROTOTYPE_NEXT(name, type, attr) \
|
||||
attr struct type *name##_RB_NEXT(struct type *)
|
||||
#define RB_PROTOTYPE_PREV(name, type, attr) \
|
||||
attr struct type *name##_RB_PREV(struct type *)
|
||||
#define RB_PROTOTYPE_MINMAX(name, type, attr) \
|
||||
attr struct type *name##_RB_MINMAX(struct name *, int)
|
||||
|
||||
/* Main rb operation.
|
||||
* Moves node close to the key of elm to top
|
||||
*/
|
||||
#define RB_GENERATE(name, type, field, cmp) \
|
||||
RB_GENERATE_INTERNAL(name, type, field, cmp,)
|
||||
#define RB_GENERATE_STATIC(name, type, field, cmp) \
|
||||
RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static)
|
||||
#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \
|
||||
RB_GENERATE_INSERT_COLOR(name, type, field, attr) \
|
||||
RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \
|
||||
RB_GENERATE_INSERT(name, type, field, cmp, attr) \
|
||||
RB_GENERATE_REMOVE(name, type, field, attr) \
|
||||
RB_GENERATE_FIND(name, type, field, cmp, attr) \
|
||||
RB_GENERATE_NFIND(name, type, field, cmp, attr) \
|
||||
RB_GENERATE_NEXT(name, type, field, attr) \
|
||||
RB_GENERATE_PREV(name, type, field, attr) \
|
||||
RB_GENERATE_MINMAX(name, type, field, attr)
|
||||
|
||||
#define RB_GENERATE_INSERT_COLOR(name, type, field, attr) \
|
||||
attr void \
|
||||
name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
struct type *parent, *gparent, *tmp; \
|
||||
while ((parent = RB_PARENT(elm, field)) != NULL && \
|
||||
RB_COLOR(parent, field) == RB_RED) { \
|
||||
gparent = RB_PARENT(parent, field); \
|
||||
if (parent == RB_LEFT(gparent, field)) { \
|
||||
tmp = RB_RIGHT(gparent, field); \
|
||||
if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
|
||||
RB_COLOR(tmp, field) = RB_BLACK; \
|
||||
RB_SET_BLACKRED(parent, gparent, field);\
|
||||
elm = gparent; \
|
||||
continue; \
|
||||
} \
|
||||
if (RB_RIGHT(parent, field) == elm) { \
|
||||
RB_ROTATE_LEFT(head, parent, tmp, field);\
|
||||
tmp = parent; \
|
||||
parent = elm; \
|
||||
elm = tmp; \
|
||||
} \
|
||||
RB_SET_BLACKRED(parent, gparent, field); \
|
||||
RB_ROTATE_RIGHT(head, gparent, tmp, field); \
|
||||
} else { \
|
||||
tmp = RB_LEFT(gparent, field); \
|
||||
if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
|
||||
RB_COLOR(tmp, field) = RB_BLACK; \
|
||||
RB_SET_BLACKRED(parent, gparent, field);\
|
||||
elm = gparent; \
|
||||
continue; \
|
||||
} \
|
||||
if (RB_LEFT(parent, field) == elm) { \
|
||||
RB_ROTATE_RIGHT(head, parent, tmp, field);\
|
||||
tmp = parent; \
|
||||
parent = elm; \
|
||||
elm = tmp; \
|
||||
} \
|
||||
RB_SET_BLACKRED(parent, gparent, field); \
|
||||
RB_ROTATE_LEFT(head, gparent, tmp, field); \
|
||||
} \
|
||||
} \
|
||||
RB_COLOR(head->rbh_root, field) = RB_BLACK; \
|
||||
}
|
||||
|
||||
#define RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \
|
||||
attr void \
|
||||
name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \
|
||||
{ \
|
||||
struct type *tmp; \
|
||||
while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \
|
||||
elm != RB_ROOT(head)) { \
|
||||
if (RB_LEFT(parent, field) == elm) { \
|
||||
tmp = RB_RIGHT(parent, field); \
|
||||
if (RB_COLOR(tmp, field) == RB_RED) { \
|
||||
RB_SET_BLACKRED(tmp, parent, field); \
|
||||
RB_ROTATE_LEFT(head, parent, tmp, field);\
|
||||
tmp = RB_RIGHT(parent, field); \
|
||||
} \
|
||||
if ((RB_LEFT(tmp, field) == NULL || \
|
||||
RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
|
||||
(RB_RIGHT(tmp, field) == NULL || \
|
||||
RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
|
||||
RB_COLOR(tmp, field) = RB_RED; \
|
||||
elm = parent; \
|
||||
parent = RB_PARENT(elm, field); \
|
||||
} else { \
|
||||
if (RB_RIGHT(tmp, field) == NULL || \
|
||||
RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\
|
||||
struct type *oleft; \
|
||||
if ((oleft = RB_LEFT(tmp, field)) \
|
||||
!= NULL) \
|
||||
RB_COLOR(oleft, field) = RB_BLACK;\
|
||||
RB_COLOR(tmp, field) = RB_RED; \
|
||||
RB_ROTATE_RIGHT(head, tmp, oleft, field);\
|
||||
tmp = RB_RIGHT(parent, field); \
|
||||
} \
|
||||
RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
|
||||
RB_COLOR(parent, field) = RB_BLACK; \
|
||||
if (RB_RIGHT(tmp, field)) \
|
||||
RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\
|
||||
RB_ROTATE_LEFT(head, parent, tmp, field);\
|
||||
elm = RB_ROOT(head); \
|
||||
break; \
|
||||
} \
|
||||
} else { \
|
||||
tmp = RB_LEFT(parent, field); \
|
||||
if (RB_COLOR(tmp, field) == RB_RED) { \
|
||||
RB_SET_BLACKRED(tmp, parent, field); \
|
||||
RB_ROTATE_RIGHT(head, parent, tmp, field);\
|
||||
tmp = RB_LEFT(parent, field); \
|
||||
} \
|
||||
if ((RB_LEFT(tmp, field) == NULL || \
|
||||
RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
|
||||
(RB_RIGHT(tmp, field) == NULL || \
|
||||
RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
|
||||
RB_COLOR(tmp, field) = RB_RED; \
|
||||
elm = parent; \
|
||||
parent = RB_PARENT(elm, field); \
|
||||
} else { \
|
||||
if (RB_LEFT(tmp, field) == NULL || \
|
||||
RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\
|
||||
struct type *oright; \
|
||||
if ((oright = RB_RIGHT(tmp, field)) \
|
||||
!= NULL) \
|
||||
RB_COLOR(oright, field) = RB_BLACK;\
|
||||
RB_COLOR(tmp, field) = RB_RED; \
|
||||
RB_ROTATE_LEFT(head, tmp, oright, field);\
|
||||
tmp = RB_LEFT(parent, field); \
|
||||
} \
|
||||
RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
|
||||
RB_COLOR(parent, field) = RB_BLACK; \
|
||||
if (RB_LEFT(tmp, field)) \
|
||||
RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\
|
||||
RB_ROTATE_RIGHT(head, parent, tmp, field);\
|
||||
elm = RB_ROOT(head); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
if (elm) \
|
||||
RB_COLOR(elm, field) = RB_BLACK; \
|
||||
}
|
||||
|
||||
#define RB_GENERATE_REMOVE(name, type, field, attr) \
|
||||
attr struct type * \
|
||||
name##_RB_REMOVE(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
struct type *child, *parent, *old = elm; \
|
||||
int color; \
|
||||
if (RB_LEFT(elm, field) == NULL) \
|
||||
child = RB_RIGHT(elm, field); \
|
||||
else if (RB_RIGHT(elm, field) == NULL) \
|
||||
child = RB_LEFT(elm, field); \
|
||||
else { \
|
||||
struct type *left; \
|
||||
elm = RB_RIGHT(elm, field); \
|
||||
while ((left = RB_LEFT(elm, field)) != NULL) \
|
||||
elm = left; \
|
||||
child = RB_RIGHT(elm, field); \
|
||||
parent = RB_PARENT(elm, field); \
|
||||
color = RB_COLOR(elm, field); \
|
||||
if (child) \
|
||||
RB_PARENT(child, field) = parent; \
|
||||
if (parent) { \
|
||||
if (RB_LEFT(parent, field) == elm) \
|
||||
RB_LEFT(parent, field) = child; \
|
||||
else \
|
||||
RB_RIGHT(parent, field) = child; \
|
||||
RB_AUGMENT(parent); \
|
||||
} else \
|
||||
RB_ROOT(head) = child; \
|
||||
if (RB_PARENT(elm, field) == old) \
|
||||
parent = elm; \
|
||||
(elm)->field = (old)->field; \
|
||||
if (RB_PARENT(old, field)) { \
|
||||
if (RB_LEFT(RB_PARENT(old, field), field) == old)\
|
||||
RB_LEFT(RB_PARENT(old, field), field) = elm;\
|
||||
else \
|
||||
RB_RIGHT(RB_PARENT(old, field), field) = elm;\
|
||||
RB_AUGMENT(RB_PARENT(old, field)); \
|
||||
} else \
|
||||
RB_ROOT(head) = elm; \
|
||||
RB_PARENT(RB_LEFT(old, field), field) = elm; \
|
||||
if (RB_RIGHT(old, field)) \
|
||||
RB_PARENT(RB_RIGHT(old, field), field) = elm; \
|
||||
if (parent) { \
|
||||
left = parent; \
|
||||
do { \
|
||||
RB_AUGMENT(left); \
|
||||
} while ((left = RB_PARENT(left, field)) != NULL); \
|
||||
} \
|
||||
goto color; \
|
||||
} \
|
||||
parent = RB_PARENT(elm, field); \
|
||||
color = RB_COLOR(elm, field); \
|
||||
if (child) \
|
||||
RB_PARENT(child, field) = parent; \
|
||||
if (parent) { \
|
||||
if (RB_LEFT(parent, field) == elm) \
|
||||
RB_LEFT(parent, field) = child; \
|
||||
else \
|
||||
RB_RIGHT(parent, field) = child; \
|
||||
RB_AUGMENT(parent); \
|
||||
} else \
|
||||
RB_ROOT(head) = child; \
|
||||
color: \
|
||||
if (color == RB_BLACK) \
|
||||
name##_RB_REMOVE_COLOR(head, parent, child); \
|
||||
return (old); \
|
||||
} \
|
||||
|
||||
#define RB_GENERATE_INSERT(name, type, field, cmp, attr) \
|
||||
/* Inserts a node into the RB tree */ \
|
||||
attr struct type * \
|
||||
name##_RB_INSERT(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
struct type *tmp; \
|
||||
struct type *parent = NULL; \
|
||||
int comp = 0; \
|
||||
tmp = RB_ROOT(head); \
|
||||
while (tmp) { \
|
||||
parent = tmp; \
|
||||
comp = (cmp)(elm, parent); \
|
||||
if (comp < 0) \
|
||||
tmp = RB_LEFT(tmp, field); \
|
||||
else if (comp > 0) \
|
||||
tmp = RB_RIGHT(tmp, field); \
|
||||
else \
|
||||
return (tmp); \
|
||||
} \
|
||||
RB_SET(elm, parent, field); \
|
||||
if (parent != NULL) { \
|
||||
if (comp < 0) \
|
||||
RB_LEFT(parent, field) = elm; \
|
||||
else \
|
||||
RB_RIGHT(parent, field) = elm; \
|
||||
RB_AUGMENT(parent); \
|
||||
} else \
|
||||
RB_ROOT(head) = elm; \
|
||||
name##_RB_INSERT_COLOR(head, elm); \
|
||||
return (NULL); \
|
||||
}
|
||||
|
||||
#define RB_GENERATE_FIND(name, type, field, cmp, attr) \
|
||||
/* Finds the node with the same key as elm */ \
|
||||
attr struct type * \
|
||||
name##_RB_FIND(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
struct type *tmp = RB_ROOT(head); \
|
||||
int comp; \
|
||||
while (tmp) { \
|
||||
comp = cmp(elm, tmp); \
|
||||
if (comp < 0) \
|
||||
tmp = RB_LEFT(tmp, field); \
|
||||
else if (comp > 0) \
|
||||
tmp = RB_RIGHT(tmp, field); \
|
||||
else \
|
||||
return (tmp); \
|
||||
} \
|
||||
return (NULL); \
|
||||
}
|
||||
|
||||
#define RB_GENERATE_NFIND(name, type, field, cmp, attr) \
|
||||
/* Finds the first node greater than or equal to the search key */ \
|
||||
attr struct type * \
|
||||
name##_RB_NFIND(struct name *head, struct type *elm) \
|
||||
{ \
|
||||
struct type *tmp = RB_ROOT(head); \
|
||||
struct type *res = NULL; \
|
||||
int comp; \
|
||||
while (tmp) { \
|
||||
comp = cmp(elm, tmp); \
|
||||
if (comp < 0) { \
|
||||
res = tmp; \
|
||||
tmp = RB_LEFT(tmp, field); \
|
||||
} \
|
||||
else if (comp > 0) \
|
||||
tmp = RB_RIGHT(tmp, field); \
|
||||
else \
|
||||
return (tmp); \
|
||||
} \
|
||||
return (res); \
|
||||
}
|
||||
|
||||
#define RB_GENERATE_NEXT(name, type, field, attr) \
|
||||
/* ARGSUSED */ \
|
||||
attr struct type * \
|
||||
name##_RB_NEXT(struct type *elm) \
|
||||
{ \
|
||||
if (RB_RIGHT(elm, field)) { \
|
||||
elm = RB_RIGHT(elm, field); \
|
||||
while (RB_LEFT(elm, field)) \
|
||||
elm = RB_LEFT(elm, field); \
|
||||
} else { \
|
||||
if (RB_PARENT(elm, field) && \
|
||||
(elm == RB_LEFT(RB_PARENT(elm, field), field))) \
|
||||
elm = RB_PARENT(elm, field); \
|
||||
else { \
|
||||
while (RB_PARENT(elm, field) && \
|
||||
(elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
|
||||
elm = RB_PARENT(elm, field); \
|
||||
elm = RB_PARENT(elm, field); \
|
||||
} \
|
||||
} \
|
||||
return (elm); \
|
||||
}
|
||||
|
||||
#define RB_GENERATE_PREV(name, type, field, attr) \
|
||||
/* ARGSUSED */ \
|
||||
attr struct type * \
|
||||
name##_RB_PREV(struct type *elm) \
|
||||
{ \
|
||||
if (RB_LEFT(elm, field)) { \
|
||||
elm = RB_LEFT(elm, field); \
|
||||
while (RB_RIGHT(elm, field)) \
|
||||
elm = RB_RIGHT(elm, field); \
|
||||
} else { \
|
||||
if (RB_PARENT(elm, field) && \
|
||||
(elm == RB_RIGHT(RB_PARENT(elm, field), field))) \
|
||||
elm = RB_PARENT(elm, field); \
|
||||
else { \
|
||||
while (RB_PARENT(elm, field) && \
|
||||
(elm == RB_LEFT(RB_PARENT(elm, field), field)))\
|
||||
elm = RB_PARENT(elm, field); \
|
||||
elm = RB_PARENT(elm, field); \
|
||||
} \
|
||||
} \
|
||||
return (elm); \
|
||||
}
|
||||
|
||||
#define RB_GENERATE_MINMAX(name, type, field, attr) \
|
||||
attr struct type * \
|
||||
name##_RB_MINMAX(struct name *head, int val) \
|
||||
{ \
|
||||
struct type *tmp = RB_ROOT(head); \
|
||||
struct type *parent = NULL; \
|
||||
while (tmp) { \
|
||||
parent = tmp; \
|
||||
if (val < 0) \
|
||||
tmp = RB_LEFT(tmp, field); \
|
||||
else \
|
||||
tmp = RB_RIGHT(tmp, field); \
|
||||
} \
|
||||
return (parent); \
|
||||
}
|
||||
|
||||
#define RB_NEGINF -1
|
||||
#define RB_INF 1
|
||||
|
||||
#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y)
|
||||
#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y)
|
||||
#define RB_FIND(name, x, y) name##_RB_FIND(x, y)
|
||||
#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y)
|
||||
#define RB_NEXT(name, x, y) name##_RB_NEXT(y)
|
||||
#define RB_PREV(name, x, y) name##_RB_PREV(y)
|
||||
#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF)
|
||||
#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF)
|
||||
|
||||
#define RB_FOREACH(x, name, head) \
|
||||
for ((x) = RB_MIN(name, head); \
|
||||
(x) != NULL; \
|
||||
(x) = name##_RB_NEXT(x))
|
||||
|
||||
#define RB_FOREACH_FROM(x, name, y) \
|
||||
for ((x) = (y); \
|
||||
((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \
|
||||
(x) = (y))
|
||||
|
||||
#define RB_FOREACH_SAFE(x, name, head, y) \
|
||||
for ((x) = RB_MIN(name, head); \
|
||||
((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \
|
||||
(x) = (y))
|
||||
|
||||
#define RB_FOREACH_REVERSE(x, name, head) \
|
||||
for ((x) = RB_MAX(name, head); \
|
||||
(x) != NULL; \
|
||||
(x) = name##_RB_PREV(x))
|
||||
|
||||
#define RB_FOREACH_REVERSE_FROM(x, name, y) \
|
||||
for ((x) = (y); \
|
||||
((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \
|
||||
(x) = (y))
|
||||
|
||||
#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \
|
||||
for ((x) = RB_MAX(name, head); \
|
||||
((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \
|
||||
(x) = (y))
|
||||
|
||||
#endif /* _SYS_TREE_H_ */
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* 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 <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "sys/ioctl.h"
|
||||
#include "ff_ipc.h"
|
||||
|
||||
/*
|
||||
* In general, we always call like this: ioctl(fd, com, data),
|
||||
* but if there is a pointer in the data and the pointer points to
|
||||
* a memory area, for example, data is struct ifreq, and it uses
|
||||
* ifreq.ifr_ifru.ifru_data, we must copy the memory to msg->buf_addr,
|
||||
* after this, it can be used to communicate with F-Stack process.
|
||||
* Otherwise, an unknown error will occur.
|
||||
*
|
||||
* Two cases:
|
||||
* 1.Normal, there is no need to copy memory: ioctl_va(fd, com, data, 0).
|
||||
* 2.There is a memory need to be copied: ioctl_va(fd, com, data, 3, offset, cpy_mem, clen).
|
||||
* offset: the offset of cpy_mem relative to data struct.
|
||||
* cpy_mem: the memory address that need to be copied.
|
||||
* clen: the size of memory that the cpy_mem pointed to.
|
||||
*
|
||||
*/
|
||||
int
|
||||
ioctl_va(int fd, unsigned long com, void *data, int argc, ...)
|
||||
{
|
||||
struct ff_msg *msg, *retmsg = NULL;
|
||||
unsigned size;
|
||||
void *cpy_mem;
|
||||
size_t offset, clen;
|
||||
|
||||
if (argc != 0 && argc != 3) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (argc == 3) {
|
||||
va_list ap;
|
||||
va_start(ap, argc);
|
||||
offset = va_arg(ap, size_t);
|
||||
cpy_mem = va_arg(ap, void *);
|
||||
clen = va_arg(ap, size_t);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
if (com > 0xffffffff) {
|
||||
printf("WARNING: ioctl sign-extension ioctl %lx\n", com);
|
||||
com &= 0xffffffff;
|
||||
}
|
||||
|
||||
size = IOCPARM_LEN(com);
|
||||
if ((size > IOCPARM_MAX) ||
|
||||
((com & (IOC_IN | IOC_OUT)) == 0) ||
|
||||
(size == 0) ||
|
||||
(com & IOC_VOID))
|
||||
return (ENOTTY);
|
||||
|
||||
msg = ff_ipc_msg_alloc();
|
||||
if (msg == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (size > msg->buf_len) {
|
||||
errno = EINVAL;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg->msg_type = FF_IOCTL;
|
||||
msg->ioctl.cmd = com;
|
||||
msg->ioctl.data = msg->buf_addr;
|
||||
memcpy(msg->ioctl.data, data, size);
|
||||
msg->buf_addr += size;
|
||||
|
||||
if (argc == 3) {
|
||||
if (size + clen > msg->buf_len) {
|
||||
errno = EINVAL;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
char *ptr = (char *)(msg->ioctl.data) + offset;
|
||||
char *buf_addr = msg->buf_addr;
|
||||
memcpy(ptr, &buf_addr, sizeof(char *));
|
||||
memcpy(buf_addr, cpy_mem, clen);
|
||||
}
|
||||
|
||||
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 = 0;
|
||||
|
||||
if (com & IOC_OUT) {
|
||||
memcpy(data, retmsg->ioctl.data, size);
|
||||
if (argc == 3) {
|
||||
memcpy(cpy_mem, retmsg->buf_addr, clen);
|
||||
char *ptr = (char *)data + offset;
|
||||
memcpy(ptr, &cpy_mem, sizeof(void *));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
errno = retmsg->result;
|
||||
}
|
||||
|
||||
ff_ipc_msg_free(msg);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <string.h>
|
||||
|
||||
/* States*/
|
||||
#define NAMING 0
|
||||
#define GOTONE 1
|
||||
#define GOTTWO 2
|
||||
#define RESET 3
|
||||
/* Inputs */
|
||||
#define DIGIT (4*0)
|
||||
#define END (4*1)
|
||||
#define DELIM (4*2)
|
||||
#define LETTER (4*3)
|
||||
|
||||
void
|
||||
link_addr(const char *addr, struct sockaddr_dl *sdl)
|
||||
{
|
||||
char *cp = sdl->sdl_data;
|
||||
char *cplim = sdl->sdl_len + (char *)sdl;
|
||||
int byte = 0, state = NAMING, new;
|
||||
|
||||
bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1);
|
||||
sdl->sdl_family = AF_LINK;
|
||||
do {
|
||||
state &= ~LETTER;
|
||||
if ((*addr >= '0') && (*addr <= '9')) {
|
||||
new = *addr - '0';
|
||||
} else if ((*addr >= 'a') && (*addr <= 'f')) {
|
||||
new = *addr - 'a' + 10;
|
||||
} else if ((*addr >= 'A') && (*addr <= 'F')) {
|
||||
new = *addr - 'A' + 10;
|
||||
} else if (*addr == 0) {
|
||||
state |= END;
|
||||
} else if (state == NAMING &&
|
||||
(((*addr >= 'A') && (*addr <= 'Z')) ||
|
||||
((*addr >= 'a') && (*addr <= 'z'))))
|
||||
state |= LETTER;
|
||||
else
|
||||
state |= DELIM;
|
||||
addr++;
|
||||
switch (state /* | INPUT */) {
|
||||
case NAMING | DIGIT:
|
||||
case NAMING | LETTER:
|
||||
*cp++ = addr[-1];
|
||||
continue;
|
||||
case NAMING | DELIM:
|
||||
state = RESET;
|
||||
sdl->sdl_nlen = cp - sdl->sdl_data;
|
||||
continue;
|
||||
case GOTTWO | DIGIT:
|
||||
*cp++ = byte;
|
||||
/* FALLTHROUGH */
|
||||
case RESET | DIGIT:
|
||||
state = GOTONE;
|
||||
byte = new;
|
||||
continue;
|
||||
case GOTONE | DIGIT:
|
||||
state = GOTTWO;
|
||||
byte = new + (byte << 4);
|
||||
continue;
|
||||
default: /* | DELIM */
|
||||
state = RESET;
|
||||
*cp++ = byte;
|
||||
byte = 0;
|
||||
continue;
|
||||
case GOTONE | END:
|
||||
case GOTTWO | END:
|
||||
*cp++ = byte;
|
||||
/* FALLTHROUGH */
|
||||
case RESET | END:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} while (cp < cplim);
|
||||
sdl->sdl_alen = cp - LLADDR(sdl);
|
||||
new = cp - (char *)sdl;
|
||||
if (new > sizeof(*sdl))
|
||||
sdl->sdl_len = new;
|
||||
return;
|
||||
}
|
||||
|
||||
static const char hexlist[] = "0123456789abcdef";
|
||||
|
||||
char *
|
||||
link_ntoa(const struct sockaddr_dl *sdl)
|
||||
{
|
||||
static char obuf[64];
|
||||
char *out = obuf;
|
||||
int i;
|
||||
u_char *in = (u_char *)LLADDR(sdl);
|
||||
u_char *inlim = in + sdl->sdl_alen;
|
||||
int firsttime = 1;
|
||||
|
||||
if (sdl->sdl_nlen) {
|
||||
bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen);
|
||||
out += sdl->sdl_nlen;
|
||||
if (sdl->sdl_alen)
|
||||
*out++ = ':';
|
||||
}
|
||||
while (in < inlim) {
|
||||
if (firsttime)
|
||||
firsttime = 0;
|
||||
else
|
||||
*out++ = '.';
|
||||
i = *in++;
|
||||
if (i > 0xf) {
|
||||
out[1] = hexlist[i & 0xf];
|
||||
i >>= 4;
|
||||
out[0] = hexlist[i];
|
||||
out += 2;
|
||||
} else
|
||||
*out++ = hexlist[i];
|
||||
}
|
||||
*out = 0;
|
||||
return (obuf);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*-
|
||||
* Copyright (c) 1998, M. Warner Losh <imp@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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "compat.h"
|
||||
|
||||
void *
|
||||
reallocf(void *ptr, size_t size)
|
||||
{
|
||||
void *nptr;
|
||||
|
||||
nptr = realloc(ptr, size);
|
||||
|
||||
/*
|
||||
* When the System V compatibility option (malloc "V" flag) is
|
||||
* in effect, realloc(ptr, 0) frees the memory and returns NULL.
|
||||
* So, to avoid double free, call free() only when size != 0.
|
||||
* realloc(ptr, 0) can't fail when ptr != NULL.
|
||||
*/
|
||||
if (!nptr && ptr && size != 0)
|
||||
free(ptr);
|
||||
return (nptr);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(dst, src, siz)
|
||||
char *dst;
|
||||
const char *src;
|
||||
size_t siz;
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char * __restrict dst, const char * __restrict src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0) {
|
||||
while (--n != 0) {
|
||||
if ((*d++ = *s++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*-
|
||||
* Copyright (c) 2004 Ted Unangst and Todd Miller
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#define INVALID 1
|
||||
#define TOOSMALL 2
|
||||
#define TOOLARGE 3
|
||||
|
||||
long long
|
||||
strtonum(const char *numstr, long long minval, long long maxval,
|
||||
const char **errstrp)
|
||||
{
|
||||
long long ll = 0;
|
||||
int error = 0;
|
||||
char *ep;
|
||||
struct errval {
|
||||
const char *errstr;
|
||||
int err;
|
||||
} ev[4] = {
|
||||
{ NULL, 0 },
|
||||
{ "invalid", EINVAL },
|
||||
{ "too small", ERANGE },
|
||||
{ "too large", ERANGE },
|
||||
};
|
||||
|
||||
ev[0].err = errno;
|
||||
errno = 0;
|
||||
if (minval > maxval) {
|
||||
error = INVALID;
|
||||
} else {
|
||||
ll = strtoll(numstr, &ep, 10);
|
||||
if (errno == EINVAL || numstr == ep || *ep != '\0')
|
||||
error = INVALID;
|
||||
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
|
||||
error = TOOSMALL;
|
||||
else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
|
||||
error = TOOLARGE;
|
||||
}
|
||||
if (errstrp != NULL)
|
||||
*errstrp = ev[error].errstr;
|
||||
errno = ev[error].err;
|
||||
if (error)
|
||||
ll = 0;
|
||||
|
||||
return (ll);
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "ff_ipc.h"
|
||||
|
||||
int
|
||||
sysctl(int *name, unsigned namelen, void *old,
|
||||
size_t *oldlenp, const void *new, size_t newlen)
|
||||
{
|
||||
struct ff_msg *msg, *retmsg = NULL;
|
||||
|
||||
if (old != NULL && oldlenp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg = ff_ipc_msg_alloc();
|
||||
if (msg == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t oldlen = 0;
|
||||
if (old && oldlenp) {
|
||||
oldlen = *oldlenp;
|
||||
}
|
||||
|
||||
if (namelen + oldlen + newlen > msg->buf_len) {
|
||||
errno = EINVAL;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *buf_addr = msg->buf_addr;
|
||||
|
||||
msg->msg_type = FF_SYSCTL;
|
||||
msg->sysctl.name = (int *)buf_addr;
|
||||
msg->sysctl.namelen = namelen;
|
||||
memcpy(msg->sysctl.name, name, namelen*sizeof(int));
|
||||
|
||||
buf_addr += namelen*sizeof(int);
|
||||
|
||||
if (new != NULL && newlen != 0) {
|
||||
msg->sysctl.new = buf_addr;
|
||||
msg->sysctl.newlen = newlen;
|
||||
memcpy(msg->sysctl.new, new, newlen);
|
||||
|
||||
buf_addr += newlen;
|
||||
} else {
|
||||
msg->sysctl.new = NULL;
|
||||
msg->sysctl.newlen = 0;
|
||||
}
|
||||
|
||||
if (oldlenp != NULL) {
|
||||
msg->sysctl.oldlenp = (size_t *)buf_addr;
|
||||
memcpy(msg->sysctl.oldlenp, oldlenp, sizeof(size_t));
|
||||
buf_addr += sizeof(size_t);
|
||||
|
||||
if (old != NULL) {
|
||||
msg->sysctl.old = (void *)buf_addr;
|
||||
memcpy(msg->sysctl.old, old, *oldlenp);
|
||||
buf_addr += *oldlenp;
|
||||
} else {
|
||||
msg->sysctl.old = NULL;
|
||||
}
|
||||
} else {
|
||||
msg->sysctl.oldlenp = NULL;
|
||||
msg->sysctl.old = NULL;
|
||||
}
|
||||
|
||||
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 = 0;
|
||||
if (oldlenp && retmsg->sysctl.oldlenp) {
|
||||
*oldlenp = *retmsg->sysctl.oldlenp;
|
||||
}
|
||||
|
||||
if (old && retmsg->sysctl.old && oldlenp) {
|
||||
memcpy(old, retmsg->sysctl.old, *oldlenp);
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
errno = retmsg->result;
|
||||
}
|
||||
|
||||
ff_ipc_msg_free(msg);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Copied from FreeBSD's header files.
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYSCTL_H
|
||||
#define _COMPAT_SYSCTL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/*
|
||||
* Definitions for sysctl call. The sysctl call uses a hierarchical name
|
||||
* for objects that can be examined or modified. The name is expressed as
|
||||
* a sequence of integers. Like a file path name, the meaning of each
|
||||
* component depends on its place in the hierarchy. The top-level and kern
|
||||
* identifiers are defined here, and other identifiers are defined in the
|
||||
* respective subsystem header files.
|
||||
*/
|
||||
|
||||
#define CTL_MAXNAME 24 /* largest number of components supported */
|
||||
|
||||
#define CTLTYPE 0xf /* mask for the type */
|
||||
#define CTLTYPE_NODE 1 /* name is a node */
|
||||
#define CTLTYPE_INT 2 /* name describes an integer */
|
||||
#define CTLTYPE_STRING 3 /* name describes a string */
|
||||
#define CTLTYPE_S64 4 /* name describes a signed 64-bit number */
|
||||
#define CTLTYPE_OPAQUE 5 /* name describes a structure */
|
||||
#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
|
||||
#define CTLTYPE_UINT 6 /* name describes an unsigned integer */
|
||||
#define CTLTYPE_LONG 7 /* name describes a long */
|
||||
#define CTLTYPE_ULONG 8 /* name describes an unsigned long */
|
||||
#define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */
|
||||
#define CTLTYPE_U8 0xa /* name describes an unsigned 8-bit number */
|
||||
#define CTLTYPE_U16 0xb /* name describes an unsigned 16-bit number */
|
||||
#define CTLTYPE_S8 0xc /* name describes a signed 8-bit number */
|
||||
#define CTLTYPE_S16 0xd /* name describes a signed 16-bit number */
|
||||
#define CTLTYPE_S32 0xe /* name describes a signed 32-bit number */
|
||||
#define CTLTYPE_U32 0xf /* name describes an unsigned 32-bit number */
|
||||
|
||||
#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
|
||||
#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
|
||||
#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
|
||||
#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
|
||||
#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
|
||||
#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */
|
||||
#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */
|
||||
#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */
|
||||
#define CTLMASK_SECURE 0x00F00000 /* Secure level */
|
||||
#define CTLFLAG_TUN 0x00080000 /* Default value is loaded from getenv() */
|
||||
#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN)
|
||||
#define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN)
|
||||
#define CTLFLAG_MPSAFE 0x00040000 /* Handler is MP safe */
|
||||
#define CTLFLAG_VNET 0x00020000 /* Prisons with vnet can fiddle */
|
||||
#define CTLFLAG_DYING 0x00010000 /* Oid is being removed */
|
||||
#define CTLFLAG_CAPRD 0x00008000 /* Can be read in capability mode */
|
||||
#define CTLFLAG_CAPWR 0x00004000 /* Can be written in capability mode */
|
||||
#define CTLFLAG_STATS 0x00002000 /* Statistics, not a tuneable */
|
||||
#define CTLFLAG_NOFETCH 0x00001000 /* Don't fetch tunable from getenv() */
|
||||
#define CTLFLAG_CAPRW (CTLFLAG_CAPRD|CTLFLAG_CAPWR)
|
||||
|
||||
struct clockinfo {
|
||||
int hz; /* clock frequency */
|
||||
int tick; /* micro-seconds per hz tick */
|
||||
int spare;
|
||||
int stathz; /* statistics clock frequency */
|
||||
int profhz; /* profiling clock frequency */
|
||||
};
|
||||
|
||||
struct loadavg {
|
||||
__uint32_t ldavg[3];
|
||||
long fscale;
|
||||
};
|
||||
|
||||
/* Structure extended to include extended attribute field in ACPI 3.0. */
|
||||
struct bios_smap_xattr {
|
||||
u_int64_t base;
|
||||
u_int64_t length;
|
||||
u_int32_t type;
|
||||
u_int32_t xattr;
|
||||
} __packed;
|
||||
|
||||
/* systemwide totals computed every five seconds */
|
||||
struct vmtotal {
|
||||
int16_t t_rq; /* length of the run queue */
|
||||
int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */
|
||||
int16_t t_pw; /* jobs in page wait */
|
||||
int16_t t_sl; /* jobs sleeping in core */
|
||||
int16_t t_sw; /* swapped out runnable/short block jobs */
|
||||
int32_t t_vm; /* total virtual memory */
|
||||
int32_t t_avm; /* active virtual memory */
|
||||
int32_t t_rm; /* total real memory in use */
|
||||
int32_t t_arm; /* active real memory */
|
||||
int32_t t_vmshr; /* shared virtual memory */
|
||||
int32_t t_avmshr; /* active shared virtual memory */
|
||||
int32_t t_rmshr; /* shared real memory */
|
||||
int32_t t_armshr; /* active shared real memory */
|
||||
int32_t t_free; /* free memory pages */
|
||||
};
|
||||
|
||||
struct efi_md {
|
||||
uint32_t md_type;
|
||||
#define EFI_MD_TYPE_NULL 0
|
||||
#define EFI_MD_TYPE_CODE 1 /* Loader text. */
|
||||
#define EFI_MD_TYPE_DATA 2 /* Loader data. */
|
||||
#define EFI_MD_TYPE_BS_CODE 3 /* Boot services text. */
|
||||
#define EFI_MD_TYPE_BS_DATA 4 /* Boot services data. */
|
||||
#define EFI_MD_TYPE_RT_CODE 5 /* Runtime services text. */
|
||||
#define EFI_MD_TYPE_RT_DATA 6 /* Runtime services data. */
|
||||
#define EFI_MD_TYPE_FREE 7 /* Unused/free memory. */
|
||||
#define EFI_MD_TYPE_BAD 8 /* Bad memory */
|
||||
#define EFI_MD_TYPE_RECLAIM 9 /* ACPI reclaimable memory. */
|
||||
#define EFI_MD_TYPE_FIRMWARE 10 /* ACPI NV memory */
|
||||
#define EFI_MD_TYPE_IOMEM 11 /* Memory-mapped I/O. */
|
||||
#define EFI_MD_TYPE_IOPORT 12 /* I/O port space. */
|
||||
#define EFI_MD_TYPE_PALCODE 13 /* PAL */
|
||||
uint32_t __pad;
|
||||
uint64_t md_phys;
|
||||
void *md_virt;
|
||||
uint64_t md_pages;
|
||||
uint64_t md_attr;
|
||||
#define EFI_MD_ATTR_UC 0x0000000000000001UL
|
||||
#define EFI_MD_ATTR_WC 0x0000000000000002UL
|
||||
#define EFI_MD_ATTR_WT 0x0000000000000004UL
|
||||
#define EFI_MD_ATTR_WB 0x0000000000000008UL
|
||||
#define EFI_MD_ATTR_UCE 0x0000000000000010UL
|
||||
#define EFI_MD_ATTR_WP 0x0000000000001000UL
|
||||
#define EFI_MD_ATTR_RP 0x0000000000002000UL
|
||||
#define EFI_MD_ATTR_XP 0x0000000000004000UL
|
||||
#define EFI_MD_ATTR_RT 0x8000000000000000UL
|
||||
};
|
||||
|
||||
struct efi_map_header {
|
||||
uint64_t memory_size;
|
||||
uint64_t descriptor_size;
|
||||
uint32_t descriptor_version;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
int
|
||||
sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
|
||||
const void *newp, size_t newlen)
|
||||
{
|
||||
int real_oid[CTL_MAXNAME+2];
|
||||
size_t oidlen;
|
||||
|
||||
oidlen = sizeof(real_oid) / sizeof(int);
|
||||
if (sysctlnametomib(name, real_oid, &oidlen) < 0)
|
||||
return (-1);
|
||||
return (sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen));
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2001 The FreeBSD Project. 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 FREEBSD PROJECT ``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 FREEBSD PROJECT 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/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*
|
||||
* This function uses a presently undocumented interface to the kernel
|
||||
* to walk the tree and get the type so it can print the value.
|
||||
* This interface is under work and consideration, and should probably
|
||||
* be killed with a big axe by the first person who can find the time.
|
||||
* (be aware though, that the proper interface isn't as obvious as it
|
||||
* may seem, there are various conflicting requirements.
|
||||
*/
|
||||
int
|
||||
sysctlnametomib(const char *name, int *mibp, size_t *sizep)
|
||||
{
|
||||
int oid[2];
|
||||
int error;
|
||||
|
||||
oid[0] = 0;
|
||||
oid[1] = 3;
|
||||
|
||||
*sizep *= sizeof(int);
|
||||
error = sysctl(oid, 2, mibp, sizep, name, strlen(name));
|
||||
*sizep /= sizeof(int);
|
||||
return (error);
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
# From: @(#)Makefile 8.1 (Berkeley) 6/5/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= ifconfig
|
||||
|
||||
SRCS= ifconfig.c # base support
|
||||
|
||||
TOPDIR?=${CURDIR}/../..
|
||||
include ${TOPDIR}/tools/opts.mk
|
||||
|
||||
#
|
||||
# NB: The order here defines the order in which the constructors
|
||||
# are called. This in turn defines the default order in which
|
||||
# status is displayed. Probably should add a priority mechanism
|
||||
# to the registration process so we don't depend on this aspect
|
||||
# of the toolchain.
|
||||
#
|
||||
SRCS+= af_link.c # LLC support
|
||||
ifneq (${MK_INET_SUPPORT},"no")
|
||||
SRCS+= af_inet.c # IPv4 support
|
||||
endif
|
||||
ifneq (${MK_INET6_SUPPORT},"no")
|
||||
SRCS+= af_inet6.c # IPv6 support
|
||||
endif
|
||||
ifneq (${MK_INET6_SUPPORT},"no")
|
||||
SRCS+= af_nd6.c # ND6 support
|
||||
endif
|
||||
|
||||
SRCS+= ifclone.c # clone device support
|
||||
|
||||
ifneq (${MK_MAC_SUPPORT},"no")
|
||||
SRCS+= ifmac.c # MAC support
|
||||
endif
|
||||
|
||||
ifneq (${MK_IFMEDIA_SUPPORT},"no")
|
||||
SRCS+= ifmedia.c # SIOC[GS]IFMEDIA support
|
||||
endif
|
||||
|
||||
SRCS+= iffib.c # non-default FIB support
|
||||
SRCS+= ifvlan.c # SIOC[GS]ETVLAN support
|
||||
SRCS+= ifvxlan.c # VXLAN support
|
||||
SRCS+= ifgre.c # GRE keys etc
|
||||
SRCS+= ifgif.c # GIF reversed header workaround
|
||||
|
||||
ifneq (${MK_SFP_SUPPORT},"no")
|
||||
SRCS+= sfp.c # SFP/SFP+ information
|
||||
LIBADD+= m
|
||||
endif
|
||||
|
||||
ifneq (${MK_IEEE80211_SUPPORT},"no")
|
||||
SRCS+= ifieee80211.c # SIOC[GS]IEEE80211 support
|
||||
LIBADD+= 80211
|
||||
endif
|
||||
|
||||
SRCS+= carp.c # SIOC[GS]VH support
|
||||
SRCS+= ifgroup.c # ...
|
||||
ifneq (${MK_PF},"no")
|
||||
SRCS+= ifpfsync.c # pfsync(4) support
|
||||
endif
|
||||
|
||||
SRCS+= ifbridge.c # bridge support
|
||||
ifneq (${MK_LAGG_SUPPORT},"no")
|
||||
SRCS+= iflagg.c # lagg support
|
||||
endif
|
||||
|
||||
ifneq (${MK_INET6_SUPPORT},"no")
|
||||
CFLAGS+= -DINET6
|
||||
endif
|
||||
ifneq (${MK_INET_SUPPORT},"no")
|
||||
CFLAGS+= -DINET
|
||||
endif
|
||||
ifneq (${MK_JAIL},"no")
|
||||
ifndef (RELEASE_CRUNCH)
|
||||
ifndef (RESCUE)
|
||||
CFLAGS+= -DJAIL
|
||||
LIBADD+= jail
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
MAN= ifconfig.8
|
||||
|
||||
CFLAGS+= -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wnested-externs
|
||||
WARNS?= 2
|
||||
|
||||
include ${TOPDIR}/tools/prog.mk
|
||||
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static struct in_aliasreq in_addreq;
|
||||
static struct ifreq in_ridreq;
|
||||
static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
|
||||
extern char *f_inet, *f_addr;
|
||||
|
||||
static void
|
||||
in_status(int s __unused, const struct ifaddrs *ifa)
|
||||
{
|
||||
struct sockaddr_in *sin, null_sin;
|
||||
#ifndef FSTACK
|
||||
int error, n_flags;
|
||||
#endif
|
||||
|
||||
memset(&null_sin, 0, sizeof(null_sin));
|
||||
|
||||
sin = (struct sockaddr_in *)ifa->ifa_addr;
|
||||
if (sin == NULL)
|
||||
return;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
|
||||
n_flags = 0;
|
||||
else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
|
||||
n_flags = NI_NOFQDN;
|
||||
else
|
||||
n_flags = NI_NUMERICHOST;
|
||||
|
||||
error = getnameinfo((struct sockaddr *)sin, sin->sin_len, addr_buf,
|
||||
sizeof(addr_buf), NULL, 0, n_flags);
|
||||
|
||||
if (error)
|
||||
#endif
|
||||
inet_ntop(AF_INET, &sin->sin_addr, addr_buf, sizeof(addr_buf));
|
||||
|
||||
printf("\tinet %s", addr_buf);
|
||||
|
||||
if (ifa->ifa_flags & IFF_POINTOPOINT) {
|
||||
sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
|
||||
if (sin == NULL)
|
||||
sin = &null_sin;
|
||||
printf(" --> %s ", inet_ntoa(sin->sin_addr));
|
||||
}
|
||||
|
||||
sin = (struct sockaddr_in *)ifa->ifa_netmask;
|
||||
if (sin == NULL)
|
||||
sin = &null_sin;
|
||||
if (f_inet != NULL && strcmp(f_inet, "cidr") == 0) {
|
||||
int cidr = 32;
|
||||
unsigned long smask;
|
||||
|
||||
smask = ntohl(sin->sin_addr.s_addr);
|
||||
while ((smask & 1) == 0) {
|
||||
smask = smask >> 1;
|
||||
cidr--;
|
||||
if (cidr == 0)
|
||||
break;
|
||||
}
|
||||
printf("/%d ", cidr);
|
||||
} else if (f_inet != NULL && strcmp(f_inet, "dotted") == 0)
|
||||
printf(" netmask %s ", inet_ntoa(sin->sin_addr));
|
||||
else
|
||||
printf(" netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr));
|
||||
|
||||
if (ifa->ifa_flags & IFF_BROADCAST) {
|
||||
sin = (struct sockaddr_in *)ifa->ifa_broadaddr;
|
||||
if (sin != NULL && sin->sin_addr.s_addr != 0)
|
||||
printf("broadcast %s ", inet_ntoa(sin->sin_addr));
|
||||
}
|
||||
|
||||
print_vhid(ifa, " ");
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
#define SIN(x) ((struct sockaddr_in *) &(x))
|
||||
static struct sockaddr_in *sintab[] = {
|
||||
SIN(in_ridreq.ifr_addr), SIN(in_addreq.ifra_addr),
|
||||
SIN(in_addreq.ifra_mask), SIN(in_addreq.ifra_broadaddr)
|
||||
};
|
||||
|
||||
static void
|
||||
in_getaddr(const char *s, int which)
|
||||
{
|
||||
struct sockaddr_in *sin = sintab[which];
|
||||
#ifndef FSTACK
|
||||
struct hostent *hp;
|
||||
struct netent *np;
|
||||
#endif
|
||||
|
||||
sin->sin_len = sizeof(*sin);
|
||||
sin->sin_family = AF_INET;
|
||||
|
||||
if (which == ADDR) {
|
||||
char *p = NULL;
|
||||
|
||||
if((p = strrchr(s, '/')) != NULL) {
|
||||
const char *errstr;
|
||||
/* address is `name/masklen' */
|
||||
int masklen;
|
||||
struct sockaddr_in *min = sintab[MASK];
|
||||
*p = '\0';
|
||||
if (!isdigit(*(p + 1)))
|
||||
errstr = "invalid";
|
||||
else
|
||||
masklen = (int)strtonum(p + 1, 0, 32, &errstr);
|
||||
if (errstr != NULL) {
|
||||
*p = '/';
|
||||
errx(1, "%s: bad value (width %s)", s, errstr);
|
||||
}
|
||||
min->sin_family = AF_INET;
|
||||
min->sin_len = sizeof(*min);
|
||||
min->sin_addr.s_addr = htonl(~((1LL << (32 - masklen)) - 1) &
|
||||
0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
if (inet_aton(s, &sin->sin_addr))
|
||||
return;
|
||||
#ifdef FSTACK
|
||||
else
|
||||
errx(1, "%s: bad value", s);
|
||||
#else
|
||||
if ((hp = gethostbyname(s)) != NULL)
|
||||
bcopy(hp->h_addr, (char *)&sin->sin_addr,
|
||||
MIN((size_t)hp->h_length, sizeof(sin->sin_addr)));
|
||||
else if ((np = getnetbyname(s)) != NULL)
|
||||
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
|
||||
else
|
||||
errx(1, "%s: bad value", s);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
in_status_tunnel(int s)
|
||||
{
|
||||
char src[NI_MAXHOST];
|
||||
char dst[NI_MAXHOST];
|
||||
struct ifreq ifr;
|
||||
const struct sockaddr *sa = (const struct sockaddr *) &ifr.ifr_addr;
|
||||
#ifdef FSTACK
|
||||
const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
|
||||
#endif
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, name, IFNAMSIZ);
|
||||
|
||||
if (ioctl(s, SIOCGIFPSRCADDR, (caddr_t)&ifr) < 0)
|
||||
return;
|
||||
if (sa->sa_family != AF_INET)
|
||||
return;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0, NI_NUMERICHOST) != 0)
|
||||
src[0] = '\0';
|
||||
#else
|
||||
if (inet_ntop(AF_INET, &sin->sin_addr, src, sizeof(src)) == NULL)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (ioctl(s, SIOCGIFPDSTADDR, (caddr_t)&ifr) < 0)
|
||||
return;
|
||||
if (sa->sa_family != AF_INET)
|
||||
return;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0, NI_NUMERICHOST) != 0)
|
||||
dst[0] = '\0';
|
||||
#else
|
||||
if (inet_ntop(AF_INET, &sin->sin_addr, dst, sizeof(dst)) == NULL)
|
||||
return;
|
||||
#endif
|
||||
|
||||
printf("\ttunnel inet %s --> %s\n", src, dst);
|
||||
}
|
||||
|
||||
static void
|
||||
in_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres)
|
||||
{
|
||||
struct in_aliasreq addreq;
|
||||
|
||||
memset(&addreq, 0, sizeof(addreq));
|
||||
strlcpy(addreq.ifra_name, name, IFNAMSIZ);
|
||||
memcpy(&addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
|
||||
memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len);
|
||||
|
||||
if (ioctl(s, SIOCSIFPHYADDR, &addreq) < 0)
|
||||
warn("SIOCSIFPHYADDR");
|
||||
}
|
||||
|
||||
static struct afswtch af_inet = {
|
||||
.af_name = "inet",
|
||||
.af_af = AF_INET,
|
||||
.af_status = in_status,
|
||||
.af_getaddr = in_getaddr,
|
||||
.af_status_tunnel = in_status_tunnel,
|
||||
.af_settunnel = in_set_tunnel,
|
||||
.af_difaddr = SIOCDIFADDR,
|
||||
.af_aifaddr = SIOCAIFADDR,
|
||||
.af_ridreq = &in_ridreq,
|
||||
.af_addreq = &in_addreq,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
inet_ctor(void)
|
||||
{
|
||||
#ifndef FSTACK
|
||||
#ifndef RESCUE
|
||||
if (!feature_present("inet"))
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
af_register(&af_inet);
|
||||
}
|
|
@ -0,0 +1,547 @@
|
|||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static struct in6_ifreq in6_ridreq;
|
||||
static struct in6_aliasreq in6_addreq =
|
||||
{ .ifra_flags = 0,
|
||||
.ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } };
|
||||
static int ip6lifetime;
|
||||
|
||||
static int prefix(void *, int);
|
||||
static char *sec2str(time_t);
|
||||
static int explicit_prefix = 0;
|
||||
extern char *f_inet6, *f_addr;
|
||||
|
||||
extern void setnd6flags(const char *, int, int, const struct afswtch *);
|
||||
extern void setnd6defif(const char *, int, int, const struct afswtch *);
|
||||
extern void nd6_status(int);
|
||||
|
||||
static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/
|
||||
|
||||
static void
|
||||
setifprefixlen(const char *addr, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
if (afp->af_getprefix != NULL)
|
||||
afp->af_getprefix(addr, MASK);
|
||||
explicit_prefix = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
setip6flags(const char *dummyaddr __unused, int flag, int dummysoc __unused,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
if (afp->af_af != AF_INET6)
|
||||
err(1, "address flags can be set only for inet6 addresses");
|
||||
|
||||
if (flag < 0)
|
||||
in6_addreq.ifra_flags &= ~(-flag);
|
||||
else
|
||||
in6_addreq.ifra_flags |= flag;
|
||||
}
|
||||
|
||||
static void
|
||||
setip6lifetime(const char *cmd, const char *val, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct timespec now;
|
||||
time_t newval;
|
||||
char *ep;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
||||
newval = (time_t)strtoul(val, &ep, 0);
|
||||
if (val == ep)
|
||||
errx(1, "invalid %s", cmd);
|
||||
if (afp->af_af != AF_INET6)
|
||||
errx(1, "%s not allowed for the AF", cmd);
|
||||
if (strcmp(cmd, "vltime") == 0) {
|
||||
in6_addreq.ifra_lifetime.ia6t_expire = now.tv_sec + newval;
|
||||
in6_addreq.ifra_lifetime.ia6t_vltime = newval;
|
||||
} else if (strcmp(cmd, "pltime") == 0) {
|
||||
in6_addreq.ifra_lifetime.ia6t_preferred = now.tv_sec + newval;
|
||||
in6_addreq.ifra_lifetime.ia6t_pltime = newval;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setip6pltime(const char *seconds, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
setip6lifetime("pltime", seconds, s, afp);
|
||||
}
|
||||
|
||||
static void
|
||||
setip6vltime(const char *seconds, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
setip6lifetime("vltime", seconds, s, afp);
|
||||
}
|
||||
|
||||
static void
|
||||
setip6eui64(const char *cmd, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
const struct sockaddr_in6 *sin6 = NULL;
|
||||
const struct in6_addr *lladdr = NULL;
|
||||
struct in6_addr *in6;
|
||||
|
||||
if (afp->af_af != AF_INET6)
|
||||
errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
|
||||
in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr;
|
||||
if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0)
|
||||
errx(EXIT_FAILURE, "interface index is already filled");
|
||||
if (getifaddrs(&ifap) != 0)
|
||||
err(EXIT_FAILURE, "getifaddrs");
|
||||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr->sa_family == AF_INET6 &&
|
||||
strcmp(ifa->ifa_name, name) == 0) {
|
||||
sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
||||
lladdr = &sin6->sin6_addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!lladdr)
|
||||
errx(EXIT_FAILURE, "could not determine link local address");
|
||||
|
||||
memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
|
||||
|
||||
freeifaddrs(ifap);
|
||||
}
|
||||
|
||||
static void
|
||||
in6_status(int s __unused, const struct ifaddrs *ifa)
|
||||
{
|
||||
struct sockaddr_in6 *sin, null_sin;
|
||||
struct in6_ifreq ifr6;
|
||||
int s6;
|
||||
u_int32_t flags6;
|
||||
struct in6_addrlifetime lifetime;
|
||||
struct timespec now;
|
||||
int error, n_flags;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
||||
|
||||
memset(&null_sin, 0, sizeof(null_sin));
|
||||
|
||||
sin = (struct sockaddr_in6 *)ifa->ifa_addr;
|
||||
if (sin == NULL)
|
||||
return;
|
||||
|
||||
strlcpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
|
||||
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
warn("socket(AF_INET6,SOCK_DGRAM)");
|
||||
return;
|
||||
}
|
||||
ifr6.ifr_addr = *sin;
|
||||
if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
|
||||
warn("ioctl(SIOCGIFAFLAG_IN6)");
|
||||
close(s6);
|
||||
return;
|
||||
}
|
||||
flags6 = ifr6.ifr_ifru.ifru_flags6;
|
||||
memset(&lifetime, 0, sizeof(lifetime));
|
||||
ifr6.ifr_addr = *sin;
|
||||
if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) {
|
||||
warn("ioctl(SIOCGIFALIFETIME_IN6)");
|
||||
close(s6);
|
||||
return;
|
||||
}
|
||||
lifetime = ifr6.ifr_ifru.ifru_lifetime;
|
||||
close(s6);
|
||||
|
||||
if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
|
||||
n_flags = 0;
|
||||
else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
|
||||
n_flags = NI_NOFQDN;
|
||||
else
|
||||
n_flags = NI_NUMERICHOST;
|
||||
error = getnameinfo((struct sockaddr *)sin, sin->sin6_len,
|
||||
addr_buf, sizeof(addr_buf), NULL, 0,
|
||||
n_flags);
|
||||
if (error != 0)
|
||||
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
|
||||
sizeof(addr_buf));
|
||||
printf("\tinet6 %s", addr_buf);
|
||||
|
||||
if (ifa->ifa_flags & IFF_POINTOPOINT) {
|
||||
sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
|
||||
/*
|
||||
* some of the interfaces do not have valid destination
|
||||
* address.
|
||||
*/
|
||||
if (sin != NULL && sin->sin6_family == AF_INET6) {
|
||||
int error;
|
||||
|
||||
error = getnameinfo((struct sockaddr *)sin,
|
||||
sin->sin6_len, addr_buf,
|
||||
sizeof(addr_buf), NULL, 0,
|
||||
NI_NUMERICHOST);
|
||||
if (error != 0)
|
||||
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
|
||||
sizeof(addr_buf));
|
||||
printf(" --> %s ", addr_buf);
|
||||
}
|
||||
}
|
||||
|
||||
sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
|
||||
if (sin == NULL)
|
||||
sin = &null_sin;
|
||||
if (f_inet6 != NULL && strcmp(f_inet6, "cidr") == 0)
|
||||
printf("/%d ", prefix(&sin->sin6_addr,
|
||||
sizeof(struct in6_addr)));
|
||||
else
|
||||
printf(" prefixlen %d ", prefix(&sin->sin6_addr,
|
||||
sizeof(struct in6_addr)));
|
||||
|
||||
if ((flags6 & IN6_IFF_ANYCAST) != 0)
|
||||
printf("anycast ");
|
||||
if ((flags6 & IN6_IFF_TENTATIVE) != 0)
|
||||
printf("tentative ");
|
||||
if ((flags6 & IN6_IFF_DUPLICATED) != 0)
|
||||
printf("duplicated ");
|
||||
if ((flags6 & IN6_IFF_DETACHED) != 0)
|
||||
printf("detached ");
|
||||
if ((flags6 & IN6_IFF_DEPRECATED) != 0)
|
||||
printf("deprecated ");
|
||||
if ((flags6 & IN6_IFF_AUTOCONF) != 0)
|
||||
printf("autoconf ");
|
||||
if ((flags6 & IN6_IFF_TEMPORARY) != 0)
|
||||
printf("temporary ");
|
||||
if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
|
||||
printf("prefer_source ");
|
||||
|
||||
if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
|
||||
printf("scopeid 0x%x ",
|
||||
((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
|
||||
|
||||
if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
|
||||
printf("pltime ");
|
||||
if (lifetime.ia6t_preferred) {
|
||||
printf("%s ", lifetime.ia6t_preferred < now.tv_sec
|
||||
? "0" :
|
||||
sec2str(lifetime.ia6t_preferred - now.tv_sec));
|
||||
} else
|
||||
printf("infty ");
|
||||
|
||||
printf("vltime ");
|
||||
if (lifetime.ia6t_expire) {
|
||||
printf("%s ", lifetime.ia6t_expire < now.tv_sec
|
||||
? "0" :
|
||||
sec2str(lifetime.ia6t_expire - now.tv_sec));
|
||||
} else
|
||||
printf("infty ");
|
||||
}
|
||||
|
||||
print_vhid(ifa, " ");
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
#define SIN6(x) ((struct sockaddr_in6 *) &(x))
|
||||
static struct sockaddr_in6 *sin6tab[] = {
|
||||
SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr),
|
||||
SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr)
|
||||
};
|
||||
|
||||
static void
|
||||
in6_getprefix(const char *plen, int which)
|
||||
{
|
||||
struct sockaddr_in6 *sin = sin6tab[which];
|
||||
u_char *cp;
|
||||
int len = atoi(plen);
|
||||
|
||||
if ((len < 0) || (len > 128))
|
||||
errx(1, "%s: bad value", plen);
|
||||
sin->sin6_len = sizeof(*sin);
|
||||
if (which != MASK)
|
||||
sin->sin6_family = AF_INET6;
|
||||
if ((len == 0) || (len == 128)) {
|
||||
memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr));
|
||||
return;
|
||||
}
|
||||
memset((void *)&sin->sin6_addr, 0x00, sizeof(sin->sin6_addr));
|
||||
for (cp = (u_char *)&sin->sin6_addr; len > 7; len -= 8)
|
||||
*cp++ = 0xff;
|
||||
*cp = 0xff << (8 - len);
|
||||
}
|
||||
|
||||
static void
|
||||
in6_getaddr(const char *s, int which)
|
||||
{
|
||||
struct sockaddr_in6 *sin = sin6tab[which];
|
||||
struct addrinfo hints, *res;
|
||||
int error = -1;
|
||||
|
||||
newaddr &= 1;
|
||||
|
||||
sin->sin6_len = sizeof(*sin);
|
||||
if (which != MASK)
|
||||
sin->sin6_family = AF_INET6;
|
||||
|
||||
if (which == ADDR) {
|
||||
char *p = NULL;
|
||||
if((p = strrchr(s, '/')) != NULL) {
|
||||
*p = '\0';
|
||||
in6_getprefix(p + 1, MASK);
|
||||
explicit_prefix = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sin->sin6_family == AF_INET6) {
|
||||
bzero(&hints, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_INET6;
|
||||
error = getaddrinfo(s, NULL, &hints, &res);
|
||||
}
|
||||
if (error != 0) {
|
||||
if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
|
||||
errx(1, "%s: bad value", s);
|
||||
} else
|
||||
bcopy(res->ai_addr, sin, res->ai_addrlen);
|
||||
}
|
||||
|
||||
static int
|
||||
prefix(void *val, int size)
|
||||
{
|
||||
u_char *name = (u_char *)val;
|
||||
int byte, bit, plen = 0;
|
||||
|
||||
for (byte = 0; byte < size; byte++, plen += 8)
|
||||
if (name[byte] != 0xff)
|
||||
break;
|
||||
if (byte == size)
|
||||
return (plen);
|
||||
for (bit = 7; bit != 0; bit--, plen++)
|
||||
if (!(name[byte] & (1 << bit)))
|
||||
break;
|
||||
for (; bit != 0; bit--)
|
||||
if (name[byte] & (1 << bit))
|
||||
return(0);
|
||||
byte++;
|
||||
for (; byte < size; byte++)
|
||||
if (name[byte])
|
||||
return(0);
|
||||
return (plen);
|
||||
}
|
||||
|
||||
static char *
|
||||
sec2str(time_t total)
|
||||
{
|
||||
static char result[256];
|
||||
int days, hours, mins, secs;
|
||||
int first = 1;
|
||||
char *p = result;
|
||||
|
||||
if (0) {
|
||||
days = total / 3600 / 24;
|
||||
hours = (total / 3600) % 24;
|
||||
mins = (total / 60) % 60;
|
||||
secs = total % 60;
|
||||
|
||||
if (days) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dd", days);
|
||||
}
|
||||
if (!first || hours) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dh", hours);
|
||||
}
|
||||
if (!first || mins) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dm", mins);
|
||||
}
|
||||
sprintf(p, "%ds", secs);
|
||||
} else
|
||||
sprintf(result, "%lu", (unsigned long)total);
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
static void
|
||||
in6_postproc(int s, const struct afswtch *afp)
|
||||
{
|
||||
if (explicit_prefix == 0) {
|
||||
/* Aggregatable address architecture defines all prefixes
|
||||
are 64. So, it is convenient to set prefixlen to 64 if
|
||||
it is not specified. */
|
||||
setifprefixlen("64", 0, s, afp);
|
||||
/* in6_getprefix("64", MASK) if MASK is available here... */
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
in6_status_tunnel(int s)
|
||||
{
|
||||
char src[NI_MAXHOST];
|
||||
char dst[NI_MAXHOST];
|
||||
struct in6_ifreq in6_ifr;
|
||||
const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr;
|
||||
|
||||
memset(&in6_ifr, 0, sizeof(in6_ifr));
|
||||
strlcpy(in6_ifr.ifr_name, name, sizeof(in6_ifr.ifr_name));
|
||||
|
||||
if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0)
|
||||
return;
|
||||
if (sa->sa_family != AF_INET6)
|
||||
return;
|
||||
if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0,
|
||||
NI_NUMERICHOST) != 0)
|
||||
src[0] = '\0';
|
||||
|
||||
if (ioctl(s, SIOCGIFPDSTADDR_IN6, (caddr_t)&in6_ifr) < 0)
|
||||
return;
|
||||
if (sa->sa_family != AF_INET6)
|
||||
return;
|
||||
if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0,
|
||||
NI_NUMERICHOST) != 0)
|
||||
dst[0] = '\0';
|
||||
|
||||
printf("\ttunnel inet6 %s --> %s\n", src, dst);
|
||||
}
|
||||
|
||||
static void
|
||||
in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres)
|
||||
{
|
||||
struct in6_aliasreq in6_addreq;
|
||||
|
||||
memset(&in6_addreq, 0, sizeof(in6_addreq));
|
||||
strlcpy(in6_addreq.ifra_name, name, sizeof(in6_addreq.ifra_name));
|
||||
memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
|
||||
memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr,
|
||||
dstres->ai_addr->sa_len);
|
||||
|
||||
if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0)
|
||||
warn("SIOCSIFPHYADDR_IN6");
|
||||
}
|
||||
|
||||
static struct cmd inet6_cmds[] = {
|
||||
DEF_CMD_ARG("prefixlen", setifprefixlen),
|
||||
DEF_CMD("anycast", IN6_IFF_ANYCAST, setip6flags),
|
||||
DEF_CMD("tentative", IN6_IFF_TENTATIVE, setip6flags),
|
||||
DEF_CMD("-tentative", -IN6_IFF_TENTATIVE, setip6flags),
|
||||
DEF_CMD("deprecated", IN6_IFF_DEPRECATED, setip6flags),
|
||||
DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED, setip6flags),
|
||||
DEF_CMD("autoconf", IN6_IFF_AUTOCONF, setip6flags),
|
||||
DEF_CMD("-autoconf", -IN6_IFF_AUTOCONF, setip6flags),
|
||||
DEF_CMD("prefer_source",IN6_IFF_PREFER_SOURCE, setip6flags),
|
||||
DEF_CMD("-prefer_source",-IN6_IFF_PREFER_SOURCE,setip6flags),
|
||||
DEF_CMD("accept_rtadv", ND6_IFF_ACCEPT_RTADV, setnd6flags),
|
||||
DEF_CMD("-accept_rtadv",-ND6_IFF_ACCEPT_RTADV, setnd6flags),
|
||||
DEF_CMD("no_radr", ND6_IFF_NO_RADR, setnd6flags),
|
||||
DEF_CMD("-no_radr", -ND6_IFF_NO_RADR, setnd6flags),
|
||||
DEF_CMD("defaultif", 1, setnd6defif),
|
||||
DEF_CMD("-defaultif", -1, setnd6defif),
|
||||
DEF_CMD("ifdisabled", ND6_IFF_IFDISABLED, setnd6flags),
|
||||
DEF_CMD("-ifdisabled", -ND6_IFF_IFDISABLED, setnd6flags),
|
||||
DEF_CMD("nud", ND6_IFF_PERFORMNUD, setnd6flags),
|
||||
DEF_CMD("-nud", -ND6_IFF_PERFORMNUD, setnd6flags),
|
||||
DEF_CMD("auto_linklocal",ND6_IFF_AUTO_LINKLOCAL,setnd6flags),
|
||||
DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags),
|
||||
DEF_CMD("no_prefer_iface",ND6_IFF_NO_PREFER_IFACE,setnd6flags),
|
||||
DEF_CMD("-no_prefer_iface",-ND6_IFF_NO_PREFER_IFACE,setnd6flags),
|
||||
DEF_CMD("no_dad", ND6_IFF_NO_DAD, setnd6flags),
|
||||
DEF_CMD("-no_dad", -ND6_IFF_NO_DAD, setnd6flags),
|
||||
DEF_CMD_ARG("pltime", setip6pltime),
|
||||
DEF_CMD_ARG("vltime", setip6vltime),
|
||||
DEF_CMD("eui64", 0, setip6eui64),
|
||||
};
|
||||
|
||||
static struct afswtch af_inet6 = {
|
||||
.af_name = "inet6",
|
||||
.af_af = AF_INET6,
|
||||
.af_status = in6_status,
|
||||
.af_getaddr = in6_getaddr,
|
||||
.af_getprefix = in6_getprefix,
|
||||
.af_other_status = nd6_status,
|
||||
.af_postproc = in6_postproc,
|
||||
.af_status_tunnel = in6_status_tunnel,
|
||||
.af_settunnel = in6_set_tunnel,
|
||||
.af_difaddr = SIOCDIFADDR_IN6,
|
||||
.af_aifaddr = SIOCAIFADDR_IN6,
|
||||
.af_ridreq = &in6_addreq,
|
||||
.af_addreq = &in6_addreq,
|
||||
};
|
||||
|
||||
static void
|
||||
in6_Lopt_cb(const char *optarg __unused)
|
||||
{
|
||||
ip6lifetime++; /* print IPv6 address lifetime */
|
||||
}
|
||||
static struct option in6_Lopt = {
|
||||
.opt = "L",
|
||||
.opt_usage = "[-L]",
|
||||
.cb = in6_Lopt_cb
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
inet6_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
#ifndef RESCUE
|
||||
if (!feature_present("inet6"))
|
||||
return;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < nitems(inet6_cmds); i++)
|
||||
cmd_register(&inet6_cmds[i]);
|
||||
af_register(&af_inet6);
|
||||
opt_register(&in6_Lopt);
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/ethernet.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static struct ifreq link_ridreq;
|
||||
|
||||
extern char *f_ether;
|
||||
|
||||
static void
|
||||
link_status(int s __unused, const struct ifaddrs *ifa)
|
||||
{
|
||||
/* XXX no const 'cuz LLADDR is defined wrong */
|
||||
struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr;
|
||||
char *ether_format, *format_char;
|
||||
|
||||
if (sdl != NULL && sdl->sdl_alen > 0) {
|
||||
if ((sdl->sdl_type == IFT_ETHER ||
|
||||
sdl->sdl_type == IFT_L2VLAN ||
|
||||
sdl->sdl_type == IFT_BRIDGE) &&
|
||||
sdl->sdl_alen == ETHER_ADDR_LEN) {
|
||||
ether_format = ether_ntoa((struct ether_addr *)LLADDR(sdl));
|
||||
if (f_ether != NULL && strcmp(f_ether, "dash") == 0) {
|
||||
for (format_char = strchr(ether_format, ':');
|
||||
format_char != NULL;
|
||||
format_char = strchr(ether_format, ':'))
|
||||
*format_char = '-';
|
||||
}
|
||||
printf("\tether %s\n", ether_format);
|
||||
} else {
|
||||
int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
|
||||
|
||||
printf("\tlladdr %s\n", link_ntoa(sdl) + n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
link_getaddr(const char *addr, int which)
|
||||
{
|
||||
char *temp;
|
||||
struct sockaddr_dl sdl;
|
||||
struct sockaddr *sa = &link_ridreq.ifr_addr;
|
||||
|
||||
if (which != ADDR)
|
||||
errx(1, "can't set link-level netmask or broadcast");
|
||||
if ((temp = malloc(strlen(addr) + 2)) == NULL)
|
||||
errx(1, "malloc failed");
|
||||
temp[0] = ':';
|
||||
strcpy(temp + 1, addr);
|
||||
sdl.sdl_len = sizeof(sdl);
|
||||
link_addr(temp, &sdl);
|
||||
free(temp);
|
||||
if (sdl.sdl_alen > sizeof(sa->sa_data))
|
||||
errx(1, "malformed link-level address");
|
||||
sa->sa_family = AF_LINK;
|
||||
sa->sa_len = sdl.sdl_alen;
|
||||
bcopy(LLADDR(&sdl), sa->sa_data, sdl.sdl_alen);
|
||||
}
|
||||
|
||||
static struct afswtch af_link = {
|
||||
.af_name = "link",
|
||||
.af_af = AF_LINK,
|
||||
.af_status = link_status,
|
||||
.af_getaddr = link_getaddr,
|
||||
.af_aifaddr = SIOCSIFLLADDR,
|
||||
.af_addreq = &link_ridreq,
|
||||
};
|
||||
static struct afswtch af_ether = {
|
||||
.af_name = "ether",
|
||||
.af_af = AF_LINK,
|
||||
.af_status = link_status,
|
||||
.af_getaddr = link_getaddr,
|
||||
.af_aifaddr = SIOCSIFLLADDR,
|
||||
.af_addreq = &link_ridreq,
|
||||
};
|
||||
static struct afswtch af_lladdr = {
|
||||
.af_name = "lladdr",
|
||||
.af_af = AF_LINK,
|
||||
.af_status = link_status,
|
||||
.af_getaddr = link_getaddr,
|
||||
.af_aifaddr = SIOCSIFLLADDR,
|
||||
.af_addreq = &link_ridreq,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
link_ctor(void)
|
||||
{
|
||||
af_register(&af_link);
|
||||
af_register(&af_ether);
|
||||
af_register(&af_lladdr);
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Hiroki Sato. 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 REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <netinet6/nd6.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
#define MAX_SYSCTL_TRY 5
|
||||
#define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \
|
||||
"\004IFDISABLED\005DONT_SET_IFROUTE\006AUTO_LINKLOCAL" \
|
||||
"\007NO_RADR\010NO_PREFER_IFACE\011IGNORELOOP\012NO_DAD" \
|
||||
"\020DEFAULTIF"
|
||||
|
||||
static int isnd6defif(int);
|
||||
void setnd6flags(const char *, int, int, const struct afswtch *);
|
||||
void setnd6defif(const char *, int, int, const struct afswtch *);
|
||||
void nd6_status(int);
|
||||
|
||||
void
|
||||
setnd6flags(const char *dummyaddr __unused,
|
||||
int d, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct in6_ndireq nd;
|
||||
int error;
|
||||
|
||||
memset(&nd, 0, sizeof(nd));
|
||||
strlcpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
|
||||
error = ioctl(s, SIOCGIFINFO_IN6, &nd);
|
||||
if (error) {
|
||||
warn("ioctl(SIOCGIFINFO_IN6)");
|
||||
return;
|
||||
}
|
||||
if (d < 0)
|
||||
nd.ndi.flags &= ~(-d);
|
||||
else
|
||||
nd.ndi.flags |= d;
|
||||
error = ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd);
|
||||
if (error)
|
||||
warn("ioctl(SIOCSIFINFO_IN6)");
|
||||
}
|
||||
|
||||
void
|
||||
setnd6defif(const char *dummyaddr __unused,
|
||||
int d, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct in6_ndifreq ndifreq;
|
||||
int ifindex;
|
||||
int error;
|
||||
|
||||
memset(&ndifreq, 0, sizeof(ndifreq));
|
||||
strlcpy(ndifreq.ifname, ifr.ifr_name, sizeof(ndifreq.ifname));
|
||||
|
||||
if (d < 0) {
|
||||
if (isnd6defif(s)) {
|
||||
/* ifindex = 0 means to remove default if */
|
||||
ifindex = 0;
|
||||
} else
|
||||
return;
|
||||
} else if ((ifindex = if_nametoindex(ndifreq.ifname)) == 0) {
|
||||
warn("if_nametoindex(%s)", ndifreq.ifname);
|
||||
return;
|
||||
}
|
||||
|
||||
ndifreq.ifindex = ifindex;
|
||||
error = ioctl(s, SIOCSDEFIFACE_IN6, (caddr_t)&ndifreq);
|
||||
if (error)
|
||||
warn("ioctl(SIOCSDEFIFACE_IN6)");
|
||||
}
|
||||
|
||||
static int
|
||||
isnd6defif(int s)
|
||||
{
|
||||
struct in6_ndifreq ndifreq;
|
||||
unsigned int ifindex;
|
||||
int error;
|
||||
|
||||
memset(&ndifreq, 0, sizeof(ndifreq));
|
||||
strlcpy(ndifreq.ifname, ifr.ifr_name, sizeof(ndifreq.ifname));
|
||||
|
||||
ifindex = if_nametoindex(ndifreq.ifname);
|
||||
error = ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq);
|
||||
if (error) {
|
||||
warn("ioctl(SIOCGDEFIFACE_IN6)");
|
||||
return (error);
|
||||
}
|
||||
return (ndifreq.ifindex == ifindex);
|
||||
}
|
||||
|
||||
void
|
||||
nd6_status(int s)
|
||||
{
|
||||
struct in6_ndireq nd;
|
||||
int s6;
|
||||
int error;
|
||||
int isdefif;
|
||||
|
||||
memset(&nd, 0, sizeof(nd));
|
||||
strlcpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
|
||||
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
if (errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
|
||||
warn("socket(AF_INET6, SOCK_DGRAM)");
|
||||
return;
|
||||
}
|
||||
error = ioctl(s6, SIOCGIFINFO_IN6, &nd);
|
||||
if (error) {
|
||||
if (errno != EPFNOSUPPORT)
|
||||
warn("ioctl(SIOCGIFINFO_IN6)");
|
||||
close(s6);
|
||||
return;
|
||||
}
|
||||
isdefif = isnd6defif(s6);
|
||||
close(s6);
|
||||
if (nd.ndi.flags == 0 && !isdefif)
|
||||
return;
|
||||
printb("\tnd6 options",
|
||||
(unsigned int)(nd.ndi.flags | (isdefif << 15)), ND6BITS);
|
||||
putchar('\n');
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
/* $FreeBSD$ */
|
||||
/* from $OpenBSD: ifconfig.c,v 1.82 2003/10/19 05:43:35 mcbride Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Michael Shalayeff. All rights reserved.
|
||||
* Copyright (c) 2003 Ryan McBride. 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 OR HIS RELATIVES 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 MIND, 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/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <netinet/ip_carp.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static const char *carp_states[] = { CARP_STATES };
|
||||
|
||||
static void carp_status(int s);
|
||||
static void setcarp_vhid(const char *, int, int, const struct afswtch *rafp);
|
||||
static void setcarp_callback(int, void *);
|
||||
static void setcarp_advbase(const char *,int, int, const struct afswtch *rafp);
|
||||
static void setcarp_advskew(const char *, int, int, const struct afswtch *rafp);
|
||||
static void setcarp_passwd(const char *, int, int, const struct afswtch *rafp);
|
||||
|
||||
static int carpr_vhid = -1;
|
||||
static int carpr_advskew = -1;
|
||||
static int carpr_advbase = -1;
|
||||
static int carpr_state = -1;
|
||||
static unsigned char const *carpr_key;
|
||||
|
||||
static void
|
||||
carp_status(int s)
|
||||
{
|
||||
struct carpreq carpr[CARP_MAXVHID];
|
||||
int i;
|
||||
|
||||
bzero(carpr, sizeof(struct carpreq) * CARP_MAXVHID);
|
||||
carpr[0].carpr_count = CARP_MAXVHID;
|
||||
ifr.ifr_data = (caddr_t)&carpr;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCGVH, (caddr_t)&ifr) == -1)
|
||||
#else
|
||||
size_t offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
size_t clen = sizeof(struct carpreq) * CARP_MAXVHID;
|
||||
if (ioctl_va(s, SIOCGVH, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) == -1)
|
||||
#endif
|
||||
return;
|
||||
|
||||
for (i = 0; i < carpr[0].carpr_count; i++) {
|
||||
printf("\tcarp: %s vhid %d advbase %d advskew %d",
|
||||
carp_states[carpr[i].carpr_state], carpr[i].carpr_vhid,
|
||||
carpr[i].carpr_advbase, carpr[i].carpr_advskew);
|
||||
if (printkeys && carpr[i].carpr_key[0] != '\0')
|
||||
printf(" key \"%s\"\n", carpr[i].carpr_key);
|
||||
else
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setcarp_vhid(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
carpr_vhid = atoi(val);
|
||||
|
||||
if (carpr_vhid <= 0 || carpr_vhid > CARP_MAXVHID)
|
||||
errx(1, "vhid must be greater than 0 and less than %u",
|
||||
CARP_MAXVHID);
|
||||
|
||||
switch (afp->af_af) {
|
||||
#ifdef INET
|
||||
case AF_INET:
|
||||
{
|
||||
struct in_aliasreq *ifra;
|
||||
|
||||
ifra = (struct in_aliasreq *)afp->af_addreq;
|
||||
ifra->ifra_vhid = carpr_vhid;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
{
|
||||
struct in6_aliasreq *ifra;
|
||||
|
||||
ifra = (struct in6_aliasreq *)afp->af_addreq;
|
||||
ifra->ifra_vhid = carpr_vhid;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
errx(1, "%s doesn't support carp(4)", afp->af_name);
|
||||
}
|
||||
|
||||
callback_register(setcarp_callback, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
setcarp_callback(int s, void *arg __unused)
|
||||
{
|
||||
struct carpreq carpr;
|
||||
|
||||
bzero(&carpr, sizeof(struct carpreq));
|
||||
carpr.carpr_vhid = carpr_vhid;
|
||||
carpr.carpr_count = 1;
|
||||
ifr.ifr_data = (caddr_t)&carpr;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCGVH, (caddr_t)&ifr) == -1 && errno != ENOENT)
|
||||
#else
|
||||
size_t offset, clen;
|
||||
offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
clen = sizeof(carpr);
|
||||
if (ioctl_va(s, SIOCGVH, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) == -1
|
||||
&& errno != ENOENT)
|
||||
#endif
|
||||
err(1, "SIOCGVH");
|
||||
|
||||
if (carpr_key != NULL)
|
||||
/* XXX Should hash the password into the key here? */
|
||||
#ifndef FSTACK
|
||||
strlcpy(carpr.carpr_key, carpr_key, CARP_KEY_LEN);
|
||||
#else
|
||||
strlcpy((char *)carpr.carpr_key, (const char *)carpr_key, CARP_KEY_LEN);
|
||||
#endif
|
||||
if (carpr_advskew > -1)
|
||||
carpr.carpr_advskew = carpr_advskew;
|
||||
if (carpr_advbase > -1)
|
||||
carpr.carpr_advbase = carpr_advbase;
|
||||
if (carpr_state > -1)
|
||||
carpr.carpr_state = carpr_state;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCSVH, (caddr_t)&ifr) == -1)
|
||||
#else
|
||||
if (ioctl_va(s, SIOCSVH, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) == -1)
|
||||
#endif
|
||||
err(1, "SIOCSVH");
|
||||
}
|
||||
|
||||
static void
|
||||
setcarp_passwd(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
if (carpr_vhid == -1)
|
||||
errx(1, "passwd requires vhid");
|
||||
|
||||
#ifndef FSTACK
|
||||
carpr_key = val;
|
||||
#else
|
||||
carpr_key = (const unsigned char *)val;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
setcarp_advskew(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
if (carpr_vhid == -1)
|
||||
errx(1, "advskew requires vhid");
|
||||
|
||||
carpr_advskew = atoi(val);
|
||||
}
|
||||
|
||||
static void
|
||||
setcarp_advbase(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
if (carpr_vhid == -1)
|
||||
errx(1, "advbase requires vhid");
|
||||
|
||||
carpr_advbase = atoi(val);
|
||||
}
|
||||
|
||||
static void
|
||||
setcarp_state(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (carpr_vhid == -1)
|
||||
errx(1, "state requires vhid");
|
||||
|
||||
for (i = 0; i <= CARP_MAXSTATE; i++)
|
||||
if (strcasecmp(carp_states[i], val) == 0) {
|
||||
carpr_state = i;
|
||||
return;
|
||||
}
|
||||
|
||||
errx(1, "unknown state");
|
||||
}
|
||||
|
||||
static struct cmd carp_cmds[] = {
|
||||
DEF_CMD_ARG("advbase", setcarp_advbase),
|
||||
DEF_CMD_ARG("advskew", setcarp_advskew),
|
||||
DEF_CMD_ARG("pass", setcarp_passwd),
|
||||
DEF_CMD_ARG("vhid", setcarp_vhid),
|
||||
DEF_CMD_ARG("state", setcarp_state),
|
||||
};
|
||||
static struct afswtch af_carp = {
|
||||
.af_name = "af_carp",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = carp_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
carp_ctor(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems(carp_cmds); i++)
|
||||
cmd_register(&carp_cmds[i]);
|
||||
af_register(&af_carp);
|
||||
}
|
|
@ -0,0 +1,760 @@
|
|||
/*-
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_bridgevar.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
#define PV2ID(pv, epri, eaddr) do { \
|
||||
epri = pv >> 48; \
|
||||
eaddr[0] = pv >> 40; \
|
||||
eaddr[1] = pv >> 32; \
|
||||
eaddr[2] = pv >> 24; \
|
||||
eaddr[3] = pv >> 16; \
|
||||
eaddr[4] = pv >> 8; \
|
||||
eaddr[5] = pv >> 0; \
|
||||
} while (0)
|
||||
|
||||
static const char *stpstates[] = {
|
||||
"disabled",
|
||||
"listening",
|
||||
"learning",
|
||||
"forwarding",
|
||||
"blocking",
|
||||
"discarding"
|
||||
};
|
||||
static const char *stpproto[] = {
|
||||
"stp",
|
||||
"-",
|
||||
"rstp"
|
||||
};
|
||||
static const char *stproles[] = {
|
||||
"disabled",
|
||||
"root",
|
||||
"designated",
|
||||
"alternate",
|
||||
"backup"
|
||||
};
|
||||
|
||||
static int
|
||||
get_val(const char *cp, u_long *valp)
|
||||
{
|
||||
char *endptr;
|
||||
u_long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoul(cp, &endptr, 0);
|
||||
if (cp[0] == '\0' || endptr[0] != '\0' || errno == ERANGE)
|
||||
return (-1);
|
||||
|
||||
*valp = val;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
do_cmd(int sock, u_long op, void *arg, size_t argsize, int set)
|
||||
{
|
||||
struct ifdrv ifd;
|
||||
|
||||
memset(&ifd, 0, sizeof(ifd));
|
||||
|
||||
strlcpy(ifd.ifd_name, ifr.ifr_name, sizeof(ifd.ifd_name));
|
||||
ifd.ifd_cmd = op;
|
||||
ifd.ifd_len = argsize;
|
||||
ifd.ifd_data = arg;
|
||||
|
||||
#ifndef FSTACK
|
||||
return (ioctl(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd));
|
||||
#else
|
||||
size_t offset = (char *)&(ifd.ifd_data) - (char *)&(ifd);
|
||||
return (ioctl_va(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd,
|
||||
3, offset, arg, argsize));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
do_bridgeflag(int sock, const char *ifs, int flag, int set)
|
||||
{
|
||||
struct ifbreq req;
|
||||
|
||||
strlcpy(req.ifbr_ifsname, ifs, sizeof(req.ifbr_ifsname));
|
||||
|
||||
if (do_cmd(sock, BRDGGIFFLGS, &req, sizeof(req), 0) < 0)
|
||||
err(1, "unable to get bridge flags");
|
||||
|
||||
if (set)
|
||||
req.ifbr_ifsflags |= flag;
|
||||
else
|
||||
req.ifbr_ifsflags &= ~flag;
|
||||
|
||||
if (do_cmd(sock, BRDGSIFFLGS, &req, sizeof(req), 1) < 0)
|
||||
err(1, "unable to set bridge flags");
|
||||
}
|
||||
|
||||
static void
|
||||
bridge_interfaces(int s, const char *prefix)
|
||||
{
|
||||
struct ifbifconf bifc;
|
||||
struct ifbreq *req;
|
||||
char *inbuf = NULL, *ninbuf;
|
||||
char *p, *pad;
|
||||
int i, len = 8192;
|
||||
|
||||
pad = strdup(prefix);
|
||||
if (pad == NULL)
|
||||
err(1, "strdup");
|
||||
/* replace the prefix with whitespace */
|
||||
for (p = pad; *p != '\0'; p++) {
|
||||
if(isprint(*p))
|
||||
*p = ' ';
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
ninbuf = realloc(inbuf, len);
|
||||
if (ninbuf == NULL)
|
||||
err(1, "unable to allocate interface buffer");
|
||||
bifc.ifbic_len = len;
|
||||
bifc.ifbic_buf = inbuf = ninbuf;
|
||||
if (do_cmd(s, BRDGGIFS, &bifc, sizeof(bifc), 0) < 0)
|
||||
err(1, "unable to get interface list");
|
||||
if ((bifc.ifbic_len + sizeof(*req)) < len)
|
||||
break;
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
for (i = 0; i < bifc.ifbic_len / sizeof(*req); i++) {
|
||||
req = bifc.ifbic_req + i;
|
||||
printf("%s%s ", prefix, req->ifbr_ifsname);
|
||||
printb("flags", req->ifbr_ifsflags, IFBIFBITS);
|
||||
printf("\n");
|
||||
|
||||
printf("%s", pad);
|
||||
printf("ifmaxaddr %u", req->ifbr_addrmax);
|
||||
printf(" port %u priority %u", req->ifbr_portno,
|
||||
req->ifbr_priority);
|
||||
printf(" path cost %u", req->ifbr_path_cost);
|
||||
|
||||
if (req->ifbr_ifsflags & IFBIF_STP) {
|
||||
if (req->ifbr_proto < nitems(stpproto))
|
||||
printf(" proto %s", stpproto[req->ifbr_proto]);
|
||||
else
|
||||
printf(" <unknown proto %d>",
|
||||
req->ifbr_proto);
|
||||
|
||||
printf("\n%s", pad);
|
||||
if (req->ifbr_role < nitems(stproles))
|
||||
printf("role %s", stproles[req->ifbr_role]);
|
||||
else
|
||||
printf("<unknown role %d>",
|
||||
req->ifbr_role);
|
||||
if (req->ifbr_state < nitems(stpstates))
|
||||
printf(" state %s", stpstates[req->ifbr_state]);
|
||||
else
|
||||
printf(" <unknown state %d>",
|
||||
req->ifbr_state);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
free(inbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
bridge_addresses(int s, const char *prefix)
|
||||
{
|
||||
struct ifbaconf ifbac;
|
||||
struct ifbareq *ifba;
|
||||
char *inbuf = NULL, *ninbuf;
|
||||
int i, len = 8192;
|
||||
struct ether_addr ea;
|
||||
|
||||
for (;;) {
|
||||
ninbuf = realloc(inbuf, len);
|
||||
if (ninbuf == NULL)
|
||||
err(1, "unable to allocate address buffer");
|
||||
ifbac.ifbac_len = len;
|
||||
ifbac.ifbac_buf = inbuf = ninbuf;
|
||||
if (do_cmd(s, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0)
|
||||
err(1, "unable to get address cache");
|
||||
if ((ifbac.ifbac_len + sizeof(*ifba)) < len)
|
||||
break;
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) {
|
||||
ifba = ifbac.ifbac_req + i;
|
||||
memcpy(ea.octet, ifba->ifba_dst,
|
||||
sizeof(ea.octet));
|
||||
printf("%s%s Vlan%d %s %lu ", prefix, ether_ntoa(&ea),
|
||||
ifba->ifba_vlan, ifba->ifba_ifsname, ifba->ifba_expire);
|
||||
printb("flags", ifba->ifba_flags, IFBAFBITS);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
free(inbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
bridge_status(int s)
|
||||
{
|
||||
struct ifbropreq ifbp;
|
||||
struct ifbrparam param;
|
||||
u_int16_t pri;
|
||||
u_int8_t ht, fd, ma, hc, pro;
|
||||
u_int8_t lladdr[ETHER_ADDR_LEN];
|
||||
u_int16_t bprio;
|
||||
u_int32_t csize, ctime;
|
||||
|
||||
if (do_cmd(s, BRDGGCACHE, ¶m, sizeof(param), 0) < 0)
|
||||
return;
|
||||
csize = param.ifbrp_csize;
|
||||
if (do_cmd(s, BRDGGTO, ¶m, sizeof(param), 0) < 0)
|
||||
return;
|
||||
ctime = param.ifbrp_ctime;
|
||||
if (do_cmd(s, BRDGPARAM, &ifbp, sizeof(ifbp), 0) < 0)
|
||||
return;
|
||||
pri = ifbp.ifbop_priority;
|
||||
pro = ifbp.ifbop_protocol;
|
||||
ht = ifbp.ifbop_hellotime;
|
||||
fd = ifbp.ifbop_fwddelay;
|
||||
hc = ifbp.ifbop_holdcount;
|
||||
ma = ifbp.ifbop_maxage;
|
||||
|
||||
PV2ID(ifbp.ifbop_bridgeid, bprio, lladdr);
|
||||
printf("\tid %s priority %u hellotime %u fwddelay %u\n",
|
||||
ether_ntoa((struct ether_addr *)lladdr), pri, ht, fd);
|
||||
printf("\tmaxage %u holdcnt %u proto %s maxaddr %u timeout %u\n",
|
||||
ma, hc, stpproto[pro], csize, ctime);
|
||||
|
||||
PV2ID(ifbp.ifbop_designated_root, bprio, lladdr);
|
||||
printf("\troot id %s priority %d ifcost %u port %u\n",
|
||||
ether_ntoa((struct ether_addr *)lladdr), bprio,
|
||||
ifbp.ifbop_root_path_cost, ifbp.ifbop_root_port & 0xfff);
|
||||
|
||||
bridge_interfaces(s, "\tmember: ");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_add(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
|
||||
if (do_cmd(s, BRDGADD, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGADD %s", val);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_delete(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
|
||||
if (do_cmd(s, BRDGDEL, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGDEL %s", val);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_discover(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_DISCOVER, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_discover(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_DISCOVER, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_learn(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_LEARNING, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_learn(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_LEARNING, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_sticky(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_STICKY, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_sticky(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_STICKY, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_span(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
|
||||
if (do_cmd(s, BRDGADDS, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGADDS %s", val);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_span(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname));
|
||||
if (do_cmd(s, BRDGDELS, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGDELS %s", val);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_stp(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_STP, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_stp(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_STP, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_edge(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_edge(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_EDGE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_autoedge(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_AUTOEDGE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_ptp(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_PTP, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_ptp(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_PTP, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_autoptp(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
do_bridgeflag(s, val, IFBIF_BSTP_AUTOPTP, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_flush(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.ifbr_ifsflags = IFBF_FLUSHDYN;
|
||||
if (do_cmd(s, BRDGFLUSH, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGFLUSH");
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_flushall(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.ifbr_ifsflags = IFBF_FLUSHALL;
|
||||
if (do_cmd(s, BRDGFLUSH, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGFLUSH");
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_static(const char *val, const char *mac, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct ifbareq req;
|
||||
struct ether_addr *ea;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
strlcpy(req.ifba_ifsname, val, sizeof(req.ifba_ifsname));
|
||||
|
||||
ea = ether_aton(mac);
|
||||
if (ea == NULL)
|
||||
errx(1, "%s: invalid address: %s", val, mac);
|
||||
|
||||
memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
|
||||
req.ifba_flags = IFBAF_STATIC;
|
||||
req.ifba_vlan = 1; /* XXX allow user to specify */
|
||||
|
||||
if (do_cmd(s, BRDGSADDR, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGSADDR %s", val);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_deladdr(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbareq req;
|
||||
struct ether_addr *ea;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
ea = ether_aton(val);
|
||||
if (ea == NULL)
|
||||
errx(1, "invalid address: %s", val);
|
||||
|
||||
memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
|
||||
|
||||
if (do_cmd(s, BRDGDADDR, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGDADDR %s", val);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_addr(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
bridge_addresses(s, "");
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_maxaddr(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
param.ifbrp_csize = val & 0xffffffff;
|
||||
|
||||
if (do_cmd(s, BRDGSCACHE, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSCACHE %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_hellotime(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
param.ifbrp_hellotime = val & 0xff;
|
||||
|
||||
if (do_cmd(s, BRDGSHT, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSHT %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_fwddelay(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
param.ifbrp_fwddelay = val & 0xff;
|
||||
|
||||
if (do_cmd(s, BRDGSFD, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSFD %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_maxage(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
param.ifbrp_maxage = val & 0xff;
|
||||
|
||||
if (do_cmd(s, BRDGSMA, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSMA %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_priority(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xffff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
param.ifbrp_prio = val & 0xffff;
|
||||
|
||||
if (do_cmd(s, BRDGSPRI, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSPRI %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_protocol(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
|
||||
if (strcasecmp(arg, "stp") == 0) {
|
||||
param.ifbrp_proto = 0;
|
||||
} else if (strcasecmp(arg, "rstp") == 0) {
|
||||
param.ifbrp_proto = 2;
|
||||
} else {
|
||||
errx(1, "unknown stp protocol");
|
||||
}
|
||||
|
||||
if (do_cmd(s, BRDGSPROTO, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSPROTO %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_holdcount(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
param.ifbrp_txhc = val & 0xff;
|
||||
|
||||
if (do_cmd(s, BRDGSTXHC, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSTXHC %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_ifpriority(const char *ifn, const char *pri, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
u_long val;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
if (get_val(pri, &val) < 0 || (val & ~0xff) != 0)
|
||||
errx(1, "invalid value: %s", pri);
|
||||
|
||||
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
|
||||
req.ifbr_priority = val & 0xff;
|
||||
|
||||
if (do_cmd(s, BRDGSIFPRIO, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGSIFPRIO %s", pri);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_ifpathcost(const char *ifn, const char *cost, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
u_long val;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
if (get_val(cost, &val) < 0)
|
||||
errx(1, "invalid value: %s", cost);
|
||||
|
||||
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
|
||||
req.ifbr_path_cost = val;
|
||||
|
||||
if (do_cmd(s, BRDGSIFCOST, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGSIFCOST %s", cost);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_ifmaxaddr(const char *ifn, const char *arg, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
struct ifbreq req;
|
||||
u_long val;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
|
||||
req.ifbr_addrmax = val & 0xffffffff;
|
||||
|
||||
if (do_cmd(s, BRDGSIFAMAX, &req, sizeof(req), 1) < 0)
|
||||
err(1, "BRDGSIFAMAX %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_timeout(const char *arg, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifbrparam param;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0)
|
||||
errx(1, "invalid value: %s", arg);
|
||||
|
||||
param.ifbrp_ctime = val & 0xffffffff;
|
||||
|
||||
if (do_cmd(s, BRDGSTO, ¶m, sizeof(param), 1) < 0)
|
||||
err(1, "BRDGSTO %s", arg);
|
||||
}
|
||||
|
||||
static void
|
||||
setbridge_private(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_PRIVATE, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetbridge_private(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
do_bridgeflag(s, val, IFBIF_PRIVATE, 0);
|
||||
}
|
||||
|
||||
static struct cmd bridge_cmds[] = {
|
||||
DEF_CMD_ARG("addm", setbridge_add),
|
||||
DEF_CMD_ARG("deletem", setbridge_delete),
|
||||
DEF_CMD_ARG("discover", setbridge_discover),
|
||||
DEF_CMD_ARG("-discover", unsetbridge_discover),
|
||||
DEF_CMD_ARG("learn", setbridge_learn),
|
||||
DEF_CMD_ARG("-learn", unsetbridge_learn),
|
||||
DEF_CMD_ARG("sticky", setbridge_sticky),
|
||||
DEF_CMD_ARG("-sticky", unsetbridge_sticky),
|
||||
DEF_CMD_ARG("span", setbridge_span),
|
||||
DEF_CMD_ARG("-span", unsetbridge_span),
|
||||
DEF_CMD_ARG("stp", setbridge_stp),
|
||||
DEF_CMD_ARG("-stp", unsetbridge_stp),
|
||||
DEF_CMD_ARG("edge", setbridge_edge),
|
||||
DEF_CMD_ARG("-edge", unsetbridge_edge),
|
||||
DEF_CMD_ARG("autoedge", setbridge_autoedge),
|
||||
DEF_CMD_ARG("-autoedge", unsetbridge_autoedge),
|
||||
DEF_CMD_ARG("ptp", setbridge_ptp),
|
||||
DEF_CMD_ARG("-ptp", unsetbridge_ptp),
|
||||
DEF_CMD_ARG("autoptp", setbridge_autoptp),
|
||||
DEF_CMD_ARG("-autoptp", unsetbridge_autoptp),
|
||||
DEF_CMD("flush", 0, setbridge_flush),
|
||||
DEF_CMD("flushall", 0, setbridge_flushall),
|
||||
DEF_CMD_ARG2("static", setbridge_static),
|
||||
DEF_CMD_ARG("deladdr", setbridge_deladdr),
|
||||
DEF_CMD("addr", 1, setbridge_addr),
|
||||
DEF_CMD_ARG("maxaddr", setbridge_maxaddr),
|
||||
DEF_CMD_ARG("hellotime", setbridge_hellotime),
|
||||
DEF_CMD_ARG("fwddelay", setbridge_fwddelay),
|
||||
DEF_CMD_ARG("maxage", setbridge_maxage),
|
||||
DEF_CMD_ARG("priority", setbridge_priority),
|
||||
DEF_CMD_ARG("proto", setbridge_protocol),
|
||||
DEF_CMD_ARG("holdcnt", setbridge_holdcount),
|
||||
DEF_CMD_ARG2("ifpriority", setbridge_ifpriority),
|
||||
DEF_CMD_ARG2("ifpathcost", setbridge_ifpathcost),
|
||||
DEF_CMD_ARG2("ifmaxaddr", setbridge_ifmaxaddr),
|
||||
DEF_CMD_ARG("timeout", setbridge_timeout),
|
||||
DEF_CMD_ARG("private", setbridge_private),
|
||||
DEF_CMD_ARG("-private", unsetbridge_private),
|
||||
};
|
||||
static struct afswtch af_bridge = {
|
||||
.af_name = "af_bridge",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = bridge_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
bridge_ctor(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems(bridge_cmds); i++)
|
||||
cmd_register(&bridge_cmds[i]);
|
||||
af_register(&af_bridge);
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static void
|
||||
list_cloners(void)
|
||||
{
|
||||
struct if_clonereq ifcr;
|
||||
char *cp, *buf;
|
||||
int idx;
|
||||
int s;
|
||||
|
||||
s = socket(AF_LOCAL, SOCK_DGRAM, 0);
|
||||
if (s == -1)
|
||||
err(1, "socket(AF_LOCAL,SOCK_DGRAM)");
|
||||
|
||||
memset(&ifcr, 0, sizeof(ifcr));
|
||||
|
||||
if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
|
||||
err(1, "SIOCIFGCLONERS for count");
|
||||
|
||||
buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
|
||||
if (buf == NULL)
|
||||
err(1, "unable to allocate cloner name buffer");
|
||||
|
||||
ifcr.ifcr_count = ifcr.ifcr_total;
|
||||
ifcr.ifcr_buffer = buf;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
|
||||
#else
|
||||
size_t offset = (char *)&(ifcr.ifcr_buffer) - (char *)&(ifcr);
|
||||
size_t clen = ifcr.ifcr_total * IFNAMSIZ;
|
||||
if (ioctl_va(s, SIOCIFGCLONERS, &ifcr, 3, offset, buf, clen) < 0)
|
||||
#endif
|
||||
err(1, "SIOCIFGCLONERS for names");
|
||||
|
||||
/*
|
||||
* In case some disappeared in the mean time, clamp it down.
|
||||
*/
|
||||
if (ifcr.ifcr_count > ifcr.ifcr_total)
|
||||
ifcr.ifcr_count = ifcr.ifcr_total;
|
||||
|
||||
for (cp = buf, idx = 0; idx < ifcr.ifcr_count; idx++, cp += IFNAMSIZ) {
|
||||
if (idx > 0)
|
||||
putchar(' ');
|
||||
printf("%s", cp);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
free(buf);
|
||||
}
|
||||
|
||||
struct clone_defcb {
|
||||
char ifprefix[IFNAMSIZ];
|
||||
clone_callback_func *clone_cb;
|
||||
SLIST_ENTRY(clone_defcb) next;
|
||||
};
|
||||
|
||||
static SLIST_HEAD(, clone_defcb) clone_defcbh =
|
||||
SLIST_HEAD_INITIALIZER(clone_defcbh);
|
||||
|
||||
void
|
||||
clone_setdefcallback(const char *ifprefix, clone_callback_func *p)
|
||||
{
|
||||
struct clone_defcb *dcp;
|
||||
|
||||
dcp = malloc(sizeof(*dcp));
|
||||
strlcpy(dcp->ifprefix, ifprefix, IFNAMSIZ-1);
|
||||
dcp->clone_cb = p;
|
||||
SLIST_INSERT_HEAD(&clone_defcbh, dcp, next);
|
||||
}
|
||||
|
||||
/*
|
||||
* Do the actual clone operation. Any parameters must have been
|
||||
* setup by now. If a callback has been setup to do the work
|
||||
* then defer to it; otherwise do a simple create operation with
|
||||
* no parameters.
|
||||
*/
|
||||
static void
|
||||
ifclonecreate(int s, void *arg)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
struct clone_defcb *dcp;
|
||||
clone_callback_func *clone_cb = NULL;
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
(void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
if (clone_cb == NULL) {
|
||||
/* Try to find a default callback */
|
||||
SLIST_FOREACH(dcp, &clone_defcbh, next) {
|
||||
if (strncmp(dcp->ifprefix, ifr.ifr_name,
|
||||
strlen(dcp->ifprefix)) == 0) {
|
||||
clone_cb = dcp->clone_cb;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clone_cb == NULL) {
|
||||
/* NB: no parameters */
|
||||
if (ioctl(s, SIOCIFCREATE2, &ifr) < 0)
|
||||
err(1, "SIOCIFCREATE2");
|
||||
} else {
|
||||
clone_cb(s, &ifr);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we get a different name back than we put in, update record and
|
||||
* indicate it should be printed later.
|
||||
*/
|
||||
if (strncmp(name, ifr.ifr_name, sizeof(name)) != 0) {
|
||||
strlcpy(name, ifr.ifr_name, sizeof(name));
|
||||
printifname = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(clone_create, arg, d)
|
||||
{
|
||||
callback_register(ifclonecreate, NULL);
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(clone_destroy, arg, d)
|
||||
{
|
||||
(void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
if (ioctl(s, SIOCIFDESTROY, &ifr) < 0)
|
||||
err(1, "SIOCIFDESTROY");
|
||||
}
|
||||
|
||||
static struct cmd clone_cmds[] = {
|
||||
DEF_CLONE_CMD("create", 0, clone_create),
|
||||
DEF_CMD("destroy", 0, clone_destroy),
|
||||
DEF_CLONE_CMD("plumb", 0, clone_create),
|
||||
DEF_CMD("unplumb", 0, clone_destroy),
|
||||
};
|
||||
|
||||
static void
|
||||
clone_Copt_cb(const char *optarg __unused)
|
||||
{
|
||||
list_cloners();
|
||||
exit(0);
|
||||
}
|
||||
static struct option clone_Copt = { .opt = "C", .opt_usage = "[-C]", .cb = clone_Copt_cb };
|
||||
|
||||
static __constructor void
|
||||
clone_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(clone_cmds); i++)
|
||||
cmd_register(&clone_cmds[i]);
|
||||
opt_register(&clone_Copt);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Copyright (c) 1997 Peter Wemm.
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed for the FreeBSD Project
|
||||
* by Peter Wemm.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* so there!
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define __constructor __attribute__((constructor))
|
||||
|
||||
#ifdef FSTACK
|
||||
#include "compat.h"
|
||||
|
||||
#ifndef __unused
|
||||
#define __unused __attribute__((unused))
|
||||
#endif
|
||||
|
||||
int fake_socket(int domain, int type, int protocol);
|
||||
int fake_close(int fd);
|
||||
|
||||
#define socket(a, b, c) fake_socket((a), (b), (c))
|
||||
#define close(a) fake_close((a))
|
||||
|
||||
#ifndef nitems
|
||||
#define nitems(x) (sizeof((x)) / sizeof((x)[0]))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
struct afswtch;
|
||||
struct cmd;
|
||||
|
||||
typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp);
|
||||
typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp);
|
||||
|
||||
struct cmd {
|
||||
const char *c_name;
|
||||
int c_parameter;
|
||||
#define NEXTARG 0xffffff /* has following arg */
|
||||
#define NEXTARG2 0xfffffe /* has 2 following args */
|
||||
#define OPTARG 0xfffffd /* has optional following arg */
|
||||
union {
|
||||
c_func *c_func;
|
||||
c_func2 *c_func2;
|
||||
} c_u;
|
||||
int c_iscloneop;
|
||||
struct cmd *c_next;
|
||||
};
|
||||
void cmd_register(struct cmd *);
|
||||
|
||||
typedef void callback_func(int s, void *);
|
||||
void callback_register(callback_func *, void *);
|
||||
|
||||
/*
|
||||
* Macros for declaring command functions and initializing entries.
|
||||
*/
|
||||
#define DECL_CMD_FUNC(name, cmd, arg) \
|
||||
void name(const char *cmd, int arg, int s, const struct afswtch *afp)
|
||||
#define DECL_CMD_FUNC2(name, arg1, arg2) \
|
||||
void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp)
|
||||
|
||||
#define DEF_CMD(name, param, func) { name, param, { .c_func = func }, 0, NULL }
|
||||
#define DEF_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 0, NULL }
|
||||
#define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func }, 0, NULL }
|
||||
#define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 0, NULL }
|
||||
#define DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1, NULL }
|
||||
#define DEF_CLONE_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 1, NULL }
|
||||
#define DEF_CLONE_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func }, 1, NULL }
|
||||
|
||||
struct ifaddrs;
|
||||
struct addrinfo;
|
||||
|
||||
enum {
|
||||
RIDADDR,
|
||||
ADDR,
|
||||
MASK,
|
||||
DSTADDR,
|
||||
};
|
||||
|
||||
struct afswtch {
|
||||
const char *af_name; /* as given on cmd line, e.g. "inet" */
|
||||
short af_af; /* AF_* */
|
||||
/*
|
||||
* Status is handled one of two ways; if there is an
|
||||
* address associated with the interface then the
|
||||
* associated address family af_status method is invoked
|
||||
* with the appropriate addressin info. Otherwise, if
|
||||
* all possible info is to be displayed and af_other_status
|
||||
* is defined then it is invoked after all address status
|
||||
* is presented.
|
||||
*/
|
||||
void (*af_status)(int, const struct ifaddrs *);
|
||||
void (*af_other_status)(int);
|
||||
/* parse address method */
|
||||
void (*af_getaddr)(const char *, int);
|
||||
/* parse prefix method (IPv6) */
|
||||
void (*af_getprefix)(const char *, int);
|
||||
void (*af_postproc)(int s, const struct afswtch *);
|
||||
u_long af_difaddr; /* set dst if address ioctl */
|
||||
u_long af_aifaddr; /* set if address ioctl */
|
||||
void *af_ridreq; /* */
|
||||
void *af_addreq; /* */
|
||||
struct afswtch *af_next;
|
||||
|
||||
/* XXX doesn't fit model */
|
||||
void (*af_status_tunnel)(int);
|
||||
void (*af_settunnel)(int s, struct addrinfo *srcres,
|
||||
struct addrinfo *dstres);
|
||||
};
|
||||
void af_register(struct afswtch *);
|
||||
|
||||
struct option {
|
||||
const char *opt;
|
||||
const char *opt_usage;
|
||||
void (*cb)(const char *arg);
|
||||
struct option *next;
|
||||
};
|
||||
void opt_register(struct option *);
|
||||
|
||||
extern struct ifreq ifr;
|
||||
extern char name[IFNAMSIZ]; /* name of interface */
|
||||
extern int allmedia;
|
||||
extern int supmedia;
|
||||
extern int printkeys;
|
||||
extern int newaddr;
|
||||
extern int verbose;
|
||||
extern int printifname;
|
||||
|
||||
void setifcap(const char *, int value, int s, const struct afswtch *);
|
||||
|
||||
void Perror(const char *cmd);
|
||||
void printb(const char *s, unsigned value, const char *bits);
|
||||
|
||||
void ifmaybeload(const char *name);
|
||||
|
||||
typedef void clone_callback_func(int, struct ifreq *);
|
||||
void clone_setdefcallback(const char *, clone_callback_func *);
|
||||
|
||||
void sfp_status(int s, struct ifreq *ifr, int verbose);
|
||||
|
||||
/*
|
||||
* XXX expose this so modules that neeed to know of any pending
|
||||
* operations on ifmedia can avoid cmd line ordering confusion.
|
||||
*/
|
||||
struct ifmediareq *ifmedia_getstate(int s);
|
||||
|
||||
void print_vhid(const struct ifaddrs *, const char *);
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/*-
|
||||
* Copyright (c) 2011 Alexander V. Chernikov
|
||||
* Copyright (c) 2011 Christian S.J. Peron
|
||||
* Copyright (c) 2011 Bjoern A. Zeeb
|
||||
* 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$
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static void
|
||||
fib_status(int s)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
if (ioctl(s, SIOCGIFFIB, (caddr_t)&ifr) == 0 &&
|
||||
ifr.ifr_fib != RT_DEFAULT_FIB)
|
||||
printf("\tfib: %u\n", ifr.ifr_fib);
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
if (ioctl(s, SIOCGTUNFIB, (caddr_t)&ifr) == 0 &&
|
||||
ifr.ifr_fib != RT_DEFAULT_FIB)
|
||||
printf("\ttunnelfib: %u\n", ifr.ifr_fib);
|
||||
}
|
||||
|
||||
static void
|
||||
setiffib(const char *val, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
unsigned long fib;
|
||||
char *ep;
|
||||
|
||||
fib = strtoul(val, &ep, 0);
|
||||
if (*ep != '\0' || fib > UINT_MAX) {
|
||||
warn("fib %s not valid", val);
|
||||
return;
|
||||
}
|
||||
|
||||
strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
||||
ifr.ifr_fib = fib;
|
||||
if (ioctl(s, SIOCSIFFIB, (caddr_t)&ifr) < 0)
|
||||
warn("ioctl (SIOCSIFFIB)");
|
||||
}
|
||||
|
||||
static void
|
||||
settunfib(const char *val, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
unsigned long fib;
|
||||
char *ep;
|
||||
|
||||
fib = strtoul(val, &ep, 0);
|
||||
if (*ep != '\0' || fib > UINT_MAX) {
|
||||
warn("fib %s not valid", val);
|
||||
return;
|
||||
}
|
||||
|
||||
strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
||||
ifr.ifr_fib = fib;
|
||||
if (ioctl(s, SIOCSTUNFIB, (caddr_t)&ifr) < 0)
|
||||
warn("ioctl (SIOCSTUNFIB)");
|
||||
}
|
||||
|
||||
static struct cmd fib_cmds[] = {
|
||||
DEF_CMD_ARG("fib", setiffib),
|
||||
DEF_CMD_ARG("tunnelfib", settunfib),
|
||||
};
|
||||
|
||||
static struct afswtch af_fib = {
|
||||
.af_name = "af_fib",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = fib_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
fib_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(fib_cmds); i++)
|
||||
cmd_register(&fib_cmds[i]);
|
||||
af_register(&af_fib);
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*-
|
||||
* Copyright (c) 2009 Hiroki Sato. 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 OR HIS RELATIVES 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 MIND, 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_gif.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
#define GIFBITS "\020\2IGNORE_SOURCE"
|
||||
|
||||
static void gif_status(int);
|
||||
|
||||
static void
|
||||
gif_status(int s)
|
||||
{
|
||||
int opts;
|
||||
|
||||
ifr.ifr_data = (caddr_t)&opts;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GIFGOPTS, &ifr) == -1)
|
||||
#else
|
||||
size_t offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
size_t clen = sizeof(int);
|
||||
if (ioctl_va(s, GIFGOPTS, &ifr, 3, offset, ifr.ifr_data, clen) == -1)
|
||||
#endif
|
||||
return;
|
||||
if (opts == 0)
|
||||
return;
|
||||
printb("\toptions", opts, GIFBITS);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
setgifopts(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
int opts;
|
||||
|
||||
ifr.ifr_data = (caddr_t)&opts;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GIFGOPTS, &ifr) == -1) {
|
||||
#else
|
||||
size_t offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
size_t clen = sizeof(int);
|
||||
if (ioctl_va(s, GIFGOPTS, &ifr, 3, offset, ifr.ifr_data, clen) == -1) {
|
||||
#endif
|
||||
warn("ioctl(GIFGOPTS)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d < 0)
|
||||
opts &= ~(-d);
|
||||
else
|
||||
opts |= d;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GIFSOPTS, &ifr) == -1) {
|
||||
#else
|
||||
if (ioctl_va(s, GIFSOPTS, &ifr, 3, offset, ifr.ifr_data, clen) == -1) {
|
||||
#endif
|
||||
warn("ioctl(GIFSOPTS)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static struct cmd gif_cmds[] = {
|
||||
DEF_CMD("ignore_source", GIF_IGNORE_SOURCE, setgifopts),
|
||||
DEF_CMD("-ignore_source", -GIF_IGNORE_SOURCE, setgifopts),
|
||||
};
|
||||
|
||||
static struct afswtch af_gif = {
|
||||
.af_name = "af_gif",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = gif_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
gif_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(gif_cmds); i++)
|
||||
cmd_register(&gif_cmds[i]);
|
||||
af_register(&af_gif);
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
/*-
|
||||
* Copyright (c) 2008 Andrew Thompson. 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 OR HIS RELATIVES 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 MIND, 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/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_gre.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
#define GREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ"
|
||||
|
||||
static void gre_status(int s);
|
||||
|
||||
static void
|
||||
gre_status(int s)
|
||||
{
|
||||
uint32_t opts = 0;
|
||||
|
||||
ifr.ifr_data = (caddr_t)&opts;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GREGKEY, &ifr) == 0)
|
||||
#else
|
||||
size_t offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
size_t clen = sizeof(uint32_t);
|
||||
if (ioctl_va(s, GREGKEY, &ifr, 3, offset, ifr.ifr_data, clen) == 0)
|
||||
#endif
|
||||
if (opts != 0)
|
||||
printf("\tgrekey: 0x%x (%u)\n", opts, opts);
|
||||
opts = 0;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GREGOPTS, &ifr) != 0 || opts == 0)
|
||||
#else
|
||||
if (ioctl_va(s, GREGOPTS, &ifr, 3, offset, ifr.ifr_data, clen) != 0 || opts == 0)
|
||||
#endif
|
||||
return;
|
||||
printb("\toptions", opts, GREBITS);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
setifgrekey(const char *val, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
uint32_t grekey = strtol(val, NULL, 0);
|
||||
|
||||
strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
||||
ifr.ifr_data = (caddr_t)&grekey;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GRESKEY, (caddr_t)&ifr) < 0)
|
||||
#else
|
||||
size_t offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
size_t clen = sizeof(uint32_t);
|
||||
if (ioctl_va(s, GRESKEY, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) < 0)
|
||||
#endif
|
||||
warn("ioctl (set grekey)");
|
||||
}
|
||||
|
||||
static void
|
||||
setifgreopts(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
uint32_t opts;
|
||||
|
||||
ifr.ifr_data = (caddr_t)&opts;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GREGOPTS, &ifr) == -1) {
|
||||
#else
|
||||
size_t offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
size_t clen = sizeof(uint32_t);
|
||||
if (ioctl_va(s, GREGOPTS, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) == -1) {
|
||||
#endif
|
||||
warn("ioctl(GREGOPTS)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d < 0)
|
||||
opts &= ~(-d);
|
||||
else
|
||||
opts |= d;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, GRESOPTS, &ifr) == -1) {
|
||||
#else
|
||||
if (ioctl_va(s, GRESOPTS, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) == -1) {
|
||||
#endif
|
||||
warn("ioctl(GIFSOPTS)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct cmd gre_cmds[] = {
|
||||
DEF_CMD_ARG("grekey", setifgrekey),
|
||||
DEF_CMD("enable_csum", GRE_ENABLE_CSUM, setifgreopts),
|
||||
DEF_CMD("-enable_csum",-GRE_ENABLE_CSUM,setifgreopts),
|
||||
DEF_CMD("enable_seq", GRE_ENABLE_SEQ, setifgreopts),
|
||||
DEF_CMD("-enable_seq",-GRE_ENABLE_SEQ, setifgreopts),
|
||||
};
|
||||
static struct afswtch af_gre = {
|
||||
.af_name = "af_gre",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = gre_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
gre_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(gre_cmds); i++)
|
||||
cmd_register(&gre_cmds[i]);
|
||||
af_register(&af_gre);
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
/*-
|
||||
* Copyright (c) 2006 Max Laier. 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
setifgroup(const char *group_name, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct ifgroupreq ifgr;
|
||||
|
||||
memset(&ifgr, 0, sizeof(ifgr));
|
||||
strlcpy(ifgr.ifgr_name, name, IFNAMSIZ);
|
||||
|
||||
if (group_name[0] && isdigit(group_name[strlen(group_name) - 1]))
|
||||
errx(1, "setifgroup: group names may not end in a digit");
|
||||
|
||||
if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ)
|
||||
errx(1, "setifgroup: group name too long");
|
||||
if (ioctl(s, SIOCAIFGROUP, (caddr_t)&ifgr) == -1 && errno != EEXIST)
|
||||
err(1," SIOCAIFGROUP");
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
static void
|
||||
unsetifgroup(const char *group_name, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct ifgroupreq ifgr;
|
||||
|
||||
memset(&ifgr, 0, sizeof(ifgr));
|
||||
strlcpy(ifgr.ifgr_name, name, IFNAMSIZ);
|
||||
|
||||
if (group_name[0] && isdigit(group_name[strlen(group_name) - 1]))
|
||||
errx(1, "unsetifgroup: group names may not end in a digit");
|
||||
|
||||
if (strlcpy(ifgr.ifgr_group, group_name, IFNAMSIZ) >= IFNAMSIZ)
|
||||
errx(1, "unsetifgroup: group name too long");
|
||||
if (ioctl(s, SIOCDIFGROUP, (caddr_t)&ifgr) == -1 && errno != ENOENT)
|
||||
err(1, "SIOCDIFGROUP");
|
||||
}
|
||||
|
||||
static void
|
||||
getifgroups(int s)
|
||||
{
|
||||
int len, cnt;
|
||||
struct ifgroupreq ifgr;
|
||||
struct ifg_req *ifg;
|
||||
|
||||
memset(&ifgr, 0, sizeof(ifgr));
|
||||
strlcpy(ifgr.ifgr_name, name, IFNAMSIZ);
|
||||
|
||||
if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifgr) == -1) {
|
||||
if (errno == EINVAL || errno == ENOTTY)
|
||||
return;
|
||||
else
|
||||
err(1, "SIOCGIFGROUP");
|
||||
}
|
||||
|
||||
len = ifgr.ifgr_len;
|
||||
ifgr.ifgr_groups =
|
||||
(struct ifg_req *)calloc(len / sizeof(struct ifg_req),
|
||||
sizeof(struct ifg_req));
|
||||
if (ifgr.ifgr_groups == NULL)
|
||||
err(1, "getifgroups");
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCGIFGROUP, (caddr_t)&ifgr) == -1)
|
||||
#else
|
||||
size_t offset = (char *)&(ifgr.ifgr_groups) - (char *)&(ifgr);
|
||||
size_t clen = len;
|
||||
if (ioctl_va(s, SIOCGIFGROUP, (caddr_t)&ifgr, 3, offset, ifgr.ifgr_groups, clen) == -1)
|
||||
#endif
|
||||
err(1, "SIOCGIFGROUP");
|
||||
|
||||
cnt = 0;
|
||||
ifg = ifgr.ifgr_groups;
|
||||
for (; ifg && len >= sizeof(struct ifg_req); ifg++) {
|
||||
len -= sizeof(struct ifg_req);
|
||||
if (strcmp(ifg->ifgrq_group, "all")) {
|
||||
if (cnt == 0)
|
||||
printf("\tgroups: ");
|
||||
cnt++;
|
||||
printf("%s ", ifg->ifgrq_group);
|
||||
}
|
||||
}
|
||||
if (cnt)
|
||||
printf("\n");
|
||||
|
||||
free(ifgr.ifgr_groups);
|
||||
}
|
||||
|
||||
static void
|
||||
printgroup(const char *groupname)
|
||||
{
|
||||
struct ifgroupreq ifgr;
|
||||
struct ifg_req *ifg;
|
||||
int len, cnt = 0;
|
||||
int s;
|
||||
|
||||
s = socket(AF_LOCAL, SOCK_DGRAM, 0);
|
||||
if (s == -1)
|
||||
err(1, "socket(AF_LOCAL,SOCK_DGRAM)");
|
||||
bzero(&ifgr, sizeof(ifgr));
|
||||
strlcpy(ifgr.ifgr_name, groupname, sizeof(ifgr.ifgr_name));
|
||||
if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
|
||||
if (errno == EINVAL || errno == ENOTTY ||
|
||||
errno == ENOENT)
|
||||
exit(0);
|
||||
else
|
||||
err(1, "SIOCGIFGMEMB");
|
||||
}
|
||||
|
||||
len = ifgr.ifgr_len;
|
||||
if ((ifgr.ifgr_groups = calloc(1, len)) == NULL)
|
||||
err(1, "printgroup");
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
|
||||
#else
|
||||
size_t offset = (char *)&(ifgr.ifgr_groups) - (char *)&(ifgr);
|
||||
size_t clen = len;
|
||||
if (ioctl_va(s, SIOCGIFGMEMB, (caddr_t)&ifgr, 3, offset, ifgr.ifgr_groups, clen) == -1)
|
||||
#endif
|
||||
err(1, "SIOCGIFGMEMB");
|
||||
|
||||
for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(struct ifg_req);
|
||||
ifg++) {
|
||||
len -= sizeof(struct ifg_req);
|
||||
printf("%s\n", ifg->ifgrq_member);
|
||||
cnt++;
|
||||
}
|
||||
free(ifgr.ifgr_groups);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static struct cmd group_cmds[] = {
|
||||
DEF_CMD_ARG("group", setifgroup),
|
||||
DEF_CMD_ARG("-group", unsetifgroup),
|
||||
};
|
||||
static struct afswtch af_group = {
|
||||
.af_name = "af_group",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = getifgroups,
|
||||
};
|
||||
static struct option group_gopt = { "g:", "[-g groupname]", printgroup };
|
||||
|
||||
static __constructor void
|
||||
group_ctor(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems(group_cmds); i++)
|
||||
cmd_register(&group_cmds[i]);
|
||||
af_register(&af_group);
|
||||
opt_register(&group_gopt);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,332 @@
|
|||
/*-
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_lagg.h>
|
||||
#include <net/ieee8023ad_lacp.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
char lacpbuf[120]; /* LACP peer '[(a,a,a),(p,p,p)]' */
|
||||
|
||||
static void
|
||||
setlaggport(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct lagg_reqport rp;
|
||||
|
||||
bzero(&rp, sizeof(rp));
|
||||
strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
|
||||
strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
|
||||
|
||||
/* Don't choke if the port is already in this lagg. */
|
||||
if (ioctl(s, SIOCSLAGGPORT, &rp) && errno != EEXIST)
|
||||
err(1, "SIOCSLAGGPORT");
|
||||
}
|
||||
|
||||
static void
|
||||
unsetlaggport(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct lagg_reqport rp;
|
||||
|
||||
bzero(&rp, sizeof(rp));
|
||||
strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
|
||||
strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname));
|
||||
|
||||
if (ioctl(s, SIOCSLAGGDELPORT, &rp))
|
||||
err(1, "SIOCSLAGGDELPORT");
|
||||
}
|
||||
|
||||
static void
|
||||
setlaggproto(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct lagg_protos lpr[] = LAGG_PROTOS;
|
||||
struct lagg_reqall ra;
|
||||
int i;
|
||||
|
||||
bzero(&ra, sizeof(ra));
|
||||
ra.ra_proto = LAGG_PROTO_MAX;
|
||||
|
||||
for (i = 0; i < nitems(lpr); i++) {
|
||||
if (strcmp(val, lpr[i].lpr_name) == 0) {
|
||||
ra.ra_proto = lpr[i].lpr_proto;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ra.ra_proto == LAGG_PROTO_MAX)
|
||||
errx(1, "Invalid aggregation protocol: %s", val);
|
||||
|
||||
strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
|
||||
if (ioctl(s, SIOCSLAGG, &ra) != 0)
|
||||
err(1, "SIOCSLAGG");
|
||||
}
|
||||
|
||||
static void
|
||||
setlaggflowidshift(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct lagg_reqopts ro;
|
||||
|
||||
bzero(&ro, sizeof(ro));
|
||||
ro.ro_opts = LAGG_OPT_FLOWIDSHIFT;
|
||||
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
||||
ro.ro_flowid_shift = (int)strtol(val, NULL, 10);
|
||||
if (ro.ro_flowid_shift & ~LAGG_OPT_FLOWIDSHIFT_MASK)
|
||||
errx(1, "Invalid flowid_shift option: %s", val);
|
||||
|
||||
if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
|
||||
err(1, "SIOCSLAGGOPTS");
|
||||
}
|
||||
|
||||
static void
|
||||
setlaggrr_limit(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct lagg_reqopts ro;
|
||||
|
||||
bzero(&ro, sizeof(ro));
|
||||
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
||||
ro.ro_bkt = (int)strtol(val, NULL, 10);
|
||||
|
||||
if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
|
||||
err(1, "SIOCSLAGG");
|
||||
}
|
||||
|
||||
static void
|
||||
setlaggsetopt(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct lagg_reqopts ro;
|
||||
|
||||
bzero(&ro, sizeof(ro));
|
||||
ro.ro_opts = d;
|
||||
switch (ro.ro_opts) {
|
||||
case LAGG_OPT_USE_FLOWID:
|
||||
case -LAGG_OPT_USE_FLOWID:
|
||||
case LAGG_OPT_LACP_STRICT:
|
||||
case -LAGG_OPT_LACP_STRICT:
|
||||
case LAGG_OPT_LACP_TXTEST:
|
||||
case -LAGG_OPT_LACP_TXTEST:
|
||||
case LAGG_OPT_LACP_RXTEST:
|
||||
case -LAGG_OPT_LACP_RXTEST:
|
||||
case LAGG_OPT_LACP_TIMEOUT:
|
||||
case -LAGG_OPT_LACP_TIMEOUT:
|
||||
break;
|
||||
default:
|
||||
err(1, "Invalid lagg option");
|
||||
}
|
||||
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
||||
|
||||
if (ioctl(s, SIOCSLAGGOPTS, &ro) != 0)
|
||||
err(1, "SIOCSLAGGOPTS");
|
||||
}
|
||||
|
||||
static void
|
||||
setlagghash(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct lagg_reqflags rf;
|
||||
char *str, *tmp, *tok;
|
||||
|
||||
|
||||
rf.rf_flags = 0;
|
||||
str = tmp = strdup(val);
|
||||
while ((tok = strsep(&tmp, ",")) != NULL) {
|
||||
if (strcmp(tok, "l2") == 0)
|
||||
rf.rf_flags |= LAGG_F_HASHL2;
|
||||
else if (strcmp(tok, "l3") == 0)
|
||||
rf.rf_flags |= LAGG_F_HASHL3;
|
||||
else if (strcmp(tok, "l4") == 0)
|
||||
rf.rf_flags |= LAGG_F_HASHL4;
|
||||
else
|
||||
errx(1, "Invalid lagghash option: %s", tok);
|
||||
}
|
||||
free(str);
|
||||
if (rf.rf_flags == 0)
|
||||
errx(1, "No lagghash options supplied");
|
||||
|
||||
strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname));
|
||||
if (ioctl(s, SIOCSLAGGHASH, &rf))
|
||||
err(1, "SIOCSLAGGHASH");
|
||||
}
|
||||
|
||||
static char *
|
||||
lacp_format_mac(const uint8_t *mac, char *buf, size_t buflen)
|
||||
{
|
||||
snprintf(buf, buflen, "%02X-%02X-%02X-%02X-%02X-%02X",
|
||||
(int)mac[0], (int)mac[1], (int)mac[2], (int)mac[3],
|
||||
(int)mac[4], (int)mac[5]);
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
static char *
|
||||
lacp_format_peer(struct lacp_opreq *req, const char *sep)
|
||||
{
|
||||
char macbuf1[20];
|
||||
char macbuf2[20];
|
||||
|
||||
snprintf(lacpbuf, sizeof(lacpbuf),
|
||||
"[(%04X,%s,%04X,%04X,%04X),%s(%04X,%s,%04X,%04X,%04X)]",
|
||||
req->actor_prio,
|
||||
lacp_format_mac(req->actor_mac, macbuf1, sizeof(macbuf1)),
|
||||
req->actor_key, req->actor_portprio, req->actor_portno, sep,
|
||||
req->partner_prio,
|
||||
lacp_format_mac(req->partner_mac, macbuf2, sizeof(macbuf2)),
|
||||
req->partner_key, req->partner_portprio, req->partner_portno);
|
||||
|
||||
return(lacpbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
lagg_status(int s)
|
||||
{
|
||||
struct lagg_protos lpr[] = LAGG_PROTOS;
|
||||
struct lagg_reqport rp, rpbuf[LAGG_MAX_PORTS];
|
||||
struct lagg_reqall ra;
|
||||
struct lagg_reqopts ro;
|
||||
struct lagg_reqflags rf;
|
||||
struct lacp_opreq *lp;
|
||||
const char *proto = "<unknown>";
|
||||
int i, isport = 0;
|
||||
|
||||
bzero(&rp, sizeof(rp));
|
||||
bzero(&ra, sizeof(ra));
|
||||
bzero(&ro, sizeof(ro));
|
||||
|
||||
strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
|
||||
strlcpy(rp.rp_portname, name, sizeof(rp.rp_portname));
|
||||
|
||||
if (ioctl(s, SIOCGLAGGPORT, &rp) == 0)
|
||||
isport = 1;
|
||||
|
||||
strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
|
||||
ra.ra_size = sizeof(rpbuf);
|
||||
ra.ra_port = rpbuf;
|
||||
|
||||
strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname));
|
||||
ioctl(s, SIOCGLAGGOPTS, &ro);
|
||||
|
||||
strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname));
|
||||
if (ioctl(s, SIOCGLAGGFLAGS, &rf) != 0)
|
||||
rf.rf_flags = 0;
|
||||
|
||||
if (ioctl(s, SIOCGLAGG, &ra) == 0) {
|
||||
lp = (struct lacp_opreq *)&ra.ra_lacpreq;
|
||||
|
||||
for (i = 0; i < nitems(lpr); i++) {
|
||||
if (ra.ra_proto == lpr[i].lpr_proto) {
|
||||
proto = lpr[i].lpr_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\tlaggproto %s", proto);
|
||||
if (rf.rf_flags & LAGG_F_HASHMASK) {
|
||||
const char *sep = "";
|
||||
|
||||
printf(" lagghash ");
|
||||
if (rf.rf_flags & LAGG_F_HASHL2) {
|
||||
printf("%sl2", sep);
|
||||
sep = ",";
|
||||
}
|
||||
if (rf.rf_flags & LAGG_F_HASHL3) {
|
||||
printf("%sl3", sep);
|
||||
sep = ",";
|
||||
}
|
||||
if (rf.rf_flags & LAGG_F_HASHL4) {
|
||||
printf("%sl4", sep);
|
||||
sep = ",";
|
||||
}
|
||||
}
|
||||
if (isport)
|
||||
printf(" laggdev %s", rp.rp_ifname);
|
||||
putchar('\n');
|
||||
if (verbose) {
|
||||
printf("\tlagg options:\n");
|
||||
printb("\t\tflags", ro.ro_opts, LAGG_OPT_BITS);
|
||||
putchar('\n');
|
||||
printf("\t\tflowid_shift: %d\n", ro.ro_flowid_shift);
|
||||
if (ra.ra_proto == LAGG_PROTO_ROUNDROBIN)
|
||||
printf("\t\trr_limit: %d\n", ro.ro_bkt);
|
||||
printf("\tlagg statistics:\n");
|
||||
printf("\t\tactive ports: %d\n", ro.ro_active);
|
||||
printf("\t\tflapping: %u\n", ro.ro_flapping);
|
||||
if (ra.ra_proto == LAGG_PROTO_LACP) {
|
||||
printf("\tlag id: %s\n",
|
||||
lacp_format_peer(lp, "\n\t\t "));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ra.ra_ports; i++) {
|
||||
lp = (struct lacp_opreq *)&rpbuf[i].rp_lacpreq;
|
||||
printf("\tlaggport: %s ", rpbuf[i].rp_portname);
|
||||
printb("flags", rpbuf[i].rp_flags, LAGG_PORT_BITS);
|
||||
if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
|
||||
printb(" state", lp->actor_state,
|
||||
LACP_STATE_BITS);
|
||||
putchar('\n');
|
||||
if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
|
||||
printf("\t\t%s\n",
|
||||
lacp_format_peer(lp, "\n\t\t "));
|
||||
}
|
||||
|
||||
if (0 /* XXX */) {
|
||||
printf("\tsupported aggregation protocols:\n");
|
||||
for (i = 0; i < nitems(lpr); i++)
|
||||
printf("\t\tlaggproto %s\n", lpr[i].lpr_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct cmd lagg_cmds[] = {
|
||||
DEF_CMD_ARG("laggport", setlaggport),
|
||||
DEF_CMD_ARG("-laggport", unsetlaggport),
|
||||
DEF_CMD_ARG("laggproto", setlaggproto),
|
||||
DEF_CMD_ARG("lagghash", setlagghash),
|
||||
DEF_CMD("use_flowid", LAGG_OPT_USE_FLOWID, setlaggsetopt),
|
||||
DEF_CMD("-use_flowid", -LAGG_OPT_USE_FLOWID, setlaggsetopt),
|
||||
DEF_CMD("lacp_strict", LAGG_OPT_LACP_STRICT, setlaggsetopt),
|
||||
DEF_CMD("-lacp_strict", -LAGG_OPT_LACP_STRICT, setlaggsetopt),
|
||||
DEF_CMD("lacp_txtest", LAGG_OPT_LACP_TXTEST, setlaggsetopt),
|
||||
DEF_CMD("-lacp_txtest", -LAGG_OPT_LACP_TXTEST, setlaggsetopt),
|
||||
DEF_CMD("lacp_rxtest", LAGG_OPT_LACP_RXTEST, setlaggsetopt),
|
||||
DEF_CMD("-lacp_rxtest", -LAGG_OPT_LACP_RXTEST, setlaggsetopt),
|
||||
DEF_CMD("lacp_fast_timeout", LAGG_OPT_LACP_TIMEOUT, setlaggsetopt),
|
||||
DEF_CMD("-lacp_fast_timeout", -LAGG_OPT_LACP_TIMEOUT, setlaggsetopt),
|
||||
DEF_CMD_ARG("flowid_shift", setlaggflowidshift),
|
||||
DEF_CMD_ARG("rr_limit", setlaggrr_limit),
|
||||
};
|
||||
static struct afswtch af_lagg = {
|
||||
.af_name = "af_lagg",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = lagg_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
lagg_ctor(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems(lagg_cmds); i++)
|
||||
cmd_register(&lagg_cmds[i]);
|
||||
af_register(&af_lagg);
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/*-
|
||||
* Copyright (c) 2001 Networks Associates Technology, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed for the FreeBSD Project by NAI Labs, the
|
||||
* Security Research Division of Network Associates, Inc. under
|
||||
* DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
|
||||
* CHATS research program.
|
||||
*
|
||||
* 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 author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mac.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static void
|
||||
maclabel_status(int s)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
mac_t label;
|
||||
char *label_text;
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
if (mac_prepare_ifnet_label(&label) == -1)
|
||||
return;
|
||||
ifr.ifr_ifru.ifru_data = (void *)label;
|
||||
if (ioctl(s, SIOCGIFMAC, &ifr) == -1)
|
||||
goto mac_free;
|
||||
|
||||
|
||||
if (mac_to_text(label, &label_text) == -1)
|
||||
goto mac_free;
|
||||
|
||||
if (strlen(label_text) != 0)
|
||||
printf("\tmaclabel %s\n", label_text);
|
||||
free(label_text);
|
||||
|
||||
mac_free:
|
||||
mac_free(label);
|
||||
}
|
||||
|
||||
static void
|
||||
setifmaclabel(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
mac_t label;
|
||||
int error;
|
||||
|
||||
if (mac_from_text(&label, val) == -1) {
|
||||
perror(val);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_ifru.ifru_data = (void *)label;
|
||||
|
||||
error = ioctl(s, SIOCSIFMAC, &ifr);
|
||||
mac_free(label);
|
||||
if (error == -1)
|
||||
perror("setifmac");
|
||||
}
|
||||
|
||||
static struct cmd mac_cmds[] = {
|
||||
DEF_CMD_ARG("maclabel", setifmaclabel),
|
||||
};
|
||||
static struct afswtch af_mac = {
|
||||
.af_name = "af_maclabel",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = maclabel_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
mac_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(mac_cmds); i++)
|
||||
cmd_register(&mac_cmds[i]);
|
||||
af_register(&af_mac);
|
||||
}
|
|
@ -0,0 +1,853 @@
|
|||
/* $NetBSD: ifconfig.c,v 1.34 1997/04/21 01:17:58 lukem Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Jason R. Thorpe.
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed for the NetBSD Project
|
||||
* by Jason R. Thorpe.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_media.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
static void domediaopt(const char *, int, int);
|
||||
static int get_media_subtype(int, const char *);
|
||||
static int get_media_mode(int, const char *);
|
||||
static int get_media_options(int, const char *);
|
||||
static int lookup_media_word(struct ifmedia_description *, const char *);
|
||||
static void print_media_word(int, int);
|
||||
static void print_media_word_ifconfig(int);
|
||||
|
||||
static struct ifmedia_description *get_toptype_desc(int);
|
||||
static struct ifmedia_type_to_subtype *get_toptype_ttos(int);
|
||||
static struct ifmedia_description *get_subtype_desc(int,
|
||||
struct ifmedia_type_to_subtype *ttos);
|
||||
|
||||
#define IFM_OPMODE(x) \
|
||||
((x) & (IFM_IEEE80211_ADHOC | IFM_IEEE80211_HOSTAP | \
|
||||
IFM_IEEE80211_IBSS | IFM_IEEE80211_WDS | IFM_IEEE80211_MONITOR | \
|
||||
IFM_IEEE80211_MBSS))
|
||||
#define IFM_IEEE80211_STA 0
|
||||
|
||||
static void
|
||||
media_status(int s)
|
||||
{
|
||||
struct ifmediareq ifmr;
|
||||
int *media_list, i;
|
||||
int xmedia = 1;
|
||||
|
||||
(void) memset(&ifmr, 0, sizeof(ifmr));
|
||||
(void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
|
||||
|
||||
/*
|
||||
* Check if interface supports extended media types.
|
||||
*/
|
||||
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
|
||||
xmedia = 0;
|
||||
if (xmedia == 0 && ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
|
||||
/*
|
||||
* Interface doesn't support SIOC{G,S}IFMEDIA.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
if (ifmr.ifm_count == 0) {
|
||||
warnx("%s: no media types?", name);
|
||||
return;
|
||||
}
|
||||
|
||||
media_list = (int *)malloc(ifmr.ifm_count * sizeof(int));
|
||||
if (media_list == NULL)
|
||||
err(1, "malloc");
|
||||
ifmr.ifm_ulist = media_list;
|
||||
|
||||
if (xmedia) {
|
||||
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
|
||||
err(1, "SIOCGIFXMEDIA");
|
||||
} else {
|
||||
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
|
||||
err(1, "SIOCGIFMEDIA");
|
||||
}
|
||||
|
||||
printf("\tmedia: ");
|
||||
print_media_word(ifmr.ifm_current, 1);
|
||||
if (ifmr.ifm_active != ifmr.ifm_current) {
|
||||
putchar(' ');
|
||||
putchar('(');
|
||||
print_media_word(ifmr.ifm_active, 0);
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
|
||||
if (ifmr.ifm_status & IFM_AVALID) {
|
||||
printf("\tstatus: ");
|
||||
switch (IFM_TYPE(ifmr.ifm_active)) {
|
||||
case IFM_ETHER:
|
||||
case IFM_ATM:
|
||||
if (ifmr.ifm_status & IFM_ACTIVE)
|
||||
printf("active");
|
||||
else
|
||||
printf("no carrier");
|
||||
break;
|
||||
|
||||
case IFM_FDDI:
|
||||
case IFM_TOKEN:
|
||||
if (ifmr.ifm_status & IFM_ACTIVE)
|
||||
printf("inserted");
|
||||
else
|
||||
printf("no ring");
|
||||
break;
|
||||
|
||||
case IFM_IEEE80211:
|
||||
if (ifmr.ifm_status & IFM_ACTIVE) {
|
||||
/* NB: only sta mode associates */
|
||||
if (IFM_OPMODE(ifmr.ifm_active) == IFM_IEEE80211_STA)
|
||||
printf("associated");
|
||||
else
|
||||
printf("running");
|
||||
} else
|
||||
printf("no carrier");
|
||||
break;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
if (ifmr.ifm_count > 0 && supmedia) {
|
||||
printf("\tsupported media:\n");
|
||||
for (i = 0; i < ifmr.ifm_count; i++) {
|
||||
printf("\t\t");
|
||||
print_media_word_ifconfig(media_list[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
free(media_list);
|
||||
}
|
||||
|
||||
struct ifmediareq *
|
||||
ifmedia_getstate(int s)
|
||||
{
|
||||
static struct ifmediareq *ifmr = NULL;
|
||||
int *mwords;
|
||||
int xmedia = 1;
|
||||
|
||||
if (ifmr == NULL) {
|
||||
ifmr = (struct ifmediareq *)malloc(sizeof(struct ifmediareq));
|
||||
if (ifmr == NULL)
|
||||
err(1, "malloc");
|
||||
|
||||
(void) memset(ifmr, 0, sizeof(struct ifmediareq));
|
||||
(void) strlcpy(ifmr->ifm_name, name,
|
||||
sizeof(ifmr->ifm_name));
|
||||
|
||||
ifmr->ifm_count = 0;
|
||||
ifmr->ifm_ulist = NULL;
|
||||
|
||||
/*
|
||||
* We must go through the motions of reading all
|
||||
* supported media because we need to know both
|
||||
* the current media type and the top-level type.
|
||||
*/
|
||||
|
||||
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)ifmr) < 0) {
|
||||
xmedia = 0;
|
||||
}
|
||||
if (xmedia == 0 && ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0) {
|
||||
err(1, "SIOCGIFMEDIA");
|
||||
}
|
||||
|
||||
if (ifmr->ifm_count == 0)
|
||||
errx(1, "%s: no media types?", name);
|
||||
|
||||
mwords = (int *)malloc(ifmr->ifm_count * sizeof(int));
|
||||
if (mwords == NULL)
|
||||
err(1, "malloc");
|
||||
|
||||
ifmr->ifm_ulist = mwords;
|
||||
if (xmedia) {
|
||||
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)ifmr) < 0)
|
||||
err(1, "SIOCGIFXMEDIA");
|
||||
} else {
|
||||
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)ifmr) < 0)
|
||||
err(1, "SIOCGIFMEDIA");
|
||||
}
|
||||
}
|
||||
|
||||
return ifmr;
|
||||
}
|
||||
|
||||
static void
|
||||
setifmediacallback(int s, void *arg)
|
||||
{
|
||||
struct ifmediareq *ifmr = (struct ifmediareq *)arg;
|
||||
static int did_it = 0;
|
||||
|
||||
if (!did_it) {
|
||||
ifr.ifr_media = ifmr->ifm_current;
|
||||
if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0)
|
||||
err(1, "SIOCSIFMEDIA (media)");
|
||||
free(ifmr->ifm_ulist);
|
||||
free(ifmr);
|
||||
did_it = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setmedia(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifmediareq *ifmr;
|
||||
int subtype;
|
||||
|
||||
ifmr = ifmedia_getstate(s);
|
||||
|
||||
/*
|
||||
* We are primarily concerned with the top-level type.
|
||||
* However, "current" may be only IFM_NONE, so we just look
|
||||
* for the top-level type in the first "supported type"
|
||||
* entry.
|
||||
*
|
||||
* (I'm assuming that all supported media types for a given
|
||||
* interface will be the same top-level type..)
|
||||
*/
|
||||
subtype = get_media_subtype(IFM_TYPE(ifmr->ifm_ulist[0]), val);
|
||||
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_media = (ifmr->ifm_current & IFM_IMASK) |
|
||||
IFM_TYPE(ifmr->ifm_ulist[0]) | subtype;
|
||||
|
||||
ifmr->ifm_current = ifr.ifr_media;
|
||||
callback_register(setifmediacallback, (void *)ifmr);
|
||||
}
|
||||
|
||||
static void
|
||||
setmediaopt(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
domediaopt(val, 0, s);
|
||||
}
|
||||
|
||||
static void
|
||||
unsetmediaopt(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
|
||||
domediaopt(val, 1, s);
|
||||
}
|
||||
|
||||
static void
|
||||
domediaopt(const char *val, int clear, int s)
|
||||
{
|
||||
struct ifmediareq *ifmr;
|
||||
int options;
|
||||
|
||||
ifmr = ifmedia_getstate(s);
|
||||
|
||||
options = get_media_options(IFM_TYPE(ifmr->ifm_ulist[0]), val);
|
||||
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_media = ifmr->ifm_current;
|
||||
if (clear)
|
||||
ifr.ifr_media &= ~options;
|
||||
else {
|
||||
if (options & IFM_HDX) {
|
||||
ifr.ifr_media &= ~IFM_FDX;
|
||||
options &= ~IFM_HDX;
|
||||
}
|
||||
ifr.ifr_media |= options;
|
||||
}
|
||||
ifmr->ifm_current = ifr.ifr_media;
|
||||
callback_register(setifmediacallback, (void *)ifmr);
|
||||
}
|
||||
|
||||
static void
|
||||
setmediainst(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifmediareq *ifmr;
|
||||
int inst;
|
||||
|
||||
ifmr = ifmedia_getstate(s);
|
||||
|
||||
inst = atoi(val);
|
||||
if (inst < 0 || inst > (int)IFM_INST_MAX)
|
||||
errx(1, "invalid media instance: %s", val);
|
||||
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_media = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT;
|
||||
|
||||
ifmr->ifm_current = ifr.ifr_media;
|
||||
callback_register(setifmediacallback, (void *)ifmr);
|
||||
}
|
||||
|
||||
static void
|
||||
setmediamode(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifmediareq *ifmr;
|
||||
int mode;
|
||||
|
||||
ifmr = ifmedia_getstate(s);
|
||||
|
||||
mode = get_media_mode(IFM_TYPE(ifmr->ifm_ulist[0]), val);
|
||||
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode;
|
||||
|
||||
ifmr->ifm_current = ifr.ifr_media;
|
||||
callback_register(setifmediacallback, (void *)ifmr);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* A good chunk of this is duplicated from sys/net/ifmedia.c
|
||||
**********************************************************************/
|
||||
|
||||
static struct ifmedia_description ifm_type_descriptions[] =
|
||||
IFM_TYPE_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_ethernet_descriptions[] =
|
||||
IFM_SUBTYPE_ETHERNET_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_ethernet_aliases[] =
|
||||
IFM_SUBTYPE_ETHERNET_ALIASES;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_ethernet_option_descriptions[] =
|
||||
IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_tokenring_descriptions[] =
|
||||
IFM_SUBTYPE_TOKENRING_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_tokenring_aliases[] =
|
||||
IFM_SUBTYPE_TOKENRING_ALIASES;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_tokenring_option_descriptions[] =
|
||||
IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_fddi_descriptions[] =
|
||||
IFM_SUBTYPE_FDDI_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_fddi_aliases[] =
|
||||
IFM_SUBTYPE_FDDI_ALIASES;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_fddi_option_descriptions[] =
|
||||
IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_ieee80211_descriptions[] =
|
||||
IFM_SUBTYPE_IEEE80211_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_ieee80211_aliases[] =
|
||||
IFM_SUBTYPE_IEEE80211_ALIASES;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_ieee80211_option_descriptions[] =
|
||||
IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS;
|
||||
|
||||
struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions[] =
|
||||
IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS;
|
||||
|
||||
struct ifmedia_description ifm_subtype_ieee80211_mode_aliases[] =
|
||||
IFM_SUBTYPE_IEEE80211_MODE_ALIASES;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_atm_descriptions[] =
|
||||
IFM_SUBTYPE_ATM_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_atm_aliases[] =
|
||||
IFM_SUBTYPE_ATM_ALIASES;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_atm_option_descriptions[] =
|
||||
IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_shared_descriptions[] =
|
||||
IFM_SUBTYPE_SHARED_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_subtype_shared_aliases[] =
|
||||
IFM_SUBTYPE_SHARED_ALIASES;
|
||||
|
||||
static struct ifmedia_description ifm_shared_option_descriptions[] =
|
||||
IFM_SHARED_OPTION_DESCRIPTIONS;
|
||||
|
||||
static struct ifmedia_description ifm_shared_option_aliases[] =
|
||||
IFM_SHARED_OPTION_ALIASES;
|
||||
|
||||
struct ifmedia_type_to_subtype {
|
||||
struct {
|
||||
struct ifmedia_description *desc;
|
||||
int alias;
|
||||
} subtypes[5];
|
||||
struct {
|
||||
struct ifmedia_description *desc;
|
||||
int alias;
|
||||
} options[4];
|
||||
struct {
|
||||
struct ifmedia_description *desc;
|
||||
int alias;
|
||||
} modes[3];
|
||||
};
|
||||
|
||||
/* must be in the same order as IFM_TYPE_DESCRIPTIONS */
|
||||
static struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[] = {
|
||||
{
|
||||
{
|
||||
{ &ifm_subtype_shared_descriptions[0], 0 },
|
||||
{ &ifm_subtype_shared_aliases[0], 1 },
|
||||
{ &ifm_subtype_ethernet_descriptions[0], 0 },
|
||||
{ &ifm_subtype_ethernet_aliases[0], 1 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ &ifm_shared_option_descriptions[0], 0 },
|
||||
{ &ifm_shared_option_aliases[0], 1 },
|
||||
{ &ifm_subtype_ethernet_option_descriptions[0], 0 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ NULL, 0 },
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
{ &ifm_subtype_shared_descriptions[0], 0 },
|
||||
{ &ifm_subtype_shared_aliases[0], 1 },
|
||||
{ &ifm_subtype_tokenring_descriptions[0], 0 },
|
||||
{ &ifm_subtype_tokenring_aliases[0], 1 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ &ifm_shared_option_descriptions[0], 0 },
|
||||
{ &ifm_shared_option_aliases[0], 1 },
|
||||
{ &ifm_subtype_tokenring_option_descriptions[0], 0 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ NULL, 0 },
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
{ &ifm_subtype_shared_descriptions[0], 0 },
|
||||
{ &ifm_subtype_shared_aliases[0], 1 },
|
||||
{ &ifm_subtype_fddi_descriptions[0], 0 },
|
||||
{ &ifm_subtype_fddi_aliases[0], 1 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ &ifm_shared_option_descriptions[0], 0 },
|
||||
{ &ifm_shared_option_aliases[0], 1 },
|
||||
{ &ifm_subtype_fddi_option_descriptions[0], 0 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ NULL, 0 },
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
{ &ifm_subtype_shared_descriptions[0], 0 },
|
||||
{ &ifm_subtype_shared_aliases[0], 1 },
|
||||
{ &ifm_subtype_ieee80211_descriptions[0], 0 },
|
||||
{ &ifm_subtype_ieee80211_aliases[0], 1 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ &ifm_shared_option_descriptions[0], 0 },
|
||||
{ &ifm_shared_option_aliases[0], 1 },
|
||||
{ &ifm_subtype_ieee80211_option_descriptions[0], 0 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ &ifm_subtype_ieee80211_mode_descriptions[0], 0 },
|
||||
{ &ifm_subtype_ieee80211_mode_aliases[0], 0 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
{ &ifm_subtype_shared_descriptions[0], 0 },
|
||||
{ &ifm_subtype_shared_aliases[0], 1 },
|
||||
{ &ifm_subtype_atm_descriptions[0], 0 },
|
||||
{ &ifm_subtype_atm_aliases[0], 1 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ &ifm_shared_option_descriptions[0], 0 },
|
||||
{ &ifm_shared_option_aliases[0], 1 },
|
||||
{ &ifm_subtype_atm_option_descriptions[0], 0 },
|
||||
{ NULL, 0 },
|
||||
},
|
||||
{
|
||||
{ NULL, 0 },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static int
|
||||
get_media_subtype(int type, const char *val)
|
||||
{
|
||||
struct ifmedia_description *desc;
|
||||
struct ifmedia_type_to_subtype *ttos;
|
||||
int rval, i;
|
||||
|
||||
/* Find the top-level interface type. */
|
||||
for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
|
||||
desc->ifmt_string != NULL; desc++, ttos++)
|
||||
if (type == desc->ifmt_word)
|
||||
break;
|
||||
if (desc->ifmt_string == NULL)
|
||||
errx(1, "unknown media type 0x%x", type);
|
||||
|
||||
for (i = 0; ttos->subtypes[i].desc != NULL; i++) {
|
||||
rval = lookup_media_word(ttos->subtypes[i].desc, val);
|
||||
if (rval != -1)
|
||||
return (rval);
|
||||
}
|
||||
errx(1, "unknown media subtype: %s", val);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
static int
|
||||
get_media_mode(int type, const char *val)
|
||||
{
|
||||
struct ifmedia_description *desc;
|
||||
struct ifmedia_type_to_subtype *ttos;
|
||||
int rval, i;
|
||||
|
||||
/* Find the top-level interface type. */
|
||||
for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
|
||||
desc->ifmt_string != NULL; desc++, ttos++)
|
||||
if (type == desc->ifmt_word)
|
||||
break;
|
||||
if (desc->ifmt_string == NULL)
|
||||
errx(1, "unknown media mode 0x%x", type);
|
||||
|
||||
for (i = 0; ttos->modes[i].desc != NULL; i++) {
|
||||
rval = lookup_media_word(ttos->modes[i].desc, val);
|
||||
if (rval != -1)
|
||||
return (rval);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
get_media_options(int type, const char *val)
|
||||
{
|
||||
struct ifmedia_description *desc;
|
||||
struct ifmedia_type_to_subtype *ttos;
|
||||
char *optlist, *optptr;
|
||||
int option = 0, i, rval = 0;
|
||||
|
||||
/* We muck with the string, so copy it. */
|
||||
optlist = strdup(val);
|
||||
if (optlist == NULL)
|
||||
err(1, "strdup");
|
||||
|
||||
/* Find the top-level interface type. */
|
||||
for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
|
||||
desc->ifmt_string != NULL; desc++, ttos++)
|
||||
if (type == desc->ifmt_word)
|
||||
break;
|
||||
if (desc->ifmt_string == NULL)
|
||||
errx(1, "unknown media type 0x%x", type);
|
||||
|
||||
/*
|
||||
* Look up the options in the user-provided comma-separated
|
||||
* list.
|
||||
*/
|
||||
optptr = optlist;
|
||||
for (; (optptr = strtok(optptr, ",")) != NULL; optptr = NULL) {
|
||||
for (i = 0; ttos->options[i].desc != NULL; i++) {
|
||||
option = lookup_media_word(ttos->options[i].desc, optptr);
|
||||
if (option != -1)
|
||||
break;
|
||||
}
|
||||
if (option == 0)
|
||||
errx(1, "unknown option: %s", optptr);
|
||||
rval |= option;
|
||||
}
|
||||
|
||||
free(optlist);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
static int
|
||||
lookup_media_word(struct ifmedia_description *desc, const char *val)
|
||||
{
|
||||
|
||||
for (; desc->ifmt_string != NULL; desc++)
|
||||
if (strcasecmp(desc->ifmt_string, val) == 0)
|
||||
return (desc->ifmt_word);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static struct ifmedia_description *get_toptype_desc(int ifmw)
|
||||
{
|
||||
struct ifmedia_description *desc;
|
||||
|
||||
for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++)
|
||||
if (IFM_TYPE(ifmw) == desc->ifmt_word)
|
||||
break;
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
static struct ifmedia_type_to_subtype *get_toptype_ttos(int ifmw)
|
||||
{
|
||||
struct ifmedia_description *desc;
|
||||
struct ifmedia_type_to_subtype *ttos;
|
||||
|
||||
for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
|
||||
desc->ifmt_string != NULL; desc++, ttos++)
|
||||
if (IFM_TYPE(ifmw) == desc->ifmt_word)
|
||||
break;
|
||||
|
||||
return ttos;
|
||||
}
|
||||
|
||||
static struct ifmedia_description *get_subtype_desc(int ifmw,
|
||||
struct ifmedia_type_to_subtype *ttos)
|
||||
{
|
||||
int i;
|
||||
struct ifmedia_description *desc;
|
||||
|
||||
for (i = 0; ttos->subtypes[i].desc != NULL; i++) {
|
||||
if (ttos->subtypes[i].alias)
|
||||
continue;
|
||||
for (desc = ttos->subtypes[i].desc;
|
||||
desc->ifmt_string != NULL; desc++) {
|
||||
if (IFM_SUBTYPE(ifmw) == desc->ifmt_word)
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct ifmedia_description *get_mode_desc(int ifmw,
|
||||
struct ifmedia_type_to_subtype *ttos)
|
||||
{
|
||||
int i;
|
||||
struct ifmedia_description *desc;
|
||||
|
||||
for (i = 0; ttos->modes[i].desc != NULL; i++) {
|
||||
if (ttos->modes[i].alias)
|
||||
continue;
|
||||
for (desc = ttos->modes[i].desc;
|
||||
desc->ifmt_string != NULL; desc++) {
|
||||
if (IFM_MODE(ifmw) == desc->ifmt_word)
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
print_media_word(int ifmw, int print_toptype)
|
||||
{
|
||||
struct ifmedia_description *desc;
|
||||
struct ifmedia_type_to_subtype *ttos;
|
||||
int seen_option = 0, i;
|
||||
|
||||
/* Find the top-level interface type. */
|
||||
desc = get_toptype_desc(ifmw);
|
||||
ttos = get_toptype_ttos(ifmw);
|
||||
if (desc->ifmt_string == NULL) {
|
||||
printf("<unknown type>");
|
||||
return;
|
||||
} else if (print_toptype) {
|
||||
printf("%s", desc->ifmt_string);
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't print the top-level type; it's not like we can
|
||||
* change it, or anything.
|
||||
*/
|
||||
|
||||
/* Find subtype. */
|
||||
desc = get_subtype_desc(ifmw, ttos);
|
||||
if (desc == NULL) {
|
||||
printf("<unknown subtype>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (print_toptype)
|
||||
putchar(' ');
|
||||
|
||||
printf("%s", desc->ifmt_string);
|
||||
|
||||
if (print_toptype) {
|
||||
desc = get_mode_desc(ifmw, ttos);
|
||||
if (desc != NULL && strcasecmp("autoselect", desc->ifmt_string))
|
||||
printf(" mode %s", desc->ifmt_string);
|
||||
}
|
||||
|
||||
/* Find options. */
|
||||
for (i = 0; ttos->options[i].desc != NULL; i++) {
|
||||
if (ttos->options[i].alias)
|
||||
continue;
|
||||
for (desc = ttos->options[i].desc;
|
||||
desc->ifmt_string != NULL; desc++) {
|
||||
if (ifmw & desc->ifmt_word) {
|
||||
if (seen_option == 0)
|
||||
printf(" <");
|
||||
printf("%s%s", seen_option++ ? "," : "",
|
||||
desc->ifmt_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s", seen_option ? ">" : "");
|
||||
|
||||
if (print_toptype && IFM_INST(ifmw) != 0)
|
||||
printf(" instance %d", IFM_INST(ifmw));
|
||||
}
|
||||
|
||||
static void
|
||||
print_media_word_ifconfig(int ifmw)
|
||||
{
|
||||
struct ifmedia_description *desc;
|
||||
struct ifmedia_type_to_subtype *ttos;
|
||||
int seen_option = 0, i;
|
||||
|
||||
/* Find the top-level interface type. */
|
||||
desc = get_toptype_desc(ifmw);
|
||||
ttos = get_toptype_ttos(ifmw);
|
||||
if (desc->ifmt_string == NULL) {
|
||||
printf("<unknown type>");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't print the top-level type; it's not like we can
|
||||
* change it, or anything.
|
||||
*/
|
||||
|
||||
/* Find subtype. */
|
||||
desc = get_subtype_desc(ifmw, ttos);
|
||||
if (desc == NULL) {
|
||||
printf("<unknown subtype>");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("media %s", desc->ifmt_string);
|
||||
|
||||
desc = get_mode_desc(ifmw, ttos);
|
||||
if (desc != NULL)
|
||||
printf(" mode %s", desc->ifmt_string);
|
||||
|
||||
/* Find options. */
|
||||
for (i = 0; ttos->options[i].desc != NULL; i++) {
|
||||
if (ttos->options[i].alias)
|
||||
continue;
|
||||
for (desc = ttos->options[i].desc;
|
||||
desc->ifmt_string != NULL; desc++) {
|
||||
if (ifmw & desc->ifmt_word) {
|
||||
if (seen_option == 0)
|
||||
printf(" mediaopt ");
|
||||
printf("%s%s", seen_option++ ? "," : "",
|
||||
desc->ifmt_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IFM_INST(ifmw) != 0)
|
||||
printf(" instance %d", IFM_INST(ifmw));
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* ...until here.
|
||||
**********************************************************************/
|
||||
|
||||
static struct cmd media_cmds[] = {
|
||||
DEF_CMD_ARG("media", setmedia),
|
||||
DEF_CMD_ARG("mode", setmediamode),
|
||||
DEF_CMD_ARG("mediaopt", setmediaopt),
|
||||
DEF_CMD_ARG("-mediaopt",unsetmediaopt),
|
||||
DEF_CMD_ARG("inst", setmediainst),
|
||||
DEF_CMD_ARG("instance", setmediainst),
|
||||
};
|
||||
static struct afswtch af_media = {
|
||||
.af_name = "af_media",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = media_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
ifmedia_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(media_cmds); i++)
|
||||
cmd_register(&media_cmds[i]);
|
||||
af_register(&af_media);
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
* Copyright (c) 2003 Ryan McBride. All rights reserved.
|
||||
* Copyright (c) 2004 Max Laier. 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$
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/pfvar.h>
|
||||
#include <net/if_pfsync.h>
|
||||
#include <net/route.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
void setpfsync_syncdev(const char *, int, int, const struct afswtch *);
|
||||
void unsetpfsync_syncdev(const char *, int, int, const struct afswtch *);
|
||||
void setpfsync_syncpeer(const char *, int, int, const struct afswtch *);
|
||||
void unsetpfsync_syncpeer(const char *, int, int, const struct afswtch *);
|
||||
void setpfsync_syncpeer(const char *, int, int, const struct afswtch *);
|
||||
void setpfsync_maxupd(const char *, int, int, const struct afswtch *);
|
||||
void setpfsync_defer(const char *, int, int, const struct afswtch *);
|
||||
void pfsync_status(int);
|
||||
|
||||
void
|
||||
setpfsync_syncdev(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct pfsyncreq preq;
|
||||
|
||||
bzero((char *)&preq, sizeof(struct pfsyncreq));
|
||||
ifr.ifr_data = (caddr_t)&preq;
|
||||
|
||||
if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCGETPFSYNC");
|
||||
|
||||
strlcpy(preq.pfsyncr_syncdev, val, sizeof(preq.pfsyncr_syncdev));
|
||||
|
||||
if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCSETPFSYNC");
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
unsetpfsync_syncdev(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct pfsyncreq preq;
|
||||
|
||||
bzero((char *)&preq, sizeof(struct pfsyncreq));
|
||||
ifr.ifr_data = (caddr_t)&preq;
|
||||
|
||||
if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCGETPFSYNC");
|
||||
|
||||
bzero((char *)&preq.pfsyncr_syncdev, sizeof(preq.pfsyncr_syncdev));
|
||||
|
||||
if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCSETPFSYNC");
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
setpfsync_syncpeer(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct pfsyncreq preq;
|
||||
struct addrinfo hints, *peerres;
|
||||
int ecode;
|
||||
|
||||
bzero((char *)&preq, sizeof(struct pfsyncreq));
|
||||
ifr.ifr_data = (caddr_t)&preq;
|
||||
|
||||
if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCGETPFSYNC");
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
|
||||
|
||||
if ((ecode = getaddrinfo(val, NULL, &hints, &peerres)) != 0)
|
||||
errx(1, "error in parsing address string: %s",
|
||||
gai_strerror(ecode));
|
||||
|
||||
if (peerres->ai_addr->sa_family != AF_INET)
|
||||
errx(1, "only IPv4 addresses supported for the syncpeer");
|
||||
|
||||
preq.pfsyncr_syncpeer.s_addr = ((struct sockaddr_in *)
|
||||
peerres->ai_addr)->sin_addr.s_addr;
|
||||
|
||||
if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCSETPFSYNC");
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
unsetpfsync_syncpeer(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct pfsyncreq preq;
|
||||
|
||||
bzero((char *)&preq, sizeof(struct pfsyncreq));
|
||||
ifr.ifr_data = (caddr_t)&preq;
|
||||
|
||||
if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCGETPFSYNC");
|
||||
|
||||
preq.pfsyncr_syncpeer.s_addr = 0;
|
||||
|
||||
if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCSETPFSYNC");
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
setpfsync_maxupd(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct pfsyncreq preq;
|
||||
int maxupdates;
|
||||
|
||||
maxupdates = atoi(val);
|
||||
if ((maxupdates < 0) || (maxupdates > 255))
|
||||
errx(1, "maxupd %s: out of range", val);
|
||||
|
||||
memset((char *)&preq, 0, sizeof(struct pfsyncreq));
|
||||
ifr.ifr_data = (caddr_t)&preq;
|
||||
|
||||
if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCGETPFSYNC");
|
||||
|
||||
preq.pfsyncr_maxupdates = maxupdates;
|
||||
|
||||
if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCSETPFSYNC");
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
setpfsync_defer(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
{
|
||||
struct pfsyncreq preq;
|
||||
|
||||
memset((char *)&preq, 0, sizeof(struct pfsyncreq));
|
||||
ifr.ifr_data = (caddr_t)&preq;
|
||||
|
||||
if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCGETPFSYNC");
|
||||
|
||||
preq.pfsyncr_defer = d;
|
||||
if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCSETPFSYNC");
|
||||
}
|
||||
|
||||
void
|
||||
pfsync_status(int s)
|
||||
{
|
||||
struct pfsyncreq preq;
|
||||
|
||||
bzero((char *)&preq, sizeof(struct pfsyncreq));
|
||||
ifr.ifr_data = (caddr_t)&preq;
|
||||
|
||||
if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
|
||||
return;
|
||||
|
||||
if (preq.pfsyncr_syncdev[0] != '\0' ||
|
||||
preq.pfsyncr_syncpeer.s_addr != INADDR_PFSYNC_GROUP)
|
||||
printf("\t");
|
||||
|
||||
if (preq.pfsyncr_syncdev[0] != '\0')
|
||||
printf("pfsync: syncdev: %s ", preq.pfsyncr_syncdev);
|
||||
if (preq.pfsyncr_syncpeer.s_addr != INADDR_PFSYNC_GROUP)
|
||||
printf("syncpeer: %s ", inet_ntoa(preq.pfsyncr_syncpeer));
|
||||
|
||||
if (preq.pfsyncr_syncdev[0] != '\0' ||
|
||||
preq.pfsyncr_syncpeer.s_addr != INADDR_PFSYNC_GROUP) {
|
||||
printf("maxupd: %d ", preq.pfsyncr_maxupdates);
|
||||
printf("defer: %s\n", preq.pfsyncr_defer ? "on" : "off");
|
||||
}
|
||||
}
|
||||
|
||||
static struct cmd pfsync_cmds[] = {
|
||||
DEF_CMD_ARG("syncdev", setpfsync_syncdev),
|
||||
DEF_CMD("-syncdev", 1, unsetpfsync_syncdev),
|
||||
DEF_CMD_ARG("syncif", setpfsync_syncdev),
|
||||
DEF_CMD("-syncif", 1, unsetpfsync_syncdev),
|
||||
DEF_CMD_ARG("syncpeer", setpfsync_syncpeer),
|
||||
DEF_CMD("-syncpeer", 1, unsetpfsync_syncpeer),
|
||||
DEF_CMD_ARG("maxupd", setpfsync_maxupd),
|
||||
DEF_CMD("defer", 1, setpfsync_defer),
|
||||
DEF_CMD("-defer", 0, setpfsync_defer),
|
||||
};
|
||||
static struct afswtch af_pfsync = {
|
||||
.af_name = "af_pfsync",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = pfsync_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
pfsync_ctor(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems(pfsync_cmds); i++)
|
||||
cmd_register(&pfsync_cmds[i]);
|
||||
af_register(&af_pfsync);
|
||||
}
|
|
@ -0,0 +1,259 @@
|
|||
/*
|
||||
* Copyright (c) 1999 Bill Paul <wpaul@ctr.columbia.edu>
|
||||
* Copyright (c) 2012 ADARA Networks, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Portions of this software were developed by Robert N. M. Watson under
|
||||
* contract to ADARA Networks, Inc.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Bill Paul.
|
||||
* 4. Neither the name of the author nor the names of any co-contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD
|
||||
* 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/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_vlan_var.h>
|
||||
#include <net/route.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#define NOTAG ((u_short) -1)
|
||||
|
||||
static struct vlanreq params = {
|
||||
.vlr_tag = NOTAG,
|
||||
};
|
||||
|
||||
static int
|
||||
getvlan(int s, struct ifreq *ifr, struct vlanreq *vreq)
|
||||
{
|
||||
bzero((char *)vreq, sizeof(*vreq));
|
||||
ifr->ifr_data = (caddr_t)vreq;
|
||||
|
||||
#ifndef FSTACK
|
||||
return ioctl(s, SIOCGETVLAN, (caddr_t)ifr);
|
||||
#else
|
||||
size_t offset = (char *)&(ifr->ifr_data) - (char *)ifr;
|
||||
size_t clen = sizeof(*vreq);
|
||||
return ioctl_va(s, SIOCGETVLAN, (caddr_t)ifr, 3, offset, ifr->ifr_data, clen);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
vlan_status(int s)
|
||||
{
|
||||
struct vlanreq vreq;
|
||||
|
||||
if (getvlan(s, &ifr, &vreq) == -1)
|
||||
return;
|
||||
printf("\tvlan: %d", vreq.vlr_tag);
|
||||
|
||||
if (ioctl(s, SIOCGVLANPCP, (caddr_t)&ifr) != -1)
|
||||
printf(" vlanpcp: %u", ifr.ifr_vlan_pcp);
|
||||
printf(" parent interface: %s", vreq.vlr_parent[0] == '\0' ?
|
||||
"<none>" : vreq.vlr_parent);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
vlan_create(int s, struct ifreq *ifr)
|
||||
{
|
||||
if (params.vlr_tag != NOTAG || params.vlr_parent[0] != '\0') {
|
||||
/*
|
||||
* One or both parameters were specified, make sure both.
|
||||
*/
|
||||
if (params.vlr_tag == NOTAG)
|
||||
errx(1, "must specify a tag for vlan create");
|
||||
if (params.vlr_parent[0] == '\0')
|
||||
errx(1, "must specify a parent device for vlan create");
|
||||
ifr->ifr_data = (caddr_t) ¶ms;
|
||||
#ifdef FSTACK
|
||||
size_t offset = (char *)&(ifr->ifr_data) - (char *)ifr;
|
||||
size_t clen = sizeof(params);
|
||||
if (ioctl_va(s, SIOCIFCREATE2, ifr, 3, offset, ifr->ifr_data, clen) < 0)
|
||||
err(1, "SIOCIFCREATE2");
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
|
||||
err(1, "SIOCIFCREATE2");
|
||||
}
|
||||
|
||||
static void
|
||||
vlan_cb(int s, void *arg)
|
||||
{
|
||||
if ((params.vlr_tag != NOTAG) ^ (params.vlr_parent[0] != '\0'))
|
||||
errx(1, "both vlan and vlandev must be specified");
|
||||
}
|
||||
|
||||
static void
|
||||
vlan_set(int s, struct ifreq *ifr)
|
||||
{
|
||||
if (params.vlr_tag != NOTAG && params.vlr_parent[0] != '\0') {
|
||||
ifr->ifr_data = (caddr_t) ¶ms;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCSETVLAN, (caddr_t)ifr) == -1)
|
||||
#else
|
||||
size_t offset = (char *)&(ifr->ifr_data) - (char *)ifr;
|
||||
size_t clen = sizeof(params);
|
||||
if (ioctl_va(s, SIOCSETVLAN, ifr, 3, offset, ifr->ifr_data, clen) == -1)
|
||||
#endif
|
||||
err(1, "SIOCSETVLAN");
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvlantag, val, d)
|
||||
{
|
||||
struct vlanreq vreq;
|
||||
u_long ul;
|
||||
char *endp;
|
||||
|
||||
ul = strtoul(val, &endp, 0);
|
||||
if (*endp != '\0')
|
||||
errx(1, "invalid value for vlan");
|
||||
params.vlr_tag = ul;
|
||||
/* check if the value can be represented in vlr_tag */
|
||||
if (params.vlr_tag != ul)
|
||||
errx(1, "value for vlan out of range");
|
||||
|
||||
if (getvlan(s, &ifr, &vreq) != -1)
|
||||
vlan_set(s, &ifr);
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvlandev, val, d)
|
||||
{
|
||||
struct vlanreq vreq;
|
||||
|
||||
strlcpy(params.vlr_parent, val, sizeof(params.vlr_parent));
|
||||
|
||||
if (getvlan(s, &ifr, &vreq) != -1)
|
||||
vlan_set(s, &ifr);
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvlanpcp, val, d)
|
||||
{
|
||||
u_long ul;
|
||||
char *endp;
|
||||
|
||||
ul = strtoul(val, &endp, 0);
|
||||
if (*endp != '\0')
|
||||
errx(1, "invalid value for vlanpcp");
|
||||
if (ul > 7)
|
||||
errx(1, "value for vlanpcp out of range");
|
||||
ifr.ifr_vlan_pcp = ul;
|
||||
if (ioctl(s, SIOCSVLANPCP, (caddr_t)&ifr) == -1)
|
||||
err(1, "SIOCSVLANPCP");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(unsetvlandev, val, d)
|
||||
{
|
||||
struct vlanreq vreq;
|
||||
|
||||
bzero((char *)&vreq, sizeof(struct vlanreq));
|
||||
ifr.ifr_data = (caddr_t)&vreq;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
|
||||
#else
|
||||
size_t offset = (char *)&(ifr.ifr_data) - (char *)&(ifr);
|
||||
size_t clen = sizeof(vreq);
|
||||
if (ioctl_va(s, SIOCGETVLAN, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) == -1)
|
||||
#endif
|
||||
err(1, "SIOCGETVLAN");
|
||||
|
||||
bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent));
|
||||
vreq.vlr_tag = 0;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
|
||||
#else
|
||||
if (ioctl_va(s, SIOCSETVLAN, (caddr_t)&ifr, 3, offset, ifr.ifr_data, clen) == -1)
|
||||
#endif
|
||||
err(1, "SIOCSETVLAN");
|
||||
}
|
||||
|
||||
static struct cmd vlan_cmds[] = {
|
||||
DEF_CLONE_CMD_ARG("vlan", setvlantag),
|
||||
DEF_CLONE_CMD_ARG("vlandev", setvlandev),
|
||||
DEF_CMD_ARG("vlanpcp", setvlanpcp),
|
||||
/* NB: non-clone cmds */
|
||||
DEF_CMD_ARG("vlan", setvlantag),
|
||||
DEF_CMD_ARG("vlandev", setvlandev),
|
||||
/* XXX For compatibility. Should become DEF_CMD() some day. */
|
||||
DEF_CMD_OPTARG("-vlandev", unsetvlandev),
|
||||
DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap),
|
||||
DEF_CMD("-vlanmtu", -IFCAP_VLAN_MTU, setifcap),
|
||||
DEF_CMD("vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap),
|
||||
DEF_CMD("-vlanhwtag", -IFCAP_VLAN_HWTAGGING, setifcap),
|
||||
DEF_CMD("vlanhwfilter", IFCAP_VLAN_HWFILTER, setifcap),
|
||||
DEF_CMD("-vlanhwfilter", -IFCAP_VLAN_HWFILTER, setifcap),
|
||||
DEF_CMD("-vlanhwtso", -IFCAP_VLAN_HWTSO, setifcap),
|
||||
DEF_CMD("vlanhwtso", IFCAP_VLAN_HWTSO, setifcap),
|
||||
DEF_CMD("vlanhwcsum", IFCAP_VLAN_HWCSUM, setifcap),
|
||||
DEF_CMD("-vlanhwcsum", -IFCAP_VLAN_HWCSUM, setifcap),
|
||||
};
|
||||
static struct afswtch af_vlan = {
|
||||
.af_name = "af_vlan",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = vlan_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
vlan_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(vlan_cmds); i++)
|
||||
cmd_register(&vlan_cmds[i]);
|
||||
af_register(&af_vlan);
|
||||
callback_register(vlan_cb, NULL);
|
||||
clone_setdefcallback("vlan", vlan_create);
|
||||
}
|
|
@ -0,0 +1,673 @@
|
|||
/*-
|
||||
* Copyright (c) 2014, Bryan Venteicher <bryanv@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 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 ``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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef FSTACK
|
||||
__FBSDID("$FreeBSD$");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_vxlan.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
#ifdef FSTACK
|
||||
#include "arpa/inet.h"
|
||||
#endif
|
||||
|
||||
static struct ifvxlanparam params = {
|
||||
.vxlp_vni = VXLAN_VNI_MAX,
|
||||
};
|
||||
|
||||
static int
|
||||
get_val(const char *cp, u_long *valp)
|
||||
{
|
||||
char *endptr;
|
||||
u_long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoul(cp, &endptr, 0);
|
||||
if (cp[0] == '\0' || endptr[0] != '\0' || errno == ERANGE)
|
||||
return (-1);
|
||||
|
||||
*valp = val;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
do_cmd(int sock, u_long op, void *arg, size_t argsize, int set)
|
||||
{
|
||||
struct ifdrv ifd;
|
||||
|
||||
bzero(&ifd, sizeof(ifd));
|
||||
|
||||
strlcpy(ifd.ifd_name, ifr.ifr_name, sizeof(ifd.ifd_name));
|
||||
ifd.ifd_cmd = op;
|
||||
ifd.ifd_len = argsize;
|
||||
ifd.ifd_data = arg;
|
||||
|
||||
#ifndef FSTACK
|
||||
return (ioctl(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd));
|
||||
#else
|
||||
size_t offset = (char *)&(ifd.ifd_data) - (char *)&(ifd);
|
||||
return (ioctl_va(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd,
|
||||
3, offset, ifd.ifd_data, argsize));
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
vxlan_exists(int sock)
|
||||
{
|
||||
struct ifvxlancfg cfg;
|
||||
|
||||
bzero(&cfg, sizeof(cfg));
|
||||
|
||||
return (do_cmd(sock, VXLAN_CMD_GET_CONFIG, &cfg, sizeof(cfg), 0) != -1);
|
||||
}
|
||||
|
||||
static void
|
||||
vxlan_status(int s)
|
||||
{
|
||||
struct ifvxlancfg cfg;
|
||||
char src[NI_MAXHOST], dst[NI_MAXHOST];
|
||||
char srcport[NI_MAXSERV], dstport[NI_MAXSERV];
|
||||
struct sockaddr *lsa, *rsa;
|
||||
int vni, mc, ipv6;
|
||||
|
||||
bzero(&cfg, sizeof(cfg));
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_GET_CONFIG, &cfg, sizeof(cfg), 0) < 0)
|
||||
return;
|
||||
|
||||
vni = cfg.vxlc_vni;
|
||||
lsa = &cfg.vxlc_local_sa.sa;
|
||||
rsa = &cfg.vxlc_remote_sa.sa;
|
||||
ipv6 = rsa->sa_family == AF_INET6;
|
||||
|
||||
/* Just report nothing if the network identity isn't set yet. */
|
||||
if (vni >= VXLAN_VNI_MAX)
|
||||
return;
|
||||
|
||||
#ifndef FSTACK
|
||||
if (getnameinfo(lsa, lsa->sa_len, src, sizeof(src),
|
||||
srcport, sizeof(srcport), NI_NUMERICHOST | NI_NUMERICSERV) != 0)
|
||||
src[0] = srcport[0] = '\0';
|
||||
if (getnameinfo(rsa, rsa->sa_len, dst, sizeof(dst),
|
||||
dstport, sizeof(dstport), NI_NUMERICHOST | NI_NUMERICSERV) != 0)
|
||||
dst[0] = dstport[0] = '\0';
|
||||
#else
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)lsa;
|
||||
if (inet_ntop(AF_INET, &sin->sin_addr, src, sizeof(src)) == NULL)
|
||||
return;
|
||||
|
||||
sin = (struct sockaddr_in *)rsa;
|
||||
if (inet_ntop(AF_INET, &sin->sin_addr, dst, sizeof(dst)) == NULL)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!ipv6) {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)rsa;
|
||||
mc = IN_MULTICAST(ntohl(sin->sin_addr.s_addr));
|
||||
} else {
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)rsa;
|
||||
mc = IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr);
|
||||
}
|
||||
|
||||
printf("\tvxlan vni %d", vni);
|
||||
printf(" local %s%s%s:%s", ipv6 ? "[" : "", src, ipv6 ? "]" : "",
|
||||
srcport);
|
||||
printf(" %s %s%s%s:%s", mc ? "group" : "remote", ipv6 ? "[" : "",
|
||||
dst, ipv6 ? "]" : "", dstport);
|
||||
|
||||
if (verbose) {
|
||||
printf("\n\t\tconfig: ");
|
||||
printf("%slearning portrange %d-%d ttl %d",
|
||||
cfg.vxlc_learn ? "" : "no", cfg.vxlc_port_min,
|
||||
cfg.vxlc_port_max, cfg.vxlc_ttl);
|
||||
printf("\n\t\tftable: ");
|
||||
printf("cnt %d max %d timeout %d",
|
||||
cfg.vxlc_ftable_cnt, cfg.vxlc_ftable_max,
|
||||
cfg.vxlc_ftable_timeout);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
#define _LOCAL_ADDR46 \
|
||||
(VXLAN_PARAM_WITH_LOCAL_ADDR4 | VXLAN_PARAM_WITH_LOCAL_ADDR6)
|
||||
#define _REMOTE_ADDR46 \
|
||||
(VXLAN_PARAM_WITH_REMOTE_ADDR4 | VXLAN_PARAM_WITH_REMOTE_ADDR6)
|
||||
|
||||
static void
|
||||
vxlan_check_params(void)
|
||||
{
|
||||
|
||||
if ((params.vxlp_with & _LOCAL_ADDR46) == _LOCAL_ADDR46)
|
||||
errx(1, "cannot specify both local IPv4 and IPv6 addresses");
|
||||
if ((params.vxlp_with & _REMOTE_ADDR46) == _REMOTE_ADDR46)
|
||||
errx(1, "cannot specify both remote IPv4 and IPv6 addresses");
|
||||
if ((params.vxlp_with & VXLAN_PARAM_WITH_LOCAL_ADDR4 &&
|
||||
params.vxlp_with & VXLAN_PARAM_WITH_REMOTE_ADDR6) ||
|
||||
(params.vxlp_with & VXLAN_PARAM_WITH_LOCAL_ADDR6 &&
|
||||
params.vxlp_with & VXLAN_PARAM_WITH_REMOTE_ADDR4))
|
||||
errx(1, "cannot mix IPv4 and IPv6 addresses");
|
||||
}
|
||||
|
||||
#undef _LOCAL_ADDR46
|
||||
#undef _REMOTE_ADDR46
|
||||
|
||||
static void
|
||||
vxlan_cb(int s, void *arg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vxlan_create(int s, struct ifreq *ifr)
|
||||
{
|
||||
|
||||
vxlan_check_params();
|
||||
|
||||
ifr->ifr_data = (caddr_t) ¶ms;
|
||||
#ifndef FSTACK
|
||||
if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
|
||||
#else
|
||||
size_t offset = (char *)&(ifr->ifr_data) - (char *)ifr;
|
||||
size_t clen = sizeof(params);
|
||||
if (ioctl_va(s, SIOCIFCREATE2, ifr, 3, offset, ifr->ifr_data, clen) < 0)
|
||||
#endif
|
||||
err(1, "SIOCIFCREATE2");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_vni, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || val >= VXLAN_VNI_MAX)
|
||||
errx(1, "invalid network identifier: %s", arg);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_VNI;
|
||||
params.vxlp_vni = val;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
cmd.vxlcmd_vni = val;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_VNI, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_VNI");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_local, addr, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
struct addrinfo *ai;
|
||||
struct sockaddr *sa;
|
||||
int error;
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
|
||||
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
|
||||
errx(1, "error in parsing local address string: %s",
|
||||
gai_strerror(error));
|
||||
|
||||
sa = ai->ai_addr;
|
||||
|
||||
switch (ai->ai_family) {
|
||||
#ifdef INET
|
||||
case AF_INET: {
|
||||
struct in_addr addr = ((struct sockaddr_in *) sa)->sin_addr;
|
||||
|
||||
if (IN_MULTICAST(ntohl(addr.s_addr)))
|
||||
errx(1, "local address cannot be multicast");
|
||||
|
||||
cmd.vxlcmd_sa.in4.sin_family = AF_INET;
|
||||
cmd.vxlcmd_sa.in4.sin_addr = addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef INET6
|
||||
case AF_INET6: {
|
||||
struct in6_addr *addr = &((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
|
||||
if (IN6_IS_ADDR_MULTICAST(addr))
|
||||
errx(1, "local address cannot be multicast");
|
||||
|
||||
cmd.vxlcmd_sa.in6.sin6_family = AF_INET6;
|
||||
cmd.vxlcmd_sa.in6.sin6_addr = *addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
errx(1, "local address %s not supported", addr);
|
||||
}
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
if (cmd.vxlcmd_sa.sa.sa_family == AF_INET) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_LOCAL_ADDR4;
|
||||
params.vxlp_local_in4 = cmd.vxlcmd_sa.in4.sin_addr;
|
||||
} else {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_LOCAL_ADDR6;
|
||||
params.vxlp_local_in6 = cmd.vxlcmd_sa.in6.sin6_addr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_LOCAL_ADDR, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_LOCAL_ADDR");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_remote, addr, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
struct addrinfo *ai;
|
||||
struct sockaddr *sa;
|
||||
int error;
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
|
||||
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
|
||||
errx(1, "error in parsing remote address string: %s",
|
||||
gai_strerror(error));
|
||||
|
||||
sa = ai->ai_addr;
|
||||
|
||||
switch (ai->ai_family) {
|
||||
#ifdef INET
|
||||
case AF_INET: {
|
||||
struct in_addr addr = ((struct sockaddr_in *)sa)->sin_addr;
|
||||
|
||||
if (IN_MULTICAST(ntohl(addr.s_addr)))
|
||||
errx(1, "remote address cannot be multicast");
|
||||
|
||||
cmd.vxlcmd_sa.in4.sin_family = AF_INET;
|
||||
cmd.vxlcmd_sa.in4.sin_addr = addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef INET6
|
||||
case AF_INET6: {
|
||||
struct in6_addr *addr = &((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
|
||||
if (IN6_IS_ADDR_MULTICAST(addr))
|
||||
errx(1, "remote address cannot be multicast");
|
||||
|
||||
cmd.vxlcmd_sa.in6.sin6_family = AF_INET6;
|
||||
cmd.vxlcmd_sa.in6.sin6_addr = *addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
errx(1, "remote address %s not supported", addr);
|
||||
}
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
if (cmd.vxlcmd_sa.sa.sa_family == AF_INET) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_REMOTE_ADDR4;
|
||||
params.vxlp_remote_in4 = cmd.vxlcmd_sa.in4.sin_addr;
|
||||
} else {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_REMOTE_ADDR6;
|
||||
params.vxlp_remote_in6 = cmd.vxlcmd_sa.in6.sin6_addr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_REMOTE_ADDR, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_group, addr, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
struct addrinfo *ai;
|
||||
struct sockaddr *sa;
|
||||
int error;
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
|
||||
if ((error = getaddrinfo(addr, NULL, NULL, &ai)) != 0)
|
||||
errx(1, "error in parsing group address string: %s",
|
||||
gai_strerror(error));
|
||||
|
||||
sa = ai->ai_addr;
|
||||
|
||||
switch (ai->ai_family) {
|
||||
#ifdef INET
|
||||
case AF_INET: {
|
||||
struct in_addr addr = ((struct sockaddr_in *)sa)->sin_addr;
|
||||
|
||||
if (!IN_MULTICAST(ntohl(addr.s_addr)))
|
||||
errx(1, "group address must be multicast");
|
||||
|
||||
cmd.vxlcmd_sa.in4.sin_family = AF_INET;
|
||||
cmd.vxlcmd_sa.in4.sin_addr = addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef INET6
|
||||
case AF_INET6: {
|
||||
struct in6_addr *addr = &((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
|
||||
if (!IN6_IS_ADDR_MULTICAST(addr))
|
||||
errx(1, "group address must be multicast");
|
||||
|
||||
cmd.vxlcmd_sa.in6.sin6_family = AF_INET6;
|
||||
cmd.vxlcmd_sa.in6.sin6_addr = *addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
errx(1, "group address %s not supported", addr);
|
||||
}
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
if (cmd.vxlcmd_sa.sa.sa_family == AF_INET) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_REMOTE_ADDR4;
|
||||
params.vxlp_remote_in4 = cmd.vxlcmd_sa.in4.sin_addr;
|
||||
} else {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_REMOTE_ADDR6;
|
||||
params.vxlp_remote_in6 = cmd.vxlcmd_sa.in6.sin6_addr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_REMOTE_ADDR, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_REMOTE_ADDR");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_local_port, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
|
||||
errx(1, "invalid local port: %s", arg);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_LOCAL_PORT;
|
||||
params.vxlp_local_port = val;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
cmd.vxlcmd_port = val;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_LOCAL_PORT, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_LOCAL_PORT");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_remote_port, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || val >= UINT16_MAX)
|
||||
errx(1, "invalid remote port: %s", arg);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_REMOTE_PORT;
|
||||
params.vxlp_remote_port = val;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
cmd.vxlcmd_port = val;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_REMOTE_PORT, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_REMOTE_PORT");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC2(setvxlan_port_range, arg1, arg2)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
u_long min, max;
|
||||
|
||||
if (get_val(arg1, &min) < 0 || min >= UINT16_MAX)
|
||||
errx(1, "invalid port range minimum: %s", arg1);
|
||||
if (get_val(arg2, &max) < 0 || max >= UINT16_MAX)
|
||||
errx(1, "invalid port range maximum: %s", arg2);
|
||||
if (max < min)
|
||||
errx(1, "invalid port range");
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_PORT_RANGE;
|
||||
params.vxlp_min_port = min;
|
||||
params.vxlp_max_port = max;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
cmd.vxlcmd_port_min = min;
|
||||
cmd.vxlcmd_port_max = max;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_PORT_RANGE, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_PORT_RANGE");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_timeout, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
|
||||
errx(1, "invalid timeout value: %s", arg);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_FTABLE_TIMEOUT;
|
||||
params.vxlp_ftable_timeout = val & 0xFFFFFFFF;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
cmd.vxlcmd_ftable_timeout = val & 0xFFFFFFFF;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_FTABLE_TIMEOUT, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_FTABLE_TIMEOUT");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_maxaddr, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || (val & ~0xFFFFFFFF) != 0)
|
||||
errx(1, "invalid maxaddr value: %s", arg);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_FTABLE_MAX;
|
||||
params.vxlp_ftable_max = val & 0xFFFFFFFF;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
cmd.vxlcmd_ftable_max = val & 0xFFFFFFFF;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_FTABLE_MAX, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_FTABLE_MAX");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_dev, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_MULTICAST_IF;
|
||||
strlcpy(params.vxlp_mc_ifname, arg,
|
||||
sizeof(params.vxlp_mc_ifname));
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
strlcpy(cmd.vxlcmd_ifname, arg, sizeof(cmd.vxlcmd_ifname));
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_MULTICAST_IF, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_MULTICAST_IF");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_ttl, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
u_long val;
|
||||
|
||||
if (get_val(arg, &val) < 0 || val > 256)
|
||||
errx(1, "invalid TTL value: %s", arg);
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_TTL;
|
||||
params.vxlp_ttl = val;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
cmd.vxlcmd_ttl = val;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_TTL, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_TTL");
|
||||
}
|
||||
|
||||
static
|
||||
DECL_CMD_FUNC(setvxlan_learn, arg, d)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
|
||||
if (!vxlan_exists(s)) {
|
||||
params.vxlp_with |= VXLAN_PARAM_WITH_LEARN;
|
||||
params.vxlp_learn = d;
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
if (d != 0)
|
||||
cmd.vxlcmd_flags |= VXLAN_CMD_FLAG_LEARN;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_SET_LEARN, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_SET_LEARN");
|
||||
}
|
||||
|
||||
static void
|
||||
setvxlan_flush(const char *val, int d, int s, const struct afswtch *afp)
|
||||
{
|
||||
struct ifvxlancmd cmd;
|
||||
|
||||
bzero(&cmd, sizeof(cmd));
|
||||
if (d != 0)
|
||||
cmd.vxlcmd_flags |= VXLAN_CMD_FLAG_FLUSH_ALL;
|
||||
|
||||
if (do_cmd(s, VXLAN_CMD_FLUSH, &cmd, sizeof(cmd), 1) < 0)
|
||||
err(1, "VXLAN_CMD_FLUSH");
|
||||
}
|
||||
|
||||
static struct cmd vxlan_cmds[] = {
|
||||
|
||||
DEF_CLONE_CMD_ARG("vxlanid", setvxlan_vni),
|
||||
DEF_CLONE_CMD_ARG("vxlanlocal", setvxlan_local),
|
||||
DEF_CLONE_CMD_ARG("vxlanremote", setvxlan_remote),
|
||||
DEF_CLONE_CMD_ARG("vxlangroup", setvxlan_group),
|
||||
DEF_CLONE_CMD_ARG("vxlanlocalport", setvxlan_local_port),
|
||||
DEF_CLONE_CMD_ARG("vxlanremoteport", setvxlan_remote_port),
|
||||
DEF_CLONE_CMD_ARG2("vxlanportrange", setvxlan_port_range),
|
||||
DEF_CLONE_CMD_ARG("vxlantimeout", setvxlan_timeout),
|
||||
DEF_CLONE_CMD_ARG("vxlanmaxaddr", setvxlan_maxaddr),
|
||||
DEF_CLONE_CMD_ARG("vxlandev", setvxlan_dev),
|
||||
DEF_CLONE_CMD_ARG("vxlanttl", setvxlan_ttl),
|
||||
DEF_CLONE_CMD("vxlanlearn", 1, setvxlan_learn),
|
||||
DEF_CLONE_CMD("-vxlanlearn", 0, setvxlan_learn),
|
||||
|
||||
DEF_CMD_ARG("vxlanvni", setvxlan_vni),
|
||||
DEF_CMD_ARG("vxlanlocal", setvxlan_local),
|
||||
DEF_CMD_ARG("vxlanremote", setvxlan_remote),
|
||||
DEF_CMD_ARG("vxlangroup", setvxlan_group),
|
||||
DEF_CMD_ARG("vxlanlocalport", setvxlan_local_port),
|
||||
DEF_CMD_ARG("vxlanremoteport", setvxlan_remote_port),
|
||||
DEF_CMD_ARG2("vxlanportrange", setvxlan_port_range),
|
||||
DEF_CMD_ARG("vxlantimeout", setvxlan_timeout),
|
||||
DEF_CMD_ARG("vxlanmaxaddr", setvxlan_maxaddr),
|
||||
DEF_CMD_ARG("vxlandev", setvxlan_dev),
|
||||
DEF_CMD_ARG("vxlanttl", setvxlan_ttl),
|
||||
DEF_CMD("vxlanlearn", 1, setvxlan_learn),
|
||||
DEF_CMD("-vxlanlearn", 0, setvxlan_learn),
|
||||
|
||||
DEF_CMD("vxlanflush", 0, setvxlan_flush),
|
||||
DEF_CMD("vxlanflushall", 1, setvxlan_flush),
|
||||
};
|
||||
|
||||
static struct afswtch af_vxlan = {
|
||||
.af_name = "af_vxlan",
|
||||
.af_af = AF_UNSPEC,
|
||||
.af_other_status = vxlan_status,
|
||||
};
|
||||
|
||||
static __constructor void
|
||||
vxlan_ctor(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nitems(vxlan_cmds); i++)
|
||||
cmd_register(&vxlan_cmds[i]);
|
||||
af_register(&af_vxlan);
|
||||
callback_register(vxlan_cb, NULL);
|
||||
clone_setdefcallback("vxlan", vxlan_create);
|
||||
}
|
|
@ -0,0 +1,916 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 Alexander V. Chernikov. 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/sff8436.h>
|
||||
#include <net/sff8472.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ifconfig.h"
|
||||
|
||||
struct i2c_info {
|
||||
int fd; /* fd to issue SIOCGI2C */
|
||||
int error; /* Store first error */
|
||||
int qsfp; /* True if transceiver is QSFP */
|
||||
int do_diag; /* True if we need to request DDM */
|
||||
struct ifreq *ifr; /* Pointer to pre-filled ifreq */
|
||||
};
|
||||
|
||||
static int read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off,
|
||||
uint8_t len, uint8_t *buf);
|
||||
static void dump_i2c_data(struct i2c_info *ii, uint8_t addr, uint8_t off,
|
||||
uint8_t len);
|
||||
|
||||
struct _nv {
|
||||
int v;
|
||||
const char *n;
|
||||
};
|
||||
|
||||
const char *find_value(struct _nv *x, int value);
|
||||
const char *find_zero_bit(struct _nv *x, int value, int sz);
|
||||
|
||||
/* SFF-8472 Rev. 11.4 table 3.4: Connector values */
|
||||
static struct _nv conn[] = {
|
||||
{ 0x00, "Unknown" },
|
||||
{ 0x01, "SC" },
|
||||
{ 0x02, "Fibre Channel Style 1 copper" },
|
||||
{ 0x03, "Fibre Channel Style 2 copper" },
|
||||
{ 0x04, "BNC/TNC" },
|
||||
{ 0x05, "Fibre Channel coaxial" },
|
||||
{ 0x06, "FiberJack" },
|
||||
{ 0x07, "LC" },
|
||||
{ 0x08, "MT-RJ" },
|
||||
{ 0x09, "MU" },
|
||||
{ 0x0A, "SG" },
|
||||
{ 0x0B, "Optical pigtail" },
|
||||
{ 0x0C, "MPO Parallel Optic" },
|
||||
{ 0x20, "HSSDC II" },
|
||||
{ 0x21, "Copper pigtail" },
|
||||
{ 0x22, "RJ45" },
|
||||
{ 0x23, "No separate connector" }, /* SFF-8436 */
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* SFF-8472 Rev. 11.4 table 3.5: Transceiver codes */
|
||||
/* 10G Ethernet/IB compliance codes, byte 3 */
|
||||
static struct _nv eth_10g[] = {
|
||||
{ 0x80, "10G Base-ER" },
|
||||
{ 0x40, "10G Base-LRM" },
|
||||
{ 0x20, "10G Base-LR" },
|
||||
{ 0x10, "10G Base-SR" },
|
||||
{ 0x08, "1X SX" },
|
||||
{ 0x04, "1X LX" },
|
||||
{ 0x02, "1X Copper Active" },
|
||||
{ 0x01, "1X Copper Passive" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* Ethernet compliance codes, byte 6 */
|
||||
static struct _nv eth_compat[] = {
|
||||
{ 0x80, "BASE-PX" },
|
||||
{ 0x40, "BASE-BX10" },
|
||||
{ 0x20, "100BASE-FX" },
|
||||
{ 0x10, "100BASE-LX/LX10" },
|
||||
{ 0x08, "1000BASE-T" },
|
||||
{ 0x04, "1000BASE-CX" },
|
||||
{ 0x02, "1000BASE-LX" },
|
||||
{ 0x01, "1000BASE-SX" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* FC link length, byte 7 */
|
||||
static struct _nv fc_len[] = {
|
||||
{ 0x80, "very long distance" },
|
||||
{ 0x40, "short distance" },
|
||||
{ 0x20, "intermediate distance" },
|
||||
{ 0x10, "long distance" },
|
||||
{ 0x08, "medium distance" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* Channel/Cable technology, byte 7-8 */
|
||||
static struct _nv cab_tech[] = {
|
||||
{ 0x0400, "Shortwave laser (SA)" },
|
||||
{ 0x0200, "Longwave laser (LC)" },
|
||||
{ 0x0100, "Electrical inter-enclosure (EL)" },
|
||||
{ 0x80, "Electrical intra-enclosure (EL)" },
|
||||
{ 0x40, "Shortwave laser (SN)" },
|
||||
{ 0x20, "Shortwave laser (SL)" },
|
||||
{ 0x10, "Longwave laser (LL)" },
|
||||
{ 0x08, "Active Cable" },
|
||||
{ 0x04, "Passive Cable" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* FC Transmission media, byte 9 */
|
||||
static struct _nv fc_media[] = {
|
||||
{ 0x80, "Twin Axial Pair" },
|
||||
{ 0x40, "Twisted Pair" },
|
||||
{ 0x20, "Miniature Coax" },
|
||||
{ 0x10, "Viao Coax" },
|
||||
{ 0x08, "Miltimode, 62.5um" },
|
||||
{ 0x04, "Multimode, 50um" },
|
||||
{ 0x02, "" },
|
||||
{ 0x01, "Single Mode" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* FC Speed, byte 10 */
|
||||
static struct _nv fc_speed[] = {
|
||||
{ 0x80, "1200 MBytes/sec" },
|
||||
{ 0x40, "800 MBytes/sec" },
|
||||
{ 0x20, "1600 MBytes/sec" },
|
||||
{ 0x10, "400 MBytes/sec" },
|
||||
{ 0x08, "3200 MBytes/sec" },
|
||||
{ 0x04, "200 MBytes/sec" },
|
||||
{ 0x01, "100 MBytes/sec" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* SFF-8436 Rev. 4.8 table 33: Specification compliance */
|
||||
|
||||
/* 10/40G Ethernet compliance codes, byte 128 + 3 */
|
||||
static struct _nv eth_1040g[] = {
|
||||
{ 0x80, "Extended" },
|
||||
{ 0x40, "10GBASE-LRM" },
|
||||
{ 0x20, "10GBASE-LR" },
|
||||
{ 0x10, "10GBASE-SR" },
|
||||
{ 0x08, "40GBASE-CR4" },
|
||||
{ 0x04, "40GBASE-SR4" },
|
||||
{ 0x02, "40GBASE-LR4" },
|
||||
{ 0x01, "40G Active Cable" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
#define SFF_8636_EXT_COMPLIANCE 0x80
|
||||
|
||||
/* SFF-8024 Rev. 3.4 table 4.4: Extended Specification Compliance */
|
||||
static struct _nv eth_extended_comp[] = {
|
||||
{ 0xFF, "Reserved" },
|
||||
{ 0x1A, "2 lambda DWDM 100G" },
|
||||
{ 0x19, "100G ACC or 25GAUI C2M ACC" },
|
||||
{ 0x18, "100G AOC or 25GAUI C2M AOC" },
|
||||
{ 0x17, "100G CLR4" },
|
||||
{ 0x16, "10GBASE-T with SFI electrical interface" },
|
||||
{ 0x15, "G959.1 profile P1L1-2D2" },
|
||||
{ 0x14, "G959.1 profile P1S1-2D2" },
|
||||
{ 0x13, "G959.1 profile P1I1-2D1" },
|
||||
{ 0x12, "40G PSM4 Parallel SMF" },
|
||||
{ 0x11, "4 x 10GBASE-SR" },
|
||||
{ 0x10, "40GBASE-ER4" },
|
||||
{ 0x0F, "Reserved" },
|
||||
{ 0x0D, "25GBASE-CR CA-N" },
|
||||
{ 0x0C, "25GBASE-CR CA-S" },
|
||||
{ 0x0B, "100GBASE-CR4 or 25GBASE-CR CA-L" },
|
||||
{ 0x0A, "Reserved" },
|
||||
{ 0x09, "100G CWDM4 MSA without FEC" },
|
||||
{ 0x08, "100G ACC (Active Copper Cable)" },
|
||||
{ 0x07, "100G PSM4 Parallel SMF" },
|
||||
{ 0x06, "100G CWDM4 MSA with FEC" },
|
||||
{ 0x05, "100GBASE-SR10" },
|
||||
{ 0x04, "100GBASE-ER4" },
|
||||
{ 0x03, "100GBASE-LR4" },
|
||||
{ 0x02, "100GBASE-SR4" },
|
||||
{ 0x01, "100G AOC (Active Optical Cable) or 25GAUI C2M ACC" },
|
||||
{ 0x00, "Unspecified" }
|
||||
};
|
||||
|
||||
/* SFF-8636 Rev. 2.5 table 6.3: Revision compliance */
|
||||
static struct _nv rev_compl[] = {
|
||||
{ 0x1, "SFF-8436 rev <=4.8" },
|
||||
{ 0x2, "SFF-8436 rev <=4.8" },
|
||||
{ 0x3, "SFF-8636 rev <=1.3" },
|
||||
{ 0x4, "SFF-8636 rev <=1.4" },
|
||||
{ 0x5, "SFF-8636 rev <=1.5" },
|
||||
{ 0x6, "SFF-8636 rev <=2.0" },
|
||||
{ 0x7, "SFF-8636 rev <=2.5" },
|
||||
{ 0x0, "Unspecified" }
|
||||
};
|
||||
|
||||
const char *
|
||||
find_value(struct _nv *x, int value)
|
||||
{
|
||||
for (; x->n != NULL; x++)
|
||||
if (x->v == value)
|
||||
return (x->n);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
find_zero_bit(struct _nv *x, int value, int sz)
|
||||
{
|
||||
int v, m;
|
||||
const char *s;
|
||||
|
||||
v = 1;
|
||||
for (v = 1, m = 1 << (8 * sz); v < m; v *= 2) {
|
||||
if ((value & v) == 0)
|
||||
continue;
|
||||
if ((s = find_value(x, value & v)) != NULL) {
|
||||
value &= ~v;
|
||||
return (s);
|
||||
}
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_sff_identifier(char *buf, size_t size, uint8_t value)
|
||||
{
|
||||
const char *x;
|
||||
|
||||
x = NULL;
|
||||
if (value <= SFF_8024_ID_LAST)
|
||||
x = sff_8024_id[value];
|
||||
else {
|
||||
if (value > 0x80)
|
||||
x = "Vendor specific";
|
||||
else
|
||||
x = "Reserved";
|
||||
}
|
||||
|
||||
snprintf(buf, size, "%s", x);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_sff_connector(char *buf, size_t size, uint8_t value)
|
||||
{
|
||||
const char *x;
|
||||
|
||||
if ((x = find_value(conn, value)) == NULL) {
|
||||
if (value >= 0x0D && value <= 0x1F)
|
||||
x = "Unallocated";
|
||||
else if (value >= 0x24 && value <= 0x7F)
|
||||
x = "Unallocated";
|
||||
else
|
||||
x = "Vendor specific";
|
||||
}
|
||||
|
||||
snprintf(buf, size, "%s", x);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_sff_rev_compliance(char *buf, size_t size, uint8_t value)
|
||||
{
|
||||
const char *x;
|
||||
|
||||
if (value > 0x07)
|
||||
x = "Unallocated";
|
||||
else
|
||||
x = find_value(rev_compl, value);
|
||||
|
||||
snprintf(buf, size, "%s", x);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_identifier(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_ID, 1, &data);
|
||||
convert_sff_identifier(buf, size, data);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_connector(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_CONNECTOR, 1, &data);
|
||||
convert_sff_connector(buf, size, data);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_identifier(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_ID, 1, &data);
|
||||
convert_sff_identifier(buf, size, data);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_connector(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_CONNECTOR, 1, &data);
|
||||
convert_sff_connector(buf, size, data);
|
||||
}
|
||||
|
||||
static void
|
||||
printf_sfp_transceiver_descr(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[12];
|
||||
const char *tech_class, *tech_len, *tech_tech, *tech_media, *tech_speed;
|
||||
|
||||
tech_class = NULL;
|
||||
tech_len = NULL;
|
||||
tech_tech = NULL;
|
||||
tech_media = NULL;
|
||||
tech_speed = NULL;
|
||||
|
||||
/* Read bytes 3-10 at once */
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 8, &xbuf[3]);
|
||||
|
||||
/* Check 10G ethernet first */
|
||||
tech_class = find_zero_bit(eth_10g, xbuf[3], 1);
|
||||
if (tech_class == NULL) {
|
||||
/* No match. Try 1G */
|
||||
tech_class = find_zero_bit(eth_compat, xbuf[6], 1);
|
||||
}
|
||||
|
||||
tech_len = find_zero_bit(fc_len, xbuf[7], 1);
|
||||
tech_tech = find_zero_bit(cab_tech, xbuf[7] << 8 | xbuf[8], 2);
|
||||
tech_media = find_zero_bit(fc_media, xbuf[9], 1);
|
||||
tech_speed = find_zero_bit(fc_speed, xbuf[10], 1);
|
||||
|
||||
printf("Class: %s\n", tech_class);
|
||||
printf("Length: %s\n", tech_len);
|
||||
printf("Tech: %s\n", tech_tech);
|
||||
printf("Media: %s\n", tech_media);
|
||||
printf("Speed: %s\n", tech_speed);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
const char *tech_class;
|
||||
uint8_t code;
|
||||
|
||||
unsigned char qbuf[8];
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 8, (uint8_t *)qbuf);
|
||||
|
||||
/* Check 10G Ethernet/IB first */
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 1, &code);
|
||||
tech_class = find_zero_bit(eth_10g, code, 1);
|
||||
if (tech_class == NULL) {
|
||||
/* No match. Try Ethernet 1G */
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START + 3,
|
||||
1, (caddr_t)&code);
|
||||
tech_class = find_zero_bit(eth_compat, code, 1);
|
||||
}
|
||||
|
||||
if (tech_class == NULL)
|
||||
tech_class = "Unknown";
|
||||
|
||||
snprintf(buf, size, "%s", tech_class);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
const char *tech_class;
|
||||
uint8_t code;
|
||||
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_CODE_E1040100G, 1, &code);
|
||||
|
||||
/* Check for extended specification compliance */
|
||||
if (code & SFF_8636_EXT_COMPLIANCE) {
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_OPTIONS_START, 1, &code);
|
||||
tech_class = find_value(eth_extended_comp, code);
|
||||
} else
|
||||
/* Check 10/40G Ethernet class only */
|
||||
tech_class = find_zero_bit(eth_1040g, code, 1);
|
||||
|
||||
if (tech_class == NULL)
|
||||
tech_class = "Unknown";
|
||||
|
||||
snprintf(buf, size, "%s", tech_class);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print SFF-8472/SFF-8436 string to supplied buffer.
|
||||
* All (vendor-specific) strings are padded right with '0x20'.
|
||||
*/
|
||||
static void
|
||||
convert_sff_name(char *buf, size_t size, char *xbuf)
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = &xbuf[16]; *(p - 1) == 0x20; p--)
|
||||
;
|
||||
*p = '\0';
|
||||
snprintf(buf, size, "%s", xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_sff_date(char *buf, size_t size, char *xbuf)
|
||||
{
|
||||
|
||||
snprintf(buf, size, "20%c%c-%c%c-%c%c", xbuf[0], xbuf[1],
|
||||
xbuf[2], xbuf[3], xbuf[4], xbuf[5]);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[17];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_VENDOR_START, 16, (uint8_t *)xbuf);
|
||||
convert_sff_name(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[17];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_PN_START, 16, (uint8_t *)xbuf);
|
||||
convert_sff_name(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[17];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_SN_START, 16, (uint8_t *)xbuf);
|
||||
convert_sff_name(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[6];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
/* Date code, see Table 3.8 for description */
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_DATE_START, 6, (uint8_t *)xbuf);
|
||||
convert_sff_date(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[17];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_VENDOR_START, 16, (uint8_t *)xbuf);
|
||||
convert_sff_name(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[17];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_PN_START, 16, (uint8_t *)xbuf);
|
||||
convert_sff_name(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[17];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_SN_START, 16, (uint8_t *)xbuf);
|
||||
convert_sff_name(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[6];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_DATE_START, 6, (uint8_t *)xbuf);
|
||||
convert_sff_date(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
print_sfp_vendor(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
char xbuf[80];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
if (ii->qsfp != 0) {
|
||||
get_qsfp_vendor_name(ii, xbuf, 20);
|
||||
get_qsfp_vendor_pn(ii, &xbuf[20], 20);
|
||||
get_qsfp_vendor_sn(ii, &xbuf[40], 20);
|
||||
get_qsfp_vendor_date(ii, &xbuf[60], 20);
|
||||
} else {
|
||||
get_sfp_vendor_name(ii, xbuf, 20);
|
||||
get_sfp_vendor_pn(ii, &xbuf[20], 20);
|
||||
get_sfp_vendor_sn(ii, &xbuf[40], 20);
|
||||
get_sfp_vendor_date(ii, &xbuf[60], 20);
|
||||
}
|
||||
|
||||
snprintf(buf, size, "vendor: %s PN: %s SN: %s DATE: %s",
|
||||
xbuf, &xbuf[20], &xbuf[40], &xbuf[60]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts internal templerature (SFF-8472, SFF-8436)
|
||||
* 16-bit unsigned value to human-readable representation:
|
||||
*
|
||||
* Internally measured Module temperature are represented
|
||||
* as a 16-bit signed twos complement value in increments of
|
||||
* 1/256 degrees Celsius, yielding a total range of –128C to +128C
|
||||
* that is considered valid between –40 and +125C.
|
||||
*
|
||||
*/
|
||||
static void
|
||||
convert_sff_temp(char *buf, size_t size, uint8_t *xbuf)
|
||||
{
|
||||
double d;
|
||||
|
||||
d = (double)xbuf[0];
|
||||
d += (double)xbuf[1] / 256;
|
||||
|
||||
snprintf(buf, size, "%.2f C", d);
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves supplied voltage (SFF-8472, SFF-8436).
|
||||
* 16-bit usigned value, treated as range 0..+6.55 Volts
|
||||
*/
|
||||
static void
|
||||
convert_sff_voltage(char *buf, size_t size, uint8_t *xbuf)
|
||||
{
|
||||
double d;
|
||||
|
||||
d = (double)((xbuf[0] << 8) | xbuf[1]);
|
||||
snprintf(buf, size, "%.2f Volts", d / 10000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts value in @xbuf to both milliwats and dBm
|
||||
* human representation.
|
||||
*/
|
||||
static void
|
||||
convert_sff_power(struct i2c_info *ii, char *buf, size_t size, uint8_t *xbuf)
|
||||
{
|
||||
uint16_t mW;
|
||||
double dbm;
|
||||
|
||||
mW = (xbuf[0] << 8) + xbuf[1];
|
||||
|
||||
/* Convert mw to dbm */
|
||||
dbm = 10.0 * log10(1.0 * mW / 10000);
|
||||
|
||||
/*
|
||||
* Assume internally-calibrated data.
|
||||
* This is always true for SFF-8346, and explicitly
|
||||
* checked for SFF-8472.
|
||||
*/
|
||||
|
||||
/* Table 3.9, bit 5 is set, internally calibrated */
|
||||
snprintf(buf, size, "%d.%02d mW (%.2f dBm)",
|
||||
mW / 10000, (mW % 10000) / 100, dbm);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_temp(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8472_DIAG, SFF_8472_TEMP, 2, xbuf);
|
||||
convert_sff_temp(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_voltage(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8472_DIAG, SFF_8472_VCC, 2, xbuf);
|
||||
convert_sff_voltage(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static int
|
||||
get_qsfp_temp(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_TEMP, 2, xbuf);
|
||||
if ((xbuf[0] == 0xFF && xbuf[1] == 0xFF) || (xbuf[0] == 0 && xbuf[1] == 0))
|
||||
return (-1);
|
||||
convert_sff_temp(buf, size, xbuf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_voltage(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_VCC, 2, xbuf);
|
||||
convert_sff_voltage(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_rx_power(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8472_DIAG, SFF_8472_RX_POWER, 2, xbuf);
|
||||
convert_sff_power(ii, buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_sfp_tx_power(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8472_DIAG, SFF_8472_TX_POWER, 2, xbuf);
|
||||
convert_sff_power(ii, buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_rx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_RX_CH1_MSB + (chan-1)*2, 2, xbuf);
|
||||
convert_sff_power(ii, buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_tx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
|
||||
{
|
||||
uint8_t xbuf[2];
|
||||
|
||||
memset(xbuf, 0, sizeof(xbuf));
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_TX_CH1_MSB + (chan-1)*2, 2, xbuf);
|
||||
convert_sff_power(ii, buf, size, xbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
get_qsfp_rev_compliance(struct i2c_info *ii, char *buf, size_t size)
|
||||
{
|
||||
uint8_t xbuf;
|
||||
|
||||
xbuf = 0;
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_STATUS, 1, &xbuf);
|
||||
convert_sff_rev_compliance(buf, size, xbuf);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
get_qsfp_br(struct i2c_info *ii)
|
||||
{
|
||||
uint8_t xbuf;
|
||||
uint32_t rate;
|
||||
|
||||
xbuf = 0;
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8436_BITRATE, 1, &xbuf);
|
||||
rate = xbuf * 100;
|
||||
if (xbuf == 0xFF) {
|
||||
read_i2c(ii, SFF_8436_BASE, SFF_8636_BITRATE, 1, &xbuf);
|
||||
rate = xbuf * 250;
|
||||
}
|
||||
|
||||
return (rate);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads i2c data from opened kernel socket.
|
||||
*/
|
||||
static int
|
||||
read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
|
||||
uint8_t *buf)
|
||||
{
|
||||
struct ifi2creq req;
|
||||
int i, l;
|
||||
|
||||
if (ii->error != 0)
|
||||
return (ii->error);
|
||||
|
||||
ii->ifr->ifr_data = (caddr_t)&req;
|
||||
|
||||
i = 0;
|
||||
l = 0;
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.dev_addr = addr;
|
||||
req.offset = off;
|
||||
req.len = len;
|
||||
|
||||
while (len > 0) {
|
||||
l = MIN(sizeof(req.data), len);
|
||||
req.len = l;
|
||||
if (ioctl(ii->fd, SIOCGI2C, ii->ifr) != 0) {
|
||||
ii->error = errno;
|
||||
return (errno);
|
||||
}
|
||||
|
||||
memcpy(&buf[i], req.data, l);
|
||||
len -= l;
|
||||
i += l;
|
||||
req.offset += l;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_i2c_data(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len)
|
||||
{
|
||||
unsigned char buf[16];
|
||||
int i, read;
|
||||
|
||||
while (len > 0) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
read = MIN(sizeof(buf), len);
|
||||
read_i2c(ii, addr, off, read, buf);
|
||||
if (ii->error != 0) {
|
||||
fprintf(stderr, "Error reading i2c info\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\t");
|
||||
for (i = 0; i < read; i++)
|
||||
printf("%02X ", buf[i]);
|
||||
printf("\n");
|
||||
len -= read;
|
||||
off += read;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_qsfp_status(struct i2c_info *ii, int verbose)
|
||||
{
|
||||
char buf[80], buf2[40], buf3[40];
|
||||
uint32_t bitrate;
|
||||
int i;
|
||||
|
||||
ii->qsfp = 1;
|
||||
|
||||
/* Transceiver type */
|
||||
get_qsfp_identifier(ii, buf, sizeof(buf));
|
||||
get_qsfp_transceiver_class(ii, buf2, sizeof(buf2));
|
||||
get_qsfp_connector(ii, buf3, sizeof(buf3));
|
||||
if (ii->error == 0)
|
||||
printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
|
||||
print_sfp_vendor(ii, buf, sizeof(buf));
|
||||
if (ii->error == 0)
|
||||
printf("\t%s\n", buf);
|
||||
|
||||
if (verbose > 1) {
|
||||
get_qsfp_rev_compliance(ii, buf, sizeof(buf));
|
||||
if (ii->error == 0)
|
||||
printf("\tcompliance level: %s\n", buf);
|
||||
|
||||
bitrate = get_qsfp_br(ii);
|
||||
if (ii->error == 0 && bitrate > 0)
|
||||
printf("\tnominal bitrate: %u Mbps\n", bitrate);
|
||||
}
|
||||
|
||||
/*
|
||||
* The standards in this area are not clear when the
|
||||
* additional measurements are present or not. Use a valid
|
||||
* temperature reading as an indicator for the presence of
|
||||
* voltage and TX/RX power measurements.
|
||||
*/
|
||||
if (get_qsfp_temp(ii, buf, sizeof(buf)) == 0) {
|
||||
get_qsfp_voltage(ii, buf2, sizeof(buf2));
|
||||
printf("\tmodule temperature: %s voltage: %s\n", buf, buf2);
|
||||
for (i = 1; i <= 4; i++) {
|
||||
get_qsfp_rx_power(ii, buf, sizeof(buf), i);
|
||||
get_qsfp_tx_power(ii, buf2, sizeof(buf2), i);
|
||||
printf("\tlane %d: RX: %s TX: %s\n", i, buf, buf2);
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose > 2) {
|
||||
printf("\n\tSFF8436 DUMP (0xA0 128..255 range):\n");
|
||||
dump_i2c_data(ii, SFF_8436_BASE, 128, 128);
|
||||
printf("\n\tSFF8436 DUMP (0xA0 0..81 range):\n");
|
||||
dump_i2c_data(ii, SFF_8436_BASE, 0, 82);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_sfp_status(struct i2c_info *ii, int verbose)
|
||||
{
|
||||
char buf[80], buf2[40], buf3[40];
|
||||
uint8_t diag_type, flags;
|
||||
|
||||
/* Read diagnostic monitoring type */
|
||||
read_i2c(ii, SFF_8472_BASE, SFF_8472_DIAG_TYPE, 1, (caddr_t)&diag_type);
|
||||
if (ii->error != 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Read monitoring data IFF it is supplied AND is
|
||||
* internally calibrated
|
||||
*/
|
||||
flags = SFF_8472_DDM_DONE | SFF_8472_DDM_INTERNAL;
|
||||
if ((diag_type & flags) == flags)
|
||||
ii->do_diag = 1;
|
||||
|
||||
/* Transceiver type */
|
||||
get_sfp_identifier(ii, buf, sizeof(buf));
|
||||
get_sfp_transceiver_class(ii, buf2, sizeof(buf2));
|
||||
get_sfp_connector(ii, buf3, sizeof(buf3));
|
||||
if (ii->error == 0)
|
||||
printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
|
||||
print_sfp_vendor(ii, buf, sizeof(buf));
|
||||
if (ii->error == 0)
|
||||
printf("\t%s\n", buf);
|
||||
|
||||
if (verbose > 5)
|
||||
printf_sfp_transceiver_descr(ii, buf, sizeof(buf));
|
||||
/*
|
||||
* Request current measurements iff they are provided:
|
||||
*/
|
||||
if (ii->do_diag != 0) {
|
||||
get_sfp_temp(ii, buf, sizeof(buf));
|
||||
get_sfp_voltage(ii, buf2, sizeof(buf2));
|
||||
printf("\tmodule temperature: %s Voltage: %s\n", buf, buf2);
|
||||
get_sfp_rx_power(ii, buf, sizeof(buf));
|
||||
get_sfp_tx_power(ii, buf2, sizeof(buf2));
|
||||
printf("\tRX: %s TX: %s\n", buf, buf2);
|
||||
}
|
||||
|
||||
if (verbose > 2) {
|
||||
printf("\n\tSFF8472 DUMP (0xA0 0..127 range):\n");
|
||||
dump_i2c_data(ii, SFF_8472_BASE, 0, 128);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sfp_status(int s, struct ifreq *ifr, int verbose)
|
||||
{
|
||||
struct i2c_info ii;
|
||||
uint8_t id_byte;
|
||||
|
||||
/* Prepare necessary into pass to i2c reader */
|
||||
memset(&ii, 0, sizeof(ii));
|
||||
ii.fd = s;
|
||||
ii.ifr = ifr;
|
||||
|
||||
/*
|
||||
* Try to read byte 0 from i2c:
|
||||
* Both SFF-8472 and SFF-8436 use it as
|
||||
* 'identification byte'.
|
||||
* Stop reading status on zero as value -
|
||||
* this might happen in case of empty transceiver slot.
|
||||
*/
|
||||
id_byte = 0;
|
||||
read_i2c(&ii, SFF_8472_BASE, SFF_8472_ID, 1, (caddr_t)&id_byte);
|
||||
if (ii.error != 0 || id_byte == 0)
|
||||
return;
|
||||
|
||||
switch (id_byte) {
|
||||
case SFF_8024_ID_QSFP:
|
||||
case SFF_8024_ID_QSFPPLUS:
|
||||
case SFF_8024_ID_QSFP28:
|
||||
print_qsfp_status(&ii, verbose);
|
||||
break;
|
||||
default:
|
||||
print_sfp_status(&ii, verbose);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
MK_INET_SUPPORT="yes"
|
||||
MK_INET6_SUPPORT="no"
|
||||
MK_IFMEDIA_SUPPORT="no"
|
||||
MK_MAC_SUPPORT="no"
|
||||
MK_SFP_SUPPORT="no"
|
||||
MK_IEEE80211_SUPPORT="no"
|
||||
MK_PF="no"
|
||||
MK_LAGG_SUPPORT="no"
|
||||
MK_JAIL="no"
|
|
@ -42,16 +42,15 @@ ifeq ($(FF_DPDK),)
|
|||
endif
|
||||
|
||||
FF_PROG_CFLAGS:= -g -Wall -Werror -DFSTACK -std=gnu99
|
||||
FF_PROG_CFLAGS+= -I${TOPDIR}/tools/compat
|
||||
FF_PROG_CFLAGS+= -I${TOPDIR}/lib -I${TOPDIR}/tools/ipc
|
||||
FF_PROG_CFLAGS+= -I${TOPDIR}/lib -I${TOPDIR}/tools/compat
|
||||
FF_PROG_CFLAGS+= -I${TOPDIR}/tools/compat/include -D__BSD_VISIBLE
|
||||
FF_PROG_CFLAGS+= -include ${FF_DPDK}/include/rte_config.h
|
||||
FF_PROG_CFLAGS+= -I${FF_DPDK}/include
|
||||
|
||||
FF_PROG_LIBS:= -L${TOPDIR}/tools/ipc -lfstack_ipc
|
||||
FF_PROG_LIBS+= -L${FF_DPDK}/lib
|
||||
FF_PROG_LIBS+= -g -Wl,--no-as-needed -fvisibility=default -pthread -lm -lrt
|
||||
FF_PROG_LIBS+= -Wl,--whole-archive -lrte_eal -Wl,-lrte_mempool -lrte_ring
|
||||
FF_PROG_LIBS+= -Wl,--no-whole-archive -lrt -lm -ldl -lcrypto
|
||||
FF_PROG_LIBS:= -L${TOPDIR}/tools/compat -Wl,--whole-archive -lffcompat
|
||||
FF_PROG_LIBS+= -Wl,--no-whole-archive -L${FF_DPDK}/lib
|
||||
FF_PROG_LIBS+= -Wl,--whole-archive -lrte_eal -lrte_mempool -lrte_ring
|
||||
FF_PROG_LIBS+= -Wl,--no-whole-archive -lrt -lm -ldl -lcrypto -pthread
|
||||
|
||||
CFLAGS+= ${FF_PROG_CFLAGS}
|
||||
CXXFLAGS+= ${FF_PROG_CFLAGS}
|
||||
|
@ -65,7 +64,6 @@ else
|
|||
${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}
|
||||
endif
|
||||
|
||||
|
||||
clean:
|
||||
@rm -f ${PROG} ${OBJS}
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
|
||||
TOPDIR?=${CURDIR}/../..
|
||||
|
||||
PROG=sysctl
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Derived from FreeBSD's /sbin/sysctl/sysctl.c.
|
||||
* Derived from FreeBSD's sbin/sysctl/sysctl.c.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
|
@ -79,13 +79,87 @@ static const char rcsid[] =
|
|||
|
||||
#ifdef FSTACK
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "sysctl.h"
|
||||
#include "sys/sysctl.h"
|
||||
#include "ff_ipc.h"
|
||||
|
||||
static uint16_t proc_id;
|
||||
struct clockinfo {
|
||||
int hz; /* clock frequency */
|
||||
int tick; /* micro-seconds per hz tick */
|
||||
int spare;
|
||||
int stathz; /* statistics clock frequency */
|
||||
int profhz; /* profiling clock frequency */
|
||||
};
|
||||
|
||||
#define sysctl(a, b, c, d, e, f) sysctl_ipc(proc_id, (a), (b), (c), (d), (e), (f))
|
||||
struct loadavg {
|
||||
__uint32_t ldavg[3];
|
||||
long fscale;
|
||||
};
|
||||
|
||||
/* Structure extended to include extended attribute field in ACPI 3.0. */
|
||||
struct bios_smap_xattr {
|
||||
u_int64_t base;
|
||||
u_int64_t length;
|
||||
u_int32_t type;
|
||||
u_int32_t xattr;
|
||||
} __packed;
|
||||
|
||||
/* systemwide totals computed every five seconds */
|
||||
struct vmtotal {
|
||||
int16_t t_rq; /* length of the run queue */
|
||||
int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */
|
||||
int16_t t_pw; /* jobs in page wait */
|
||||
int16_t t_sl; /* jobs sleeping in core */
|
||||
int16_t t_sw; /* swapped out runnable/short block jobs */
|
||||
int32_t t_vm; /* total virtual memory */
|
||||
int32_t t_avm; /* active virtual memory */
|
||||
int32_t t_rm; /* total real memory in use */
|
||||
int32_t t_arm; /* active real memory */
|
||||
int32_t t_vmshr; /* shared virtual memory */
|
||||
int32_t t_avmshr; /* active shared virtual memory */
|
||||
int32_t t_rmshr; /* shared real memory */
|
||||
int32_t t_armshr; /* active shared real memory */
|
||||
int32_t t_free; /* free memory pages */
|
||||
};
|
||||
|
||||
struct efi_md {
|
||||
uint32_t md_type;
|
||||
#define EFI_MD_TYPE_NULL 0
|
||||
#define EFI_MD_TYPE_CODE 1 /* Loader text. */
|
||||
#define EFI_MD_TYPE_DATA 2 /* Loader data. */
|
||||
#define EFI_MD_TYPE_BS_CODE 3 /* Boot services text. */
|
||||
#define EFI_MD_TYPE_BS_DATA 4 /* Boot services data. */
|
||||
#define EFI_MD_TYPE_RT_CODE 5 /* Runtime services text. */
|
||||
#define EFI_MD_TYPE_RT_DATA 6 /* Runtime services data. */
|
||||
#define EFI_MD_TYPE_FREE 7 /* Unused/free memory. */
|
||||
#define EFI_MD_TYPE_BAD 8 /* Bad memory */
|
||||
#define EFI_MD_TYPE_RECLAIM 9 /* ACPI reclaimable memory. */
|
||||
#define EFI_MD_TYPE_FIRMWARE 10 /* ACPI NV memory */
|
||||
#define EFI_MD_TYPE_IOMEM 11 /* Memory-mapped I/O. */
|
||||
#define EFI_MD_TYPE_IOPORT 12 /* I/O port space. */
|
||||
#define EFI_MD_TYPE_PALCODE 13 /* PAL */
|
||||
uint32_t __pad;
|
||||
uint64_t md_phys;
|
||||
void *md_virt;
|
||||
uint64_t md_pages;
|
||||
uint64_t md_attr;
|
||||
#define EFI_MD_ATTR_UC 0x0000000000000001UL
|
||||
#define EFI_MD_ATTR_WC 0x0000000000000002UL
|
||||
#define EFI_MD_ATTR_WT 0x0000000000000004UL
|
||||
#define EFI_MD_ATTR_WB 0x0000000000000008UL
|
||||
#define EFI_MD_ATTR_UCE 0x0000000000000010UL
|
||||
#define EFI_MD_ATTR_WP 0x0000000000001000UL
|
||||
#define EFI_MD_ATTR_RP 0x0000000000002000UL
|
||||
#define EFI_MD_ATTR_XP 0x0000000000004000UL
|
||||
#define EFI_MD_ATTR_RT 0x8000000000000000UL
|
||||
};
|
||||
|
||||
struct efi_map_header {
|
||||
uint64_t memory_size;
|
||||
uint64_t descriptor_size;
|
||||
uint32_t descriptor_version;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -239,7 +313,7 @@ main(int argc, char **argv)
|
|||
break;
|
||||
#ifdef FSTACK
|
||||
case 'p':
|
||||
proc_id = atoi(optarg);
|
||||
ff_set_proc_id(atoi(optarg));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue