pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ggsn/+/38484?usp=email )
Change subject: WIP: ggsn: apply configured APN MTU to tun ......................................................................
WIP: ggsn: apply configured APN MTU to tun
Change-Id: Ifae556169d895860812c9ea5633292d7e3fab338 --- M ggsn/ggsn.c M ggsn/ggsn.h M ggsn/ggsn_vty.c 3 files changed, 33 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/84/38484/1
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 1908958..53b5213 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -309,6 +309,16 @@ return -1; }
+ if (apn->tun.cfg.mtu_apply) { + rc = osmo_netdev_set_mtu(apn->tun.tun->netdev, apn->cfg.mtu); + if (rc < 0) { + LOGPAPN(LOGL_ERROR, apn, "Failed to set tun interface MTU %u: %s\n", + apn->cfg.mtu, strerror(errno)); + apn_stop(apn); + return -1; + } + } + if (apn->tun.cfg.ipup_script) { LOGPAPN(LOGL_INFO, apn, "Running ip-up script %s\n", apn->tun.cfg.ipup_script); diff --git a/ggsn/ggsn.h b/ggsn/ggsn.h index bd953a4..23df05e 100644 --- a/ggsn/ggsn.h +++ b/ggsn/ggsn.h @@ -95,6 +95,8 @@ /* ip-up and ip-down script names/paths */ char *ipup_script; char *ipdown_script; + /* Whether to apply the MTU (apn->cfg.mtu) on the tun device: */ + bool mtu_apply; } cfg; struct tun_t *tun; } tun; diff --git a/ggsn/ggsn_vty.c b/ggsn/ggsn_vty.c index eda0096..b0f07fe 100644 --- a/ggsn/ggsn_vty.c +++ b/ggsn/ggsn_vty.c @@ -422,16 +422,33 @@ /* MAX_POSSIBLE_APN_MTU = 9000 * MAX_DESIRED_APN_MTU = 1420 */ DEFUN(cfg_apn_mtu, cfg_apn_mtu_cmd, - "mtu (<0-" OSMO_STRINGIFY_VAL(MAX_POSSIBLE_APN_MTU) ">|default)", + "mtu (<0-" OSMO_STRINGIFY_VAL(MAX_POSSIBLE_APN_MTU) ">|default) [apply]", "Configure announced MTU\n" "MTU of the APN, announced to the UE\n" - "Default value of the MTU of the APN (1420)\n") + "Default value of the MTU of the APN (1420)\n" + "Apply the MTU on the tun-device of the APN\n") { struct apn_ctx *apn = (struct apn_ctx *) vty->index; + int rc; + if (strcmp(argv[0], "default") == 0) apn->cfg.mtu = MAX_DESIRED_APN_MTU; else apn->cfg.mtu = atoi(argv[0]); + apn->tun.cfg.mtu_apply = (argc > 1); + + if (apn->tun.cfg.mtu_apply && apn->tun.tun) { + rc = osmo_netdev_set_mtu(apn->tun.tun->netdev, apn->cfg.mtu); + if (rc < 0) { + char buf_err[128]; + strerror_r(errno, buf_err, sizeof(buf_err)); + LOGPAPN(LOGL_ERROR, apn, "Failed to set tun interface MTU %u: %s (%d)\n", + apn->cfg.mtu, buf_err, rc); + vty_out(vty, "%% Failed to set tun interface MTU %u: %s (%d)%s", + apn->cfg.mtu, buf_err, rc, VTY_NEWLINE); + return CMD_WARNING; + } + } return CMD_SUCCESS; }
@@ -705,7 +722,8 @@ VTY_NEWLINE); }
- vty_out(vty, " mtu %" PRIu16 "%s", apn->cfg.mtu, VTY_NEWLINE); + vty_out(vty, " mtu %" PRIu16 "%s%s", apn->cfg.mtu, + apn->tun.cfg.mtu_apply ? " apply" : "", VTY_NEWLINE);
if (!apn->cfg.tx_gpdu_seq) vty_out(vty, " no g-pdu tx-sequence-numbers%s", VTY_NEWLINE);