1998-01-29 00:49:32 +00:00
|
|
|
/*
|
|
|
|
* Written by Eivind Eklund <eivind@yes.no>
|
|
|
|
* for Yes Interactive
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998, Yes Interactive. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in any form is permitted. Redistribution in
|
|
|
|
* source form should include the above copyright and this set of
|
|
|
|
* conditions, because large sections american law seems to have been
|
|
|
|
* created by a bunch of jerks on drugs that are now illegal, forcing
|
|
|
|
* me to include this copyright-stuff instead of placing this in the
|
|
|
|
* public domain. The name of of 'Yes Interactive' or 'Eivind Eklund'
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1998-01-29 00:49:32 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
struct datalink;
|
1998-04-07 00:54:26 +00:00
|
|
|
struct bundle;
|
1999-05-08 11:07:56 +00:00
|
|
|
struct iovec;
|
|
|
|
struct physical;
|
|
|
|
struct bundle;
|
|
|
|
struct ccp;
|
|
|
|
struct cmdargs;
|
|
|
|
|
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
|
|
|
/* Device types (don't use zero, it'll be confused with NULL in physical2iov */
|
1999-08-06 20:04:08 +00:00
|
|
|
#define I4B_DEVICE 1
|
|
|
|
#define TTY_DEVICE 2
|
|
|
|
#define TCP_DEVICE 3
|
|
|
|
#define UDP_DEVICE 4
|
1999-11-06 22:50:59 +00:00
|
|
|
#define ETHER_DEVICE 5
|
|
|
|
#define EXEC_DEVICE 6
|
2000-09-14 22:02:54 +00:00
|
|
|
#define ATM_DEVICE 7
|
1999-08-06 20:04:08 +00:00
|
|
|
|
|
|
|
/* Returns from awaitcarrier() */
|
|
|
|
#define CARRIER_PENDING 1
|
|
|
|
#define CARRIER_OK 2
|
|
|
|
#define CARRIER_LOST 3
|
1999-05-08 11:07:56 +00:00
|
|
|
|
1999-09-26 23:02:18 +00:00
|
|
|
/* A cd ``necessity'' value */
|
1999-11-26 22:44:33 +00:00
|
|
|
#define CD_VARIABLE 0
|
|
|
|
#define CD_REQUIRED 1
|
|
|
|
#define CD_NOTREQUIRED 2
|
|
|
|
#define CD_DEFAULT 3
|
|
|
|
|
|
|
|
struct cd {
|
|
|
|
unsigned necessity : 2; /* A CD_ value */
|
|
|
|
int delay; /* Wait this many seconds after login script */
|
|
|
|
};
|
1999-09-26 23:02:18 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
struct device {
|
|
|
|
int type;
|
|
|
|
const char *name;
|
2001-06-18 14:59:36 +00:00
|
|
|
u_short mtu;
|
1999-11-26 22:44:33 +00:00
|
|
|
struct cd cd;
|
1999-05-12 09:49:12 +00:00
|
|
|
|
1999-08-06 20:04:08 +00:00
|
|
|
int (*awaitcarrier)(struct physical *);
|
1999-11-06 22:50:59 +00:00
|
|
|
int (*removefromset)(struct physical *, fd_set *, fd_set *, fd_set *);
|
1999-05-08 11:07:56 +00:00
|
|
|
int (*raw)(struct physical *);
|
|
|
|
void (*offline)(struct physical *);
|
|
|
|
void (*cooked)(struct physical *);
|
1999-05-12 09:49:12 +00:00
|
|
|
void (*stoptimer)(struct physical *);
|
|
|
|
void (*destroy)(struct physical *);
|
|
|
|
ssize_t (*read)(struct physical *, void *, size_t);
|
|
|
|
ssize_t (*write)(struct physical *, const void *, size_t);
|
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
|
|
|
void (*device2iov)(struct device *, struct iovec *, int *, int, int *, int *);
|
1999-05-08 11:07:56 +00:00
|
|
|
int (*speed)(struct physical *);
|
|
|
|
const char *(*openinfo)(struct physical *);
|
|
|
|
};
|
1998-04-07 00:54:26 +00:00
|
|
|
|
1998-01-29 00:49:32 +00:00
|
|
|
struct physical {
|
1998-01-30 19:46:07 +00:00
|
|
|
struct link link;
|
2000-03-14 01:46:09 +00:00
|
|
|
struct fdescriptor desc;
|
1998-05-01 19:26:12 +00:00
|
|
|
int type; /* What sort of PHYS_* link are we ? */
|
1998-02-02 19:33:40 +00:00
|
|
|
struct async async; /* Our async state */
|
1998-02-18 19:35:59 +00:00
|
|
|
struct hdlc hdlc; /* Our hdlc state */
|
2000-03-14 01:47:07 +00:00
|
|
|
int fd; /* File descriptor for this device */
|
1998-03-10 03:06:07 +00:00
|
|
|
struct mbuf *out; /* mbuf that suffered a short write */
|
1998-01-30 19:46:07 +00:00
|
|
|
int connect_count;
|
1998-03-13 00:44:51 +00:00
|
|
|
struct datalink *dl; /* my owner */
|
1998-01-29 00:49:32 +00:00
|
|
|
|
1999-04-03 11:54:00 +00:00
|
|
|
struct {
|
|
|
|
u_char buf[MAX_MRU]; /* Our input data buffer */
|
|
|
|
size_t sz;
|
|
|
|
} input;
|
|
|
|
|
1998-03-06 00:34:47 +00:00
|
|
|
struct {
|
1999-06-01 19:08:59 +00:00
|
|
|
char full[DEVICE_LEN]; /* Our current device name */
|
1998-03-06 00:34:47 +00:00
|
|
|
char *base;
|
|
|
|
} name;
|
|
|
|
|
1999-10-21 21:55:22 +00:00
|
|
|
time_t Utmp; /* Are we in utmp ? */
|
1998-05-29 18:33:10 +00:00
|
|
|
pid_t session_owner; /* HUP this when closing the link */
|
1998-03-10 03:06:07 +00:00
|
|
|
|
1999-05-12 09:49:12 +00:00
|
|
|
struct device *handler; /* device specific handler */
|
|
|
|
|
1998-02-17 19:29:03 +00:00
|
|
|
struct {
|
1999-05-08 11:07:56 +00:00
|
|
|
unsigned rts_cts : 1; /* Is rts/cts enabled ? */
|
|
|
|
unsigned parity; /* What parity is enabled? (tty flags) */
|
|
|
|
unsigned speed; /* tty speed */
|
|
|
|
|
1999-04-27 00:23:57 +00:00
|
|
|
char devlist[LINE_LEN]; /* NUL separated list of devices */
|
|
|
|
int ndev; /* number of devices in list */
|
1999-11-26 22:44:33 +00:00
|
|
|
struct cd cd;
|
1998-02-17 19:29:03 +00:00
|
|
|
} cfg;
|
1998-01-29 00:49:32 +00:00
|
|
|
};
|
|
|
|
|
1998-02-09 19:21:11 +00:00
|
|
|
#define field2phys(fp, name) \
|
|
|
|
((struct physical *)((char *)fp - (int)(&((struct physical *)0)->name)))
|
|
|
|
|
|
|
|
#define link2physical(l) \
|
|
|
|
((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL)
|
|
|
|
|
|
|
|
#define descriptor2physical(d) \
|
|
|
|
((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL)
|
1998-01-30 19:46:07 +00:00
|
|
|
|
1999-11-06 22:50:59 +00:00
|
|
|
#define PHYSICAL_NOFORCE 1
|
|
|
|
#define PHYSICAL_FORCE_ASYNC 2
|
|
|
|
#define PHYSICAL_FORCE_SYNC 3
|
|
|
|
#define PHYSICAL_FORCE_SYNCNOACF 4
|
1999-05-12 09:49:12 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
extern struct physical *physical_Create(struct datalink *, int);
|
|
|
|
extern int physical_Open(struct physical *, struct bundle *);
|
|
|
|
extern int physical_Raw(struct physical *);
|
|
|
|
extern int physical_GetSpeed(struct physical *);
|
1998-05-01 19:26:12 +00:00
|
|
|
extern int physical_SetSpeed(struct physical *, int);
|
1999-05-08 11:07:56 +00:00
|
|
|
extern int physical_SetParity(struct physical *, const char *);
|
|
|
|
extern int physical_SetRtsCts(struct physical *, int);
|
1998-05-01 19:26:12 +00:00
|
|
|
extern void physical_SetSync(struct physical *);
|
1999-05-08 11:07:56 +00:00
|
|
|
extern int physical_ShowStatus(struct cmdargs const *);
|
|
|
|
extern void physical_Offline(struct physical *);
|
|
|
|
extern void physical_Close(struct physical *);
|
|
|
|
extern void physical_Destroy(struct physical *);
|
|
|
|
extern struct physical *iov2physical(struct datalink *, struct iovec *, int *,
|
1999-11-06 22:50:59 +00:00
|
|
|
int, int, int *, int *);
|
|
|
|
extern int physical2iov(struct physical *, struct iovec *, int *, int, int *,
|
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
|
|
|
int *);
|
|
|
|
extern const char *physical_LockedDevice(struct physical *);
|
1999-05-08 11:07:56 +00:00
|
|
|
extern void physical_ChangedPid(struct physical *, pid_t);
|
1998-01-29 00:49:32 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
extern int physical_IsSync(struct physical *);
|
2001-06-18 14:59:36 +00:00
|
|
|
extern u_short physical_DeviceMTU(struct physical *);
|
1999-05-08 11:07:56 +00:00
|
|
|
extern const char *physical_GetDevice(struct physical *);
|
|
|
|
extern void physical_SetDeviceList(struct physical *, int, const char *const *);
|
|
|
|
extern void physical_SetDevice(struct physical *, const char *);
|
1998-05-01 19:26:12 +00:00
|
|
|
|
|
|
|
extern ssize_t physical_Read(struct physical *, void *, size_t);
|
|
|
|
extern ssize_t physical_Write(struct physical *, const void *, size_t);
|
2000-03-14 01:46:09 +00:00
|
|
|
extern int physical_doUpdateSet(struct fdescriptor *, fd_set *, fd_set *,
|
1999-05-08 11:07:56 +00:00
|
|
|
fd_set *, int *, int);
|
2000-03-14 01:46:09 +00:00
|
|
|
extern int physical_IsSet(struct fdescriptor *, const fd_set *);
|
|
|
|
extern void physical_DescriptorRead(struct fdescriptor *, struct bundle *,
|
1999-11-06 22:50:59 +00:00
|
|
|
const fd_set *);
|
1998-05-01 19:26:12 +00:00
|
|
|
extern void physical_Login(struct physical *, const char *);
|
1998-05-15 18:21:45 +00:00
|
|
|
extern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *,
|
|
|
|
fd_set *);
|
1998-05-15 23:58:30 +00:00
|
|
|
extern int physical_SetMode(struct physical *, int);
|
1998-08-25 17:48:43 +00:00
|
|
|
extern void physical_DeleteQueue(struct physical *);
|
1999-05-24 16:39:17 +00:00
|
|
|
extern void physical_SetupStack(struct physical *, const char *, int);
|
1999-05-12 09:49:12 +00:00
|
|
|
extern void physical_StopDeviceTimer(struct physical *);
|
1999-06-05 21:36:00 +00:00
|
|
|
extern int physical_MaxDeviceSize(void);
|
1999-08-06 20:04:08 +00:00
|
|
|
extern int physical_AwaitCarrier(struct physical *);
|
1999-11-06 22:50:59 +00:00
|
|
|
extern void physical_SetDescriptor(struct physical *);
|