aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-11-14 14:33:06 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-11-14 19:00:31 +0100
commit36c070e6e320b97bb4761e29c934f5f269e06b35 (patch)
tree9f25a7083a20dc0337bf4adacca741a5c649cafd
parentcbc83e14df5ebbc656de8ec0e5c26a1a6efadf0e (diff)
downloadpasst-36c070e6e320b97bb4761e29c934f5f269e06b35.tar
passt-36c070e6e320b97bb4761e29c934f5f269e06b35.tar.gz
passt-36c070e6e320b97bb4761e29c934f5f269e06b35.tar.bz2
passt-36c070e6e320b97bb4761e29c934f5f269e06b35.tar.lz
passt-36c070e6e320b97bb4761e29c934f5f269e06b35.tar.xz
passt-36c070e6e320b97bb4761e29c934f5f269e06b35.tar.zst
passt-36c070e6e320b97bb4761e29c934f5f269e06b35.zip
ndp: Use struct assignment in preference to memcpy() for IPv6 addresses
There are a number of places we can simply assign IPv6 addresses about, rather than the current mildly ugly memcpy(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--ndp.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/ndp.c b/ndp.c
index 8f52471..fd512ae 100644
--- a/ndp.c
+++ b/ndp.c
@@ -158,7 +158,7 @@ struct ndp_ra {
unsigned char var[sizeof(struct opt_mtu) + sizeof(struct opt_rdnss) +
sizeof(struct opt_dnssl)];
-} __attribute__((packed));
+} __attribute__((packed, aligned(__alignof__(struct in6_addr))));
/**
* struct ndp_ns - NDP Neighbor Solicitation (NS) message
@@ -168,7 +168,7 @@ struct ndp_ra {
struct ndp_ns {
struct icmp6hdr ih;
struct in6_addr target_addr;
-} __attribute__((packed));
+} __attribute__((packed, aligned(__alignof__(struct in6_addr))));
/**
* ndp_send() - Send an NDP message
@@ -192,7 +192,7 @@ static void ndp_send(const struct ctx *c, const struct in6_addr *dst,
* @addr: IPv6 address to advertise
*/
static void ndp_na(const struct ctx *c, const struct in6_addr *dst,
- const void *addr)
+ const struct in6_addr *addr)
{
struct ndp_na na = {
.ih = {
@@ -202,6 +202,7 @@ static void ndp_na(const struct ctx *c, const struct in6_addr *dst,
.icmp6_solicited = 1,
.icmp6_override = 1,
},
+ .target_addr = *addr,
.target_l2_addr = {
.header = {
.type = OPT_TARGET_L2_ADDR,
@@ -210,7 +211,6 @@ static void ndp_na(const struct ctx *c, const struct in6_addr *dst,
}
};
- memcpy(&na.target_addr, addr, sizeof(na.target_addr));
memcpy(na.target_l2_addr.mac, c->our_tap_mac, ETH_ALEN);
ndp_send(c, dst, &na, sizeof(na));
@@ -242,6 +242,7 @@ static void ndp_ra(const struct ctx *c, const struct in6_addr *dst)
.valid_lifetime = ~0U,
.pref_lifetime = ~0U,
},
+ .prefix = c->ip6.addr,
.source_ll = {
.header = {
.type = OPT_SRC_L2_ADDR,
@@ -251,8 +252,6 @@ static void ndp_ra(const struct ctx *c, const struct in6_addr *dst)
};
unsigned char *ptr = NULL;
- memcpy(&ra.prefix, &c->ip6.addr, sizeof(ra.prefix));
-
ptr = &ra.var[0];
if (c->mtu != -1) {
@@ -282,8 +281,7 @@ static void ndp_ra(const struct ctx *c, const struct in6_addr *dst)
.lifetime = ~0U,
};
for (i = 0; i < n; i++) {
- memcpy(&rdnss->dns[i], &c->ip6.dns[i],
- sizeof(rdnss->dns[i]));
+ rdnss->dns[i] = c->ip6.dns[i];
}
ptr += offsetof(struct opt_rdnss, dns) +
i * sizeof(rdnss->dns[0]);