mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
added memrnd() (#685)
This commit is contained in:
parent
cfa92d28d8
commit
667b7df083
|
@ -211,6 +211,7 @@ void hexdump (const uint8_t * buf, size_t len);
|
||||||
void print_n2n_version ();
|
void print_n2n_version ();
|
||||||
int is_empty_ip_address (const n2n_sock_t * sock);
|
int is_empty_ip_address (const n2n_sock_t * sock);
|
||||||
void print_edge_stats (const n2n_edge_t *eee);
|
void print_edge_stats (const n2n_edge_t *eee);
|
||||||
|
int memrnd (uint8_t *address, size_t len);
|
||||||
|
|
||||||
/* Sockets */
|
/* Sockets */
|
||||||
char* sock_to_cstr (n2n_sock_str_t out,
|
char* sock_to_cstr (n2n_sock_str_t out,
|
||||||
|
|
|
@ -367,9 +367,7 @@ n2n_edge_t* edge_init (const n2n_edge_conf_t *conf, int *rv) {
|
||||||
|
|
||||||
// setup authenitcation scheme
|
// setup authenitcation scheme
|
||||||
eee->conf.auth.scheme = n2n_auth_simple_id;
|
eee->conf.auth.scheme = n2n_auth_simple_id;
|
||||||
for(idx = 0; idx < N2N_AUTH_TOKEN_SIZE; ++idx) {
|
memrnd(eee->conf.auth.token, N2N_AUTH_TOKEN_SIZE);
|
||||||
eee->conf.auth.token[idx] = n2n_rand() % 0xff;
|
|
||||||
}
|
|
||||||
eee->conf.auth.toksize = sizeof(eee->conf.auth.token);
|
eee->conf.auth.toksize = sizeof(eee->conf.auth.token);
|
||||||
|
|
||||||
// first time calling edge_init_sockets needs -1 in the sockets for it does throw an error
|
// first time calling edge_init_sockets needs -1 in the sockets for it does throw an error
|
||||||
|
@ -1059,9 +1057,7 @@ void send_register_super (n2n_edge_t *eee) {
|
||||||
cmn.flags = 0;
|
cmn.flags = 0;
|
||||||
memcpy(cmn.community, eee->conf.community_name, N2N_COMMUNITY_SIZE);
|
memcpy(cmn.community, eee->conf.community_name, N2N_COMMUNITY_SIZE);
|
||||||
|
|
||||||
for(idx = 0; idx < N2N_COOKIE_SIZE; ++idx) {
|
memrnd(eee->curr_sn->last_cookie, N2N_COOKIE_SIZE);
|
||||||
eee->curr_sn->last_cookie[idx] = n2n_rand() % 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(reg.cookie, eee->curr_sn->last_cookie, N2N_COOKIE_SIZE);
|
memcpy(reg.cookie, eee->curr_sn->last_cookie, N2N_COOKIE_SIZE);
|
||||||
reg.dev_addr.net_addr = ntohl(eee->device.ip_addr);
|
reg.dev_addr.net_addr = ntohl(eee->device.ip_addr);
|
||||||
|
|
18
src/n2n.c
18
src/n2n.c
|
@ -610,6 +610,24 @@ int sock_equal (const n2n_sock_t * a,
|
||||||
|
|
||||||
/* *********************************************** */
|
/* *********************************************** */
|
||||||
|
|
||||||
|
// fills a specified memory area with random numbers
|
||||||
|
int memrnd (uint8_t *address, size_t len) {
|
||||||
|
|
||||||
|
for(; len >= 8; len -= 8) {
|
||||||
|
*(uint64_t*)address = n2n_rand();
|
||||||
|
address += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(; len > 0; len--) {
|
||||||
|
*address = n2n_rand();
|
||||||
|
address++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *********************************************** */
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
int gettimeofday (struct timeval *tp, void *tzp) {
|
int gettimeofday (struct timeval *tp, void *tzp) {
|
||||||
|
|
||||||
|
|
|
@ -405,15 +405,11 @@ int sn_init(n2n_sn_t *sss) {
|
||||||
|
|
||||||
/* Random auth token */
|
/* Random auth token */
|
||||||
sss->auth.scheme = n2n_auth_simple_id;
|
sss->auth.scheme = n2n_auth_simple_id;
|
||||||
for(idx = 0; idx < N2N_AUTH_TOKEN_SIZE; ++idx) {
|
memrnd(sss->auth.token, N2N_AUTH_TOKEN_SIZE);
|
||||||
sss->auth.token[idx] = n2n_rand() % 0xff;
|
|
||||||
}
|
|
||||||
sss->auth.toksize = sizeof(sss->auth.token);
|
sss->auth.toksize = sizeof(sss->auth.token);
|
||||||
|
|
||||||
/* Random MAC address */
|
/* Random MAC address */
|
||||||
for(i = 0; i < 6; i++) {
|
memrnd(sss->mac_addr, N2N_MAC_SIZE);
|
||||||
sss->mac_addr[i] = n2n_rand();
|
|
||||||
}
|
|
||||||
sss->mac_addr[0] &= ~0x01; /* Clear multicast bit */
|
sss->mac_addr[0] &= ~0x01; /* Clear multicast bit */
|
||||||
sss->mac_addr[0] |= 0x02; /* Set locally-assigned bit */
|
sss->mac_addr[0] |= 0x02; /* Set locally-assigned bit */
|
||||||
|
|
||||||
|
@ -890,12 +886,10 @@ static int re_register_and_purge_supernodes (n2n_sn_t *sss, struct sn_community
|
||||||
cmn.flags = N2N_FLAGS_FROM_SUPERNODE;
|
cmn.flags = N2N_FLAGS_FROM_SUPERNODE;
|
||||||
memcpy(cmn.community, comm->community, N2N_COMMUNITY_SIZE);
|
memcpy(cmn.community, comm->community, N2N_COMMUNITY_SIZE);
|
||||||
|
|
||||||
for(idx = 0; idx < N2N_COOKIE_SIZE; ++idx) {
|
memrnd(cookie, N2N_COOKIE_SIZE);
|
||||||
cookie[idx] = n2n_rand() % 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(reg.cookie, cookie, N2N_COOKIE_SIZE);
|
memcpy(reg.cookie, cookie, N2N_COOKIE_SIZE);
|
||||||
memcpy(peer->last_cookie, cookie, N2N_COOKIE_SIZE);
|
memcpy(peer->last_cookie, cookie, N2N_COOKIE_SIZE);
|
||||||
|
|
||||||
reg.dev_addr.net_addr = ntohl(peer->dev_addr.net_addr);
|
reg.dev_addr.net_addr = ntohl(peer->dev_addr.net_addr);
|
||||||
reg.dev_addr.net_bitlen = mask2bitlen(ntohl(peer->dev_addr.net_bitlen));
|
reg.dev_addr.net_bitlen = mask2bitlen(ntohl(peer->dev_addr.net_bitlen));
|
||||||
get_local_auth(sss, &(reg.auth));
|
get_local_auth(sss, &(reg.auth));
|
||||||
|
|
|
@ -150,8 +150,7 @@ int tuntap_open (tuntap_dev *device,
|
||||||
// also after the TAP interface UP status has been notified
|
// also after the TAP interface UP status has been notified
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < 6; i++)
|
memrnd(device->mac_addr, N2N_MAC_SIZE);
|
||||||
device->mac_addr[i] = n2n_rand();
|
|
||||||
|
|
||||||
// clear multicast bit
|
// clear multicast bit
|
||||||
device->mac_addr[0] &= ~0x01;
|
device->mac_addr[0] &= ~0x01;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user