Hello,

I'm using ptp4l on a device with 2 ethernet interfaces with ptp support.
We configure one interface to use for synchronzation with udpv4 as
transport protocol which works fine.

Lately I found that if configuring both interfaces to be in the same
IPv4 subnet, synchronization stopped working even if forcing the
interface to use.

I looked through the the code (udp.c) and found the function
mcast_bind() that should force the interface for sending. It uses the
socket option IP_MULTICAST_IF with a structure carrying the interface index.

The same socket option may also be called with the ipv4 address of the
interface. I tried this variant and it works fine.

Attached you can find a patch with my changes.

kind regards,
Matthias


Hottinger Baldwin Messtechnik GmbH, Im Tiefen See 45, 64293 Darmstadt, Germany 
| www.hbm.com

Registered as GmbH (German limited liability corporation) in the commercial 
register at the local court of Darmstadt, HRB 1147
Company domiciled in Darmstadt | Managing Director: Andreas Huellhorst | 
Chairman of the board: Eoghan O�Lionaird

Als Gesellschaft mit beschraenkter Haftung eingetragen im Handelsregister des 
Amtsgerichts Darmstadt unter HRB 1147
Sitz der Gesellschaft: Darmstadt | Geschaeftsfuehrung: Andreas Huellhorst | 
Aufsichtsratsvorsitzender: Eoghan O�Lionaird

The information in this email is confidential. It is intended solely for the 
addressee. If you are not the intended recipient, please let me know and delete 
this email.

Die in dieser E-Mail enthaltene Information ist vertraulich und lediglich fuer 
den Empfaenger bestimmt. Sollten Sie nicht der eigentliche Empfaenger sein, 
informieren Sie mich bitte kurz und loeschen diese E-Mail.
From d6668b69432fba5916b63965332d5206619939c9 Mon Sep 17 00:00:00 2001
From: Matthias Loy <matthias....@hbm.com>
Date: Wed, 27 Sep 2017 13:23:14 +0200
Subject: [PATCH] make sure to send udpv4 over specific interface

---
 udp.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/udp.c b/udp.c
index 6dabc31..737fb24 100644
--- a/udp.c
+++ b/udp.c
@@ -20,7 +20,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <net/if.h>
-#include <netdb.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -49,6 +48,8 @@ struct udp {
 	struct address mac;
 };
 
+static int udp_protocol_addr(struct transport *t, uint8_t *addr);
+
 static int mcast_bind(int fd, int index)
 {
 	int err;
@@ -243,6 +244,16 @@ static int udp_send(struct transport *t, struct fdarray *fda, int event,
 	if (event == TRANS_ONESTEP)
 		len += 2;
 
+	struct in_addr ifAddr;
+
+	udp_protocol_addr(t, &ifAddr);
+
+	/* make sure to send over this interface */
+	if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &ifAddr, sizeof(ifAddr))) {
+		pr_err("Error setsockopt IP_MULTICAST_IF for interface");
+		return -1;
+	}
+
 	cnt = sendto(fd, buf, len, 0, &addr->sa, sizeof(addr->sin));
 	if (cnt < 1) {
 		pr_err("sendto failed: %m");
-- 
2.7.4

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-users mailing list
Linuxptp-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-users

Reply via email to