Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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