Skip to content

Commit 1430cba

Browse files
author
Luigi Rizzo
committed
initial import from svn. Compiles with the new code NETMAP_API 11
0 parents  commit 1430cba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+31737
-0
lines changed

BSDmakefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# forward to use gmake
2+
all $(.TARGETS) :
3+
gmake MAKE=gmake $(.TARGETS)

Makefile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# This is a gnu makefile to build ipfw in userspace.
3+
# Usage:
4+
#
5+
# make NETMAP_INC=/some/place/with/netmap-release/sys
6+
#
7+
# build with make NETMAP_INC=/place/with/netmap/sys
8+
9+
SUBDIRS= ipfw dummynet
10+
.PHONY: ipfw kipfw
11+
12+
include Makefile.inc
13+
all: ipfw kipfw
14+
15+
ipfw: $(OBJDIR)
16+
$(MSG) Building userspace ...
17+
@(cd ipfw && $(MAKE) $(MAKECMDGOALS) )
18+
19+
$(OBJDIR):
20+
-@mkdir $(OBJDIR)
21+
22+
kipfw: $(OBJDIR)
23+
$(MSG) Building datapath ...
24+
@(cd $(OBJDIR) && $(MAKE) -f ../Makefile.kipfw && cp kipfw ..)
25+
26+
clean:
27+
-@rm -rf $(OBJDIR) kipfw
28+
@(cd ipfw && $(MAKE) clean )
29+
30+
tgz:
31+
@$(MAKE) clean
32+
(cd ..; tar cvzf /tmp/ipfw-user.tgz --exclude .svn ipfw-user)
33+
34+
# compute diffs wrt FreeBSD head tree in BSD_HEAD
35+
diffs:
36+
-@diff -urp --exclude Makefile $(BSD_HEAD)/sbin/ipfw ipfw
37+
-@diff -urp --exclude Makefile $(BSD_HEAD)/sys sys

Makefile.inc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# this is a gnu makefile
3+
4+
BSD_HEAD ?= /home/luigi/FreeBSD/head
5+
NETMAP_INC ?= ../netmap-release/sys
6+
7+
OBJDIR=objs
8+
OSARCH := $(shell uname)
9+
OSARCH := $(findstring $(OSARCH),FreeBSD Linux Darwin)
10+
ifeq ($(OSARCH),)
11+
OSARCH := Windows
12+
endif
13+
14+
ifeq ($V,) # no echo
15+
MSG=@echo
16+
HIDE=@
17+
else
18+
MSG=@\#
19+
HIDE=
20+
endif
21+
22+
# ipfw and kipfw are built in subdirs so the paths for
23+
# headers refer to one directory up
24+
INCDIRS += -I ../$(OBJDIR)/include_e -DEMULATE_SYSCTL
25+
INCDIRS += -I ../sys -I ../extra/sys -I ../extra/sys/contrib/pf
26+
.c.o:
27+
$(MSG) " CC $<"
28+
$(HIDE) $(CC) $(CFLAGS) -c $< -o $@

