Experimental HTTPClient with proxy support

Committer:
igorsk
Date:
Wed Jun 29 16:01:58 2011 +0000
Revision:
0:b56b6a05cad4

        

Who changed what in which revision?

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