Skip to content

Commit

Permalink
MINOR: server: add set-proxy-v2-tlv-fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuraga committed Dec 5, 2023
1 parent 0e22b30 commit 421b28a
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 14 deletions.
4 changes: 2 additions & 2 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ frontend test
bind 192.168.1.2:8080 name webserv3 thread 1/1
bind [2a01:c9c0:a3:8::3]:80 name ipv6 thread 1/1-1
bind 192.168.1.1:80 name test-quic quic-socket connection thread 1/1
bind 192.168.1.1:80 name testnbcon thread 1/all nbconn 6
bind 192.168.1.1:80 name testnbcon thread 1/all nbconn 6
bind-process odd
option httplog
option dontlognull
Expand Down Expand Up @@ -650,7 +650,7 @@ backend test
external-check command /bin/false
use-server webserv if TRUE
use-server webserv2 unless TRUE
server webserv 192.168.1.1:9200 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 id 1234 pool-purge-delay 10s tcp-ut 2s curves secp384r1 client-sigalgs ECDSA+SHA256:RSA+SHA256 sigalgs ECDSA+SHA256 log-bufsize 10
server webserv 192.168.1.1:9200 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128 id 1234 pool-purge-delay 10s tcp-ut 2s curves secp384r1 client-sigalgs ECDSA+SHA256:RSA+SHA256 sigalgs ECDSA+SHA256 log-bufsize 10 set-proxy-v2-tlv-fmt(0x20) %[fc_pp_tlv(0x20)]
server webserv2 192.168.1.1:9300 maxconn 1000 ssl weight 10 inter 2s cookie BLAH slowstart 6000 proxy-v2-options authority,crc32c ws h1 pool-low-conn 128
http-request set-dst hdr(x-dst)
http-request set-dst-port int(4000)
Expand Down
10 changes: 10 additions & 0 deletions configuration/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ func parseServerParams(serverOptions []params.ServerOption, serverParams *models
case "ws":
serverParams.Ws = v.Value
}
case *params.ServerOptionIDValue:
if v.Name == "set-proxy-v2-tlv-fmt" {
serverParams.SetProxyV2TlvFmt = &models.ServerParamsSetProxyV2TlvFmt{
ID: &v.ID,
Value: &v.Value,
}
}
}
}
// Add corresponding arguments to the source option.
Expand Down Expand Up @@ -803,6 +810,9 @@ func serializeServerParams(s models.ServerParams) (options []params.ServerOption
if s.Socks4 != "" {
options = append(options, &params.ServerOptionValue{Name: "socks4", Value: s.Socks4})
}
if s.SetProxyV2TlvFmt != nil && s.SetProxyV2TlvFmt.ID != nil && s.SetProxyV2TlvFmt.Value != nil {
options = append(options, &params.ServerOptionIDValue{Name: "set-proxy-v2-tlv-fmt", ID: *s.SetProxyV2TlvFmt.ID, Value: *s.SetProxyV2TlvFmt.Value})
}
if s.TCPUt != nil {
options = append(options, &params.ServerOptionValue{Name: "tcp-ut", Value: strconv.FormatInt(*s.TCPUt, 10)})
}
Expand Down
42 changes: 42 additions & 0 deletions configuration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ func TestGetServers(t *testing.T) { //nolint:gocognit,gocyclo
if s.Name == "webserv2" && s.LogBufsize != nil {
t.Errorf("%v: LogBufsize should be nil: %v", s.Name, s.LogBufsize)
}
if s.Name == "webserv" {
if s.SetProxyV2TlvFmt != nil {
if s.SetProxyV2TlvFmt.ID != nil {
if *s.SetProxyV2TlvFmt.ID != "0x20" {
t.Errorf("%v: SetProxyV2TlvFmt ID should be 0x20: %s", s.Name, *s.SetProxyV2TlvFmt.ID)
}
} else {
t.Errorf("%v: SetProxyV2TlvFmt ID should be set", s.Name)
}
if s.SetProxyV2TlvFmt.Value != nil {
if *s.SetProxyV2TlvFmt.Value != "%[fc_pp_tlv(0x20)]" {
t.Errorf("%v: SetProxyV2TlvFmt Value should be %%[fc_pp_tlv(0x20)]: %s", s.Name, *s.SetProxyV2TlvFmt.Value)
}
} else {
t.Errorf("%v: SetProxyV2TlvFmt Value should be set", s.Name)
}
} else {
t.Errorf("%v: SetProxyV2TlvFmt should be set", s.Name)
}
}
}

_, servers, err = clientTest.GetServers("backend", "test_2", "")
Expand Down Expand Up @@ -168,6 +188,24 @@ func TestGetServer(t *testing.T) {
if s.LogBufsize == nil || *s.LogBufsize != 10 {
t.Errorf("%v: LogBufsize should be 10: %v", s.Name, s.LogBufsize)
}
if s.SetProxyV2TlvFmt != nil {
if s.SetProxyV2TlvFmt.ID != nil {
if *s.SetProxyV2TlvFmt.ID != "0x20" {
t.Errorf("%v: SetProxyV2TlvFmt ID should be 0x20: %s", s.Name, *s.SetProxyV2TlvFmt.ID)
}
} else {
t.Errorf("%v: SetProxyV2TlvFmt ID should be set", s.Name)
}
if s.SetProxyV2TlvFmt.Value != nil {
if *s.SetProxyV2TlvFmt.Value != "%[fc_pp_tlv(0x20)]" {
t.Errorf("%v: SetProxyV2TlvFmt Value should be %%[fc_pp_tlv(0x20)]: %s", s.Name, *s.SetProxyV2TlvFmt.Value)
}
} else {
t.Errorf("%v: SetProxyV2TlvFmt Value should be set", s.Name)
}
} else {
t.Errorf("%v: SetProxyV2TlvFmt should be set", s.Name)
}

_, err = s.MarshalBinary()
if err != nil {
Expand Down Expand Up @@ -270,6 +308,10 @@ func TestCreateEditDeleteServer(t *testing.T) {
Sigalgs: "RSA+SHA256",
ClientSigalgs: "ECDSA+SHA256",
LogBufsize: misc.Int64P(11),
SetProxyV2TlvFmt: &models.ServerParamsSetProxyV2TlvFmt{
ID: misc.StringP("0x50"),
Value: misc.StringP("%[fc_pp_tlv(0x20)]"),
},
},
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/renameio v1.0.1
github.com/google/uuid v1.3.1
github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205124653-983ec1a8fa02
github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205133436-67d880c8f163
github.com/json-iterator/go v1.1.12
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
golang.org/x/text v0.13.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.14.0
)

Expand All @@ -40,6 +40,6 @@ require (
github.com/rogpeppe/go-internal v1.6.1 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWU
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205124653-983ec1a8fa02 h1:UqP7BhPVKlI/49JwnZDlR1rHZ3YQulmk5gPxl4V+rYA=
github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205124653-983ec1a8fa02/go.mod h1:ASOyT1KguwXaY0NfoLNjLLs0OlnYHnFgUJsdJe6NhZg=
github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205133436-67d880c8f163 h1:drZRX/gg1eUH3f4VkdjfEwfGqiDxJP0xvNQQt7FeHgc=
github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205133436-67d880c8f163/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=
github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down Expand Up @@ -209,8 +209,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -220,8 +220,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand Down
126 changes: 125 additions & 1 deletion models/server_params.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 421b28a

Please sign in to comment.