Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post 2.0.0 fixes #16

Merged
merged 12 commits into from
Dec 30, 2023
23 changes: 0 additions & 23 deletions .circleci/config.yml

This file was deleted.

96 changes: 96 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Test

on:
push:
pull_request:
workflow_dispatch:

env:
GO111MODULE: on

permissions:
contents: read

jobs:
golangci-lint:
permissions:
contents: read
pull-requests: read
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '^1.20'
check-latest: true
cache: true

- uses: golangci/[email protected]
with:
version: latest
args: --verbose


test-unix:
strategy:
fail-fast: false
matrix:
platform:
- ubuntu
- macOS
go:
- 20
- 21
name: '${{ matrix.platform }} | 1.${{ matrix.go }}.x'
runs-on: ${{ matrix.platform }}-latest
steps:

- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: 1.${{ matrix.go }}.x
cache: true

- run: |
export GOBIN=$HOME/go/bin
go install github.com/kyoh86/richgo@latest
- run: RICHGO_FORCE_COLOR=1 PATH=$HOME/go/bin/:$PATH richgo test -v -race ./...


test-win:
name: MINGW64
defaults:
run:
shell: msys2 {0}
runs-on: windows-latest
steps:

- shell: bash
run: git config --global core.autocrlf input

- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >
git
make
unzip
mingw-w64-x86_64-go

- uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-${{ matrix.go }}-

- run: |
export GOBIN=$HOME/go/bin
go install github.com/kyoh86/richgo@latest

