Module Name:    src
Committed By:   pgoyette
Date:           Fri Jan 11 06:27:45 UTC 2019

Modified Files:
        src/sys/compat/common [pgoyette-compat]: compat_50_mod.c compat_mod.h
            rtsock_50.c
        src/sys/kern [pgoyette-compat]: compat_stub.c
        src/sys/net [pgoyette-compat]: rtsock.c
        src/sys/sys [pgoyette-compat]: compat_stub.h
Added Files:
        src/sys/compat/net [pgoyette-compat]: route_50.h

Log Message:
Rework the various sysctl-related routines to call the correct code
for each version.  While here, extract the 5.0 specific code instead
of including in the main rtsock.c code.

Also, clean up all the sysctl-related routines to prevent building
more than one copy, no matter how many places rtsock.c gets #include'd
into!


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.17 -r1.1.2.18 src/sys/compat/common/compat_50_mod.c
cvs rdiff -u -r1.1.42.23 -r1.1.42.24 src/sys/compat/common/compat_mod.h
cvs rdiff -u -r1.6.2.1 -r1.6.2.2 src/sys/compat/common/rtsock_50.c
cvs rdiff -u -r0 -r1.1.2.1 src/sys/compat/net/route_50.h
cvs rdiff -u -r1.1.2.32 -r1.1.2.33 src/sys/kern/compat_stub.c
cvs rdiff -u -r1.238.2.13 -r1.238.2.14 src/sys/net/rtsock.c
cvs rdiff -u -r1.1.2.44 -r1.1.2.45 src/sys/sys/compat_stub.h

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/compat_50_mod.c
diff -u src/sys/compat/common/compat_50_mod.c:1.1.2.17 src/sys/compat/common/compat_50_mod.c:1.1.2.18
--- src/sys/compat/common/compat_50_mod.c:1.1.2.17	Fri Oct 12 22:30:54 2018
+++ src/sys/compat/common/compat_50_mod.c	Fri Jan 11 06:27:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_50_mod.c,v 1.1.2.17 2018/10/12 22:30:54 pgoyette Exp $	*/
+/*	$NetBSD: compat_50_mod.c,v 1.1.2.18 2019/01/11 06:27:45 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_50_mod.c,v 1.1.2.17 2018/10/12 22:30:54 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_50_mod.c,v 1.1.2.18 2019/01/11 06:27:45 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -86,6 +86,7 @@ compat_50_init(void)
 	wsevent_50_init();
 	vnd_50_init();
 	rndpseudo_50_init();
+	rtsock_50_init();
 
 	return error;
 
@@ -106,6 +107,7 @@ compat_50_fini(void)
 {
 	int error = 0;
 
+	rtsock_50_fini();
 	rndpseudo_50_fini();
 	vnd_50_fini();
 	wsevent_50_fini();
@@ -149,6 +151,7 @@ compat_50_fini(void)
 	wsevent_50_init();
 	vnd_50_init();
 	rndpseudo_50_init();
+	rtsock_50_init();
 
 	return error;
 }

Index: src/sys/compat/common/compat_mod.h
diff -u src/sys/compat/common/compat_mod.h:1.1.42.23 src/sys/compat/common/compat_mod.h:1.1.42.24
--- src/sys/compat/common/compat_mod.h:1.1.42.23	Fri Oct 12 22:30:54 2018
+++ src/sys/compat/common/compat_mod.h	Fri Jan 11 06:27:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_mod.h,v 1.1.42.23 2018/10/12 22:30:54 pgoyette Exp $	*/
+/*	$NetBSD: compat_mod.h,v 1.1.42.24 2019/01/11 06:27:45 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -74,6 +74,8 @@ void vnd_50_init(void);
 void vnd_50_fini(void);
 void rndpseudo_50_init(void);
 void rndpseudo_50_fini(void);
+void rtsock_50_init(void);
+void rtsock_50_fini(void);
 #endif
 
 #ifdef COMPAT_40

Index: src/sys/compat/common/rtsock_50.c
diff -u src/sys/compat/common/rtsock_50.c:1.6.2.1 src/sys/compat/common/rtsock_50.c:1.6.2.2
--- src/sys/compat/common/rtsock_50.c:1.6.2.1	Mon May 21 04:36:03 2018
+++ src/sys/compat/common/rtsock_50.c	Fri Jan 11 06:27:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock_50.c,v 1.6.2.1 2018/05/21 04:36:03 pgoyette Exp $	*/
+/*	$NetBSD: rtsock_50.c,v 1.6.2.2 2019/01/11 06:27:45 pgoyette Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.6.2.1 2018/05/21 04:36:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,v 1.6.2.2 2019/01/11 06:27:45 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: rtsock_50.c,
 #define	COMPAT_RTSOCK
 
 #include <net/rtsock.c>
+#include <compat/net/route_50.h>
 
 void
 compat_50_rt_oifmsg(struct ifnet *ifp)
@@ -156,3 +157,20 @@ compat_50_iflist(struct ifnet *ifp, stru
 	w->w_where = (char *)w->w_where + len;
 	return 0;
 }
+
+MODULE_SET_HOOK(rtsock_50_hook, "rts_50", compat_50_iflist);
+MODULE_UNSET_HOOK(rtsock_50_hook); 
+ 
+void
+rtsock_50_init(void)
+{
+ 
+	rtsock_50_hook_set();
+}
+ 
+void
+rtsock_50_fini(void)
+{  
+
+	rtsock_50_hook_unset();
+}

Index: src/sys/kern/compat_stub.c
diff -u src/sys/kern/compat_stub.c:1.1.2.32 src/sys/kern/compat_stub.c:1.1.2.33
--- src/sys/kern/compat_stub.c:1.1.2.32	Mon Oct 15 22:06:16 2018
+++ src/sys/kern/compat_stub.c	Fri Jan 11 06:27:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.c,v 1.1.2.32 2018/10/15 22:06:16 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.c,v 1.1.2.33 2019/01/11 06:27:45 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -157,6 +157,11 @@ struct uipc_syscalls_50_hook_t uipc_sysc
 struct rtsock14_hook_t rtsock14_hook;
 
 /*
+ * rtsock 50 compatability
+ */
+struct rtsock_50_hook_t rtsock_50_hook;
+
+/*
  * rtsock 70 compatability
  */
 struct rtsock_70_hook_t rtsock_70_hook;

Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.238.2.13 src/sys/net/rtsock.c:1.238.2.14
--- src/sys/net/rtsock.c:1.238.2.13	Mon Nov 26 01:52:50 2018
+++ src/sys/net/rtsock.c	Fri Jan 11 06:27:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.238.2.13 2018/11/26 01:52:50 pgoyette Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.238.2.14 2019/01/11 06:27:45 pgoyette Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.238.2.13 2018/11/26 01:52:50 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.238.2.14 2019/01/11 06:27:45 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -168,12 +168,12 @@ static struct mbuf *rt_makeifannouncemsg
 static int rt_msg2(int, struct rt_addrinfo *, void *, struct rt_walkarg *, int *);
 static void _rt_setmetrics(int, const struct rt_xmsghdr *, struct rtentry *);
 static void rtm_setmetrics(const struct rtentry *, struct rt_xmsghdr *);
