From 914911ba87e09bab36dbb807451cd4e91b4b395e Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Mon, 18 Oct 2021 12:01:11 +0200 Subject: [PATCH] [lonetix/bgp] Take advantage of smallbytecopy.h for prefix copies --- lonetix/bgp/bgp.c | 5 +++-- lonetix/bgp/prefix.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lonetix/bgp/bgp.c b/lonetix/bgp/bgp.c index ee9d7aa..4b3baf0 100644 --- a/lonetix/bgp/bgp.c +++ b/lonetix/bgp/bgp.c @@ -17,6 +17,7 @@ #include "sys/con.h" #include "argv.h" #include "numlib.h" +#include "smallbytecopy.h" #include #include @@ -454,7 +455,7 @@ Prefix *Bgp_NextMpPrefix(Bgpmpiter *it) cur->isAddPath = TRUE; cur->pathId = pfx->pathId; cur->width = pfx->width; - memcpy(cur->bytes, pfx->bytes, PFXLEN(pfx->width)); + _smallbytecopy16(cur->bytes, pfx->bytes, PFXLEN(pfx->width)); } else { // Regular prefix const RawPrefix *pfx = (const RawPrefix *) rawPfx; @@ -462,7 +463,7 @@ Prefix *Bgp_NextMpPrefix(Bgpmpiter *it) cur->isAddPath = FALSE; cur->pathId = 0; cur->width = pfx->width; - memcpy(cur->bytes, pfx->bytes, PFXLEN(pfx->width)); + _smallbytecopy16(cur->bytes, pfx->bytes, PFXLEN(pfx->width)); } return cur; diff --git a/lonetix/bgp/prefix.c b/lonetix/bgp/prefix.c index 962e4d5..f42e76b 100644 --- a/lonetix/bgp/prefix.c +++ b/lonetix/bgp/prefix.c @@ -13,6 +13,7 @@ #include "sys/endian.h" #include "sys/ip.h" #include "numlib.h" +#include "smallbytecopy.h" #include #include @@ -41,13 +42,13 @@ char *Bgp_PrefixToString(Afi afi, const RawPrefix *prefix, char *dest) switch (afi) { case AFI_IP: memset(&adr, 0, sizeof(adr)); - memcpy(&adr, prefix->bytes, PFXLEN(prefix->width)); + _smallbytecopy4(adr.bytes, prefix->bytes, PFXLEN(prefix->width)); dest = Ipv4_AdrToString(&adr, dest); break; case AFI_IP6: memset(&adr6, 0, sizeof(adr6)); - memcpy(&adr6, prefix->bytes, PFXLEN(prefix->width)); + _smallbytecopy16(adr6.bytes, prefix->bytes, PFXLEN(prefix->width)); dest = Ipv6_AdrToString(&adr6, dest); break; @@ -122,7 +123,7 @@ Judgement Bgp_StringToPrefix(const char *s, Prefix *dest) dest->isAddPath = FALSE; dest->width = width; - memcpy(dest->bytes, adr.bytes, PFXLEN(width)); + _smallbytecopy16(dest->bytes, adr.bytes, PFXLEN(width)); return OK; }