2 * ipxcp.c - PPP IPX Control Protocol.
4 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name "Carnegie Mellon University" must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission. For permission or any legal
21 * details, please contact
22 * Office of Technology Transfer
23 * Carnegie Mellon University
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
29 * 4. Redistributions of any form whatsoever must retain the following
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
57 #include <sys/types.h>
58 #include <sys/socket.h>
59 #include <netinet/in.h>
64 #include "pathnames.h"
69 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
70 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
71 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
72 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
74 #define wo (&ipxcp_wantoptions[0])
75 #define ao (&ipxcp_allowoptions[0])
76 #define go (&ipxcp_gotoptions[0])
77 #define ho (&ipxcp_hisoptions[0])
80 * Callbacks for fsm code. (CI = Configuration Information)
82 static void ipxcp_resetci (fsm *); /* Reset our CI */
83 static int ipxcp_cilen (fsm *); /* Return length of our CI */
84 static void ipxcp_addci (fsm *, u_char *, int *); /* Add our CI */
85 static int ipxcp_ackci (fsm *, u_char *, int); /* Peer ack'd our CI */
86 static int ipxcp_nakci (fsm *, u_char *, int, int);/* Peer nak'd our CI */
87 static int ipxcp_rejci (fsm *, u_char *, int); /* Peer rej'd our CI */
88 static int ipxcp_reqci (fsm *, u_char *, int *, int); /* Rcv CI */
89 static void ipxcp_up (fsm *); /* We're UP */
90 static void ipxcp_down (fsm *); /* We're DOWN */
91 static void ipxcp_finished (fsm *); /* Don't need lower layer */
92 static void ipxcp_script (fsm *, char *); /* Run an up/down script */
94 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
96 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
97 ipxcp_resetci, /* Reset our Configuration Information */
98 ipxcp_cilen, /* Length of our Configuration Information */
99 ipxcp_addci, /* Add our Configuration Information */
100 ipxcp_ackci, /* ACK our Configuration Information */
101 ipxcp_nakci, /* NAK our Configuration Information */
102 ipxcp_rejci, /* Reject our Configuration Information */
103 ipxcp_reqci, /* Request peer's Configuration Information */
104 ipxcp_up, /* Called when fsm reaches OPENED state */
105 ipxcp_down, /* Called when fsm leaves OPENED state */
106 NULL, /* Called when we want the lower layer up */
107 ipxcp_finished, /* Called when we want the lower layer down */
108 NULL, /* Called when Protocol-Reject received */
109 NULL, /* Retransmission is necessary */
110 NULL, /* Called to handle protocol-specific codes */
111 "IPXCP" /* String name of protocol */
115 * Command-line options.
117 static int setipxnode (char **);
118 static void printipxnode (option_t *,
119 void (*)(void *, char *, ...), void *);
120 static int setipxname (char **);
122 static option_t ipxcp_option_list[] = {
123 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
124 "Enable IPXCP (and IPX)", OPT_PRIO | 1 },
125 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
126 "Enable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS | 1 },
127 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
128 "Disable IPXCP (and IPX)", OPT_PRIOSUB },
129 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
130 "Disable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS },
132 { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
133 "Set our IPX network number", OPT_PRIO, &ipxcp_wantoptions[0].neg_nn },
135 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
136 "Accept peer IPX network number", 1,
137 &ipxcp_allowoptions[0].accept_network },
139 { "ipx-node", o_special, (void *)setipxnode,
140 "Set IPX node number", OPT_A2PRINTER, (void *)printipxnode },
142 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
143 "Accept our IPX address", 1,
144 &ipxcp_allowoptions[0].accept_local },
146 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
147 "Accept peer's IPX address", 1,
148 &ipxcp_allowoptions[0].accept_remote },
150 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
151 "Set IPX routing proto number", OPT_PRIO,
152 &ipxcp_wantoptions[0].neg_router },
154 { "ipx-router-name", o_special, setipxname,
155 "Set IPX router name", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC,
156 &ipxcp_wantoptions[0].name },
158 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
159 "Set timeout for IPXCP", OPT_PRIO },
160 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
161 "Set max #xmits for IPXCP term-reqs", OPT_PRIO },
162 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
163 "Set max #xmits for IPXCP conf-reqs", OPT_PRIO },
164 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
165 "Set max #conf-naks for IPXCP", OPT_PRIO },
171 * Protocol entry points.
174 static void ipxcp_init (int);
175 static void ipxcp_open (int);
176 static void ipxcp_close (int, char *);
177 static void ipxcp_lowerup (int);
178 static void ipxcp_lowerdown (int);
179 static void ipxcp_input (int, u_char *, int);
180 static void ipxcp_protrej (int);
181 static int ipxcp_printpkt (u_char *, int,
182 void (*) (void *, char *, ...), void *);
184 struct protent ipxcp_protent = {
205 * Lengths of configuration options.
209 #define CILEN_COMPLETE 2 /* length of complete option */
210 #define CILEN_NETN 6 /* network number length option */
211 #define CILEN_NODEN 8 /* node number length option */
212 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
213 #define CILEN_NAME 3 /* Minimum length of router name */
214 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
216 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
217 (x) == CONFNAK ? "NAK" : "REJ")
219 static int ipxcp_is_up;
221 static char *ipx_ntoa (u_int32_t);
223 /* Used in printing the node number */
224 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
226 /* Used to generate the proper bit mask */
227 #define BIT(num) (1 << (num))
230 * Convert from internal to external notation
234 to_external(short int internal)
238 if (internal & BIT(IPX_NONE) )
247 * Make a string representation of a network IP address.
251 ipx_ntoa(u_int32_t ipxaddr)
254 slprintf(b, sizeof(b), "%x", ipxaddr);
260 setipxnodevalue(u_char *src, u_char *dst)
266 if (!isxdigit (*src))
269 for (indx = 0; indx < 5; ++indx) {
271 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
274 item = toupper (*src) - '0';
278 dst[5] = (dst[5] << 4) | item;
284 static int ipx_prio_our, ipx_prio_his;
287 setipxnode(char **argv)
294 memset (our_node, 0, 6);
295 memset (his_node, 0, 6);
297 end = setipxnodevalue ((u_char *)*argv, our_node);
300 end = setipxnodevalue (++end, his_node);
304 ipxcp_wantoptions[0].neg_node = 1;
305 if (option_priority >= ipx_prio_our) {
306 memcpy(&ipxcp_wantoptions[0].our_node[0], our_node, 6);
307 ipx_prio_our = option_priority;
309 if (have_his && option_priority >= ipx_prio_his) {
310 memcpy(&ipxcp_wantoptions[0].his_node[0], his_node, 6);
311 ipx_prio_his = option_priority;
316 option_error("invalid parameter '%s' for ipx-node option", *argv);
321 printipxnode(option_t *opt, void (*printer) (void *, char *, ...), void *arg)
325 p = ipxcp_wantoptions[0].our_node;
327 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
328 p[0], p[1], p[2], p[3], p[4], p[5]);
330 p = ipxcp_wantoptions[0].his_node;
332 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
333 p[0], p[1], p[2], p[3], p[4], p[5]);
337 setipxname (char **argv)
339 u_char *dest = ipxcp_wantoptions[0].name;
344 ipxcp_wantoptions[0].neg_name = 1;
345 ipxcp_allowoptions[0].neg_name = 1;
346 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
351 if (! isalnum (ch) && ch != '_') {
352 option_error("IPX router name must be alphanumeric or _");
356 if (count >= sizeof (ipxcp_wantoptions[0].name) - 1) {
357 option_error("IPX router name is limited to %d characters",
358 sizeof (ipxcp_wantoptions[0].name) - 1);
362 dest[count++] = toupper (ch);
370 * ipxcp_init - Initialize IPXCP.
375 fsm *f = &ipxcp_fsm[unit];
378 f->protocol = PPP_IPXCP;
379 f->callbacks = &ipxcp_callbacks;
380 fsm_init(&ipxcp_fsm[unit]);
382 memset (wo->name, 0, sizeof (wo->name));
383 memset (wo->our_node, 0, sizeof (wo->our_node));
384 memset (wo->his_node, 0, sizeof (wo->his_node));
387 wo->neg_complete = 1;
393 ao->neg_complete = 1;
396 ao->accept_local = 0;
397 ao->accept_remote = 0;
398 ao->accept_network = 0;
405 * Copy the node number
409 copy_node (u_char *src, u_char *dst)
411 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
415 * Compare node numbers
419 compare_node (u_char *src, u_char *dst)
421 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
425 * Is the node number zero?
429 zero_node (u_char *node)
432 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
433 if (node [indx] != 0)
439 * Increment the node number
443 inc_node (u_char *node)
452 PUTLONG (magic_num, outp);
456 * ipxcp_open - IPXCP is allowed to come up.
461 fsm_open(&ipxcp_fsm[unit]);
465 * ipxcp_close - Take IPXCP down.
468 ipxcp_close(int unit, char *reason)
470 fsm_close(&ipxcp_fsm[unit], reason);
475 * ipxcp_lowerup - The lower layer is up.
478 ipxcp_lowerup(int unit)
480 fsm_lowerup(&ipxcp_fsm[unit]);
485 * ipxcp_lowerdown - The lower layer is down.
488 ipxcp_lowerdown(int unit)
490 fsm_lowerdown(&ipxcp_fsm[unit]);
495 * ipxcp_input - Input IPXCP packet.
498 ipxcp_input(int unit, u_char *p, int len)
500 fsm_input(&ipxcp_fsm[unit], p, len);
505 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
507 * Pretend the lower layer went down, so we shut up.
510 ipxcp_protrej(int unit)
512 fsm_lowerdown(&ipxcp_fsm[unit]);
517 * ipxcp_resetci - Reset our CI.
520 ipxcp_resetci(fsm *f)
522 wo->req_node = wo->neg_node && ao->neg_node;
523 wo->req_nn = wo->neg_nn && ao->neg_nn;
525 if (wo->our_network == 0) {
527 ao->accept_network = 1;
530 * If our node number is zero then change it.
532 if (zero_node (wo->our_node)) {
533 inc_node (wo->our_node);
534 ao->accept_local = 1;
538 * If his node number is zero then change it.
540 if (zero_node (wo->his_node)) {
541 inc_node (wo->his_node);
542 ao->accept_remote = 1;
545 * If no routing agent was specified then we do RIP/SAP according to the
546 * RFC documents. If you have specified something then OK. Otherwise, we
549 if (ao->router == 0) {
550 ao->router |= BIT(RIP_SAP);
551 wo->router |= BIT(RIP_SAP);
554 /* Always specify a routing protocol unless it was REJected. */
557 * Start with these default values
563 * ipxcp_cilen - Return length of our CI.
571 len = go->neg_nn ? CILEN_NETN : 0;
572 len += go->neg_node ? CILEN_NODEN : 0;
573 len += go->neg_name ? CILEN_NAME + strlen ((char *)go->name) - 1 : 0;
575 /* RFC says that defaults should not be included. */
576 if (go->neg_router && to_external(go->router) != RIP_SAP)
577 len += CILEN_PROTOCOL;
584 * ipxcp_addci - Add our desired CIs to a packet.
587 ipxcp_addci(fsm *f, u_char *ucp, int *lenp)
590 * Add the options to the record.
593 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
594 PUTCHAR (CILEN_NETN, ucp);
595 PUTLONG (go->our_network, ucp);
600 PUTCHAR (IPX_NODE_NUMBER, ucp);
601 PUTCHAR (CILEN_NODEN, ucp);
602 for (indx = 0; indx < sizeof (go->our_node); ++indx)
603 PUTCHAR (go->our_node[indx], ucp);
607 int cilen = strlen ((char *)go->name);
609 PUTCHAR (IPX_ROUTER_NAME, ucp);
610 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
611 for (indx = 0; indx < cilen; ++indx)
612 PUTCHAR (go->name [indx], ucp);
615 if (go->neg_router) {
616 short external = to_external (go->router);
617 if (external != RIP_SAP) {
618 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
619 PUTCHAR (CILEN_PROTOCOL, ucp);
620 PUTSHORT (external, ucp);
626 * ipxcp_ackci - Ack our CIs.
633 ipxcp_ackci(fsm *f, u_char *p, int len)
635 u_short cilen, citype, cishort;
639 #define ACKCIVOID(opt, neg) \
641 if ((len -= CILEN_VOID) < 0) \
643 GETCHAR(citype, p); \
645 if (cilen != CILEN_VOID || \
650 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
652 #define ACKCICHARS(opt, neg, val, cnt) \
654 int indx, count = cnt; \
655 len -= (count + 2); \
658 GETCHAR(citype, p); \
660 if (cilen != (count + 2) || \
663 for (indx = 0; indx < count; ++indx) {\
664 GETCHAR(cichar, p); \
665 if (cichar != ((u_char *) &val)[indx]) \
672 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
673 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen((char *)val))
675 #define ACKCINETWORK(opt, neg, val) \
677 if ((len -= CILEN_NETN) < 0) \
679 GETCHAR(citype, p); \
681 if (cilen != CILEN_NETN || \
684 GETLONG(cilong, p); \
689 #define ACKCIPROTO(opt, neg, val) \
693 GETCHAR(citype, p); \
695 if (cilen != CILEN_PROTOCOL || citype != opt) \
700 GETSHORT(cishort, p); \
701 if (cishort != to_external (val) || cishort == RIP_SAP) \
705 * Process the ACK frame in the order in which the frame was assembled
708 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
709 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
710 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
712 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
714 * This is the end of the record.
720 * The frame is invalid
722 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
727 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
728 * This should not modify any state if the Nak is bad
729 * or if IPXCP is in the OPENED state.
737 ipxcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject)
739 u_char citype, cilen, *next;
742 ipxcp_options no; /* options we've seen Naks for */
743 ipxcp_options try; /* options to request next time */
745 BZERO(&no, sizeof(no));
748 while (len >= CILEN_VOID) {
752 if (cilen < CILEN_VOID || len < 0)
754 next = &p [cilen - CILEN_VOID];
757 case IPX_NETWORK_NUMBER:
758 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
765 else if (l && ao->accept_network)
769 case IPX_NODE_NUMBER:
770 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
776 else if (!zero_node (p) && ao->accept_local &&
777 ! compare_node (p, ho->his_node))
778 copy_node (p, try.our_node);
781 /* This has never been sent. Ignore the NAK frame */
782 case IPX_COMPRESSION_PROTOCOL:
785 case IPX_ROUTER_PROTOCOL:
786 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
790 if (s > 15) /* This is just bad, but ignore for now. */
794 if (no.router & s) /* duplicate NAKs are always bad */
797 if (no.router == 0) /* Reset on first NAK only */
805 /* These, according to the RFC, must never be NAKed. */
806 case IPX_ROUTER_NAME:
810 /* These are for options which we have not seen. */
818 * Do not permit the peer to force a router protocol which we do not
819 * support. However, default to the condition that will accept "NONE".
821 try.router &= (ao->router | BIT(IPX_NONE));
822 if (try.router == 0 && ao->router != 0)
823 try.router = BIT(IPX_NONE);
829 * OK, the Nak is good. Now we can update state.
830 * If there are any options left, we ignore them.
832 if (f->state != OPENED)
838 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
843 * ipxcp_rejci - Reject some of our CIs.
846 ipxcp_rejci(fsm *f, u_char *p, int len)
848 u_short cilen, citype, cishort;
851 ipxcp_options try; /* options to request next time */
853 #define REJCINETWORK(opt, neg, val) \
854 if (neg && p[0] == opt) { \
855 if ((len -= CILEN_NETN) < 0) \
857 GETCHAR(citype, p); \
859 if (cilen != CILEN_NETN || \
862 GETLONG(cilong, p); \
868 #define REJCICHARS(opt, neg, val, cnt) \
869 if (neg && p[0] == opt) { \
870 int indx, count = cnt; \
871 len -= (count + 2); \
874 GETCHAR(citype, p); \
876 if (cilen != (count + 2) || \
879 for (indx = 0; indx < count; ++indx) {\
880 GETCHAR(cichar, p); \
881 if (cichar != ((u_char *) &val)[indx]) \
889 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
890 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen((char *)val))
892 #define REJCIVOID(opt, neg) \
893 if (neg && p[0] == opt) { \
894 if ((len -= CILEN_VOID) < 0) \
896 GETCHAR(citype, p); \
898 if (cilen != CILEN_VOID || citype != opt) \
903 /* a reject for RIP/SAP is invalid since we don't send it and you can't
904 reject something which is not sent. (You can NAK, but you can't REJ.) */
905 #define REJCIPROTO(opt, neg, val, bit) \
906 if (neg && p[0] == opt) { \
907 if ((len -= CILEN_PROTOCOL) < 0) \
909 GETCHAR(citype, p); \
911 if (cilen != CILEN_PROTOCOL) \
913 GETSHORT(cishort, p); \
914 if (cishort != to_external (val) || cishort == RIP_SAP) \
919 * Any Rejected CIs must be in exactly the same order that we sent.
920 * Check packet length and CI length at each step.
921 * If we find any deviations, then this packet is bad.
926 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
927 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
928 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
929 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
931 * This is the end of the record.
934 if (f->state != OPENED)
940 * The frame is invalid at this point.
942 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
947 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
949 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
950 * appropriately. If reject_if_disagree is non-zero, doesn't return
951 * CONFNAK; returns CONFREJ if it can't return CONFACK.
954 ipxcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree)
956 u_char *cip, *next; /* Pointer to current and next CIs */
957 u_short cilen, citype; /* Parsed len, type */
958 u_short cishort; /* Parsed short value */
959 u_int32_t cinetwork; /* Parsed address values */
960 int rc = CONFACK; /* Final packet return code */
961 int orc; /* Individual option return code */
962 u_char *p; /* Pointer to next char to parse */
963 u_char *ucp = inp; /* Pointer to current output char */
964 int l = *len; /* Length left */
967 * Reset all his options.
969 BZERO(ho, sizeof(*ho));
972 * Process all his options.
976 orc = CONFACK; /* Assume success */
977 cip = p = next; /* Remember begining of CI */
978 if (l < 2 || /* Not enough data for CI header or */
979 p[1] < 2 || /* CI length too small or */
980 p[1] > l) { /* CI length too big? */
981 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
982 orc = CONFREJ; /* Reject bad CI */
983 cilen = l; /* Reject till end of packet */
984 l = 0; /* Don't loop again */
987 GETCHAR(citype, p); /* Parse CI type */
988 GETCHAR(cilen, p); /* Parse CI length */
989 l -= cilen; /* Adjust remaining length */
990 next += cilen; /* Step to next CI */
992 switch (citype) { /* Check CI type */
994 * The network number must match. Choose the larger of the two.
996 case IPX_NETWORK_NUMBER:
997 /* if we wont negotiate the network number or the length is wrong
998 then reject the option */
999 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
1003 GETLONG(cinetwork, p);
1005 /* If the network numbers match then acknowledge them. */
1006 if (cinetwork != 0) {
1007 ho->his_network = cinetwork;
1009 if (wo->our_network == cinetwork)
1012 * If the network number is not given or we don't accept their change or
1013 * the network number is too small then NAK it.
1015 if (! ao->accept_network || cinetwork < wo->our_network) {
1016 DECPTR (sizeof (u_int32_t), p);
1017 PUTLONG (wo->our_network, p);
1023 * The peer sent '0' for the network. Give it ours if we have one.
1025 if (go->our_network != 0) {
1026 DECPTR (sizeof (u_int32_t), p);
1027 PUTLONG (wo->our_network, p);
1030 * We don't have one. Reject the value.
1037 * The node number is required
1039 case IPX_NODE_NUMBER:
1040 /* if we wont negotiate the node number or the length is wrong
1041 then reject the option */
1042 if ( cilen != CILEN_NODEN ) {
1047 copy_node (p, ho->his_node);
1050 * If the remote does not have a number and we do then NAK it with the value
1051 * which we have for it. (We never have a default value of zero.)
1053 if (zero_node (ho->his_node)) {
1055 copy_node (wo->his_node, p);
1056 INCPTR (sizeof (wo->his_node), p);
1060 * If you have given me the expected network node number then I'll accept
1063 if (compare_node (wo->his_node, ho->his_node)) {
1066 INCPTR (sizeof (wo->his_node), p);
1070 * If his node number is the same as ours then ask him to try the next
1073 if (compare_node (ho->his_node, go->our_node)) {
1074 inc_node (ho->his_node);
1076 copy_node (ho->his_node, p);
1077 INCPTR (sizeof (wo->his_node), p);
1081 * If we don't accept a new value then NAK it.
1083 if (! ao->accept_remote) {
1084 copy_node (wo->his_node, p);
1085 INCPTR (sizeof (wo->his_node), p);
1091 INCPTR (sizeof (wo->his_node), p);
1094 * Compression is not desired at this time. It is always rejected.
1096 case IPX_COMPRESSION_PROTOCOL:
1100 * The routing protocol is a bitmask of various types. Any combination
1101 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1102 * routing protocol must be specified only once.
1104 case IPX_ROUTER_PROTOCOL:
1105 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1110 GETSHORT (cishort, p);
1112 if (wo->neg_router == 0) {
1114 wo->router = BIT(IPX_NONE);
1117 if ((cishort == IPX_NONE && ho->router != 0) ||
1118 (ho->router & BIT(IPX_NONE))) {
1123 cishort = BIT(cishort);
1124 if (ho->router & cishort) {
1129 ho->router |= cishort;
1132 /* Finally do not allow a router protocol which we do not
1135 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1138 if (cishort == BIT(NLSP) &&
1139 (ao->router & BIT(RIP_SAP)) &&
1144 protocol = IPX_NONE;
1146 DECPTR (sizeof (u_int16_t), p);
1147 PUTSHORT (protocol, p);
1152 * The router name is advisorary. Just accept it if it is not too large.
1154 case IPX_ROUTER_NAME:
1155 if (cilen >= CILEN_NAME) {
1156 int name_size = cilen - CILEN_NAME;
1157 if (name_size >= sizeof (ho->name))
1158 name_size = sizeof (ho->name) - 1;
1159 memset (ho->name, 0, sizeof (ho->name));
1160 memcpy (ho->name, p, name_size);
1161 ho->name [name_size] = '\0';
1169 * This is advisorary.
1172 if (cilen != CILEN_COMPLETE)
1175 ho->neg_complete = 1;
1180 * All other entries are not known at this time.
1187 if (orc == CONFACK && /* Good CI */
1188 rc != CONFACK) /* but prior CI wasnt? */
1189 continue; /* Don't send this one */
1191 if (orc == CONFNAK) { /* Nak this CI? */
1192 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1193 orc = CONFREJ; /* Get tough if so */
1194 if (rc == CONFREJ) /* Rejecting prior CI? */
1195 continue; /* Don't send this one */
1196 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1197 rc = CONFNAK; /* Not anymore... */
1198 ucp = inp; /* Backup */
1202 if (orc == CONFREJ && /* Reject this CI */
1203 rc != CONFREJ) { /* but no prior ones? */
1205 ucp = inp; /* Backup */
1208 /* Need to move CI? */
1210 BCOPY(cip, ucp, cilen); /* Move it */
1212 /* Update output pointer */
1217 * If we aren't rejecting this packet, and we want to negotiate
1218 * their address, and they didn't send their address, then we
1219 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1220 * input buffer is long enough that we can append the extra
1224 if (rc != CONFREJ && !ho->neg_node &&
1225 wo->req_nn && !reject_if_disagree) {
1226 if (rc == CONFACK) {
1228 wo->req_nn = 0; /* don't ask again */
1229 ucp = inp; /* reset pointer */
1232 if (zero_node (wo->his_node))
1233 inc_node (wo->his_node);
1235 PUTCHAR (IPX_NODE_NUMBER, ucp);
1236 PUTCHAR (CILEN_NODEN, ucp);
1237 copy_node (wo->his_node, ucp);
1238 INCPTR (sizeof (wo->his_node), ucp);
1241 *len = ucp - inp; /* Compute output length */
1242 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1243 return (rc); /* Return final code */
1247 * ipxcp_up - IPXCP has come UP.
1249 * Configure the IP network interface appropriately and bring it up.
1257 IPXCPDEBUG(("ipxcp: up"));
1259 /* The default router protocol is RIP/SAP. */
1260 if (ho->router == 0)
1261 ho->router = BIT(RIP_SAP);
1263 if (go->router == 0)
1264 go->router = BIT(RIP_SAP);
1266 /* Fetch the network number */
1268 ho->his_network = wo->his_network;
1271 copy_node (wo->his_node, ho->his_node);
1273 if (!wo->neg_node && !go->neg_node)
1274 copy_node (wo->our_node, go->our_node);
1276 if (zero_node (go->our_node)) {
1277 static char errmsg[] = "Could not determine local IPX node address";
1280 ipxcp_close(f->unit, errmsg);
1284 go->network = go->our_network;
1285 if (ho->his_network != 0 && ho->his_network > go->network)
1286 go->network = ho->his_network;
1288 if (go->network == 0) {
1289 static char errmsg[] = "Can not determine network number";
1292 ipxcp_close (unit, errmsg);
1296 /* bring the interface up */
1299 warn("sifup failed (IPX)");
1300 ipxcp_close(unit, "Interface configuration failed");
1305 /* set the network number for IPX */
1306 if (!sipxfaddr(unit, go->network, go->our_node)) {
1308 warn("sipxfaddr failed");
1309 ipxcp_close(unit, "Interface configuration failed");
1313 np_up(f->unit, PPP_IPX);
1316 * Execute the ipx-up script, like this:
1317 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1320 ipxcp_script (f, _PATH_IPXUP);
1324 * ipxcp_down - IPXCP has gone DOWN.
1326 * Take the IP network interface down, clear its addresses
1327 * and delete routes through it.
1333 IPXCPDEBUG(("ipxcp: down"));
1338 np_down(f->unit, PPP_IPX);
1340 sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
1342 ipxcp_script (f, _PATH_IPXDOWN);
1347 * ipxcp_finished - possibly shut down the lower layers.
1350 ipxcp_finished(fsm *f)
1352 np_finished(f->unit, PPP_IPX);
1357 * ipxcp_script - Execute a script with arguments
1358 * interface-name tty-name speed local-IPX remote-IPX networks.
1361 ipxcp_script(fsm *f, char *script)
1363 char strspeed[32], strlocal[32], strremote[32];
1364 char strnetwork[32], strpid[32];
1365 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1367 slprintf(strpid, sizeof(strpid), "%d", getpid());
1368 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1370 strproto_lcl[0] = '\0';
1371 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1372 if (go->router & BIT(RIP_SAP))
1373 strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1374 if (go->router & BIT(NLSP))
1375 strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1378 if (strproto_lcl[0] == '\0')
1379 strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1381 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1383 strproto_rmt[0] = '\0';
1384 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1385 if (ho->router & BIT(RIP_SAP))
1386 strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1387 if (ho->router & BIT(NLSP))
1388 strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1391 if (strproto_rmt[0] == '\0')
1392 strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1394 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1396 strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1398 slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1400 slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1406 argv[4] = strnetwork;
1408 argv[6] = strremote;
1409 argv[7] = strproto_lcl;
1410 argv[8] = strproto_rmt;
1411 argv[9] = (char *)go->name;
1412 argv[10] = (char *)ho->name;
1416 run_program(script, argv, 0, NULL, NULL, 0);
1420 * ipxcp_printpkt - print the contents of an IPXCP packet.
1422 static char *ipxcp_codenames[] = {
1423 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1424 "TermReq", "TermAck", "CodeRej"
1428 ipxcp_printpkt(u_char *p, int plen,
1429 void (*printer) (void *, char *, ...), void *arg)
1431 int code, id, len, olen;
1432 u_char *pstart, *optend;
1436 if (plen < HEADERLEN)
1442 if (len < HEADERLEN || len > plen)
1445 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1446 printer(arg, " %s", ipxcp_codenames[code-1]);
1448 printer(arg, " code=0x%x", code);
1449 printer(arg, " id=0x%x", id);
1456 /* print option list */
1461 if (olen < CILEN_VOID || olen > len) {
1468 case IPX_NETWORK_NUMBER:
1469 if (olen == CILEN_NETN) {
1472 printer (arg, "network %s", ipx_ntoa (cilong));
1475 case IPX_NODE_NUMBER:
1476 if (olen == CILEN_NODEN) {
1478 printer (arg, "node ");
1479 while (p < optend) {
1481 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1485 case IPX_COMPRESSION_PROTOCOL:
1486 if (olen == CILEN_COMPRESS) {
1488 GETSHORT (cishort, p);
1489 printer (arg, "compression %d", (int) cishort);
1492 case IPX_ROUTER_PROTOCOL:
1493 if (olen == CILEN_PROTOCOL) {
1495 GETSHORT (cishort, p);
1496 printer (arg, "router proto %d", (int) cishort);
1499 case IPX_ROUTER_NAME:
1500 if (olen >= CILEN_NAME) {
1502 printer (arg, "router name \"");
1503 while (p < optend) {
1505 if (code >= 0x20 && code <= 0x7E)
1506 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1508 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1510 printer (arg, "\"");
1514 if (olen == CILEN_COMPLETE) {
1516 printer (arg, "complete");
1523 while (p < optend) {
1525 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1533 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1535 print_string((char *)p, len, printer, arg);
1542 /* print the rest of the bytes in the packet */
1543 for (; len > 0; --len) {
1545 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1550 #endif /* ifdef IPX_CHANGE */