config: convert 'p2p_dst_mac', letting it be a per-port option.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-08-21 22:59:28 +02:00
parent a31f2d0ddf
commit 852c288ebe
7 changed files with 16 additions and 26 deletions

View File

@ -214,6 +214,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX), GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX), GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
PORT_ITEM_STR("ptp_dst_mac", "01:1B:19:00:00:00"), PORT_ITEM_STR("ptp_dst_mac", "01:1B:19:00:00:00"),
PORT_ITEM_STR("p2p_dst_mac", "01:80:C2:00:00:0E"),
GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX), GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX),
GLOB_ITEM_INT("slaveOnly", 0, 0, 1), GLOB_ITEM_INT("slaveOnly", 0, 0, 1),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX), GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
@ -460,7 +461,6 @@ static enum parser_result parse_global_setting(const char *option,
struct config *cfg) struct config *cfg)
{ {
int i; int i;
unsigned char mac[MAC_LEN];
unsigned char oui[OUI_LEN]; unsigned char oui[OUI_LEN];
enum parser_result r; enum parser_result r;
@ -468,14 +468,7 @@ static enum parser_result parse_global_setting(const char *option,
if (r != NOT_PARSED) if (r != NOT_PARSED)
return r; return r;
if (!strcmp(option, "p2p_dst_mac")) { if (!strcmp(option, "uds_address")) {
if (MAC_LEN != sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]))
return BAD_VALUE;
for (i = 0; i < MAC_LEN; i++)
cfg->p2p_dst_mac[i] = mac[i];
} else if (!strcmp(option, "uds_address")) {
if (strlen(value) > MAX_IFNAME_SIZE) if (strlen(value) > MAX_IFNAME_SIZE)
return OUT_OF_RANGE; return OUT_OF_RANGE;
strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE); strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE);

View File

@ -47,7 +47,6 @@ struct config {
/* the rest are legacy fields */ /* the rest are legacy fields */
struct default_ds dds; struct default_ds dds;
unsigned char *p2p_dst_mac;
char *uds_address; char *uds_address;
}; };

View File

@ -23,7 +23,6 @@
#include <stdint.h> #include <stdint.h>
#define MAC_LEN 6 #define MAC_LEN 6
#define P2P_DST_MAC 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E
typedef uint8_t eth_addr[MAC_LEN]; typedef uint8_t eth_addr[MAC_LEN];

View File

@ -189,6 +189,10 @@ The default is E2E.
The MAC address to which PTP messages should be sent. The MAC address to which PTP messages should be sent.
Relevant only with L2 transport. The default is 01:1B:19:00:00:00. Relevant only with L2 transport. The default is 01:1B:19:00:00:00.
.TP .TP
.B p2p_dst_mac
The MAC address to which peer delay messages should be sent.
Relevant only with L2 transport. The default is 01:80:C2:00:00:0E.
.TP
.B network_transport .B network_transport
Select the network transport. Possible values are UDPv4, UDPv6 and L2. Select the network transport. Possible values are UDPv4, UDPv6 and L2.
The default is UDPv4. The default is UDPv4.
@ -416,10 +420,6 @@ disabled. The default is 200000000 (20%).
The number of the SHM segment used by ntpshm servo. The number of the SHM segment used by ntpshm servo.
The default is 0. The default is 0.
.TP .TP
.B p2p_dst_mac
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 udp6_scope .B udp6_scope
Specifies the desired scope for the IPv6 multicast messages. This Specifies the desired scope for the IPv6 multicast messages. This
will be used as the second byte of the primary address. This option will be used as the second byte of the primary address. This option

View File

@ -59,7 +59,6 @@ static struct config cfg_settings = {
}, },
}, },
.p2p_dst_mac = p2p_dst_mac,
.uds_address = uds_path, .uds_address = uds_path,
}; };

15
raw.c
View File

@ -149,9 +149,8 @@ static int raw_close(struct transport *t, struct fdarray *fda)
return 0; return 0;
} }
unsigned char p2p_dst_mac[MAC_LEN] = { P2P_DST_MAC }; static int open_socket(const char *name, int event, unsigned char *ptp_dst_mac,
unsigned char *p2p_dst_mac)
static int open_socket(const char *name, int event, unsigned char *ptp_dst_mac)
{ {
struct sockaddr_ll addr; struct sockaddr_ll addr;
int fd, index; int fd, index;
@ -204,6 +203,7 @@ static int raw_open(struct transport *t, const char *name,
{ {
struct raw *raw = container_of(t, struct raw, t); struct raw *raw = container_of(t, struct raw, t);
unsigned char ptp_dst_mac[MAC_LEN]; unsigned char ptp_dst_mac[MAC_LEN];
unsigned char p2p_dst_mac[MAC_LEN];
int efd, gfd; int efd, gfd;
char *str; char *str;
@ -212,17 +212,22 @@ static int raw_open(struct transport *t, const char *name,
pr_err("invalid ptp_dst_mac %s", str); pr_err("invalid ptp_dst_mac %s", str);
return -1; return -1;
} }
str = config_get_string(t->cfg, name, "p2p_dst_mac");
if (str2mac(str, p2p_dst_mac)) {
pr_err("invalid p2p_dst_mac %s", str);
return -1;
}
mac_to_addr(&raw->ptp_addr, ptp_dst_mac); mac_to_addr(&raw->ptp_addr, ptp_dst_mac);
mac_to_addr(&raw->p2p_addr, p2p_dst_mac); mac_to_addr(&raw->p2p_addr, p2p_dst_mac);
if (sk_interface_macaddr(name, &raw->src_addr)) if (sk_interface_macaddr(name, &raw->src_addr))
goto no_mac; goto no_mac;
efd = open_socket(name, 1, ptp_dst_mac); efd = open_socket(name, 1, ptp_dst_mac, p2p_dst_mac);
if (efd < 0) if (efd < 0)
goto no_event; goto no_event;
gfd = open_socket(name, 0, ptp_dst_mac); gfd = open_socket(name, 0, ptp_dst_mac, p2p_dst_mac);
if (gfd < 0) if (gfd < 0)
goto no_general; goto no_general;

5
raw.h
View File

@ -23,11 +23,6 @@
#include "fd.h" #include "fd.h"
#include "transport.h" #include "transport.h"
/**
* The MAC address to use for peer messages.
*/
extern unsigned char p2p_dst_mac[];
/** /**
* Allocate an instance of a raw Ethernet transport. * Allocate an instance of a raw Ethernet transport.
* @return Pointer to a new transport instance on success, NULL otherwise. * @return Pointer to a new transport instance on success, NULL otherwise.