func unpackDest(service Service, attrs nlgo.AttrMap) (Dest, error) { var dest Dest var addr []byte for _, attr := range attrs.Slice() { switch attr.Field() { case IPVS_DEST_ATTR_ADDR: addr = ([]byte)(attr.Value.(nlgo.Binary)) case IPVS_DEST_ATTR_PORT: dest.Port = unpackPort(attr.Value.(nlgo.U16)) case IPVS_DEST_ATTR_FWD_METHOD: dest.FwdMethod = (FwdMethod)(attr.Value.(nlgo.U32)) case IPVS_DEST_ATTR_WEIGHT: dest.Weight = (uint32)(attr.Value.(nlgo.U32)) case IPVS_DEST_ATTR_U_THRESH: dest.UThresh = (uint32)(attr.Value.(nlgo.U32)) case IPVS_DEST_ATTR_L_THRESH: dest.LThresh = (uint32)(attr.Value.(nlgo.U32)) case IPVS_DEST_ATTR_ACTIVE_CONNS: dest.ActiveConns = (uint32)(attr.Value.(nlgo.U32)) case IPVS_DEST_ATTR_INACT_CONNS: dest.InactConns = (uint32)(attr.Value.(nlgo.U32)) case IPVS_DEST_ATTR_PERSIST_CONNS: dest.PersistConns = (uint32)(attr.Value.(nlgo.U32)) } } if addrIP, err := unpackAddr(addr, service.Af); err != nil { return dest, fmt.Errorf("ipvs:Dest.unpack: addr: %s", err) } else { dest.Addr = addrIP } return dest, nil }
func unpackInfo(attrs nlgo.AttrMap) (info Info, err error) { for _, attr := range attrs.Slice() { switch attr.Field() { case IPVS_INFO_ATTR_VERSION: info.Version = (Version)(attr.Value.(nlgo.U32)) case IPVS_INFO_ATTR_CONN_TAB_SIZE: info.ConnTabSize = (uint32)(attr.Value.(nlgo.U32)) } } return }
func unpackService(attrs nlgo.AttrMap) (Service, error) { var service Service var addr nlgo.Binary var flags nlgo.Binary for _, attr := range attrs.Slice() { switch attr.Field() { case IPVS_SVC_ATTR_AF: service.Af = (Af)(attr.Value.(nlgo.U16)) case IPVS_SVC_ATTR_PROTOCOL: service.Protocol = (Protocol)(attr.Value.(nlgo.U16)) case IPVS_SVC_ATTR_ADDR: addr = attr.Value.(nlgo.Binary) case IPVS_SVC_ATTR_PORT: service.Port = unpackPort(attr.Value.(nlgo.U16)) case IPVS_SVC_ATTR_FWMARK: service.FwMark = (uint32)(attr.Value.(nlgo.U32)) case IPVS_SVC_ATTR_SCHED_NAME: service.SchedName = (string)(attr.Value.(nlgo.NulString)) case IPVS_SVC_ATTR_FLAGS: flags = attr.Value.(nlgo.Binary) case IPVS_SVC_ATTR_TIMEOUT: service.Timeout = (uint32)(attr.Value.(nlgo.U32)) case IPVS_SVC_ATTR_NETMASK: service.Netmask = (uint32)(attr.Value.(nlgo.U32)) } } if addrIP, err := unpackAddr(addr, service.Af); err != nil { return service, fmt.Errorf("ipvs:Service.unpack: addr: %s", err) } else { service.Addr = addrIP } if err := unpack(flags, &service.Flags); err != nil { return service, fmt.Errorf("ipvs:Service.unpack: flags: %s", err) } return service, nil }