Subject: Re: kern/31304: sk and rtk don't contribute to random pool [patch included]
To: Rui Paulo <rpaulo@NetBSD.org>
From: Rhialto <rhialto@falu.nl>
List: netbsd-bugs
Date: 09/13/2005 16:42:13
On Tue 13 Sep 2005 at 14:23:47 +0100, Rui Paulo wrote:
> Hmm. I looked at tlp(4) and it had the 'sc' prefix.

It looks like this isn't done very consistently. I notice for instance
in struct rtk_softc that there are sc_ and rtk_ prefixes, and similar in
sk_softc. There is even sk_dev where it is usually sc_dev.

Here are new diffs. I test-compiled both; 2.0.2 with my own custom
config, -current with GENERIC. I need to find some convenient time to
reboot my server to run this.

The diff for -current is now bigger since it adds some sc_ prefixes
where there were none before (in the rtk code). I suppose somebody
should go over all of these and make them more regular.

For 2.0.2:

Index: dev/ic/rtl81x9.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9.c,v
retrieving revision 1.45.4.1
diff -u -u -r1.45.4.1 rtl81x9.c
--- dev/ic/rtl81x9.c	21 Jun 2004 16:39:00 -0000	1.45.4.1
+++ dev/ic/rtl81x9.c	13 Sep 2005 14:09:28 -0000
@@ -768,6 +768,11 @@
 		printf("%s: WARNING: unable to establish power hook\n",
 		    sc->sc_dev.dv_xname);
 
+#if NRND > 0
+	rnd_attach_source(&sc->sc_rnd_source, sc->sc_dev.dv_xname,
+	    RND_TYPE_NET, 0);
+#endif
+
 	return;
  fail_4:
 	for (i = 0; i < RTK_TX_LIST_CNT; i++) {
@@ -863,6 +868,10 @@
 	/* Delete all remaining media. */
 	ifmedia_delete_instance(&sc->mii.mii_media, IFM_INST_ANY);
 
+#if NRND > 0
+	rnd_detach_source(&sc->sc_rnd_source);
+#endif
+
 	ether_ifdetach(ifp);
 	if_detach(ifp);
 
@@ -1265,6 +1274,11 @@
 	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
 		rtk_start(ifp);
 
+#if NRND > 0
+	if (RND_ENABLED(&sc->sc_rnd_source))
+	    rnd_add_uint32(&sc->sc_rnd_source, status);
+#endif
+
 	return (handled);
 }
 
Index: dev/ic/rtl81x9var.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9var.h,v
retrieving revision 1.11.2.2
diff -u -u -r1.11.2.2 rtl81x9var.h
--- dev/ic/rtl81x9var.h	21 Jun 2004 17:12:38 -0000	1.11.2.2
+++ dev/ic/rtl81x9var.h	13 Sep 2005 14:09:32 -0000
@@ -33,6 +33,11 @@
  *
  *	FreeBSD Id: if_rlreg.h,v 1.9 1999/06/20 18:56:09 wpaul Exp
  */
+#include "rnd.h"
+
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
 
 #define RTK_ETHER_ALIGN	2
 #define RTK_RXSTAT_LEN	4
@@ -140,6 +145,9 @@
 	int	(*sc_enable)	__P((struct rtk_softc *));
 	void	(*sc_disable)	__P((struct rtk_softc *));
 	void	(*sc_power)	__P((struct rtk_softc *, int));
+#if NRND > 0
+	rndsource_element_t     sc_rnd_source;
+#endif
 };
 
 #define RTK_ATTACHED 0x00000001 /* attach has succeeded */
Index: dev/pci/if_skvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_skvar.h,v
retrieving revision 1.3.2.1
diff -u -u -r1.3.2.1 if_skvar.h
--- dev/pci/if_skvar.h	7 Jan 2005 12:16:04 -0000	1.3.2.1
+++ dev/pci/if_skvar.h	13 Sep 2005 14:09:36 -0000
@@ -87,6 +87,12 @@
 #ifndef _DEV_PCI_IF_SKVAR_H_
 #define _DEV_PCI_IF_SKVAR_H_
 
+#include "rnd.h"
+
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+
 struct sk_jslot {
 	caddr_t			sk_buf;
 	int			sk_inuse;
@@ -208,6 +214,9 @@
 	u_int32_t		sk_intrmask;
 	bus_dma_tag_t		sc_dmatag;
 	struct sk_if_softc	*sk_if[2];
+#if NRND > 0
+	rndsource_element_t     sc_rnd_source;
+#endif
 };
 
 /* Softc for each logical interface */
Index: dev/pci/if_sk.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_sk.c,v
retrieving revision 1.7.2.4
diff -u -u -r1.7.2.4 if_sk.c
--- dev/pci/if_sk.c	7 Jan 2005 12:13:50 -0000	1.7.2.4
+++ dev/pci/if_sk.c	13 Sep 2005 14:09:42 -0000
@@ -122,6 +122,7 @@
  */
  
 #include "bpfilter.h"
+#include "rnd.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -151,6 +152,9 @@
 #if NBPFILTER > 0
 #include <net/bpf.h>
 #endif
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
 
 #include <dev/mii/mii.h>
 #include <dev/mii/miivar.h>
@@ -1292,8 +1296,12 @@
 	ether_ifattach(ifp, sc_if->sk_enaddr);
 
 #if NRND > 0
