Skip to content

Commit

Permalink
Add tool: ifconfig.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
logwang committed Jun 6, 2017
1 parent b40d699 commit df6ad73
Show file tree
Hide file tree
Showing 87 changed files with 27,185 additions and 314 deletions.
3 changes: 1 addition & 2 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
28 changes: 28 additions & 0 deletions lib/ff_dpdk_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lib/ff_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,3 +1095,8 @@ sched_unbind(struct thread* td)

}

void
getcredhostid(struct ucred *cred, unsigned long *hostid)
{
*hostid = 0;
}
6 changes: 6 additions & 0 deletions lib/ff_kern_condvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 8 additions & 1 deletion lib/ff_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 */
Expand All @@ -62,6 +68,7 @@ struct ff_msg {

union {
struct ff_sysctl_args sysctl;
struct ff_ioctl_args ioctl;
};
} __attribute__((packed)) __rte_cache_aligned;

Expand Down
2 changes: 1 addition & 1 deletion lib/ff_syscall_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ linux2freebsd_ioctl(unsigned long request)
case LINUX_TIOCPKT_IOCTL:
return TIOCPKT_IOCTL;
default:
return (-1);
return request;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS=ipc sysctl
SUBDIRS=compat sysctl ifconfig

all:
for d in $(SUBDIRS); do ( cd $$d; $(MAKE) all ) ; done
Expand Down
42 changes: 26 additions & 16 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
# 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:
```
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.
```

Except this option, it is same with the original FreeBSD sysctl, see [Manual page](https://www.freebsd.org/cgi/man.cgi?sysctl).
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]
```
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

Expand Down
10 changes: 6 additions & 4 deletions tools/ipc/Makefile → tools/compat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ 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
DPDK_CFLAGS+= -DRTE_MACHINE_CPUFLAG_SSSE3 -DRTE_MACHINE_CPUFLAG_SSE4_1 -DRTE_MACHINE_CPUFLAG_SSE4_2
DPDK_CFLAGS+= -DRTE_COMPILE_TIME_CPUFLAGS=RTE_CPUFLAG_SSE,RTE_CPUFLAG_SSE2,RTE_CPUFLAG_SSE3,RTE_CPUFLAG_SSSE3,RTE_CPUFLAG_SSE4_1,RTE_CPUFLAG_SSE4_2
DPDK_CFLAGS+= -I${FF_DPDK}/include

CFLAGS+= ${DPDK_CFLAGS}
CFLAGS+= -I${TOPDIR}/lib
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}
Expand Down
44 changes: 44 additions & 0 deletions tools/compat/compat.h
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions tools/compat/feature_present.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*-
* Copyright (c) 2008 Yahoo!, Inc.
* All rights reserved.
* Written by: John Baldwin <[email protected]>
*
* 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);
}
Loading

0 comments on commit df6ad73

Please sign in to comment.