From 7c9a79f1823cdc59a94ddf7c442a604feb054544 Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Tue, 9 Apr 2024 15:01:23 +1000 Subject: [PATCH 01/14] ospf6d: factor out generic TLV handling In preperation for Extended LSA types and their TLVs, factor out the TLV handling from the Gracefull Restart functionality. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_asbr.c | 1 + ospf6d/ospf6_flood.c | 1 + ospf6d/ospf6_gr.c | 9 ++++--- ospf6d/ospf6_gr.h | 53 +++++------------------------------- ospf6d/ospf6_gr_helper.c | 25 ++++++++--------- ospf6d/ospf6_interface.c | 1 + ospf6d/ospf6_intra.c | 1 + ospf6d/ospf6_message.c | 1 + ospf6d/ospf6_neighbor.c | 1 + ospf6d/ospf6_tlv.h | 58 ++++++++++++++++++++++++++++++++++++++++ ospf6d/ospf6_top.c | 1 + ospf6d/ospf6_zebra.c | 1 + ospf6d/ospf6d.c | 1 + ospf6d/subdir.am | 1 + 14 files changed, 92 insertions(+), 63 deletions(-) create mode 100644 ospf6d/ospf6_tlv.h diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index 2065527c93..caac704624 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -39,6 +39,7 @@ #include "ospf6d.h" #include "ospf6_spf.h" #include "ospf6_nssa.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" diff --git a/ospf6d/ospf6_flood.c b/ospf6d/ospf6_flood.c index b87aa2ffe1..04ff35083f 100644 --- a/ospf6d/ospf6_flood.c +++ b/ospf6d/ospf6_flood.c @@ -26,6 +26,7 @@ #include "ospf6_flood.h" #include "ospf6_nssa.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" unsigned char conf_debug_ospf6_flooding; diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index ab119a4ea4..7295dee0f0 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -30,6 +30,7 @@ #include "ospf6d/ospf6_flood.h" #include "ospf6d/ospf6_intra.h" #include "ospf6d/ospf6_spf.h" +#include "ospf6d/ospf6_tlv.h" #include "ospf6d/ospf6_gr.h" #include "ospf6d/ospf6_gr_clippy.c" @@ -57,13 +58,13 @@ static int ospf6_gr_lsa_originate(struct ospf6_interface *oi, 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); - grace_lsa->tlv_period.header.length = htons(GRACE_PERIOD_LENGTH); + grace_lsa->tlv_period.header.type = htons(TLV_GRACE_PERIOD_TYPE); + grace_lsa->tlv_period.header.length = htons(TLV_GRACE_PERIOD_LENGTH); grace_lsa->tlv_period.interval = htonl(gr_info->grace_period); /* Put restart reason. */ - grace_lsa->tlv_reason.header.type = htons(RESTART_REASON_TYPE); - grace_lsa->tlv_reason.header.length = htons(RESTART_REASON_LENGTH); + grace_lsa->tlv_reason.header.type = htons(TLV_GRACE_RESTART_REASON_TYPE); + grace_lsa->tlv_reason.header.length = htons(TLV_GRACE_RESTART_REASON_LENGTH); grace_lsa->tlv_reason.reason = reason; /* Fill LSA Header */ diff --git a/ospf6d/ospf6_gr.h b/ospf6d/ospf6_gr.h index 84ef3aeb8a..eddd63e431 100644 --- a/ospf6d/ospf6_gr.h +++ b/ospf6d/ospf6_gr.h @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * OSPF6 Graceful Retsart helper functions. + * OSPF6 Graceful Restart helper functions. + * Ref RFC 5187 * * Copyright (C) 2021-22 Vmware, Inc. * Rajesh Kumar Girada @@ -60,58 +61,16 @@ enum ospf6_gr_helper_rejected_reason { OSPF6_HELPER_RESTARTING, }; -#ifdef roundup -#define ROUNDUP(val, gran) roundup(val, gran) -#else /* roundup */ -#define ROUNDUP(val, gran) (((val)-1 | (gran)-1) + 1) -#endif /* roundup */ -/* - * Generic TLV (type, length, value) macros - */ -struct tlv_header { - uint16_t type; /* Type of Value */ - uint16_t length; /* Length of Value portion only, in bytes */ -}; - -#define TLV_HDR_SIZE (sizeof(struct tlv_header)) - -#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t))) - -#define TLV_SIZE(tlvh) (uint32_t)(TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh)) - -#define TLV_HDR_TOP(lsah) \ - (struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE) - -#define TLV_HDR_NEXT(tlvh) \ - (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh)) - -/* Ref RFC5187 appendix-A */ -/* Grace period TLV */ -#define GRACE_PERIOD_TYPE 1 -#define GRACE_PERIOD_LENGTH 4 -struct grace_tlv_graceperiod { - struct tlv_header header; - uint32_t interval; -}; -#define GRACE_PERIOD_TLV_SIZE sizeof(struct grace_tlv_graceperiod) - -/* Restart reason TLV */ -#define RESTART_REASON_TYPE 2 -#define RESTART_REASON_LENGTH 1 -struct grace_tlv_restart_reason { - struct tlv_header header; - uint8_t reason; - uint8_t reserved[3]; -}; -#define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct grace_tlv_restart_reason) +#define GRACE_PERIOD_TLV_SIZE sizeof(struct tlv_grace_period) +#define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct tlv_grace_restart_reason) #define OSPF6_GRACE_LSA_MIN_SIZE \ GRACE_PERIOD_TLV_SIZE + GRACE_RESTART_REASON_TLV_SIZE struct ospf6_grace_lsa { - struct grace_tlv_graceperiod tlv_period; - struct grace_tlv_restart_reason tlv_reason; + struct tlv_grace_period tlv_period; + struct tlv_grace_restart_reason tlv_reason; }; struct advRtr { diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c index f0e5d3a15c..e02a841d00 100644 --- a/ospf6d/ospf6_gr_helper.c +++ b/ospf6d/ospf6_gr_helper.c @@ -32,6 +32,7 @@ #include "ospf6_neighbor.h" #include "ospf6_intra.h" #include "ospf6d.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" #include "ospf6d/ospf6_gr_helper_clippy.c" @@ -129,8 +130,8 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa, { struct ospf6_lsa_header *lsah = NULL; struct tlv_header *tlvh = NULL; - struct grace_tlv_graceperiod *gracePeriod; - struct grace_tlv_restart_reason *grReason; + struct tlv_grace_period *gracePeriod; + struct tlv_grace_restart_reason *grReason; uint16_t length = 0; int sum = 0; @@ -157,8 +158,8 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa, } switch (ntohs(tlvh->type)) { - case GRACE_PERIOD_TYPE: - gracePeriod = (struct grace_tlv_graceperiod *)tlvh; + case TLV_GRACE_PERIOD_TYPE: + gracePeriod = (struct tlv_grace_period *)tlvh; *interval = ntohl(gracePeriod->interval); sum += TLV_SIZE(tlvh); @@ -167,8 +168,8 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa, || *interval < OSPF6_MIN_GRACE_INTERVAL) return OSPF6_FAILURE; break; - case RESTART_REASON_TYPE: - grReason = (struct grace_tlv_restart_reason *)tlvh; + case TLV_GRACE_RESTART_REASON_TYPE: + grReason = (struct tlv_grace_restart_reason *)tlvh; *reason = grReason->reason; sum += TLV_SIZE(tlvh); @@ -1218,8 +1219,8 @@ static int ospf6_grace_lsa_show_info(struct vty *vty, struct ospf6_lsa *lsa, { struct ospf6_lsa_header *lsah = NULL; struct tlv_header *tlvh = NULL; - struct grace_tlv_graceperiod *gracePeriod; - struct grace_tlv_restart_reason *grReason; + struct tlv_grace_period *gracePeriod; + struct tlv_grace_restart_reason *grReason; uint16_t length = 0; int sum = 0; @@ -1255,8 +1256,8 @@ static int ospf6_grace_lsa_show_info(struct vty *vty, struct ospf6_lsa *lsa, } switch (ntohs(tlvh->type)) { - case GRACE_PERIOD_TYPE: - gracePeriod = (struct grace_tlv_graceperiod *)tlvh; + case TLV_GRACE_PERIOD_TYPE: + gracePeriod = (struct tlv_grace_period *)tlvh; sum += TLV_SIZE(tlvh); if (vty) { @@ -1272,8 +1273,8 @@ static int ospf6_grace_lsa_show_info(struct vty *vty, struct ospf6_lsa *lsa, ntohl(gracePeriod->interval)); } break; - case RESTART_REASON_TYPE: - grReason = (struct grace_tlv_restart_reason *)tlvh; + case TLV_GRACE_RESTART_REASON_TYPE: + grReason = (struct tlv_grace_restart_reason *)tlvh; sum += TLV_SIZE(tlvh); if (vty) { if (use_json) diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 7f813ce3cc..25c0392d99 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -30,6 +30,7 @@ #include "ospf6d.h" #include "ospf6_bfd.h" #include "ospf6_zebra.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" #include "ospf6_proto.h" diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index b06796ada0..5d9beb561a 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -32,6 +32,7 @@ #include "ospf6_flood.h" #include "ospf6d.h" #include "ospf6_spf.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" unsigned char conf_debug_ospf6_brouter = 0; diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index a6ee8d8b01..e8380af5c4 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -33,6 +33,7 @@ #include "ospf6_flood.h" #include "ospf6d.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include #include "lib/libospf.h" diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index 0e44f2a142..acf15da4c3 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -30,6 +30,7 @@ #include "ospf6_lsa.h" #include "ospf6_spf.h" #include "ospf6_zebra.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" diff --git a/ospf6d/ospf6_tlv.h b/ospf6d/ospf6_tlv.h new file mode 100644 index 0000000000..f94d7f2621 --- /dev/null +++ b/ospf6d/ospf6_tlv.h @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * OSPFv3 Type Length Value. + * + */ + +#ifndef OSPF6_TLV_H +#define OSPF6_TLV_H + +/* + * Generic TLV (type, length, value) macros + */ +struct tlv_header { + uint16_t type; /* Type of Value */ + uint16_t length; /* Length of Value portion only, in bytes */ +}; + +#ifdef roundup +#define ROUNDUP(val, gran) roundup(val, gran) +#else /* roundup */ +#define ROUNDUP(val, gran) (((val)-1 | (gran)-1) + 1) +#endif /* roundup */ + +#define TLV_HDR_SIZE (sizeof(struct tlv_header)) + +#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t))) + +#define TLV_SIZE(tlvh) ((uint32_t)(TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))) + +#define TLV_HDR_TOP(lsah) \ + ((struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE)) + +#define TLV_HDR_NEXT(tlvh) \ + ((struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))) + +/* + * RFC 5187 - OSPFv3 Graceful Restart - Grace-LSA + * Graceful restart predates Extended-LSA TLVs and IANA TLV register. + */ +/* Grace period TLV. */ +#define TLV_GRACE_PERIOD_TYPE 1 +#define TLV_GRACE_PERIOD_LENGTH 4 +struct tlv_grace_period { + struct tlv_header header; + uint32_t interval; +}; + +/* Restart reason TLV. */ +#define TLV_GRACE_RESTART_REASON_TYPE 2 +#define TLV_GRACE_RESTART_REASON_LENGTH 1 +struct tlv_grace_restart_reason { + struct tlv_header header; + uint8_t reason; + uint8_t reserved[3]; +}; + + +#endif /* OSPF6_TLV_H */ diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index a3fb205374..ad487f3565 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -37,6 +37,7 @@ #include "ospf6_intra.h" #include "ospf6_spf.h" #include "ospf6d.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" #include "ospf6_nssa.h" diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 911f3567d4..466301309f 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -27,6 +27,7 @@ #include "ospf6_zebra.h" #include "ospf6d.h" #include "ospf6_area.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index d90a950d79..e4e0354fc9 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -30,6 +30,7 @@ #include "ospf6_flood.h" #include "ospf6d.h" #include "ospf6_bfd.h" +#include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" #include "ospf6_nssa.h" diff --git a/ospf6d/subdir.am b/ospf6d/subdir.am index 5f89af9508..a7bd94bd77 100644 --- a/ospf6d/subdir.am +++ b/ospf6d/subdir.am @@ -58,6 +58,7 @@ noinst_HEADERS += \ ospf6d/ospf6_route.h \ ospf6d/ospf6_routemap_nb.h \ ospf6d/ospf6_spf.h \ + ospf6d/ospf6_tlv.h \ ospf6d/ospf6_top.h \ ospf6d/ospf6_zebra.h \ ospf6d/ospf6d.h \ From 89e18bfad1cb0e01af904d539da1d4a6aeb2ae5b Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Wed, 15 May 2024 16:42:43 +1000 Subject: [PATCH 02/14] ospf6d: move lsa structs to ospf6_lsa.h It will be cleaner to have the LSAs in a single header and the future TLVs in a single header. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_abr.h | 16 -------- ospf6d/ospf6_asbr.h | 11 ----- ospf6d/ospf6_gr.c | 1 + ospf6d/ospf6_interface.c | 2 +- ospf6d/ospf6_intra.h | 60 --------------------------- ospf6d/ospf6_lsa.h | 89 ++++++++++++++++++++++++++++++++++++++++ ospf6d/ospf6_spf.c | 2 +- tests/ospf6d/test_lsdb.c | 1 + 8 files changed, 93 insertions(+), 89 deletions(-) diff --git a/ospf6d/ospf6_abr.h b/ospf6d/ospf6_abr.h index 52686ed49f..ab9e000d43 100644 --- a/ospf6d/ospf6_abr.h +++ b/ospf6d/ospf6_abr.h @@ -17,22 +17,6 @@ extern unsigned char conf_debug_ospf6_abr; #define OSPF6_DEBUG_ABR_OFF() (conf_debug_ospf6_abr = 0) #define IS_OSPF6_DEBUG_ABR (conf_debug_ospf6_abr) -/* Inter-Area-Prefix-LSA */ -#define OSPF6_INTER_PREFIX_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ -struct ospf6_inter_prefix_lsa { - uint32_t metric; - struct ospf6_prefix prefix; -}; - -/* Inter-Area-Router-LSA */ -#define OSPF6_INTER_ROUTER_LSA_FIX_SIZE 12U -struct ospf6_inter_router_lsa { - uint8_t mbz; - uint8_t options[3]; - uint32_t metric; - uint32_t router_id; -}; - #define OSPF6_ABR_SUMMARY_METRIC(E) \ (ntohl((E)->metric & htonl(OSPF6_EXT_PATH_METRIC_MAX))) #define OSPF6_ABR_SUMMARY_METRIC_SET(E, C) \ diff --git a/ospf6d/ospf6_asbr.h b/ospf6d/ospf6_asbr.h index 21e6d898e8..ace3ba8488 100644 --- a/ospf6d/ospf6_asbr.h +++ b/ospf6d/ospf6_asbr.h @@ -79,17 +79,6 @@ struct ospf6_external_aggr_rt { struct hash *match_extnl_hash; }; -/* AS-External-LSA */ -#define OSPF6_AS_EXTERNAL_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ -struct ospf6_as_external_lsa { - uint32_t bits_metric; - - struct ospf6_prefix prefix; - /* followed by none or one forwarding address */ - /* followed by none or one external route tag */ - /* followed by none or one referenced LS-ID */ -}; - #define OSPF6_ASBR_BIT_T ntohl (0x01000000) #define OSPF6_ASBR_BIT_F ntohl (0x02000000) #define OSPF6_ASBR_BIT_E ntohl (0x04000000) diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index 7295dee0f0..543de1c9e3 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -16,6 +16,7 @@ #include "printfrr.h" #include "lib_errors.h" +#include "ospf6_proto.h" #include "ospf6d/ospf6_lsa.h" #include "ospf6d/ospf6_lsdb.h" #include "ospf6d/ospf6_route.h" diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 25c0392d99..60f92385dd 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -14,6 +14,7 @@ #include "plist.h" #include "zclient.h" +#include "ospf6_proto.h" #include "ospf6_lsa.h" #include "ospf6_lsdb.h" #include "ospf6_top.h" @@ -33,7 +34,6 @@ #include "ospf6_tlv.h" #include "ospf6_gr.h" #include "lib/json.h" -#include "ospf6_proto.h" #include "lib/keychain.h" #include "ospf6_auth_trailer.h" #include "ospf6d/ospf6_interface_clippy.c" diff --git a/ospf6d/ospf6_intra.h b/ospf6d/ospf6_intra.h index 7d154cb4c6..f77089fc05 100644 --- a/ospf6d/ospf6_intra.h +++ b/ospf6d/ospf6_intra.h @@ -55,30 +55,6 @@ extern in_addr_t conf_debug_ospf6_brouter_specific_area_id; (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA \ && conf_debug_ospf6_brouter_specific_area_id == (area_id)) -/* Router-LSA */ -#define OSPF6_ROUTER_LSA_MIN_SIZE 4U -struct ospf6_router_lsa { - uint8_t bits; - uint8_t options[3]; - /* followed by ospf6_router_lsdesc(s) */ -}; - -/* Link State Description in Router-LSA */ -#define OSPF6_ROUTER_LSDESC_FIX_SIZE 16U -struct ospf6_router_lsdesc { - uint8_t type; - uint8_t reserved; - uint16_t metric; /* output cost */ - uint32_t interface_id; - uint32_t neighbor_interface_id; - in_addr_t neighbor_router_id; -}; - -#define OSPF6_ROUTER_LSDESC_POINTTOPOINT 1 -#define OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK 2 -#define OSPF6_ROUTER_LSDESC_STUB_NETWORK 3 -#define OSPF6_ROUTER_LSDESC_VIRTUAL_LINK 4 - enum stub_router_mode { OSPF6_NOT_STUB_ROUTER, OSPF6_IS_STUB_ROUTER, @@ -99,42 +75,6 @@ enum stub_router_mode { #define ROUTER_LSDESC_GET_NBR_ROUTERID(x) \ (((struct ospf6_router_lsdesc *)(x))->neighbor_router_id) -/* Network-LSA */ -#define OSPF6_NETWORK_LSA_MIN_SIZE 4U -struct ospf6_network_lsa { - uint8_t reserved; - uint8_t options[3]; - /* followed by ospf6_netowrk_lsd(s) */ -}; - -/* Link State Description in Router-LSA */ -#define OSPF6_NETWORK_LSDESC_FIX_SIZE 4U -struct ospf6_network_lsdesc { - in_addr_t router_id; -}; -#define NETWORK_LSDESC_GET_NBR_ROUTERID(x) \ - (((struct ospf6_network_lsdesc *)(x))->router_id) - -/* Link-LSA */ -#define OSPF6_LINK_LSA_MIN_SIZE 24U /* w/o 1st IPv6 prefix */ -struct ospf6_link_lsa { - uint8_t priority; - uint8_t options[3]; - struct in6_addr linklocal_addr; - uint32_t prefix_num; - /* followed by ospf6 prefix(es) */ -}; - -/* Intra-Area-Prefix-LSA */ -#define OSPF6_INTRA_PREFIX_LSA_MIN_SIZE 12U /* w/o 1st IPv6 prefix */ -struct ospf6_intra_prefix_lsa { - uint16_t prefix_num; - uint16_t ref_type; - uint32_t ref_id; - in_addr_t ref_adv_router; - /* followed by ospf6 prefix(es) */ -}; - #define OSPF6_ROUTER_LSA_SCHEDULE(oa) \ do { \ diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index 4fc2f0dd18..d2501c42ce 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -117,6 +117,95 @@ static inline uint16_t ospf6_lsa_size(struct ospf6_lsa_header *header) #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1)) +/* Router-LSA */ +#define OSPF6_ROUTER_LSA_MIN_SIZE 4U +struct ospf6_router_lsa { + uint8_t bits; + uint8_t options[3]; + /* followed by ospf6_router_lsdesc(s) */ +}; + +/* Link State Description in Router-LSA */ +#define OSPF6_ROUTER_LSDESC_FIX_SIZE 16U +struct ospf6_router_lsdesc { + uint8_t type; + uint8_t reserved; + uint16_t metric; /* output cost */ + uint32_t interface_id; + uint32_t neighbor_interface_id; + in_addr_t neighbor_router_id; +}; + +#define OSPF6_ROUTER_LSDESC_POINTTOPOINT 1 +#define OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK 2 +#define OSPF6_ROUTER_LSDESC_STUB_NETWORK 3 +#define OSPF6_ROUTER_LSDESC_VIRTUAL_LINK 4 + +/* Network-LSA */ +#define OSPF6_NETWORK_LSA_MIN_SIZE 4U +struct ospf6_network_lsa { + uint8_t reserved; + uint8_t options[3]; + /* followed by ospf6_network_lsdesc(s) */ +}; + +/* Link State Description in Network-LSA */ +#define OSPF6_NETWORK_LSDESC_FIX_SIZE 4U +struct ospf6_network_lsdesc { + in_addr_t router_id; +}; +#define NETWORK_LSDESC_GET_NBR_ROUTERID(x) \ + (((struct ospf6_network_lsdesc *)(x))->router_id) + +/* Inter-Area-Prefix-LSA */ +#define OSPF6_INTER_PREFIX_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ +struct ospf6_inter_prefix_lsa { + uint32_t metric; + struct ospf6_prefix prefix; +}; + +/* Inter-Area-Router-LSA */ +#define OSPF6_INTER_ROUTER_LSA_FIX_SIZE 12U +struct ospf6_inter_router_lsa { + uint8_t mbz; + uint8_t options[3]; + uint32_t metric; + uint32_t router_id; +}; + +/* AS-External-LSA */ +#define OSPF6_AS_EXTERNAL_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ +struct ospf6_as_external_lsa { + uint32_t bits_metric; + + struct ospf6_prefix prefix; + /* followed by none or one forwarding address */ + /* followed by none or one external route tag */ + /* followed by none or one referenced LS-ID */ +}; + +/* FIXME: move nssa lsa here. */ + +/* Link-LSA */ +#define OSPF6_LINK_LSA_MIN_SIZE 24U /* w/o 1st IPv6 prefix */ +struct ospf6_link_lsa { + uint8_t priority; + uint8_t options[3]; + struct in6_addr linklocal_addr; + uint32_t prefix_num; + /* followed by ospf6 prefix(es) */ +}; + +/* Intra-Area-Prefix-LSA */ +#define OSPF6_INTRA_PREFIX_LSA_MIN_SIZE 12U /* w/o 1st IPv6 prefix */ +struct ospf6_intra_prefix_lsa { + uint16_t prefix_num; + uint16_t ref_type; + uint32_t ref_id; + in_addr_t ref_adv_router; + /* followed by ospf6 prefix(es) */ +}; + struct ospf6_lsa { char name[64]; /* dump string */ diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 7879dae8d7..5c6c1f0f26 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -16,11 +16,11 @@ #include "frrevent.h" #include "lib_errors.h" +#include "ospf6_proto.h" #include "ospf6_lsa.h" #include "ospf6_lsdb.h" #include "ospf6_route.h" #include "ospf6_area.h" -#include "ospf6_proto.h" #include "ospf6_abr.h" #include "ospf6_asbr.h" #include "ospf6_spf.h" diff --git a/tests/ospf6d/test_lsdb.c b/tests/ospf6d/test_lsdb.c index f9df73538a..9cec4a3182 100644 --- a/tests/ospf6d/test_lsdb.c +++ b/tests/ospf6d/test_lsdb.c @@ -12,6 +12,7 @@ #include "vector.h" #include "vty.h" +#include "ospf6d/ospf6_proto.h" /* for struct ospf6_prefix */ #include "ospf6d/ospf6_lsa.h" #include "ospf6d/ospf6_lsdb.h" From 33f90a5a1a41ebbfa73149b663efb7ec08df52d6 Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Wed, 15 May 2024 16:46:58 +1000 Subject: [PATCH 03/14] ospf6d: add space between multi-line macros For readability Signed-off-by: Andrew Cooks --- ospf6d/ospf6_intra.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ospf6d/ospf6_intra.h b/ospf6d/ospf6_intra.h index f77089fc05..fafa6d1282 100644 --- a/ospf6d/ospf6_intra.h +++ b/ospf6d/ospf6_intra.h @@ -13,10 +13,13 @@ extern in_addr_t conf_debug_ospf6_brouter_specific_area_id; #define OSPF6_DEBUG_BROUTER_SUMMARY 0x01 #define OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER 0x02 #define OSPF6_DEBUG_BROUTER_SPECIFIC_AREA 0x04 + #define OSPF6_DEBUG_BROUTER_ON() \ (conf_debug_ospf6_brouter |= OSPF6_DEBUG_BROUTER_SUMMARY) + #define OSPF6_DEBUG_BROUTER_OFF() \ (conf_debug_ospf6_brouter &= ~OSPF6_DEBUG_BROUTER_SUMMARY) + #define IS_OSPF6_DEBUG_BROUTER \ (conf_debug_ospf6_brouter & OSPF6_DEBUG_BROUTER_SUMMARY) @@ -26,14 +29,17 @@ extern in_addr_t conf_debug_ospf6_brouter_specific_area_id; conf_debug_ospf6_brouter |= \ OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER; \ } while (0) + #define OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF() \ do { \ conf_debug_ospf6_brouter_specific_router_id = 0; \ conf_debug_ospf6_brouter &= \ ~OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER; \ } while (0) + #define IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER \ (conf_debug_ospf6_brouter & OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER) + #define IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID(router_id) \ (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER \ && conf_debug_ospf6_brouter_specific_router_id == (router_id)) @@ -43,14 +49,17 @@ extern in_addr_t conf_debug_ospf6_brouter_specific_area_id; conf_debug_ospf6_brouter_specific_area_id = (area_id); \ conf_debug_ospf6_brouter |= OSPF6_DEBUG_BROUTER_SPECIFIC_AREA; \ } while (0) + #define OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF() \ do { \ conf_debug_ospf6_brouter_specific_area_id = 0; \ conf_debug_ospf6_brouter &= \ ~OSPF6_DEBUG_BROUTER_SPECIFIC_AREA; \ } while (0) + #define IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA \ (conf_debug_ospf6_brouter & OSPF6_DEBUG_BROUTER_SPECIFIC_AREA) + #define IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(area_id) \ (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA \ && conf_debug_ospf6_brouter_specific_area_id == (area_id)) @@ -68,10 +77,13 @@ enum stub_router_mode { : 0) #define ROUTER_LSDESC_GET_METRIC(x) \ (ntohs(((struct ospf6_router_lsdesc *)(x))->metric)) + #define ROUTER_LSDESC_GET_IFID(x) \ (ntohl(((struct ospf6_router_lsdesc *)(x))->interface_id)) + #define ROUTER_LSDESC_GET_NBR_IFID(x) \ (ntohl(((struct ospf6_router_lsdesc *)(x))->neighbor_interface_id)) + #define ROUTER_LSDESC_GET_NBR_ROUTERID(x) \ (((struct ospf6_router_lsdesc *)(x))->neighbor_router_id) @@ -82,18 +94,21 @@ enum stub_router_mode { event_add_event(master, ospf6_router_lsa_originate, \ oa, 0, &(oa)->thread_router_lsa); \ } while (0) + #define OSPF6_NETWORK_LSA_SCHEDULE(oi) \ do { \ if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \ event_add_event(master, ospf6_network_lsa_originate, \ oi, 0, &(oi)->thread_network_lsa); \ } while (0) + #define OSPF6_LINK_LSA_SCHEDULE(oi) \ do { \ if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \ event_add_event(master, ospf6_link_lsa_originate, oi, \ 0, &(oi)->thread_link_lsa); \ } while (0) + #define OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oa) \ do { \ if (CHECK_FLAG((oa)->flag, OSPF6_AREA_ENABLE)) \ @@ -101,6 +116,7 @@ enum stub_router_mode { master, ospf6_intra_prefix_lsa_originate_stub, \ oa, 0, &(oa)->thread_intra_prefix_lsa); \ } while (0) + #define OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi) \ do { \ if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \ From 1290a06f5fcae26bdf941f0aedda20150ab01ba3 Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Thu, 6 Jun 2024 08:18:27 +1000 Subject: [PATCH 04/14] ospf6d: cleanup Router-LSAs Options bit order Signed-off-by: Andrew Cooks --- ospf6d/ospf6_proto.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ospf6d/ospf6_proto.h b/ospf6d/ospf6_proto.h index 4307ee3c6e..645a408781 100644 --- a/ospf6d/ospf6_proto.h +++ b/ospf6d/ospf6_proto.h @@ -16,11 +16,12 @@ #define ALLSPFROUTERS6 "ff02::5" #define ALLDROUTERS6 "ff02::6" -#define OSPF6_ROUTER_BIT_W (1 << 3) +/* RFC 5340 A.4.3 Router-LSAs Options field */ +#define OSPF6_ROUTER_BIT_NT (1 << 4) +#define OSPF6_ROUTER_BIT_W (1 << 3) /* DEPRECATED */ #define OSPF6_ROUTER_BIT_V (1 << 2) #define OSPF6_ROUTER_BIT_E (1 << 1) #define OSPF6_ROUTER_BIT_B (1 << 0) -#define OSPF6_ROUTER_BIT_NT (1 << 4) /* OSPF options */ From 1b64893e237399988998ad76799dd2ddcc4cbf8b Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Fri, 19 Jul 2024 13:04:05 +1000 Subject: [PATCH 05/14] ospf6d: replace ospf6_lsa_header_end() The void * return type of the replacement enables the removal of a cast at every point of use, and the name no longer suggests that it points to the last byte of the header. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_abr.c | 25 ++++++++----------------- ospf6d/ospf6_asbr.c | 26 +++++++++----------------- ospf6d/ospf6_gr.c | 2 +- ospf6d/ospf6_intra.c | 33 +++++++++++---------------------- ospf6d/ospf6_lsa.c | 6 +++--- ospf6d/ospf6_lsa.h | 5 +++++ ospf6d/ospf6_lsdb.c | 3 +-- ospf6d/ospf6_message.c | 11 +++-------- ospf6d/ospf6_nssa.c | 21 +++++++-------------- ospf6d/ospf6_spf.c | 6 ++---- 10 files changed, 50 insertions(+), 88 deletions(-) diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index 0c5be29ff8..343dfefcec 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -553,8 +553,7 @@ 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 *) - ospf6_lsa_header_end(lsa_header); + router_lsa = lsa_after_header(lsa_header); p = (caddr_t)router_lsa + sizeof(struct ospf6_inter_router_lsa); /* Fill Inter-Area-Router-LSA */ @@ -565,8 +564,7 @@ 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 *) - ospf6_lsa_header_end(lsa_header); + prefix_lsa = lsa_after_header(lsa_header); p = (caddr_t)prefix_lsa + sizeof(struct ospf6_inter_prefix_lsa); /* Fill Inter-Area-Prefix-LSA */ @@ -1016,8 +1014,7 @@ 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 = lsa_after_header(lsa->header); prefix.family = AF_INET6; prefix.prefixlen = prefix_lsa->prefix.prefix_length; ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa, @@ -1036,8 +1033,7 @@ 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); + router_lsa = lsa_after_header(lsa->header); ospf6_linkstate_prefix(router_lsa->router_id, htonl(0), &prefix); if (is_debug) inet_ntop(AF_INET, &router_lsa->router_id, buf, @@ -1429,8 +1425,7 @@ 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 = lsa_after_header(lsa->header); ospf6_prefix_in6_addr(&in6, prefix_lsa, &prefix_lsa->prefix); if (buf) { @@ -1452,8 +1447,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( - lsa->header); + prefix_lsa = lsa_after_header(lsa->header); if (use_json) { json_object_int_add( @@ -1489,9 +1483,7 @@ 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 = lsa_after_header(lsa->header); if (buf) inet_ntop(AF_INET, &router_lsa->router_id, buf, buflen); @@ -1508,8 +1500,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( - lsa->header); + router_lsa = lsa_after_header(lsa->header); ospf6_options_printbuf(router_lsa->options, buf, sizeof(buf)); if (use_json) { diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index caac704624..8fa85badbe 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -103,8 +103,7 @@ 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 *)ospf6_lsa_header_end( - lsa_header); + as_external_lsa = lsa_after_header(lsa_header); p = (caddr_t)((caddr_t)as_external_lsa + sizeof(struct ospf6_as_external_lsa)); @@ -217,8 +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( - lsa->header); + external = lsa_after_header(lsa->header); if (!CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T)) return 0; @@ -521,8 +519,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( - lsa->header); + external = lsa_after_header(lsa->header); if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) zlog_debug("Calculate AS-External route for %s", lsa->name); @@ -726,8 +723,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( - lsa->header); + external = lsa_after_header(lsa->header); if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL) || (IS_OSPF6_DEBUG_NSSA)) debug = true; @@ -2425,8 +2421,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( - lsa->header); + external = lsa_after_header(lsa->header); if (pos == 0) { ospf6_prefix_in6_addr(&in6, external, @@ -2460,8 +2455,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( - lsa->header); + external = lsa_after_header(lsa->header); /* bits */ snprintf(buf, sizeof(buf), "%c%c%c", @@ -3028,8 +3022,7 @@ ospf6_originate_summary_lsa(struct ospf6 *ospf6, return; } - external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( - aggr_lsa->header); + external = lsa_after_header(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, @@ -3177,7 +3170,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 = lsa_after_header(lsa->header); metric = (unsigned long)OSPF6_ASBR_METRIC(asel); tag = ospf6_as_external_lsa_get_tag(lsa); mtype = CHECK_FLAG(asel->bits_metric, @@ -3366,8 +3359,7 @@ 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 *)ospf6_lsa_header_end( - lsa->header); + ext_lsa = lsa_after_header(lsa->header); if (rt->prefix.prefixlen != ext_lsa->prefix.prefix_length) return; diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index 543de1c9e3..74a7cccd12 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -56,7 +56,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 *)ospf6_lsa_header_end(lsa_header); + grace_lsa = lsa_after_header(lsa_header); /* Put grace period. */ grace_lsa->tlv_period.header.type = htons(TLV_GRACE_PERIOD_TYPE); diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 5d9beb561a..77365ac4a2 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -243,7 +243,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 *)ospf6_lsa_header_end(lsa_header); + router_lsa = lsa_after_header(lsa_header); ospf6_router_lsa_options_set(oa, router_lsa); @@ -304,8 +304,7 @@ 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 *) - ospf6_lsa_header_end(lsa_header); + router_lsa = lsa_after_header(lsa_header); ospf6_router_lsa_options_set(oa, router_lsa); @@ -564,15 +563,13 @@ void ospf6_network_lsa_originate(struct event *thread) /* prepare buffer */ memset(buffer, 0, sizeof(buffer)); lsa_header = (struct ospf6_lsa_header *)buffer; - network_lsa = - (struct ospf6_network_lsa *)ospf6_lsa_header_end(lsa_header); + network_lsa = lsa_after_header(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 *)ospf6_lsa_header_end( - lsa->header); + link_lsa = lsa_after_header(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]; @@ -796,7 +793,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 *)ospf6_lsa_header_end(lsa_header); + link_lsa = lsa_after_header(lsa_header); /* Fill Link-LSA */ link_lsa->priority = oi->priority; @@ -1038,8 +1035,7 @@ 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 *)ospf6_lsa_header_end( - lsa_header); + intra_prefix_lsa = lsa_after_header(lsa_header); /* Fill Intra-Area-Prefix-LSA */ intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_ROUTER); @@ -1154,8 +1150,7 @@ 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 *) - ospf6_lsa_header_end(lsa_header); + intra_prefix_lsa = lsa_after_header(lsa_header); /* Fill Intra-Area-Prefix-LSA */ intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_ROUTER); @@ -1262,8 +1257,7 @@ 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 *)ospf6_lsa_header_end( - lsa_header); + intra_prefix_lsa = lsa_after_header(lsa_header); /* Fill Intra-Area-Prefix-LSA */ intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_NETWORK); @@ -1659,10 +1653,7 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, } continue; } - intra_prefix_lsa = - (struct ospf6_intra_prefix_lsa *) - ospf6_lsa_header_end( - lsa->header); + intra_prefix_lsa = lsa_after_header(lsa->header); if (intra_prefix_lsa->ref_adv_router == oa->ospf6->router_id) { @@ -1743,8 +1734,7 @@ 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 = lsa_after_header(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, @@ -1972,8 +1962,7 @@ 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 = lsa_after_header(lsa->header); prefix_num = ntohs(intra_prefix_lsa->prefix_num); start = (caddr_t)intra_prefix_lsa diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 017751825f..d8d13d4b4b 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -65,7 +65,7 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, { char *start, *end, *current; - start = ospf6_lsa_header_end(lsa->header); + start = lsa_after_header(lsa->header); end = ospf6_lsa_end(lsa->header); if (use_json) { @@ -234,8 +234,8 @@ int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2) if (length <= 0) return 0; - return memcmp(ospf6_lsa_header_end(lsa1->header), - ospf6_lsa_header_end(lsa2->header), length); + return memcmp(lsa_after_header(lsa1->header), + lsa_after_header(lsa2->header), length); } /* ospf6 age functions */ diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index d2501c42ce..25955147a7 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -92,6 +92,11 @@ static inline char *ospf6_lsa_header_end(struct ospf6_lsa_header *header) return (char *)header + sizeof(struct ospf6_lsa_header); } +static inline void *lsa_after_header(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); diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c index 9aca5550a6..e5de30484a 100644 --- a/ospf6d/ospf6_lsdb.c +++ b/ospf6d/ospf6_lsdb.c @@ -229,8 +229,7 @@ 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 = lsa_after_header(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_message.c b/ospf6d/ospf6_message.c index e8380af5c4..33d15e7243 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -1304,9 +1304,7 @@ static unsigned ospf6_lsa_examin(struct ospf6_lsa_header *lsah, 4 bytes of referenced link state ID. */ if (headeronly) break; - as_external_lsa = - (struct ospf6_as_external_lsa - *)((caddr_t)lsah + OSPF6_LSA_HEADER_SIZE); + as_external_lsa = lsa_after_header(lsah); exp_length = OSPF6_LSA_HEADER_SIZE + OSPF6_AS_EXTERNAL_LSA_MIN_SIZE; /* To find out if the last optional field (Referenced Link State @@ -1351,8 +1349,7 @@ static unsigned ospf6_lsa_examin(struct ospf6_lsa_header *lsah, by N>=0 IPv6 prefix blocks (with N declared beforehand). */ if (headeronly) break; - link_lsa = (struct ospf6_link_lsa *)((caddr_t)lsah - + OSPF6_LSA_HEADER_SIZE); + link_lsa = lsa_after_header(lsah); return ospf6_prefixes_examin( (struct ospf6_prefix *)((caddr_t)link_lsa + OSPF6_LINK_LSA_MIN_SIZE), @@ -1367,9 +1364,7 @@ static unsigned ospf6_lsa_examin(struct ospf6_lsa_header *lsah, */ if (headeronly) break; - intra_prefix_lsa = - (struct ospf6_intra_prefix_lsa - *)((caddr_t)lsah + OSPF6_LSA_HEADER_SIZE); + intra_prefix_lsa = lsa_after_header(lsah); return ospf6_prefixes_examin( (struct ospf6_prefix *)((caddr_t)intra_prefix_lsa diff --git a/ospf6d/ospf6_nssa.c b/ospf6d/ospf6_nssa.c index ea2be20cf3..8a5de468c9 100644 --- a/ospf6d/ospf6_nssa.c +++ b/ospf6d/ospf6_nssa.c @@ -52,8 +52,7 @@ 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 *)ospf6_lsa_header_end( - lsa->header); + router_lsa = lsa_after_header(lsa->header); /* ignore non-ABR routers */ if (!CHECK_FLAG(router_lsa->bits, OSPF6_ROUTER_BIT_B)) @@ -414,8 +413,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( - type7->header); + nssa = lsa_after_header(type7->header); prefix.family = AF_INET6; prefix.prefixlen = nssa->prefix.prefix_length; ospf6_prefix_in6_addr(&prefix.u.prefix6, nssa, &nssa->prefix); @@ -435,10 +433,8 @@ 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 *)ospf6_lsa_header_end( - lsa_header); - ext = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end( - type7->header); + extnew = lsa_after_header(lsa_header); + ext = lsa_after_header(type7->header); old_ptr = (caddr_t)((caddr_t)ext + sizeof(struct ospf6_as_external_lsa)); new_ptr = (caddr_t)((caddr_t)extnew @@ -546,8 +542,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( - type7->header); + ext_lsa = lsa_after_header(type7->header); prefix.family = AF_INET6; prefix.prefixlen = ext_lsa->prefix.prefix_length; ospf6_prefix_in6_addr(&prefix.u.prefix6, ext_lsa, @@ -614,8 +609,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( - lsa->header); + nssa_lsa = lsa_after_header(lsa->header); if (!CHECK_FLAG(nssa_lsa->prefix.prefix_options, OSPF6_PREFIX_OPTION_P)) { @@ -1240,8 +1234,7 @@ 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 *)ospf6_lsa_header_end( - lsa_header); + as_external_lsa = lsa_after_header(lsa_header); p = (caddr_t)((caddr_t)as_external_lsa + sizeof(struct ospf6_as_external_lsa)); diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 5c6c1f0f26..5f2c5a6c47 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -290,8 +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( - lsa->header); + link_lsa = lsa_after_header(lsa->header); if (IS_OSPF6_DEBUG_SPF(PROCESS)) { inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf, sizeof(buf)); @@ -1136,8 +1135,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( - lsa->header); + external = lsa_after_header(lsa->header); prefix.family = AF_INET6; prefix.prefixlen = external->prefix.prefix_length; ospf6_prefix_in6_addr(&prefix.u.prefix6, external, &external->prefix); From 1bb4955371b234e3833fbe8421bf31838d9aae7b Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Mon, 10 Jun 2024 13:27:54 +1000 Subject: [PATCH 06/14] ospf6d: use lsa_after_header pointer arithmetic Replaces open type casting and pointer arithmetic for readability. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_intra.c | 24 ++++++------------------ ospf6d/ospf6_lsa.h | 1 + 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 77365ac4a2..f12f125b7b 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -196,9 +196,7 @@ int ospf6_router_is_stub_router(struct ospf6_lsa *lsa) struct ospf6_router_lsa *rtr_lsa; if (lsa != NULL && OSPF6_LSA_IS_TYPE(ROUTER, lsa)) { - rtr_lsa = (struct ospf6_router_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + rtr_lsa = lsa_after_header(lsa->header); if (!OSPF6_OPT_ISSET(rtr_lsa->options, OSPF6_OPT_R)) { return OSPF6_IS_STUB_ROUTER; @@ -459,9 +457,7 @@ static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, char buf[128], options[32]; json_object *json_arr = NULL; - network_lsa = - (struct ospf6_network_lsa *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + network_lsa = lsa_after_header(lsa->header); ospf6_options_printbuf(network_lsa->options, options, sizeof(options)); if (use_json) @@ -682,8 +678,7 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, json_object *json_arr = NULL; char prefix_string[133]; - link_lsa = (struct ospf6_link_lsa *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + link_lsa = lsa_after_header(lsa->header); ospf6_options_printbuf(link_lsa->options, options, sizeof(options)); inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf, sizeof(buf)); @@ -852,10 +847,7 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa, char tbuf[16]; if (lsa) { - intra_prefix_lsa = - (struct ospf6_intra_prefix_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + intra_prefix_lsa = lsa_after_header(lsa->header); prefixnum = ntohs(intra_prefix_lsa->prefix_num); if ((pos + 1) > prefixnum) @@ -906,9 +898,7 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, json_object *json_arr = NULL; char prefix_string[133]; - intra_prefix_lsa = (struct ospf6_intra_prefix_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + intra_prefix_lsa = lsa_after_header(lsa->header); prefixnum = ntohs(intra_prefix_lsa->prefix_num); @@ -1306,9 +1296,7 @@ void ospf6_intra_prefix_lsa_originate_transit(struct event *thread) } } - link_lsa = (struct ospf6_link_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + link_lsa = lsa_after_header(lsa->header); prefix_num = (unsigned short)ntohl(link_lsa->prefix_num); start = (char *)link_lsa + sizeof(struct ospf6_link_lsa); diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index 25955147a7..9a8b9b0dcd 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -240,6 +240,7 @@ struct ospf6_lsa { bool tobe_acknowledged; }; + #define OSPF6_LSA_HEADERONLY 0x01 #define OSPF6_LSA_FLOODBACK 0x02 #define OSPF6_LSA_DUPLICATE 0x04 From d0366de57c11a7698945acc1dfaf8a6bead1f6f5 Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Thu, 18 Jul 2024 12:56:14 +1000 Subject: [PATCH 07/14] ospf6d: replace TLV_HDR_TOP macro with lsdesc_start function The original TLV_HDR_TOP implementation only worked for Graceful Restart LSAs, because they had no "LSA body". This change introduces a body size lookup table and changes the macro to a function that accounts for the LSA body for all LSA types, and provides type checking on the provided pointer before arithmetic. It also removes the open type casting and pointer arithmetic. The introduced lsdesc_start() is used to find the start of a descriptor, and will be used for TLVs in E-LSAs as well as old LSA. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_gr_helper.c | 4 ++-- ospf6d/ospf6_intra.c | 35 ++++++++++++----------------------- ospf6d/ospf6_lsa.c | 31 +++++++++++++++++++++++++++++++ ospf6d/ospf6_lsa.h | 7 ++++++- ospf6d/ospf6_tlv.h | 3 --- 5 files changed, 51 insertions(+), 29 deletions(-) diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c index e02a841d00..639d56e273 100644 --- a/ospf6d/ospf6_gr_helper.c +++ b/ospf6d/ospf6_gr_helper.c @@ -145,7 +145,7 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa, length = ntohs(lsah->length) - OSPF6_LSA_HEADER_SIZE; - for (tlvh = TLV_HDR_TOP(lsah); sum < length && tlvh; + for (tlvh = lsdesc_start(lsah); sum < length && tlvh; tlvh = TLV_HDR_NEXT(tlvh)) { /* Check TLV len against overall LSA */ @@ -1241,7 +1241,7 @@ static int ospf6_grace_lsa_show_info(struct vty *vty, struct ospf6_lsa *lsa, zlog_debug(" TLV info:"); } - for (tlvh = TLV_HDR_TOP(lsah); sum < length && tlvh; + for (tlvh = lsdesc_start(lsah); sum < length && tlvh; tlvh = TLV_HDR_NEXT(tlvh)) { /* Check TLV len */ diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index f12f125b7b..470fc66084 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -246,9 +246,7 @@ void ospf6_router_lsa_originate(struct event *thread) ospf6_router_lsa_options_set(oa, router_lsa); /* describe links for each interfaces */ - lsdesc = (struct ospf6_router_lsdesc - *)((caddr_t)router_lsa - + sizeof(struct ospf6_router_lsa)); + lsdesc = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_ROUTER); for (ALL_LIST_ELEMENTS(oa->if_list, node, nnode, oi)) { /* Interfaces in state Down or Loopback are not described */ @@ -271,9 +269,9 @@ void ospf6_router_lsa_originate(struct event *thread) && ((size_t)((char *)lsdesc - buffer) + sizeof(struct ospf6_router_lsdesc) > oa->router_lsa_size_limit)) { - if ((caddr_t)lsdesc - == (caddr_t)router_lsa - + sizeof(struct ospf6_router_lsa)) { + if (lsdesc == + lsdesc_start_lsa_type(lsa_header, + OSPF6_LSTYPE_ROUTER)) { zlog_warn( "Size limit setting for Router-LSA too short"); return; @@ -307,9 +305,8 @@ void ospf6_router_lsa_originate(struct event *thread) ospf6_router_lsa_options_set(oa, router_lsa); /* describe links for each interfaces */ - lsdesc = (struct ospf6_router_lsdesc - *)((caddr_t)router_lsa - + sizeof(struct ospf6_router_lsa)); + lsdesc = lsdesc_start_lsa_type(lsa_header, + OSPF6_LSTYPE_ROUTER); link_state_id++; } @@ -571,9 +568,7 @@ void ospf6_network_lsa_originate(struct event *thread) network_lsa->options[2] |= link_lsa->options[2]; } - lsdesc = (struct ospf6_network_lsdesc - *)((caddr_t)network_lsa - + sizeof(struct ospf6_network_lsa)); + lsdesc = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_NETWORK); /* set Link Description to the router itself */ lsdesc->router_id = oi->area->ospf6->router_id; @@ -797,8 +792,7 @@ void ospf6_link_lsa_originate(struct event *thread) sizeof(struct in6_addr)); link_lsa->prefix_num = htonl(oi->route_connected->count); - op = (struct ospf6_prefix *)((caddr_t)link_lsa - + sizeof(struct ospf6_link_lsa)); + op = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_LINK); /* connected prefix to advertise */ for (route = ospf6_route_head(oi->route_connected); route; @@ -1109,12 +1103,10 @@ void ospf6_intra_prefix_lsa_originate_stub(struct event *thread) /* put prefixes to advertise */ prefix_num = 0; - op = (struct ospf6_prefix *)((caddr_t)intra_prefix_lsa - + sizeof(struct ospf6_intra_prefix_lsa)); + op = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_INTRA_PREFIX); for (route = ospf6_route_head(route_advertise); route; route = ospf6_route_best_next(route)) { if (((caddr_t)op - (caddr_t)lsa_header) > MAX_LSA_PAYLOAD) { - intra_prefix_lsa->prefix_num = htons(prefix_num); /* Fill LSA Header */ @@ -1149,10 +1141,8 @@ void ospf6_intra_prefix_lsa_originate_stub(struct event *thread) /* Put next set of prefixes to advertise */ prefix_num = 0; - op = (struct ospf6_prefix - *)((caddr_t)intra_prefix_lsa - + sizeof(struct - ospf6_intra_prefix_lsa)); + op = lsdesc_start_lsa_type(lsa_header, + OSPF6_LSTYPE_INTRA_PREFIX); } op->prefix_length = route->prefix.prefixlen; @@ -1339,8 +1329,7 @@ void ospf6_intra_prefix_lsa_originate_transit(struct event *thread) zlog_debug("Trailing garbage in %s", lsa->name); } - op = (struct ospf6_prefix *)((caddr_t)intra_prefix_lsa - + sizeof(struct ospf6_intra_prefix_lsa)); + op = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_INTRA_PREFIX); prefix_num = 0; for (route = ospf6_route_head(route_advertise); route; diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index d8d13d4b4b..de04391b6b 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -37,6 +37,37 @@ DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_LSA, "OSPF6 LSA"); DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_LSA_HEADER, "OSPF6 LSA header"); DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_LSA_SUMMARY, "OSPF6 LSA summary"); +const uint8_t ospf6_lsa_min_size[OSPF6_LSTYPE_SIZE] = { + [OSPF6_LSTYPE_UNKNOWN] = 0, + [0x00ff & OSPF6_LSTYPE_ROUTER] = OSPF6_ROUTER_LSA_MIN_SIZE, + [0x00ff & OSPF6_LSTYPE_NETWORK] = OSPF6_NETWORK_LSA_MIN_SIZE, + [0x00ff & OSPF6_LSTYPE_INTER_PREFIX] = OSPF6_INTER_PREFIX_LSA_MIN_SIZE, + [0x00ff & OSPF6_LSTYPE_INTER_ROUTER] = OSPF6_INTER_ROUTER_LSA_FIX_SIZE, + [0x00ff & OSPF6_LSTYPE_AS_EXTERNAL] = OSPF6_AS_EXTERNAL_LSA_MIN_SIZE, + [0x00ff & OSPF6_LSTYPE_GROUP_MEMBERSHIP] = 0, /* Unused */ + [0x00ff & OSPF6_LSTYPE_TYPE_7] = OSPF6_AS_EXTERNAL_LSA_MIN_SIZE, + [0x00ff & OSPF6_LSTYPE_LINK] = OSPF6_LINK_LSA_MIN_SIZE, + [0x00ff & OSPF6_LSTYPE_INTRA_PREFIX] = OSPF6_INTRA_PREFIX_LSA_MIN_SIZE, + [0x00ff & OSPF6_LSTYPE_GRACE_LSA] = 0 +}; + +void *lsdesc_start_lsa_type(struct ospf6_lsa_header *header, int lsa_type) +{ + uint8_t t = (0x00ff & lsa_type); + + if (t == OSPF6_LSTYPE_UNKNOWN || t >= OSPF6_LSTYPE_SIZE) { + zlog_debug("Cannot get descriptor offset for unknown lsa type 0x%x", + t); + return ospf6_lsa_end(header); + } + return (char *)lsa_after_header(header) + ospf6_lsa_min_size[t]; +} + +void *lsdesc_start(struct ospf6_lsa_header *header) +{ + return lsdesc_start_lsa_type(header, ntohs(header->type)); +} + static struct ospf6_lsa_handler *lsa_handlers[OSPF6_LSTYPE_SIZE]; struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa) diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index 9a8b9b0dcd..2f443603c2 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -87,6 +87,8 @@ struct ospf6_lsa_header { uint16_t length; /* LSA length */ }; + + static inline char *ospf6_lsa_header_end(struct ospf6_lsa_header *header) { return (char *)header + sizeof(struct ospf6_lsa_header); @@ -121,7 +123,6 @@ static inline uint16_t ospf6_lsa_size(struct ospf6_lsa_header *header) #define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2) #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1)) - /* Router-LSA */ #define OSPF6_ROUTER_LSA_MIN_SIZE 4U struct ospf6_router_lsa { @@ -369,4 +370,8 @@ extern void ospf6_flush_self_originated_lsas_now(struct ospf6 *ospf6); extern struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa); struct ospf6_lsa *ospf6_find_external_lsa(struct ospf6 *ospf6, struct prefix *p); + +void *lsdesc_start_lsa_type(struct ospf6_lsa_header *header, int lsa_type); +void *lsdesc_start(struct ospf6_lsa_header *header); + #endif /* OSPF6_LSA_H */ diff --git a/ospf6d/ospf6_tlv.h b/ospf6d/ospf6_tlv.h index f94d7f2621..a687a05939 100644 --- a/ospf6d/ospf6_tlv.h +++ b/ospf6d/ospf6_tlv.h @@ -27,9 +27,6 @@ struct tlv_header { #define TLV_SIZE(tlvh) ((uint32_t)(TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))) -#define TLV_HDR_TOP(lsah) \ - ((struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE)) - #define TLV_HDR_NEXT(tlvh) \ ((struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))) From cd6d36fd82603d803666d04fd8e539362ae9fcfa Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Mon, 5 Aug 2024 16:09:30 +1000 Subject: [PATCH 08/14] ospf6d: add nth_lsdesc() Add utility function to find the Nth router lsdesc or network lsdesc in an LSA. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_lsa.c | 22 ++++++++++++++++++++++ ospf6d/ospf6_lsa.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index de04391b6b..088ebf56a4 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -70,6 +70,28 @@ void *lsdesc_start(struct ospf6_lsa_header *header) static struct ospf6_lsa_handler *lsa_handlers[OSPF6_LSTYPE_SIZE]; +void *nth_lsdesc(struct ospf6_lsa_header *header, int pos) +{ + char *lsdesc = lsdesc_start(header); + char *lsa_end = ospf6_lsa_end(header); + char *nth; + int lsdesc_size; + + if (ntohs(header->type) == OSPF6_LSTYPE_ROUTER) + lsdesc_size = OSPF6_ROUTER_LSDESC_FIX_SIZE; + else if (ntohs(header->type) == OSPF6_LSTYPE_NETWORK) + lsdesc_size = OSPF6_NETWORK_LSDESC_FIX_SIZE; + else + return NULL; + + nth = lsdesc + (pos * lsdesc_size); + + if (nth + lsdesc_size <= lsa_end) + return nth; + + return NULL; +} + struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa) { struct ospf6 *ospf6 = NULL; diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index 2f443603c2..d6e0cf7710 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -374,4 +374,6 @@ struct ospf6_lsa *ospf6_find_external_lsa(struct ospf6 *ospf6, void *lsdesc_start_lsa_type(struct ospf6_lsa_header *header, int lsa_type); void *lsdesc_start(struct ospf6_lsa_header *header); +void *nth_lsdesc(struct ospf6_lsa_header *header, int pos); + #endif /* OSPF6_LSA_H */ From 8ea50a44b5b98e542e0c3d0d3043dc3090f87e82 Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Mon, 10 Jun 2024 14:11:47 +1000 Subject: [PATCH 09/14] ospf6d: use nth_lsdesc() in ospf6_network_lsa_get_ar_id() Signed-off-by: Andrew Cooks --- ospf6d/ospf6_intra.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 470fc66084..ebecd41ad6 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -419,30 +419,13 @@ void ospf6_router_lsa_originate(struct event *thread) static char *ospf6_network_lsa_get_ar_id(struct ospf6_lsa *lsa, char *buf, int buflen, int pos) { - char *start, *end, *current; - struct ospf6_network_lsa *network_lsa; - struct ospf6_network_lsdesc *lsdesc; + struct ospf6_network_lsdesc *lsdesc = nth_lsdesc(lsa->header, pos); - if (lsa) { - network_lsa = (struct ospf6_network_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + if (!lsdesc || !buf || buflen < (1 + INET_ADDRSTRLEN)) + return NULL; - start = (char *)network_lsa + sizeof(struct ospf6_network_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); - current = start + pos * (sizeof(struct ospf6_network_lsdesc)); - - if ((current + sizeof(struct ospf6_network_lsdesc)) <= end) { - lsdesc = (struct ospf6_network_lsdesc *)current; - if (buf) { - inet_ntop(AF_INET, &lsdesc->router_id, buf, - buflen); - return buf; - } - } - } - - return NULL; + inet_ntop(AF_INET, &lsdesc->router_id, buf, buflen); + return buf; } static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, From b3f72964f28653a683b40e7db3d5d343b9a971fc Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Mon, 10 Jun 2024 14:08:12 +1000 Subject: [PATCH 10/14] ospf6d: use nth_lsdesc() in ospf6_router_lsa_get_nbr_id() Improves code readability by reducing pointer casting and arithmetic, and intendation. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_intra.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index ebecd41ad6..fb3bf15dcd 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -44,41 +44,20 @@ uint32_t conf_debug_ospf6_brouter_specific_area_id; /* RFC2740 3.4.3.1 Router-LSA */ /******************************/ +/* OSPF6_LSTYPE_ROUTER */ static char *ospf6_router_lsa_get_nbr_id(struct ospf6_lsa *lsa, char *buf, int buflen, int pos) { - struct ospf6_router_lsa *router_lsa; - struct ospf6_router_lsdesc *lsdesc; - char *start, *end; char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN]; + struct ospf6_router_lsdesc *lsdesc = nth_lsdesc(lsa->header, pos); - if (lsa) { - router_lsa = (struct ospf6_router_lsa - *)((char *)lsa->header - + sizeof(struct ospf6_lsa_header)); - start = (char *)router_lsa + sizeof(struct ospf6_router_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); + if (!lsdesc || !buf || buflen < (2 + 2 * INET_ADDRSTRLEN)) + return NULL; - lsdesc = (struct ospf6_router_lsdesc - *)(start - + pos * (sizeof(struct - ospf6_router_lsdesc))); - if ((char *)lsdesc + sizeof(struct ospf6_router_lsdesc) - <= end) { - if (buf && (buflen > INET_ADDRSTRLEN * 2)) { - inet_ntop(AF_INET, - &lsdesc->neighbor_interface_id, buf1, - sizeof(buf1)); - inet_ntop(AF_INET, &lsdesc->neighbor_router_id, - buf2, sizeof(buf2)); - snprintf(buf, buflen, "%s/%s", buf2, buf1); - - return buf; - } - } - } - - return NULL; + inet_ntop(AF_INET, &lsdesc->neighbor_interface_id, buf1, sizeof(buf1)); + inet_ntop(AF_INET, &lsdesc->neighbor_router_id, buf2, sizeof(buf2)); + snprintf(buf, buflen, "%s/%s", buf2, buf1); + return buf; } static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, From 554350abe0e0c11ca15b0d8c71b17adf231b1595 Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Mon, 5 Aug 2024 16:14:20 +1000 Subject: [PATCH 11/14] ospf6d: add nth_prefix() Add utility function to find the Nth prefix in a link LSA or Intra Prefix LSA. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_lsa.c | 24 ++++++++++++++++++++++++ ospf6d/ospf6_lsa.h | 1 + 2 files changed, 25 insertions(+) diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 088ebf56a4..622e5f9e0f 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -92,6 +92,30 @@ void *nth_lsdesc(struct ospf6_lsa_header *header, int pos) return NULL; } +void *nth_prefix(struct ospf6_lsa_header *header, int pos) +{ + struct ospf6_prefix *prefix = lsdesc_start(header); + char *end = ospf6_lsa_end(header); + int i = 0; + + if (ntohs(header->type) != OSPF6_LSTYPE_LINK && + ntohs(header->type) != OSPF6_LSTYPE_INTRA_PREFIX) + return NULL; + + if (pos == 0) + return prefix; + + while ((char *)prefix < end && + (char *)prefix + OSPF6_PREFIX_SIZE(prefix) <= end) { + if (i == pos) + return prefix; + i++; + prefix = OSPF6_PREFIX_NEXT(prefix); + } + + return NULL; +} + struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa) { struct ospf6 *ospf6 = NULL; diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index d6e0cf7710..e2c8edd248 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -375,5 +375,6 @@ void *lsdesc_start_lsa_type(struct ospf6_lsa_header *header, int lsa_type); void *lsdesc_start(struct ospf6_lsa_header *header); void *nth_lsdesc(struct ospf6_lsa_header *header, int pos); +void *nth_prefix(struct ospf6_lsa_header *header, int pos); #endif /* OSPF6_LSA_H */ From 6a7751b38aa5b8140f6f7f2c17b519ed4992247e Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Wed, 19 Jun 2024 15:38:51 +1000 Subject: [PATCH 12/14] ospf6d: use nth_prefix() in ospf6_link_lsa_get_prefix_str() Signed-off-by: Andrew Cooks --- ospf6d/ospf6_intra.c | 60 +++++++++++++------------------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index fb3bf15dcd..2988f12394 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -574,52 +574,26 @@ void ospf6_network_lsa_originate(struct event *thread) static char *ospf6_link_lsa_get_prefix_str(struct ospf6_lsa *lsa, char *buf, int buflen, int pos) { - char *start, *end, *current; - struct ospf6_link_lsa *link_lsa; - struct in6_addr in6; - struct ospf6_prefix *prefix; - int cnt = 0, prefixnum; + struct ospf6_link_lsa *link_lsa = lsa_after_header(lsa->header); + struct ospf6_prefix *prefix = nth_prefix(lsa->header, pos); + struct in6_addr in6 = { 0 }; - if (lsa) { - link_lsa = (struct ospf6_link_lsa - *)((caddr_t)lsa->header - + sizeof(struct ospf6_lsa_header)); + if (!lsa || !prefix || !buf || buflen < (1 + INET6_ADDRSTRLEN)) + return NULL; - if (pos == 0) { - inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf, - buflen); - return (buf); - } - - prefixnum = ntohl(link_lsa->prefix_num); - if (pos > prefixnum) - return NULL; - - start = (char *)link_lsa + sizeof(struct ospf6_link_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); - current = start; - - while (current + sizeof(struct ospf6_prefix) <= end) { - prefix = (struct ospf6_prefix *)current; - if (prefix->prefix_length == 0 - || current + OSPF6_PREFIX_SIZE(prefix) > end) { - return NULL; - } - - if (cnt < (pos - 1)) { - current += OSPF6_PREFIX_SIZE(prefix); - cnt++; - } else { - memset(&in6, 0, sizeof(in6)); - memcpy(&in6, OSPF6_PREFIX_BODY(prefix), - OSPF6_PREFIX_SPACE( - prefix->prefix_length)); - inet_ntop(AF_INET6, &in6, buf, buflen); - return (buf); - } - } + /* position zero is used for the lladdr in the body of the LSA */ + if (pos == 0) { + inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf, buflen); + return buf; } - return NULL; + + memcpy(&in6, OSPF6_PREFIX_BODY(prefix), + OSPF6_PREFIX_SPACE(prefix->prefix_length)); + inet_ntop(AF_INET6, &in6, buf, buflen); + + return buf; + + } static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, From 9eef5e64833c9f2727914cec1a3355c31c2952b9 Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Wed, 19 Jun 2024 16:40:55 +1000 Subject: [PATCH 13/14] ospf6d: use nth_prefix() in ospf6_intra_prefix_lsa_get_prefix_str() Signed-off-by: Andrew Cooks --- ospf6d/ospf6_intra.c | 49 ++++++++++---------------------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 2988f12394..e3c76b971c 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -769,49 +769,22 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa, char *buf, int buflen, int pos) { - char *start, *end, *current; - struct ospf6_intra_prefix_lsa *intra_prefix_lsa; - struct in6_addr in6; - int prefixnum, cnt = 0; - struct ospf6_prefix *prefix; + struct ospf6_prefix *prefix = nth_prefix(lsa->header, pos); + struct in6_addr in6 = { 0 }; char tbuf[16]; - if (lsa) { - intra_prefix_lsa = lsa_after_header(lsa->header); + /* ensure buflen >= INET6_ADDRSTRLEN + '/128\0' */ + if (!lsa || !prefix || !buf || buflen < (5 + INET6_ADDRSTRLEN)) + return NULL; - prefixnum = ntohs(intra_prefix_lsa->prefix_num); - if ((pos + 1) > prefixnum) - return NULL; + memcpy(&in6, OSPF6_PREFIX_BODY(prefix), + OSPF6_PREFIX_SPACE(prefix->prefix_length)); + inet_ntop(AF_INET6, &in6, buf, buflen); - start = (char *)intra_prefix_lsa - + sizeof(struct ospf6_intra_prefix_lsa); - end = ospf6_lsa_end(lsa->header); - current = start; + snprintf(tbuf, sizeof(tbuf), "/%d", prefix->prefix_length); + strlcat(buf, tbuf, buflen); - while (current + sizeof(struct ospf6_prefix) <= end) { - prefix = (struct ospf6_prefix *)current; - if (prefix->prefix_length == 0 - || current + OSPF6_PREFIX_SIZE(prefix) > end) { - return NULL; - } - - if (cnt < pos) { - current += OSPF6_PREFIX_SIZE(prefix); - cnt++; - } else { - memset(&in6, 0, sizeof(in6)); - memcpy(&in6, OSPF6_PREFIX_BODY(prefix), - OSPF6_PREFIX_SPACE( - prefix->prefix_length)); - inet_ntop(AF_INET6, &in6, buf, buflen); - snprintf(tbuf, sizeof(tbuf), "/%d", - prefix->prefix_length); - strlcat(buf, tbuf, buflen); - return (buf); - } - } - } - return NULL; + return buf; } static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, From b2526ddc3f992bb6e2dcc95fad9bbbd8c23b0bdf Mon Sep 17 00:00:00 2001 From: Andrew Cooks Date: Wed, 11 Sep 2024 20:27:08 +1000 Subject: [PATCH 14/14] ospf6d: apply CI style suggestions Apply formatting changes suggested by CI frrbot. Signed-off-by: Andrew Cooks --- ospf6d/ospf6_gr.c | 3 ++- ospf6d/ospf6_gr.h | 2 +- ospf6d/ospf6_gr_helper.c | 2 -- ospf6d/ospf6_intra.c | 2 -- ospf6d/ospf6_lsa.h | 27 +++++++++++++-------------- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index 74a7cccd12..64eb90d5f2 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -65,7 +65,8 @@ static int ospf6_gr_lsa_originate(struct ospf6_interface *oi, /* Put restart reason. */ grace_lsa->tlv_reason.header.type = htons(TLV_GRACE_RESTART_REASON_TYPE); - grace_lsa->tlv_reason.header.length = htons(TLV_GRACE_RESTART_REASON_LENGTH); + grace_lsa->tlv_reason.header.length = + htons(TLV_GRACE_RESTART_REASON_LENGTH); grace_lsa->tlv_reason.reason = reason; /* Fill LSA Header */ diff --git a/ospf6d/ospf6_gr.h b/ospf6d/ospf6_gr.h index eddd63e431..e10d20680b 100644 --- a/ospf6d/ospf6_gr.h +++ b/ospf6d/ospf6_gr.h @@ -62,7 +62,7 @@ enum ospf6_gr_helper_rejected_reason { }; -#define GRACE_PERIOD_TLV_SIZE sizeof(struct tlv_grace_period) +#define GRACE_PERIOD_TLV_SIZE sizeof(struct tlv_grace_period) #define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct tlv_grace_restart_reason) #define OSPF6_GRACE_LSA_MIN_SIZE \ diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c index 639d56e273..da8b829cf1 100644 --- a/ospf6d/ospf6_gr_helper.c +++ b/ospf6d/ospf6_gr_helper.c @@ -147,7 +147,6 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa, for (tlvh = lsdesc_start(lsah); sum < length && tlvh; tlvh = TLV_HDR_NEXT(tlvh)) { - /* Check TLV len against overall LSA */ if (sum + TLV_SIZE(tlvh) > length) { if (IS_DEBUG_OSPF6_GR) @@ -1243,7 +1242,6 @@ static int ospf6_grace_lsa_show_info(struct vty *vty, struct ospf6_lsa *lsa, for (tlvh = lsdesc_start(lsah); sum < length && tlvh; tlvh = TLV_HDR_NEXT(tlvh)) { - /* Check TLV len */ if (sum + TLV_SIZE(tlvh) > length) { if (vty) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index e3c76b971c..324cd7abe8 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -592,8 +592,6 @@ static char *ospf6_link_lsa_get_prefix_str(struct ospf6_lsa *lsa, char *buf, inet_ntop(AF_INET6, &in6, buf, buflen); return buf; - - } static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index e2c8edd248..b2c83a1d37 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -88,7 +88,6 @@ struct ospf6_lsa_header { }; - static inline char *ospf6_lsa_header_end(struct ospf6_lsa_header *header) { return (char *)header + sizeof(struct ospf6_lsa_header); @@ -124,7 +123,7 @@ static inline uint16_t ospf6_lsa_size(struct ospf6_lsa_header *header) #define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1)) /* Router-LSA */ -#define OSPF6_ROUTER_LSA_MIN_SIZE 4U +#define OSPF6_ROUTER_LSA_MIN_SIZE 4U struct ospf6_router_lsa { uint8_t bits; uint8_t options[3]; @@ -132,7 +131,7 @@ struct ospf6_router_lsa { }; /* Link State Description in Router-LSA */ -#define OSPF6_ROUTER_LSDESC_FIX_SIZE 16U +#define OSPF6_ROUTER_LSDESC_FIX_SIZE 16U struct ospf6_router_lsdesc { uint8_t type; uint8_t reserved; @@ -142,13 +141,13 @@ struct ospf6_router_lsdesc { in_addr_t neighbor_router_id; }; -#define OSPF6_ROUTER_LSDESC_POINTTOPOINT 1 -#define OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK 2 -#define OSPF6_ROUTER_LSDESC_STUB_NETWORK 3 -#define OSPF6_ROUTER_LSDESC_VIRTUAL_LINK 4 +#define OSPF6_ROUTER_LSDESC_POINTTOPOINT 1 +#define OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK 2 +#define OSPF6_ROUTER_LSDESC_STUB_NETWORK 3 +#define OSPF6_ROUTER_LSDESC_VIRTUAL_LINK 4 /* Network-LSA */ -#define OSPF6_NETWORK_LSA_MIN_SIZE 4U +#define OSPF6_NETWORK_LSA_MIN_SIZE 4U struct ospf6_network_lsa { uint8_t reserved; uint8_t options[3]; @@ -156,7 +155,7 @@ struct ospf6_network_lsa { }; /* Link State Description in Network-LSA */ -#define OSPF6_NETWORK_LSDESC_FIX_SIZE 4U +#define OSPF6_NETWORK_LSDESC_FIX_SIZE 4U struct ospf6_network_lsdesc { in_addr_t router_id; }; @@ -164,14 +163,14 @@ struct ospf6_network_lsdesc { (((struct ospf6_network_lsdesc *)(x))->router_id) /* Inter-Area-Prefix-LSA */ -#define OSPF6_INTER_PREFIX_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ +#define OSPF6_INTER_PREFIX_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ struct ospf6_inter_prefix_lsa { uint32_t metric; struct ospf6_prefix prefix; }; /* Inter-Area-Router-LSA */ -#define OSPF6_INTER_ROUTER_LSA_FIX_SIZE 12U +#define OSPF6_INTER_ROUTER_LSA_FIX_SIZE 12U struct ospf6_inter_router_lsa { uint8_t mbz; uint8_t options[3]; @@ -180,7 +179,7 @@ struct ospf6_inter_router_lsa { }; /* AS-External-LSA */ -#define OSPF6_AS_EXTERNAL_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ +#define OSPF6_AS_EXTERNAL_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ struct ospf6_as_external_lsa { uint32_t bits_metric; @@ -193,7 +192,7 @@ struct ospf6_as_external_lsa { /* FIXME: move nssa lsa here. */ /* Link-LSA */ -#define OSPF6_LINK_LSA_MIN_SIZE 24U /* w/o 1st IPv6 prefix */ +#define OSPF6_LINK_LSA_MIN_SIZE 24U /* w/o 1st IPv6 prefix */ struct ospf6_link_lsa { uint8_t priority; uint8_t options[3]; @@ -203,7 +202,7 @@ struct ospf6_link_lsa { }; /* Intra-Area-Prefix-LSA */ -#define OSPF6_INTRA_PREFIX_LSA_MIN_SIZE 12U /* w/o 1st IPv6 prefix */ +#define OSPF6_INTRA_PREFIX_LSA_MIN_SIZE 12U /* w/o 1st IPv6 prefix */ struct ospf6_intra_prefix_lsa { uint16_t prefix_num; uint16_t ref_type;