Skip to content

Commit

Permalink
- Removed legacy PTPv1 multicast group support
Browse files Browse the repository at this point in the history
- Restored lost NetBSD compatibility (as reported by
  Anton Samsonov, feature #19)
- Small network header cleanup
  • Loading branch information
wowczarek committed Feb 7, 2014
1 parent cef38c0 commit b82172b
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 119 deletions.
49 changes: 47 additions & 2 deletions configure.ac
Expand Up @@ -317,13 +317,38 @@ AC_CHECK_LIB([rt], [clock_gettime])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h netinet/ether.h stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h unistd.h glob.h sched.h utmp.h utmpx.h linux/rtc.h])
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h net/ethernet.h netinet/in.h netinet/ether.h net/if.h stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h unistd.h glob.h sched.h utmp.h utmpx.h linux/rtc.h])

# MUST chck for cpuset AFTER the check for param as the latter needs
# the former to pass the compile check.
AC_CHECK_HEADERS([sys/cpuset.h], [], [],
[#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# include <sys/param.h>
#endif
])

# Similar case for if_arp.h with socket.h and net/if.h
AC_CHECK_HEADERS([net/if_arp.h], [], [],
[
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
])

# ...and for if_ether.h
AC_CHECK_HEADERS([net/if_ether.h], [], [],
[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
])

