xref: /freebsd/usr.sbin/ppp/bundle.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
17a6f8720SBrian Somers /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
47a6f8720SBrian Somers  * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
57a6f8720SBrian Somers  * All rights reserved.
67a6f8720SBrian Somers  *
77a6f8720SBrian Somers  * Redistribution and use in source and binary forms, with or without
87a6f8720SBrian Somers  * modification, are permitted provided that the following conditions
97a6f8720SBrian Somers  * are met:
107a6f8720SBrian Somers  * 1. Redistributions of source code must retain the above copyright
117a6f8720SBrian Somers  *    notice, this list of conditions and the following disclaimer.
127a6f8720SBrian Somers  * 2. Redistributions in binary form must reproduce the above copyright
137a6f8720SBrian Somers  *    notice, this list of conditions and the following disclaimer in the
147a6f8720SBrian Somers  *    documentation and/or other materials provided with the distribution.
157a6f8720SBrian Somers  *
167a6f8720SBrian Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
177a6f8720SBrian Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
187a6f8720SBrian Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
197a6f8720SBrian Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
207a6f8720SBrian Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
217a6f8720SBrian Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
227a6f8720SBrian Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
237a6f8720SBrian Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
247a6f8720SBrian Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
257a6f8720SBrian Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
267a6f8720SBrian Somers  * SUCH DAMAGE.
277a6f8720SBrian Somers  */
287a6f8720SBrian Somers 
29455aabc3SBrian Somers #define	PHASE_DEAD		0	/* Link is dead */
30455aabc3SBrian Somers #define	PHASE_ESTABLISH		1	/* Establishing link */
31455aabc3SBrian Somers #define	PHASE_AUTHENTICATE	2	/* Being authenticated */
32455aabc3SBrian Somers #define	PHASE_NETWORK		3	/* We're alive ! */
33455aabc3SBrian Somers #define	PHASE_TERMINATE		4	/* Terminating link */
34455aabc3SBrian Somers 
351342caedSBrian Somers /* cfg.opt bit settings */
360508c09aSBrian Somers #define OPT_FILTERDECAP		1
370508c09aSBrian Somers #define OPT_FORCE_SCRIPTS	2 /* force chat scripts */
380508c09aSBrian Somers #define OPT_IDCHECK		3
390508c09aSBrian Somers #define OPT_IFACEALIAS		4
4030949fd4SBrian Somers #ifndef NOINET6
410508c09aSBrian Somers #define OPT_IPCP		5
420508c09aSBrian Somers #define OPT_IPV6CP		6
4330949fd4SBrian Somers #endif
440508c09aSBrian Somers #define OPT_KEEPSESSION		7
450508c09aSBrian Somers #define OPT_LOOPBACK		8
460508c09aSBrian Somers #define OPT_NAS_IP_ADDRESS	9
470508c09aSBrian Somers #define OPT_NAS_IDENTIFIER	10
480508c09aSBrian Somers #define OPT_PASSWDAUTH		11
490508c09aSBrian Somers #define OPT_PROXY		12
500508c09aSBrian Somers #define OPT_PROXYALL		13
510508c09aSBrian Somers #define OPT_SROUTES		14
520508c09aSBrian Somers #define OPT_TCPMSSFIXUP		15
530508c09aSBrian Somers #define OPT_THROUGHPUT		16
540508c09aSBrian Somers #define OPT_UTMP		17
550508c09aSBrian Somers #define OPT_MAX			17
561342caedSBrian Somers 
5749052c95SBrian Somers #define MAX_ENDDISC_CLASS 5
5849052c95SBrian Somers 
590508c09aSBrian Somers #define Enabled(b, o)		((b)->cfg.optmask & (1ull << (o)))
600508c09aSBrian Somers #define opt_enable(b, o)	((b)->cfg.optmask |= (1ull << (o)))
610508c09aSBrian Somers #define opt_disable(b, o)	((b)->cfg.optmask &= ~(1ull << (o)))
625ca5389aSBrian Somers 
63ab2de065SBrian Somers /* AutoAdjust() values */
64ab2de065SBrian Somers #define AUTO_UP		1
65ab2de065SBrian Somers #define AUTO_DOWN	2
66ab2de065SBrian Somers 
6796c9bb21SBrian Somers struct sockaddr_un;
683006ec67SBrian Somers struct datalink;
692289f246SBrian Somers struct physical;
7083d1af55SBrian Somers struct link;
71b6217683SBrian Somers struct server;
72b6217683SBrian Somers struct prompt;
738fa6ebe4SBrian Somers struct iface;
742289f246SBrian Somers 
757a6f8720SBrian Somers struct bundle {
76f013f33eSBrian Somers   struct fdescriptor desc;    /* really all our datalinks */
77faefde08SBrian Somers   int unit;                   /* The device/interface unit number */
78faefde08SBrian Somers 
79faefde08SBrian Somers   struct {
80faefde08SBrian Somers     char Name[20];            /* The /dev/XXXX name */
818e7bd08eSBrian Somers     int fd;                   /* The /dev/XXXX descriptor */
823a7b6d76SBrian Somers     unsigned header : 1;      /* Family header sent & received ? */
83faefde08SBrian Somers   } dev;
84faefde08SBrian Somers 
85ab2de065SBrian Somers   u_long bandwidth;           /* struct tuninfo speed */
868fa6ebe4SBrian Somers   struct iface *iface;        /* Interface information */
87faefde08SBrian Somers 
8826fe3a55SBrian Somers   int routing_seq;            /* The current routing sequence number */
89455aabc3SBrian Somers   u_int phase;                /* Curent phase */
90ff0f9439SBrian Somers 
91ff0f9439SBrian Somers   struct {
92ff0f9439SBrian Somers     int all;                  /* Union of all physical::type's */
93ff0f9439SBrian Somers     int open;                 /* Union of all open physical::type's */
94ff0f9439SBrian Somers   } phys_type;
957a6f8720SBrian Somers 
96a0cbd833SBrian Somers   unsigned CleaningUp : 1;    /* Going to exit.... */
9767b072f7SBrian Somers   unsigned NatEnabled : 1;    /* Are we using libalias ? */
98a0cbd833SBrian Somers 
996d666775SBrian Somers   struct fsm_parent fsm;      /* Our callback functions */
1003006ec67SBrian Somers   struct datalink *links;     /* Our data links */
101ab886ad0SBrian Somers 
102dade2407SBrian Somers   time_t upat;                /* When the link came up */
103dade2407SBrian Somers 
104ab886ad0SBrian Somers   struct {
105dade2407SBrian Somers     struct {
106057f1760SBrian Somers       unsigned timeout;          /* NCP Idle timeout value */
107057f1760SBrian Somers       unsigned min_timeout;      /* Don't idle out before this */
108dade2407SBrian Somers     } idle;
10992f4ff1cSBrian Somers     struct {
110972a1bcfSBrian Somers       char name[AUTHLEN];        /* PAP/CHAP system name */
111972a1bcfSBrian Somers       char key[AUTHLEN];         /* PAP/CHAP key */
11292f4ff1cSBrian Somers     } auth;
1130508c09aSBrian Somers     unsigned long long optmask;  /* Uses OPT_ bits from above */
11449052c95SBrian Somers     char label[50];              /* last thing `load'ed */
1156c1d6731SBrian Somers     u_short ifqueue;             /* Interface queue size */
11604eaa58cSBrian Somers 
1176f8e9f0aSBrian Somers     struct {
118057f1760SBrian Somers       unsigned timeout;          /* How long to leave the output queue choked */
1196f8e9f0aSBrian Somers     } choked;
120ab886ad0SBrian Somers   } cfg;
121ab886ad0SBrian Somers 
12230949fd4SBrian Somers   struct ncp ncp;
1235828db6dSBrian Somers 
1245ca5389aSBrian Somers   struct {
1255ca5389aSBrian Somers     struct filter in;         /* incoming packet filter */
1265ca5389aSBrian Somers     struct filter out;        /* outgoing packet filter */
1275ca5389aSBrian Somers     struct filter dial;       /* dial-out packet filter */
1285ca5389aSBrian Somers     struct filter alive;      /* keep-alive packet filter */
1295ca5389aSBrian Somers   } filter;
1305ca5389aSBrian Somers 
13193ee0ff2SBrian Somers   struct {
13293ee0ff2SBrian Somers     struct pppTimer timer;    /* timeout after cfg.idle_timeout */
13393ee0ff2SBrian Somers     time_t done;
13493ee0ff2SBrian Somers   } idle;
1355cf4388bSBrian Somers 
136bf1eaec5SBrian Somers #ifndef NORADIUS
137bf1eaec5SBrian Somers   struct {
138bf1eaec5SBrian Somers     struct pppTimer timer;
139bf1eaec5SBrian Somers     time_t done;
140bf1eaec5SBrian Somers   } session;
141bf1eaec5SBrian Somers #endif
142bf1eaec5SBrian Somers 
1435cf4388bSBrian Somers   struct {
1445cf4388bSBrian Somers     int fd;                   /* write status here */
1455cf4388bSBrian Somers   } notify;
14604eaa58cSBrian Somers 
14704eaa58cSBrian Somers   struct {
1486f8e9f0aSBrian Somers     struct pppTimer timer;    /* choked output queue timer */
1496f8e9f0aSBrian Somers   } choked;
150972a1bcfSBrian Somers 
151972a1bcfSBrian Somers #ifndef NORADIUS
152972a1bcfSBrian Somers   struct radius radius;       /* Info retrieved from radius server */
153794c9bbcSBrian Somers   struct radacct radacct;
154cf7c10d0SHajimu UMEMOTO #ifndef NOINET6
155cf7c10d0SHajimu UMEMOTO   struct radacct radacct6;
156cf7c10d0SHajimu UMEMOTO #endif
157972a1bcfSBrian Somers #endif
1587a6f8720SBrian Somers };
1597a6f8720SBrian Somers 
1602f786681SBrian Somers #define descriptor2bundle(d) \
1612f786681SBrian Somers   ((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
1622f786681SBrian Somers 
163cf0a3940SBrian Somers extern struct bundle *bundle_Create(const char *, int, int);
16468a0f0ccSBrian Somers extern void bundle_Destroy(struct bundle *);
165455aabc3SBrian Somers extern const char *bundle_PhaseName(struct bundle *);
166455aabc3SBrian Somers #define bundle_Phase(b) ((b)->phase)
1675563ebdeSBrian Somers extern void bundle_NewPhase(struct bundle *, u_int);
16892b09558SBrian Somers extern void bundle_LinksRemoved(struct bundle *);
1693006ec67SBrian Somers extern void bundle_Close(struct bundle *, const char *, int);
170899011c4SBrian Somers extern void bundle_Down(struct bundle *, int);
171ba23f397SBrian Somers extern void bundle_Open(struct bundle *, const char *, int, int);
1723006ec67SBrian Somers extern void bundle_LinkClosed(struct bundle *, struct datalink *);
1733006ec67SBrian Somers 
174aef795ccSBrian Somers extern int bundle_ShowLinks(struct cmdargs const *);
175c08717dfSBrian Somers extern int bundle_ShowStatus(struct cmdargs const *);
1760a4b6c5cSBrian Somers extern void bundle_StartIdleTimer(struct bundle *, unsigned secs);
177057f1760SBrian Somers extern void bundle_SetIdleTimer(struct bundle *, unsigned, unsigned);
178ab886ad0SBrian Somers extern void bundle_StopIdleTimer(struct bundle *);
1793b0f8d2eSBrian Somers extern int bundle_IsDead(struct bundle *);
180503a7782SBrian Somers extern struct datalink *bundle2datalink(struct bundle *, const char *);
181b6217683SBrian Somers 
182bf1eaec5SBrian Somers #ifndef NORADIUS
183bf1eaec5SBrian Somers extern void bundle_StartSessionTimer(struct bundle *, unsigned secs);
184bf1eaec5SBrian Somers extern void bundle_StopSessionTimer(struct bundle *);
185bf1eaec5SBrian Somers #endif
186bf1eaec5SBrian Somers 
187f013f33eSBrian Somers extern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
188f013f33eSBrian Somers extern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
189b6217683SBrian Somers 
190b6217683SBrian Somers extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
191cd7bd93aSBrian Somers 
192e8607d38SBrian Somers extern int bundle_DatalinkClone(struct bundle *, struct datalink *,
193cd7bd93aSBrian Somers                                 const char *);
194cd7bd93aSBrian Somers extern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
195565e35e5SBrian Somers extern void bundle_CleanDatalinks(struct bundle *);
19649052c95SBrian Somers extern void bundle_SetLabel(struct bundle *, const char *);
19749052c95SBrian Somers extern const char *bundle_GetLabel(struct bundle *);
19896c9bb21SBrian Somers extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
1992cb305afSBrian Somers extern int bundle_LinkSize(void);
2002cb305afSBrian Somers extern void bundle_ReceiveDatalink(struct bundle *, int);
201dd0645c5SBrian Somers extern int bundle_SetMode(struct bundle *, struct datalink *, int);
20258d55334SBrian Somers extern int bundle_RenameDatalink(struct bundle *, struct datalink *,
20358d55334SBrian Somers                                  const char *);
2041384bd27SBrian Somers extern void bundle_setsid(struct bundle *, int);
205da66dd13SBrian Somers extern void bundle_LockTun(struct bundle *);
206057f1760SBrian Somers extern unsigned bundle_HighestState(struct bundle *);
207991c2a7bSBrian Somers extern int bundle_Exception(struct bundle *, int);
20830949fd4SBrian Somers extern void bundle_AdjustFilters(struct bundle *, struct ncpaddr *,
20930949fd4SBrian Somers                                  struct ncpaddr *);
21030949fd4SBrian Somers extern void bundle_AdjustDNS(struct bundle *);
211ab2de065SBrian Somers extern void bundle_CalculateBandwidth(struct bundle *);
212ab2de065SBrian Somers extern void bundle_AutoAdjust(struct bundle *, int, int);
213ab2de065SBrian Somers extern int bundle_WantAutoloadTimer(struct bundle *);
21406b47306SBrian Somers extern void bundle_ChangedPID(struct bundle *);
215b42135deSBrian Somers extern void bundle_Notify(struct bundle *, char);
21646df5aa7SBrian Somers extern int bundle_Uptime(struct bundle *);
217