Make struct bundle into a sort of `struct descriptor'.

It does the fdsets/reads/writes for each of it's
datalinks.
This commit is contained in:
Brian Somers 1998-03-20 19:48:28 +00:00
parent 62043f48c6
commit 2f7866811e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=34722
21 changed files with 108 additions and 61 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: arp.c,v 1.27.2.7 1998/03/16 22:51:37 brian Exp $
* $Id: arp.c,v 1.27.2.8 1998/03/16 22:53:25 brian Exp $
*
*/
@ -61,6 +61,7 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "arp.h"

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.29 1998/03/18 23:15:29 brian Exp $
* $Id: bundle.c,v 1.1.2.30 1998/03/19 22:25:44 brian Exp $
*/
#include <sys/param.h>
@ -60,6 +60,7 @@
#include "ipcp.h"
#include "link.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "loadalias.h"
#include "vars.h"
@ -69,7 +70,6 @@
#include "lcp.h"
#include "ccp.h"
#include "async.h"
#include "descriptor.h"
#include "physical.h"
#include "modem.h"
#include "main.h"
@ -296,9 +296,55 @@ bundle_Close(struct bundle *bundle, const char *name, int staydown)
}
}
/*
* Open tunnel device and returns its descriptor
*/
static int
bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
{
struct bundle *bundle = descriptor2bundle(d);
struct datalink *dl;
int result;
result = 0;
for (dl = bundle->links; dl; dl = dl->next)
result += descriptor_UpdateSet(&dl->desc, r, w, e, n);
return result;
}
static int
bundle_IsSet(struct descriptor *d, const fd_set *fdset)
{
struct bundle *bundle = descriptor2bundle(d);
struct datalink *dl;
for (dl = bundle->links; dl; dl = dl->next)
if (descriptor_IsSet(&dl->desc, fdset))
return 1;
return 0;
}
static void
bundle_DescriptorRead(struct descriptor *d, struct bundle *bundle,
const fd_set *fdset)
{
struct datalink *dl;
for (dl = bundle->links; dl; dl = dl->next)
if (descriptor_IsSet(&dl->desc, fdset))
descriptor_Read(&dl->desc, bundle, fdset);
}
static void
bundle_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
const fd_set *fdset)
{
struct datalink *dl;
for (dl = bundle->links; dl; dl = dl->next)
if (descriptor_IsSet(&dl->desc, fdset))
descriptor_Write(&dl->desc, bundle, fdset);
}
#define MAX_TUN 256
/*
@ -413,6 +459,13 @@ bundle_Create(const char *prefix)
return NULL;
}
bundle.desc.type = BUNDLE_DESCRIPTOR;
bundle.desc.next = NULL;
bundle.desc.UpdateSet = bundle_UpdateSet;
bundle.desc.IsSet = bundle_IsSet;
bundle.desc.Read = bundle_DescriptorRead;
bundle.desc.Write = bundle_DescriptorWrite;
ipcp_Init(&bundle.ncp.ipcp, &bundle, &bundle.links->physical->link,
&bundle.fsm);
@ -729,19 +782,6 @@ bundle2link(struct bundle *bundle, const char *name)
return physical ? &physical->link : NULL;
}
int
bundle_UpdateSet(struct bundle *bundle, fd_set *r, fd_set *w, fd_set *e, int *n)
{
struct datalink *dl;
int result;
result = 0;
for (dl = bundle->links; dl; dl = dl->next)
result += descriptor_UpdateSet(&dl->desc, r, w, e, n);
return result;
}
int
bundle_FillQueues(struct bundle *bundle)
{

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.18 1998/03/16 22:53:06 brian Exp $
* $Id: bundle.h,v 1.1.2.19 1998/03/18 23:15:31 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -38,6 +38,7 @@ struct physical;
struct link;
struct bundle {
struct descriptor desc; /* really all our datalinks */
int unit; /* The tun number */
int ifIndex; /* The interface number */
int tun_fd; /* The /dev/tunX descriptor */
@ -72,6 +73,9 @@ struct bundle {
} idle;
};
#define descriptor2bundle(d) \
((d)->type == BUNDLE_DESCRIPTOR ? (struct bundle *)(d) : NULL)
extern struct bundle *bundle_Create(const char *);
extern void bundle_Destroy(struct bundle *);
extern const char *bundle_PhaseName(struct bundle *);
@ -85,8 +89,6 @@ extern void bundle_Close(struct bundle *, const char *, int);
extern void bundle_Open(struct bundle *, const char *name);
extern void bundle_LinkClosed(struct bundle *, struct datalink *);
extern int bundle_UpdateSet(struct bundle *, fd_set *, fd_set *, fd_set *,
int *);
extern int bundle_FillQueues(struct bundle *);
extern int bundle_ShowLinks(struct cmdargs const *);
extern void bundle_StartIdleTimer(struct bundle *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ccp.c,v 1.30.2.25 1998/03/18 23:16:05 brian Exp $
* $Id: ccp.c,v 1.30.2.26 1998/03/20 19:46:41 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -50,8 +50,8 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "bundle.h"
#include "descriptor.h"
#include "bundle.h"
#include "prompt.h"
#include "lqr.h"
#include "hdlc.h"

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: chat.c,v 1.44.2.15 1998/03/13 00:43:55 brian Exp $
* $Id: chat.c,v 1.44.2.16 1998/03/13 21:07:59 brian Exp $
*/
#include <sys/param.h>
@ -296,7 +296,7 @@ chat_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
}
static int
chat_IsSet(struct descriptor *d, fd_set *fdset)
chat_IsSet(struct descriptor *d, const fd_set *fdset)
{
struct chat *c = descriptor2chat(d);
return Physical_IsSet(&c->physical->desc, fdset);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.40 1998/03/16 22:53:38 brian Exp $
* $Id: command.c,v 1.131.2.41 1998/03/17 22:29:05 brian Exp $
*
*/
#include <sys/param.h>
@ -66,6 +66,7 @@
#include "vars.h"
#include "systems.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "main.h"
#include "route.h"
@ -74,7 +75,6 @@
#include "auth.h"
#include "async.h"
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "server.h"
#include "prompt.h"

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.25 1998/03/18 21:53:56 brian Exp $
* $Id: datalink.c,v 1.1.2.26 1998/03/18 21:54:03 brian Exp $
*/
#include <sys/param.h>
@ -278,7 +278,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
}
static int
datalink_IsSet(struct descriptor *d, fd_set *fdset)
datalink_IsSet(struct descriptor *d, const fd_set *fdset)
{
struct datalink *dl = descriptor2datalink(d);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: descriptor.h,v 1.1.2.6 1998/02/16 00:00:03 brian Exp $
* $Id: descriptor.h,v 1.1.2.7 1998/02/23 00:38:28 brian Exp $
*/
#define PHYSICAL_DESCRIPTOR (1)
@ -31,13 +31,14 @@
#define PROMPT_DESCRIPTOR (3)
#define CHAT_DESCRIPTOR (4)
#define DATALINK_DESCRIPTOR (5)
#define BUNDLE_DESCRIPTOR (6)
struct descriptor {
int type;
struct descriptor *next;
int (*UpdateSet)(struct descriptor *, fd_set *, fd_set *, fd_set *, int *);
int (*IsSet)(struct descriptor *, fd_set *);
int (*IsSet)(struct descriptor *, const fd_set *);
void (*Read)(struct descriptor *, struct bundle *, const fd_set *);
void (*Write)(struct descriptor *, struct bundle *, const fd_set *);
};

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ip.c,v 1.38.2.13 1998/03/16 22:52:17 brian Exp $
* $Id: ip.c,v 1.38.2.14 1998/03/16 22:53:51 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@ -62,6 +62,7 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "vjcomp.h"
#include "lcp.h"

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.c,v 1.50.2.24 1998/03/16 22:53:53 brian Exp $
* $Id: ipcp.c,v 1.50.2.25 1998/03/20 19:46:49 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -53,6 +53,7 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "loadalias.h"
#include "vars.h"
@ -63,7 +64,6 @@
#include "hdlc.h"
#include "async.h"
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "id.h"
#include "arp.h"

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.c,v 1.55.2.30 1998/03/16 22:54:02 brian Exp $
* $Id: lcp.c,v 1.55.2.31 1998/03/20 19:46:55 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -55,6 +55,7 @@
#include "ipcp.h"
#include "lcpproto.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "lqr.h"
#include "hdlc.h"
@ -70,7 +71,6 @@
#include "modem.h"
#include "tun.h"
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "prompt.h"
#include "chat.h"

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: link.c,v 1.1.2.12 1998/03/16 22:52:24 brian Exp $
* $Id: link.c,v 1.1.2.13 1998/03/16 22:54:05 brian Exp $
*
*/
@ -52,8 +52,8 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "bundle.h"
#include "descriptor.h"
#include "bundle.h"
#include "prompt.h"
void

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.34 1998/03/16 22:53:11 brian Exp $
* $Id: main.c,v 1.121.2.35 1998/03/16 22:54:10 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -63,6 +63,7 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "loadalias.h"
#include "vars.h"
@ -77,7 +78,6 @@
#include "tun.h"
#include "route.h"
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "server.h"
#include "prompt.h"
@ -521,7 +521,7 @@ DoLoop(struct bundle *bundle)
handle_signals();
bundle_UpdateSet(bundle, &rfds, &wfds, &efds, &nfds);
descriptor_UpdateSet(&bundle->desc, &rfds, &wfds, &efds, &nfds);
descriptor_UpdateSet(&server.desc, &rfds, &wfds, &efds, &nfds);
/* If there are aren't many packets queued, look for some more. */
@ -563,11 +563,11 @@ DoLoop(struct bundle *bundle)
if (descriptor_IsSet(&prompt.desc, &rfds))
descriptor_Read(&prompt.desc, bundle, &rfds);
/* XXX FIX ME ! */
if (descriptor_IsSet(&bundle2datalink(bundle, NULL)->desc, &wfds))
descriptor_Write(&bundle2datalink(bundle, NULL)->desc, bundle, &wfds);
if (descriptor_IsSet(&bundle2datalink(bundle, NULL)->desc, &rfds))
descriptor_Read(&bundle2datalink(bundle, NULL)->desc, bundle, &rfds);
if (descriptor_IsSet(&bundle->desc, &wfds))
descriptor_Write(&bundle->desc, bundle, &wfds);
if (descriptor_IsSet(&bundle->desc, &rfds))
descriptor_Read(&bundle->desc, bundle, &rfds);
if (bundle->tun_fd >= 0 && FD_ISSET(bundle->tun_fd, &rfds)) {
/* something to read from tun */

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.77.2.38 1998/03/18 21:53:48 brian Exp $
* $Id: modem.c,v 1.77.2.39 1998/03/20 19:47:19 brian Exp $
*
* TODO:
*/
@ -65,9 +65,9 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "prompt.h"
#include "chat.h"

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.c,v 1.1.2.17 1998/03/16 22:52:38 brian Exp $
* $Id: physical.c,v 1.1.2.18 1998/03/16 22:54:18 brian Exp $
*
*/
@ -221,7 +221,7 @@ Physical_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
}
int
Physical_IsSet(struct descriptor *d, fd_set *fdset)
Physical_IsSet(struct descriptor *d, const fd_set *fdset)
{
struct physical *p = descriptor2physical(d);

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.h,v 1.1.2.15 1998/03/13 00:44:51 brian Exp $
* $Id: physical.h,v 1.1.2.16 1998/03/20 19:47:22 brian Exp $
*
*/
@ -101,7 +101,7 @@ ssize_t Physical_Write(struct physical *phys, const void *buf, size_t nbytes);
int Physical_ReportProtocolStatus(struct cmdargs const *);
int Physical_UpdateSet(struct descriptor *, fd_set *, fd_set *, fd_set *,
int *, int);
int Physical_IsSet(struct descriptor *, fd_set *);
int Physical_IsSet(struct descriptor *, const fd_set *);
void Physical_DescriptorWrite(struct descriptor *, struct bundle *,
const fd_set *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: prompt.c,v 1.1.2.14 1998/03/16 22:53:15 brian Exp $
* $Id: prompt.c,v 1.1.2.15 1998/03/16 22:54:22 brian Exp $
*/
#include <sys/param.h>
@ -95,7 +95,7 @@ prompt_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
}
static int
prompt_IsSet(struct descriptor *d, fd_set *fdset)
prompt_IsSet(struct descriptor *d, const fd_set *fdset)
{
struct prompt *p = descriptor2prompt(d);
LogPrintf(LogDEBUG, "descriptor2prompt; %p -> %p\n", d, p);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: route.c,v 1.42.2.11 1998/03/16 22:52:50 brian Exp $
* $Id: route.c,v 1.42.2.12 1998/03/16 22:54:23 brian Exp $
*
*/
@ -60,9 +60,9 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "route.h"
#include "descriptor.h"
#include "prompt.h"
static void

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: server.c,v 1.16.2.7 1998/02/18 20:39:08 brian Exp $
* $Id: server.c,v 1.16.2.8 1998/02/23 00:38:42 brian Exp $
*/
#include <sys/param.h>
@ -69,7 +69,7 @@ server_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
}
static int
server_IsSet(struct descriptor *d, fd_set *fdset)
server_IsSet(struct descriptor *d, const fd_set *fdset)
{
struct server *s = descriptor2server(d);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: tun.c,v 1.6.4.7 1998/03/16 22:52:52 brian Exp $
* $Id: tun.c,v 1.6.4.8 1998/03/16 22:54:28 brian Exp $
*/
#include <sys/param.h>
@ -56,6 +56,7 @@
#include "slcompress.h"
#include "ipcp.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "tun.h"

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vjcomp.c,v 1.16.2.8 1998/03/16 22:52:54 brian Exp $
* $Id: vjcomp.c,v 1.16.2.9 1998/03/16 22:54:32 brian Exp $
*
* TODO:
*/
@ -46,6 +46,7 @@
#include "ccp.h"
#include "link.h"
#include "filter.h"
#include "descriptor.h"
#include "bundle.h"
#include "vjcomp.h"