/*
* ipcp.c - PPP IP Control Protocol.
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* TODO:
*/
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#define __FAVOR_BSD
#endif
#include "pppd.h"
#include "fsm.h"
#include "ipcp.h"
#include "pathnames.h"
#endif
/* global vars */
/* Hook for a plugin to know when IP protocol has come up */
/* Hook for a plugin to know when IP protocol has come down */
/* local vars */
/*
* Callbacks for fsm code. (CI = Configuration Information)
*/
ipcp_resetci, /* Reset our Configuration Information */
ipcp_cilen, /* Length of our Configuration Information */
ipcp_addci, /* Add our Configuration Information */
ipcp_ackci, /* ACK our Configuration Information */
ipcp_nakci, /* NAK our Configuration Information */
ipcp_rejci, /* Reject our Configuration Information */
ipcp_reqci, /* Request peer's Configuration Information */
ipcp_up, /* Called when fsm reaches OPENED state */
ipcp_down, /* Called when fsm leaves OPENED state */
NULL, /* Called when we want the lower layer up */
ipcp_finished, /* Called when we want the lower layer down */
NULL, /* Retransmission is necessary */
NULL, /* Called to handle protocol-specific codes */
"IPCP", /* String name of protocol */
NULL /* Peer rejected a code number */
};
/*
* Command-line options.
*/
static int setvjslots __P((char **));
static int setdnsaddr __P((char **));
static int setwinsaddr __P((char **));
static int autoproxyarp __P((char **));
"Disable IP and IPCP" },
"Disable IP and IPCP" },
"Disable VJ connection-ID compression", OPT_A2COPY,
&ipcp_allowoptions[0].cflag },
"Disable VJ connection-ID compression", OPT_A2COPY,
&ipcp_allowoptions[0].cflag },
"Set maximum VJ header slots" },
"Accept peer's address for us", 1 },
"Accept peer's address for it", 1 },
"Set ip script parameter" },
"Don't use name for default IP adrs", 1 },
"DNS address for the peer's use" },
"Set timeout for IPCP" },
"Set max #xmits for term-reqs" },
"Set max #xmits for conf-reqs" },
"Set max #conf-naks for IPCP" },
"disable defaultroute option", OPT_A2COPY,
&ipcp_wantoptions[0].default_route },
"disable defaultroute option", OPT_A2COPY,
&ipcp_wantoptions[0].default_route },
"Add proxy ARP entry if needed", OPT_ENABLE,
&ipcp_allowoptions[0].proxy_arp },
&ipcp_wantoptions[0].req_dns2 },
{ NULL }
};
/*
* Protocol entry points from main code.
*/
static void ipcp_close __P((int, char *));
static void ipcp_lowerup __P((int));
static void ipcp_lowerdown __P((int));
static void ipcp_protrej __P((int));
void (*) __P((void *, const char *, ...)), void *));
static void ip_check_options __P((void));
static int ip_demand_conf __P((int));
NULL,
1,
"IPCP",
"IP",
};
static void ipcp_script_done __P((void *, int));
/*
* Lengths of configuration options.
*/
/*
* This state variable is used to ensure that we don't
*/
static enum script_state {
/*
* Make a string representation of a network IP address.
*/
char *
{
static char b[64];
return b;
}
/*
* Option parsing.
*/
/*
* setvjslots - set maximum number of connection slots for VJ compression
*/
static int
char **argv;
{
int value;
return 0;
option_error("vj-max-slots value must be between 2 and 16");
return 0;
}
ipcp_wantoptions [0].maxslotindex =
return 1;
}
/*
* setmsservaddr - Set the primary and secondary server addresses in the
* array. setdnsaddr() and setwinsaddr() call this function with either
* dnsaddr[] or winsaddr[] as the serverarray argument.
*/
static int
char *servname;
{
return 0;
}
/*
* If there is no primary then this is the first instance of the
* option, we must set the primary. In that case, try to set the
* secondary to h_addr_list[1]. If the primary is already set, then
* this is the second instance of the option, and we must set
* the secondary.
*/
if (serverarray[0] == 0) {
serverarray[0] = addr;
else
} else {
}
return (1);
}
/*
* setdnsaddr - set the dns address(es)
*/
static int
char **argv;
{
return (0);
}
return (1);
}
/*
* setwinsaddr - set the wins address(es)
* This is primrarly used with the Samba package under UNIX or for pointing
* the caller to the existing WINS server on a Windows NT platform.
*/
static int
char **argv;
{
option_error("invalid address parameter '%s' for ms-wins option",
*argv);
return (0);
}
return (1);
}
/*
* autoproxyarp -- enable proxy ARP but don't emit error messages if
* it's not actually needed.
*/
/*ARGSUSED*/
static int
char **argv;
{
proxy_arp_quiet[0] = 1;
return (1);
}
/*
* ipcp_init - Initialize IPCP.
*/
static void
int unit;
{
f->callbacks = &ipcp_callbacks;
/*
* These aren't actually negotiated. Instead, they control
* whether the user may use the proxyarp and defaultroute options.
*/
proxy_arp_quiet[unit] = 0;
}
/*
* ipcp_open - IPCP is allowed to come up.
*/
static void
int unit;
{
}
/*
* ipcp_close - Take IPCP down.
*/
static void
int unit;
char *reason;
{
}
/*
* ipcp_lowerup - The lower layer is up.
*/
static void
int unit;
{
}
/*
* ipcp_lowerdown - The lower layer is down.
*/
static void
int unit;
{
}
/*
* ipcp_input - Input IPCP packet.
*/
static void
int unit;
u_char *p;
int len;
{
}
/*
* ipcp_protrej - A Protocol-Reject was received for IPCP.
*/
static void
int unit;
{
}
/*
* ipcp_resetci - Reset our CI.
* Called by fsm_sconfreq, Send Configure Request.
*/
static void
ipcp_resetci(f)
fsm *f;
{
if (disable_defaultip)
}
/*
* ipcp_cilen - Return length of our CI.
* Called by fsm_sconfreq, Send Configure Request.
*/
static int
ipcp_cilen(f)
fsm *f;
{
/*
* First see if we want to change our options to the old
* forms because we have received old forms from the peer.
*/
/* use the old style of address negotiation */
/* try an older style of VJ negotiation */
/* use the old style only if the peer did */
}
}
}
/*
* ipcp_addci - Add our desired CIs to a packet.
* Called by fsm_sconfreq, Send Configure Request.
*/
static void
fsm *f;
int *lenp;
{
if (neg) { \
if (len >= CILEN_ADDRS) { \
len -= CILEN_ADDRS; \
} else \
}
if (neg) { \
if (!old) { \
} \
} else \
neg = 0; \
}
if (neg) { \
if (len >= CILEN_ADDR) { \
len -= CILEN_ADDR; \
} else \
neg = 0; \
}
}
/*
* ipcp_ackci - Ack our CIs.
* Called by fsm_rconfack, Receive Configure ACK.
*
* Returns:
* 0 - Ack was bad.
* 1 - Ack was good.
*/
static int
fsm *f;
u_char *p;
int len;
{
/*
* CIs must be in exactly the same order that we sent...
* Check packet length and CI length at each step.
* If we find any deviations, then this packet is bad.
*/
goto bad; \
goto bad;
if (neg) { \
goto bad; \
goto bad; \
}
if (neg) { \
goto bad; \
if (!old) { \
GETCHAR(cimaxslotindex, p); \
if (cimaxslotindex != maxslotindex) \
goto bad; \
goto bad; \
} \
}
if (neg) { \
goto bad; \
}
/*
* If there are any remaining CIs, then this packet is bad.
*/
if (len != 0)
goto bad;
return (1);
bad:
IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
return (0);
}
/*
* ipcp_nakci - Peer has sent a NAK for some of our CIs.
* This should not modify any state if the Nak is bad
* or if IPCP is in the OPENED state.
* Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
*
* Returns:
* 0 - Nak was bad.
* 1 - Nak was good.
*/
static int
fsm *f;
u_char *p;
int len;
{
/*
* Any Nak'd CIs must be in exactly the same order that we sent.
* Check packet length and CI length at each step.
* If we find any deviations, then this packet is bad.
*/
if ((neg) && \
p[0] == opt) { \
INCPTR(2, p); \
code \
}
p[0] == opt) { \
INCPTR(2, p); \
code \
}
p[0] == opt) { \
INCPTR(2, p); \
code \
}
/*
* Accept the peer's idea of {our,his} address, if different
* from our idea, only if the accept_{local,remote} flag is set.
*/
}
}
);
/*
* Accept the peer's value of maxslotindex provided that it
* is less than what we asked for. Turn off slot-ID compression
* if the peer wants. Send old-style compress-type option if
* the peer wants.
*/
GETCHAR(cimaxslotindex, p);
if (cishort == IPCP_VJ_COMP) {
if (!cicflag)
} else {
}
} else {
} else {
}
}
);
}
);
);
);
/*
* There may be remaining CIs, if the peer is requesting negotiation
* on an option that we didn't include in our request packet.
* If they want to negotiate about IP addresses, we comply.
* If they want us to ask for compression, we refuse.
*/
while (len > CILEN_VOID) {
goto bad;
switch (citype) {
case CI_COMPRESSTYPE:
goto bad;
break;
case CI_ADDRS:
|| cilen != CILEN_ADDRS)
goto bad;
break;
case CI_ADDR:
goto bad;
break;
}
p = next;
}
/*
* OK, the Nak is good. Now we can update state.
* If there are any remaining options, we ignore them.
*/
return 1;
bad:
IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
return 0;
}
/*
* ipcp_rejci - Reject some of our CIs.
* Callback from fsm_rconfnakrej.
*/
static int
fsm *f;
u_char *p;
int len;
{
/*
* Any Rejected CIs must be in exactly the same order that we sent.
* Check packet length and CI length at each step.
* If we find any deviations, then this packet is bad.
*/
if ((neg) && \
p[0] == opt) { \
INCPTR(2, p); \
/* Check rejected value. */ \
goto bad; \
/* Check rejected value. */ \
goto bad; \
}
len >= p[1] && \
p[0] == opt) { \
len -= p[1]; \
INCPTR(2, p); \
/* Check rejected value. */ \
goto bad; \
if (!old) { \
GETCHAR(cimaxslotindex, p); \
if (cimaxslotindex != maxslot) \
goto bad; \
goto bad; \
} \
}
p[0] == opt) { \
INCPTR(2, p); \
/* Check rejected value. */ \
goto bad; \
}
/*
* If there are any remaining CIs, then this packet is bad.
*/
if (len != 0)
goto bad;
/*
* Now we can update state.
*/
return 1;
bad:
IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
return 0;
}
/*
* ipcp_reqci - Check the peer's requested CIs and send appropriate response.
* Callback from fsm_rconfreq, Receive Configure Request
*
* Returns: CODE_CONFACK, CODE_CONFNAK or CODE_CONFREJ and input
* packet modified appropriately. If reject_if_disagree is non-zero,
* doesn't return CODE_CONFNAK; returns CODE_CONFREJ if it can't
* return CODE_CONFACK.
*/
static int
fsm *f;
u_char *p; /* Requested CIs */
int *lenp; /* Length of requested CIs */
bool dont_nak;
{
int d;
ret = CODE_CONFACK;
nakp = nak_buffer;
/*
* Reset all his options.
*/
/*
* Process all his options.
*/
/*
* RFC 1661 page 40 -- if the option extends beyond the
* packet, then discard the entire packet.
*/
return (0);
}
prev = p;
switch (type) { /* Check CI type */
case CI_ADDRS:
break;
}
if (cilen != CILEN_ADDRS) {
/*
* rfc1661, page 40 -- a recongnized option with an
* invalid length should be Nak'ed.
*/
} else {
/*
* If he has no address, or if we both have his
* address but disagree about it, then NAK it with our
* idea. In particular, if we don't know his address,
* but he does, then accept it.
*/
/*
* If neither we nor he knows his address, reject
* the option.
*/
break;
} else if (ciaddr1 != 0) {
}
/*
* If he doesn't know our address, or if we both have
* our address * but disagree about it, then NAK it
* with our idea.
*/
} else {
}
}
}
if (newret == CODE_CONFNAK) {
}
break;
case CI_ADDR:
break;
}
if (cilen != CILEN_ADDR) {
/*
* rfc1661, page 40 -- a recongnized option with an
* invalid length should be Nak'ed.
*/
} else {
/*
* If he has no address, or if we both have his
* address but disagree about it, then NAK it with our
* idea. In particular, if we don't know his address,
* but he does, then accept it.
*/
wo->default_route != 0) {
/*
* If this is a dialup line (default_route is
* set), and neither side knows about his address,
* suggest an arbitrary rfc1918 address.
*/
/*
* If this is not a dialup line, don't ACK an
* address of 0.0.0.0 - reject it instead.
*/
break;
}
}
if (newret == CODE_CONFNAK) {
}
break;
case CI_MS_DNS1:
case CI_MS_DNS2:
/* Warning -- these options work backwards. */
/* Microsoft primary or secondary DNS request */
break;
}
if (cilen != CILEN_ADDR) {
} else {
}
}
if (newret == CODE_CONFNAK) {
}
break;
case CI_MS_WINS1:
case CI_MS_WINS2:
/* Warning -- these options work backwards. */
/* Microsoft primary or secondary WINS request */
break;
}
if (cilen != CILEN_ADDR) {
} else {
}
}
if (newret == CODE_CONFNAK) {
}
break;
case CI_COMPRESSTYPE:
break;
}
} else {
if (cishort != IPCP_VJ_COMP &&
GETCHAR(maxslotindex, p);
}
cflag = 0;
}
} else {
cflag = 1;
}
}
if (newret == CODE_CONFNAK) {
if (cishort == IPCP_VJ_COMP) {
} else {
}
}
break;
default:
break;
}
/* Cope with confused peers. */
if (cilen < 2)
cilen = 2;
/*
* If this is an Ack'able CI, but we're sending back a Nak,
* don't include this CI.
*/
continue;
if (newret == CODE_CONFNAK) {
if (dont_nak) {
} else {
/* Ignore subsequent Nak'able things if rejecting. */
if (ret == CODE_CONFREJ)
continue;
ret = CODE_CONFNAK;
}
}
if (newret == CODE_CONFREJ) {
ret = CODE_CONFREJ;
}
}
/*
* If we aren't rejecting this packet, and we want to negotiate
* their address, and they didn't send their address, then we
* send a NAK with a CI_ADDR option appended. We assume the
* input buffer is long enough that we can append the extra
* option safely.
*/
if (ret == CODE_CONFACK)
ret = CODE_CONFNAK;
}
switch (ret) {
case CODE_CONFACK:
break;
case CODE_CONFNAK:
break;
case CODE_CONFREJ:
break;
}
return (ret); /* Return final code */
}
/*
* ip_check_options - check that any IP-related options are OK,
* and assign appropriate defaults.
*/
static void
{
/*
* Default our local IP address based on our hostname.
* If local IP address already given, don't bother.
*/
/*
* Look up our hostname (possibly with domain name appended)
* and take the first IP address as our local IP address.
* If there isn't an IP address for our hostname, too bad.
*/
ipcp_from_hostname = 1;
}
}
}
}
/*
* ip_demand_conf - configure the interface as though
* IPCP were up, for use with dial-on-demand.
*/
static int
int u;
{
/* make up an arbitrary address for the peer */
}
/* make up an arbitrary address for us */
}
return 0;
if (!sifup(u))
return 0;
return 0;
default_route_set[u] = 1;
proxy_arp_set[u] = 1;
return 1;
}
/*
* ipcp_up - IPCP has come UP.
*
* Configure the IP network interface appropriately and bring it up.
*/
static void
ipcp_up(f)
fsm *f;
{
IPCPDEBUG(("ipcp: up"));
/*
* We must have a non-zero IP address for both ends of the link.
*/
if (wo->accept_remote) {
/* Pick some rfc1918 address. */
dbglog("Peer refused to provide his address; assuming %I",
} else {
error("Could not determine remote IP address");
return;
}
}
error("Could not determine local IP address");
return;
}
/*
* Check that the peer is allowed to use the IP address it wants.
*/
return;
}
}
/* set tcp compression */
return;
}
/*
* If we are doing dial-on-demand, the interface is already
* configured, so we put out any saved-up packets, then set the
* interface to pass IP packets.
*/
if (demand) {
} else
script_unsetenv("OLDIPLOCAL");
} else
script_unsetenv("OLDIPREMOTE");
/* Set the interface to the new addresses */
warn("Interface configuration failed");
return;
}
/* assign a default route through the interface if required */
if (wo->default_route)
/* Make a proxy ARP entry if requested. */
}
return;
}
} else {
/*
* Set IP addresses and (if specified) netmask.
*/
#if SIFUPFIRST
/* bring the interface up for IP */
warn("Interface failed to come up");
return;
}
#endif
warn("Interface configuration failed");
return;
}
#if !SIFUPFIRST
/* bring the interface up for IP */
warn("Interface failed to come up");
return;
}
#endif
return;
}
/* assign a default route through the interface if required */
if (wo->default_route)
/* Make a proxy ARP entry if requested. */
}
if (ip_up_hook != NULL)
(*ip_up_hook)();
/*
* Execute the ip-up script, like this:
*/
}
}
/*
* ipcp_down - IPCP has gone DOWN.
*
* Take the IP network interface down, clear its addresses
* and delete routes through it.
*/
static void
ipcp_down(f)
fsm *f;
{
IPCPDEBUG(("ipcp: down"));
/* XXX a bit IPv4-centric here, we only need to get the stats
* before the interface is marked down. */
update_link_stats(f->unit);
if (ip_down_hook != NULL)
(*ip_down_hook)();
if (ipcp_is_up[f->unit]) {
ipcp_is_up[f->unit] = 0;
}
if (debug)
warn("Failed to disable VJ TCP header compression.");
}
/*
* If we are doing dial-on-demand, set the interface
* to queue up outgoing packets (for now).
*/
if (demand) {
if (debug)
warn("Failed to enable Queueing on outgoing packets.");
}
} else {
if (debug)
warn("Could not set interface to drop packets.");
}
warn("Could not bring interface down.");
}
/* Execute the ip-down script */
}
}
/*
* ipcp_clear_addrs() - clear the interface addresses, routes,
* proxy arp entries, etc.
*/
static void
int unit;
{
if (proxy_arp_set[unit]) {
proxy_arp_set[unit] = 0;
}
if (default_route_set[unit]) {
default_route_set[unit] = 0;
}
warn("Could not clear addresses");
}
/*
* ipcp_finished - possibly shut down the lower layers.
*/
static void
fsm *f;
{
}
/*
* ipcp_script_done - called when the ip-up or ip-down script
* has finished.
*/
/*ARGSUSED*/
static void
void *arg;
int status;
{
ipcp_script_pid = 0;
switch (ipcp_script_state) {
case s_up:
}
break;
case s_down:
}
break;
}
}
/*
* ipcp_script - Execute a script with arguments
* interface-name tty-name speed local-IP remote-IP.
*/
static void
char *script;
{
ipcp_gotoptions[0].ouraddr);
ipcp_hisoptions[0].hisaddr);
}
/*
* create_resolv - create the replacement resolv.conf file
*/
static void
{
FILE *f;
if (f == NULL) {
return;
}
if (peerdns1)
if (peerdns2)
if (fclose(f) != 0)
}
/*
* ipcp_printpkt - print the contents of an IPCP packet.
*/
static int
u_char *p;
int plen;
void *arg;
{
return 0;
pstart = p;
return 0;
switch (code) {
case CODE_CONFREQ:
case CODE_CONFACK:
case CODE_CONFNAK:
case CODE_CONFREJ:
/* print option list */
while (len >= 2) {
p -= 2;
break;
}
switch (code) {
case CI_ADDRS:
if (olen == CILEN_ADDRS) {
p += 2;
}
break;
case CI_COMPRESSTYPE:
if (olen >= CILEN_COMPRESS) {
p += 2;
switch (cishort) {
case IPCP_VJ_COMP:
break;
case IPCP_VJ_COMP_OLD:
break;
default:
}
}
break;
case CI_ADDR:
if (olen == CILEN_ADDR) {
p += 2;
}
break;
case CI_MS_DNS1:
case CI_MS_DNS2:
p += 2;
cilong);
break;
case CI_MS_WINS1:
case CI_MS_WINS2:
p += 2;
cilong);
break;
case CI_SUBNET:
p += 2;
break;
}
while (p < optend) {
}
}
break;
case CODE_TERMACK:
case CODE_TERMREQ:
p += len;
len = 0;
}
break;
}
/* print the rest of the bytes in the packet */
}
return p - pstart;
}
char *
int val;
{
*cp++ = 'U';
*cp++ = 'A';
*cp++ = 'P';
*cp++ = 'R';
*cp++ = 'S';
*cp++ = 'F';
*cp++ = ' ';
*cp = '\0';
return buf;
}
/*
* ip_active_pkt - see if this IP packet is worth bringing the link up for.
* We don't bring the link up for IP fragments or for TCP FIN packets
* with no data.
*/
static int
int len;
{
int val;
int hlen;
len -= PPP_HDRLEN;
pkt += PPP_HDRLEN;
return 0;
}
return 0;
}
if (val != IPPROTO_TCP) {
if (debug) {
} else {
}
}
return 1;
}
return 0;
}
return 0;
}
return 1;
}
static void
int unit;
{
if (!ipcp_protent.enabled_flag) {
return;
}
}