]> git.puffer.fish Git - matthieu/frr.git/commitdiff
eigrpd: Create consts for TLV size
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 27 Oct 2017 16:53:52 +0000 (12:53 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 2 Nov 2017 12:10:05 +0000 (08:10 -0400)
1) Create #defines for TLV SIZE and use them
2) Speed up prefix length by using a switch statement

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
eigrpd/eigrp_const.h
eigrpd/eigrp_packet.c
eigrpd/eigrp_update.c

index c5f6e64d0b4546a47b2b71d179187df86ea12070..94f6aa70d46c07552046e4acd992e64ad6117c9d 100644 (file)
@@ -297,6 +297,12 @@ enum eigrp_fsm_events {
 #define EIGRP_TLV_IPv4_EXT              (EIGRP_TLV_IPv4 | EIGRP_TLV_EXTERNAL)
 #define EIGRP_TLV_IPv4_COM              (EIGRP_TLV_IPv4 | EIGRP_TLV_COMMUNITY)
 
+#define EIGRP_TLV_IPV4_SIZE_GRT_24_BIT      0x001D
+#define EIGRP_TLV_IPV4_SIZE_GRT_16_BIT      0x001C
+#define EIGRP_TLV_IPV4_SIZE_GRT_8_BIT       0x001B
+#define EIGRP_TLV_IPV4_SIZE_GRT_0_BIT       0x001A
+#define EIGRP_TLV_MAX_IPV4_BYTE             EIGRP_TLV_IPV4_SIZE_GRT_24_BIT
+
 /* max number of TLV IPv4 prefixes in packet */
 #define EIGRP_TLV_MAX_IPv4                             25
 
index 5b54f813269f0e84f389b6533729ebc2ff647600..ecabee4aa7acd627c9ee4ec9636375de25386f80 100644 (file)
@@ -1165,25 +1165,57 @@ u_int16_t eigrp_add_internalTLV_to_stream(struct stream *s,
        u_int16_t length;
 
        stream_putw(s, EIGRP_TLV_IPv4_INT);
-       if (pe->destination->prefixlen <= 8) {
-               stream_putw(s, 0x001A);
-               length = 0x001A;
-       }
-       if ((pe->destination->prefixlen > 8)
-           && (pe->destination->prefixlen <= 16)) {
-               stream_putw(s, 0x001B);
-               length = 0x001B;
-       }
-       if ((pe->destination->prefixlen > 16)
-           && (pe->destination->prefixlen <= 24)) {
-               stream_putw(s, 0x001C);
-               length = 0x001C;
-       }
-       if (pe->destination->prefixlen > 24) {
-               stream_putw(s, 0x001D);
-               length = 0x001D;
+       switch (pe->destination->prefixlen) {
+       case 0:
+       case 1:
+       case 2:
+       case 3:
+       case 4:
+       case 5:
+       case 6:
+       case 7:
+       case 8:
+               length = EIGRP_TLV_IPV4_SIZE_GRT_0_BIT;
+               stream_putw(s, length);
+               break;
+       case 9:
+       case 10:
+       case 11:
+       case 12:
+       case 13:
+       case 14:
+       case 15:
+       case 16:
+               length = EIGRP_TLV_IPV4_SIZE_GRT_8_BIT;
+               stream_putw(s, length);
+               break;
+       case 17:
+       case 18:
+       case 19:
+       case 20:
+       case 21:
+       case 22:
+       case 23:
+       case 24:
+               length = EIGRP_TLV_IPV4_SIZE_GRT_16_BIT;
+               stream_putw(s, length);
+               break;
+       case 25:
+       case 26:
+       case 27:
+       case 28:
+       case 29:
+       case 30:
+       case 31:
+       case 32:
+               length = EIGRP_TLV_IPV4_SIZE_GRT_24_BIT;
+               stream_putw(s, length);
+               break;
+       default:
+               zlog_err("%s: Unexpected prefix length: %d",
+                        __PRETTY_FUNCTION__, pe->destination->prefixlen);
+               return 0;
        }
-
        stream_putl(s, 0x00000000);
 
        /*Metric*/
index b4d1c58870feb02668b7639b22b0017d60d429c0..c3eb62886af9182bd77e8c6baa8c27b82f0f06cb 100644 (file)
@@ -560,7 +560,7 @@ void eigrp_update_send_EOT(struct eigrp_neighbor *nbr)
                        if (eigrp_nbr_split_horizon_check(te, ei))
                                continue;
 
-                       if ((length + 0x001D) > mtu) {
+                       if ((length + EIGRP_TLV_MAX_IPV4_BYTE) > mtu) {
                                eigrp_update_place_on_nbr_queue (nbr, ep, seq_no, length);
                                seq_no++;
 
@@ -635,7 +635,8 @@ void eigrp_update_send(struct eigrp_interface *ei)
                if (eigrp_nbr_split_horizon_check(ne, ei))
                        continue;
 
-               if ((length + 0x001D) > (u_int16_t)ei->ifp->mtu) {
+               if ((length + EIGRP_TLV_MAX_IPV4_BYTE) >
+                   (u_int16_t)ei->ifp->mtu) {
                        if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
                            && (ei->params.auth_keychain != NULL)) {
                                eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);