From 9e368f57507fad9da57057257b8635a57a7a886e Mon Sep 17 00:00:00 2001 From: Mathias Merscher Date: Mon, 1 May 2017 11:11:53 +0200 Subject: [PATCH 1/3] adds support for parsing FWM virtual servers --- ipvs.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ipvs.go b/ipvs.go index e7012f732..86830d10e 100644 --- a/ipvs.go +++ b/ipvs.go @@ -33,6 +33,8 @@ type IPVSBackendStatus struct { LocalAddress net.IP // The local (virtual) port. LocalPort uint16 + // The local firewall mark + LocalMark string // The transport protocol (TCP, UDP). Proto string // The remote (real) IP address. @@ -142,6 +144,7 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) { status []IPVSBackendStatus scanner = bufio.NewScanner(file) proto string + localMark string localAddress net.IP localPort uint16 err error @@ -164,6 +167,12 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) { if err != nil { return nil, err } + case fields[0] == "FWM": + if len(fields) < 2 { + continue + } + proto = fields[0] + localMark = fields[1] case fields[0] == "->": if len(fields) < 6 { continue @@ -187,6 +196,7 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) { status = append(status, IPVSBackendStatus{ LocalAddress: localAddress, LocalPort: localPort, + LocalMark: localMark, RemoteAddress: remoteAddress, RemotePort: remotePort, Proto: proto, From 085c02ccfde37a24b49e220018a4656b3178156d Mon Sep 17 00:00:00 2001 From: Mathias Merscher Date: Mon, 1 May 2017 11:26:48 +0200 Subject: [PATCH 2/3] only fill needed fields in IPVSBackendStatus struct --- ipvs.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ipvs.go b/ipvs.go index 86830d10e..17bd2071a 100644 --- a/ipvs.go +++ b/ipvs.go @@ -163,6 +163,7 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) { continue } proto = fields[0] + localMark = "" localAddress, localPort, err = parseIPPort(fields[1]) if err != nil { return nil, err @@ -173,6 +174,8 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) { } proto = fields[0] localMark = fields[1] + localAddress = nil + localPort = 0 case fields[0] == "->": if len(fields) < 6 { continue From 9a94a5b2d44393f44495e83e96f52a1213c33971 Mon Sep 17 00:00:00 2001 From: Mathias Merscher Date: Mon, 1 May 2017 11:28:53 +0200 Subject: [PATCH 3/3] adds tests for FWM virtual_servers --- fixtures/net/ip_vs | 3 +++ ipvs_test.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/fixtures/net/ip_vs b/fixtures/net/ip_vs index 6a6a97d7d..f95a0b0d0 100644 --- a/fixtures/net/ip_vs +++ b/fixtures/net/ip_vs @@ -12,3 +12,6 @@ TCP C0A80039:0CEA wlc TCP C0A80037:0CEA wlc -> C0A8321A:0CEA Tunnel 0 0 0 -> C0A83120:0CEA Tunnel 100 0 0 +FWM 10001000 wlc + -> C0A8321A:0CEA Route 0 0 1 + -> C0A83215:0CEA Route 0 0 2 diff --git a/ipvs_test.go b/ipvs_test.go index 796ee5b88..3a676f797 100644 --- a/ipvs_test.go +++ b/ipvs_test.go @@ -94,6 +94,25 @@ var ( ActiveConn: 0, InactConn: 0, }, + + { + LocalMark: "10001000", + RemoteAddress: net.ParseIP("192.168.50.26"), + RemotePort: 3306, + Proto: "FWM", + Weight: 0, + ActiveConn: 0, + InactConn: 1, + }, + { + LocalMark: "10001000", + RemoteAddress: net.ParseIP("192.168.50.21"), + RemotePort: 3306, + Proto: "FWM", + Weight: 0, + ActiveConn: 0, + InactConn: 2, + }, } )