apn_start: avoid segfault if missing tun-device

Check if tun-device is defined and give the user a hint that it is
missing instead of segfaulting with gtpu-mode kernel-gtp:
  20210205141701206 DGGSN <0002> ggsn.c:186 APN(internet): Starting
  20210205141701206 DGGSN <0002> ggsn.c:204 APN(internet): Opening Kernel GTP device (null)
  Segmentation fault

With gtpu-mode tun it didn't segfault, but still tried to open the NULL
device:
  20210205141557598 DGGSN <0002> ggsn.c:186 APN(internet): Starting
  20210205141557599 DGGSN <0002> ggsn.c:189 APN(internet): Opening TUN device (null)
  20210205141557599 DTUN <0001> tun.c:195 errno=1/Operation not permitted ioctl() failed

Related: OS#3208
Change-Id: I9f71af65cc0eed71728c04b774e5c08352947913
This commit is contained in:
Oliver Smith 2021-02-05 14:15:20 +01:00
parent 349cbfcf50
commit 02a82c3c9b
1 changed files with 4 additions and 0 deletions

View File

@ -699,6 +699,10 @@ DEFUN(cfg_apn_no_shutdown, cfg_apn_no_shutdown_cmd,
struct apn_ctx *apn = (struct apn_ctx *) vty->index;
if (apn->cfg.shutdown) {
if (!apn->tun.cfg.dev_name) {
vty_out(vty, "%% Failed to start APN, tun-device is not configured%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (apn_start(apn) < 0) {
vty_out(vty, "%% Failed to start APN, check log for details%s", VTY_NEWLINE);
return CMD_WARNING;