Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:8f5825f330b0 1 /** In contrast to pppd 2.3.1, DNS support has been added, proxy-ARP and
RodColeman 0:8f5825f330b0 2 dial-on-demand has been stripped. */
RodColeman 0:8f5825f330b0 3 /*****************************************************************************
RodColeman 0:8f5825f330b0 4 * ipcp.c - Network PPP IP Control Protocol program file.
RodColeman 0:8f5825f330b0 5 *
RodColeman 0:8f5825f330b0 6 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
RodColeman 0:8f5825f330b0 7 * portions Copyright (c) 1997 by Global Election Systems Inc.
RodColeman 0:8f5825f330b0 8 *
RodColeman 0:8f5825f330b0 9 * The authors hereby grant permission to use, copy, modify, distribute,
RodColeman 0:8f5825f330b0 10 * and license this software and its documentation for any purpose, provided
RodColeman 0:8f5825f330b0 11 * that existing copyright notices are retained in all copies and that this
RodColeman 0:8f5825f330b0 12 * notice and the following disclaimer are included verbatim in any
RodColeman 0:8f5825f330b0 13 * distributions. No written agreement, license, or royalty fee is required
RodColeman 0:8f5825f330b0 14 * for any of the authorized uses.
RodColeman 0:8f5825f330b0 15 *
RodColeman 0:8f5825f330b0 16 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
RodColeman 0:8f5825f330b0 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
RodColeman 0:8f5825f330b0 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
RodColeman 0:8f5825f330b0 19 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
RodColeman 0:8f5825f330b0 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
RodColeman 0:8f5825f330b0 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
RodColeman 0:8f5825f330b0 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
RodColeman 0:8f5825f330b0 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
RodColeman 0:8f5825f330b0 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
RodColeman 0:8f5825f330b0 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RodColeman 0:8f5825f330b0 26 *
RodColeman 0:8f5825f330b0 27 ******************************************************************************
RodColeman 0:8f5825f330b0 28 * REVISION HISTORY
RodColeman 0:8f5825f330b0 29 *
RodColeman 0:8f5825f330b0 30 * 03-01-01 Marc Boucher <marc@mbsi.ca>
RodColeman 0:8f5825f330b0 31 * Ported to lwIP.
RodColeman 0:8f5825f330b0 32 * 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
RodColeman 0:8f5825f330b0 33 * Original.
RodColeman 0:8f5825f330b0 34 *****************************************************************************/
RodColeman 0:8f5825f330b0 35 /*
RodColeman 0:8f5825f330b0 36 * ipcp.c - PPP IP Control Protocol.
RodColeman 0:8f5825f330b0 37 *
RodColeman 0:8f5825f330b0 38 * Copyright (c) 1989 Carnegie Mellon University.
RodColeman 0:8f5825f330b0 39 * All rights reserved.
RodColeman 0:8f5825f330b0 40 *
RodColeman 0:8f5825f330b0 41 * Redistribution and use in source and binary forms are permitted
RodColeman 0:8f5825f330b0 42 * provided that the above copyright notice and this paragraph are
RodColeman 0:8f5825f330b0 43 * duplicated in all such forms and that any documentation,
RodColeman 0:8f5825f330b0 44 * advertising materials, and other materials related to such
RodColeman 0:8f5825f330b0 45 * distribution and use acknowledge that the software was developed
RodColeman 0:8f5825f330b0 46 * by Carnegie Mellon University. The name of the
RodColeman 0:8f5825f330b0 47 * University may not be used to endorse or promote products derived
RodColeman 0:8f5825f330b0 48 * from this software without specific prior written permission.
RodColeman 0:8f5825f330b0 49 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
RodColeman 0:8f5825f330b0 50 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
RodColeman 0:8f5825f330b0 51 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
RodColeman 0:8f5825f330b0 52 */
RodColeman 0:8f5825f330b0 53
RodColeman 0:8f5825f330b0 54 #include "lwip/opt.h"
RodColeman 0:8f5825f330b0 55
RodColeman 0:8f5825f330b0 56 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
RodColeman 0:8f5825f330b0 57
RodColeman 0:8f5825f330b0 58 #include "ppp.h"
RodColeman 0:8f5825f330b0 59 #include "pppdebug.h"
RodColeman 0:8f5825f330b0 60
RodColeman 0:8f5825f330b0 61 #include "auth.h"
RodColeman 0:8f5825f330b0 62 #include "fsm.h"
RodColeman 0:8f5825f330b0 63 #include "vj.h"
RodColeman 0:8f5825f330b0 64 #include "ipcp.h"
RodColeman 0:8f5825f330b0 65
RodColeman 0:8f5825f330b0 66 #include "lwip/inet.h"
RodColeman 0:8f5825f330b0 67
RodColeman 0:8f5825f330b0 68 #include <string.h>
RodColeman 0:8f5825f330b0 69
RodColeman 0:8f5825f330b0 70 /* #define OLD_CI_ADDRS 1 */ /* Support deprecated address negotiation. */
RodColeman 0:8f5825f330b0 71
RodColeman 0:8f5825f330b0 72 /* global vars */
RodColeman 0:8f5825f330b0 73 ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */
RodColeman 0:8f5825f330b0 74 ipcp_options ipcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
RodColeman 0:8f5825f330b0 75 ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
RodColeman 0:8f5825f330b0 76 ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
RodColeman 0:8f5825f330b0 77
RodColeman 0:8f5825f330b0 78 /* local vars */
RodColeman 0:8f5825f330b0 79 static int default_route_set[NUM_PPP]; /* Have set up a default route */
RodColeman 0:8f5825f330b0 80 static int cis_received[NUM_PPP]; /* # Conf-Reqs received */
RodColeman 0:8f5825f330b0 81
RodColeman 0:8f5825f330b0 82
RodColeman 0:8f5825f330b0 83 /*
RodColeman 0:8f5825f330b0 84 * Callbacks for fsm code. (CI = Configuration Information)
RodColeman 0:8f5825f330b0 85 */
RodColeman 0:8f5825f330b0 86 static void ipcp_resetci (fsm *); /* Reset our CI */
RodColeman 0:8f5825f330b0 87 static int ipcp_cilen (fsm *); /* Return length of our CI */
RodColeman 0:8f5825f330b0 88 static void ipcp_addci (fsm *, u_char *, int *); /* Add our CI */
RodColeman 0:8f5825f330b0 89 static int ipcp_ackci (fsm *, u_char *, int); /* Peer ack'd our CI */
RodColeman 0:8f5825f330b0 90 static int ipcp_nakci (fsm *, u_char *, int); /* Peer nak'd our CI */
RodColeman 0:8f5825f330b0 91 static int ipcp_rejci (fsm *, u_char *, int); /* Peer rej'd our CI */
RodColeman 0:8f5825f330b0 92 static int ipcp_reqci (fsm *, u_char *, int *, int); /* Rcv CI */
RodColeman 0:8f5825f330b0 93 static void ipcp_up (fsm *); /* We're UP */
RodColeman 0:8f5825f330b0 94 static void ipcp_down (fsm *); /* We're DOWN */
RodColeman 0:8f5825f330b0 95 #if PPP_ADDITIONAL_CALLBACKS
RodColeman 0:8f5825f330b0 96 static void ipcp_script (fsm *, char *); /* Run an up/down script */
RodColeman 0:8f5825f330b0 97 #endif
RodColeman 0:8f5825f330b0 98 static void ipcp_finished (fsm *); /* Don't need lower layer */
RodColeman 0:8f5825f330b0 99
RodColeman 0:8f5825f330b0 100
RodColeman 0:8f5825f330b0 101 fsm ipcp_fsm[NUM_PPP]; /* IPCP fsm structure */
RodColeman 0:8f5825f330b0 102
RodColeman 0:8f5825f330b0 103
RodColeman 0:8f5825f330b0 104 static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */
RodColeman 0:8f5825f330b0 105 ipcp_resetci, /* Reset our Configuration Information */
RodColeman 0:8f5825f330b0 106 ipcp_cilen, /* Length of our Configuration Information */
RodColeman 0:8f5825f330b0 107 ipcp_addci, /* Add our Configuration Information */
RodColeman 0:8f5825f330b0 108 ipcp_ackci, /* ACK our Configuration Information */
RodColeman 0:8f5825f330b0 109 ipcp_nakci, /* NAK our Configuration Information */
RodColeman 0:8f5825f330b0 110 ipcp_rejci, /* Reject our Configuration Information */
RodColeman 0:8f5825f330b0 111 ipcp_reqci, /* Request peer's Configuration Information */
RodColeman 0:8f5825f330b0 112 ipcp_up, /* Called when fsm reaches LS_OPENED state */
RodColeman 0:8f5825f330b0 113 ipcp_down, /* Called when fsm leaves LS_OPENED state */
RodColeman 0:8f5825f330b0 114 NULL, /* Called when we want the lower layer up */
RodColeman 0:8f5825f330b0 115 ipcp_finished, /* Called when we want the lower layer down */
RodColeman 0:8f5825f330b0 116 NULL, /* Called when Protocol-Reject received */
RodColeman 0:8f5825f330b0 117 NULL, /* Retransmission is necessary */
RodColeman 0:8f5825f330b0 118 NULL, /* Called to handle protocol-specific codes */
RodColeman 0:8f5825f330b0 119 "IPCP" /* String name of protocol */
RodColeman 0:8f5825f330b0 120 };
RodColeman 0:8f5825f330b0 121
RodColeman 0:8f5825f330b0 122 /*
RodColeman 0:8f5825f330b0 123 * Protocol entry points from main code.
RodColeman 0:8f5825f330b0 124 */
RodColeman 0:8f5825f330b0 125 static void ipcp_init (int);
RodColeman 0:8f5825f330b0 126 static void ipcp_open (int);
RodColeman 0:8f5825f330b0 127 static void ipcp_close (int, char *);
RodColeman 0:8f5825f330b0 128 static void ipcp_lowerup (int);
RodColeman 0:8f5825f330b0 129 static void ipcp_lowerdown (int);
RodColeman 0:8f5825f330b0 130 static void ipcp_input (int, u_char *, int);
RodColeman 0:8f5825f330b0 131 static void ipcp_protrej (int);
RodColeman 0:8f5825f330b0 132
RodColeman 0:8f5825f330b0 133
RodColeman 0:8f5825f330b0 134 struct protent ipcp_protent = {
RodColeman 0:8f5825f330b0 135 PPP_IPCP,
RodColeman 0:8f5825f330b0 136 ipcp_init,
RodColeman 0:8f5825f330b0 137 ipcp_input,
RodColeman 0:8f5825f330b0 138 ipcp_protrej,
RodColeman 0:8f5825f330b0 139 ipcp_lowerup,
RodColeman 0:8f5825f330b0 140 ipcp_lowerdown,
RodColeman 0:8f5825f330b0 141 ipcp_open,
RodColeman 0:8f5825f330b0 142 ipcp_close,
RodColeman 0:8f5825f330b0 143 #if PPP_ADDITIONAL_CALLBACKS
RodColeman 0:8f5825f330b0 144 ipcp_printpkt,
RodColeman 0:8f5825f330b0 145 NULL,
RodColeman 0:8f5825f330b0 146 #endif /* PPP_ADDITIONAL_CALLBACKS */
RodColeman 0:8f5825f330b0 147 1,
RodColeman 0:8f5825f330b0 148 "IPCP",
RodColeman 0:8f5825f330b0 149 #if PPP_ADDITIONAL_CALLBACKS
RodColeman 0:8f5825f330b0 150 ip_check_options,
RodColeman 0:8f5825f330b0 151 NULL,
RodColeman 0:8f5825f330b0 152 ip_active_pkt
RodColeman 0:8f5825f330b0 153 #endif /* PPP_ADDITIONAL_CALLBACKS */
RodColeman 0:8f5825f330b0 154 };
RodColeman 0:8f5825f330b0 155
RodColeman 0:8f5825f330b0 156 static void ipcp_clear_addrs (int);
RodColeman 0:8f5825f330b0 157
RodColeman 0:8f5825f330b0 158 /*
RodColeman 0:8f5825f330b0 159 * Lengths of configuration options.
RodColeman 0:8f5825f330b0 160 */
RodColeman 0:8f5825f330b0 161 #define CILEN_VOID 2
RodColeman 0:8f5825f330b0 162 #define CILEN_COMPRESS 4 /* min length for compression protocol opt. */
RodColeman 0:8f5825f330b0 163 #define CILEN_VJ 6 /* length for RFC1332 Van-Jacobson opt. */
RodColeman 0:8f5825f330b0 164 #define CILEN_ADDR 6 /* new-style single address option */
RodColeman 0:8f5825f330b0 165 #define CILEN_ADDRS 10 /* old-style dual address option */
RodColeman 0:8f5825f330b0 166
RodColeman 0:8f5825f330b0 167
RodColeman 0:8f5825f330b0 168 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
RodColeman 0:8f5825f330b0 169 (x) == CONFNAK ? "NAK" : "REJ")
RodColeman 0:8f5825f330b0 170
RodColeman 0:8f5825f330b0 171
RodColeman 0:8f5825f330b0 172 /*
RodColeman 0:8f5825f330b0 173 * ipcp_init - Initialize IPCP.
RodColeman 0:8f5825f330b0 174 */
RodColeman 0:8f5825f330b0 175 static void
RodColeman 0:8f5825f330b0 176 ipcp_init(int unit)
RodColeman 0:8f5825f330b0 177 {
RodColeman 0:8f5825f330b0 178 fsm *f = &ipcp_fsm[unit];
RodColeman 0:8f5825f330b0 179 ipcp_options *wo = &ipcp_wantoptions[unit];
RodColeman 0:8f5825f330b0 180 ipcp_options *ao = &ipcp_allowoptions[unit];
RodColeman 0:8f5825f330b0 181
RodColeman 0:8f5825f330b0 182 f->unit = unit;
RodColeman 0:8f5825f330b0 183 f->protocol = PPP_IPCP;
RodColeman 0:8f5825f330b0 184 f->callbacks = &ipcp_callbacks;
RodColeman 0:8f5825f330b0 185 fsm_init(&ipcp_fsm[unit]);
RodColeman 0:8f5825f330b0 186
RodColeman 0:8f5825f330b0 187 memset(wo, 0, sizeof(*wo));
RodColeman 0:8f5825f330b0 188 memset(ao, 0, sizeof(*ao));
RodColeman 0:8f5825f330b0 189
RodColeman 0:8f5825f330b0 190 wo->neg_addr = 1;
RodColeman 0:8f5825f330b0 191 wo->ouraddr = 0;
RodColeman 0:8f5825f330b0 192 #if VJ_SUPPORT
RodColeman 0:8f5825f330b0 193 wo->neg_vj = 1;
RodColeman 0:8f5825f330b0 194 #else /* VJ_SUPPORT */
RodColeman 0:8f5825f330b0 195 wo->neg_vj = 0;
RodColeman 0:8f5825f330b0 196 #endif /* VJ_SUPPORT */
RodColeman 0:8f5825f330b0 197 wo->vj_protocol = IPCP_VJ_COMP;
RodColeman 0:8f5825f330b0 198 wo->maxslotindex = MAX_SLOTS - 1;
RodColeman 0:8f5825f330b0 199 wo->cflag = 0;
RodColeman 0:8f5825f330b0 200 wo->default_route = 1;
RodColeman 0:8f5825f330b0 201
RodColeman 0:8f5825f330b0 202 ao->neg_addr = 1;
RodColeman 0:8f5825f330b0 203 #if VJ_SUPPORT
RodColeman 0:8f5825f330b0 204 ao->neg_vj = 1;
RodColeman 0:8f5825f330b0 205 #else /* VJ_SUPPORT */
RodColeman 0:8f5825f330b0 206 ao->neg_vj = 0;
RodColeman 0:8f5825f330b0 207 #endif /* VJ_SUPPORT */
RodColeman 0:8f5825f330b0 208 ao->maxslotindex = MAX_SLOTS - 1;
RodColeman 0:8f5825f330b0 209 ao->cflag = 1;
RodColeman 0:8f5825f330b0 210 ao->default_route = 1;
RodColeman 0:8f5825f330b0 211 }
RodColeman 0:8f5825f330b0 212
RodColeman 0:8f5825f330b0 213
RodColeman 0:8f5825f330b0 214 /*
RodColeman 0:8f5825f330b0 215 * ipcp_open - IPCP is allowed to come up.
RodColeman 0:8f5825f330b0 216 */
RodColeman 0:8f5825f330b0 217 static void
RodColeman 0:8f5825f330b0 218 ipcp_open(int unit)
RodColeman 0:8f5825f330b0 219 {
RodColeman 0:8f5825f330b0 220 fsm_open(&ipcp_fsm[unit]);
RodColeman 0:8f5825f330b0 221 }
RodColeman 0:8f5825f330b0 222
RodColeman 0:8f5825f330b0 223
RodColeman 0:8f5825f330b0 224 /*
RodColeman 0:8f5825f330b0 225 * ipcp_close - Take IPCP down.
RodColeman 0:8f5825f330b0 226 */
RodColeman 0:8f5825f330b0 227 static void
RodColeman 0:8f5825f330b0 228 ipcp_close(int unit, char *reason)
RodColeman 0:8f5825f330b0 229 {
RodColeman 0:8f5825f330b0 230 fsm_close(&ipcp_fsm[unit], reason);
RodColeman 0:8f5825f330b0 231 }
RodColeman 0:8f5825f330b0 232
RodColeman 0:8f5825f330b0 233
RodColeman 0:8f5825f330b0 234 /*
RodColeman 0:8f5825f330b0 235 * ipcp_lowerup - The lower layer is up.
RodColeman 0:8f5825f330b0 236 */
RodColeman 0:8f5825f330b0 237 static void
RodColeman 0:8f5825f330b0 238 ipcp_lowerup(int unit)
RodColeman 0:8f5825f330b0 239 {
RodColeman 0:8f5825f330b0 240 fsm_lowerup(&ipcp_fsm[unit]);
RodColeman 0:8f5825f330b0 241 }
RodColeman 0:8f5825f330b0 242
RodColeman 0:8f5825f330b0 243
RodColeman 0:8f5825f330b0 244 /*
RodColeman 0:8f5825f330b0 245 * ipcp_lowerdown - The lower layer is down.
RodColeman 0:8f5825f330b0 246 */
RodColeman 0:8f5825f330b0 247 static void
RodColeman 0:8f5825f330b0 248 ipcp_lowerdown(int unit)
RodColeman 0:8f5825f330b0 249 {
RodColeman 0:8f5825f330b0 250 fsm_lowerdown(&ipcp_fsm[unit]);
RodColeman 0:8f5825f330b0 251 }
RodColeman 0:8f5825f330b0 252
RodColeman 0:8f5825f330b0 253
RodColeman 0:8f5825f330b0 254 /*
RodColeman 0:8f5825f330b0 255 * ipcp_input - Input IPCP packet.
RodColeman 0:8f5825f330b0 256 */
RodColeman 0:8f5825f330b0 257 static void
RodColeman 0:8f5825f330b0 258 ipcp_input(int unit, u_char *p, int len)
RodColeman 0:8f5825f330b0 259 {
RodColeman 0:8f5825f330b0 260 fsm_input(&ipcp_fsm[unit], p, len);
RodColeman 0:8f5825f330b0 261 }
RodColeman 0:8f5825f330b0 262
RodColeman 0:8f5825f330b0 263
RodColeman 0:8f5825f330b0 264 /*
RodColeman 0:8f5825f330b0 265 * ipcp_protrej - A Protocol-Reject was received for IPCP.
RodColeman 0:8f5825f330b0 266 *
RodColeman 0:8f5825f330b0 267 * Pretend the lower layer went down, so we shut up.
RodColeman 0:8f5825f330b0 268 */
RodColeman 0:8f5825f330b0 269 static void
RodColeman 0:8f5825f330b0 270 ipcp_protrej(int unit)
RodColeman 0:8f5825f330b0 271 {
RodColeman 0:8f5825f330b0 272 fsm_lowerdown(&ipcp_fsm[unit]);
RodColeman 0:8f5825f330b0 273 }
RodColeman 0:8f5825f330b0 274
RodColeman 0:8f5825f330b0 275
RodColeman 0:8f5825f330b0 276 /*
RodColeman 0:8f5825f330b0 277 * ipcp_resetci - Reset our CI.
RodColeman 0:8f5825f330b0 278 */
RodColeman 0:8f5825f330b0 279 static void
RodColeman 0:8f5825f330b0 280 ipcp_resetci(fsm *f)
RodColeman 0:8f5825f330b0 281 {
RodColeman 0:8f5825f330b0 282 ipcp_options *wo = &ipcp_wantoptions[f->unit];
RodColeman 0:8f5825f330b0 283
RodColeman 0:8f5825f330b0 284 wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
RodColeman 0:8f5825f330b0 285 if (wo->ouraddr == 0) {
RodColeman 0:8f5825f330b0 286 wo->accept_local = 1;
RodColeman 0:8f5825f330b0 287 }
RodColeman 0:8f5825f330b0 288 if (wo->hisaddr == 0) {
RodColeman 0:8f5825f330b0 289 wo->accept_remote = 1;
RodColeman 0:8f5825f330b0 290 }
RodColeman 0:8f5825f330b0 291 /* Request DNS addresses from the peer */
RodColeman 0:8f5825f330b0 292 wo->req_dns1 = ppp_settings.usepeerdns;
RodColeman 0:8f5825f330b0 293 wo->req_dns2 = ppp_settings.usepeerdns;
RodColeman 0:8f5825f330b0 294 ipcp_gotoptions[f->unit] = *wo;
RodColeman 0:8f5825f330b0 295 cis_received[f->unit] = 0;
RodColeman 0:8f5825f330b0 296 }
RodColeman 0:8f5825f330b0 297
RodColeman 0:8f5825f330b0 298
RodColeman 0:8f5825f330b0 299 /*
RodColeman 0:8f5825f330b0 300 * ipcp_cilen - Return length of our CI.
RodColeman 0:8f5825f330b0 301 */
RodColeman 0:8f5825f330b0 302 static int
RodColeman 0:8f5825f330b0 303 ipcp_cilen(fsm *f)
RodColeman 0:8f5825f330b0 304 {
RodColeman 0:8f5825f330b0 305 ipcp_options *go = &ipcp_gotoptions[f->unit];
RodColeman 0:8f5825f330b0 306 ipcp_options *wo = &ipcp_wantoptions[f->unit];
RodColeman 0:8f5825f330b0 307 ipcp_options *ho = &ipcp_hisoptions[f->unit];
RodColeman 0:8f5825f330b0 308
RodColeman 0:8f5825f330b0 309 #define LENCIVJ(neg, old) (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
RodColeman 0:8f5825f330b0 310 #define LENCIADDR(neg, old) (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
RodColeman 0:8f5825f330b0 311 #define LENCIDNS(neg) (neg ? (CILEN_ADDR) : 0)
RodColeman 0:8f5825f330b0 312
RodColeman 0:8f5825f330b0 313 /*
RodColeman 0:8f5825f330b0 314 * First see if we want to change our options to the old
RodColeman 0:8f5825f330b0 315 * forms because we have received old forms from the peer.
RodColeman 0:8f5825f330b0 316 */
RodColeman 0:8f5825f330b0 317 if (wo->neg_addr && !go->neg_addr && !go->old_addrs) {
RodColeman 0:8f5825f330b0 318 /* use the old style of address negotiation */
RodColeman 0:8f5825f330b0 319 go->neg_addr = 1;
RodColeman 0:8f5825f330b0 320 go->old_addrs = 1;
RodColeman 0:8f5825f330b0 321 }
RodColeman 0:8f5825f330b0 322 if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
RodColeman 0:8f5825f330b0 323 /* try an older style of VJ negotiation */
RodColeman 0:8f5825f330b0 324 if (cis_received[f->unit] == 0) {
RodColeman 0:8f5825f330b0 325 /* keep trying the new style until we see some CI from the peer */
RodColeman 0:8f5825f330b0 326 go->neg_vj = 1;
RodColeman 0:8f5825f330b0 327 } else {
RodColeman 0:8f5825f330b0 328 /* use the old style only if the peer did */
RodColeman 0:8f5825f330b0 329 if (ho->neg_vj && ho->old_vj) {
RodColeman 0:8f5825f330b0 330 go->neg_vj = 1;
RodColeman 0:8f5825f330b0 331 go->old_vj = 1;
RodColeman 0:8f5825f330b0 332 go->vj_protocol = ho->vj_protocol;
RodColeman 0:8f5825f330b0 333 }
RodColeman 0:8f5825f330b0 334 }
RodColeman 0:8f5825f330b0 335 }
RodColeman 0:8f5825f330b0 336
RodColeman 0:8f5825f330b0 337 return (LENCIADDR(go->neg_addr, go->old_addrs) +
RodColeman 0:8f5825f330b0 338 LENCIVJ(go->neg_vj, go->old_vj) +
RodColeman 0:8f5825f330b0 339 LENCIDNS(go->req_dns1) +
RodColeman 0:8f5825f330b0 340 LENCIDNS(go->req_dns2));
RodColeman 0:8f5825f330b0 341 }
RodColeman 0:8f5825f330b0 342
RodColeman 0:8f5825f330b0 343
RodColeman 0:8f5825f330b0 344 /*
RodColeman 0:8f5825f330b0 345 * ipcp_addci - Add our desired CIs to a packet.
RodColeman 0:8f5825f330b0 346 */
RodColeman 0:8f5825f330b0 347 static void
RodColeman 0:8f5825f330b0 348 ipcp_addci(fsm *f, u_char *ucp, int *lenp)
RodColeman 0:8f5825f330b0 349 {
RodColeman 0:8f5825f330b0 350 ipcp_options *go = &ipcp_gotoptions[f->unit];
RodColeman 0:8f5825f330b0 351 int len = *lenp;
RodColeman 0:8f5825f330b0 352
RodColeman 0:8f5825f330b0 353 #define ADDCIVJ(opt, neg, val, old, maxslotindex, cflag) \
RodColeman 0:8f5825f330b0 354 if (neg) { \
RodColeman 0:8f5825f330b0 355 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
RodColeman 0:8f5825f330b0 356 if (len >= vjlen) { \
RodColeman 0:8f5825f330b0 357 PUTCHAR(opt, ucp); \
RodColeman 0:8f5825f330b0 358 PUTCHAR(vjlen, ucp); \
RodColeman 0:8f5825f330b0 359 PUTSHORT(val, ucp); \
RodColeman 0:8f5825f330b0 360 if (!old) { \
RodColeman 0:8f5825f330b0 361 PUTCHAR(maxslotindex, ucp); \
RodColeman 0:8f5825f330b0 362 PUTCHAR(cflag, ucp); \
RodColeman 0:8f5825f330b0 363 } \
RodColeman 0:8f5825f330b0 364 len -= vjlen; \
RodColeman 0:8f5825f330b0 365 } else { \
RodColeman 0:8f5825f330b0 366 neg = 0; \
RodColeman 0:8f5825f330b0 367 } \
RodColeman 0:8f5825f330b0 368 }
RodColeman 0:8f5825f330b0 369
RodColeman 0:8f5825f330b0 370 #define ADDCIADDR(opt, neg, old, val1, val2) \
RodColeman 0:8f5825f330b0 371 if (neg) { \
RodColeman 0:8f5825f330b0 372 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
RodColeman 0:8f5825f330b0 373 if (len >= addrlen) { \
RodColeman 0:8f5825f330b0 374 u32_t l; \
RodColeman 0:8f5825f330b0 375 PUTCHAR(opt, ucp); \
RodColeman 0:8f5825f330b0 376 PUTCHAR(addrlen, ucp); \
RodColeman 0:8f5825f330b0 377 l = ntohl(val1); \
RodColeman 0:8f5825f330b0 378 PUTLONG(l, ucp); \
RodColeman 0:8f5825f330b0 379 if (old) { \
RodColeman 0:8f5825f330b0 380 l = ntohl(val2); \
RodColeman 0:8f5825f330b0 381 PUTLONG(l, ucp); \
RodColeman 0:8f5825f330b0 382 } \
RodColeman 0:8f5825f330b0 383 len -= addrlen; \
RodColeman 0:8f5825f330b0 384 } else { \
RodColeman 0:8f5825f330b0 385 neg = 0; \
RodColeman 0:8f5825f330b0 386 } \
RodColeman 0:8f5825f330b0 387 }
RodColeman 0:8f5825f330b0 388
RodColeman 0:8f5825f330b0 389 #define ADDCIDNS(opt, neg, addr) \
RodColeman 0:8f5825f330b0 390 if (neg) { \
RodColeman 0:8f5825f330b0 391 if (len >= CILEN_ADDR) { \
RodColeman 0:8f5825f330b0 392 u32_t l; \
RodColeman 0:8f5825f330b0 393 PUTCHAR(opt, ucp); \
RodColeman 0:8f5825f330b0 394 PUTCHAR(CILEN_ADDR, ucp); \
RodColeman 0:8f5825f330b0 395 l = ntohl(addr); \
RodColeman 0:8f5825f330b0 396 PUTLONG(l, ucp); \
RodColeman 0:8f5825f330b0 397 len -= CILEN_ADDR; \
RodColeman 0:8f5825f330b0 398 } else { \
RodColeman 0:8f5825f330b0 399 neg = 0; \
RodColeman 0:8f5825f330b0 400 } \
RodColeman 0:8f5825f330b0 401 }
RodColeman 0:8f5825f330b0 402
RodColeman 0:8f5825f330b0 403 ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
RodColeman 0:8f5825f330b0 404 go->old_addrs, go->ouraddr, go->hisaddr);
RodColeman 0:8f5825f330b0 405
RodColeman 0:8f5825f330b0 406 ADDCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
RodColeman 0:8f5825f330b0 407 go->maxslotindex, go->cflag);
RodColeman 0:8f5825f330b0 408
RodColeman 0:8f5825f330b0 409 ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
RodColeman 0:8f5825f330b0 410
RodColeman 0:8f5825f330b0 411 ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
RodColeman 0:8f5825f330b0 412
RodColeman 0:8f5825f330b0 413 *lenp -= len;
RodColeman 0:8f5825f330b0 414 }
RodColeman 0:8f5825f330b0 415
RodColeman 0:8f5825f330b0 416
RodColeman 0:8f5825f330b0 417 /*
RodColeman 0:8f5825f330b0 418 * ipcp_ackci - Ack our CIs.
RodColeman 0:8f5825f330b0 419 *
RodColeman 0:8f5825f330b0 420 * Returns:
RodColeman 0:8f5825f330b0 421 * 0 - Ack was bad.
RodColeman 0:8f5825f330b0 422 * 1 - Ack was good.
RodColeman 0:8f5825f330b0 423 */
RodColeman 0:8f5825f330b0 424 static int
RodColeman 0:8f5825f330b0 425 ipcp_ackci(fsm *f, u_char *p, int len)
RodColeman 0:8f5825f330b0 426 {
RodColeman 0:8f5825f330b0 427 ipcp_options *go = &ipcp_gotoptions[f->unit];
RodColeman 0:8f5825f330b0 428 u_short cilen, citype, cishort;
RodColeman 0:8f5825f330b0 429 u32_t cilong;
RodColeman 0:8f5825f330b0 430 u_char cimaxslotindex, cicflag;
RodColeman 0:8f5825f330b0 431
RodColeman 0:8f5825f330b0 432 /*
RodColeman 0:8f5825f330b0 433 * CIs must be in exactly the same order that we sent...
RodColeman 0:8f5825f330b0 434 * Check packet length and CI length at each step.
RodColeman 0:8f5825f330b0 435 * If we find any deviations, then this packet is bad.
RodColeman 0:8f5825f330b0 436 */
RodColeman 0:8f5825f330b0 437
RodColeman 0:8f5825f330b0 438 #define ACKCIVJ(opt, neg, val, old, maxslotindex, cflag) \
RodColeman 0:8f5825f330b0 439 if (neg) { \
RodColeman 0:8f5825f330b0 440 int vjlen = old? CILEN_COMPRESS : CILEN_VJ; \
RodColeman 0:8f5825f330b0 441 if ((len -= vjlen) < 0) { \
RodColeman 0:8f5825f330b0 442 goto bad; \
RodColeman 0:8f5825f330b0 443 } \
RodColeman 0:8f5825f330b0 444 GETCHAR(citype, p); \
RodColeman 0:8f5825f330b0 445 GETCHAR(cilen, p); \
RodColeman 0:8f5825f330b0 446 if (cilen != vjlen || \
RodColeman 0:8f5825f330b0 447 citype != opt) { \
RodColeman 0:8f5825f330b0 448 goto bad; \
RodColeman 0:8f5825f330b0 449 } \
RodColeman 0:8f5825f330b0 450 GETSHORT(cishort, p); \
RodColeman 0:8f5825f330b0 451 if (cishort != val) { \
RodColeman 0:8f5825f330b0 452 goto bad; \
RodColeman 0:8f5825f330b0 453 } \
RodColeman 0:8f5825f330b0 454 if (!old) { \
RodColeman 0:8f5825f330b0 455 GETCHAR(cimaxslotindex, p); \
RodColeman 0:8f5825f330b0 456 if (cimaxslotindex != maxslotindex) { \
RodColeman 0:8f5825f330b0 457 goto bad; \
RodColeman 0:8f5825f330b0 458 } \
RodColeman 0:8f5825f330b0 459 GETCHAR(cicflag, p); \
RodColeman 0:8f5825f330b0 460 if (cicflag != cflag) { \
RodColeman 0:8f5825f330b0 461 goto bad; \
RodColeman 0:8f5825f330b0 462 } \
RodColeman 0:8f5825f330b0 463 } \
RodColeman 0:8f5825f330b0 464 }
RodColeman 0:8f5825f330b0 465
RodColeman 0:8f5825f330b0 466 #define ACKCIADDR(opt, neg, old, val1, val2) \
RodColeman 0:8f5825f330b0 467 if (neg) { \
RodColeman 0:8f5825f330b0 468 int addrlen = (old? CILEN_ADDRS: CILEN_ADDR); \
RodColeman 0:8f5825f330b0 469 u32_t l; \
RodColeman 0:8f5825f330b0 470 if ((len -= addrlen) < 0) { \
RodColeman 0:8f5825f330b0 471 goto bad; \
RodColeman 0:8f5825f330b0 472 } \
RodColeman 0:8f5825f330b0 473 GETCHAR(citype, p); \
RodColeman 0:8f5825f330b0 474 GETCHAR(cilen, p); \
RodColeman 0:8f5825f330b0 475 if (cilen != addrlen || \
RodColeman 0:8f5825f330b0 476 citype != opt) { \
RodColeman 0:8f5825f330b0 477 goto bad; \
RodColeman 0:8f5825f330b0 478 } \
RodColeman 0:8f5825f330b0 479 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 480 cilong = htonl(l); \
RodColeman 0:8f5825f330b0 481 if (val1 != cilong) { \
RodColeman 0:8f5825f330b0 482 goto bad; \
RodColeman 0:8f5825f330b0 483 } \
RodColeman 0:8f5825f330b0 484 if (old) { \
RodColeman 0:8f5825f330b0 485 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 486 cilong = htonl(l); \
RodColeman 0:8f5825f330b0 487 if (val2 != cilong) { \
RodColeman 0:8f5825f330b0 488 goto bad; \
RodColeman 0:8f5825f330b0 489 } \
RodColeman 0:8f5825f330b0 490 } \
RodColeman 0:8f5825f330b0 491 }
RodColeman 0:8f5825f330b0 492
RodColeman 0:8f5825f330b0 493 #define ACKCIDNS(opt, neg, addr) \
RodColeman 0:8f5825f330b0 494 if (neg) { \
RodColeman 0:8f5825f330b0 495 u32_t l; \
RodColeman 0:8f5825f330b0 496 if ((len -= CILEN_ADDR) < 0) { \
RodColeman 0:8f5825f330b0 497 goto bad; \
RodColeman 0:8f5825f330b0 498 } \
RodColeman 0:8f5825f330b0 499 GETCHAR(citype, p); \
RodColeman 0:8f5825f330b0 500 GETCHAR(cilen, p); \
RodColeman 0:8f5825f330b0 501 if (cilen != CILEN_ADDR || \
RodColeman 0:8f5825f330b0 502 citype != opt) { \
RodColeman 0:8f5825f330b0 503 goto bad; \
RodColeman 0:8f5825f330b0 504 } \
RodColeman 0:8f5825f330b0 505 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 506 cilong = htonl(l); \
RodColeman 0:8f5825f330b0 507 if (addr != cilong) { \
RodColeman 0:8f5825f330b0 508 goto bad; \
RodColeman 0:8f5825f330b0 509 } \
RodColeman 0:8f5825f330b0 510 }
RodColeman 0:8f5825f330b0 511
RodColeman 0:8f5825f330b0 512 ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
RodColeman 0:8f5825f330b0 513 go->old_addrs, go->ouraddr, go->hisaddr);
RodColeman 0:8f5825f330b0 514
RodColeman 0:8f5825f330b0 515 ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
RodColeman 0:8f5825f330b0 516 go->maxslotindex, go->cflag);
RodColeman 0:8f5825f330b0 517
RodColeman 0:8f5825f330b0 518 ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
RodColeman 0:8f5825f330b0 519
RodColeman 0:8f5825f330b0 520 ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
RodColeman 0:8f5825f330b0 521
RodColeman 0:8f5825f330b0 522 /*
RodColeman 0:8f5825f330b0 523 * If there are any remaining CIs, then this packet is bad.
RodColeman 0:8f5825f330b0 524 */
RodColeman 0:8f5825f330b0 525 if (len != 0) {
RodColeman 0:8f5825f330b0 526 goto bad;
RodColeman 0:8f5825f330b0 527 }
RodColeman 0:8f5825f330b0 528 return (1);
RodColeman 0:8f5825f330b0 529
RodColeman 0:8f5825f330b0 530 bad:
RodColeman 0:8f5825f330b0 531 IPCPDEBUG(LOG_INFO, ("ipcp_ackci: received bad Ack!\n"));
RodColeman 0:8f5825f330b0 532 return (0);
RodColeman 0:8f5825f330b0 533 }
RodColeman 0:8f5825f330b0 534
RodColeman 0:8f5825f330b0 535 /*
RodColeman 0:8f5825f330b0 536 * ipcp_nakci - Peer has sent a NAK for some of our CIs.
RodColeman 0:8f5825f330b0 537 * This should not modify any state if the Nak is bad
RodColeman 0:8f5825f330b0 538 * or if IPCP is in the LS_OPENED state.
RodColeman 0:8f5825f330b0 539 *
RodColeman 0:8f5825f330b0 540 * Returns:
RodColeman 0:8f5825f330b0 541 * 0 - Nak was bad.
RodColeman 0:8f5825f330b0 542 * 1 - Nak was good.
RodColeman 0:8f5825f330b0 543 */
RodColeman 0:8f5825f330b0 544 static int
RodColeman 0:8f5825f330b0 545 ipcp_nakci(fsm *f, u_char *p, int len)
RodColeman 0:8f5825f330b0 546 {
RodColeman 0:8f5825f330b0 547 ipcp_options *go = &ipcp_gotoptions[f->unit];
RodColeman 0:8f5825f330b0 548 u_char cimaxslotindex, cicflag;
RodColeman 0:8f5825f330b0 549 u_char citype, cilen, *next;
RodColeman 0:8f5825f330b0 550 u_short cishort;
RodColeman 0:8f5825f330b0 551 u32_t ciaddr1, ciaddr2, l, cidnsaddr;
RodColeman 0:8f5825f330b0 552 ipcp_options no; /* options we've seen Naks for */
RodColeman 0:8f5825f330b0 553 ipcp_options try; /* options to request next time */
RodColeman 0:8f5825f330b0 554
RodColeman 0:8f5825f330b0 555 BZERO(&no, sizeof(no));
RodColeman 0:8f5825f330b0 556 try = *go;
RodColeman 0:8f5825f330b0 557
RodColeman 0:8f5825f330b0 558 /*
RodColeman 0:8f5825f330b0 559 * Any Nak'd CIs must be in exactly the same order that we sent.
RodColeman 0:8f5825f330b0 560 * Check packet length and CI length at each step.
RodColeman 0:8f5825f330b0 561 * If we find any deviations, then this packet is bad.
RodColeman 0:8f5825f330b0 562 */
RodColeman 0:8f5825f330b0 563 #define NAKCIADDR(opt, neg, old, code) \
RodColeman 0:8f5825f330b0 564 if (go->neg && \
RodColeman 0:8f5825f330b0 565 len >= (cilen = (old? CILEN_ADDRS: CILEN_ADDR)) && \
RodColeman 0:8f5825f330b0 566 p[1] == cilen && \
RodColeman 0:8f5825f330b0 567 p[0] == opt) { \
RodColeman 0:8f5825f330b0 568 len -= cilen; \
RodColeman 0:8f5825f330b0 569 INCPTR(2, p); \
RodColeman 0:8f5825f330b0 570 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 571 ciaddr1 = htonl(l); \
RodColeman 0:8f5825f330b0 572 if (old) { \
RodColeman 0:8f5825f330b0 573 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 574 ciaddr2 = htonl(l); \
RodColeman 0:8f5825f330b0 575 no.old_addrs = 1; \
RodColeman 0:8f5825f330b0 576 } else { \
RodColeman 0:8f5825f330b0 577 ciaddr2 = 0; \
RodColeman 0:8f5825f330b0 578 } \
RodColeman 0:8f5825f330b0 579 no.neg = 1; \
RodColeman 0:8f5825f330b0 580 code \
RodColeman 0:8f5825f330b0 581 }
RodColeman 0:8f5825f330b0 582
RodColeman 0:8f5825f330b0 583 #define NAKCIVJ(opt, neg, code) \
RodColeman 0:8f5825f330b0 584 if (go->neg && \
RodColeman 0:8f5825f330b0 585 ((cilen = p[1]) == CILEN_COMPRESS || cilen == CILEN_VJ) && \
RodColeman 0:8f5825f330b0 586 len >= cilen && \
RodColeman 0:8f5825f330b0 587 p[0] == opt) { \
RodColeman 0:8f5825f330b0 588 len -= cilen; \
RodColeman 0:8f5825f330b0 589 INCPTR(2, p); \
RodColeman 0:8f5825f330b0 590 GETSHORT(cishort, p); \
RodColeman 0:8f5825f330b0 591 no.neg = 1; \
RodColeman 0:8f5825f330b0 592 code \
RodColeman 0:8f5825f330b0 593 }
RodColeman 0:8f5825f330b0 594
RodColeman 0:8f5825f330b0 595 #define NAKCIDNS(opt, neg, code) \
RodColeman 0:8f5825f330b0 596 if (go->neg && \
RodColeman 0:8f5825f330b0 597 ((cilen = p[1]) == CILEN_ADDR) && \
RodColeman 0:8f5825f330b0 598 len >= cilen && \
RodColeman 0:8f5825f330b0 599 p[0] == opt) { \
RodColeman 0:8f5825f330b0 600 len -= cilen; \
RodColeman 0:8f5825f330b0 601 INCPTR(2, p); \
RodColeman 0:8f5825f330b0 602 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 603 cidnsaddr = htonl(l); \
RodColeman 0:8f5825f330b0 604 no.neg = 1; \
RodColeman 0:8f5825f330b0 605 code \
RodColeman 0:8f5825f330b0 606 }
RodColeman 0:8f5825f330b0 607
RodColeman 0:8f5825f330b0 608 /*
RodColeman 0:8f5825f330b0 609 * Accept the peer's idea of {our,his} address, if different
RodColeman 0:8f5825f330b0 610 * from our idea, only if the accept_{local,remote} flag is set.
RodColeman 0:8f5825f330b0 611 */
RodColeman 0:8f5825f330b0 612 NAKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr, go->old_addrs,
RodColeman 0:8f5825f330b0 613 if (go->accept_local && ciaddr1) { /* Do we know our address? */
RodColeman 0:8f5825f330b0 614 try.ouraddr = ciaddr1;
RodColeman 0:8f5825f330b0 615 IPCPDEBUG(LOG_INFO, ("local IP address %s\n",
RodColeman 0:8f5825f330b0 616 inet_ntoa(ciaddr1)));
RodColeman 0:8f5825f330b0 617 }
RodColeman 0:8f5825f330b0 618 if (go->accept_remote && ciaddr2) { /* Does he know his? */
RodColeman 0:8f5825f330b0 619 try.hisaddr = ciaddr2;
RodColeman 0:8f5825f330b0 620 IPCPDEBUG(LOG_INFO, ("remote IP address %s\n",
RodColeman 0:8f5825f330b0 621 inet_ntoa(ciaddr2)));
RodColeman 0:8f5825f330b0 622 }
RodColeman 0:8f5825f330b0 623 );
RodColeman 0:8f5825f330b0 624
RodColeman 0:8f5825f330b0 625 /*
RodColeman 0:8f5825f330b0 626 * Accept the peer's value of maxslotindex provided that it
RodColeman 0:8f5825f330b0 627 * is less than what we asked for. Turn off slot-ID compression
RodColeman 0:8f5825f330b0 628 * if the peer wants. Send old-style compress-type option if
RodColeman 0:8f5825f330b0 629 * the peer wants.
RodColeman 0:8f5825f330b0 630 */
RodColeman 0:8f5825f330b0 631 NAKCIVJ(CI_COMPRESSTYPE, neg_vj,
RodColeman 0:8f5825f330b0 632 if (cilen == CILEN_VJ) {
RodColeman 0:8f5825f330b0 633 GETCHAR(cimaxslotindex, p);
RodColeman 0:8f5825f330b0 634 GETCHAR(cicflag, p);
RodColeman 0:8f5825f330b0 635 if (cishort == IPCP_VJ_COMP) {
RodColeman 0:8f5825f330b0 636 try.old_vj = 0;
RodColeman 0:8f5825f330b0 637 if (cimaxslotindex < go->maxslotindex) {
RodColeman 0:8f5825f330b0 638 try.maxslotindex = cimaxslotindex;
RodColeman 0:8f5825f330b0 639 }
RodColeman 0:8f5825f330b0 640 if (!cicflag) {
RodColeman 0:8f5825f330b0 641 try.cflag = 0;
RodColeman 0:8f5825f330b0 642 }
RodColeman 0:8f5825f330b0 643 } else {
RodColeman 0:8f5825f330b0 644 try.neg_vj = 0;
RodColeman 0:8f5825f330b0 645 }
RodColeman 0:8f5825f330b0 646 } else {
RodColeman 0:8f5825f330b0 647 if (cishort == IPCP_VJ_COMP || cishort == IPCP_VJ_COMP_OLD) {
RodColeman 0:8f5825f330b0 648 try.old_vj = 1;
RodColeman 0:8f5825f330b0 649 try.vj_protocol = cishort;
RodColeman 0:8f5825f330b0 650 } else {
RodColeman 0:8f5825f330b0 651 try.neg_vj = 0;
RodColeman 0:8f5825f330b0 652 }
RodColeman 0:8f5825f330b0 653 }
RodColeman 0:8f5825f330b0 654 );
RodColeman 0:8f5825f330b0 655
RodColeman 0:8f5825f330b0 656 NAKCIDNS(CI_MS_DNS1, req_dns1,
RodColeman 0:8f5825f330b0 657 try.dnsaddr[0] = cidnsaddr;
RodColeman 0:8f5825f330b0 658 IPCPDEBUG(LOG_INFO, ("primary DNS address %s\n", inet_ntoa(cidnsaddr)));
RodColeman 0:8f5825f330b0 659 );
RodColeman 0:8f5825f330b0 660
RodColeman 0:8f5825f330b0 661 NAKCIDNS(CI_MS_DNS2, req_dns2,
RodColeman 0:8f5825f330b0 662 try.dnsaddr[1] = cidnsaddr;
RodColeman 0:8f5825f330b0 663 IPCPDEBUG(LOG_INFO, ("secondary DNS address %s\n", inet_ntoa(cidnsaddr)));
RodColeman 0:8f5825f330b0 664 );
RodColeman 0:8f5825f330b0 665
RodColeman 0:8f5825f330b0 666 /*
RodColeman 0:8f5825f330b0 667 * There may be remaining CIs, if the peer is requesting negotiation
RodColeman 0:8f5825f330b0 668 * on an option that we didn't include in our request packet.
RodColeman 0:8f5825f330b0 669 * If they want to negotiate about IP addresses, we comply.
RodColeman 0:8f5825f330b0 670 * If they want us to ask for compression, we refuse.
RodColeman 0:8f5825f330b0 671 */
RodColeman 0:8f5825f330b0 672 while (len > CILEN_VOID) {
RodColeman 0:8f5825f330b0 673 GETCHAR(citype, p);
RodColeman 0:8f5825f330b0 674 GETCHAR(cilen, p);
RodColeman 0:8f5825f330b0 675 if( (len -= cilen) < 0 ) {
RodColeman 0:8f5825f330b0 676 goto bad;
RodColeman 0:8f5825f330b0 677 }
RodColeman 0:8f5825f330b0 678 next = p + cilen - 2;
RodColeman 0:8f5825f330b0 679
RodColeman 0:8f5825f330b0 680 switch (citype) {
RodColeman 0:8f5825f330b0 681 case CI_COMPRESSTYPE:
RodColeman 0:8f5825f330b0 682 if (go->neg_vj || no.neg_vj ||
RodColeman 0:8f5825f330b0 683 (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
RodColeman 0:8f5825f330b0 684 goto bad;
RodColeman 0:8f5825f330b0 685 }
RodColeman 0:8f5825f330b0 686 no.neg_vj = 1;
RodColeman 0:8f5825f330b0 687 break;
RodColeman 0:8f5825f330b0 688 case CI_ADDRS:
RodColeman 0:8f5825f330b0 689 if ((go->neg_addr && go->old_addrs) || no.old_addrs
RodColeman 0:8f5825f330b0 690 || cilen != CILEN_ADDRS) {
RodColeman 0:8f5825f330b0 691 goto bad;
RodColeman 0:8f5825f330b0 692 }
RodColeman 0:8f5825f330b0 693 try.neg_addr = 1;
RodColeman 0:8f5825f330b0 694 try.old_addrs = 1;
RodColeman 0:8f5825f330b0 695 GETLONG(l, p);
RodColeman 0:8f5825f330b0 696 ciaddr1 = htonl(l);
RodColeman 0:8f5825f330b0 697 if (ciaddr1 && go->accept_local) {
RodColeman 0:8f5825f330b0 698 try.ouraddr = ciaddr1;
RodColeman 0:8f5825f330b0 699 }
RodColeman 0:8f5825f330b0 700 GETLONG(l, p);
RodColeman 0:8f5825f330b0 701 ciaddr2 = htonl(l);
RodColeman 0:8f5825f330b0 702 if (ciaddr2 && go->accept_remote) {
RodColeman 0:8f5825f330b0 703 try.hisaddr = ciaddr2;
RodColeman 0:8f5825f330b0 704 }
RodColeman 0:8f5825f330b0 705 no.old_addrs = 1;
RodColeman 0:8f5825f330b0 706 break;
RodColeman 0:8f5825f330b0 707 case CI_ADDR:
RodColeman 0:8f5825f330b0 708 if (go->neg_addr || no.neg_addr || cilen != CILEN_ADDR) {
RodColeman 0:8f5825f330b0 709 goto bad;
RodColeman 0:8f5825f330b0 710 }
RodColeman 0:8f5825f330b0 711 try.old_addrs = 0;
RodColeman 0:8f5825f330b0 712 GETLONG(l, p);
RodColeman 0:8f5825f330b0 713 ciaddr1 = htonl(l);
RodColeman 0:8f5825f330b0 714 if (ciaddr1 && go->accept_local) {
RodColeman 0:8f5825f330b0 715 try.ouraddr = ciaddr1;
RodColeman 0:8f5825f330b0 716 }
RodColeman 0:8f5825f330b0 717 if (try.ouraddr != 0) {
RodColeman 0:8f5825f330b0 718 try.neg_addr = 1;
RodColeman 0:8f5825f330b0 719 }
RodColeman 0:8f5825f330b0 720 no.neg_addr = 1;
RodColeman 0:8f5825f330b0 721 break;
RodColeman 0:8f5825f330b0 722 }
RodColeman 0:8f5825f330b0 723 p = next;
RodColeman 0:8f5825f330b0 724 }
RodColeman 0:8f5825f330b0 725
RodColeman 0:8f5825f330b0 726 /* If there is still anything left, this packet is bad. */
RodColeman 0:8f5825f330b0 727 if (len != 0) {
RodColeman 0:8f5825f330b0 728 goto bad;
RodColeman 0:8f5825f330b0 729 }
RodColeman 0:8f5825f330b0 730
RodColeman 0:8f5825f330b0 731 /*
RodColeman 0:8f5825f330b0 732 * OK, the Nak is good. Now we can update state.
RodColeman 0:8f5825f330b0 733 */
RodColeman 0:8f5825f330b0 734 if (f->state != LS_OPENED) {
RodColeman 0:8f5825f330b0 735 *go = try;
RodColeman 0:8f5825f330b0 736 }
RodColeman 0:8f5825f330b0 737
RodColeman 0:8f5825f330b0 738 return 1;
RodColeman 0:8f5825f330b0 739
RodColeman 0:8f5825f330b0 740 bad:
RodColeman 0:8f5825f330b0 741 IPCPDEBUG(LOG_INFO, ("ipcp_nakci: received bad Nak!\n"));
RodColeman 0:8f5825f330b0 742 return 0;
RodColeman 0:8f5825f330b0 743 }
RodColeman 0:8f5825f330b0 744
RodColeman 0:8f5825f330b0 745
RodColeman 0:8f5825f330b0 746 /*
RodColeman 0:8f5825f330b0 747 * ipcp_rejci - Reject some of our CIs.
RodColeman 0:8f5825f330b0 748 */
RodColeman 0:8f5825f330b0 749 static int
RodColeman 0:8f5825f330b0 750 ipcp_rejci(fsm *f, u_char *p, int len)
RodColeman 0:8f5825f330b0 751 {
RodColeman 0:8f5825f330b0 752 ipcp_options *go = &ipcp_gotoptions[f->unit];
RodColeman 0:8f5825f330b0 753 u_char cimaxslotindex, ciflag, cilen;
RodColeman 0:8f5825f330b0 754 u_short cishort;
RodColeman 0:8f5825f330b0 755 u32_t cilong;
RodColeman 0:8f5825f330b0 756 ipcp_options try; /* options to request next time */
RodColeman 0:8f5825f330b0 757
RodColeman 0:8f5825f330b0 758 try = *go;
RodColeman 0:8f5825f330b0 759 /*
RodColeman 0:8f5825f330b0 760 * Any Rejected CIs must be in exactly the same order that we sent.
RodColeman 0:8f5825f330b0 761 * Check packet length and CI length at each step.
RodColeman 0:8f5825f330b0 762 * If we find any deviations, then this packet is bad.
RodColeman 0:8f5825f330b0 763 */
RodColeman 0:8f5825f330b0 764 #define REJCIADDR(opt, neg, old, val1, val2) \
RodColeman 0:8f5825f330b0 765 if (go->neg && \
RodColeman 0:8f5825f330b0 766 len >= (cilen = old? CILEN_ADDRS: CILEN_ADDR) && \
RodColeman 0:8f5825f330b0 767 p[1] == cilen && \
RodColeman 0:8f5825f330b0 768 p[0] == opt) { \
RodColeman 0:8f5825f330b0 769 u32_t l; \
RodColeman 0:8f5825f330b0 770 len -= cilen; \
RodColeman 0:8f5825f330b0 771 INCPTR(2, p); \
RodColeman 0:8f5825f330b0 772 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 773 cilong = htonl(l); \
RodColeman 0:8f5825f330b0 774 /* Check rejected value. */ \
RodColeman 0:8f5825f330b0 775 if (cilong != val1) { \
RodColeman 0:8f5825f330b0 776 goto bad; \
RodColeman 0:8f5825f330b0 777 } \
RodColeman 0:8f5825f330b0 778 if (old) { \
RodColeman 0:8f5825f330b0 779 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 780 cilong = htonl(l); \
RodColeman 0:8f5825f330b0 781 /* Check rejected value. */ \
RodColeman 0:8f5825f330b0 782 if (cilong != val2) { \
RodColeman 0:8f5825f330b0 783 goto bad; \
RodColeman 0:8f5825f330b0 784 } \
RodColeman 0:8f5825f330b0 785 } \
RodColeman 0:8f5825f330b0 786 try.neg = 0; \
RodColeman 0:8f5825f330b0 787 }
RodColeman 0:8f5825f330b0 788
RodColeman 0:8f5825f330b0 789 #define REJCIVJ(opt, neg, val, old, maxslot, cflag) \
RodColeman 0:8f5825f330b0 790 if (go->neg && \
RodColeman 0:8f5825f330b0 791 p[1] == (old? CILEN_COMPRESS : CILEN_VJ) && \
RodColeman 0:8f5825f330b0 792 len >= p[1] && \
RodColeman 0:8f5825f330b0 793 p[0] == opt) { \
RodColeman 0:8f5825f330b0 794 len -= p[1]; \
RodColeman 0:8f5825f330b0 795 INCPTR(2, p); \
RodColeman 0:8f5825f330b0 796 GETSHORT(cishort, p); \
RodColeman 0:8f5825f330b0 797 /* Check rejected value. */ \
RodColeman 0:8f5825f330b0 798 if (cishort != val) { \
RodColeman 0:8f5825f330b0 799 goto bad; \
RodColeman 0:8f5825f330b0 800 } \
RodColeman 0:8f5825f330b0 801 if (!old) { \
RodColeman 0:8f5825f330b0 802 GETCHAR(cimaxslotindex, p); \
RodColeman 0:8f5825f330b0 803 if (cimaxslotindex != maxslot) { \
RodColeman 0:8f5825f330b0 804 goto bad; \
RodColeman 0:8f5825f330b0 805 } \
RodColeman 0:8f5825f330b0 806 GETCHAR(ciflag, p); \
RodColeman 0:8f5825f330b0 807 if (ciflag != cflag) { \
RodColeman 0:8f5825f330b0 808 goto bad; \
RodColeman 0:8f5825f330b0 809 } \
RodColeman 0:8f5825f330b0 810 } \
RodColeman 0:8f5825f330b0 811 try.neg = 0; \
RodColeman 0:8f5825f330b0 812 }
RodColeman 0:8f5825f330b0 813
RodColeman 0:8f5825f330b0 814 #define REJCIDNS(opt, neg, dnsaddr) \
RodColeman 0:8f5825f330b0 815 if (go->neg && \
RodColeman 0:8f5825f330b0 816 ((cilen = p[1]) == CILEN_ADDR) && \
RodColeman 0:8f5825f330b0 817 len >= cilen && \
RodColeman 0:8f5825f330b0 818 p[0] == opt) { \
RodColeman 0:8f5825f330b0 819 u32_t l; \
RodColeman 0:8f5825f330b0 820 len -= cilen; \
RodColeman 0:8f5825f330b0 821 INCPTR(2, p); \
RodColeman 0:8f5825f330b0 822 GETLONG(l, p); \
RodColeman 0:8f5825f330b0 823 cilong = htonl(l); \
RodColeman 0:8f5825f330b0 824 /* Check rejected value. */ \
RodColeman 0:8f5825f330b0 825 if (cilong != dnsaddr) { \
RodColeman 0:8f5825f330b0 826 goto bad; \
RodColeman 0:8f5825f330b0 827 } \
RodColeman 0:8f5825f330b0 828 try.neg = 0; \
RodColeman 0:8f5825f330b0 829 }
RodColeman 0:8f5825f330b0 830
RodColeman 0:8f5825f330b0 831 REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
RodColeman 0:8f5825f330b0 832 go->old_addrs, go->ouraddr, go->hisaddr);
RodColeman 0:8f5825f330b0 833
RodColeman 0:8f5825f330b0 834 REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
RodColeman 0:8f5825f330b0 835 go->maxslotindex, go->cflag);
RodColeman 0:8f5825f330b0 836
RodColeman 0:8f5825f330b0 837 REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
RodColeman 0:8f5825f330b0 838
RodColeman 0:8f5825f330b0 839 REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
RodColeman 0:8f5825f330b0 840
RodColeman 0:8f5825f330b0 841 /*
RodColeman 0:8f5825f330b0 842 * If there are any remaining CIs, then this packet is bad.
RodColeman 0:8f5825f330b0 843 */
RodColeman 0:8f5825f330b0 844 if (len != 0) {
RodColeman 0:8f5825f330b0 845 goto bad;
RodColeman 0:8f5825f330b0 846 }
RodColeman 0:8f5825f330b0 847 /*
RodColeman 0:8f5825f330b0 848 * Now we can update state.
RodColeman 0:8f5825f330b0 849 */
RodColeman 0:8f5825f330b0 850 if (f->state != LS_OPENED) {
RodColeman 0:8f5825f330b0 851 *go = try;
RodColeman 0:8f5825f330b0 852 }
RodColeman 0:8f5825f330b0 853 return 1;
RodColeman 0:8f5825f330b0 854
RodColeman 0:8f5825f330b0 855 bad:
RodColeman 0:8f5825f330b0 856 IPCPDEBUG(LOG_INFO, ("ipcp_rejci: received bad Reject!\n"));
RodColeman 0:8f5825f330b0 857 return 0;
RodColeman 0:8f5825f330b0 858 }
RodColeman 0:8f5825f330b0 859
RodColeman 0:8f5825f330b0 860
RodColeman 0:8f5825f330b0 861 /*
RodColeman 0:8f5825f330b0 862 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
RodColeman 0:8f5825f330b0 863 *
RodColeman 0:8f5825f330b0 864 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
RodColeman 0:8f5825f330b0 865 * appropriately. If reject_if_disagree is non-zero, doesn't return
RodColeman 0:8f5825f330b0 866 * CONFNAK; returns CONFREJ if it can't return CONFACK.
RodColeman 0:8f5825f330b0 867 */
RodColeman 0:8f5825f330b0 868 static int
RodColeman 0:8f5825f330b0 869 ipcp_reqci(fsm *f, u_char *inp/* Requested CIs */,int *len/* Length of requested CIs */,int reject_if_disagree)
RodColeman 0:8f5825f330b0 870 {
RodColeman 0:8f5825f330b0 871 ipcp_options *wo = &ipcp_wantoptions[f->unit];
RodColeman 0:8f5825f330b0 872 ipcp_options *ho = &ipcp_hisoptions[f->unit];
RodColeman 0:8f5825f330b0 873 ipcp_options *ao = &ipcp_allowoptions[f->unit];
RodColeman 0:8f5825f330b0 874 #ifdef OLD_CI_ADDRS
RodColeman 0:8f5825f330b0 875 ipcp_options *go = &ipcp_gotoptions[f->unit];
RodColeman 0:8f5825f330b0 876 #endif
RodColeman 0:8f5825f330b0 877 u_char *cip, *next; /* Pointer to current and next CIs */
RodColeman 0:8f5825f330b0 878 u_short cilen, citype; /* Parsed len, type */
RodColeman 0:8f5825f330b0 879 u_short cishort; /* Parsed short value */
RodColeman 0:8f5825f330b0 880 u32_t tl, ciaddr1; /* Parsed address values */
RodColeman 0:8f5825f330b0 881 #ifdef OLD_CI_ADDRS
RodColeman 0:8f5825f330b0 882 u32_t ciaddr2; /* Parsed address values */
RodColeman 0:8f5825f330b0 883 #endif
RodColeman 0:8f5825f330b0 884 int rc = CONFACK; /* Final packet return code */
RodColeman 0:8f5825f330b0 885 int orc; /* Individual option return code */
RodColeman 0:8f5825f330b0 886 u_char *p; /* Pointer to next char to parse */
RodColeman 0:8f5825f330b0 887 u_char *ucp = inp; /* Pointer to current output char */
RodColeman 0:8f5825f330b0 888 int l = *len; /* Length left */
RodColeman 0:8f5825f330b0 889 u_char maxslotindex, cflag;
RodColeman 0:8f5825f330b0 890 int d;
RodColeman 0:8f5825f330b0 891
RodColeman 0:8f5825f330b0 892 cis_received[f->unit] = 1;
RodColeman 0:8f5825f330b0 893
RodColeman 0:8f5825f330b0 894 /*
RodColeman 0:8f5825f330b0 895 * Reset all his options.
RodColeman 0:8f5825f330b0 896 */
RodColeman 0:8f5825f330b0 897 BZERO(ho, sizeof(*ho));
RodColeman 0:8f5825f330b0 898
RodColeman 0:8f5825f330b0 899 /*
RodColeman 0:8f5825f330b0 900 * Process all his options.
RodColeman 0:8f5825f330b0 901 */
RodColeman 0:8f5825f330b0 902 next = inp;
RodColeman 0:8f5825f330b0 903 while (l) {
RodColeman 0:8f5825f330b0 904 orc = CONFACK; /* Assume success */
RodColeman 0:8f5825f330b0 905 cip = p = next; /* Remember begining of CI */
RodColeman 0:8f5825f330b0 906 if (l < 2 || /* Not enough data for CI header or */
RodColeman 0:8f5825f330b0 907 p[1] < 2 || /* CI length too small or */
RodColeman 0:8f5825f330b0 908 p[1] > l) { /* CI length too big? */
RodColeman 0:8f5825f330b0 909 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: bad CI length!\n"));
RodColeman 0:8f5825f330b0 910 orc = CONFREJ; /* Reject bad CI */
RodColeman 0:8f5825f330b0 911 cilen = (u_short)l;/* Reject till end of packet */
RodColeman 0:8f5825f330b0 912 l = 0; /* Don't loop again */
RodColeman 0:8f5825f330b0 913 goto endswitch;
RodColeman 0:8f5825f330b0 914 }
RodColeman 0:8f5825f330b0 915 GETCHAR(citype, p); /* Parse CI type */
RodColeman 0:8f5825f330b0 916 GETCHAR(cilen, p); /* Parse CI length */
RodColeman 0:8f5825f330b0 917 l -= cilen; /* Adjust remaining length */
RodColeman 0:8f5825f330b0 918 next += cilen; /* Step to next CI */
RodColeman 0:8f5825f330b0 919
RodColeman 0:8f5825f330b0 920 switch (citype) { /* Check CI type */
RodColeman 0:8f5825f330b0 921 #ifdef OLD_CI_ADDRS /* Need to save space... */
RodColeman 0:8f5825f330b0 922 case CI_ADDRS:
RodColeman 0:8f5825f330b0 923 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: received ADDRS\n"));
RodColeman 0:8f5825f330b0 924 if (!ao->neg_addr ||
RodColeman 0:8f5825f330b0 925 cilen != CILEN_ADDRS) { /* Check CI length */
RodColeman 0:8f5825f330b0 926 orc = CONFREJ; /* Reject CI */
RodColeman 0:8f5825f330b0 927 break;
RodColeman 0:8f5825f330b0 928 }
RodColeman 0:8f5825f330b0 929
RodColeman 0:8f5825f330b0 930 /*
RodColeman 0:8f5825f330b0 931 * If he has no address, or if we both have his address but
RodColeman 0:8f5825f330b0 932 * disagree about it, then NAK it with our idea.
RodColeman 0:8f5825f330b0 933 * In particular, if we don't know his address, but he does,
RodColeman 0:8f5825f330b0 934 * then accept it.
RodColeman 0:8f5825f330b0 935 */
RodColeman 0:8f5825f330b0 936 GETLONG(tl, p); /* Parse source address (his) */
RodColeman 0:8f5825f330b0 937 ciaddr1 = htonl(tl);
RodColeman 0:8f5825f330b0 938 IPCPDEBUG(LOG_INFO, ("his addr %s\n", inet_ntoa(ciaddr1)));
RodColeman 0:8f5825f330b0 939 if (ciaddr1 != wo->hisaddr
RodColeman 0:8f5825f330b0 940 && (ciaddr1 == 0 || !wo->accept_remote)) {
RodColeman 0:8f5825f330b0 941 orc = CONFNAK;
RodColeman 0:8f5825f330b0 942 if (!reject_if_disagree) {
RodColeman 0:8f5825f330b0 943 DECPTR(sizeof(u32_t), p);
RodColeman 0:8f5825f330b0 944 tl = ntohl(wo->hisaddr);
RodColeman 0:8f5825f330b0 945 PUTLONG(tl, p);
RodColeman 0:8f5825f330b0 946 }
RodColeman 0:8f5825f330b0 947 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
RodColeman 0:8f5825f330b0 948 /*
RodColeman 0:8f5825f330b0 949 * If neither we nor he knows his address, reject the option.
RodColeman 0:8f5825f330b0 950 */
RodColeman 0:8f5825f330b0 951 orc = CONFREJ;
RodColeman 0:8f5825f330b0 952 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
RodColeman 0:8f5825f330b0 953 break;
RodColeman 0:8f5825f330b0 954 }
RodColeman 0:8f5825f330b0 955
RodColeman 0:8f5825f330b0 956 /*
RodColeman 0:8f5825f330b0 957 * If he doesn't know our address, or if we both have our address
RodColeman 0:8f5825f330b0 958 * but disagree about it, then NAK it with our idea.
RodColeman 0:8f5825f330b0 959 */
RodColeman 0:8f5825f330b0 960 GETLONG(tl, p); /* Parse desination address (ours) */
RodColeman 0:8f5825f330b0 961 ciaddr2 = htonl(tl);
RodColeman 0:8f5825f330b0 962 IPCPDEBUG(LOG_INFO, ("our addr %s\n", inet_ntoa(ciaddr2)));
RodColeman 0:8f5825f330b0 963 if (ciaddr2 != wo->ouraddr) {
RodColeman 0:8f5825f330b0 964 if (ciaddr2 == 0 || !wo->accept_local) {
RodColeman 0:8f5825f330b0 965 orc = CONFNAK;
RodColeman 0:8f5825f330b0 966 if (!reject_if_disagree) {
RodColeman 0:8f5825f330b0 967 DECPTR(sizeof(u32_t), p);
RodColeman 0:8f5825f330b0 968 tl = ntohl(wo->ouraddr);
RodColeman 0:8f5825f330b0 969 PUTLONG(tl, p);
RodColeman 0:8f5825f330b0 970 }
RodColeman 0:8f5825f330b0 971 } else {
RodColeman 0:8f5825f330b0 972 go->ouraddr = ciaddr2; /* accept peer's idea */
RodColeman 0:8f5825f330b0 973 }
RodColeman 0:8f5825f330b0 974 }
RodColeman 0:8f5825f330b0 975
RodColeman 0:8f5825f330b0 976 ho->neg_addr = 1;
RodColeman 0:8f5825f330b0 977 ho->old_addrs = 1;
RodColeman 0:8f5825f330b0 978 ho->hisaddr = ciaddr1;
RodColeman 0:8f5825f330b0 979 ho->ouraddr = ciaddr2;
RodColeman 0:8f5825f330b0 980 break;
RodColeman 0:8f5825f330b0 981 #endif
RodColeman 0:8f5825f330b0 982
RodColeman 0:8f5825f330b0 983 case CI_ADDR:
RodColeman 0:8f5825f330b0 984 if (!ao->neg_addr) {
RodColeman 0:8f5825f330b0 985 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Reject ADDR not allowed\n"));
RodColeman 0:8f5825f330b0 986 orc = CONFREJ; /* Reject CI */
RodColeman 0:8f5825f330b0 987 break;
RodColeman 0:8f5825f330b0 988 } else if (cilen != CILEN_ADDR) { /* Check CI length */
RodColeman 0:8f5825f330b0 989 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Reject ADDR bad len\n"));
RodColeman 0:8f5825f330b0 990 orc = CONFREJ; /* Reject CI */
RodColeman 0:8f5825f330b0 991 break;
RodColeman 0:8f5825f330b0 992 }
RodColeman 0:8f5825f330b0 993
RodColeman 0:8f5825f330b0 994 /*
RodColeman 0:8f5825f330b0 995 * If he has no address, or if we both have his address but
RodColeman 0:8f5825f330b0 996 * disagree about it, then NAK it with our idea.
RodColeman 0:8f5825f330b0 997 * In particular, if we don't know his address, but he does,
RodColeman 0:8f5825f330b0 998 * then accept it.
RodColeman 0:8f5825f330b0 999 */
RodColeman 0:8f5825f330b0 1000 GETLONG(tl, p); /* Parse source address (his) */
RodColeman 0:8f5825f330b0 1001 ciaddr1 = htonl(tl);
RodColeman 0:8f5825f330b0 1002 if (ciaddr1 != wo->hisaddr
RodColeman 0:8f5825f330b0 1003 && (ciaddr1 == 0 || !wo->accept_remote)) {
RodColeman 0:8f5825f330b0 1004 orc = CONFNAK;
RodColeman 0:8f5825f330b0 1005 if (!reject_if_disagree) {
RodColeman 0:8f5825f330b0 1006 DECPTR(sizeof(u32_t), p);
RodColeman 0:8f5825f330b0 1007 tl = ntohl(wo->hisaddr);
RodColeman 0:8f5825f330b0 1008 PUTLONG(tl, p);
RodColeman 0:8f5825f330b0 1009 }
RodColeman 0:8f5825f330b0 1010 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Nak ADDR %s\n", inet_ntoa(ciaddr1)));
RodColeman 0:8f5825f330b0 1011 } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
RodColeman 0:8f5825f330b0 1012 /*
RodColeman 0:8f5825f330b0 1013 * Don't ACK an address of 0.0.0.0 - reject it instead.
RodColeman 0:8f5825f330b0 1014 */
RodColeman 0:8f5825f330b0 1015 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Reject ADDR %s\n", inet_ntoa(ciaddr1)));
RodColeman 0:8f5825f330b0 1016 orc = CONFREJ;
RodColeman 0:8f5825f330b0 1017 wo->req_addr = 0; /* don't NAK with 0.0.0.0 later */
RodColeman 0:8f5825f330b0 1018 break;
RodColeman 0:8f5825f330b0 1019 }
RodColeman 0:8f5825f330b0 1020
RodColeman 0:8f5825f330b0 1021 ho->neg_addr = 1;
RodColeman 0:8f5825f330b0 1022 ho->hisaddr = ciaddr1;
RodColeman 0:8f5825f330b0 1023 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: ADDR %s\n", inet_ntoa(ciaddr1)));
RodColeman 0:8f5825f330b0 1024 break;
RodColeman 0:8f5825f330b0 1025
RodColeman 0:8f5825f330b0 1026 case CI_MS_DNS1:
RodColeman 0:8f5825f330b0 1027 case CI_MS_DNS2:
RodColeman 0:8f5825f330b0 1028 /* Microsoft primary or secondary DNS request */
RodColeman 0:8f5825f330b0 1029 d = citype == CI_MS_DNS2;
RodColeman 0:8f5825f330b0 1030
RodColeman 0:8f5825f330b0 1031 /* If we do not have a DNS address then we cannot send it */
RodColeman 0:8f5825f330b0 1032 if (ao->dnsaddr[d] == 0 ||
RodColeman 0:8f5825f330b0 1033 cilen != CILEN_ADDR) { /* Check CI length */
RodColeman 0:8f5825f330b0 1034 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting DNS%d Request\n", d+1));
RodColeman 0:8f5825f330b0 1035 orc = CONFREJ; /* Reject CI */
RodColeman 0:8f5825f330b0 1036 break;
RodColeman 0:8f5825f330b0 1037 }
RodColeman 0:8f5825f330b0 1038 GETLONG(tl, p);
RodColeman 0:8f5825f330b0 1039 if (htonl(tl) != ao->dnsaddr[d]) {
RodColeman 0:8f5825f330b0 1040 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Naking DNS%d Request %s\n",
RodColeman 0:8f5825f330b0 1041 d+1, inet_ntoa(tl)));
RodColeman 0:8f5825f330b0 1042 DECPTR(sizeof(u32_t), p);
RodColeman 0:8f5825f330b0 1043 tl = ntohl(ao->dnsaddr[d]);
RodColeman 0:8f5825f330b0 1044 PUTLONG(tl, p);
RodColeman 0:8f5825f330b0 1045 orc = CONFNAK;
RodColeman 0:8f5825f330b0 1046 }
RodColeman 0:8f5825f330b0 1047 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: received DNS%d Request\n", d+1));
RodColeman 0:8f5825f330b0 1048 break;
RodColeman 0:8f5825f330b0 1049
RodColeman 0:8f5825f330b0 1050 case CI_MS_WINS1:
RodColeman 0:8f5825f330b0 1051 case CI_MS_WINS2:
RodColeman 0:8f5825f330b0 1052 /* Microsoft primary or secondary WINS request */
RodColeman 0:8f5825f330b0 1053 d = citype == CI_MS_WINS2;
RodColeman 0:8f5825f330b0 1054 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: received WINS%d Request\n", d+1));
RodColeman 0:8f5825f330b0 1055
RodColeman 0:8f5825f330b0 1056 /* If we do not have a DNS address then we cannot send it */
RodColeman 0:8f5825f330b0 1057 if (ao->winsaddr[d] == 0 ||
RodColeman 0:8f5825f330b0 1058 cilen != CILEN_ADDR) { /* Check CI length */
RodColeman 0:8f5825f330b0 1059 orc = CONFREJ; /* Reject CI */
RodColeman 0:8f5825f330b0 1060 break;
RodColeman 0:8f5825f330b0 1061 }
RodColeman 0:8f5825f330b0 1062 GETLONG(tl, p);
RodColeman 0:8f5825f330b0 1063 if (htonl(tl) != ao->winsaddr[d]) {
RodColeman 0:8f5825f330b0 1064 DECPTR(sizeof(u32_t), p);
RodColeman 0:8f5825f330b0 1065 tl = ntohl(ao->winsaddr[d]);
RodColeman 0:8f5825f330b0 1066 PUTLONG(tl, p);
RodColeman 0:8f5825f330b0 1067 orc = CONFNAK;
RodColeman 0:8f5825f330b0 1068 }
RodColeman 0:8f5825f330b0 1069 break;
RodColeman 0:8f5825f330b0 1070
RodColeman 0:8f5825f330b0 1071 case CI_COMPRESSTYPE:
RodColeman 0:8f5825f330b0 1072 if (!ao->neg_vj) {
RodColeman 0:8f5825f330b0 1073 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting COMPRESSTYPE not allowed\n"));
RodColeman 0:8f5825f330b0 1074 orc = CONFREJ;
RodColeman 0:8f5825f330b0 1075 break;
RodColeman 0:8f5825f330b0 1076 } else if (cilen != CILEN_VJ && cilen != CILEN_COMPRESS) {
RodColeman 0:8f5825f330b0 1077 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting COMPRESSTYPE len=%d\n", cilen));
RodColeman 0:8f5825f330b0 1078 orc = CONFREJ;
RodColeman 0:8f5825f330b0 1079 break;
RodColeman 0:8f5825f330b0 1080 }
RodColeman 0:8f5825f330b0 1081 GETSHORT(cishort, p);
RodColeman 0:8f5825f330b0 1082
RodColeman 0:8f5825f330b0 1083 if (!(cishort == IPCP_VJ_COMP ||
RodColeman 0:8f5825f330b0 1084 (cishort == IPCP_VJ_COMP_OLD && cilen == CILEN_COMPRESS))) {
RodColeman 0:8f5825f330b0 1085 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting COMPRESSTYPE %d\n", cishort));
RodColeman 0:8f5825f330b0 1086 orc = CONFREJ;
RodColeman 0:8f5825f330b0 1087 break;
RodColeman 0:8f5825f330b0 1088 }
RodColeman 0:8f5825f330b0 1089
RodColeman 0:8f5825f330b0 1090 ho->neg_vj = 1;
RodColeman 0:8f5825f330b0 1091 ho->vj_protocol = cishort;
RodColeman 0:8f5825f330b0 1092 if (cilen == CILEN_VJ) {
RodColeman 0:8f5825f330b0 1093 GETCHAR(maxslotindex, p);
RodColeman 0:8f5825f330b0 1094 if (maxslotindex > ao->maxslotindex) {
RodColeman 0:8f5825f330b0 1095 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Naking VJ max slot %d\n", maxslotindex));
RodColeman 0:8f5825f330b0 1096 orc = CONFNAK;
RodColeman 0:8f5825f330b0 1097 if (!reject_if_disagree) {
RodColeman 0:8f5825f330b0 1098 DECPTR(1, p);
RodColeman 0:8f5825f330b0 1099 PUTCHAR(ao->maxslotindex, p);
RodColeman 0:8f5825f330b0 1100 }
RodColeman 0:8f5825f330b0 1101 }
RodColeman 0:8f5825f330b0 1102 GETCHAR(cflag, p);
RodColeman 0:8f5825f330b0 1103 if (cflag && !ao->cflag) {
RodColeman 0:8f5825f330b0 1104 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Naking VJ cflag %d\n", cflag));
RodColeman 0:8f5825f330b0 1105 orc = CONFNAK;
RodColeman 0:8f5825f330b0 1106 if (!reject_if_disagree) {
RodColeman 0:8f5825f330b0 1107 DECPTR(1, p);
RodColeman 0:8f5825f330b0 1108 PUTCHAR(wo->cflag, p);
RodColeman 0:8f5825f330b0 1109 }
RodColeman 0:8f5825f330b0 1110 }
RodColeman 0:8f5825f330b0 1111 ho->maxslotindex = maxslotindex;
RodColeman 0:8f5825f330b0 1112 ho->cflag = cflag;
RodColeman 0:8f5825f330b0 1113 } else {
RodColeman 0:8f5825f330b0 1114 ho->old_vj = 1;
RodColeman 0:8f5825f330b0 1115 ho->maxslotindex = MAX_SLOTS - 1;
RodColeman 0:8f5825f330b0 1116 ho->cflag = 1;
RodColeman 0:8f5825f330b0 1117 }
RodColeman 0:8f5825f330b0 1118 IPCPDEBUG(LOG_INFO, (
RodColeman 0:8f5825f330b0 1119 "ipcp_reqci: received COMPRESSTYPE p=%d old=%d maxslot=%d cflag=%d\n",
RodColeman 0:8f5825f330b0 1120 ho->vj_protocol, ho->old_vj, ho->maxslotindex, ho->cflag));
RodColeman 0:8f5825f330b0 1121 break;
RodColeman 0:8f5825f330b0 1122
RodColeman 0:8f5825f330b0 1123 default:
RodColeman 0:8f5825f330b0 1124 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting unknown CI type %d\n", citype));
RodColeman 0:8f5825f330b0 1125 orc = CONFREJ;
RodColeman 0:8f5825f330b0 1126 break;
RodColeman 0:8f5825f330b0 1127 }
RodColeman 0:8f5825f330b0 1128
RodColeman 0:8f5825f330b0 1129 endswitch:
RodColeman 0:8f5825f330b0 1130 if (orc == CONFACK && /* Good CI */
RodColeman 0:8f5825f330b0 1131 rc != CONFACK) { /* but prior CI wasnt? */
RodColeman 0:8f5825f330b0 1132 continue; /* Don't send this one */
RodColeman 0:8f5825f330b0 1133 }
RodColeman 0:8f5825f330b0 1134
RodColeman 0:8f5825f330b0 1135 if (orc == CONFNAK) { /* Nak this CI? */
RodColeman 0:8f5825f330b0 1136 if (reject_if_disagree) { /* Getting fed up with sending NAKs? */
RodColeman 0:8f5825f330b0 1137 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Rejecting too many naks\n"));
RodColeman 0:8f5825f330b0 1138 orc = CONFREJ; /* Get tough if so */
RodColeman 0:8f5825f330b0 1139 } else {
RodColeman 0:8f5825f330b0 1140 if (rc == CONFREJ) { /* Rejecting prior CI? */
RodColeman 0:8f5825f330b0 1141 continue; /* Don't send this one */
RodColeman 0:8f5825f330b0 1142 }
RodColeman 0:8f5825f330b0 1143 if (rc == CONFACK) { /* Ack'd all prior CIs? */
RodColeman 0:8f5825f330b0 1144 rc = CONFNAK; /* Not anymore... */
RodColeman 0:8f5825f330b0 1145 ucp = inp; /* Backup */
RodColeman 0:8f5825f330b0 1146 }
RodColeman 0:8f5825f330b0 1147 }
RodColeman 0:8f5825f330b0 1148 }
RodColeman 0:8f5825f330b0 1149
RodColeman 0:8f5825f330b0 1150 if (orc == CONFREJ && /* Reject this CI */
RodColeman 0:8f5825f330b0 1151 rc != CONFREJ) { /* but no prior ones? */
RodColeman 0:8f5825f330b0 1152 rc = CONFREJ;
RodColeman 0:8f5825f330b0 1153 ucp = inp; /* Backup */
RodColeman 0:8f5825f330b0 1154 }
RodColeman 0:8f5825f330b0 1155
RodColeman 0:8f5825f330b0 1156 /* Need to move CI? */
RodColeman 0:8f5825f330b0 1157 if (ucp != cip) {
RodColeman 0:8f5825f330b0 1158 BCOPY(cip, ucp, cilen); /* Move it */
RodColeman 0:8f5825f330b0 1159 }
RodColeman 0:8f5825f330b0 1160
RodColeman 0:8f5825f330b0 1161 /* Update output pointer */
RodColeman 0:8f5825f330b0 1162 INCPTR(cilen, ucp);
RodColeman 0:8f5825f330b0 1163 }
RodColeman 0:8f5825f330b0 1164
RodColeman 0:8f5825f330b0 1165 /*
RodColeman 0:8f5825f330b0 1166 * If we aren't rejecting this packet, and we want to negotiate
RodColeman 0:8f5825f330b0 1167 * their address, and they didn't send their address, then we
RodColeman 0:8f5825f330b0 1168 * send a NAK with a CI_ADDR option appended. We assume the
RodColeman 0:8f5825f330b0 1169 * input buffer is long enough that we can append the extra
RodColeman 0:8f5825f330b0 1170 * option safely.
RodColeman 0:8f5825f330b0 1171 */
RodColeman 0:8f5825f330b0 1172 if (rc != CONFREJ && !ho->neg_addr &&
RodColeman 0:8f5825f330b0 1173 wo->req_addr && !reject_if_disagree) {
RodColeman 0:8f5825f330b0 1174 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: Requesting peer address\n"));
RodColeman 0:8f5825f330b0 1175 if (rc == CONFACK) {
RodColeman 0:8f5825f330b0 1176 rc = CONFNAK;
RodColeman 0:8f5825f330b0 1177 ucp = inp; /* reset pointer */
RodColeman 0:8f5825f330b0 1178 wo->req_addr = 0; /* don't ask again */
RodColeman 0:8f5825f330b0 1179 }
RodColeman 0:8f5825f330b0 1180 PUTCHAR(CI_ADDR, ucp);
RodColeman 0:8f5825f330b0 1181 PUTCHAR(CILEN_ADDR, ucp);
RodColeman 0:8f5825f330b0 1182 tl = ntohl(wo->hisaddr);
RodColeman 0:8f5825f330b0 1183 PUTLONG(tl, ucp);
RodColeman 0:8f5825f330b0 1184 }
RodColeman 0:8f5825f330b0 1185
RodColeman 0:8f5825f330b0 1186 *len = (int)(ucp - inp); /* Compute output length */
RodColeman 0:8f5825f330b0 1187 IPCPDEBUG(LOG_INFO, ("ipcp_reqci: returning Configure-%s\n", CODENAME(rc)));
RodColeman 0:8f5825f330b0 1188 return (rc); /* Return final code */
RodColeman 0:8f5825f330b0 1189 }
RodColeman 0:8f5825f330b0 1190
RodColeman 0:8f5825f330b0 1191
RodColeman 0:8f5825f330b0 1192 #if 0
RodColeman 0:8f5825f330b0 1193 /*
RodColeman 0:8f5825f330b0 1194 * ip_check_options - check that any IP-related options are OK,
RodColeman 0:8f5825f330b0 1195 * and assign appropriate defaults.
RodColeman 0:8f5825f330b0 1196 */
RodColeman 0:8f5825f330b0 1197 static void
RodColeman 0:8f5825f330b0 1198 ip_check_options(u_long localAddr)
RodColeman 0:8f5825f330b0 1199 {
RodColeman 0:8f5825f330b0 1200 ipcp_options *wo = &ipcp_wantoptions[0];
RodColeman 0:8f5825f330b0 1201
RodColeman 0:8f5825f330b0 1202 /*
RodColeman 0:8f5825f330b0 1203 * Load our default IP address but allow the remote host to give us
RodColeman 0:8f5825f330b0 1204 * a new address.
RodColeman 0:8f5825f330b0 1205 */
RodColeman 0:8f5825f330b0 1206 if (wo->ouraddr == 0 && !ppp_settings.disable_defaultip) {
RodColeman 0:8f5825f330b0 1207 wo->accept_local = 1; /* don't insist on this default value */
RodColeman 0:8f5825f330b0 1208 wo->ouraddr = htonl(localAddr);
RodColeman 0:8f5825f330b0 1209 }
RodColeman 0:8f5825f330b0 1210 }
RodColeman 0:8f5825f330b0 1211 #endif
RodColeman 0:8f5825f330b0 1212
RodColeman 0:8f5825f330b0 1213
RodColeman 0:8f5825f330b0 1214 /*
RodColeman 0:8f5825f330b0 1215 * ipcp_up - IPCP has come UP.
RodColeman 0:8f5825f330b0 1216 *
RodColeman 0:8f5825f330b0 1217 * Configure the IP network interface appropriately and bring it up.
RodColeman 0:8f5825f330b0 1218 */
RodColeman 0:8f5825f330b0 1219 static void
RodColeman 0:8f5825f330b0 1220 ipcp_up(fsm *f)
RodColeman 0:8f5825f330b0 1221 {
RodColeman 0:8f5825f330b0 1222 u32_t mask;
RodColeman 0:8f5825f330b0 1223 ipcp_options *ho = &ipcp_hisoptions[f->unit];
RodColeman 0:8f5825f330b0 1224 ipcp_options *go = &ipcp_gotoptions[f->unit];
RodColeman 0:8f5825f330b0 1225 ipcp_options *wo = &ipcp_wantoptions[f->unit];
RodColeman 0:8f5825f330b0 1226
RodColeman 0:8f5825f330b0 1227 np_up(f->unit, PPP_IP);
RodColeman 0:8f5825f330b0 1228 IPCPDEBUG(LOG_INFO, ("ipcp: up\n"));
RodColeman 0:8f5825f330b0 1229
RodColeman 0:8f5825f330b0 1230 /*
RodColeman 0:8f5825f330b0 1231 * We must have a non-zero IP address for both ends of the link.
RodColeman 0:8f5825f330b0 1232 */
RodColeman 0:8f5825f330b0 1233 if (!ho->neg_addr) {
RodColeman 0:8f5825f330b0 1234 ho->hisaddr = wo->hisaddr;
RodColeman 0:8f5825f330b0 1235 }
RodColeman 0:8f5825f330b0 1236 #ifdef __PPP_STRICT_IMPL__ //DG : Kludge for bad 3g providers PPP impl
RodColeman 0:8f5825f330b0 1237 if (ho->hisaddr == 0) {
RodColeman 0:8f5825f330b0 1238 IPCPDEBUG(LOG_ERR, ("Could not determine remote IP address\n"));
RodColeman 0:8f5825f330b0 1239 ipcp_close(f->unit, "Could not determine remote IP address");
RodColeman 0:8f5825f330b0 1240 return;
RodColeman 0:8f5825f330b0 1241 }
RodColeman 0:8f5825f330b0 1242 #endif
RodColeman 0:8f5825f330b0 1243 if (go->ouraddr == 0) {
RodColeman 0:8f5825f330b0 1244 IPCPDEBUG(LOG_ERR, ("Could not determine local IP address\n"));
RodColeman 0:8f5825f330b0 1245 ipcp_close(f->unit, "Could not determine local IP address");
RodColeman 0:8f5825f330b0 1246 return;
RodColeman 0:8f5825f330b0 1247 }
RodColeman 0:8f5825f330b0 1248
RodColeman 0:8f5825f330b0 1249 if (ppp_settings.usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
RodColeman 0:8f5825f330b0 1250 /*pppGotDNSAddrs(go->dnsaddr[0], go->dnsaddr[1]);*/
RodColeman 0:8f5825f330b0 1251 }
RodColeman 0:8f5825f330b0 1252
RodColeman 0:8f5825f330b0 1253 /*
RodColeman 0:8f5825f330b0 1254 * Check that the peer is allowed to use the IP address it wants.
RodColeman 0:8f5825f330b0 1255 */
RodColeman 0:8f5825f330b0 1256 if (!auth_ip_addr(f->unit, ho->hisaddr)) {
RodColeman 0:8f5825f330b0 1257 IPCPDEBUG(LOG_ERR, ("Peer is not authorized to use remote address %s\n",
RodColeman 0:8f5825f330b0 1258 inet_ntoa(ho->hisaddr)));
RodColeman 0:8f5825f330b0 1259 ipcp_close(f->unit, "Unauthorized remote IP address");
RodColeman 0:8f5825f330b0 1260 return;
RodColeman 0:8f5825f330b0 1261 }
RodColeman 0:8f5825f330b0 1262
RodColeman 0:8f5825f330b0 1263 /* set tcp compression */
RodColeman 0:8f5825f330b0 1264 sifvjcomp(f->unit, ho->neg_vj, ho->cflag, ho->maxslotindex);
RodColeman 0:8f5825f330b0 1265
RodColeman 0:8f5825f330b0 1266 /*
RodColeman 0:8f5825f330b0 1267 * Set IP addresses and (if specified) netmask.
RodColeman 0:8f5825f330b0 1268 */
RodColeman 0:8f5825f330b0 1269 mask = GetMask(go->ouraddr);
RodColeman 0:8f5825f330b0 1270
RodColeman 0:8f5825f330b0 1271 if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask, go->dnsaddr[0], go->dnsaddr[1])) {
RodColeman 0:8f5825f330b0 1272 IPCPDEBUG(LOG_WARNING, ("sifaddr failed\n"));
RodColeman 0:8f5825f330b0 1273 ipcp_close(f->unit, "Interface configuration failed");
RodColeman 0:8f5825f330b0 1274 return;
RodColeman 0:8f5825f330b0 1275 }
RodColeman 0:8f5825f330b0 1276
RodColeman 0:8f5825f330b0 1277 /* bring the interface up for IP */
RodColeman 0:8f5825f330b0 1278 if (!sifup(f->unit)) {
RodColeman 0:8f5825f330b0 1279 IPCPDEBUG(LOG_WARNING, ("sifup failed\n"));
RodColeman 0:8f5825f330b0 1280 ipcp_close(f->unit, "Interface configuration failed");
RodColeman 0:8f5825f330b0 1281 return;
RodColeman 0:8f5825f330b0 1282 }
RodColeman 0:8f5825f330b0 1283
RodColeman 0:8f5825f330b0 1284 sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
RodColeman 0:8f5825f330b0 1285
RodColeman 0:8f5825f330b0 1286 /* assign a default route through the interface if required */
RodColeman 0:8f5825f330b0 1287 if (ipcp_wantoptions[f->unit].default_route) {
RodColeman 0:8f5825f330b0 1288 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr)) {
RodColeman 0:8f5825f330b0 1289 default_route_set[f->unit] = 1;
RodColeman 0:8f5825f330b0 1290 }
RodColeman 0:8f5825f330b0 1291 }
RodColeman 0:8f5825f330b0 1292
RodColeman 0:8f5825f330b0 1293 IPCPDEBUG(LOG_NOTICE, ("local IP address %s\n", inet_ntoa(go->ouraddr)));
RodColeman 0:8f5825f330b0 1294 IPCPDEBUG(LOG_NOTICE, ("remote IP address %s\n", inet_ntoa(ho->hisaddr)));
RodColeman 0:8f5825f330b0 1295 if (go->dnsaddr[0]) {
RodColeman 0:8f5825f330b0 1296 IPCPDEBUG(LOG_NOTICE, ("primary DNS address %s\n", inet_ntoa(go->dnsaddr[0])));
RodColeman 0:8f5825f330b0 1297 }
RodColeman 0:8f5825f330b0 1298 if (go->dnsaddr[1]) {
RodColeman 0:8f5825f330b0 1299 IPCPDEBUG(LOG_NOTICE, ("secondary DNS address %s\n", inet_ntoa(go->dnsaddr[1])));
RodColeman 0:8f5825f330b0 1300 }
RodColeman 0:8f5825f330b0 1301 }
RodColeman 0:8f5825f330b0 1302
RodColeman 0:8f5825f330b0 1303
RodColeman 0:8f5825f330b0 1304 /*
RodColeman 0:8f5825f330b0 1305 * ipcp_down - IPCP has gone DOWN.
RodColeman 0:8f5825f330b0 1306 *
RodColeman 0:8f5825f330b0 1307 * Take the IP network interface down, clear its addresses
RodColeman 0:8f5825f330b0 1308 * and delete routes through it.
RodColeman 0:8f5825f330b0 1309 */
RodColeman 0:8f5825f330b0 1310 static void
RodColeman 0:8f5825f330b0 1311 ipcp_down(fsm *f)
RodColeman 0:8f5825f330b0 1312 {
RodColeman 0:8f5825f330b0 1313 IPCPDEBUG(LOG_INFO, ("ipcp: down\n"));
RodColeman 0:8f5825f330b0 1314 np_down(f->unit, PPP_IP);
RodColeman 0:8f5825f330b0 1315 sifvjcomp(f->unit, 0, 0, 0);
RodColeman 0:8f5825f330b0 1316
RodColeman 0:8f5825f330b0 1317 sifdown(f->unit);
RodColeman 0:8f5825f330b0 1318 ipcp_clear_addrs(f->unit);
RodColeman 0:8f5825f330b0 1319 }
RodColeman 0:8f5825f330b0 1320
RodColeman 0:8f5825f330b0 1321
RodColeman 0:8f5825f330b0 1322 /*
RodColeman 0:8f5825f330b0 1323 * ipcp_clear_addrs() - clear the interface addresses, routes, etc.
RodColeman 0:8f5825f330b0 1324 */
RodColeman 0:8f5825f330b0 1325 static void
RodColeman 0:8f5825f330b0 1326 ipcp_clear_addrs(int unit)
RodColeman 0:8f5825f330b0 1327 {
RodColeman 0:8f5825f330b0 1328 u32_t ouraddr, hisaddr;
RodColeman 0:8f5825f330b0 1329
RodColeman 0:8f5825f330b0 1330 ouraddr = ipcp_gotoptions[unit].ouraddr;
RodColeman 0:8f5825f330b0 1331 hisaddr = ipcp_hisoptions[unit].hisaddr;
RodColeman 0:8f5825f330b0 1332 if (default_route_set[unit]) {
RodColeman 0:8f5825f330b0 1333 cifdefaultroute(unit, ouraddr, hisaddr);
RodColeman 0:8f5825f330b0 1334 default_route_set[unit] = 0;
RodColeman 0:8f5825f330b0 1335 }
RodColeman 0:8f5825f330b0 1336 cifaddr(unit, ouraddr, hisaddr);
RodColeman 0:8f5825f330b0 1337 }
RodColeman 0:8f5825f330b0 1338
RodColeman 0:8f5825f330b0 1339
RodColeman 0:8f5825f330b0 1340 /*
RodColeman 0:8f5825f330b0 1341 * ipcp_finished - possibly shut down the lower layers.
RodColeman 0:8f5825f330b0 1342 */
RodColeman 0:8f5825f330b0 1343 static void
RodColeman 0:8f5825f330b0 1344 ipcp_finished(fsm *f)
RodColeman 0:8f5825f330b0 1345 {
RodColeman 0:8f5825f330b0 1346 np_finished(f->unit, PPP_IP);
RodColeman 0:8f5825f330b0 1347 }
RodColeman 0:8f5825f330b0 1348
RodColeman 0:8f5825f330b0 1349 #if PPP_ADDITIONAL_CALLBACKS
RodColeman 0:8f5825f330b0 1350 static int
RodColeman 0:8f5825f330b0 1351 ipcp_printpkt(u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
RodColeman 0:8f5825f330b0 1352 {
RodColeman 0:8f5825f330b0 1353 LWIP_UNUSED_ARG(p);
RodColeman 0:8f5825f330b0 1354 LWIP_UNUSED_ARG(plen);
RodColeman 0:8f5825f330b0 1355 LWIP_UNUSED_ARG(printer);
RodColeman 0:8f5825f330b0 1356 LWIP_UNUSED_ARG(arg);
RodColeman 0:8f5825f330b0 1357 return 0;
RodColeman 0:8f5825f330b0 1358 }
RodColeman 0:8f5825f330b0 1359
RodColeman 0:8f5825f330b0 1360 /*
RodColeman 0:8f5825f330b0 1361 * ip_active_pkt - see if this IP packet is worth bringing the link up for.
RodColeman 0:8f5825f330b0 1362 * We don't bring the link up for IP fragments or for TCP FIN packets
RodColeman 0:8f5825f330b0 1363 * with no data.
RodColeman 0:8f5825f330b0 1364 */
RodColeman 0:8f5825f330b0 1365 #define IP_HDRLEN 20 /* bytes */
RodColeman 0:8f5825f330b0 1366 #define IP_OFFMASK 0x1fff
RodColeman 0:8f5825f330b0 1367 #define IPPROTO_TCP 6
RodColeman 0:8f5825f330b0 1368 #define TCP_HDRLEN 20
RodColeman 0:8f5825f330b0 1369 #define TH_FIN 0x01
RodColeman 0:8f5825f330b0 1370
RodColeman 0:8f5825f330b0 1371 /*
RodColeman 0:8f5825f330b0 1372 * We use these macros because the IP header may be at an odd address,
RodColeman 0:8f5825f330b0 1373 * and some compilers might use word loads to get th_off or ip_hl.
RodColeman 0:8f5825f330b0 1374 */
RodColeman 0:8f5825f330b0 1375
RodColeman 0:8f5825f330b0 1376 #define net_short(x) (((x)[0] << 8) + (x)[1])
RodColeman 0:8f5825f330b0 1377 #define get_iphl(x) (((unsigned char *)(x))[0] & 0xF)
RodColeman 0:8f5825f330b0 1378 #define get_ipoff(x) net_short((unsigned char *)(x) + 6)
RodColeman 0:8f5825f330b0 1379 #define get_ipproto(x) (((unsigned char *)(x))[9])
RodColeman 0:8f5825f330b0 1380 #define get_tcpoff(x) (((unsigned char *)(x))[12] >> 4)
RodColeman 0:8f5825f330b0 1381 #define get_tcpflags(x) (((unsigned char *)(x))[13])
RodColeman 0:8f5825f330b0 1382
RodColeman 0:8f5825f330b0 1383 static int
RodColeman 0:8f5825f330b0 1384 ip_active_pkt(u_char *pkt, int len)
RodColeman 0:8f5825f330b0 1385 {
RodColeman 0:8f5825f330b0 1386 u_char *tcp;
RodColeman 0:8f5825f330b0 1387 int hlen;
RodColeman 0:8f5825f330b0 1388
RodColeman 0:8f5825f330b0 1389 len -= PPP_HDRLEN;
RodColeman 0:8f5825f330b0 1390 pkt += PPP_HDRLEN;
RodColeman 0:8f5825f330b0 1391 if (len < IP_HDRLEN) {
RodColeman 0:8f5825f330b0 1392 return 0;
RodColeman 0:8f5825f330b0 1393 }
RodColeman 0:8f5825f330b0 1394 if ((get_ipoff(pkt) & IP_OFFMASK) != 0) {
RodColeman 0:8f5825f330b0 1395 return 0;
RodColeman 0:8f5825f330b0 1396 }
RodColeman 0:8f5825f330b0 1397 if (get_ipproto(pkt) != IPPROTO_TCP) {
RodColeman 0:8f5825f330b0 1398 return 1;
RodColeman 0:8f5825f330b0 1399 }
RodColeman 0:8f5825f330b0 1400 hlen = get_iphl(pkt) * 4;
RodColeman 0:8f5825f330b0 1401 if (len < hlen + TCP_HDRLEN) {
RodColeman 0:8f5825f330b0 1402 return 0;
RodColeman 0:8f5825f330b0 1403 }
RodColeman 0:8f5825f330b0 1404 tcp = pkt + hlen;
RodColeman 0:8f5825f330b0 1405 if ((get_tcpflags(tcp) & TH_FIN) != 0 && len == hlen + get_tcpoff(tcp) * 4) {
RodColeman 0:8f5825f330b0 1406 return 0;
RodColeman 0:8f5825f330b0 1407 }
RodColeman 0:8f5825f330b0 1408 return 1;
RodColeman 0:8f5825f330b0 1409 }
RodColeman 0:8f5825f330b0 1410 #endif /* PPP_ADDITIONAL_CALLBACKS */
RodColeman 0:8f5825f330b0 1411
RodColeman 0:8f5825f330b0 1412 #endif /* PPP_SUPPORT */