RADIUS_PACKET **fr_packet_list_yank(fr_packet_list_t *pl,
RADIUS_PACKET *request);
int fr_packet_list_num_elements(fr_packet_list_t *pl);
-int fr_packet_list_id_alloc(fr_packet_list_t *pl,
+int fr_packet_list_id_alloc(fr_packet_list_t *pl, int proto,
RADIUS_PACKET *request, void **pctx);
int fr_packet_list_id_free(fr_packet_list_t *pl,
RADIUS_PACKET *request);
-int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd,
+int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd, int proto,
fr_ipaddr_t *dst_ipaddr, int dst_port,
void *ctx);
int fr_packet_list_socket_remove(fr_packet_list_t *pl, int sockfd,
#endif
#endif
-#ifdef WITH_TCP
int proto;
+#ifdef WITH_TCP
int max_connections;
int num_connections;
#endif
fr_ipaddr_t other_ipaddr;
int other_port;
-#ifdef WITH_TCP
int proto;
+#ifdef WITH_TCP
/* for a proxy connecting to home servers */
time_t last_packet;
time_t opened;
RADCLIENT *client_create(RADCLIENT_LIST *clients, REQUEST *request);
#endif
RADCLIENT *client_find(const RADCLIENT_LIST *clients,
- const fr_ipaddr_t *ipaddr
-#ifdef WITH_TCP
- , int proto
-#endif
-);
+ const fr_ipaddr_t *ipaddr, int proto);
+
RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
int number);
RADCLIENT *client_find_old(const fr_ipaddr_t *ipaddr);
int port;
int type; /* auth/acct */
-#ifdef WITH_TCP
int proto;
-#endif
int max_connections;
int num_connections; /* protected by proxy mutex */
int max_requests; /* for one connection */
int dont_use;
#ifdef WITH_TCP
- int type;
+ int proto;
#endif
uint8_t id[32];
return 1;
}
-int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd,
+int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd, int proto,
fr_ipaddr_t *dst_ipaddr, int dst_port,
void *ctx)
{
memset(ps, 0, sizeof(*ps));
ps->ctx = ctx;
-
-#ifdef WITH_TCP
- sizeof_src = sizeof(ps->type);
-
- if (getsockopt(sockfd, SOL_SOCKET, SO_TYPE, &ps->type, &sizeof_src) < 0) {
- fr_strerror_printf("%s", strerror(errno));
- return 0;
- }
-
-#endif
+ ps->proto = proto;
/*
* Get address family, etc. first, so we know if we
* We also assume that the sender doesn't care which protocol
* should be used.
*/
-int fr_packet_list_id_alloc(fr_packet_list_t *pl,
+int fr_packet_list_id_alloc(fr_packet_list_t *pl, int proto,
RADIUS_PACKET *request, void **pctx)
{
int i, j, k, fd, id, start_i, start_j, start_k;
return 0;
}
+#ifndef WITH_TCP
+ if ((proto != 0) && (proto != IPPROTO_UDP)) {
+ fr_strerror_printf("Invalid destination protocol");
+ return 0;
+ }
+#endif
+
/*
* Special case: unspec == "don't care"
*/
*/
if (ps->num_outgoing == 256) continue;
+#ifdef WITH_TCP
+ if (ps->proto != proto) continue;
+#endif
+
/*
- * MUST match dst port, if one has been given.
+ * MUST match dst port, if we have one.
*/
if ((ps->dst_port != 0) &&
(ps->dst_port != request->dst_port)) continue;
/*
+ * MUST match requested src port, if one has been given.
+ */
+ if ((request->src_port != 0) &&
+ (ps->dst_port != request->dst_port)) continue;
+
+ /*
* We're sourcing from *, and they asked for a
* specific source address: ignore it.
*/
if (!FD_ISSET(pl->sockets[start].sockfd, set)) continue;
#ifdef WITH_TCP
- if (pl->sockets[start].type == SOCK_STREAM) {
+ if (pl->sockets[start].proto == IPPROTO_TCP) {
packet = fr_tcp_recv(pl->sockets[start].sockfd, 0);
} else
#endif
* If there IS an enclosing network,
* inherit the lifetime from it.
*/
- network = client_find(clients, &client->ipaddr
-#ifdef WITH_TCP
- , client->proto
-#endif
- );
+ network = client_find(clients, &client->ipaddr, client->proto);
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
-#ifdef WITH_TCP
- , int proto
-#endif
- )
+ const fr_ipaddr_t *ipaddr, int proto)
{
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;
*/
if (!c->shortname) c->shortname = strdup(name2);
-#ifdef WITH_TCP
c->proto = IPPROTO_UDP;
+#ifdef WITH_TCP
if (hs_proto) {
if (strcmp(hs_proto, "udp") == 0) {
free(hs_proto);
{
RADCLIENT *client;
fr_ipaddr_t ipaddr;
-
-#ifdef WITH_TCP
int proto = IPPROTO_UDP;
-#endif
if (argc < 1) {
cprintf(listener, "ERROR: Must specify <ipaddr>\n");
}
#endif
- client = client_find(NULL, &ipaddr
-#ifdef WITH_TCP
- , proto
-#endif
- );
+ client = client_find(NULL, &ipaddr, proto);
if (!client) {
cprintf(listener, "ERROR: No such client\n");
return NULL;
{
void *proxy_listener;
- if (fr_packet_list_id_alloc(proxy_list, packet,
- &proxy_listener)) {
+ if (fr_packet_list_id_alloc(proxy_list, request->home_server->proto,
+ packet, &proxy_listener)) {
request->proxy_listener = proxy_listener;
return 1;
}
return 0;
}
- if (!fr_packet_list_id_alloc(proxy_list, packet,
- &proxy_listener)) {
+ if (!fr_packet_list_id_alloc(proxy_list, request->home_server->proto,
+ packet, &proxy_listener)) {
RDEBUG2("ERROR: Failed allocating Id for new socket when proxying requests.");
return 0;
}
return;
}
- RDEBUG2("Child is finally responsive for request %d", request->number);
+ RDEBUG2("Child is responsive for request %d", request->number);
remove_from_request_hash(request);
#ifdef WITH_PROXY
char buffer[128];
rad_assert(request->magic == REQUEST_MAGIC);
+
+ if (request->master_state == REQUEST_STOP_PROCESSING) {
+ ev_request_free(&request);
+ return;
+ }
+
rad_assert(request->child_state == REQUEST_PROXIED);
/*
inet_ntop(request->proxy->dst_ipaddr.af,
&request->proxy->dst_ipaddr.ipaddr,
buffer, sizeof(buffer)),
- request->proxy->dst_port);
+ request->proxy->dst_port);
/*
* Note that we set proxied BEFORE sending the packet.
PTHREAD_MUTEX_LOCK(&proxy_mutex);
if (!fr_packet_list_socket_add(proxy_list, this->fd,
+ sock->proto,
&sock->other_ipaddr, sock->other_port,
this)) {
radlog(L_ERR, "Fatal error adding socket: %s",
*/
rad_assert(clients != NULL);
- client = client_find(clients, ipaddr
-#ifdef WITH_TCP
- ,sock->proto
-#endif
- );
+ client = client_find(clients, ipaddr,sock->proto);
if (!client) {
char name[256], buffer[128];
/*
* Go find the enclosing network again.
*/
- client = client_find(clients, ipaddr
-#ifdef WITH_TCP
- , sock->proto
-#endif
- );
+ client = client_find(clients, ipaddr, sock->proto);
/*
* WTF?
return -1;
}
-#ifdef WITH_TCP
sock->proto = IPPROTO_UDP;
-#endif
if (cf_pair_find(cs, "proto")) {
#ifndef WITH_TCP
sock->my_ipaddr = home->src_ipaddr;
sock->my_port = src_port;
-
-#ifdef WITH_TCP
sock->proto = home->proto;
+
+#ifdef WITH_TCP
sock->last_packet = time(NULL);
if (home->proto == IPPROTO_TCP) {
}
}
-#ifdef WITH_TCP
home->proto = IPPROTO_UDP;
+#ifdef WITH_TCP
if (hs_proto) {
if (strcmp(hs_proto, "udp") == 0) {
free(hs_proto);