@@ -625,6 +625,68 @@ func printNodeProfile(nodeProfile *ptpv1.PtpProfile) {
625625 glog .Infof ("------------------------------------" )
626626}
627627
628+ // extractAuthSettingsForPhc2sys extracts sa_file, spp, and active_key_id from ptp4lConf
629+ // and returns a phc2sys-compatible [global] section with those settings
630+ func extractAuthSettingsForPhc2sys (ptp4lConf * string ) string {
631+ if ptp4lConf == nil || * ptp4lConf == "" {
632+ return ""
633+ }
634+
635+ var saFile , spp , activeKeyId string
636+ inGlobal := false
637+
638+ for _ , line := range strings .Split (* ptp4lConf , "\n " ) {
639+ line = strings .TrimSpace (line )
640+
641+ if line == "[global]" {
642+ inGlobal = true
643+ continue
644+ }
645+ if strings .HasPrefix (line , "[" ) && line != "[global]" {
646+ inGlobal = false
647+ continue
648+ }
649+
650+ if inGlobal {
651+ if strings .HasPrefix (line , "sa_file" ) {
652+ parts := strings .Fields (line )
653+ if len (parts ) >= 2 {
654+ saFile = parts [1 ]
655+ }
656+ } else if strings .HasPrefix (line , "spp" ) && ! strings .HasPrefix (line , "spp " ) {
657+ // Skip lines like "spp_foo"
658+ } else if strings .HasPrefix (line , "spp " ) {
659+ parts := strings .Fields (line )
660+ if len (parts ) >= 2 {
661+ spp = parts [1 ]
662+ }
663+ } else if strings .HasPrefix (line , "active_key_id" ) {
664+ parts := strings .Fields (line )
665+ if len (parts ) >= 2 {
666+ activeKeyId = parts [1 ]
667+ }
668+ }
669+ }
670+ }
671+
672+ // Only generate config if we have auth settings
673+ if saFile == "" {
674+ return ""
675+ }
676+
677+ var result strings.Builder
678+ result .WriteString ("[global]\n " )
679+ result .WriteString (fmt .Sprintf ("sa_file %s\n " , saFile ))
680+ if spp != "" {
681+ result .WriteString (fmt .Sprintf ("spp %s\n " , spp ))
682+ }
683+ if activeKeyId != "" {
684+ result .WriteString (fmt .Sprintf ("active_key_id %s\n " , activeKeyId ))
685+ }
686+
687+ return result .String ()
688+ }
689+
628690/*
629691update: March 7th 2024
630692To support PTP HA phc2sys profile is appended to the end
@@ -712,6 +774,19 @@ func (dn *Daemon) applyNodePtpProfile(runID int, nodeProfile *ptpv1.PtpProfile)
712774 }
713775 configFile = fmt .Sprintf ("phc2sys.%d.config" , runID )
714776 configPath = fmt .Sprintf ("%s/%s" , configPrefix , configFile )
777+ if clockType == event .GM && nodeProfile .Ptp4lConf != nil {
778+ phc2sysAuthConfig := extractAuthSettingsForPhc2sys (nodeProfile .Ptp4lConf )
779+ if phc2sysAuthConfig != "" {
780+ if configInput == nil || * configInput == "" {
781+ configInput = & phc2sysAuthConfig
782+ } else {
783+ // Prepend auth settings to existing config
784+ merged := phc2sysAuthConfig + "\n " + * configInput
785+ configInput = & merged
786+ }
787+ glog .Infof ("Injected auth settings into phc2sys config for grandmaster profile %s" , * nodeProfile .Name )
788+ }
789+ }
715790 case ts2phcProcessName :
716791 configInput = nodeProfile .Ts2PhcConf
717792 configOpts = nodeProfile .Ts2PhcOpts
0 commit comments