udp6: set hop limit with udp_ttl option.
Use the udp_ttl option to configure both IPv4 and IPv6 transports. Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
This commit is contained in:
		
							parent
							
								
									f44178476b
								
							
						
					
					
						commit
						d8bfa0fa69
					
				@ -60,6 +60,7 @@ ntpshm_segment		0
 | 
				
			|||||||
transportSpecific	0x0
 | 
					transportSpecific	0x0
 | 
				
			||||||
ptp_dst_mac		01:1B:19:00:00:00
 | 
					ptp_dst_mac		01:1B:19:00:00:00
 | 
				
			||||||
p2p_dst_mac		01:80:C2:00:00:0E
 | 
					p2p_dst_mac		01:80:C2:00:00:0E
 | 
				
			||||||
 | 
					udp_ttl			1
 | 
				
			||||||
udp6_scope		0x0E
 | 
					udp6_scope		0x0E
 | 
				
			||||||
uds_address		/var/run/ptp4l
 | 
					uds_address		/var/run/ptp4l
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										7
									
								
								ptp4l.8
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								ptp4l.8
									
									
									
									
									
								
							@ -243,6 +243,13 @@ devices" that are not synchronized to each other. For this mode, the
 | 
				
			|||||||
collection of clocks must be synchronized by an external program, for
 | 
					collection of clocks must be synchronized by an external program, for
 | 
				
			||||||
example phc2sys(8) in "automatic" mode.
 | 
					example phc2sys(8) in "automatic" mode.
 | 
				
			||||||
The default is 0 (disabled).
 | 
					The default is 0 (disabled).
 | 
				
			||||||
 | 
					.TP
 | 
				
			||||||
 | 
					.B udp_ttl
 | 
				
			||||||
 | 
					Specifies the Time to live (TTL) value for IPv4 multicast messages and the hop
 | 
				
			||||||
 | 
					limit for IPv6 multicast messages. This option is only relevant with the IPv4
 | 
				
			||||||
 | 
					and IPv6 UDP transports. The default is 1 to restrict the messages sent by
 | 
				
			||||||
 | 
					.B ptp4l
 | 
				
			||||||
 | 
					to the same subnet.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.SH PROGRAM AND CLOCK OPTIONS
 | 
					.SH PROGRAM AND CLOCK OPTIONS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								udp6.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								udp6.c
									
									
									
									
									
								
							@ -99,7 +99,7 @@ static int udp6_close(struct transport *t, struct fdarray *fda)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int open_socket_ipv6(const char *name, struct in6_addr mc_addr[2], short port,
 | 
					static int open_socket_ipv6(const char *name, struct in6_addr mc_addr[2], short port,
 | 
				
			||||||
			    int *interface_index)
 | 
								    int *interface_index, int hop_limit)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct sockaddr_in6 addr;
 | 
						struct sockaddr_in6 addr;
 | 
				
			||||||
	int fd, index, on = 1;
 | 
						int fd, index, on = 1;
 | 
				
			||||||
@ -132,6 +132,11 @@ static int open_socket_ipv6(const char *name, struct in6_addr mc_addr[2], short
 | 
				
			|||||||
		pr_err("setsockopt SO_BINDTODEVICE failed: %m");
 | 
							pr_err("setsockopt SO_BINDTODEVICE failed: %m");
 | 
				
			||||||
		goto no_option;
 | 
							goto no_option;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hop_limit,
 | 
				
			||||||
 | 
							       sizeof(hop_limit))) {
 | 
				
			||||||
 | 
							pr_err("setsockopt IPV6_MULTICAST_HOPS failed: %m");
 | 
				
			||||||
 | 
							goto no_option;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	addr.sin6_addr = mc_addr[0];
 | 
						addr.sin6_addr = mc_addr[0];
 | 
				
			||||||
	if (mc_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
 | 
						if (mc_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
 | 
				
			||||||
		pr_err("mcast_join failed");
 | 
							pr_err("mcast_join failed");
 | 
				
			||||||
@ -160,8 +165,9 @@ static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
 | 
				
			|||||||
		    enum timestamp_type ts_type)
 | 
							    enum timestamp_type ts_type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct udp6 *udp6 = container_of(t, struct udp6, t);
 | 
						struct udp6 *udp6 = container_of(t, struct udp6, t);
 | 
				
			||||||
	int efd, gfd;
 | 
						int efd, gfd, hop_limit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						hop_limit = config_get_int(t->cfg, name, "udp_ttl");
 | 
				
			||||||
	udp6->mac.len = 0;
 | 
						udp6->mac.len = 0;
 | 
				
			||||||
	sk_interface_macaddr(name, &udp6->mac);
 | 
						sk_interface_macaddr(name, &udp6->mac);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -176,11 +182,11 @@ static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
 | 
				
			|||||||
	if (1 != inet_pton(AF_INET6, PTP_PDELAY_MCAST_IP6ADDR, &mc6_addr[MC_PDELAY]))
 | 
						if (1 != inet_pton(AF_INET6, PTP_PDELAY_MCAST_IP6ADDR, &mc6_addr[MC_PDELAY]))
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	efd = open_socket_ipv6(name, mc6_addr, EVENT_PORT, &udp6->index);
 | 
						efd = open_socket_ipv6(name, mc6_addr, EVENT_PORT, &udp6->index, hop_limit);
 | 
				
			||||||
	if (efd < 0)
 | 
						if (efd < 0)
 | 
				
			||||||
		goto no_event;
 | 
							goto no_event;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gfd = open_socket_ipv6(name, mc6_addr, GENERAL_PORT, &udp6->index);
 | 
						gfd = open_socket_ipv6(name, mc6_addr, GENERAL_PORT, &udp6->index, hop_limit);
 | 
				
			||||||
	if (gfd < 0)
 | 
						if (gfd < 0)
 | 
				
			||||||
		goto no_general;
 | 
							goto no_general;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user