HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

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