From: Shawn Bohrer <[email protected]>

Signed-off-by: Shawn Bohrer <[email protected]>
---
 config.c    | 6 ++++++
 config.h    | 1 +
 default.cfg | 1 +
 ptp4l.8     | 4 ++++
 ptp4l.c     | 2 ++
 udp.c       | 7 +++++++
 udp.h       | 5 +++++
 7 files changed, 26 insertions(+)

diff --git a/config.c b/config.c
index 8cae57f..2c27ac5 100644
--- a/config.c
+++ b/config.c
@@ -387,6 +387,12 @@ static enum parser_result parse_global_setting(const char 
*option,
                for (i = 0; i < MAC_LEN; i++)
                        cfg->p2p_dst_mac[i] = mac[i];
 
+       } else if (!strcmp(option, "udp4_mcast_ttl")) {
+               r = get_ranged_int(value, &val, 1, INT_MAX);
+               if (r != PARSED_OK)
+                       return r;
+               *cfg->udp4_mcast_ttl = val;
+
        } else if (!strcmp(option, "udp6_scope")) {
                r = get_ranged_uint(value, &uval, 0x00, 0x0F);
                if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 94704a4..86231ac 100644
--- a/config.h
+++ b/config.h
@@ -89,6 +89,7 @@ struct config {
        unsigned char *ptp_dst_mac;
        unsigned char *p2p_dst_mac;
        unsigned char *udp6_scope;
+       int *udp4_mcast_ttl;
 
        int print_level;
        int use_syslog;
diff --git a/default.cfg b/default.cfg
index 72665a6..4ecf812 100644
--- a/default.cfg
+++ b/default.cfg
@@ -58,6 +58,7 @@ clock_servo           pi
 transportSpecific      0x0
 ptp_dst_mac            01:1B:19:00:00:00
 p2p_dst_mac            01:80:C2:00:00:0E
+udp4_mcast_ttl         1
 udp6_scope             0x0E
 #
 # Default interface options
diff --git a/ptp4l.8 b/ptp4l.8
index 493626d..9551b19 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -348,6 +348,10 @@ Relevant only with L2 transport. The default is 
01:1B:19:00:00:00.
 The MAC address where should be peer delay messages the PTP peer.
 Relevant only with L2 transport. The default is 01:80:C2:00:00:0E.
 .TP
+.B udp4_mcast_ttl
+Specifies the time-to-live value of outgoing multicast messages.
+This option is only relevant with IPv4 transport.  The default is 1.
+.TP
 .B udp6_scope
 Specifies the desired scope for the IPv6 multicast messages.  This
 will be used as the second byte of the primary address.  This option
diff --git a/ptp4l.c b/ptp4l.c
index b0d1c9c..664914b 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -31,6 +31,7 @@
 #include "raw.h"
 #include "sk.h"
 #include "transport.h"
+#include "udp.h"
 #include "udp6.h"
 #include "util.h"
 #include "version.h"
@@ -111,6 +112,7 @@ static struct config cfg_settings = {
        .ptp_dst_mac = ptp_dst_mac,
        .p2p_dst_mac = p2p_dst_mac,
        .udp6_scope = &udp6_scope,
+       .udp4_mcast_ttl = &udp4_mcast_ttl,
 
        .print_level = LOG_INFO,
        .use_syslog = 1,
diff --git a/udp.c b/udp.c
index be7f2b7..d39f83c 100644
--- a/udp.c
+++ b/udp.c
@@ -41,6 +41,8 @@
 #define PTP_PRIMARY_MCAST_IPADDR "224.0.1.129"
 #define PTP_PDELAY_MCAST_IPADDR  "224.0.0.107"
 
+int udp4_mcast_ttl = 1;
+
 struct udp {
        struct transport t;
        uint8_t ip[4];
@@ -124,6 +126,11 @@ static int open_socket(char *name, struct in_addr 
mc_addr[2], short port)
                pr_err("setsockopt SO_BINDTODEVICE failed: %m");
                goto no_option;
        }
+       if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
+                      &udp4_mcast_ttl, sizeof(udp4_mcast_ttl))) {
+               pr_err("setsockopt IP_MULTICAST_TTL failed: %m");
+               goto no_option;
+       }
        addr.sin_addr = mc_addr[0];
        if (mcast_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
                pr_err("mcast_join failed");
diff --git a/udp.h b/udp.h
index fc0d54d..a95922f 100644
--- a/udp.h
+++ b/udp.h
@@ -24,6 +24,11 @@
 #include "transport.h"
 
 /**
+ * The desired time-to-live value of outgoing multicast messages.
+ */
+extern int udp4_mcast_ttl;
+
+/**
  * Allocate an instance of a UDP/IPv4 transport.
  * @return Pointer to a new transport instance on success, NULL otherwise.
  */
-- 
2.2.1


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to