Compare commits
220 Commits
fd1a1285ac
...
e4988b9e9c
| Author | SHA1 | Date | |
|---|---|---|---|
|
e4988b9e9c
|
|||
|
0183b35acf
|
|||
|
|
faeb599a19 | ||
|
|
a4e72918df | ||
|
|
d7e8dbe0e7 | ||
|
|
71d16f25ff | ||
|
|
c426cef08b | ||
|
|
bda2c6eaa7 | ||
|
|
d68aee8249 | ||
|
|
2f966bb365 | ||
|
|
4a7740f70f | ||
|
|
5be4096452 | ||
|
|
3747aa7abd | ||
|
|
e3eb1f96a5 | ||
|
|
2f5e346532 | ||
|
|
a9fdd76fa3 | ||
|
|
0a9a139409 | ||
|
|
2811e2383f | ||
|
|
ed6cc0e6f6 | ||
|
|
487474a80e | ||
|
|
edb86d27ad | ||
|
|
c0d2118a77 | ||
|
|
70e80f76e0 | ||
|
|
e4092ebebd | ||
|
|
2330e6470e | ||
|
|
7d59eedd39 | ||
|
|
c536bef802 | ||
|
|
23a5cdfe31 | ||
|
|
6894867b9f | ||
|
|
8f11ffa5a4 | ||
|
|
1f18b731c4 | ||
|
|
e3689d29b7 | ||
|
|
2a812f332f | ||
|
|
b16a754713 | ||
|
|
b6238c939e | ||
|
|
6e8a3cef1e | ||
|
|
e56abf5eaa | ||
|
|
6b1881e94c | ||
|
|
7ff46e742b | ||
|
|
a87a277701 | ||
|
|
ef41aa28ce | ||
|
|
d5322e187d | ||
|
|
0a2b23bb88 | ||
|
|
3a30c63eff | ||
|
|
9c27f92f9d | ||
|
|
9e3e2b358b | ||
|
|
a6acb8736c | ||
|
|
3d4e3a8fbe | ||
|
|
97407b2527 | ||
|
|
dc22121739 | ||
|
|
06c0945ac5 | ||
|
|
2b19c80ae3 | ||
|
|
21b15727c5 | ||
|
|
569e712248 | ||
|
|
8c033a12a1 | ||
|
|
6b58ebb993 | ||
|
|
7179de77da | ||
|
|
e6a8c8e013 | ||
|
|
137971e957 | ||
|
|
9abb50a7e2 | ||
|
|
2766a94e3b | ||
|
|
c420e9494a | ||
|
|
407db114c6 | ||
|
|
0537b01d4b | ||
|
|
79dc61e7dc | ||
|
|
67a660117e | ||
|
|
831714e07f | ||
|
|
f047af8148 | ||
|
|
8948d00545 | ||
|
|
2e8a13f135 | ||
|
|
f647519e1c | ||
|
|
94ae912138 | ||
|
|
e3b56376dc | ||
|
|
8c88934763 | ||
|
|
d0dc6076c8 | ||
|
|
842dadad94 | ||
|
|
d086d7869d | ||
|
|
d4d97177eb | ||
|
|
7254e15a02 | ||
|
|
ee4b484a38 | ||
|
|
9a378aea99 | ||
|
|
3db88eb23c | ||
|
|
c4d2ef7d97 | ||
|
|
00f18733d8 | ||
|
|
4d14689ff1 | ||
|
|
027196026b | ||
|
|
b59ab48407 | ||
|
|
181e22011d | ||
|
|
0397bc63e7 | ||
|
|
a6befda070 | ||
|
|
5aeaf9e512 | ||
|
|
2c9d971437 | ||
|
|
6623be1e69 | ||
|
|
67a7c91220 | ||
|
|
a91f8e2971 | ||
|
|
b2ff2b6276 | ||
|
|
0ae6656bdb | ||
|
|
14893f9ea9 | ||
|
|
06e165e664 | ||
|
|
a2106c248d | ||
|
|
7a5bb0690e | ||
|
|
f67a5b4fed | ||
|
|
eab4cdb1ad | ||
|
|
bb60f5f15f | ||
|
|
adf3bf6710 | ||
|
|
bf75ac9cd9 | ||
|
|
cef20db3c7 | ||
|
|
40983ee4f1 | ||
|
|
9eac498d81 | ||
|
|
0b1793a93f | ||
|
|
5f86acee91 | ||
|
|
e47db2ea47 | ||
|
|
4030b4370b | ||
|
|
72019786eb | ||
|
|
b732cb1b69 | ||
|
|
00c30c4fdf | ||
|
|
1d4b06abda | ||
|
|
d74228e4a9 | ||
|
|
be5020cbae | ||
|
|
6494b95700 | ||
|
|
ff0c10b66c | ||
|
|
79688de09e | ||
|
|
b5289a8472 | ||
|
|
ff55d6a173 | ||
|
|
ccaac70a04 | ||
|
|
7f5c063ffb | ||
|
|
1e7e8722ee | ||
|
|
2dd31a5f96 | ||
|
|
5b9b3d5709 | ||
|
|
22e065e5cb | ||
|
|
03be90b606 | ||
|
|
6ebda9368c | ||
|
|
964672adb5 | ||
|
|
1988ee1d78 | ||
|
|
3668a2f9af | ||
|
|
db7f48890a | ||
|
|
c8d949733a | ||
|
|
81afe325f6 | ||
|
|
04fc9b2894 | ||
|
|
d896f9ff3c | ||
|
|
c8b07c6edb | ||
|
|
9f38b7b6e0 | ||
|
|
ba9bef6268 | ||
|
|
b2e4bc1b8f | ||
|
|
a7044db87c | ||
|
|
8e2b35525c | ||
|
|
875533a65f | ||
|
|
1f25f12e4a | ||
|
|
7fde67f3d3 | ||
|
|
2f304c1afc | ||
|
|
e0d7494a71 | ||
|
|
1e9bb89764 | ||
|
|
e7851fa29d | ||
|
|
0c11ce5785 | ||
|
|
6d5738b931 | ||
|
|
dcfaca04a5 | ||
|
|
c63c94d7c8 | ||
|
|
09acdee3e1 | ||
|
|
c2eb3e4095 | ||
|
|
54bac4fcf6 | ||
|
|
9a626f2889 | ||
|
|
c6fbe52fbd | ||
|
|
a505e22844 | ||
|
|
40be483e2b | ||
|
|
fd48ff08b9 | ||
|
|
0c037c5831 | ||
|
|
8b9fc86d12 | ||
|
|
66b8a7323d | ||
|
|
865c6aa640 | ||
|
|
2c5eb574f9 | ||
|
|
ef319d2153 | ||
|
|
467310bb4f | ||
|
|
b787bad536 | ||
|
|
93d7d36b68 | ||
|
|
87d9806a88 | ||
|
|
ae3f4ed9ac | ||
|
|
b53248b6da | ||
|
|
bb6b87bb54 | ||
|
|
cd4ad61d1c | ||
|
|
b809bf0785 | ||
|
|
c583e207c8 | ||
|
|
5aeb0a3cb2 | ||
|
|
5a62bd7faa | ||
|
|
81b279b060 | ||
|
|
ac1ba977f4 | ||
|
|
7303dea98c | ||
|
|
1aded8ec29 | ||
|
|
53f8d31f77 | ||
|
|
7013d8e323 | ||
|
|
6e5e2dea64 | ||
|
|
219e17edb6 | ||
|
|
582eb29617 | ||
|
|
d8ede46d8a | ||
|
|
d4546ccae0 | ||
|
|
61e7a23a11 | ||
|
|
7c90d54b91 | ||
|
|
a6555c8ab1 | ||
|
|
8d861c9682 | ||
|
|
368ab1b710 | ||
|
|
13cf44c813 | ||
|
|
91cf697fb4 | ||
|
|
153108aeac | ||
|
|
2c82c01233 | ||
|
|
21957cc0cc | ||
|
|
63b0b4261c | ||
|
|
522ca2804d | ||
|
|
78b76437e5 | ||
|
|
b9a346dd62 | ||
|
|
dfcc08feed | ||
|
|
49662179e9 | ||
|
|
996126cc40 | ||
|
|
f67eae0a7f | ||
|
|
8dc7a2d4b3 | ||
|
|
f6b6610980 | ||
|
|
82299973e0 | ||
|
|
762b4487bf | ||
|
|
19e3115420 | ||
|
|
58c734a681 | ||
|
|
2d171c6dd9 | ||
|
|
7cc6e7ad72 |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.deps
|
||||
.dirstamp
|
||||
*.[ios]
|
||||
test
|
||||
@@ -13,4 +13,4 @@ compiler:
|
||||
script:
|
||||
- git clone --depth=1 https://github.com/jedisct1/libsodium.git --branch=stable
|
||||
- cd libsodium && ./configure --enable-minimal --disable-dependency-tracking && cd -
|
||||
- make CFLAGS=-std=c99 CPPFLAGS="-D_GNU_SOURCE -I./libsodium/src/libsodium/include" mud.o
|
||||
- make CFLAGS="-std=gnu99" CPPFLAGS="-I./libsodium/src/libsodium/include" mud.o
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2016, angt
|
||||
Copyright (c) 2016-2020, Adrien Gallouët <adrien@gallouet.fr>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
8
Makefile
Normal file
8
Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
CFLAGS=-march=native -O2
|
||||
LDLIBS=-lsodium
|
||||
|
||||
test:
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f test
|
||||
23
README.md
23
README.md
@@ -1 +1,22 @@
|
||||

