-/* $OpenBSD: npppd_auth.c,v 1.22 2021/03/29 03:54:39 yasuoka Exp $ */
+/* $OpenBSD: npppd_auth.c,v 1.23 2024/02/26 10:42:05 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
* SUCH DAMAGE.
*/
/**@file authentication realm */
-/* $Id: npppd_auth.c,v 1.22 2021/03/29 03:54:39 yasuoka Exp $ */
+/* $Id: npppd_auth.c,v 1.23 2024/02/26 10:42:05 yasuoka Exp $ */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include "net_utils.h"
#include "npppd_auth_local.h"
+#include "npppd_radius.h"
/**
* Create a npppd_auth_base object.
"server%s.",
nauth, (nauth > 1)? "s" : "", nacct, (nacct > 1)? "s" : "");
+ if (nacct > 0 && _this->rad_acct_on == 0) {
+ radius_acct_on(base->npppd, _this->rad_acct_setting);
+ _this->rad_acct_on = 1;
+ }
+
return 0;
}
-/* $Id: npppd_radius.c,v 1.9 2024/02/26 08:47:28 yasuoka Exp $ */
+/* $Id: npppd_radius.c,v 1.10 2024/02/26 10:42:05 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
* All rights reserved.
static int l2tp_put_tunnel_attributes(RADIUS_PACKET *, void *);
static int pptp_put_tunnel_attributes(RADIUS_PACKET *, void *);
static int radius_acct_request(npppd *, npppd_ppp *, int );
+static void radius_acct_on_cb(void *, RADIUS_PACKET *, int, RADIUS_REQUEST_CTX);
static void npppd_ppp_radius_acct_reqcb(void *, RADIUS_PACKET *, int, RADIUS_REQUEST_CTX);
/***********************************************************************
ATTR_INT32(RADIUS_TYPE_NAS_PORT, ppp->id);
/* npppd has no physical / virtual ports in design. */
+ /* RFC 2865 5.32. NAS-Identifier */
+ ATTR_STR(RADIUS_TYPE_NAS_IDENTIFIER, "npppd");
+
/* RFC 2865 5.31. Calling-Station-Id */
if (ppp->calling_number[0] != '\0')
ATTR_STR(RADIUS_TYPE_CALLING_STATION_ID, ppp->calling_number);
return -1;
}
+void
+radius_acct_on(npppd *pppd, radius_req_setting *rad_setting)
+{
+ RADIUS_REQUEST_CTX radctx = NULL;
+ RADIUS_PACKET *radpkt = NULL;
+
+ if (!radius_req_setting_has_server(rad_setting))
+ return;
+ if ((radpkt = radius_new_request_packet(RADIUS_CODE_ACCOUNTING_REQUEST))
+ == NULL)
+ goto fail;
+
+ if (radius_prepare(rad_setting, NULL, &radctx, radius_acct_on_cb) != 0)
+ goto fail;
+
+ /*
+ * RFC 2865 "5.4. NAS-IP-Address" or RFC 3162 "2.1. NAS-IPv6-Address"
+ */
+ if (radius_prepare_nas_address(rad_setting, radpkt) != 0)
+ goto fail;
+
+ /* RFC 2865 "5.41. NAS-Port-Type" */
+ ATTR_INT32(RADIUS_TYPE_NAS_PORT_TYPE, RADIUS_NAS_PORT_TYPE_VIRTUAL);
+
+ /* RFC 2866 5.1. Acct-Status-Type */
+ ATTR_INT32(RADIUS_TYPE_ACCT_STATUS_TYPE, RADIUS_ACCT_STATUS_TYPE_ACCT_ON);
+ /* RFC 2865 5.32. NAS-Identifier */
+ ATTR_STR(RADIUS_TYPE_NAS_IDENTIFIER, "npppd");
+
+ /* Send the request */
+ radius_request(radctx, radpkt);
+
+ return;
+ fail:
+ if (radctx != NULL)
+ radius_cancel_request(radctx);
+ if (radpkt != NULL)
+ radius_delete_packet(radpkt);
+}
+
+static void
+radius_acct_on_cb(void *context, RADIUS_PACKET *pkt, int flags,
+ RADIUS_REQUEST_CTX ctx)
+{
+ if ((flags & (RADIUS_REQUEST_TIMEOUT | RADIUS_REQUEST_ERROR)) != 0)
+ radius_request_failover(ctx);
+}
+
#ifdef USE_NPPPD_PPTP
#include "pptp.h"
#endif
-/* $OpenBSD: ppp.c,v 1.30 2021/03/29 03:54:39 yasuoka Exp $ */
+/* $OpenBSD: ppp.c,v 1.31 2024/02/26 10:42:05 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-/* $Id: ppp.c,v 1.30 2021/03/29 03:54:39 yasuoka Exp $ */
+/* $Id: ppp.c,v 1.31 2024/02/26 10:42:05 yasuoka Exp $ */
/**@file
* This file provides PPP(Point-to-Point Protocol, RFC 1661) and
* {@link :: _npppd_ppp PPP instance} related functions.
if (radius_prepare_nas_address(rad_setting, radpkt) != 0)
goto fail;
+ /* RFC 2865 5.32. NAS-Identifier */
+ if (radius_put_string_attr(radpkt, RADIUS_TYPE_NAS_IDENTIFIER, "npppd")
+ != 0)
+ goto fail;
+
/* RFC 2865 "5.6. Service-Type" */
if (radius_put_uint32_attr(radpkt, RADIUS_TYPE_SERVICE_TYPE,
RADIUS_SERVICE_TYPE_FRAMED) != 0)