Skip to content

Commit e991dc9

Browse files
committed
Passive is a state
Signed-off-by: Adrien Gallouët <[email protected]>
1 parent ffd8bc0 commit e991dc9

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

mud.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static struct mud_path *
472472
mud_get_path(struct mud *mud,
473473
union mud_sockaddr *local,
474474
union mud_sockaddr *remote,
475-
int create)
475+
enum mud_state state)
476476
{
477477
if (local->sa.sa_family != remote->sa.sa_family) {
478478
errno = EINVAL;
@@ -491,7 +491,7 @@ mud_get_path(struct mud *mud,
491491

492492
return path;
493493
}
494-
if (!create) {
494+
if (state <= MUD_DOWN) {
495495
errno = 0;
496496
return NULL;
497497
}
@@ -523,12 +523,11 @@ mud_get_path(struct mud *mud,
523523

524524
path->conf.local = *local;
525525
path->conf.remote = *remote;
526-
path->conf.state = MUD_UP;
526+
path->conf.state = state;
527527
path->conf.beat = 100 * MUD_ONE_MSEC;
528528
path->conf.fixed_rate = 1;
529529
path->conf.loss_limit = 255;
530530
path->status = MUD_PROBING;
531-
path->passive = create >> 1;
532531
path->idle = mud_now(mud);
533532

534533
return path;
@@ -1048,7 +1047,7 @@ mud_recv_msg(struct mud *mud, struct mud_path *path,
10481047
path->rx.loss = (uint64_t)msg->loss;
10491048
path->msg.sent = 0;
10501049

1051-
if (path->passive)
1050+
if (path->conf.state == MUD_PASSIVE)
10521051
return;
10531052

10541053
mud_update_mtu(path, size);
@@ -1081,7 +1080,7 @@ mud_recv_msg(struct mud *mud, struct mud_path *path,
10811080
mud->err.keyx.count++;
10821081
return;
10831082
}
1084-
} else if (!path->passive) {
1083+
} else if (path->conf.state == MUD_UP) {
10851084
mud->keyx.use_next = 1;
10861085
}
10871086
mud_send_msg(mud, path, now, sent_time,
@@ -1142,7 +1141,7 @@ mud_recv(struct mud *mud, void *data, size_t size)
11421141
if (mud_localaddr(&local, &msg))
11431142
return 0;
11441143

1145-
struct mud_path *path = mud_get_path(mud, &local, &remote, 3);
1144+
struct mud_path *path = mud_get_path(mud, &local, &remote, MUD_PASSIVE);
11461145

11471146
if (!path || path->conf.state <= MUD_DOWN)
11481147
return 0;
@@ -1164,19 +1163,20 @@ mud_recv(struct mud *mud, void *data, size_t size)
11641163
static int
11651164
mud_path_update(struct mud *mud, struct mud_path *path, uint64_t now)
11661165
{
1167-
if (path->conf.state < MUD_DOWN)
1168-
return 0;
1169-
1170-
if (path->conf.state == MUD_DOWN || path->passive) {
1171-
if (mud_timeout(now, path->rx.time, 5 * MUD_ONE_MIN)) {
1172-
memset(path, 0, sizeof(struct mud_path));
1173-
return 0;
1174-
}
1166+
switch (path->conf.state) {
1167+
case MUD_DOWN:
1168+
path->status = MUD_DELETING;
1169+
case MUD_PASSIVE:
1170+
if (mud_timeout(now, path->rx.time, 5 * MUD_ONE_MIN)) {
1171+
memset(path, 0, sizeof(struct mud_path));
1172+
return 0;
1173+
}
1174+
case MUD_UP: break;
1175+
default: return 0;
11751176
}
1176-
if (path->conf.state == MUD_DOWN) {
1177-
path->status = MUD_DELETING;
1177+
if (path->conf.state == MUD_DOWN)
11781178
return 0;
1179-
}
1179+
11801180
if (path->msg.sent >= MUD_MSG_SENT_MAX) {
11811181
if (path->mtu.probe) {
11821182
mud_update_mtu(path, 0);
@@ -1196,7 +1196,7 @@ mud_path_update(struct mud *mud, struct mud_path *path, uint64_t now)
11961196
path->status = MUD_LOSSY;
11971197
return 0;
11981198
}
1199-
if (path->passive &&
1199+
if (path->conf.state == MUD_PASSIVE &&
12001200
mud_timeout(mud->last_recv_time, path->rx.time,
12011201
MUD_MSG_SENT_MAX * path->conf.beat)) {
12021202
path->status = MUD_WAITING;
@@ -1214,7 +1214,7 @@ mud_path_update(struct mud *mud, struct mud_path *path, uint64_t now)
12141214
static uint64_t
12151215
mud_path_track(struct mud *mud, struct mud_path *path, uint64_t now)
12161216
{
1217-
if (path->passive)
1217+
if (path->conf.state != MUD_UP)
12181218
return now;
12191219

12201220
uint64_t timeout = path->conf.beat;
@@ -1319,8 +1319,9 @@ mud_set_path(struct mud *mud, struct mud_path_conf *conf)
13191319
errno = EINVAL;
13201320
return -1;
13211321
}
1322-
struct mud_path *path = mud_get_path(mud, &conf->local, &conf->remote,
1323-
conf->state > MUD_DOWN);
1322+
struct mud_path *path = mud_get_path(mud, &conf->local,
1323+
&conf->remote,
1324+
conf->state);
13241325
if (!path)
13251326
return -1;
13261327

mud.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct mud;
1313
enum mud_state {
1414
MUD_EMPTY = 0,
1515
MUD_DOWN,
16+
MUD_PASSIVE,
1617
MUD_UP,
1718
MUD_LAST,
1819
};
@@ -88,7 +89,6 @@ struct mud_path {
8889
size_t last;
8990
size_t ok;
9091
} mtu;
91-
int passive;
9292
uint64_t idle;
9393
};
9494

0 commit comments

Comments
 (0)