{"modulePath":"github.com/kernel/hypeman","version":"v0.4.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package network\n\n## Constants\n\n```go\nconst DefaultDownloadBurstMultiplier = 4\n```\nDefaultDownloadBurstMultiplier is the default multiplier for the TBF burst bucket size. A larger bucket allows faster initial burst before settling to sustained rate. Configurable via DOWNLOAD\\_BURST\\_MULTIPLIER environment variable.\n\n```go\nconst DefaultUploadBurstMultiplier = 4\n```\nDefaultUploadBurstMultiplier is the default multiplier applied to guaranteed upload rate to calculate the burst ceiling. This allows VMs to burst above their guaranteed rate when other VMs are not using their full bandwidth allocation. Configurable via UPLOAD\\_BURST\\_MULTIPLIER environment variable.\n\n```go\nconst TAPPrefix = \"hype-\"\n```\nTAPPrefix is the prefix used for hypeman TAP devices\n\n## Variables\n\n```go\nvar (\n\t// ErrNotFound is returned when the default network is not found\n\tErrNotFound = errors.New(\"network not found\")\n\n\t// ErrNameExists is returned when an instance name already exists\n\tErrNameExists = errors.New(\"instance name already exists\")\n)\n```\n\n## Functions\n\n```go\nfunc DeriveGateway(cidr string) (string, error)\n```\nDeriveGateway returns the first usable IP in a subnet (used as gateway). e.g., 10.100.0.0/16 -\u003e 10.100.0.1\n\n```go\nfunc GenerateTAPName(instanceID string) string\n```\nGenerateTAPName generates TAP device name from instance ID. Exported for use by other packages (e.g., vm\\_metrics).\n\n```go\nfunc GuestToGuestEnabled(n *Network) bool\n```\nGuestToGuestEnabled reports whether direct VM-to-VM traffic is permitted on the given network. Hypeman provisions its default networks with per-TAP port isolation (Isolated=true), which blocks direct guest-to-guest traffic. The flag is read from the network rather than assumed so a non-isolated network is reported truthfully.\n\n```go\nfunc NewUniqueMAC(used []string) (string, error)\n```\nNewUniqueMAC returns a locally administered MAC that is not in used. Callers that assign MACs outside the network allocator (macOS vmnet) use it so both paths share one uniqueness rule.\n\n## Types\n\n```go\ntype AllocateRequest struct {\n\tInstanceID    string\n\tInstanceName  string\n\tDownloadBps   int64 // Download rate limit in bytes/sec (external→VM, TAP egress TBF)\n\tUploadBps     int64 // Upload rate limit in bytes/sec (VM→external, HTB class rate)\n\tUploadCeilBps int64 // Upload ceiling in bytes/sec (HTB burst when bandwidth available, 0 = same as UploadBps)\n}\n```\nAllocateRequest is the request to allocate network for an instance Always allocates from the default network\n\n```go\ntype Allocation struct {\n\tInstanceID   string\n\tInstanceName string\n\tNetwork      string\n\tIP           string\n\tMAC          string\n\tTAPDevice    string\n\tGateway      string // Gateway IP for this network\n\tNetmask      string // Netmask in dotted decimal notation\n\tDNS          string // DNS server for guest configuration\n\tState        string // \"running\", \"standby\" (derived from CH or snapshot)\n\tClassID      string // HTB class ID actually assigned (may differ from deriveClassID if collision occurred)\n}\n```\nAllocation represents a network allocation for an instance\n\n```go\ntype Manager interface {\n\t// Lifecycle\n\tInitialize(ctx context.Context, runningInstanceIDs []string) error\n\n\t// Instance allocation operations (called by instance manager)\n\tCreateAllocation(ctx context.Context, req AllocateRequest) (*NetworkConfig, error)\n\tRecreateAllocation(ctx context.Context, instanceID string, downloadBps, uploadBps int64) error\n\tReleaseAllocation(ctx context.Context, alloc *Allocation) error\n\t// ReleaseByInstanceID is a best-effort cleanup fallback when the full Allocation\n\t// can't be derived (e.g. metadata read failed). Deletes the TAP device using the\n\t// deterministic name from the instance ID.\n\tReleaseByInstanceID(ctx context.Context, instanceID string) error\n\n\t// SetupHTB initializes HTB qdisc on the bridge for upload fair sharing.\n\t// Should be called during network initialization with the total network capacity.\n\tSetupHTB(ctx context.Context, capacityBps int64) error\n\n\t// Queries (derive from CH/snapshots)\n\tGetAllocation(ctx context.Context, instanceID string) (*Allocation, error)\n\tListAllocations(ctx context.Context) ([]Allocation, error)\n\tNameExists(ctx context.Context, name string, excludeInstanceID string) (bool, error)\n\t// EffectiveDefaultNetwork returns the platform backend's default network.\n\t// Before Initialize it returns the network the backend will create or attach;\n\t// after Initialize it returns the backend state cached by the manager.\n\tEffectiveDefaultNetwork() (*Network, error)\n\n\t// CleanupOrphanedTAPs removes TAP devices not associated with any preserved\n\t// instance. Pass minAge\u003e0 to skip TAPs younger than that, which avoids racing\n\t// against in-flight CreateAllocation calls whose metadata hasn't been persisted.\n\tCleanupOrphanedTAPs(ctx context.Context, preserveInstanceIDs []string, minAge time.Duration) int\n\n\t// CleanupOrphanedClasses removes bridge tc filters/classes not referenced by\n\t// a live TAP's filter.\n\tCleanupOrphanedClasses(ctx context.Context) int\n\n\t// GetUploadBurstMultiplier returns the configured multiplier for upload burst ceiling.\n\tGetUploadBurstMultiplier() int\n\n\t// GetDownloadBurstMultiplier returns the configured multiplier for download burst bucket.\n\tGetDownloadBurstMultiplier() int\n}\n```\nManager defines the interface for network management\n\n```go\nfunc NewManager(p *paths.Paths, cfg *config.Config, meter metric.Meter) Manager\n```\nNewManager creates a new network manager. If meter is nil, metrics are disabled.\n\n```go\ntype Metrics struct {\n\t// contains filtered or unexported fields\n}\n```\nMetrics holds the metrics instruments for network operations.\n\n```go\ntype Model string\n```\nModel identifies the guest networking model a host provides. Each platform backend returns its model from NetworkModel; API layers map it onto their own wire enums so this package stays free of API dependencies.\n\n```go\nconst (\n\t// ModelBridge is a Linux bridge with per-VM TAP devices.\n\tModelBridge Model = \"bridge\"\n\t// ModelNAT is hypervisor-provided NAT (Virtualization.framework on macOS).\n\tModelNAT Model = \"nat\"\n)\n```\n\n```go\nfunc NetworkModel() Model\n```\nNetworkModel identifies the guest networking model in use on this host. Linux hosts use a bridge with per-VM TAP devices.\n\n```go\ntype Network struct {\n\tName      string // \"default\", \"internal\"\n\tSubnet    string // \"192.168.0.0/16\"\n\tGateway   string // \"192.168.0.1\"\n\tBridge    string // \"vmbr0\" (derived from kernel)\n\tIsolated  bool   // Bridge_slave isolation mode\n\tDefault   bool   // True for default network\n\tCreatedAt time.Time\n}\n```\nNetwork represents a virtual network for instances\n\n```go\ntype NetworkConfig struct {\n\tIP        string\n\tMAC       string\n\tGateway   string\n\tNetmask   string\n\tDNS       string\n\tTAPDevice string\n}\n```\nNetworkConfig is the configuration returned after allocation\n\n","path":"github.com/kernel/hypeman/lib/network","name":"network","synopsis":"","isRedistributable":true}
