public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
031138031654957795e367d61f7d7a3d1e9b3053 blob 6982 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
 
# SPDX-License-Identifier: GPL-2.0-or-later
#
# PASST - Plug A Simple Socket Transport
#  for qemu/UNIX domain socket mode
#
# PASTA - Pack A Subtle Tap Abstraction
#  for network namespace/tap device mode
#
# Copyright (c) 2021 Red Hat GmbH
# Author: Stefano Brivio <sbrivio@redhat.com>

VERSION ?= $(shell git describe --tags HEAD 2>/dev/null || echo "unknown\ version")

# Does the target platform allow IPv4 connections to be handled via
# the IPv6 socket API? (Linux does)
DUAL_STACK_SOCKETS := 1

TARGET ?= $(shell $(CC) -dumpmachine)
$(if $(TARGET),,$(error Failed to get target architecture))
# Get 'uname -m'-like architecture description for target
TARGET_ARCH := $(firstword $(subst -, ,$(TARGET)))
TARGET_ARCH := $(patsubst [:upper:],[:lower:],$(TARGET_ARCH))
TARGET_ARCH := $(patsubst arm%,arm,$(TARGET_ARCH))
TARGET_ARCH := $(subst powerpc,ppc,$(TARGET_ARCH))

# On some systems enabling optimization also enables source fortification,
# automagically. Do not override it.
FORTIFY_FLAG :=
ifeq ($(shell $(CC) -O2 -dM -E - < /dev/null 2>&1 | grep ' _FORTIFY_SOURCE ' > /dev/null; echo $$?),1)
FORTIFY_FLAG := -D_FORTIFY_SOURCE=2
endif

# Require preprocessor flags we can't build without
BASE_CPPFLAGS := -D_XOPEN_SOURCE=700 -D_GNU_SOURCE \
	-DPAGE_SIZE=$(shell getconf PAGE_SIZE) \
	-DVERSION=\"$(VERSION)\"
CPPFLAGS := $(FORTIFY_FLAG) -DDUAL_STACK_SOCKETS=$(DUAL_STACK_SOCKETS)

WARNINGS = -Wall -Wextra -Wno-format-zero-length -Wformat-security
CFLAGS = -pedantic -std=c11 -O2 -pie -fPIE $(WARNINGS)

PASST_SRCS = arch.c arp.c bitmap.c checksum.c conf.c dhcp.c dhcpv6.c \
	epoll_ctl.c flow.c fwd.c fwd_rule.c icmp.c igmp.c inany.c iov.c ip.c \
	isolation.c lineread.c log.c mld.c ndp.c netlink.c migrate.c packet.c \
	passt.c pasta.c pcap.c pif.c repair.c serialise.c tap.c tcp.c \
	tcp_buf.c tcp_splice.c tcp_vu.c udp.c udp_flow.c udp_vu.c util.c \
	vhost_user.c virtio.c vu_common.c
QRAP_SRCS = qrap.c
PASST_REPAIR_SRCS = passt-repair.c
SRCS = $(PASST_SRCS) $(QRAP_SRCS) $(PASST_REPAIR_SRCS)

MANPAGES = passt.1 pasta.1 qrap.1 passt-repair.1

PASST_HEADERS = arch.h arp.h bitmap.h checksum.h conf.h dhcp.h dhcpv6.h \
	epoll_ctl.h flow.h fwd.h fwd_rule.h flow_table.h icmp.h icmp_flow.h \
	inany.h iov.h ip.h isolation.h lineread.h log.h migrate.h ndp.h \
	netlink.h packet.h passt.h pasta.h pcap.h pif.h repair.h serialise.h \
	siphash.h tap.h tcp.h tcp_buf.h tcp_conn.h tcp_internal.h tcp_splice.h \
	tcp_vu.h udp.h udp_flow.h udp_internal.h udp_vu.h util.h vhost_user.h \
	virtio.h vu_common.h

