From: Alan T. DeKok Date: Fri, 27 Nov 2009 10:47:56 +0000 (+0100) Subject: Add tcp/udp to CLI for home_servers X-Git-Tag: release_3_0_0_beta0~1657 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=f037c57d0660cf1d80f48d36feddc295a870ebd2;p=freeradius.git Add tcp/udp to CLI for home_servers --- diff --git a/src/include/realms.h b/src/include/realms.h index 1467b2b..506d087 100644 --- a/src/include/realms.h +++ b/src/include/realms.h @@ -136,7 +136,7 @@ REALM *realm_find(const char *name); /* name is from a packet */ REALM *realm_find2(const char *name); /* ... with name taken from realm_find */ home_server *home_server_ldb(const char *realmname, home_pool_t *pool, REQUEST *request); -home_server *home_server_find(fr_ipaddr_t *ipaddr, int port); +home_server *home_server_find(fr_ipaddr_t *ipaddr, int port, int proto); #ifdef WITH_COA home_server *home_server_byname(const char *name, int type); #endif diff --git a/src/main/command.c b/src/main/command.c index 7b9769a..899b764 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -577,7 +577,7 @@ static int command_show_home_servers(rad_listen_t *listener, UNUSED int argc, UN { int i; home_server *home; - const char *type, *state; + const char *type, *state, *proto; char buffer[256]; @@ -598,6 +598,16 @@ static int command_show_home_servers(rad_listen_t *listener, UNUSED int argc, UN } else continue; + if (home->proto == IPPROTO_UDP) { + proto = "udp"; + } +#ifdef WITH_TCP + else if (home->proto == IPPROTO_TCP) { + proto = "tcp"; + } +#endif + else proto = "??"; + if (home->state == HOME_STATE_ALIVE) { state = "alive"; @@ -609,9 +619,9 @@ static int command_show_home_servers(rad_listen_t *listener, UNUSED int argc, UN } else continue; - cprintf(listener, "%s\t%d\t%s\t%s\t%d\n", + cprintf(listener, "%s\t%d\t%s\t%s\t%s\t%d\n", ip_ntoh(&home->ipaddr, buffer, sizeof(buffer)), - home->port, type, state, + home->port, proto, type, state, home->currently_outstanding); } @@ -864,14 +874,16 @@ static int command_show_client_config(rad_listen_t *listener, int argc, char *ar } #ifdef WITH_PROXY -static home_server *get_home_server(rad_listen_t *listener, int argc, char *argv[]) +static home_server *get_home_server(rad_listen_t *listener, int argc, + char *argv[], int *last) { home_server *home; int port; + int proto = IPPROTO_UDP; fr_ipaddr_t ipaddr; if (argc < 2) { - cprintf(listener, "ERROR: Must specify \n"); + cprintf(listener, "ERROR: Must specify [proto]\n"); return NULL; } @@ -883,7 +895,21 @@ static home_server *get_home_server(rad_listen_t *listener, int argc, char *argv port = atoi(argv[1]); - home = home_server_find(&ipaddr, port); + if (last) *last = 2; + if (argc > 2) { + if (strcmp(argv[2], "udp") == 0) { + proto = IPPROTO_UDP; + if (last) *last = 3; + } +#ifdef WITH_TCP + if (strcmp(argv[2], "tcp") == 0) { + proto = IPPROTO_TCP; + if (last) *last = 3; + } +#endif + } + + home = home_server_find(&ipaddr, port, proto); if (!home) { cprintf(listener, "ERROR: No such home server\n"); return NULL; @@ -897,7 +923,7 @@ static int command_show_home_server_config(rad_listen_t *listener, int argc, cha home_server *home; FILE *fp; - home = get_home_server(listener, argc, argv); + home = get_home_server(listener, argc, argv, NULL); if (!home) { return 0; } @@ -921,29 +947,30 @@ extern void mark_home_server_dead(home_server *home, struct timeval *when); static int command_set_home_server_state(rad_listen_t *listener, int argc, char *argv[]) { + int last; home_server *home; if (argc < 3) { - cprintf(listener, "ERROR: Must specify \n"); + cprintf(listener, "ERROR: Must specify [proto] \n"); return 0; } - home = get_home_server(listener, argc, argv); + home = get_home_server(listener, argc, argv, &last); if (!home) { return 0; } - if (strcmp(argv[2], "alive") == 0) { + if (strcmp(argv[last], "alive") == 0) { revive_home_server(home); - } else if (strcmp(argv[2], "dead") == 0) { + } else if (strcmp(argv[last], "dead") == 0) { struct timeval now; gettimeofday(&now, NULL); /* we do this WAY too ofetn */ mark_home_server_dead(home, &now); } else { - cprintf(listener, "ERROR: Unknown state \"%s\"\n", argv[2]); + cprintf(listener, "ERROR: Unknown state \"%s\"\n", argv[last]); return 0; } @@ -954,7 +981,7 @@ static int command_show_home_server_state(rad_listen_t *listener, int argc, char { home_server *home; - home = get_home_server(listener, argc, argv); + home = get_home_server(listener, argc, argv, NULL); if (!home) { return 0; } @@ -1328,13 +1355,13 @@ static fr_command_table_t command_table_show_client[] = { #ifdef WITH_PROXY static fr_command_table_t command_table_show_home[] = { { "config", FR_READ, - "show home_server config - show configuration for given home server", + "show home_server config [proto] - show configuration for given home server", command_show_home_server_config, NULL }, { "list", FR_READ, "show home_server list - shows list of home servers", command_show_home_servers, NULL }, { "state", FR_READ, - "show home_server state - shows state of given home server", + "show home_server state [proto] - shows state of given home server", command_show_home_server_state, NULL }, { NULL, 0, NULL, NULL, NULL } @@ -1544,7 +1571,7 @@ static int command_stats_home_server(rad_listen_t *listener, int argc, char *arg return 0; } - home = get_home_server(listener, argc, argv); + home = get_home_server(listener, argc, argv, NULL); if (!home) { return 0; } @@ -1659,7 +1686,7 @@ static fr_command_table_t command_table_add[] = { #ifdef WITH_PROXY static fr_command_table_t command_table_set_home[] = { { "state", FR_WRITE, - "set home_server state [alive|dead] - set state for given home server", + "set home_server state [proto] [alive|dead] - set state for given home server", command_set_home_server_state, NULL }, { NULL, 0, NULL, NULL, NULL } diff --git a/src/main/realms.c b/src/main/realms.c index b3be96d..a49c18b 100644 --- a/src/main/realms.c +++ b/src/main/realms.c @@ -142,6 +142,7 @@ static int home_server_addr_cmp(const void *one, const void *two) if (a->server && !b->server) return -1; if (!a->server && b->server) return +1; + if (a->server && b->server) { int rcode = a->type - b->type; if (rcode != 0) return rcode; @@ -2217,13 +2218,18 @@ home_server *home_server_ldb(const char *realmname, } -home_server *home_server_find(fr_ipaddr_t *ipaddr, int port) +home_server *home_server_find(fr_ipaddr_t *ipaddr, int port, int proto) { home_server myhome; memset(&myhome, 0, sizeof(myhome)); myhome.ipaddr = *ipaddr; myhome.port = port; +#ifdef WITH_TCP + myhome.proto = proto; +#else + myhome.proto = IPPROTO_UDP; +#endif myhome.server = NULL; /* we're not called for internal proxying */ return rbtree_finddata(home_servers_byaddr, &myhome);