Skip to content

Commit

Permalink
[Backport] NETOBSERV-1779 allow port filtering if protocol not set (#750
Browse files Browse the repository at this point in the history
)

* allow port filtering if protocol not set

* rework the protocol check diff

Signed-off-by: Mohamed Mahmoud <[email protected]>

---------

Signed-off-by: Mohamed Mahmoud <[email protected]>
Co-authored-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
jpinsonneau and msherif1234 authored Aug 22, 2024
1 parent 0545880 commit c9413e7
Showing 1 changed file with 48 additions and 67 deletions.
115 changes: 48 additions & 67 deletions controllers/ebpf/agent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,78 +449,59 @@ func (c *AgentController) configureFlowFilter(filter *flowslatest.EBPFFlowFilter
config = append(config, corev1.EnvVar{Name: envFilterProtocol,
Value: filter.Protocol,
})
switch filter.Protocol {
case "TCP", "UDP", "SCTP":
if filter.SourcePorts.Type == intstr.String {
if strings.Contains(filter.SourcePorts.String(), "-") {
config = append(config, corev1.EnvVar{Name: envFilterSourcePortRange,
Value: filter.SourcePorts.String(),
})
}
if strings.Contains(filter.SourcePorts.String(), ",") {
config = append(config, corev1.EnvVar{Name: envFilterSourcePorts,
Value: filter.SourcePorts.String(),
})
}
}
if filter.SourcePorts.Type == intstr.Int {
config = append(config, corev1.EnvVar{Name: envFilterSourcePort,
Value: strconv.Itoa(filter.SourcePorts.IntValue()),
})
}
if filter.DestPorts.Type == intstr.String {
if strings.Contains(filter.DestPorts.String(), "-") {
config = append(config, corev1.EnvVar{Name: envFilterDestPortRange,
Value: filter.DestPorts.String(),
})
}
if strings.Contains(filter.DestPorts.String(), ",") {
config = append(config, corev1.EnvVar{Name: envFilterDestPorts,
Value: filter.DestPorts.String(),
})
}
}
if filter.DestPorts.Type == intstr.Int {
config = append(config, corev1.EnvVar{Name: envFilterDestPort,
Value: strconv.Itoa(filter.DestPorts.IntValue()),
})

}
if filter.Ports.Type == intstr.String {
if strings.Contains(filter.Ports.String(), "-") {
config = append(config, corev1.EnvVar{Name: envFilterPortRange,
Value: filter.Ports.String(),
})
}
if strings.Contains(filter.Ports.String(), ",") {
config = append(config, corev1.EnvVar{Name: envFilterPorts,
Value: filter.Ports.String(),
})
}
}
if filter.Ports.Type == intstr.Int {
config = append(config, corev1.EnvVar{Name: envFilterPort,
Value: strconv.Itoa(filter.Ports.IntValue()),
})
}

case "ICMP", "ICMPv6":
if *filter.ICMPType != 0 {
config = append(config, corev1.EnvVar{Name: envFilterICMPType,
Value: strconv.Itoa(*filter.ICMPType),
})
}
if *filter.ICMPCode != 0 {
config = append(config, corev1.EnvVar{Name: envFilterICMPCode,
Value: strconv.Itoa(*filter.ICMPCode)})
}
}
}

if filter.SourcePorts.Type == intstr.String {
config = append(config, corev1.EnvVar{Name: envFilterSourcePortRange,
Value: filter.SourcePorts.String(),
})
}
if filter.SourcePorts.Type == intstr.Int {
config = append(config, corev1.EnvVar{Name: envFilterSourcePort,
Value: strconv.Itoa(filter.SourcePorts.IntValue()),
})
}
if filter.DestPorts.Type == intstr.String {
config = append(config, corev1.EnvVar{Name: envFilterDestPortRange,
Value: filter.DestPorts.String(),
})
}
if filter.DestPorts.Type == intstr.Int {
config = append(config, corev1.EnvVar{Name: envFilterDestPort,
Value: strconv.Itoa(filter.DestPorts.IntValue()),
})
}
if filter.Ports.Type == intstr.String {
config = append(config, corev1.EnvVar{Name: envFilterPortRange,
Value: filter.Ports.String(),
})
}
if filter.Ports.Type == intstr.Int {
config = append(config, corev1.EnvVar{Name: envFilterPort,
Value: strconv.Itoa(filter.Ports.IntValue()),
})
}
if *filter.ICMPType != 0 {
config = append(config, corev1.EnvVar{Name: envFilterICMPType,
Value: strconv.Itoa(*filter.ICMPType),
})
}
if *filter.ICMPCode != 0 {
config = append(config, corev1.EnvVar{Name: envFilterICMPCode,
Value: strconv.Itoa(*filter.ICMPCode)})
}
if filter.PeerIP != "" {
config = append(config, corev1.EnvVar{Name: envFilterPeerIPAddress,
Value: filter.PeerIP})
}
if *filter.ICMPType != 0 {
config = append(config, corev1.EnvVar{Name: envFilterICMPType,
Value: strconv.Itoa(*filter.ICMPType),
})
}
if *filter.ICMPCode != 0 {
config = append(config, corev1.EnvVar{Name: envFilterICMPCode,
Value: strconv.Itoa(*filter.ICMPCode)})
}
return config
}

Expand Down

0 comments on commit c9413e7

Please sign in to comment.