33#include <sys/endian.h>
34#include <sys/kernel.h>
38#include <sys/socket.h>
39#include <sys/sysproto.h>
46#include <net/if_types.h>
71 uint16_t
node[UUID_NODE_LEN>>1];
78#define UUID_ETHER_EMPTY 0
79#define UUID_ETHER_RANDOM 1
80#define UUID_ETHER_UNIQUE 2
81 uint16_t
node[UUID_NODE_LEN>>1];
104 for (i = 0; i < (UUID_NODE_LEN>>1); i++)
105 uuid_ether[0].node[i] = (uint16_t)arc4random();
109 for (i = 0; i < (UUID_NODE_LEN>>1); i++)
123 uint64_t time = 0x01B21DD213814000LL;
126 time += (uint64_t)
bt.sec * 10000000LL;
127 time += (10000000LL * (uint32_t)(
bt.frac >> 32)) >> 32;
128 return (time & ((1LL << 60) - 1LL));
146 uuid.
seq = (uint16_t)arc4random() & 0x3fff;
158 uuid.
seq = htobe16(uuid.
seq | 0x8000);
160 for (n = 0; n <
count; n++) {
164 uuid.
time.
x.
hi = ((uint16_t)(
time >> 48) & 0xfff) | (1 << 12);
165 store[n] = *(
struct uuid *)&uuid;
172#ifndef _SYS_SYSPROTO_H_
195 store =
malloc(
count *
sizeof(
struct uuid), M_TEMP, M_WAITOK);
197 error = copyout(store, uap->
store,
count *
sizeof(
struct uuid));
214 for (i = 0; i < UUID_NODE_LEN; i++)
279 cnt =
snprintf(
buf, sz,
"%08x-%04x-%04x-%04x-%04x%04x%04x",
281 be16toh(id->
node[0]), be16toh(id->
node[1]), be16toh(id->
node[2]));
327 le32enc(p, uuid->time_low);
328 le16enc(p + 4, uuid->time_mid);
329 le16enc(p + 6, uuid->time_hi_and_version);
330 p[8] = uuid->clock_seq_hi_and_reserved;
331 p[9] = uuid->clock_seq_low;
332 for (i = 0; i < _UUID_NODE_LEN; i++)
333 p[10 + i] = uuid->node[i];
343 uuid->time_low = le32dec(p);
344 uuid->time_mid = le16dec(p + 4);
345 uuid->time_hi_and_version = le16dec(p + 6);
346 uuid->clock_seq_hi_and_reserved = p[8];
347 uuid->clock_seq_low = p[9];
348 for (i = 0; i < _UUID_NODE_LEN; i++)
349 uuid->node[i] = p[10 + i];
359 be32enc(p, uuid->time_low);
360 be16enc(p + 4, uuid->time_mid);
361 be16enc(p + 6, uuid->time_hi_and_version);
362 p[8] = uuid->clock_seq_hi_and_reserved;
363 p[9] = uuid->clock_seq_low;
364 for (i = 0; i < _UUID_NODE_LEN; i++)
365 p[10 + i] = uuid->node[i];
375 uuid->time_low = be32dec(p);
376 uuid->time_mid = be16dec(p + 4);
377 uuid->time_hi_and_version = be16dec(p + 6);
378 uuid->clock_seq_hi_and_reserved = p[8];
379 uuid->clock_seq_low = p[9];
380 for (i = 0; i < _UUID_NODE_LEN; i++)
381 uuid->node[i] = p[10 + i];
390 if (size == 0 || *str ==
'\0') {
392 if ((
flags & VUUIDF_EMPTYOK) != 0) {
394 bzero(uuid,
sizeof(*uuid));
415 n =
sscanf(str,
"%8x-%4x-%4x-%2x%2x-%2x%2x%2x%2x%2x%2x", c + 0, c + 1,
416 c + 2, c + 3, c + 4, c + 5, c + 6, c + 7, c + 8, c + 9, c + 10);
423 uuid->time_low = c[0];
424 uuid->time_mid = c[1];
425 uuid->time_hi_and_version = c[2];
426 uuid->clock_seq_hi_and_reserved = c[3];
427 uuid->clock_seq_low = c[4];
428 for (n = 0; n < 6; n++)
429 uuid->node[n] = c[n + 5];
432 if ((
flags & VUUIDF_CHECKSEMANTICS) == 0)
435 return (((c[3] & 0x80) != 0x00 &&
436 (c[3] & 0xc0) != 0x80 &&
437 (c[3] & 0xe0) != 0xc0) ? EINVAL : 0);
440#define VUUIDF_PARSEFLAGS (VUUIDF_EMPTYOK | VUUIDF_CHECKSEMANTICS)
450uuidcmp(
const struct uuid *uuid1,
const struct uuid *uuid2)
453 return (memcmp(uuid1, uuid2,
sizeof(
struct uuid)));
static struct bt_table bt
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
void bintime(struct bintime *bt)
int printf_uuid(struct uuid *uuid)
int sbuf_printf_uuid(struct sbuf *sb, struct uuid *uuid)
void le_uuid_enc(void *buf, struct uuid const *uuid)
int uuidcmp(const struct uuid *uuid1, const struct uuid *uuid2)
int validate_uuid(const char *str, size_t size, struct uuid *uuid, int flags)
CTASSERT(sizeof(struct uuid)==16)
MTX_SYSINIT(uuid_lock, &uuid_mutex, "UUID generator mutex lock", MTX_DEF)
struct uuid * kern_uuidgen(struct uuid *store, size_t count)
#define VUUIDF_PARSEFLAGS
int parse_uuid(const char *str, struct uuid *uuid)
int uuid_ether_add(const uint8_t *addr)
static struct uuid_private uuid_last
void be_uuid_enc(void *buf, struct uuid const *uuid)
int snprintf_uuid(char *buf, size_t sz, struct uuid *uuid)
#define UUID_ETHER_UNIQUE
int uuid_ether_del(const uint8_t *addr)
#define UUID_ETHER_RANDOM
int sys_uuidgen(struct thread *td, struct uuidgen_args *uap)
static struct uuid_macaddr uuid_ether[UUID_NETHER]
static struct mtx uuid_mutex
void be_uuid_dec(void const *buf, struct uuid *uuid)
static void uuid_node(uint16_t *node)
static uint64_t uuid_time(void)
void le_uuid_dec(void const *buf, struct uuid *uuid)
uint16_t node[UUID_NODE_LEN > >1]
union uuid_private::@5 time
struct uuid_private::@5::@6 x
uint16_t node[UUID_NODE_LEN > >1]
int printf(const char *fmt,...)
int snprintf(char *str, size_t size, const char *format,...)
int sbuf_cat(struct sbuf *s, const char *str)
int sscanf(const char *ibuf, const char *fmt,...)