From 865c6aa64056bcd6fa3cc5ddf43b1a087e3cd407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Wed, 14 Mar 2018 22:36:58 +0000 Subject: [PATCH] Compute MTU only with usable paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/mud.c b/mud.c index 9a32996..21f0cec 100644 --- a/mud.c +++ b/mud.c @@ -449,9 +449,9 @@ mud_get_path(struct mud *mud, struct sockaddr_storage *local_addr, for (unsigned i = 0; i < mud->count; i++) { struct mud_path *path = &mud->paths[i]; - if (path->state && - !mud_cmp_addr(local_addr, &path->local_addr) && - !mud_cmp_addr(addr, &path->addr)) + if ((path->state != MUD_EMPTY) && + (!mud_cmp_addr(local_addr, &path->local_addr)) && + (!mud_cmp_addr(addr, &path->addr))) return path; } @@ -673,21 +673,24 @@ mud_set_state(struct mud *mud, struct sockaddr *peer, enum mud_state state) size_t mud_get_mtu(struct mud *mud) { - size_t mtu; + size_t mtu = MUD_PACKET_MAX_SIZE; + unsigned count = 0; - if (mud->count) { - mtu = MUD_PACKET_MAX_SIZE; + for (unsigned i = 0; i < mud->count; i++) { + struct mud_path *path = &mud->paths[i]; - for (unsigned i = 0; i < mud->count; i++) { - struct mud_path *path = &mud->paths[i]; + if (path->state <= MUD_DOWN) + continue; - if (mtu > path->mtu.ok) - mtu = path->mtu.ok; - } - } else { - mtu = mud->mtu; + count++; + + if (mtu > path->mtu.ok) + mtu = path->mtu.ok; } + if (!count) + mtu = mud->mtu; + if (mtu > MUD_PACKET_MAX_SIZE) mtu = MUD_PACKET_MAX_SIZE;