Module Name:    src
Committed By:   maxv
Date:           Wed Feb  7 13:22:42 UTC 2018

Modified Files:
        src/sys/netinet: ip_mroute.c

Log Message:
Style and constify.


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/sys/netinet/ip_mroute.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/ip_mroute.c
diff -u src/sys/netinet/ip_mroute.c:1.152 src/sys/netinet/ip_mroute.c:1.153
--- src/sys/netinet/ip_mroute.c:1.152	Wed Feb  7 12:15:32 2018
+++ src/sys/netinet/ip_mroute.c	Wed Feb  7 13:22:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.152 2018/02/07 12:15:32 maxv Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.153 2018/02/07 13:22:41 maxv Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.152 2018/02/07 12:15:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.153 2018/02/07 13:22:41 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -254,7 +254,7 @@ static struct mbuf *pim_register_prepare
 #define	ENCAP_PROTO	IPPROTO_IPIP
 
 /* prototype IP hdr for encapsulated packets */
-struct ip multicast_encap_iphdr = {
+static const struct ip multicast_encap_iphdr = {
 	.ip_hl = sizeof(struct ip) >> 2,
 	.ip_v = IPVERSION,
 	.ip_len = sizeof(struct ip),
@@ -777,7 +777,7 @@ add_vif(struct vifctl *vifcp)
 		 * local interface (e.g. it could be 127.0.0.2), we don't
 		 * check its address.
 		 */
-	    ifp = NULL;
+		ifp = NULL;
 	} else
 #endif
 	{
@@ -1137,8 +1137,7 @@ add_mfc(struct sockopt *sopt)
 			}
 		}
 		if (rt == NULL) {	/* no upcall, so make a new entry */
-			rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE,
-						  M_NOWAIT);
+			rt = malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
 			if (rt == NULL) {
 				splx(s);
 				return ENOBUFS;
@@ -1294,8 +1293,7 @@ ip_mforward(struct mbuf *m, struct ifnet
 			log(LOG_ERR,
 			    "ip_mforward: received source-routed packet from %x\n",
 			    ntohl(ip->ip_src.s_addr));
-
-		return 1;
+		return EOPNOTSUPP;
 	}
 
 	/*
@@ -1323,19 +1321,18 @@ ip_mforward(struct mbuf *m, struct ifnet
 		return ip_mdq(m, ifp, rt);
 	} else {
 		/*
-		 * If we don't have a route for packet's origin,
-		 * Make a copy of the packet & send message to routing daemon
+		 * If we don't have a route for packet's origin, make a copy
+		 * of the packet and send message to routing daemon.
 		 */
 
 		struct mbuf *mb0;
 		struct rtdetq *rte;
 		u_int32_t hash;
-		int hlen = ip->ip_hl << 2;
+		const int hlen = ip->ip_hl << 2;
 #ifdef UPCALL_TIMING
 		struct timeval tp;
-
 		microtime(&tp);
-#endif /* UPCALL_TIMING */
+#endif
 
 		++mrtstat.mrts_mfc_misses;
 
@@ -1350,8 +1347,7 @@ ip_mforward(struct mbuf *m, struct ifnet
 		 * just going to fail anyway.  Make sure to pullup the header so
 		 * that other people can't step on it.
 		 */
-		rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE,
-					      M_NOWAIT);
+		rte = malloc(sizeof(*rte), M_MRTABLE, M_NOWAIT);
 		if (rte == NULL) {
 			splx(s);
 			return ENOBUFS;
@@ -1389,8 +1385,7 @@ ip_mforward(struct mbuf *m, struct ifnet
 				goto non_fatal;
 
 			/* no upcall, so make a new entry */
-			rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE,
-						  M_NOWAIT);
+			rt = malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
 			if (rt == NULL)
 				goto fail;
 
@@ -1481,7 +1476,7 @@ ip_mforward(struct mbuf *m, struct ifnet
 		rte->ifp = ifp;
 #ifdef UPCALL_TIMING
 		rte->t = tp;
-#endif /* UPCALL_TIMING */
+#endif
 
 		splx(s);
 
@@ -1489,7 +1484,6 @@ ip_mforward(struct mbuf *m, struct ifnet
 	}
 }
 
-
 /*ARGSUSED*/
 static void
 expire_upcalls(void *v)
@@ -1542,28 +1536,26 @@ expire_upcalls(void *v)
 }
 
 /*
+ * Macro to send packet on vif.
+ */
+#define MC_SEND(ip, vifp, m) do {					\
+	if ((vifp)->v_flags & VIFF_TUNNEL)				\
+		encap_send((ip), (vifp), (m));				\
+	else								\
+		phyint_send((ip), (vifp), (m));				\
+} while (/*CONSTCOND*/ 0)
+
+/*
  * Packet forwarding routine once entry in the cache is made
  */
 static int
 ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt)
 {
-	struct ip  *ip = mtod(m, struct ip *);
+	struct ip *ip = mtod(m, struct ip *);
 	vifi_t vifi;
 	struct vif *vifp;
 	struct sockaddr_in sin;
-	int plen = ntohs(ip->ip_len) - (ip->ip_hl << 2);
-
-/*
- * Macro to send packet on vif.  Since RSVP packets don't get counted on
- * input, they shouldn't get counted on output, so statistics keeping is
- * separate.
- */
-#define MC_SEND(ip, vifp, m) do {					\
-	if ((vifp)->v_flags & VIFF_TUNNEL)				\
-		encap_send((ip), (vifp), (m));				\
-	else								\
-		phyint_send((ip), (vifp), (m));				\
-} while (/*CONSTCOND*/ 0)
+	const int plen = ntohs(ip->ip_len) - (ip->ip_hl << 2);
 
 	/*
 	 * Don't forward if it didn't arrive from the parent vif for its origin.
@@ -1577,6 +1569,7 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp
 			    vifi >= numvifs ? 0 : viftable[vifi].v_ifp);
 		++mrtstat.mrts_wrong_if;
 		++rt->mfc_wrong_if;
+
 		/*
 		 * If we are doing PIM assert processing, send a message
 		 * to the routing daemon.
@@ -1616,7 +1609,7 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp
 
 			if (delta > ASSERT_MSG_TIME) {
 				struct igmpmsg *im;
-				int hlen = ip->ip_hl << 2;
+				const int hlen = ip->ip_hl << 2;
 				struct mbuf *mm =
 				    m_copym(m, 0, hlen, M_DONTWAIT);
 
@@ -1659,10 +1652,10 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp
 	/*
 	 * For each vif, decide if a copy of the packet should be forwarded.
 	 * Forward if:
-	 *		- the ttl exceeds the vif's threshold
-	 *		- there are group members downstream on interface
+	 *  - the ttl exceeds the vif's threshold
+	 *  - there are group members downstream on interface
 	 */
-	for (vifp = viftable, vifi = 0; vifi < numvifs; vifp++, vifi++)
+	for (vifp = viftable, vifi = 0; vifi < numvifs; vifp++, vifi++) {
 		if ((rt->mfc_ttls[vifi] > 0) &&
 			(ip->ip_ttl > rt->mfc_ttls[vifi])) {
 			vifp->v_pkt_out++;
@@ -1674,6 +1667,7 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp
 #endif
 			MC_SEND(ip, vifp, m);
 		}
+	}
 
 	/*
 	 * Perform upcall-related bw measuring.
@@ -1694,7 +1688,7 @@ static void
 phyint_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
 {
 	struct mbuf *mb_copy;
-	int hlen = ip->ip_hl << 2;
+	const int hlen = ip->ip_hl << 2;
 
 	/*
 	 * Make a new reference to the packet; make sure that
@@ -1922,7 +1916,6 @@ tbf_queue(struct vif *vifp, struct mbuf 
 	splx(s);
 }
 
-
 /*
  * processes the queue at the interface
  */

Reply via email to