Expand All @@ -348,6 +373,26 @@ m4_version_prereq(2.60,[
# Check for tick in the timex structure
AC_CHECK_MEMBERS([struct timex.tick], [], [], [[#include <sys/timex.h>]])

# ether_add: octet vs. ether_addr_octet - FreeBSD, any others?
AC_CHECK_MEMBERS([struct ether_addr.octet], [], [],
[
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_NETINET_ETHER_H
#include <netinet/ether.h>
#endif
#ifdef HAVE_NET_ETHERNET_H
#include <net/ethernet.h>
#endif
#ifdef HAVE_NET_IF_ETHER_H
#include <net/if.h>
#endif
#ifdef HAVE_NET_IF_ETHER_H
#include <net/if_ether.h>
#endif
])

# Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
Expand Down
5 changes: 0 additions & 5 deletions doc/ptpd-2.3.0-migration-guide.html
Expand Up @@ -164,11 +164,6 @@ <h1>PTPd 2.2.x &rarr; 2.3.0 migration guide</h1>
<td class="c3">PTP domain number (between 0-3)</td>
</tr>
<tr>
<td class="c1">-I NUM</td>
<td class="c2">--ptpengine:alt_mcast_group</td>
<td class="c3">Mcast group</td>
</tr>
<tr>
<td class="c1">-n NUM</td>
<td class="c2">--ptpengine:log_announce_interval</td>
<td class="c3">announce interval</td>
Expand Down
3 changes: 0 additions & 3 deletions src/datatypes.h
Expand Up @@ -799,9 +799,6 @@ typedef struct {
UInteger8 priority2;
UInteger8 domainNumber;
// UInteger8 timeSource;
#ifdef PTPD_EXPERIMENTAL
UInteger8 mcast_group_Number;
#endif

/*
* For slave state, grace period of n * announceReceiptTimeout
Expand Down
13 changes: 3 additions & 10 deletions src/dep/constants_dep.h
Expand Up @@ -46,11 +46,12 @@
# include <net/if.h>
# include <net/if_dl.h>
# include <net/if_types.h>
#ifdef HAVE_NET_IF_ETHER_H
# include <net/if_ether.h>
#endif
# if defined(__FreeBSD__) || defined(__APPLE__)
# include <net/ethernet.h>
# include <sys/uio.h>
# else
# include <net/if_ether.h>
# endif
# include <ifaddrs.h>
# define IFACE_NAME_LENGTH IF_NAMESIZE
Expand Down Expand Up @@ -93,11 +94,6 @@
#define DEFAULT_PTP_DOMAIN_ADDRESS "224.0.1.129"
#define PEER_PTP_DOMAIN_ADDRESS "224.0.0.107"

/* used for -I option */
#define ALTERNATE_PTP_DOMAIN1_ADDRESS "224.0.1.130"
#define ALTERNATE_PTP_DOMAIN2_ADDRESS "224.0.1.131"
#define ALTERNATE_PTP_DOMAIN3_ADDRESS "224.0.1.132"

/* 802.3 Support */

#define PTP_ETHER_DST "01:1b:19:00:00:00"
Expand Down Expand Up @@ -156,14 +152,11 @@ enum {
/* default size for string buffers */
#define BUF_SIZE 1000


#define NANOSECONDS_MAX 999999999


// limit operator messages to once every X seconds
#define OPERATOR_MESSAGES_INTERVAL 300.0


#define MAXTIMESTR 32

#endif /*CONSTANTS_DEP_H_*/
17 changes: 0 additions & 17 deletions src/dep/daemonconfig.c
Expand Up @@ -811,9 +811,6 @@ loadDefaultSettings( RunTimeOpts* rtOpts )
rtOpts->timeProperties.frequencyTraceable = FALSE;
rtOpts->timeProperties.ptpTimescale = FALSE;

#ifdef PTPD_EXPERIMENTAL
rtOpts->mcast_group_Number = 0;
#endif
rtOpts->ip_mode = IPMODE_MULTICAST;

rtOpts->noAdjust = NO_ADJUST; // false
Expand Down Expand Up @@ -1416,17 +1413,6 @@ parseConfig ( dictionary* dict, RunTimeOpts *rtOpts )
"DiffServ CodepPoint for packet prioritisation (decimal). When set to zero, \n"
" this option is not used. Use 46 for Expedited Forwarding (0x2e).",0,63);


#ifdef PTPD_EXPERIMENTAL
CONFIG_MAP_INT_RANGE("ptpengine:alt_mcast_group",rtOpts->mcast_group_Number,rtOpts->mcast_group_Number,
"Use PTP alternative multicast group like PTPv1:\n"
"0 = 224.0.1.129, 1 = 224.0.1.130, 2 = 224.0.1.131, 3 = 224.0.1.132.",0,3);
#else
if(!IS_QUIET() && CONFIG_ISSET("ptpengine:alt_mcast_group"))
INFO("PTPv1 multicast group support not enabled. Please compile with PTPD_EXPERIMENTAL \n"
"to use ptpengine:v1style_mcast_group.");
#endif /* PTPD_EXPERIMENTAL */

#ifdef PTPD_STATISTICS

CONFIG_MAP_BOOLEAN("ptpengine:delay_outlier_filter_enable",rtOpts->delaySMOutlierFilterEnabled,rtOpts->delaySMOutlierFilterEnabled,
Expand Down Expand Up @@ -2720,9 +2706,6 @@ int checkSubsystemRestart(dictionary* newConfig, dictionary* oldConfig)
COMPONENT_RESTART_REQUIRED("ptpengine:multicast_ttl", PTPD_RESTART_NETWORK );
COMPONENT_RESTART_REQUIRED("ptpengine:ip_dscp", PTPD_RESTART_NETWORK );

COMPONENT_RESTART_REQUIRED("ptpengine:alt_mcast_group", PTPD_RESTART_NETWORK );


#ifdef PTPD_SNMP
COMPONENT_RESTART_REQUIRED("global:enable_snmp", PTPD_RESTART_DAEMON );
#endif /* PTPD_SNMP */
Expand Down
5 changes: 2 additions & 3 deletions src/dep/ipv4_acl.c
Expand Up @@ -139,12 +139,11 @@ createMaskTable(const char* input)
ret=(MaskTable*)calloc(1,sizeof(MaskTable));
ret->entries = (AclEntry*)calloc(masksFound, sizeof(AclEntry));
ret->numEntries = maskParser(input,ret->entries);
return ret;
} else {
if(masksFound < 0)
ERROR("Error while parsing access list: \"%s\"\n", input);
ERROR("Error while parsing access list: \"%s\"\n", input);
return NULL;
}
return ret;
}

/* Print the contents of a single mask table */
Expand Down
64 changes: 16 additions & 48 deletions src/dep/net.c
Expand Up @@ -71,12 +71,6 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#endif
#if HAVE_NETINET_ETHER_H
#include <netinet/ether.h>
#else /* !HAVE_NETINET_ETHER_H */
#include <net/ethernet.h>
#endif /* HAVE_NETINET_ETHER_H */


/* choose kernel-level nanoseconds or microseconds resolution on the client-side */
#if !defined(SO_TIMESTAMPING) && !defined(SO_TIMESTAMPNS) && !defined(SO_TIMESTAMP) && !defined(SO_BINTIME)
Expand Down Expand Up @@ -183,46 +177,6 @@ netShutdown(NetPath * netPath)
return TRUE;
}


Boolean
chooseMcastGroup(RunTimeOpts * rtOpts, struct in_addr *netAddr)
{

char *addrStr;

#ifdef PTPD_EXPERIMENTAL
switch(rtOpts->mcast_group_Number){
case 0:
addrStr = DEFAULT_PTP_DOMAIN_ADDRESS;
break;

case 1:
addrStr = ALTERNATE_PTP_DOMAIN1_ADDRESS;
break;
case 2:
addrStr = ALTERNATE_PTP_DOMAIN2_ADDRESS;
break;
case 3:
addrStr = ALTERNATE_PTP_DOMAIN3_ADDRESS;
break;

default:
ERROR("Unk group %d\n", rtOpts->mcast_group_Number);
exit(3);
break;
}
#else
addrStr = DEFAULT_PTP_DOMAIN_ADDRESS;
#endif

if (!inet_aton(addrStr, netAddr)) {
ERROR("failed to encode multicast address: %s\n", addrStr);
return FALSE;
}
return TRUE;
}


/*Test if network layer is OK for PTP*/
UInteger8
lookupCommunicationTechnology(UInteger8 communicationTechnology)
Expand Down Expand Up @@ -482,13 +436,17 @@ netInitMulticast(NetPath * netPath, RunTimeOpts * rtOpts)
char addrStr[NET_ADDRESS_LENGTH];

/* Init General multicast IP address */
if(!chooseMcastGroup(rtOpts, &netAddr)){
memcpy(addrStr, DEFAULT_PTP_DOMAIN_ADDRESS, NET_ADDRESS_LENGTH);
if (!inet_aton(addrStr, &netAddr)) {
ERROR("failed to encode multicast address: %s\n", addrStr);
return FALSE;
}

netPath->multicastAddr = netAddr.s_addr;
if(!netInitMulticastIPv4(netPath, netPath->multicastAddr)) {
return FALSE;
}

/* End of General multicast Ip address init */


Expand Down Expand Up @@ -732,8 +690,13 @@ netInit(NetPath * netPath, RunTimeOpts * rtOpts, PtpClock * ptpClock)
#ifdef PTPD_PCAP
if (rtOpts->transport == IEEE_802_3) {
netPath->headerOffset = PACKET_BEGIN_ETHER;
#ifdef HAVE_STRUCT_ETHER_ADDR_OCTET
memcpy(netPath->etherDest.octet, ether_aton(PTP_ETHER_DST), ETHER_ADDR_LEN);
memcpy(netPath->peerEtherDest.octet, ether_aton(PTP_ETHER_PEER), ETHER_ADDR_LEN);
#else
memcpy(netPath->etherDest.ether_addr_octet, ether_aton(PTP_ETHER_DST), ETHER_ADDR_LEN);
memcpy(netPath->peerEtherDest.ether_addr_octet, ether_aton(PTP_ETHER_PEER), ETHER_ADDR_LEN);
#endif /* HAVE_STRUCT_ETHER_ADDR_OCTET */
} else
#endif
netPath->headerOffset = PACKET_BEGIN_UDP;
Expand Down Expand Up @@ -1306,7 +1269,7 @@ netRecvGeneral(Octet * buf, NetPath * netPath)
#ifdef PTPD_PCAP
if (netPath->pcapGeneral == NULL) {
#endif
ret=recvfrom(netPath->generalSock, buf, PACKET_SIZE, MSG_DONTWAIT, &from_addr, &from_addr_len);
ret=recvfrom(netPath->generalSock, buf, PACKET_SIZE, MSG_DONTWAIT, (struct sockaddr*)&from_addr, &from_addr_len);
netPath->lastRecvAddr = from_addr.sin_addr.s_addr;
return ret;
#ifdef PTPD_PCAP
Expand Down Expand Up @@ -1352,8 +1315,13 @@ netSendPcapEther(Octet * buf, UInteger16 length,
struct ether_addr * dst, struct ether_addr * src,
pcap_t * pcap) {
Octet ether[ETHER_HDR_LEN + PACKET_SIZE];
#ifdef HAVE_STRUCT_ETHER_ADDR_OCTET
memcpy(ether, dst->octet, ETHER_ADDR_LEN);
memcpy(ether + ETHER_ADDR_LEN, src->octet, ETHER_ADDR_LEN);
#else
memcpy(ether, dst->ether_addr_octet, ETHER_ADDR_LEN);
memcpy(ether + ETHER_ADDR_LEN, src->ether_addr_octet, ETHER_ADDR_LEN);
#endif /* HAVE_STRUCT_ETHER_ADDR_OCTET */
*((short *)&ether[2 * ETHER_ADDR_LEN]) = htons(PTP_ETHER_TYPE);
memcpy(ether + ETHER_HDR_LEN, buf, length);

Expand Down
2 changes: 1 addition & 1 deletion src/dep/servo.c
Expand Up @@ -615,7 +615,7 @@ servo_perform_clock_step(RunTimeOpts * rtOpts, PtpClock * ptpClock)
#ifndef NTIME_MSG
strncpy(utx.ut_line, "}", sizeof(utx.ut_line));
#else
strncpy(utx.ut_line, NTIME_MSG, sizeof(utx_ut.line));
strncpy(utx.ut_line, NTIME_MSG, sizeof(utx.ut_line));
#endif /* NTIME_MSG */
#ifdef NEW_TIME
utx.ut_tv.tv_sec = newTime.seconds;
Expand Down
32 changes: 18 additions & 14 deletions src/dep/sys.c
Expand Up @@ -53,16 +53,21 @@

#include "../ptpd.h"

#if defined(linux)
#ifdef HAVE_NETINET_ETHER_H
# include <netinet/ether.h>
#elif defined( __FreeBSD__ )
#endif

#ifdef HAVE_NET_ETHERNET_H
# include <net/ethernet.h>
#elif defined( __NetBSD__ )
# include <net/if_ether.h>
#elif defined( __OpenBSD__ )
# include <some ether header> // force build error
#endif

#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif

#ifdef HAVE_NET_IF_ETHER_H
# include <net/if_ether.h>
#endif

/* only C99 has the round function built-in */
double round (double __x);
Expand Down Expand Up @@ -232,18 +237,17 @@ int ether_ntohost_cache(char *hostname, struct ether_addr *addr)
static struct ether_addr prev_addr;
static char buf[BUF_SIZE];

#if defined(linux) || defined(__NetBSD__)
if (memcmp(addr->ether_addr_octet, &prev_addr,
#ifdef HAVE_STRUCT_ETHER_ADDR_OCTET
if (memcmp(addr->octet, &prev_addr,
sizeof(struct ether_addr )) != 0) {
valid = 0;
}
#else // e.g. defined(__FreeBSD__)
if (memcmp(addr->octet, &prev_addr,
#else
if (memcmp(addr->ether_addr_octet, &prev_addr,
sizeof(struct ether_addr )) != 0) {
valid = 0;
}
#endif

if (!valid) {
if(ether_ntohost(buf, addr)){
snprintf(buf, BUF_SIZE,"%s", "unknown");
Expand Down Expand Up @@ -412,7 +416,7 @@ logMessage(int priority, const char * format, ...)
if(!startupInProgress)
goto end;
else
goto stderr;
goto std_err;
}
}

Expand Down Expand Up @@ -442,9 +446,9 @@ logMessage(int priority, const char * format, ...)
if (!startupInProgress)
goto end;
else
goto stderr;
goto std_err;
}
stderr:
std_err:
va_start(ap, format);
/* Either all else failed or we're running in foreground - or we also log to stderr */
writeMessage(stderr, priority, format, ap);
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.c
Expand Up @@ -2793,7 +2793,7 @@ static void
issueManagementRespOrAck(MsgManagement *outgoing, RunTimeOpts *rtOpts,
PtpClock *ptpClock)
{
Integer32 dst;
Integer32 dst = 0;

/* pack ManagementTLV */
msgPackManagementTLV( ptpClock->msgObuf, outgoing, ptpClock);
Expand Down

0 comments on commit b82172b

Please sign in to comment.