Skip to content

Commit 6d58272

Browse files
author
Paul Jakma
committed
[bgpd] cleanup, compact and consolidate capability parsing code
2007-07-26 Paul Jakma <paul.jakma@sun.com> * (general) Clean up and compact capability parsing slightly. Consolidate validation of length and logging of generic TLV, and memcpy of capability data, thus removing such from cap specifc code (not always present or correct). * bgp_open.h: Add structures for the generic capability TLV header and for the data formats of the various specific capabilities we support. Hence remove the badly named, or else misdefined, struct capability. * bgp_open.c: (bgp_capability_vty_out) Use struct capability_mp_data. Do the length checks *before* memcpy()'ing based on that length (stored capability - should have been validated anyway on input, but..). (bgp_afi_safi_valid_indices) new function to validate (afi,safi) which is about to be used as index into arrays, consolidates several instances of same, at least one of which appeared to be incomplete.. (bgp_capability_mp) Much condensed. (bgp_capability_orf_entry) New, process one ORF entry (bgp_capability_orf) Condensed. Fixed to process all ORF entries. (bgp_capability_restart) Condensed, and fixed to use a cap-specific type, rather than abusing capability_mp. (struct message capcode_str) added to aid generic logging. (size_t cap_minsizes[]) added to aid generic validation of capability length field. (bgp_capability_parse) Generic logging and validation of TLV consolidated here. Code compacted as much as possible. * bgp_packet.c: (bgp_open_receive) Capability parsers now use streams, so no more need here to manually fudge the input stream getp. (bgp_capability_msg_parse) use struct capability_mp_data. Validate lengths /before/ memcpy. Use bgp_afi_safi_valid_indices. (bgp_capability_receive) Exported for use by test harness. * bgp_vty.c: (bgp_show_summary) fix conversion warning (bgp_show_peer) ditto * bgp_debug.h: Fix storage 'extern' after type 'const'. * lib/log.c: (mes_lookup) warning about code not being in same-number array slot should be debug, not warning. E.g. BGP has several discontigious number spaces, allocating from different parts of a space is not uncommon (e.g. IANA assigned versus vendor-assigned code points in some number space).
1 parent dfdb8f1 commit 6d58272

File tree

10 files changed

+566
-416
lines changed

10 files changed

+566
-416
lines changed

Diff for: bgpd/ChangeLog

+38
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
2007-07-26 Paul Jakma <paul.jakma@sun.com>
2+
3+
* (general) Clean up and compact capability parsing slightly.
4+
Consolidate validation of length and logging of generic TLV, and
5+
memcpy of capability data, thus removing such from cap specifc
6+
code (not always present or correct).
7+
* bgp_open.h: Add structures for the generic capability TLV header
8+
and for the data formats of the various specific capabilities we
9+
support. Hence remove the badly named, or else misdefined, struct
10+
capability.
11+
* bgp_open.c: (bgp_capability_vty_out) Use struct capability_mp_data.
12+
Do the length checks *before* memcpy()'ing based on that length
13+
(stored capability - should have been validated anyway on input,
14+
but..).
15+
(bgp_afi_safi_valid_indices) new function to validate (afi,safi)
16+
which is about to be used as index into arrays, consolidates
17+
several instances of same, at least one of which appeared to be
18+
incomplete..
19+
(bgp_capability_mp) Much condensed.
20+
(bgp_capability_orf_entry) New, process one ORF entry
21+
(bgp_capability_orf) Condensed. Fixed to process all ORF entries.
22+
(bgp_capability_restart) Condensed, and fixed to use a
23+
cap-specific type, rather than abusing capability_mp.
24+
(struct message capcode_str) added to aid generic logging.
25+
(size_t cap_minsizes[]) added to aid generic validation of
26+
capability length field.
27+
(bgp_capability_parse) Generic logging and validation of TLV
28+
consolidated here. Code compacted as much as possible.
29+
* bgp_packet.c: (bgp_open_receive) Capability parsers now use
30+
streams, so no more need here to manually fudge the input stream
31+
getp.
32+
(bgp_capability_msg_parse) use struct capability_mp_data. Validate
33+
lengths /before/ memcpy. Use bgp_afi_safi_valid_indices.
34+
(bgp_capability_receive) Exported for use by test harness.
35+
* bgp_vty.c: (bgp_show_summary) fix conversion warning
36+
(bgp_show_peer) ditto
37+
* bgp_debug.h: Fix storage 'extern' after type 'const'.
38+
139
2007-07-31 Lorenzo Colitti <lorenzo@colitti.com>
240

341
* bgp_dump.c: (general) Add comments to code.

Diff for: bgpd/bgp_debug.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extern unsigned long term_bgp_debug_zebra;
110110
#define BGP_DEBUG(a, b) (term_bgp_debug_ ## a & BGP_DEBUG_ ## b)
111111
#define CONF_BGP_DEBUG(a, b) (conf_bgp_debug_ ## a & BGP_DEBUG_ ## b)
112112

113-
const extern char *bgp_type_str[];
113+
extern const char *bgp_type_str[];
114114

115115
extern int bgp_dump_attr (struct peer *, struct attr *, char *, size_t);
116116
extern void bgp_notify_print (struct peer *, struct bgp_notify *, const char *);

0 commit comments

Comments
 (0)