Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPVS: Add support for parsing FWM virtual servers #48

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fixtures/net/ip_vs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ TCP [2620:0000:0000:0000:0000:0000:0000:0001]:0050 sh
-> [2620:0000:0000:0000:0000:0000:0000:0002]:0050 Route 1 0 0
-> [2620:0000:0000:0000:0000:0000:0000:0003]:0050 Route 1 0 0
-> [2620:0000:0000:0000:0000:0000:0000:0004]:0050 Route 1 1 1
FWM 10001000 wlc
-> C0A8321A:0CEA Route 0 0 1
-> C0A83215:0CEA Route 0 0 2
13 changes: 13 additions & 0 deletions ipvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -160,10 +163,19 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) {
continue
}
proto = fields[0]
localMark = ""
localAddress, localPort, err = parseIPPort(fields[1])
if err != nil {
return nil, err
}
case fields[0] == "FWM":
if len(fields) < 2 {
continue
}
proto = fields[0]
localMark = fields[1]
localAddress = nil
localPort = 0
case fields[0] == "->":
if len(fields) < 6 {
continue
Expand All @@ -187,6 +199,7 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) {
status = append(status, IPVSBackendStatus{
LocalAddress: localAddress,
LocalPort: localPort,
LocalMark: localMark,
RemoteAddress: remoteAddress,
RemotePort: remotePort,
Proto: proto,
Expand Down
17 changes: 17 additions & 0 deletions ipvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ var (
Weight: 1,
ActiveConn: 1,
InactConn: 1,
{
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,
},
}
)
Expand Down