From 64cf222377512d2cbdc8d750420e11cc5ddecdbd Mon Sep 17 00:00:00 2001 Message-Id: <64cf222377512d2cbdc8d750420e11cc5ddecdbd.1714035588.git.mdw@distorted.org.uk> From: Mark Wooding Date: Mon, 1 Jan 2007 12:44:59 +0000 Subject: [PATCH] admin: New command SETIFNAME to change an interface's recorded name. Organization: Straylight/Edgeware From: Mark Wooding Also the machinery in peer.c to make it work, and documentation for the new command and matching notification. --- doc/tripe-admin.5.in | 21 +++++++++++++++++++++ server/admin.c | 12 ++++++++++++ server/peer.c | 21 +++++++++++++++++++-- server/tripe.h | 13 +++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/doc/tripe-admin.5.in b/doc/tripe-admin.5.in index 4bd8144b..0d9e7b66 100644 --- a/doc/tripe-admin.5.in +++ b/doc/tripe-admin.5.in @@ -425,6 +425,15 @@ or 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 @@ -647,6 +656,7 @@ was not recognised. .BR ADDR , .BR IFNAME , .BR KILL , +.BR SETIFNAME , 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 +.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 diff --git a/server/admin.c b/server/admin.c index 7917b26f..b166b853 100644 --- a/server/admin.c +++ b/server/admin.c @@ -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; @@ -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 }, + { "setifname", "PEER NEW-NAME", 2, 2, acmd_setifname }, { "stats", "PEER", 1, 1, acmd_stats }, #ifndef NTRACE { "trace", "[OPTIONS]", 0, 1, acmd_trace }, diff --git a/server/peer.c b/server/peer.c index 50dec936..c9198924 100644 --- a/server/peer.c +++ b/server/peer.c @@ -554,7 +554,20 @@ stats *p_stats(peer *p) { return (&p->st); } * 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@ --- * * @@ -684,6 +697,7 @@ peer *p_create(peerspec *spec) 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) @@ -691,13 +705,14 @@ peer *p_create(peerspec *spec) 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, - "%s", p->t->ops->ifname(p->t), + "%s", p->ifname, "?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); + if (p->ifname) + xfree(p->ifname); p->t->ops->destroy(p->t); if (p->spec.t_ka) sel_rmtimer(&p->tka); diff --git a/server/tripe.h b/server/tripe.h index 59ae9c94..6bee0c3d 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -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 */ + char *ifname; /* Interface name for tunnel */ 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*/); +/* --- @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 -- [mdw]