chiark / gitweb /
server/peer.c, server/keyset.c: Fix key renegotiation behaviour.
[tripe] / server / tun-slip.c
index 2efda8900e03be73b5a344ee6c553490f3740a07..d405cc49f41075fcaa8f0c0b9030b664b60a08db 100644 (file)
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id$
  *
  * Tunnel packets via SLIP
  *
  * (c) 2005 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Trivial IP Encryption (TrIPE).
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * TrIPE is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with TrIPE; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -55,7 +53,7 @@ struct tunnel {
 #   define ST_EOF 4u                   /*   File descriptor reported EOF */
   size_t n;                            /* Number of bytes used in buffer */
   octet buf[PKBUFSZ];                  /* Buffer for incoming data */
-};  
+};
 
 /*----- Static variables --------------------------------------------------*/
 
@@ -64,11 +62,6 @@ static const char *slipcmd;          /* Script to make new interfaces */
 
 /*----- Main code ---------------------------------------------------------*/
 
-#define SL_END 0xc0
-#define SL_ESC 0xdb
-#define SL_ESCEND 0xdc
-#define SL_ESCESC 0xdd
-
 /* --- @t_read@ --- *
  *
  * Arguments:  @int fd@ = file descriptor to read
@@ -100,11 +93,11 @@ static void t_read(int fd, unsigned mode, void *v)
 #endif
        errno == EAGAIN)
       return;
-    a_warn("TUN", "%s", t->sl->name, "read-error", "?ERRNO", A_END);
+    a_warn("TUN", "%s", p_ifname(t->p), "read-error", "?ERRNO", A_END);
     return;
   }
   if (!n) {
-    a_warn("TUN", "%s", t->sl->name, "slip", "eof", A_END);
+    a_warn("TUN", "%s", p_ifname(t->p), "slip", "eof", A_END);
     t->st = ST_EOF;
     sel_rmfile(&t->f);
     return;
@@ -126,7 +119,7 @@ static void t_read(int fd, unsigned mode, void *v)
        if (st & ST_BAD)
          ;
        else if (st & ST_ESC)
-         a_warn("TUN", "%s", t->sl->name, "slip", "escape-end", A_END);
+         a_warn("TUN", "%s", p_ifname(t->p), "slip", "escape-end", A_END);
        else if (q == t->buf) {
          T( trace(T_TUNNEL, "tun-slip: empty packet"); )
        } else {
@@ -143,7 +136,7 @@ static void t_read(int fd, unsigned mode, void *v)
        break;
       case SL_ESC:
        if ((st & ST_ESC) && !(st & ST_BAD)) {
-         a_warn("TUN", "%s", t->sl->name, "slip", "bad-escape", A_END);
+         a_warn("TUN", "%s", p_ifname(t->p), "slip", "bad-escape", A_END);
          st |= ST_BAD;
        } else
          st |= ST_ESC;
@@ -158,7 +151,7 @@ static void t_read(int fd, unsigned mode, void *v)
        goto emit;
       default:
        if ((st & ST_ESC) && !(st & ST_BAD)) {
-         a_warn("TUN", "%s", t->sl->name, "slip", "bad-escape", A_END);
+         a_warn("TUN", "%s", p_ifname(t->p), "slip", "bad-escape", A_END);
          st |= ST_BAD;
        }
       emit:
@@ -166,7 +159,7 @@ static void t_read(int fd, unsigned mode, void *v)
          if (q < ll)
            *q++ = o;
          else {
-           a_warn("TUN", "%s", t->sl->name, "slip", "overflow", A_END);
+           a_warn("TUN", "%s", p_ifname(t->p), "slip", "overflow", A_END);
            st |= ST_BAD;
          }
        }
@@ -253,13 +246,14 @@ whine:
 /* --- @t_create@ --- *
  *
  * Arguments:  @peer *p@ = pointer to peer block
+ *             @char **ifn@ = where to put the interface name
  *
  * Returns:    A tunnel block if it worked, or null on failure.
  *
  * Use:                Initializes a new tunnel.
  */
 
-static tunnel *t_create(peer *p)
+static tunnel *t_create(peer *p, char **ifn)
 {
   slipif *sl = 0;
   int pin[2] = { -1, -1 }, pout[2] = { -1, -1 };
@@ -345,6 +339,7 @@ found:
   sel_initfile(&sel, &t->f, sl->ifd, SEL_READ, t_read, t);
   sel_addfile(&t->f);
   write(sl->ofd, end, sizeof(end));
+  *ifn = xstrdup(sl->name);
   dstr_destroy(&d);
   return (t);
 
@@ -361,14 +356,18 @@ fail:
   return (0);
 }
 
-/* --- @t_ifname@ --- *
+/* --- @t_setifname@ --- *
  *
  * Arguments:  @tunnel *t@ = pointer to tunnel block
+ *             @const char *ifn@ = new interface name
+ *
+ * Returns:    ---
  *
- * Returns:    A pointer to the tunnel's interface name.
+ * Use:                Updates the interface name of a slip interface.
  */
 
-static const char *t_ifname(tunnel *t) { return (t->sl->name); }
+static void t_setifname(tunnel *t, const char *ifn)
+  { xfree(t->sl->name); t->sl->name = xstrdup(ifn); }
 
 /* --- @t_inject@ --- *
  *
@@ -442,7 +441,7 @@ const tunnel_ops tun_slip = {
   "slip",
   t_init,
   t_create,
-  t_ifname,
+  t_setifname,
   t_inject,
   t_destroy
 };