136285Sbrian/*-
236285Sbrian * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
336285Sbrian * All rights reserved.
436285Sbrian *
536285Sbrian * Redistribution and use in source and binary forms, with or without
636285Sbrian * modification, are permitted provided that the following conditions
736285Sbrian * are met:
836285Sbrian * 1. Redistributions of source code must retain the above copyright
936285Sbrian *    notice, this list of conditions and the following disclaimer.
1036285Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1136285Sbrian *    notice, this list of conditions and the following disclaimer in the
1236285Sbrian *    documentation and/or other materials provided with the distribution.
1336285Sbrian *
1436285Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1536285Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1636285Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1736285Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1836285Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1936285Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2036285Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2136285Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2236285Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2336285Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2436285Sbrian * SUCH DAMAGE.
2536285Sbrian *
2650479Speter * $FreeBSD$
2736285Sbrian */
2836285Sbrian
2936285Sbrianstruct mbuf;
3036285Sbrianstruct physical;
3136285Sbrianstruct bundle;
3236285Sbrianstruct cmdargs;
3336285Sbrianstruct datalink;
3436285Sbrian
3536285Sbrian#define ENDDISC_NULL	0
3636285Sbrian#define ENDDISC_LOCAL	1
3736285Sbrian#define ENDDISC_IP	2
3836285Sbrian#define ENDDISC_MAC	3
3936285Sbrian#define ENDDISC_MAGIC	4
4036285Sbrian#define ENDDISC_PSN	5
4136285Sbrian
4236285Sbrian#define MP_LINKSENT	0	/* We attached the link to another ppp */
4336285Sbrian#define MP_UP		1	/* We've started MP */
4436285Sbrian#define MP_ADDED	2	/* We've added the link to our MP */
4536285Sbrian#define MP_FAILED	3	/* No go */
4636285Sbrian
4736285Sbrian#define MPSERVER_CONNECTED	0
4836285Sbrian#define MPSERVER_LISTENING	1
4936285Sbrian#define MPSERVER_FAILED		2
5036285Sbrian
5136285Sbrianstruct enddisc {
5236285Sbrian  u_char class;
5336285Sbrian  char address[50];
5436285Sbrian  int len;
5536285Sbrian};
5636285Sbrian
5736285Sbrianstruct peerid {
5836285Sbrian  struct enddisc enddisc;	/* Peers endpoint discriminator */
5956175Sbrian  char authname[AUTHLEN];	/* Peers name (authenticated) */
6036285Sbrian};
6136285Sbrian
6236285Sbrianstruct mpserver {
6358028Sbrian  struct fdescriptor desc;
6436285Sbrian  int fd;			/* listen()ing or connect()ing here */
6536285Sbrian  struct sockaddr_un socket;	/* On this socket */
6636285Sbrian
6736285Sbrian  struct {
6836285Sbrian    struct datalink *dl;	/* Send this datalink */
6936285Sbrian  } send;			/* (in UpdateSet()) */
7036285Sbrian};
7136285Sbrian
7236285Sbrianstruct mp {
7336285Sbrian  struct link link;
7436285Sbrian
7536285Sbrian  unsigned active : 1;
7636285Sbrian  unsigned peer_is12bit : 1;	/* 12/24bit seq nos */
7736285Sbrian  unsigned local_is12bit : 1;
7836285Sbrian  u_short peer_mrru;
7936285Sbrian  u_short local_mrru;
8036285Sbrian
8136285Sbrian  struct peerid peer;		/* Who are we talking to */
8236285Sbrian  struct mpserver server;	/* Our ``sharing'' socket */
8336285Sbrian
8436285Sbrian  struct {
8536285Sbrian    u_int32_t seq;		/* next outgoing seq */
8636285Sbrian    int link;			/* Next link to send on */
8781634Sbrian    int af;			/* Next address family to send */
8836285Sbrian  } out;
8936285Sbrian
9036285Sbrian  struct {
9136285Sbrian    u_int32_t min_in;		/* minimum received incoming seq */
9236285Sbrian    u_int32_t next_in;		/* next incoming seq to process */
9336285Sbrian  } seq;
9436285Sbrian
9536285Sbrian  struct {
9636285Sbrian    u_short mrru;		/* Max Reconstructed Receive Unit */
9736285Sbrian    unsigned shortseq : 2;	/* I want short Sequence Numbers */
9847858Sbrian    unsigned negenddisc : 2;	/* I want an endpoint discriminator */
9936285Sbrian    struct enddisc enddisc;	/* endpoint discriminator */
10049434Sbrian    struct {
10149434Sbrian      int min;			/* Lowest percent of bundle->bandwidth */
10249434Sbrian      int max;			/* Highest percent of bundle->bandwidth out */
10349434Sbrian      int period;		/* link->throughput sample period */
10449434Sbrian    } autoload;
10536285Sbrian  } cfg;
10636285Sbrian
10736285Sbrian  struct mbuf *inbufs;		/* Received fragments */
10836285Sbrian  struct fsm_parent fsmp;	/* Our callback functions */
10936285Sbrian  struct bundle *bundle;	/* Parent */
11036285Sbrian};
11136285Sbrian
11236285Sbrianstruct mp_link {
11336285Sbrian  u_int32_t seq;		/* 12 or 24 bit incoming seq */
11449434Sbrian  unsigned bandwidth;		/* Our link bandwidth (or zero) */
11536285Sbrian};
11636285Sbrian
11736285Sbrianstruct mp_header {
11836285Sbrian  unsigned begin : 1;
11936285Sbrian  unsigned end : 1;
12036285Sbrian  u_int32_t seq;
12136285Sbrian};
12236285Sbrian
12336285Sbrian#define descriptor2mpserver(d) \
12436285Sbrian  ((d)->type == MPSERVER_DESCRIPTOR ? (struct mpserver *)(d) : NULL)
12536285Sbrian#define mpserver_IsOpen(s) ((s)->fd != -1)
12636285Sbrian
12736285Sbrianextern void peerid_Init(struct peerid *);
12836285Sbrianextern int peerid_Equal(const struct peerid *, const struct peerid *);
12936285Sbrianextern void mpserver_Init(struct mpserver *);
13036285Sbrianextern int mpserver_Open(struct mpserver *, struct peerid *);
13136285Sbrianextern void mpserver_Close(struct mpserver *);
13236285Sbrianextern void mp_Init(struct mp *, struct bundle *);
13336285Sbrianextern void mp_linkInit(struct mp_link *);
13436285Sbrianextern int mp_Up(struct mp *, struct datalink *);
13536285Sbrianextern void mp_Down(struct mp *);
13646686Sbrianextern struct mbuf *mp_Input(struct bundle *, struct link *, struct mbuf *);
13781634Sbrianextern int mp_FillPhysicalQueues(struct bundle *);
13849434Sbrianextern int mp_SetDatalinkBandwidth(struct cmdargs const *);
13936285Sbrianextern int mp_ShowStatus(struct cmdargs const *);
140134789Sbrianextern const char *mp_Enddisc(u_char, const char *, size_t);
14136285Sbrianextern int mp_SetEnddisc(struct cmdargs const *);
14236312Sbrianextern void mp_LinkLost(struct mp *, struct datalink *);
14349434Sbrianextern void mp_RestartAutoloadTimer(struct mp *);
14449434Sbrianextern void mp_CheckAutoloadTimer(struct mp *);
14549434Sbrianextern void mp_StopAutoloadTimer(struct mp *);
14681634Sbrianextern size_t mp_QueueLen(struct mp *);
147