@@ -26,6 +26,7 @@ import (
2626 parser_errors "github.com/haproxytech/client-native/v6/config-parser/errors"
2727 "github.com/haproxytech/client-native/v6/config-parser/params"
2828 "github.com/haproxytech/client-native/v6/config-parser/types"
29+ "github.com/haproxytech/client-native/v6/misc"
2930
3031 "github.com/haproxytech/client-native/v6/models"
3132)
@@ -187,42 +188,27 @@ func ParseDgramBinds(logForward string, p parser.Parser) (models.DgramBinds, err
187188
188189func ParseDgramBind (ondiskDgramBind types.DgramBind ) * models.DgramBind {
189190 b := & models.DgramBind {}
190- if strings .HasPrefix (ondiskDgramBind .Path , "/" ) {
191- b .Address = ondiskDgramBind .Path
192- } else {
193- addSlice := strings .Split (ondiskDgramBind .Path , ":" )
194- switch n := len (addSlice ); {
195- case n == 0 :
196- return nil
197- case n == 4 : // :::443
198- b .Address = "::"
199- if addSlice [3 ] != "" {
200- p , err := strconv .ParseInt (addSlice [3 ], 10 , 64 )
201- if err == nil {
202- b .Port = & p
203- }
204- }
205- case n > 1 :
206- b .Address = addSlice [0 ]
207- ports := strings .Split (addSlice [1 ], "-" )
208-
209- // *:<port>
210- if ports [0 ] != "" {
211- port , err := strconv .ParseInt (ports [0 ], 10 , 64 )
212- if err == nil {
213- b .Port = & port
214- }
191+ address , port , err := misc .ParseBindAddress (ondiskDgramBind .Path )
192+ if err != nil {
193+ return nil
194+ }
195+ b .Address = address
196+ if port != "" {
197+ ports := strings .Split (port , "-" )
198+ // *:<port>
199+ if ports [0 ] != "" {
200+ p , err := strconv .ParseInt (ports [0 ], 10 , 64 )
201+ if err == nil {
202+ b .Port = & p
215203 }
216- // *:<port-first>-<port-last>
217- if b . Port != nil && len ( ports ) == 2 {
218- portRangeEnd , err := strconv . ParseInt (ports [ 1 ], 10 , 64 )
219- // Deny inverted interval.
220- if err == nil && ( * b . Port < portRangeEnd ) {
221- b . PortRangeEnd = & portRangeEnd
222- }
204+ }
205+ // *:<port-first>-<port-last>
206+ if b . Port != nil && len (ports ) == 2 {
207+ portRangeEnd , err := strconv . ParseInt ( ports [ 1 ], 10 , 64 )
208+ // Deny inverted interval.
209+ if err == nil && ( * b . Port < portRangeEnd ) {
210+ b . PortRangeEnd = & portRangeEnd
223211 }
224- case n > 0 :
225- b .Address = addSlice [0 ]
226212 }
227213 }
228214 for _ , p := range ondiskDgramBind .Params {
@@ -253,7 +239,7 @@ func SerializeDgramBind(b models.DgramBind) types.DgramBind {
253239 Params : []params.DgramBindOption {},
254240 }
255241 if b .Port != nil {
256- dBind .Path = b .Address + ":" + strconv .FormatInt (* b .Port , 10 )
242+ dBind .Path = misc . SanitizeIPv6Address ( b .Address ) + ":" + strconv .FormatInt (* b .Port , 10 )
257243 if b .PortRangeEnd != nil {
258244 dBind .Path = dBind .Path + "-" + strconv .FormatInt (* b .PortRangeEnd , 10 )
259245 }
0 commit comments