]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: don't make any assumptions about the size of an enum
authorRenato Westphal <renato@opensourcerouting.org>
Tue, 1 Aug 2017 00:37:46 +0000 (21:37 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Tue, 1 Aug 2017 02:45:03 +0000 (23:45 -0300)
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 <renato@opensourcerouting.org>
bgpd/bgp_open.h
bgpd/bgpd.h

index 6b92e6e38ce747f445296e100a7917bcdc9f3b97..83b79a589a2aaa7418eaafc99c373a0bbc88ff54 100644 (file)
@@ -29,9 +29,9 @@ struct capability_header {
 
 /* Generic MP capability data */
 struct capability_mp_data {
-       iana_afi_t afi;
+       uint16_t afi; /* iana_afi_t */
        u_char reserved;
-       iana_safi_t safi;
+       uint8_t safi; /* iana_safi_t */
 };
 
 struct capability_as4 {
index ff15115e03a6cd79d16561fa98a975342b16254f..250ee5f4e849237b3fe60227460aae4ac6684383 100644 (file)
@@ -922,10 +922,10 @@ DECLARE_QOBJ_TYPE(peer)
    stream. */
 struct bgp_nlri {
        /* AFI.  */
-       afi_t afi;
+       uint16_t afi; /* iana_afi_t */
 
        /* SAFI.  */
-       safi_t safi;
+       uint8_t safi; /* iana_safi_t */
 
        /* Pointer to NLRI byte stream.  */
        u_char *nlri;