-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
350 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package types | ||
|
||
type CliOpts struct { | ||
LogLevel int | ||
MaxWorkers int | ||
CidrRange string | ||
Nameserver string | ||
Nameport int | ||
Timeout float32 | ||
Mode string | ||
Zone string | ||
Proto string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"time" | ||
|
||
"github.com/miekg/dns" | ||
) | ||
|
||
type QueryResult struct { | ||
Answers []dns.RR | ||
Additional []dns.RR | ||
Raw *dns.Msg | ||
IP *net.IP | ||
RTT *time.Duration | ||
} | ||
|
||
type SvcResult struct { | ||
Name string | ||
Namespace string | ||
IP *net.IP | ||
Ports []*PortResult | ||
Endpoints []*PodResult | ||
} | ||
|
||
func (s *SvcResult) String() string { return fmt.Sprintf("%s/%s", s.Namespace, s.Name) } | ||
|
||
type PodResult struct { | ||
Name string | ||
Namespace string | ||
IP *net.IP | ||
Ports []*PortResult | ||
} | ||
|
||
type PortResult struct { | ||
Proto string | ||
PortNo int | ||
PortName string | ||
} | ||
|
||
func (p *PortResult) String() string { return fmt.Sprintf("%d/%s", p.PortNo, p.Proto) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package util | ||
|
||
func Reverse(numbers []string) []string { | ||
newNumbers := make([]string, len(numbers)) | ||
for i, j := 0, len(numbers)-1; i <= j; i, j = i+1, j-1 { | ||
newNumbers[i], newNumbers[j] = numbers[j], numbers[i] | ||
} | ||
return newNumbers | ||
} | ||
|
||
func IsElement(s []string, str string) bool { | ||
for _, v := range s { | ||
if v == str { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/seancfoley/ipaddress-go/ipaddr" | ||
"github.com/seancfoley/ipaddress-go/ipaddr/addrstrparam" | ||
) | ||
|
||
func ParseIPv4CIDR(cidr string) (*ipaddr.IPAddress, error) { | ||
pb := addrstrparam.IPAddressStringParamsBuilder{} | ||
pb.AllowWildcardedSeparator(true) | ||
pb.AllowIPv4(true) | ||
pb.AllowIPv6(false) | ||
pb.AllowMask(true) | ||
pb.AllowPrefix(true) | ||
pb.AllowEmpty(false) | ||
pb.AllowSingleSegment(false) | ||
params := pb.ToParams() | ||
|
||
ipastr := ipaddr.NewIPAddressStringParams(cidr, params) | ||
|
||
if !ipastr.IsPrefixed() { | ||
return nil, fmt.Errorf("CIDR %s requires prefix, use /32 for a single host", cidr) | ||
} | ||
|
||
subnet, err := ipastr.ToAddress() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return subnet.ToPrefixBlock(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package util | ||
|
||
import "github.com/jpts/coredns-enum/internal/types" | ||
|
||
type SortByNsName []*types.SvcResult | ||
|
||
func (a SortByNsName) Len() int { return len(a) } | ||
|
||
func (a SortByNsName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | ||
|
||
func (a SortByNsName) Less(i, j int) bool { | ||
if a[i].Namespace == a[j].Namespace { | ||
return a[i].Name < a[j].Name | ||
} | ||
return a[i].Namespace < a[j].Namespace | ||
} |
Oops, something went wrong.