Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Style, reduce the indentation level when possible, and a...
details: https://anonhg.NetBSD.org/src/rev/41cca6e0d81c
branches: trunk
changeset: 359005:41cca6e0d81c
user: maxv <maxv%NetBSD.org@localhost>
date: Thu Jan 25 10:45:58 2018 +0000
description:
Style, reduce the indentation level when possible, and add a missing NULL
check after M_PREPEND.
diffstat:
sys/netinet/in_l2tp.c | 77 ++++++++++++++++++++++----------------------
sys/netinet6/in6_l2tp.c | 84 ++++++++++++++++++++++++------------------------
2 files changed, 80 insertions(+), 81 deletions(-)
diffs (281 lines):
diff -r dc4cda9ce2fe -r 41cca6e0d81c sys/netinet/in_l2tp.c
--- a/sys/netinet/in_l2tp.c Thu Jan 25 10:33:37 2018 +0000
+++ b/sys/netinet/in_l2tp.c Thu Jan 25 10:45:58 2018 +0000
@@ -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 @@
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 @@
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 @@
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 @@
}
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 @@
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) {
diff -r dc4cda9ce2fe -r 41cca6e0d81c sys/netinet6/in6_l2tp.c
--- a/sys/netinet6/in6_l2tp.c Thu Jan 25 10:33:37 2018 +0000
+++ b/sys/netinet6/in6_l2tp.c Thu Jan 25 10:45:58 2018 +0000
@@ -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 @@
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 @@
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 @@
#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 @@
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 @@
/* 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 @@
m_freem(m);
IP_STATINC(IP_STAT_NOL2TP);
return IPPROTO_DONE;
- } 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;
- }
- /* 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) {
Home |
Main Index |
Thread Index |
Old Index