Code cleanup

This commit is contained in:
Luca Deri 2018-06-08 08:19:06 +02:00
parent 27c10a1fb8
commit b00f329a31
4 changed files with 56 additions and 70 deletions

View File

@ -45,7 +45,7 @@ MAN8DIR=$(MANDIR)/man8
N2N_LIB=n2n.a N2N_LIB=n2n.a
N2N_OBJS=n2n.o n2n_keyfile.o wire.o minilzo.o twofish.o \ N2N_OBJS=n2n.o n2n_keyfile.o wire.o minilzo.o twofish.o \
egde_utils.o \ edge_utils.o \
transform_null.o transform_tf.o transform_aes.o \ transform_null.o transform_tf.o transform_aes.o \
tuntap_freebsd.o tuntap_netbsd.o tuntap_linux.o \ tuntap_freebsd.o tuntap_netbsd.o tuntap_linux.o \
tuntap_osx.o version.o tuntap_osx.o version.o
@ -60,6 +60,7 @@ endif
APPS=edge APPS=edge
APPS+=supernode APPS+=supernode
APPS+=example_edge_embed
DOCS=edge.8.gz supernode.1.gz n2n_v2.7.gz DOCS=edge.8.gz supernode.1.gz n2n_v2.7.gz
@ -77,6 +78,9 @@ supernode: sn.c $(N2N_LIB) n2n.h Makefile
benchmark: benchmark.c $(N2N_LIB) n2n_wire.h n2n.h Makefile benchmark: benchmark.c $(N2N_LIB) n2n_wire.h n2n.h Makefile
$(CC) $(CFLAGS) benchmark.c $(N2N_LIB) $(LIBS_SN) -o benchmark $(CC) $(CFLAGS) benchmark.c $(N2N_LIB) $(LIBS_SN) -o benchmark
example_edge_embed: example_edge_embed.c $(N2N_LIB) n2n.h
$(CC) $(CFLAGS) example_edge_embed.c $(N2N_LIB) $(LIBS_EDGE) -o example_edge_embed
.c.o: n2n.h n2n_keyfile.h n2n_transforms.h n2n_wire.h twofish.h Makefile .c.o: n2n.h n2n_keyfile.h n2n_transforms.h n2n_wire.h twofish.h Makefile
$(CC) $(CFLAGS) -c $< $(CC) $(CFLAGS) -c $<

65
edge.c
View File

@ -222,57 +222,6 @@ static void help() {
/* ************************************** */ /* ************************************** */
/** Start the registration process.
*
* If the peer is already in pending_peers, ignore the request.
* If not in pending_peers, add it and send a REGISTER.
*
* If hdr is for a direct peer-to-peer packet, try to register back to sender
* even if the MAC is in pending_peers. This is because an incident direct
* packet indicates that peer-to-peer exchange should work so more aggressive
* registration can be permitted (once per incoming packet) as this should only
* last for a small number of packets..
*
* Called from the main loop when Rx a packet for our device mac.
*/
void try_send_register(n2n_edge_t * eee,
uint8_t from_supernode,
const n2n_mac_t mac,
const n2n_sock_t * peer)
{
/* REVISIT: purge of pending_peers not yet done. */
struct peer_info * scan = find_peer_by_mac(eee->pending_peers, mac);
macstr_t mac_buf;
n2n_sock_str_t sockbuf;
if(NULL == scan)
{
scan = calloc(1, sizeof(struct peer_info));
memcpy(scan->mac_addr, mac, N2N_MAC_SIZE);
scan->sock = *peer;
scan->last_seen = time(NULL); /* Don't change this it marks the pending peer for removal. */
peer_list_add(&(eee->pending_peers), scan);
traceEvent(TRACE_DEBUG, "=== new pending %s -> %s",
macaddr_str(mac_buf, scan->mac_addr),
sock_to_cstr(sockbuf, &(scan->sock)));
traceEvent(TRACE_INFO, "Pending peers list size=%u",
(unsigned int)peer_list_size(eee->pending_peers));
/* trace Sending REGISTER */
send_register(eee, &(scan->sock));
/* pending_peers now owns scan. */
} else {
}
}
/* ************************************** */
#if defined(DUMMY_ID_00001) /* Disabled waiting for config option to enable it */ #if defined(DUMMY_ID_00001) /* Disabled waiting for config option to enable it */
static char gratuitous_arp[] = { static char gratuitous_arp[] = {
@ -799,17 +748,3 @@ int main(int argc, char* argv[]) {
} }
/* ************************************** */ /* ************************************** */
#ifdef QUICK_INIT
int main(int argc, char* argv[]) {
traceLevel = 10;
return(quick_edge_init("n2n0",
"mynetwork",
"ntop2018",
"DE:AD:BE:EF:01:10",
"192.168.254.10",
"192.12.193.11:7654"));
}
#endif

View File

@ -151,6 +151,57 @@ void supernode2addr(n2n_sock_t * sn, const n2n_sn_name_t addrIn) {
/* ************************************** */ /* ************************************** */
/** Start the registration process.
*
* If the peer is already in pending_peers, ignore the request.
* If not in pending_peers, add it and send a REGISTER.
*
* If hdr is for a direct peer-to-peer packet, try to register back to sender
* even if the MAC is in pending_peers. This is because an incident direct
* packet indicates that peer-to-peer exchange should work so more aggressive
* registration can be permitted (once per incoming packet) as this should only
* last for a small number of packets..
*
* Called from the main loop when Rx a packet for our device mac.
*/
static void try_send_register(n2n_edge_t * eee,
uint8_t from_supernode,
const n2n_mac_t mac,
const n2n_sock_t * peer)
{
/* REVISIT: purge of pending_peers not yet done. */
struct peer_info * scan = find_peer_by_mac(eee->pending_peers, mac);
macstr_t mac_buf;
n2n_sock_str_t sockbuf;
if(NULL == scan)
{
scan = calloc(1, sizeof(struct peer_info));
memcpy(scan->mac_addr, mac, N2N_MAC_SIZE);
scan->sock = *peer;
scan->last_seen = time(NULL); /* Don't change this it marks the pending peer for removal. */
peer_list_add(&(eee->pending_peers), scan);
traceEvent(TRACE_DEBUG, "=== new pending %s -> %s",
macaddr_str(mac_buf, scan->mac_addr),
sock_to_cstr(sockbuf, &(scan->sock)));
traceEvent(TRACE_INFO, "Pending peers list size=%u",
(unsigned int)peer_list_size(eee->pending_peers));
/* trace Sending REGISTER */
send_register(eee, &(scan->sock));
/* pending_peers now owns scan. */
} else {
}
}
/* ************************************** */
/** Update the last_seen time for this peer, or get registered. */ /** Update the last_seen time for this peer, or get registered. */
void check_peer(n2n_edge_t * eee, void check_peer(n2n_edge_t * eee,
uint8_t from_supernode, uint8_t from_supernode,

4
n2n.h
View File

@ -317,10 +317,6 @@ void check_peer(n2n_edge_t * eee,
uint8_t from_supernode, uint8_t from_supernode,
const n2n_mac_t mac, const n2n_mac_t mac,
const n2n_sock_t * peer); const n2n_sock_t * peer);
void try_send_register(n2n_edge_t * eee,
uint8_t from_supernode,
const n2n_mac_t mac,
const n2n_sock_t * peer);
void set_peer_operational(n2n_edge_t * eee, void set_peer_operational(n2n_edge_t * eee,
const n2n_mac_t mac, const n2n_mac_t mac,
const n2n_sock_t * peer); const n2n_sock_t * peer);