Skip to content

Commit a46a2e9

Browse files
committed
bgpd: don't make any assumptions about the size of an enum
The size of an enum is compiler dependent and thus we shouldn't use enums inside structures that represent fields of a packet. Problem detected by the 'test_capability' unit test. The problem was not apparent before because the 'iana_safi_t' enum didn't exist and 'safi_t' was a typedef to uint8_t. Now we have two different enums, 'iana_afi_t' and 'iana_safi_t', and both need to be encoded in different ways on the wire (2 bytes vs 1 byte). Signed-off-by: Renato Westphal <[email protected]>
1 parent 085347c commit a46a2e9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

bgpd/bgp_open.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ struct capability_header {
2929

3030
/* Generic MP capability data */
3131
struct capability_mp_data {
32-
iana_afi_t afi;
32+
uint16_t afi; /* iana_afi_t */
3333
u_char reserved;
34-
iana_safi_t safi;
34+
uint8_t safi; /* iana_safi_t */
3535
};
3636

3737
struct capability_as4 {

bgpd/bgpd.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,10 @@ DECLARE_QOBJ_TYPE(peer)
922922
stream. */
923923
struct bgp_nlri {
924924
/* AFI. */
925-
afi_t afi;
925+
uint16_t afi; /* iana_afi_t */
926926

927927
/* SAFI. */
928-
safi_t safi;
928+
uint8_t safi; /* iana_safi_t */
929929

930930
/* Pointer to NLRI byte stream. */
931931
u_char *nlri;

0 commit comments

Comments
 (0)