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.
45 #define RCSID "$Id: ipxcp.c,v 1.22 2003/07/28 12:25:41 carlsonj Exp $"
55 #include <sys/types.h>
56 #include <sys/socket.h>
57 #include <netinet/in.h>
62 #include "pathnames.h"
65 static const char rcsid[] = RCSID;
68 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
69 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
70 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
71 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
73 #define wo (&ipxcp_wantoptions[0])
74 #define ao (&ipxcp_allowoptions[0])
75 #define go (&ipxcp_gotoptions[0])
76 #define ho (&ipxcp_hisoptions[0])
79 * Callbacks for fsm code. (CI = Configuration Information)
81 static void ipxcp_resetci __P((fsm *)); /* Reset our CI */
82 static int ipxcp_cilen __P((fsm *)); /* Return length of our CI */
83 static void ipxcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
84 static int ipxcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
85 static int ipxcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
86 static int ipxcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
87 static int ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
88 static void ipxcp_up __P((fsm *)); /* We're UP */
89 static void ipxcp_down __P((fsm *)); /* We're DOWN */
90 static void ipxcp_finished __P((fsm *)); /* Don't need lower layer */
91 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
93 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
95 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
96 ipxcp_resetci, /* Reset our Configuration Information */
97 ipxcp_cilen, /* Length of our Configuration Information */
98 ipxcp_addci, /* Add our Configuration Information */
99 ipxcp_ackci, /* ACK our Configuration Information */
100 ipxcp_nakci, /* NAK our Configuration Information */
101 ipxcp_rejci, /* Reject our Configuration Information */
102 ipxcp_reqci, /* Request peer's Configuration Information */
103 ipxcp_up, /* Called when fsm reaches OPENED state */
104 ipxcp_down, /* Called when fsm leaves OPENED state */
105 NULL, /* Called when we want the lower layer up */
106 ipxcp_finished, /* Called when we want the lower layer down */
107 NULL, /* Called when Protocol-Reject received */
108 NULL, /* Retransmission is necessary */
109 NULL, /* Called to handle protocol-specific codes */
110 "IPXCP" /* String name of protocol */
114 * Command-line options.
116 static int setipxnode __P((char **));
117 static void printipxnode __P((option_t *,
118 void (*)(void *, char *, ...), void *));
119 static int setipxname __P((char **));
121 static option_t ipxcp_option_list[] = {
122 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
123 "Enable IPXCP (and IPX)", OPT_PRIO | 1 },
124 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
125 "Enable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS | 1 },
126 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
127 "Disable IPXCP (and IPX)", OPT_PRIOSUB },
128 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
129 "Disable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS },
131 { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
132 "Set our IPX network number", OPT_PRIO, &ipxcp_wantoptions[0].neg_nn },
134 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
135 "Accept peer IPX network number", 1,
136 &ipxcp_allowoptions[0].accept_network },
138 { "ipx-node", o_special, (void *)setipxnode,
139 "Set IPX node number", OPT_A2PRINTER, (void *)printipxnode },
141 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
142 "Accept our IPX address", 1,
143 &ipxcp_allowoptions[0].accept_local },
145 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
146 "Accept peer's IPX address", 1,
147 &ipxcp_allowoptions[0].accept_remote },
149 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
150 "Set IPX routing proto number", OPT_PRIO,
151 &ipxcp_wantoptions[0].neg_router },
153 { "ipx-router-name", o_special, setipxname,
154 "Set IPX router name", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC,
155 &ipxcp_wantoptions[0].name },
157 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
158 "Set timeout for IPXCP", OPT_PRIO },
159 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
160 "Set max #xmits for IPXCP term-reqs", OPT_PRIO },
161 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
162 "Set max #xmits for IPXCP conf-reqs", OPT_PRIO },
163 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
164 "Set max #conf-naks for IPXCP", OPT_PRIO },
170 * Protocol entry points.
173 static void ipxcp_init __P((int));
174 static void ipxcp_open __P((int));
175 static void ipxcp_close __P((int, char *));
176 static void ipxcp_lowerup __P((int));
177 static void ipxcp_lowerdown __P((int));
178 static void ipxcp_input __P((int, u_char *, int));
179 static void ipxcp_protrej __P((int));
180 static int ipxcp_printpkt __P((u_char *, int,
181 void (*) __P((void *, char *, ...)), void *));
183 struct protent ipxcp_protent = {
204 * Lengths of configuration options.
208 #define CILEN_COMPLETE 2 /* length of complete option */
209 #define CILEN_NETN 6 /* network number length option */
210 #define CILEN_NODEN 8 /* node number length option */
211 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
212 #define CILEN_NAME 3 /* Minimum length of router name */
213 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
215 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
216 (x) == CONFNAK ? "NAK" : "REJ")
218 static int ipxcp_is_up;
220 static char *ipx_ntoa __P((u_int32_t));
222 /* Used in printing the node number */
223 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
225 /* Used to generate the proper bit mask */
226 #define BIT(num) (1 << (num))
229 * Convert from internal to external notation
233 to_external(internal)
238 if (internal & BIT(IPX_NONE) )
247 * Make a string representation of a network IP address.
255 slprintf(b, sizeof(b), "%x", ipxaddr);
261 setipxnodevalue(src,dst)
268 if (!isxdigit (*src))
271 for (indx = 0; indx < 5; ++indx) {
273 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
276 item = toupper (*src) - '0';
280 dst[5] = (dst[5] << 4) | item;
286 static int ipx_prio_our, ipx_prio_his;
297 memset (our_node, 0, 6);
298 memset (his_node, 0, 6);
300 end = setipxnodevalue (*argv, our_node);
303 end = setipxnodevalue (++end, his_node);
307 ipxcp_wantoptions[0].neg_node = 1;
308 if (option_priority >= ipx_prio_our) {
309 memcpy(&ipxcp_wantoptions[0].our_node[0], our_node, 6);
310 ipx_prio_our = option_priority;
312 if (have_his && option_priority >= ipx_prio_his) {
313 memcpy(&ipxcp_wantoptions[0].his_node[0], his_node, 6);
314 ipx_prio_his = option_priority;
319 option_error("invalid parameter '%s' for ipx-node option", *argv);
324 printipxnode(opt, printer, arg)
326 void (*printer) __P((void *, char *, ...));
331 p = ipxcp_wantoptions[0].our_node;
333 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
334 p[0], p[1], p[2], p[3], p[4], p[5]);
336 p = ipxcp_wantoptions[0].his_node;
338 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
339 p[0], p[1], p[2], p[3], p[4], p[5]);
346 char *dest = ipxcp_wantoptions[0].name;
351 ipxcp_wantoptions[0].neg_name = 1;
352 ipxcp_allowoptions[0].neg_name = 1;
353 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
358 if (! isalnum (ch) && ch != '_') {
359 option_error("IPX router name must be alphanumeric or _");
363 if (count >= sizeof (ipxcp_wantoptions[0].name) - 1) {
364 option_error("IPX router name is limited to %d characters",
365 sizeof (ipxcp_wantoptions[0].name) - 1);
369 dest[count++] = toupper (ch);
377 * ipxcp_init - Initialize IPXCP.
383 fsm *f = &ipxcp_fsm[unit];
386 f->protocol = PPP_IPXCP;
387 f->callbacks = &ipxcp_callbacks;
388 fsm_init(&ipxcp_fsm[unit]);
390 memset (wo->name, 0, sizeof (wo->name));
391 memset (wo->our_node, 0, sizeof (wo->our_node));
392 memset (wo->his_node, 0, sizeof (wo->his_node));
395 wo->neg_complete = 1;
401 ao->neg_complete = 1;
404 ao->accept_local = 0;
405 ao->accept_remote = 0;
406 ao->accept_network = 0;
413 * Copy the node number
420 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
424 * Compare node numbers
428 compare_node (src, dst)
431 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
435 * Is the node number zero?
443 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
444 if (node [indx] != 0)
450 * Increment the node number
464 PUTLONG (magic_num, outp);
468 * ipxcp_open - IPXCP is allowed to come up.
474 fsm_open(&ipxcp_fsm[unit]);
478 * ipxcp_close - Take IPXCP down.
481 ipxcp_close(unit, reason)
485 fsm_close(&ipxcp_fsm[unit], reason);
490 * ipxcp_lowerup - The lower layer is up.
496 fsm_lowerup(&ipxcp_fsm[unit]);
501 * ipxcp_lowerdown - The lower layer is down.
504 ipxcp_lowerdown(unit)
507 fsm_lowerdown(&ipxcp_fsm[unit]);
512 * ipxcp_input - Input IPXCP packet.
515 ipxcp_input(unit, p, len)
520 fsm_input(&ipxcp_fsm[unit], p, len);
525 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
527 * Pretend the lower layer went down, so we shut up.
533 fsm_lowerdown(&ipxcp_fsm[unit]);
538 * ipxcp_resetci - Reset our CI.
544 wo->req_node = wo->neg_node && ao->neg_node;
545 wo->req_nn = wo->neg_nn && ao->neg_nn;
547 if (wo->our_network == 0) {
549 ao->accept_network = 1;
552 * If our node number is zero then change it.
554 if (zero_node (wo->our_node)) {
555 inc_node (wo->our_node);
556 ao->accept_local = 1;
560 * If his node number is zero then change it.
562 if (zero_node (wo->his_node)) {
563 inc_node (wo->his_node);
564 ao->accept_remote = 1;
567 * If no routing agent was specified then we do RIP/SAP according to the
568 * RFC documents. If you have specified something then OK. Otherwise, we
571 if (ao->router == 0) {
572 ao->router |= BIT(RIP_SAP);
573 wo->router |= BIT(RIP_SAP);
576 /* Always specify a routing protocol unless it was REJected. */
579 * Start with these default values
585 * ipxcp_cilen - Return length of our CI.
594 len = go->neg_nn ? CILEN_NETN : 0;
595 len += go->neg_node ? CILEN_NODEN : 0;
596 len += go->neg_name ? CILEN_NAME + strlen (go->name) - 1 : 0;
598 /* RFC says that defaults should not be included. */
599 if (go->neg_router && to_external(go->router) != RIP_SAP)
600 len += CILEN_PROTOCOL;
607 * ipxcp_addci - Add our desired CIs to a packet.
610 ipxcp_addci(f, ucp, lenp)
616 * Add the options to the record.
619 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
620 PUTCHAR (CILEN_NETN, ucp);
621 PUTLONG (go->our_network, ucp);
626 PUTCHAR (IPX_NODE_NUMBER, ucp);
627 PUTCHAR (CILEN_NODEN, ucp);
628 for (indx = 0; indx < sizeof (go->our_node); ++indx)
629 PUTCHAR (go->our_node[indx], ucp);
633 int cilen = strlen (go->name);
635 PUTCHAR (IPX_ROUTER_NAME, ucp);
636 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
637 for (indx = 0; indx < cilen; ++indx)
638 PUTCHAR (go->name [indx], ucp);
641 if (go->neg_router) {
642 short external = to_external (go->router);
643 if (external != RIP_SAP) {
644 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
645 PUTCHAR (CILEN_PROTOCOL, ucp);
646 PUTSHORT (external, ucp);
652 * ipxcp_ackci - Ack our CIs.
659 ipxcp_ackci(f, p, len)
664 u_short cilen, citype, cishort;
668 #define ACKCIVOID(opt, neg) \
670 if ((len -= CILEN_VOID) < 0) \
672 GETCHAR(citype, p); \
674 if (cilen != CILEN_VOID || \
679 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
681 #define ACKCICHARS(opt, neg, val, cnt) \
683 int indx, count = cnt; \
684 len -= (count + 2); \
687 GETCHAR(citype, p); \
689 if (cilen != (count + 2) || \
692 for (indx = 0; indx < count; ++indx) {\
693 GETCHAR(cichar, p); \
694 if (cichar != ((u_char *) &val)[indx]) \
701 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
702 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
704 #define ACKCINETWORK(opt, neg, val) \
706 if ((len -= CILEN_NETN) < 0) \
708 GETCHAR(citype, p); \
710 if (cilen != CILEN_NETN || \
713 GETLONG(cilong, p); \
718 #define ACKCIPROTO(opt, neg, val) \
722 GETCHAR(citype, p); \
724 if (cilen != CILEN_PROTOCOL || citype != opt) \
729 GETSHORT(cishort, p); \
730 if (cishort != to_external (val) || cishort == RIP_SAP) \
734 * Process the ACK frame in the order in which the frame was assembled
737 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
738 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
739 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
741 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
743 * This is the end of the record.
749 * The frame is invalid
751 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
756 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
757 * This should not modify any state if the Nak is bad
758 * or if IPXCP is in the OPENED state.
766 ipxcp_nakci(f, p, len)
771 u_char citype, cilen, *next;
774 ipxcp_options no; /* options we've seen Naks for */
775 ipxcp_options try; /* options to request next time */
777 BZERO(&no, sizeof(no));
780 while (len >= CILEN_VOID) {
784 if (cilen < CILEN_VOID || len < 0)
786 next = &p [cilen - CILEN_VOID];
789 case IPX_NETWORK_NUMBER:
790 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
795 if (l && ao->accept_network)
799 case IPX_NODE_NUMBER:
800 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
804 if (!zero_node (p) && ao->accept_local &&
805 ! compare_node (p, ho->his_node))
806 copy_node (p, try.our_node);
809 /* This has never been sent. Ignore the NAK frame */
810 case IPX_COMPRESSION_PROTOCOL:
813 case IPX_ROUTER_PROTOCOL:
814 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
818 if (s > 15) /* This is just bad, but ignore for now. */
822 if (no.router & s) /* duplicate NAKs are always bad */
825 if (no.router == 0) /* Reset on first NAK only */
833 /* These, according to the RFC, must never be NAKed. */
834 case IPX_ROUTER_NAME:
838 /* These are for options which we have not seen. */
846 * Do not permit the peer to force a router protocol which we do not
847 * support. However, default to the condition that will accept "NONE".
849 try.router &= (ao->router | BIT(IPX_NONE));
850 if (try.router == 0 && ao->router != 0)
851 try.router = BIT(IPX_NONE);
857 * OK, the Nak is good. Now we can update state.
858 * If there are any options left, we ignore them.
860 if (f->state != OPENED)
866 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
871 * ipxcp_rejci - Reject some of our CIs.
874 ipxcp_rejci(f, p, len)
879 u_short cilen, citype, cishort;
882 ipxcp_options try; /* options to request next time */
884 #define REJCINETWORK(opt, neg, val) \
885 if (neg && p[0] == opt) { \
886 if ((len -= CILEN_NETN) < 0) \
888 GETCHAR(citype, p); \
890 if (cilen != CILEN_NETN || \
893 GETLONG(cilong, p); \
899 #define REJCICHARS(opt, neg, val, cnt) \
900 if (neg && p[0] == opt) { \
901 int indx, count = cnt; \
902 len -= (count + 2); \
905 GETCHAR(citype, p); \
907 if (cilen != (count + 2) || \
910 for (indx = 0; indx < count; ++indx) {\
911 GETCHAR(cichar, p); \
912 if (cichar != ((u_char *) &val)[indx]) \
920 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
921 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
923 #define REJCIVOID(opt, neg) \
924 if (neg && p[0] == opt) { \
925 if ((len -= CILEN_VOID) < 0) \
927 GETCHAR(citype, p); \
929 if (cilen != CILEN_VOID || citype != opt) \
934 /* a reject for RIP/SAP is invalid since we don't send it and you can't
935 reject something which is not sent. (You can NAK, but you can't REJ.) */
936 #define REJCIPROTO(opt, neg, val, bit) \
937 if (neg && p[0] == opt) { \
938 if ((len -= CILEN_PROTOCOL) < 0) \
940 GETCHAR(citype, p); \
942 if (cilen != CILEN_PROTOCOL) \
944 GETSHORT(cishort, p); \
945 if (cishort != to_external (val) || cishort == RIP_SAP) \
950 * Any Rejected CIs must be in exactly the same order that we sent.
951 * Check packet length and CI length at each step.
952 * If we find any deviations, then this packet is bad.
957 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
958 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
959 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
960 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
962 * This is the end of the record.
965 if (f->state != OPENED)
971 * The frame is invalid at this point.
973 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
978 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
980 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
981 * appropriately. If reject_if_disagree is non-zero, doesn't return
982 * CONFNAK; returns CONFREJ if it can't return CONFACK.
985 ipxcp_reqci(f, inp, len, reject_if_disagree)
987 u_char *inp; /* Requested CIs */
988 int *len; /* Length of requested CIs */
989 int reject_if_disagree;
991 u_char *cip, *next; /* Pointer to current and next CIs */
992 u_short cilen, citype; /* Parsed len, type */
993 u_short cishort; /* Parsed short value */
994 u_int32_t cinetwork; /* Parsed address values */
995 int rc = CONFACK; /* Final packet return code */
996 int orc; /* Individual option return code */
997 u_char *p; /* Pointer to next char to parse */
998 u_char *ucp = inp; /* Pointer to current output char */
999 int l = *len; /* Length left */
1002 * Reset all his options.
1004 BZERO(ho, sizeof(*ho));
1007 * Process all his options.
1011 orc = CONFACK; /* Assume success */
1012 cip = p = next; /* Remember begining of CI */
1013 if (l < 2 || /* Not enough data for CI header or */
1014 p[1] < 2 || /* CI length too small or */
1015 p[1] > l) { /* CI length too big? */
1016 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
1017 orc = CONFREJ; /* Reject bad CI */
1018 cilen = l; /* Reject till end of packet */
1019 l = 0; /* Don't loop again */
1022 GETCHAR(citype, p); /* Parse CI type */
1023 GETCHAR(cilen, p); /* Parse CI length */
1024 l -= cilen; /* Adjust remaining length */
1025 next += cilen; /* Step to next CI */
1027 switch (citype) { /* Check CI type */
1029 * The network number must match. Choose the larger of the two.
1031 case IPX_NETWORK_NUMBER:
1032 /* if we wont negotiate the network number or the length is wrong
1033 then reject the option */
1034 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
1038 GETLONG(cinetwork, p);
1040 /* If the network numbers match then acknowledge them. */
1041 if (cinetwork != 0) {
1042 ho->his_network = cinetwork;
1044 if (wo->our_network == cinetwork)
1047 * If the network number is not given or we don't accept their change or
1048 * the network number is too small then NAK it.
1050 if (! ao->accept_network || cinetwork < wo->our_network) {
1051 DECPTR (sizeof (u_int32_t), p);
1052 PUTLONG (wo->our_network, p);
1058 * The peer sent '0' for the network. Give it ours if we have one.
1060 if (go->our_network != 0) {
1061 DECPTR (sizeof (u_int32_t), p);
1062 PUTLONG (wo->our_network, p);
1065 * We don't have one. Reject the value.
1072 * The node number is required
1074 case IPX_NODE_NUMBER:
1075 /* if we wont negotiate the node number or the length is wrong
1076 then reject the option */
1077 if ( cilen != CILEN_NODEN ) {
1082 copy_node (p, ho->his_node);
1085 * If the remote does not have a number and we do then NAK it with the value
1086 * which we have for it. (We never have a default value of zero.)
1088 if (zero_node (ho->his_node)) {
1090 copy_node (wo->his_node, p);
1091 INCPTR (sizeof (wo->his_node), p);
1095 * If you have given me the expected network node number then I'll accept
1098 if (compare_node (wo->his_node, ho->his_node)) {
1101 INCPTR (sizeof (wo->his_node), p);
1105 * If his node number is the same as ours then ask him to try the next
1108 if (compare_node (ho->his_node, go->our_node)) {
1109 inc_node (ho->his_node);
1111 copy_node (ho->his_node, p);
1112 INCPTR (sizeof (wo->his_node), p);
1116 * If we don't accept a new value then NAK it.
1118 if (! ao->accept_remote) {
1119 copy_node (wo->his_node, p);
1120 INCPTR (sizeof (wo->his_node), p);
1126 INCPTR (sizeof (wo->his_node), p);
1129 * Compression is not desired at this time. It is always rejected.
1131 case IPX_COMPRESSION_PROTOCOL:
1135 * The routing protocol is a bitmask of various types. Any combination
1136 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1137 * routing protocol must be specified only once.
1139 case IPX_ROUTER_PROTOCOL:
1140 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1145 GETSHORT (cishort, p);
1147 if (wo->neg_router == 0) {
1149 wo->router = BIT(IPX_NONE);
1152 if ((cishort == IPX_NONE && ho->router != 0) ||
1153 (ho->router & BIT(IPX_NONE))) {
1158 cishort = BIT(cishort);
1159 if (ho->router & cishort) {
1164 ho->router |= cishort;
1167 /* Finally do not allow a router protocol which we do not
1170 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1173 if (cishort == BIT(NLSP) &&
1174 (ao->router & BIT(RIP_SAP)) &&
1179 protocol = IPX_NONE;
1181 DECPTR (sizeof (u_int16_t), p);
1182 PUTSHORT (protocol, p);
1187 * The router name is advisorary. Just accept it if it is not too large.
1189 case IPX_ROUTER_NAME:
1190 if (cilen >= CILEN_NAME) {
1191 int name_size = cilen - CILEN_NAME;
1192 if (name_size > sizeof (ho->name))
1193 name_size = sizeof (ho->name) - 1;
1194 memset (ho->name, 0, sizeof (ho->name));
1195 memcpy (ho->name, p, name_size);
1196 ho->name [name_size] = '\0';
1204 * This is advisorary.
1207 if (cilen != CILEN_COMPLETE)
1210 ho->neg_complete = 1;
1215 * All other entries are not known at this time.
1222 if (orc == CONFACK && /* Good CI */
1223 rc != CONFACK) /* but prior CI wasnt? */
1224 continue; /* Don't send this one */
1226 if (orc == CONFNAK) { /* Nak this CI? */
1227 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1228 orc = CONFREJ; /* Get tough if so */
1229 if (rc == CONFREJ) /* Rejecting prior CI? */
1230 continue; /* Don't send this one */
1231 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1232 rc = CONFNAK; /* Not anymore... */
1233 ucp = inp; /* Backup */
1237 if (orc == CONFREJ && /* Reject this CI */
1238 rc != CONFREJ) { /* but no prior ones? */
1240 ucp = inp; /* Backup */
1243 /* Need to move CI? */
1245 BCOPY(cip, ucp, cilen); /* Move it */
1247 /* Update output pointer */
1252 * If we aren't rejecting this packet, and we want to negotiate
1253 * their address, and they didn't send their address, then we
1254 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1255 * input buffer is long enough that we can append the extra
1259 if (rc != CONFREJ && !ho->neg_node &&
1260 wo->req_nn && !reject_if_disagree) {
1261 if (rc == CONFACK) {
1263 wo->req_nn = 0; /* don't ask again */
1264 ucp = inp; /* reset pointer */
1267 if (zero_node (wo->his_node))
1268 inc_node (wo->his_node);
1270 PUTCHAR (IPX_NODE_NUMBER, ucp);
1271 PUTCHAR (CILEN_NODEN, ucp);
1272 copy_node (wo->his_node, ucp);
1273 INCPTR (sizeof (wo->his_node), ucp);
1276 *len = ucp - inp; /* Compute output length */
1277 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1278 return (rc); /* Return final code */
1282 * ipxcp_up - IPXCP has come UP.
1284 * Configure the IP network interface appropriately and bring it up.
1293 IPXCPDEBUG(("ipxcp: up"));
1295 /* The default router protocol is RIP/SAP. */
1296 if (ho->router == 0)
1297 ho->router = BIT(RIP_SAP);
1299 if (go->router == 0)
1300 go->router = BIT(RIP_SAP);
1302 /* Fetch the network number */
1304 ho->his_network = wo->his_network;
1307 copy_node (wo->his_node, ho->his_node);
1309 if (!wo->neg_node && !go->neg_node)
1310 copy_node (wo->our_node, go->our_node);
1312 if (zero_node (go->our_node)) {
1313 static char errmsg[] = "Could not determine local IPX node address";
1316 ipxcp_close(f->unit, errmsg);
1320 go->network = go->our_network;
1321 if (ho->his_network != 0 && ho->his_network > go->network)
1322 go->network = ho->his_network;
1324 if (go->network == 0) {
1325 static char errmsg[] = "Can not determine network number";
1328 ipxcp_close (unit, errmsg);
1332 /* bring the interface up */
1335 warn("sifup failed (IPX)");
1336 ipxcp_close(unit, "Interface configuration failed");
1341 /* set the network number for IPX */
1342 if (!sipxfaddr(unit, go->network, go->our_node)) {
1344 warn("sipxfaddr failed");
1345 ipxcp_close(unit, "Interface configuration failed");
1349 np_up(f->unit, PPP_IPX);
1352 * Execute the ipx-up script, like this:
1353 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1356 ipxcp_script (f, _PATH_IPXUP);
1360 * ipxcp_down - IPXCP has gone DOWN.
1362 * Take the IP network interface down, clear its addresses
1363 * and delete routes through it.
1370 IPXCPDEBUG(("ipxcp: down"));
1375 np_down(f->unit, PPP_IPX);
1377 sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
1379 ipxcp_script (f, _PATH_IPXDOWN);
1384 * ipxcp_finished - possibly shut down the lower layers.
1390 np_finished(f->unit, PPP_IPX);
1395 * ipxcp_script - Execute a script with arguments
1396 * interface-name tty-name speed local-IPX remote-IPX networks.
1399 ipxcp_script(f, script)
1403 char strspeed[32], strlocal[32], strremote[32];
1404 char strnetwork[32], strpid[32];
1405 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1407 slprintf(strpid, sizeof(strpid), "%d", getpid());
1408 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1410 strproto_lcl[0] = '\0';
1411 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1412 if (go->router & BIT(RIP_SAP))
1413 strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1414 if (go->router & BIT(NLSP))
1415 strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1418 if (strproto_lcl[0] == '\0')
1419 strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1421 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1423 strproto_rmt[0] = '\0';
1424 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1425 if (ho->router & BIT(RIP_SAP))
1426 strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1427 if (ho->router & BIT(NLSP))
1428 strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1431 if (strproto_rmt[0] == '\0')
1432 strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1434 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1436 strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1438 slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1440 slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1446 argv[4] = strnetwork;
1448 argv[6] = strremote;
1449 argv[7] = strproto_lcl;
1450 argv[8] = strproto_rmt;
1452 argv[10] = ho->name;
1456 run_program(script, argv, 0, NULL, NULL);
1460 * ipxcp_printpkt - print the contents of an IPXCP packet.
1462 static char *ipxcp_codenames[] = {
1463 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1464 "TermReq", "TermAck", "CodeRej"
1468 ipxcp_printpkt(p, plen, printer, arg)
1471 void (*printer) __P((void *, char *, ...));
1474 int code, id, len, olen;
1475 u_char *pstart, *optend;
1479 if (plen < HEADERLEN)
1485 if (len < HEADERLEN || len > plen)
1488 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1489 printer(arg, " %s", ipxcp_codenames[code-1]);
1491 printer(arg, " code=0x%x", code);
1492 printer(arg, " id=0x%x", id);
1499 /* print option list */
1504 if (olen < CILEN_VOID || olen > len) {
1511 case IPX_NETWORK_NUMBER:
1512 if (olen == CILEN_NETN) {
1515 printer (arg, "network %s", ipx_ntoa (cilong));
1518 case IPX_NODE_NUMBER:
1519 if (olen == CILEN_NODEN) {
1521 printer (arg, "node ");
1522 while (p < optend) {
1524 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1528 case IPX_COMPRESSION_PROTOCOL:
1529 if (olen == CILEN_COMPRESS) {
1531 GETSHORT (cishort, p);
1532 printer (arg, "compression %d", (int) cishort);
1535 case IPX_ROUTER_PROTOCOL:
1536 if (olen == CILEN_PROTOCOL) {
1538 GETSHORT (cishort, p);
1539 printer (arg, "router proto %d", (int) cishort);
1542 case IPX_ROUTER_NAME:
1543 if (olen >= CILEN_NAME) {
1545 printer (arg, "router name \"");
1546 while (p < optend) {
1548 if (code >= 0x20 && code <= 0x7E)
1549 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1551 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1553 printer (arg, "\"");
1557 if (olen == CILEN_COMPLETE) {
1559 printer (arg, "complete");
1566 while (p < optend) {
1568 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1576 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1578 print_string(p, len, printer, arg);
1585 /* print the rest of the bytes in the packet */
1586 for (; len > 0; --len) {
1588 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1593 #endif /* ifdef IPX_CHANGE */