162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci# Makefile for net selftests
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciCFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
562306a36Sopenharmony_ciCFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES)
662306a36Sopenharmony_ci# Additional include paths needed by kselftest.h
762306a36Sopenharmony_ciCFLAGS += -I../
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciTEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh \
1062306a36Sopenharmony_ci	      rtnetlink.sh xfrm_policy.sh test_blackhole_dev.sh
1162306a36Sopenharmony_ciTEST_PROGS += fib_tests.sh fib-onlink-tests.sh pmtu.sh udpgso.sh ip_defrag.sh
1262306a36Sopenharmony_ciTEST_PROGS += udpgso_bench.sh fib_rule_tests.sh msg_zerocopy.sh psock_snd.sh
1362306a36Sopenharmony_ciTEST_PROGS += udpgro_bench.sh udpgro.sh test_vxlan_under_vrf.sh reuseport_addr_any.sh
1462306a36Sopenharmony_ciTEST_PROGS += test_vxlan_fdb_changelink.sh so_txtime.sh ipv6_flowlabel.sh
1562306a36Sopenharmony_ciTEST_PROGS += tcp_fastopen_backup_key.sh fcnal-test.sh l2tp.sh traceroute.sh
1662306a36Sopenharmony_ciTEST_PROGS += fin_ack_lat.sh fib_nexthop_multiprefix.sh fib_nexthops.sh fib_nexthop_nongw.sh
1762306a36Sopenharmony_ciTEST_PROGS += altnames.sh icmp.sh icmp_redirect.sh ip6_gre_headroom.sh
1862306a36Sopenharmony_ciTEST_PROGS += route_localnet.sh
1962306a36Sopenharmony_ciTEST_PROGS += reuseaddr_ports_exhausted.sh
2062306a36Sopenharmony_ciTEST_PROGS += txtimestamp.sh
2162306a36Sopenharmony_ciTEST_PROGS += vrf-xfrm-tests.sh
2262306a36Sopenharmony_ciTEST_PROGS += rxtimestamp.sh
2362306a36Sopenharmony_ciTEST_PROGS += devlink_port_split.py
2462306a36Sopenharmony_ciTEST_PROGS += drop_monitor_tests.sh
2562306a36Sopenharmony_ciTEST_PROGS += vrf_route_leaking.sh
2662306a36Sopenharmony_ciTEST_PROGS += bareudp.sh
2762306a36Sopenharmony_ciTEST_PROGS += amt.sh
2862306a36Sopenharmony_ciTEST_PROGS += unicast_extensions.sh
2962306a36Sopenharmony_ciTEST_PROGS += udpgro_fwd.sh
3062306a36Sopenharmony_ciTEST_PROGS += udpgro_frglist.sh
3162306a36Sopenharmony_ciTEST_PROGS += veth.sh
3262306a36Sopenharmony_ciTEST_PROGS += ioam6.sh
3362306a36Sopenharmony_ciTEST_PROGS += gro.sh
3462306a36Sopenharmony_ciTEST_PROGS += gre_gso.sh
3562306a36Sopenharmony_ciTEST_PROGS += cmsg_so_mark.sh
3662306a36Sopenharmony_ciTEST_PROGS += cmsg_time.sh cmsg_ipv6.sh
3762306a36Sopenharmony_ciTEST_PROGS += netns-name.sh
3862306a36Sopenharmony_ciTEST_PROGS += srv6_end_dt46_l3vpn_test.sh
3962306a36Sopenharmony_ciTEST_PROGS += srv6_end_dt4_l3vpn_test.sh
4062306a36Sopenharmony_ciTEST_PROGS += srv6_end_dt6_l3vpn_test.sh
4162306a36Sopenharmony_ciTEST_PROGS += srv6_hencap_red_l3vpn_test.sh
4262306a36Sopenharmony_ciTEST_PROGS += srv6_hl2encap_red_l2vpn_test.sh
4362306a36Sopenharmony_ciTEST_PROGS += srv6_end_next_csid_l3vpn_test.sh
4462306a36Sopenharmony_ciTEST_PROGS += srv6_end_x_next_csid_l3vpn_test.sh
4562306a36Sopenharmony_ciTEST_PROGS += srv6_end_flavors_test.sh
4662306a36Sopenharmony_ciTEST_PROGS += vrf_strict_mode_test.sh
4762306a36Sopenharmony_ciTEST_PROGS += arp_ndisc_evict_nocarrier.sh
4862306a36Sopenharmony_ciTEST_PROGS += ndisc_unsolicited_na_test.sh
4962306a36Sopenharmony_ciTEST_PROGS += arp_ndisc_untracked_subnets.sh
5062306a36Sopenharmony_ciTEST_PROGS += stress_reuseport_listen.sh
5162306a36Sopenharmony_ciTEST_PROGS += l2_tos_ttl_inherit.sh
5262306a36Sopenharmony_ciTEST_PROGS += bind_bhash.sh
5362306a36Sopenharmony_ciTEST_PROGS += ip_local_port_range.sh
5462306a36Sopenharmony_ciTEST_PROGS += rps_default_mask.sh
5562306a36Sopenharmony_ciTEST_PROGS += big_tcp.sh
5662306a36Sopenharmony_ciTEST_PROGS_EXTENDED := in_netns.sh setup_loopback.sh setup_veth.sh
5762306a36Sopenharmony_ciTEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh
5862306a36Sopenharmony_ciTEST_GEN_FILES =  socket nettest
5962306a36Sopenharmony_ciTEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
6062306a36Sopenharmony_ciTEST_GEN_FILES += tcp_mmap tcp_inq psock_snd txring_overwrite
6162306a36Sopenharmony_ciTEST_GEN_FILES += udpgso udpgso_bench_tx udpgso_bench_rx ip_defrag
6262306a36Sopenharmony_ciTEST_GEN_FILES += so_txtime ipv6_flowlabel ipv6_flowlabel_mgr so_netns_cookie
6362306a36Sopenharmony_ciTEST_GEN_FILES += tcp_fastopen_backup_key
6462306a36Sopenharmony_ciTEST_GEN_FILES += fin_ack_lat
6562306a36Sopenharmony_ciTEST_GEN_FILES += reuseaddr_ports_exhausted
6662306a36Sopenharmony_ciTEST_GEN_FILES += hwtstamp_config rxtimestamp timestamping txtimestamp
6762306a36Sopenharmony_ciTEST_GEN_FILES += ipsec
6862306a36Sopenharmony_ciTEST_GEN_FILES += ioam6_parser
6962306a36Sopenharmony_ciTEST_GEN_FILES += gro
7062306a36Sopenharmony_ciTEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
7162306a36Sopenharmony_ciTEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls tun tap
7262306a36Sopenharmony_ciTEST_GEN_FILES += toeplitz
7362306a36Sopenharmony_ciTEST_GEN_FILES += cmsg_sender
7462306a36Sopenharmony_ciTEST_GEN_FILES += stress_reuseport_listen
7562306a36Sopenharmony_ciTEST_PROGS += test_vxlan_vnifiltering.sh
7662306a36Sopenharmony_ciTEST_GEN_FILES += io_uring_zerocopy_tx
7762306a36Sopenharmony_ciTEST_PROGS += io_uring_zerocopy_tx.sh
7862306a36Sopenharmony_ciTEST_GEN_FILES += bind_bhash
7962306a36Sopenharmony_ciTEST_GEN_PROGS += sk_bind_sendto_listen
8062306a36Sopenharmony_ciTEST_GEN_PROGS += sk_connect_zero_addr
8162306a36Sopenharmony_ciTEST_PROGS += test_ingress_egress_chaining.sh
8262306a36Sopenharmony_ciTEST_GEN_PROGS += so_incoming_cpu
8362306a36Sopenharmony_ciTEST_PROGS += sctp_vrf.sh
8462306a36Sopenharmony_ciTEST_GEN_FILES += sctp_hello
8562306a36Sopenharmony_ciTEST_GEN_FILES += csum
8662306a36Sopenharmony_ciTEST_GEN_FILES += nat6to4.o
8762306a36Sopenharmony_ciTEST_GEN_FILES += xdp_dummy.o
8862306a36Sopenharmony_ciTEST_GEN_FILES += ip_local_port_range
8962306a36Sopenharmony_ciTEST_GEN_FILES += bind_wildcard
9062306a36Sopenharmony_ciTEST_PROGS += test_vxlan_mdb.sh
9162306a36Sopenharmony_ciTEST_PROGS += test_bridge_neigh_suppress.sh
9262306a36Sopenharmony_ciTEST_PROGS += test_vxlan_nolocalbypass.sh
9362306a36Sopenharmony_ciTEST_PROGS += test_bridge_backup_port.sh
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciTEST_FILES := settings
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciinclude ../lib.mk
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci$(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
10062306a36Sopenharmony_ci$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread -lcrypto
10162306a36Sopenharmony_ci$(OUTPUT)/tcp_inq: LDLIBS += -lpthread
10262306a36Sopenharmony_ci$(OUTPUT)/bind_bhash: LDLIBS += -lpthread
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci# Rules to generate bpf objs
10562306a36Sopenharmony_ciCLANG ?= clang
10662306a36Sopenharmony_ciSCRATCH_DIR := $(OUTPUT)/tools
10762306a36Sopenharmony_ciBUILD_DIR := $(SCRATCH_DIR)/build
10862306a36Sopenharmony_ciBPFDIR := $(abspath ../../../lib/bpf)
10962306a36Sopenharmony_ciAPIDIR := $(abspath ../../../include/uapi)
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ciCCINCLUDE += -I../bpf
11262306a36Sopenharmony_ciCCINCLUDE += -I../../../../usr/include/
11362306a36Sopenharmony_ciCCINCLUDE += -I$(SCRATCH_DIR)/include
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ciBPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciMAKE_DIRS := $(BUILD_DIR)/libbpf
11862306a36Sopenharmony_ci$(MAKE_DIRS):
11962306a36Sopenharmony_ci	mkdir -p $@
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci# Get Clang's default includes on this system, as opposed to those seen by
12262306a36Sopenharmony_ci# '--target=bpf'. This fixes "missing" files on some architectures/distros,
12362306a36Sopenharmony_ci# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
12462306a36Sopenharmony_ci#
12562306a36Sopenharmony_ci# Use '-idirafter': Don't interfere with include mechanics except where the
12662306a36Sopenharmony_ci# build would have failed anyways.
12762306a36Sopenharmony_cidefine get_sys_includes
12862306a36Sopenharmony_ci$(shell $(1) $(2) -v -E - </dev/null 2>&1 \
12962306a36Sopenharmony_ci	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
13062306a36Sopenharmony_ci$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
13162306a36Sopenharmony_ciendef
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ciifneq ($(CROSS_COMPILE),)
13462306a36Sopenharmony_ciCLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
13562306a36Sopenharmony_ciendif
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ciCLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci$(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o: $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
14062306a36Sopenharmony_ci	$(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)		       \
14362306a36Sopenharmony_ci	   $(APIDIR)/linux/bpf.h					       \
14462306a36Sopenharmony_ci	   | $(BUILD_DIR)/libbpf
14562306a36Sopenharmony_ci	$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/     \
14662306a36Sopenharmony_ci		    EXTRA_CFLAGS='-g -O0'				       \
14762306a36Sopenharmony_ci		    DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ciEXTRA_CLEAN := $(SCRATCH_DIR)
150