diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2017-08-21 02:29:35 +0200 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2017-08-24 01:25:45 +0200 |
commit | f80dd32b13cf5b5a0559e2660de2e54f04b100c8 (patch) | |
tree | 3513a3d1da9f64bf1e24d0904bc78b4881c29c95 /isisd/isis_zebra.c | |
parent | bgpd: use the new API to send routes to zebra (diff) | |
download | frr-f80dd32b13cf5b5a0559e2660de2e54f04b100c8.tar.xz frr-f80dd32b13cf5b5a0559e2660de2e54f04b100c8.zip |
isisd: unify ipv4/ipv6 zebra-tx functions
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'isisd/isis_zebra.c')
-rw-r--r-- | isisd/isis_zebra.c | 129 |
1 files changed, 39 insertions, 90 deletions
diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index 35b2091e9..e3537e2a0 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -245,12 +245,13 @@ static int isis_zebra_link_params(int command, struct zclient *zclient, return 0; } -static void isis_zebra_route_add_ipv4(struct prefix *prefix, - struct isis_route_info *route_info) +static void isis_zebra_route_add_route(struct prefix *prefix, + struct isis_route_info *route_info) { struct zapi_route api; struct zapi_nexthop *api_nh; struct isis_nexthop *nexthop; + struct isis_nexthop6 *nexthop6; struct listnode *node; int count = 0; @@ -270,82 +271,38 @@ static void isis_zebra_route_add_ipv4(struct prefix *prefix, api.distance = route_info->depth; #endif - /* Nexthop, ifindex, distance and metric information */ - for (ALL_LIST_ELEMENTS_RO(route_info->nexthops, node, nexthop)) { - api_nh = &api.nexthops[count]; - /* FIXME: can it be ? */ - if (nexthop->ip.s_addr != INADDR_ANY) { - api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX; - api_nh->gate.ipv4 = nexthop->ip; - } else { - api_nh->type = NEXTHOP_TYPE_IFINDEX; + /* Nexthops */ + switch (prefix->family) { + case AF_INET: + for (ALL_LIST_ELEMENTS_RO(route_info->nexthops, node, + nexthop)) { + api_nh = &api.nexthops[count]; + /* FIXME: can it be ? */ + if (nexthop->ip.s_addr != INADDR_ANY) { + api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX; + api_nh->gate.ipv4 = nexthop->ip; + } else { + api_nh->type = NEXTHOP_TYPE_IFINDEX; + } + api_nh->ifindex = nexthop->ifindex; + count++; } - api_nh->ifindex = nexthop->ifindex; - count++; - } - if (!count) - return; - - api.nexthop_num = count; - - zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); - SET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); - UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); -} - -static void isis_zebra_route_del_ipv4(struct prefix *prefix, - struct isis_route_info *route_info) -{ - struct zapi_route api; - - UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); - - memset(&api, 0, sizeof(api)); - api.vrf_id = VRF_DEFAULT; - api.type = ZEBRA_ROUTE_ISIS; - api.safi = SAFI_UNICAST; - api.prefix = *prefix; - - zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); -} - -static void isis_zebra_route_add_ipv6(struct prefix *prefix, - struct isis_route_info *route_info) -{ - struct zapi_route api; - struct zapi_nexthop *api_nh; - struct isis_nexthop6 *nexthop6; - struct listnode *node; - int count = 0; - - if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) - return; - - memset(&api, 0, sizeof(api)); - api.vrf_id = VRF_DEFAULT; - api.type = ZEBRA_ROUTE_ISIS; - api.safi = SAFI_UNICAST; - SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); - SET_FLAG(api.message, ZAPI_MESSAGE_METRIC); - api.metric = route_info->cost; -#if 0 - SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); - api.distance = route_info->depth; -#endif - api.prefix = *prefix; - - /* for each nexthop */ - for (ALL_LIST_ELEMENTS_RO(route_info->nexthops6, node, nexthop6)) { - if (!IN6_IS_ADDR_LINKLOCAL(&nexthop6->ip6) - && !IN6_IS_ADDR_UNSPECIFIED(&nexthop6->ip6)) { - continue; + break; + case AF_INET6: + for (ALL_LIST_ELEMENTS_RO(route_info->nexthops6, node, + nexthop6)) { + if (!IN6_IS_ADDR_LINKLOCAL(&nexthop6->ip6) + && !IN6_IS_ADDR_UNSPECIFIED(&nexthop6->ip6)) { + continue; + } + + api_nh = &api.nexthops[count]; + api_nh->gate.ipv6 = nexthop6->ip6; + api_nh->ifindex = nexthop6->ifindex; + api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; + count++; } - - api_nh = &api.nexthops[count]; - api_nh->gate.ipv6 = nexthop6->ip6; - api_nh->ifindex = nexthop6->ifindex; - api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; - count++; + break; } if (!count) return; @@ -357,8 +314,8 @@ static void isis_zebra_route_add_ipv6(struct prefix *prefix, UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); } -static void isis_zebra_route_del_ipv6(struct prefix *prefix, - struct isis_route_info *route_info) +static void isis_zebra_route_del_route(struct prefix *prefix, + struct isis_route_info *route_info) { struct zapi_route api; @@ -381,18 +338,10 @@ void isis_zebra_route_update(struct prefix *prefix, if (zclient->sock < 0) return; - if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) { - if (prefix->family == AF_INET) - isis_zebra_route_add_ipv4(prefix, route_info); - else if (prefix->family == AF_INET6) - isis_zebra_route_add_ipv6(prefix, route_info); - } else { - if (prefix->family == AF_INET) - isis_zebra_route_del_ipv4(prefix, route_info); - else if (prefix->family == AF_INET6) - isis_zebra_route_del_ipv6(prefix, route_info); - } - return; + if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) + isis_zebra_route_add_route(prefix, route_info); + else + isis_zebra_route_del_route(prefix, route_info); } static int isis_zebra_read_ipv4(int command, struct zclient *zclient, |