From 6b74716eb3d31b5a99e985fe2be9ef9b397729bf Mon Sep 17 00:00:00 2001 From: huangyichen Date: Tue, 25 Jul 2023 20:45:33 +0800 Subject: [PATCH 1/4] set ipc socket by options --ipc-sockopt-path --- tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go b/tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go index c9b885685..bc269e4ff 100644 --- a/tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go +++ b/tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go @@ -45,7 +45,7 @@ type DpvsAgentServer struct { func unixDialer(ctx context.Context) (net.Conn, error) { retry := 0 d := net.Dialer{Timeout: 10 * time.Second} - raddr := net.UnixAddr{Name: "/var/run/dpvs.ipc", Net: "unix"} + raddr := net.UnixAddr{Name: IpcSocket, Net: "unix"} for { conn, err := d.DialContext(ctx, "unix", raddr.String()) if err == nil { From e730166b5d8f155a0fa6644b7a45b0f966c8e50d Mon Sep 17 00:00:00 2001 From: huangyichen Date: Mon, 14 Aug 2023 19:54:03 +0800 Subject: [PATCH 2/4] fix spelling mistake --- tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go | 4 +-- tools/dpvs-agent/dpvs-agent-api.yaml | 6 ++-- .../models/virtual_server_spec_expand.go | 36 +++++++++---------- .../models/virtual_server_spec_tiny.go | 4 +-- tools/dpvs-agent/pkg/ipc/types/getmodel.go | 4 +-- tools/dpvs-agent/pkg/ipc/types/laddr.go | 1 + .../dpvs-agent/pkg/ipc/types/virtualserver.go | 2 +- tools/dpvs-agent/restapi/embedded_spec.go | 36 +++++++++---------- .../device/put_device_name_nic_parameters.go | 4 +-- tools/dpvs-agent/restapi/server.go | 3 +- 10 files changed, 51 insertions(+), 49 deletions(-) diff --git a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go index 1b3fc1997..1ba7a08e3 100644 --- a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go +++ b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go @@ -69,8 +69,8 @@ func (h *putVsItem) Handle(params apiVs.PutVsVipPortParams) middleware.Responder vs.SetFlagsExpireQuiescent() } - if params.Spec.SyncProxy != nil && *params.Spec.SyncProxy { - vs.SetFlagsSyncProxy() + if params.Spec.SynProxy != nil && *params.Spec.SynProxy { + vs.SetFlagsSynProxy() } } diff --git a/tools/dpvs-agent/dpvs-agent-api.yaml b/tools/dpvs-agent/dpvs-agent-api.yaml index ac8487bef..62ee33065 100644 --- a/tools/dpvs-agent/dpvs-agent-api.yaml +++ b/tools/dpvs-agent/dpvs-agent-api.yaml @@ -497,7 +497,7 @@ definitions: format: "uint32" Flags: type: "string" - SyncProxy: + SynProxy: type: "string" enum: - "true" @@ -530,7 +530,7 @@ definitions: - rr - wrr - wlc - - connhash + - conhash DestCheck: type: array items: @@ -556,7 +556,7 @@ definitions: #Flags: # type: "integer" # format: "uint32" - SyncProxy: + SynProxy: type: "boolean" default: false ExpireQuiescent: diff --git a/tools/dpvs-agent/models/virtual_server_spec_expand.go b/tools/dpvs-agent/models/virtual_server_spec_expand.go index dd887a72d..88525c785 100644 --- a/tools/dpvs-agent/models/virtual_server_spec_expand.go +++ b/tools/dpvs-agent/models/virtual_server_spec_expand.go @@ -65,15 +65,15 @@ type VirtualServerSpecExpand struct { RSs *RealServerExpandList `json:"RSs,omitempty"` // sched name - // Enum: [rr wrr wlc connhash] + // Enum: [rr wrr wlc conhash] SchedName string `json:"SchedName,omitempty"` // stats Stats *ServerStats `json:"Stats,omitempty"` - // sync proxy + // syn proxy // Enum: [true false] - SyncProxy string `json:"SyncProxy,omitempty"` + SynProxy string `json:"SynProxy,omitempty"` // timeout Timeout uint32 `json:"Timeout,omitempty"` @@ -107,7 +107,7 @@ func (m *VirtualServerSpecExpand) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateSyncProxy(formats); err != nil { + if err := m.validateSynProxy(formats); err != nil { res = append(res, err) } @@ -222,7 +222,7 @@ var virtualServerSpecExpandTypeSchedNamePropEnum []interface{} func init() { var res []string - if err := json.Unmarshal([]byte(`["rr","wrr","wlc","connhash"]`), &res); err != nil { + if err := json.Unmarshal([]byte(`["rr","wrr","wlc","conhash"]`), &res); err != nil { panic(err) } for _, v := range res { @@ -241,8 +241,8 @@ const ( // VirtualServerSpecExpandSchedNameWlc captures enum value "wlc" VirtualServerSpecExpandSchedNameWlc string = "wlc" - // VirtualServerSpecExpandSchedNameConnhash captures enum value "connhash" - VirtualServerSpecExpandSchedNameConnhash string = "connhash" + // VirtualServerSpecExpandSchedNameConhash captures enum value "conhash" + VirtualServerSpecExpandSchedNameConhash string = "conhash" ) // prop value enum @@ -285,7 +285,7 @@ func (m *VirtualServerSpecExpand) validateStats(formats strfmt.Registry) error { return nil } -var virtualServerSpecExpandTypeSyncProxyPropEnum []interface{} +var virtualServerSpecExpandTypeSynProxyPropEnum []interface{} func init() { var res []string @@ -293,34 +293,34 @@ func init() { panic(err) } for _, v := range res { - virtualServerSpecExpandTypeSyncProxyPropEnum = append(virtualServerSpecExpandTypeSyncProxyPropEnum, v) + virtualServerSpecExpandTypeSynProxyPropEnum = append(virtualServerSpecExpandTypeSynProxyPropEnum, v) } } const ( - // VirtualServerSpecExpandSyncProxyTrue captures enum value "true" - VirtualServerSpecExpandSyncProxyTrue string = "true" + // VirtualServerSpecExpandSynProxyTrue captures enum value "true" + VirtualServerSpecExpandSynProxyTrue string = "true" - // VirtualServerSpecExpandSyncProxyFalse captures enum value "false" - VirtualServerSpecExpandSyncProxyFalse string = "false" + // VirtualServerSpecExpandSynProxyFalse captures enum value "false" + VirtualServerSpecExpandSynProxyFalse string = "false" ) // prop value enum -func (m *VirtualServerSpecExpand) validateSyncProxyEnum(path, location string, value string) error { - if err := validate.EnumCase(path, location, value, virtualServerSpecExpandTypeSyncProxyPropEnum, true); err != nil { +func (m *VirtualServerSpecExpand) validateSynProxyEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, virtualServerSpecExpandTypeSynProxyPropEnum, true); err != nil { return err } return nil } -func (m *VirtualServerSpecExpand) validateSyncProxy(formats strfmt.Registry) error { - if swag.IsZero(m.SyncProxy) { // not required +func (m *VirtualServerSpecExpand) validateSynProxy(formats strfmt.Registry) error { + if swag.IsZero(m.SynProxy) { // not required return nil } // value enum - if err := m.validateSyncProxyEnum("SyncProxy", "body", m.SyncProxy); err != nil { + if err := m.validateSynProxyEnum("SynProxy", "body", m.SynProxy); err != nil { return err } diff --git a/tools/dpvs-agent/models/virtual_server_spec_tiny.go b/tools/dpvs-agent/models/virtual_server_spec_tiny.go index 3ebfd849c..c90a985a4 100644 --- a/tools/dpvs-agent/models/virtual_server_spec_tiny.go +++ b/tools/dpvs-agent/models/virtual_server_spec_tiny.go @@ -42,8 +42,8 @@ type VirtualServerSpecTiny struct { // Enum: [rr wrr wlc connhash] SchedName string `json:"SchedName,omitempty"` - // sync proxy - SyncProxy *bool `json:"SyncProxy,omitempty"` + // syn proxy + SynProxy *bool `json:"SynProxy,omitempty"` // timeout Timeout uint32 `json:"Timeout,omitempty"` diff --git a/tools/dpvs-agent/pkg/ipc/types/getmodel.go b/tools/dpvs-agent/pkg/ipc/types/getmodel.go index 7e3a1b392..a1d0e30f8 100644 --- a/tools/dpvs-agent/pkg/ipc/types/getmodel.go +++ b/tools/dpvs-agent/pkg/ipc/types/getmodel.go @@ -29,7 +29,7 @@ func (vs *VirtualServerSpec) GetModel() *models.VirtualServerSpecExpand { Port: vs.GetPort(), Proto: vs.GetProto(), Fwmark: vs.GetFwmark(), - SyncProxy: "false", + SynProxy: "false", ExpireQuiescent: "false", SchedName: vs.GetSchedName(), Timeout: vs.GetTimeout(), @@ -40,7 +40,7 @@ func (vs *VirtualServerSpec) GetModel() *models.VirtualServerSpecExpand { flags := "" if (vs.GetFlags() & DPVS_SVC_F_SYNPROXY) != 0 { - modelVs.SyncProxy = "true" + modelVs.SynProxy = "true" flags += "SynProxy|" } diff --git a/tools/dpvs-agent/pkg/ipc/types/laddr.go b/tools/dpvs-agent/pkg/ipc/types/laddr.go index ed26f5069..34e3ac7a5 100644 --- a/tools/dpvs-agent/pkg/ipc/types/laddr.go +++ b/tools/dpvs-agent/pkg/ipc/types/laddr.go @@ -85,6 +85,7 @@ func (o *LocalAddrFront) GetAf() uint32 { func (o *LocalAddrFront) SetAf(af uint32) { o.af = af } + func (o *LocalAddrFront) SetAfByAddr(addr string) { i := strings.Index(addr, "/") if i != -1 { diff --git a/tools/dpvs-agent/pkg/ipc/types/virtualserver.go b/tools/dpvs-agent/pkg/ipc/types/virtualserver.go index a3e1c6456..f2a397fec 100644 --- a/tools/dpvs-agent/pkg/ipc/types/virtualserver.go +++ b/tools/dpvs-agent/pkg/ipc/types/virtualserver.go @@ -265,7 +265,7 @@ func (vs *VirtualServerSpec) GetFwmark() uint32 { return vs.fwmark } -func (vs *VirtualServerSpec) SetFlagsSyncProxy() { +func (vs *VirtualServerSpec) SetFlagsSynProxy() { vs.setFlags(DPVS_SVC_F_SYNPROXY) } diff --git a/tools/dpvs-agent/restapi/embedded_spec.go b/tools/dpvs-agent/restapi/embedded_spec.go index 797f664d2..e83c226d2 100644 --- a/tools/dpvs-agent/restapi/embedded_spec.go +++ b/tools/dpvs-agent/restapi/embedded_spec.go @@ -1859,13 +1859,13 @@ func init() { "rr", "wrr", "wlc", - "connhash" + "conhash" ] }, "Stats": { "$ref": "#/definitions/ServerStats" }, - "SyncProxy": { + "SynProxy": { "type": "string", "enum": [ "true", @@ -1913,7 +1913,7 @@ func init() { "connhash" ] }, - "SyncProxy": { + "SynProxy": { "type": "boolean", "default": false }, @@ -1961,8 +1961,8 @@ func init() { "forward2kni": { "enum": [ "unset", - "on", - "off" + true, + false ], "type": "string", "default": "unset", @@ -1996,8 +1996,8 @@ func init() { "promisc": { "enum": [ "unset", - "on", - "off" + true, + false ], "type": "string", "default": "unset", @@ -2526,8 +2526,8 @@ func init() { { "enum": [ "unset", - "on", - "off" + true, + false ], "type": "string", "default": "unset", @@ -2548,8 +2548,8 @@ func init() { { "enum": [ "unset", - "on", - "off" + true, + false ], "type": "string", "default": "unset", @@ -4200,13 +4200,13 @@ func init() { "rr", "wrr", "wlc", - "connhash" + "conhash" ] }, "Stats": { "$ref": "#/definitions/ServerStats" }, - "SyncProxy": { + "SynProxy": { "type": "string", "enum": [ "true", @@ -4254,7 +4254,7 @@ func init() { "connhash" ] }, - "SyncProxy": { + "SynProxy": { "type": "boolean", "default": false }, @@ -4302,8 +4302,8 @@ func init() { "forward2kni": { "enum": [ "unset", - "on", - "off" + true, + false ], "type": "string", "default": "unset", @@ -4337,8 +4337,8 @@ func init() { "promisc": { "enum": [ "unset", - "on", - "off" + true, + false ], "type": "string", "default": "unset", diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go index a8cd915e3..cf56efd5f 100644 --- a/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go @@ -130,7 +130,7 @@ func (o *PutDeviceNameNicParams) bindForward2Kni(rawData []string, hasKey bool, // validateForward2Kni carries on validations for parameter Forward2Kni func (o *PutDeviceNameNicParams) validateForward2Kni(formats strfmt.Registry) error { - if err := validate.EnumCase("forward2Kni", "query", *o.Forward2Kni, []interface{}{"unset", "on", "off"}, true); err != nil { + if err := validate.EnumCase("forward2Kni", "query", *o.Forward2Kni, []interface{}{"unset", true, false}, true); err != nil { return err } @@ -210,7 +210,7 @@ func (o *PutDeviceNameNicParams) bindPromisc(rawData []string, hasKey bool, form // validatePromisc carries on validations for parameter Promisc func (o *PutDeviceNameNicParams) validatePromisc(formats strfmt.Registry) error { - if err := validate.EnumCase("promisc", "query", *o.Promisc, []interface{}{"unset", "on", "off"}, true); err != nil { + if err := validate.EnumCase("promisc", "query", *o.Promisc, []interface{}{"unset", true, false}, true); err != nil { return err } diff --git a/tools/dpvs-agent/restapi/server.go b/tools/dpvs-agent/restapi/server.go index 2c8225403..c5ede575b 100644 --- a/tools/dpvs-agent/restapi/server.go +++ b/tools/dpvs-agent/restapi/server.go @@ -8,6 +8,7 @@ import ( "crypto/x509" "errors" "fmt" + "io/ioutil" "log" "net" "net/http" @@ -273,7 +274,7 @@ func (s *Server) Serve() (err error) { if s.TLSCACertificate != "" { // include specified CA certificate - caCert, caCertErr := os.ReadFile(string(s.TLSCACertificate)) + caCert, caCertErr := ioutil.ReadFile(string(s.TLSCACertificate)) if caCertErr != nil { return caCertErr } From 7a2196d7ff7ad418096b87b866cdca12696a353d Mon Sep 17 00:00:00 2001 From: huangyichen Date: Tue, 15 Aug 2023 09:19:35 +0800 Subject: [PATCH 3/4] BUGFIX: set correct laddr ip family --- tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go | 1 - tools/dpvs-agent/pkg/ipc/types/laddr.go | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go index d8765ba6d..36eb19e0d 100644 --- a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go +++ b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go @@ -49,7 +49,6 @@ func (h *putVsLaddr) Handle(params apiVs.PutVsVipPortLaddrParams) middleware.Res lds := make([]*types.LocalAddrDetail, 1) lds[0] = types.NewLocalAddrDetail() - lds[0].SetAf(laddr.GetAf()) lds[0].SetAddr(params.Spec.Addr) lds[0].SetIfName(params.Spec.Device) diff --git a/tools/dpvs-agent/pkg/ipc/types/laddr.go b/tools/dpvs-agent/pkg/ipc/types/laddr.go index 34e3ac7a5..1a4272796 100644 --- a/tools/dpvs-agent/pkg/ipc/types/laddr.go +++ b/tools/dpvs-agent/pkg/ipc/types/laddr.go @@ -244,7 +244,7 @@ func (o *LocalAddrDetail) Dump(buf []byte) bool { return o.Copy(tmp) } -func (o *LocalAddrDetail) SetAf(af uint32) { +func (o *LocalAddrDetail) setAf(af uint32) { o.af = af } @@ -293,10 +293,14 @@ func (o *LocalAddrDetail) GetAddr() string { func (o *LocalAddrDetail) SetAddr(addr string) { if strings.Contains(addr, ":") { copy(o.addr[:], net.ParseIP(addr)) + // o.af = unix.AF_INET6 + o.setAf(unix.AF_INET6) } else { buf := new(bytes.Buffer) binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) copy(o.addr[:], buf.Bytes()[12:]) + // o.af = unix.AF_INET + o.setAf(unix.AF_INET) } } From 149584b44bbb865acd41e455580dedd6d060f28e Mon Sep 17 00:00:00 2001 From: huangyichen Date: Tue, 22 Aug 2023 17:32:50 +0800 Subject: [PATCH 4/4] fix spelling mistake: TUNNEL --- tools/dpvs-agent/pkg/ipc/types/const.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/dpvs-agent/pkg/ipc/types/const.go b/tools/dpvs-agent/pkg/ipc/types/const.go index 30be74fdb..6cbf89f02 100644 --- a/tools/dpvs-agent/pkg/ipc/types/const.go +++ b/tools/dpvs-agent/pkg/ipc/types/const.go @@ -96,7 +96,7 @@ func (e *DpvsFwdMode) String() string { case DPVS_FWD_MODE_DR: return "DR" case DPVS_FWD_MODE_TUNNEL: - return "TUNNLE" + return "TUNNEL" case DPVS_FWD_MODE_BYPASS: return "BYPASS" case DPVS_FWD_MODE_SNAT: @@ -115,7 +115,7 @@ func (e *DpvsFwdMode) FromString(name string) { *e = DPVS_FWD_LOCALNODE case "DR": *e = DPVS_FWD_MODE_DR - case "TUNNLE": + case "TUNNEL": *e = DPVS_FWD_MODE_TUNNEL case "BYPASS": *e = DPVS_FWD_MODE_BYPASS