Commit bec54710 authored by 神楽坂玲奈's avatar 神楽坂玲奈

new

parent c512117d
Pipeline #16679 passed with stages
in 43 seconds
......@@ -3,9 +3,9 @@ project(tun)
set(CMAKE_CXX_STANDARD 20)
add_executable(tun src/Config.h src/Router.h src/checksum.h src/main.cpp)
add_executable(tun src/main.cpp)
set(CMAKE_CXX_FLAGS_DEBUG -ggdb)
#set(CMAKE_CXX_FLAGS_DEBUG -ggdb)
find_package(Threads REQUIRED)
target_link_libraries(tun Threads::Threads)
......
#!/bin/bash
pid=0
down=$(echo $1 | jq -r '.routers | .[].up')
echo $down
run_stop() {
signalCode=$1
if [ -n "$DOWN_SCRIPT" ]; then
eval "$DOWN_SCRIPT"
if [ -n "$down" ]; then
eval "$down"
fi
if [ $pid -ne 0 ]; then
kill "-$signalCode" "$pid"
......
......@@ -2,7 +2,6 @@
#define TUN_CONFIG_H
#include <nlohmann/json.hpp>
#include <boost/core/noncopyable.hpp>
using json = nlohmann::json;
......
......@@ -8,6 +8,5 @@ uint16_t csum(uint16_t *packet, int packlen) {
}
if (packlen > 0) sum += *(unsigned char *) packet;
while (sum >> 16) sum = (sum & 0xffff) + (sum >> 16);
return (uint16_t)
~sum;
return (uint16_t) ~sum;
}
\ No newline at end of file
......@@ -26,13 +26,13 @@ void inbound(int raw) {
socklen_t address_length = sizeof(address);
size_t packet_length;
while ((packet_length = recvfrom(raw, buffer, sizeof(buffer), 0, (sockaddr *) &address, &address_length)) >= 0) {
auto header_length = ((ipv6hdr *) buffer)->version == 4 ? ((iphdr *) buffer)->ihl : sizeof(ipv6hdr);
auto header_length = ((ipv6hdr *) buffer)->version == 4 ? ((iphdr *) buffer)->ihl * 4 : sizeof(ipv6hdr);
auto meta = (Meta *) (buffer + header_length);
if (!(Router::all.contains(meta->src_id) && meta->dst_id == config.local_id && meta->reserved == 0)) continue;
auto router = Router::all[meta->src_id];
auto inner = buffer + header_length + sizeof(Meta);
auto payload_length = packet_length - header_length - sizeof(Meta);
router->decrypt(inner, payload_length);
auto inner = buffer + (header_length + sizeof(Meta));
auto inner_length = packet_length - (header_length + sizeof(Meta));
router->decrypt(inner, inner_length);
switch (((ipv6hdr *) inner)->version) {
case 4:
if (csum((uint16_t *) inner, ((iphdr *) inner)->ihl * 4)) continue;
......@@ -45,7 +45,7 @@ void inbound(int raw) {
}
router->remote_addr = address;
if (write(router->tun, inner, payload_length) < 0) {
if (write(router->tun, inner, inner_length) < 0) {
perror("inbound write");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment