Skip to content

Commit c3463df

Browse files
committed
RFC: Add index to srcPort acl
1 parent 2e5da9b commit c3463df

3 files changed

Lines changed: 28 additions & 27 deletions

File tree

proxy/ha_proxy_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,8 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsMultipleFrontends()
11951195
expectedData := fmt.Sprintf(
11961196
`%s
11971197
acl url_my-service-12222_0 path_beg /path
1198-
acl srcPort_my-service-11111 dst_port 1111
1199-
use_backend my-service-1-be2222_0 if url_my-service-12222_0 srcPort_my-service-11111
1198+
acl srcPort_my-service-11111_0 dst_port 1111
1199+
use_backend my-service-1-be2222_0 if url_my-service-12222_0 srcPort_my-service-11111_0
12001200
12011201
frontend tcpFE_3333
12021202
bind *:3333
@@ -1366,8 +1366,8 @@ frontend service_1234
13661366
tcp-request inspect-delay 5s
13671367
tcp-request content accept if { req_ssl_hello_type 1 }
13681368
acl sni_my-service-14321-1
1369-
acl srcPort_my-service-11234 dst_port 1234
1370-
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234%s`,
1369+
acl srcPort_my-service-11234_3 dst_port 1234
1370+
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234_3%s`,
13711371
tmpl,
13721372
s.ServicesContent,
13731373
)
@@ -1405,8 +1405,8 @@ frontend service_1234
14051405
tcp-request inspect-delay 5s
14061406
tcp-request content accept if { req_ssl_hello_type 1 }
14071407
acl sni_my-service-14321-1
1408-
acl srcPort_my-service-11234 dst_port 1234
1409-
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234%s`,
1408+
acl srcPort_my-service-11234_3 dst_port 1234
1409+
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234_3%s`,
14101410
tmpl,
14111411
s.ServicesContent,
14121412
)
@@ -1444,8 +1444,8 @@ frontend service_1234
14441444
tcp-request inspect-delay 5s
14451445
tcp-request content accept if { req_ssl_hello_type 1 }
14461446
acl sni_my-service-14321-1
1447-
acl srcPort_my-service-11234 dst_port 1234
1448-
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234%s`,
1447+
acl srcPort_my-service-11234_3 dst_port 1234
1448+
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234_3%s`,
14491449
tmpl,
14501450
s.ServicesContent,
14511451
)
@@ -1483,8 +1483,8 @@ frontend service_1234
14831483
tcp-request inspect-delay 5s
14841484
tcp-request content accept if { req_ssl_hello_type 1 }
14851485
acl sni_my-service-14321-1
1486-
acl srcPort_my-service-11234 dst_port 1234
1487-
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234%s`,
1486+
acl srcPort_my-service-11234_3 dst_port 1234
1487+
use_backend my-service-1-be4321_3 if sni_my-service-14321-1 srcPort_my-service-11234_3%s`,
14881488
tmpl,
14891489
s.ServicesContent,
14901490
)
@@ -1526,8 +1526,8 @@ frontend service_443
15261526
tcp-request inspect-delay 5s
15271527
tcp-request content accept if { req_ssl_hello_type 1 }
15281528
acl sni_my-service-14321-1
1529-
acl srcPort_my-service-1443 dst_port 443
1530-
use_backend my-service-1-be4321_0 if sni_my-service-14321-1 srcPort_my-service-1443%s`,
1529+
acl srcPort_my-service-1443_0 dst_port 443
1530+
use_backend my-service-1-be4321_0 if sni_my-service-14321-1 srcPort_my-service-1443_0%s`,
15311531
tmpl,
15321532
s.ServicesContent,
15331533
)
@@ -1648,10 +1648,10 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsDomainsForEachServi
16481648
acl url_my-service1111_1 path_beg /path
16491649
acl domain_my-service1111_1 hdr_beg(host) -i domain-1-1.com domain-1-2.com
16501650
acl url_my-service2222_45 path_beg /path
1651-
acl srcPort_my-service4321 dst_port 4321
1651+
acl srcPort_my-service4321_45 dst_port 4321
16521652
acl domain_my-service2222_45 hdr_beg(host) -i domain-2-1.com domain-2-2.com
16531653
use_backend my-service-be1111_1 if url_my-service1111_1 domain_my-service1111_1
1654-
use_backend my-service-be2222_45 if url_my-service2222_45 domain_my-service2222_45 srcPort_my-service4321%s`,
1654+
use_backend my-service-be2222_45 if url_my-service2222_45 domain_my-service2222_45 srcPort_my-service4321_45%s`,
16551655
tmpl,
16561656
s.ServicesContent,
16571657
)

proxy/template.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ backend {{$.AclName}}-be{{.Port}}_{{.Index}}
290290
{{- end}}
291291
{{- end}}
292292
{{- end}}
293-
{{- if ne $.BackendExtra ""}}
293+
{{- if ne $.BackendExtra ""}}
294294
{{ $.BackendExtra }}
295-
{{- end}}
296-
{{- if gt .HttpsPort 0}}
297-
{{- range $sd := .ServiceDest}}
295+
{{- end}}
296+
{{- range $sd := .ServiceDest}}
297+
{{- if gt $.HttpsPort 0}}
298298
backend https-{{$.AclName}}-be{{.Port}}_{{.Index}}
299299
mode {{.ReqModeFormatted}}
300300
{{- if eq .ReqModeFormatted "http"}}
@@ -356,11 +356,11 @@ backend https-{{$.AclName}}-be{{.Port}}_{{.Index}}
356356
http-request del-header Authorization
357357
{{- end}}
358358
{{- end}}
359-
{{- end}}
360-
{{- if ne $.BackendExtra ""}}
359+
{{- if ne $.BackendExtra ""}}
361360
{{ $.BackendExtra }}
362-
{{- end}}
363-
{{- end}}`
361+
{{- end}}
362+
{{- end}}
363+
{{- end}}`
364364

365365
return tmpl
366366
}
@@ -383,10 +383,11 @@ func FormatServiceForTemplates(sr *Service) {
383383
if len(sr.ServiceDest[i].ReqMode) == 0 {
384384
sr.ServiceDest[i].ReqMode = "http"
385385
}
386+
386387
if sd.SrcPort > 0 {
387-
sr.ServiceDest[i].SrcPortAclName = fmt.Sprintf(" srcPort_%s%d", sr.ServiceName, sd.SrcPort)
388-
sr.ServiceDest[i].SrcPortAcl = fmt.Sprintf("\n acl srcPort_%s%d dst_port %d",
389-
sr.ServiceName, sd.SrcPort, sd.SrcPort)
388+
sr.ServiceDest[i].SrcPortAclName = fmt.Sprintf(" srcPort_%s%d_%d", sr.ServiceName, sd.SrcPort, sd.Index)
389+
sr.ServiceDest[i].SrcPortAcl = fmt.Sprintf("\n acl srcPort_%s%d_%d dst_port %d",
390+
sr.ServiceName, sd.SrcPort, sd.Index, sd.SrcPort)
390391
}
391392
}
392393
}

proxy/template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (s *TemplateTestSuite) Test_FormatData_SrcPort_DefinesSrcPortAclNameAndSrcP
6969
s.Require().Len(service.ServiceDest, 1)
7070
sd := service.ServiceDest[0]
7171

72-
s.Equal(" srcPort_my-service-14480", sd.SrcPortAclName)
73-
s.Equal("\n acl srcPort_my-service-14480 dst_port 4480", sd.SrcPortAcl)
72+
s.Equal(" srcPort_my-service-14480_0", sd.SrcPortAclName)
73+
s.Equal("\n acl srcPort_my-service-14480_0 dst_port 4480", sd.SrcPortAcl)
7474

7575
}

0 commit comments

Comments
 (0)