-static void sysctl_net_route_setup(struct sysctllog **);
-static int sysctl_dumpentry(struct rtentry *, void *);
-static int sysctl_iflist(int, struct rt_walkarg *, int);
-static int sysctl_rtable(SYSCTLFN_PROTO);
 static void rt_adjustcount(int, int);
 
+#ifndef COMPAT_RTSOCK
+static void sysctl_net_route_setup(struct sysctllog **);
+#endif
+
 static const struct protosw COMPATNAME(route_protosw)[];
 
 struct routecb {
@@ -192,9 +192,6 @@ static kcondvar_t rt_update_cv;
 #endif
 
 #ifndef COMPAT_RTSOCK
-static int
-sysctl_iflist_addr(struct rt_walkarg *, struct ifaddr *, struct rt_addrinfo *);
-
 /*
  * Compat linkage
  */
@@ -1391,7 +1388,23 @@ MODULE_CALL_HOOK(rtsock14_hook, f2,
 #endif
 
 /*
- * MODULE_HOOK glue for rtsock70_ifaddr_list and rtsock70_newaddrmsg1
+ * MODULE_HOOK glue for rtsock50_ifaddr_listif
+ */
+MODULE_CALL_HOOK_DECL(rtsock_50_hook, f,
+    (struct ifnet *ifp, struct rt_walkarg *w, struct rt_addrinfo *info, 
+     size_t len));
+#ifndef COMPAT_RTSOCK 
+MODULE_CALL_HOOK(rtsock_50_hook, f, 
+    (struct ifnet *ifp, struct rt_walkarg *w, struct rt_addrinfo *info,
+     size_t len),               
+    (ifp, w, info, len),
+    enosys());
+#endif
+
+
+/*
+ * MODULE_HOOK glue for rtsock70_newaddrmsg1, rtsock70_ifaddr_listaddr,
+ * and rtsock70_ifaddr_listif
  */
 MODULE_CALL_HOOK_DECL(rtsock_70_hook, f1, (int, struct ifaddr *));
 #ifndef COMPAT_RTSOCK
@@ -1405,7 +1418,7 @@ MODULE_CALL_HOOK_DECL(rtsock_70_hook, f2
 MODULE_CALL_HOOK(rtsock_70_hook, f2,
     (struct rt_walkarg *w, struct ifaddr *ifa, struct rt_addrinfo *info),
     (w, ifa, info), 
-    sysctl_iflist_addr(w, ifa, info));
+    enosys());
 #endif
 
 /*
@@ -1684,7 +1697,6 @@ rt_clonedmsg(const struct sockaddr *dst,
 #undef RTF_LLINFO
 #undef RTF_CLONED
 }
-#endif /* COMPAT_RTSOCK */
 
 /*
  * This is used in dumping the kernel table via sysctl().
@@ -1752,7 +1764,6 @@ sysctl_iflist_if(struct ifnet *ifp, stru
 	return error;
 }
 
-#ifndef COMPAT_RTSOCK	/* XXX need to include the stuff in COMPAT_50 */
 static int
 sysctl_iflist_addr(struct rt_walkarg *w, struct ifaddr *ifa,
      struct rt_addrinfo *info)
@@ -1769,16 +1780,13 @@ sysctl_iflist_addr(struct rt_walkarg *w,
 		ifam->ifam_flags = ifa->ifa_flags;
 		ifam->ifam_metric = ifa->ifa_metric;
 		ifam->ifam_addrs = info->rti_addrs;
-#ifndef COMPAT_RTSOCK
 		ifam->ifam_pid = 0;
 		ifam->ifam_addrflags = if_addrflags(ifa);
-#endif
 		if ((error = copyout(w->w_tmem, w->w_where, len)) == 0)
 			w->w_where = (char *)w->w_where + len;
 	}
 	return error;
 }
-#endif /* XXX */
 
 static int
 sysctl_iflist(int af, struct rt_walkarg *w, int type)
@@ -1787,8 +1795,6 @@ sysctl_iflist(int af, struct rt_walkarg 
 	struct ifaddr *ifa;
 	struct	rt_addrinfo info;
 	int	cmd, len, error = 0;
-	int	(*iflist_if)(struct ifnet *, struct rt_walkarg *,
-			     struct rt_addrinfo *, size_t);
 	int s;
 	struct psref psref;
 	int bound;
@@ -1796,24 +1802,16 @@ sysctl_iflist(int af, struct rt_walkarg 
 	switch (type) {
 	case NET_RT_IFLIST:
 		cmd = RTM_IFINFO;
-		iflist_if = sysctl_iflist_if;
 		break;
 	case NET_RT_OOOIFLIST:
 		cmd = RTM_OOIFINFO;
-		iflist_if = rtsock14_hook_f2_call;
 		break;
-#ifdef COMPAT_50
 	case NET_RT_OOIFLIST:
 		cmd = RTM_OIFINFO;
-		iflist_if = compat_50_iflist;
 		break;
-#endif
-#ifdef COMPAT_70
 	case NET_RT_OIFLIST:
 		cmd = RTM_IFINFO;
-		iflist_if = sysctl_iflist_if;
 		break;
-#endif
 	default:
 #ifdef RTSOCK_DEBUG
 		printf("%s: unsupported IFLIST type %d\n", __func__, type);
@@ -1840,7 +1838,23 @@ sysctl_iflist(int af, struct rt_walkarg 
 			goto release_exit;
 		info.rti_info[RTAX_IFP] = NULL;
 		if (w->w_where && w->w_tmem && w->w_needed <= 0) {
-			if ((error = iflist_if(ifp, w, &info, len)) != 0) {
+			switch (type) {
+			case NET_RT_IFLIST: /* current */
+			case NET_RT_OIFLIST: /* old _70 */
+				error = sysctl_iflist_if(ifp, w, &info, len);
+				break;
+			case NET_RT_OOIFLIST: /* old _50 */
+				error = rtsock_50_hook_f_call(ifp, w, &info,
+				    len);
+				break;
+			case NET_RT_OOOIFLIST: /* old _14 */
+				error = rtsock14_hook_f2_call(ifp, w, &info,
+				    len);
+				break;
+			default:
+				error = EINVAL;
+			}
+			if (error != 0) {
 				if (error == ENOSYS)
 					error = EINVAL;
 				goto release_exit;
@@ -1857,7 +1871,18 @@ sysctl_iflist(int af, struct rt_walkarg 
 			info.rti_info[RTAX_IFA] = ifa->ifa_addr;
 			info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
 			info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr;
-			error = rtsock_70_hook_f2_call(w, ifa, &info);
+			switch (type) {
+			case NET_RT_IFLIST:
+				error = sysctl_iflist_addr(w, ifa, &info);
+				break;
+			case NET_RT_OIFLIST:
+			case NET_RT_OOIFLIST:
+			case NET_RT_OOOIFLIST:
+				error = rtsock_70_hook_f2_call(w, ifa, &info);
+				break;
+			default:
+				error = EINVAL;
+			}
 
 			_s = pserialize_read_enter();
 			ifa_release(ifa, &_psref);
@@ -1955,22 +1980,10 @@ again:
 		}
 		break;
 
-#ifdef COMPAT_14
-	case NET_RT_OOOIFLIST:
-		error = sysctl_iflist(af, &w, w.w_op);
-		break;
-#endif
-#ifdef COMPAT_50
-	case NET_RT_OOIFLIST:
-		error = sysctl_iflist(af, &w, w.w_op);
-		break;
-#endif
-#ifdef COMPAT_70
-	case NET_RT_OIFLIST:
-		error = sysctl_iflist(af, &w, w.w_op);
-		break;
-#endif
-	case NET_RT_IFLIST:
+	case NET_RT_OOOIFLIST:		/* compat_14 */
+	case NET_RT_OOIFLIST:		/* compat_50 */
+	case NET_RT_OIFLIST:		/* compat_70 */
+	case NET_RT_IFLIST:		/* current */
 		error = sysctl_iflist(af, &w, w.w_op);
 		break;
 	}
@@ -1992,6 +2005,7 @@ again:
 	}
 	return error;
 }
+#endif /* COMPAT_RTSOCK */
 
 /*
  * Routing message software interrupt routine
@@ -2064,7 +2078,9 @@ COMPATNAME(route_init)(void)
 	cv_init(&rt_update_cv, "rtsock_cv");
 #endif
 
+#ifndef COMPAT_RTSOCK
 	sysctl_net_route_setup(NULL);
+#endif
 	ri->ri_intrq.ifq_maxlen = ri->ri_maxqlen;
 	ri->ri_sih = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
 	    COMPATNAME(route_intr), NULL);
@@ -2123,6 +2139,7 @@ struct domain COMPATNAME(routedomain) = 
 	    &COMPATNAME(route_protosw)[__arraycount(COMPATNAME(route_protosw))],
 };
 
+#ifndef COMPAT_RTSOCK
 static void
 sysctl_net_route_setup(struct sysctllog **clog)
 {
@@ -2149,3 +2166,4 @@ sysctl_net_route_setup(struct sysctllog 
 		       NULL, 0, &rtstat, sizeof(rtstat),
 		       CTL_CREATE, CTL_EOL);
 }
+#endif

Index: src/sys/sys/compat_stub.h
diff -u src/sys/sys/compat_stub.h:1.1.2.44 src/sys/sys/compat_stub.h:1.1.2.45
--- src/sys/sys/compat_stub.h:1.1.2.44	Mon Oct 15 22:06:16 2018
+++ src/sys/sys/compat_stub.h	Fri Jan 11 06:27:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.h,v 1.1.2.44 2018/10/15 22:06:16 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.h,v 1.1.2.45 2019/01/11 06:27:45 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -201,13 +201,19 @@ MODULE_HOOK2(rtsock14_hook, (struct ifne
     (struct ifnet *, struct rt_walkarg *, struct rt_addrinfo *, size_t));
 
 /*
+ * Hooks for rtsock_50
+ */
+
+MODULE_HOOK(rtsock_50_hook,
+    (struct ifnet *, struct rt_walkarg *, struct rt_addrinfo *, size_t len));
+
+/*
  * Hooks for rtsock_70
  */
 struct ifaddr;
 MODULE_HOOK2(rtsock_70_hook, (int, struct ifaddr *),
     (struct rt_walkarg *, struct ifaddr *, struct rt_addrinfo *));
 
-
 /*
  * modctl handler for old style OSTAT
  */

Added files:

Index: src/sys/compat/net/route_50.h
diff -u /dev/null src/sys/compat/net/route_50.h:1.1.2.1
--- /dev/null	Fri Jan 11 06:27:45 2019
+++ src/sys/compat/net/route_50.h	Fri Jan 11 06:27:45 2019
@@ -0,0 +1,42 @@
+/*	$NetBSD: route_50.h,v 1.1.2.1 2019/01/11 06:27:45 pgoyette Exp $	*/
+
+/*-
+ * Copyright (c) 2018 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_NET_ROUTE_50_H_
+#define _COMPAT_NET_ROUTE_50_H_
+
+#include <net/route.h>
+
+/* compat interfaces */
+
+void rtsock_50_init(void);
+void rtsock_50_fini(void);
+
+#endif /* !_COMPAT_NET_ROUTE_70_H_ */

Reply via email to