chiark / gitweb /
admin: New command SETIFNAME to change an interface's recorded name.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 1 Jan 2007 12:44:59 +0000 (12:44 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 1 Jan 2007 12:51:48 +0000 (12:51 +0000)
Also the machinery in peer.c to make it work, and documentation for the
new command and matching notification.

doc/tripe-admin.5.in
server/admin.c
server/peer.c
server/tripe.h

index 4bd8144b31de139f21432296e7347d50467926a3..0d9e7b6641f2a7b9ac667731fab2cd2089abd0a9 100644 (file)
@@ -425,6 +425,15 @@ or
 if the server has or hasn't (respectively) become a daemon.
 .RE
 .SP
 if the server has or hasn't (respectively) become a daemon.
 .RE
 .SP
+.BI "SETIFNAME " peer " " new-name
+Informs the server that the
+.IR peer 's
+tunnel-interface name has been changed to
+.IR new-name .
+This is useful if firewalling decisions are made based on interface
+names: a setup script for a particular peer can change the name, and
+then update the server's records so that they're accurate.
+.SP
 .BI "STATS " peer
 Emits a number of
 .B INFO
 .BI "STATS " peer
 Emits a number of
 .B INFO
@@ -647,6 +656,7 @@ was not recognised.
 .BR ADDR ,
 .BR IFNAME ,
 .BR KILL ,
 .BR ADDR ,
 .BR IFNAME ,
 .BR KILL ,
+.BR SETIFNAME ,
 and
 .BR STATS .)
 There is no peer called
 and
 .BR STATS .)
 There is no peer called
@@ -696,6 +706,17 @@ Key exchange with
 has begun or restarted.  If key exchange keeps failing, this message
 will be repeated periodically.
 .SP
 has begun or restarted.  If key exchange keeps failing, this message
 will be repeated periodically.
 .SP
+.BI "NEWIFNAME " peer " " old-name " " new-name
+The given
+.IR peer 's
+tunnel interface name has been changed from
+.I old-name
+to
+.IR new-name ,
+as a result of a
+.B SETIFNAME
+command.
+.SP
 .BI "USER " tokens\fR...
 An administration client issued a notification using the
 .B NOTIFY
 .BI "USER " tokens\fR...
 An administration client issued a notification using the
 .B NOTIFY
index 7917b26fb434b021c6204230bcefb7b3428be9a1..b166b853dbdb3de411ad610993cc00f8ed1558f8 100644 (file)
@@ -1239,6 +1239,17 @@ static void acmd_ifname(admin *a, unsigned ac, char *av[])
   }
 }
 
   }
 }
 
