Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a number of federation bugs #26

Merged
merged 26 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a8e462e
Remove supernode debug function, the same data is available via the m…
hamishcoleman Apr 27, 2024
5eba41b
Move resolve defines to where they are used.
hamishcoleman Apr 27, 2024
9af71a9
Move another peer_info function into the correct location
hamishcoleman Apr 28, 2024
61a75ae
More peer_info consolidation
hamishcoleman Apr 28, 2024
afa90a3
Make find_peer_time_stamp_and_verify function more genericly usable
hamishcoleman Apr 28, 2024
0607c37
Use same function for both edge and supernode
hamishcoleman Apr 28, 2024
fe65e1d
Avoid using the peer_info_t when not needed
hamishcoleman Apr 28, 2024
721ad65
Address linter concerns
hamishcoleman Apr 28, 2024
40491ce
Address linter concern
hamishcoleman Apr 29, 2024
e92ced9
Continue consolidating peer_info access
hamishcoleman Apr 29, 2024
ca37718
Rename field to better reflect its actual use
hamishcoleman Apr 29, 2024
3523b42
Add a getter for peer hostname
hamishcoleman Apr 29, 2024
080e0f0
Move more peer info defines to the correct place
hamishcoleman Apr 29, 2024
5c02069
Any newly allocated peer_info struct will already have the selection …
hamishcoleman Apr 29, 2024
06a8795
Also rename field in threaded resolver
hamishcoleman Apr 29, 2024
3ffff72
An API to access the MAC routing table
hamishcoleman Apr 30, 2024
057c8b5
Address linter concern
hamishcoleman Apr 30, 2024
daee8ae
Fix last seen datatype
hamishcoleman Apr 30, 2024
0090341
Pretty printer for new API call
hamishcoleman Apr 30, 2024
6747751
Use bool in an appropriate place
hamishcoleman Apr 30, 2024
f18dbf6
Annotate try_broadcast and try_forward better
hamishcoleman Apr 30, 2024
7ad6061
Refactor functions trying to increase readability
hamishcoleman Apr 30, 2024
a9b1afa
Fix bug with updating associations (also refactor for readability)
hamishcoleman Apr 30, 2024
bef79a2
Address lint concerns
hamishcoleman Apr 30, 2024
cf0d6e9
Fix bug with federation registration
hamishcoleman Apr 30, 2024
f3202d0
Note a future TODO
hamishcoleman Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions apps/n3n-edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,11 @@ int main (int argc, char* argv[]) {
sn_selection_sort(&(eee->conf.supernodes));
eee->curr_sn = eee->conf.supernodes;
supernode_connect(eee);
traceEvent(TRACE_NORMAL, "received first PONG from supernode [%s]", eee->curr_sn->ip_addr);
traceEvent(
TRACE_NORMAL,
"received first PONG from supernode [%s]",
eee->curr_sn->hostname
);
runlevel++;
} else if(last_action <= (now - BOOTSTRAP_TIMEOUT)) {
// timeout
Expand Down Expand Up @@ -918,8 +922,11 @@ int main (int argc, char* argv[]) {
eee->sn_wait = 1;
send_register_super(eee);
runlevel++;
traceEvent(TRACE_INFO, "send REGISTER_SUPER to supernode [%s] asking for IP address",
eee->curr_sn->ip_addr);
traceEvent(
TRACE_INFO,
"send REGISTER_SUPER to supernode [%s] asking for IP address",
eee->curr_sn->hostname
);
} else {
runlevel += 2; /* skip waiting for TUNTAP IP address */
traceEvent(TRACE_DEBUG, "skip auto IP address asignment");
Expand Down
42 changes: 2 additions & 40 deletions apps/n3n-supernode.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <n3n/conffile.h> // for n3n_config_set_option
#include <n3n/initfuncs.h> // for n3n_initfuncs()
#include <n3n/logging.h> // for traceEvent
#include <n3n/peer_info.h> // for n3n_peer_add_by_hostname
#include <n3n/supernode.h> // for load_allowed_sn_community, calculate_s...
#include <signal.h> // for signal, SIGHUP, SIGINT, SIGPIPE, SIGTERM
#include <stdbool.h>
Expand All @@ -42,7 +41,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_ADD_STR

// FIXME, including private headers
#include "../src/peer_info.h" // for peer_info, peer_info_init
#include "../src/peer_info.h" // for peer_info

#ifdef _WIN32
#include "../src/win32/defs.h" // FIXME: untangle the include path
Expand Down Expand Up @@ -352,43 +351,6 @@ static void n3n_sn_config (int argc, char **argv, char *defname, struct n3n_runt



/* *************************************************** */

#ifdef __linux__
// TODO: this uses internal peer_info structures, move it to src/ or replace
// it with a mangement api
static void dump_registrations (int signo) {

struct sn_community *comm, *ctmp;
struct peer_info *list, *tmp;
char buf[32];
time_t now = time(NULL);
u_int num = 0;

traceEvent(TRACE_NORMAL, "====================================");

HASH_ITER(hh, sss_node.communities, comm, ctmp) {
traceEvent(TRACE_NORMAL, "dumping community: %s", comm->community);

HASH_ITER(hh, comm->edges, list, tmp) {
if(list->sock.family == AF_INET) {
traceEvent(TRACE_NORMAL, "[id: %u][MAC: %s][edge: %u.%u.%u.%u:%u][last seen: %u sec ago]",
++num, macaddr_str(buf, list->mac_addr),
list->sock.addr.v4[0], list->sock.addr.v4[1], list->sock.addr.v4[2], list->sock.addr.v4[3],
list->sock.port,
now - list->last_seen);
} else {
traceEvent(TRACE_NORMAL, "[id: %u][MAC: %s][edge: IPv6:%u][last seen: %u sec ago]",
++num, macaddr_str(buf, list->mac_addr), list->sock.port,
now - list->last_seen);
}
}
}

traceEvent(TRACE_NORMAL, "====================================");
}
#endif

/* *************************************************** */

static bool keep_running = true;
Expand Down Expand Up @@ -614,6 +576,7 @@ int main (int argc, char * argv[]) {

// Add our freshly opened socket to any edges added by federation
// TODO: this uses internal peer_info struct, move it to sn_utils?
// (It is the last user in this file, so yes, move it)
struct peer_info *scan, *tmp;
HASH_ITER(hh, sss_node.federation->edges, scan, tmp) {
scan->socket_fd = sss_node.sock;
Expand Down Expand Up @@ -652,7 +615,6 @@ int main (int argc, char * argv[]) {
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, term_handler);
signal(SIGINT, term_handler);
signal(SIGHUP, dump_registrations);
#endif
#ifdef _WIN32
SetConsoleCtrlHandler(term_handler, TRUE);
Expand Down
1 change: 0 additions & 1 deletion include/n2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ int quick_edge_init (char *device_name, char *community_name,
int comm_init (struct sn_community *comm, char *cmn);
void sn_init (struct n3n_runtime_data *sss);
void sn_term (struct n3n_runtime_data *sss);
struct peer_info* add_sn_to_list_by_mac_or_sock (struct peer_info **sn_list, n2n_sock_t *sock, const n2n_mac_t mac, int *skip_add);
int assign_one_ip_subnet (struct n3n_runtime_data *sss, struct sn_community *comm);

#endif /* _N2N_H_ */
9 changes: 0 additions & 9 deletions include/n2n_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
#define SORT_COMMUNITIES_INTERVAL 90 /* sec. until supernode sorts communities' hash list again */

#define AF_INVALID 0xff /* to mark a socket invalid by an invalid address family (do not use AF_UNSPEC, it could turn into auto-detect) */
#define N2N_RESOLVE_INTERVAL 300 /* seconds until edge and supernode try to resolve supernode names again */
#define N2N_RESOLVE_CHECK_INTERVAL 30 /* seconds until main loop checking in on changes from resolver thread */

#define ETH_FRAMESIZE 14
#define IP4_SRCOFFSET 12
Expand Down Expand Up @@ -107,10 +105,6 @@

#define DEFAULT_MTU 1290

#define HASH_ADD_PEER(head,add) \
HASH_ADD(hh,head,mac_addr,sizeof(n2n_mac_t),add)
#define HASH_FIND_PEER(head,mac,out) \
HASH_FIND(hh,head,mac,sizeof(n2n_mac_t),out)
#define N2N_EDGE_SN_HOST_SIZE 48
#define N2N_EDGE_SUP_ATTEMPTS 3 /* Number of failed attmpts before moving on to next supernode. */
#define N2N_PATHNAME_MAXLEN 256
Expand All @@ -137,9 +131,6 @@ enum n3n_event_topic {
#define N2N_CLOSE_SOCKET_COUNTER_MAX 15 /* number of times of edge's reconnects to supernode after */
/* which the socket explicitly is closed before reopening */

/* flag used in add_sn_to_list_by_mac_or_sock */
enum skip_add {SN_ADD = 0, SN_ADD_SKIP = 1, SN_ADD_ADDED = 2};

#define N2N_NETMASK_STR_SIZE 16 /* dotted decimal 12 numbers + 3 dots */
#define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/

Expand Down
1 change: 1 addition & 0 deletions include/n2n_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ struct n2n_edge_stats {
uint32_t sn_reg_nak; /* Number of REGISTER_SUPER requests declined. */
uint32_t sn_fwd; /* Number of messages forwarded. */
uint32_t sn_broadcast; /* Number of messages broadcast to a community. */
uint32_t sn_drop;
};

typedef struct n2n_tcp_connection {
Expand Down
23 changes: 23 additions & 0 deletions scripts/n3nctl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ def subcmd_show_edges(rpc, args):
return str_table(rows, columns, args.orderby)


def subcmd_mac(rpc, args):
if args.orderby is None:
args.orderby = "mac"

rows = rpc.get('get_mac')
columns = [
'_type',
'mac',
'dest',
'age',
]

now = int(time.time())
for row in rows:
row["age"] = num2timestr(now - int(row["last_seen"]))

return str_table(rows, columns, args.orderby)


def subcmd_show_help(rpc, args):
result = 'Commands with pretty-printed output:\n\n'
for name, cmd in subcmds.items():
Expand Down Expand Up @@ -262,6 +281,10 @@ subcmds = {
'func': subcmd_show_edges,
'help': 'Show the list of edges/peers',
},
'mac': {
'func': subcmd_mac,
'help': 'Show the mac address routing information',
},
}


Expand Down
9 changes: 7 additions & 2 deletions src/conffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ int n3n_config_set_option (void *conf, char *section, char *option, char *value)
return -1;
}
case n3n_conf_supernode: {
struct peer_info **supernodes = (struct peer_info **)valvoid;
peer_info_t **supernodes = (peer_info_t **)valvoid;
return n3n_peer_add_by_hostname(supernodes, value);
}
case n3n_conf_privatekey: {
Expand Down Expand Up @@ -730,7 +730,12 @@ static void dump_option (FILE *f, void *conf, int level, struct n3n_conf_option
struct peer_info **supernodes = (struct peer_info **)valvoid;
struct peer_info *scan, *tmp;
HASH_ITER(hh, *supernodes, scan, tmp) {
fprintf(f, "%s=%s\n", option->name, scan->ip_addr);
fprintf(
f,
"%s=%s\n",
option->name,
peer_info_get_hostname(scan)
);
}
fprintf(f, "\n");
return;
Expand Down
Loading
Loading