Change in osmo-ggsn[master]: properly store IPv6 addresses in struct tun_t

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Nov 22 14:12:40 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11871 )

Change subject: properly store IPv6 addresses in struct tun_t
......................................................................

properly store IPv6 addresses in struct tun_t

All addresses in struct tun_t were stored as an in_addr.
But IPv6 addresses need an in6_addr, so switch tun_t addresses
to the in64_addr wrapper struct.

This is an ABI break, as documented in TODO-RELEASE.

Fixes an out of bounds memcpy() identified by Coverity.

Change-Id: Idd2431ad25d7fa182e52e2bd5231ceb04d427c34
Related: CID#174278
---
M TODO-RELEASE
M lib/tun.c
M lib/tun.h
3 files changed, 17 insertions(+), 10 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/TODO-RELEASE b/TODO-RELEASE
index d0852fc..bbad169 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
 # If any interfaces have been added since the last public release: c:r:a + 1.
 # If any interfaces have been removed or changed since the last public release: c:r:0.
 #library	what		description / commit summary line
+libmisc		tun_t		tun_t structure has grown due to switch from in_addr to in46_addr (g#11870)
diff --git a/lib/tun.c b/lib/tun.c
index 6ae006b..1aeed55 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -68,10 +68,14 @@
 	if (rc < 0)
 		return rc;
 
-	if (addr)
-		this->addr.s_addr = addr->s_addr;
-	if (dstaddr)
-		this->dstaddr.s_addr = dstaddr->s_addr;
+	if (addr) {
+		this->addr.len = sizeof(struct in_addr);
+		this->addr.v4.s_addr = addr->s_addr;
+	}
+	if (dstaddr) {
+		this->dstaddr.len = sizeof(struct in_addr);
+		this->dstaddr.v4.s_addr = dstaddr->s_addr;
+	}
 	if (netmask)
 		this->netmask.s_addr = netmask->s_addr;
 	this->addrs++;
@@ -89,8 +93,10 @@
 	rc = netdev_setaddr6(this->devname, addr, dstaddr, prefixlen);
 	if (rc < 0)
 		return rc;
-	if (dstaddr)
-		memcpy(&this->dstaddr, dstaddr, sizeof(*dstaddr));
+	if (dstaddr) {
+		this->dstaddr.len = sizeof(*dstaddr);
+		memcpy(&this->dstaddr.v6, dstaddr, sizeof(*dstaddr));
+	}
 	this->addrs++;
 #if defined(__FreeBSD__) || defined (__APPLE__)
 	this->routes = 1;
@@ -270,7 +276,7 @@
 {
 
 	if (tun->routes) {
-		netdev_delroute(&tun->dstaddr, &tun->addr, &tun->netmask);
+		netdev_delroute(&tun->dstaddr.v4, &tun->addr.v4, &tun->netmask);
 	}
 
 	if (tun->fd >= 0) {
@@ -323,7 +329,7 @@
 	char smask[TUN_ADDRSIZE];
 	int rc;
 
-	strncpy(snet, inet_ntoa(tun->addr), sizeof(snet));
+	strncpy(snet, inet_ntoa(tun->addr.v4), sizeof(snet));
 	snet[sizeof(snet) - 1] = 0;
 	strncpy(smask, inet_ntoa(tun->netmask), sizeof(smask));
 	smask[sizeof(smask) - 1] = 0;
diff --git a/lib/tun.h b/lib/tun.h
index 6bf141f..07ca04a 100644
--- a/lib/tun.h
+++ b/lib/tun.h
@@ -31,8 +31,8 @@
 
 struct tun_t {
 	int fd;			/* File descriptor to tun interface */
-	struct in_addr addr;
-	struct in_addr dstaddr;
+	struct in46_addr addr;
+	struct in46_addr dstaddr;
 	struct in_addr netmask;
 	int addrs;		/* Number of allocated IP addresses */
 	int routes;		/* One if we allocated an automatic route */

-- 
To view, visit https://gerrit.osmocom.org/11871
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Idd2431ad25d7fa182e52e2bd5231ceb04d427c34
Gerrit-Change-Number: 11871
Gerrit-PatchSet: 3
Gerrit-Owner: Stefan Sperling <ssperling at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Stefan Sperling <ssperling at sysmocom.de>
Gerrit-CC: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181122/a14d739f/attachment.htm>


More information about the gerrit-log mailing list