Merge branch 'feat-freebsd' into 'main'

Support for FreeBSD

See merge request Monsterovich/lanemu!21
This commit is contained in:
Nikolay Borodin 2024-03-06 12:28:23 +00:00
commit 8bc524b711
17 changed files with 1966 additions and 1013 deletions

View file

@ -1,6 +1,24 @@
CLIB_DIR="../clib"
CLIB_DIR=../clib
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
export PKG_CONFIG_PATH=$(shell pwd)/pkg-config/linux
endif
ifeq ($(UNAME), FreeBSD)
export PKG_CONFIG_PATH=$(shell pwd)/pkg-config/freebsd
endif
freebsd:
@$(MAKE) -C tapLinux DEFAULTCONF=Release-amd64
@$(MAKE) -C appIndicator
mkdir -p ${CLIB_DIR}
install -m 744 tapLinux/dist/Release/* ${CLIB_DIR}
install -m 744 appIndicator/dist/Release/* ${CLIB_DIR}
# for build system
all:
@$(MAKE) -C tapLinux DEFAULTCONF=Release-i386
@$(MAKE) -C tapLinux DEFAULTCONF=Release-amd64
@ -20,4 +38,4 @@ install:
mkdir -p ${CLIB_DIR}
install -m 744 tapLinux/dist/Release/* ${CLIB_DIR}
install -m 744 appIndicator/dist/Release/* ${CLIB_DIR}
install -m 644 tapWindows/dist/Release/* ${CLIB_DIR}
install -m 644 tapWindows/dist/Release/* ${CLIB_DIR}

View file

@ -39,7 +39,7 @@ OBJECTFILES= \
# C Compiler Flags
CFLAGS=-m64 $(shell pkg-config --cflags ayatana-appindicator3-0.1 libnotify)
CFLAGS=-m64 $(shell pkg-config --cflags jdk ayatana-appindicator3-0.1 libnotify)
# CC Compiler Flags
CCFLAGS=

View file

@ -37,7 +37,7 @@
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include</pElem>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include/linux</pElem>
</incDir>
<commandLine>$(shell pkg-config --cflags ayatana-appindicator3-0.1 libnotify)</commandLine>
<commandLine>$(shell pkg-config --cflags jdk ayatana-appindicator3-0.1 libnotify)</commandLine>
</cTool>
<linkerTool>
<output>dist/Release/libAppIndicator64.so</output>

View file

@ -0,0 +1,5 @@
Name: Jdk
Description: The jdk headers
Version: 11
Cflags: -I/usr/local/openjdk11/include -I/usr/local/openjdk11/include/freebsd

View file

@ -0,0 +1,5 @@
Name: Jdk
Description: The jdk headers
Version: 11
Cflags: -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux

View file

@ -39,7 +39,7 @@ OBJECTFILES= \
# C Compiler Flags
CFLAGS=-m64
CFLAGS=-m64 $(shell pkg-config --cflags jdk) ${EXTRA_CFLAGS}
# CC Compiler Flags
CCFLAGS=
@ -65,7 +65,7 @@ dist/Release/libTunTapLinux64.so: ${OBJECTFILES}
${OBJECTDIR}/org_p2pvpn_tuntap_TunTapLinux.o: org_p2pvpn_tuntap_TunTapLinux.c
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.c) -O2 -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapLinux.o org_p2pvpn_tuntap_TunTapLinux.c
$(COMPILE.c) -O2 -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapLinux.o org_p2pvpn_tuntap_TunTapLinux.c
# Subprojects
.build-subprojects:

View file

@ -39,7 +39,7 @@ OBJECTFILES= \
# C Compiler Flags
CFLAGS=-m32
CFLAGS=-m32 $(shell pkg-config --cflags jdk) ${EXTRA_CFLAGS}
# CC Compiler Flags
CCFLAGS=
@ -65,7 +65,7 @@ dist/Release/libTunTapLinux.so: ${OBJECTFILES}
${OBJECTDIR}/org_p2pvpn_tuntap_TunTapLinux.o: org_p2pvpn_tuntap_TunTapLinux.c
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.c) -O2 -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapLinux.o org_p2pvpn_tuntap_TunTapLinux.c
$(COMPILE.c) -O2 -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapLinux.o org_p2pvpn_tuntap_TunTapLinux.c
# Subprojects
.build-subprojects:

View file

@ -33,10 +33,10 @@
<cTool>
<developmentMode>5</developmentMode>
<architecture>2</architecture>
<incDir>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include</pElem>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include/linux</pElem>
</incDir>
<commandLine>$(shell pkg-config --cflags jdk)</commandLine>
<preprocessorList>
<Elem>USE_TRANSIENT</Elem>
</preprocessorList>
</cTool>
<linkerTool>
<output>dist/Release/libTunTapLinux64.so</output>
@ -57,10 +57,10 @@
<cTool>
<developmentMode>5</developmentMode>
<architecture>1</architecture>
<incDir>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include</pElem>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include/linux</pElem>
</incDir>
<commandLine>$(shell pkg-config --cflags jdk)</commandLine>
<preprocessorList>
<Elem>USE_TRANSIENT</Elem>
</preprocessorList>
</cTool>
<linkerTool>
<output>dist/Release/libTunTapLinux.so</output>

View file

@ -20,12 +20,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#ifdef __FreeBSD__
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_tap.h>
#else
#include <linux/ioctl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#endif
#ifdef __FreeBSD__
#define TUNTAP_DEV "/dev/tap"
#else
#define TUNTAP_DEV "/dev/net/tun"
#endif
#include <jni.h>
#include "org_p2pvpn_tuntap_TunTapLinux.h"
@ -64,20 +78,47 @@ JFUNC(jint, openTun) {
struct ifreq ifr;
int fd;
if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
#ifdef __FreeBSD__
int i;
size_t len = sizeof(i);
sysctlbyname("net.link.tap.devfs_cloning", &i, &len, NULL, 0);
if (!i) {
printf("error: net.link.tap.devfs_cloning = 0\n");
return 1;
}
#endif
if ((fd = open(TUNTAP_DEV, O_RDWR)) < 0) {
printf("error: open\n");
return 1;
}
#ifdef __FreeBSD__
#ifdef USE_TRANSIENT
i = 1;
if (ioctl(fd, TAPSTRANSIENT, &i) < 0) {
printf("error: ioctl(TAPSTRANSIENT)\n");
return 1;
}
#endif
if (ioctl(fd, TAPGIFNAME, (void*)&ifr) < 0) {
close(fd);
printf("error: ioctl(TAPGIFNAME)\n");
return 1;
}
#else
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(fd, TUNSETIFF, (void*)&ifr) < 0) {
close(fd);
printf("error: ioctl\n");
printf("error: ioctl(TUNSETIFF)\n");
return 1;
}
#endif
setFdDev(env, this, fd, ifr.ifr_name);

View file

@ -39,7 +39,7 @@ OBJECTFILES= \
# C Compiler Flags
CFLAGS=-m32
CFLAGS=-m32 $(shell pkg-config --cflags jdk)
# CC Compiler Flags
CCFLAGS=
@ -65,7 +65,7 @@ dist/Release/libTunTapWindows.dll: ${OBJECTFILES}
${OBJECTDIR}/org_p2pvpn_tuntap_TunTapWindows.o: org_p2pvpn_tuntap_TunTapWindows.c
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.c) -O2 -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapWindows.o org_p2pvpn_tuntap_TunTapWindows.c
$(COMPILE.c) -O2 -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapWindows.o org_p2pvpn_tuntap_TunTapWindows.c
# Subprojects
.build-subprojects:

View file

@ -39,7 +39,7 @@ OBJECTFILES= \
# C Compiler Flags
CFLAGS=-m64
CFLAGS=-m64 $(shell pkg-config --cflags jdk)
# CC Compiler Flags
CCFLAGS=
@ -65,7 +65,7 @@ dist/Release/libTunTapWindows64.dll: ${OBJECTFILES}
${OBJECTDIR}/org_p2pvpn_tuntap_TunTapWindows.o: org_p2pvpn_tuntap_TunTapWindows.c
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.c) -O2 -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapWindows.o org_p2pvpn_tuntap_TunTapWindows.c
$(COMPILE.c) -O2 -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/org_p2pvpn_tuntap_TunTapWindows.o org_p2pvpn_tuntap_TunTapWindows.c
# Subprojects
.build-subprojects:

View file

@ -34,10 +34,7 @@
<developmentMode>5</developmentMode>
<architecture>1</architecture>
<commandlineTool>i686-w64-mingw32-gcc</commandlineTool>
<incDir>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include</pElem>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include/linux</pElem>
</incDir>
<commandLine>$(shell pkg-config --cflags jdk)</commandLine>
</cTool>
<linkerTool>
<output>dist/Release/libTunTapWindows.dll</output>
@ -59,10 +56,7 @@
<developmentMode>5</developmentMode>
<architecture>2</architecture>
<commandlineTool>x86_64-w64-mingw32-gcc</commandlineTool>
<incDir>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include</pElem>
<pElem>/usr/lib/jvm/java-11-openjdk-amd64/include/linux</pElem>
</incDir>
<commandLine>$(shell pkg-config --cflags jdk)</commandLine>
</cTool>
<linkerTool>
<output>dist/Release/libTunTapWindows64.dll</output>

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
build.xml.data.CRC32=8a1a520a
build.xml.script.CRC32=18fa743c
build.xml.stylesheet.CRC32=28e38971@1.38.2.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=60833d52
nbproject/build-impl.xml.script.CRC32=033dd344
nbproject/build-impl.xml.stylesheet.CRC32=f33e10ff@1.38.2.45
build.xml.data.CRC32=8a1a520a
build.xml.script.CRC32=18fa743c
build.xml.stylesheet.CRC32=28e38971@1.38.2.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=60833d52
nbproject/build-impl.xml.script.CRC32=0262032a
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.107.0.48

View file

@ -1,74 +1,86 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=P2PVPN
application.vendor=nerv
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/P2PVPN.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit.classpath}:\
${libs.junit_4.classpath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.clib.dir=clib
src.resources.dir=resources
src.src.dir=src
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=P2PVPN
application.vendor=nerv
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/P2PVPN.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit.classpath}:\
${libs.junit_4.classpath}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.clib.dir=clib
src.resources.dir=resources
src.src.dir=src

View file

@ -147,8 +147,9 @@ public class MainWindow extends javax.swing.JFrame implements RoutungTableListen
});
popupMenu.add(quit);
boolean isLinux = System.getProperty("os.name").startsWith("Linux");
String osName = System.getProperty("os.name");
boolean isLinux = osName.startsWith("Linux") || osName.startsWith("FreeBSD");
if (isLinux) {
trayIcon = new AppIndicatorTrayIcon(
Toolkit.getDefaultToolkit().getImage(InfoWindow.class.getClassLoader().getResource(LANEMU_IMG)),

View file

@ -75,7 +75,7 @@ public abstract class TunTap {
if (osName.startsWith("Windows")) {
return new TunTapWindows();
} else if (osName.equals("Linux")) {
} else if (osName.equals("Linux") || osName.equals("FreeBSD")) {
return new TunTapLinux();
} else {
throw new Exception("The operating system " + osName + " is not supported!");