chiark / gitweb /
server/: Calculate address size on demand, rather than tracking it.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 4 Sep 2017 01:25:41 +0000 (02:25 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 14 Jun 2018 09:34:25 +0000 (10:34 +0100)
It's fine when the address is just in the peer spec, but this isn't
going to be the case forever.

server/admin.c
server/peer.c
server/servutil.c
server/tripe.h

index 867c4247584db8c628b823be0b408964d3b62e47..aafe0b9c8c69b896c1e597be48d0f5ef7c2fc4d6 100644 (file)
@@ -1110,7 +1110,6 @@ static void a_resolve(admin *a, admin_resop *r, const char *tag,
     goto fail;
   }
   r->sa.sin.sin_family = AF_INET;
-  r->sasz = sizeof(r->sa.sin);
   r->addr = xstrdup(av[i]);
   if (!av[i + 1])
     pt = TRIPE_PORT;
@@ -1223,7 +1222,6 @@ static void a_doadd(admin_resop *r, int rc)
   T( trace(T_ADMIN, "admin: done add op %s", BGTAG(add)); )
 
   if (rc == ARES_OK) {
-    add->peer.sasz = add->r.sasz;
     add->peer.sa = add->r.sa;
     if (p_findbyaddr(&add->r.sa))
       a_bgfail(&add->r.bg, "peer-addr-exists", "?ADDR", &add->r.sa, A_END);
index f74b977dd09bb892b285559b3d95f98253054861..891888b0b56aef503798ed45dbb2bd12794a8283 100644 (file)
@@ -481,6 +481,8 @@ static void p_setkatimer(peer *);
 
 static int p_dotxend(peer *p)
 {
+  socklen_t sasz = addrsz(&p->spec.sa);
+
   if (!BOK(&p->b)) {
     a_warn("PEER", "?PEER", p, "packet-build-failed", A_END);
     return (0);
@@ -488,7 +490,7 @@ static int p_dotxend(peer *p)
   IF_TRACING(T_PEER, trace_block(T_PACKET, "peer: sending packet",
                                 BBASE(&p->b), BLEN(&p->b)); )
   if (sendto(sock.fd, BBASE(&p->b), BLEN(&p->b),
-            0, &p->spec.sa.sa, p->spec.sasz) < 0) {
+            0, &p->spec.sa.sa, sasz) < 0) {
     a_warn("PEER", "?PEER", p, "socket-write-error", "?ERRNO", A_END);
     return (0);
   } else {
index e4772c4c025c9bf1cf0d16ef16d8f06e62717f41..707213968f9dd2be252e7485c313c3bbbce7e4e5 100644 (file)
@@ -121,4 +121,19 @@ int mystrieq(const char *x, const char *y)
   }
 }
 
+/* --- @addrsz@ --- *
+ *
+ * Arguments:  @const addr *a@ = a network address
+ *
+ * Returns:    The size of the address, for passing into the sockets API.
+ */
+
+socklen_t addrsz(const addr *a)
+{
+  switch (a->sa.sa_family) {
+    case AF_INET: return (sizeof(a->sin));
+    default: abort();
+  }
+}
+
 /*----- That's all, folks -------------------------------------------------*/
index 3402776ffae132d2c17a55f0d5857a719170bd59..fa5333bd75f9fa78e1d8a5ba5e6f6b0aa14a58f9 100644 (file)
@@ -595,7 +595,6 @@ typedef struct peerspec {
   const tunnel_ops *tops;              /* Tunnel operations */
   unsigned long t_ka;                  /* Keep alive interval */
   addr sa;                             /* Socket address to speak to */
-  size_t sasz;                         /* Socket address size */
   unsigned f;                          /* Flags for the peer */
 #define PSF_KXMASK 255u                        /*   Key-exchange flags to set */
 #define PSF_MOBILE 256u                        /*   Address may change rapidly */
@@ -1730,6 +1729,15 @@ extern const char *timestr(time_t /*t*/);
 
 extern int mystrieq(const char */*x*/, const char */*y*/);
 
+/* --- @addrsz@ --- *
+ *
+ * Arguments:  @const addr *a@ = a network address
+ *
+ * Returns:    The size of the address, for passing into the sockets API.
+ */
+
+extern socklen_t addrsz(const addr */*a*/);
+
 /* --- @seq_reset@ --- *
  *
  * Arguments:  @seqwin *s@ = sequence-checking window