Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Sep 2014 04:33:37 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r271184 - in stable/9: sys/netinet6 usr.bin/netstat
Message-ID:  <201409060433.s864Xbc8051396@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Sat Sep  6 04:33:37 2014
New Revision: 271184
URL: http://svnweb.freebsd.org/changeset/base/271184

Log:
  MFC r270348:
  Add some missing checks for unsupported interfaces (e.g. pflog(4)) when
  handling ioctls. While here, remove duplicated checks for a NULL ifp in
  in6_control(): this check is already done near the beginning of the
  function.
  
  MFC r270349:
  Suppress warnings when retrieving protocol stats from interfaces that
  don't support IPv6 (e.g. pflog(4)).
  
  PR:	189117

Modified:
  stable/9/sys/netinet6/in6.c
  stable/9/sys/netinet6/scope6.c
  stable/9/sys/netinet6/scope6_var.h
  stable/9/usr.bin/netstat/inet6.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/usr.bin/netstat/   (props changed)

Modified: stable/9/sys/netinet6/in6.c
==============================================================================
--- stable/9/sys/netinet6/in6.c	Fri Sep  5 23:56:25 2014	(r271183)
+++ stable/9/sys/netinet6/in6.c	Sat Sep  6 04:33:37 2014	(r271184)
@@ -284,7 +284,7 @@ in6_control(struct socket *so, u_long cm
 		return (mrt6_ioctl ? mrt6_ioctl(cmd, data) : EOPNOTSUPP);
 	}
 
