|
@@ -1,5 +1,3 @@
|
|
|
-// +build linux
|
|
|
-
|
|
|
package ipvs
|
|
|
|
|
|
import (
|
|
@@ -124,8 +122,8 @@ func (i *Handle) doCmdwithResponse(s *Service, d *Destination, cmd uint8) ([][]b
|
|
|
req.Seq = atomic.AddUint32(&i.seq, 1)
|
|
|
|
|
|
if s == nil {
|
|
|
- req.Flags |= syscall.NLM_F_DUMP //Flag to dump all messages
|
|
|
- req.AddData(nl.NewRtAttr(ipvsCmdAttrService, nil)) //Add a dummy attribute
|
|
|
+ req.Flags |= syscall.NLM_F_DUMP // Flag to dump all messages
|
|
|
+ req.AddData(nl.NewRtAttr(ipvsCmdAttrService, nil)) // Add a dummy attribute
|
|
|
} else {
|
|
|
req.AddData(fillService(s))
|
|
|
}
|
|
@@ -134,7 +132,6 @@ func (i *Handle) doCmdwithResponse(s *Service, d *Destination, cmd uint8) ([][]b
|
|
|
if cmd == ipvsCmdGetDest {
|
|
|
req.Flags |= syscall.NLM_F_DUMP
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
req.AddData(fillDestination(d))
|
|
|
}
|
|
@@ -259,7 +256,6 @@ done:
|
|
|
}
|
|
|
|
|
|
func parseIP(ip []byte, family uint16) (net.IP, error) {
|
|
|
-
|
|
|
var resIP net.IP
|
|
|
|
|
|
switch family {
|
|
@@ -276,7 +272,6 @@ func parseIP(ip []byte, family uint16) (net.IP, error) {
|
|
|
|
|
|
// parseStats
|
|
|
func assembleStats(msg []byte) (SvcStats, error) {
|
|
|
-
|
|
|
var s SvcStats
|
|
|
|
|
|
attrs, err := nl.ParseRouteAttr(msg)
|
|
@@ -314,7 +309,6 @@ func assembleStats(msg []byte) (SvcStats, error) {
|
|
|
|
|
|
// assembleService assembles a services back from a hain of netlink attributes
|
|
|
func assembleService(attrs []syscall.NetlinkRouteAttr) (*Service, error) {
|
|
|
-
|
|
|
var s Service
|
|
|
var addressBytes []byte
|
|
|
|
|
@@ -366,10 +360,9 @@ func assembleService(attrs []syscall.NetlinkRouteAttr) (*Service, error) {
|
|
|
|
|
|
// parseService given a ipvs netlink response this function will respond with a valid service entry, an error otherwise
|
|
|
func (i *Handle) parseService(msg []byte) (*Service, error) {
|
|
|
-
|
|
|
var s *Service
|
|
|
|
|
|
- //Remove General header for this message and parse the NetLink message
|
|
|
+ // Remove General header for this message and parse the NetLink message
|
|
|
hdr := deserializeGenlMsg(msg)
|
|
|
NetLinkAttrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
|
|
|
if err != nil {
|
|
@@ -379,13 +372,13 @@ func (i *Handle) parseService(msg []byte) (*Service, error) {
|
|
|
return nil, fmt.Errorf("error no valid netlink message found while parsing service record")
|
|
|
}
|
|
|
|
|
|
- //Now Parse and get IPVS related attributes messages packed in this message.
|
|
|
+ // Now Parse and get IPVS related attributes messages packed in this message.
|
|
|
ipvsAttrs, err := nl.ParseRouteAttr(NetLinkAttrs[0].Value)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- //Assemble all the IPVS related attribute messages and create a service record
|
|
|
+ // Assemble all the IPVS related attribute messages and create a service record
|
|
|
s, err = assembleService(ipvsAttrs)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
@@ -422,7 +415,6 @@ func (i *Handle) doCmdWithoutAttr(cmd uint8) ([][]byte, error) {
|
|
|
}
|
|
|
|
|
|
func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error) {
|
|
|
-
|
|
|
var d Destination
|
|
|
var addressBytes []byte
|
|
|
|
|
@@ -486,9 +478,12 @@ func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error)
|
|
|
|
|
|
// getIPFamily parses the IP family based on raw data from netlink.
|
|
|
// For AF_INET, netlink will set the first 4 bytes with trailing zeros
|
|
|
-// 10.0.0.1 -> [10 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0]
|
|
|
+//
|
|
|
+// 10.0.0.1 -> [10 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0]
|
|
|
+//
|
|
|
// For AF_INET6, the full 16 byte array is used:
|
|
|
-// 2001:db8:3c4d:15::1a00 -> [32 1 13 184 60 77 0 21 0 0 0 0 0 0 26 0]
|
|
|
+//
|
|
|
+// 2001:db8:3c4d:15::1a00 -> [32 1 13 184 60 77 0 21 0 0 0 0 0 0 26 0]
|
|
|
func getIPFamily(address []byte) (uint16, error) {
|
|
|
if len(address) == 4 {
|
|
|
return syscall.AF_INET, nil
|
|
@@ -519,7 +514,7 @@ func isZeros(b []byte) bool {
|
|
|
func (i *Handle) parseDestination(msg []byte) (*Destination, error) {
|
|
|
var dst *Destination
|
|
|
|
|
|
- //Remove General header for this message
|
|
|
+ // Remove General header for this message
|
|
|
hdr := deserializeGenlMsg(msg)
|
|
|
NetLinkAttrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
|
|
|
if err != nil {
|
|
@@ -529,13 +524,13 @@ func (i *Handle) parseDestination(msg []byte) (*Destination, error) {
|
|
|
return nil, fmt.Errorf("error no valid netlink message found while parsing destination record")
|
|
|
}
|
|
|
|
|
|
- //Now Parse and get IPVS related attributes messages packed in this message.
|
|
|
+ // Now Parse and get IPVS related attributes messages packed in this message.
|
|
|
ipvsAttrs, err := nl.ParseRouteAttr(NetLinkAttrs[0].Value)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- //Assemble netlink attributes and create a Destination record
|
|
|
+ // Assemble netlink attributes and create a Destination record
|
|
|
dst, err = assembleDestination(ipvsAttrs)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
@@ -546,7 +541,6 @@ func (i *Handle) parseDestination(msg []byte) (*Destination, error) {
|
|
|
|
|
|
// doGetDestinationsCmd a wrapper function to be used by GetDestinations and GetDestination(d) apis
|
|
|
func (i *Handle) doGetDestinationsCmd(s *Service, d *Destination) ([]*Destination, error) {
|
|
|
-
|
|
|
var res []*Destination
|
|
|
|
|
|
msgs, err := i.doCmdwithResponse(s, d, ipvsCmdGetDest)
|
|
@@ -568,7 +562,7 @@ func (i *Handle) doGetDestinationsCmd(s *Service, d *Destination) ([]*Destinatio
|
|
|
func (i *Handle) parseConfig(msg []byte) (*Config, error) {
|
|
|
var c Config
|
|
|
|
|
|
- //Remove General header for this message
|
|
|
+ // Remove General header for this message
|
|
|
hdr := deserializeGenlMsg(msg)
|
|
|
attrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
|
|
|
if err != nil {
|