Skip to content

Commit

Permalink
hack to fully support ptping
Browse files Browse the repository at this point in the history
Summary: We use port 1 in sptp, and port > 10 in ptping. This can be used to distinguish the request, and set the announce packet destination accordingly.

Reviewed By: leoleovich

Differential Revision: D67096100

fbshipit-source-id: 965787ae793b67bfaed34d16eb41b65021c5b5ed
  • Loading branch information
abulimov authored and facebook-github-bot committed Dec 11, 2024
1 parent 422aebf commit 1450a6b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ptp/ptp4u/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ func readPacketBuf(connFd int, buf []byte) (int, unix.Sockaddr, error) {
return n, saddr, err
}

func updateSockaddrWithPort(sa unix.Sockaddr, port int) {
switch sa := sa.(type) {
case *unix.SockaddrInet4:
sa.Port = port
case *unix.SockaddrInet6:
sa.Port = port
}
}

// handleEventMessage is a handler which gets called every time Event Message arrives
func (s *Server) handleEventMessages(eventConn *net.UDPConn) {
buf := make([]byte, timestamp.PayloadSizeBytes)
Expand Down Expand Up @@ -300,7 +309,12 @@ func (s *Server) handleEventMessages(eventConn *net.UDPConn) {
expire = time.Now().Add(subscriptionDuration)
// SYNC DELAY_REQUEST and ANNOUNCE
if sc = worker.FindSubscription(dReq.Header.SourcePortIdentity, ptp.MessageDelayReq); sc == nil {
gclisa = timestamp.NewSockaddrWithPort(eclisa, ptp.PortGeneral)
// if the port number is > 10, it's a ptping request which expects announce to come to the same ephemeral port
if dReq.SourcePortIdentity.PortNumber > 10 {
gclisa = eclisa
} else {
gclisa = timestamp.NewSockaddrWithPort(eclisa, ptp.PortGeneral)
}
// Create a new subscription
sc = NewSubscriptionClient(worker.queue, worker.signalingQueue, eclisa, gclisa, ptp.MessageDelayReq, s.Config, subscriptionDuration, expire)
worker.RegisterSubscription(dReq.Header.SourcePortIdentity, ptp.MessageDelayReq, sc)
Expand All @@ -310,6 +324,12 @@ func (s *Server) handleEventMessages(eventConn *net.UDPConn) {
sc.SetExpire(expire)
// sptp is stateless, port can change
sc.eclisa = eclisa
// if the port number is > 10, it's a ptping request which expects announce to come to the same ephemeral port
if dReq.SourcePortIdentity.PortNumber > 10 {
sc.gclisa = eclisa
} else {
updateSockaddrWithPort(sc.gclisa, ptp.PortGeneral)
}
}
sc.UpdateSyncDelayReq(rxTS, dReq.SequenceID)
sc.UpdateAnnounceDelayReq(dReq.CorrectionField, dReq.SequenceID)
Expand Down

0 comments on commit 1450a6b

Please sign in to comment.