143313Sbrian/*
2330449Seadler * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3330449Seadler *
443313Sbrian * Copyright 1999 Internet Business Solutions Ltd., Switzerland
543313Sbrian * All rights reserved.
643313Sbrian *
743313Sbrian * Redistribution and use in source and binary forms, with or without
843313Sbrian * modification, are permitted provided that the following conditions
943313Sbrian * are met:
1043313Sbrian * 1. Redistributions of source code must retain the above copyright
1143313Sbrian *    notice, this list of conditions and the following disclaimer.
1243313Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1343313Sbrian *    notice, this list of conditions and the following disclaimer in the
1443313Sbrian *    documentation and/or other materials provided with the distribution.
1543313Sbrian *
1643313Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1743313Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1843313Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1943313Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2043313Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2143313Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2243313Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2343313Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2443313Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2543313Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2643313Sbrian * SUCH DAMAGE.
2743313Sbrian *
2850479Speter * $FreeBSD: stable/11/usr.sbin/ppp/radius.h 330449 2018-03-05 07:26:05Z eadler $
2943313Sbrian */
3043313Sbrian
3198132Sbrian#define	MPPE_POLICY_ALLOWED	1
3298132Sbrian#define	MPPE_POLICY_REQUIRED	2
3398132Sbrian
3498132Sbrian#define	MPPE_TYPE_40BIT		2
3598132Sbrian#define	MPPE_TYPE_128BIT	4
3698132Sbrian
37169986Snovel#define	RPI_DEFAULT		1
38169986Snovel#define	RPI_PID			2
39169986Snovel#define	RPI_IFNUM		3
40169986Snovel#define	RPI_TUNNUM		4
41169986Snovel
4243313Sbrianstruct radius {
4358028Sbrian  struct fdescriptor desc;	/* We're a sort of (selectable) fdescriptor */
4443693Sbrian  struct {
4543693Sbrian    int fd;			/* We're selecting on this */
4643693Sbrian    struct rad_handle *rad;	/* Using this to talk to our lib */
4743693Sbrian    struct pppTimer timer;	/* for this long */
4843693Sbrian    struct authinfo *auth;	/* Tell this about success/failure */
4943693Sbrian  } cx;
5043313Sbrian  unsigned valid : 1;           /* Is this structure valid ? */
5143313Sbrian  unsigned vj : 1;              /* FRAMED Compression */
5243313Sbrian  struct in_addr ip;            /* FRAMED IP */
5343313Sbrian  struct in_addr mask;          /* FRAMED Netmask */
5443313Sbrian  unsigned long mtu;            /* FRAMED MTU */
5596153Sbrian  unsigned long sessiontime;    /* Session-Timeout */
5696153Sbrian  char *filterid;		/* FRAMED Filter Id */
5743313Sbrian  struct sticky_route *routes;  /* FRAMED Routes */
5896730Sbrian  char *msrepstr;		/* MS-CHAP2-Response */
5996324Sbrian  char *repstr;			/* Reply-Message */
6096324Sbrian  char *errstr;			/* Error-Message */
61116586Sume#ifndef NOINET6
62116622Sume  uint8_t *ipv6prefix;		/* FRAMED IPv6 Prefix */
63116586Sume  struct sticky_route *ipv6routes;  /* FRAMED IPv6 Routes */
64116586Sume#endif
6543313Sbrian  struct {
6698132Sbrian    int policy;			/* MPPE_POLICY_* */
6798132Sbrian    int types;			/* MPPE_TYPE_*BIT bitmask */
6898132Sbrian    char *recvkey;
6998132Sbrian    size_t recvkeylen;
7098132Sbrian    char *sendkey;
7198132Sbrian    size_t sendkeylen;
7298132Sbrian  } mppe;
7398132Sbrian  struct {
7474001Sbrian    char file[PATH_MAX];	/* Radius config file */
7543313Sbrian  } cfg;
76132273Sbrian  struct {
77132273Sbrian    struct pppTimer timer;	/* for this long */
78132273Sbrian    int interval;
79132273Sbrian  } alive;
80169986Snovel  short unsigned int port_id_type;
8143313Sbrian};
8243313Sbrian
8365178Sbrianstruct radacct {
8465178Sbrian  struct radius *rad_parent;	/* "Parent" struct radius stored in bundle */
8565178Sbrian  char user_name[AUTHLEN];	/* Session User-Name */
8665178Sbrian  char session_id[256];		/* Unique session ID */
8765178Sbrian  char multi_session_id[51];	/* Unique MP session ID */
8865178Sbrian  int  authentic;		/* How the session has been authenticated */
89116588Sume  u_short proto;		/* Protocol number */
90116588Sume  union {
91116588Sume    struct {
92116588Sume      struct in_addr addr;
93116588Sume      struct in_addr mask;
94116588Sume    } ip;
95116588Sume#ifndef NOINET6
96116588Sume    struct {
97116588Sume      u_char ifid[8];
98116588Sume    } ipv6;
99116588Sume#endif
100116990Sume  } peer;
10165178Sbrian};
10265178Sbrian
10343693Sbrian#define descriptor2radius(d) \
10443693Sbrian  ((d)->type == RADIUS_DESCRIPTOR ? (struct radius *)(d) : NULL)
10543693Sbrian
10643313Sbrianstruct bundle;
10743313Sbrian
108140905Sbrianextern void radius_Flush(struct radius *);
10943313Sbrianextern void radius_Init(struct radius *);
11043313Sbrianextern void radius_Destroy(struct radius *);
11143313Sbrian
11243313Sbrianextern void radius_Show(struct radius *, struct prompt *);
113132273Sbrianextern void radius_StartTimer(struct bundle *);
114132273Sbrianextern void radius_StopTimer(struct radius *);
11596730Sbrianextern int radius_Authenticate(struct radius *, struct authinfo *,
11696730Sbrian                               const char *, const char *, int,
11798311Sbrian                               const char *, int);
118116588Sumeextern void radius_Account_Set_Ip(struct radacct *, struct in_addr *,
119116588Sume				  struct in_addr *);
120116588Sume#ifndef NOINET6
121116588Sumeextern void radius_Account_Set_Ipv6(struct radacct *, u_char *);
122116588Sume#endif
12398243Sbrianextern void radius_Account(struct radius *, struct radacct *,
124116588Sume                           struct datalink *, int, struct pppThroughput *);
12565178Sbrian
12665178Sbrian/* An (int) parameter to radius_Account, from radlib.h */
12765178Sbrian#if !defined(RAD_START)
12865178Sbrian#define RAD_START	1
12965178Sbrian#define RAD_STOP	2
13065178Sbrian#endif
13193767Shosokawa
132132273Sbrian#define RAD_ALIVE	3
133132273Sbrian
13493767Shosokawa/* Get address from NAS pool */
13593767Shosokawa#define RADIUS_INADDR_POOL	htonl(0xfffffffe)	/* 255.255.255.254 */
136