Module Name:    src
Committed By:   pgoyette
Date:           Sat Nov  5 23:30:22 UTC 2016

Modified Files:
        src/sys/compat/common: Makefile Makefile.sysio compat_mod.c if_43.c
        src/sys/net: if.c
Added Files:
        src/sys/compat/common: if_43.h

Log Message:
Move if_43.c back into the shared Makefile.sysio where it really
belongs.

Update the code to invoke the two routines compat_cvtcmd() and
compat_ifioctl() through indirect pointers.  Initialize those
pointers in sys/net/if.c and update them in the compat module's
initialization code.

Addresses the issue pointed out in PR kern/51598


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/compat/common/Makefile
cvs rdiff -u -r1.6 -r1.7 src/sys/compat/common/Makefile.sysio
cvs rdiff -u -r1.23 -r1.24 src/sys/compat/common/compat_mod.c
cvs rdiff -u -r1.12 -r1.13 src/sys/compat/common/if_43.c
cvs rdiff -u -r0 -r1.1 src/sys/compat/common/if_43.h
cvs rdiff -u -r1.360 -r1.361 src/sys/net/if.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/compat/common/Makefile
diff -u src/sys/compat/common/Makefile:1.59 src/sys/compat/common/Makefile:1.60
--- src/sys/compat/common/Makefile:1.59	Thu Nov  3 22:23:03 2016
+++ src/sys/compat/common/Makefile	Sat Nov  5 23:30:22 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.59 2016/11/03 22:23:03 pgoyette Exp $
+#	$NetBSD: Makefile,v 1.60 2016/11/05 23:30:22 pgoyette Exp $
 
 LIB=		compat
 NOPIC=		# defined
