From 88e008cda351399e326b94cf430df441a7f53244 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Fri, 20 Feb 2015 16:18:06 +0100 Subject: [PATCH] radius: when sending accounting information include any updated IP --- src/auth/radius.c | 9 ++++++++- src/ipc.proto | 1 + src/sec-mod-auth.c | 2 +- src/sec-mod-auth.h | 2 +- src/worker-vpn.c | 4 ++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/auth/radius.c b/src/auth/radius.c index 3c5fcd17..1f6dc463 100644 --- a/src/auth/radius.c +++ b/src/auth/radius.c @@ -400,6 +400,10 @@ static void append_acct_standard(struct radius_ctx_st * pctx, rc_handle *rh, } } + if (rc_avpair_add(rh, send, PW_CALLING_STATION_ID, pctx->remote_ip, -1, 0) == NULL) { + return; + } + if (rc_avpair_add(rh, send, PW_ACCT_SESSION_ID, pctx->sid, -1, 0) == NULL) { return; } @@ -417,13 +421,16 @@ static void append_acct_standard(struct radius_ctx_st * pctx, rc_handle *rh, return; } -static void radius_auth_session_stats(void* ctx, stats_st *stats) +static void radius_auth_session_stats(void* ctx, stats_st *stats, const char *ip) { struct radius_ctx_st * pctx = ctx; int ret; uint32_t status_type; VALUE_PAIR *send = NULL, *recvd = NULL; + if (ip) + strlcpy(pctx->remote_ip, ip, sizeof(pctx->remote_ip)); + status_type = PW_STATUS_ALIVE; syslog(LOG_DEBUG, "radius-auth: sending session interim update"); diff --git a/src/ipc.proto b/src/ipc.proto index 90eafddb..f7327013 100644 --- a/src/ipc.proto +++ b/src/ipc.proto @@ -115,6 +115,7 @@ message cli_stats_msg required uint64 bytes_out = 2; optional bytes sid = 3; /* only required by sec-mod */ required uint32 uptime = 4; /* sec-mod */ + optional string ip = 5; /* only required by sec-mod */ } /* UDP_FD */ diff --git a/src/sec-mod-auth.c b/src/sec-mod-auth.c index 54c3cf65..545fc5fe 100644 --- a/src/sec-mod-auth.c +++ b/src/sec-mod-auth.c @@ -463,7 +463,7 @@ int handle_sec_auth_stats_cmd(sec_mod_st * sec, const CliStatsMsg * req) return 0; stats_add_to(&totals, &e->stats, &e->saved_stats); - e->module->session_stats(e->auth_ctx, &totals); + e->module->session_stats(e->auth_ctx, &totals, req->ip); return 0; } diff --git a/src/sec-mod-auth.h b/src/sec-mod-auth.h index 6410954e..ab14b346 100644 --- a/src/sec-mod-auth.h +++ b/src/sec-mod-auth.h @@ -39,7 +39,7 @@ struct auth_mod_st { int (*auth_user)(void* ctx, char *groupname, int groupname_size); int (*open_session)(void *ctx, const void *sid, unsigned sid_size); /* optional, may be null */ - void (*session_stats)(void *ctx, struct stats_st *stats); /* optional, may be null */ + void (*session_stats)(void *ctx, struct stats_st *stats, const char *ip); /* optional, may be null */ void (*close_session)(void *ctx, struct stats_st *stats); /* optional may be null */ void (*auth_deinit)(void* ctx); diff --git a/src/worker-vpn.c b/src/worker-vpn.c index 02048037..3f1d78b3 100644 --- a/src/worker-vpn.c +++ b/src/worker-vpn.c @@ -610,6 +610,7 @@ int periodic_check(worker_st * ws, unsigned mtu_overhead, time_t now, sd = connect_to_secmod(ws); if (sd >= 0) { + char buf[64]; msg.bytes_in = ws->tun_bytes_in; msg.bytes_out = ws->tun_bytes_out; msg.uptime = now - ws->session_start_time; @@ -617,6 +618,9 @@ int periodic_check(worker_st * ws, unsigned mtu_overhead, time_t now, msg.sid.data = ws->sid; msg.has_sid = 1; + msg.ip = human_addr2((void *)&ws->remote_addr, ws->remote_addr_len, + buf, sizeof(buf), 0); + send_msg_to_secmod(ws, sd, SM_CMD_CLI_STATS, &msg, (pack_size_func)cli_stats_msg__get_packed_size, (pack_func) cli_stats_msg__pack);