Extend struct address to hold the peer's IP address and use it to send UC delay requests to Master.
Signed-off-by: Andriy Kohut <andr...@mellanox.com> --- address.h | 6 ++++++ raw_udp.c | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/address.h b/address.h index 35ef05f..f9eca22 100644 --- a/address.h +++ b/address.h @@ -36,6 +36,12 @@ struct address { struct sockaddr_un sun; struct sockaddr sa; }; + union { + struct sockaddr_storage ss; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + struct sockaddr sa; + } peer; }; #endif diff --git a/raw_udp.c b/raw_udp.c index 08af003..7f9209d 100644 --- a/raw_udp.c +++ b/raw_udp.c @@ -371,6 +371,7 @@ static int raw_udp_recv(struct transport *t, int fd, void *buf, int buflen, { int cnt, hlen; unsigned char *ptr = buf; + struct ip_hdr *ip_hdr = NULL; hlen = sizeof(struct eth_hdr) + sizeof(struct ip_hdr) + sizeof(struct udp_hdr); @@ -380,6 +381,10 @@ static int raw_udp_recv(struct transport *t, int fd, void *buf, int buflen, cnt = sk_receive(fd, ptr, buflen, addr, hwts, 0); + ip_hdr = (struct ip_hdr *) (ptr + sizeof(struct eth_hdr)); + addr->peer.sin.sin_family = AF_INET; + addr->peer.sin.sin_addr.s_addr = ip_hdr->ip_src.s_addr; + if (cnt >= 0) cnt -= hlen; return cnt; @@ -453,6 +458,7 @@ static void raw_udp_packet_construct(struct raw_udp *raw, struct address *addr, struct eth_hdr *eth_hdr; struct ip_hdr *ip_hdr; struct udp_hdr *udp_hdr; + struct ptp_message *msg = (struct ptp_message *) *ptr; /* UDP Header */ *ptr -= sizeof(*udp_hdr); @@ -468,9 +474,14 @@ static void raw_udp_packet_construct(struct raw_udp *raw, struct address *addr, ip_hdr = (struct ip_hdr *) *ptr; ip_hdr->ip_p = IPPROTO_UDP; - ip_hdr->ip_src = raw->ip_src.sin.sin_addr; - ip_hdr->ip_dst.s_addr = mcast_addr[MC_PRIMARY].s_addr; - ip_hdr->ip_ttl = 128; + + if (msg->header.flagField[0] & UNICAST) { + ip_hdr->ip_dst.s_addr = msg->address.peer.sin.sin_addr.s_addr; + ip_hdr->ip_ttl = 128; + } else { + ip_hdr->ip_dst.s_addr = mcast_addr[MC_PRIMARY].s_addr; + ip_hdr->ip_ttl = 1; + } ip_hdr->ip_src = raw->ip_src.sin.sin_addr; udp_hdr->udp_check = 0; -- 2.8.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel