Module Name:    src
Committed By:   maxv
Date:           Thu Jan 25 10:45:58 UTC 2018

Modified Files:
        src/sys/netinet: in_l2tp.c
        src/sys/netinet6: in6_l2tp.c

Log Message:
Style, reduce the indentation level when possible, and add a missing NULL
check after M_PREPEND.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.12 -r1.13 src/sys/netinet6/in6_l2tp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.10 src/sys/netinet/in_l2tp.c:1.11
--- src/sys/netinet/in_l2tp.c:1.10	Mon Jan 22 09:51:06 2018
+++ src/sys/netinet/in_l2tp.c	Thu Jan 25 10:45:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.10 2018/01/22 09:51:06 maxv Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.11 2018/01/25 10:45:58 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.10 2018/01/22 09:51:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.11 2018/01/25 10:45:58 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -113,7 +113,16 @@ in_l2tp_output(struct l2tp_variant *var,
 		goto looped;
 	}
 
-#ifdef NETYET
+	/* bidirectional configured tunnel mode */
+	if (sin_dst->sin_addr.s_addr == INADDR_ANY) {
+		m_freem(m);
+		if ((ifp->if_flags & IFF_DEBUG) != 0)
+			log(LOG_DEBUG, "%s: ENETUNREACH\n", __func__);
+		error = ENETUNREACH;
+		goto out;
+	}
+
+#ifdef NOTYET
 /* TODO: support ALTQ for innner frame */
 #ifdef ALTQ
 	ALTQ_SAVE_PAYLOAD(m, AF_ETHER);
@@ -122,16 +131,7 @@ in_l2tp_output(struct l2tp_variant *var,
 
 	memset(&iphdr, 0, sizeof(iphdr));
 	iphdr.ip_src = sin_src->sin_addr;
-	/* bidirectional configured tunnel mode */
-	if (sin_dst->sin_addr.s_addr != INADDR_ANY)
-		iphdr.ip_dst = sin_dst->sin_addr;
-	else {
-		m_freem(m);
-		if ((ifp->if_flags & IFF_DEBUG) != 0)
-			log(LOG_DEBUG, "%s: ENETUNREACH\n", __func__);
-		error = ENETUNREACH;
-		goto out;
-	}
+	iphdr.ip_dst = sin_dst->sin_addr;
 	iphdr.ip_p = IPPROTO_L2TP;
 	/* version will be set in ip_output() */
 	iphdr.ip_ttl = ip_l2tp_ttl;
@@ -152,11 +152,12 @@ in_l2tp_output(struct l2tp_variant *var,
 		goto out;
 	}
 #endif
+
 	/*
-	 * payload length
-	 *  NOTE: Payload length may be changed in ip_tcpmss().
-	 *        Typical case is missing of TCP mss option in original
-	 *        TCP header.
+	 * Payload length.
+	 *
+	 * NOTE: payload length may be changed in ip_tcpmss(). Typical case
+	 * is missing of TCP mss option in original TCP header.
 	 */
 	iphdr.ip_len += m->m_pkthdr.len;
 	HTONS(iphdr.ip_len);
@@ -174,12 +175,10 @@ in_l2tp_output(struct l2tp_variant *var,
 		}
 		if (var->lv_peer_cookie_len == 4) {
 			cookie_32 = htonl((uint32_t)var->lv_peer_cookie);
-			memcpy(mtod(m, void *), &cookie_32,
-			    sizeof(uint32_t));
+			memcpy(mtod(m, void *), &cookie_32, sizeof(uint32_t));
 		} else {
 			cookie_64 = htobe64(var->lv_peer_cookie);
-			memcpy(mtod(m, void *), &cookie_64,
-			    sizeof(uint64_t));
+			memcpy(mtod(m, void *), &cookie_64, sizeof(uint64_t));
 		}
 	}
 
@@ -291,28 +290,28 @@ in_l2tp_input(struct mbuf *m, int off, i
 		m_freem(m);
 		ip_statinc(IP_STAT_NOL2TP);
 		return;
-	} else {
-		sc = var->lv_softc;
-		l2tpp = &(sc->l2tp_ec.ec_if);
+	}
+
+	sc = var->lv_softc;
+	l2tpp = &(sc->l2tp_ec.ec_if);
 
