Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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