2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 * Copyright (c) 2016 by Delphix. All rights reserved.
7 ipv6cp.c - PPP IPV6 Control Protocol.
8 Copyright (C) 1999 Tommi Komulainen <Tommi.Komulainen@iki.fi>
10 Redistribution and use in source and binary forms are permitted
11 provided that the above copyright notice and this paragraph are
12 duplicated in all such forms. The name of the author may not be
13 used to endorse or promote products derived from this software
14 without specific prior written permission.
15 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 /* Original version, based on RFC2023 :
22 Copyright (c) 1995, 1996, 1997 Francis.Dupont@inria.fr, INRIA Rocquencourt,
23 Alain.Durand@imag.fr, IMAG,
24 Jean-Luc.Richier@imag.fr, IMAG-LSR.
26 Copyright (c) 1998, 1999 Francis.Dupont@inria.fr, GIE DYADE,
27 Alain.Durand@imag.fr, IMAG,
28 Jean-Luc.Richier@imag.fr, IMAG-LSR.
30 Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt
31 Économique ayant pour membres BULL S.A. et l'INRIA).
33 Ce logiciel informatique est disponible aux conditions
34 usuelles dans la recherche, c'est-à-dire qu'il peut
35 être utilisé, copié, modifié, distribué à l'unique
36 condition que ce texte soit conservé afin que
37 l'origine de ce logiciel soit reconnue.
39 Le nom de l'Institut National de Recherche en Informatique
40 et en Automatique (INRIA), de l'IMAG, ou d'une personne morale
41 ou physique ayant participé à l'élaboration de ce logiciel ne peut
42 être utilisé sans son accord préalable explicite.
44 Ce logiciel est fourni tel quel sans aucune garantie,
45 support ou responsabilité d'aucune sorte.
46 Ce logiciel est dérivé de sources d'origine
47 "University of California at Berkeley" et
48 "Digital Equipment Corporation" couvertes par des copyrights.
50 L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG)
51 est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National
52 Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant
53 sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR).
55 This work has been done in the context of GIE DYADE (joint R & D venture
56 between BULL S.A. and INRIA).
58 This software is available with usual "research" terms
59 with the aim of retain credits of the software.
60 Permission to use, copy, modify and distribute this software for any
61 purpose and without fee is hereby granted, provided that the above
62 copyright notice and this permission notice appear in all copies,
63 and the name of INRIA, IMAG, or any contributor not be used in advertising
64 or publicity pertaining to this material without the prior explicit
65 permission. The software is provided "as is" without any
66 warranties, support or liabilities of any kind.
67 This software is derived from source code from
68 "University of California at Berkeley" and
69 "Digital Equipment Corporation" protected by copyrights.
71 Grenoble's Institute of Computer Science and Applied Mathematics (IMAG)
72 is a federation of seven research units funded by the CNRS, National
73 Polytechnic Institute of Grenoble and University Joseph Fourier.
74 The research unit in Software, Systems, Networks (LSR) is member of IMAG.
81 * ipcp.c - PPP IP Control Protocol.
83 * Copyright (c) 1989 Carnegie Mellon University.
84 * All rights reserved.
86 * Redistribution and use in source and binary forms are permitted
87 * provided that the above copyright notice and this paragraph are
88 * duplicated in all such forms and that any documentation,
89 * advertising materials, and other materials related to such
90 * distribution and use acknowledge that the software was developed
91 * by Carnegie Mellon University. The name of the
92 * University may not be used to endorse or promote products derived
93 * from this software without specific prior written permission.
94 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
95 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
96 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
98 * $Id: ipv6cp.c,v 1.9 2000/04/15 01:27:11 masputra Exp $
101 #define RCSID "$Id: ipv6cp.c,v 1.9 2000/04/15 01:27:11 masputra Exp $"
106 * Proxy Neighbour Discovery.
108 * Better defines for selecting the ordering of
109 * interface up / set address. (currently checks for __linux__,
110 * since SVR4 && (SNI || __USLC__) didn't work properly)
118 #include <sys/param.h>
119 #include <sys/types.h>
120 #include <sys/socket.h>
121 #include <netinet/in.h>
122 #include <arpa/inet.h>
130 #include "pathnames.h"
132 static const char rcsid
[] = RCSID
;
135 ipv6cp_options ipv6cp_wantoptions
[NUM_PPP
]; /* Options that we want to request */
136 ipv6cp_options ipv6cp_gotoptions
[NUM_PPP
]; /* Options that peer ack'd */
137 ipv6cp_options ipv6cp_allowoptions
[NUM_PPP
]; /* Options we allow peer to request */
138 ipv6cp_options ipv6cp_hisoptions
[NUM_PPP
]; /* Options that we ack'd */
139 int no_ifaceid_neg
= 0;
142 static bool ipv6cp_is_up
;
145 * Callbacks for fsm code. (CI = Configuration Information)
147 static void ipv6cp_resetci
__P((fsm
*)); /* Reset our CI */
148 static int ipv6cp_cilen
__P((fsm
*)); /* Return length of our CI */
149 static void ipv6cp_addci
__P((fsm
*, u_char
*, int *)); /* Add our CI */
150 static int ipv6cp_ackci
__P((fsm
*, u_char
*, int)); /* Peer ack'd our CI */
151 static int ipv6cp_nakci
__P((fsm
*, u_char
*, int)); /* Peer nak'd our CI */
152 static int ipv6cp_rejci
__P((fsm
*, u_char
*, int)); /* Peer rej'd our CI */
153 static int ipv6cp_reqci
__P((fsm
*, u_char
*, int *, int)); /* Rcv CI */
154 static void ipv6cp_up
__P((fsm
*)); /* We're UP */
155 static void ipv6cp_down
__P((fsm
*)); /* We're DOWN */
156 static void ipv6cp_finished
__P((fsm
*)); /* Don't need lower layer */
158 fsm ipv6cp_fsm
[NUM_PPP
]; /* IPV6CP fsm structure */
160 static fsm_callbacks ipv6cp_callbacks
= { /* IPV6CP callback routines */
161 ipv6cp_resetci
, /* Reset our Configuration Information */
162 ipv6cp_cilen
, /* Length of our Configuration Information */
163 ipv6cp_addci
, /* Add our Configuration Information */
164 ipv6cp_ackci
, /* ACK our Configuration Information */
165 ipv6cp_nakci
, /* NAK our Configuration Information */
166 ipv6cp_rejci
, /* Reject our Configuration Information */
167 ipv6cp_reqci
, /* Request peer's Configuration Information */
168 ipv6cp_up
, /* Called when fsm reaches OPENED state */
169 ipv6cp_down
, /* Called when fsm leaves OPENED state */
170 NULL
, /* Called when we want the lower layer up */
171 ipv6cp_finished
, /* Called when we want the lower layer down */
172 NULL
, /* Retransmission is necessary */
173 NULL
, /* Called to handle protocol-specific codes */
174 "IPV6CP", /* String name of protocol */
175 NULL
/* Peer rejected a code number */
178 static int setifaceid
__P((char **arg
, option_t
*));
181 * Command-line options.
183 static option_t ipv6cp_option_list
[] = {
184 { "ipv6", o_special
, (void *)setifaceid
,
185 "Set interface identifiers for IPV6" },
186 { "noipv6", o_bool
, &ipv6cp_protent
.enabled_flag
,
187 "Disable IPv6 and IPv6CP" },
188 { "-ipv6", o_bool
, &ipv6cp_protent
.enabled_flag
,
189 "Disable IPv6 and IPv6CP" },
190 { "+ipv6", o_bool
, &ipv6cp_protent
.enabled_flag
,
191 "Enable IPv6 and IPv6CP", 1 },
192 { "ipv6cp-accept-local", o_bool
, &ipv6cp_wantoptions
[0].accept_local
,
193 "Accept peer's interface identifier for us", 1 },
194 { "ipv6cp-use-ipaddr", o_bool
, &ipv6cp_wantoptions
[0].use_ip
,
195 "Use (default) IPv4 address as interface identifier", 1 },
197 { "ipv6cp-use-persistent", o_bool
, &ipv6cp_wantoptions
[0].use_persistent
,
198 "Use unique persistent value for link local address", 1 },
199 #endif /* defined(SOL2) */
200 { "ipv6cp-restart", o_int
, &ipv6cp_fsm
[0].timeouttime
,
201 "Set timeout for IPv6CP" },
202 { "ipv6cp-max-terminate", o_int
, &ipv6cp_fsm
[0].maxtermtransmits
,
203 "Maximum number of IPV6CP Terminate-Request" },
204 { "ipv6cp-max-configure", o_int
, &ipv6cp_fsm
[0].maxconfreqtransmits
,
205 "Maximum number of IPV6CP Configure-Request" },
206 { "ipv6cp-max-failure", o_int
, &ipv6cp_fsm
[0].maxnakloops
,
207 "Maximum number of IPV6CP Configure-Nak" },
213 * Protocol entry points from main code.
215 static void ipv6cp_init
__P((int));
216 static void ipv6cp_open
__P((int));
217 static void ipv6cp_close
__P((int, char *));
218 static void ipv6cp_lowerup
__P((int));
219 static void ipv6cp_lowerdown
__P((int));
220 static void ipv6cp_input
__P((int, u_char
*, int));
221 static void ipv6cp_protrej
__P((int));
222 static int ipv6cp_printpkt
__P((u_char
*, int,
223 void (*) __P((void *, const char *, ...)), void *));
224 static void ipv6_check_options
__P((void));
225 static int ipv6_demand_conf
__P((int));
226 static int ipv6_active_pkt
__P((u_char
*, int));
228 struct protent ipv6cp_protent
= {
229 PPP_IPV6CP
, /* Protocol Number for IPV6CP */
230 ipv6cp_init
, /* Initializes IPV6CP */
231 ipv6cp_input
, /* Processes a received IPV6CP packet */
232 ipv6cp_protrej
, /* Process a received Protocol-reject */
233 ipv6cp_lowerup
, /* Called when LCP is brought up */
234 ipv6cp_lowerdown
, /* Called when LCP has gone down */
235 ipv6cp_open
, /* Called when link is established */
236 ipv6cp_close
, /* Called when link has gone down */
237 ipv6cp_printpkt
, /* Print a packet in human readable form */
238 NULL
, /* Process a received data packet */
239 0, /* IPV6CP is disabled by default */
240 "IPV6CP", /* Name of the protocol */
241 "IPV6", /* Name of the corresponding data protocol */
242 ipv6cp_option_list
, /* List of IPV6CP command-line options */
243 ipv6_check_options
, /* Assigns default values for options */
244 ipv6_demand_conf
, /* Configures demand-dial */
245 ipv6_active_pkt
/* Bring up the link for this packet? */
249 * Local forward function declarations.
251 static void ipv6cp_clear_addrs
__P((int, eui64_t
, eui64_t
));
252 static void ipv6cp_script
__P((char *));
253 static void ipv6cp_script_done
__P((void *, int));
256 * Lengths of configuration options.
259 #define CILEN_COMPRESS 4 /* length for RFC2023 compress opt. */
260 #define CILEN_IFACEID 10 /* RFC2472, interface identifier */
262 #define CODENAME(x) ((x) == CODE_CONFACK ? "ACK" : \
263 (x) == CODE_CONFNAK ? "NAK" : "REJ")
266 * This state variable is used to ensure that we don't
267 * run an ipcp-up/down script while one is already running.
269 static enum script_state
{
272 } ipv6cp_script_state
;
273 static pid_t ipv6cp_script_pid
;
276 * setifaceid - set the interface identifiers manually
280 setifaceid(argv
, opt
)
285 ipv6cp_options
*wo
= &ipv6cp_wantoptions
[0];
286 struct in6_addr addr
;
288 #define VALIDID(a) ( (((a).s6_addr32[0] == 0) && ((a).s6_addr32[1] == 0)) && \
289 (((a).s6_addr32[2] != 0) || ((a).s6_addr32[3] != 0)) )
294 comma
= strchr(arg
, ',');
297 * If comma first character, then no local identifier
303 if (inet_pton(AF_INET6
, arg
, &addr
) != 1 || !VALIDID(addr
)) {
304 option_error("Illegal interface identifier (local): %s", arg
);
308 eui64_copy(addr
.s6_addr32
[2], wo
->ourid
);
313 * If comma last character, then no remote identifier
315 if (comma
!= NULL
&& *++comma
!= '\0') {
316 if (inet_pton(AF_INET6
, comma
, &addr
) != 1 || !VALIDID(addr
)) {
317 option_error("Illegal interface identifier (remote): %s", comma
);
320 eui64_copy(addr
.s6_addr32
[2], wo
->hisid
);
324 ipv6cp_protent
.enabled_flag
= 1;
329 * Given an interface identifier, return a string representation of the
330 * link local address associated with that identifier.
331 * string will be at most 26 characters (including null terminator).
337 struct in6_addr addr
;
338 static char addrstr
[26];
340 BZERO(&addr
, sizeof (addr
));
341 addr
.s6_addr
[0] = 0xfe;
342 addr
.s6_addr
[1] = 0x80;
343 eui64_copy(ifaceid
, addr
.s6_addr
[8]);
345 (void) inet_ntop(AF_INET6
, &addr
, addrstr
, 26);
352 * ipv6cp_init - Initialize IPV6CP.
358 fsm
*f
= &ipv6cp_fsm
[unit
];
359 ipv6cp_options
*wo
= &ipv6cp_wantoptions
[unit
];
360 ipv6cp_options
*ao
= &ipv6cp_allowoptions
[unit
];
363 f
->protocol
= PPP_IPV6CP
;
364 f
->callbacks
= &ipv6cp_callbacks
;
365 fsm_init(&ipv6cp_fsm
[unit
]);
367 BZERO(wo
, sizeof(*wo
));
368 BZERO(ao
, sizeof(*ao
));
376 wo
->vj_protocol
= IPV6CP_COMP
;
383 * ipv6cp_open - IPV6CP is allowed to come up.
389 fsm_open(&ipv6cp_fsm
[unit
]);
394 * ipv6cp_close - Take IPV6CP down.
397 ipv6cp_close(unit
, reason
)
401 fsm_close(&ipv6cp_fsm
[unit
], reason
);
406 * ipv6cp_lowerup - The lower layer is up.
412 fsm_lowerup(&ipv6cp_fsm
[unit
]);
417 * ipv6cp_lowerdown - The lower layer is down.
420 ipv6cp_lowerdown(unit
)
423 fsm_lowerdown(&ipv6cp_fsm
[unit
]);
428 * ipv6cp_input - Input IPV6CP packet.
431 ipv6cp_input(unit
, p
, len
)
436 fsm_input(&ipv6cp_fsm
[unit
], p
, len
);
441 * ipv6cp_protrej - A Protocol-Reject was received for IPV6CP.
447 fsm_protreject(&ipv6cp_fsm
[unit
]);
452 * ipv6cp_resetci - Reset our CI.
458 ipv6cp_options
*wo
= &ipv6cp_wantoptions
[f
->unit
];
459 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
461 wo
->req_ifaceid
= wo
->neg_ifaceid
&& ipv6cp_allowoptions
[f
->unit
].neg_ifaceid
;
463 if (!wo
->opt_local
) {
464 eui64_magic_nz(wo
->ourid
);
468 eui64_zero(go
->hisid
); /* last proposed interface identifier */
473 * ipv6cp_cilen - Return length of our CI.
479 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
481 #define LENCIVJ(neg) (neg ? CILEN_COMPRESS : 0)
482 #define LENCIIFACEID(neg) (neg ? CILEN_IFACEID : 0)
484 return (LENCIIFACEID(go
->neg_ifaceid
) +
485 LENCIVJ(go
->neg_vj
));
490 * ipv6cp_addci - Add our desired CIs to a packet.
493 ipv6cp_addci(f
, ucp
, lenp
)
498 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
501 #define ADDCIVJ(opt, neg, val) \
503 int vjlen = CILEN_COMPRESS; \
504 if (len >= vjlen) { \
506 PUTCHAR(vjlen, ucp); \
507 PUTSHORT(val, ucp); \
513 #define ADDCIIFACEID(opt, neg, val1) \
515 int idlen = CILEN_IFACEID; \
516 if (len >= idlen) { \
518 PUTCHAR(idlen, ucp); \
519 eui64_put(val1, ucp); \
525 ADDCIIFACEID(CI_IFACEID
, go
->neg_ifaceid
, go
->ourid
);
527 ADDCIVJ(CI_COMPRESSTYPE
, go
->neg_vj
, go
->vj_protocol
);
534 * ipv6cp_ackci - Ack our CIs.
541 ipv6cp_ackci(f
, p
, len
)
546 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
547 u_short cilen
, citype
, cishort
;
551 * CIs must be in exactly the same order that we sent...
552 * Check packet length and CI length at each step.
553 * If we find any deviations, then this packet is bad.
556 #define ACKCIVJ(opt, neg, val) \
558 int vjlen = CILEN_COMPRESS; \
559 if ((len -= vjlen) < 0) \
561 GETCHAR(citype, p); \
563 if (cilen != vjlen || \
566 GETSHORT(cishort, p); \
567 if (cishort != val) \
571 #define ACKCIIFACEID(opt, neg, val1) \
573 int idlen = CILEN_IFACEID; \
574 if ((len -= idlen) < 0) \
576 GETCHAR(citype, p); \
578 if (cilen != idlen || \
581 eui64_get(ifaceid, p); \
582 if (! eui64_equals(val1, ifaceid)) \
586 ACKCIIFACEID(CI_IFACEID
, go
->neg_ifaceid
, go
->ourid
);
588 ACKCIVJ(CI_COMPRESSTYPE
, go
->neg_vj
, go
->vj_protocol
);
591 * If there are any remaining CIs, then this packet is bad.
598 IPV6CPDEBUG(("ipv6cp_ackci: received bad Ack!"));
603 * ipv6cp_nakci - Peer has sent a NAK for some of our CIs.
604 * This should not modify any state if the Nak is bad
605 * or if IPV6CP is in the OPENED state.
612 ipv6cp_nakci(f
, p
, len
)
617 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
618 u_char citype
, cilen
, *next
;
621 ipv6cp_options no
; /* options we've seen Naks for */
622 ipv6cp_options
try; /* options to request next time */
624 BZERO(&no
, sizeof(no
));
628 * Any Nak'd CIs must be in exactly the same order that we sent.
629 * Check packet length and CI length at each step.
630 * If we find any deviations, then this packet is bad.
632 #define NAKCIIFACEID(opt, neg, code) \
634 len >= (cilen = CILEN_IFACEID) && \
639 eui64_get(ifaceid, p); \
644 #define NAKCIVJ(opt, neg, code) \
646 ((cilen = p[1]) == CILEN_COMPRESS) && \
651 GETSHORT(cishort, p); \
657 * Accept the peer's idea of {our,its} interface identifier, if different
658 * from our idea, only if the accept_{local,remote} flag is set.
660 NAKCIIFACEID(CI_IFACEID
, neg_ifaceid
,
661 if (go
->accept_local
) {
662 while (eui64_iszero(ifaceid
) ||
663 eui64_equals(ifaceid
, go
->hisid
)) /* bad luck */
664 eui64_magic(ifaceid
);
666 IPV6CPDEBUG(("local LL address %s", llv6_ntoa(ifaceid
)));
671 NAKCIVJ(CI_COMPRESSTYPE
, neg_vj
,
673 if (cishort
== IPV6CP_COMP
) {
674 try.vj_protocol
= cishort
;
681 NAKCIVJ(CI_COMPRESSTYPE
, neg_vj
,
689 * There may be remaining CIs, if the peer is requesting negotiation
690 * on an option that we didn't include in our request packet.
691 * If they want to negotiate about interface identifier, we comply.
692 * If they want us to ask for compression, we refuse.
694 while (len
> CILEN_VOID
) {
697 if( (len
-= cilen
) < 0 )
699 next
= p
+ cilen
- 2;
702 case CI_COMPRESSTYPE
:
703 if (go
->neg_vj
|| no
.neg_vj
||
704 (cilen
!= CILEN_COMPRESS
))
709 if (go
->neg_ifaceid
|| no
.neg_ifaceid
|| cilen
!= CILEN_IFACEID
)
712 eui64_get(ifaceid
, p
);
713 if (go
->accept_local
) {
714 while (eui64_iszero(ifaceid
) ||
715 eui64_equals(ifaceid
, go
->hisid
)) /* bad luck */
716 eui64_magic(ifaceid
);
725 /* If there is still anything left, this packet is bad. */
730 * OK, the Nak is good. Now we can update state.
732 if (f
->state
!= OPENED
)
738 IPV6CPDEBUG(("ipv6cp_nakci: received bad Nak!"));
744 * ipv6cp_rejci - Reject some of our CIs.
747 ipv6cp_rejci(f
, p
, len
)
752 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
756 ipv6cp_options
try; /* options to request next time */
760 * Any Rejected CIs must be in exactly the same order that we sent.
761 * Check packet length and CI length at each step.
762 * If we find any deviations, then this packet is bad.
764 #define REJCIIFACEID(opt, neg, val1) \
766 len >= (cilen = CILEN_IFACEID) && \
771 eui64_get(ifaceid, p); \
772 /* Check rejected value. */ \
773 if (! eui64_equals(ifaceid, val1)) \
778 #define REJCIVJ(opt, neg, val) \
780 p[1] == CILEN_COMPRESS && \
785 GETSHORT(cishort, p); \
786 /* Check rejected value. */ \
787 if (cishort != val) \
792 REJCIIFACEID(CI_IFACEID
, neg_ifaceid
, go
->ourid
);
794 REJCIVJ(CI_COMPRESSTYPE
, neg_vj
, go
->vj_protocol
);
797 * If there are any remaining CIs, then this packet is bad.
802 * Now we can update state.
804 if (f
->state
!= OPENED
)
809 IPV6CPDEBUG(("ipv6cp_rejci: received bad Reject!"));
815 * ipv6cp_reqci - Check the peer's requested CIs and send appropriate response.
817 * Returns: CODE_CONFACK, CODE_CONFNAK or CODE_CONFREJ and input packet modified
818 * appropriately. If reject_if_disagree is non-zero, doesn't return
819 * CODE_CONFNAK; returns CODE_CONFREJ if it can't return CODE_CONFACK.
822 ipv6cp_reqci(f
, p
, lenp
, dont_nak
)
824 u_char
*p
; /* Requested CIs */
825 int *lenp
; /* Length of requested CIs */
828 ipv6cp_options
*wo
= &ipv6cp_wantoptions
[f
->unit
];
829 ipv6cp_options
*ho
= &ipv6cp_hisoptions
[f
->unit
];
830 ipv6cp_options
*ao
= &ipv6cp_allowoptions
[f
->unit
];
831 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
832 u_char
*p0
, *nakp
, *rejp
, *prev
;
834 int len
, cilen
, type
;
843 * Reset all its options.
845 BZERO(ho
, sizeof(*ho
));
848 * Process all its options.
850 for (len
= *lenp
; len
> 0; len
-= cilen
, p
= prev
+ cilen
) {
851 newret
= CODE_CONFACK
;
853 if ((len
< 2) || p
[1] > len
) {
855 * RFC 1661 page 40 -- if the option extends beyond the
856 * packet, then discard the entire packet.
865 switch (type
) { /* Check CI type */
867 IPV6CPDEBUG(("ipv6cp: received interface identifier "));
869 if (!ao
->neg_ifaceid
) {
870 newret
= CODE_CONFREJ
;
874 if (cilen
!= CILEN_IFACEID
) {
876 * rfc1661, page 40 -- a recongnized option with an
877 * invalid length should be Nak'ed.
879 newret
= CODE_CONFNAK
;
880 eui64_copy(wo
->hisid
, ifaceid
);
884 * If it has no interface identifier, or if we both
885 * have same identifier then NAK it with new idea. In
886 * particular, if we don't know his identifier, but it
887 * does, then accept that identifier.
889 eui64_get(ifaceid
, p
);
890 IPV6CPDEBUG(("(%s)", llv6_ntoa(ifaceid
)));
891 if (eui64_iszero(ifaceid
) && eui64_iszero(go
->ourid
)) {
892 newret
= CODE_CONFREJ
; /* Reject CI */
895 /* If we don't like its ID, then nak that ID. */
896 if (!eui64_iszero(wo
->hisid
) &&
897 !eui64_equals(ifaceid
, wo
->hisid
) &&
898 eui64_iszero(go
->hisid
)) {
899 newret
= CODE_CONFNAK
;
900 eui64_copy(wo
->hisid
, ifaceid
);
901 } else if (eui64_iszero(ifaceid
) ||
902 eui64_equals(ifaceid
, go
->ourid
)) {
903 newret
= CODE_CONFNAK
;
904 /* first time, try option */
905 if (eui64_iszero(go
->hisid
))
906 eui64_copy(wo
->hisid
, ifaceid
);
907 while (eui64_iszero(ifaceid
) ||
908 eui64_equals(ifaceid
, go
->ourid
)) /* bad luck */
909 eui64_magic(ifaceid
);
912 if (newret
== CODE_CONFNAK
) {
914 PUTCHAR(CILEN_IFACEID
, nakp
);
915 eui64_put(ifaceid
, nakp
);
919 eui64_copy(ifaceid
, ho
->hisid
);
922 case CI_COMPRESSTYPE
:
923 IPV6CPDEBUG(("ipv6cp: received COMPRESSTYPE "));
926 newret
= CODE_CONFREJ
;
930 if (cilen
!= CILEN_COMPRESS
) {
931 newret
= CODE_CONFNAK
;
932 cishort
= ao
->vj_protocol
;
934 GETSHORT(cishort
, p
);
935 IPV6CPDEBUG(("(%d)", cishort
));
938 if (cishort
!= IPV6CP_COMP
) {
939 newret
= CODE_CONFNAK
;
940 cishort
= IPV6CP_COMP
;
943 newret
= CODE_CONFREJ
;
949 ho
->vj_protocol
= cishort
;
953 newret
= CODE_CONFREJ
;
957 IPV6CPDEBUG((" (%s)\n", CODENAME(newret
)));
959 /* Cope with confused peers. */
964 * If this is an Ack'able CI, but we're sending back a Nak,
965 * don't include this CI.
967 if (newret
== CODE_CONFACK
&& ret
!= CODE_CONFACK
)
970 if (newret
== CODE_CONFNAK
) {
972 newret
= CODE_CONFREJ
;
974 /* Ignore subsequent Nak'able things if rejecting. */
975 if (ret
== CODE_CONFREJ
)
981 if (newret
== CODE_CONFREJ
) {
984 (void) BCOPY(prev
, rejp
, cilen
);
990 * If we aren't rejecting this packet, and we want to negotiate
991 * their identifier and they didn't send their identifier, then we
992 * send a NAK with a CI_IFACEID option appended. We assume the
993 * input buffer is long enough that we can append the extra
996 if (ret
!= CODE_CONFREJ
&& !ho
->neg_ifaceid
&&
997 wo
->req_ifaceid
&& !dont_nak
) {
998 if (ret
== CODE_CONFACK
)
1001 PUTCHAR(CI_IFACEID
, nakp
);
1002 PUTCHAR(CILEN_IFACEID
, nakp
);
1003 eui64_put(wo
->hisid
, nakp
);
1009 sys_block_proto(PPP_IPV6
);
1012 *lenp
= nakp
- nak_buffer
;
1013 (void) BCOPY(nak_buffer
, p0
, *lenp
);
1020 IPV6CPDEBUG(("ipv6cp: returning Configure-%s", CODENAME(ret
)));
1021 return (ret
); /* Return final code */
1026 * ipv6_check_options - check that any IP-related options are OK,
1027 * and assign appropriate defaults.
1030 ipv6_check_options()
1032 ipv6cp_options
*wo
= &ipv6cp_wantoptions
[0];
1036 * Persistent link-local id is only used when user has not explicitly
1037 * configure/hard-code the id
1039 if ((wo
->use_persistent
) && (!wo
->opt_local
) && (!wo
->opt_remote
)) {
1042 * On systems where there are no Ethernet interfaces used, there
1043 * may be other ways to obtain a persistent id. Right now, it
1044 * will fall back to using magic [see eui64_magic] below when
1045 * an EUI-48 from MAC address can't be obtained. Other possibilities
1046 * include obtaining EEPROM serial numbers, or some other unique
1047 * yet persistent number. On Sparc platforms, this is possible,
1048 * but too bad there's no standards yet for x86 machines.
1050 if (ether_to_eui64(&wo
->ourid
)) {
1057 * If ipv6cp-use-ipaddr is used, then both local and remote IPv4
1058 * addresses should be specified as options. Otherwise, since
1059 * ipcp has yet to negotiate the IPv4 addresses, the interface
1060 * identifiers will be based on meaningless values.
1063 if ((ipcp_wantoptions
[0].accept_local
||
1064 ipcp_wantoptions
[0].ouraddr
== 0) && eui64_iszero(wo
->ourid
)) {
1065 warn("either IPv4 or IPv6 local address should be non-zero for ipv6cp-use-ipaddr");
1067 if ((ipcp_wantoptions
[0].accept_remote
||
1068 ipcp_wantoptions
[0].hisaddr
== 0) && eui64_iszero(wo
->hisid
)) {
1069 warn("either IPv4 or IPv6 remote address should be non-zero for ipv6cp-use-ipaddr");
1073 if (!wo
->opt_local
) { /* init interface identifier */
1074 if (wo
->use_ip
&& eui64_iszero(wo
->ourid
)) {
1075 eui64_setlo32(wo
->ourid
, ntohl(ipcp_wantoptions
[0].ouraddr
));
1076 if (!eui64_iszero(wo
->ourid
))
1080 while (eui64_iszero(wo
->ourid
))
1081 eui64_magic(wo
->ourid
);
1084 if (!wo
->opt_remote
) {
1085 if (wo
->use_ip
&& eui64_iszero(wo
->hisid
)) {
1086 eui64_setlo32(wo
->hisid
, ntohl(ipcp_wantoptions
[0].hisaddr
));
1087 if (!eui64_iszero(wo
->hisid
))
1092 if (demand
&& (eui64_iszero(wo
->ourid
) || eui64_iszero(wo
->hisid
))) {
1093 fatal("local/remote LL address required for demand-dialling\n");
1099 * ipv6_demand_conf - configure the interface as though
1100 * IPV6CP were up, for use with dial-on-demand.
1106 ipv6cp_options
*wo
= &ipv6cp_wantoptions
[u
];
1112 if (!sif6addr(u
, wo
->ourid
, wo
->hisid
))
1118 if (!sifnpmode(u
, PPP_IPV6
, NPMODE_QUEUE
))
1121 notice("local LL address %s", llv6_ntoa(wo
->ourid
));
1122 notice("remote LL address %s", llv6_ntoa(wo
->hisid
));
1129 * ipv6cp_up - IPV6CP has come UP.
1131 * Configure the IPv6 network interface appropriately and bring it up.
1137 ipv6cp_options
*ho
= &ipv6cp_hisoptions
[f
->unit
];
1138 ipv6cp_options
*go
= &ipv6cp_gotoptions
[f
->unit
];
1139 ipv6cp_options
*wo
= &ipv6cp_wantoptions
[f
->unit
];
1141 IPV6CPDEBUG(("ipv6cp: up"));
1144 * We must have a non-zero LL address for both ends of the link.
1146 if (!ho
->neg_ifaceid
)
1147 ho
->hisid
= wo
->hisid
;
1149 if(!no_ifaceid_neg
) {
1150 if (eui64_iszero(ho
->hisid
)) {
1151 error("Could not determine remote LL address");
1152 ipv6cp_close(f
->unit
, "Could not determine remote LL address");
1155 if (eui64_iszero(go
->ourid
)) {
1156 error("Could not determine local LL address");
1157 ipv6cp_close(f
->unit
, "Could not determine local LL address");
1160 if (eui64_equals(go
->ourid
, ho
->hisid
)) {
1161 error("local and remote LL addresses are equal");
1162 ipv6cp_close(f
->unit
, "local and remote LL addresses are equal");
1168 /* set tcp compression */
1169 if (sif6comp(f
->unit
, ho
->neg_vj
) != 1) {
1170 ipv6cp_close(f
->unit
, "Could not enable TCP compression");
1176 * If we are doing dial-on-demand, the interface is already
1177 * configured, so we put out any saved-up packets, then set the
1178 * interface to pass IPv6 packets.
1181 if (! eui64_equals(go
->ourid
, wo
->ourid
) ||
1182 ! eui64_equals(ho
->hisid
, wo
->hisid
)) {
1183 if (! eui64_equals(go
->ourid
, wo
->ourid
))
1184 warn("Local LL address changed to %s",
1185 llv6_ntoa(go
->ourid
));
1186 if (! eui64_equals(ho
->hisid
, wo
->hisid
))
1187 warn("Remote LL address changed to %s",
1188 llv6_ntoa(ho
->hisid
));
1189 ipv6cp_clear_addrs(f
->unit
, go
->ourid
, ho
->hisid
);
1191 /* Set the interface to the new addresses */
1192 if (!sif6addr(f
->unit
, go
->ourid
, ho
->hisid
)) {
1194 warn("sif6addr failed");
1195 ipv6cp_close(f
->unit
, "Interface configuration failed");
1200 demand_rexmit(PPP_IPV6
);
1201 if (sifnpmode(f
->unit
, PPP_IPV6
, NPMODE_PASS
) != 1) {
1202 ipv6cp_close(f
->unit
, "Interface configuration failed");
1211 if (!sif6addr(f
->unit
, go
->ourid
, ho
->hisid
)) {
1213 warn("sif6addr failed");
1214 ipv6cp_close(f
->unit
, "Interface configuration failed");
1219 /* bring the interface up for IPv6 */
1220 if (!sif6up(f
->unit
)) {
1222 warn("sifup failed (IPV6)");
1223 ipv6cp_close(f
->unit
, "Interface configuration failed");
1227 if (!sifup(f
->unit
)) {
1229 warn("sifup failed (IPV6)");
1230 ipv6cp_close(f
->unit
, "Interface configuration failed");
1235 if (!sif6addr(f
->unit
, go
->ourid
, ho
->hisid
)) {
1237 warn("sif6addr failed");
1238 ipv6cp_close(f
->unit
, "Interface configuration failed");
1242 if (sifnpmode(f
->unit
, PPP_IPV6
, NPMODE_PASS
) != 1) {
1243 ipv6cp_close(f
->unit
, "Interface configuration failed");
1247 notice("local LL address %s", llv6_ntoa(go
->ourid
));
1248 notice("remote LL address %s", llv6_ntoa(ho
->hisid
));
1251 np_up(f
->unit
, PPP_IPV6
);
1255 * Execute the ipv6-up script, like this:
1256 * /etc/ppp/ipv6-up interface tty speed local-LL remote-LL
1258 script_setenv("LLLOCAL", llv6_ntoa(go
->ourid
), 0);
1259 script_setenv("LLREMOTE", llv6_ntoa(ho
->hisid
), 0);
1260 if (ipv6cp_script_state
== s_down
&& ipv6cp_script_pid
== 0) {
1261 ipv6cp_script_state
= s_up
;
1262 ipv6cp_script(_PATH_IPV6UP
);
1264 sys_unblock_proto(PPP_IPV6
);
1269 * ipv6cp_down - IPV6CP has gone DOWN.
1271 * Take the IPv6 network interface down, clear its addresses
1272 * and delete routes through it.
1278 IPV6CPDEBUG(("ipv6cp: down"));
1279 update_link_stats(f
->unit
);
1282 np_down(f
->unit
, PPP_IPV6
);
1285 if (sif6comp(f
->unit
, 0) != 1) {
1287 warn("Failed to disable TCP compression.");
1292 * If we are doing dial-on-demand, set the interface
1293 * to queue up outgoing packets (for now).
1296 if (sifnpmode(f
->unit
, PPP_IPV6
, NPMODE_QUEUE
) != 1) {
1298 warn("Failed to enable queueing on outgoing packets.");
1301 if (sifnpmode(f
->unit
, PPP_IPV6
, NPMODE_ERROR
) != 1) {
1303 warn("Could not set interface to drop packets.");
1305 #if !defined(__linux__) && !(defined(SVR4) && (defined(SNI) || defined(__USLC)))
1307 if (sif6down(f
->unit
) != 1)
1308 warn("Couldn not bring interface down.");
1310 if (sifdown(f
->unit
) != 1)
1311 warn("Could not bring interface down.");
1312 #endif /* defined(SOL2) */
1314 ipv6cp_clear_addrs(f
->unit
,
1315 ipv6cp_gotoptions
[f
->unit
].ourid
,
1316 ipv6cp_hisoptions
[f
->unit
].hisid
);
1317 #if defined(__linux__) || (defined(SVR4) && (defined(SNI) || defined(__USLC)))
1318 if (sifdown(f
->unit
) != 1)
1319 warn("Could not bring interface down.");
1323 /* Execute the ipv6-down script */
1324 if (ipv6cp_script_state
== s_up
&& ipv6cp_script_pid
== 0) {
1325 ipv6cp_script_state
= s_down
;
1326 ipv6cp_script(_PATH_IPV6DOWN
);
1332 * ipv6cp_clear_addrs() - clear the interface addresses, routes,
1333 * proxy neighbour discovery entries, etc.
1336 ipv6cp_clear_addrs(unit
, ourid
, hisid
)
1341 if (cif6addr(unit
, ourid
, hisid
) != 1)
1342 warn("Could not clear addresses");
1347 * ipv6cp_finished - possibly shut down the lower layers.
1353 np_finished(f
->unit
, PPP_IPV6
);
1358 * ipv6cp_script_done - called when the ipv6-up or ipv6-down script
1363 ipv6cp_script_done(arg
, status
)
1367 ipv6cp_script_pid
= 0;
1368 switch (ipv6cp_script_state
) {
1370 if (ipv6cp_fsm
[0].state
!= OPENED
) {
1371 ipv6cp_script_state
= s_down
;
1372 ipv6cp_script(_PATH_IPV6DOWN
);
1376 if (ipv6cp_fsm
[0].state
== OPENED
) {
1377 ipv6cp_script_state
= s_up
;
1378 ipv6cp_script(_PATH_IPV6UP
);
1386 * ipv6cp_script - Execute a script with arguments
1387 * interface-name tty-name speed local-LL remote-LL.
1390 ipv6cp_script(script
)
1393 char strspeed
[32], strlocal
[26], strremote
[26];
1396 (void) slprintf(strspeed
, sizeof (strspeed
), "%d", baud_rate
);
1397 (void) strlcpy(strlocal
, llv6_ntoa(ipv6cp_gotoptions
[0].ourid
),
1399 (void) strlcpy(strremote
, llv6_ntoa(ipv6cp_hisoptions
[0].hisid
),
1400 sizeof (strremote
));
1407 argv
[5] = strremote
;
1411 ipv6cp_script_pid
= run_program(script
, argv
, 0, ipv6cp_script_done
, NULL
);
1415 ipv6cp_printpkt(p
, plen
, printer
, arg
)
1418 void (*printer
) __P((void *, const char *, ...));
1421 int code
, id
, len
, olen
;
1422 u_char
*pstart
, *optend
;
1426 if (plen
< HEADERLEN
)
1432 if (len
< HEADERLEN
|| len
> plen
)
1436 printer(arg
, " %s id=0x%x", code_name(code
, 1), id
);
1443 /* print option list */
1448 if (olen
< 2 || olen
> len
) {
1455 case CI_COMPRESSTYPE
:
1456 if (olen
>= CILEN_COMPRESS
) {
1458 GETSHORT(cishort
, p
);
1459 printer(arg
, "compress 0x%x", cishort
);
1463 if (olen
== CILEN_IFACEID
) {
1465 eui64_get(ifaceid
, p
);
1466 printer(arg
, "addr %s", llv6_ntoa(ifaceid
));
1470 printer(arg
, "%8.*B>", optend
-p
, p
);
1477 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
1479 print_string((char *)p
, len
, printer
, arg
);
1486 /* print the rest of the bytes in the packet */
1487 printer(arg
, " %32.*B", len
, p
);
1493 * ipv6_active_pkt - see if this IP packet is worth bringing the link up for.
1494 * We don't bring the link up for IP fragments or for TCP FIN packets
1497 #define TCP_HDRLEN 20
1501 ipv6_active_pkt(pkt
, len
)
1506 struct in6_addr addr
;
1512 if (len
< IP6_HDRLEN
) {
1513 dbglog("IPv6 packet of length %d is not activity", len
);
1516 (void) BCOPY(get_ip6src(pkt
), &addr
, sizeof (addr
));
1517 (void) inet_ntop(AF_INET6
, &addr
, fromstr
, 26);
1518 (void) BCOPY(get_ip6dst(pkt
), &addr
, sizeof (addr
));
1519 (void) inet_ntop(AF_INET6
, &addr
, tostr
, 26);
1520 if (get_ip6nh(pkt
) == IPPROTO_FRAGMENT
) {
1521 dbglog("IPv6 fragment from %s->%s is not activity", fromstr
, tostr
);
1524 if (get_ip6nh(pkt
) != IPPROTO_TCP
) {
1525 info("IPv6 proto %d from %s->%s is activity", get_ip6nh(pkt
), fromstr
,
1529 if (len
< IP6_HDRLEN
+ TCP_HDRLEN
) {
1530 dbglog("Bad TCP length %d<%d+%d %s->%s is not activity", len
,
1531 IP6_HDRLEN
, TCP_HDRLEN
, fromstr
, tostr
);
1534 tcp
= pkt
+ IP6_HDRLEN
;
1535 if ((get_tcpflags(tcp
) & TH_FIN
) != 0 &&
1536 len
== IP6_HDRLEN
+ get_tcpoff(tcp
) * 4) {
1537 dbglog("Empty TCP FIN %s->%s is not activity", fromstr
, tostr
);
1540 info("TCP %d data %s%s->%s is activity", len
- IP6_HDRLEN
- TCP_HDRLEN
,
1541 tcp_flag_decode(get_tcpflags(tcp
)), fromstr
, tostr
);