Skip to contentSkip to conversation

alfred: Make sure only link-local EUI64 is used as source

PATCH In review Sven Eckelmann 2 participants 2 messages Mar 25, 2015 – May 5, 2015

lore
Share & tools
lore
#0 lore raw

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
index 621805d..adf788c 100644
@@ -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
index 59c69b4..16242bc 100644
@@ -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
index cc55489..8853970 100644
@@ -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
index c9c77b9..ac253a9 100644
@@ -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
#1 lore raw
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.

Applied in revision 986ca57, added Moritz Warnings "Tested-by" as per ticket #208 [1].

Thanks a lot!
Simon

[1] http://www.open-mesh.org/issues/208