File: ip_configuration.go

package info (click to toggle)
vip-manager 1.0.2-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 444 kB
  • sloc: sh: 312; makefile: 41
file content (29 lines) | stat: -rw-r--r-- 565 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package ipmanager

import (
	"fmt"
	"net"
	"net/netip"
)

// IPConfiguration holds the configuration for VIP manager
type IPConfiguration struct {
	VIP        netip.Addr
	Netmask    net.IPMask
	Iface      net.Interface
	RetryNum   int
	RetryAfter int
}

// getCIDR returns the CIDR composed from the given address and mask
func (c *IPConfiguration) getCIDR() string {
	return fmt.Sprintf("%s/%d", c.VIP.String(), netmaskSize(c.Netmask))
}

func netmaskSize(mask net.IPMask) int {
	ones, bits := mask.Size()
	if bits == 0 {
		panic("Invalid mask")
	}
	return ones
}