Subject: kern/31304: sk and rtk don't contribute to random pool [patch included]
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Rhialto <rhialto@falu.nl>
List: netbsd-bugs
Date: 09/12/2005 20:20:00
>Number:         31304
>Category:       kern
>Synopsis:       sk and rtk don't contribute to random pool [patch included]
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 12 20:20:00 +0000 2005
>Originator:     Rhialto
>Release:        NetBSD 2.0.2 and -current
>Organization:
	
>Environment:
	
	
	System: NetBSD radl.falu.nl 2.0.2 NetBSD 2.0.2 (Radls Doordringend
	Onjuiste Akkoord) #4: Thu Jun 16 20:52:36 CEST 2005
	rhialto@radl.falu.nl:/usr/src/sys/arch/amd64/compile/RADL amd64
	Architecture: x86_64 Machine: amd64
>Description:
	None of the network interfaces (sk and rtk) on my machine contribute
	to the randomness pool. Some other network interfaces exist that do,
	such as vr, so I did a cut and paste job for both 2.0.2 and -current.
	From code inspection it seems that in -current rtk should work
	already. sk has partial code that can't (and doesn't) work.

>How-To-Repeat:
	run `rndctl -ls' and see there are no network sources listed.
>Fix:
	First the patch for 2.0.2, then for -current.
	I compile-tested the one for 2.0.2, then cut&pasted where needed
	to my cvs tree to generate the version for -current.


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	12 Sep 2005 19:59:00 -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->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->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->rnd_source))
+	    rnd_add_uint32(&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	12 Sep 2005 19:59:04 -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     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	12 Sep 2005 19:59:08 -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     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	12 Sep 2005 19:59:13 -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->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->rnd_source))
+	    rnd_add_uint32(&sc->rnd_source, status);
+#endif
+
 	return (claimed);
 }
 

	The version for -current:

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	12 Sep 2005 19:50:31 -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     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	12 Sep 2005 19:50:37 -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->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->rnd_source))
+		rnd_add_uint32(&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.

>Unformatted: