Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

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