Skip to contentSkip to conversation

Remove unused addr_inet4or6, addr_guess_family and inline addr_copy_sa

PATCH In review Arne Schwabe 2 participants 2 messages Nov 9, 2022 – Nov 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove unused addr_inet4or6, addr_guess_family and inline addr_copy_sa

addr_copy_sa is just a single line and putting that simple assignment into an extra function does not really improve clarity.

---
 src/openvpn/socket.h | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
src/openvpn/socket.h +2 -16
index 462afa31b..94c8b6dff 100644
@@ -863,20 +863,6 @@ addr_zero_host(struct openvpn_sockaddr *addr)
     }
 }
 
-static inline void
-addr_copy_sa(struct openvpn_sockaddr *dst, const struct openvpn_sockaddr *src)
-{
-    dst->addr = src->addr;
-}
-
-static inline bool
-addr_inet4or6(struct sockaddr *addr)
-{
-    return addr->sa_family == AF_INET || addr->sa_family == AF_INET6;
-}
-
-int addr_guess_family(sa_family_t af, const char *name);
-
 static inline int
 af_addr_size(sa_family_t af)
 {
@@ -1052,7 +1038,7 @@ link_socket_read_udp_win32(struct link_socket *sock,
     sockethandle_t sh = { .s = sock->sd };
     if (sock->info.dco_installed)
     {
-        addr_copy_sa(&from->dest, &sock->info.lsa->actual.dest);
+        from->dest = sock->info.lsa->actual.dest;
         sh.is_handle = true;
     }
     return sockethandle_finalize(sh, &sock->reads, buf, from);
@@ -1089,7 +1075,7 @@ link_socket_read(struct link_socket *sock,
     else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
     {
         /* from address was returned by accept */
-        addr_copy_sa(&from->dest, &sock->info.lsa->actual.dest);
+        from->dest = sock->info.lsa->actual.dest;
         return link_socket_read_tcp(sock, buf);
     }
     else
Signature · 1 line
2.37.0 (Apple Git-136)
Acked-by on v1 1/1
#1 lore raw

My first thought was "trivial enough", the second thought was "oh wait"
- the old code copies "src->addr" to "dst->addr", while the new code copies "src" to "dst". Now, src/dst are "struct openvpn_sockaddr" here, which is a struct containing only one member, "->addr" (which is a union) - so the copying does the same thing, just with shorter source code lines.

Of course I have actually tested this :-) - the windows function has only been compile tested (github actions, no errors) and the unix function has been client-side tested with tests including TCP.

Your patch has been applied to the master branch.

commit 470d1d149aac162fac3390e7dcb29c2a9ea7dba4

Author: Arne Schwabe
Date:   Wed Nov 9 12:07:49 2022 +0100
     Remove unused addr_inet4or6, addr_guess_family and inline addr_copy_sa

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25493.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering