diff mbox series

[ovs-dev,3/4] lib: get rid of packed attribute from dhcpv6_opt_server_id struct

Message ID 1c6d1c986e52cf499a5e765108c50135a2ec6f0e.1683623703.git.lorenzo.bianconi@redhat.com
State Accepted
Headers show
Series remove unnecessary OVS_PACKED attribute from dhcpv6 structures | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Lorenzo Bianconi May 9, 2023, 9:21 a.m. UTC
Fill dhcpv6_opt_server_id structure on the stack in
compose_prefixd_packet routine in order to get rid of OVS_PACKED
attribute for dhcpv6_opt_server_id structure since it is already packed.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 controller/pinctrl.c | 52 ++++++++++++++++++++++++--------------------
 lib/ovn-l7.h         |  7 +++---
 2 files changed, 32 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/controller/pinctrl.c b/controller/pinctrl.c
index 8921d6787..1b00bf864 100644
--- a/controller/pinctrl.c
+++ b/controller/pinctrl.c
@@ -1077,31 +1077,34 @@  compose_prefixd_packet(struct dp_packet *b, struct ipv6_prefixd_state *pfd)
     } else {
         *dhcp_hdr = DHCPV6_MSG_TYPE_SOLICIT;
     }
+    dhcp_hdr += 4;
+
+    struct dhcpv6_opt_server_id opt_client_id = {
+        .opt.code = htons(DHCPV6_OPT_CLIENT_ID_CODE),
+        .opt.len = htons(sizeof(struct dhcpv6_opt_server_id) -
+                         sizeof(struct dhcpv6_opt_header)),
+        .duid_type = htons(DHCPV6_DUID_LL),
+        .hw_type = htons(DHCPV6_HW_TYPE_ETH),
+        .mac = pfd->cmac,
+    };
+    memcpy(dhcp_hdr, &opt_client_id, sizeof(struct dhcpv6_opt_server_id));
+    dhcp_hdr += sizeof(struct dhcpv6_opt_server_id);
 
-    struct dhcpv6_opt_server_id *opt_client_id =
-        (struct dhcpv6_opt_server_id *)(dhcp_hdr + 4);
-    opt_client_id->opt.code = htons(DHCPV6_OPT_CLIENT_ID_CODE);
-    opt_client_id->opt.len = htons(sizeof(struct dhcpv6_opt_server_id) -
-                                   sizeof(struct dhcpv6_opt_header));
-    opt_client_id->duid_type = htons(DHCPV6_DUID_LL);
-    opt_client_id->hw_type = htons(DHCPV6_HW_TYPE_ETH);
-    opt_client_id->mac = pfd->cmac;
-
-    unsigned char *ptr = (unsigned char *)(opt_client_id + 1);
     if (pfd->uuid.len) {
-        struct dhcpv6_opt_header *in_opt = (struct dhcpv6_opt_header *)ptr;
+        struct dhcpv6_opt_header *in_opt =
+            (struct dhcpv6_opt_header *) dhcp_hdr;
         in_opt->code = htons(DHCPV6_OPT_SERVER_ID_CODE);
         in_opt->len = htons(pfd->uuid.len);
 
-        ptr += sizeof *in_opt;
-        memcpy(ptr, pfd->uuid.data, pfd->uuid.len);
-        ptr += pfd->uuid.len;
+        dhcp_hdr += sizeof *in_opt;
+        memcpy(dhcp_hdr, pfd->uuid.data, pfd->uuid.len);
+        dhcp_hdr += pfd->uuid.len;
     }
 
     if (!ipv6_addr_is_set(&pfd->prefix)) {
         pfd->aid = random_uint16();
     }
-    struct dhcpv6_opt_ia_na *ia_pd = (struct dhcpv6_opt_ia_na *)ptr;
+    struct dhcpv6_opt_ia_na *ia_pd = (struct dhcpv6_opt_ia_na *) dhcp_hdr;
     ia_pd->opt.code = htons(DHCPV6_OPT_IA_PD);
     int opt_len = sizeof(struct dhcpv6_opt_ia_na) -
                   sizeof(struct dhcpv6_opt_header);
@@ -2466,16 +2469,17 @@  compose_out_dhcpv6_opts(struct ofpbuf *userdata,
              *
              * We use DUID Based on Link-layer Address [DUID-LL].
              */
-
-            struct dhcpv6_opt_server_id *opt_server_id = ofpbuf_put_zeros(
-                out_dhcpv6_opts, sizeof *opt_server_id);
-
-            opt_server_id->opt.code = htons(DHCPV6_OPT_SERVER_ID_CODE);
-            opt_server_id->opt.len = htons(size + 4);
-            opt_server_id->duid_type = htons(DHCPV6_DUID_LL);
-            opt_server_id->hw_type = htons(DHCPV6_HW_TYPE_ETH);
-            memcpy(&opt_server_id->mac, userdata_opt_data,
+            struct dhcpv6_opt_server_id opt_server_id = {
+                .opt.code = htons(DHCPV6_OPT_SERVER_ID_CODE),
+                .opt.len = htons(size + 4),
+                .duid_type = htons(DHCPV6_DUID_LL),
+                .hw_type = htons(DHCPV6_HW_TYPE_ETH),
+            };
+            memcpy(&opt_server_id.mac, userdata_opt_data,
                     sizeof(struct eth_addr));
+            void *ptr = ofpbuf_put_zeros(out_dhcpv6_opts,
+                                         sizeof(struct dhcpv6_opt_server_id));
+            memcpy(ptr, &opt_server_id, sizeof(struct dhcpv6_opt_server_id));
             break;
         }
 
diff --git a/lib/ovn-l7.h b/lib/ovn-l7.h
index a84068fc0..8f21df32f 100644
--- a/lib/ovn-l7.h
+++ b/lib/ovn-l7.h
@@ -296,14 +296,15 @@  struct dhcpv6_opt_header {
     ovs_be16 len;
 });
 
-OVS_PACKED(
+#define DHCP6_OPT_SERVER_ID_LEN 14
 struct dhcpv6_opt_server_id {
     struct dhcpv6_opt_header opt;
     ovs_be16 duid_type;
     ovs_be16 hw_type;
     struct eth_addr mac;
-});
-
+};
+BUILD_ASSERT_DECL(DHCP6_OPT_SERVER_ID_LEN ==
+                  sizeof(struct dhcpv6_opt_server_id));
 
 #define DHCP6_OPT_IA_ADDR_LEN 28
 struct dhcpv6_opt_ia_addr {