@@ -18,11 +18,6 @@ const (
1818 // dhcpRelayDefaultSubinterfaceIndex is the subinterface a relay attaches to
1919 // when the interface name carries no ".<index>" suffix.
2020 dhcpRelayDefaultSubinterfaceIndex = 0
21-
22- // dhcpRelayAdminStateEnable is the admin-state value that enables the relay.
23- // It is also the platform default, so it must be set explicitly to avoid a
24- // false diff against the device on every reconcile.
25- dhcpRelayAdminStateEnable = "enable"
2621)
2722
2823var _ provider.DHCPRelayProvider = (* Provider )(nil )
@@ -62,7 +57,7 @@ func (p *Provider) EnsureDHCPRelay(ctx context.Context, req *provider.DHCPRelayR
6257 sb .Update (& DHCPRelay {
6358 Interface : name ,
6459 SubinterfaceIndex : index ,
65- AdminState : dhcpRelayAdminStateEnable ,
60+ AdminState : AdminStEnable ,
6661 Server : req .DHCPRelay .Spec .Servers ,
6762 NetworkInstance : networkInstance ,
6863 })
@@ -75,21 +70,21 @@ func (p *Provider) EnsureDHCPRelay(ctx context.Context, req *provider.DHCPRelayR
7570// subinterface index. SRLinux names a subinterface "<interface>.<index>";
7671// without a suffix the relay attaches to the base subinterface.
7772func splitSubinterface (name string ) (string , int , error ) {
78- i := strings .LastIndex (name , "." )
79- if i == - 1 {
73+ base , suffix , found := strings .CutLast (name , "." )
74+ if ! found {
8075 return name , dhcpRelayDefaultSubinterfaceIndex , nil
8176 }
82- index , err := strconv .Atoi (name [ i + 1 :] )
77+ index , err := strconv .Atoi (suffix )
8378 if err != nil {
8479 return "" , 0 , fmt .Errorf ("invalid subinterface index in interface name %q: %w" , name , err )
8580 }
86- return name [: i ] , index , nil
81+ return base , index , nil
8782}
8883
8984type DHCPRelay struct {
9085 Interface string `json:"-"`
9186 SubinterfaceIndex int `json:"-"`
92- AdminState string `json:"admin-state,omitempty"`
87+ AdminState AdminSt `json:"admin-state,omitempty"`
9388 Server []string `json:"server,omitempty"`
9489 NetworkInstance string `json:"network-instance,omitempty"`
9590}
0 commit comments