And remove the old version.

Signed-off-by: Barret Rhoden <[email protected]>
---
 kern/drivers/dev/random.c | 22 ----------------------
 kern/include/ns.h         |  1 -
 kern/src/net/devip.c      |  2 +-
 kern/src/net/tcp.c        |  6 +++---
 4 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/kern/drivers/dev/random.c b/kern/drivers/dev/random.c
index bba11d887ed7..c06d2ef632a3 100644
--- a/kern/drivers/dev/random.c
+++ b/kern/drivers/dev/random.c
@@ -207,25 +207,3 @@ struct dev randomdevtab __devtab = {
        .power = devpower,
        .chaninfo = devchaninfo,
 };
-
-/* This is something used by the TCP stack.
- * I have no idea of why these numbers were chosen. */
-static uint32_t randn;
-
-static void seedrand(void)
-{
-       ERRSTACK(2);
-       if (!waserror()) {
-               _randomread((void *)&randn, sizeof(randn));
-               poperror();
-       }
-}
-
-int nrand(int n)
-{
-       if (randn == 0)
-               seedrand();
-       randn = randn * 1103515245 + 12345 + read_tsc();
-       return (randn >> 16) % n;
-}
-
diff --git a/kern/include/ns.h b/kern/include/ns.h
index 3f22c8e835ca..227bbb740385 100644
--- a/kern/include/ns.h
+++ b/kern/include/ns.h
@@ -792,7 +792,6 @@ char *nextelem(char *unused_char_p_t, char *);
 
 struct cname *newcname(char *unused_char_p_t);
 void notkilled(void);
-int nrand(int);
 uint32_t random_read(void *xp, uint32_t n);
 uint32_t urandom_read(void *xp, uint32_t n);
 uint64_t ns2fastticks(uint64_t);
diff --git a/kern/src/net/devip.c b/kern/src/net/devip.c
index 32946f051b52..1c9362ba8da8 100644
--- a/kern/src/net/devip.c
+++ b/kern/src/net/devip.c
@@ -916,7 +916,7 @@ static void setlport(struct conv *c)
                                *pp = 600;
                } else
                        while (*pp < 5000)
-                               *pp = nrand(1 << 15);
+                               urandom_read(pp, sizeof(*pp));
 
                found = 0;
                for (x = 0; x < p->nc; x++) {
diff --git a/kern/src/net/tcp.c b/kern/src/net/tcp.c
index b5306c979042..841919cc2951 100644
--- a/kern/src/net/tcp.c
+++ b/kern/src/net/tcp.c
@@ -1235,7 +1235,7 @@ int ntohtcp4(Tcp * tcph, struct block **bpp)
  */
 void tcpsndsyn(struct conv *s, Tcpctl * tcb)
 {
-       tcb->iss = (nrand(1 << 16) << 16) | nrand(1 << 16);
+       urandom_read(&tcb->iss, sizeof(tcb->iss));
        tcb->rttseq = tcb->iss;
        tcb->snd.wl2 = tcb->iss;
        tcb->snd.una = tcb->iss;
@@ -1508,7 +1508,7 @@ limbo(struct conv *s, uint8_t * source, uint8_t * dest, 
Tcp * seg, int version)
                lp->mss = seg->mss;
                lp->rcvscale = seg->ws;
                lp->irs = seg->seq;
-               lp->iss = (nrand(1 << 16) << 16) | nrand(1 << 16);
+               urandom_read(&lp->iss, sizeof(lp->iss));
        }
 
        if (sndsynack(s->p, lp) < 0) {
@@ -2680,7 +2680,7 @@ void tcpsendka(struct conv *s)
        seg.mss = 0;
        seg.ws = 0;
        if (tcpporthogdefense)
-               seg.seq = tcb->snd.una - (1 << 30) - nrand(1 << 20);
+               urandom_read(&seg.seq, sizeof(seg.seq));
        else
                seg.seq = tcb->snd.una - 1;
        seg.ack = tcb->rcv.nxt;
-- 
2.7.0.rc3.207.g0ac5344

-- 
You received this message because you are subscribed to the Google Groups 
"Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to