Skip to content

Commit

Permalink
added TransportFromProtocolSets funcs (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
YairSlobodin1 authored Jan 7, 2025
1 parent cd12519 commit da5d10b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/netset/icmpset.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ func NewICMPSet(minType, maxType, minCode, maxCode int64) *ICMPSet {
)
}

func ICMPSetFromICMP(icmp netp.ICMP) *ICMPSet {
if icmp.TypeCode == nil {
return AllICMPSet()
}
icmpType := int64(icmp.TypeCode.Type)
if icmp.TypeCode.Code == nil {
return NewICMPSet(icmpType, icmpType, int64(netp.MinICMPCode), int64(netp.MaxICMPCode))
}
icmpCode := int64(*icmp.TypeCode.Code)
return NewICMPSet(icmpType, icmpType, icmpCode, icmpCode)
}

func EmptyICMPSet() *ICMPSet {
return &ICMPSet{props: ds.NewProductLeft[*TypeSet, *CodeSet]()}
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/netset/transportset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,27 @@ func NewUDPTransport(srcMinP, srcMaxP, dstMinP, dstMaxP int64) *TransportSet {
return NewTCPorUDPTransport(netp.ProtocolStringUDP, srcMinP, srcMaxP, dstMinP, dstMaxP)
}

func NewICMPTransportFromICMPSet(icmpSet *ICMPSet) *TransportSet {
return &TransportSet{ds.NewDisjoint(
EmptyTCPorUDPSet(),
icmpSet.Copy(),
)}
}

func NewICMPTransport(minType, maxType, minCode, maxCode int64) *TransportSet {
return &TransportSet{ds.NewDisjoint(
EmptyTCPorUDPSet(),
NewICMPSet(minType, maxType, minCode, maxCode),
)}
}

func NewTCPUDPTransportFromTCPUDPSet(tcpudpSet *TCPUDPSet) *TransportSet {
return &TransportSet{ds.NewDisjoint(
tcpudpSet.Copy(),
EmptyICMPSet(),
)}
}

func AllTCPorUDPTransport(protocol netp.ProtocolString) *TransportSet {
return NewTCPorUDPTransport(protocol, netp.MinPort, netp.MaxPort, netp.MinPort, netp.MaxPort)
}
Expand Down

0 comments on commit da5d10b

Please sign in to comment.