Skip to content

Commit 4c09ca5

Browse files
committed
Merge branch 'dev'
2 parents df0df1a + a2cb019 commit 4c09ca5

File tree

3,602 files changed

+301910
-186271
lines changed

Some content is hidden

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

3,602 files changed

+301910
-186271
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To deal with the increasingly severe DDoS attacks the authorized DNS server of T
2222

2323
After several months of development and testing, DKDNS, high-performance DNS server based on DPDK officially released in October 2013. It's capable of achieving up to 11 million QPS with a single 10GE port and 18.2 million QPS with two 10GE ports. And then we developed a user-space TCP/IP stack called F-Stack that can process 0.6 million RPS with a single 10GE port.
2424

25-
With the fast growth of Tencent Cloud more and more of our services needed higher network access performance. Meanwhile, F-Stack was continuing to improve, being driven by our business growth, and, ultimately developed into a general network access framework. But our initial TCP/IP stack couldn't meet the needs of these services. Continuing to develop and maintain a complete high performance network stack would have been too expensive. After evaluating several plans; we finally determined to port FreeBSD's (11.0 stable) TCP/IP stack into F-Stack. Not only does this allow us to stop reinventing the wheel, we can take advantage of the the improvements the FreeBSD community will bring in the future. Thanks to [libplebnet](https://gitorious.org/freebsd/kmm-sandbox/commit/fa8a11970bc0ed092692736f175925766bebf6af?p=freebsd:kmm-sandbox.git;a=tree;f=lib/libplebnet;h=ae446dba0b4f8593b69b339ea667e12d5b709cfb;hb=refs/heads/work/svn_trunk_libplebnet) and [libuinet](https://github.com/pkelsey/libuinet) this work became a lot easier.
25+
With the fast growth of Tencent Cloud more and more of our services needed higher network access performance. Meanwhile, F-Stack was continuing to improve, being driven by our business growth, and, ultimately developed into a general network access framework. But our initial TCP/IP stack couldn't meet the needs of these services. Continuing to develop and maintain a complete high performance network stack would have been too expensive. After evaluating several plans; we finally determined to port FreeBSD's (13.0 stable) TCP/IP stack into F-Stack. Not only does this allow us to stop reinventing the wheel, we can take advantage of the the improvements the FreeBSD community will bring in the future. Thanks to [libplebnet](https://gitorious.org/freebsd/kmm-sandbox/commit/fa8a11970bc0ed092692736f175925766bebf6af?p=freebsd:kmm-sandbox.git;a=tree;f=lib/libplebnet;h=ae446dba0b4f8593b69b339ea667e12d5b709cfb;hb=refs/heads/work/svn_trunk_libplebnet) and [libuinet](https://github.com/pkelsey/libuinet) this work became a lot easier.
2626

2727
With the rapid development of all kinds of applications, in order to help different APPs quick and easily use F-Stack, F-Stack has integrated Nginx, Redis and other commonly used APPs, and a micro thread framework, and provides a standard Epoll/Kqueue interface.
2828

@@ -50,7 +50,8 @@ Currently, besides authorized DNS server of DNSPod, there are various products i
5050
cd f-stack
5151
# Compile DPDK
5252
cd dpdk/
53-
meson -Denable_kmods=true build
53+
# re-enable kni now, to remove kni later
54+
meson -Denable_kmods=true -Ddisable_libs=flow_classify build
5455
ninja -C build
5556
ninja -C build install
5657

@@ -122,7 +123,7 @@ Currently, besides authorized DNS server of DNSPod, there are various products i
122123

123124
#### Nginx
124125

125-
cd app/nginx-1.16.1
126+
cd app/nginx-1.25.2
126127
bash ./configure --prefix=/usr/local/nginx_fstack --with-ff_module
127128
make
128129
make install

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.23
1+
1.24

adapter/syscall/ff_hook_syscall.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ ff_hook_getsockname(int fd, struct sockaddr *name,
419419
SYSCALL(FF_SO_GETSOCKNAME, args);
420420

421421
if (ret == 0) {
422-
socklen_t cplen = *namelen ? *sh_namelen > *namelen
422+
socklen_t cplen = *sh_namelen > *namelen ? *namelen
423423
: *sh_namelen;
424424
rte_memcpy(name, sh_name, cplen);
425425
*namelen = *sh_namelen;
@@ -475,7 +475,7 @@ ff_hook_getpeername(int fd, struct sockaddr *name,
475475
SYSCALL(FF_SO_GETPEERNAME, args);
476476

477477
if (ret == 0) {
478-
socklen_t cplen = *namelen ? *sh_namelen > *namelen
478+
socklen_t cplen = *sh_namelen > *namelen ? *namelen
479479
: *sh_namelen;
480480
rte_memcpy(name, sh_name, cplen);
481481
*namelen = *sh_namelen;
@@ -794,7 +794,7 @@ ff_hook_recvfrom(int fd, void *buf, size_t len, int flags,
794794
if (ret >= 0) {
795795
rte_memcpy(buf, sh_buf, ret);
796796
if (from) {
797-
socklen_t cplen = *fromlen ? *sh_fromlen > *fromlen
797+
socklen_t cplen = *sh_fromlen > *fromlen ? *fromlen
798798
: *sh_fromlen;
799799
rte_memcpy(from, sh_from, cplen);
800800
*fromlen = *sh_fromlen;
@@ -1542,6 +1542,18 @@ ff_hook_close(int fd)
15421542

15431543
SYSCALL(FF_SO_CLOSE, args);
15441544

1545+
#ifdef FF_KERNEL_EVENT
1546+
if (ret == 0 && fstack_kernel_fd_map[fd]) {
1547+
int kernel_fd_ret = ff_linux_close(fstack_kernel_fd_map[fd]);
1548+
if (kernel_fd_ret < 0) {
1549+
ERR_LOG("fstack_kernel_fd_map[%d]=%d, ff_linux_close returns %d, errno=%d\n",
1550+
fd, fstack_kernel_fd_map[fd], kernel_fd_ret, errno);
1551+
} else {
1552+
fstack_kernel_fd_map[fd] = 0;
1553+
}
1554+
}
1555+
#endif
1556+
15451557
RETURN_NOFREE();
15461558
}
15471559

app/nginx-1.25.2/src/event/modules/ngx_ff_module.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,12 @@ kevent(int kq, const struct kevent *changelist, int nchanges,
545545
return ff_kevent(kq, changelist, nchanges, eventlist, nevents, timeout);
546546
}
547547

548-
/*
549-
* It is need to modify the definition, such as Ubuntu 22.04 or later.
550-
*
551-
* int(struct timeval * restrict, void * restrict)
552-
*/
553548
int
549+
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 31)
550+
gettimeofday(struct timeval *tv, void *tz)
551+
#else
554552
gettimeofday(struct timeval *tv, struct timezone *tz)
553+
#endif
555554
{
556555
if (unlikely(inited == 0)) {
557556
return SYSCALL(gettimeofday)(tv, tz);

app/nginx-1.25.2/src/event/ngx_event_connect.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,20 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
353353

354354
#if (NGX_HAVE_TRANSPARENT_PROXY)
355355

356+
#if (NGX_HAVE_FSTACK)
357+
extern int is_fstack_fd(int sockfd);
358+
#ifndef IP_BINDANY
359+
#define IP_BINDANY 24
360+
#endif
361+
#endif
362+
356363
static ngx_int_t
357364
ngx_event_connect_set_transparent(ngx_peer_connection_t *pc, ngx_socket_t s)
358365
{
359366
int value;
367+
#if defined(NGX_HAVE_FSTACK)
368+
int optname;
369+
#endif
360370

361371
value = 1;
362372

@@ -376,23 +386,31 @@ ngx_event_connect_set_transparent(ngx_peer_connection_t *pc, ngx_socket_t s)
376386

377387
case AF_INET:
378388

379-
#if defined(IP_TRANSPARENT)
389+
#if defined(NGX_HAVE_FSTACK)
390+
/****
391+
FreeBSD define IP_BINDANY in freebsd/netinet/in.h
392+
Fstack should only support IP_BINDANY.
393+
****/
394+
if(is_fstack_fd(s)){
395+
optname = IP_BINDANY;
396+
} else {
397+
optname = IP_TRANSPARENT;
398+
}
380399

381-
if (setsockopt(s, IPPROTO_IP, IP_TRANSPARENT,
400+
if (setsockopt(s, IPPROTO_IP, optname,
382401
(const void *) &value, sizeof(int)) == -1)
383402
{
384403
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
385-
"setsockopt(IP_TRANSPARENT) failed");
404+
"setsockopt(IP_BINDANY/IP_TRANSPARENT) failed");
386405
return NGX_ERROR;
387406
}
388407

389-
#elif defined(IP_BINDANY)
390-
391-
if (setsockopt(s, IPPROTO_IP, IP_BINDANY,
408+
#elif defined(IP_TRANSPARENT)
409+
if (setsockopt(s, IPPROTO_IP, IP_TRANSPARENT,
392410
(const void *) &value, sizeof(int)) == -1)
393411
{
394412
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
395-
"setsockopt(IP_BINDANY) failed");
413+
"setsockopt(IP_TRANSPARENT) failed");
396414
return NGX_ERROR;
397415
}
398416

config.ini

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ tso=0
2424
# HW vlan strip, default: enabled.
2525
vlan_strip=1
2626

27+
# Set [vlanN]'s addrs like [portN] later
28+
# the format is same as port_list
29+
# Set vlan filter id, to enable L3/L4 RSS below vlan hdr is not enable after f-stack-1.22.
30+
vlan_filter=1,2,4-6
31+
2732
# sleep when no pkts incomming
2833
# unit: microseconds
2934
idle_sleep=0
@@ -98,13 +103,19 @@ gateway=192.168.1.1
98103
#gateway6=ff::01
99104

100105
# Multi virtual IPv4/IPv6 net addr, Optional parameters.
101-
# `vip_ifname`: default `f-stack-x`
102-
# `vip_addr`: Separated by semicolons, MAX number 64;
103-
# Only support netmask 255.255.255.255, broadcast x.x.x.255 now, hard code in `ff_veth_setvaddr`.
104-
# `vip_addr6`: Separated by semicolons, MAX number 64.
105-
# `vip_prefix_len`: All addr6 use the same prefix now, default 64.
106+
# `vip_ifname`: default `f-stack-x`
107+
# `vip_addr`: Separated by semicolons, MAX number 64;
108+
# Only support netmask 255.255.255.255, broadcast x.x.x.255 now, hard code in `ff_veth_setvaddr`.
109+
# `ipfw_pr`: Set simplest policy routing, Optional parameters.
110+
# Such as the cmd `ff_ipfw -P 0 add 100 setfib 0 ip from 192.168.0.0/24 to any out`
111+
# can set parameter`192.168.0.0 255.255.255.0`, cidr and netmask separated by space.
112+
# Multi cidr separated by semicolons.
113+
# IPv4 only now, and if you want set more complex policy routing, should use tool `ff_ipfw`.
114+
# `vip_addr6`: Separated by semicolons, MAX number 64.
115+
# `vip_prefix_len`: All addr6 use the same prefix now, default 64.
106116
#vip_ifname=lo0
107-
#vip_addr=192.168.1.3;192.168.1.4;192.168.1.5;192.168.1.6
117+
#vip_addr=192.168.0.3;192.168.0.4;192.168.0.5;192.168.0.6
118+
#ipfw_pr=192.168.0.0 255.255.255.0;192.168.10.0 255.255.255.0
108119
#vip_addr6=ff::03;ff::04;ff::05;ff::06;ff::07
109120
#vip_prefix_len=64
110121

@@ -117,6 +128,55 @@ gateway=192.168.1.1
117128
# the format is same as port_list
118129
#slave_port_list=0,1
119130

131+
# Vlan config section, Must set after all [portN]
132+
# NOTE1: Must enable dpdk.vlan_filter first, and match it.
133+
# NOTE2: If enable vlan config, all [PortN] config will be ignored!
134+
#[vlan1]
135+
#portid=0
136+
#addr=192.169.0.2
137+
#netmask=255.255.255.0
138+
#broadcast=192.169.0.255
139+
#gateway=192.169.0.1
140+
#
141+
#vip_addr=192.169.0.3;192.169.0.4;192.169.0.5;192.169.0.6
142+
#ipfw_pr=192.169.0.0 255.255.255.0;192.169.10.0 255.255.255.0
143+
#
144+
#[vlan2]
145+
#portid=0
146+
#addr=192.169.1.2
147+
#netmask=255.255.255.0
148+
#broadcast=192.169.1.255
149+
#gateway=192.169.1.1
150+
#
151+
#vip_addr=192.169.1.3;192.169.1.4;192.169.1.5;192.169.1.6
152+
#ipfw_pr=192.169.1.0 255.255.255.0;192.169.11.0 255.255.255.0
153+
#
154+
#[vlan4]
155+
#portid=0
156+
#addr=192.169.2.2
157+
#netmask=255.255.255.0
158+
#broadcast=192.169.2.255
159+
#gateway=192.169.2.1
160+
#
161+
#vip_addr=192.169.2.3;192.169.2.4;192.169.2.5;192.169.2.6
162+
#ipfw_pr=192.169.2.0 255.255.255.0;192.169.12.0 255.255.255.0
163+
#
164+
#[vlan5]
165+
#portid=0
166+
#addr=192.169.3.2
167+
#netmask=255.255.255.0
168+
#broadcast=192.169.3.255
169+
#gateway=192.169.3.1
170+
#
171+
#addr6=fe::32
172+
#prefix_len=64
173+
#gateway6=fe::31
174+
#
175+
#vip_addr=192.169.3.3;192.169.3.4;192.169.3.5;192.169.3.6
176+
#ipfw_pr=192.169.3.0 255.255.255.0;192.169.13.0 255.255.255.0
177+
#vip_addr6=fe::33;fe::34;fe::35;fe::36;fe::37
178+
#vip_prefix_len=64
179+
120180
# Vdev config section
121181
# orrespond to dpdk.nb_vdev's index: vdev0, vdev1...
122182
# iface : Shouldn't set always.
@@ -151,12 +211,22 @@ gateway=192.168.1.1
151211
# all packets that do not belong to the following tcp_port and udp_port
152212
# will transmit to kernel; if method=accept, all packets that belong to
153213
# the following tcp_port and udp_port will transmit to kernel.
214+
# type: exception path type, 0 means kni(must set meson -Ddisable_libs=flow_classif to re-enable kni in DPDK first), 1 means virtio_user(linux only)
154215
#[kni]
216+
#type=1
155217
#enable=1
156218
#method=reject
157219
# The format is same as port_list
158220
#tcp_port=80,443
159221
#udp_port=53
222+
# KNI ratelimit value, default: 0, means disable ratelimit.
223+
# example:
224+
# The total speed limit for a single process entering the kni ring is 10,000 QPS,
225+
# 1000 QPS for general packets, 9000 QPS for console packets (ospf/arp, etc.)
226+
# The total speed limit for kni forwarding to the kernel is 20,000 QPS.
227+
#console_packets_ratelimit=0
228+
#general_packets_ratelimit=0
229+
#kernel_packets_ratelimit=0
160230

161231
# FreeBSD network performance tuning configurations.
162232
# Most native FreeBSD configurations are supported.
@@ -184,6 +254,8 @@ kern.features.inet6=1
184254
kern.ipc.somaxconn=32768
185255
kern.ipc.maxsockbuf=16777216
186256

257+
net.add_addr_allfibs=1
258+
187259
net.link.ether.inet.maxhold=5
188260

189261
net.inet.tcp.fast_finwait2_recycle=1

doc/F-Stack_API_Reference.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ However, it is supported only before F-Stack is started.
4949
The ioctl() function manipulates the underlying device parameters of special files.
5050
more info see man ioctl.
5151

52+
#### ff_stop_run
53+
54+
void ff_stop_run();
55+
56+
Stop the infinite poll loop started by `ff_run`.
57+
5258
### Network API
5359

5460
#### ff_socket

doc/F-Stack_Binary_Release_Quick_Start.md

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)