Browse Source

Protection mechanism against MAC spoofing (#512)

* Implement MAC spoofing protection mechanism

* Update edge_utils.c

* Fix compile errors

* Update edge_utils.c

* Update edge_utils.c

* Update edge_utils.c
pull/526/head
Francesco Carli 4 years ago
committed by GitHub
parent
commit
bde819700d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      src/edge_utils.c

42
src/edge_utils.c

@ -393,6 +393,20 @@ static void register_with_local_peers(n2n_edge_t * eee) {
#endif
}
/* ************************************** */
static struct peer_info* find_peer_by_sock(const n2n_sock_t *sock, struct peer_info *peer_list){
struct peer_info *scan, *tmp, *ret = NULL;
HASH_ITER(hh, peer_list, scan, tmp){
if(memcmp(&(scan->sock), sock, sizeof(n2n_sock_t)) == 0){
ret = scan;
break;
}
}
return ret;
}
/* ************************************** */
/** Start the registration process.
@ -503,6 +517,17 @@ static void check_peer_registration_needed(n2n_edge_t *eee,
HASH_FIND_PEER(eee->known_peers, mac, scan);
/* If we were not able to find it by MAC, we try to find it by socket. */
if(scan == NULL ){
scan = find_peer_by_sock(peer, eee->known_peers);
if(scan){
HASH_DEL(eee->known_peers, scan);
memcpy(scan->mac_addr, mac, sizeof(n2n_mac_t));
HASH_ADD_PEER(eee->known_peers, scan);
}
}
if (scan == NULL) {
/* Not in known_peers - start the REGISTER process. */
register_with_new_peer(eee, from_supernode, mac, dev_addr, dev_desc, peer);
@ -530,19 +555,28 @@ static void peer_set_p2p_confirmed(n2n_edge_t * eee,
const n2n_mac_t mac,
const n2n_sock_t * peer,
time_t now) {
struct peer_info *scan;
struct peer_info *scan, *scan_tmp;
macstr_t mac_buf;
n2n_sock_str_t sockbuf;
HASH_FIND_PEER(eee->pending_peers, mac, scan);
if(scan == NULL){
scan = find_peer_by_sock(peer, eee->pending_peers);
}
if(scan) {
HASH_DEL(eee->pending_peers, scan);
/* Add scan to known_peers. */
HASH_ADD_PEER(eee->known_peers, scan);
scan_tmp = find_peer_by_sock(peer, eee->known_peers);
if(scan_tmp != NULL){
HASH_DEL(eee->known_peers, scan_tmp);
scan = scan_tmp;
memcpy(scan->mac_addr, mac, sizeof(n2n_mac_t));
} else {
scan->sock = *peer;
}
HASH_ADD_PEER(eee->known_peers, scan);
scan->last_p2p = now;
traceEvent(TRACE_DEBUG, "P2P connection established: %s [%s]",

Loading…
Cancel
Save