Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

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