diff --git a/doc/Authentication.md b/doc/Authentication.md index 43cdc66..397335f 100644 --- a/doc/Authentication.md +++ b/doc/Authentication.md @@ -61,7 +61,7 @@ If a user chooses a new password or needs to be excluded from accessing the comm When using this feature federation-wide, i.e. across several supernodes, please make sure to keep all supernodes' `community.list` files in sync. So, if you delete or change a user one supernode (or add it), you need to do it at all supernodes. There is no built-in sync for the `community.list` files across the federation. External tools such as _Syncthing_ or your very own script-driven scp-based-file-distribution might be of assistance. Also, with every change, you need to restart the supernode or issue the `reload_communites` command to the management port as outlined above. -With a view to the detailed explanations below, your supernode(s) should have a non-default federation name given by the `-F ` command line parameter, e.g. `-F secretFed`. It is used to derive a private key at the supernode side and is only to be shared among supernodes. +With a view to the detailed explanations below, your supernode(s) should have a non-default federation name given by the `-F ` command line parameter, e.g. `-F secretFed`. Alternatively, it can be passed through the environment variable `N2N_FEDERATION`. It is used to derive a private key at the supernode side and is only to be shared among supernodes. #### Edge diff --git a/doc/Federation.md b/doc/Federation.md index aed94ed..70fda0b 100644 --- a/doc/Federation.md +++ b/doc/Federation.md @@ -24,7 +24,7 @@ Optionally, more anchor supernodes of the same federation can be provided to an Supernodes should be able to communicate among each other as regular edges already do. For this purpose, a special community called federation was introduced. Federation provides mechanisms to connect the supernodes of the network, and enhance backup, fail-over and load-sharing, without any visible behavioral change. -The default name for the federation is `*Federation`. Internally, a madnatory special character is prepended to the name: that way, an edge won't be able to provide a regular community with the same name of the federation. Optionally, a user can choose a federation name (same on all supernodes) and provide it via `-F mySecretFed` option to the supernode. +The default name for the federation is `*Federation`. Internally, a madnatory special character is prepended to the name: that way, an edge won't be able to provide a regular community with the same name of the federation. Optionally, a user can choose a federation name (same on all supernodes) and provide it via `-F mySecretFed` option to the supernode. Alternatively, the federation name can be passed through the environment variable `N2N_FEDERATION`. Federated supernodes register to each other using REGISTER_SUPER message type. The answer, REGISTER_SUPER_ACK, contains a payload with informations about other supernodes in the network. diff --git a/src/sn_utils.c b/src/sn_utils.c index b0d1061..98ed69f 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -751,11 +751,14 @@ int sn_init_defaults (n2n_sn_t *sss) { sss->max_auto_ip_net.net_addr = inet_addr(N2N_SN_MAX_AUTO_IP_NET_DEFAULT); sss->max_auto_ip_net.net_addr = ntohl(sss->max_auto_ip_net.net_addr); sss->max_auto_ip_net.net_bitlen = N2N_SN_AUTO_IP_NET_BIT_DEFAULT; - sss->federation = (struct sn_community *)calloc(1, sizeof(struct sn_community)); + sss->federation = (struct sn_community *)calloc(1, sizeof(struct sn_community)); /* Initialize the federation */ if(sss->federation) { - strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE); + if(getenv("N2N_FEDERATION")) + snprintf(sss->federation->community, N2N_COMMUNITY_SIZE - 1 ,"*%s", getenv("N2N_FEDERATION")); + else + strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE); sss->federation->community[N2N_COMMUNITY_SIZE - 1] = '\0'; /* enable the flag for federation */ sss->federation->is_federation = IS_FEDERATION; diff --git a/supernode.1 b/supernode.1 index 5a16c72..18daf15 100644 --- a/supernode.1 +++ b/supernode.1 @@ -30,7 +30,7 @@ An equal sign ('=') should be used between key and value. Example: -p=7777 listen on this fixed local UDP port, defaults to 7654 .TP \fB\-F \fR<\fIfed_name\fR> -name of the supernode's federation, defaults to '*Federation' +name of the supernode's federation, defaults to '*Federation' (see also N2N_FEDERATION in ENVIRONMENT) .TP \fB\-l \fR<\fIhost:port\fR> ip address or name, and port of known supernode @@ -101,6 +101,10 @@ netleo .fi .PP More details on creating the allowed communities file are found in the Communities.md and Authentication.md documentation included with this package. +.SH ENVIRONMENT +.TP +.B N2N_FEDERATION +set the federation name so it is not visible at the command line .SH EXAMPLES .TP .B supernode -p 7654 -v