diff options
Diffstat (limited to '')
-rw-r--r-- | ospf6d/ospf6_abr.c | 48 | ||||
-rw-r--r-- | ospf6d/ospf6_abr.h | 5 | ||||
-rw-r--r-- | ospf6d/ospf6_asbr.c | 112 | ||||
-rw-r--r-- | ospf6d/ospf6_asbr.h | 11 | ||||
-rw-r--r-- | ospf6d/ospf6_auth_trailer.c | 9 | ||||
-rw-r--r-- | ospf6d/ospf6_flood.c | 4 | ||||
-rw-r--r-- | ospf6d/ospf6_gr.c | 4 | ||||
-rw-r--r-- | ospf6d/ospf6_gr_helper.c | 9 | ||||
-rw-r--r-- | ospf6d/ospf6_intra.c | 65 | ||||
-rw-r--r-- | ospf6d/ospf6_lsa.c | 30 | ||||
-rw-r--r-- | ospf6d/ospf6_lsa.h | 19 | ||||
-rw-r--r-- | ospf6d/ospf6_lsdb.c | 5 | ||||
-rw-r--r-- | ospf6d/ospf6_main.c | 25 | ||||
-rw-r--r-- | ospf6d/ospf6_message.c | 45 | ||||
-rw-r--r-- | ospf6d/ospf6_neighbor.c | 2 | ||||
-rw-r--r-- | ospf6d/ospf6_nssa.c | 27 | ||||
-rw-r--r-- | ospf6d/ospf6_route.h | 3 | ||||
-rw-r--r-- | ospf6d/ospf6_snmp.c | 2 | ||||
-rw-r--r-- | ospf6d/ospf6_spf.c | 47 | ||||
-rw-r--r-- | ospf6d/ospf6_zebra.c | 2 |
20 files changed, 267 insertions, 207 deletions
diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index ef780af..0c5be29 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -553,9 +553,8 @@ int ospf6_abr_originate_summary_to_area(struct ospf6_route *route, lsa_header = (struct ospf6_lsa_header *)buffer; if (route->type == OSPF6_DEST_TYPE_ROUTER) { - router_lsa = (struct ospf6_inter_router_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + router_lsa = (struct ospf6_inter_router_lsa *) + ospf6_lsa_header_end(lsa_header); p = (caddr_t)router_lsa + sizeof(struct ospf6_inter_router_lsa); /* Fill Inter-Area-Router-LSA */ @@ -566,9 +565,8 @@ int ospf6_abr_originate_summary_to_area(struct ospf6_route *route, router_lsa->router_id = ADV_ROUTER_IN_PREFIX(&route->prefix); type = htons(OSPF6_LSTYPE_INTER_ROUTER); } else { - prefix_lsa = (struct ospf6_inter_prefix_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + prefix_lsa = (struct ospf6_inter_prefix_lsa *) + ospf6_lsa_header_end(lsa_header); p = (caddr_t)prefix_lsa + sizeof(struct ospf6_inter_prefix_lsa); /* Fill Inter-Area-Prefix-LSA */ @@ -1018,9 +1016,8 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) oa->name); } - prefix_lsa = - (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END( - lsa->header); + prefix_lsa = (struct ospf6_inter_prefix_lsa *) + ospf6_lsa_header_end(lsa->header); prefix.family = AF_INET6; prefix.prefixlen = prefix_lsa->prefix.prefix_length; ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa, @@ -1039,11 +1036,9 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) oa->name); } - router_lsa = - (struct ospf6_inter_router_lsa *)OSPF6_LSA_HEADER_END( - lsa->header); - ospf6_linkstate_prefix(router_lsa->router_id, htonl(0), - &prefix); + router_lsa = (struct ospf6_inter_router_lsa *) + ospf6_lsa_header_end(lsa->header); + ospf6_linkstate_prefix(router_lsa->router_id, htonl(0), &prefix); if (is_debug) inet_ntop(AF_INET, &router_lsa->router_id, buf, sizeof(buf)); @@ -1275,8 +1270,6 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) continue; } - list_delete_all_node(old_route->nh_list); - ospf6_route_copy_nexthops(old_route, route); old_entry_updated = true; for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode, @@ -1330,6 +1323,15 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) } } + /* We added a path or updated a path's nexthops above, + * recompute (old) route nexthops by merging all path nexthops + */ + list_delete_all_node(old_route->nh_list); + for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode, o_path)) { + ospf6_merge_nexthops(old_route->nh_list, + o_path->nh_list); + } + if (is_debug) zlog_debug( "%s: Update route: %s %p old cost %u new cost %u nh %u", @@ -1427,9 +1429,8 @@ static char *ospf6_inter_area_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa, char tbuf[16]; if (lsa != NULL) { - prefix_lsa = - (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END( - lsa->header); + prefix_lsa = (struct ospf6_inter_prefix_lsa *) + ospf6_lsa_header_end(lsa->header); ospf6_prefix_in6_addr(&in6, prefix_lsa, &prefix_lsa->prefix); if (buf) { @@ -1451,7 +1452,7 @@ static int ospf6_inter_area_prefix_lsa_show(struct vty *vty, struct ospf6_inter_prefix_lsa *prefix_lsa; char buf[INET6_ADDRSTRLEN]; - prefix_lsa = (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END( + prefix_lsa = (struct ospf6_inter_prefix_lsa *)ospf6_lsa_header_end( lsa->header); if (use_json) { @@ -1488,9 +1489,8 @@ static char *ospf6_inter_area_router_lsa_get_prefix_str(struct ospf6_lsa *lsa, struct ospf6_inter_router_lsa *router_lsa; if (lsa != NULL) { - router_lsa = - (struct ospf6_inter_router_lsa *)OSPF6_LSA_HEADER_END( - lsa->header); + router_lsa = (struct ospf6_inter_router_lsa *) + ospf6_lsa_header_end(lsa->header); if (buf) @@ -1508,7 +1508,7 @@ static int ospf6_inter_area_router_lsa_show(struct vty *vty, struct ospf6_inter_router_lsa *router_lsa; char buf[64]; - router_lsa = (struct ospf6_inter_router_lsa *)OSPF6_LSA_HEADER_END( + router_lsa = (struct ospf6_inter_router_lsa *)ospf6_lsa_header_end( lsa->header); ospf6_options_printbuf(router_lsa->options, buf, sizeof(buf)); diff --git a/ospf6d/ospf6_abr.h b/ospf6d/ospf6_abr.h index 7bb1619..52686ed 100644 --- a/ospf6d/ospf6_abr.h +++ b/ospf6d/ospf6_abr.h @@ -33,11 +33,12 @@ struct ospf6_inter_router_lsa { uint32_t router_id; }; -#define OSPF6_ABR_SUMMARY_METRIC(E) (ntohl ((E)->metric & htonl (0x00ffffff))) +#define OSPF6_ABR_SUMMARY_METRIC(E) \ + (ntohl((E)->metric & htonl(OSPF6_EXT_PATH_METRIC_MAX))) #define OSPF6_ABR_SUMMARY_METRIC_SET(E, C) \ { \ (E)->metric &= htonl(0x00000000); \ - (E)->metric |= htonl(0x00ffffff) & htonl(C); \ + (E)->metric |= htonl(OSPF6_EXT_PATH_METRIC_MAX) & htonl(C); \ } #define OSPF6_ABR_RANGE_CLEAR_COST(range) (range->path.cost = OSPF_AREA_RANGE_COST_UNSPEC) diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index d1c2b8b..2065527 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -14,6 +14,7 @@ #include "table.h" #include "plist.h" #include "frrevent.h" +#include "frrstr.h" #include "linklist.h" #include "lib/northbound_cli.h" @@ -101,9 +102,8 @@ struct ospf6_lsa *ospf6_as_external_lsa_originate(struct ospf6_route *route, /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - as_external_lsa = (struct ospf6_as_external_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + as_external_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( + lsa_header); p = (caddr_t)((caddr_t)as_external_lsa + sizeof(struct ospf6_as_external_lsa)); @@ -216,7 +216,7 @@ static route_tag_t ospf6_as_external_lsa_get_tag(struct ospf6_lsa *lsa) if (!lsa) return 0; - external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( lsa->header); if (!CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)) @@ -520,7 +520,7 @@ void ospf6_asbr_lsa_add(struct ospf6_lsa *lsa) type = ntohs(lsa->header->type); oa = lsa->lsdb->data; - external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( lsa->header); if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) @@ -725,7 +725,7 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, int type; bool debug = false; - external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( lsa->header); if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL) || (IS_OSPF6_DEBUG_NSSA)) @@ -1426,10 +1426,9 @@ static void ospf6_external_lsa_fwd_addr_set(struct ospf6 *ospf6, } void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, - struct prefix *prefix, - unsigned int nexthop_num, - const struct in6_addr *nexthop, - route_tag_t tag, struct ospf6 *ospf6) + struct prefix *prefix, unsigned int nexthop_num, + const struct in6_addr *nexthop, route_tag_t tag, + struct ospf6 *ospf6, uint32_t metric) { route_map_result_t ret; struct ospf6_route troute; @@ -1472,6 +1471,7 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, if (ROUTEMAP(red)) { troute.route_option = &tinfo; troute.ospf6 = ospf6; + troute.path.redistribute_cost = metric; tinfo.ifindex = ifindex; tinfo.tag = tag; @@ -1924,7 +1924,7 @@ static void ospf6_redistribute_default_set(struct ospf6 *ospf6, int originate) case DEFAULT_ORIGINATE_ALWAYS: ospf6_asbr_redistribute_add(DEFAULT_ROUTE, 0, (struct prefix *)&p, 0, &nexthop, 0, - ospf6); + ospf6, 0); break; } } @@ -2153,25 +2153,81 @@ static const struct route_map_rule_cmd ospf6_routemap_rule_set_metric_type_free, }; +struct ospf6_metric { + enum { metric_increment, metric_decrement, metric_absolute } type; + bool used; + uint32_t metric; +}; + static enum route_map_cmd_result_t ospf6_routemap_rule_set_metric(void *rule, const struct prefix *prefix, void *object) { - char *metric = rule; - struct ospf6_route *route = object; + struct ospf6_metric *metric; + struct ospf6_route *route; + + /* Fetch routemap's rule information. */ + metric = rule; + route = object; + + /* Set metric out value. */ + if (!metric->used) + return RMAP_OKAY; + + if (route->path.redistribute_cost > OSPF6_EXT_PATH_METRIC_MAX) + route->path.redistribute_cost = OSPF6_EXT_PATH_METRIC_MAX; + + if (metric->type == metric_increment) { + route->path.cost = route->path.redistribute_cost + + metric->metric; + + /* Check overflow */ + if (route->path.cost > OSPF6_EXT_PATH_METRIC_MAX || + route->path.cost < metric->metric) + route->path.cost = OSPF6_EXT_PATH_METRIC_MAX; + } else if (metric->type == metric_decrement) { + route->path.cost = route->path.redistribute_cost - + metric->metric; + + /* Check overflow */ + if (route->path.cost == 0 || + route->path.cost > route->path.redistribute_cost) + route->path.cost = 1; + } else if (metric->type == metric_absolute) + route->path.cost = metric->metric; - route->path.cost = atoi(metric); return RMAP_OKAY; } static void *ospf6_routemap_rule_set_metric_compile(const char *arg) { - uint32_t metric; - char *endp; - metric = strtoul(arg, &endp, 0); - if (metric > OSPF_LS_INFINITY || *endp != '\0') - return NULL; - return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); + struct ospf6_metric *metric; + + metric = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(*metric)); + metric->used = false; + + if (all_digit(arg)) + metric->type = metric_absolute; + + if ((arg[0] == '+') && all_digit(arg + 1)) { + metric->type = metric_increment; + arg++; + } + + if ((arg[0] == '-') && all_digit(arg + 1)) { + metric->type = metric_decrement; + arg++; + } + + metric->metric = strtoul(arg, NULL, 10); + + if (metric->metric > OSPF6_EXT_PATH_METRIC_MAX) + metric->metric = OSPF6_EXT_PATH_METRIC_MAX; + + if (metric->metric) + metric->used = true; + + return metric; } static void ospf6_routemap_rule_set_metric_free(void *rule) @@ -2368,7 +2424,7 @@ static char *ospf6_as_external_lsa_get_prefix_str(struct ospf6_lsa *lsa, char tbuf[16]; if (lsa) { - external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( lsa->header); if (pos == 0) { @@ -2403,7 +2459,7 @@ static int ospf6_as_external_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, char buf[64]; assert(lsa->header); - external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( lsa->header); /* bits */ @@ -2971,8 +3027,8 @@ ospf6_originate_summary_lsa(struct ospf6 *ospf6, return; } - external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END - (aggr_lsa->header); + external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( + aggr_lsa->header); metric = (unsigned long)OSPF6_ASBR_METRIC(external); tag = ospf6_as_external_lsa_get_tag(aggr_lsa); mtype = CHECK_FLAG(external->bits_metric, @@ -3120,8 +3176,7 @@ ospf6_handle_external_aggr_modify(struct ospf6 *ospf6, return OSPF6_FAILURE; } - asel = (struct ospf6_as_external_lsa *) - OSPF6_LSA_HEADER_END(lsa->header); + asel = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(lsa->header); metric = (unsigned long)OSPF6_ASBR_METRIC(asel); tag = ospf6_as_external_lsa_get_tag(lsa); mtype = CHECK_FLAG(asel->bits_metric, @@ -3310,9 +3365,8 @@ static void ospf6_handle_aggregated_exnl_rt(struct ospf6 *ospf6, lsa = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL), htonl(info->id), ospf6->router_id, ospf6->lsdb); if (lsa) { - ext_lsa = (struct ospf6_as_external_lsa - *)((char *)(lsa->header) - + sizeof(struct ospf6_lsa_header)); + ext_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( + lsa->header); if (rt->prefix.prefixlen != ext_lsa->prefix.prefix_length) return; diff --git a/ospf6d/ospf6_asbr.h b/ospf6d/ospf6_asbr.h index d63e467..21e6d89 100644 --- a/ospf6d/ospf6_asbr.h +++ b/ospf6d/ospf6_asbr.h @@ -94,11 +94,13 @@ struct ospf6_as_external_lsa { #define OSPF6_ASBR_BIT_F ntohl (0x02000000) #define OSPF6_ASBR_BIT_E ntohl (0x04000000) -#define OSPF6_ASBR_METRIC(E) (ntohl ((E)->bits_metric & htonl (0x00ffffff))) +#define OSPF6_ASBR_METRIC(E) \ + (ntohl((E)->bits_metric & htonl(OSPF6_EXT_PATH_METRIC_MAX))) #define OSPF6_ASBR_METRIC_SET(E, C) \ { \ - (E)->bits_metric &= htonl(0xff000000); \ - (E)->bits_metric |= htonl(0x00ffffff) & htonl(C); \ + (E)->bits_metric &= htonl(~OSPF6_EXT_PATH_METRIC_MAX); \ + (E)->bits_metric |= htonl(OSPF6_EXT_PATH_METRIC_MAX) & \ + htonl(C); \ } extern void ospf6_asbr_lsa_add(struct ospf6_lsa *lsa); @@ -115,7 +117,8 @@ extern void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, struct prefix *prefix, unsigned int nexthop_num, const struct in6_addr *nexthop, - route_tag_t tag, struct ospf6 *ospf6); + route_tag_t tag, struct ospf6 *ospf6, + uint32_t metric); extern void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex, struct prefix *prefix, struct ospf6 *ospf6); diff --git a/ospf6d/ospf6_auth_trailer.c b/ospf6d/ospf6_auth_trailer.c index 8d9eff4..860d273 100644 --- a/ospf6d/ospf6_auth_trailer.c +++ b/ospf6d/ospf6_auth_trailer.c @@ -517,6 +517,15 @@ int ospf6_auth_check_digest(struct ospf6_header *oh, struct ospf6_interface *oi, } } else if (CHECK_FLAG(oi->at_data.flags, OSPF6_AUTH_TRAILER_MANUAL_KEY)) { + if (oi->at_data.key_id != ntohs(ospf6_auth->id)) { + if (IS_OSPF6_DEBUG_AUTH_RX) + zlog_err("RECV[%s]: Auth SA ID mismatch for %s, received %u vs configured %u", + oi->interface->name, + ospf6_message_type(oh->type), + ntohs(ospf6_auth->id), + oi->at_data.key_id); + return OSPF6_AUTH_VALIDATE_FAILURE; + } auth_str = oi->at_data.auth_key; hash_algo = oi->at_data.hash_algo; } diff --git a/ospf6d/ospf6_flood.c b/ospf6d/ospf6_flood.c index 98d3bbc..b87aa2f 100644 --- a/ospf6d/ospf6_flood.c +++ b/ospf6d/ospf6_flood.c @@ -295,9 +295,7 @@ void ospf6_install_lsa(struct ospf6_lsa *lsa) lsa->installed = now; /* Topo change handling */ - if (CHECK_LSA_TOPO_CHG_ELIGIBLE(ntohs(lsa->header->type)) - && !CHECK_FLAG(lsa->flag, OSPF6_LSA_DUPLICATE)) { - + if (CHECK_LSA_TOPO_CHG_ELIGIBLE(ntohs(lsa->header->type))) { /* check if it is new lsa ? or existing lsa got modified ?*/ if (!old || OSPF6_LSA_IS_CHANGED(old, lsa)) ospf6_helper_handle_topo_chg(ospf6, lsa); diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index 34cb970..ab119a4 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -54,9 +54,7 @@ static int ospf6_gr_lsa_originate(struct ospf6_interface *oi, /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - grace_lsa = - (struct ospf6_grace_lsa *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + grace_lsa = (struct ospf6_grace_lsa *)ospf6_lsa_header_end(lsa_header); /* Put grace period. */ grace_lsa->tlv_period.header.type = htons(GRACE_PERIOD_TYPE); diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c index 42ea048..f0e5d3a 100644 --- a/ospf6d/ospf6_gr_helper.c +++ b/ospf6d/ospf6_gr_helper.c @@ -939,15 +939,6 @@ static void show_ospf6_gr_helper_details(struct vty *vty, struct ospf6 *ospf6, ? "Enabled" : "Disabled"); -#if CONFDATE > 20240401 - CPP_NOTICE("Remove deprecated json key: restartSupoort") -#endif - json_object_string_add( - json, "restartSupoort", - (ospf6->ospf6_helper_cfg.only_planned_restart) - ? "Planned Restart only" - : "Planned and Unplanned Restarts"); - json_object_string_add( json, "restartSupport", (ospf6->ospf6_helper_cfg.only_planned_restart) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index cb03675..b06796a 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -242,9 +242,7 @@ void ospf6_router_lsa_originate(struct event *thread) memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - router_lsa = - (struct ospf6_router_lsa *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + router_lsa = (struct ospf6_router_lsa *)ospf6_lsa_header_end(lsa_header); ospf6_router_lsa_options_set(oa, router_lsa); @@ -305,10 +303,8 @@ void ospf6_router_lsa_originate(struct event *thread) /* Reset Buffer to fill next Router LSA */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - router_lsa = - (struct ospf6_router_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + router_lsa = (struct ospf6_router_lsa *) + ospf6_lsa_header_end(lsa_header); ospf6_router_lsa_options_set(oa, router_lsa); @@ -568,16 +564,14 @@ void ospf6_network_lsa_originate(struct event *thread) memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; network_lsa = - (struct ospf6_network_lsa *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + (struct ospf6_network_lsa *)ospf6_lsa_header_end(lsa_header); /* Collect the interface's Link-LSAs to describe network's optional capabilities */ type = htons(OSPF6_LSTYPE_LINK); for (ALL_LSDB_TYPED(oi->lsdb, type, lsa)) { - link_lsa = (struct ospf6_link_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + link_lsa = (struct ospf6_link_lsa *)ospf6_lsa_header_end( + lsa->header); network_lsa->options[0] |= link_lsa->options[0]; network_lsa->options[1] |= link_lsa->options[1]; network_lsa->options[2] |= link_lsa->options[2]; @@ -711,7 +705,8 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, } start = (char *)link_lsa + sizeof(struct ospf6_link_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); + for (current = start; current < end; current += OSPF6_PREFIX_SIZE(prefix)) { prefix = (struct ospf6_prefix *)current; @@ -800,8 +795,7 @@ void ospf6_link_lsa_originate(struct event *thread) /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - link_lsa = (struct ospf6_link_lsa *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + link_lsa = (struct ospf6_link_lsa *)ospf6_lsa_header_end(lsa_header); /* Fill Link-LSA */ link_lsa->priority = oi->priority; @@ -871,7 +865,7 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa, start = (char *)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); current = start; while (current + sizeof(struct ospf6_prefix) <= end) { @@ -942,7 +936,8 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, start = (char *)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); + for (current = start; current < end; current += OSPF6_PREFIX_SIZE(prefix)) { prefix = (struct ospf6_prefix *)current; @@ -1042,9 +1037,8 @@ void ospf6_intra_prefix_lsa_originate_stub(struct event *thread) /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - intra_prefix_lsa = (struct ospf6_intra_prefix_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end( + lsa_header); /* Fill Intra-Area-Prefix-LSA */ intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_ROUTER); @@ -1159,10 +1153,8 @@ void ospf6_intra_prefix_lsa_originate_stub(struct event *thread) /* Prepare next buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - intra_prefix_lsa = - (struct ospf6_intra_prefix_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) + ospf6_lsa_header_end(lsa_header); /* Fill Intra-Area-Prefix-LSA */ intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_ROUTER); @@ -1269,9 +1261,8 @@ void ospf6_intra_prefix_lsa_originate_transit(struct event *thread) /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - intra_prefix_lsa = (struct ospf6_intra_prefix_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end( + lsa_header); /* Fill Intra-Area-Prefix-LSA */ intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_NETWORK); @@ -1326,7 +1317,8 @@ void ospf6_intra_prefix_lsa_originate_transit(struct event *thread) prefix_num = (unsigned short)ntohl(link_lsa->prefix_num); start = (char *)link_lsa + sizeof(struct ospf6_link_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + end = ospf6_lsa_end(lsa->header); + for (current = start; current < end && prefix_num; current += OSPF6_PREFIX_SIZE(op)) { op = (struct ospf6_prefix *)current; @@ -1668,7 +1660,8 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, } intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) - OSPF6_LSA_HEADER_END(lsa->header); + ospf6_lsa_header_end( + lsa->header); if (intra_prefix_lsa->ref_adv_router == oa->ospf6->router_id) { @@ -1749,9 +1742,8 @@ void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa) oa = OSPF6_AREA(lsa->lsdb->data); - intra_prefix_lsa = - (struct ospf6_intra_prefix_lsa *)OSPF6_LSA_HEADER_END( - lsa->header); + intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end( + lsa->header); if (intra_prefix_lsa->ref_type == htons(OSPF6_LSTYPE_ROUTER) || intra_prefix_lsa->ref_type == htons(OSPF6_LSTYPE_NETWORK)) ospf6_linkstate_prefix(intra_prefix_lsa->ref_adv_router, @@ -1781,7 +1773,7 @@ void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa) prefix_num = ntohs(intra_prefix_lsa->prefix_num); start = (caddr_t)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = OSPF6_LSA_END(lsa->header); + end = ospf6_lsa_end(lsa->header); for (current = start; current < end; current += OSPF6_PREFIX_SIZE(op)) { op = (struct ospf6_prefix *)current; if (prefix_num == 0) @@ -1979,14 +1971,13 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) oa = OSPF6_AREA(lsa->lsdb->data); - intra_prefix_lsa = - (struct ospf6_intra_prefix_lsa *)OSPF6_LSA_HEADER_END( - lsa->header); + intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end( + lsa->header); prefix_num = ntohs(intra_prefix_lsa->prefix_num); start = (caddr_t)intra_prefix_lsa + sizeof(struct ospf6_intra_prefix_lsa); - end = OSPF6_LSA_END(lsa->header); + end = ospf6_lsa_end(lsa->header); for (current = start; current < end; current += OSPF6_PREFIX_SIZE(op)) { op = (struct ospf6_prefix *)current; if (prefix_num == 0) diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index bc39579..0177518 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -63,10 +63,10 @@ struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa) static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, json_object *json_obj, bool use_json) { - uint8_t *start, *end, *current; + char *start, *end, *current; - start = (uint8_t *)lsa->header + sizeof(struct ospf6_lsa_header); - end = (uint8_t *)lsa->header + ntohs(lsa->header->length); + start = ospf6_lsa_header_end(lsa->header); + end = ospf6_lsa_end(lsa->header); if (use_json) { json_object_string_add(json_obj, "lsaType", "unknown"); @@ -201,10 +201,10 @@ int ospf6_lsa_is_differ(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2) return 1; /* compare body */ - if (ntohs(lsa1->header->length) != ntohs(lsa2->header->length)) + if (ospf6_lsa_size(lsa1->header) != ospf6_lsa_size(lsa2->header)) return 1; - len = ntohs(lsa1->header->length) - sizeof(struct ospf6_lsa_header); + len = ospf6_lsa_size(lsa1->header) - sizeof(struct ospf6_lsa_header); return memcmp(lsa1->header + 1, lsa2->header + 1, len); } @@ -214,7 +214,7 @@ int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2) if (OSPF6_LSA_IS_MAXAGE(lsa1) ^ OSPF6_LSA_IS_MAXAGE(lsa2)) return 1; - if (ntohs(lsa1->header->length) != ntohs(lsa2->header->length)) + if (ospf6_lsa_size(lsa1->header) != ospf6_lsa_size(lsa2->header)) return 1; /* Going beyond LSA headers to compare the payload only makes sense, * when both LSAs aren't header-only. */ @@ -228,14 +228,14 @@ int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2) if (CHECK_FLAG(lsa1->flag, OSPF6_LSA_HEADERONLY)) return 0; - length = OSPF6_LSA_SIZE(lsa1->header) - sizeof(struct ospf6_lsa_header); + length = ospf6_lsa_size(lsa1->header) - sizeof(struct ospf6_lsa_header); /* Once upper layer verifies LSAs received, length underrun should * become a warning. */ if (length <= 0) return 0; - return memcmp(OSPF6_LSA_HEADER_END(lsa1->header), - OSPF6_LSA_HEADER_END(lsa2->header), length); + return memcmp(ospf6_lsa_header_end(lsa1->header), + ospf6_lsa_header_end(lsa2->header), length); } /* ospf6 age functions */ @@ -548,7 +548,7 @@ void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa, json_object *json = NULL; start = (uint8_t *)lsa->header; - end = (uint8_t *)lsa->header + ntohs(lsa->header->length); + end = (uint8_t *)ospf6_lsa_end(lsa->header); if (use_json) { json = json_object_new_object(); @@ -613,7 +613,7 @@ void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa, json_object_int_add(json_obj, "checksum", ntohs(lsa->header->checksum)); json_object_int_add(json_obj, "length", - ntohs(lsa->header->length)); + ospf6_lsa_size(lsa->header)); json_object_int_add(json_obj, "flag", lsa->flag); json_object_int_add(json_obj, "lock", lsa->lock); json_object_int_add(json_obj, "reTxCount", lsa->retrans_count); @@ -630,7 +630,7 @@ void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa, (unsigned long)ntohl(lsa->header->seqnum)); vty_out(vty, "CheckSum: %#06hx Length: %hu\n", ntohs(lsa->header->checksum), - ntohs(lsa->header->length)); + ospf6_lsa_size(lsa->header)); vty_out(vty, "Flag: %x \n", lsa->flag); vty_out(vty, "Lock: %d \n", lsa->lock); vty_out(vty, "ReTx Count: %d\n", lsa->retrans_count); @@ -720,7 +720,7 @@ struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header) uint16_t lsa_size = 0; /* size of the entire LSA */ - lsa_size = ntohs(header->length); /* XXX vulnerable */ + lsa_size = ospf6_lsa_size(header); /* XXX vulnerable */ lsa = ospf6_lsa_alloc(lsa_size); @@ -947,7 +947,7 @@ unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *lsa_header) buffer - (uint8_t *)&lsa_header->age; /* should be 2 */ /* Skip the AGE field */ - uint16_t len = ntohs(lsa_header->length) - type_offset; + uint16_t len = ospf6_lsa_size(lsa_header) - type_offset; /* Checksum offset starts from "type" field, not the beginning of the lsa_header struct. The offset is 14, rather than 16. */ @@ -963,7 +963,7 @@ int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsa_header) buffer - (uint8_t *)&lsa_header->age; /* should be 2 */ /* Skip the AGE field */ - uint16_t len = ntohs(lsa_header->length) - type_offset; + uint16_t len = ospf6_lsa_size(lsa_header) - type_offset; return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0); diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index c9ac27d..4fc2f0d 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -87,10 +87,21 @@ struct ospf6_lsa_header { uint16_t length; /* LSA length */ }; -#define OSPF6_LSA_HEADER_END(h) ((caddr_t)(h) + sizeof(struct ospf6_lsa_header)) -#define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length)) -#define OSPF6_LSA_END(h) \ - ((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length)) +static inline char *ospf6_lsa_header_end(struct ospf6_lsa_header *header) +{ + return (char *)header + sizeof(struct ospf6_lsa_header); +} + +static inline char *ospf6_lsa_end(struct ospf6_lsa_header *header) +{ + return (char *)header + ntohs(header->length); +} + +static inline uint16_t ospf6_lsa_size(struct ospf6_lsa_header *header) +{ + return ntohs(header->length); +} + #define OSPF6_LSA_IS_TYPE(t, L) \ ((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0) #define OSPF6_LSA_IS_SAME(L1, L2) \ diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c index c9cbdf8..9aca555 100644 --- a/ospf6d/ospf6_lsdb.c +++ b/ospf6d/ospf6_lsdb.c @@ -229,9 +229,8 @@ struct ospf6_lsa *ospf6_find_inter_prefix_lsa(struct ospf6 *ospf6, struct ospf6_inter_prefix_lsa *prefix_lsa; struct prefix prefix; - prefix_lsa = - (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END( - lsa->header); + prefix_lsa = (struct ospf6_inter_prefix_lsa *) + ospf6_lsa_header_end(lsa->header); prefix.family = AF_INET6; prefix.prefixlen = prefix_lsa->prefix.prefix_length; ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa, diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 17966e7..8320f11 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -24,6 +24,7 @@ #include "vrf.h" #include "bfd.h" #include "libfrr.h" +#include "libagentx.h" #include "ospf6d.h" #include "ospf6_top.h" @@ -110,9 +111,10 @@ static void __attribute__((noreturn)) ospf6_exit(int status) ospf6_master_delete(); + keychain_terminate(); + frr_fini(); - keychain_terminate(); exit(status); } @@ -169,6 +171,8 @@ static const struct frr_yang_module_info *const ospf6d_yang_modules[] = { &frr_vrf_info, &frr_ospf_route_map_info, &frr_ospf6_route_map_info, + &ietf_key_chain_info, + &ietf_key_chain_deviation_info, }; /* actual paths filled in main() */ @@ -182,19 +186,19 @@ static char *state_paths[] = { /* clang-format off */ FRR_DAEMON_INFO(ospf6d, OSPF6, - .vty_port = OSPF6_VTY_PORT, - .proghelp = "Implementation of the OSPFv3 routing protocol.", + .vty_port = OSPF6_VTY_PORT, + .proghelp = "Implementation of the OSPFv3 routing protocol.", - .signals = ospf6_signals, - .n_signals = array_size(ospf6_signals), + .signals = ospf6_signals, + .n_signals = array_size(ospf6_signals), - .privs = &ospf6d_privs, + .privs = &ospf6d_privs, - .yang_modules = ospf6d_yang_modules, - .n_yang_modules = array_size(ospf6d_yang_modules), + .yang_modules = ospf6d_yang_modules, + .n_yang_modules = array_size(ospf6d_yang_modules), - .state_paths = state_paths, -); + .state_paths = state_paths, + ); /* clang-format on */ /* Max wait time for config to load before accepting hellos */ @@ -263,6 +267,7 @@ int main(int argc, char *argv[], char *envp[]) /* thread master */ master = om6->master; + libagentx_init(); keychain_init(); ospf6_vrf_init(); access_list_init(); diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index d13799c..a6ee8d8 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -221,12 +221,12 @@ void ospf6_lsupdate_print(struct ospf6_header *oh, int action) && action == OSPF6_ACTION_RECV) || (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND) && action == OSPF6_ACTION_SEND)) { - - for (p = (char *)((caddr_t)lsupdate - + sizeof(struct ospf6_lsupdate)); - p < OSPF6_MESSAGE_END(oh) - && p + OSPF6_LSA_SIZE(p) <= OSPF6_MESSAGE_END(oh); - p += OSPF6_LSA_SIZE(p)) { + for (p = (char *)((caddr_t)lsupdate + + sizeof(struct ospf6_lsupdate)); + p < OSPF6_MESSAGE_END(oh) && + p + ospf6_lsa_size((struct ospf6_lsa_header *)p) <= + OSPF6_MESSAGE_END(oh); + p += ospf6_lsa_size((struct ospf6_lsa_header *)p)) { ospf6_lsa_header_print_raw( (struct ospf6_lsa_header *)p); } @@ -1414,7 +1414,7 @@ ospf6_lsaseq_examin(struct ospf6_lsa_header *lsah, /* start of buffered data */ return MSG_NG; } /* save on ntohs() calls here and in the LSA validator */ - lsalen = OSPF6_LSA_SIZE(lsah); + lsalen = ospf6_lsa_size(lsah); if (lsalen < OSPF6_LSA_HEADER_SIZE) { zlog_warn( "%s: malformed LSA header #%u, declared length is %u B", @@ -1646,9 +1646,10 @@ static void ospf6_lsupdate_recv(struct in6_addr *src, struct in6_addr *dst, /* Process LSAs */ for (p = (char *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); - p < OSPF6_MESSAGE_END(oh) - && p + OSPF6_LSA_SIZE(p) <= OSPF6_MESSAGE_END(oh); - p += OSPF6_LSA_SIZE(p)) { + p < OSPF6_MESSAGE_END(oh) && + p + ospf6_lsa_size((struct ospf6_lsa_header *)p) <= + OSPF6_MESSAGE_END(oh); + p += ospf6_lsa_size((struct ospf6_lsa_header *)p)) { ospf6_receive_lsa(on, (struct ospf6_lsa_header *)p); } @@ -2702,7 +2703,7 @@ static uint16_t ospf6_make_lsupdate_list(struct ospf6_neighbor *on, stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE); for (ALL_LSDB(on->lsupdate_list, lsa, lsanext)) { - if ((length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE) > + if ((length + ospf6_lsa_size(lsa->header) + OSPF6_HEADER_SIZE) > ospf6_packet_max(on->ospf6_if)) { ospf6_fill_header(on->ospf6_if, (*op)->s, length + OSPF6_HEADER_SIZE); @@ -2719,9 +2720,9 @@ static uint16_t ospf6_make_lsupdate_list(struct ospf6_neighbor *on, stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE); } ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay); - stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header)); + stream_put((*op)->s, lsa->header, ospf6_lsa_size(lsa->header)); (*lsa_cnt)++; - length += OSPF6_LSA_SIZE(lsa->header); + length += ospf6_lsa_size(lsa->header); assert(lsa->lock == 2); ospf6_lsdb_remove(lsa, on->lsupdate_list); } @@ -2739,7 +2740,7 @@ static uint16_t ospf6_make_ls_retrans_list(struct ospf6_neighbor *on, stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE); for (ALL_LSDB(on->retrans_list, lsa, lsanext)) { - if ((length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE) > + if ((length + ospf6_lsa_size(lsa->header) + OSPF6_HEADER_SIZE) > ospf6_packet_max(on->ospf6_if)) { ospf6_fill_header(on->ospf6_if, (*op)->s, length + OSPF6_HEADER_SIZE); @@ -2763,9 +2764,9 @@ static uint16_t ospf6_make_ls_retrans_list(struct ospf6_neighbor *on, stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE); } ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay); - stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header)); + stream_put((*op)->s, lsa->header, ospf6_lsa_size(lsa->header)); (*lsa_cnt)++; - length += OSPF6_LSA_SIZE(lsa->header); + length += ospf6_lsa_size(lsa->header); } return length; } @@ -2849,9 +2850,9 @@ int ospf6_lsupdate_send_neighbor_now(struct ospf6_neighbor *on, /* skip over fixed header */ stream_forward_endp(op->s, OSPF6_LS_UPD_MIN_SIZE); ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay); - stream_put(op->s, lsa->header, OSPF6_LSA_SIZE(lsa->header)); - length = OSPF6_HEADER_SIZE + OSPF6_LS_UPD_MIN_SIZE - + OSPF6_LSA_SIZE(lsa->header); + stream_put(op->s, lsa->header, ospf6_lsa_size(lsa->header)); + length = OSPF6_HEADER_SIZE + OSPF6_LS_UPD_MIN_SIZE + + ospf6_lsa_size(lsa->header); ospf6_fill_header(on->ospf6_if, op->s, length); ospf6_fill_lsupdate_header(op->s, 1); op->length = length; @@ -2877,7 +2878,7 @@ static uint16_t ospf6_make_lsupdate_interface(struct ospf6_interface *oi, stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE); for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext)) { - if (length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE > + if (length + ospf6_lsa_size(lsa->header) + OSPF6_HEADER_SIZE > ospf6_packet_max(oi)) { ospf6_fill_header(oi, (*op)->s, length + OSPF6_HEADER_SIZE); @@ -2895,9 +2896,9 @@ static uint16_t ospf6_make_lsupdate_interface(struct ospf6_interface *oi, } ospf6_lsa_age_update_to_send(lsa, oi->transdelay); - stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header)); + stream_put((*op)->s, lsa->header, ospf6_lsa_size(lsa->header)); (*lsa_cnt)++; - length += OSPF6_LSA_SIZE(lsa->header); + length += ospf6_lsa_size(lsa->header); assert(lsa->lock == 2); ospf6_lsdb_remove(lsa, oi->lsupdate_list); diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index cb65ed2..0e44f2a 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -1015,6 +1015,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty, on->ospf6_if->interface->ifindex); json_object_int_add(json_neighbor, "neighborInterfaceIndex", on->ifindex); + json_object_string_addf(json_neighbor, "localLinkLocalAddress", + "%pI6", on->ospf6_if->linklocal_addr); json_object_string_add(json_neighbor, "linkLocalAddress", linklocal_addr); json_object_string_add(json_neighbor, "neighborState", diff --git a/ospf6d/ospf6_nssa.c b/ospf6d/ospf6_nssa.c index 405ae90..ea2be20 100644 --- a/ospf6d/ospf6_nssa.c +++ b/ospf6d/ospf6_nssa.c @@ -52,10 +52,8 @@ static int ospf6_abr_nssa_am_elected(struct ospf6_area *oa) /* Verify all the router LSA to compare the router ID */ for (ALL_LSDB_TYPED(oa->lsdb, type, lsa)) { - - router_lsa = (struct ospf6_router_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + router_lsa = (struct ospf6_router_lsa *)ospf6_lsa_header_end( + lsa->header); /* ignore non-ABR routers */ if (!CHECK_FLAG(router_lsa->bits, OSPF6_ROUTER_BIT_B)) @@ -416,7 +414,7 @@ static struct ospf6_lsa *ospf6_lsa_translated_nssa_new(struct ospf6_area *area, } /* find the translated Type-5 for this Type-7 */ - nssa = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + nssa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( type7->header); prefix.family = AF_INET6; prefix.prefixlen = nssa->prefix.prefix_length; @@ -437,12 +435,10 @@ static struct ospf6_lsa *ospf6_lsa_translated_nssa_new(struct ospf6_area *area, /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - extnew = (struct ospf6_as_external_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); - ext = (struct ospf6_as_external_lsa - *)((caddr_t)(type7->header) - + sizeof(struct ospf6_lsa_header)); + extnew = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( + lsa_header); + ext = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( + type7->header); old_ptr = (caddr_t)((caddr_t)ext + sizeof(struct ospf6_as_external_lsa)); new_ptr = (caddr_t)((caddr_t)extnew @@ -550,7 +546,7 @@ struct ospf6_lsa *ospf6_translated_nssa_refresh(struct ospf6_area *area, "%s: try to find translated Type-5 LSA for %s", __func__, type7->name); - ext_lsa = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + ext_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( type7->header); prefix.family = AF_INET6; prefix.prefixlen = ext_lsa->prefix.prefix_length; @@ -618,7 +614,7 @@ static void ospf6_abr_translate_nssa(struct ospf6_area *area, struct ospf6 *ospf6; ospf6 = area->ospf6; - nssa_lsa = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + nssa_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( lsa->header); if (!CHECK_FLAG(nssa_lsa->prefix.prefix_options, @@ -1244,9 +1240,8 @@ void ospf6_nssa_lsa_originate(struct ospf6_route *route, /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - as_external_lsa = (struct ospf6_as_external_lsa - *)((caddr_t)lsa_header - + sizeof(struct ospf6_lsa_header)); + as_external_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( + lsa_header); p = (caddr_t)((caddr_t)as_external_lsa + sizeof(struct ospf6_as_external_lsa)); diff --git a/ospf6d/ospf6_route.h b/ospf6d/ospf6_route.h index c9486bc..8881349 100644 --- a/ospf6d/ospf6_route.h +++ b/ospf6d/ospf6_route.h @@ -115,6 +115,7 @@ struct ospf6_path { /* Cost */ uint8_t metric_type; uint32_t cost; + uint32_t redistribute_cost; struct prefix ls_prefix; @@ -139,6 +140,8 @@ struct ospf6_path { #define OSPF6_PATH_COST_IS_CONFIGURED(path) (path.u.cost_config != OSPF_AREA_RANGE_COST_UNSPEC) +#define OSPF6_EXT_PATH_METRIC_MAX 0x00ffffff + #include "prefix.h" #include "table.h" #include "bitfield.h" diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 17cdcda..36864d2 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -1017,7 +1017,7 @@ static uint8_t *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length, case OSPFv3WWLSDBCHECKSUM: return SNMP_INTEGER(ntohs(lsa->header->checksum)); case OSPFv3WWLSDBADVERTISEMENT: - *var_len = ntohs(lsa->header->length); + *var_len = ospf6_lsa_size(lsa->header); return (uint8_t *)lsa->header; case OSPFv3WWLSDBTYPEKNOWN: return SNMP_INTEGER(OSPF6_LSA_IS_KNOWN(lsa->header->type) diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index e39ae50..7879dae 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -130,10 +130,10 @@ static struct ospf6_vertex *ospf6_vertex_create(struct ospf6_lsa *lsa) v->lsa = lsa; /* capability bits + options */ - v->capability = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header)); - v->options[0] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 1); - v->options[1] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 2); - v->options[2] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 3); + v->capability = *(uint8_t *)(ospf6_lsa_header_end(lsa->header)); + v->options[0] = *(uint8_t *)(ospf6_lsa_header_end(lsa->header) + 1); + v->options[1] = *(uint8_t *)(ospf6_lsa_header_end(lsa->header) + 2); + v->options[2] = *(uint8_t *)(ospf6_lsa_header_end(lsa->header) + 3); v->nh_list = list_new(); v->nh_list->cmp = (int (*)(void *, void *))ospf6_nexthop_cmp; @@ -187,7 +187,7 @@ static struct ospf6_lsa *ospf6_lsdesc_lsa(caddr_t lsdesc, inet_ntop(AF_INET, &adv_router, abuf, sizeof(abuf)); if (lsa) zlog_debug(" Link to: %s len %u, V %s", lsa->name, - ntohs(lsa->header->length), v->name); + ospf6_lsa_size(lsa->header), v->name); else zlog_debug(" Link to: [%s Id:%s Adv:%s] No LSA , V %s", ospf6_lstype_name(type), ibuf, abuf, @@ -206,8 +206,8 @@ static char *ospf6_lsdesc_backlink(struct ospf6_lsa *lsa, caddr_t lsdesc, size = (OSPF6_LSA_IS_TYPE(ROUTER, lsa) ? sizeof(struct ospf6_router_lsdesc) : sizeof(struct ospf6_network_lsdesc)); - for (backlink = OSPF6_LSA_HEADER_END(lsa->header) + 4; - backlink + size <= OSPF6_LSA_END(lsa->header); backlink += size) { + for (backlink = ospf6_lsa_header_end(lsa->header) + 4; + backlink + size <= ospf6_lsa_end(lsa->header); backlink += size) { assert(!(OSPF6_LSA_IS_TYPE(NETWORK, lsa) && VERTEX_IS_TYPE(NETWORK, v))); @@ -290,7 +290,7 @@ static void ospf6_nexthop_calc(struct ospf6_vertex *w, struct ospf6_vertex *v, != lsa->header->id) continue; - link_lsa = (struct ospf6_link_lsa *)OSPF6_LSA_HEADER_END( + link_lsa = (struct ospf6_link_lsa *)ospf6_lsa_header_end( lsa->header); if (IS_OSPF6_DEBUG_SPF(PROCESS)) { inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf, @@ -510,8 +510,8 @@ void ospf6_spf_calculation(uint32_t router_id, size = (VERTEX_IS_TYPE(ROUTER, v) ? sizeof(struct ospf6_router_lsdesc) : sizeof(struct ospf6_network_lsdesc)); - for (lsdesc = OSPF6_LSA_HEADER_END(v->lsa->header) + 4; - lsdesc + size <= OSPF6_LSA_END(v->lsa->header); + for (lsdesc = ospf6_lsa_header_end(v->lsa->header) + 4; + lsdesc + size <= ospf6_lsa_end(v->lsa->header); lsdesc += size) { lsa = ospf6_lsdesc_lsa(lsdesc, v); if (lsa == NULL) @@ -1011,7 +1011,7 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, continue; } lsa_header = rtr_lsa->header; - total_lsa_length += (ntohs(lsa_header->length) - lsa_length); + total_lsa_length += (ospf6_lsa_size(lsa_header) - lsa_length); num_lsa++; rtr_lsa = ospf6_lsdb_next(end, rtr_lsa); } @@ -1044,11 +1044,11 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, if (!OSPF6_LSA_IS_MAXAGE(rtr_lsa)) { /* Append first Link State ID LSA */ lsa_header = rtr_lsa->header; - memcpy(new_header, lsa_header, ntohs(lsa_header->length)); + memcpy(new_header, lsa_header, ospf6_lsa_size(lsa_header)); /* Assign new lsa length as aggregated length. */ ((struct ospf6_lsa_header *)new_header)->length = htons(total_lsa_length); - new_header += ntohs(lsa_header->length); + new_header += ospf6_lsa_size(lsa_header); num_lsa--; } @@ -1063,20 +1063,19 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, } if (IS_OSPF6_DEBUG_SPF(PROCESS)) { - lsd = OSPF6_LSA_HEADER_END(rtr_lsa->header) + 4; + lsd = ospf6_lsa_header_end(rtr_lsa->header) + 4; interface_id = ROUTER_LSDESC_GET_IFID(lsd); inet_ntop(AF_INET, &interface_id, ifbuf, sizeof(ifbuf)); - zlog_debug( - "%s: Next Router LSA %s to aggreat with len %u interface_id %s", - __func__, rtr_lsa->name, - ntohs(lsa_header->length), ifbuf); + zlog_debug("%s: Next Router LSA %s to aggreat with len %u interface_id %s", + __func__, rtr_lsa->name, + ospf6_lsa_size(lsa_header), ifbuf); } /* Append Next Link State ID LSA */ lsa_header = rtr_lsa->header; - memcpy(new_header, (OSPF6_LSA_HEADER_END(rtr_lsa->header) + 4), - (ntohs(lsa_header->length) - lsa_length)); - new_header += (ntohs(lsa_header->length) - lsa_length); + memcpy(new_header, (ospf6_lsa_header_end(rtr_lsa->header) + 4), + (ospf6_lsa_size(lsa_header) - lsa_length)); + new_header += (ospf6_lsa_size(lsa_header) - lsa_length); num_lsa--; rtr_lsa = ospf6_lsdb_next(end, rtr_lsa); @@ -1091,8 +1090,8 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, if (IS_OSPF6_DEBUG_SPF(PROCESS)) zlog_debug("%s: LSA %s id %u type 0%x len %u num_lsa %u", __func__, lsa->name, ntohl(lsa->header->id), - ntohs(lsa->header->type), ntohs(lsa->header->length), - num_lsa); + ntohs(lsa->header->type), + ospf6_lsa_size(lsa->header), num_lsa); return lsa; } @@ -1137,7 +1136,7 @@ int ospf6_ase_calculate_route(struct ospf6 *ospf6, struct ospf6_lsa *lsa, return 0; } - external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END( + external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( lsa->header); prefix.family = AF_INET6; prefix.prefixlen = external->prefix.prefix_length; diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 3245578..911f356 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -289,7 +289,7 @@ static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS) if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD) ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix, api.nexthop_num, nexthop, api.tag, - ospf6); + ospf6, api.metric); else ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix, ospf6); |