Merge pull request #4526 from CHKDSK88/endian

eigrpd: Fix endianness issue in packets
This commit is contained in:
Donald Sharp 2019-06-14 12:05:41 -04:00 committed by GitHub
commit 6dc2e4358f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 32 deletions

View File

@ -1114,6 +1114,7 @@ static struct TLV_IPv4_Internal_type *eigrp_IPv4_InternalTLV_new(void)
struct TLV_IPv4_Internal_type *eigrp_read_ipv4_tlv(struct stream *s) struct TLV_IPv4_Internal_type *eigrp_read_ipv4_tlv(struct stream *s)
{ {
struct TLV_IPv4_Internal_type *tlv; struct TLV_IPv4_Internal_type *tlv;
uint32_t destination_tmp;
tlv = eigrp_IPv4_InternalTLV_new(); tlv = eigrp_IPv4_InternalTLV_new();
@ -1133,31 +1134,16 @@ struct TLV_IPv4_Internal_type *eigrp_read_ipv4_tlv(struct stream *s)
tlv->prefix_length = stream_getc(s); tlv->prefix_length = stream_getc(s);
if (tlv->prefix_length <= 8) { destination_tmp = stream_getc(s) << 24;
tlv->destination_part[0] = stream_getc(s); if (tlv->prefix_length > 8)
tlv->destination.s_addr = (tlv->destination_part[0]); destination_tmp |= stream_getc(s) << 16;
} else if (tlv->prefix_length > 8 && tlv->prefix_length <= 16) { if (tlv->prefix_length > 16)
tlv->destination_part[0] = stream_getc(s); destination_tmp |= stream_getc(s) << 8;
tlv->destination_part[1] = stream_getc(s); if (tlv->prefix_length > 24)
tlv->destination.s_addr = ((tlv->destination_part[1] << 8) destination_tmp |= stream_getc(s);
+ tlv->destination_part[0]);
} else if (tlv->prefix_length > 16 && tlv->prefix_length <= 24) { tlv->destination.s_addr = htonl(destination_tmp);
tlv->destination_part[0] = stream_getc(s);
tlv->destination_part[1] = stream_getc(s);
tlv->destination_part[2] = stream_getc(s);
tlv->destination.s_addr = ((tlv->destination_part[2] << 16)
+ (tlv->destination_part[1] << 8)
+ tlv->destination_part[0]);
} else if (tlv->prefix_length > 24 && tlv->prefix_length <= 32) {
tlv->destination_part[0] = stream_getc(s);
tlv->destination_part[1] = stream_getc(s);
tlv->destination_part[2] = stream_getc(s);
tlv->destination_part[3] = stream_getc(s);
tlv->destination.s_addr = ((tlv->destination_part[3] << 24)
+ (tlv->destination_part[2] << 16)
+ (tlv->destination_part[1] << 8)
+ tlv->destination_part[0]);
}
return tlv; return tlv;
} }
@ -1234,15 +1220,13 @@ uint16_t eigrp_add_internalTLV_to_stream(struct stream *s,
stream_putc(s, pe->destination->prefixlen); stream_putc(s, pe->destination->prefixlen);
stream_putc(s, pe->destination->u.prefix4.s_addr & 0xFF); stream_putc(s, (ntohl(pe->destination->u.prefix4.s_addr) >> 24) & 0xFF);
if (pe->destination->prefixlen > 8) if (pe->destination->prefixlen > 8)
stream_putc(s, (pe->destination->u.prefix4.s_addr >> 8) & 0xFF); stream_putc(s, (ntohl(pe->destination->u.prefix4.s_addr) >> 16) & 0xFF);
if (pe->destination->prefixlen > 16) if (pe->destination->prefixlen > 16)
stream_putc(s, stream_putc(s, (ntohl(pe->destination->u.prefix4.s_addr) >> 8) & 0xFF);
(pe->destination->u.prefix4.s_addr >> 16) & 0xFF);
if (pe->destination->prefixlen > 24) if (pe->destination->prefixlen > 24)
stream_putc(s, stream_putc(s, ntohl(pe->destination->u.prefix4.s_addr) & 0xFF);
(pe->destination->u.prefix4.s_addr >> 24) & 0xFF);
return length; return length;
} }

View File

@ -409,7 +409,6 @@ struct TLV_IPv4_Internal_type {
uint8_t prefix_length; uint8_t prefix_length;
unsigned char destination_part[4];
struct in_addr destination; struct in_addr destination;
} __attribute__((packed)); } __attribute__((packed));