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