xref: /freebsd/usr.sbin/ppp/mp.h (revision 7f3dea244c40159a41ab22da77a434d7c5b5e85a)
1 /*-
2  * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *	$Id: mp.h,v 1.6 1999/06/09 16:54:03 brian Exp $
27  */
28 
29 struct mbuf;
30 struct physical;
31 struct bundle;
32 struct cmdargs;
33 struct datalink;
34 
35 #define ENDDISC_NULL	0
36 #define ENDDISC_LOCAL	1
37 #define ENDDISC_IP	2
38 #define ENDDISC_MAC	3
39 #define ENDDISC_MAGIC	4
40 #define ENDDISC_PSN	5
41 
42 #define MP_LINKSENT	0	/* We attached the link to another ppp */
43 #define MP_UP		1	/* We've started MP */
44 #define MP_ADDED	2	/* We've added the link to our MP */
45 #define MP_FAILED	3	/* No go */
46 
47 #define MPSERVER_CONNECTED	0
48 #define MPSERVER_LISTENING	1
49 #define MPSERVER_FAILED		2
50 
51 struct enddisc {
52   u_char class;
53   char address[50];
54   int len;
55 };
56 
57 struct peerid {
58   struct enddisc enddisc;	/* Peers endpoint discriminator */
59   char authname[50];		/* Peers name (authenticated) */
60 };
61 
62 struct mpserver {
63   struct descriptor desc;
64   int fd;			/* listen()ing or connect()ing here */
65   struct sockaddr_un socket;	/* On this socket */
66 
67   struct {
68     struct datalink *dl;	/* Send this datalink */
69   } send;			/* (in UpdateSet()) */
70 };
71 
72 struct mp {
73   struct link link;
74 
75   unsigned active : 1;
76   unsigned peer_is12bit : 1;	/* 12/24bit seq nos */
77   unsigned local_is12bit : 1;
78   u_short peer_mrru;
79   u_short local_mrru;
80 
81   struct peerid peer;		/* Who are we talking to */
82   struct mpserver server;	/* Our ``sharing'' socket */
83 
84   struct {
85     u_int32_t seq;		/* next outgoing seq */
86     int link;			/* Next link to send on */
87   } out;
88 
89   struct {
90     u_int32_t min_in;		/* minimum received incoming seq */
91     u_int32_t next_in;		/* next incoming seq to process */
92   } seq;
93 
94   struct {
95     u_short mrru;		/* Max Reconstructed Receive Unit */
96     unsigned shortseq : 2;	/* I want short Sequence Numbers */
97     unsigned negenddisc : 2;	/* I want an endpoint discriminator */
98     struct enddisc enddisc;	/* endpoint discriminator */
99     struct {
100       int min;			/* Lowest percent of bundle->bandwidth */
101       int max;			/* Highest percent of bundle->bandwidth out */
102       int period;		/* link->throughput sample period */
103     } autoload;
104   } cfg;
105 
106   struct mbuf *inbufs;		/* Received fragments */
107   struct fsm_parent fsmp;	/* Our callback functions */
108   struct bundle *bundle;	/* Parent */
109 };
110 
111 struct mp_link {
112   u_int32_t seq;		/* 12 or 24 bit incoming seq */
113   unsigned bandwidth;		/* Our link bandwidth (or zero) */
114 };
115 
116 struct mp_header {
117   unsigned begin : 1;
118   unsigned end : 1;
119   u_int32_t seq;
120 };
121 
122 #define descriptor2mpserver(d) \
123   ((d)->type == MPSERVER_DESCRIPTOR ? (struct mpserver *)(d) : NULL)
124 #define mpserver_IsOpen(s) ((s)->fd != -1)
125 
126 extern void peerid_Init(struct peerid *);
127 extern int peerid_Equal(const struct peerid *, const struct peerid *);
128 extern void mpserver_Init(struct mpserver *);
129 extern int mpserver_Open(struct mpserver *, struct peerid *);
130 extern void mpserver_Close(struct mpserver *);
131 extern void mp_Init(struct mp *, struct bundle *);
132 extern void mp_linkInit(struct mp_link *);
133 extern int mp_Up(struct mp *, struct datalink *);
134 extern void mp_Down(struct mp *);
135 extern struct mbuf *mp_Input(struct bundle *, struct link *, struct mbuf *);
136 extern int mp_FillQueues(struct bundle *);
137 extern int mp_SetDatalinkBandwidth(struct cmdargs const *);
138 extern int mp_ShowStatus(struct cmdargs const *);
139 extern const char *mp_Enddisc(u_char, const char *, int);
140 extern int mp_SetEnddisc(struct cmdargs const *);
141 extern void mp_LinkLost(struct mp *, struct datalink *);
142 extern void mp_DeleteQueue(struct mp *);
143 extern void mp_RestartAutoloadTimer(struct mp *);
144 extern void mp_CheckAutoloadTimer(struct mp *);
145 extern void mp_StopAutoloadTimer(struct mp *);
146