Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: select ICMP version for common ICMP rules #1713

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pkg/utils/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,22 @@ func (i *IPTablesSaveRestore) Restore(table string, data []byte) error {
func CommonICMPRules(family v1core.IPFamily) []ICMPRule {
// Allow various types of ICMP that are important for routing
// This first block applies to both IPv4 and IPv6 type rules

var icmpProto, icmpType string
if family == v1core.IPv6Protocol {
icmpProto = ICMPv6Proto
icmpType = ICMPv6Type
} else {
icmpProto = ICMPv4Proto
icmpType = ICMPv4Type
}

icmpRules := []ICMPRule{
{ICMPv4Proto, ICMPv4Type, "echo-request", "allow icmp echo requests"},
{icmpProto, icmpType, "echo-request", "allow icmp echo requests"},
// destination-unreachable here is also responsible for handling / allowing PMTU
// (https://en.wikipedia.org/wiki/Path_MTU_Discovery) responses
{ICMPv4Proto, ICMPv4Type, "destination-unreachable", "allow icmp destination unreachable messages"},
{ICMPv4Proto, ICMPv4Type, "time-exceeded", "allow icmp time exceeded messages"},
{icmpProto, icmpType, "destination-unreachable", "allow icmp destination unreachable messages"},
{icmpProto, icmpType, "time-exceeded", "allow icmp time exceeded messages"},
}

if family == v1core.IPv6Protocol {
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/iptables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestCommonICMPRules(t *testing.T) {
name: "IPv6",
family: v1core.IPv6Protocol,
expected: []ICMPRule{
{"icmp", "--icmp-type", "echo-request", "allow icmp echo requests"},
{"icmp", "--icmp-type", "destination-unreachable", "allow icmp destination unreachable messages"},
{"icmp", "--icmp-type", "time-exceeded", "allow icmp time exceeded messages"},
{"ipv6-icmp", "--icmpv6-type", "echo-request", "allow icmp echo requests"},
{"ipv6-icmp", "--icmpv6-type", "destination-unreachable", "allow icmp destination unreachable messages"},
{"ipv6-icmp", "--icmpv6-type", "time-exceeded", "allow icmp time exceeded messages"},
{"ipv6-icmp", "--icmpv6-type", "neighbor-solicitation", "allow icmp neighbor solicitation messages"},
{"ipv6-icmp", "--icmpv6-type", "neighbor-advertisement", "allow icmp neighbor advertisement messages"},
{"ipv6-icmp", "--icmpv6-type", "echo-reply", "allow icmp echo reply messages"},
Expand Down