Add mud_get_bad()

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2019-10-15 14:11:07 +00:00
parent 842dadad94
commit d0dc6076c8
2 changed files with 27 additions and 6 deletions

23
mud.c
View File

@@ -154,12 +154,7 @@ struct mud {
int set;
struct sockaddr_storage addr;
} peer;
struct {
struct {
struct sockaddr_storage addr;
uint64_t time;
} decrypt, difftime, keyx;
} bad;
struct mud_bad bad;
uint64_t window;
uint64_t base_time;
};
@@ -675,6 +670,19 @@ mud_peer(struct mud *mud, struct sockaddr *peer)
return 0;
}
int
mud_get_bad(struct mud *mud, struct mud_bad *bad)
{
if (!bad) {
errno = EINVAL;
return -1;
}
memcpy(bad, &mud->bad, sizeof(struct mud_bad));
return 0;
}
int
mud_get_key(struct mud *mud, unsigned char *key, size_t *size)
{
@@ -1303,6 +1311,7 @@ mud_recv_msg(struct mud *mud, struct mud_path *path,
if (mud_keyx(mud, msg->pk, msg->aes)) {
mud->bad.keyx.addr = path->addr;
mud->bad.keyx.time = now;
mud->bad.keyx.count++;
return;
}
@@ -1373,6 +1382,7 @@ mud_recv(struct mud *mud, void *data, size_t size)
(MUD_TIME_MASK(send_time - now) > mud->time_tolerance)) {
mud->bad.difftime.addr = addr;
mud->bad.difftime.time = now;
mud->bad.difftime.count++;
return 0;
}
@@ -1383,6 +1393,7 @@ mud_recv(struct mud *mud, void *data, size_t size)
if (ret <= 0) {
mud->bad.decrypt.addr = addr;
mud->bad.decrypt.time = now;
mud->bad.decrypt.count++;
return 0;
}

10
mud.h
View File

@@ -53,6 +53,14 @@ struct mud_path {
unsigned msg_sent;
};
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 *);
@@ -64,6 +72,8 @@ int mud_get_key (struct mud *, unsigned char *, size_t *);
void mud_set_mtu (struct mud *, size_t);
size_t mud_get_mtu (struct mud *);
int mud_get_bad (struct mud *, struct mud_bad *);
long mud_send_wait (struct mud *);
int mud_set_time_tolerance (struct mud *, unsigned long);