- run: RICHGO_FORCE_COLOR=1 PATH=$HOME/go/bin/:$PATH richgo test -v ./...
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# IPLib
[![Documentation](https://godoc.org/github.com/c-robinson/iplib?status.svg)](http://godoc.org/github.com/c-robinson/iplib)
[![CircleCI](https://circleci.com/gh/c-robinson/iplib/tree/main.svg?style=svg)](https://circleci.com/gh/c-robinson/iplib/tree/main)
[![Documentation](https://godoc.org/github.com/c-robinson/iplib?status.svg)](https://pkg.go.dev/github.com/c-robinson/iplib/v2)
[![Go Report Card](https://goreportcard.com/badge/github.com/c-robinson/iplib)](https://goreportcard.com/report/github.com/c-robinson/iplib)
[![Coverage Status](https://coveralls.io/repos/github/c-robinson/iplib/badge.svg?branch=main)](https://coveralls.io/github/c-robinson/iplib?branch=main)
[![Tests](https://img.shields.io/github/actions/workflow/status/c-robinson/iplib/test.yml?branch=main&longCache=true&label=Test&logo=github%20actions&logoColor=fff)](https://github.com/c-robinson/iplib/actions?query=workflow%3ATest)

**ATTENTION** version 2.0.0 is a breaking change from previous versions for
handling IPv6 addresses (functions for IPv4 are unchanged). Calls that result
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ module github.com/c-robinson/iplib/v2

go 1.20

replace (
github.com/c-robinson/iplib/v2/iana => ./iana
github.com/c-robinson/iplib/v2/iid => ./iid
)

require lukechampine.com/uint128 v1.3.0
5 changes: 2 additions & 3 deletions hostmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ func decrementBoundaryByte(bb, bv byte, count uint128.Uint128) (uint128.Uint128,
byteMax := uint128.From64(256 - uint64(bb)) // max value of unmasked bits in the byte
byteVal := uint128.From64(uint64(bv)) // cur value of unmasked bits in the byte

mod := uint128.New(0, 0)

var mod uint128.Uint128
count, mod = count.QuoRem(byteMax)

// extract the actual modulus into bmod
Expand Down Expand Up @@ -342,7 +341,7 @@ func incrementBoundaryByte(bb, bv byte, count uint128.Uint128) (uint128.Uint128,
return uint128.Uint128{}, byte(count.Lo)
}

mod := uint128.New(0, 0)
var mod uint128.Uint128
count, mod = count.QuoRem(byteMax)
rb := make([]byte, 16)
mod.PutBytesBE(rb)
Expand Down
7 changes: 3 additions & 4 deletions iana/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# iana
[![Documentation](https://godoc.org/github.com/c-robinson/iplib?status.svg)](http://godoc.org/github.com/c-robinson/iplib/iana)
[![CircleCI](https://circleci.com/gh/c-robinson/iplib/tree/main.svg?style=svg)](https://circleci.com/gh/c-robinson/iplib/tree/main)
[![Documentation](https://godoc.org/github.com/c-robinson/iplib?status.svg)](http://godoc.org/github.com/c-robinson/iplib/v2/iana)
[![Go Report Card](https://goreportcard.com/badge/github.com/c-robinson/iplib)](https://goreportcard.com/report/github.com/c-robinson/iplib)
[![Coverage Status](https://coveralls.io/repos/github/c-robinson/iplib/badge.svg?branch=main)](https://coveralls.io/github/c-robinson/iplib?branch=main)
[![Tests](https://img.shields.io/github/actions/workflow/status/c-robinson/iplib/test.yml?branch=main&longCache=true&label=Test&logo=github%20actions&logoColor=fff)](https://github.com/c-robinson/iplib/actions?query=workflow%3ATest)

This package imports the [Internet Assigned Number Authority (IANA)](https://www.iana.org/)
Special IP Address Registry for [IPv4](https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml)
Expand All @@ -14,7 +13,7 @@ are contained within an reserved IP address block.
## Installing

```sh
go get -u github.com/c-robinson/iplib/v2/iana
go get -u github.com/c-robinson/iplib/v2
```

## Using IANA
Expand Down
5 changes: 0 additions & 5 deletions iana/go.mod

This file was deleted.

1 change: 0 additions & 1 deletion iana/go.sum

This file was deleted.

6 changes: 3 additions & 3 deletions iana/iana.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func GetRFCsForNetwork(n iplib.Net) []string {
func IsForwardable(n iplib.Net) bool {
reservations := GetReservationsForNetwork(n)
for _, r := range reservations {
if r.Forwardable == false {
if !r.Forwardable {
return false
}
}
Expand All @@ -187,7 +187,7 @@ func IsForwardable(n iplib.Net) bool {
func IsGlobal(n iplib.Net) bool {
reservations := GetReservationsForNetwork(n)
for _, r := range reservations {
if r.Global == false {
if !r.Global {
return false
}
}
Expand All @@ -203,7 +203,7 @@ func IsGlobal(n iplib.Net) bool {
func IsReserved(n iplib.Net) bool {
reservations := GetReservationsForNetwork(n)
for _, r := range reservations {
if r.Reserved == true {
if r.Reserved {
return true
}
}
Expand Down
7 changes: 3 additions & 4 deletions iid/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# iid
[![Documentation](https://godoc.org/github.com/c-robinson/iplib?status.svg)](http://godoc.org/github.com/c-robinson/iplib/iid)
[![CircleCI](https://circleci.com/gh/c-robinson/iplib/tree/main.svg?style=svg)](https://circleci.com/gh/c-robinson/iplib/tree/main)
[![Documentation](https://godoc.org/github.com/c-robinson/iplib?status.svg)](http://godoc.org/github.com/c-robinson/iplib/v2/iid)
[![Go Report Card](https://goreportcard.com/badge/github.com/c-robinson/iplib)](https://goreportcard.com/report/github.com/c-robinson/iplib)
[![Coverage Status](https://coveralls.io/repos/github/c-robinson/iplib/badge.svg?branch=main)](https://coveralls.io/github/c-robinson/iplib?branch=main)
[![Tests](https://img.shields.io/github/actions/workflow/status/c-robinson/iplib/test.yml?branch=main&longCache=true&label=Test&logo=github%20actions&logoColor=fff)](https://github.com/c-robinson/iplib/actions?query=workflow%3ATest)

This package implements functions for generating and validating IPv6 Interface
Identifiers (IID's) for use in link-local, global unicast and Stateless Address
Expand All @@ -13,7 +12,7 @@ given interface on a network, and is unique _within_ that network.
## Installing

```sh
go get -u github.com/c-robinson/iplib/v2/iid
go get -u github.com/c-robinson/iplib/v2
```

## Using IID
Expand Down
5 changes: 0 additions & 5 deletions iid/go.mod

This file was deleted.

1 change: 0 additions & 1 deletion iid/go.sum

This file was deleted.

15 changes: 3 additions & 12 deletions iplib.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ func (bi ByIP) Swap(a, b int) {
// implementation, see CompareIPs()
func (bi ByIP) Less(a, b int) bool {
val := CompareIPs(bi[a], bi[b])
if val == -1 {
return true
}
return false
return val == -1
}

// ARPAToIP takes a strings containing an ARPA domain and returns the
Expand Down Expand Up @@ -191,8 +188,7 @@ func CompareNets(a, b Net) int {
// CopyIP creates a new net.IP object containing the same data as the supplied
// net.IP (e.g. creates a new array and duplicates the contents)
func CopyIP(ip net.IP) net.IP {
var xip []byte
xip = make([]byte, len(ip))
xip := make([]byte, len(ip))
copy(xip, ip)
return xip
}
Expand Down Expand Up @@ -323,7 +319,7 @@ func ForceIP4(ip net.IP) net.IP {
// or ':'
func HexStringToIP(s string) net.IP {
normalize := func(c rune) rune {
if strings.IndexRune(":.", c) == -1 {
if !strings.ContainsRune(":.", c) {
return c
}
return -1
Expand Down Expand Up @@ -603,8 +599,3 @@ func generateNetLimits(version int, filler byte) net.IP {
}
return b
}

func getCloneBigInt(z *big.Int) *big.Int {
nz := new(big.Int)
return nz.Set(z)
}
13 changes: 11 additions & 2 deletions iplib_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

func BenchmarkParseCIDR4(b *testing.B) {
for i := 0; i < b.N; i++ {
ParseCIDR("10.0.0.0/24")
_, _, _ = ParseCIDR("10.0.0.0/24")
}
}

func BenchmarkParseCIDR6(b *testing.B) {
for i := 0; i < b.N; i++ {
ParseCIDR("2001:db8::/98")
_, _, _ = ParseCIDR("2001:db8::/98")
}
}

Expand Down Expand Up @@ -271,3 +271,12 @@ func BenchmarkNet6_NextIPWithinHostmask(b *testing.B) {
xip, _ = NextIP6WithinHostmask(xip, hm)
}
}

func BenchmarkNet6_Enumerate(b *testing.B) {
_, n, _ := ParseCIDR("2001:db8::/98")
n6 := n.(Net6)
b.ResetTimer()
for i := 0; i < b.N; i++ {
n6.Enumerate(8192, 1024)
}
}
9 changes: 3 additions & 6 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ func (bn ByNet) Swap(a, b int) {
// implementation, see CompareNets()
func (bn ByNet) Less(a, b int) bool {
val := CompareNets(bn[a], bn[b])
if val == -1 {
return true
}
return false
return val == -1
}

// ParseCIDR returns a new Net object. It is a passthrough to net.ParseCIDR
Expand Down Expand Up @@ -111,5 +108,5 @@ func fitNetworkBetween(a, b net.IP, mask int) (Net, bool, error) {
if va == 0 && vb == 0 {
return xnet, true, nil
}
return fitNetworkBetween(a, b, mask + 1)
}
return fitNetworkBetween(a, b, mask+1)
}
5 changes: 5 additions & 0 deletions net4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ func TestNet4_Enumerate(t *testing.T) {
if x != 0 {
t.Errorf("[%d] want last address %s, got %s", i, tt.last, addrlist[tt.total-1])
}
for ii, a := range addrlist {
if a == nil {
t.Errorf("[%d] address %d is nil", i, ii)
}
}
}
}

Expand Down
Loading
Loading