summaryrefslogtreecommitdiff
path: root/eigrpd/eigrp_packet.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2017-10-27 12:53:52 -0400
committerDonald Sharp <sharpd@cumulusnetworks.com>2017-11-02 08:10:05 -0400
commit03161b73808b856574839a95e528fc0e68baaa7d (patch)
tree11ec04eb6004fdd06935fc2faebb8dca9844589c /eigrpd/eigrp_packet.c
parent453a5340a8dc1400f44d1843b8687ac750282b12 (diff)
eigrpd: Create consts for TLV size
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>
Diffstat (limited to 'eigrpd/eigrp_packet.c')
-rw-r--r--eigrpd/eigrp_packet.c68
1 files changed, 50 insertions, 18 deletions
diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c
index 5b54f81326..ecabee4aa7 100644
--- a/eigrpd/eigrp_packet.c
+++ b/eigrpd/eigrp_packet.c
@@ -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*/