From d4f58e0b8497626d2f5ce5ec4a140d19a92bd283 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Tue, 4 Jan 2022 01:13:50 +0000 Subject: isisd: add TLV_SIZE_MISMATCH for tlvs length mismatch Basically in frrouting source code principle, the log string should not be a complicated abstraction or streamlined for grep. But for log format for the "TLV size does not match ..." can be unified, which makes development easier. > $ grep "TLV size does not match expected size for" isisd/isis_tlvs.c > "TLV size does not match expected size for Administrative Group!\n"); > "TLV size does not match expected size for Local IPv6 address!\n"); > ...(snip)... > "TLV size does not match expected size for Adjacency SID!\n"); > "TLV size does not match expected size for Adjacency SID!\n"); > "TLV size does not match expected size for Adjacency SID!\n"); > "TLV size does not match expected size for LAN-Adjacency SID!\n"); > "TLV size does not match expected size for LAN-Adjacency SID!\n"); > "TLV size does not match expected size for LAN-Adjacency SID!\n"); > > $ grep "TLV size does not match expected size for" isisd/isis_tlvs.c | wc -l > 25 Signed-off-by: Hiroki Shirokura Signed-off-by: Louis Scalbert --- isisd/isis_tlvs.c | 110 +++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 54 deletions(-) (limited to 'isisd') diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index 114c627c1..8eaa095b3 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -30,6 +30,10 @@ #include "isisd/isis_te.h" #include "isisd/isis_sr.h" +#define TLV_SIZE_MISMATCH(log, indent, target) \ + sbuf_push(log, indent, \ + "TLV size does not match expected size for " target "!\n") + DEFINE_MTYPE_STATIC(ISISD, ISIS_TLV, "ISIS TLVs"); DEFINE_MTYPE(ISISD, ISIS_SUBTLV, "ISIS Sub-TLVs"); DEFINE_MTYPE_STATIC(ISISD, ISIS_MT_ITEM_LIST, "ISIS MT Item Lists"); @@ -896,8 +900,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, /* Standard Metric as defined in RFC5305 */ case ISIS_SUBTLV_ADMIN_GRP: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Administrative Group!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Administrative Group"); stream_forward_getp(s, subtlv_len); } else { exts->adm_group = stream_getl(s); @@ -915,8 +919,7 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_LLRI: if (subtlv_len != ISIS_SUBTLV_LLRI_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Link ID!\n"); + TLV_SIZE_MISMATCH(log, indent, "Link ID"); stream_forward_getp(s, subtlv_len); } else { exts->local_llri = stream_getl(s); @@ -926,8 +929,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_LOCAL_IPADDR: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Local IP address!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Local IP address"); stream_forward_getp(s, subtlv_len); } else { stream_get(&exts->local_addr.s_addr, s, 4); @@ -936,8 +939,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_RMT_IPADDR: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Remote IP address!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Remote IP address"); stream_forward_getp(s, subtlv_len); } else { stream_get(&exts->neigh_addr.s_addr, s, 4); @@ -946,8 +949,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_LOCAL_IPADDR6: if (subtlv_len != ISIS_SUBTLV_IPV6_ADDR_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Local IPv6 address!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Local IPv6 address"); stream_forward_getp(s, subtlv_len); } else { stream_get(&exts->local_addr6, s, 16); @@ -956,8 +959,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_RMT_IPADDR6: if (subtlv_len != ISIS_SUBTLV_IPV6_ADDR_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Remote IPv6 address!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Remote IPv6 address"); stream_forward_getp(s, subtlv_len); } else { stream_get(&exts->neigh_addr6, s, 16); @@ -966,8 +969,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_MAX_BW: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Maximum Bandwidth!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Maximum Bandwidth"); stream_forward_getp(s, subtlv_len); } else { exts->max_bw = stream_getf(s); @@ -976,8 +979,9 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_MAX_RSV_BW: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Maximum Reservable Bandwidth!\n"); + TLV_SIZE_MISMATCH( + log, indent, + "Maximum Reservable Bandwidth"); stream_forward_getp(s, subtlv_len); } else { exts->max_rsv_bw = stream_getf(s); @@ -986,8 +990,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_UNRSV_BW: if (subtlv_len != ISIS_SUBTLV_UNRSV_BW_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Unreserved Bandwidth!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Unreserved Bandwidth"); stream_forward_getp(s, subtlv_len); } else { for (int i = 0; i < MAX_CLASS_TYPE; i++) @@ -997,8 +1001,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_TE_METRIC: if (subtlv_len != ISIS_SUBTLV_TE_METRIC_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Traffic Engineering Metric!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Traffic Engineering Metric"); stream_forward_getp(s, subtlv_len); } else { exts->te_metric = stream_get3(s); @@ -1007,8 +1011,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_RAS: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Remote AS number!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Remote AS number"); stream_forward_getp(s, subtlv_len); } else { exts->remote_as = stream_getl(s); @@ -1017,8 +1021,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_RIP: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Remote ASBR IP Address!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Remote ASBR IP Address"); stream_forward_getp(s, subtlv_len); } else { stream_get(&exts->remote_ip.s_addr, s, 4); @@ -1028,8 +1032,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, /* Extended Metrics as defined in RFC 7810 */ case ISIS_SUBTLV_AV_DELAY: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Average Link Delay!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Average Link Delay"); stream_forward_getp(s, subtlv_len); } else { exts->delay = stream_getl(s); @@ -1038,8 +1042,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_MM_DELAY: if (subtlv_len != ISIS_SUBTLV_MM_DELAY_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Min/Max Link Delay!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Min/Max Link Delay"); stream_forward_getp(s, subtlv_len); } else { exts->min_delay = stream_getl(s); @@ -1049,8 +1053,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_DELAY_VAR: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Delay Variation!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Delay Variation"); stream_forward_getp(s, subtlv_len); } else { exts->delay_var = stream_getl(s); @@ -1059,8 +1063,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_PKT_LOSS: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Link Packet Loss!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Link Packet Loss"); stream_forward_getp(s, subtlv_len); } else { exts->pkt_loss = stream_getl(s); @@ -1069,8 +1073,9 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_RES_BW: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Unidirectional Residual Bandwidth!\n"); + TLV_SIZE_MISMATCH( + log, indent, + "Unidirectional Residual Bandwidth"); stream_forward_getp(s, subtlv_len); } else { exts->res_bw = stream_getf(s); @@ -1079,8 +1084,9 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_AVA_BW: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Unidirectional Available Bandwidth!\n"); + TLV_SIZE_MISMATCH( + log, indent, + "Unidirectional Available Bandwidth"); stream_forward_getp(s, subtlv_len); } else { exts->ava_bw = stream_getf(s); @@ -1089,8 +1095,9 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, break; case ISIS_SUBTLV_USE_BW: if (subtlv_len != ISIS_SUBTLV_DEF_SIZE) { - sbuf_push(log, indent, - "TLV size does not match expected size for Unidirectional Utilized Bandwidth!\n"); + TLV_SIZE_MISMATCH( + log, indent, + "Unidirectional Utilized Bandwidth"); stream_forward_getp(s, subtlv_len); } else { exts->use_bw = stream_getf(s); @@ -1101,8 +1108,7 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, case ISIS_SUBTLV_ADJ_SID: if (subtlv_len != ISIS_SUBTLV_ADJ_SID_SIZE && subtlv_len != ISIS_SUBTLV_ADJ_SID_SIZE + 1) { - sbuf_push(log, indent, - "TLV size does not match expected size for Adjacency SID!\n"); + TLV_SIZE_MISMATCH(log, indent, "Adjacency SID"); stream_forward_getp(s, subtlv_len); } else { struct isis_adj_sid *adj; @@ -1113,9 +1119,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, adj->weight = stream_getc(s); if (adj->flags & EXT_SUBTLV_LINK_ADJ_SID_VFLG && subtlv_len != ISIS_SUBTLV_ADJ_SID_SIZE) { - sbuf_push( - log, indent, - "TLV size does not match expected size for Adjacency SID!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Adjacency SID"); stream_forward_getp(s, subtlv_len - 2); XFREE(MTYPE_ISIS_SUBTLV, adj); break; @@ -1125,9 +1130,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, && subtlv_len != ISIS_SUBTLV_ADJ_SID_SIZE + 1) { - sbuf_push( - log, indent, - "TLV size does not match expected size for Adjacency SID!\n"); + TLV_SIZE_MISMATCH(log, indent, + "Adjacency SID"); stream_forward_getp(s, subtlv_len - 2); XFREE(MTYPE_ISIS_SUBTLV, adj); break; @@ -1152,8 +1156,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, case ISIS_SUBTLV_LAN_ADJ_SID: if (subtlv_len != ISIS_SUBTLV_LAN_ADJ_SID_SIZE && subtlv_len != ISIS_SUBTLV_LAN_ADJ_SID_SIZE + 1) { - sbuf_push(log, indent, - "TLV size does not match expected size for LAN-Adjacency SID!\n"); + TLV_SIZE_MISMATCH(log, indent, + "LAN-Adjacency SID"); stream_forward_getp(s, subtlv_len); } else { struct isis_lan_adj_sid *lan; @@ -1168,9 +1172,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, if (lan->flags & EXT_SUBTLV_LINK_ADJ_SID_VFLG && subtlv_len != ISIS_SUBTLV_LAN_ADJ_SID_SIZE) { - sbuf_push( - log, indent, - "TLV size does not match expected size for LAN-Adjacency SID!\n"); + TLV_SIZE_MISMATCH(log, indent, + "LAN-Adjacency SID"); stream_forward_getp( s, subtlv_len - 2 - ISIS_SYS_ID_LEN); @@ -1182,9 +1185,8 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, && subtlv_len != ISIS_SUBTLV_LAN_ADJ_SID_SIZE + 1) { - sbuf_push( - log, indent, - "TLV size does not match expected size for LAN-Adjacency SID!\n"); + TLV_SIZE_MISMATCH(log, indent, + "LAN-Adjacency SID"); stream_forward_getp( s, subtlv_len - 2 - ISIS_SYS_ID_LEN); -- cgit v1.2.3