Makefile.kipfw

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# gnu Makefile to build a userland version of the
2+
# kernel code for ipfw+dummynet
3+
#
4+
# The kernel code is compiled with appropriate flags to make
5+
# it see a kernel-like environment.
6+
# The userland emulation code is compiler with regular flags.
7+
8+
# M is the current directory, used in recursive builds
9+
# so we allow it to be overridden
10+
include ../Makefile.inc
11+
VPATH = ../extra:../sys/netpfil/ipfw:../sys/netinet:../sys/net
12+
M ?= $(shell pwd)
13+
OBJPATH = $(M)/../$(OBJDIR)
14+
15+
ifeq ($(OSARCH),Darwin)
16+
CFLAGS2 += -D__BSD_VISIBLE
17+
EFILES_. += libutil.h
18+
EFILES_sys += condvar.h priv.h _lock.h rmlock.h
19+
EFILES_machine += in_cksum.h
20+
EFILES_netinet += ip_carp.h pim.h sctp.h
21+
EFILES_net += netisr.h vnet.h
22+
endif
23+
24+
ifeq ($(OSARCH),Linux)
25+
CFLAGS2 += -D__BSD_VISIBLE
26+
CFLAGS2 += -include ../extra/linux_defs.h
27+
CFLAGS2 += -Wno-unused-but-set-variable
28+
EFILES_. += libutil.h
29+
EFILES_sys += condvar.h priv.h _lock.h rmlock.h
30+
EFILES_sys += lock.h ucred.h # taskqueue.h
31+
EFILES_sys += sockio.h
32+
EFILES_machine += in_cksum.h
33+
EFILES_netinet += in_pcb.h ip_carp.h pim.h sctp.h tcp_var.h
34+
EFILES_net += if_types.h bpf.h netisr.h vnet.h
35+
EFILES_linux += module.h
36+
endif
37+
38+
ifeq ($(OSARCH),Windows)
39+
CFLAGS2 += -D__BSD_VISIBLE
40+
# CFLAGS2 += -include ../extra/linux_defs.h
41+
CFLAGS2 += -Wno-unused-but-set-variable
42+
# EFILES_. += libutil.h
43+
# EFILES_sys += condvar.h priv.h _lock.h rmlock.h
44+
# EFILES_sys += lock.h ucred.h # taskqueue.h
45+
# EFILES_sys += sockio.h
46+
# EFILES_machine += in_cksum.h
47+
# EFILES_netinet += in_pcb.h ip_carp.h pim.h sctp.h tcp_var.h
48+
# EFILES_net += if_types.h bpf.h netisr.h vnet.h
49+
# EFILES_linux += module.h
50+
EFILES_sys += sockio.h
51+
EFILES_net += ethernet.h
52+
EFILES_sys += condvar.h priv.h socketvar.h ucred.h
53+
EFILES_net += vnet.h
54+
EFILES_netinet += in_pcb.h ip_carp.h pim.h sctp.h tcp_var.h
55+
endif
56+
57+
NETMAP_FLAGS = -DWITH_NETMAP -I$(NETMAP_INC)
58+
59+
E_CFLAGS += $(INCDIRS)
60+
E_CFLAGS += -include $(M)/../extra/glue.h # headers
61+
E_CFLAGS += -include $(M)/../extra/missing.h # headers
62+
E_CFLAGS += -O2 -Wall -Werror -fno-strict-aliasing
63+
E_CFLAGS += -g
64+
E_CFLAGS += -DKERNEL_SIDE # build the kernel side of the firewall
65+
E_CFLAGS += -DUSERSPACE # communicate through userspace
66+
E_CFLAGS += $(EFLAGS) $(NETMAP_FLAGS)
67+
E_CFLAGS += -DINET
68+
E_CFLAGS += -DIPFIREWALL_DEFAULT_TO_ACCEPT
69+
E_CFLAGS += -D_BSD_SOURCE
70+
# many of the kernel headers need _KERNEL
71+
E_CFLAGS += -D_KERNEL
72+
E_CFLAGS += $(CFLAGS2)
73+
74+
#ipfw + dummynet section, other parts are not compiled in
75+
SRCS_IPFW = ip_fw2.c ip_fw_pfil.c ip_fw_sockopt.c
76+
SRCS_IPFW += ip_fw_dynamic.c ip_fw_table.c
77+
SRCS_IPFW += ip_fw_log.c
78+
SRCS_IPFW += ip_dummynet.c ip_dn_io.c ip_dn_glue.c
79+
SRCS_IPFW += dn_heap.c
80+
SRCS_IPFW += dn_sched_fifo.c dn_sched_wf2q.c
81+
SRCS_IPFW += dn_sched_rr.c dn_sched_qfq.c
82+
SRCS_IPFW += dn_sched_prio.c
83+
SRCS_NET = radix.c
84+
SRCS_NETINET = in_cksum.c
85+
# Module glue and functions missing in linux
86+
IPFW_SRCS = $(SRCS_IPFW) $(SRCS_NET) $(SRCS_NETINET)
87+
IPFW_SRCS += ipfw2_mod.c # bsd_compat.c
88+
89+
IPFW_SRCS += missing.c session.c netmap_io.c
90+
IPFW_CFLAGS= -DINET
91+
92+
E_CFLAGS += -Dradix
93+
MOD := kipfw
94+
95+
LIBS= -lpthread
96+
CFLAGS = $(E_CFLAGS)
97+
98+
IPFW_OBJS= $(IPFW_SRCS:%.c=%.o)
99+
100+
all: include_e $(MOD)
101+
102+
# entries to create empty files
103+
EFILES_. += opt_inet.h opt_ipsec.h opt_ipdivert.h
104+
EFILES_. += opt_inet6.h opt_ipfw.h opt_mpath.h
105+
EFILES_. += opt_mbuf_stress_test.h opt_param.h
106+
EFILES_. += timeconv.h
107+
108+
EFILES_altq += if_altq.h
109+
110+
EFILES_net += if_var.h route.h if_clone.h
111+
EFILES_netpfil/pf += pf_mtag.h
112+
EFILES_netinet += in_var.h ip_var.h udp_var.h
113+
EFILES_netinet6 += ip6_var.h
114+
EFILES_sys += proc.h sockopt.h sysctl.h
115+
# new
116+
EFILES_sys += mutex.h _mutex.h _rwlock.h rwlock.h
117+
EFILES_sys += eventhandler.h
118+
EFILES_sys += jail.h ktr.h
119+
120+
#EFILES += sys/_lock.h sys/_rwlock.h sys/rwlock.h sys/rmlock.h sys/_mutex.h sys/mutex.h
121+
#EFILES += sys/condvar.h sys/eventhandler.h # sys/domain.h
122+
#EFILES += sys/limits.h sys/lock.h sys/mutex.h sys/priv.h
123+
#EFILES += sys/proc.h sys/rwlock.h sys/socket.h sys/socketvar.h
124+
#EFILES += sys/sysctl.h sys/time.h sys/ucred.h
125+
126+
127+
#EFILES += vm/uma_int.h vm/vm_int.h vm/uma_dbg.h
128+
#EFILES += vm/vm_dbg.h vm/vm_page.h vm/vm.h
129+
#EFILES += sys/rwlock.h sys/sysctl.h
130+
131+
# first make a list of directories from variable names
132+
EDIRS= $(subst EFILES_,,$(filter EFILES_%,$(.VARIABLES)))
133+
# then prepend the directory name to individual files.
134+
# $(empty) serves to interpret the following space literally,
135+
# and the ": = " substitution packs spaces into one.
136+
EFILES = $(foreach i,$(EDIRS),$(subst $(empty) , $(i)/, $(EFILES_$(i): = )))
137+
138+
include_e:
139+
-@echo "Building $(OBJPATH)/include_e ..."
140+
-$(HIDE) rm -rf $(OBJPATH)/include_e opt_*
141+
-$(HIDE) mkdir -p $(OBJPATH)/include_e
142+
-$(HIDE) (cd $(OBJPATH)/include_e; mkdir -p $(EDIRS); touch $(EFILES) )
143+
144+
145+
$(IPFW_OBJS) : ../extra/glue.h
146+
147+
ip_fw2.o ip_dummynet.o: # EFLAGS= -include missing.h
148+
149+
radix.o:# CFLAGS += -U_KERNEL
150+
151+
# session.o: CFLAGS = -O2
152+
nm_util.o: CFLAGS = -O2 -Wall -Werror $(NETMAP_FLAGS)
153+
154+
$(MOD): $(IPFW_OBJS)
155+
$(MSG) " LD $@"
156+
$(HIDE)$(CC) -o $@ $^ $(LIBS)
157+
158+
clean:
159+
-rm -f *.o $(DN) $(MOD)
160+
-rm -rf include_e
161+
162+
diff:
163+
@-(for i in $(SRCS_IPFW) ; do diff -ubw $(BSD_HEAD)/sys/netpfil/ipfw/$$i .; done)
164+
@-(for i in $(SRCS_NET) ; do diff -ubw $(BSD_HEAD)/sys/net/$$i . ; done)
165+
@-(for i in $(SRCS_NETINET) ; do diff -ubw $(BSD_HEAD)/sys/netinet/$$i .; done)

