Changeset View
Changeset View
Standalone View
Standalone View
head/sys/netinet6/ip6_id.c
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
* Effectively the id is restricted to the lower (bits - 1) bits, thus | * Effectively the id is restricted to the lower (bits - 1) bits, thus | ||||
* yielding two different cycles by toggling the msb on and off. | * yielding two different cycles by toggling the msb on and off. | ||||
* This avoids reuse issues caused by reseeding. | * This avoids reuse issues caused by reseeding. | ||||
*/ | */ | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/random.h> | |||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/libkern.h> | #include <sys/libkern.h> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/route.h> | #include <net/route.h> | ||||
#include <net/vnet.h> | #include <net/vnet.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <netinet/ip6.h> | #include <netinet/ip6.h> | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return randomid(&randomtab_32); | return randomid(&randomtab_32); | ||||
} | } | ||||
u_int32_t | u_int32_t | ||||
ip6_randomflowlabel(void) | ip6_randomflowlabel(void) | ||||
{ | { | ||||
/* | |||||
* It's ok to emit zero flow labels early, before random is available | |||||
* (seeded). RFC 6437: | |||||
* | |||||
* "A Flow Label of zero is used to indicate packets that have not been | |||||
* labeled." | |||||
*/ | |||||
if (__predict_false(!is_random_seeded())) | |||||
return (0); | |||||
return randomid(&randomtab_20) & 0xfffff; | return randomid(&randomtab_20) & 0xfffff; | ||||
} | } |