-        rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
+        rnd_attach_source(&sc->sc_rnd_source, sc->sk_dev.dv_xname,
             RND_TYPE_NET, 0);
+	/*
+	 * Note that there is no sk_detach function where one could call
+	 * rnd_detach_source(&sc->rnd_source);
+	 */
 #endif
 
 	DPRINTFN(2, ("sk_attach: end\n"));
@@ -2152,6 +2160,11 @@
 	if (ifp1 != NULL && !IFQ_IS_EMPTY(&ifp1->if_snd))
 		sk_start(ifp1);
 
+#if NRND > 0
+	if (RND_ENABLED(&sc->sc_rnd_source))
+	    rnd_add_uint32(&sc->sc_rnd_source, status);
+#endif
+
 	return (claimed);
 }
 

For -current:

Index: dev/ic/rtl81x9.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9.c,v
retrieving revision 1.51
diff -u -u -r1.51 rtl81x9.c
--- dev/ic/rtl81x9.c	27 Feb 2005 00:27:02 -0000	1.51
+++ dev/ic/rtl81x9.c	13 Sep 2005 14:10:02 -0000
@@ -779,7 +779,7 @@
 
 
 #if NRND > 0
-	rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
+	rnd_attach_source(&sc->sc_rnd_source, sc->sc_dev.dv_xname,
 	    RND_TYPE_NET, 0);
 #endif
 
@@ -880,7 +880,7 @@
 	ifmedia_delete_instance(&sc->mii.mii_media, IFM_INST_ANY);
 
 #if NRND > 0
-	rnd_detach_source(&sc->rnd_source);
+	rnd_detach_source(&sc->sc_rnd_source);
 #endif
 
 	ether_ifdetach(ifp);
@@ -1289,8 +1289,8 @@
 		rtk_start(ifp);
 
 #if NRND > 0
-	if (RND_ENABLED(&sc->rnd_source))
-		rnd_add_uint32(&sc->rnd_source, status);
+	if (RND_ENABLED(&sc->sc_rnd_source))
+		rnd_add_uint32(&sc->sc_rnd_source, status);
 #endif
 
 	return (handled);
Index: dev/ic/rtl81x9var.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9var.h,v
retrieving revision 1.19
diff -u -u -r1.19 rtl81x9var.h
--- dev/ic/rtl81x9var.h	30 May 2005 04:43:47 -0000	1.19
+++ dev/ic/rtl81x9var.h	13 Sep 2005 14:10:04 -0000
@@ -158,7 +158,7 @@
 	void	(*sc_disable)	(struct rtk_softc *);
 	void	(*sc_power)	(struct rtk_softc *, int);
 #if NRND > 0
-	rndsource_element_t     rnd_source;
+	rndsource_element_t     sc_rnd_source;
 #endif
 };
 
Index: dev/pci/if_skvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_skvar.h,v
retrieving revision 1.6
diff -u -u -r1.6 if_skvar.h
--- dev/pci/if_skvar.h	30 May 2005 04:35:22 -0000	1.6
+++ dev/pci/if_skvar.h	13 Sep 2005 14:10:07 -0000
@@ -87,6 +87,12 @@
 #ifndef _DEV_PCI_IF_SKVAR_H_
 #define _DEV_PCI_IF_SKVAR_H_
 
+#include "rnd.h"
+
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+
 struct sk_jslot {
 	caddr_t			sk_buf;
 	int			sk_inuse;
@@ -208,6 +214,9 @@
 	u_int32_t		sk_intrmask;
 	bus_dma_tag_t		sc_dmatag;
 	struct sk_if_softc	*sk_if[2];
+#if NRND > 0
+	rndsource_element_t     sc_rnd_source;
+#endif
 };
 
 /* Softc for each logical interface */
Index: dev/pci/if_sk.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_sk.c,v
retrieving revision 1.16
diff -u -u -r1.16 if_sk.c
--- dev/pci/if_sk.c	11 Sep 2005 23:49:39 -0000	1.16
+++ dev/pci/if_sk.c	13 Sep 2005 14:10:09 -0000
@@ -122,6 +122,7 @@
  */
 
 #include "bpfilter.h"
+#include "rnd.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -151,6 +152,9 @@
 #if NBPFILTER > 0
 #include <net/bpf.h>
 #endif
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
 
 #include <dev/mii/mii.h>
 #include <dev/mii/miivar.h>
@@ -1295,7 +1299,7 @@
 	ether_ifattach(ifp, sc_if->sk_enaddr);
 
 #if NRND > 0
-        rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
+        rnd_attach_source(&sc->sc_rnd_source, sc->sk_dev.dv_xname,
             RND_TYPE_NET, 0);
 #endif
 
@@ -2158,6 +2162,11 @@
 	if (ifp1 != NULL && !IFQ_IS_EMPTY(&ifp1->if_snd))
 		sk_start(ifp1);
 
+#if NRND > 0
+	if (RND_ENABLED(&sc->sc_rnd_source))
+		rnd_add_uint32(&sc->sc_rnd_source, status);
+#endif
+
 	return (claimed);
 }
 
-Olaf.
-- 
___ Olaf 'Rhialto' Seibert      -- You author it, and I'll reader it.
\X/ rhialto/at/xs4all.nl        -- Cetero censeo "authored" delendum esse.