summaryrefslogtreecommitdiffstats
path: root/src/ogAdmServer.c
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2020-07-03 12:42:00 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-07-03 14:11:35 +0200
commit06af0c26f4c46088d8a6f97877f865527bcbc409 (patch)
treef4ba170d0be8a1192a4f23d8c85a5c103e1b2885 /src/ogAdmServer.c
parentd6789f1384eb515f7bbe0d25762ffb82567eec38 (diff)
#990 Use client broadcast address on WoL
Some universities have computers in a different subnet where the ogServer is, but ogServer WoL functionality only supported to send packet to its own subnets. This commit solves this. Now ogServer sends two WoL packets per client, one with the broadcast address of the interface indicated in the config file, the other with the broadcast address calculated with the address and netmask of the client. To ensure that the second WoL works correctly you must configure correctly the IP and netmask of the clients. Also, you have to configure the network of your organization to route WoL packet to the correct subnet.
Diffstat (limited to 'src/ogAdmServer.c')
-rw-r--r--src/ogAdmServer.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/ogAdmServer.c b/src/ogAdmServer.c
index b0eb86a..f063eb1 100644
--- a/src/ogAdmServer.c
+++ b/src/ogAdmServer.c
@@ -447,7 +447,8 @@ int checkDato(struct og_dbi *dbi, char *dato, const char *tabla,
// false: En caso de ocurrir algún error
// ________________________________________________________________________________________________________
-bool Levanta(char *ptrIP[], char *ptrMacs[], int lon, char *mar)
+bool Levanta(char *ptrIP[], char *ptrMacs[], char *ptrNetmasks[], int lon,
+ char *mar)
{
unsigned int on = 1;
struct sockaddr_in local;
@@ -472,7 +473,7 @@ bool Levanta(char *ptrIP[], char *ptrMacs[], int lon, char *mar)
local.sin_addr.s_addr = htonl(INADDR_ANY);
for (i = 0; i < lon; i++) {
- if (!WakeUp(s, ptrIP[i], ptrMacs[i], mar)) {
+ if (!WakeUp(s, ptrIP[i], ptrMacs[i], ptrNetmasks[i], mar)) {
syslog(LOG_ERR, "problem sending magic packet\n");
close(s);
return false;
@@ -566,16 +567,28 @@ enum wol_delivery_type {
// false: En caso de ocurrir algún error
//_____________________________________________________________________________________________________________
//
-bool WakeUp(int s, char* iph, char *mac, char *mar)
+bool WakeUp(int s, char* iph, char *mac, char *netmask, char *mar)
{
+ struct in_addr addr, netmask_addr, broadcast_addr ={};
unsigned int macaddr[OG_WOL_MACADDR_LEN];
char HDaddress_bin[OG_WOL_MACADDR_LEN];
struct sockaddr_in WakeUpCliente;
struct wol_msg Trama_WakeUp;
- struct in_addr addr;
bool ret;
int i;
+ if (inet_aton(iph, &addr) < 0) {
+ syslog(LOG_ERR, "bad IP address\n");
+ return false;
+ }
+
+ if (inet_aton(netmask, &netmask_addr) < 0) {
+ syslog(LOG_ERR, "bad netmask address: %s\n", netmask);
+ return false;
+ }
+
+ broadcast_addr.s_addr = addr.s_addr | ~netmask_addr.s_addr;
+
for (i = 0; i < 6; i++) // Primera secuencia de la trama Wake Up (0xFFFFFFFFFFFF)
Trama_WakeUp.secuencia_FF[i] = 0xFF;
@@ -596,13 +609,10 @@ bool WakeUp(int s, char* iph, char *mac, char *mar)
switch (atoi(mar)) {
case OG_WOL_BROADCAST:
ret = wake_up_broadcast(s, &WakeUpCliente, &Trama_WakeUp);
+ ret &= wake_up_unicast(s, &WakeUpCliente, &Trama_WakeUp,
+ &broadcast_addr);
break;
case OG_WOL_UNICAST:
- if (inet_aton(iph, &addr) < 0) {
- syslog(LOG_ERR, "bad IP address for unicast wol\n");
- ret = false;
- break;
- }
ret = wake_up_unicast(s, &WakeUpCliente, &Trama_WakeUp, &addr);
break;
default: