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 #define RCSID "$Id: ipxcp.c,v 1.18 1999/08/24 05:31:09 paulus Exp $"
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
39 #include "pathnames.h"
42 static const char rcsid[] = RCSID;
45 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
46 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
47 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
48 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
50 #define wo (&ipxcp_wantoptions[0])
51 #define ao (&ipxcp_allowoptions[0])
52 #define go (&ipxcp_gotoptions[0])
53 #define ho (&ipxcp_hisoptions[0])
56 * Callbacks for fsm code. (CI = Configuration Information)
58 static void ipxcp_resetci __P((fsm *)); /* Reset our CI */
59 static int ipxcp_cilen __P((fsm *)); /* Return length of our CI */
60 static void ipxcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
61 static int ipxcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
62 static int ipxcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
63 static int ipxcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
64 static int ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
65 static void ipxcp_up __P((fsm *)); /* We're UP */
66 static void ipxcp_down __P((fsm *)); /* We're DOWN */
67 static void ipxcp_finished __P((fsm *)); /* Don't need lower layer */
68 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
70 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
72 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
73 ipxcp_resetci, /* Reset our Configuration Information */
74 ipxcp_cilen, /* Length of our Configuration Information */
75 ipxcp_addci, /* Add our Configuration Information */
76 ipxcp_ackci, /* ACK our Configuration Information */
77 ipxcp_nakci, /* NAK our Configuration Information */
78 ipxcp_rejci, /* Reject our Configuration Information */
79 ipxcp_reqci, /* Request peer's Configuration Information */
80 ipxcp_up, /* Called when fsm reaches OPENED state */
81 ipxcp_down, /* Called when fsm leaves OPENED state */
82 NULL, /* Called when we want the lower layer up */
83 ipxcp_finished, /* Called when we want the lower layer down */
84 NULL, /* Called when Protocol-Reject received */
85 NULL, /* Retransmission is necessary */
86 NULL, /* Called to handle protocol-specific codes */
87 "IPXCP" /* String name of protocol */
91 * Command-line options.
93 static int setipxnode __P((char **));
94 static int setipxname __P((char **));
96 static option_t ipxcp_option_list[] = {
97 { "ipx", o_bool, &ipxcp_protent.enabled_flag,
98 "Enable IPXCP (and IPX)", 1 },
99 { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
100 "Enable IPXCP (and IPX)", 1 },
101 { "noipx", o_bool, &ipxcp_protent.enabled_flag,
102 "Disable IPXCP (and IPX)" },
103 { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
104 "Disable IPXCP (and IPX)" } ,
105 { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
106 "Set our IPX network number", 0, &ipxcp_wantoptions[0].neg_nn },
107 { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
108 "Accept peer IPX network number", 1,
109 &ipxcp_allowoptions[0].accept_network },
110 { "ipx-node", o_special, setipxnode,
111 "Set IPX node number" },
112 { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
113 "Accept our IPX address", 1,
114 &ipxcp_allowoptions[0].accept_local },
115 { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
116 "Accept peer's IPX address", 1,
117 &ipxcp_allowoptions[0].accept_remote },
118 { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
119 "Set IPX routing proto number", 0,
120 &ipxcp_wantoptions[0].neg_router },
121 { "ipx-router-name", o_special, setipxname,
122 "Set IPX router name" },
123 { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
124 "Set timeout for IPXCP" },
125 { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
126 "Set max #xmits for IPXCP term-reqs" },
127 { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
128 "Set max #xmits for IPXCP conf-reqs" },
129 { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
130 "Set max #conf-naks for IPXCP" },
135 * Protocol entry points.
138 static void ipxcp_init __P((int));
139 static void ipxcp_open __P((int));
140 static void ipxcp_close __P((int, char *));
141 static void ipxcp_lowerup __P((int));
142 static void ipxcp_lowerdown __P((int));
143 static void ipxcp_input __P((int, u_char *, int));
144 static void ipxcp_protrej __P((int));
145 static int ipxcp_printpkt __P((u_char *, int,
146 void (*) __P((void *, char *, ...)), void *));
148 struct protent ipxcp_protent = {
169 * Lengths of configuration options.
173 #define CILEN_COMPLETE 2 /* length of complete option */
174 #define CILEN_NETN 6 /* network number length option */
175 #define CILEN_NODEN 8 /* node number length option */
176 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
177 #define CILEN_NAME 3 /* Minimum length of router name */
178 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
180 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
181 (x) == CONFNAK ? "NAK" : "REJ")
183 static int ipxcp_is_up;
185 static char *ipx_ntoa __P((u_int32_t));
187 /* Used in printing the node number */
188 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
190 /* Used to generate the proper bit mask */
191 #define BIT(num) (1 << (num))
194 * Convert from internal to external notation
198 to_external(internal)
203 if (internal & BIT(IPX_NONE) )
212 * Make a string representation of a network IP address.
220 slprintf(b, sizeof(b), "%x", ipxaddr);
226 setipxnodevalue(src,dst)
233 if (!isxdigit (*src))
236 for (indx = 0; indx < 5; ++indx) {
238 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
241 item = toupper (*src) - '0';
245 dst[5] = (dst[5] << 4) | item;
257 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
258 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
260 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
262 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
265 ipxcp_wantoptions[0].neg_node = 1;
269 option_error("invalid parameter '%s' for ipx-node option", *argv);
277 char *dest = ipxcp_wantoptions[0].name;
282 ipxcp_wantoptions[0].neg_name = 1;
283 ipxcp_allowoptions[0].neg_name = 1;
284 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
289 if (! isalnum (ch) && ch != '_') {
290 option_error("IPX router name must be alphanumeric or _");
294 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
295 option_error("IPX router name is limited to %d characters",
296 sizeof (ipxcp_wantoptions[0].name) - 1);
300 dest[count++] = toupper (ch);
307 * ipxcp_init - Initialize IPXCP.
313 fsm *f = &ipxcp_fsm[unit];
316 f->protocol = PPP_IPXCP;
317 f->callbacks = &ipxcp_callbacks;
318 fsm_init(&ipxcp_fsm[unit]);
320 memset (wo->name, 0, sizeof (wo->name));
321 memset (wo->our_node, 0, sizeof (wo->our_node));
322 memset (wo->his_node, 0, sizeof (wo->his_node));
325 wo->neg_complete = 1;
331 ao->neg_complete = 1;
334 ao->accept_local = 0;
335 ao->accept_remote = 0;
336 ao->accept_network = 0;
343 * Copy the node number
350 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
354 * Compare node numbers
358 compare_node (src, dst)
361 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
365 * Is the node number zero?
373 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
374 if (node [indx] != 0)
380 * Increment the node number
394 PUTLONG (magic_num, outp);
398 * ipxcp_open - IPXCP is allowed to come up.
404 fsm_open(&ipxcp_fsm[unit]);
408 * ipxcp_close - Take IPXCP down.
411 ipxcp_close(unit, reason)
415 fsm_close(&ipxcp_fsm[unit], reason);
420 * ipxcp_lowerup - The lower layer is up.
426 fsm_lowerup(&ipxcp_fsm[unit]);
431 * ipxcp_lowerdown - The lower layer is down.
434 ipxcp_lowerdown(unit)
437 fsm_lowerdown(&ipxcp_fsm[unit]);
442 * ipxcp_input - Input IPXCP packet.
445 ipxcp_input(unit, p, len)
450 fsm_input(&ipxcp_fsm[unit], p, len);
455 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
457 * Pretend the lower layer went down, so we shut up.
463 fsm_lowerdown(&ipxcp_fsm[unit]);
468 * ipxcp_resetci - Reset our CI.
474 wo->req_node = wo->neg_node && ao->neg_node;
475 wo->req_nn = wo->neg_nn && ao->neg_nn;
477 if (wo->our_network == 0) {
479 ao->accept_network = 1;
482 * If our node number is zero then change it.
484 if (zero_node (wo->our_node)) {
485 inc_node (wo->our_node);
486 ao->accept_local = 1;
490 * If his node number is zero then change it.
492 if (zero_node (wo->his_node)) {
493 inc_node (wo->his_node);
494 ao->accept_remote = 1;
497 * If no routing agent was specified then we do RIP/SAP according to the
498 * RFC documents. If you have specified something then OK. Otherwise, we
501 if (ao->router == 0) {
502 ao->router |= BIT(RIP_SAP);
503 wo->router |= BIT(RIP_SAP);
506 /* Always specify a routing protocol unless it was REJected. */
509 * Start with these default values
515 * ipxcp_cilen - Return length of our CI.
524 len = go->neg_nn ? CILEN_NETN : 0;
525 len += go->neg_node ? CILEN_NODEN : 0;
526 len += go->neg_name ? CILEN_NAME + strlen (go->name) - 1 : 0;
528 /* RFC says that defaults should not be included. */
529 if (go->neg_router && to_external(go->router) != RIP_SAP)
530 len += CILEN_PROTOCOL;
537 * ipxcp_addci - Add our desired CIs to a packet.
540 ipxcp_addci(f, ucp, lenp)
546 * Add the options to the record.
549 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
550 PUTCHAR (CILEN_NETN, ucp);
551 PUTLONG (go->our_network, ucp);
556 PUTCHAR (IPX_NODE_NUMBER, ucp);
557 PUTCHAR (CILEN_NODEN, ucp);
558 for (indx = 0; indx < sizeof (go->our_node); ++indx)
559 PUTCHAR (go->our_node[indx], ucp);
563 int cilen = strlen (go->name);
565 PUTCHAR (IPX_ROUTER_NAME, ucp);
566 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
567 for (indx = 0; indx < cilen; ++indx)
568 PUTCHAR (go->name [indx], ucp);
571 if (go->neg_router) {
572 short external = to_external (go->router);
573 if (external != RIP_SAP) {
574 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
575 PUTCHAR (CILEN_PROTOCOL, ucp);
576 PUTSHORT (external, ucp);
582 * ipxcp_ackci - Ack our CIs.
589 ipxcp_ackci(f, p, len)
594 u_short cilen, citype, cishort;
598 #define ACKCIVOID(opt, neg) \
600 if ((len -= CILEN_VOID) < 0) \
602 GETCHAR(citype, p); \
604 if (cilen != CILEN_VOID || \
609 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
611 #define ACKCICHARS(opt, neg, val, cnt) \
613 int indx, count = cnt; \
614 len -= (count + 2); \
617 GETCHAR(citype, p); \
619 if (cilen != (count + 2) || \
622 for (indx = 0; indx < count; ++indx) {\
623 GETCHAR(cichar, p); \
624 if (cichar != ((u_char *) &val)[indx]) \
631 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
632 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
634 #define ACKCINETWORK(opt, neg, val) \
636 if ((len -= CILEN_NETN) < 0) \
638 GETCHAR(citype, p); \
640 if (cilen != CILEN_NETN || \
643 GETLONG(cilong, p); \
648 #define ACKCIPROTO(opt, neg, val) \
652 GETCHAR(citype, p); \
654 if (cilen != CILEN_PROTOCOL || citype != opt) \
659 GETSHORT(cishort, p); \
660 if (cishort != to_external (val) || cishort == RIP_SAP) \
664 * Process the ACK frame in the order in which the frame was assembled
667 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
668 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
669 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
671 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
673 * This is the end of the record.
679 * The frame is invalid
681 IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
686 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
687 * This should not modify any state if the Nak is bad
688 * or if IPXCP is in the OPENED state.
696 ipxcp_nakci(f, p, len)
701 u_char citype, cilen, *next;
704 ipxcp_options no; /* options we've seen Naks for */
705 ipxcp_options try; /* options to request next time */
707 BZERO(&no, sizeof(no));
710 while (len > CILEN_VOID) {
716 next = &p [cilen - CILEN_VOID];
719 case IPX_NETWORK_NUMBER:
720 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
725 if (l && ao->accept_network)
729 case IPX_NODE_NUMBER:
730 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
734 if (!zero_node (p) && ao->accept_local &&
735 ! compare_node (p, ho->his_node))
736 copy_node (p, try.our_node);
739 /* This has never been sent. Ignore the NAK frame */
740 case IPX_COMPRESSION_PROTOCOL:
743 case IPX_ROUTER_PROTOCOL:
744 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
748 if (s > 15) /* This is just bad, but ignore for now. */
752 if (no.router & s) /* duplicate NAKs are always bad */
755 if (no.router == 0) /* Reset on first NAK only */
763 /* These, according to the RFC, must never be NAKed. */
764 case IPX_ROUTER_NAME:
768 /* These are for options which we have not seen. */
776 * Do not permit the peer to force a router protocol which we do not
777 * support. However, default to the condition that will accept "NONE".
779 try.router &= (ao->router | BIT(IPX_NONE));
780 if (try.router == 0 && ao->router != 0)
781 try.router = BIT(IPX_NONE);
787 * OK, the Nak is good. Now we can update state.
788 * If there are any options left, we ignore them.
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");
1271 /* set the network number for IPX */
1272 if (!sipxfaddr(unit, go->network, go->our_node)) {
1274 warn("sipxfaddr failed");
1275 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"));
1305 np_down(f->unit, PPP_IPX);
1307 sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
1309 ipxcp_script (f, _PATH_IPXDOWN);
1314 * ipxcp_finished - possibly shut down the lower layers.
1320 np_finished(f->unit, PPP_IPX);
1325 * ipxcp_script - Execute a script with arguments
1326 * interface-name tty-name speed local-IPX remote-IPX networks.
1329 ipxcp_script(f, script)
1333 char strspeed[32], strlocal[32], strremote[32];
1334 char strnetwork[32], strpid[32];
1335 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1337 slprintf(strpid, sizeof(strpid), "%d", getpid());
1338 slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1340 strproto_lcl[0] = '\0';
1341 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1342 if (go->router & BIT(RIP_SAP))
1343 strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1344 if (go->router & BIT(NLSP))
1345 strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1348 if (strproto_lcl[0] == '\0')
1349 strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1351 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1353 strproto_rmt[0] = '\0';
1354 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1355 if (ho->router & BIT(RIP_SAP))
1356 strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1357 if (ho->router & BIT(NLSP))
1358 strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1361 if (strproto_rmt[0] == '\0')
1362 strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1364 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1366 strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1368 slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1370 slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1376 argv[4] = strnetwork;
1378 argv[6] = strremote;
1379 argv[7] = strproto_lcl;
1380 argv[8] = strproto_rmt;
1382 argv[10] = ho->name;
1386 run_program(script, argv, 0, NULL, NULL);
1390 * ipxcp_printpkt - print the contents of an IPXCP packet.
1392 static char *ipxcp_codenames[] = {
1393 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1394 "TermReq", "TermAck", "CodeRej"
1398 ipxcp_printpkt(p, plen, printer, arg)
1401 void (*printer) __P((void *, char *, ...));
1404 int code, id, len, olen;
1405 u_char *pstart, *optend;
1409 if (plen < HEADERLEN)
1415 if (len < HEADERLEN || len > plen)
1418 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1419 printer(arg, " %s", ipxcp_codenames[code-1]);
1421 printer(arg, " code=0x%x", code);
1422 printer(arg, " id=0x%x", id);
1429 /* print option list */
1434 if (olen < CILEN_VOID || olen > len) {
1441 case IPX_NETWORK_NUMBER:
1442 if (olen == CILEN_NETN) {
1445 printer (arg, "network %s", ipx_ntoa (cilong));
1448 case IPX_NODE_NUMBER:
1449 if (olen == CILEN_NODEN) {
1451 printer (arg, "node ");
1452 while (p < optend) {
1454 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1458 case IPX_COMPRESSION_PROTOCOL:
1459 if (olen == CILEN_COMPRESS) {
1461 GETSHORT (cishort, p);
1462 printer (arg, "compression %d", (int) cishort);
1465 case IPX_ROUTER_PROTOCOL:
1466 if (olen == CILEN_PROTOCOL) {
1468 GETSHORT (cishort, p);
1469 printer (arg, "router proto %d", (int) cishort);
1472 case IPX_ROUTER_NAME:
1473 if (olen >= CILEN_NAME) {
1475 printer (arg, "router name \"");
1476 while (p < optend) {
1478 if (code >= 0x20 && code <= 0x7E)
1479 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1481 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1483 printer (arg, "\"");
1487 if (olen == CILEN_COMPLETE) {
1489 printer (arg, "complete");
1496 while (p < optend) {
1498 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1506 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1508 print_string(p, len, printer, arg);
1515 /* print the rest of the bytes in the packet */
1516 for (; len > 0; --len) {
1518 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1523 #endif /* ifdef IPX_CHANGE */