@@ -11,9 +11,6 @@ CPPFLAGS=	${COMPATCPPFLAGS} ${SKIP_AUTOD
 # Common compatibility code, used by all emulations
 SRCS=	compat_exec.c compat_util.c
 
-# Compatability code for 4.3BSD 
-SRCS+=	if_43.c
-
 # Include compatability code common to libcompat and the compat module
 
 .include "Makefile.sysio"

Index: src/sys/compat/common/Makefile.sysio
diff -u src/sys/compat/common/Makefile.sysio:1.6 src/sys/compat/common/Makefile.sysio:1.7
--- src/sys/compat/common/Makefile.sysio:1.6	Thu Nov  3 22:23:03 2016
+++ src/sys/compat/common/Makefile.sysio	Sat Nov  5 23:30:22 2016
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile.sysio,v 1.6 2016/11/03 22:23:03 pgoyette Exp $
+#	$NetBSD: Makefile.sysio,v 1.7 2016/11/05 23:30:22 pgoyette Exp $
 
 # Sources for syscall and ioctl compatibility across the versions.
 
 # Compatibility code for 4.3BSD
 SRCS+=	kern_exit_43.c kern_info_43.c kern_resource_43.c kern_sig_43.c \
-	tty_43.c uipc_syscalls_43.c vfs_syscalls_43.c vm_43.c
+	tty_43.c uipc_syscalls_43.c vfs_syscalls_43.c vm_43.c if_43.c
 
 # Compatibility code for NetBSD 0.9
 SRCS+=	kern_info_09.c

Index: src/sys/compat/common/compat_mod.c
diff -u src/sys/compat/common/compat_mod.c:1.23 src/sys/compat/common/compat_mod.c:1.24
--- src/sys/compat/common/compat_mod.c:1.23	Sat Dec  5 01:59:51 2015
+++ src/sys/compat/common/compat_mod.c	Sat Nov  5 23:30:22 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_mod.c,v 1.23 2015/12/05 01:59:51 pgoyette Exp $	*/
+/*	$NetBSD: compat_mod.c,v 1.24 2016/11/05 23:30:22 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_mod.c,v 1.23 2015/12/05 01:59:51 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_mod.c,v 1.24 2016/11/05 23:30:22 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -59,11 +59,12 @@ __KERNEL_RCSID(0, "$NetBSD: compat_mod.c
 
 #include <compat/common/compat_util.h>
 #include <compat/common/compat_mod.h>
+#include <compat/common/if_43.h>
 
 #if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_50)
 static struct sysctllog *compat_clog = NULL;
 #endif
- 
+
 MODULE(MODULE_CLASS_EXEC, compat, NULL);
 
 int	ttcompat(struct tty *, u_long, void *, int, struct lwp *);
@@ -235,6 +236,7 @@ compat_modcmd(modcmd_t cmd, void *arg)
 #ifdef COMPAT_43
 		KASSERT(ttcompatvec == NULL);
 		ttcompatvec = ttcompat;
+		if_43_init();
 #endif
 #ifdef COMPAT_16
 #if defined(COMPAT_SIGCONTEXT)
@@ -332,4 +334,7 @@ compat_sysctl_fini(void)
 #if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_50)
         sysctl_teardown(&compat_clog);
 #endif
+#if defined(COMPAT_43)
+	if_43_fini();
+#endif
 }

Index: src/sys/compat/common/if_43.c
diff -u src/sys/compat/common/if_43.c:1.12 src/sys/compat/common/if_43.c:1.13
--- src/sys/compat/common/if_43.c:1.12	Mon Jul 25 08:30:19 2016
+++ src/sys/compat/common/if_43.c	Sat Nov  5 23:30:22 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_43.c,v 1.12 2016/07/25 08:30:19 ozaki-r Exp $	*/
+/*	$NetBSD: if_43.c,v 1.13 2016/11/05 23:30:22 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.12 2016/07/25 08:30:19 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.13 2016/11/05 23:30:22 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -73,7 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.
 #include <compat/sys/sockio.h>
 
 #include <compat/common/compat_util.h>
-
+#include <compat/common/if_43.h>
 #include <uvm/uvm_extern.h>
 
 u_long 
@@ -280,3 +280,31 @@ compat_ifioctl(struct socket *so, u_long
 
 	return error;
 }
+
+#if defined(COMPAT_43)
+static u_long (*orig_compat_cvtcmd)(u_long);
+static int (*orig_compat_ifioctl)(struct socket *, u_long, u_long,
+    void *, struct lwp *);
+
+void
+if_43_init(void)
+{
+	extern u_long (*vec_compat_cvtcmd)(u_long);
+	extern int (*vec_compat_ifioctl)(struct socket *, u_long, u_long,
+	    void *, struct lwp *);
+
+	orig_compat_cvtcmd = vec_compat_cvtcmd;
+	vec_compat_cvtcmd = compat_cvtcmd;
+
+	orig_compat_ifioctl = vec_compat_ifioctl;
+	vec_compat_ifioctl =  compat_ifioctl;
+}
+
+void
+if_43_fini(void)
+{
+
+	vec_compat_cvtcmd = orig_compat_cvtcmd;
+	vec_compat_ifioctl = orig_compat_ifioctl;
+}
+#endif /* defined(COMPAT_43) */

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.360 src/sys/net/if.c:1.361
--- src/sys/net/if.c:1.360	Fri Oct 28 05:52:05 2016
+++ src/sys/net/if.c	Sat Nov  5 23:30:22 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.360 2016/10/28 05:52:05 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.361 2016/11/05 23:30:22 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.360 2016/10/28 05:52:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.361 2016/11/05 23:30:22 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -227,6 +227,25 @@ static void sysctl_percpuq_setup(struct 
 static void sysctl_net_pktq_setup(struct sysctllog **, int);
 #endif
 
+/*
+ * Pointer to stub or real compat_cvtcmd() depending on presence of
+ * the compat module
+ */
+u_long stub_compat_cvtcmd(u_long);
+u_long (*vec_compat_cvtcmd)(u_long) = stub_compat_cvtcmd;
+
+/* Similarly, pointer to compat_ifioctl() if it is present */
+
+int (*vec_compat_ifioctl)(struct socket *, u_long, u_long, void *,
+	struct lwp *) = NULL;
+
+/* The stub version of compat_cvtcmd() */
+u_long stub_compat_cvtcmd(u_long cmd)
+{
+
+	return cmd;
+}
+
 static int
 if_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
     void *arg0, void *arg1, void *arg2, void *arg3)
@@ -2769,7 +2788,7 @@ doifioctl(struct socket *so, u_long cmd,
 	}
 
 #ifdef COMPAT_OIFREQ
-	cmd = compat_cvtcmd(cmd);
+	cmd = (*vec_compat_cvtcmd)(cmd);
 	if (cmd != ocmd) {
 		oifr = data;
 		data = ifr = &ifrb;
@@ -2866,11 +2885,12 @@ doifioctl(struct socket *so, u_long cmd,
 		error = EOPNOTSUPP;
 	else {
 #ifdef COMPAT_OSOCK
-		error = compat_ifioctl(so, ocmd, cmd, data, l);
-#else
-		error = (*so->so_proto->pr_usrreqs->pr_ioctl)(so,
-		    cmd, data, ifp);
+		if (vec_compat_ifioctl != NULL)
+			error = (*vec_compat_ifioctl)(so, ocmd, cmd, data, l);
+		else
 #endif
+			error = (*so->so_proto->pr_usrreqs->pr_ioctl)(so,
+			    cmd, data, ifp);
 	}
 
 	if (((oif_flags ^ ifp->if_flags) & IFF_UP) != 0) {
@@ -3015,7 +3035,7 @@ ifreq_setaddr(u_long cmd, struct ifreq *
 	struct ifreq ifrb;
 	struct oifreq *oifr = NULL;
 	u_long ocmd = cmd;
-	cmd = compat_cvtcmd(cmd);
+	cmd = (*vec_compat_cvtcmd)(cmd);
 	if (cmd != ocmd) {
 		oifr = (struct oifreq *)(void *)ifr;
 		ifr = &ifrb;

Added files:

Index: src/sys/compat/common/if_43.h
diff -u /dev/null src/sys/compat/common/if_43.h:1.1
--- /dev/null	Sat Nov  5 23:30:22 2016
+++ src/sys/compat/common/if_43.h	Sat Nov  5 23:30:22 2016
@@ -0,0 +1,44 @@
+/*	$NetBSD: if_43.h,v 1.1 2016/11/05 23:30:22 pgoyette Exp $	*/
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Paul Goyette
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef	_COMPAT_IF_43_H_
+#define	_COMPAT_IF_43_H_
+
+#if defined(COMPAT_43)
+extern u_long (*vec_compat_cvtcmd)(u_long); 
+extern int (*vec_compat_ifioctl)(struct socket *, u_long, u_long, 
+    void *, struct lwp *);
+
+void if_43_init(void);
+void if_43_fini(void);
+#endif
+
+#endif /* !_COMPAT_IF_43_H_ */

Reply via email to