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