summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-06-28 09:12:25 +0200
committerHarald Welte <laforge@gnumonks.org>2015-11-15 14:04:06 +0100
commitcf34183616c2d004ab775def49c7b65f1f3d9e94 (patch)
tree10463398286c640b3b8ac5fe9ccd1c185e8ad06c
parent487d3ea8b4b82e10aab7d5db13ec55bbd20eb12a (diff)
ganc: don't put IP addressess as string into a FQDN attribute
... there is a separate IP address IE that should be used for this. Otherwise, devices may treat 1.2.3.4 as a hostname and make forward dns lookups on it ;)
-rw-r--r--openbsc/src/osmo-ganc/ganc_server.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/openbsc/src/osmo-ganc/ganc_server.c b/openbsc/src/osmo-ganc/ganc_server.c
index 7a54ff5..3e4d8f7 100644
--- a/openbsc/src/osmo-ganc/ganc_server.c
+++ b/openbsc/src/osmo-ganc/ganc_server.c
@@ -147,6 +147,28 @@ static int tx_unc_reg_acc(struct gan_peer *peer)
return unc_peer_tx(peer, msg);
}
+static int push_fqdn_or_ip(struct msgb *msg, const char *host,
+ uint8_t fqdn_att, uint8_t ip_att)
+{
+ struct in_addr ia;
+ int rc;
+
+ rc = inet_aton(host, &ia);
+ if (rc == 0) {
+ /* it is not an IP address */
+ msgb_tlv_put(msg, fqdn_att, strlen(host)+1,
+ (uint8_t *) host);
+ } else {
+ uint8_t buf[5];
+
+ buf[0] = 0x21; /* Type: IPv4 */
+ memcpy(buf+1, &ia, 4);
+ msgb_tlv_put(msg, ip_att, sizeof(buf), buf);
+ }
+
+ return rc;
+}
+
/* 10.1.3: GA-RC DISCOVERY ACCEPT */
static int tx_unc_disco_acc(struct gan_peer *peer, const char *segw_host,
const char *ganc_host)
@@ -159,9 +181,10 @@ static int tx_unc_disco_acc(struct gan_peer *peer, const char *segw_host,
return -ENOMEM;
push_rc_csr_hdr(msg, GA_PDISC_RC, GA_MT_RC_DISCOVERY_ACCEPT);
-
- msgb_tlv_put(msg, GA_IE_DEF_SEGW_FQDN, strlen(segw_host)+1, (uint8_t *) segw_host);
- msgb_tlv_put(msg, GA_IE_DEF_GANC_FQDN, strlen(ganc_host)+1, (uint8_t *) ganc_host);
+ push_fqdn_or_ip(msg, segw_host,
+ GA_IE_DEF_SEGW_FQDN, GA_IE_DEF_SEGW_IP);
+ push_fqdn_or_ip(msg, ganc_host,
+ GA_IE_DEF_GANC_FQDN, GA_IE_DEF_GANC_IP);
return unc_peer_tx(peer, msg);
}