Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled IPV6_V6ONLY option for tcp IPv6 bind logic, net.ipv6.bindv6on… #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmake-build
*.o
Makefile.depend
udptunnel
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required (VERSION 3.10)
project ("udptunnel" "C")

if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message (FATAL_ERROR "In-source builds are not allowed")
endif ()

set (CMAKE_PROJECT_DESCRIPTION "UDP tunnel over TCP")
set (CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/andrew-aladjev/udptunnel")
set (PROJECT_VERSION "1.2.1")

if (NOT DEFINED CMAKE_INSTALL_BINDIR)
set (CMAKE_INSTALL_BINDIR "sbin" CACHE PATH "output directory for binaries")
endif ()

set (CMAKE_C_FLAGS "-O2 -std=c11 -Wall")
set (CMAKE_EXE_LINKER_FLAGS "-static")

if (NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set (CMAKE_BUILD_TYPE "Release")
endif ()

set (
SOURCES
"log.c"
"network.c"
"udptunnel.c"
"utils.c"
)

add_executable (${PROJECT_NAME} ${SOURCES})
install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

include (CPackConfig.cmake)
include (CPack)
29 changes: 29 additions & 0 deletions CPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
set (CPACK_PACKAGE_NAME ${PROJECT_NAME})
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set (CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")

set (CPACK_PACKAGE_LICENSE "LGPLv2")
set (CPACK_RPM_PACKAGE_LICENSE ${CPACK_PACKAGE_LICENSE})
set (CPACK_FREEBSD_PACKAGE_LICENSE ${CPACK_PACKAGE_LICENSE})

set (CPACK_PACKAGE_MAINTAINER "Andrew Aladjev <[email protected]>")
set (CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_MAINTAINER})
set (CPACK_FREEBSD_PACKAGE_MAINTAINER ${CPACK_PACKAGE_MAINTAINER})

set (CPACK_DEBIAN_PACKAGE_SECTION "net")
set (CPACK_FREEBSD_PACKAGE_ORIGIN "net/${PROJECT_NAME}")

set (CPACK_PACKAGE_ARCHITECTURE "amd64")
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE})
set (CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE})

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
set (CPACK_GENERATOR "DEB" "RPM")
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set (CPACK_GENERATOR "FREEBSD")
endif ()

set (PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set (CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_PACKAGE_ARCHITECTURE}")
set (CPACK_STRIP_FILES true)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
UDP tunnel over TCP. License: LGPLv2.

Please build it using the following commands:

```bash
rm -rf cmake-build
cmake -S . -B cmake-build
cmake --build cmake-build
cmake --build cmake-build --target package
```

After that you will receive packages for DEB-based and RPM-based distros:

```
cmake-build/udptunnel-*.amd64.deb
cmake-build/udptunnel-*.amd64.rpm
```
5 changes: 5 additions & 0 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ int *tcp_listener(const char *s)
if ((fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) < 0)
continue; /* ignore */
opt = 1;
if (ai->ai_family == AF_INET6) {
/* we are going to bind to IPv6 address only */
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)) < 0)
err_sys("setsockopt(IPPROTO_IPV6, IPV6_V6ONLY)");
}
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0)
err_sys("setsockopt(SOL_SOCKET, SO_REUSEADDR)");
if (bind(fd, (struct sockaddr *) ai->ai_addr, ai->ai_addrlen) < 0)
Expand Down
4 changes: 1 addition & 3 deletions udptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@ static void tcp_to_udp(struct relay *relay)

static void send_handshake(struct relay *relay)
{
if (sendto(relay->tcp_sock, relay->handshake, sizeof(relay->handshake), 0,
(struct sockaddr *) &relay->remote_udpaddr,
sizeof(relay->remote_udpaddr)) < 0)
if (send(relay->tcp_sock, relay->handshake, sizeof(relay->handshake), 0) < 0)
err_sys("sendto(tcp, handshake)");
}

Expand Down