]> git.proxmox.com Git - mirror_frr.git/blobdiff - babeld/babel_interface.c
Merge pull request #12550 from AbhishekNR/mld_join
[mirror_frr.git] / babeld / babel_interface.c
index cc5089801739d0b8a36d1e5833285f61aa52556a..ceff472c2a27f180550fd89610323bdd1f68a933 100644 (file)
@@ -1,23 +1,6 @@
+// SPDX-License-Identifier: MIT
 /*
 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
 */
 
 #include <zebra.h>
@@ -66,7 +49,7 @@ static vector babel_enable_if;                 /* enable interfaces (by cmd). */
 
 int babel_ifp_up(struct interface *ifp)
 {
-    debugf(BABEL_DEBUG_IF, "receive a 'interface up'");
+    debugf(BABEL_DEBUG_IF, "receive an 'interface up'");
 
     interface_recalculate(ifp);
     return 0;
@@ -75,7 +58,7 @@ int babel_ifp_up(struct interface *ifp)
 int
 babel_ifp_down(struct interface *ifp)
 {
-    debugf(BABEL_DEBUG_IF, "receive a 'interface down'");
+    debugf(BABEL_DEBUG_IF, "receive an 'interface down'");
 
     if (ifp == NULL) {
         return 0;
@@ -87,7 +70,7 @@ babel_ifp_down(struct interface *ifp)
 
 int babel_ifp_create (struct interface *ifp)
 {
-    debugf(BABEL_DEBUG_IF, "receive a 'interface add'");
+    debugf(BABEL_DEBUG_IF, "receive an 'interface add'");
 
     interface_recalculate(ifp);
 
@@ -97,7 +80,7 @@ int babel_ifp_create (struct interface *ifp)
 int
 babel_ifp_destroy(struct interface *ifp)
 {
-    debugf(BABEL_DEBUG_IF, "receive a 'interface delete'");
+    debugf(BABEL_DEBUG_IF, "receive an 'interface delete'");
 
     if (IS_ENABLE(ifp))
         interface_reset(ifp);
@@ -112,7 +95,7 @@ babel_interface_address_add (ZAPI_CALLBACK_ARGS)
     struct connected *ifc;
     struct prefix *prefix;
 
-    debugf(BABEL_DEBUG_IF, "receive a 'interface address add'");
+    debugf(BABEL_DEBUG_IF, "receive an 'interface address add'");
 
     ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
                                         zclient->ibuf, vrf_id);
@@ -148,7 +131,7 @@ babel_interface_address_delete (ZAPI_CALLBACK_ARGS)
     struct connected *ifc;
     struct prefix *prefix;
 
-    debugf(BABEL_DEBUG_IF, "receive a 'interface address delete'");
+    debugf(BABEL_DEBUG_IF, "receive an 'interface address delete'");
 
     ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
                                         zclient->ibuf, vrf_id);
@@ -295,17 +278,18 @@ static void
 babel_set_wired_internal(babel_interface_nfo *babel_ifp, int wired)
 {
     if(wired) {
-        babel_ifp->flags |= BABEL_IF_WIRED;
-        babel_ifp->flags |= BABEL_IF_SPLIT_HORIZON;
+        SET_FLAG(babel_ifp->flags, BABEL_IF_WIRED);
+        SET_FLAG(babel_ifp->flags, BABEL_IF_SPLIT_HORIZON);
         babel_ifp->cost = BABEL_DEFAULT_RXCOST_WIRED;
         babel_ifp->channel = BABEL_IF_CHANNEL_NONINTERFERING;
-        babel_ifp->flags &= ~BABEL_IF_LQ;
-    } else {
-        babel_ifp->flags &= ~BABEL_IF_WIRED;
-        babel_ifp->flags &= ~BABEL_IF_SPLIT_HORIZON;
+        UNSET_FLAG(babel_ifp->flags, BABEL_IF_LQ);
+    } 
+    else {
+        UNSET_FLAG(babel_ifp->flags, BABEL_IF_WIRED);
+        UNSET_FLAG(babel_ifp->flags, BABEL_IF_SPLIT_HORIZON);
         babel_ifp->cost = BABEL_DEFAULT_RXCOST_WIRELESS;
         babel_ifp->channel = BABEL_IF_CHANNEL_INTERFERING;
-        babel_ifp->flags |= BABEL_IF_LQ;
+        SET_FLAG(babel_ifp->flags, BABEL_IF_LQ);
     }
 
 }
@@ -595,7 +579,7 @@ interface_recalculate(struct interface *ifp)
         return -1;
     }
 
-    babel_ifp->flags |= BABEL_IF_IS_UP;
+    SET_FLAG(babel_ifp->flags, BABEL_IF_IS_UP);
 
     mtu = MIN(ifp->mtu, ifp->mtu6);
 
@@ -632,15 +616,15 @@ interface_recalculate(struct interface *ifp)
 
     rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
                     (char*)&mreq, sizeof(mreq));
-    if(rc < 0) {
-        flog_err_sys(EC_LIB_SOCKET,
-                 "setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
-                  ifp->name, safe_strerror(errno));
-        /* This is probably due to a missing link-local address,
-         so down this interface, and wait until the main loop
-         tries to up it again. */
-        interface_reset(ifp);
-        return -1;
+    if (rc < 0 && errno != EADDRINUSE) {
+           flog_err_sys(EC_LIB_SOCKET,
+                        "setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
+                        ifp->name, safe_strerror(errno));
+           /* This is probably due to a missing link-local address,
+            so down this interface, and wait until the main loop
+            tries to up it again. */
+           interface_reset(ifp);
+           return -1;
     }
 
     set_timeout(&babel_ifp->hello_timeout, babel_ifp->hello_interval);
@@ -653,7 +637,7 @@ interface_recalculate(struct interface *ifp)
     debugf(BABEL_DEBUG_COMMON,
            "Upped interface %s (%s, cost=%d, channel=%d%s).",
            ifp->name,
-           (babel_ifp->flags & BABEL_IF_WIRED) ? "wired" : "wireless",
+           CHECK_FLAG(babel_ifp->flags, BABEL_IF_WIRED) ? "wired" : "wireless",
            babel_ifp->cost,
            babel_ifp->channel,
            babel_ifp->ipv4 ? ", IPv4" : "");
@@ -673,11 +657,12 @@ interface_reset(struct interface *ifp)
     struct ipv6_mreq mreq;
     babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
 
-    if (!(babel_ifp->flags & BABEL_IF_IS_UP))
+    if (!CHECK_FLAG(babel_ifp->flags, BABEL_IF_IS_UP))
         return 0;
 
     debugf(BABEL_DEBUG_IF, "interface reset: %s", ifp->name);
-    babel_ifp->flags &= ~BABEL_IF_IS_UP;
+
+    UNSET_FLAG(babel_ifp->flags, BABEL_IF_IS_UP);
 
     flush_interface_routes(ifp, 0);
     babel_ifp->buffered = 0;
@@ -706,7 +691,7 @@ interface_reset(struct interface *ifp)
 
     debugf(BABEL_DEBUG_COMMON,"Upped network %s (%s, cost=%d%s).",
            ifp->name,
-           (babel_ifp->flags & BABEL_IF_WIRED) ? "wired" : "wireless",
+           CHECK_FLAG(babel_ifp->flags, BABEL_IF_WIRED) ? "wired" : "wireless",
            babel_ifp->cost,
            babel_ifp->ipv4 ? ", IPv4" : "");