Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet remove now unused pseudo-random ip id code.



details:   https://anonhg.NetBSD.org/src/rev/dae8639642d2
branches:  trunk
changeset: 953418:dae8639642d2
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Mar 08 18:03:25 2021 +0000

description:
remove now unused pseudo-random ip id code.

diffstat:

 sys/netinet/files.netinet |    3 +-
 sys/netinet/in_var.h      |   10 +--
 sys/netinet/ip_id.c       |  148 ----------------------------------------------
 sys/netinet/ip_input.c    |    6 +-
 4 files changed, 4 insertions(+), 163 deletions(-)

diffs (227 lines):

diff -r aab99a74fab9 -r dae8639642d2 sys/netinet/files.netinet
--- a/sys/netinet/files.netinet Mon Mar 08 17:54:43 2021 +0000
+++ b/sys/netinet/files.netinet Mon Mar 08 18:03:25 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.netinet,v 1.28 2017/07/29 05:48:16 maxv Exp $
+#      $NetBSD: files.netinet,v 1.29 2021/03/08 18:03:25 christos Exp $
 
 defflag opt_tcp_debug.h                TCP_DEBUG
 defparam opt_tcp_debug.h       TCP_NDEBUG
@@ -34,7 +34,6 @@
 file   netinet/in_selsrc.c     inet & ipselsrc
 file   netinet/ip_flow.c       inet & gateway
 file   netinet/ip_icmp.c       inet
-file   netinet/ip_id.c         inet
 file   netinet/ip_input.c      inet
 file   netinet/ip_mroute.c     inet & mrouting
 file   netinet/ip_output.c     inet
diff -r aab99a74fab9 -r dae8639642d2 sys/netinet/in_var.h
--- a/sys/netinet/in_var.h      Mon Mar 08 17:54:43 2021 +0000
+++ b/sys/netinet/in_var.h      Mon Mar 08 18:03:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_var.h,v 1.99 2021/03/08 17:54:23 christos Exp $     */
+/*     $NetBSD: in_var.h,v 1.100 2021/03/08 18:03:25 christos Exp $    */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -447,14 +447,6 @@
 void   in_addrhash_remove(struct in_ifaddr *);
 int    ipflow_fastforward(struct mbuf *);
 
-struct ipid_state;
-typedef struct ipid_state ipid_state_t;
-
-ipid_state_t * ip_id_init(void);
-void           ip_id_fini(ipid_state_t *);
-uint16_t       ip_randomid(ipid_state_t *, uint16_t);
-
-extern ipid_state_t *  ip_ids;
 extern uint16_t                ip_id;
 extern int             ip_do_randomid;
 
