Skip to content
Merged
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
22 changes: 22 additions & 0 deletions netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,17 @@ func assembleService(attrs []syscall.NetlinkRouteAttr) (*Service, error) {

}

// in older kernels (< 3.18), the svc address family attribute may not exist so we must
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this is only an issue for destination addresses since IPVS_DEST_ATTR_ADDR_FAMILY was added later while IPVS_SVC_ATTR_AF had always existed, but this extra check doesn't seem to hurt.

// assume it based on the svc address provided.
if s.AddressFamily == 0 {
addr := (net.IP)(addressBytes)
if addr.To4() != nil {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In running a few more tests, I realized this won't work because To4() checks the last 4 bytes for v4 addresses and leading 0 but netlink returns IPv4 addresses in the first 4 bytes.

Will follow-up with a fix.

s.AddressFamily = syscall.AF_INET
} else {
s.AddressFamily = syscall.AF_INET6
}
}

// parse Address after parse AddressFamily incase of parseIP error
if addressBytes != nil {
ip, err := parseIP(addressBytes, s.AddressFamily)
Expand Down Expand Up @@ -458,6 +469,17 @@ func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error)
}
}

// in older kernels (< 3.18), the destination address family attribute doesn't exist so we must
// assume it based on the destination address provided.
if d.AddressFamily == 0 {
addr := (net.IP)(addressBytes)
if addr.To4() != nil {
d.AddressFamily = syscall.AF_INET
} else {
d.AddressFamily = syscall.AF_INET6
}
}

// parse Address after parse AddressFamily incase of parseIP error
if addressBytes != nil {
ip, err := parseIP(addressBytes, d.AddressFamily)
Expand Down