{
const RADCLIENT *a = one;
const RADCLIENT *b = two;
+#ifndef WITH_TCP
return fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
+#else
+ int rcode;
+
+ rcode = fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
+ if (rcode != 0) return rcode;
+
+ /*
+ * Wildcard match
+ */
+ if ((a->proto == IPPROTO_IP) ||
+ (b->proto == IPPROTO_IP)) return 0;
+
+ return (a->proto - b->proto);
+#endif
}
#ifdef WITH_STATS
* If there IS an enclosing network,
* inherit the lifetime from it.
*/
- network = client_find(clients, &client->ipaddr);
+ network = client_find(clients, &client->ipaddr
+#ifdef WITH_TCP
+ , client->proto
+#endif
+ );
if (network) {
client->lifetime = network->lifetime;
}
* Find a client in the RADCLIENTS list.
*/
RADCLIENT *client_find(const RADCLIENT_LIST *clients,
- const fr_ipaddr_t *ipaddr)
+ const fr_ipaddr_t *ipaddr
+#ifdef WITH_TCP
+ , int proto
+#endif
+ )
{
int i, max_prefix;
RADCLIENT myclient;
myclient.prefix = i;
myclient.ipaddr = *ipaddr;
+#ifdef WITH_TCP
+ myclient.proto = proto;
+#endif
client_sane(&myclient); /* clean up the ipaddress */
if (!clients->trees[i]) continue;
*/
RADCLIENT *client_find_old(const fr_ipaddr_t *ipaddr)
{
- return client_find(root_clients, ipaddr);
+ return client_find(root_clients, ipaddr, IPPROTO_UDP);
}
static struct in_addr cl_ip4addr;
static struct in6_addr cl_ip6addr;
+#ifdef WITH_TCP
+static char *hs_proto = NULL;
+#endif
static const CONF_PARSER client_config[] = {
{ "ipaddr", PW_TYPE_IPADDR,
{ "server", PW_TYPE_STRING_PTR, /* compatability with 2.0-pre */
offsetof(RADCLIENT, server), 0, NULL },
+#ifdef WITH_TCP
+ { "proto", PW_TYPE_STRING_PTR,
+ 0, &hs_proto, NULL },
+ { "max_connections", PW_TYPE_INTEGER,
+ offsetof(RADCLIENT, max_connections), 0, "16" },
+#endif
+
#ifdef WITH_DYNAMIC_CLIENTS
{ "dynamic_clients", PW_TYPE_STRING_PTR,
offsetof(RADCLIENT, client_server), 0, NULL },
c->prefix = -1;
if (cf_section_parse(cs, c, client_config) < 0) {
- client_free(c);
cf_log_err(cf_sectiontoitem(cs),
"Error parsing client section.");
+ error:
+ client_free(c);
+#ifdef WITH_TCP
+ free(hs_proto);
+ hs_proto = NULL;
+#endif
+
return NULL;
}
* per-server clients cannot.
*/
if (in_server && c->server) {
- client_free(c);
cf_log_err(cf_sectiontoitem(cs),
"Clients inside of an server section cannot point to a server.");
- return NULL;
+ goto error;
}
/*
if (prefix_ptr) {
c->prefix = atoi(prefix_ptr + 1);
if ((c->prefix < 0) || (c->prefix > 128)) {
- client_free(c);
cf_log_err(cf_sectiontoitem(cs),
"Invalid Prefix value '%s' for IP.",
prefix_ptr + 1);
- return NULL;
+ goto error;
}
/* Replace '/' with '\0' */
*prefix_ptr = '\0';
* Always get the numeric representation of IP
*/
if (ip_hton(name2, AF_UNSPEC, &c->ipaddr) < 0) {
- client_free(c);
cf_log_err(cf_sectiontoitem(cs),
"Failed to look up hostname %s: %s",
name2, fr_strerror());
- return NULL;
+ goto error;
}
if (prefix_ptr) *prefix_ptr = '/';
c->ipaddr.ipaddr.ip4addr = cl_ip4addr;
if ((c->prefix < -1) || (c->prefix > 32)) {
- client_free(c);
cf_log_err(cf_sectiontoitem(cs),
"Netmask must be between 0 and 32");
- return NULL;
+ goto error;
}
} else if (cf_pair_find(cs, "ipv6addr")) {
c->ipaddr.ipaddr.ip6addr = cl_ip6addr;
if ((c->prefix < -1) || (c->prefix > 128)) {
- client_free(c);
cf_log_err(cf_sectiontoitem(cs),
"Netmask must be between 0 and 128");
- return NULL;
+ goto error;
}
} else {
cf_log_err(cf_sectiontoitem(cs),
"No IP address defined for the client");
- client_free(c);
- return NULL;
+ goto error;
}
ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
* Set the short name to the name2
*/
if (!c->shortname) c->shortname = strdup(name2);
+
+#ifdef WITH_TCP
+ c->proto = IPPROTO_UDP;
+ if (hs_proto) {
+ if (strcmp(hs_proto, "udp") == 0) {
+ free(hs_proto);
+ hs_proto = NULL;
+
+ } else if (strcmp(hs_proto, "tcp") == 0) {
+ free(hs_proto);
+ hs_proto = NULL;
+ c->proto = IPPROTO_TCP;
+
+ } else if (strcmp(hs_proto, "*") == 0) {
+ free(hs_proto);
+ hs_proto = NULL;
+ c->proto = IPPROTO_IP; /* fake for dual */
+
+ } else {
+ cf_log_err(cf_sectiontoitem(cs),
+ "Unknown proto \"%s\".", hs_proto);
+ goto error;
+ }
+ }
+#endif
}
if (c->prefix < 0) switch (c->ipaddr.af) {
(c->prefix == 128))) {
cf_log_err(cf_sectiontoitem(cs),
"Dynamic clients MUST be a network, not a single IP address.");
- client_free(c);
- return NULL;
+ goto error;
}
return c;
if (value && (strcmp(value, "yes") == 0)) return c;
#endif
- client_free(c);
cf_log_err(cf_sectiontoitem(cs),
"secret must be at least 1 character long");
- return NULL;
+ goto error;
}
#ifdef WITH_COA
HOME_TYPE_COA);
}
if (!c->coa_pool && !c->coa_server) {
- client_free(c);
cf_log_err(cf_sectiontoitem(cs), "No such home_server or home_server_pool \"%s\"", c->coa_name);
- return NULL;
+ goto error;
}
}
#endif
RADCLIENT *client;
fr_ipaddr_t ipaddr;
+#ifdef WITH_TCP
+ int proto = IPPROTO_UDP;
+#endif
+
if (argc < 1) {
cprintf(listener, "ERROR: Must specify <ipaddr>\n");
return NULL;
return NULL;
}
- client = client_find(NULL, &ipaddr);
+#ifdef WITH_TCP
+ if (argc >= 2) {
+ if (strcmp(argv[1], "tcp") == 0) {
+ proto = IPPROTO_TCP;
+
+ } else if (strcmp(argv[1], "udp") == 0) {
+ proto = IPPROTO_UDP;
+
+ } else {
+ cprintf(listener, "ERROR: Unknown protocol %s. Please use \"udp\" or \"tcp\"\n",
+ argv[1]);
+ return NULL;
+ }
+ }
+#endif
+
+ client = client_find(NULL, &ipaddr
+#ifdef WITH_TCP
+ , proto
+#endif
+ );
if (!client) {
cprintf(listener, "ERROR: No such client\n");
return NULL;
static fr_command_table_t command_table_show_client[] = {
{ "config", FR_READ,
- "show client config <ipaddr> - show configuration for given client",
+ "show client config <ipaddr> "
+#ifdef WITH_TCP
+ "[proto] "
+#endif
+ "- show configuration for given client",
command_show_client_config, NULL },
{ "list", FR_READ,
"show client list - shows list of global clients",
static fr_command_table_t command_table_stats[] = {
{ "client", FR_READ,
- "stats client [auth/acct] <ipaddr> - show statistics for given client, or for all clients (auth or acct)",
+ "stats client [auth/acct] <ipaddr> "
+#ifdef WITH_TCP
+ "[proto] "
+#endif
+ "- show statistics for given client, or for all clients (auth or acct)",
command_stats_client, NULL },
#ifdef WITH_PROXY
{ "home_server", FR_READ,