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.
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
60 #include "pathnames.h"
65 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
66 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
67 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
68 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
70 #define wo (&ipxcp_wantoptions[0])
71 #define ao (&ipxcp_allowoptions[0])
72 #define go (&ipxcp_gotoptions[0])
73 #define ho (&ipxcp_hisoptions[0])
76 * Callbacks for fsm code. (CI = Configuration Information)
78 static void ipxcp_resetci (fsm *); /* Reset our CI */
79 static int ipxcp_cilen (fsm *); /* Return length of our CI */
80 static void ipxcp_addci (fsm *, u_char *, int *); /* Add our CI */
81 static int ipxcp_ackci (fsm *, u_char *, int); /* Peer ack'd our CI */
82 static int ipxcp_nakci (fsm *, u_char *, int, int);/* Peer nak'd our CI */
83 static int ipxcp_rejci (fsm *, u_char *, int); /* Peer rej'd our CI */
84 static int ipxcp_reqci (fsm *, u_char *, int *, int); /* Rcv CI */
85 static void ipxcp_up (fsm *); /* We're UP */
86 static void ipxcp_down (fsm *); /* We're DOWN */
87 static void ipxcp_finished (fsm *); /* Don't need lower layer */
88 static void ipxcp_script (fsm *, char *); /* Run an up/down script */
90 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
92 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
93 ipxcp_resetci, /* Reset our Configuration Information */
94 ipxcp_cilen, /* Length of our Configuration Information */
95 ipxcp_addci, /* Add our Configuration Information */
96 ipxcp_ackci, /* ACK our Configuration Information */
97 ipxcp_nakci, /* NAK our Configuration Information */
98 ipxcp_rejci, /* Reject our Configuration Information */
99 ipxcp_reqci, /* Request peer's Configuration Information */
100 ipxcp_up, /* Called when fsm reaches OPENED state */
101 ipxcp_down, /* Called when fsm leaves OPENED state */
102 NULL, /* Called when we want the lower layer up */
103 ipxcp_finished, /* Called when we want the lower layer down */
104 NULL, /* Called when Protocol-Reject received */
105 NULL, /* Retransmission is necessary */
106 NULL, /* Called to handle protocol-specific codes */
107 "IPXCP" /* String name of protocol */
111 * Command-line options.
113 static int setipxnode (char **);
114 static void printipxnode (option_t *,
115 void (*)(void *, char *, ...), void *);
116 static int setipxname (char **);
118 static option_t ipxcp_option_list[] = {
119 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
120 "Enable IPXCP (and IPX)", OPT_PRIO | 1 },
121 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
122 "Enable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS | 1 },
123 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
124 "Disable IPXCP (and IPX)", OPT_PRIOSUB },
125 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
126 "Disable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS },
128 { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
129 "Set our IPX network number", OPT_PRIO, &ipxcp_wantoptions[0].neg_nn },
131 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
132 "Accept peer IPX network number", 1,
133 &ipxcp_allowoptions[0].accept_network },
135 { "ipx-node", o_special, (void *)setipxnode,
136 "Set IPX node number", OPT_A2PRINTER, (void *)printipxnode },
138 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
139 "Accept our IPX address", 1,
140 &ipxcp_allowoptions[0].accept_local },
142 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
143 "Accept peer's IPX address", 1,
144 &ipxcp_allowoptions[0].accept_remote },
146 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
147 "Set IPX routing proto number", OPT_PRIO,
148 &ipxcp_wantoptions[0].neg_router },
150 { "ipx-router-name", o_special, setipxname,
151 "Set IPX router name", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC,
152 &ipxcp_wantoptions[0].name },
154 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
155 "Set timeout for IPXCP", OPT_PRIO },
156 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
157 "Set max #xmits for IPXCP term-reqs", OPT_PRIO },
158 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
159 "Set max #xmits for IPXCP conf-reqs", OPT_PRIO },
160 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
161 "Set max #conf-naks for IPXCP", OPT_PRIO },
167 * Protocol entry points.
170 static void ipxcp_init (int);
171 static void ipxcp_open (int);
172 static void ipxcp_close (int, char *);
173 static void ipxcp_lowerup (int);
174 static void ipxcp_lowerdown (int);
175 static void ipxcp_input (int, u_char *, int);
176 static void ipxcp_protrej (int);
177 static int ipxcp_printpkt (u_char *, int,
178 void (*) (void *, char *, ...), void *);
180 struct protent ipxcp_protent = {
201 * Lengths of configuration options.
205 #define CILEN_COMPLETE 2 /* length of complete option */
206 #define CILEN_NETN 6 /* network number length option */
207 #define CILEN_NODEN 8 /* node number length option */
208 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
209 #define CILEN_NAME 3 /* Minimum length of router name */
210 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
212 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
213 (x) == CONFNAK ? "NAK" : "REJ")
215 static int ipxcp_is_up;
217 static char *ipx_ntoa (u_int32_t);
219 /* Used in printing the node number */
220 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
222 /* Used to generate the proper bit mask */
223 #define BIT(num) (1 << (num))
226 * Convert from internal to external notation
230 to_external(short int internal)
234 if (internal & BIT(IPX_NONE) )
243 * Make a string representation of a network IP address.
247 ipx_ntoa(u_int32_t ipxaddr)
250 slprintf(b, sizeof(b), "%x", ipxaddr);
256 setipxnodevalue(u_char *src, u_char *dst)
262 if (!isxdigit (*src))
265 for (indx = 0; indx < 5; ++indx) {
267 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
270 item = toupper (*src) - '0';
274 dst[5] = (dst[5] << 4) | item;
280 static int ipx_prio_our, ipx_prio_his;
283 setipxnode(char **argv)
290 memset (our_node, 0, 6);
291 memset (his_node, 0, 6);
293 end = setipxnodevalue ((u_char *)*argv, our_node);
296 end = setipxnodevalue (++end, his_node);
300 ipxcp_wantoptions[0].neg_node = 1;
301 if (option_priority >= ipx_prio_our) {
302 memcpy(&ipxcp_wantoptions[0].our_node[0], our_node, 6);
303 ipx_prio_our = option_priority;
305 if (have_his && option_priority >= ipx_prio_his) {
306 memcpy(&ipxcp_wantoptions[0].his_node[0], his_node, 6);
307 ipx_prio_his = option_priority;
312 option_error("invalid parameter '%s' for ipx-node option", *argv);
317 printipxnode(option_t *opt, void (*printer) (void *, char *, ...), void *arg)
321 p = ipxcp_wantoptions[0].our_node;
323 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
324 p[0], p[1], p[2], p[3], p[4], p[5]);
326 p = ipxcp_wantoptions[0].his_node;
328 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
329 p[0], p[1], p[2], p[3], p[4], p[5]);
333 setipxname (char **argv)
335 u_char *dest = ipxcp_wantoptions[0].name;
340 ipxcp_wantoptions[0].neg_name = 1;
341 ipxcp_allowoptions[0].neg_name = 1;
342 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
347 if (! isalnum (ch) && ch != '_') {
348 option_error("IPX router name must be alphanumeric or _");
352 if (count >= sizeof (ipxcp_wantoptions[0].name) - 1) {
353 option_error("IPX router name is limited to %d characters",
354 sizeof (ipxcp_wantoptions[0].name) - 1);
358 dest[count++] = toupper (ch);
366 * ipxcp_init - Initialize IPXCP.
371 fsm *f = &ipxcp_fsm[unit];
374 f->protocol = PPP_IPXCP;
375 f->callbacks = &ipxcp_callbacks;
376 fsm_init(&ipxcp_fsm[unit]);
378 memset (wo->name, 0, sizeof (wo->name));
379 memset (wo->our_node, 0, sizeof (wo->our_node));
380 memset (wo->his_node, 0, sizeof (wo->his_node));
383 wo->neg_complete = 1;
389 ao->neg_complete = 1;
392 ao->accept_local = 0;
393 ao->accept_remote = 0;
394 ao->accept_network = 0;
401 * Copy the node number
405 copy_node (u_char *src, u_char *dst)
407 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
411 * Compare node numbers
415 compare_node (u_char *src, u_char *dst)
417 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
421 * Is the node number zero?
425 zero_node (u_char *node)
428 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
429 if (node [indx] != 0)
435 * Increment the node number
439 inc_node (u_char *node)
448 PUTLONG (magic_num, outp);
452 * ipxcp_open - IPXCP is allowed to come up.
457 fsm_open(&ipxcp_fsm[unit]);
461 * ipxcp_close - Take IPXCP down.
464 ipxcp_close(int unit, char *reason)
466 fsm_close(&ipxcp_fsm[unit], reason);
471 * ipxcp_lowerup - The lower layer is up.
474 ipxcp_lowerup(int unit)
476 fsm_lowerup(&ipxcp_fsm[unit]);
481 * ipxcp_lowerdown - The lower layer is down.
484 ipxcp_lowerdown(int unit)
486 fsm_lowerdown(&ipxcp_fsm[unit]);
491 * ipxcp_input - Input IPXCP packet.
494 ipxcp_input(int unit, u_char *p, int len)
496 fsm_input(&ipxcp_fsm[unit], p, len);
501 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
503 * Pretend the lower layer went down, so we shut up.
506 ipxcp_protrej(int unit)
508 fsm_lowerdown(&ipxcp_fsm[unit]);
513 * ipxcp_resetci - Reset our CI.
516 ipxcp_resetci(fsm *f)
518 wo->req_node = wo->neg_node && ao->neg_node;
519 wo->req_nn = wo->neg_nn && ao->neg_nn;
521 if (wo->our_network == 0) {
523 ao->accept_network = 1;
526 * If our node number is zero then change it.
528 if (zero_node (wo->our_node)) {
529 inc_node (wo->our_node);
530 ao->accept_local = 1;
534 * If his node number is zero then change it.
536 if (zero_node (wo->his_node)) {
537 inc_node (wo->his_node);
538 ao->accept_remote = 1;
541 * If no routing agent was specified then we do RIP/SAP according to the
542 * RFC documents. If you have specified something then OK. Otherwise, we
545 if (ao->router == 0) {
546 ao->router |= BIT(RIP_SAP);
547 wo->router |= BIT(RIP_SAP);
550 /* Always specify a routing protocol unless it was REJected. */
553 * Start with these default values
559 * ipxcp_cilen - Return length of our CI.
567 len = go->neg_nn ? CILEN_NETN : 0;
568 len += go->neg_node ? CILEN_NODEN : 0;
569 len += go->neg_name ? CILEN_NAME + strlen ((char *)go->name) - 1 : 0;
571 /* RFC says that defaults should not be included. */
572 if (go->neg_router && to_external(go->router) != RIP_SAP)
573 len += CILEN_PROTOCOL;
580 * ipxcp_addci - Add our desired CIs to a packet.
583 ipxcp_addci(fsm *f, u_char *ucp, int *lenp)
586 * Add the options to the record.
589 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
590 PUTCHAR (CILEN_NETN, ucp);
591 PUTLONG (go->our_network, ucp);
596 PUTCHAR (IPX_NODE_NUMBER, ucp);
597 PUTCHAR (CILEN_NODEN, ucp);
598 for (indx = 0; indx < sizeof (go->our_node); ++indx)
599 PUTCHAR (go->our_node[indx], ucp);
603 int cilen = strlen ((char *)go->name);
605 PUTCHAR (IPX_ROUTER_NAME, ucp);
606 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
607 for (indx = 0; indx < cilen; ++indx)
608 PUTCHAR (go->name [indx], ucp);
611 if (go->neg_router) {
612 short external = to_external (go->router);
613 if (external != RIP_SAP) {
614 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
615 PUTCHAR (CILEN_PROTOCOL, ucp);
616 PUTSHORT (external, ucp);
622 * ipxcp_ackci - Ack our CIs.
629 ipxcp_ackci(fsm *f, u_char *p, int len)
631 u_short cilen, citype, cishort;
635 #define ACKCIVOID(opt, neg) \
637 if ((len -= CILEN_VOID) < 0) \
639 GETCHAR(citype, p); \
641 if (cilen != CILEN_VOID || \
646 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
648 #define ACKCICHARS(opt, neg, val, cnt) \
650 int indx, count = cnt; \
651 len -= (count + 2); \
654 GETCHAR(citype, p); \
656 if (cilen != (count + 2) || \
659 for (indx = 0; indx < count; ++indx) {\
660 GETCHAR(cichar, p); \
661 if (cichar != ((u_char *) &val)[indx]) \
668 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
669 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen((char *)val))
671 #define ACKCINETWORK(opt, neg, val) \
673 if ((len -= CILEN_NETN) < 0) \
675 GETCHAR(citype, p); \
677 if (cilen != CILEN_NETN || \
680 GETLONG(cilong, p); \
685 #define ACKCIPROTO(opt, neg, val) \
689 GETCHAR(citype, p); \
691 if (cilen != CILEN_PROTOCOL || citype != opt) \
696 GETSHORT(cishort, p); \
697 if (cishort != to_external (val) || cishort == RIP_SAP) \
701 * Process the ACK frame in the order in which the frame was assembled
704 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
705 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
706 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
708 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
710 * This is the end of the record.
716 * The frame is invalid
718 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
723 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
724 * This should not modify any state if the Nak is bad
725 * or if IPXCP is in the OPENED state.
733 ipxcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject)
735 u_char citype, cilen, *next;
738 ipxcp_options no; /* options we've seen Naks for */
739 ipxcp_options try; /* options to request next time */
741 BZERO(&no, sizeof(no));
744 while (len >= CILEN_VOID) {
748 if (cilen < CILEN_VOID || len < 0)
750 next = &p [cilen - CILEN_VOID];
753 case IPX_NETWORK_NUMBER:
754 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
761 else if (l && ao->accept_network)
765 case IPX_NODE_NUMBER:
766 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
772 else if (!zero_node (p) && ao->accept_local &&
773 ! compare_node (p, ho->his_node))
774 copy_node (p, try.our_node);
777 /* This has never been sent. Ignore the NAK frame */
778 case IPX_COMPRESSION_PROTOCOL:
781 case IPX_ROUTER_PROTOCOL:
782 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
786 if (s > 15) /* This is just bad, but ignore for now. */
790 if (no.router & s) /* duplicate NAKs are always bad */
793 if (no.router == 0) /* Reset on first NAK only */
801 /* These, according to the RFC, must never be NAKed. */
802 case IPX_ROUTER_NAME:
806 /* These are for options which we have not seen. */
814 * Do not permit the peer to force a router protocol which we do not
815 * support. However, default to the condition that will accept "NONE".
817 try.router &= (ao->router | BIT(IPX_NONE));
818 if (try.router == 0 && ao->router != 0)
819 try.router = BIT(IPX_NONE);
825 * OK, the Nak is good. Now we can update state.
826 * If there are any options left, we ignore them.
828 if (f->state != OPENED)
834 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
839 * ipxcp_rejci - Reject some of our CIs.
842 ipxcp_rejci(fsm *f, u_char *p, int len)
844 u_short cilen, citype, cishort;
847 ipxcp_options try; /* options to request next time */
849 #define REJCINETWORK(opt, neg, val) \
850 if (neg && p[0] == opt) { \
851 if ((len -= CILEN_NETN) < 0) \
853 GETCHAR(citype, p); \
855 if (cilen != CILEN_NETN || \
858 GETLONG(cilong, p); \
864 #define REJCICHARS(opt, neg, val, cnt) \
865 if (neg && p[0] == opt) { \
866 int indx, count = cnt; \
867 len -= (count + 2); \
870 GETCHAR(citype, p); \
872 if (cilen != (count + 2) || \
875 for (indx = 0; indx < count; ++indx) {\
876 GETCHAR(cichar, p); \
877 if (cichar != ((u_char *) &val)[indx]) \
885 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
886 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen((char *)val))
888 #define REJCIVOID(opt, neg) \
889 if (neg && p[0] == opt) { \
890 if ((len -= CILEN_VOID) < 0) \
892 GETCHAR(citype, p); \
894 if (cilen != CILEN_VOID || citype != opt) \
899 /* a reject for RIP/SAP is invalid since we don't send it and you can't
900 reject something which is not sent. (You can NAK, but you can't REJ.) */
901 #define REJCIPROTO(opt, neg, val, bit) \
902 if (neg && p[0] == opt) { \
903 if ((len -= CILEN_PROTOCOL) < 0) \
905 GETCHAR(citype, p); \
907 if (cilen != CILEN_PROTOCOL) \
909 GETSHORT(cishort, p); \
910 if (cishort != to_external (val) || cishort == RIP_SAP) \
915 * Any Rejected CIs must be in exactly the same order that we sent.
916 * Check packet length and CI length at each step.
917 * If we find any deviations, then this packet is bad.
922 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
923 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
924 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
925 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
927 * This is the end of the record.
930 if (f->state != OPENED)
936 * The frame is invalid at this point.
938 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
943 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
945 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
946 * appropriately. If reject_if_disagree is non-zero, doesn't return
947 * CONFNAK; returns CONFREJ if it can't return CONFACK.
950 ipxcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree)
952 u_char *cip, *next; /* Pointer to current and next CIs */
953 u_short cilen, citype; /* Parsed len, type */
954 u_short cishort; /* Parsed short value */
955 u_int32_t cinetwork; /* Parsed address values */
956 int rc = CONFACK; /* Final packet return code */
957 int orc; /* Individual option return code */
958 u_char *p; /* Pointer to next char to parse */
959 u_char *ucp = inp; /* Pointer to current output char */
960 int l = *len; /* Length left */
963 * Reset all his options.
965 BZERO(ho, sizeof(*ho));
968 * Process all his options.
972 orc = CONFACK; /* Assume success */
973 cip = p = next; /* Remember begining of CI */
974 if (l < 2 || /* Not enough data for CI header or */
975 p[1] < 2 || /* CI length too small or */
976 p[1] > l) { /* CI length too big? */
977 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
978 orc = CONFREJ; /* Reject bad CI */
979 cilen = l; /* Reject till end of packet */
980 l = 0; /* Don't loop again */
983 GETCHAR(citype, p); /* Parse CI type */
984 GETCHAR(cilen, p); /* Parse CI length */
985 l -= cilen; /* Adjust remaining length */
986 next += cilen; /* Step to next CI */
988 switch (citype) { /* Check CI type */
990 * The network number must match. Choose the larger of the two.
992 case IPX_NETWORK_NUMBER:
993 /* if we wont negotiate the network number or the length is wrong
994 then reject the option */
995 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
999 GETLONG(cinetwork, p);
1001 /* If the network numbers match then acknowledge them. */
1002 if (cinetwork != 0) {
1003 ho->his_network = cinetwork;
1005 if (wo->our_network == cinetwork)
1008 * If the network number is not given or we don't accept their change or
1009 * the network number is too small then NAK it.
1011 if (! ao->accept_network || cinetwork < wo->our_network) {
1012 DECPTR (sizeof (u_int32_t), p);
1013 PUTLONG (wo->our_network, p);
1019 * The peer sent '0' for the network. Give it ours if we have one.
1021 if (go->our_network != 0) {
1022 DECPTR (sizeof (u_int32_t), p);
1023 PUTLONG (wo->our_network, p);
1026 * We don't have one. Reject the value.
1033 * The node number is required
1035 case IPX_NODE_NUMBER:
1036 /* if we wont negotiate the node number or the length is wrong
1037 then reject the option */
1038 if ( cilen != CILEN_NODEN ) {
1043 copy_node (p, ho->his_node);
1046 * If the remote does not have a number and we do then NAK it with the value
1047 * which we have for it. (We never have a default value of zero.)
1049 if (zero_node (ho->his_node)) {
1051 copy_node (wo->his_node, p);
1052 INCPTR (sizeof (wo->his_node), p);
1056 * If you have given me the expected network node number then I'll accept
1059 if (compare_node (wo->his_node, ho->his_node)) {
1062 INCPTR (sizeof (wo->his_node), p);
1066 * If his node number is the same as ours then ask him to try the next
1069 if (compare_node (ho->his_node, go->our_node)) {
1070 inc_node (ho->his_node);
1072 copy_node (ho->his_node, p);
1073 INCPTR (sizeof (wo->his_node), p);
1077 * If we don't accept a new value then NAK it.
1079 if (! ao->accept_remote) {
1080 copy_node (wo->his_node, p);
1081 INCPTR (sizeof (wo->his_node), p);
1087 INCPTR (sizeof (wo->his_node), p);
1090 * Compression is not desired at this time. It is always rejected.
1092 case IPX_COMPRESSION_PROTOCOL:
1096 * The routing protocol is a bitmask of various types. Any combination
1097 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1098 * routing protocol must be specified only once.
1100 case IPX_ROUTER_PROTOCOL:
1101 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1106 GETSHORT (cishort, p);
1108 if (wo->neg_router == 0) {
1110 wo->router = BIT(IPX_NONE);
1113 if ((cishort == IPX_NONE && ho->router != 0) ||
1114 (ho->router & BIT(IPX_NONE))) {
1119 cishort = BIT(cishort);
1120 if (ho->router & cishort) {
1125 ho->router |= cishort;
1128 /* Finally do not allow a router protocol which we do not
1131 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1134 if (cishort == BIT(NLSP) &&
1135 (ao->router & BIT(RIP_SAP)) &&
1140 protocol = IPX_NONE;
1142 DECPTR (sizeof (u_int16_t), p);
1143 PUTSHORT (protocol, p);
1148 * The router name is advisorary. Just accept it if it is not too large.
1150 case IPX_ROUTER_NAME:
1151 if (cilen >= CILEN_NAME) {
1152 int name_size = cilen - CILEN_NAME;
1153 if (name_size >= sizeof (ho->name))
1154 name_size = sizeof (ho->name) - 1;
1155 memset (ho->name, 0, sizeof (ho->name));
1156 memcpy (ho->name, p, name_size);
1157 ho->name [name_size] = '\0';
1165 * This is advisorary.
1168 if (cilen != CILEN_COMPLETE)
1171 ho->neg_complete = 1;
1176 * All other entries are not known at this time.
1183 if (orc == CONFACK && /* Good CI */
1184 rc != CONFACK) /* but prior CI wasnt? */
1185 continue; /* Don't send this one */
1187 if (orc == CONFNAK) { /* Nak this CI? */
1188 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1189 orc = CONFREJ; /* Get tough if so */
1190 if (rc == CONFREJ) /* Rejecting prior CI? */
1191 continue; /* Don't send this one */
1192 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1193 rc = CONFNAK; /* Not anymore... */
1194 ucp = inp; /* Backup */
1198 if (orc == CONFREJ && /* Reject this CI */
1199 rc != CONFREJ) { /* but no prior ones? */
1201 ucp = inp; /* Backup */
1204 /* Need to move CI? */
1206 BCOPY(cip, ucp, cilen); /* Move it */
1208 /* Update output pointer */
1213 * If we aren't rejecting this packet, and we want to negotiate
1214 * their address, and they didn't send their address, then we
1215 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1216 * input buffer is long enough that we can append the extra
1220 if (rc != CONFREJ && !ho->neg_node &&
1221 wo->req_nn && !reject_if_disagree) {
1222 if (rc == CONFACK) {
1224 wo->req_nn = 0; /* don't ask again */
1225 ucp = inp; /* reset pointer */
1228 if (zero_node (wo->his_node))
1229 inc_node (wo->his_node);
1231 PUTCHAR (IPX_NODE_NUMBER, ucp);
1232 PUTCHAR (CILEN_NODEN, ucp);
1233 copy_node (wo->his_node, ucp);
1234 INCPTR (sizeof (wo->his_node), ucp);
1237 *len = ucp - inp; /* Compute output length */
1238 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1239 return (rc); /* Return final code */
1243 * ipxcp_up - IPXCP has come UP.
1245 * Configure the IP network interface appropriately and bring it up.
1253 IPXCPDEBUG(("ipxcp: up"));
1255 /* The default router protocol is RIP/SAP. */
1256 if (ho->router == 0)
1257 ho->router = BIT(RIP_SAP);
1259 if (go->router == 0)
1260 go->router = BIT(RIP_SAP);
1262 /* Fetch the network number */
1264 ho->his_network = wo->his_network;
1267 copy_node (wo->his_node, ho->his_node);
1269 if (!wo->neg_node && !go->neg_node)
1270 copy_node (wo->our_node, go->our_node);
1272 if (zero_node (go->our_node)) {
1273 static char errmsg[] = "Could not determine local IPX node address";
1276 ipxcp_close(f->unit, errmsg);
1280 go->network = go->our_network;
1281 if (ho->his_network != 0 && ho->his_network > go->network)
1282 go->network = ho->his_network;
1284 if (go->network == 0) {
1285 static char errmsg[] = "Can not determine network number";
1288 ipxcp_close (unit, errmsg);
1292 /* bring the interface up */
1295 warn("sifup failed (IPX)");
1296 ipxcp_close(unit, "Interface configuration failed");
1301 /* set the network number for IPX */
1302 if (!sipxfaddr(unit, go->network, go->our_node)) {
1304 warn("sipxfaddr failed");
1305 ipxcp_close(unit, "Interface configuration failed");
1309 np_up(f->unit, PPP_IPX);
1312 * Execute the ipx-up script, like this:
1313 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1316 ipxcp_script (f, _PATH_IPXUP);
1320 * ipxcp_down - IPXCP has gone DOWN.
1322 * Take the IP network interface down, clear its addresses
1323 * and delete routes through it.
1329 IPXCPDEBUG(("ipxcp: down"));
1334 np_down(f->unit, PPP_IPX);
1336 sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
1338 ipxcp_script (f, _PATH_IPXDOWN);
1343 * ipxcp_finished - possibly shut down the lower layers.
1346 ipxcp_finished(fsm *f)
1348 np_finished(f->unit, PPP_IPX);
1353 * ipxcp_script - Execute a script with arguments
1354 * interface-name tty-name speed local-IPX remote-IPX networks.
1357 ipxcp_script(fsm *f, char *script)
1359 char strspeed[32], strlocal[32], strremote[32];
1360 char strnetwork[32], strpid[32];
1361 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1363 slprintf(strpid, sizeof(strpid), "%d", getpid());
1364 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1366 strproto_lcl[0] = '\0';
1367 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1368 if (go->router & BIT(RIP_SAP))
1369 strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1370 if (go->router & BIT(NLSP))
1371 strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1374 if (strproto_lcl[0] == '\0')
1375 strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1377 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1379 strproto_rmt[0] = '\0';
1380 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1381 if (ho->router & BIT(RIP_SAP))
1382 strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1383 if (ho->router & BIT(NLSP))
1384 strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1387 if (strproto_rmt[0] == '\0')
1388 strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1390 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1392 strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1394 slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1396 slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1402 argv[4] = strnetwork;
1404 argv[6] = strremote;
1405 argv[7] = strproto_lcl;
1406 argv[8] = strproto_rmt;
1407 argv[9] = (char *)go->name;
1408 argv[10] = (char *)ho->name;
1412 run_program(script, argv, 0, NULL, NULL, 0);
1416 * ipxcp_printpkt - print the contents of an IPXCP packet.
1418 static char *ipxcp_codenames[] = {
1419 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1420 "TermReq", "TermAck", "CodeRej"
1424 ipxcp_printpkt(u_char *p, int plen,
1425 void (*printer) (void *, char *, ...), void *arg)
1427 int code, id, len, olen;
1428 u_char *pstart, *optend;
1432 if (plen < HEADERLEN)
1438 if (len < HEADERLEN || len > plen)
1441 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1442 printer(arg, " %s", ipxcp_codenames[code-1]);
1444 printer(arg, " code=0x%x", code);
1445 printer(arg, " id=0x%x", id);
1452 /* print option list */
1457 if (olen < CILEN_VOID || olen > len) {
1464 case IPX_NETWORK_NUMBER:
1465 if (olen == CILEN_NETN) {
1468 printer (arg, "network %s", ipx_ntoa (cilong));
1471 case IPX_NODE_NUMBER:
1472 if (olen == CILEN_NODEN) {
1474 printer (arg, "node ");
1475 while (p < optend) {
1477 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1481 case IPX_COMPRESSION_PROTOCOL:
1482 if (olen == CILEN_COMPRESS) {
1484 GETSHORT (cishort, p);
1485 printer (arg, "compression %d", (int) cishort);
1488 case IPX_ROUTER_PROTOCOL:
1489 if (olen == CILEN_PROTOCOL) {
1491 GETSHORT (cishort, p);
1492 printer (arg, "router proto %d", (int) cishort);
1495 case IPX_ROUTER_NAME:
1496 if (olen >= CILEN_NAME) {
1498 printer (arg, "router name \"");
1499 while (p < optend) {
1501 if (code >= 0x20 && code <= 0x7E)
1502 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1504 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1506 printer (arg, "\"");
1510 if (olen == CILEN_COMPLETE) {
1512 printer (arg, "complete");
1519 while (p < optend) {
1521 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1529 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1531 print_string((char *)p, len, printer, arg);
1538 /* print the rest of the bytes in the packet */
1539 for (; len > 0; --len) {
1541 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1546 #endif /* ifdef IPX_CHANGE */