diff -r aab99a74fab9 -r dae8639642d2 sys/netinet/ip_id.c
--- a/sys/netinet/ip_id.c       Mon Mar 08 17:54:43 2021 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*     $NetBSD: ip_id.c,v 1.16 2019/10/18 04:09:02 msaitoh Exp $       */
-
-/*-
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by the 3am Software Foundry ("3am").  It was developed by Matt Thomas.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_id.c,v 1.16 2019/10/18 04:09:02 msaitoh Exp $");
-
-#include <sys/param.h>
-#include <sys/kmem.h>
-#include <sys/mutex.h>
-#include <sys/cprng.h>
-
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/in_var.h>
-
-#include <lib/libkern/libkern.h>
-
-#define        IPID_MAXID      65535
-#define        IPID_NUMIDS     32768
-
-struct ipid_state {
-       kmutex_t        ids_lock;
-       uint16_t        ids_start_slot;
-       uint16_t        ids_slots[IPID_MAXID];
-};
-
-static inline uint32_t
-ipid_random(void)
-{
-       return cprng_fast32();
-}
-
-/*
- * Initializes the  
- * the msb flag. The msb flag is used to generate two distinct
- * cycles of random numbers and thus avoiding reuse of ids.
- *
- * This function is called from id_randomid() when needed, an
- * application does not have to worry about it.
- */
-ipid_state_t *
-ip_id_init(void)
-{
-       ipid_state_t *ids;
-       size_t i;
-
-       ids = kmem_alloc(sizeof(ipid_state_t), KM_SLEEP);
-       mutex_init(&ids->ids_lock, MUTEX_DEFAULT, IPL_SOFTNET);
-
-       ids->ids_start_slot = ipid_random();
-       for (i = 0; i < __arraycount(ids->ids_slots); i++) {
-               ids->ids_slots[i] = i;
-       }
-
-       /*
-        * Shuffle the array.
-        */
-       for (i = __arraycount(ids->ids_slots); --i > 0;) {
-               size_t k = ipid_random() % (i + 1);
-               uint16_t t = ids->ids_slots[i];
-               ids->ids_slots[i] = ids->ids_slots[k];
-               ids->ids_slots[k] = t;
-       }
-       return ids;
-}
-
-void
-ip_id_fini(ipid_state_t *ids)
-{
-
-       mutex_destroy(&ids->ids_lock);
-       kmem_free(ids, sizeof(ipid_state_t));
-}
-
-uint16_t
-ip_randomid(ipid_state_t *ids, uint16_t salt)
-{
-       uint32_t r, k, id;
-
-       /* A random number. */
-       r = ipid_random();
-
-       /*
-        * We do a modified Fisher-Yates shuffle but only one position at a
-        * time. Instead of the last entry, we swap with the first entry and
-        * then advance the start of the window by 1.  The next time that 
-        * swapped-out entry can be used is at least 32768 iterations in the
-        * future.
-        *
-        * The easiest way to visual this is to imagine a card deck with 52
-        * cards.  First thing we do is split that into two sets, each with
-        * half of the cards; call them deck A and deck B.  Pick a card
-        * randomly from deck A and remember it, then place it at the
-        * bottom of deck B.  Then take the top card from deck B and add it
-        * to deck A.  Pick another card randomly from deck A and ...
-        */
-       mutex_enter(&ids->ids_lock);
-       k = (r & (IPID_NUMIDS - 1)) + ids->ids_start_slot;
-       if (k >= IPID_MAXID) {
-               k -= IPID_MAXID;
-       }
-       id = ids->ids_slots[k];
-       if (k != ids->ids_start_slot) {
-               ids->ids_slots[k] = ids->ids_slots[ids->ids_start_slot];
-               ids->ids_slots[ids->ids_start_slot] = id;
-       }
-       if (++ids->ids_start_slot == IPID_MAXID) {
-               ids->ids_start_slot = 0;
-       }
-       mutex_exit(&ids->ids_lock);
-
-       /*
-        * Add an optional salt to the id to further obscure it.
-        */
-       id += salt;
-       if (id >= IPID_MAXID) {
-               id -= IPID_MAXID;
-       }
-       return (uint16_t)htons(id + 1);
-}
diff -r aab99a74fab9 -r dae8639642d2 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c    Mon Mar 08 17:54:43 2021 +0000
+++ b/sys/netinet/ip_input.c    Mon Mar 08 18:03:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_input.c,v 1.400 2021/03/07 14:58:27 christos Exp $  */
+/*     $NetBSD: ip_input.c,v 1.401 2021/03/08 18:03:25 christos Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.400 2021/03/07 14:58:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.401 2021/03/08 18:03:25 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -189,7 +189,6 @@
 
 pktqueue_t *           ip_pktq                 __read_mostly;
 pfil_head_t *          inet_pfil_hook          __read_mostly;
-ipid_state_t *         ip_ids                  __read_mostly;
 percpu_t *             ipstat_percpu           __read_mostly;
 
 static percpu_t                *ipforward_rt_percpu    __cacheline_aligned;
@@ -291,7 +290,6 @@
 
        ip_reass_init();
 
-       ip_ids = ip_id_init();
        ip_id = time_uptime & 0xfffff;
 
 #ifdef GATEWAY



Home | Main Index | Thread Index | Old Index