C := \#include <sys/random.h>\nint main(){int a=getrandom(0, 0, 0);}
ifeq ($(shell printf "$(C)" | $(CC) -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
	CPPFLAGS += -DHAS_GETRANDOM
endif

ifeq ($(shell :|$(CC) -fstack-protector-strong -S -xc - -o - >/dev/null 2>&1; echo $$?),0)
	CFLAGS += -fstack-protector-strong
endif

prefix		?= /usr/local
exec_prefix	?= $(prefix)
bindir		?= $(exec_prefix)/bin
datarootdir	?= $(prefix)/share
docdir		?= $(datarootdir)/doc/passt
mandir		?= $(datarootdir)/man
man1dir		?= $(mandir)/man1

BASEBIN = passt qrap passt-repair
ifeq ($(TARGET_ARCH),x86_64)
BASEBIN += passt.avx2
endif

BIN = $(BASEBIN) pasta
ifeq ($(TARGET_ARCH),x86_64)
BIN += pasta.avx2
endif

all: $(BIN) $(MANPAGES) docs

static: CFLAGS += -static
static: CPPFLAGS += -DGLIBC_NO_STATIC_NSS
static: clean all

seccomp.h: seccomp.sh $(PASST_SRCS) $(PASST_HEADERS)
	@ EXTRA_SYSCALLS="$(EXTRA_SYSCALLS)" ARCH="$(TARGET_ARCH)" CC="$(CC)" ./seccomp.sh seccomp.h $(PASST_SRCS) $(PASST_HEADERS)

seccomp_repair.h: seccomp.sh $(PASST_REPAIR_SRCS)
	@ ARCH="$(TARGET_ARCH)" CC="$(CC)" ./seccomp.sh seccomp_repair.h $(PASST_REPAIR_SRCS)

$(BASEBIN): %:
	$(CC) $(BASE_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(filter %.c,$^) -o $@

passt: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h

passt.avx2: CFLAGS += -Ofast -mavx2 -ftree-vectorize -funroll-loops
passt.avx2: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h

pasta.avx2 pasta.1 pasta: pasta%: passt%
	ln -sf $< $@

qrap: BASE_CPPFLAGS += -DARCH=\"$(TARGET_ARCH)\"
qrap: $(QRAP_SRCS) passt.h

passt-repair: $(PASST_REPAIR_SRCS) seccomp_repair.h

valgrind: EXTRA_SYSCALLS += rt_sigprocmask rt_sigtimedwait rt_sigaction	\
			    rt_sigreturn getpid gettid kill clock_gettime \
			    mmap|mmap2 munmap open unlink gettimeofday futex \
			    statx readlink
valgrind: CFLAGS += -g
valgrind: CPPFLAGS += -DVALGRIND
valgrind: all

.PHONY: clean
clean:
	$(RM) $(BIN) *~ *.o seccomp.h seccomp_repair.h pasta.1 \
		passt.tar passt.tar.gz *.deb *.rpm \
		passt.pid README.plain.md

install: $(BIN) $(MANPAGES) docs
	mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir)
	cp -d $(BIN) $(DESTDIR)$(bindir)
	cp -d $(MANPAGES) $(DESTDIR)$(man1dir)
	mkdir -p $(DESTDIR)$(docdir)
	cp -d README.plain.md $(DESTDIR)$(docdir)/README.md
	cp -d doc/demo.sh $(DESTDIR)$(docdir)

uninstall:
	$(RM) $(BIN:%=$(DESTDIR)$(prefix)/bin/%)
	$(RM) $(MANPAGES:%=$(DESTDIR)$(man1dir)/%)
	$(RM) $(DESTDIR)$(docdir)/README.md
	$(RM) $(DESTDIR)$(docdir)/demo.sh
	-rmdir $(DESTDIR)$(docdir)

pkgs: static
	tar cf passt.tar -P --xform 's//\/usr\/bin\//' $(BIN)
	tar rf passt.tar -P --xform 's//\/usr\/share\/man\/man1\//' \
		$(MANPAGES)
	gzip passt.tar
	EMAIL="sbrivio@redhat.com" fakeroot alien --to-deb \
		--description="User-mode networking for VMs and namespaces" \
		-k --version=$(shell git rev-parse --short HEAD) \
		passt.tar.gz
	fakeroot alien --to-rpm --target=$(shell uname -m) \
		--description="User-mode networking for VMs and namespaces" \
		-k --version=g$(shell git rev-parse --short HEAD) passt.tar.gz

# TODO: This hack makes a "plain" Markdown version of README.md that can be
# reasonably shipped as documentation file, while the current README.md is
# definitely intended for web browser consumption. It should probably work the
# other way around: the web version should be obtained by adding HTML and
# JavaScript portions to a plain Markdown, instead. However, cgit needs to use
# a file in the git tree. Find a better way around this.
docs: README.md
	@(								\
		skip=0;							\
		while read l; do					\
			case $$l in					\
			"## Demo")	exit 0		;;		\
			"<!"*)				;;		\
			"</"*)		skip=1		;;		\
			"<"*)		skip=2		;;		\
			esac;						\
									\
			[ $$skip -eq 0 ]	&& echo "$$l";		\
			[ $$skip -eq 1 ]	&& skip=0;		\
		done < README.md;					\
	) > README.plain.md

CLANG_TIDY = clang-tidy
CLANG_TIDY_FLAGS = -DCLANG_TIDY_58992

clang-tidy: $(PASST_SRCS)
	$(CLANG_TIDY) $^ -- $(BASE_CPPFLAGS) $(CPPFLAGS) $(CLANG_TIDY_FLAGS)

CPPCHECK = cppcheck
CPPCHECK_FLAGS = --std=c11 --error-exitcode=1 --enable=all --force	\
	--inconclusive --library=posix --quiet				\
	--inline-suppr							\
	$(shell if $(CPPCHECK) --quiet --check-level=exhaustive /dev/null; then \
		echo "--check-level=exhaustive";			\
	else								\
		echo "";						\
	fi)								\
	--suppress=missingIncludeSystem					\
	--suppress=unusedStructMember					\
	 -D CPPCHECK_6936

