Skip to content

Commit

Permalink
Make TCP sockets work with udpfromto.
Browse files Browse the repository at this point in the history
Add a "proto" field to RADIUS_PACKET.
Have it checked in rad_send(), so that we just use write().
Using sendto() is OK for TCP sockets.
Using udpfromto is not OK for TCP sockets.

Ensure that the TCP code in listen.c sets the proto field.
Ensure that rad_alloc_reply() sets the proto field
Ensure that radclient sets the proto field as necessary

Conflicts:
	src/main/radclient.c
  • Loading branch information
alandekok committed Jan 31, 2014
1 parent b31f858 commit e497159
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/include/libradius.h
Expand Up @@ -395,6 +395,7 @@ typedef struct radius_packet {
ssize_t offset;
#ifdef WITH_TCP
size_t partial;
int proto;
#endif
} RADIUS_PACKET;

Expand Down
21 changes: 21 additions & 0 deletions src/lib/radius.c
Expand Up @@ -2074,6 +2074,24 @@ int rad_send(RADIUS_PACKET *packet, RADIUS_PACKET const *original,
if ((fr_debug_flag > 3) && fr_log_fp) rad_print_hex(packet);
#endif

#ifdef WITH_TCP
/*
* If the socket is TCP, call write(). Calling sendto()
* is allowed on some platforms, but it's not nice. Even
* worse, if UDPFROMTO is defined, we *can't* use it on
* TCP sockets. So... just call write().
*/
if (packet->proto == IPPROTO_TCP) {
ssize_t rcode;

rcode = write(packet->sockfd, packet->data, packet->data_len);
if (rcode >= 0) return rcode;

fr_strerror_printf("sendto failed: %s", fr_syserror(errno));
return -1;
}
#endif

/*
* And send it on it's way.
*/
Expand Down Expand Up @@ -4651,6 +4669,9 @@ RADIUS_PACKET *rad_alloc_reply(TALLOC_CTX *ctx, RADIUS_PACKET *packet)
reply->data = NULL;
reply->data_len = 0;

#ifdef WITH_TCP
reply->proto = packet->proto;
#endif
return reply;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/listen.c
Expand Up @@ -434,6 +434,7 @@ static int dual_tcp_recv(rad_listen_t *listener)
sock->packet->src_port = sock->other_port;
sock->packet->dst_ipaddr = sock->my_ipaddr;
sock->packet->dst_port = sock->my_port;
sock->packet->proto = sock->proto;
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/main/radclient.c
Expand Up @@ -254,6 +254,7 @@ static int radclient_init(TALLOC_CTX *ctx, char const *filename)
request->packet->src_port = client_port;
request->packet->dst_ipaddr = server_ipaddr;
request->packet->dst_port = server_port;
request->packet->proto = ipproto;
#endif

request->filename = filename;
Expand Down

0 comments on commit e497159

Please sign in to comment.