Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Wed Dec 15 18:01:30 2010 +0000
Revision:
7:4e2468d7d5cb
Parent:
0:ac1725ba162c

        

Who changed what in which revision?

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