cppcheck: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
	$(CPPCHECK) $(CPPCHECK_FLAGS) $(BASE_CPPFLAGS) $^
debug log:

solving 03113803 ...
found 03113803 in https://archives.passt.top/passt-dev/20260421024344.1379633-8-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421032338.1909084-8-david@gibson.dropbear.id.au/
found 18343491 in https://archives.passt.top/passt-dev/20260421024344.1379633-7-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421032338.1909084-7-david@gibson.dropbear.id.au/
found a2576771 in https://archives.passt.top/passt-dev/20260421032338.1909084-6-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421024344.1379633-6-david@gibson.dropbear.id.au/
found 1e5f0282 in https://archives.passt.top/passt-dev/20260421024344.1379633-5-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421032338.1909084-5-david@gibson.dropbear.id.au/
found e89e5556 in https://archives.passt.top/passt-dev/20260421024344.1379633-4-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421032338.1909084-4-david@gibson.dropbear.id.au/
found 0de98375 in https://archives.passt.top/passt-dev/20260421024344.1379633-3-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421032338.1909084-3-david@gibson.dropbear.id.au/
found 17e70d22 in https://archives.passt.top/passt-dev/20260421024344.1379633-2-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421032338.1909084-2-david@gibson.dropbear.id.au/
found f697c12b in https://passt.top/passt
preparing index
index prepared:
100644 f697c12b25d2c6f105038e6482aed2b442e3d84b	Makefile

applying [1/14] https://archives.passt.top/passt-dev/20260421024344.1379633-2-david@gibson.dropbear.id.au/
diff --git a/Makefile b/Makefile
index f697c12b..17e70d22 100644

Checking patch Makefile...
Applied patch Makefile cleanly.

skipping https://archives.passt.top/passt-dev/20260421032338.1909084-2-david@gibson.dropbear.id.au/ for 17e70d22
index at:
100644 17e70d221697244268c4545701086928a2418245	Makefile

applying [2/14] https://archives.passt.top/passt-dev/20260421024344.1379633-3-david@gibson.dropbear.id.au/
diff --git a/Makefile b/Makefile
index 17e70d22..0de98375 100644

Checking patch Makefile...
Applied patch Makefile cleanly.

skipping https://archives.passt.top/passt-dev/20260421032338.1909084-3-david@gibson.dropbear.id.au/ for 0de98375
index at:
100644 0de98375cd37e7f7240e9cd34449e5f62ec2bfed	Makefile

applying [3/14] https://archives.passt.top/passt-dev/20260421024344.1379633-4-david@gibson.dropbear.id.au/
diff --git a/Makefile b/Makefile
index 0de98375..e89e5556 100644

Checking patch Makefile...
Applied patch Makefile cleanly.

skipping https://archives.passt.top/passt-dev/20260421032338.1909084-4-david@gibson.dropbear.id.au/ for e89e5556
index at:
100644 e89e5556309230173aea0df2c38724a7abb83e72	Makefile

applying [4/14] https://archives.passt.top/passt-dev/20260421024344.1379633-5-david@gibson.dropbear.id.au/
diff --git a/Makefile b/Makefile
index e89e5556..1e5f0282 100644

Checking patch Makefile...
Applied patch Makefile cleanly.

skipping https://archives.passt.top/passt-dev/20260421032338.1909084-5-david@gibson.dropbear.id.au/ for 1e5f0282
index at:
100644 1e5f0282ff3f7bd3e76d1e9bd857f7f18fd56b22	Makefile

applying [5/14] https://archives.passt.top/passt-dev/20260421032338.1909084-6-david@gibson.dropbear.id.au/
diff --git a/Makefile b/Makefile
index 1e5f0282..a2576771 100644

Checking patch Makefile...
Applied patch Makefile cleanly.

skipping https://archives.passt.top/passt-dev/20260421024344.1379633-6-david@gibson.dropbear.id.au/ for a2576771
index at:
100644 a257677176c0ed8f0e420cf9ccbbd47ce4c61105	Makefile

applying [6/14] https://archives.passt.top/passt-dev/20260421024344.1379633-7-david@gibson.dropbear.id.au/
diff --git a/Makefile b/Makefile
index a2576771..18343491 100644

Checking patch Makefile...
Applied patch Makefile cleanly.

skipping https://archives.passt.top/passt-dev/20260421032338.1909084-7-david@gibson.dropbear.id.au/ for 18343491
index at:
100644 183434916d582467a60b94a9e1349a6550bfe009	Makefile

applying [7/14] https://archives.passt.top/passt-dev/20260421024344.1379633-8-david@gibson.dropbear.id.au/
diff --git a/Makefile b/Makefile
index 18343491..03113803 100644

Checking patch Makefile...
Applied patch Makefile cleanly.

skipping https://archives.passt.top/passt-dev/20260421032338.1909084-8-david@gibson.dropbear.id.au/ for 03113803
index at:
100644 031138031654957795e367d61f7d7a3d1e9b3053	Makefile

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).