From b234ee7859de556c272c36fc691cee4cb08f7230 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Thu, 20 May 2021 16:14:17 +0900
Subject: [PATCH] network: fix an infinite loop

Fixes #19467.

(cherry picked from commit e8f99f4e249916e12c09ee5cc9a108cba6a2b5c0)

Reference: https://github.com/systemd/systemd-stable/commit/b234ee7859de556c272c36fc691cee4cb08f7230
Conflict: adapt context
---
 src/network/networkd-link.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 8219d95b0d..c781dd58d7 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -157,6 +157,12 @@ static void link_update_master_operstate(Link *link, NetDev *netdev) {
         if (!netdev)
                 return;
 
+        /* If an interface is self-mentioned in Bridge= or friends, then it introduces an infinite loop.
+         * FIXME: there still exits a possibility of an infinite loop when two or more interfaces
+         * mention each other in Bridge= or so. We need to detect such a loop. */
+        if (link->ifindex == netdev->ifindex)
+                return;
+
         if (link_get(link->manager, netdev->ifindex, &master) < 0)
                 return;
 
-- 
2.27.0

