cidr

package
v2.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cidr provides utilities for working with CIDR blocks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIPv4Cidrs

func GetIPv4Cidrs(cidrs []string) ([]string, error)

GetIPv4Cidrs gets the IPv4 CIDRs from a string slice.

func GetIPv6Cidrs

func GetIPv6Cidrs(cidrs []string) ([]string, error)

GetIPv6Cidrs gets the IPv6 CIDRs from a string slice.

func SplitIntoSubnetsIPv4

func SplitIntoSubnetsIPv4(cidrBlock string, numSubnets int) ([]*net.IPNet, error)

SplitIntoSubnetsIPv4 splits a IPv4 CIDR into a specified number of subnets. If the number of required subnets isn't a power of 2 then CIDR will be split into the next highest power of 2, and you will end up with unused ranges. NOTE: this code is adapted from kops https://github.com/kubernetes/kops/blob/c323819e6480d71bad8d21184516e3162eaeca8f/pkg/util/subnet/subnet.go#L46

func SplitIntoSubnetsIPv6

func SplitIntoSubnetsIPv6(cidrBlock string, numSubnets int) ([]*net.IPNet, error)

SplitIntoSubnetsIPv6 splits a IPv6 address into a specified number of subnets. AWS IPv6 based subnets **must always have a /64 prefix**. AWS provides an IPv6 CIDR with /56 prefix. That's the initial CIDR. We must convert that to /64 and slice the subnets by increasing the subnet ID by 1. so given: 2600:1f14:e08:7400::/56 sub1: 2600:1f14:e08:7400::/64 sub2: 2600:1f14:e08:7401::/64 sub3: 2600:1f14:e08:7402::/64 sub4: 2600:1f14:e08:7403::/64 This function can also be called with /64 prefix to further slice existing subnet addresses. When splitting further, we always have to take the LAST one to avoid collisions since the prefix stays the same, but the subnet ID increases. To see this restriction read https://docs.aws.amazon.com/vpc/latest/userguide/how-it-works.html#ipv4-ipv6-comparison

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL