2 * ipxcp.c - PPP IPX Control Protocol.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 static char rcsid[] = "$Id: ipxcp.c,v 1.11 1999/03/16 04:00:53 paulus Exp $";
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
40 #include "pathnames.h"
44 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
45 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
46 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
47 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
49 #define wo (&ipxcp_wantoptions[0])
50 #define ao (&ipxcp_allowoptions[0])
51 #define go (&ipxcp_gotoptions[0])
52 #define ho (&ipxcp_hisoptions[0])
55 * Callbacks for fsm code. (CI = Configuration Information)
57 static void ipxcp_resetci __P((fsm *)); /* Reset our CI */
58 static int ipxcp_cilen __P((fsm *)); /* Return length of our CI */
59 static void ipxcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
60 static int ipxcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
61 static int ipxcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
62 static int ipxcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
63 static int ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
64 static void ipxcp_up __P((fsm *)); /* We're UP */
65 static void ipxcp_down __P((fsm *)); /* We're DOWN */
66 static void ipxcp_finished __P((fsm *)); /* Don't need lower layer */
67 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
69 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
71 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
72 ipxcp_resetci, /* Reset our Configuration Information */
73 ipxcp_cilen, /* Length of our Configuration Information */
74 ipxcp_addci, /* Add our Configuration Information */
75 ipxcp_ackci, /* ACK our Configuration Information */
76 ipxcp_nakci, /* NAK our Configuration Information */
77 ipxcp_rejci, /* Reject our Configuration Information */
78 ipxcp_reqci, /* Request peer's Configuration Information */
79 ipxcp_up, /* Called when fsm reaches OPENED state */
80 ipxcp_down, /* Called when fsm leaves OPENED state */
81 NULL, /* Called when we want the lower layer up */
82 ipxcp_finished, /* Called when we want the lower layer down */
83 NULL, /* Called when Protocol-Reject received */
84 NULL, /* Retransmission is necessary */
85 NULL, /* Called to handle protocol-specific codes */
86 "IPXCP" /* String name of protocol */
90 * Command-line options.
92 static int setipxnode __P((char **));
93 static int setipxname __P((char **));
95 static option_t ipxcp_option_list[] = {
96 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
97 "Enable IPXCP (and IPX)", 1 },
98 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
99 "Enable IPXCP (and IPX)", 1 },
100 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
101 "Disable IPXCP (and IPX)" },
102 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
103 "Disable IPXCP (and IPX)" } ,
104 { "ipx-network", o_int, &ipxcp_wantoptions[0].our_network,
105 "Set our IPX network number", 0, &ipxcp_wantoptions[0].neg_nn },
106 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
107 "Accept peer IPX network number", 1,
108 &ipxcp_allowoptions[0].accept_network },
109 { "ipx-node", o_special, setipxnode,
110 "Set IPX node number" },
111 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
112 "Accept our IPX address", 1,
113 &ipxcp_allowoptions[0].accept_local },
114 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
115 "Accept peer's IPX address", 1,
116 &ipxcp_allowoptions[0].accept_remote },
117 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
118 "Set IPX routing proto number", 0,
119 &ipxcp_wantoptions[0].neg_router },
120 { "ipx-router-name", o_special, setipxname,
121 "Set IPX router name" },
122 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
123 "Set timeout for IPXCP" },
124 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
125 "Set max #xmits for IPXCP term-reqs" },
126 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
127 "Set max #xmits for IPXCP conf-reqs" },
128 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
129 "Set max #conf-naks for IPXCP" },
134 * Protocol entry points.
137 static void ipxcp_init __P((int));
138 static void ipxcp_open __P((int));
139 static void ipxcp_close __P((int, char *));
140 static void ipxcp_lowerup __P((int));
141 static void ipxcp_lowerdown __P((int));
142 static void ipxcp_input __P((int, u_char *, int));
143 static void ipxcp_protrej __P((int));
144 static int ipxcp_printpkt __P((u_char *, int,
145 void (*) __P((void *, char *, ...)), void *));
147 struct protent ipxcp_protent = {
167 * Lengths of configuration options.
171 #define CILEN_COMPLETE 2 /* length of complete option */
172 #define CILEN_NETN 6 /* network number length option */
173 #define CILEN_NODEN 8 /* node number length option */
174 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
175 #define CILEN_NAME 3 /* Minimum length of router name */
176 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
178 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
179 (x) == CONFNAK ? "NAK" : "REJ")
181 static int ipxcp_is_up;
183 /* Used in printing the node number */
184 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
186 /* Used to generate the proper bit mask */
187 #define BIT(num) (1 << (num))
190 * Convert from internal to external notation
194 to_external(internal)
199 if (internal & IPX_NONE)
208 * Make a string representation of a network IP address.
216 slprintf(b, sizeof(b), "%x", ipxaddr);
222 setipxnodevalue(src,dst)
229 if (!isxdigit (*src))
232 for (indx = 0; indx < 5; ++indx) {
234 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
237 item = toupper (*src) - '0';
241 dst[5] = (dst[5] << 4) | item;
253 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
254 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
256 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
258 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
261 ipxcp_wantoptions[0].neg_node = 1;
265 option_error("invalid parameter '%s' for ipx-node option", *argv);
273 char *dest = ipxcp_wantoptions[0].name;
278 ipxcp_wantoptions[0].neg_name = 1;
279 ipxcp_allowoptions[0].neg_name = 1;
280 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
285 if (! isalnum (ch) && ch != '_') {
286 option_error("IPX router name must be alphanumeric or _");
290 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
291 option_error("IPX router name is limited to %d characters",
292 sizeof (ipxcp_wantoptions[0].name) - 1);
296 dest[count++] = toupper (ch);
303 * ipxcp_init - Initialize IPXCP.
309 fsm *f = &ipxcp_fsm[unit];
312 f->protocol = PPP_IPXCP;
313 f->callbacks = &ipxcp_callbacks;
314 fsm_init(&ipxcp_fsm[unit]);
316 memset (wo->name, 0, sizeof (wo->name));
317 memset (wo->our_node, 0, sizeof (wo->our_node));
318 memset (wo->his_node, 0, sizeof (wo->his_node));
321 wo->neg_complete = 1;
327 ao->neg_complete = 1;
330 ao->accept_local = 0;
331 ao->accept_remote = 0;
332 ao->accept_network = 0;
339 * Copy the node number
346 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
350 * Compare node numbers
354 compare_node (src, dst)
357 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
361 * Is the node number zero?
369 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
370 if (node [indx] != 0)
376 * Increment the node number
390 PUTLONG (magic_num, outp);
394 * ipxcp_open - IPXCP is allowed to come up.
400 fsm_open(&ipxcp_fsm[unit]);
404 * ipxcp_close - Take IPXCP down.
407 ipxcp_close(unit, reason)
411 fsm_close(&ipxcp_fsm[unit], reason);
416 * ipxcp_lowerup - The lower layer is up.
422 fsm_lowerup(&ipxcp_fsm[unit]);
427 * ipxcp_lowerdown - The lower layer is down.
430 ipxcp_lowerdown(unit)
433 fsm_lowerdown(&ipxcp_fsm[unit]);
438 * ipxcp_input - Input IPXCP packet.
441 ipxcp_input(unit, p, len)
446 fsm_input(&ipxcp_fsm[unit], p, len);
451 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
453 * Pretend the lower layer went down, so we shut up.
459 fsm_lowerdown(&ipxcp_fsm[unit]);
464 * ipxcp_resetci - Reset our CI.
470 wo->req_node = wo->neg_node && ao->neg_node;
471 wo->req_nn = wo->neg_nn && ao->neg_nn;
473 if (wo->our_network == 0) {
475 ao->accept_network = 1;
478 * If our node number is zero then change it.
480 if (zero_node (wo->our_node)) {
481 inc_node (wo->our_node);
482 ao->accept_local = 1;
486 * If his node number is zero then change it.
488 if (zero_node (wo->his_node)) {
489 inc_node (wo->his_node);
490 ao->accept_remote = 1;
493 * If no routing agent was specified then we do RIP/SAP according to the
494 * RFC documents. If you have specified something then OK. Otherwise, we
497 if (ao->router == 0) {
498 ao->router |= BIT(RIP_SAP);
499 wo->router |= BIT(RIP_SAP);
502 /* Always specify a routing protocol unless it was REJected. */
505 * Start with these default values
511 * ipxcp_cilen - Return length of our CI.
520 len = go->neg_nn ? CILEN_NETN : 0;
521 len += go->neg_node ? CILEN_NODEN : 0;
522 len += go->neg_name ? CILEN_NAME + strlen (go->name) - 1 : 0;
524 /* RFC says that defaults should not be included. */
525 if (go->neg_router && to_external(go->router) != RIP_SAP)
526 len += CILEN_PROTOCOL;
533 * ipxcp_addci - Add our desired CIs to a packet.
536 ipxcp_addci(f, ucp, lenp)
542 * Add the options to the record.
545 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
546 PUTCHAR (CILEN_NETN, ucp);
547 PUTLONG (go->our_network, ucp);
552 PUTCHAR (IPX_NODE_NUMBER, ucp);
553 PUTCHAR (CILEN_NODEN, ucp);
554 for (indx = 0; indx < sizeof (go->our_node); ++indx)
555 PUTCHAR (go->our_node[indx], ucp);
559 int cilen = strlen (go->name);
561 PUTCHAR (IPX_ROUTER_NAME, ucp);
562 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
563 for (indx = 0; indx < cilen; ++indx)
564 PUTCHAR (go->name [indx], ucp);
567 if (go->neg_router) {
568 short external = to_external (go->router);
569 if (external != RIP_SAP) {
570 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
571 PUTCHAR (CILEN_PROTOCOL, ucp);
572 PUTSHORT (external, ucp);
578 * ipxcp_ackci - Ack our CIs.
585 ipxcp_ackci(f, p, len)
590 u_short cilen, citype, cishort;
594 #define ACKCIVOID(opt, neg) \
596 if ((len -= CILEN_VOID) < 0) \
598 GETCHAR(citype, p); \
600 if (cilen != CILEN_VOID || \
605 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
607 #define ACKCICHARS(opt, neg, val, cnt) \
609 int indx, count = cnt; \
610 len -= (count + 2); \
613 GETCHAR(citype, p); \
615 if (cilen != (count + 2) || \
618 for (indx = 0; indx < count; ++indx) {\
619 GETCHAR(cichar, p); \
620 if (cichar != ((u_char *) &val)[indx]) \
627 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
628 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
630 #define ACKCINETWORK(opt, neg, val) \
632 if ((len -= CILEN_NETN) < 0) \
634 GETCHAR(citype, p); \
636 if (cilen != CILEN_NETN || \
639 GETLONG(cilong, p); \
644 #define ACKCIPROTO(opt, neg, val) \
648 GETCHAR(citype, p); \
650 if (cilen != CILEN_PROTOCOL || citype != opt) \
655 GETSHORT(cishort, p); \
656 if (cishort != to_external (val) || cishort == RIP_SAP) \
660 * Process the ACK frame in the order in which the frame was assembled
663 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
664 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
665 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
666 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
667 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
668 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
670 * This is the end of the record.
676 * The frame is invalid
678 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
683 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
684 * This should not modify any state if the Nak is bad
685 * or if IPXCP is in the OPENED state.
693 ipxcp_nakci(f, p, len)
698 u_char citype, cilen, *next;
701 ipxcp_options no; /* options we've seen Naks for */
702 ipxcp_options try; /* options to request next time */
704 BZERO(&no, sizeof(no));
707 while (len > CILEN_VOID) {
713 next = &p [cilen - CILEN_VOID];
716 case IPX_NETWORK_NUMBER:
717 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
722 if (l && ao->accept_network)
726 case IPX_NODE_NUMBER:
727 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
731 if (!zero_node (p) && ao->accept_local &&
732 ! compare_node (p, ho->his_node))
733 copy_node (p, try.our_node);
736 /* This has never been sent. Ignore the NAK frame */
737 case IPX_COMPRESSION_PROTOCOL:
740 case IPX_ROUTER_PROTOCOL:
741 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
745 if (s > 15) /* This is just bad, but ignore for now. */
749 if (no.router & s) /* duplicate NAKs are always bad */
752 if (no.router == 0) /* Reset on first NAK only */
760 /* These, according to the RFC, must never be NAKed. */
761 case IPX_ROUTER_NAME:
765 /* These are for options which we have not seen. */
772 /* If there is still anything left, this packet is bad. */
777 * Do not permit the peer to force a router protocol which we do not
778 * support. However, default to the condition that will accept "NONE".
780 try.router &= (ao->router | BIT(IPX_NONE));
781 if (try.router == 0 && ao->router != 0)
782 try.router = BIT(IPX_NONE);
788 * OK, the Nak is good. Now we can update state.
790 if (f->state != OPENED)
796 IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
801 * ipxcp_rejci - Reject some of our CIs.
804 ipxcp_rejci(f, p, len)
809 u_short cilen, citype, cishort;
812 ipxcp_options try; /* options to request next time */
814 #define REJCINETWORK(opt, neg, val) \
815 if (neg && p[0] == opt) { \
816 if ((len -= CILEN_NETN) < 0) \
818 GETCHAR(citype, p); \
820 if (cilen != CILEN_NETN || \
823 GETLONG(cilong, p); \
829 #define REJCICHARS(opt, neg, val, cnt) \
830 if (neg && p[0] == opt) { \
831 int indx, count = cnt; \
832 len -= (count + 2); \
835 GETCHAR(citype, p); \
837 if (cilen != (count + 2) || \
840 for (indx = 0; indx < count; ++indx) {\
841 GETCHAR(cichar, p); \
842 if (cichar != ((u_char *) &val)[indx]) \
850 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
851 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
853 #define REJCIVOID(opt, neg) \
854 if (neg && p[0] == opt) { \
855 if ((len -= CILEN_VOID) < 0) \
857 GETCHAR(citype, p); \
859 if (cilen != CILEN_VOID || citype != opt) \
864 /* a reject for RIP/SAP is invalid since we don't send it and you can't
865 reject something which is not sent. (You can NAK, but you can't REJ.) */
866 #define REJCIPROTO(opt, neg, val, bit) \
867 if (neg && p[0] == opt) { \
868 if ((len -= CILEN_PROTOCOL) < 0) \
870 GETCHAR(citype, p); \
872 if (cilen != CILEN_PROTOCOL) \
874 GETSHORT(cishort, p); \
875 if (cishort != to_external (val) || cishort == RIP_SAP) \
880 * Any Rejected CIs must be in exactly the same order that we sent.
881 * Check packet length and CI length at each step.
882 * If we find any deviations, then this packet is bad.
887 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
888 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
889 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
890 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
892 * This is the end of the record.
895 if (f->state != OPENED)
901 * The frame is invalid at this point.
903 IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
908 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
910 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
911 * appropriately. If reject_if_disagree is non-zero, doesn't return
912 * CONFNAK; returns CONFREJ if it can't return CONFACK.
915 ipxcp_reqci(f, inp, len, reject_if_disagree)
917 u_char *inp; /* Requested CIs */
918 int *len; /* Length of requested CIs */
919 int reject_if_disagree;
921 u_char *cip, *next; /* Pointer to current and next CIs */
922 u_short cilen, citype; /* Parsed len, type */
923 u_short cishort; /* Parsed short value */
924 u_int32_t cinetwork; /* Parsed address values */
925 int rc = CONFACK; /* Final packet return code */
926 int orc; /* Individual option return code */
927 u_char *p; /* Pointer to next char to parse */
928 u_char *ucp = inp; /* Pointer to current output char */
929 int l = *len; /* Length left */
932 * Reset all his options.
934 BZERO(ho, sizeof(*ho));
937 * Process all his options.
941 orc = CONFACK; /* Assume success */
942 cip = p = next; /* Remember begining of CI */
943 if (l < 2 || /* Not enough data for CI header or */
944 p[1] < 2 || /* CI length too small or */
945 p[1] > l) { /* CI length too big? */
946 IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
947 orc = CONFREJ; /* Reject bad CI */
948 cilen = l; /* Reject till end of packet */
949 l = 0; /* Don't loop again */
952 GETCHAR(citype, p); /* Parse CI type */
953 GETCHAR(cilen, p); /* Parse CI length */
954 l -= cilen; /* Adjust remaining length */
955 next += cilen; /* Step to next CI */
957 switch (citype) { /* Check CI type */
959 * The network number must match. Choose the larger of the two.
961 case IPX_NETWORK_NUMBER:
962 /* if we wont negotiate the network number or the length is wrong
963 then reject the option */
964 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
968 GETLONG(cinetwork, p);
970 /* If the network numbers match then acknowledge them. */
971 if (cinetwork != 0) {
972 ho->his_network = cinetwork;
974 if (wo->our_network == cinetwork)
977 * If the network number is not given or we don't accept their change or
978 * the network number is too small then NAK it.
980 if (! ao->accept_network || cinetwork < wo->our_network) {
981 DECPTR (sizeof (u_int32_t), p);
982 PUTLONG (wo->our_network, p);
988 * The peer sent '0' for the network. Give it ours if we have one.
990 if (go->our_network != 0) {
991 DECPTR (sizeof (u_int32_t), p);
992 PUTLONG (wo->our_network, p);
995 * We don't have one. Reject the value.
1002 * The node number is required
1004 case IPX_NODE_NUMBER:
1005 /* if we wont negotiate the node number or the length is wrong
1006 then reject the option */
1007 if ( cilen != CILEN_NODEN ) {
1012 copy_node (p, ho->his_node);
1015 * If the remote does not have a number and we do then NAK it with the value
1016 * which we have for it. (We never have a default value of zero.)
1018 if (zero_node (ho->his_node)) {
1020 copy_node (wo->his_node, p);
1021 INCPTR (sizeof (wo->his_node), p);
1025 * If you have given me the expected network node number then I'll accept
1028 if (compare_node (wo->his_node, ho->his_node)) {
1031 INCPTR (sizeof (wo->his_node), p);
1035 * If his node number is the same as ours then ask him to try the next
1038 if (compare_node (ho->his_node, go->our_node)) {
1039 inc_node (ho->his_node);
1041 copy_node (ho->his_node, p);
1042 INCPTR (sizeof (wo->his_node), p);
1046 * If we don't accept a new value then NAK it.
1048 if (! ao->accept_remote) {
1049 copy_node (wo->his_node, p);
1050 INCPTR (sizeof (wo->his_node), p);
1056 INCPTR (sizeof (wo->his_node), p);
1059 * Compression is not desired at this time. It is always rejected.
1061 case IPX_COMPRESSION_PROTOCOL:
1065 * The routing protocol is a bitmask of various types. Any combination
1066 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1067 * routing protocol must be specified only once.
1069 case IPX_ROUTER_PROTOCOL:
1070 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1075 GETSHORT (cishort, p);
1077 if (wo->neg_router == 0) {
1079 wo->router = BIT(IPX_NONE);
1082 if ((cishort == IPX_NONE && ho->router != 0) ||
1083 (ho->router & BIT(IPX_NONE))) {
1088 cishort = BIT(cishort);
1089 if (ho->router & cishort) {
1094 ho->router |= cishort;
1097 /* Finally do not allow a router protocol which we do not
1100 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1103 if (cishort == BIT(NLSP) &&
1104 (ao->router & BIT(RIP_SAP)) &&
1109 protocol = IPX_NONE;
1111 DECPTR (sizeof (u_int16_t), p);
1112 PUTSHORT (protocol, p);
1117 * The router name is advisorary. Just accept it if it is not too large.
1119 case IPX_ROUTER_NAME:
1120 if (cilen >= CILEN_NAME) {
1121 int name_size = cilen - CILEN_NAME;
1122 if (name_size > sizeof (ho->name))
1123 name_size = sizeof (ho->name) - 1;
1124 memset (ho->name, 0, sizeof (ho->name));
1125 memcpy (ho->name, p, name_size);
1126 ho->name [name_size] = '\0';
1134 * This is advisorary.
1137 if (cilen != CILEN_COMPLETE)
1140 ho->neg_complete = 1;
1145 * All other entries are not known at this time.
1152 if (orc == CONFACK && /* Good CI */
1153 rc != CONFACK) /* but prior CI wasnt? */
1154 continue; /* Don't send this one */
1156 if (orc == CONFNAK) { /* Nak this CI? */
1157 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1158 orc = CONFREJ; /* Get tough if so */
1159 if (rc == CONFREJ) /* Rejecting prior CI? */
1160 continue; /* Don't send this one */
1161 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1162 rc = CONFNAK; /* Not anymore... */
1163 ucp = inp; /* Backup */
1167 if (orc == CONFREJ && /* Reject this CI */
1168 rc != CONFREJ) { /* but no prior ones? */
1170 ucp = inp; /* Backup */
1173 /* Need to move CI? */
1175 BCOPY(cip, ucp, cilen); /* Move it */
1177 /* Update output pointer */
1182 * If we aren't rejecting this packet, and we want to negotiate
1183 * their address, and they didn't send their address, then we
1184 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1185 * input buffer is long enough that we can append the extra
1189 if (rc != CONFREJ && !ho->neg_node &&
1190 wo->req_nn && !reject_if_disagree) {
1191 if (rc == CONFACK) {
1193 wo->req_nn = 0; /* don't ask again */
1194 ucp = inp; /* reset pointer */
1197 if (zero_node (wo->his_node))
1198 inc_node (wo->his_node);
1200 PUTCHAR (IPX_NODE_NUMBER, ucp);
1201 PUTCHAR (CILEN_NODEN, ucp);
1202 copy_node (wo->his_node, ucp);
1203 INCPTR (sizeof (wo->his_node), ucp);
1206 *len = ucp - inp; /* Compute output length */
1207 IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1208 return (rc); /* Return final code */
1212 * ipxcp_up - IPXCP has come UP.
1214 * Configure the IP network interface appropriately and bring it up.
1223 IPXCPDEBUG(("ipxcp: up"));
1225 /* The default router protocol is RIP/SAP. */
1226 if (ho->router == 0)
1227 ho->router = BIT(RIP_SAP);
1229 if (go->router == 0)
1230 go->router = BIT(RIP_SAP);
1232 /* Fetch the network number */
1234 ho->his_network = wo->his_network;
1237 copy_node (wo->his_node, ho->his_node);
1239 if (!wo->neg_node && !go->neg_node)
1240 copy_node (wo->our_node, go->our_node);
1242 if (zero_node (go->our_node)) {
1243 static char errmsg[] = "Could not determine local IPX node address";
1246 ipxcp_close(f->unit, errmsg);
1250 go->network = go->our_network;
1251 if (ho->his_network != 0 && ho->his_network > go->network)
1252 go->network = ho->his_network;
1254 if (go->network == 0) {
1255 static char errmsg[] = "Can not determine network number";
1258 ipxcp_close (unit, errmsg);
1262 /* bring the interface up */
1265 warn("sifup failed (IPX)");
1266 ipxcp_close(unit, "Interface configuration failed");
1270 /* set the network number for IPX */
1271 if (!sipxfaddr(unit, go->network, go->our_node)) {
1273 warn("sipxfaddr failed");
1274 ipxcp_close(unit, "Interface configuration failed");
1279 np_up(f->unit, PPP_IPX);
1282 * Execute the ipx-up script, like this:
1283 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1286 ipxcp_script (f, _PATH_IPXUP);
1290 * ipxcp_down - IPXCP has gone DOWN.
1292 * Take the IP network interface down, clear its addresses
1293 * and delete routes through it.
1300 IPXCPDEBUG(("ipxcp: down"));
1304 np_down(f->unit, PPP_IPX);
1306 cipxfaddr (f->unit);
1308 ipxcp_script (f, _PATH_IPXDOWN);
1313 * ipxcp_finished - possibly shut down the lower layers.
1319 np_finished(f->unit, PPP_IPX);
1324 * ipxcp_script - Execute a script with arguments
1325 * interface-name tty-name speed local-IPX remote-IPX networks.
1328 ipxcp_script(f, script)
1332 char strspeed[32], strlocal[32], strremote[32];
1333 char strnetwork[32], strpid[32];
1334 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1336 slprintf(strpid, sizeof(strpid), "%d", getpid());
1337 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1339 strproto_lcl[0] = '\0';
1340 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1341 if (go->router & BIT(RIP_SAP))
1342 strlcpy (strproto_lcl, sizeof(strproto_lcl), "RIP ");
1343 if (go->router & BIT(NLSP))
1344 strlcat (strproto_lcl, sizeof(strproto_lcl), "NLSP ");
1347 if (strproto_lcl[0] == '\0')
1348 strlcpy (strproto_lcl, sizeof(strproto_lcl), "NONE ");
1350 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1352 strproto_rmt[0] = '\0';
1353 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1354 if (ho->router & BIT(RIP_SAP))
1355 strlcpy (strproto_rmt, sizeof(strproto_rmt), "RIP ");
1356 if (ho->router & BIT(NLSP))
1357 strlcat (strproto_rmt, sizeof(strproto_rmt), "NLSP ");
1360 if (strproto_rmt[0] == '\0')
1361 strlcpy (strproto_rmt, sizeof(strproto_rmt), "NONE ");
1363 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1365 strlcpy (strnetwork, sizeof(strnetwork), ipx_ntoa (go->network));
1367 slprintf (strlocal, sizeof(strlocal),
1368 "%02X%02X%02X%02X%02X%02X",
1369 NODE(go->our_node));
1371 slprintf (strremote, sizeof(strremote),
1372 "%02X%02X%02X%02X%02X%02X",
1373 NODE(ho->his_node));
1379 argv[4] = strnetwork;
1381 argv[6] = strremote;
1382 argv[7] = strproto_lcl;
1383 argv[8] = strproto_rmt;
1385 argv[10] = ho->name;
1389 run_program(script, argv, 0, NULL, NULL);
1393 * ipxcp_printpkt - print the contents of an IPXCP packet.
1395 static char *ipxcp_codenames[] = {
1396 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1397 "TermReq", "TermAck", "CodeRej"
1401 ipxcp_printpkt(p, plen, printer, arg)
1404 void (*printer) __P((void *, char *, ...));
1407 int code, id, len, olen;
1408 u_char *pstart, *optend;
1412 if (plen < HEADERLEN)
1418 if (len < HEADERLEN || len > plen)
1421 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1422 printer(arg, " %s", ipxcp_codenames[code-1]);
1424 printer(arg, " code=0x%x", code);
1425 printer(arg, " id=0x%x", id);
1432 /* print option list */
1437 if (olen < CILEN_VOID || olen > len) {
1444 case IPX_NETWORK_NUMBER:
1445 if (olen == CILEN_NETN) {
1448 printer (arg, "network %s", ipx_ntoa (cilong));
1451 case IPX_NODE_NUMBER:
1452 if (olen == CILEN_NODEN) {
1454 printer (arg, "node ");
1455 while (p < optend) {
1457 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1461 case IPX_COMPRESSION_PROTOCOL:
1462 if (olen == CILEN_COMPRESS) {
1464 GETSHORT (cishort, p);
1465 printer (arg, "compression %d", (int) cishort);
1468 case IPX_ROUTER_PROTOCOL:
1469 if (olen == CILEN_PROTOCOL) {
1471 GETSHORT (cishort, p);
1472 printer (arg, "router proto %d", (int) cishort);
1475 case IPX_ROUTER_NAME:
1476 if (olen >= CILEN_NAME) {
1478 printer (arg, "router name \"");
1479 while (p < optend) {
1481 if (code >= 0x20 && code <= 0x7E)
1482 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1484 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1486 printer (arg, "\"");
1490 if (olen == CILEN_COMPLETE) {
1492 printer (arg, "complete");
1499 while (p < optend) {
1501 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1509 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1511 print_string(p, len, printer, arg);
1518 /* print the rest of the bytes in the packet */
1519 for (; len > 0; --len) {
1521 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1526 #endif /* ifdef IPX_CHANGE */