From d83cd7283c90cc791c70b5c8010c71f4c7144584 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 25 Nov 2012 20:30:14 +0100 Subject: [PATCH] udp6: add an option to set the multicast scope. Signed-off-by: Richard Cochran --- config.c | 5 +++++ config.h | 1 + default.cfg | 1 + ptp4l.c | 2 ++ udp6.c | 4 ++++ udp6.h | 6 ++++++ 6 files changed, 19 insertions(+) diff --git a/config.c b/config.c index 9a9420f..7e31a33 100644 --- a/config.c +++ b/config.c @@ -255,6 +255,11 @@ 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, "udp6_scope")) { + if (1 != sscanf(value, "%hhx", &u8) || (u8 & 0xF0)) + return BAD_VALUE; + *cfg->udp6_scope = u8; + } else if (!strcmp(option, "logging_level")) { if (1 != sscanf(value, "%d", &val) || !(val >= PRINT_LEVEL_MIN && val <= PRINT_LEVEL_MAX)) diff --git a/config.h b/config.h index b1f5fc6..5ceba9d 100644 --- a/config.h +++ b/config.h @@ -71,6 +71,7 @@ struct config { unsigned char *ptp_dst_mac; unsigned char *p2p_dst_mac; + unsigned char *udp6_scope; int print_level; int use_syslog; diff --git a/default.cfg b/default.cfg index 9b4fa73..9cf6bbf 100644 --- a/default.cfg +++ b/default.cfg @@ -43,6 +43,7 @@ clock_servo pi transportSpecific 0x0 ptp_dst_mac 01:1B:19:00:00:00 p2p_dst_mac 01:80:C2:00:00:0E +udp6_scope 0x0E # # Default interface options # diff --git a/ptp4l.c b/ptp4l.c index 572193f..1c9aad0 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -31,6 +31,7 @@ #include "raw.h" #include "sk.h" #include "transport.h" +#include "udp6.h" #include "util.h" int assume_two_step = 0; @@ -78,6 +79,7 @@ static struct config cfg_settings = { .ptp_dst_mac = ptp_dst_mac, .p2p_dst_mac = p2p_dst_mac, + .udp6_scope = &udp6_scope, .print_level = LOG_INFO, .use_syslog = 1, diff --git a/udp6.c b/udp6.c index d8815c7..9e68574 100644 --- a/udp6.c +++ b/udp6.c @@ -40,6 +40,8 @@ #define PTP_PRIMARY_MCAST_IP6ADDR "FF0E:0:0:0:0:0:0:181" #define PTP_PDELAY_MCAST_IP6ADDR "FF02:0:0:0:0:0:0:6B" +unsigned char udp6_scope = 0x0E; + struct udp6 { struct transport t; int index; @@ -160,6 +162,8 @@ static int udp6_open(struct transport *t, char *name, struct fdarray *fda, if (1 != inet_pton(AF_INET6, PTP_PRIMARY_MCAST_IP6ADDR, &mc6_addr[MC_PRIMARY])) return -1; + mc6_addr[MC_PRIMARY].s6_addr[1] = udp6_scope; + if (1 != inet_pton(AF_INET6, PTP_PDELAY_MCAST_IP6ADDR, &mc6_addr[MC_PDELAY])) return -1; diff --git a/udp6.h b/udp6.h index 8613da5..e451262 100644 --- a/udp6.h +++ b/udp6.h @@ -23,6 +23,12 @@ #include "fd.h" #include "transport.h" +/** + * The desired scope for the multicast messages. This will be used as + * the second byte of the primary IPv6 address. See RFC 4291. + */ +extern unsigned char udp6_scope; + /** * Allocate an instance of a UDP/IPv6 transport. * @return Pointer to a new transport instance on success, NULL otherwise.