[Openvpn-devel,1/9] maddr: create helper function to populate maddr object from eth_addr

Message ID 20191009143422.9419-2-a@unstable.cc
State Accepted
Headers show
Series
  • support VLANs in TAP mode
Related show

Commit Message

Antonio Quartulli Oct. 9, 2019, 2:34 p.m.
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
 src/openvpn/mroute.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Gert Doering Oct. 9, 2019, 5:57 p.m. | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

This is one of the easy ones, and very "obviously correct".  Client side
tested on Linux and FreeBSD with t_client / TAP tests (which do not really
excercise this code, unfortunately, but my test server is still down).

While I do prefer memcpy()'s using "sizeof(dest)" to "OPENVPN_ETH_ALEN", 
mroute.eth_addr is "uint8_t[OPENVPN_ETH_ALEN]" so this is safe enough.

Your patch has been applied to the master branch.

commit 5e27e47d631f61ee3f9234dd076389232495e714
Author: Antonio Quartulli
Date:   Wed Oct 9 16:34:14 2019 +0200

     maddr: create helper function to populate maddr object from eth_addr

     Signed-off-by: Antonio Quartulli <a@unstable.cc>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20191009143422.9419-2-a@unstable.cc>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18921.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/mroute.c b/src/openvpn/mroute.c
index db8c9876..c52ef7b1 100644
--- a/src/openvpn/mroute.c
+++ b/src/openvpn/mroute.c
@@ -247,6 +247,16 @@  mroute_extract_addr_ip(struct mroute_addr *src, struct mroute_addr *dest,
     return ret;
 }
 
+static void
+mroute_copy_ether_to_addr(struct mroute_addr *maddr,
+                          const uint8_t *ether_addr)
+{
+    maddr->type = MR_ADDR_ETHER;
+    maddr->netbits = 0;
+    maddr->len = OPENVPN_ETH_ALEN;
+    memcpy(maddr->eth_addr, ether_addr, OPENVPN_ETH_ALEN);
+}
+
 unsigned int
 mroute_extract_addr_ether(struct mroute_addr *src,
                           struct mroute_addr *dest,
@@ -260,17 +270,11 @@  mroute_extract_addr_ether(struct mroute_addr *src,
         const struct openvpn_ethhdr *eth = (const struct openvpn_ethhdr *) BPTR(buf);
         if (src)
         {
-            src->type = MR_ADDR_ETHER;
-            src->netbits = 0;
-            src->len = 6;
-            memcpy(src->eth_addr, eth->source, sizeof(dest->eth_addr));
+            mroute_copy_ether_to_addr(src, eth->source);
         }
         if (dest)
         {
-            dest->type = MR_ADDR_ETHER;
-            dest->netbits = 0;
-            dest->len = 6;
-            memcpy(dest->eth_addr, eth->dest, sizeof(dest->eth_addr));
+            mroute_copy_ether_to_addr(dest, eth->dest);
 
             /* ethernet broadcast/multicast packet? */
             if (is_mac_mcast_addr(eth->dest))