alfred: Make sure only link-local EUI64 is used as source
PATCH 1/1 alfred: Make sure only link-local EUI64 is used as source
The linux kernel automatically chooses the source address. This can make problems when the metric prefers an address which is not the link-local EUI64 address. For example an user can add an additional address which also can be used for link-local communication but has a higher value in the metric. This can cause alfred to send UDP link-local packets with an address which cannot be decoded by the receiver to get the MAC address of the device. The communication with this device would then fail.
It is possible to define the source address when we directly bind to it. This has the problem that this address cannot receive packets with a multicast address as destination. The workaround is to create two sockets for one netsock structure. One is the socket which can send all data and receives unicast packets. The second one is receiving the multicast traffic like the announcements from master alfred server processes.
--- alfred.h | 4 ++- netsock.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- recv.c | 5 +-- send.c | 2 ++ server.c | 2 ++ 5 files changed, 103 insertions(+), 16 deletions(-)
alfred.h +3 -1
@@ -102,6 +102,7 @@ struct interface {uint32_t scope_id;char *interface;int netsock; +int netsock_mcast;struct hashtable_t *server_hash;
@@ -151,7 +152,8 @@ int alfred_client_set_data(struct globals *globals);int alfred_client_modeswitch (struct globals *globals);int alfred_client_change_interface (struct globals *globals);/* recv.c */ -int recv_alfred_packet (struct globals *globals,struct interface *interface); +int recv_alfred_packet (struct globals *globals,struct interface *interface, +int recv_sock);struct transaction_head *transaction_add (struct globals *globals,struct ether_addr mac,uint16_t id); struct transaction_head *
netsock.c +93 -13
188 lines not on this page · raw message
recv.c +3 -2
@@ -379,7 +379,8 @@ static int process_alfred_status_txend(struct globals *globals,return 0 ; } -int recv_alfred_packet (struct globals *globals,struct interface *interface) +int recv_alfred_packet (struct globals *globals,struct interface *interface, +int recv_sock) {uint8_t buf[MAX_PAYLOAD ];ssize_t length;
@@ -391,7 +392,7 @@ int recv_alfred_packet(struct globals *globals, struct interface *interface)return -1 ; sourcelen =sizeof (source); - length =recvfrom (interface->netsock, buf,sizeof (buf),0 , + length =recvfrom (recv_sock, buf,sizeof (buf),0 , (struct sockaddr *)&source, &sourcelen);if (length <=0 ) {perror ("read from network socket failed" );
send.c +2 -0
@@ -182,7 +182,9 @@ ssize_t send_alfred_packet(struct interface *interface,if (ret == -EPERM ) {perror ("Error during sent" );close (interface->netsock); +close (interface->netsock_mcast); interface->netsock =-1 ; + interface->netsock_mcast =-1 ; }return ret;
server.c +2 -0
@@ -262,7 +262,9 @@ static void check_if_socket(struct interface *interface) close:close (interface->netsock); +close (interface->netsock_mcast); interface->netsock =-1 ; + interface->netsock_mcast =-1 ;close (sock); }
Signature · 1 line
2.1.4
Quoted 8 lines · On Wednesday 25 March 2015 19:51:07 Sven Eckelmann wrote:
The linux kernel automatically chooses the source address. This can make problems when the metric prefers an address which is not the link-local EUI64 address. For example an user can add an additional address which also can be used for link-local communication but has a higher value in the metric. This can cause alfred to send UDP link-local packets with an address which cannot be decoded by the receiver to get the MAC address of the device. The communication with this device would then fail.
Quoted 8 lines
It is possible to define the source address when we directly bind to it. This has the problem that this address cannot receive packets with a multicast address as destination. The workaround is to create two sockets for one netsock structure. One is the socket which can send all data and receives unicast packets. The second one is receiving the multicast traffic like the announcements from master alfred server processes.
Signed-off-by Sven Eckelmann <[email protected]>
Applied in revision 986ca57, added Moritz Warnings "Tested-by" as per ticket #208 [1].
Thanks a lot!
Simon