Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: c-robinson/iplib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.1
Choose a base ref
...
head repository: c-robinson/iplib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.2
Choose a head ref
  • 1 commit
  • 18 files changed
  • 1 contributor

Commits on Dec 30, 2023

  1. post 2.0.0 fixes (#16)

    * ...aaaaaaand update doc references as well
    
    * it is not obvious how go.mod should work for submods
    
    * v2 before submodule name in replace
    
    * fix docs for new go.mod approach
    
    * add benchmark for enumerate
    
    * make sure all the addresses are actually present
    
    * add linefeed at end to avoid go test error
    
    * race detector didnt like var re-use
    
    * fixes for 'golangci-lint run'
    
    * swap over from circleci/coveralls to actions
    
    * update readme's for new test badges
    
    * explicitly pick a golangci action version
    c-robinson authored Dec 30, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    808dd52 View commit details
Showing with 155 additions and 84 deletions.
  1. +0 −23 .circleci/config.yml
  2. +96 −0 .github/workflows/test.yml
  3. +2 −3 README.md
  4. +5 −0 go.mod
  5. +2 −3 hostmask.go
  6. +3 −4 iana/README.md
  7. +0 −5 iana/go.mod
  8. +0 −1 iana/go.sum
  9. +3 −3 iana/iana.go
  10. +3 −4 iid/README.md
  11. +0 −5 iid/go.mod
  12. +0 −1 iid/go.sum
  13. +3 −12 iplib.go
  14. +11 −2 iplib_bench_test.go
  15. +3 −6 net.go
  16. +5 −0 net4_test.go
  17. +14 −12 net6.go
  18. +5 −0 net6_test.go
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/golangci-lint-action@v3.7.0
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
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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)
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)
@@ -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
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
@@ -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
}
}
@@ -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
}
}
@@ -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
}
}
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
@@ -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
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
@@ -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
@@ -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
}
@@ -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
@@ -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
@@ -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")
}
}

@@ -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
@@ -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
@@ -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
@@ -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)
}
}
}
}

Loading