alfred: Handle EPERM on every sendto
PATCH 1/2 alfred: Handle EPERM on every sendto
The announcements are currently only sent by alfred instances in master mode. Slave instances don't announce themself and thus don't detect the broken socket. To also catch such problems, it is useful to handle the detection of EPERM during the send in send_alfred_packet which is always called when a link-local UDP packet is send over the network.
--- send.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
send.c +7 -9
@@ -32,7 +32,6 @@int announce_master (struct globals *globals) { -ssize_t ret;struct alfred_announce_master_v0 announcement;if (globals->netsock <0 )
@@ -42,14 +41,8 @@ int announce_master(struct globals *globals) announcement.header.version =ALFRED_VERSION ; announcement.header.length =htons (0 ); - ret =send_alfred_packet (globals, &in6addr_localmcast, &announcement, -sizeof (announcement)); -if (ret == -EPERM ) { -fprintf (stderr,"Error during announcement\n" ); -netsock_close (globals->netsock); - globals->netsock =-1 ; - } - +send_alfred_packet (globals, &in6addr_localmcast, &announcement, +sizeof (announcement));return 0 ; }
@@ -176,6 +169,11 @@ ssize_t send_alfred_packet(struct globals *globals, const struct in6_addr *dest, ret =sendto (globals->netsock, buf, length,0 , (struct sockaddr *)&dest_addr,sizeof (struct sockaddr_in6 )); +if (ret == -EPERM ) { +fprintf (stderr,"Error during sent\n" ); +netsock_close (globals->netsock); + globals->netsock =-1 ; + }return ret; }
Signature · 1 line
1.9.2
PATCH 2/2 alfred: Check for changed interface properties
The interface may have been recreated or the mac address was changed. In this situations socket has to be recreated to avoid proplems with the link-local IPv6 address and the scope_id (interface id).
These properties are polled and checked every 60 seconds and the appropriate measures are taken when an error/change occurs.
--- alfred.h | 3 +++ server.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
alfred.h +3 -0
@@ -31,6 +31,7 @@#include "packet.h" #define ALFRED_INTERVAL 10 +#define ALFRED_IF_CHECK_INTERVAL 60#define ALFRED_REQUEST_TIMEOUT 10#define ALFRED_SERVER_TIMEOUT 60#define ALFRED_DATA_TIMEOUT 600
@@ -102,6 +103,8 @@ struct globals {int netsock;int unix_sock; +struct timespec if_check; +struct hashtable_t *server_hash;struct hashtable_t *data_hash;struct hashtable_t *transaction_hash;
server.c +65 -0
97 lines not on this page · raw message
Signature · 1 line
1.9.2
Quoted 7 lines
The announcements are currently only sent by alfred instances in master mode. Slave instances don't announce themself and thus don't detect the broken socket. To also catch such problems, it is useful to handle the detection of EPERM during the send in
send_alfred_packetwhich is always called when a link-local UDP packet is send over the network.Signed-off-by Sven Eckelmann <[email protected]>
Sorry, I forgot to reply:
Both patches have been merged:
839cfd5 alfred: Check for changed interface properties fcd4b0a alfred: Handle EPERM on every sendto
Thank you!!
Simon
Quoted 46 lines
--- send.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)send.c +7
-9@@ -32,7 +32,6 @@int announce_master (struct globals *globals) { -ssize_t ret;struct alfred_announce_master_v0 announcement;if (globals->netsock <0 )@@ -42,14 +41,8 @@ int announce_master(struct globals *globals) announcement.header.version =ALFRED_VERSION ; announcement.header.length =htons (0 ); - ret =send_alfred_packet (globals, &in6addr_localmcast, &announcement, -sizeof (announcement)); -if (ret == -EPERM ) { -fprintf (stderr,"Error during announcement\n" ); -netsock_close (globals->netsock); - globals->netsock =-1 ; - } - +send_alfred_packet (globals, &in6addr_localmcast, &announcement, +sizeof (announcement));return 0 ; }@@ -176,6 +169,11 @@ ssize_t send_alfred_packet(struct globals *globals,const struct in6_addr *dest, ret =sendto (globals->netsock, buf, length,0 , (struct sockaddr *)&dest_addr,sizeof (struct sockaddr_in6 )); +if (ret == -EPERM ) { +fprintf (stderr,"Error during sent\n" ); +netsock_close (globals->netsock); + globals->netsock =-1 ; + }return ret;}