Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap functions.
> -Original Message- > From: Geva, Erez > Sent: Thursday, March 11, 2021 2:23 AM > To: Richard Cochran > Cc: linuxptp-devel@lists.sourceforge.net > Subject: Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap > functions. > > How do you want to call the 64 bits? > I think that naming should be consistence. > > Erez I think the usual scheme is "htonll" or "ntohll" for "long long". Thanks, Jake > > -Original Message- > From: Richard Cochran > Sent: Thursday, 11 March 2021 04:12 > To: Geva, Erez (ext) (DI PA DCP R&D 3) > Cc: linuxptp-devel@lists.sourceforge.net > Subject: Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap > functions. > > On Wed, Mar 10, 2021 at 11:17:48PM +0100, Erez Geva wrote: > > Replace byte order with explicit length. > > > > Add function for byte order for 64 bits. > > > > Signed-off-by: Erez Geva > > --- > > clock.c | 4 +- > > msg.c | 51 ++--- > > nsm.c | 2 +- > > port.c | 5 +- > > raw.c | 10 +-- > > tc.c| 8 +- > > tlv.c | 207 ++-- > > transport.c | 9 ++- > > udp.c | 6 +- > > udp6.c | 4 +- > > util.h | 67 + > > 11 files changed, 221 insertions(+), 152 deletions(-) > > > > diff --git a/clock.c b/clock.c > > index 7005636..5b3b4d0 100644 > > --- a/clock.c > > +++ b/clock.c > > @@ -255,12 +255,12 @@ void clock_send_notification(struct clock *c, struct > ptp_message *msg, > > if (!event_bitmask_get(s->events, event)) > > continue; > > /* send event */ > > - msg->header.sequenceId = htons(s->sequenceId); > > + msg->header.sequenceId = hton16(s->sequenceId); > > I really don't see any improvement here. > > Sorry, > Richard > > > ___ > Linuxptp-devel mailing list > Linuxptp-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linuxptp-devel ___ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap functions.
How do you want to call the 64 bits? I think that naming should be consistence. Erez -Original Message- From: Richard Cochran Sent: Thursday, 11 March 2021 04:12 To: Geva, Erez (ext) (DI PA DCP R&D 3) Cc: linuxptp-devel@lists.sourceforge.net Subject: Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap functions. On Wed, Mar 10, 2021 at 11:17:48PM +0100, Erez Geva wrote: > Replace byte order with explicit length. > > Add function for byte order for 64 bits. > > Signed-off-by: Erez Geva > --- > clock.c | 4 +- > msg.c | 51 ++--- > nsm.c | 2 +- > port.c | 5 +- > raw.c | 10 +-- > tc.c| 8 +- > tlv.c | 207 ++-- > transport.c | 9 ++- > udp.c | 6 +- > udp6.c | 4 +- > util.h | 67 + > 11 files changed, 221 insertions(+), 152 deletions(-) > > diff --git a/clock.c b/clock.c > index 7005636..5b3b4d0 100644 > --- a/clock.c > +++ b/clock.c > @@ -255,12 +255,12 @@ void clock_send_notification(struct clock *c, struct > ptp_message *msg, > if (!event_bitmask_get(s->events, event)) > continue; > /* send event */ > - msg->header.sequenceId = htons(s->sequenceId); > + msg->header.sequenceId = hton16(s->sequenceId); I really don't see any improvement here. Sorry, Richard ___ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap functions.
> -Original Message- > From: Richard Cochran > Sent: Wednesday, March 10, 2021 7:12 PM > To: Erez Geva > Cc: linuxptp-devel@lists.sourceforge.net > Subject: Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap > functions. > > On Wed, Mar 10, 2021 at 11:17:48PM +0100, Erez Geva wrote: > > Replace byte order with explicit length. > > > > Add function for byte order for 64 bits. > > > > Signed-off-by: Erez Geva > > --- > > clock.c | 4 +- > > msg.c | 51 ++--- > > nsm.c | 2 +- > > port.c | 5 +- > > raw.c | 10 +-- > > tc.c| 8 +- > > tlv.c | 207 ++-- > > transport.c | 9 ++- > > udp.c | 6 +- > > udp6.c | 4 +- > > util.h | 67 + > > 11 files changed, 221 insertions(+), 152 deletions(-) > > > > diff --git a/clock.c b/clock.c > > index 7005636..5b3b4d0 100644 > > --- a/clock.c > > +++ b/clock.c > > @@ -255,12 +255,12 @@ void clock_send_notification(struct clock *c, struct > ptp_message *msg, > > if (!event_bitmask_get(s->events, event)) > > continue; > > /* send event */ > > - msg->header.sequenceId = htons(s->sequenceId); > > + msg->header.sequenceId = hton16(s->sequenceId); > > I really don't see any improvement here. > > Sorry, > Richard > I'm personally a fan of the bit length being in the name myself, but I don't think it's worth churn for no other reason. I also generally prefer "cpu_to_le16" or "cpu_to_be16" instead of hotn.. but again not worth changing just to rename. Thanks, Jake ___ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
Re: [Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap functions.
On Wed, Mar 10, 2021 at 11:17:48PM +0100, Erez Geva wrote: > Replace byte order with explicit length. > > Add function for byte order for 64 bits. > > Signed-off-by: Erez Geva > --- > clock.c | 4 +- > msg.c | 51 ++--- > nsm.c | 2 +- > port.c | 5 +- > raw.c | 10 +-- > tc.c| 8 +- > tlv.c | 207 ++-- > transport.c | 9 ++- > udp.c | 6 +- > udp6.c | 4 +- > util.h | 67 + > 11 files changed, 221 insertions(+), 152 deletions(-) > > diff --git a/clock.c b/clock.c > index 7005636..5b3b4d0 100644 > --- a/clock.c > +++ b/clock.c > @@ -255,12 +255,12 @@ void clock_send_notification(struct clock *c, struct > ptp_message *msg, > if (!event_bitmask_get(s->events, event)) > continue; > /* send event */ > - msg->header.sequenceId = htons(s->sequenceId); > + msg->header.sequenceId = hton16(s->sequenceId); I really don't see any improvement here. Sorry, Richard ___ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
[Linuxptp-devel] [PATCH 1/2] Explicit length byte order swap functions.
Replace byte order with explicit length. Add function for byte order for 64 bits. Signed-off-by: Erez Geva --- clock.c | 4 +- msg.c | 51 ++--- nsm.c | 2 +- port.c | 5 +- raw.c | 10 +-- tc.c| 8 +- tlv.c | 207 ++-- transport.c | 9 ++- udp.c | 6 +- udp6.c | 4 +- util.h | 67 + 11 files changed, 221 insertions(+), 152 deletions(-) diff --git a/clock.c b/clock.c index 7005636..5b3b4d0 100644 --- a/clock.c +++ b/clock.c @@ -255,12 +255,12 @@ void clock_send_notification(struct clock *c, struct ptp_message *msg, if (!event_bitmask_get(s->events, event)) continue; /* send event */ - msg->header.sequenceId = htons(s->sequenceId); + msg->header.sequenceId = hton16(s->sequenceId); s->sequenceId++; msg->management.targetPortIdentity.clockIdentity = s->targetPortIdentity.clockIdentity; msg->management.targetPortIdentity.portNumber = - htons(s->targetPortIdentity.portNumber); + hton16(s->targetPortIdentity.portNumber); msg->address = s->addr; port_forward_to(uds, msg); } diff --git a/msg.c b/msg.c index c4516ad..5676add 100644 --- a/msg.c +++ b/msg.c @@ -25,6 +25,7 @@ #include "contain.h" #include "msg.h" #include "print.h" +#include "util.h" #include "tlv.h" int assume_two_step = 0; @@ -61,37 +62,37 @@ static void pool_debug(const char *str, void *addr) static void announce_pre_send(struct announce_msg *m) { - m->currentUtcOffset = htons(m->currentUtcOffset); + m->currentUtcOffset = hton16(m->currentUtcOffset); m->grandmasterClockQuality.offsetScaledLogVariance = - htons(m->grandmasterClockQuality.offsetScaledLogVariance); - m->stepsRemoved = htons(m->stepsRemoved); + hton16(m->grandmasterClockQuality.offsetScaledLogVariance); + m->stepsRemoved = hton16(m->stepsRemoved); } static void announce_post_recv(struct announce_msg *m) { - m->currentUtcOffset = ntohs(m->currentUtcOffset); + m->currentUtcOffset = ntoh16(m->currentUtcOffset); m->grandmasterClockQuality.offsetScaledLogVariance = - ntohs(m->grandmasterClockQuality.offsetScaledLogVariance); - m->stepsRemoved = ntohs(m->stepsRemoved); + ntoh16(m->grandmasterClockQuality.offsetScaledLogVariance); + m->stepsRemoved = ntoh16(m->stepsRemoved); } static int hdr_post_recv(struct ptp_header *m) { if ((m->ver & MAJOR_VERSION_MASK) != PTP_MAJOR_VERSION) return -EPROTO; - m->messageLength = ntohs(m->messageLength); + m->messageLength = ntoh16(m->messageLength); m->correction = net2host64(m->correction); - m->sourcePortIdentity.portNumber = ntohs(m->sourcePortIdentity.portNumber); - m->sequenceId = ntohs(m->sequenceId); + m->sourcePortIdentity.portNumber = ntoh16(m->sourcePortIdentity.portNumber); + m->sequenceId = ntoh16(m->sequenceId); return 0; } static int hdr_pre_send(struct ptp_header *m) { - m->messageLength = htons(m->messageLength); + m->messageLength = hton16(m->messageLength); m->correction = host2net64(m->correction); - m->sourcePortIdentity.portNumber = htons(m->sourcePortIdentity.portNumber); - m->sequenceId = htons(m->sequenceId); + m->sourcePortIdentity.portNumber = hton16(m->sourcePortIdentity.portNumber); + m->sequenceId = hton16(m->sequenceId); return 0; } @@ -171,12 +172,12 @@ static void msg_tlv_recycle(struct ptp_message *msg) static void port_id_post_recv(struct PortIdentity *pid) { - pid->portNumber = ntohs(pid->portNumber); + pid->portNumber = ntoh16(pid->portNumber); } static void port_id_pre_send(struct PortIdentity *pid) { - pid->portNumber = htons(pid->portNumber); + pid->portNumber = hton16(pid->portNumber); } static int suffix_post_recv(struct ptp_message *msg, int len) @@ -195,8 +196,8 @@ static int suffix_post_recv(struct ptp_message *msg, int len) return -ENOMEM; } extra->tlv = (struct TLV *) ptr; - extra->tlv->type = ntohs(extra->tlv->type); - extra->tlv->length = ntohs(extra->tlv->length); + extra->tlv->type = ntoh16(extra->tlv->type); + extra->tlv->length = ntoh16(extra->tlv->length); if (extra->tlv->length % 2) { tlv_extra_recycle(extra); return -EBADMSG; @@ -227,26 +228,26 @@ static void suffix_pre_send(struct ptp_message *msg) TAILQ_FOREACH(extra, &msg->tlv_list, list) { tlv = extra->tlv; tlv_pre_send(tlv, extra); -