-		if (l2tpp == NULL || (l2tpp->if_flags & IFF_UP) == 0) {
+	if (l2tpp == NULL || (l2tpp->if_flags & IFF_UP) == 0) {
 #ifdef L2TP_DEBUG
-			if (l2tpp == NULL)
-				log(LOG_DEBUG, "%s: l2tpp is NULL\n", __func__);
-			else
-				log(LOG_DEBUG, "%s: l2tpp is down\n", __func__);
+		if (l2tpp == NULL)
+			log(LOG_DEBUG, "%s: l2tpp is NULL\n", __func__);
+		else
+			log(LOG_DEBUG, "%s: l2tpp is down\n", __func__);
 #endif
-			m_freem(m);
-			ip_statinc(IP_STAT_NOL2TP);
-			goto out;
-		}
+		m_freem(m);
+		ip_statinc(IP_STAT_NOL2TP);
+		goto out;
+	}
 
-		/* other CPU do l2tp_delete_tunnel */
-		if (var->lv_psrc == NULL || var->lv_pdst == NULL) {
-			m_freem(m);
-			ip_statinc(IP_STAT_NOL2TP);
-			goto out;
-		}
+	/* other CPU did l2tp_delete_tunnel */
+	if (var->lv_psrc == NULL || var->lv_pdst == NULL) {
+		m_freem(m);
+		ip_statinc(IP_STAT_NOL2TP);
+		goto out;
 	}
 
 	if (var->lv_state != L2TP_STATE_UP) {

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.12 src/sys/netinet6/in6_l2tp.c:1.13
--- src/sys/netinet6/in6_l2tp.c:1.12	Mon Dec 18 03:21:44 2017
+++ src/sys/netinet6/in6_l2tp.c	Thu Jan 25 10:45:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.12 2017/12/18 03:21:44 knakahara Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.13 2018/01/25 10:45:58 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.12 2017/12/18 03:21:44 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.13 2018/01/25 10:45:58 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -113,6 +113,14 @@ in6_l2tp_output(struct l2tp_variant *var
 		goto looped;
 	}
 
+	/* bidirectional configured tunnel mode */
+	if (IN6_IS_ADDR_UNSPECIFIED(&sin6_dst->sin6_addr)) {
+		m_freem(m);
+		if ((ifp->if_flags & IFF_DEBUG) != 0)
+			log(LOG_DEBUG, "%s: ENETUNREACH\n", __func__);
+		return ENETUNREACH;
+	}
+
 #ifdef NOTYET
 /* TODO: support ALTQ for innner frame */
 #ifdef ALTQ
@@ -122,18 +130,10 @@ in6_l2tp_output(struct l2tp_variant *var
 
 	memset(&ip6hdr, 0, sizeof(ip6hdr));
 	ip6hdr.ip6_src = sin6_src->sin6_addr;
-	/* bidirectional configured tunnel mode */
-	if (!IN6_IS_ADDR_UNSPECIFIED(&sin6_dst->sin6_addr))
-		ip6hdr.ip6_dst = sin6_dst->sin6_addr;
-	else {
-		m_freem(m);
-		if ((ifp->if_flags & IFF_DEBUG) != 0)
-			log(LOG_DEBUG, "%s: ENETUNREACH\n", __func__);
-		return ENETUNREACH;
-	}
+	ip6hdr.ip6_dst = sin6_dst->sin6_addr;
 	/* unlike IPv4, IP version must be filled by caller of ip6_output() */
-	ip6hdr.ip6_vfc  = 0x60;
-	ip6hdr.ip6_nxt  = IPPROTO_L2TP;
+	ip6hdr.ip6_vfc = 0x60;
+	ip6hdr.ip6_nxt = IPPROTO_L2TP;
 	ip6hdr.ip6_hlim = ip6_l2tp_hlim;
 	/* outer IP payload length */
 	ip6hdr.ip6_plen = 0;
@@ -152,10 +152,10 @@ in6_l2tp_output(struct l2tp_variant *var
 #endif
 
 	/*
-	 * payload length
-	 *  NOTE: Payload length may be changed in ip_tcpmss().
-	 *        Typical case is missing of TCP mss option in original
-	 *        TCP header.
+	 * Payload length.
+	 *
+	 * NOTE: payload length may be changed in ip_tcpmss(). Typical case
+	 * is missing of TCP mss option in original TCP header.
 	 */
 	ip6hdr.ip6_plen += m->m_pkthdr.len;
 	HTONS(ip6hdr.ip6_plen);
@@ -171,12 +171,10 @@ in6_l2tp_output(struct l2tp_variant *var
 			return ENOBUFS;
 		if (var->lv_peer_cookie_len == 4) {
 			cookie_32 = htonl((uint32_t)var->lv_peer_cookie);
-			memcpy(mtod(m, void *), &cookie_32,
-			    sizeof(uint32_t));
+			memcpy(mtod(m, void *), &cookie_32, sizeof(uint32_t));
 		} else {
 			cookie_64 = htobe64(var->lv_peer_cookie);
-			memcpy(mtod(m, void *), &cookie_64,
-			    sizeof(uint64_t));
+			memcpy(mtod(m, void *), &cookie_64, sizeof(uint64_t));
 		}
 	}
 
@@ -191,11 +189,12 @@ in6_l2tp_output(struct l2tp_variant *var
 
 	/* prepend new IP header */
 	M_PREPEND(m, sizeof(struct ip6_hdr), M_DONTWAIT);
+	if (m == NULL)
+		return ENOBUFS;
 	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if (m)
-			m = m_copyup(m, sizeof(struct ip), 0);
+		m = m_copyup(m, sizeof(struct ip), 0);
 	} else {
-		if (m && m->m_len < sizeof(struct ip6_hdr))
+		if (m->m_len < sizeof(struct ip6_hdr))
 			m = m_pullup(m, sizeof(struct ip6_hdr));
 	}
 	if (m == NULL)
@@ -282,27 +281,28 @@ in6_l2tp_input(struct mbuf **mp, int *of
 		m_freem(m);
 		IP_STATINC(IP_STAT_NOL2TP);
 		return IPPROTO_DONE;
-	} else {
-		sc = var->lv_softc;
-		l2tpp = &(sc->l2tp_ec.ec_if);
+	}
 
-		if (l2tpp == NULL || (l2tpp->if_flags & IFF_UP) == 0) {
+	sc = var->lv_softc;
+	l2tpp = &(sc->l2tp_ec.ec_if);
+
+	if (l2tpp == NULL || (l2tpp->if_flags & IFF_UP) == 0) {
 #ifdef L2TP_DEBUG
-			if (l2tpp == NULL)
-				log(LOG_DEBUG, "%s: l2tpp is NULL\n", __func__);
-			else
-				log(LOG_DEBUG, "%s: l2tpp is down\n", __func__);
+		if (l2tpp == NULL)
+			log(LOG_DEBUG, "%s: l2tpp is NULL\n", __func__);
+		else
+			log(LOG_DEBUG, "%s: l2tpp is down\n", __func__);
 #endif
-			m_freem(m);
-			IP_STATINC(IP_STAT_NOL2TP);
-			goto out;
-		}
-		/* other CPU do l2tp_delete_tunnel */
-		if (var->lv_psrc == NULL || var->lv_pdst == NULL) {
-			m_freem(m);
-			ip_statinc(IP_STAT_NOL2TP);
-			goto out;
-		}
+		m_freem(m);
+		IP_STATINC(IP_STAT_NOL2TP);
+		goto out;
+	}
+
+	/* other CPU did l2tp_delete_tunnel */
+	if (var->lv_psrc == NULL || var->lv_pdst == NULL) {
+		m_freem(m);
+		ip_statinc(IP_STAT_NOL2TP);
+		goto out;
 	}
 
 	if (var->lv_state != L2TP_STATE_UP) {

Reply via email to