Commit Graph

35 Commits (34945679fef64de38bb89ba0bff90837b606f007)

Author SHA1 Message Date
Richard Cochran 9dcd6c31e7 utils: Constify the posix clock interface.
The function to open a posix clock never modifies the passed in
string.  This patch adds the const keyword to ensure this function
stays that way.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:43:44 -08:00
Petr Machata f9f00d8fe8 util: Add a function to render timestamp type
TLV_PORT_PROPERTIES_NP carries, among other attributes, a timestamp type
used for that port. In order to make it possible to format the value for
user consumption, introduce a new function ts_str().

Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-10-12 19:42:42 -07:00
Richard Cochran d32758aa09 phc2sys, phc_ctl: Re-factor common code.
The two programs, phc2sys and phc_ctl, use nearly identical subroutines to
open an instance of a dynamic posix clock.  In anticipation of yet a third
program with similar needs, this patch refactors the common code into the
utilities.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-08-25 12:19:36 -07:00
Miroslav Lichvar dd30b3a0d9 util: Fix addreq() to not read past addresses.
Fix the length of compared data to be the size of the IPv4/IPv6 address.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2019-03-25 06:25:07 -07:00
Anders Selhammer d88b4ff229 util: Added IPv6 support in help funtions addreq and str2addr
Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-11-01 20:17:50 -07:00
Anders Selhammer 57b98c216a Add possibility to set clockIdentity
Currently the clockIdentity is generated from the mac address of the first
interface/port in config file. This patch add the possibility to set it in
config file.
The reason is if the stack is restarted with a different set of ports, it
may be circumstances when clockIdentity needs to be equal as before
restart even if the port setup is different.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-09-30 18:45:52 -07:00
Richard Cochran bc18131d27 util: Add a method to compare binary addresses.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:47 -07:00
Richard Cochran 40480f3b28 util: Make a useful helper function more public.
The function, str2addr(), will be needed by the upcoming unicast
client code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:47 -07:00
Richard Cochran 0483bf4972 util: Relocate utility functions from pmc.c.
The file, pmc.c, contains utility functions for printing out a port address
structure.  We will want to call these functions from pmc_common.c, and so
this patch moves the utility functions where they belong.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-08 07:20:42 -08:00
Feras Daoud 7546434030 ptp4l: Add IPoIB interface support for ptp4l
The current implementation of ptp4l always assumes 6 octets MAC
address, which is correct for Ethernet interfaces but not for IPoIB
interfaces (that have 20 octets MAC), therefore running ptp4l over
IPoIB interface does not function correctly.

In Infiniband, every interface has three identifiers:
GUID, GID, and LID.
The GUID is similar in concept to a MAC address. From RFC4392:
The EUI-64 portion of a GID is referred to as the Global Unique
Identifier (GUID) and is the only persistent identifier of a port.

Therefore, to support IPoIB interfaces, the GUID of the port should
be used instead of the MAC.
This patch checks the interface type before creating the clock identity,
for Infiniband ports, it retrieves the GUID of the port using sysfs
and use it to create the clock identity.

sysfs method was chosen since the GUID is the 6 lsb bytes of
the 20 byte device address, and SIOCGIFHWADDR ioctl call returns
the 14 msb bytes of the device address, so it is not possible to
get the GUID using SIOCGIFHWADDR ioctl call.

[ RC: fixed trivial coding style error, space after switch keyword. ]

Signed-off-by: Feras Daoud <ferasda@mellanox.com>
Reviewed-by: Alex Vesker <valex@mellanox.com>
2017-08-10 10:42:16 +02:00
Richard Cochran b738afb604 fsm: Make the transition out of INITIALIZING part of the FSM code.
The state machines in 1588 do not specify an event that causes a transition
out of the initializing state.  This was left as a local issue.  For this
transition, the current code assigns the next state outside of the FSM.  But
doing so prevents an alternative FSM to handle this transition differently.

By introducing a new event, this patch places this transition where it
belongs, namely under the control of the FSM code,

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:54 +01:00
Jesuiter, Henry (ALC NetworX GmbH) dc09312ce7 Fix data type for return value of vasprintf()
Since size_t is an unsigned data type, it won't evaluate correctly on errors
of vasprintf(). This patch makes 'len2' a signed integer, as expected by
vasprintf().

'len2' is of type 'size_t' in util.c:451, but vasprintf in line
457 returns '-1' on error which is checked in line 460. Currently
this check will always fail (regardless of the return value of
vasprintf()), according to its declaration as unsigned int.

[ RC: Added more explanation taken from another list message. ]

