I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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