diff --git a/mud b/mud index e3eb1f9..3747aa7 160000 --- a/mud +++ b/mud @@ -1 +1 @@ -Subproject commit e3eb1f96a50451f3feabeaa622be455f7f464e24 +Subproject commit 3747aa7abd05385257355c13a3e19415464ef5c7 diff --git a/src/bind.c b/src/bind.c index aeb7590..2b51541 100644 --- a/src/bind.c +++ b/src/bind.c @@ -308,6 +308,18 @@ gt_bind(int argc, char **argv) req.path.fixed_rate)) res.ret = errno; break; + case CTL_CONF: + if (mud_set_conf(mud, &req.conf)) + res.ret = errno; + break; + case CTL_STATUS: + memcpy(res.status.tun_name, tun_name, sizeof(tun_name)); // XXX + res.status.pid = pid; + res.status.mtu = mtu; + res.status.chacha = chacha; + res.status.bind = bind_addr; + res.status.peer = peer_addr; + break; case CTL_PATH_STATUS: { unsigned count = 0; @@ -331,34 +343,6 @@ gt_bind(int argc, char **argv) res.ret = 0; } break; - case CTL_TC: - if (mud_set_tc(mud, req.tc)) - res.ret = errno; - break; - case CTL_KXTIMEOUT: - if (mud_set_keyx_timeout(mud, req.ms)) - res.ret = errno; - break; - case CTL_TIMETOLERANCE: - if (mud_set_time_tolerance(mud, req.ms)) - res.ret = errno; - break; - case CTL_LOSSLIMIT: - if (mud_set_loss_limit(mud, req.percent)) - res.ret = errno; - break; - case CTL_KEEPALIVE: - if (mud_set_keepalive(mud, req.ms)) - res.ret = errno; - break; - case CTL_STATUS: - memcpy(res.status.tun_name, tun_name, sizeof(tun_name)); // XXX - res.status.pid = pid; - res.status.mtu = mtu; - res.status.chacha = chacha; - res.status.bind = bind_addr; - res.status.peer = peer_addr; - break; case CTL_BAD: if (mud_get_bad(mud, &res.bad)) res.ret = errno; diff --git a/src/ctl.h b/src/ctl.h index 307dddc..995566f 100644 --- a/src/ctl.h +++ b/src/ctl.h @@ -10,12 +10,8 @@ enum ctl_type { CTL_NONE = 0, CTL_STATE, + CTL_CONF, CTL_STATUS, - CTL_TC, - CTL_KXTIMEOUT, - CTL_TIMETOLERANCE, - CTL_LOSSLIMIT, - CTL_KEEPALIVE, CTL_PATH_STATUS, CTL_BAD, }; @@ -32,7 +28,6 @@ struct ctl_msg { unsigned long beat; unsigned char fixed_rate; } path; - struct mud_path path_status; struct { char tun_name[64]; long pid; @@ -41,10 +36,9 @@ struct ctl_msg { struct sockaddr_storage bind; struct sockaddr_storage peer; } status; + struct mud_conf conf; + struct mud_path path_status; struct mud_bad bad; - int tc; - unsigned long ms; - unsigned percent; }; }; diff --git a/src/set.c b/src/set.c index f158102..c8e283d 100644 --- a/src/set.c +++ b/src/set.c @@ -7,96 +7,6 @@ #include "../argz/argz.h" -static int -gt_set_kxtimeout(int fd, unsigned long ms) -{ - struct ctl_msg res, req = { - .type = CTL_KXTIMEOUT, - .ms = ms, - }; - - int ret = ctl_reply(fd, &res, &req); - - if (ret) { - perror("set kxtimeout"); - return 1; - } - - return 0; -} - -static int -gt_set_timetolerance(int fd, unsigned long ms) -{ - struct ctl_msg res, req = { - .type = CTL_TIMETOLERANCE, - .ms = ms, - }; - - int ret = ctl_reply(fd, &res, &req); - - if (ret) { - perror("set timetolerance"); - return 1; - } - - return 0; -} - -static int -gt_set_losslimit(int fd, unsigned percent) -{ - struct ctl_msg res, req = { - .type = CTL_LOSSLIMIT, - .percent = percent, - }; - - int ret = ctl_reply(fd, &res, &req); - - if (ret) { - perror("set losslimit"); - return 1; - } - - return 0; -} - -static int -gt_set_keepalive(int fd, unsigned long ms) -{ - struct ctl_msg res, req = { - .type = CTL_KEEPALIVE, - .ms = ms, - }; - - int ret = ctl_reply(fd, &res, &req); - - if (ret) { - perror("set keepalive"); - return 1; - } - - return 0; -} - -static int -gt_set_tc(int fd, int tc) -{ - struct ctl_msg res, req = { - .type = CTL_TC, - .tc = tc, - }; - - int ret = ctl_reply(fd, &res, &req); - - if (ret) { - perror("set tc"); - return 1; - } - - return 0; -} - static int gt_argz_tc(void *data, int argc, char **argv) { @@ -118,7 +28,7 @@ gt_argz_tc(void *data, int argc, char **argv) } else return -1; if (data) - *(int *)data = val; + *(int *)data = (val << 1) | 1; return 1; } @@ -127,19 +37,18 @@ int gt_set(int argc, char **argv) { const char *dev = NULL; - int tc; - unsigned long kxtimeout; - unsigned long timetolerance; - unsigned losslimit; - unsigned long keepalive; + + struct ctl_msg req = { + .type = CTL_CONF, + }, res = {0}; struct argz pathz[] = { {"dev", "NAME", &dev, argz_str}, - {"tc", "CS|AF|EF", &tc, gt_argz_tc}, - {"kxtimeout", "SECONDS", &kxtimeout, argz_time}, - {"timetolerance", "SECONDS", &timetolerance, argz_time}, - {"losslimit", "PERCENT", &losslimit, argz_percent}, - {"keepalive", "SECONDS", &keepalive, argz_time}, + {"tc", "CS|AF|EF", &req.conf.tc, gt_argz_tc}, + {"kxtimeout", "SECONDS", &req.conf.kxtimeout, argz_time}, + {"timetolerance", "SECONDS", &req.conf.timetolerance, argz_time}, + {"losslimit", "PERCENT", &req.conf.losslimit, argz_percent}, + {"keepalive", "SECONDS", &req.conf.keepalive, argz_time}, {NULL}}; if (argz(pathz, argc, argv)) @@ -164,24 +73,12 @@ gt_set(int argc, char **argv) return 1; } - int ret = 0; + int ret = ctl_reply(fd, &res, &req); - if (argz_is_set(pathz, "tc")) - ret |= gt_set_tc(fd, tc); - - if (argz_is_set(pathz, "kxtimeout")) - ret |= gt_set_kxtimeout(fd, kxtimeout); - - if (argz_is_set(pathz, "timetolerance")) - ret |= gt_set_timetolerance(fd, timetolerance); - - if (argz_is_set(pathz, "losslimit")) - ret |= gt_set_losslimit(fd, losslimit); - - if (argz_is_set(pathz, "keepalive")) - ret |= gt_set_keepalive(fd, keepalive); + if (ret) + perror("set"); ctl_delete(fd); - return ret; + return !!ret; }