reinstate a simple version of ip_randomid()

This commit is contained in:
christos 2021-03-08 20:01:54 +00:00
parent 6383459232
commit fd63f5967c
2 changed files with 12 additions and 5 deletions

View File

@ -26,7 +26,7 @@
#ifdef _KERNEL
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: npf_ext_normalize.c,v 1.10 2020/05/30 14:16:56 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: npf_ext_normalize.c,v 1.11 2021/03/08 20:01:54 christos Exp $");
#include <sys/types.h>
#include <sys/module.h>
@ -114,7 +114,7 @@ npf_normalize_ip4(npf_cache_t *npc, npf_normalize_t *np)
if (np->n_random_id) {
uint16_t oid = ip->ip_id, nid;
nid = htons(ip_randomid(ip_ids, 0));
nid = ip_randomid();
cksum = npf_fixup16_cksum(cksum, oid, nid);
ip->ip_id = nid;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_var.h,v 1.100 2021/03/08 18:03:25 christos Exp $ */
/* $NetBSD: in_var.h,v 1.101 2021/03/08 20:01:54 christos Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -450,6 +450,14 @@ int ipflow_fastforward(struct mbuf *);
extern uint16_t ip_id;
extern int ip_do_randomid;
static __inline uint16_t
ip_randomid(void)
{
uint16_t id = (uint16_t)cprng_fast32();
return id ? id : 1;
}
/*
* ip_newid_range: "allocate" num contiguous IP IDs.
*
@ -462,8 +470,7 @@ ip_newid_range(const struct in_ifaddr *ia, u_int num)
if (ip_do_randomid) {
/* XXX ignore num */
id = (uint16_t)cprng_fast32();
return id ? id : 1;
return ip_randomid();
}
/* Never allow an IP ID of 0 (detect wrap). */