-	switch(cmd) {
+	switch (cmd) {
 	case SIOCAADDRCTL_POLICY:
 	case SIOCDADDRCTL_POLICY:
 		if (td != NULL) {
@@ -356,14 +356,10 @@ in6_control(struct socket *so, u_long cm
 			if (error)
 				return (error);
 		}
-		return (scope6_set(ifp,
-		    (struct scope6_id *)ifr->ifr_ifru.ifru_scope_id));
+		/* FALLTHROUGH */
 	case SIOCGSCOPE6:
-		return (scope6_get(ifp,
-		    (struct scope6_id *)ifr->ifr_ifru.ifru_scope_id));
 	case SIOCGSCOPE6DEF:
-		return (scope6_get_default((struct scope6_id *)
-		    ifr->ifr_ifru.ifru_scope_id));
+		return (scope6_ioctl(cmd, data, ifp));
 	}
 
 	switch (cmd) {
@@ -494,6 +490,13 @@ in6_control(struct socket *so, u_long cm
 			if (error)
 				goto out;
 		}
+		/* FALLTHROUGH */
+	case SIOCGIFSTAT_IN6:
+	case SIOCGIFSTAT_ICMP6:
+		if (ifp->if_afdata[AF_INET6] == NULL) {
+			error = EPFNOSUPPORT;
+			goto out;
+		}
 		break;
 
 	case SIOCGIFADDR_IN6:
@@ -569,10 +572,6 @@ in6_control(struct socket *so, u_long cm
 		break;
 
 	case SIOCGIFSTAT_IN6:
-		if (ifp == NULL) {
-			error = EINVAL;
-			goto out;
-		}
 		bzero(&ifr->ifr_ifru.ifru_stat,
 		    sizeof(ifr->ifr_ifru.ifru_stat));
 		ifr->ifr_ifru.ifru_stat =
@@ -580,10 +579,6 @@ in6_control(struct socket *so, u_long cm
 		break;
 
 	case SIOCGIFSTAT_ICMP6:
-		if (ifp == NULL) {
-			error = EINVAL;
-			goto out;
-		}
 		bzero(&ifr->ifr_ifru.ifru_icmp6stat,
 		    sizeof(ifr->ifr_ifru.ifru_icmp6stat));
 		ifr->ifr_ifru.ifru_icmp6stat =
@@ -799,7 +794,7 @@ in6_control(struct socket *so, u_long cm
 	}
 
 	default:
-		if (ifp == NULL || ifp->if_ioctl == 0) {
+		if (ifp->if_ioctl == NULL) {
 			error = EOPNOTSUPP;
 			goto out;
 		}

Modified: stable/9/sys/netinet6/scope6.c
==============================================================================
--- stable/9/sys/netinet6/scope6.c	Fri Sep  5 23:56:25 2014	(r271183)
+++ stable/9/sys/netinet6/scope6.c	Sat Sep  6 04:33:37 2014	(r271184)
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/socket.h>
+#include <sys/sockio.h>
 #include <sys/systm.h>
 #include <sys/queue.h>
 #include <sys/syslog.h>
@@ -72,6 +73,9 @@ static VNET_DEFINE(struct scope6_id, sid
 #define SID(ifp) \
 	(((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->scope6_id)
 
+static int	scope6_get(struct ifnet *, struct scope6_id *);
+static int	scope6_set(struct ifnet *, struct scope6_id *);
+
 void
 scope6_init(void)
 {
@@ -115,6 +119,30 @@ scope6_ifdetach(struct scope6_id *sid)
 }
 
 int
+scope6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
+{
+	struct in6_ifreq *ifr;
+
+	if (ifp->if_afdata[AF_INET6] == NULL)
+		return (EPFNOSUPPORT);
+
+	ifr = (struct in6_ifreq *)data;
+	switch (cmd) {
+	case SIOCSSCOPE6:
+		return (scope6_set(ifp,
+		    (struct scope6_id *)ifr->ifr_ifru.ifru_scope_id));
+	case SIOCGSCOPE6:
+		return (scope6_get(ifp,
+		    (struct scope6_id *)ifr->ifr_ifru.ifru_scope_id));
+	case SIOCGSCOPE6DEF:
+		return (scope6_get_default(
+		    (struct scope6_id *)ifr->ifr_ifru.ifru_scope_id));
+	default:
+		return (EOPNOTSUPP);
+	}
+}
+
+static int
 scope6_set(struct ifnet *ifp, struct scope6_id *idlist)
 {
 	int i;
@@ -177,7 +205,7 @@ scope6_set(struct ifnet *ifp, struct sco
 	return (error);
 }
 
-int
+static int
 scope6_get(struct ifnet *ifp, struct scope6_id *idlist)
 {
 	struct scope6_id *sid;
@@ -196,7 +224,6 @@ scope6_get(struct ifnet *ifp, struct sco
 	return (0);
 }
 
-
 /*
  * Get a scope of the address. Node-local, link-local, site-local or global.
  */

Modified: stable/9/sys/netinet6/scope6_var.h
==============================================================================
--- stable/9/sys/netinet6/scope6_var.h	Fri Sep  5 23:56:25 2014	(r271183)
+++ stable/9/sys/netinet6/scope6_var.h	Sat Sep  6 04:33:37 2014	(r271184)
@@ -45,8 +45,7 @@ struct scope6_id {
 void	scope6_init(void);
 struct scope6_id *scope6_ifattach(struct ifnet *);
 void	scope6_ifdetach(struct scope6_id *);
-int	scope6_set(struct ifnet *, struct scope6_id *);
-int	scope6_get(struct ifnet *, struct scope6_id *);
+int	scope6_ioctl(u_long cmd, caddr_t data, struct ifnet *);
 void	scope6_setdefault(struct ifnet *);
 int	scope6_get_default(struct scope6_id *);
 u_int32_t scope6_addr2default(struct in6_addr *);

Modified: stable/9/usr.bin/netstat/inet6.c
==============================================================================
--- stable/9/usr.bin/netstat/inet6.c	Fri Sep  5 23:56:25 2014	(r271183)
+++ stable/9/usr.bin/netstat/inet6.c	Sat Sep  6 04:33:37 2014	(r271184)
@@ -540,13 +540,13 @@ ip6_ifstats(char *ifname)
 	}
 
 	strcpy(ifr.ifr_name, ifname);
-	printf("ip6 on %s:\n", ifr.ifr_name);
-
 	if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
-		perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
+		if (errno != EPFNOSUPPORT)
+			perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
 		goto end;
 	}
 
+	printf("ip6 on %s:\n", ifr.ifr_name);
 	p(ifs6_in_receive, "\t%ju total input datagram%s\n");
 	p(ifs6_in_hdrerr, "\t%ju datagram%s with invalid header received\n");
 	p(ifs6_in_toobig, "\t%ju datagram%s exceeded MTU received\n");
@@ -945,13 +945,13 @@ icmp6_ifstats(char *ifname)
 	}
 
 	strcpy(ifr.ifr_name, ifname);
-	printf("icmp6 on %s:\n", ifr.ifr_name);
-
 	if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
-		perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
+		if (errno != EPFNOSUPPORT)
+			perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
 		goto end;
 	}
 
+	printf("icmp6 on %s:\n", ifr.ifr_name);
 	p(ifs6_in_msg, "\t%ju total input message%s\n");
 	p(ifs6_in_error, "\t%ju total input error message%s\n");
 	p(ifs6_in_dstunreach, "\t%ju input destination unreachable error%s\n");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409060433.s864Xbc8051396>