Apply TC on all packets
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
22
mud.c
22
mud.c
@@ -68,7 +68,6 @@
|
|||||||
|
|
||||||
#define MUD_MSG(X) ((X) & UINT64_C(1))
|
#define MUD_MSG(X) ((X) & UINT64_C(1))
|
||||||
#define MUD_MSG_MARK(X) ((X) | UINT64_C(1))
|
#define MUD_MSG_MARK(X) ((X) | UINT64_C(1))
|
||||||
#define MUD_MSG_TC (192) // CS6
|
|
||||||
#define MUD_MSG_SENT_MAX (3)
|
#define MUD_MSG_SENT_MAX (3)
|
||||||
#define MUD_MSG_TIMEOUT (100 * MUD_ONE_MSEC)
|
#define MUD_MSG_TIMEOUT (100 * MUD_ONE_MSEC)
|
||||||
|
|
||||||
@@ -86,6 +85,8 @@
|
|||||||
#define MUD_KEYX_RESET_TIMEOUT (200 * MUD_ONE_MSEC)
|
#define MUD_KEYX_RESET_TIMEOUT (200 * MUD_ONE_MSEC)
|
||||||
#define MUD_TIME_TOLERANCE ( 10 * MUD_ONE_MIN)
|
#define MUD_TIME_TOLERANCE ( 10 * MUD_ONE_MIN)
|
||||||
|
|
||||||
|
#define MUD_TC (192) // CS6
|
||||||
|
|
||||||
#define MUD_LOSS_LIMIT (20)
|
#define MUD_LOSS_LIMIT (20)
|
||||||
#define MUD_LOSS_COUNT (3)
|
#define MUD_LOSS_COUNT (3)
|
||||||
|
|
||||||
@@ -151,7 +152,7 @@ struct mud {
|
|||||||
} crypto;
|
} crypto;
|
||||||
uint64_t last_recv_time;
|
uint64_t last_recv_time;
|
||||||
size_t mtu;
|
size_t mtu;
|
||||||
int msg_tc;
|
int tc;
|
||||||
struct {
|
struct {
|
||||||
int set;
|
int set;
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
@@ -371,7 +372,7 @@ mud_select_path(struct mud *mud, unsigned k)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
mud_send_path(struct mud *mud, struct mud_path *path, uint64_t now,
|
mud_send_path(struct mud *mud, struct mud_path *path, uint64_t now,
|
||||||
void *data, size_t size, int tc, int flags)
|
void *data, size_t size, int flags)
|
||||||
{
|
{
|
||||||
if (!size || !path)
|
if (!size || !path)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -413,7 +414,7 @@ mud_send_path(struct mud *mud, struct mud_path *path, uint64_t now,
|
|||||||
cmsg->cmsg_type = IP_TOS;
|
cmsg->cmsg_type = IP_TOS;
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||||
|
|
||||||
memcpy(CMSG_DATA(cmsg), &tc, sizeof(int));
|
memcpy(CMSG_DATA(cmsg), &mud->tc, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path->addr.ss_family == AF_INET6) {
|
if (path->addr.ss_family == AF_INET6) {
|
||||||
@@ -437,7 +438,7 @@ mud_send_path(struct mud *mud, struct mud_path *path, uint64_t now,
|
|||||||
cmsg->cmsg_type = IPV6_TCLASS;
|
cmsg->cmsg_type = IPV6_TCLASS;
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||||
|
|
||||||
memcpy(CMSG_DATA(cmsg), &tc, sizeof(int));
|
memcpy(CMSG_DATA(cmsg), &mud->tc, sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ret = sendmsg(mud->fd, &msg, flags);
|
ssize_t ret = sendmsg(mud->fd, &msg, flags);
|
||||||
@@ -745,7 +746,7 @@ mud_set_tc(struct mud *mud, int tc)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mud->msg_tc = tc;
|
mud->tc = tc;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -964,7 +965,7 @@ mud_create(struct sockaddr *addr)
|
|||||||
|
|
||||||
mud->time_tolerance = MUD_TIME_TOLERANCE;
|
mud->time_tolerance = MUD_TIME_TOLERANCE;
|
||||||
mud->keyx_timeout = MUD_KEYX_TIMEOUT;
|
mud->keyx_timeout = MUD_KEYX_TIMEOUT;
|
||||||
mud->msg_tc = MUD_MSG_TC;
|
mud->tc = MUD_TC;
|
||||||
mud->mtu = MUD_MTU_MIN;
|
mud->mtu = MUD_MTU_MIN;
|
||||||
mud->loss_limit = MUD_LOSS_LIMIT;
|
mud->loss_limit = MUD_LOSS_LIMIT;
|
||||||
|
|
||||||
@@ -1158,8 +1159,7 @@ mud_send_msg(struct mud *mud, struct mud_path *path, uint64_t now,
|
|||||||
|
|
||||||
mud_encrypt_opt(&mud->crypto.private, &opt);
|
mud_encrypt_opt(&mud->crypto.private, &opt);
|
||||||
|
|
||||||
return mud_send_path(mud, path, now, dst, size,
|
return mud_send_path(mud, path, now, dst, size, sent_time ? MSG_CONFIRM : 0);
|
||||||
mud->msg_tc, sent_time ? MSG_CONFIRM : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -1553,7 +1553,7 @@ mud_send_wait(struct mud *mud)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mud_send(struct mud *mud, const void *data, size_t size, unsigned tc)
|
mud_send(struct mud *mud, const void *data, size_t size)
|
||||||
{
|
{
|
||||||
if (!size)
|
if (!size)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1578,5 +1578,5 @@ mud_send(struct mud *mud, const void *data, size_t size, unsigned tc)
|
|||||||
const unsigned k = (a << 8) | b;
|
const unsigned k = (a << 8) | b;
|
||||||
|
|
||||||
return mud_send_path(mud, mud_select_path(mud, k),
|
return mud_send_path(mud, mud_select_path(mud, k),
|
||||||
now, packet, (size_t)packet_size, tc & 255, 0);
|
now, packet, (size_t)packet_size, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
2
mud.h
2
mud.h
@@ -95,6 +95,6 @@ int mud_set_state (struct mud *, struct sockaddr *, enum mud_state,
|
|||||||
int mud_peer (struct mud *, struct sockaddr *);
|
int mud_peer (struct mud *, struct sockaddr *);
|
||||||
|
|
||||||
int mud_recv (struct mud *, void *, size_t);
|
int mud_recv (struct mud *, void *, size_t);
|
||||||
int mud_send (struct mud *, const void *, size_t, unsigned);
|
int mud_send (struct mud *, const void *, size_t);
|
||||||
|
|
||||||
struct mud_path *mud_get_paths(struct mud *, unsigned *);
|
struct mud_path *mud_get_paths(struct mud *, unsigned *);
|
||||||
|
|||||||
2
test.c
2
test.c
@@ -85,7 +85,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
// we can safely call mud_send()
|
// we can safely call mud_send()
|
||||||
// even if the link is not ready
|
// even if the link is not ready
|
||||||
int r = mud_send(mud, argv[1], strlen(argv[1]), 0);
|
int r = mud_send(mud, argv[1], strlen(argv[1]));
|
||||||
|
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
if (errno == EAGAIN)
|
if (errno == EAGAIN)
|
||||||
|
|||||||
Reference in New Issue
Block a user