Skip to content

Commit

Permalink
generic
Browse files Browse the repository at this point in the history
Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg committed Jun 25, 2024
1 parent 668e216 commit 259c371
Show file tree
Hide file tree
Showing 38 changed files with 3,287 additions and 1,346 deletions.
21 changes: 14 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ linters-settings:
lines: 100
statements: 50
gci:
prefix: github.com/np-guard
sections:
- prefix(github.com/np-guard)
goconst:
min-len: 2
min-occurrences: 2
Expand All @@ -29,19 +30,22 @@ linters-settings:
goimports:
local-prefixes: github.com/np-guard
mnd:
ignored-numbers:
- 0,1,2,3
checks:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
ignored-numbers: 0,1,2,3
ignored-functions: strings.SplitN

- argument
- case
- condition
- return
govet:
shadow: true
enable:
- shadow
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand Down Expand Up @@ -132,6 +136,9 @@ issues:
- revive
- goconst
- funlen
- path: ds
linters:
- dupl

run:
timeout: 5m
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fmt:

lint:
@echo -- $@ --
CGO_ENABLED=0 go vet ./...
go vet ./...
golangci-lint run

precommit: mod fmt lint
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# models
A collection of Golang packages with models for connectivity and network resources
A collection of Golang packages with models for cartesian products and network resources

## Packages
* **interval** - A canonical representation of a set of intervals defined over integers
* **ipblock** - A canonical representation of a set of IP ranges. Currently limited to IPv4
* **hypercube** - A canonical representation of a set of n-dimensional hypercubes. All dimensions are defined over integers.
* **netp** - Various structs for representing and handling common network protocols (TCP, UDP, ICMP)
* **connection** - A canonical representation of a set of connections. E.g., for representing all protocols/ports/codes permitted by a given firewall, given a specific source and destination.
* **ds** - A set of generic data structures: maps, sets, and cartesian product of sets.
* **interval** - Interval data structure, and a set implemented using sets of intervals.
* **netp** - Various structs for representing and handling common network protocols (TCP, UDP, ICMP).
* **netset** - Sets of network-related tuples: IP addresses x ports x protocols, etc.
* **connection** - Set of connections. E.g., for representing all protocols/ports/codes permitted by a given firewall, given a specific source and destination.
* **spec** - A collection of structs for defining required connectivity. Automatically generated from a JSON schema (see below).

## Code generation
Expand Down
42 changes: 42 additions & 0 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2023- IBM Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package connection

import (
"github.com/np-guard/models/pkg/netp"
"github.com/np-guard/models/pkg/netset"
)

type Set = netset.TransportSet

func NewTCPorUDP(protocol netp.ProtocolString, srcMinP, srcMaxP, dstMinP, dstMaxP int64) *Set {
return netset.NewTCPorUDPTransport(protocol, srcMinP, srcMaxP, dstMinP, dstMaxP)
}

func AllICMP() *Set {
return netset.AllOrNothingTransport(false, true)
}

func NewTCPSet() *Set {
return NewTCPorUDP(netp.ProtocolStringTCP, netp.MinPort, netp.MaxPort, netp.MinPort, netp.MaxPort)
}

func ICMPConnection(icmpType, icmpCode *int64) (*Set, error) {
icmp, err := netp.ICMPFromTypeAndCode64(icmpType, icmpCode)
if err != nil {
return nil, err
}
return netset.NewICMPTransport(icmp), nil
}

func All() *Set {
return netset.AllTransportSet()
}

func None() *Set {
return netset.AllOrNothingTransport(false, false)
}
Loading

0 comments on commit 259c371

Please sign in to comment.