|
||||
# MUD
|
||||
|
||||
MUD is a secure, multipath network protocol over UDP.
|
||||
See [glorytun](https://github.com/angt/glorytun) for details.
|
||||
|
||||
### Compatibility
|
||||
|
||||
Linux is the platform of choice but it was successfully ported to OpenBSD and OSX.
|
||||
|
||||
### Dependencies
|
||||
|
||||
* A recent version of GCC or Clang.
|
||||
* [libsodium](https://github.com/jedisct1/libsodium).
|
||||
|
||||
### Security
|
||||
|
||||
Encryption and authentication is done with AEGIS256 when aesni is available otherwise ChaCha20-Poly1305 is used.
|
||||
The Diffie-Hellman function X25519 is used for key exchange.
|
||||
|
||||
### Issues
|
||||
|
||||
For feature requests and bug reports, please create an [issue](https://github.com/angt/mud/issues).
|
||||
|
||||
97
mud.h
97
mud.h
@@ -1,25 +1,106 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define MUD_PATH_MAX (32U)
|
||||
#define MUD_PUBKEY_SIZE (32U)
|
||||
|
||||
struct mud;
|
||||
|
||||
struct mud *mud_create (int, int, int, int, int);
|
||||
enum mud_state {
|
||||
MUD_EMPTY = 0,
|
||||
MUD_DOWN,
|
||||
MUD_BACKUP,
|
||||
MUD_UP,
|
||||
};
|
||||
|
||||
struct mud_stat {
|
||||
uint64_t val;
|
||||
uint64_t var;
|
||||
int setup;
|
||||
};
|
||||
|
||||
struct mud_conf {
|
||||
uint64_t keepalive;
|
||||
uint64_t timetolerance;
|
||||
uint64_t kxtimeout;
|
||||
int tc;
|
||||
};
|
||||
|
||||
struct mud_path {
|
||||
enum mud_state state;
|
||||
struct sockaddr_storage local_addr, addr, r_addr;
|
||||
struct mud_stat rtt;
|
||||
struct {
|
||||
uint64_t total;
|
||||
uint64_t bytes;
|
||||
uint64_t time;
|
||||
uint64_t rate;
|
||||
uint64_t loss;
|
||||
} tx, rx;
|
||||
struct {
|
||||
struct {
|
||||
uint64_t total;
|
||||
uint64_t bytes;
|
||||
uint64_t time;
|
||||
uint64_t acc;
|
||||
uint64_t acc_time;
|
||||
} tx, rx;
|
||||
uint64_t time;
|
||||
uint64_t sent;
|
||||
uint64_t set;
|
||||
} msg;
|
||||
struct {
|
||||
size_t min;
|
||||
size_t max;
|
||||
size_t probe;
|
||||
size_t last;
|
||||
size_t ok;
|
||||
} mtu;
|
||||
struct {
|
||||
uint64_t tx_max_rate;
|
||||
uint64_t rx_max_rate;
|
||||
uint64_t beat;
|
||||
unsigned char fixed_rate;
|
||||
unsigned char loss_limit;
|
||||
} conf;
|
||||
uint64_t idle;
|
||||
unsigned char ok;
|
||||
};
|
||||
|
||||
struct mud_bad {
|
||||
struct {
|
||||
struct sockaddr_storage addr;
|
||||
uint64_t time;
|
||||
uint64_t count;
|
||||
} decrypt, difftime, keyx;
|
||||
};
|
||||
|
||||
struct mud *mud_create (struct sockaddr *);
|
||||
void mud_delete (struct mud *);
|
||||
|
||||
int mud_update (struct mud *);
|
||||
int mud_send_wait (struct mud *);
|
||||
|
||||
int mud_get_fd (struct mud *);
|
||||
size_t mud_get_mtu (struct mud *);
|
||||
int mud_get_bad (struct mud *, struct mud_bad *);
|
||||
|
||||
int mud_set_key (struct mud *, unsigned char *, size_t);
|
||||
int mud_get_key (struct mud *, unsigned char *, size_t *);
|
||||
|
||||
int mud_set_mtu (struct mud *, int mtu);
|
||||
int mud_get_mtu (struct mud *);
|
||||
int mud_set_aes (struct mud *);
|
||||
int mud_set_conf (struct mud *, struct mud_conf *);
|
||||
|
||||
int mud_set_send_timeout_msec (struct mud *, unsigned);
|
||||
int mud_set_time_tolerance_sec (struct mud *, unsigned);
|
||||
int mud_set_tc (struct mud *, int);
|
||||
int mud_set_state (struct mud *, struct sockaddr *, enum mud_state,
|
||||
unsigned long, unsigned long, unsigned long,
|
||||
unsigned char, unsigned char);
|
||||
|
||||
int mud_peer (struct mud *, const char *, const char *, int, int);
|
||||
int mud_peer (struct mud *, struct sockaddr *);
|
||||
|
||||
int mud_recv (struct mud *, void *, size_t);
|
||||
int mud_send (struct mud *, const void *, size_t, int);
|
||||
int mud_send (struct mud *, const void *, size_t);
|
||||
|
||||
struct mud_path *mud_get_paths(struct mud *, unsigned *);
|
||||
|
||||
121
test.c
Normal file
121
test.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "mud.c"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <poll.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 2)
|
||||
return -1;
|
||||
|
||||
int client = argc == 2;
|
||||
|
||||
struct sockaddr_in local = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(client + 20000),
|
||||
.sin_addr = {
|
||||
.s_addr = htonl(INADDR_LOOPBACK),
|
||||
},
|
||||
};
|
||||
|
||||
struct mud *mud = mud_create((struct sockaddr *)&local);
|
||||
|
||||
if (!mud) {
|
||||
perror("mud_create");
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char key[] = "0123456789ABCDEF0123456789ABCDEF";
|
||||
|
||||
if (mud_set_key(mud, key, sizeof(key))) {
|
||||
perror("mud_set_key");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// client is little harder to setup
|
||||
if (client) {
|
||||
struct sockaddr_in remote = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(20000),
|
||||
.sin_addr = {
|
||||
.s_addr = htonl(INADDR_LOOPBACK),
|
||||
},
|
||||
};
|
||||
|
||||
// we are going to connect to remote...
|
||||
if (mud_peer(mud, (struct sockaddr *)&remote)) {
|
||||
perror("mud_peer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ...from loopback at 1MBps (not 1Mbps)
|
||||
if (mud_set_state(mud, (struct sockaddr *)&local,
|
||||
MUD_UP, 1000 * 1000, 1000 * 1000, 0, 0, 0)) {
|
||||
perror("mud_set_state");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char buf[1500];
|
||||
|
||||
for (;;) {
|
||||
// mandatory, mud have lot of work to do.
|
||||
if (mud_update(mud))
|
||||
usleep(100000); // don't use all the cpu
|
||||
|
||||
if (client) {
|
||||
// when there is data, mud_recv() is mandatory
|
||||
struct pollfd pollfd = {
|
||||
.fd = mud_get_fd(mud),
|
||||
.events = POLLIN,
|
||||
};
|
||||
|
||||
switch (poll(&pollfd, 1, 0)) {
|
||||
case -1:
|
||||
perror("poll");
|
||||
return -1;
|
||||
case 1:
|
||||
if (mud_recv(mud, buf, sizeof(buf)) == -1) {
|
||||
perror("mud_recv");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// we can safely call mud_send()
|
||||
// even if the link is not ready
|
||||
int r = mud_send(mud, argv[1], strlen(argv[1]));
|
||||
|
||||
if (r == -1) {
|
||||
if (errno == EAGAIN)
|
||||
continue;
|
||||
|
||||
perror("mud_send");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// we sent everything, bye :)
|
||||
if (r)
|
||||
break;
|
||||
} else {
|
||||
int r = mud_recv(mud, buf, sizeof(buf));
|
||||
|
||||
if (r == -1) {
|
||||
if (errno == EAGAIN)
|
||||
continue;
|
||||
|
||||
perror("mud_recv");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (r) {
|
||||
buf[r] = 0;
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mud_delete(mud);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user