Module Name: src Committed By: martin Date: Thu Sep 5 09:22:44 UTC 2024
Modified Files: src/distrib/sets/lists/base [netbsd-10]: mi src/distrib/sets/lists/debug [netbsd-10]: mi src/distrib/sets/lists/man [netbsd-10]: mi src/distrib/sets/lists/tests [netbsd-10]: mi src/etc/mtree [netbsd-10]: NetBSD.dist.tests src/sys/rump/net/lib/libshmif [netbsd-10]: if_shmem.c shmifvar.h src/tests/usr.bin [netbsd-10]: Makefile src/usr.bin [netbsd-10]: Makefile Added Files: src/tests/usr.bin/shmif_pcapin [netbsd-10]: Makefile d_pcap.in.bz2.uue d_pcap.out.bz2.uue t_basic.sh src/usr.bin/shmif_pcapin [netbsd-10]: Makefile shmif_pcapin.1 shmif_pcapin.c Log Message: Pull up following revision(s) (requested by ozaki-r in ticket #817): tests/usr.bin/Makefile: revision 1.41 (patch) distrib/sets/lists/base/mi: revision 1.1350 (patch) usr.bin/shmif_pcapin/shmif_pcapin.1: revision 1.1 distrib/sets/lists/man/mi: revision 1.1787 (patch) distrib/sets/lists/debug/mi: revision 1.447 (patch) tests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue: revision 1.1 sys/rump/net/lib/libshmif/if_shmem.c: revision 1.88 etc/mtree/NetBSD.dist.tests: revision 1.207 sys/rump/net/lib/libshmif/shmifvar.h: revision 1.12 usr.bin/shmif_pcapin/shmif_pcapin.c: revision 1.1 usr.bin/shmif_pcapin/Makefile: revision 1.1 tests/usr.bin/shmif_pcapin/t_basic.sh: revision 1.1 usr.bin/Makefile: revision 1.240 distrib/sets/lists/tests/mi: revision 1.1335 (patch) tests/usr.bin/shmif_pcapin/Makefile: revision 1.1 tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue: revision 1.1 shmif: export LOCK_* definitions They will be used by upcoming shmif_pcapin. Add shmif_pcapin(1) utility program It can send any frames that are stored in a pcap(3) file format to shmif(4) Ethernet interface via the bus of it. If you want to write some tests for networking with rump kernels and the tests need to send frames that are difficult to generate by stock programs, shmif_pcapin can be helpful. The author of shmif_pcapin is k-goda@IIJ and the man page is written by ozaki-r. tests: add a basic test for shmif_pcapin The original author of the test is k-goda@IIJ. ozaki-r tweaked the test to improve stability and added comments. distrib, etc: install shmif_pcapin and its tests To generate a diff of this commit: cvs rdiff -u -r1.1314.2.7 -r1.1314.2.8 src/distrib/sets/lists/base/mi cvs rdiff -u -r1.394.2.8 -r1.394.2.9 src/distrib/sets/lists/debug/mi cvs rdiff -u -r1.1757.2.11 -r1.1757.2.12 src/distrib/sets/lists/man/mi cvs rdiff -u -r1.1238.2.9 -r1.1238.2.10 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.197.2.3 -r1.197.2.4 src/etc/mtree/NetBSD.dist.tests cvs rdiff -u -r1.84.4.1 -r1.84.4.2 src/sys/rump/net/lib/libshmif/if_shmem.c cvs rdiff -u -r1.11 -r1.11.22.1 src/sys/rump/net/lib/libshmif/shmifvar.h cvs rdiff -u -r1.37 -r1.37.2.1 src/tests/usr.bin/Makefile cvs rdiff -u -r0 -r1.1.2.2 src/tests/usr.bin/shmif_pcapin/Makefile \ src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue \ src/tests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue \ src/tests/usr.bin/shmif_pcapin/t_basic.sh cvs rdiff -u -r1.238 -r1.238.2.1 src/usr.bin/Makefile cvs rdiff -u -r0 -r1.1.2.2 src/usr.bin/shmif_pcapin/Makefile \ src/usr.bin/shmif_pcapin/shmif_pcapin.1 \ src/usr.bin/shmif_pcapin/shmif_pcapin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/base/mi diff -u src/distrib/sets/lists/base/mi:1.1314.2.7 src/distrib/sets/lists/base/mi:1.1314.2.8 --- src/distrib/sets/lists/base/mi:1.1314.2.7 Thu Jun 20 18:07:03 2024 +++ src/distrib/sets/lists/base/mi Thu Sep 5 09:22:42 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1314.2.7 2024/06/20 18:07:03 martin Exp $ +# $NetBSD: mi,v 1.1314.2.8 2024/09/05 09:22:42 martin Exp $ # # Note: Don't delete entries from here - mark them as "obsolete" instead, # unless otherwise stated below. @@ -833,6 +833,7 @@ ./usr/bin/shar base-util-bin ./usr/bin/shlock base-util-bin ./usr/bin/shmif_dumpbus base-util-bin rump +./usr/bin/shmif_pcapin base-util-bin rump ./usr/bin/showmount base-nfsclient-bin ./usr/bin/shuffle base-util-bin ./usr/bin/skey base-util-bin skey Index: src/distrib/sets/lists/debug/mi diff -u src/distrib/sets/lists/debug/mi:1.394.2.8 src/distrib/sets/lists/debug/mi:1.394.2.9 --- src/distrib/sets/lists/debug/mi:1.394.2.8 Fri Aug 23 18:28:10 2024 +++ src/distrib/sets/lists/debug/mi Thu Sep 5 09:22:43 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.394.2.8 2024/08/23 18:28:10 martin Exp $ +# $NetBSD: mi,v 1.394.2.9 2024/09/05 09:22:43 martin Exp $ ./etc/mtree/set.debug comp-sys-root ./usr/lib comp-sys-usr compatdir ./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile @@ -801,6 +801,7 @@ ./usr/libdata/debug/usr/bin/sftp.debug comp-secsh-debug debug ./usr/libdata/debug/usr/bin/shlock.debug comp-util-debug debug ./usr/libdata/debug/usr/bin/shmif_dumpbus.debug comp-util-debug debug,rump +./usr/libdata/debug/usr/bin/shmif_pcapin.debug comp-util-debug debug,rump ./usr/libdata/debug/usr/bin/showmount.debug comp-nfsclient-debug debug ./usr/libdata/debug/usr/bin/shuffle.debug comp-util-debug debug ./usr/libdata/debug/usr/bin/size.debug comp-util-debug binutils,debug Index: src/distrib/sets/lists/man/mi diff -u src/distrib/sets/lists/man/mi:1.1757.2.11 src/distrib/sets/lists/man/mi:1.1757.2.12 --- src/distrib/sets/lists/man/mi:1.1757.2.11 Fri Jun 21 10:39:38 2024 +++ src/distrib/sets/lists/man/mi Thu Sep 5 09:22:42 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1757.2.11 2024/06/21 10:39:38 martin Exp $ +# $NetBSD: mi,v 1.1757.2.12 2024/09/05 09:22:42 martin Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -4027,6 +4027,7 @@ ./usr/share/man/html1/shar.html man-util-htmlman html ./usr/share/man/html1/shlock.html man-util-htmlman html ./usr/share/man/html1/shmif_dumpbus.html man-util-htmlman rump,html +./usr/share/man/html1/shmif_pcapin.html man-util-htmlman rump,html ./usr/share/man/html1/shuffle.html man-util-htmlman html ./usr/share/man/html1/skey.html man-util-htmlman skey,html ./usr/share/man/html1/skeyaudit.html man-util-htmlman skey,html @@ -7150,6 +7151,7 @@ ./usr/share/man/man1/shar.1 man-util-man .man ./usr/share/man/man1/shlock.1 man-util-man .man ./usr/share/man/man1/shmif_dumpbus.1 man-util-man rump,.man +./usr/share/man/man1/shmif_pcapin.1 man-util-man rump,.man ./usr/share/man/man1/shuffle.1 man-util-man .man ./usr/share/man/man1/skey.1 man-util-man skey,.man ./usr/share/man/man1/skeyaudit.1 man-util-man skey,.man Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1238.2.9 src/distrib/sets/lists/tests/mi:1.1238.2.10 --- src/distrib/sets/lists/tests/mi:1.1238.2.9 Sat Aug 24 16:42:26 2024 +++ src/distrib/sets/lists/tests/mi Thu Sep 5 09:22:44 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1238.2.9 2024/08/24 16:42:26 martin Exp $ +# $NetBSD: mi,v 1.1238.2.10 2024/09/05 09:22:44 martin Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6440,6 +6440,12 @@ ./usr/tests/usr.bin/shmif_dumpbus/d_pkthdrs.out.bz2.uue tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/shmif_dumpbus/shmbus.bz2.uue tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/shmif_dumpbus/t_basic tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/shmif_pcapin tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/shmif_pcapin/Atffile tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/shmif_pcapin/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua +./usr/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/shmif_pcapin/t_basic tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/sort tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/sort/Atffile tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/sort/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua Index: src/etc/mtree/NetBSD.dist.tests diff -u src/etc/mtree/NetBSD.dist.tests:1.197.2.3 src/etc/mtree/NetBSD.dist.tests:1.197.2.4 --- src/etc/mtree/NetBSD.dist.tests:1.197.2.3 Sat Aug 24 16:42:26 2024 +++ src/etc/mtree/NetBSD.dist.tests Thu Sep 5 09:22:44 2024 @@ -1,4 +1,4 @@ -# $NetBSD: NetBSD.dist.tests,v 1.197.2.3 2024/08/24 16:42:26 martin Exp $ +# $NetBSD: NetBSD.dist.tests,v 1.197.2.4 2024/09/05 09:22:44 martin Exp $ ./usr/libdata/debug/usr/tests ./usr/libdata/debug/usr/tests/atf @@ -472,6 +472,7 @@ ./usr/tests/usr.bin/sdiff ./usr/tests/usr.bin/sed ./usr/tests/usr.bin/shmif_dumpbus +./usr/tests/usr.bin/shmif_pcapin ./usr/tests/usr.bin/sort ./usr/tests/usr.bin/tar ./usr/tests/usr.bin/tmux Index: src/sys/rump/net/lib/libshmif/if_shmem.c diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.84.4.1 src/sys/rump/net/lib/libshmif/if_shmem.c:1.84.4.2 --- src/sys/rump/net/lib/libshmif/if_shmem.c:1.84.4.1 Sat Aug 24 16:42:26 2024 +++ src/sys/rump/net/lib/libshmif/if_shmem.c Thu Sep 5 09:22:44 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: if_shmem.c,v 1.84.4.1 2024/08/24 16:42:26 martin Exp $ */ +/* $NetBSD: if_shmem.c,v 1.84.4.2 2024/09/05 09:22:44 martin Exp $ */ /* * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.84.4.1 2024/08/24 16:42:26 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.84.4.2 2024/09/05 09:22:44 martin Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -111,10 +111,6 @@ struct shmif_sc { static void shmif_rcv(void *); -#define LOCK_UNLOCKED 0 -#define LOCK_LOCKED 1 -#define LOCK_COOLDOWN 1001 - vmem_t *shmif_units; static void Index: src/sys/rump/net/lib/libshmif/shmifvar.h diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.11 src/sys/rump/net/lib/libshmif/shmifvar.h:1.11.22.1 --- src/sys/rump/net/lib/libshmif/shmifvar.h:1.11 Fri Apr 3 13:57:48 2020 +++ src/sys/rump/net/lib/libshmif/shmifvar.h Thu Sep 5 09:22:44 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: shmifvar.h,v 1.11 2020/04/03 13:57:48 christos Exp $ */ +/* $NetBSD: shmifvar.h,v 1.11.22.1 2024/09/05 09:22:44 martin Exp $ */ /*- * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved. @@ -63,6 +63,10 @@ struct shmif_pkthdr { #define BUSMEM_SIZE (1024*1024U) #define BUSMEM_DATASIZE (BUSMEM_SIZE - sizeof(struct shmif_mem)) +#define LOCK_UNLOCKED 0 +#define LOCK_LOCKED 1 +#define LOCK_COOLDOWN 1001 + #if 0 #ifdef _KERNEL #include <rump/rumpuser.h> Index: src/tests/usr.bin/Makefile diff -u src/tests/usr.bin/Makefile:1.37 src/tests/usr.bin/Makefile:1.37.2.1 --- src/tests/usr.bin/Makefile:1.37 Thu Jul 21 09:52:48 2022 +++ src/tests/usr.bin/Makefile Thu Sep 5 09:22:42 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.37 2022/07/21 09:52:48 kre Exp $ +# $NetBSD: Makefile,v 1.37.2.1 2024/09/05 09:22:42 martin Exp $ # .include <bsd.own.mk> @@ -9,8 +9,8 @@ TESTS_SUBDIRS= awk basename bzip2 cc cmp diff dirname find fstat gdb grep gzip id indent \ infocmp jot ld locale m4 make mixerctl mkdep nbperf \ netpgpverify patch pkill pr printf pwhash realpath rump_server \ - shmif_dumpbus sdiff sed sort tar tmux tr unifdef uniq \ - vmstat xlint ztest + shmif_dumpbus shmif_pcapin sdiff sed sort tar tmux tr \ + unifdef uniq vmstat xlint ztest .if ${MKCXX} != "no" TESTS_SUBDIRS+= c++ Index: src/usr.bin/Makefile diff -u src/usr.bin/Makefile:1.238 src/usr.bin/Makefile:1.238.2.1 --- src/usr.bin/Makefile:1.238 Mon Jun 6 10:56:29 2022 +++ src/usr.bin/Makefile Thu Sep 5 09:22:44 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.238 2022/06/06 10:56:29 nia Exp $ +# $NetBSD: Makefile,v 1.238.2.1 2024/09/05 09:22:44 martin Exp $ # from: @(#)Makefile 8.3 (Berkeley) 1/7/94 .include <bsd.own.mk> @@ -48,7 +48,7 @@ SUBDIR+= apropos whatis .if (${MKRUMP} != "no") SUBDIR+= rump_allserver rump_dhcpclient rump_halt rump_server shmif_dumpbus \ - rump_wmd + shmif_pcapin rump_wmd .endif .if (${MKBSDGREP} != "no") Added files: Index: src/tests/usr.bin/shmif_pcapin/Makefile diff -u /dev/null src/tests/usr.bin/shmif_pcapin/Makefile:1.1.2.2 --- /dev/null Thu Sep 5 09:22:45 2024 +++ src/tests/usr.bin/shmif_pcapin/Makefile Thu Sep 5 09:22:43 2024 @@ -0,0 +1,11 @@ +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/usr.bin/shmif_pcapin +FILESDIR= ${TESTSDIR} + +TESTS_SH+= t_basic +TESTS_SH_SRC_t_basic= ../../net/net_common.sh t_basic.sh + +FILES+= d_pcap.in.bz2.uue d_pcap.out.bz2.uue + +.include <bsd.test.mk> Index: src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue diff -u /dev/null src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue:1.1.2.2 --- /dev/null Thu Sep 5 09:22:45 2024 +++ src/tests/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue Thu Sep 5 09:22:43 2024 @@ -0,0 +1,27 @@ +begin 644 d_pcap.in.bz2 +M0EIH.3%!6293671X8T@`",M_______TOA>KK]E_____W_____^\C:_:XZKOZ +M]#3:(5__T`/^`.@`&YM"%4,@-`!DQJ````T9&@``````T-!DT`&@```````` +M`:`/*%*@]1^GJHT`!ZAM(```#0T```:`!H:``&@````````````#1"?_ZJJ8 +MF`F```````!,``````````$R8````````$PFF(`T#30:#$R`&AD&C`(`#31D +M!A`9,@R:9-#$9,@-``:,@8F3(```#0`"HI(HU-I)Z0]0]1Z@`&F@:``-H@TR +M#:0\I_ZJ@]1I@@/4:,1ZAM33:FAIM3)ZCU-&F)^IFE/4\D:-E!Z@T:-J;-SK +MR`JJ%4J5)T*)-32B3R*)+)(CJ$2:E1)B(DZE826U/9(DPB3#@JQ9*B2PSSSS +M9LVP9M5FS9LV;-FS9LV;-FS9LV;-FS9YY^B\\0\^J17N5=!4RI/5U,(DK%&* +M+4Q6)$F+99227:0M%1)4F*+2]"26DF2),B\_$F%B2IHRPQ<&+5MEM7SBR),+ +M5NA$EP56V8PDD<U$E)I5'IE.XK)2KZVOS,FEDU^3H9-##$KC#IC=6T`````` +M`````````$!`^\_VJ&P;!ZKK/X\O9-8[E>O%K^>4,BKE+2UEE#G&E557XWT6 +M3)?&:'#=Z_8XKD/#<ISSQ7-=VYYWS6>=<=X3R;:N`W+<OE/FN&[MK/DNM:K5 +M5:B37(DK%Y:L63LU<^WK#KEAW"S0K;L&)$F_]WVR)-HB31I%Y*Z_'P[K:\!$ +MF6Q6N(B3'5:O3LMHB39(DP23<+QU<XI5B#=[S`R4V:)+.3X6#M>!@X2)+/;J +MU(2I$E@62254G\/$Y<AH=2T]`^6^\W3K42:>P?68W+;-5NVC?]BKLE>D1)[! +MAIV+L63:-'9,F.S=SP=#1O&'LU;Y7VE;5]MAL?N,,>Q8=$KE-&_9/NJR[5AT +M:OGJ<Q6[5-A3?.Z='X&@\TYB1NVX=XZIJ.*X;P'>O>NL=>UG?N*_6UW1/!<1 +MQ&V<1X+7<5Q7Q&NZMWW?]LUG\G&>&^DU72O+N4YCO'':6\=HWSKF]=H_JUVT +M8;IXC8."T.1QMN^1^'IG^6R;C>OZ$2<)>2[!I=6\JB2(!0'LHS1`1*+YBP:G +M<^L*HT2-$4:2-E635)24E@E*SFA]Z1`1.%C!!DXL&*2VN*BL9^L*\M)6`ZE7 +M35\PZ>-(A%.BD$,U)2TG'S,O.%EED(0A"(HOTT<OU]O?XC?D```````HI]&B +MI4911111B@:(7\)-.;XQ#&>&(8]>)+$G;[YCYC+M_H;?9NHB5R&HPYOI]5HZ +M>OIO&8((JP?0=@*@/^`GMR#G\",%>3">$0!3L@_2.$DN8QPFL,L#<G,@M@,: +J-JKQW2,:6F)XLZ5PWCHDXS0;&N$ITBCG5:$2?OYN3_XNY(IPH2#H\,:0 +` +end Index: src/tests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue diff -u /dev/null src/tests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue:1.1.2.2 --- /dev/null Thu Sep 5 09:22:45 2024 +++ src/tests/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue Thu Sep 5 09:22:43 2024 @@ -0,0 +1,13 @@ +begin 644 d_pcap.out.bz2 +M0EIH.3%!62936>CJBS$`#$]?@``00&5_\0@B0``_Y?]@0`*8VP``<_2/4T_U +M4!,``0P1AS_]50(9#31D9&1H9,@)JDDTF*>13U/4&0>IFB:;:H8`9--!D,$- +M,1HQTI'UI>:/S1B,1J3^)&3UD9,D=9'Y(_1'A(_J1RD?*1Y5(]I&2/&1SD<D +M<T??OF9F````````".THE5<[;+;H6@P`!555408@``-!@!SY[[[[[[\_C(\) +M'"D<Y&J1D)=NFVM:^5(Q&D>$C$:1WD<9'K2/YD<N/'-:RY2,KQD95JD9(=9& +M^M]9K4C:D:N$C*OWD962,K_*1OQVUK761DC>1VD=Y''COK6MY'G(VD<,X:UK +MVD;R.'#AK6M4C)&I&LUK6MI&U(R1FVV:UY2.TCTD>,C4C?>S)'61QD;2,D=) +M'I(X2/A(X2.E([2.5(^<C*1\Y'TD;2/*D?1&Z,1B/61]I'_2-I'WI'X1[R,1 +M]I'=&\CI(])'>D>T)>\C>$O@CM2.<CZR-4CA(R1DC$=4=Z1J1VD>Z/Q(^,CS +.1VD?^+N2*<*$AT=468@C +` +end Index: src/tests/usr.bin/shmif_pcapin/t_basic.sh diff -u /dev/null src/tests/usr.bin/shmif_pcapin/t_basic.sh:1.1.2.2 --- /dev/null Thu Sep 5 09:22:45 2024 +++ src/tests/usr.bin/shmif_pcapin/t_basic.sh Thu Sep 5 09:22:43 2024 @@ -0,0 +1,89 @@ +# $NetBSD: t_basic.sh,v 1.1.2.2 2024/09/05 09:22:43 martin Exp $ +# +# Copyright (c) 2017-2018 Internet Initiative Japan Inc. +# Copyright (c) 2011 The NetBSD Foundation, Inc. +# 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. +# + +SOCK=unix://commsock +BUS=bus0 + +unpack_file() +{ + + atf_check -s exit:0 uudecode $(atf_get_srcdir)/${1}.bz2.uue + atf_check -s exit:0 bunzip2 -f ${1}.bz2 +} + +atf_test_case pcap cleanup + +pcap_head() +{ + + atf_set "descr" "Write frames from pcap(3) file to shmif(4) interface" +} + +pcap_body() +{ + unpack_file d_pcap.in + unpack_file d_pcap.out + + rump_server_npf_start ${SOCK} # need librumpdev_bpf + rump_server_add_iface ${SOCK} shmif0 ${BUS} + + export RUMP_SERVER=${SOCK} + export LD_PRELOAD=/usr/lib/librumphijack.so + export RUMPHIJACK=path=/rump,socket=all:nolocal,sysctl=yes,,blanket=/dev/bpf + + atf_check -s exit:0 rump.ifconfig shmif0 up + + # Capture frames on shmif0 to examine later. + tcpdump -c 58 -eni shmif0 -w shmif0.in.pcap & + sleep 1 # give shmif0 a change to turn into promiscuous mode + # Write frames to the bus. + atf_check -s exit:0 -o ignore shmif_pcapin d_pcap.in ${BUS} + wait # for tcpdump to exit + + # Check if written frames surely arrives at shmif0. + atf_check -s exit:0 -o match:"input: 58 packets, 5684 bytes" rump.ifconfig -v shmif0 + # Check if frames captured on shmif0 are expected ones. + atf_check -s exit:0 -o file:d_pcap.out -e ignore tcpdump -entr shmif0.in.pcap + + unset LD_PRELOAD + unset RUMP_SERVER +} + +pcap_cleanup() +{ + + $DEBUG && dump + cleanup +} + + +atf_init_test_cases() +{ + + atf_add_test_case pcap +} Index: src/usr.bin/shmif_pcapin/Makefile diff -u /dev/null src/usr.bin/shmif_pcapin/Makefile:1.1.2.2 --- /dev/null Thu Sep 5 09:22:45 2024 +++ src/usr.bin/shmif_pcapin/Makefile Thu Sep 5 09:22:42 2024 @@ -0,0 +1,16 @@ +# $NetBSD: Makefile,v 1.1.2.2 2024/09/05 09:22:42 martin Exp $ +# + +PROG= shmif_pcapin + +.include <bsd.own.mk> + +SHMIFD= ${NETBSDSRCDIR}/sys/rump/net/lib/libshmif +.PATH: ${SHMIFD} + +SRCS+= shmif_pcapin.c shmif_busops.c +CPPFLAGS+= -I${SHMIFD} + +LDADD+= -lpcap + +.include <bsd.prog.mk> Index: src/usr.bin/shmif_pcapin/shmif_pcapin.1 diff -u /dev/null src/usr.bin/shmif_pcapin/shmif_pcapin.1:1.1.2.2 --- /dev/null Thu Sep 5 09:22:45 2024 +++ src/usr.bin/shmif_pcapin/shmif_pcapin.1 Thu Sep 5 09:22:42 2024 @@ -0,0 +1,53 @@ +.\" $NetBSD: shmif_pcapin.1,v 1.1.2.2 2024/09/05 09:22:42 martin Exp $ +.\" +.\" Copyright (c) 2024 Internet Initiative Japan Inc. +.\" 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 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. +.\" +.Dd August 30, 2024 +.Dt SHMIF_PCAPIN 1 +.Os +.Sh NAME +.Nm shmif_pcapin +.Nd sends frames to rump kernels via shmif bus +.Sh SYNOPSIS +.Nm +.Ar pcapfile +.Ar busfile +.Sh DESCRIPTION +The +.Nm +utility sends frames stored in +.Ar pcapfile +to rump kernels +via +.Ar busfile , +the bus of +.Xr shmif 4 +Ethernet interfaces attached to the rump kernels. +.El +.Sh SEE ALSO +.Xr pcap 3 , +.Xr shmif 4 +.Sh AUTHORS +.An Kazuya Goda Aq Mt k-g...@iij.ad.jp Index: src/usr.bin/shmif_pcapin/shmif_pcapin.c diff -u /dev/null src/usr.bin/shmif_pcapin/shmif_pcapin.c:1.1.2.2 --- /dev/null Thu Sep 5 09:22:45 2024 +++ src/usr.bin/shmif_pcapin/shmif_pcapin.c Thu Sep 5 09:22:42 2024 @@ -0,0 +1,212 @@ +/* $NetBSD: shmif_pcapin.c,v 1.1.2.2 2024/09/05 09:22:42 martin Exp $ */ + +/*- + * Copyright (c) 2017-2018 Internet Initiative Japan Inc. + * Copyright (c) 2010 Antti Kantee. + * 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 AUTHOR ``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. + */ + +#include <rump/rumpuser_port.h> + +#ifndef lint +__RCSID("$NetBSD: shmif_pcapin.c,v 1.1.2.2 2024/09/05 09:22:42 martin Exp $"); +#endif /* !lint */ + +#include <stddef.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/atomic.h> +#include <sys/bswap.h> + +#include <assert.h> +#include <err.h> +#include <fcntl.h> +#include <inttypes.h> +#include <pcap.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "shmifvar.h" + +__dead static void +usage(void) +{ + +#ifndef HAVE_GETPROGNAME +#define getprogname() "shmif_pcapin" +#endif + + fprintf(stderr, "usage: %s pcap-file-path bus-path\n", getprogname()); + exit(1); +} + +/* + * The BUFSIZE come from shmif_dumpbus.c because there're not any experiences to + * make a decision about best size. + */ +#define BUFSIZE 64*1024 + +/* + * dowakeup, shmif_lockbus and shmif_unlockbus copy from + * sys/rump/net/lib/libshimif/if_shmem.c. So if you have to understood locking + * mechanism, you also see that. + */ +static int +dowakeup(int memfd) +{ + struct iovec iov; + uint32_t ver = SHMIF_VERSION; + + iov.iov_base = &ver; + iov.iov_len = sizeof(ver); + + if (lseek(memfd, IFMEM_WAKEUP, SEEK_SET) == IFMEM_WAKEUP) + return writev(memfd, &iov, 1); + else + return -1; +} + +/* + * This locking needs work and will misbehave severely if: + * 1) the backing memory has to be paged in + * 2) some lockholder exits while holding the lock + */ +static void +shmif_lockbus(struct shmif_mem *busmem) +{ + int i = 0; + + while (__predict_false(atomic_cas_32(&busmem->shm_lock, + LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) { + if (__predict_false(++i > LOCK_COOLDOWN)) { + usleep(1000); + i = 0; + } + continue; + } + membar_enter(); +} + +static void +shmif_unlockbus(struct shmif_mem *busmem) +{ + unsigned int old __diagused; + + membar_exit(); + old = atomic_swap_32(&busmem->shm_lock, LOCK_UNLOCKED); + assert(old == LOCK_LOCKED); +} + + +int +main(int argc, char *argv[]) +{ + struct stat sb; + void *busmem; + struct shmif_mem *bmem; + int fd; + const u_char *pkt; + char *buf; + char pcap_errbuf[PCAP_ERRBUF_SIZE]; + pcap_t *pcap; + struct pcap_pkthdr pcaphdr; + + argc -= optind; + argv += optind; + + if (argc != 2) + usage(); + + buf = malloc(BUFSIZE); + if (buf == NULL) + err(EXIT_FAILURE, "malloc"); + + fd = open(argv[1], O_RDWR); + if (fd == -1) + err(EXIT_FAILURE, "open bus"); + + if (fstat(fd, &sb) == -1) + err(EXIT_FAILURE, "stat"); + + busmem = mmap(NULL, sb.st_size, PROT_WRITE|PROT_READ, + MAP_FILE|MAP_SHARED, fd, 0); + if (busmem == MAP_FAILED) + err(EXIT_FAILURE, "mmap"); + bmem = busmem; + + if (bmem->shm_magic != SHMIF_MAGIC) + errx(EXIT_FAILURE, "%s not a shmif bus", argv[1]); + + /* + * if bmem->shm_version is 0, it indicates to not write any packets + * by anyone. + */ + if (bmem->shm_version != SHMIF_VERSION && bmem->shm_version != 0) + errx(EXIT_FAILURE, "bus version %d, program %d", + bmem->shm_version, SHMIF_VERSION); + + fprintf(stdout, "bus version %d, lock: %d, generation: %" PRIu64 + ", firstoff: 0x%04x, lastoff: 0x%04x\n", bmem->shm_version, + bmem->shm_lock, bmem->shm_gen, bmem->shm_first, bmem->shm_last); + + pcap = pcap_open_offline(argv[0], pcap_errbuf); + if (pcap == NULL) + err(EXIT_FAILURE, "cannot open pcap file: %s", pcap_errbuf); + + while ((pkt = pcap_next(pcap, &pcaphdr))) { + struct shmif_pkthdr sp; + uint32_t dataoff; + struct timeval tv; + bool wrap; + + gettimeofday(&tv, NULL); + sp.sp_len = pcaphdr.len; + sp.sp_sec = tv.tv_sec; + sp.sp_usec = tv.tv_usec; + memcpy(buf, pkt, pcaphdr.len); + + shmif_lockbus(bmem); + + bmem->shm_last = shmif_nextpktoff(bmem, bmem->shm_last); + wrap = false; + + dataoff = shmif_buswrite(bmem, bmem->shm_last, &sp, + sizeof(sp), &wrap); + dataoff = shmif_buswrite(bmem, dataoff, buf, pcaphdr.len, &wrap); + + if (wrap) + bmem->shm_gen++; + + shmif_unlockbus(bmem); + } + + if (dowakeup(fd) == -1) + errx(EXIT_FAILURE, "writev for wakeup"); + + return 0; +}