README

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# README FILE FOR IPFW-USER ON TOP OF NETMAP
2+
3+
This directory contains a version of ipfw and dummynet that can
4+
run in userland, using NETMAP as the backend for packet I/O.
5+
This permits a throughput about 10 times higher than the
6+
corresponding in-kernel version. I have measured about 6.5 Mpps
7+
for plain filtering, and 2.2 Mpps going through a pipe.
8+
Some optimizations are possible when running on netmap pipes,
9+
or other netmap ports that support zero copy.
10+
11+
To build the code simply run
12+
make NETMAP_INC=/some/where/with/netmap-release/sys
13+
14+
pointing to the netmap 'sys' directory
15+
(the makefile uses gmake underneath)
16+
17+
The base version comes from FreeBSD-HEAD -r '{2012-08-03}'
18+
(and subsequently updated in late 2013)
19+
with small modifications listed below
20+
21+
netinet/ipfw
22+
ip_dn_io.c
23+
support for on-stack mbufs
24+
ip_fw2.c
25+
some conditional compilation for functions not
26+
available in userspace
27+
ip_fw_log.c
28+
revise snprintf, SNPARGS (MAC)
29+
30+
31+
sbin/ipfw and the kernel counterpart communicate throuugh a
32+
TCP socket (localhost:5555) carrying the raw data that would
33+
normally be carried on seg/getsockopt.
34+
35+
For testing purposes, opening a telnet session to port 5556 and
36+
typing some bytes will start a fake 'infinite source' so you can
37+
check how fast your ruleset works.
38+
39+
gmake
40+
dummynet/ipfw & # preferably in another window
41+
telnet localhost 5556 # type some bytes to start 'traffic'
42+
43+
sh -c "while true; do ipfw/ipfw show; ipfw/ipfw zero; sleep 1; done"
44+
45+
(on an i7-3400 I get about 15 Mpps)
46+
47+
Real packet I/O is possible using netmap info.iet.unipi.it/~luigi/netmap/
48+
You can use a couple of VALE switches (part of netmap) to connect
49+
a source and sink to the userspace firewall, as follows
50+
51+
s f f d
52+
[pkt-gen]-->--[valeA]-->--[kipfw]-->--[valeB]-->--[pkt-gen]
53+
54+
The commands to run (in separate windows) are
55+
56+
# preliminarly, load the netmap module
57+
sudo kldload netmap.ko
58+
59+
# connect the firewall to two vale switches
60+
./kipfw valeA:f valeB:f &
61+
62+
# configure ipfw/dummynet
63+
ipfw/ipfw show # or other
64+
65+
# start the sink
66+
pkt-gen -i valeB:d -f rx
67+
68+
# start an infinite source
69+
pkt-gen -i valeA:s -f tx
70+
71+
# plain again with the firewall and enjoy
72+
ipfw/ipfw show # or other
73+
74+
On my i7-3400 I get about 6.5 Mpps with a single rule, and about 2.2 Mpps
75+
when going through a dummynet pipe. This is for a single process handling
76+
the traffic.

0 commit comments

Comments
 (0)