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.24 2005/08/25 23:59:34 paulus Exp $"
55 #include <sys/types.h>
56 #include <sys/socket.h>
57 #include <netinet/in.h>
62 #include "pathnames.h"
67 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
68 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
69 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
70 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
72 #define wo (&ipxcp_wantoptions[0])
73 #define ao (&ipxcp_allowoptions[0])
74 #define go (&ipxcp_gotoptions[0])
75 #define ho (&ipxcp_hisoptions[0])
78 * Callbacks for fsm code. (CI = Configuration Information)
80 static void ipxcp_resetci __P((fsm *)); /* Reset our CI */
81 static int ipxcp_cilen __P((fsm *)); /* Return length of our CI */
82 static void ipxcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
83 static int ipxcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
84 static int ipxcp_nakci __P((fsm *, u_char *, int, int));/* Peer nak'd our CI */
85 static int ipxcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
86 static int ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
87 static void ipxcp_up __P((fsm *)); /* We're UP */
88 static void ipxcp_down __P((fsm *)); /* We're DOWN */
89 static void ipxcp_finished __P((fsm *)); /* Don't need lower layer */
90 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
92 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
94 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
95 ipxcp_resetci, /* Reset our Configuration Information */
96 ipxcp_cilen, /* Length of our Configuration Information */
97 ipxcp_addci, /* Add our Configuration Information */
98 ipxcp_ackci, /* ACK our Configuration Information */
99 ipxcp_nakci, /* NAK our Configuration Information */
100 ipxcp_rejci, /* Reject our Configuration Information */
101 ipxcp_reqci, /* Request peer's Configuration Information */
102 ipxcp_up, /* Called when fsm reaches OPENED state */
103 ipxcp_down, /* Called when fsm leaves OPENED state */
104 NULL, /* Called when we want the lower layer up */
105 ipxcp_finished, /* Called when we want the lower layer down */
106 NULL, /* Called when Protocol-Reject received */
107 NULL, /* Retransmission is necessary */
108 NULL, /* Called to handle protocol-specific codes */
109 "IPXCP" /* String name of protocol */
113 * Command-line options.
115 static int setipxnode __P((char **));
116 static void printipxnode __P((option_t *,
117 void (*)(void *, char *, ...), void *));
118 static int setipxname __P((char **));
120 static option_t ipxcp_option_list[] = {
121 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
122 "Enable IPXCP (and IPX)", OPT_PRIO | 1 },
123 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
124 "Enable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS | 1 },
125 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
126 "Disable IPXCP (and IPX)", OPT_PRIOSUB },
127 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
128 "Disable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS },
130 { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
131 "Set our IPX network number", OPT_PRIO, &ipxcp_wantoptions[0].neg_nn },
133 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
134 "Accept peer IPX network number", 1,
135 &ipxcp_allowoptions[0].accept_network },
137 { "ipx-node", o_special, (void *)setipxnode,
138 "Set IPX node number", OPT_A2PRINTER, (void *)printipxnode },
140 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
141 "Accept our IPX address", 1,
142 &ipxcp_allowoptions[0].accept_local },
144 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
145 "Accept peer's IPX address", 1,
146 &ipxcp_allowoptions[0].accept_remote },
148 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
149 "Set IPX routing proto number", OPT_PRIO,
150 &ipxcp_wantoptions[0].neg_router },
152 { "ipx-router-name", o_special, setipxname,
153 "Set IPX router name", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC,
154 &ipxcp_wantoptions[0].name },
156 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
157 "Set timeout for IPXCP", OPT_PRIO },
158 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
159 "Set max #xmits for IPXCP term-reqs", OPT_PRIO },
160 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
161 "Set max #xmits for IPXCP conf-reqs", OPT_PRIO },
162 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
163 "Set max #conf-naks for IPXCP", OPT_PRIO },
169 * Protocol entry points.
172 static void ipxcp_init __P((int));
173 static void ipxcp_open __P((int));
174 static void ipxcp_close __P((int, char *));
175 static void ipxcp_lowerup __P((int));
176 static void ipxcp_lowerdown __P((int));
177 static void ipxcp_input __P((int, u_char *, int));
178 static void ipxcp_protrej __P((int));
179 static int ipxcp_printpkt __P((u_char *, int,
180 void (*) __P((void *, char *, ...)), void *));
182 struct protent ipxcp_protent = {
203 * Lengths of configuration options.
207 #define CILEN_COMPLETE 2 /* length of complete option */
208 #define CILEN_NETN 6 /* network number length option */
209 #define CILEN_NODEN 8 /* node number length option */
210 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
211 #define CILEN_NAME 3 /* Minimum length of router name */
212 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
214 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
215 (x) == CONFNAK ? "NAK" : "REJ")
217 static int ipxcp_is_up;
219 static char *ipx_ntoa __P((u_int32_t));
221 /* Used in printing the node number */
222 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
224 /* Used to generate the proper bit mask */
225 #define BIT(num) (1 << (num))
228 * Convert from internal to external notation
232 to_external(internal)
237 if (internal & BIT(IPX_NONE) )
246 * Make a string representation of a network IP address.
254 slprintf(b, sizeof(b), "%x", ipxaddr);
260 setipxnodevalue(src,dst)
267 if (!isxdigit (*src))
270 for (indx = 0; indx < 5; ++indx) {
272 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
275 item = toupper (*src) - '0';
279 dst[5] = (dst[5] << 4) | item;
285 static int ipx_prio_our, ipx_prio_his;
296 memset (our_node, 0, 6);
297 memset (his_node, 0, 6);
299 end = setipxnodevalue (*argv, our_node);
302 end = setipxnodevalue (++end, his_node);
306 ipxcp_wantoptions[0].neg_node = 1;
307 if (option_priority >= ipx_prio_our) {
308 memcpy(&ipxcp_wantoptions[0].our_node[0], our_node, 6);
309 ipx_prio_our = option_priority;
311 if (have_his && option_priority >= ipx_prio_his) {
312 memcpy(&ipxcp_wantoptions[0].his_node[0], his_node, 6);
313 ipx_prio_his = option_priority;
318 option_error("invalid parameter '%s' for ipx-node option", *argv);
323 printipxnode(opt, printer, arg)
325 void (*printer) __P((void *, char *, ...));
330 p = ipxcp_wantoptions[0].our_node;
332 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
333 p[0], p[1], p[2], p[3], p[4], p[5]);
335 p = ipxcp_wantoptions[0].his_node;
337 printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
338 p[0], p[1], p[2], p[3], p[4], p[5]);
345 u_char *dest = ipxcp_wantoptions[0].name;
350 ipxcp_wantoptions[0].neg_name = 1;
351 ipxcp_allowoptions[0].neg_name = 1;
352 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
357 if (! isalnum (ch) && ch != '_') {
358 option_error("IPX router name must be alphanumeric or _");
362 if (count >= sizeof (ipxcp_wantoptions[0].name) - 1) {
363 option_error("IPX router name is limited to %d characters",
364 sizeof (ipxcp_wantoptions[0].name) - 1);
368 dest[count++] = toupper (ch);
376 * ipxcp_init - Initialize IPXCP.
382 fsm *f = &ipxcp_fsm[unit];
385 f->protocol = PPP_IPXCP;
386 f->callbacks = &ipxcp_callbacks;
387 fsm_init(&ipxcp_fsm[unit]);
389 memset (wo->name, 0, sizeof (wo->name));
390 memset (wo->our_node, 0, sizeof (wo->our_node));
391 memset (wo->his_node, 0, sizeof (wo->his_node));
394 wo->neg_complete = 1;
400 ao->neg_complete = 1;
403 ao->accept_local = 0;
404 ao->accept_remote = 0;
405 ao->accept_network = 0;
412 * Copy the node number
419 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
423 * Compare node numbers
427 compare_node (src, dst)
430 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
434 * Is the node number zero?
442 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
443 if (node [indx] != 0)
449 * Increment the node number
463 PUTLONG (magic_num, outp);
467 * ipxcp_open - IPXCP is allowed to come up.
473 fsm_open(&ipxcp_fsm[unit]);
477 * ipxcp_close - Take IPXCP down.
480 ipxcp_close(unit, reason)
484 fsm_close(&ipxcp_fsm[unit], reason);
489 * ipxcp_lowerup - The lower layer is up.
495 fsm_lowerup(&ipxcp_fsm[unit]);
500 * ipxcp_lowerdown - The lower layer is down.
503 ipxcp_lowerdown(unit)
506 fsm_lowerdown(&ipxcp_fsm[unit]);
511 * ipxcp_input - Input IPXCP packet.
514 ipxcp_input(unit, p, len)
519 fsm_input(&ipxcp_fsm[unit], p, len);
524 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
526 * Pretend the lower layer went down, so we shut up.
532 fsm_lowerdown(&ipxcp_fsm[unit]);
537 * ipxcp_resetci - Reset our CI.
543 wo->req_node = wo->neg_node && ao->neg_node;
544 wo->req_nn = wo->neg_nn && ao->neg_nn;
546 if (wo->our_network == 0) {
548 ao->accept_network = 1;
551 * If our node number is zero then change it.
553 if (zero_node (wo->our_node)) {
554 inc_node (wo->our_node);
555 ao->accept_local = 1;
559 * If his node number is zero then change it.
561 if (zero_node (wo->his_node)) {
562 inc_node (wo->his_node);
563 ao->accept_remote = 1;
566 * If no routing agent was specified then we do RIP/SAP according to the
567 * RFC documents. If you have specified something then OK. Otherwise, we
570 if (ao->router == 0) {
571 ao->router |= BIT(RIP_SAP);
572 wo->router |= BIT(RIP_SAP);
575 /* Always specify a routing protocol unless it was REJected. */
578 * Start with these default values
584 * ipxcp_cilen - Return length of our CI.
593 len = go->neg_nn ? CILEN_NETN : 0;
594 len += go->neg_node ? CILEN_NODEN : 0;
595 len += go->neg_name ? CILEN_NAME + strlen ((char *)go->name) - 1 : 0;
597 /* RFC says that defaults should not be included. */
598 if (go->neg_router && to_external(go->router) != RIP_SAP)
599 len += CILEN_PROTOCOL;
606 * ipxcp_addci - Add our desired CIs to a packet.
609 ipxcp_addci(f, ucp, lenp)
615 * Add the options to the record.
618 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
619 PUTCHAR (CILEN_NETN, ucp);
620 PUTLONG (go->our_network, ucp);
625 PUTCHAR (IPX_NODE_NUMBER, ucp);
626 PUTCHAR (CILEN_NODEN, ucp);
627 for (indx = 0; indx < sizeof (go->our_node); ++indx)
628 PUTCHAR (go->our_node[indx], ucp);
632 int cilen = strlen ((char *)go->name);
634 PUTCHAR (IPX_ROUTER_NAME, ucp);
635 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
636 for (indx = 0; indx < cilen; ++indx)
637 PUTCHAR (go->name [indx], ucp);
640 if (go->neg_router) {
641 short external = to_external (go->router);
642 if (external != RIP_SAP) {
643 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
644 PUTCHAR (CILEN_PROTOCOL, ucp);
645 PUTSHORT (external, ucp);
651 * ipxcp_ackci - Ack our CIs.
658 ipxcp_ackci(f, p, len)
663 u_short cilen, citype, cishort;
667 #define ACKCIVOID(opt, neg) \
669 if ((len -= CILEN_VOID) < 0) \
671 GETCHAR(citype, p); \
673 if (cilen != CILEN_VOID || \
678 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
680 #define ACKCICHARS(opt, neg, val, cnt) \
682 int indx, count = cnt; \
683 len -= (count + 2); \
686 GETCHAR(citype, p); \
688 if (cilen != (count + 2) || \
691 for (indx = 0; indx < count; ++indx) {\
692 GETCHAR(cichar, p); \
693 if (cichar != ((u_char *) &val)[indx]) \
700 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
701 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen((char *)val))
703 #define ACKCINETWORK(opt, neg, val) \
705 if ((len -= CILEN_NETN) < 0) \
707 GETCHAR(citype, p); \
709 if (cilen != CILEN_NETN || \
712 GETLONG(cilong, p); \
717 #define ACKCIPROTO(opt, neg, val) \
721 GETCHAR(citype, p); \
723 if (cilen != CILEN_PROTOCOL || citype != opt) \
728 GETSHORT(cishort, p); \
729 if (cishort != to_external (val) || cishort == RIP_SAP) \
733 * Process the ACK frame in the order in which the frame was assembled
736 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
737 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
738 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
740 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
742 * This is the end of the record.
748 * The frame is invalid
750 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
755 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
756 * This should not modify any state if the Nak is bad
757 * or if IPXCP is in the OPENED state.
765 ipxcp_nakci(f, p, len, treat_as_reject)
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))
797 else if (l && ao->accept_network)
801 case IPX_NODE_NUMBER:
802 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
808 else if (!zero_node (p) && ao->accept_local &&
809 ! compare_node (p, ho->his_node))
810 copy_node (p, try.our_node);
813 /* This has never been sent. Ignore the NAK frame */
814 case IPX_COMPRESSION_PROTOCOL:
817 case IPX_ROUTER_PROTOCOL:
818 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
822 if (s > 15) /* This is just bad, but ignore for now. */
826 if (no.router & s) /* duplicate NAKs are always bad */
829 if (no.router == 0) /* Reset on first NAK only */
837 /* These, according to the RFC, must never be NAKed. */
838 case IPX_ROUTER_NAME:
842 /* These are for options which we have not seen. */
850 * Do not permit the peer to force a router protocol which we do not
851 * support. However, default to the condition that will accept "NONE".
853 try.router &= (ao->router | BIT(IPX_NONE));
854 if (try.router == 0 && ao->router != 0)
855 try.router = BIT(IPX_NONE);
861 * OK, the Nak is good. Now we can update state.
862 * If there are any options left, we ignore them.
864 if (f->state != OPENED)
870 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
875 * ipxcp_rejci - Reject some of our CIs.
878 ipxcp_rejci(f, p, len)
883 u_short cilen, citype, cishort;
886 ipxcp_options try; /* options to request next time */
888 #define REJCINETWORK(opt, neg, val) \
889 if (neg && p[0] == opt) { \
890 if ((len -= CILEN_NETN) < 0) \
892 GETCHAR(citype, p); \
894 if (cilen != CILEN_NETN || \
897 GETLONG(cilong, p); \
903 #define REJCICHARS(opt, neg, val, cnt) \
904 if (neg && p[0] == opt) { \
905 int indx, count = cnt; \
906 len -= (count + 2); \
909 GETCHAR(citype, p); \
911 if (cilen != (count + 2) || \
914 for (indx = 0; indx < count; ++indx) {\
915 GETCHAR(cichar, p); \
916 if (cichar != ((u_char *) &val)[indx]) \
924 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
925 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen((char *)val))
927 #define REJCIVOID(opt, neg) \
928 if (neg && p[0] == opt) { \
929 if ((len -= CILEN_VOID) < 0) \
931 GETCHAR(citype, p); \
933 if (cilen != CILEN_VOID || citype != opt) \
938 /* a reject for RIP/SAP is invalid since we don't send it and you can't
939 reject something which is not sent. (You can NAK, but you can't REJ.) */
940 #define REJCIPROTO(opt, neg, val, bit) \
941 if (neg && p[0] == opt) { \
942 if ((len -= CILEN_PROTOCOL) < 0) \
944 GETCHAR(citype, p); \
946 if (cilen != CILEN_PROTOCOL) \
948 GETSHORT(cishort, p); \
949 if (cishort != to_external (val) || cishort == RIP_SAP) \
954 * Any Rejected CIs must be in exactly the same order that we sent.
955 * Check packet length and CI length at each step.
956 * If we find any deviations, then this packet is bad.
961 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
962 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
963 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
964 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
966 * This is the end of the record.
969 if (f->state != OPENED)
975 * The frame is invalid at this point.
977 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
982 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
984 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
985 * appropriately. If reject_if_disagree is non-zero, doesn't return
986 * CONFNAK; returns CONFREJ if it can't return CONFACK.
989 ipxcp_reqci(f, inp, len, reject_if_disagree)
991 u_char *inp; /* Requested CIs */
992 int *len; /* Length of requested CIs */
993 int reject_if_disagree;
995 u_char *cip, *next; /* Pointer to current and next CIs */
996 u_short cilen, citype; /* Parsed len, type */
997 u_short cishort; /* Parsed short value */
998 u_int32_t cinetwork; /* Parsed address values */
999 int rc = CONFACK; /* Final packet return code */
1000 int orc; /* Individual option return code */
1001 u_char *p; /* Pointer to next char to parse */
1002 u_char *ucp = inp; /* Pointer to current output char */
1003 int l = *len; /* Length left */
1006 * Reset all his options.
1008 BZERO(ho, sizeof(*ho));
1011 * Process all his options.
1015 orc = CONFACK; /* Assume success */
1016 cip = p = next; /* Remember begining of CI */
1017 if (l < 2 || /* Not enough data for CI header or */
1018 p[1] < 2 || /* CI length too small or */
1019 p[1] > l) { /* CI length too big? */
1020 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
1021 orc = CONFREJ; /* Reject bad CI */
1022 cilen = l; /* Reject till end of packet */
1023 l = 0; /* Don't loop again */
1026 GETCHAR(citype, p); /* Parse CI type */
1027 GETCHAR(cilen, p); /* Parse CI length */
1028 l -= cilen; /* Adjust remaining length */
1029 next += cilen; /* Step to next CI */
1031 switch (citype) { /* Check CI type */
1033 * The network number must match. Choose the larger of the two.
1035 case IPX_NETWORK_NUMBER:
1036 /* if we wont negotiate the network number or the length is wrong
1037 then reject the option */
1038 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
1042 GETLONG(cinetwork, p);
1044 /* If the network numbers match then acknowledge them. */
1045 if (cinetwork != 0) {
1046 ho->his_network = cinetwork;
1048 if (wo->our_network == cinetwork)
1051 * If the network number is not given or we don't accept their change or
1052 * the network number is too small then NAK it.
1054 if (! ao->accept_network || cinetwork < wo->our_network) {
1055 DECPTR (sizeof (u_int32_t), p);
1056 PUTLONG (wo->our_network, p);
1062 * The peer sent '0' for the network. Give it ours if we have one.
1064 if (go->our_network != 0) {
1065 DECPTR (sizeof (u_int32_t), p);
1066 PUTLONG (wo->our_network, p);
1069 * We don't have one. Reject the value.
1076 * The node number is required
1078 case IPX_NODE_NUMBER:
1079 /* if we wont negotiate the node number or the length is wrong
1080 then reject the option */
1081 if ( cilen != CILEN_NODEN ) {
1086 copy_node (p, ho->his_node);
1089 * If the remote does not have a number and we do then NAK it with the value
1090 * which we have for it. (We never have a default value of zero.)
1092 if (zero_node (ho->his_node)) {
1094 copy_node (wo->his_node, p);
1095 INCPTR (sizeof (wo->his_node), p);
1099 * If you have given me the expected network node number then I'll accept
1102 if (compare_node (wo->his_node, ho->his_node)) {
1105 INCPTR (sizeof (wo->his_node), p);
1109 * If his node number is the same as ours then ask him to try the next
1112 if (compare_node (ho->his_node, go->our_node)) {
1113 inc_node (ho->his_node);
1115 copy_node (ho->his_node, p);
1116 INCPTR (sizeof (wo->his_node), p);
1120 * If we don't accept a new value then NAK it.
1122 if (! ao->accept_remote) {
1123 copy_node (wo->his_node, p);
1124 INCPTR (sizeof (wo->his_node), p);
1130 INCPTR (sizeof (wo->his_node), p);
1133 * Compression is not desired at this time. It is always rejected.
1135 case IPX_COMPRESSION_PROTOCOL:
1139 * The routing protocol is a bitmask of various types. Any combination
1140 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1141 * routing protocol must be specified only once.
1143 case IPX_ROUTER_PROTOCOL:
1144 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1149 GETSHORT (cishort, p);
1151 if (wo->neg_router == 0) {
1153 wo->router = BIT(IPX_NONE);
1156 if ((cishort == IPX_NONE && ho->router != 0) ||
1157 (ho->router & BIT(IPX_NONE))) {
1162 cishort = BIT(cishort);
1163 if (ho->router & cishort) {
1168 ho->router |= cishort;
1171 /* Finally do not allow a router protocol which we do not
1174 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1177 if (cishort == BIT(NLSP) &&
1178 (ao->router & BIT(RIP_SAP)) &&
1183 protocol = IPX_NONE;
1185 DECPTR (sizeof (u_int16_t), p);
1186 PUTSHORT (protocol, p);
1191 * The router name is advisorary. Just accept it if it is not too large.
1193 case IPX_ROUTER_NAME:
1194 if (cilen >= CILEN_NAME) {
1195 int name_size = cilen - CILEN_NAME;
1196 if (name_size >= sizeof (ho->name))
1197 name_size = sizeof (ho->name) - 1;
1198 memset (ho->name, 0, sizeof (ho->name));
1199 memcpy (ho->name, p, name_size);
1200 ho->name [name_size] = '\0';
1208 * This is advisorary.
1211 if (cilen != CILEN_COMPLETE)
1214 ho->neg_complete = 1;
1219 * All other entries are not known at this time.
1226 if (orc == CONFACK && /* Good CI */
1227 rc != CONFACK) /* but prior CI wasnt? */
1228 continue; /* Don't send this one */
1230 if (orc == CONFNAK) { /* Nak this CI? */
1231 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1232 orc = CONFREJ; /* Get tough if so */
1233 if (rc == CONFREJ) /* Rejecting prior CI? */
1234 continue; /* Don't send this one */
1235 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1236 rc = CONFNAK; /* Not anymore... */
1237 ucp = inp; /* Backup */
1241 if (orc == CONFREJ && /* Reject this CI */
1242 rc != CONFREJ) { /* but no prior ones? */
1244 ucp = inp; /* Backup */
1247 /* Need to move CI? */
1249 BCOPY(cip, ucp, cilen); /* Move it */
1251 /* Update output pointer */
1256 * If we aren't rejecting this packet, and we want to negotiate
1257 * their address, and they didn't send their address, then we
1258 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1259 * input buffer is long enough that we can append the extra
1263 if (rc != CONFREJ && !ho->neg_node &&
1264 wo->req_nn && !reject_if_disagree) {
1265 if (rc == CONFACK) {
1267 wo->req_nn = 0; /* don't ask again */
1268 ucp = inp; /* reset pointer */
1271 if (zero_node (wo->his_node))
1272 inc_node (wo->his_node);
1274 PUTCHAR (IPX_NODE_NUMBER, ucp);
1275 PUTCHAR (CILEN_NODEN, ucp);
1276 copy_node (wo->his_node, ucp);
1277 INCPTR (sizeof (wo->his_node), ucp);
1280 *len = ucp - inp; /* Compute output length */
1281 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1282 return (rc); /* Return final code */
1286 * ipxcp_up - IPXCP has come UP.
1288 * Configure the IP network interface appropriately and bring it up.
1297 IPXCPDEBUG(("ipxcp: up"));
1299 /* The default router protocol is RIP/SAP. */
1300 if (ho->router == 0)
1301 ho->router = BIT(RIP_SAP);
1303 if (go->router == 0)
1304 go->router = BIT(RIP_SAP);
1306 /* Fetch the network number */
1308 ho->his_network = wo->his_network;
1311 copy_node (wo->his_node, ho->his_node);
1313 if (!wo->neg_node && !go->neg_node)
1314 copy_node (wo->our_node, go->our_node);
1316 if (zero_node (go->our_node)) {
1317 static char errmsg[] = "Could not determine local IPX node address";
1320 ipxcp_close(f->unit, errmsg);
1324 go->network = go->our_network;
1325 if (ho->his_network != 0 && ho->his_network > go->network)
1326 go->network = ho->his_network;
1328 if (go->network == 0) {
1329 static char errmsg[] = "Can not determine network number";
1332 ipxcp_close (unit, errmsg);
1336 /* bring the interface up */
1339 warn("sifup failed (IPX)");
1340 ipxcp_close(unit, "Interface configuration failed");
1345 /* set the network number for IPX */
1346 if (!sipxfaddr(unit, go->network, go->our_node)) {
1348 warn("sipxfaddr failed");
1349 ipxcp_close(unit, "Interface configuration failed");
1353 np_up(f->unit, PPP_IPX);
1356 * Execute the ipx-up script, like this:
1357 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1360 ipxcp_script (f, _PATH_IPXUP);
1364 * ipxcp_down - IPXCP has gone DOWN.
1366 * Take the IP network interface down, clear its addresses
1367 * and delete routes through it.
1374 IPXCPDEBUG(("ipxcp: down"));
1379 np_down(f->unit, PPP_IPX);
1381 sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
1383 ipxcp_script (f, _PATH_IPXDOWN);
1388 * ipxcp_finished - possibly shut down the lower layers.
1394 np_finished(f->unit, PPP_IPX);
1399 * ipxcp_script - Execute a script with arguments
1400 * interface-name tty-name speed local-IPX remote-IPX networks.
1403 ipxcp_script(f, script)
1407 char strspeed[32], strlocal[32], strremote[32];
1408 char strnetwork[32], strpid[32];
1409 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1411 slprintf(strpid, sizeof(strpid), "%d", getpid());
1412 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1414 strproto_lcl[0] = '\0';
1415 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1416 if (go->router & BIT(RIP_SAP))
1417 strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1418 if (go->router & BIT(NLSP))
1419 strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1422 if (strproto_lcl[0] == '\0')
1423 strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1425 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1427 strproto_rmt[0] = '\0';
1428 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1429 if (ho->router & BIT(RIP_SAP))
1430 strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1431 if (ho->router & BIT(NLSP))
1432 strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1435 if (strproto_rmt[0] == '\0')
1436 strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1438 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1440 strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1442 slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1444 slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1450 argv[4] = strnetwork;
1452 argv[6] = strremote;
1453 argv[7] = strproto_lcl;
1454 argv[8] = strproto_rmt;
1455 argv[9] = (char *)go->name;
1456 argv[10] = (char *)ho->name;
1460 run_program(script, argv, 0, NULL, NULL, 0);
1464 * ipxcp_printpkt - print the contents of an IPXCP packet.
1466 static char *ipxcp_codenames[] = {
1467 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1468 "TermReq", "TermAck", "CodeRej"
1472 ipxcp_printpkt(p, plen, printer, arg)
1475 void (*printer) __P((void *, char *, ...));
1478 int code, id, len, olen;
1479 u_char *pstart, *optend;
1483 if (plen < HEADERLEN)
1489 if (len < HEADERLEN || len > plen)
1492 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1493 printer(arg, " %s", ipxcp_codenames[code-1]);
1495 printer(arg, " code=0x%x", code);
1496 printer(arg, " id=0x%x", id);
1503 /* print option list */
1508 if (olen < CILEN_VOID || olen > len) {
1515 case IPX_NETWORK_NUMBER:
1516 if (olen == CILEN_NETN) {
1519 printer (arg, "network %s", ipx_ntoa (cilong));
1522 case IPX_NODE_NUMBER:
1523 if (olen == CILEN_NODEN) {
1525 printer (arg, "node ");
1526 while (p < optend) {
1528 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1532 case IPX_COMPRESSION_PROTOCOL:
1533 if (olen == CILEN_COMPRESS) {
1535 GETSHORT (cishort, p);
1536 printer (arg, "compression %d", (int) cishort);
1539 case IPX_ROUTER_PROTOCOL:
1540 if (olen == CILEN_PROTOCOL) {
1542 GETSHORT (cishort, p);
1543 printer (arg, "router proto %d", (int) cishort);
1546 case IPX_ROUTER_NAME:
1547 if (olen >= CILEN_NAME) {
1549 printer (arg, "router name \"");
1550 while (p < optend) {
1552 if (code >= 0x20 && code <= 0x7E)
1553 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1555 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1557 printer (arg, "\"");
1561 if (olen == CILEN_COMPLETE) {
1563 printer (arg, "complete");
1570 while (p < optend) {
1572 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1580 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1582 print_string((char *)p, len, printer, arg);
1589 /* print the rest of the bytes in the packet */
1590 for (; len > 0; --len) {
1592 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1597 #endif /* ifdef IPX_CHANGE */