diff --git a/pkg/netset/icmpset.go b/pkg/netset/icmpset.go index 22136bc..5c0b947 100644 --- a/pkg/netset/icmpset.go +++ b/pkg/netset/icmpset.go @@ -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]()} } diff --git a/pkg/netset/transportset.go b/pkg/netset/transportset.go index 6eb7ffa..9cddea9 100644 --- a/pkg/netset/transportset.go +++ b/pkg/netset/transportset.go @@ -35,6 +35,13 @@ 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(), @@ -42,6 +49,13 @@ func NewICMPTransport(minType, maxType, minCode, maxCode int64) *TransportSet { )} } +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) }