[MERGED] osmo-ggsn[master]: lib/netdev.c: Cosmetic changes (coding style / cleanups)

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
Wed Apr 25 19:49:47 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: lib/netdev.c: Cosmetic changes (coding style / cleanups)
......................................................................


lib/netdev.c: Cosmetic changes (coding style / cleanups)

Change-Id: I60cbca616a4f727e2374c52715f9286a0f4c5e4b
---
M lib/netdev.c
1 file changed, 11 insertions(+), 50 deletions(-)

Approvals:
  Pau Espin Pedrol: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/lib/netdev.c b/lib/netdev.c
index eff808d..0011588 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -109,7 +109,6 @@
 
 #if defined(__linux__)
 	ifr.ifr_netmask.sa_family = AF_INET;
-
 #elif defined(__FreeBSD__) || defined (__APPLE__)
 	((struct sockaddr_in *)&ifr.ifr_addr)->sin_len =
 	    sizeof(struct sockaddr_in);
@@ -157,7 +156,6 @@
 #if defined(__linux__)
 		memcpy(&((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr,
 		       netmask, sizeof(*netmask));
-
 #elif defined(__FreeBSD__) || defined (__APPLE__)
 		((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr =
 		    netmask->s_addr;
@@ -173,13 +171,10 @@
 
 	close(fd);
 
-	/* On linux the route to the interface is set automatically
-	   on FreeBSD we have to do this manually */
-
-	/* TODO: How does it work on Solaris? */
-
 	netdev_sifflags(devname, IFF_UP | IFF_RUNNING);
 
+	/* On linux the route to the interface is set automatically
+	   on FreeBSD we have to do this manually */
 #if defined(__FreeBSD__) || defined (__APPLE__)
 	netdev_addroute(dstaddr, addr, &this->netmask);
 #endif
@@ -253,13 +248,10 @@
 
 	close(fd);
 
-	/* On linux the route to the interface is set automatically
-	   on FreeBSD we have to do this manually */
-
-	/* TODO: How does it work on Solaris? */
-
 	netdev_sifflags(devname, IFF_UP | IFF_RUNNING);
 
+	/* On linux the route to the interface is set automatically
+	   on FreeBSD we have to do this manually */
 #if 0	/* FIXME */
 //#if defined(__FreeBSD__) || defined (__APPLE__)
 	netdev_addroute6(dstaddr, addr, prefixlen);
@@ -271,7 +263,7 @@
 int netdev_addaddr4(const char *devname, struct in_addr *addr,
 		    struct in_addr *dstaddr, struct in_addr *netmask)
 {
-
+	int fd;
 #if defined(__linux__)
 	struct {
 		struct nlmsghdr n;
@@ -281,7 +273,6 @@
 
 	struct sockaddr_nl local;
 	socklen_t addr_len;
-	int fd;
 	int status;
 
 	struct sockaddr_nl nladdr;
@@ -374,14 +365,7 @@
 		close(fd);
 		return -1;
 	}
-
-
-	close(fd);
-	return 0;
-
 #elif defined (__FreeBSD__) || defined (__APPLE__)
-
-	int fd;
 	struct ifaliasreq areq;
 
 	memset(&areq, 0, sizeof(areq));
@@ -420,18 +404,15 @@
 		close(fd);
 		return -1;
 	}
-
+#endif
 	close(fd);
 	return 0;
-
-#endif
-
 }
 
 int netdev_addaddr6(const char *devname, struct in6_addr *addr,
 		    struct in6_addr *dstaddr, int prefixlen)
 {
-
+	int fd;
 #if defined(__linux__)
 	struct {
 		struct nlmsghdr n;
@@ -441,7 +422,6 @@
 
 	struct sockaddr_nl local;
 	socklen_t addr_len;
-	int fd;
 	int status;
 
 	struct sockaddr_nl nladdr;
@@ -534,14 +514,7 @@
 		close(fd);
 		return -1;
 	}
-
-
-	close(fd);
-	return 0;
-
 #elif defined (__FreeBSD__) || defined (__APPLE__)
-
-	int fd;
 	struct ifaliasreq areq;
 
 	memset(&areq, 0, sizeof(areq));
@@ -575,21 +548,16 @@
 		close(fd);
 		return -1;
 	}
-
+#endif
 	close(fd);
 	return 0;
-
-#endif
-
 }
 
 static int netdev_route(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask, int delete)
 {
-
-#if defined(__linux__)
-
-	struct rtentry r;
 	int fd;
+#if defined(__linux__)
+	struct rtentry r;
 
 	memset(&r, '\0', sizeof(r));
 	r.rt_flags = RTF_UP | RTF_GATEWAY;	/* RTF_HOST not set */
@@ -624,19 +592,13 @@
 			return -1;
 		}
 	}
-	close(fd);
-	return 0;
-
 #elif defined(__FreeBSD__) || defined (__APPLE__)
-
 	struct {
 		struct rt_msghdr rt;
 		struct sockaddr_in dst;
 		struct sockaddr_in gate;
 		struct sockaddr_in mask;
 	} req;
-
-	int fd;
 	struct rt_msghdr *rtm;
 
 	if ((fd = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) {
@@ -676,10 +638,9 @@
 		close(fd);
 		return -1;
 	}
+#endif
 	close(fd);
 	return 0;
-#endif
-
 }
 
 int netdev_addroute(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask)

-- 
To view, visit https://gerrit.osmocom.org/7924
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I60cbca616a4f727e2374c52715f9286a0f4c5e4b
Gerrit-PatchSet: 2
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list