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.8 1998/11/07 06:59:27 paulus Exp $";
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
41 #include "pathnames.h"
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_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 NULL, /* 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 /* Used in printing the node number */
182 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
184 /* Used to generate the proper bit mask */
185 #define BIT(num) (1 << (num))
188 * Convert from internal to external notation
192 to_external(internal)
197 if (internal & IPX_NONE)
206 * Make a string representation of a network IP address.
214 sprintf(b, "%x", ipxaddr);
220 setipxnodevalue(src,dst)
227 if (!isxdigit (*src))
230 for (indx = 0; indx < 5; ++indx) {
232 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
235 item = toupper (*src) - '0';
239 dst[5] = (dst[5] << 4) | item;
251 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
252 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
254 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
256 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
259 ipxcp_wantoptions[0].neg_node = 1;
263 option_error("invalid parameter '%s' for ipx-node option", *argv);
271 char *dest = ipxcp_wantoptions[0].name;
276 ipxcp_wantoptions[0].neg_name = 1;
277 ipxcp_allowoptions[0].neg_name = 1;
278 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
283 if (! isalnum (ch) && ch != '_') {
284 option_error("IPX router name must be alphanumeric or _");
288 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
289 option_error("IPX router name is limited to %d characters",
290 sizeof (ipxcp_wantoptions[0].name) - 1);
294 dest[count++] = toupper (ch);
301 * ipxcp_init - Initialize IPXCP.
307 fsm *f = &ipxcp_fsm[unit];
310 f->protocol = PPP_IPXCP;
311 f->callbacks = &ipxcp_callbacks;
312 fsm_init(&ipxcp_fsm[unit]);
314 memset (wo->name, 0, sizeof (wo->name));
315 memset (wo->our_node, 0, sizeof (wo->our_node));
316 memset (wo->his_node, 0, sizeof (wo->his_node));
319 wo->neg_complete = 1;
325 ao->neg_complete = 1;
328 ao->accept_local = 0;
329 ao->accept_remote = 0;
330 ao->accept_network = 0;
337 * Copy the node number
344 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
348 * Compare node numbers
352 compare_node (src, dst)
355 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
359 * Is the node number zero?
367 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
368 if (node [indx] != 0)
374 * Increment the node number
388 PUTLONG (magic_num, outp);
392 * ipxcp_open - IPXCP is allowed to come up.
398 fsm_open(&ipxcp_fsm[unit]);
402 * ipxcp_close - Take IPXCP down.
405 ipxcp_close(unit, reason)
409 fsm_close(&ipxcp_fsm[unit], reason);
414 * ipxcp_lowerup - The lower layer is up.
420 fsm_lowerup(&ipxcp_fsm[unit]);
425 * ipxcp_lowerdown - The lower layer is down.
428 ipxcp_lowerdown(unit)
431 fsm_lowerdown(&ipxcp_fsm[unit]);
436 * ipxcp_input - Input IPXCP packet.
439 ipxcp_input(unit, p, len)
444 fsm_input(&ipxcp_fsm[unit], p, len);
449 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
451 * Pretend the lower layer went down, so we shut up.
457 fsm_lowerdown(&ipxcp_fsm[unit]);
462 * ipxcp_resetci - Reset our CI.
468 wo->req_node = wo->neg_node && ao->neg_node;
469 wo->req_nn = wo->neg_nn && ao->neg_nn;
471 if (wo->our_network == 0) {
473 ao->accept_network = 1;
476 * If our node number is zero then change it.
478 if (zero_node (wo->our_node)) {
479 inc_node (wo->our_node);
480 ao->accept_local = 1;
484 * If his node number is zero then change it.
486 if (zero_node (wo->his_node)) {
487 inc_node (wo->his_node);
488 ao->accept_remote = 1;
491 * If no routing agent was specified then we do RIP/SAP according to the
492 * RFC documents. If you have specified something then OK. Otherwise, we
495 if (ao->router == 0) {
496 ao->router |= BIT(RIP_SAP);
497 wo->router |= BIT(RIP_SAP);
500 /* Always specify a routing protocol unless it was REJected. */
503 * Start with these default values
509 * ipxcp_cilen - Return length of our CI.
518 len = go->neg_nn ? CILEN_NETN : 0;
519 len += go->neg_node ? CILEN_NODEN : 0;
520 len += go->neg_name ? CILEN_NAME + strlen (go->name) - 1 : 0;
522 /* RFC says that defaults should not be included. */
523 if (go->neg_router && to_external(go->router) != RIP_SAP)
524 len += CILEN_PROTOCOL;
531 * ipxcp_addci - Add our desired CIs to a packet.
534 ipxcp_addci(f, ucp, lenp)
540 * Add the options to the record.
543 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
544 PUTCHAR (CILEN_NETN, ucp);
545 PUTLONG (go->our_network, ucp);
550 PUTCHAR (IPX_NODE_NUMBER, ucp);
551 PUTCHAR (CILEN_NODEN, ucp);
552 for (indx = 0; indx < sizeof (go->our_node); ++indx)
553 PUTCHAR (go->our_node[indx], ucp);
557 int cilen = strlen (go->name);
559 PUTCHAR (IPX_ROUTER_NAME, ucp);
560 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
561 for (indx = 0; indx < cilen; ++indx)
562 PUTCHAR (go->name [indx], ucp);
565 if (go->neg_router) {
566 short external = to_external (go->router);
567 if (external != RIP_SAP) {
568 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
569 PUTCHAR (CILEN_PROTOCOL, ucp);
570 PUTSHORT (external, ucp);
576 * ipxcp_ackci - Ack our CIs.
583 ipxcp_ackci(f, p, len)
588 u_short cilen, citype, cishort;
592 #define ACKCIVOID(opt, neg) \
594 if ((len -= CILEN_VOID) < 0) \
596 GETCHAR(citype, p); \
598 if (cilen != CILEN_VOID || \
603 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
605 #define ACKCICHARS(opt, neg, val, cnt) \
607 int indx, count = cnt; \
608 len -= (count + 2); \
611 GETCHAR(citype, p); \
613 if (cilen != (count + 2) || \
616 for (indx = 0; indx < count; ++indx) {\
617 GETCHAR(cichar, p); \
618 if (cichar != ((u_char *) &val)[indx]) \
625 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
626 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
628 #define ACKCINETWORK(opt, neg, val) \
630 if ((len -= CILEN_NETN) < 0) \
632 GETCHAR(citype, p); \
634 if (cilen != CILEN_NETN || \
637 GETLONG(cilong, p); \
642 #define ACKCIPROTO(opt, neg, val) \
646 GETCHAR(citype, p); \
648 if (cilen != CILEN_PROTOCOL || citype != opt) \
653 GETSHORT(cishort, p); \
654 if (cishort != to_external (val) || cishort == RIP_SAP) \
658 * Process the ACK frame in the order in which the frame was assembled
661 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
662 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
663 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
664 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
665 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
666 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
668 * This is the end of the record.
674 * The frame is invalid
676 IPXCPDEBUG((LOG_INFO, "ipxcp_ackci: received bad Ack!"));
681 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
682 * This should not modify any state if the Nak is bad
683 * or if IPXCP is in the OPENED state.
691 ipxcp_nakci(f, p, len)
696 u_char citype, cilen, *next;
699 ipxcp_options no; /* options we've seen Naks for */
700 ipxcp_options try; /* options to request next time */
702 BZERO(&no, sizeof(no));
705 while (len > CILEN_VOID) {
711 next = &p [cilen - CILEN_VOID];
714 case IPX_NETWORK_NUMBER:
715 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
720 IPXCPDEBUG((LOG_INFO, "local IP address %d", l));
721 if (l && ao->accept_network)
725 case IPX_NODE_NUMBER:
726 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
730 IPXCPDEBUG((LOG_INFO,
731 "local node number %02X%02X%02X%02X%02X%02X",
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 */
762 IPXCPDEBUG((LOG_INFO, "Router protocol number %d", s));
765 /* These, according to the RFC, must never be NAKed. */
766 case IPX_ROUTER_NAME:
770 /* These are for options which we have not seen. */
777 /* If there is still anything left, this packet is bad. */
782 * Do not permit the peer to force a router protocol which we do not
783 * support. However, default to the condition that will accept "NONE".
785 try.router &= (ao->router | BIT(IPX_NONE));
786 if (try.router == 0 && ao->router != 0)
787 try.router = BIT(IPX_NONE);
793 * OK, the Nak is good. Now we can update state.
795 if (f->state != OPENED)
801 IPXCPDEBUG((LOG_INFO, "ipxcp_nakci: received bad Nak!"));
806 * ipxcp_rejci - Reject some of our CIs.
809 ipxcp_rejci(f, p, len)
814 u_short cilen, citype, cishort;
817 ipxcp_options try; /* options to request next time */
819 #define REJCINETWORK(opt, neg, val) \
820 if (neg && p[0] == opt) { \
821 if ((len -= CILEN_NETN) < 0) \
823 GETCHAR(citype, p); \
825 if (cilen != CILEN_NETN || \
828 GETLONG(cilong, p); \
831 IPXCPDEBUG((LOG_INFO,"ipxcp_rejci rejected long opt %d", opt)); \
835 #define REJCICHARS(opt, neg, val, cnt) \
836 if (neg && p[0] == opt) { \
837 int indx, count = cnt; \
838 len -= (count + 2); \
841 GETCHAR(citype, p); \
843 if (cilen != (count + 2) || \
846 for (indx = 0; indx < count; ++indx) {\
847 GETCHAR(cichar, p); \
848 if (cichar != ((u_char *) &val)[indx]) \
853 IPXCPDEBUG((LOG_INFO,"ipxcp_rejci rejected opt %d", opt)); \
857 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
858 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
860 #define REJCIVOID(opt, neg) \
861 if (neg && p[0] == opt) { \
862 if ((len -= CILEN_VOID) < 0) \
864 GETCHAR(citype, p); \
866 if (cilen != CILEN_VOID || citype != opt) \
868 IPXCPDEBUG((LOG_INFO, "ipxcp_rejci rejected void opt %d", opt)); \
872 /* a reject for RIP/SAP is invalid since we don't send it and you can't
873 reject something which is not sent. (You can NAK, but you can't REJ.) */
874 #define REJCIPROTO(opt, neg, val, bit) \
875 if (neg && p[0] == opt) { \
876 if ((len -= CILEN_PROTOCOL) < 0) \
878 GETCHAR(citype, p); \
880 if (cilen != CILEN_PROTOCOL) \
882 GETSHORT(cishort, p); \
883 if (cishort != to_external (val) || cishort == RIP_SAP) \
885 IPXCPDEBUG((LOG_INFO, "ipxcp_rejci short opt %d", opt)); \
889 * Any Rejected CIs must be in exactly the same order that we sent.
890 * Check packet length and CI length at each step.
891 * If we find any deviations, then this packet is bad.
896 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
897 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
898 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
899 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
901 * This is the end of the record.
904 if (f->state != OPENED)
910 * The frame is invalid at this point.
912 IPXCPDEBUG((LOG_INFO, "ipxcp_rejci: received bad Reject!"));
917 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
919 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
920 * appropriately. If reject_if_disagree is non-zero, doesn't return
921 * CONFNAK; returns CONFREJ if it can't return CONFACK.
924 ipxcp_reqci(f, inp, len, reject_if_disagree)
926 u_char *inp; /* Requested CIs */
927 int *len; /* Length of requested CIs */
928 int reject_if_disagree;
930 u_char *cip, *next; /* Pointer to current and next CIs */
931 u_short cilen, citype; /* Parsed len, type */
932 u_short cishort; /* Parsed short value */
933 u_int32_t cinetwork; /* Parsed address values */
934 int rc = CONFACK; /* Final packet return code */
935 int orc; /* Individual option return code */
936 u_char *p; /* Pointer to next char to parse */
937 u_char *ucp = inp; /* Pointer to current output char */
938 int l = *len; /* Length left */
941 * Reset all his options.
943 BZERO(ho, sizeof(*ho));
946 * Process all his options.
950 orc = CONFACK; /* Assume success */
951 cip = p = next; /* Remember begining of CI */
952 if (l < 2 || /* Not enough data for CI header or */
953 p[1] < 2 || /* CI length too small or */
954 p[1] > l) { /* CI length too big? */
955 IPXCPDEBUG((LOG_INFO, "ipxcp_reqci: bad CI length!"));
956 orc = CONFREJ; /* Reject bad CI */
957 cilen = l; /* Reject till end of packet */
958 l = 0; /* Don't loop again */
961 GETCHAR(citype, p); /* Parse CI type */
962 GETCHAR(cilen, p); /* Parse CI length */
963 l -= cilen; /* Adjust remaining length */
964 next += cilen; /* Step to next CI */
966 switch (citype) { /* Check CI type */
968 * The network number must match. Choose the larger of the two.
970 case IPX_NETWORK_NUMBER:
971 IPXCPDEBUG((LOG_INFO, "ipxcp: received Network Number request"));
973 /* if we wont negotiate the network number or the length is wrong
974 then reject the option */
975 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
979 GETLONG(cinetwork, p);
980 IPXCPDEBUG((LOG_INFO,"Remote proposed IPX network number is %8Lx",tl));
982 /* If the network numbers match then acknowledge them. */
983 if (cinetwork != 0) {
984 ho->his_network = cinetwork;
986 if (wo->our_network == cinetwork)
989 * If the network number is not given or we don't accept their change or
990 * the network number is too small then NAK it.
992 if (! ao->accept_network || cinetwork < wo->our_network) {
993 DECPTR (sizeof (u_int32_t), p);
994 PUTLONG (wo->our_network, p);
1000 * The peer sent '0' for the network. Give it ours if we have one.
1002 if (go->our_network != 0) {
1003 DECPTR (sizeof (u_int32_t), p);
1004 PUTLONG (wo->our_network, p);
1007 * We don't have one. Reject the value.
1014 * The node number is required
1016 case IPX_NODE_NUMBER:
1017 IPXCPDEBUG((LOG_INFO, "ipxcp: received Node Number request"));
1019 /* if we wont negotiate the node number or the length is wrong
1020 then reject the option */
1021 if ( cilen != CILEN_NODEN ) {
1026 copy_node (p, ho->his_node);
1029 * If the remote does not have a number and we do then NAK it with the value
1030 * which we have for it. (We never have a default value of zero.)
1032 if (zero_node (ho->his_node)) {
1034 copy_node (wo->his_node, p);
1035 INCPTR (sizeof (wo->his_node), p);
1039 * If you have given me the expected network node number then I'll accept
1042 if (compare_node (wo->his_node, ho->his_node)) {
1045 INCPTR (sizeof (wo->his_node), p);
1049 * If his node number is the same as ours then ask him to try the next
1052 if (compare_node (ho->his_node, go->our_node)) {
1053 inc_node (ho->his_node);
1055 copy_node (ho->his_node, p);
1056 INCPTR (sizeof (wo->his_node), p);
1060 * If we don't accept a new value then NAK it.
1062 if (! ao->accept_remote) {
1063 copy_node (wo->his_node, p);
1064 INCPTR (sizeof (wo->his_node), p);
1070 INCPTR (sizeof (wo->his_node), p);
1073 * Compression is not desired at this time. It is always rejected.
1075 case IPX_COMPRESSION_PROTOCOL:
1076 IPXCPDEBUG((LOG_INFO, "ipxcp: received Compression Protocol request "));
1080 * The routing protocol is a bitmask of various types. Any combination
1081 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1082 * routing protocol must be specified only once.
1084 case IPX_ROUTER_PROTOCOL:
1085 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1090 GETSHORT (cishort, p);
1091 IPXCPDEBUG((LOG_INFO,
1092 "Remote router protocol number 0x%04x",
1095 if (wo->neg_router == 0) {
1097 wo->router = BIT(IPX_NONE);
1100 if ((cishort == IPX_NONE && ho->router != 0) ||
1101 (ho->router & BIT(IPX_NONE))) {
1106 cishort = BIT(cishort);
1107 if (ho->router & cishort) {
1112 ho->router |= cishort;
1115 /* Finally do not allow a router protocol which we do not
1118 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1121 if (cishort == BIT(NLSP) &&
1122 (ao->router & BIT(RIP_SAP)) &&
1127 protocol = IPX_NONE;
1129 DECPTR (sizeof (u_int16_t), p);
1130 PUTSHORT (protocol, p);
1135 * The router name is advisorary. Just accept it if it is not too large.
1137 case IPX_ROUTER_NAME:
1138 IPXCPDEBUG((LOG_INFO, "ipxcp: received Router Name request"));
1139 if (cilen >= CILEN_NAME) {
1140 int name_size = cilen - CILEN_NAME;
1141 if (name_size > sizeof (ho->name))
1142 name_size = sizeof (ho->name) - 1;
1143 memset (ho->name, 0, sizeof (ho->name));
1144 memcpy (ho->name, p, name_size);
1145 ho->name [name_size] = '\0';
1153 * This is advisorary.
1156 IPXCPDEBUG((LOG_INFO, "ipxcp: received Complete request"));
1157 if (cilen != CILEN_COMPLETE)
1160 ho->neg_complete = 1;
1165 * All other entries are not known at this time.
1168 IPXCPDEBUG((LOG_INFO, "ipxcp: received Complete request"));
1174 IPXCPDEBUG((LOG_INFO, " (%s)\n", CODENAME(orc)));
1176 if (orc == CONFACK && /* Good CI */
1177 rc != CONFACK) /* but prior CI wasnt? */
1178 continue; /* Don't send this one */
1180 if (orc == CONFNAK) { /* Nak this CI? */
1181 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1182 orc = CONFREJ; /* Get tough if so */
1183 if (rc == CONFREJ) /* Rejecting prior CI? */
1184 continue; /* Don't send this one */
1185 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1186 rc = CONFNAK; /* Not anymore... */
1187 ucp = inp; /* Backup */
1191 if (orc == CONFREJ && /* Reject this CI */
1192 rc != CONFREJ) { /* but no prior ones? */
1194 ucp = inp; /* Backup */
1197 /* Need to move CI? */
1199 BCOPY(cip, ucp, cilen); /* Move it */
1201 /* Update output pointer */
1206 * If we aren't rejecting this packet, and we want to negotiate
1207 * their address, and they didn't send their address, then we
1208 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1209 * input buffer is long enough that we can append the extra
1213 if (rc != CONFREJ && !ho->neg_node &&
1214 wo->req_nn && !reject_if_disagree) {
1215 if (rc == CONFACK) {
1217 wo->req_nn = 0; /* don't ask again */
1218 ucp = inp; /* reset pointer */
1221 if (zero_node (wo->his_node))
1222 inc_node (wo->his_node);
1224 PUTCHAR (IPX_NODE_NUMBER, ucp);
1225 PUTCHAR (CILEN_NODEN, ucp);
1226 copy_node (wo->his_node, ucp);
1227 INCPTR (sizeof (wo->his_node), ucp);
1230 *len = ucp - inp; /* Compute output length */
1231 IPXCPDEBUG((LOG_INFO, "ipxcp: returning Configure-%s", CODENAME(rc)));
1232 return (rc); /* Return final code */
1236 * ipxcp_up - IPXCP has come UP.
1238 * Configure the IP network interface appropriately and bring it up.
1247 IPXCPDEBUG((LOG_INFO, "ipxcp: up"));
1249 /* The default router protocol is RIP/SAP. */
1250 if (ho->router == 0)
1251 ho->router = BIT(RIP_SAP);
1253 if (go->router == 0)
1254 go->router = BIT(RIP_SAP);
1256 /* Fetch the network number */
1258 ho->his_network = wo->his_network;
1261 copy_node (wo->his_node, ho->his_node);
1263 if (!wo->neg_node && !go->neg_node)
1264 copy_node (wo->our_node, go->our_node);
1266 if (zero_node (go->our_node)) {
1267 static char errmsg[] = "Could not determine local IPX node address";
1268 IPXCPDEBUG((LOG_ERR, errmsg));
1269 ipxcp_close(f->unit, errmsg);
1273 go->network = go->our_network;
1274 if (ho->his_network != 0 && ho->his_network > go->network)
1275 go->network = ho->his_network;
1277 if (go->network == 0) {
1278 static char errmsg[] = "Can not determine network number";
1279 IPXCPDEBUG((LOG_ERR, errmsg));
1280 ipxcp_close (unit, errmsg);
1284 /* bring the interface up */
1286 IPXCPDEBUG((LOG_WARNING, "sifup failed"));
1287 ipxcp_close(unit, "Interface configuration failed");
1291 /* set the network number for IPX */
1292 if (!sipxfaddr(unit, go->network, go->our_node)) {
1293 IPXCPDEBUG((LOG_WARNING, "sipxfaddr failed"));
1294 ipxcp_close(unit, "Interface configuration failed");
1299 * Execute the ipx-up script, like this:
1300 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1303 ipxcp_script (f, _PATH_IPXUP);
1307 * ipxcp_down - IPXCP has gone DOWN.
1309 * Take the IP network interface down, clear its addresses
1310 * and delete routes through it.
1317 IPXCPDEBUG((LOG_INFO, "ipxcp: down"));
1319 cipxfaddr (f->unit);
1321 ipxcp_script (f, _PATH_IPXDOWN);
1326 * ipxcp_script - Execute a script with arguments
1327 * interface-name tty-name speed local-IPX remote-IPX networks.
1330 ipxcp_script(f, script)
1334 char strspeed[32], strlocal[32], strremote[32];
1335 char strnetwork[32], strpid[32];
1336 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1338 sprintf (strpid, "%d", getpid());
1339 sprintf (strspeed, "%d", baud_rate);
1341 strproto_lcl[0] = '\0';
1342 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1343 if (go->router & BIT(RIP_SAP))
1344 strcpy (strproto_lcl, "RIP ");
1345 if (go->router & BIT(NLSP))
1346 strcat (strproto_lcl, "NLSP ");
1349 if (strproto_lcl[0] == '\0')
1350 strcpy (strproto_lcl, "NONE ");
1352 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1354 strproto_rmt[0] = '\0';
1355 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1356 if (ho->router & BIT(RIP_SAP))
1357 strcpy (strproto_rmt, "RIP ");
1358 if (ho->router & BIT(NLSP))
1359 strcat (strproto_rmt, "NLSP ");
1362 if (strproto_rmt[0] == '\0')
1363 strcpy (strproto_rmt, "NONE ");
1365 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1367 strcpy (strnetwork, ipx_ntoa (go->network));
1370 "%02X%02X%02X%02X%02X%02X",
1371 NODE(go->our_node));
1374 "%02X%02X%02X%02X%02X%02X",
1375 NODE(ho->his_node));
1381 argv[4] = strnetwork;
1383 argv[6] = strremote;
1384 argv[7] = strproto_lcl;
1385 argv[8] = strproto_rmt;
1387 argv[10] = ho->name;
1391 run_program(script, argv, 0, NULL, NULL);
1395 * ipxcp_printpkt - print the contents of an IPXCP packet.
1397 static char *ipxcp_codenames[] = {
1398 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1399 "TermReq", "TermAck", "CodeRej"
1403 ipxcp_printpkt(p, plen, printer, arg)
1406 void (*printer) __P((void *, char *, ...));
1409 int code, id, len, olen;
1410 u_char *pstart, *optend;
1414 if (plen < HEADERLEN)
1420 if (len < HEADERLEN || len > plen)
1423 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1424 printer(arg, " %s", ipxcp_codenames[code-1]);
1426 printer(arg, " code=0x%x", code);
1427 printer(arg, " id=0x%x", id);
1434 /* print option list */
1439 if (olen < CILEN_VOID || olen > len) {
1446 case IPX_NETWORK_NUMBER:
1447 if (olen == CILEN_NETN) {
1450 printer (arg, "network %s", ipx_ntoa (cilong));
1453 case IPX_NODE_NUMBER:
1454 if (olen == CILEN_NODEN) {
1456 printer (arg, "node ");
1457 while (p < optend) {
1459 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1463 case IPX_COMPRESSION_PROTOCOL:
1464 if (olen == CILEN_COMPRESS) {
1466 GETSHORT (cishort, p);
1467 printer (arg, "compression %d", (int) cishort);
1470 case IPX_ROUTER_PROTOCOL:
1471 if (olen == CILEN_PROTOCOL) {
1473 GETSHORT (cishort, p);
1474 printer (arg, "router proto %d", (int) cishort);
1477 case IPX_ROUTER_NAME:
1478 if (olen >= CILEN_NAME) {
1480 printer (arg, "router name \"");
1481 while (p < optend) {
1483 if (code >= 0x20 && code <= 0x7E)
1484 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1486 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1488 printer (arg, "\"");
1492 if (olen == CILEN_COMPLETE) {
1494 printer (arg, "complete");
1501 while (p < optend) {
1503 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1511 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1513 print_string(p, len, printer, arg);
1520 /* print the rest of the bytes in the packet */
1521 for (; len > 0; --len) {
1523 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1528 #endif /* ifdef IPX_CHANGE */