]> git.proxmox.com Git - mirror_frr.git/blobdiff - babeld/xroute.c
Merge pull request #13149 from pushpasis/mgmt_cleanup_zlog
[mirror_frr.git] / babeld / xroute.c
index 2e123564ea267dcc13fe5940411a06591d2bd341..30204cd6ff3a092ac6d894435936ac7ec9230234 100644 (file)
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: MIT
 /*
 Copyright (c) 2007, 2008 by Juliusz Chroboczek
 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>
@@ -43,63 +26,54 @@ static int numxroutes = 0, maxxroutes = 0;
 
 /* Add redistributed route to Babel table. */
 int
-babel_ipv4_route_add (struct zapi_ipv4 *api, struct prefix_ipv4 *prefix,
-                      unsigned int ifindex, struct in_addr *nexthop)
-{
-    unsigned char uchar_prefix[16];
-
-    inaddr_to_uchar(uchar_prefix, &prefix->prefix);
-    debugf(BABEL_DEBUG_ROUTE, "Adding new ipv4 route coming from Zebra.");
-    xroute_add_new_route(uchar_prefix, prefix->prefixlen + 96,
-                         api->metric, ifindex, 0, 1);
-    return 0;
-}
-
-/* Remove redistributed route from Babel table. */
-int
-babel_ipv4_route_delete (struct zapi_ipv4 *api, struct prefix_ipv4 *prefix,
-                         unsigned int ifindex)
+babel_route_add (struct zapi_route *api)
 {
     unsigned char uchar_prefix[16];
-    struct xroute *xroute = NULL;
 
-    inaddr_to_uchar(uchar_prefix, &prefix->prefix);
-    xroute = find_xroute(uchar_prefix, prefix->prefixlen + 96);
-    if (xroute != NULL) {
-        debugf(BABEL_DEBUG_ROUTE, "Removing ipv4 route (from zebra).");
-        flush_xroute(xroute);
+    switch (api->prefix.family) {
+    case AF_INET:
+        inaddr_to_uchar(uchar_prefix, &api->prefix.u.prefix4);
+        debugf(BABEL_DEBUG_ROUTE, "Adding new ipv4 route coming from Zebra.");
+        xroute_add_new_route(uchar_prefix, api->prefix.prefixlen + 96,
+                             api->metric, api->nexthops[0].ifindex, 0, 1);
+        break;
+    case AF_INET6:
+        in6addr_to_uchar(uchar_prefix, &api->prefix.u.prefix6);
+        debugf(BABEL_DEBUG_ROUTE, "Adding new ipv6 route coming from Zebra.");
+        xroute_add_new_route(uchar_prefix, api->prefix.prefixlen,
+                             api->metric, api->nexthops[0].ifindex, 0, 1);
+        break;
     }
-    return 0;
-}
-
-/* Add redistributed route to Babel table. */
-int
-babel_ipv6_route_add (struct zapi_ipv6 *api, struct prefix_ipv6 *prefix,
-                      unsigned int ifindex, struct in6_addr *nexthop)
-{
-    unsigned char uchar_prefix[16];
 
-    in6addr_to_uchar(uchar_prefix, &prefix->prefix);
-    debugf(BABEL_DEBUG_ROUTE, "Adding new route coming from Zebra.");
-    xroute_add_new_route(uchar_prefix, prefix->prefixlen, api->metric, ifindex,
-                         0, 1);
     return 0;
 }
 
 /* Remove redistributed route from Babel table. */
 int
-babel_ipv6_route_delete (struct zapi_ipv6 *api, struct prefix_ipv6 *prefix,
-                         unsigned int ifindex)
+babel_route_delete (struct zapi_route *api)
 {
     unsigned char uchar_prefix[16];
     struct xroute *xroute = NULL;
 
-    in6addr_to_uchar(uchar_prefix, &prefix->prefix);
-    xroute = find_xroute(uchar_prefix, prefix->prefixlen);
-    if (xroute != NULL) {
-        debugf(BABEL_DEBUG_ROUTE, "Removing route (from zebra).");
-        flush_xroute(xroute);
+    switch (api->prefix.family) {
+    case AF_INET:
+        inaddr_to_uchar(uchar_prefix, &api->prefix.u.prefix4);
+        xroute = find_xroute(uchar_prefix, api->prefix.prefixlen + 96);
+        if (xroute != NULL) {
+            debugf(BABEL_DEBUG_ROUTE, "Removing ipv4 route (from zebra).");
+            flush_xroute(xroute);
+        }
+        break;
+    case AF_INET6:
+        in6addr_to_uchar(uchar_prefix, &api->prefix.u.prefix6);
+        xroute = find_xroute(uchar_prefix, api->prefix.prefixlen);
+        if (xroute != NULL) {
+            debugf(BABEL_DEBUG_ROUTE, "Removing ipv6 route (from zebra).");
+            flush_xroute(xroute);
+        }
+        break;
     }
+
     return 0;
 }
 
@@ -178,7 +152,7 @@ add_xroute(unsigned char prefix[16], unsigned char plen,
 
 /* Returns an overestimate of the number of xroutes. */
 int
-xroutes_estimate()
+xroutes_estimate(void)
 {
     return numxroutes;
 }