aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith <keith@rhizomatica.org>2021-09-29 21:00:04 +0200
committerKeith <keith@rhizomatica.org>2021-09-30 20:45:19 +0200
commit6cee1a1ded99a21c3bb79e891f48d29d3ba3020a (patch)
tree77c43f3d37b590288c00d3d26a5b5865f81d5b5c
parentc0e146467ae2896840c836e638742d1e8fafa235 (diff)
VTY: Don't display 'PDP Address: invalid' for IPv4v6
We were not handling the case of PDP_TYPE_N_IETF_IPv4v6 in gprs_pdpaddr2str() and showed "invalid" for these addresses. Depends: libosmocore Change-Id: I1f82f9d8fc13dcc4474760329bd74ae9685b9031 Change-Id: Id36b7520677e4a0af40d05dc503b26d1b0b74a26
-rw-r--r--include/osmocom/sgsn/gprs_sgsn.h2
-rw-r--r--src/sgsn/sgsn_ctrl.c2
-rw-r--r--src/sgsn/sgsn_vty.c26
3 files changed, 24 insertions, 6 deletions
diff --git a/include/osmocom/sgsn/gprs_sgsn.h b/include/osmocom/sgsn/gprs_sgsn.h
index c176494b1..dcda5c37a 100644
--- a/include/osmocom/sgsn/gprs_sgsn.h
+++ b/include/osmocom/sgsn/gprs_sgsn.h
@@ -417,7 +417,7 @@ uint32_t sgsn_alloc_ptmsi(void);
struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx);
void sgsn_inst_init(struct sgsn_instance *sgsn);
-char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len);
+char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len, bool return_ipv6);
/*
* ctrl interface related work
diff --git a/src/sgsn/sgsn_ctrl.c b/src/sgsn/sgsn_ctrl.c
index ad91d25a5..69034e210 100644
--- a/src/sgsn/sgsn_ctrl.c
+++ b/src/sgsn/sgsn_ctrl.c
@@ -43,7 +43,7 @@ static int get_subscriber_list(struct ctrl_cmd *cmd, void *d)
llist_for_each_entry(pdp, &mm->pdp_list, list)
addr = gprs_pdpaddr2str(pdp->lib->eua.v,
- pdp->lib->eua.l);
+ pdp->lib->eua.l, false);
cmd->reply = talloc_asprintf_append(
cmd->reply,
diff --git a/src/sgsn/sgsn_vty.c b/src/sgsn/sgsn_vty.c
index e0e26775e..6327d1a3d 100644
--- a/src/sgsn/sgsn_vty.c
+++ b/src/sgsn/sgsn_vty.c
@@ -135,7 +135,7 @@ DEFUN(cfg_sgsn_timer, cfg_sgsn_timer_cmd,
return osmo_tdef_vty_set_cmd(vty, g_cfg->T_defs, argv);
}
-char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len)
+char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len, bool return_ipv6)
{
static char str[INET6_ADDRSTRLEN + 10];
@@ -148,15 +148,28 @@ char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len)
case PDP_TYPE_N_IETF_IPv4:
if (len < 2 + 4)
break;
- strcpy(str, "IPv4 ");
+ osmo_strlcpy(str, "IPv4 ", sizeof(str));
inet_ntop(AF_INET, pdpa+2, str+5, sizeof(str)-5);
return str;
case PDP_TYPE_N_IETF_IPv6:
if (len < 2 + 8)
break;
- strcpy(str, "IPv6 ");
+ osmo_strlcpy(str, "IPv6 ", sizeof(str));
inet_ntop(AF_INET6, pdpa+2, str+5, sizeof(str)-5);
return str;
+ case PDP_TYPE_N_IETF_IPv4v6:
+ if (len < 2 + 20)
+ break;
+ if (return_ipv6) {
+ /* The IPv6 token, (rightmost four fields) is a duplicate of
+ * the site prefix + subnetID (leftmost fields) in pdpa here */
+ osmo_strlcpy(str, "IPv6 ", sizeof(str));
+ inet_ntop(AF_INET6, pdpa+6, str+5, sizeof(str)-5);
+ return str;
+ }
+ osmo_strlcpy(str, "IPv4 ", sizeof(str));
+ inet_ntop(AF_INET, pdpa+2, str+5, sizeof(str)-5);
+ return str;
default:
break;
}
@@ -552,8 +565,13 @@ static void vty_dump_pdp(struct vty *vty, const char *pfx,
osmo_apn_to_str(apnbuf, pdp->lib->apn_use.v, pdp->lib->apn_use.l),
VTY_NEWLINE);
vty_out(vty, "%s PDP Address: %s%s", pfx,
- gprs_pdpaddr2str(pdp->lib->eua.v, pdp->lib->eua.l),
+ gprs_pdpaddr2str(pdp->lib->eua.v, pdp->lib->eua.l, false),
VTY_NEWLINE);
+ if (pdp->lib->eua.v[1] == PDP_TYPE_N_IETF_IPv4v6) {
+ vty_out(vty, "%s PDP Address: %s%s", pfx,
+ gprs_pdpaddr2str(pdp->lib->eua.v, pdp->lib->eua.l, true),
+ VTY_NEWLINE);
+ }
vty_out(vty, "%s GTPv%d Local Control(%s / TEIC: 0x%08x) ", pfx, pdp->lib->version,
sgsn_gtp_ntoa(&pdp->lib->gsnlc), pdp->lib->teic_own);
vty_out(vty, "Data(%s / TEID: 0x%08x)%s",