1998-02-02 19:32:16 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1998-02-02 19:32:16 +00:00
|
|
|
*/
|
|
|
|
|
1998-02-07 20:50:08 +00:00
|
|
|
#define PHASE_DEAD 0 /* Link is dead */
|
|
|
|
#define PHASE_ESTABLISH 1 /* Establishing link */
|
|
|
|
#define PHASE_AUTHENTICATE 2 /* Being authenticated */
|
|
|
|
#define PHASE_NETWORK 3 /* We're alive ! */
|
|
|
|
#define PHASE_TERMINATE 4 /* Terminating link */
|
|
|
|
|
1998-04-16 00:26:21 +00:00
|
|
|
/* cfg.opt bit settings */
|
2004-11-29 17:11:15 +00:00
|
|
|
#define OPT_FILTERDECAP 1
|
|
|
|
#define OPT_FORCE_SCRIPTS 2 /* force chat scripts */
|
|
|
|
#define OPT_IDCHECK 3
|
|
|
|
#define OPT_IFACEALIAS 4
|
2001-08-14 16:05:52 +00:00
|
|
|
#ifndef NOINET6
|
2004-11-29 17:11:15 +00:00
|
|
|
#define OPT_IPCP 5
|
|
|
|
#define OPT_IPV6CP 6
|
2001-08-14 16:05:52 +00:00
|
|
|
#endif
|
2004-11-29 17:11:15 +00:00
|
|
|
#define OPT_KEEPSESSION 7
|
|
|
|
#define OPT_LOOPBACK 8
|
|
|
|
#define OPT_NAS_IP_ADDRESS 9
|
|
|
|
#define OPT_NAS_IDENTIFIER 10
|
|
|
|
#define OPT_PASSWDAUTH 11
|
|
|
|
#define OPT_PROXY 12
|
|
|
|
#define OPT_PROXYALL 13
|
|
|
|
#define OPT_SROUTES 14
|
|
|
|
#define OPT_TCPMSSFIXUP 15
|
|
|
|
#define OPT_THROUGHPUT 16
|
|
|
|
#define OPT_UTMP 17
|
|
|
|
#define OPT_MAX 17
|
1998-04-16 00:26:21 +00:00
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
#define MAX_ENDDISC_CLASS 5
|
|
|
|
|
2004-11-29 17:11:15 +00:00
|
|
|
#define Enabled(b, o) ((b)->cfg.optmask & (1ull << (o)))
|
|
|
|
#define opt_enable(b, o) ((b)->cfg.optmask |= (1ull << (o)))
|
|
|
|
#define opt_disable(b, o) ((b)->cfg.optmask &= ~(1ull << (o)))
|
1998-03-16 22:52:54 +00:00
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
/* AutoAdjust() values */
|
|
|
|
#define AUTO_UP 1
|
|
|
|
#define AUTO_DOWN 2
|
|
|
|
|
1998-05-02 21:57:50 +00:00
|
|
|
struct sockaddr_un;
|
1998-02-16 00:01:12 +00:00
|
|
|
struct datalink;
|
1998-02-06 02:23:48 +00:00
|
|
|
struct physical;
|
1998-02-06 02:24:29 +00:00
|
|
|
struct link;
|
1998-04-03 19:26:02 +00:00
|
|
|
struct server;
|
|
|
|
struct prompt;
|
1998-10-22 02:32:50 +00:00
|
|
|
struct iface;
|
1998-02-06 02:23:48 +00:00
|
|
|
|
1998-02-02 19:32:16 +00:00
|
|
|
struct bundle {
|
2000-03-14 01:47:11 +00:00
|
|
|
struct fdescriptor desc; /* really all our datalinks */
|
1998-05-06 23:50:25 +00:00
|
|
|
int unit; /* The device/interface unit number */
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char Name[20]; /* The /dev/XXXX name */
|
2000-03-14 01:47:07 +00:00
|
|
|
int fd; /* The /dev/XXXX descriptor */
|
2000-01-23 01:48:19 +00:00
|
|
|
unsigned header : 1; /* Family header sent & received ? */
|
1998-05-06 23:50:25 +00:00
|
|
|
} dev;
|
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
u_long bandwidth; /* struct tuninfo speed */
|
1998-10-22 02:32:50 +00:00
|
|
|
struct iface *iface; /* Interface information */
|
1998-05-06 23:50:25 +00:00
|
|
|
|
1998-02-04 01:03:19 +00:00
|
|
|
int routing_seq; /* The current routing sequence number */
|
1998-02-07 20:50:08 +00:00
|
|
|
u_int phase; /* Curent phase */
|
1998-06-12 17:45:10 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int all; /* Union of all physical::type's */
|
|
|
|
int open; /* Union of all open physical::type's */
|
|
|
|
} phys_type;
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1998-03-16 22:53:15 +00:00
|
|
|
unsigned CleaningUp : 1; /* Going to exit.... */
|
1999-08-19 18:15:52 +00:00
|
|
|
unsigned NatEnabled : 1; /* Are we using libalias ? */
|
1998-03-16 22:53:15 +00:00
|
|
|
|
1998-02-27 01:22:39 +00:00
|
|
|
struct fsm_parent fsm; /* Our callback functions */
|
1998-02-16 00:01:12 +00:00
|
|
|
struct datalink *links; /* Our data links */
|
1998-03-09 19:26:41 +00:00
|
|
|
|
1999-08-17 17:22:46 +00:00
|
|
|
time_t upat; /* When the link came up */
|
|
|
|
|
1998-03-09 19:26:41 +00:00
|
|
|
struct {
|
1999-08-17 17:22:46 +00:00
|
|
|
struct {
|
2004-11-29 17:11:15 +00:00
|
|
|
unsigned timeout; /* NCP Idle timeout value */
|
|
|
|
unsigned min_timeout; /* Don't idle out before this */
|
1999-08-17 17:22:46 +00:00
|
|
|
} idle;
|
1998-04-03 19:24:49 +00:00
|
|
|
struct {
|
2004-11-29 17:11:15 +00:00
|
|
|
char name[AUTHLEN]; /* PAP/CHAP system name */
|
|
|
|
char key[AUTHLEN]; /* PAP/CHAP key */
|
1998-04-03 19:24:49 +00:00
|
|
|
} auth;
|
2004-11-29 17:11:15 +00:00
|
|
|
unsigned long long optmask; /* Uses OPT_ bits from above */
|
|
|
|
char label[50]; /* last thing `load'ed */
|
|
|
|
u_short ifqueue; /* Interface queue size */
|
1998-05-21 01:13:32 +00:00
|
|
|
|
1998-08-25 17:48:43 +00:00
|
|
|
struct {
|
2004-11-29 17:11:15 +00:00
|
|
|
unsigned timeout; /* How long to leave the output queue choked */
|
1998-08-25 17:48:43 +00:00
|
|
|
} choked;
|
1998-03-09 19:26:41 +00:00
|
|
|
} cfg;
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
struct ncp ncp;
|
1998-03-13 21:07:46 +00:00
|
|
|
|
1998-03-16 22:52:54 +00:00
|
|
|
struct {
|
1999-01-28 01:56:34 +00:00
|
|
|
struct filter in; /* incoming packet filter */
|
|
|
|
struct filter out; /* outgoing packet filter */
|
|
|
|
struct filter dial; /* dial-out packet filter */
|
|
|
|
struct filter alive; /* keep-alive packet filter */
|
1998-03-16 22:52:54 +00:00
|
|
|
} filter;
|
|
|
|
|
1998-03-18 23:15:31 +00:00
|
|
|
struct {
|
1999-01-28 01:56:34 +00:00
|
|
|
struct pppTimer timer; /* timeout after cfg.idle_timeout */
|
1998-03-18 23:15:31 +00:00
|
|
|
time_t done;
|
|
|
|
} idle;
|
1998-03-25 18:38:59 +00:00
|
|
|
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
struct {
|
|
|
|
struct pppTimer timer;
|
|
|
|
time_t done;
|
|
|
|
} session;
|
|
|
|
#endif
|
|
|
|
|
1998-03-25 18:38:59 +00:00
|
|
|
struct {
|
1999-01-28 01:56:34 +00:00
|
|
|
int fd; /* write status here */
|
1998-03-25 18:38:59 +00:00
|
|
|
} notify;
|
1998-05-21 01:13:32 +00:00
|
|
|
|
1998-08-25 17:48:43 +00:00
|
|
|
struct {
|
1999-01-28 01:56:34 +00:00
|
|
|
struct pppTimer timer; /* choked output queue timer */
|
1998-08-25 17:48:43 +00:00
|
|
|
} choked;
|
1999-01-28 01:56:34 +00:00
|
|
|
|
|
|
|
#ifndef NORADIUS
|
|
|
|
struct radius radius; /* Info retrieved from radius server */
|
2000-08-28 22:44:54 +00:00
|
|
|
struct radacct radacct;
|
2003-06-19 18:55:49 +00:00
|
|
|
#ifndef NOINET6
|
|
|
|
struct radacct radacct6;
|
|
|
|
#endif
|
1999-01-28 01:56:34 +00:00
|
|
|
#endif
|
1998-02-02 19:32:16 +00:00
|
|
|
};
|
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
#define descriptor2bundle(d) \
|
|
|
|
((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
|
|
|
|
|
1999-11-17 21:12:35 +00:00
|
|
|
extern struct bundle *bundle_Create(const char *, int, int);
|
1998-02-08 19:29:45 +00:00
|
|
|
extern void bundle_Destroy(struct bundle *);
|
1998-02-07 20:50:08 +00:00
|
|
|
extern const char *bundle_PhaseName(struct bundle *);
|
|
|
|
#define bundle_Phase(b) ((b)->phase)
|
1998-03-13 00:44:33 +00:00
|
|
|
extern void bundle_NewPhase(struct bundle *, u_int);
|
1998-08-07 18:42:51 +00:00
|
|
|
extern void bundle_LinksRemoved(struct bundle *);
|
1998-02-16 00:01:12 +00:00
|
|
|
extern void bundle_Close(struct bundle *, const char *, int);
|
1998-06-16 19:40:28 +00:00
|
|
|
extern void bundle_Down(struct bundle *, int);
|
1998-07-29 18:21:17 +00:00
|
|
|
extern void bundle_Open(struct bundle *, const char *, int, int);
|
1998-02-16 00:01:12 +00:00
|
|
|
extern void bundle_LinkClosed(struct bundle *, struct datalink *);
|
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
extern int bundle_ShowLinks(struct cmdargs const *);
|
1998-04-11 21:50:47 +00:00
|
|
|
extern int bundle_ShowStatus(struct cmdargs const *);
|
2000-07-11 22:11:36 +00:00
|
|
|
extern void bundle_StartIdleTimer(struct bundle *, unsigned secs);
|
2004-09-05 01:46:52 +00:00
|
|
|
extern void bundle_SetIdleTimer(struct bundle *, unsigned, unsigned);
|
1998-03-09 19:26:41 +00:00
|
|
|
extern void bundle_StopIdleTimer(struct bundle *);
|
1998-04-03 19:21:56 +00:00
|
|
|
extern int bundle_IsDead(struct bundle *);
|
1998-02-21 01:45:26 +00:00
|
|
|
extern struct datalink *bundle2datalink(struct bundle *, const char *);
|
1998-04-03 19:26:02 +00:00
|
|
|
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
extern void bundle_StartSessionTimer(struct bundle *, unsigned secs);
|
|
|
|
extern void bundle_StopSessionTimer(struct bundle *);
|
|
|
|
#endif
|
|
|
|
|
2000-03-14 01:46:09 +00:00
|
|
|
extern void bundle_RegisterDescriptor(struct bundle *, struct fdescriptor *);
|
|
|
|
extern void bundle_UnRegisterDescriptor(struct bundle *, struct fdescriptor *);
|
1998-04-03 19:26:02 +00:00
|
|
|
|
|
|
|
extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
|
1998-04-05 22:48:25 +00:00
|
|
|
|
1998-05-10 10:21:11 +00:00
|
|
|
extern int bundle_DatalinkClone(struct bundle *, struct datalink *,
|
|
|
|
const char *);
|
1998-04-05 22:48:25 +00:00
|
|
|
extern void bundle_DatalinkRemove(struct bundle *, struct datalink *);
|
1998-04-10 13:19:23 +00:00
|
|
|
extern void bundle_CleanDatalinks(struct bundle *);
|
1998-04-23 03:23:03 +00:00
|
|
|
extern void bundle_SetLabel(struct bundle *, const char *);
|
|
|
|
extern const char *bundle_GetLabel(struct bundle *);
|
1998-05-02 21:57:50 +00:00
|
|
|
extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
|
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
1999-11-25 02:47:04 +00:00
|
|
|
extern int bundle_LinkSize(void);
|
|
|
|
extern void bundle_ReceiveDatalink(struct bundle *, int);
|
1998-05-15 23:58:30 +00:00
|
|
|
extern int bundle_SetMode(struct bundle *, struct datalink *, int);
|
1998-05-16 23:47:28 +00:00
|
|
|
extern int bundle_RenameDatalink(struct bundle *, struct datalink *,
|
|
|
|
const char *);
|
1998-05-28 23:17:51 +00:00
|
|
|
extern void bundle_setsid(struct bundle *, int);
|
1998-06-06 20:50:57 +00:00
|
|
|
extern void bundle_LockTun(struct bundle *);
|
2004-09-05 01:46:52 +00:00
|
|
|
extern unsigned bundle_HighestState(struct bundle *);
|
1998-12-10 18:36:30 +00:00
|
|
|
extern int bundle_Exception(struct bundle *, int);
|
2001-08-14 16:05:52 +00:00
|
|
|
extern void bundle_AdjustFilters(struct bundle *, struct ncpaddr *,
|
|
|
|
struct ncpaddr *);
|
|
|
|
extern void bundle_AdjustDNS(struct bundle *);
|
1999-08-05 10:32:16 +00:00
|
|
|
extern void bundle_CalculateBandwidth(struct bundle *);
|
|
|
|
extern void bundle_AutoAdjust(struct bundle *, int, int);
|
|
|
|
extern int bundle_WantAutoloadTimer(struct bundle *);
|
2000-01-21 00:33:27 +00:00
|
|
|
extern void bundle_ChangedPID(struct bundle *);
|
2000-04-07 23:46:14 +00:00
|
|
|
extern void bundle_Notify(struct bundle *, char);
|
2001-11-03 21:45:32 +00:00
|
|
|
extern int bundle_Uptime(struct bundle *);
|