NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

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