xref: /freebsd/usr.sbin/ppp/ipcp.h (revision 76238846ad3e9e271a3d1f792f72beab727fd153)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5  *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
6  *                           Internet Initiative Japan, Inc (IIJ)
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #define	IPCP_MAXCODE	CODE_CODEREJ
34 
35 #define	TY_IPADDRS	1
36 #define	TY_COMPPROTO	2
37 #define	TY_IPADDR	3
38 
39 /* Domain NameServer and NetBIOS NameServer options */
40 
41 #define TY_PRIMARY_DNS		129
42 #define TY_PRIMARY_NBNS		130
43 #define TY_SECONDARY_DNS	131
44 #define TY_SECONDARY_NBNS	132
45 #define TY_ADJUST_NS		119 /* subtract from NS val for REJECT bit */
46 
47 struct ipcp {
48   struct fsm fsm;			/* The finite state machine */
49 
50   struct {
51     struct {
52       int slots;			/* Maximum VJ slots */
53       unsigned slotcomp : 1;		/* Slot compression */
54       unsigned neg : 2;			/* VJ negotiation */
55     } vj;
56 
57     struct ncprange  my_range;		/* MYADDR spec */
58     struct in_addr   netmask;		/* Iface netmask (unused by most OSs) */
59     struct ncprange  peer_range;	/* HISADDR spec */
60     struct iplist    peer_list;		/* Ranges of HISADDR values */
61 
62     struct in_addr   TriggerAddress;	/* Address to suggest in REQ */
63     unsigned HaveTriggerAddress : 1;	/* Trigger address specified */
64 
65     struct {
66       struct in_addr dns[2];		/* DNS addresses offered */
67       unsigned dns_neg : 2;		/* dns negotiation */
68       struct in_addr nbns[2];		/* NetBIOS NS addresses offered */
69     } ns;
70 
71     struct fsm_retry fsm;		/* frequency to resend requests */
72   } cfg;
73 
74   struct {
75     struct slcompress cslc;		/* VJ state */
76     struct slstat slstat;		/* VJ statistics */
77   } vj;
78 
79   struct {
80     unsigned resolver : 1;		/* Found resolv.conf ? */
81     unsigned writable : 1;		/* Can write resolv.conf ? */
82     struct in_addr dns[2];		/* Current DNS addresses */
83     char *resolv;			/* Contents of resolv.conf */
84     char *resolv_nons;			/* Contents of resolv.conf without ns */
85   } ns;
86 
87   unsigned heis1172 : 1;		/* True if he is speaking rfc1172 */
88 
89   unsigned peer_req : 1;		/* Any TY_IPADDR REQs from the peer ? */
90   struct in_addr peer_ip;		/* IP address he's willing to use */
91   u_int32_t peer_compproto;		/* VJ params he's willing to use */
92 
93   struct in_addr ifmask;		/* Interface netmask */
94 
95   struct in_addr my_ip;			/* IP address I'm willing to use */
96   u_int32_t my_compproto;		/* VJ params I'm willing to use */
97 
98   u_int32_t peer_reject;		/* Request codes rejected by peer */
99   u_int32_t my_reject;			/* Request codes I have rejected */
100 
101   struct pppThroughput throughput;	/* throughput statistics */
102   struct mqueue Queue[3];		/* Output packet queues */
103 };
104 
105 #define fsm2ipcp(fp) (fp->proto == PROTO_IPCP ? (struct ipcp *)fp : NULL)
106 #define IPCP_QUEUES(ipcp) (sizeof ipcp->Queue / sizeof ipcp->Queue[0])
107 
108 struct bundle;
109 struct link;
110 struct cmdargs;
111 struct iface_addr;
112 
113 extern void ipcp_Init(struct ipcp *, struct bundle *, struct link *,
114                       const struct fsm_parent *);
115 extern void ipcp_Destroy(struct ipcp *);
116 extern void ipcp_Setup(struct ipcp *, u_int32_t);
117 extern void ipcp_SetLink(struct ipcp *, struct link *);
118 
119 extern int  ipcp_Show(struct cmdargs const *);
120 extern struct mbuf *ipcp_Input(struct bundle *, struct link *, struct mbuf *);
121 extern void ipcp_AddInOctets(struct ipcp *, int);
122 extern void ipcp_AddOutOctets(struct ipcp *, int);
123 extern int  ipcp_UseHisIPaddr(struct bundle *, struct in_addr);
124 extern int  ipcp_UseHisaddr(struct bundle *, const char *, int);
125 extern int  ipcp_vjset(struct cmdargs const *);
126 extern void ipcp_IfaceAddrAdded(struct ipcp *, const struct iface_addr *);
127 extern void ipcp_IfaceAddrDeleted(struct ipcp *, const struct iface_addr *);
128 extern int  ipcp_InterfaceUp(struct ipcp *);
129 extern struct in_addr addr2mask(struct in_addr);
130 extern int ipcp_WriteDNS(struct ipcp *);
131 extern void ipcp_RestoreDNS(struct ipcp *);
132 extern void ipcp_LoadDNS(struct ipcp *);
133 extern size_t ipcp_QueueLen(struct ipcp *);
134 extern int ipcp_PushPacket(struct ipcp *, struct link *);
135