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