/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
ipv6cp.c - PPP IPV6 Control Protocol.
Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
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. The name of the author 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.
*/
/* Original version, based on RFC2023 :
Copyright (c) 1995, 1996, 1997 Francis.Dupont@inria.fr, INRIA Rocquencourt,
Alain.Durand@imag.fr, IMAG,
Jean-Luc.Richier@imag.fr, IMAG-LSR.
Copyright (c) 1998, 1999 Francis.Dupont@inria.fr, GIE DYADE,
Alain.Durand@imag.fr, IMAG,
Jean-Luc.Richier@imag.fr, IMAG-LSR.
Ce travail a �t� fait au sein du GIE DYADE (Groupement d'Int�r�t
�conomique ayant pour membres BULL S.A. et l'INRIA).
Ce logiciel informatique est disponible aux conditions
usuelles dans la recherche, c'est-�-dire qu'il peut
�tre utilis�, copi�, modifi�, distribu� � l'unique
condition que ce texte soit conserv� afin que
l'origine de ce logiciel soit reconnue.
Le nom de l'Institut National de Recherche en Informatique
et en Automatique (INRIA), de l'IMAG, ou d'une personne morale
ou physique ayant particip� � l'�laboration de ce logiciel ne peut
�tre utilis� sans son accord pr�alable explicite.
Ce logiciel est fourni tel quel sans aucune garantie,
support ou responsabilit� d'aucune sorte.
Ce logiciel est d�riv� de sources d'origine
"University of California at Berkeley" et
"Digital Equipment Corporation" couvertes par des copyrights.
L'Institut d'Informatique et de Math�matiques Appliqu�es de Grenoble (IMAG)
est une f�d�ration d'unit�s mixtes de recherche du CNRS, de l'Institut National
Polytechnique de Grenoble et de l'Universit� Joseph Fourier regroupant
sept laboratoires dont le laboratoire Logiciels, Syst�mes, R�seaux (LSR).
This work has been done in the context of GIE DYADE (joint R & D venture
between BULL S.A. and INRIA).
This software is available with usual "research" terms
with the aim of retain credits of the software.
Permission to use, copy, modify and distribute this software for any
purpose and without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies,
and the name of INRIA, IMAG, or any contributor not be used in advertising
or publicity pertaining to this material without the prior explicit
permission. The software is provided "as is" without any
warranties, support or liabilities of any kind.
This software is derived from source code from
"University of California at Berkeley" and
"Digital Equipment Corporation" protected by copyrights.
Grenoble's Institute of Computer Science and Applied Mathematics (IMAG)
is a federation of seven research units funded by the CNRS, National
Polytechnic Institute of Grenoble and University Joseph Fourier.
The research unit in Software, Systems, Networks (LSR) is member of IMAG.
*/
/*
* Derived from :
*
*
* ipcp.c - PPP IP Control Protocol.
*
* 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.
*
* $Id: ipv6cp.c,v 1.9 2000/04/15 01:27:11 masputra Exp $
*/
/*
* TODO:
*
* Proxy Neighbour Discovery.
*
* Better defines for selecting the ordering of
* interface up / set address. (currently checks for __linux__,
* since SVR4 && (SNI || __USLC__) didn't work properly)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include "pppd.h"
#include "eui64.h"
#include "fsm.h"
#include "ipcp.h"
#include "ipv6cp.h"
#include "magic.h"
#include "pathnames.h"
#endif
/* global vars */
int no_ifaceid_neg = 0;
/* local vars */
static bool ipv6cp_is_up;
/*
* Callbacks for fsm code. (CI = Configuration Information)
*/
ipv6cp_resetci, /* Reset our Configuration Information */
ipv6cp_cilen, /* Length of our Configuration Information */
ipv6cp_addci, /* Add our Configuration Information */
ipv6cp_ackci, /* ACK our Configuration Information */
ipv6cp_nakci, /* NAK our Configuration Information */
ipv6cp_rejci, /* Reject our Configuration Information */
ipv6cp_reqci, /* Request peer's Configuration Information */
ipv6cp_up, /* Called when fsm reaches OPENED state */
ipv6cp_down, /* Called when fsm leaves OPENED state */
NULL, /* Called when we want the lower layer up */
ipv6cp_finished, /* Called when we want the lower layer down */
NULL, /* Retransmission is necessary */
NULL, /* Called to handle protocol-specific codes */
"IPV6CP", /* String name of protocol */
NULL /* Peer rejected a code number */
};
/*
* Command-line options.
*/
"Set interface identifiers for IPV6" },
"Disable IPv6 and IPv6CP" },
"Disable IPv6 and IPv6CP" },
"Enable IPv6 and IPv6CP", 1 },
"Accept peer's interface identifier for us", 1 },
"Use (default) IPv4 address as interface identifier", 1 },
#if defined(SOL2)
"Use unique persistent value for link local address", 1 },
#endif /* defined(SOL2) */
"Set timeout for IPv6CP" },
"Maximum number of IPV6CP Terminate-Request" },
"Maximum number of IPV6CP Configure-Request" },
"Maximum number of IPV6CP Configure-Nak" },
{ NULL }
};
/*
* Protocol entry points from main code.
*/
static void ipv6cp_init __P((int));
static void ipv6cp_open __P((int));
static void ipv6cp_close __P((int, char *));
static void ipv6cp_lowerup __P((int));
static void ipv6cp_lowerdown __P((int));
static void ipv6cp_protrej __P((int));
void (*) __P((void *, const char *, ...)), void *));
static void ipv6_check_options __P((void));
static int ipv6_demand_conf __P((int));
PPP_IPV6CP, /* Protocol Number for IPV6CP */
ipv6cp_init, /* Initializes IPV6CP */
ipv6cp_input, /* Processes a received IPV6CP packet */
ipv6cp_protrej, /* Process a received Protocol-reject */
ipv6cp_lowerup, /* Called when LCP is brought up */
ipv6cp_lowerdown, /* Called when LCP has gone down */
ipv6cp_open, /* Called when link is established */
ipv6cp_close, /* Called when link has gone down */
ipv6cp_printpkt, /* Print a packet in human readable form */
NULL, /* Process a received data packet */
0, /* IPV6CP is disabled by default */
"IPV6CP", /* Name of the protocol */
"IPV6", /* Name of the corresponding data protocol */
ipv6cp_option_list, /* List of IPV6CP command-line options */
ipv6_check_options, /* Assigns default values for options */
ipv6_demand_conf, /* Configures demand-dial */
ipv6_active_pkt /* Bring up the link for this packet? */
};
/*
* Local forward function declarations.
*/
static void ipv6cp_script __P((char *));
static void ipv6cp_script_done __P((void *, int));
/*
* Lengths of configuration options.
*/
/*
* This state variable is used to ensure that we don't
*/
static enum script_state {
/*
* setifaceid - set the interface identifiers manually
*/
/*ARGSUSED*/
static int
char **argv;
{
/*
* If comma first character, then no local identifier
*/
*comma = '\0';
return 0;
}
}
/*
* If comma last character, then no remote identifier
*/
return 0;
}
}
return 1;
}
/*
* Given an interface identifier, return a string representation of the
* link local address associated with that identifier.
* string will be at most 26 characters (including null terminator).
*/
static char *
{
return addrstr;
}
/*
* ipv6cp_init - Initialize IPV6CP.
*/
static void
int unit;
{
f->protocol = PPP_IPV6CP;
f->callbacks = &ipv6cp_callbacks;
#ifdef IPV6CP_COMP
#endif
}
/*
* ipv6cp_open - IPV6CP is allowed to come up.
*/
static void
int unit;
{
}
/*
* ipv6cp_close - Take IPV6CP down.
*/
static void
int unit;
char *reason;
{
}
/*
* ipv6cp_lowerup - The lower layer is up.
*/
static void
int unit;
{
}
/*
* ipv6cp_lowerdown - The lower layer is down.
*/
static void
int unit;
{
}
/*
* ipv6cp_input - Input IPV6CP packet.
*/
static void
int unit;
u_char *p;
int len;
{
}
/*
* ipv6cp_protrej - A Protocol-Reject was received for IPV6CP.
*/
static void
int unit;
{
}
/*
* ipv6cp_resetci - Reset our CI.
*/
static void
fsm *f;
{
}
}
/*
* ipv6cp_cilen - Return length of our CI.
*/
static int
ipv6cp_cilen(f)
fsm *f;
{
}
/*
* ipv6cp_addci - Add our desired CIs to a packet.
*/
static void
fsm *f;
int *lenp;
{
if (neg) { \
int vjlen = CILEN_COMPRESS; \
} else \
neg = 0; \
}
if (neg) { \
int idlen = CILEN_IFACEID; \
} else \
neg = 0; \
}
}
/*
* ipv6cp_ackci - Ack our CIs.
*
* 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.
*/
if (neg) { \
int vjlen = CILEN_COMPRESS; \
goto bad; \
goto bad; \
goto bad; \
}
if (neg) { \
int idlen = CILEN_IFACEID; \
goto bad; \
goto bad; \
goto bad; \
}
/*
* If there are any remaining CIs, then this packet is bad.
*/
if (len != 0)
goto bad;
return (1);
bad:
IPV6CPDEBUG(("ipv6cp_ackci: received bad Ack!"));
return (0);
}
/*
* ipv6cp_nakci - Peer has sent a NAK for some of our CIs.
* This should not modify any state if the Nak is bad
* or if IPV6CP is in the OPENED state.
*
* 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.
*/
p[1] == cilen && \
p[0] == opt) { \
INCPTR(2, p); \
code \
}
p[0] == opt) { \
INCPTR(2, p); \
code \
}
/*
* Accept the peer's idea of {our,his} interface identifier, if different
* from our idea, only if the accept_{local,remote} flag is set.
*/
if (go->accept_local) {
while (eui64_iszero(ifaceid) ||
}
);
#ifdef IPV6CP_COMP
{
if (cishort == IPV6CP_COMP) {
} else {
}
}
);
#else
{
}
);
#endif
/*
* 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 interface identifier, we comply.
* If they want us to ask for compression, we refuse.
*/
while (len > CILEN_VOID) {
goto bad;
switch (citype) {
case CI_COMPRESSTYPE:
(cilen != CILEN_COMPRESS))
goto bad;
break;
case CI_IFACEID:
goto bad;
if (go->accept_local) {
while (eui64_iszero(ifaceid) ||
}
break;
}
p = next;
}
/* If there is still anything left, this packet is bad. */
if (len != 0)
goto bad;
/*
* OK, the Nak is good. Now we can update state.
*/
return 1;
bad:
IPV6CPDEBUG(("ipv6cp_nakci: received bad Nak!"));
return 0;
}
/*
* ipv6cp_rejci - Reject some of our CIs.
*/
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.
*/
p[1] == cilen && \
p[0] == opt) { \
INCPTR(2, p); \
/* Check rejected value. */ \
goto bad; \
}
p[1] == CILEN_COMPRESS && \
len >= p[1] && \
p[0] == opt) { \
len -= p[1]; \
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:
IPV6CPDEBUG(("ipv6cp_rejci: received bad Reject!"));
return 0;
}
/*
* ipv6cp_reqci - Check the peer's requested CIs and send appropriate response.
*
* 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 */
int dont_nak;
{
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_IFACEID:
IPV6CPDEBUG(("ipv6cp: received interface identifier "));
if (!ao->neg_ifaceid) {
break;
}
if (cilen != CILEN_IFACEID) {
/*
* rfc1661, page 40 -- a recongnized option with an
* invalid length should be Nak'ed.
*/
} else {
/*
* If he has no interface identifier, or if we both
* have same identifier then NAK it with new idea. In
* particular, if we don't know his identifier, but he
* does, then accept it.
*/
break;
}
/* If we don't like his ID, then nak it. */
} else if (eui64_iszero(ifaceid) ||
/* first time, try option */
while (eui64_iszero(ifaceid) ||
}
}
if (newret == CODE_CONFNAK) {
}
break;
case CI_COMPRESSTYPE:
IPV6CPDEBUG(("ipv6cp: received COMPRESSTYPE "));
break;
}
if (cilen != CILEN_COMPRESS) {
} else {
#ifdef IPV6CP_COMP
if (cishort != IPV6CP_COMP) {
}
#else
break;
#endif
}
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 identifier and they didn't send their identifier, then we
* send a NAK with a CI_IFACEID option appended. We assume the
* input buffer is long enough that we can append the extra
* option safely.
*/
if (ret == CODE_CONFACK)
wo->req_ifaceid = 0;
ret = CODE_CONFNAK;
}
switch (ret) {
case CODE_CONFACK:
break;
case CODE_CONFNAK:
break;
case CODE_CONFREJ:
break;
}
return (ret); /* Return final code */
}
/*
* ipv6_check_options - check that any IP-related options are OK,
* and assign appropriate defaults.
*/
static void
{
#if defined(SOL2)
/*
* Persistent link-local id is only used when user has not explicitly
*/
/*
* On systems where there are no Ethernet interfaces used, there
* may be other ways to obtain a persistent id. Right now, it
* will fall back to using magic [see eui64_magic] below when
* an EUI-48 from MAC address can't be obtained. Other possibilities
* include obtaining EEPROM serial numbers, or some other unique
* yet persistent number. On Sparc platforms, this is possible,
* but too bad there's no standards yet for x86 machines.
*/
}
}
#endif
/*
* If ipv6cp-use-ipaddr is used, then both local and remote IPv4
* addresses should be specified as options. Otherwise, since
* ipcp has yet to negotiate the IPv4 addresses, the interface
* identifiers will be based on meaningless values.
*/
if ((ipcp_wantoptions[0].accept_local ||
warn("either IPv4 or IPv6 local address should be non-zero for ipv6cp-use-ipaddr");
}
if ((ipcp_wantoptions[0].accept_remote ||
warn("either IPv4 or IPv6 remote address should be non-zero for ipv6cp-use-ipaddr");
}
}
}
}
if (!wo->opt_remote) {
}
}
}
}
/*
* ipv6_demand_conf - configure the interface as though
* IPV6CP were up, for use with dial-on-demand.
*/
static int
int u;
{
#if SIF6UPFIRST
if (!sif6up(u))
return 0;
#endif
return 0;
#if !SIF6UPFIRST
if (!sif6up(u))
return 0;
#endif
return 0;
return 1;
}
/*
* ipv6cp_up - IPV6CP has come UP.
*
* Configure the IPv6 network interface appropriately and bring it up.
*/
static void
ipv6cp_up(f)
fsm *f;
{
IPV6CPDEBUG(("ipv6cp: up"));
/*
* We must have a non-zero LL address for both ends of the link.
*/
if (!ho->neg_ifaceid)
if(!no_ifaceid_neg) {
error("Could not determine remote LL address");
return;
}
error("Could not determine local LL address");
return;
}
error("local and remote LL addresses are equal");
return;
}
}
#ifdef IPV6CP_COMP
/* set tcp compression */
return;
}
#endif
/*
* 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 IPv6 packets.
*/
if (demand) {
warn("Local LL address changed to %s",
warn("Remote LL address changed to %s",
/* Set the interface to the new addresses */
if (debug)
warn("sif6addr failed");
return;
}
}
return;
}
} else {
/*
* Set LL addresses
*/
#if !SIF6UPFIRST
if (debug)
warn("sif6addr failed");
return;
}
#endif
#if defined(SOL2)
/* bring the interface up for IPv6 */
if (debug)
warn("sifup failed (IPV6)");
return;
}
#else
if (debug)
warn("sifup failed (IPV6)");
return;
}
#endif
#if SIF6UPFIRST
if (debug)
warn("sif6addr failed");
return;
}
#endif
return;
}
}
ipv6cp_is_up = 1;
/*
* Execute the ipv6-up script, like this:
*/
}
}
/*
* ipv6cp_down - IPV6CP has gone DOWN.
*
* Take the IPv6 network interface down, clear its addresses
* and delete routes through it.
*/
static void
ipv6cp_down(f)
fsm *f;
{
IPV6CPDEBUG(("ipv6cp: down"));
update_link_stats(f->unit);
if (ipv6cp_is_up) {
ipv6cp_is_up = 0;
}
#ifdef IPV6CP_COMP
if (debug)
warn("Failed to disable TCP compression.");
}
#endif
/*
* 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.");
}
#if defined(SOL2)
warn("Couldn not bring interface down.");
#else
warn("Could not bring interface down.");
#endif /* defined(SOL2) */
#endif
warn("Could not bring interface down.");
#endif
}
/* Execute the ipv6-down script */
}
}
/*
* ipv6cp_clear_addrs() - clear the interface addresses, routes,
* proxy neighbour discovery entries, etc.
*/
static void
int unit;
{
warn("Could not clear addresses");
}
/*
* ipv6cp_finished - possibly shut down the lower layers.
*/
static void
fsm *f;
{
}
/*
* ipv6cp_script_done - called when the ipv6-up or ipv6-down script
* has finished.
*/
/*ARGSUSED*/
static void
void *arg;
int status;
{
ipv6cp_script_pid = 0;
switch (ipv6cp_script_state) {
case s_up:
}
break;
case s_down:
}
break;
}
}
/*
* ipv6cp_script - Execute a script with arguments
* interface-name tty-name speed local-LL remote-LL.
*/
static void
char *script;
{
sizeof (strlocal));
sizeof (strremote));
}
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_COMPRESSTYPE:
if (olen >= CILEN_COMPRESS) {
p += 2;
}
break;
case CI_IFACEID:
if (olen == CILEN_IFACEID) {
p += 2;
}
break;
}
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;
}
/*
* ipv6_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;
{
len -= PPP_HDRLEN;
pkt += PPP_HDRLEN;
if (len < IP6_HDRLEN) {
return 0;
}
return 0;
}
tostr);
return 1;
}
return 0;
}
return 0;
}
return 1;
}