Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Committer:
dcoban
Date:
Tue Apr 03 18:43:13 2012 +0000
Revision:
0:1a61c61d0845

        

Who changed what in which revision?

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