+static void acmd_setifname(admin *a, unsigned ac, char *av[])
+{
+  peer *p;
+
+  if ((p = a_findpeer(a, av[0])) != 0) {
+    a_notify("NEWIFNAME", "?PEER", p, "%s", p_ifname(p), "%s", av[1], A_END);
+    p_setifname(p, av[1]);
+    a_ok(a);
+  }  
+}
+
 static void acmd_getchal(admin *a, unsigned ac, char *av[])
 {
   buf b;
 static void acmd_getchal(admin *a, unsigned ac, char *av[])
 {
   buf b;
@@ -1417,6 +1428,7 @@ static const acmd acmdtab[] = {
   { "quit",    0,                      0,      0,      acmd_quit },
   { "reload",  0,                      0,      0,      acmd_reload },
   { "servinfo",        0,                      0,      0,      acmd_servinfo },
   { "quit",    0,                      0,      0,      acmd_quit },
   { "reload",  0,                      0,      0,      acmd_reload },
   { "servinfo",        0,                      0,      0,      acmd_servinfo },
+  { "setifname", "PEER NEW-NAME",      2,      2,      acmd_setifname },
   { "stats",   "PEER",                 1,      1,      acmd_stats },
 #ifndef NTRACE
   { "trace",   "[OPTIONS]",            0,      1,      acmd_trace },
   { "stats",   "PEER",                 1,      1,      acmd_stats },
 #ifndef NTRACE
   { "trace",   "[OPTIONS]",            0,      1,      acmd_trace },
index 50dec936a612aaf3795f990d2dab14f1a83c3224..c9198924327c9068d7c0cbc42e4dec91673b6dfb 100644 (file)
@@ -554,7 +554,20 @@ stats *p_stats(peer *p) { return (&p->st); }
  * Returns:    A pointer to the peer's interface name.
  */
 
  * Returns:    A pointer to the peer's interface name.
  */
 
-const char *p_ifname(peer *p) { return (p->t->ops->ifname(p->t)); }
+const char *p_ifname(peer *p) { return (p->ifname); }
+
+/* --- @p_setifname@ --- *
+ *
+ * Arguments:  @peer *p@ = pointer to a peer block
+ *             @const char *name@ = pointer to the new name
+ *
+ * Returns:    ---
+ *
+ * Use:                Changes the name held for a peer's interface.
+ */
+
+void p_setifname(peer *p, const char *name)
+  { if (p->ifname) xfree(p->ifname); p->ifname = xstrdup(name); }
 
 /* --- @p_addr@ --- *
  *
 
 /* --- @p_addr@ --- *
  *
@@ -684,6 +697,7 @@ peer *p_create(peerspec *spec)
   p->ks = 0;
   p->prev = 0;
   p->pings = 0;
   p->ks = 0;
   p->prev = 0;
   p->pings = 0;
+  p->ifname = 0;
   memset(&p->st, 0, sizeof(stats));
   p->st.t_start = time(0);
   if ((p->t = spec->tops->create(p)) == 0)
   memset(&p->st, 0, sizeof(stats));
   p->st.t_start = time(0);
   if ((p->t = spec->tops->create(p)) == 0)
@@ -691,13 +705,14 @@ peer *p_create(peerspec *spec)
   p_setkatimer(p);
   if (kx_init(&p->kx, p, &p->ks))
     goto tidy_1;
   p_setkatimer(p);
   if (kx_init(&p->kx, p, &p->ks))
     goto tidy_1;
+  p_setifname(p, spec->tops->ifname(p->t));
   p->next = peers;
   if (peers)
     peers->prev = p;
   peers = p;
   a_notify("ADD",
            "?PEER", p,
   p->next = peers;
   if (peers)
     peers->prev = p;
   peers = p;
   a_notify("ADD",
            "?PEER", p,
-           "%s", p->t->ops->ifname(p->t),
+           "%s", p->ifname,
            "?ADDR", &p->spec.sa,
            A_END);
   a_notify("KXSTART", "?PEER", p, A_END);
            "?ADDR", &p->spec.sa,
            A_END);
   a_notify("KXSTART", "?PEER", p, A_END);
@@ -768,6 +783,8 @@ void p_destroy(peer *p)
   a_notify("KILL", "%s", p->spec.name, A_END);
   ksl_free(&p->ks);
   kx_free(&p->kx);
   a_notify("KILL", "%s", p->spec.name, A_END);
   ksl_free(&p->ks);
   kx_free(&p->kx);
+  if (p->ifname)
+    xfree(p->ifname);
   p->t->ops->destroy(p->t);
   if (p->spec.t_ka)
     sel_rmtimer(&p->tka);
   p->t->ops->destroy(p->t);
   if (p->spec.t_ka)
     sel_rmtimer(&p->tka);
index 59ae9c94876683ed0dda20f267274badf099e9cc..6bee0c3d0d6865a4eb7a9d55fc9b7a67281b4264 100644 (file)
@@ -314,6 +314,7 @@ typedef struct peer {
   struct ping *pings;                  /* Pings we're waiting for */
   peerspec spec;                       /* Specifications for this peer */
   tunnel *t;                           /* Tunnel for local packets */
   struct ping *pings;                  /* Pings we're waiting for */
   peerspec spec;                       /* Specifications for this peer */
   tunnel *t;                           /* Tunnel for local packets */
+  char *ifname;                                /* Interface name for tunnel */
   keyset *ks;                          /* List head for keysets */
   buf b;                               /* Buffer for sending packets */
   stats st;                            /* Statistics */
   keyset *ks;                          /* List head for keysets */
   buf b;                               /* Buffer for sending packets */
   stats st;                            /* Statistics */
@@ -935,6 +936,18 @@ extern stats *p_stats(peer */*p*/);
 
 extern const char *p_ifname(peer */*p*/);
 
 
 extern const char *p_ifname(peer */*p*/);
 
+/* --- @p_setifname@ --- *
+ *
+ * Arguments:  @peer *p@ = pointer to a peer block
+ *             @const char *name@ = pointer to the new name
+ *
+ * Returns:    ---
+ *
+ * Use:                Changes the name held for a peer's interface.
+ */
+
+extern void p_setifname(peer */*p*/, const char */*name*/);
+
 /* --- @p_addr@ --- *
  *
  * Arguments:  @peer *p@ = pointer to a peer block
 /* --- @p_addr@ --- *
  *
  * Arguments:  @peer *p@ = pointer to a peer block