aboutgitcodebugslistschat
path: root/dhcpv6.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-10-19 11:43:53 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-10-19 03:34:48 +0200
commit9d8dd8b6f4a99beb73a1460100e4a2a410ac673a (patch)
treefb84d2ca0f4a6f3beb2cd954d39e575b6da4b646 /dhcpv6.c
parentf616ca231e1c6dc9256f999f868bb973d744104a (diff)
downloadpasst-9d8dd8b6f4a99beb73a1460100e4a2a410ac673a.tar
passt-9d8dd8b6f4a99beb73a1460100e4a2a410ac673a.tar.gz
passt-9d8dd8b6f4a99beb73a1460100e4a2a410ac673a.tar.bz2
passt-9d8dd8b6f4a99beb73a1460100e4a2a410ac673a.tar.lz
passt-9d8dd8b6f4a99beb73a1460100e4a2a410ac673a.tar.xz
passt-9d8dd8b6f4a99beb73a1460100e4a2a410ac673a.tar.zst
passt-9d8dd8b6f4a99beb73a1460100e4a2a410ac673a.zip
tap: Split tap_ip6_send() into UDP and ICMP variants
tap_ip6_send() has special case logic to compute the checksums for UDP and ICMP packets, which is a mild layering violation. By using a suitable helper we can split it into tap_udp6_send() and tap_icmp6_send() functions without greatly increasing the code size, this removing that layering violation. We make some small changes to the interface while there. In both cases we make the destination IPv6 address a parameter, which will be useful later. For the UDP variant we make it take just the UDP payload, and it will generate the UDP header. For the ICMP variant we pass in the ICMP header as before. The inconsistency is because that's what seems to be the more natural way to invoke the function in the callers in each case. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'dhcpv6.c')
-rw-r--r--dhcpv6.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/dhcpv6.c b/dhcpv6.c
index 7829968..e763aed 100644
--- a/dhcpv6.c
+++ b/dhcpv6.c
@@ -208,15 +208,8 @@ struct msg_hdr {
uint32_t xid:24;
} __attribute__((__packed__));
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define UH_RESP {{{ 547, 546, 0, 0, }}}
-#else
-#define UH_RESP {{{ __bswap_constant_16(547), __bswap_constant_16(546), 0, 0 }}}
-#endif
-
/**
* struct resp_t - Normal advertise and reply message
- * @uh: UDP header
* @hdr: DHCP message header
* @server_id: Server Identifier option
* @ia_na: Non-temporary Address option
@@ -226,7 +219,6 @@ struct msg_hdr {
* @dns_search: Domain Search List, here just for storage size
*/
static struct resp_t {
- struct udphdr uh;
struct msg_hdr hdr;
struct opt_server_id server_id;
@@ -236,7 +228,6 @@ static struct resp_t {
struct opt_dns_servers dns_servers;
struct opt_dns_search dns_search;
} __attribute__((__packed__)) resp = {
- UH_RESP,
{ 0 },
SERVER_ID,
@@ -270,13 +261,11 @@ static const struct opt_status_code sc_not_on_link = {
/**
* struct resp_not_on_link_t - NotOnLink error (mandated by RFC 8415, 18.3.2.)
- * @uh: UDP header
* @hdr: DHCP message header
* @server_id: Server Identifier option
* @var: Payload: IA_NA from client, status code, client ID
*/
static struct resp_not_on_link_t {
- struct udphdr uh;
struct msg_hdr hdr;
struct opt_server_id server_id;
@@ -284,7 +273,6 @@ static struct resp_not_on_link_t {
uint8_t var[sizeof(struct opt_ia_na) + sizeof(struct opt_status_code) +
sizeof(struct opt_client_id)];
} __attribute__((__packed__)) resp_not_on_link = {
- UH_RESP,
{ TYPE_REPLY, 0 },
SERVER_ID,
{ 0, },
@@ -527,12 +515,11 @@ int dhcpv6(struct ctx *c, const struct pool *p,
n += sizeof(struct opt_hdr) + ntohs(client_id->l);
n = offsetof(struct resp_not_on_link_t, var) + n;
- resp_not_on_link.uh.len = htons(n);
resp_not_on_link.hdr.xid = mh->xid;
- tap_ip6_send(c, src, IPPROTO_UDP,
- (char *)&resp_not_on_link, n, mh->xid);
+ tap_udp6_send(c, src, 547, tap_ip6_daddr(c, src), 546,
+ mh->xid, &resp_not_on_link, n);
return 1;
}
@@ -576,11 +563,11 @@ int dhcpv6(struct ctx *c, const struct pool *p,
n = offsetof(struct resp_t, client_id) +
sizeof(struct opt_hdr) + ntohs(client_id->l);
n = dhcpv6_dns_fill(c, (char *)&resp, n);
- resp.uh.len = htons(n);
resp.hdr.xid = mh->xid;
- tap_ip6_send(c, src, IPPROTO_UDP, (char *)&resp, n, mh->xid);
+ tap_udp6_send(c, src, 547, tap_ip6_daddr(c, src), 546,
+ mh->xid, &resp, n);
c->ip6.addr_seen = c->ip6.addr;
return 1;