Signed-off-by: Henry Jesuiter <henry.jesuiter@alcnetworx.de>
2016-07-12 14:55:46 +02:00
Miroslav Lichvar 01d523fb48 util: add function for simple rate limiting.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2015-09-11 21:24:34 +02:00
Richard Cochran 776f772c36 Merge the hybrid E2E work.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-09-05 21:40:48 +02:00
Richard Cochran d0eb73c87b Use the standardized low level socket address format.
The raw Ethernet transport code invented its own way of storing the MAC
address into our "struct address" data structure.  However, this private
format is incompatible with the sockaddr_ll returned from the networking
stack.  This patch converts the code to use the proper format.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-29 11:32:41 +02:00
Miroslav Lichvar 16bb89d5bf util: exit in string_* and parray_* functions when allocation fails. 2015-08-29 10:33:35 +02:00
Miroslav Lichvar e4325ee3fb util: add wrappers for memory allocation functions.
Add wrappers for malloc(), calloc(), realloc() and strdup() that check
if the allocation failed, print an error message and call exit(1). This
allows the caller to use the returned value without checking for errors.
2015-08-29 10:33:35 +02:00
Richard Cochran efa91dda77 util: provide the 'count_char' helper function.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:21:43 +02:00
Richard Cochran 5fe77584b4 util: add a helper function to scan a MAC address.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:46 +02:00
Miroslav Lichvar 2098d7c162 Add string and pointer array utility functions.
Add some functions to work with strings and arrays of pointers that will
be useful later.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-10-03 14:25:19 +02:00
Miroslav Lichvar aa24ba58e1 Don't print messages in signal handler.
Only reentrant functions should be called here.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-10-03 14:25:19 +02:00
Miroslav Lichvar ca637b2067 Move signal handling to util.c.
This will be useful in phc2sys and pmc.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2014-09-21 12:34:05 +02:00
Jiri Benc e804e6f9a0 Common type holding an address
This modifies all transports to use a new common address type, struct
address. This address is stored in a ptp_message for all received messages.

For sending, the "default" address is used with the default sending
functions, transport_send and transport_peer. The default address depends on
the transport; it's supposed to be the multicast address assigned by the
transport specification.

Later, a new transport_sendto function will be implemented that sends to the
address contained in the passed ptp_message.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-25 14:28:14 +02:00
Stephan Gatzka 110849d422 Make functions and structs dealing with string literals const correct.
This allows the compiler to check if someone writes into string
literals.

Signed-off-by: Stephan Gatzka <stephan.gatzka@gmail.com>
2014-02-07 19:41:47 +01:00
Richard Cochran a3762c506e pmc: add a command to select the target port.
This patch adds a new pmc command called "target" that lets the user
address a particular clock and port. Previously all management requests
were sent to the wild card address.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-07-22 21:47:28 +02:00
Richard Cochran e67276a56e trivial: break the very long lines of the get_ functions.
The get_ranged_ and get_arg_ declarations and definitions are just a wee
bit much too long. This patch breaks the overly long lines into two.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-06-14 12:58:56 +02:00
Ken ICHIKAWA 42cb449eaa util: Add common procedures to get argument values for ptp4l and phc2sys
Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
2013-06-04 20:16:21 +02:00
Ken ICHIKAWA 306f83e7b1 Add support for more strict config value validation
This patch adds functions to get int, uint, double value from string
with error checking and range specification.
These functions don't allow overflow and outside of the range values.

In addition, it adds parser_result cases "MALFORMED" and "OUT_OF_RANGE" to make
reason of parse error more clear.

Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
2013-06-04 20:16:21 +02:00
Miroslav Lichvar eb93926bc9 phc2sys: Handle leap seconds.
Update the currentUtcOffset and leap61/59 values at one minute
interval. When a leap second is detected, set the STA_INS/STA_DEL
bit for the system clock.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-03-20 19:37:39 +01:00
Geoff Salmon e919971905 adds CLOCK_DESCRIPTION struct
Modifies existing structs changing Octet *foo -> Octet foo[0] and
marks them PACKED so the message buffer can be cast to the structs.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-25 18:11:03 +01:00
Miroslav Lichvar 5e22865728 Update port state strings.
Update the order of the strings to reflect the changes made by commit
f530ae9333.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-08 18:38:33 +01:00
Geoff Salmon 68b4678f7b adds static_ptp_text and functions for setting PTPText and static_ptp_text
static_ptp_text is like a PTPText that includes space for the text
which makes it more convenient for ptp texts stored in the clock.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-04 12:22:11 +01:00
Richard Cochran 582a8858d7 Make the function to generate a clock identity a global function.
This will allow code reuse in the management client.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-08-05 21:46:03 +02:00
Richard Cochran b76c4e108f Introduce an event recommending the grand master state.
We already have a grand master state. Adding this event will simplify the
overall logic, since it will avoid the silly requirement to set the
qualification timeout to zero when entering the grand master state.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-01-07 08:07:54 +01:00
Richard Cochran e930bc4e11 Add utility functions for obtaining human readable strings.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2011-11-06 07:37:06 +01:00