Added "del client <ipaddr>" command for dynamic clients
authorAlan T. DeKok <aland@freeradius.org>
Fri, 17 Sep 2010 12:59:33 +0000 (14:59 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 17 Sep 2010 13:28:57 +0000 (15:28 +0200)
src/main/client.c
src/main/command.c

index 50dde1e..74875c7 100644 (file)
@@ -418,7 +418,11 @@ int client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
 #ifdef WITH_DYNAMIC_CLIENTS
 void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client)
 {
-       if (!clients || !client) return;
+       if (!client) return;
+
+       if (!clients) clients = root_clients;
+
+       if (!client->dynamic) return;
 
        rad_assert((client->prefix >= 0) && (client->prefix <= 128));
 
index 94ac308..1b6e9c3 100644 (file)
@@ -1730,6 +1730,54 @@ static int command_add_client_file(rad_listen_t *listener, int argc, char *argv[
 }
 
 
+static int command_del_client(rad_listen_t *listener, int argc, char *argv[])
+{
+#ifdef WITH_DYNAMIC_CLIENTS
+       RADCLIENT *client;
+
+       client = get_client(listener, argc - 1, argv + 1);
+       if (!client) return 0;
+
+       if (!client->dynamic) {
+               cprintf(listener, "ERROR: Client %s was not dynamically defined.\n", argv[1]);
+               return 0;
+       }
+
+       /*
+        *      DON'T delete it.  Instead, mark it as "dead now".  The
+        *      next time we receive a packet for the client, it will
+        *      be deleted.
+        *
+        *      If we don't receive a packet from it, the client
+        *      structure will stick around for a while.  Oh well...
+        */
+       client->lifetime = 1;
+#else
+       cprintf(listener, "ERROR: Dynamic clients are not supported.\n");
+#endif
+
+       return 1;
+}
+
+
+static fr_command_table_t command_table_del_client[] = {
+       { "ipaddr", FR_WRITE,
+         "del client ipaddr <ipaddr> - Delete a dynamically created client",
+         command_del_client, NULL },
+
+       { NULL, 0, NULL, NULL, NULL }
+};
+
+
+static fr_command_table_t command_table_del[] = {
+       { "client", FR_WRITE,
+         "del client <command> - Delete client configuration commands",
+         NULL, command_table_del_client },
+
+       { NULL, 0, NULL, NULL, NULL }
+};
+
+
 static fr_command_table_t command_table_add_client[] = {
        { "file", FR_WRITE,
          "add client file <filename> - Add new client definition from <filename>",
@@ -1813,6 +1861,7 @@ static fr_command_table_t command_table[] = {
        { "debug", FR_WRITE,
          "debug <command> - debugging commands",
          NULL, command_table_debug },
+       { "del", FR_WRITE, NULL, NULL, command_table_del },
        { "hup", FR_WRITE,
          "hup [module] - sends a HUP signal to the server, or optionally to one module",
          command_hup, NULL },