Skip to content

Commit

Permalink
udp6: add an option to set the multicast scope.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Nov 25, 2012
1 parent f92f09f commit d83cd72
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
2 changes: 2 additions & 0 deletions ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "raw.h"
#include "sk.h"
#include "transport.h"
#include "udp6.h"
#include "util.h"

int assume_two_step = 0;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions udp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions udp6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d83cd72

Please sign in to comment.