Skip to content

Instantly share code, notes, and snippets.

@notsure2
Last active July 13, 2019 00:37
Show Gist options
  • Save notsure2/cd0636579f0184d1c0d83a7ad7388f30 to your computer and use it in GitHub Desktop.
Save notsure2/cd0636579f0184d1c0d83a7ad7388f30 to your computer and use it in GitHub Desktop.

Revisions

  1. notsure2 revised this gist May 21, 2019. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions tunsafe_patch.diff
    Original file line number Diff line number Diff line change
    @@ -46,3 +46,15 @@ index 17f855c..2772d06 100644
    #else
    for(const WgCidrAddr &a : addresses_to_remove_) {
    if (a.size == 32) {
    diff --git a/tunsafe_cpu.h b/tunsafe_cpu.h
    index c19f6b1..d5f1a71 100644
    --- a/tunsafe_cpu.h
    +++ b/tunsafe_cpu.h
    @@ -32,7 +32,7 @@ extern uint32 x86_pcap[3];

    extern uint32 arm_pcap[1];

    -#define ARM_PCAP_NEON (arm_pcap[0] & (1 << 0))
    +#define ARM_PCAP_NEON 0

    #endif // defined(ARCH_CPU_ARM_FAMILY)
  2. notsure2 revised this gist May 21, 2019. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions build_tomato_arm.sh
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,15 @@
    #!/bin/sh
    # Put this file in TunSafe git checkout after compiling buildroot
    # It produces a statically linked binary.
    # Tested launch on R7000

    set -e
    #cpp -D__ARM_ARCH__=7 crypto/chacha20/chacha20-arm.s > crypto/chacha20/chacha20-arm.preprocessed.s
    #cpp -D__ARM_ARCH__=7 crypto/poly1305/poly1305-arm.s > crypto/poly1305/poly1305-arm.preprocessed.s

    /home/buildroot-2019.02.2/output/host/bin/arm-linux-g++ \
    -mfloat-abi=softfp -I . -g -O2 -DNDEBUG -DWITH_NETWORK_BSD=1 \
    -fno-omit-frame-pointer -march=armv7-a -mthumb -pthread -lrt -o tunsafe \
    ~/freshtomato/buildroot-2019.02.2/output/host/bin/arm-linux-g++ \
    -march=armv7-a -mtune=cortex-a9 -mfloat-abi=soft -mthumb \
    -I . -g -O2 -DNDEBUG -DWITH_NETWORK_BSD=1 \
    -fno-omit-frame-pointer -pthread -lrt -o tunsafe \
    tunsafe_amalgam.cpp \
    crypto/chacha20/chacha20-arm-linux.S \
    crypto/poly1305/poly1305-arm-linux.S \
    -std=c++11 \
    -static
    -static
  3. notsure2 revised this gist May 21, 2019. 1 changed file with 37 additions and 2 deletions.
    39 changes: 37 additions & 2 deletions tunsafe_patch.diff
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    diff --git a/tunsafe_bsd.cpp b/tunsafe_bsd.cpp
    index 17f855c..d317b3d 100644
    index 17f855c..2772d06 100644
    --- a/tunsafe_bsd.cpp
    +++ b/tunsafe_bsd.cpp
    @@ -36,7 +36,7 @@
    @@ -10,4 +10,39 @@ index 17f855c..d317b3d 100644
    +// #include <linux/if.h>
    #include <linux/if_tun.h>
    #include <sys/prctl.h>
    #include <linux/rtnetlink.h>
    #include <linux/rtnetlink.h>
    @@ -367,9 +367,9 @@ static void AddOrRemoveRoute(const RouteInfo &cd, bool remove) {
    const char *cmd = remove ? "del" : "add";
    const char *proto = (cd.family == AF_INET) ? NULL : "-6";
    if (cd.dev.empty()) {
    - RunCommand("/sbin/ip %s route %s %s via %s", proto, cmd, buf1, buf2);
    + RunCommand("/usr/sbin/ip %s route %s %s via %s", proto, cmd, buf1, buf2);
    } else {
    - RunCommand("/sbin/ip %s route %s %s dev %s", proto, cmd, buf1, cd.dev.c_str());
    + RunCommand("/usr/sbin/ip %s route %s %s dev %s", proto, cmd, buf1, cd.dev.c_str());
    }
    #elif defined(OS_MACOSX) || defined(OS_FREEBSD)
    const char *cmd = remove ? "delete" : "add";
    @@ -436,10 +436,10 @@ bool TunsafeBackendBsd::Configure(const TunConfig &&config, TunConfigOut *out) o
    addresses_to_remove_ = config.addresses;

    #if defined(OS_LINUX)
    - RunCommand("/sbin/ip address flush dev %s scope global", devname_);
    + RunCommand("/usr/sbin/ip address flush dev %s scope global", devname_);
    for(const WgCidrAddr &a : config.addresses)
    - RunCommand("/sbin/ip address add dev %s %s", devname_, print_ip_prefix(buf, a.size == 32 ? AF_INET : AF_INET6, a.addr, a.cidr));
    - RunCommand("/sbin/ip link set dev %s mtu %d up", devname_, config.mtu);
    + RunCommand("/usr/sbin/ip address add dev %s %s", devname_, print_ip_prefix(buf, a.size == 32 ? AF_INET : AF_INET6, a.addr, a.cidr));
    + RunCommand("/usr/sbin/ip link set dev %s mtu %d up", devname_, config.mtu);
    #else
    for(const WgCidrAddr &a : config.addresses) {
    if (a.size == 32) {
    @@ -515,7 +515,7 @@ void TunsafeBackendBsd::CleanupRoutes() {

    #if defined(OS_LINUX)
    for(const WgCidrAddr &a : addresses_to_remove_)
    - RunCommand("/sbin/ip address del dev %s %s", devname_, print_ip_prefix(buf, a.size == 32 ? AF_INET : AF_INET6, a.addr, a.cidr));
    + RunCommand("/usr/sbin/ip address del dev %s %s", devname_, print_ip_prefix(buf, a.size == 32 ? AF_INET : AF_INET6, a.addr, a.cidr));
    #else
    for(const WgCidrAddr &a : addresses_to_remove_) {
    if (a.size == 32) {
  4. notsure2 revised this gist May 21, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion build_tomato_arm.sh
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,5 @@ set -e
    tunsafe_amalgam.cpp \
    crypto/chacha20/chacha20-arm-linux.S \
    crypto/poly1305/poly1305-arm-linux.S \
    -std=c++11
    -std=c++11 \
    -static
  5. notsure2 created this gist May 21, 2019.
    16 changes: 16 additions & 0 deletions build_tomato_arm.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/bin/sh
    # Put this file in TunSafe git checkout after compiling buildroot
    # It produces a statically linked binary.
    # Tested launch on R7000

    set -e
    #cpp -D__ARM_ARCH__=7 crypto/chacha20/chacha20-arm.s > crypto/chacha20/chacha20-arm.preprocessed.s
    #cpp -D__ARM_ARCH__=7 crypto/poly1305/poly1305-arm.s > crypto/poly1305/poly1305-arm.preprocessed.s

    /home/buildroot-2019.02.2/output/host/bin/arm-linux-g++ \
    -mfloat-abi=softfp -I . -g -O2 -DNDEBUG -DWITH_NETWORK_BSD=1 \
    -fno-omit-frame-pointer -march=armv7-a -mthumb -pthread -lrt -o tunsafe \
    tunsafe_amalgam.cpp \
    crypto/chacha20/chacha20-arm-linux.S \
    crypto/poly1305/poly1305-arm-linux.S \
    -std=c++11
    3,797 changes: 3,797 additions & 0 deletions buildroot_config
    3,797 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
    13 changes: 13 additions & 0 deletions tunsafe_patch.diff
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    diff --git a/tunsafe_bsd.cpp b/tunsafe_bsd.cpp
    index 17f855c..d317b3d 100644
    --- a/tunsafe_bsd.cpp
    +++ b/tunsafe_bsd.cpp
    @@ -36,7 +36,7 @@
    #include <net/if_tun.h>
    #include <net/if_dl.h>
    #elif defined(OS_LINUX)
    -#include <linux/if.h>
    +// #include <linux/if.h>
    #include <linux/if_tun.h>
    #include <sys/prctl.h>
    #include <linux/rtnetlink.h>