Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 740707a

Browse files
committed
Add the notion of 'idling' a session when we get a response
A session is 'busy' when a request has been sent, and the response not yet received. As soon as the response is received, the session re-enters the 'idle' state (and any associated read timeouts can be cleared). We also clear timeouts when a session enters connected state, but only if we hadn't pre-queued the first request.
1 parent dfee11a commit 740707a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

libtac/include/libtac.h

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ struct tac_session {
161161
uint32_t tac_session_id;
162162
bool tac_encryption;
163163
bool tac_multiplex;
164+
bool tac_idle; /* not exposed via API */
164165
uint8_t tac_priv_lvl;
165166
uint8_t tac_authen_method;
166167
uint8_t tac_authen_service;

libtac/lib/session.c

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ tac_session_alloc_extra(unsigned n)
3737
sess->tac_secret = NULL;
3838
sess->tac_session_id = magic();
3939
sess->tac_encryption = sess->tac_multiplex = false;
40+
sess->tac_idle = true;
4041
sess->tac_priv_lvl = TAC_PLUS_PRIV_LVL_MIN;
4142
sess->tac_authen_service = TAC_PLUS_AUTHEN_SVC_PPP;
4243
sess->tac_authen_method = TAC_PLUS_AUTHEN_METH_TACACSPLUS;

libtac/lib/wrappers.c

+23-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ static void eventcb(struct bufferevent *bev, short events, void *ptr)
144144
if (sess->oob_cb) {
145145
if (events & BEV_EVENT_CONNECTED) {
146146
TACDEBUG(LOG_DEBUG, "session %p connected", sess);
147-
/* change for setup timeout to read/write timeout values */
148-
tac_session_reset_timeouts(sess, true);
147+
/*
148+
* if we had enqueued a request before the connect
149+
* completed, then the idle flag would be false
150+
* and we would want to reset the timer; if we didn't
151+
* have a request on-the-wire, then the timeout gets
152+
* cleared once we're connected.
153+
*/
154+
tac_session_reset_timeouts(sess, !sess->tac_idle);
149155
(sess->oob_cb)(sess, &sess->context, CONNECTED);
150156
}
151157
if (events & BEV_EVENT_ERROR) {
@@ -241,6 +247,9 @@ static void readcb(struct bufferevent *bev, void *ptr)
241247
/* turn off timeouts */
242248
tac_session_reset_timeouts(sess, false);
243249

250+
/* received response, so connection is idle again */
251+
sess->tac_idle = true;
252+
244253
tac_parse_pkt(sess, ctx, pkt, ((i > 0) ? i : 0));
245254

246255
free(pkt);
@@ -328,6 +337,9 @@ tac_authen_send_ev(struct tac_session *sess,
328337
ret = bufferevent_write_buffer(sess->bufev, evbuf);
329338
evbuffer_free(evbuf);
330339

340+
/* we have a request on-the-wire */
341+
sess->tac_idle = false;
342+
331343
TACDEBUG(LOG_DEBUG, "session %p: write status=%d", sess, ret);
332344

333345
return (ret == 0);
@@ -367,6 +379,9 @@ tac_author_send_ev(struct tac_session *sess,
367379
ret = bufferevent_write_buffer(sess->bufev, evbuf);
368380
evbuffer_free(evbuf);
369381

382+
/* we have a request on-the-wire */
383+
sess->tac_idle = false;
384+
370385
TACDEBUG(LOG_DEBUG, "session %p write status=%d", sess, ret);
371386

372387
return (ret == 0);
@@ -406,6 +421,9 @@ tac_acct_send_ev(struct tac_session *sess,
406421
ret = bufferevent_write_buffer(sess->bufev, evbuf);
407422
evbuffer_free(evbuf);
408423

424+
/* we have a request on-the-wire */
425+
sess->tac_idle = false;
426+
409427
TACDEBUG(LOG_DEBUG, "session %p write status=%d", sess, ret);
410428

411429
return (ret == 0);
@@ -442,6 +460,9 @@ tac_cont_send_ev(struct tac_session *sess, const char *pass) {
442460
ret = bufferevent_write_buffer(sess->bufev, evbuf);
443461
evbuffer_free(evbuf);
444462

463+
/* we have a request on-the-wire */
464+
sess->tac_idle = false;
465+
445466
TACDEBUG(LOG_DEBUG, "session %p write status=%d", sess, ret);
446467

447468
return (ret == 0);

0 commit comments

Comments
 (0)