ipcp.h revision 80476
1/*-
2 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3 *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4 *                           Internet Initiative Japan, Inc (IIJ)
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: head/usr.sbin/ppp/ipcp.h 80476 2001-07-28 11:32:08Z brian $
29 */
30
31#define	IPCP_MAXCODE	CODE_CODEREJ
32
33#define	TY_IPADDRS	1
34#define	TY_COMPPROTO	2
35#define	TY_IPADDR	3
36
37/* Domain NameServer and NetBIOS NameServer options */
38
39#define TY_PRIMARY_DNS		129
40#define TY_PRIMARY_NBNS		130
41#define TY_SECONDARY_DNS	131
42#define TY_SECONDARY_NBNS	132
43#define TY_ADJUST_NS		119 /* subtract from NS val for REJECT bit */
44
45struct sticky_route;
46
47struct in_range {
48  struct in_addr ipaddr;
49  struct in_addr mask;
50  int width;
51};
52
53struct port_range {
54  unsigned nports;		/* How many ports */
55  unsigned maxports;		/* How many allocated (malloc) ports */
56  u_short *port;		/* The actual ports */
57};
58
59struct ipcp {
60  struct fsm fsm;			/* The finite state machine */
61
62  struct {
63    struct {
64      int slots;			/* Maximum VJ slots */
65      unsigned slotcomp : 1;		/* Slot compression */
66      unsigned neg : 2;			/* VJ negotiation */
67    } vj;
68
69    struct in_range  my_range;		/* MYADDR spec */
70    struct in_addr   netmask;		/* Iface netmask (unused by most OSs) */
71    struct in_range  peer_range;	/* HISADDR spec */
72    struct iplist    peer_list;		/* Ranges of HISADDR values */
73
74    u_long sendpipe;			/* route sendpipe size */
75    u_long recvpipe;			/* route recvpipe size */
76
77    struct in_addr   TriggerAddress;	/* Address to suggest in REQ */
78    unsigned HaveTriggerAddress : 1;	/* Trigger address specified */
79
80    struct {
81      struct in_addr dns[2];		/* DNS addresses offered */
82      unsigned dns_neg : 2;		/* dns negotiation */
83      struct in_addr nbns[2];		/* NetBIOS NS addresses offered */
84    } ns;
85
86    struct {
87      struct port_range tcp, udp;	/* The range of urgent ports */
88      unsigned tos : 1;			/* Urgent IPTOS_LOWDELAY packets ? */
89    } urgent;
90
91    struct fsm_retry fsm;	/* How often/frequently to resend requests */
92  } cfg;
93
94  struct {
95    struct slcompress cslc;		/* VJ state */
96    struct slstat slstat;		/* VJ statistics */
97  } vj;
98
99  struct {
100    unsigned resolver : 1;		/* Found resolv.conf ? */
101    unsigned writable : 1;		/* Can write resolv.conf ? */
102    struct in_addr dns[2];		/* Current DNS addresses */
103    char *resolv;			/* Contents of resolv.conf */
104    char *resolv_nons;			/* Contents of resolv.conf without ns */
105  } ns;
106
107  struct sticky_route *route;		/* List of dynamic routes */
108
109  unsigned heis1172 : 1;		/* True if he is speaking rfc1172 */
110
111  unsigned peer_req : 1;		/* Any TY_IPADDR REQs from the peer ? */
112  struct in_addr peer_ip;		/* IP address he's willing to use */
113  u_int32_t peer_compproto;		/* VJ params he's willing to use */
114
115  struct in_addr ifmask;		/* Interface netmask */
116
117  struct in_addr my_ip;			/* IP address I'm willing to use */
118  u_int32_t my_compproto;		/* VJ params I'm willing to use */
119
120  struct in_addr dns[2];		/* DNSs to REQ/ACK */
121
122  u_int32_t peer_reject;		/* Request codes rejected by peer */
123  u_int32_t my_reject;			/* Request codes I have rejected */
124
125  struct pppThroughput throughput;	/* throughput statistics */
126  struct mqueue Queue[3];		/* Output packet queues */
127};
128
129#define fsm2ipcp(fp) (fp->proto == PROTO_IPCP ? (struct ipcp *)fp : NULL)
130#define IPCP_QUEUES(ipcp) (sizeof ipcp->Queue / sizeof ipcp->Queue[0])
131
132struct bundle;
133struct link;
134struct cmdargs;
135
136extern void ipcp_Init(struct ipcp *, struct bundle *, struct link *,
137                      const struct fsm_parent *);
138extern void ipcp_Destroy(struct ipcp *);
139extern void ipcp_Setup(struct ipcp *, u_int32_t);
140extern void ipcp_SetLink(struct ipcp *, struct link *);
141
142extern int  ipcp_Show(struct cmdargs const *);
143extern struct mbuf *ipcp_Input(struct bundle *, struct link *, struct mbuf *);
144extern void ipcp_AddInOctets(struct ipcp *, int);
145extern void ipcp_AddOutOctets(struct ipcp *, int);
146extern int  ipcp_UseHisIPaddr(struct bundle *, struct in_addr);
147extern int  ipcp_UseHisaddr(struct bundle *, const char *, int);
148extern int  ipcp_vjset(struct cmdargs const *);
149extern void ipcp_CleanInterface(struct ipcp *);
150extern int  ipcp_InterfaceUp(struct ipcp *);
151extern int  ipcp_IsUrgentPort(struct port_range *, u_short, u_short);
152extern void ipcp_AddUrgentPort(struct port_range *, u_short);
153extern void ipcp_RemoveUrgentPort(struct port_range *, u_short);
154extern void ipcp_ClearUrgentPorts(struct port_range *);
155extern struct in_addr addr2mask(struct in_addr);
156extern int ipcp_WriteDNS(struct ipcp *);
157extern void ipcp_RestoreDNS(struct ipcp *);
158extern void ipcp_LoadDNS(struct ipcp *);
159
160#define ipcp_IsUrgentTcpPort(ipcp, p1, p2) \
161          ipcp_IsUrgentPort(&(ipcp)->cfg.urgent.tcp, p1, p2)
162#define ipcp_IsUrgentUdpPort(ipcp, p1, p2) \
163          ipcp_IsUrgentPort(&(ipcp)->cfg.urgent.udp, p1, p2)
164#define ipcp_AddUrgentTcpPort(ipcp, p) \
165          ipcp_AddUrgentPort(&(ipcp)->cfg.urgent.tcp, p)
166#define ipcp_AddUrgentUdpPort(ipcp, p) \
167          ipcp_AddUrgentPort(&(ipcp)->cfg.urgent.udp, p)
168#define ipcp_RemoveUrgentTcpPort(ipcp, p) \
169          ipcp_RemoveUrgentPort(&(ipcp)->cfg.urgent.tcp, p)
170#define ipcp_RemoveUrgentUdpPort(ipcp, p) \
171          ipcp_RemoveUrgentPort(&(ipcp)->cfg.urgent.udp, p)
172#define ipcp_ClearUrgentTcpPorts(ipcp) \
173          ipcp_ClearUrgentPorts(&(ipcp)->cfg.urgent.tcp)
174#define ipcp_ClearUrgentUdpPorts(ipcp) \
175          ipcp_ClearUrgentPorts(&(ipcp)->cfg.urgent.udp)
176#define ipcp_ClearUrgentTOS(ipcp) (ipcp)->cfg.urgent.tos = 0;
177#define ipcp_SetUrgentTOS(ipcp) (ipcp)->cfg.urgent.tos = 1;
178