Skip to content

Commit af19595

Browse files
committed
Replace iptables with nftables in TestConnectTimeout e2e test
RHEL 10 removes the iptables binary entirely. The TestConnectTimeout test used iptables to set up an NFQUEUE rule for delaying SYN packets. Replace the iptables command with native nft equivalents. The underlying NFQUEUE mechanism is unchanged since it is a netfilter kernel feature that works with both iptables and nftables. Assisted with Claude
1 parent 10bbe5f commit af19595

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

test/e2e/operator_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,13 +3367,13 @@ func TestConnectTimeout(t *testing.T) {
33673367
t.Fatal("failed to determine ingress operator deployment's image: ", err)
33683368
}
33693369

3370-
iptablesImage, err := getIptablesImage(t, kclient, 1*time.Minute)
3370+
nftImage, err := getNftImage(t, kclient, 1*time.Minute)
33713371
if err != nil {
3372-
t.Fatal("failed to determine image with iptables tool: ", err)
3372+
t.Fatal("failed to determine image with nft tool: ", err)
33733373
}
33743374

33753375
// Create a pod with an HTTP application that delays the connection and sends echo responses.
3376-
httpdPod := buildDelayConnectHTTPPod("connect-timeout-http", operatorcontroller.DefaultOperandNamespace, iptablesImage, operatorImage)
3376+
httpdPod := buildDelayConnectHTTPPod("connect-timeout-http", operatorcontroller.DefaultOperandNamespace, nftImage, operatorImage)
33773377
if err := kclient.Create(context.Background(), httpdPod); err != nil {
33783378
t.Fatalf("failed to create pod %s/%s: %v", httpdPod.Namespace, httpdPod.Name, err)
33793379
}

test/e2e/util_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ func buildDelayConnectHTTPPod(name, namespace, initImage, image string) *corev1.
276276
InitContainers: []corev1.Container{
277277
{
278278
Image: initImage,
279-
Name: "init-iptables",
280-
// Integrate with the iptables rules to handle incoming traffic for the echo container.
279+
Name: "init-nftables",
280+
// Set up nftables rules to redirect incoming SYN packets to a netfilter queue.
281281
// The echo container opens the netfilter queue with the same number to delay incoming SYN packets.
282282
Command: []string{
283283
"/bin/sh",
284284
"-c",
285-
"iptables -I INPUT -p tcp --dport 8080 -m conntrack --ctstate NEW -j NFQUEUE --queue-num 100",
285+
"nft add table inet cio_test && nft add chain inet cio_test input '{ type filter hook input priority 0; policy accept; }' && nft add rule inet cio_test input tcp dport 8080 ct state new queue num 100",
286286
},
287287
SecurityContext: &corev1.SecurityContext{
288288
Privileged: &t,
@@ -442,8 +442,8 @@ func getIngressOperatorDeploymentImage(t *testing.T, client client.Client, timeo
442442
return "", fmt.Errorf("image not found")
443443
}
444444

445-
// getIptablesImage returns the image with the iptables tool installed in it.
446-
func getIptablesImage(t *testing.T, client client.Client, timeout time.Duration) (string, error) {
445+
// getNftImage returns an image with the nft tool installed in it.
446+
func getNftImage(t *testing.T, client client.Client, timeout time.Duration) (string, error) {
447447
t.Helper()
448448
daemonset, err := getDaemonSet(t, client, types.NamespacedName{Namespace: "openshift-ovn-kubernetes", Name: "ovnkube-node"}, timeout)
449449
if err != nil {

test/http/serve-delay-connect.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ func NewServeDelayConnectCommand() *cobra.Command {
5252

5353
// serveDelayConnect registers a handler on the specified netfilter queue and
5454
// starts an HTTP server on the given port. The handler delays SYN packet
55-
// acceptance by the specified delay. Use the following iptables command to configure the handler:
56-
// iptables -I INPUT -p tcp --dport 8080 -m conntrack --ctstate NEW -j NFQUEUE --queue-num 100
57-
// or this one for ipv6 stack:
58-
// ip6tables -I INPUT -p tcp --dport 8080 -m conntrack --ctstate NEW -j NFQUEUE --queue-num 100
55+
// acceptance by the specified delay. Use the following nft commands to configure the handler:
56+
// nft add table inet cio_test
57+
// nft add chain inet cio_test input '{ type filter hook input priority 0; policy accept; }'
58+
// nft add rule inet cio_test input tcp dport 8080 ct state new queue num 100
5959
func serveDelayConnect(queueNum uint16, delay time.Duration, port string) error {
6060
ctx, cancel := context.WithCancel(context.Background())
6161
defer cancel()

0 commit comments

Comments
 (0)