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.5 1997/03/04 03:39:32 paulus Exp $";
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
39 #include "pathnames.h"
42 ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
43 ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
44 ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
45 ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
47 #define wo (&ipxcp_wantoptions[0])
48 #define ao (&ipxcp_allowoptions[0])
49 #define go (&ipxcp_gotoptions[0])
50 #define ho (&ipxcp_hisoptions[0])
53 * Callbacks for fsm code. (CI = Configuration Information)
55 static void ipxcp_resetci __P((fsm *)); /* Reset our CI */
56 static int ipxcp_cilen __P((fsm *)); /* Return length of our CI */
57 static void ipxcp_addci __P((fsm *, u_char *, int *)); /* Add our CI */
58 static int ipxcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
59 static int ipxcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
60 static int ipxcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
61 static int ipxcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv CI */
62 static void ipxcp_up __P((fsm *)); /* We're UP */
63 static void ipxcp_down __P((fsm *)); /* We're DOWN */
64 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
66 fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
68 static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
69 ipxcp_resetci, /* Reset our Configuration Information */
70 ipxcp_cilen, /* Length of our Configuration Information */
71 ipxcp_addci, /* Add our Configuration Information */
72 ipxcp_ackci, /* ACK our Configuration Information */
73 ipxcp_nakci, /* NAK our Configuration Information */
74 ipxcp_rejci, /* Reject our Configuration Information */
75 ipxcp_reqci, /* Request peer's Configuration Information */
76 ipxcp_up, /* Called when fsm reaches OPENED state */
77 ipxcp_down, /* Called when fsm leaves OPENED state */
78 NULL, /* Called when we want the lower layer up */
79 NULL, /* Called when we want the lower layer down */
80 NULL, /* Called when Protocol-Reject received */
81 NULL, /* Retransmission is necessary */
82 NULL, /* Called to handle protocol-specific codes */
83 "IPXCP" /* String name of protocol */
87 * Protocol entry points.
90 static void ipxcp_init __P((int));
91 static void ipxcp_open __P((int));
92 static void ipxcp_close __P((int, char *));
93 static void ipxcp_lowerup __P((int));
94 static void ipxcp_lowerdown __P((int));
95 static void ipxcp_input __P((int, u_char *, int));
96 static void ipxcp_protrej __P((int));
97 static int ipxcp_printpkt __P((u_char *, int,
98 void (*) __P((void *, char *, ...)), void *));
100 struct protent ipxcp_protent = {
119 * Lengths of configuration options.
123 #define CILEN_COMPLETE 2 /* length of complete option */
124 #define CILEN_NETN 6 /* network number length option */
125 #define CILEN_NODEN 8 /* node number length option */
126 #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
127 #define CILEN_NAME 3 /* Minimum length of router name */
128 #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
130 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
131 (x) == CONFNAK ? "NAK" : "REJ")
133 /* Used in printing the node number */
134 #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
136 /* Used to generate the proper bit mask */
137 #define BIT(num) (1 << (num))
140 * Convert from internal to external notation
144 to_external(internal)
149 if (internal & IPX_NONE)
158 * Make a string representation of a network IP address.
166 sprintf(b, "%lx", ipxaddr);
172 * ipxcp_init - Initialize IPXCP.
178 fsm *f = &ipxcp_fsm[unit];
181 f->protocol = PPP_IPXCP;
182 f->callbacks = &ipxcp_callbacks;
183 fsm_init(&ipxcp_fsm[unit]);
185 memset (wo->name, 0, sizeof (wo->name));
186 memset (wo->our_node, 0, sizeof (wo->our_node));
187 memset (wo->his_node, 0, sizeof (wo->his_node));
190 wo->neg_complete = 1;
196 ao->neg_complete = 1;
199 ao->accept_local = 0;
200 ao->accept_remote = 0;
201 ao->accept_network = 0;
208 * Copy the node number
215 memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
219 * Compare node numbers
223 compare_node (src, dst)
226 return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
230 * Is the node number zero?
238 for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
239 if (node [indx] != 0)
245 * Increment the node number
259 PUTLONG (magic_num, outp);
263 * ipxcp_open - IPXCP is allowed to come up.
269 fsm_open(&ipxcp_fsm[unit]);
273 * ipxcp_close - Take IPXCP down.
276 ipxcp_close(unit, reason)
280 fsm_close(&ipxcp_fsm[unit], reason);
285 * ipxcp_lowerup - The lower layer is up.
291 fsm_lowerup(&ipxcp_fsm[unit]);
296 * ipxcp_lowerdown - The lower layer is down.
299 ipxcp_lowerdown(unit)
302 fsm_lowerdown(&ipxcp_fsm[unit]);
307 * ipxcp_input - Input IPXCP packet.
310 ipxcp_input(unit, p, len)
315 fsm_input(&ipxcp_fsm[unit], p, len);
320 * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
322 * Pretend the lower layer went down, so we shut up.
328 fsm_lowerdown(&ipxcp_fsm[unit]);
333 * ipxcp_resetci - Reset our CI.
342 wo->req_node = wo->neg_node && ao->neg_node;
343 wo->req_nn = wo->neg_nn && ao->neg_nn;
345 if (wo->our_network == 0) {
347 ao->accept_network = 1;
350 * If our node number is zero then change it.
352 if (zero_node (wo->our_node)) {
353 inc_node (wo->our_node);
354 ao->accept_local = 1;
358 * If his node number is zero then change it.
360 if (zero_node (wo->his_node)) {
361 inc_node (wo->his_node);
362 ao->accept_remote = 1;
365 * If no routing agent was specified then we do RIP/SAP according to the
366 * RFC documents. If you have specified something then OK. Otherwise, we
369 if (ao->router == 0) {
370 ao->router |= BIT(RIP_SAP);
371 wo->router |= BIT(RIP_SAP);
374 /* Always specify a routing protocol unless it was REJected. */
377 * Start with these default values
383 * ipxcp_cilen - Return length of our CI.
393 len = go->neg_nn ? CILEN_NETN : 0;
394 len += go->neg_node ? CILEN_NODEN : 0;
395 len += go->neg_name ? CILEN_NAME + strlen (go->name) - 1 : 0;
397 /* RFC says that defaults should not be included. */
398 if (go->neg_router && to_external(go->router) != RIP_SAP)
399 len += CILEN_PROTOCOL;
406 * ipxcp_addci - Add our desired CIs to a packet.
409 ipxcp_addci(f, ucp, lenp)
417 * Add the options to the record.
420 PUTCHAR (IPX_NETWORK_NUMBER, ucp);
421 PUTCHAR (CILEN_NETN, ucp);
422 PUTLONG (go->our_network, ucp);
427 PUTCHAR (IPX_NODE_NUMBER, ucp);
428 PUTCHAR (CILEN_NODEN, ucp);
429 for (indx = 0; indx < sizeof (go->our_node); ++indx)
430 PUTCHAR (go->our_node[indx], ucp);
434 int cilen = strlen (go->name);
436 PUTCHAR (IPX_ROUTER_NAME, ucp);
437 PUTCHAR (CILEN_NAME + cilen - 1, ucp);
438 for (indx = 0; indx < cilen; ++indx)
439 PUTCHAR (go->name [indx], ucp);
442 if (go->neg_router) {
443 short external = to_external (go->router);
444 if (external != RIP_SAP) {
445 PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
446 PUTCHAR (CILEN_PROTOCOL, ucp);
447 PUTSHORT (external, ucp);
453 * ipxcp_ackci - Ack our CIs.
460 ipxcp_ackci(f, p, len)
466 u_short cilen, citype, cishort;
470 #define ACKCIVOID(opt, neg) \
472 if ((len -= CILEN_VOID) < 0) \
474 GETCHAR(citype, p); \
476 if (cilen != CILEN_VOID || \
481 #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
483 #define ACKCICHARS(opt, neg, val, cnt) \
485 int indx, count = cnt; \
486 len -= (count + 2); \
489 GETCHAR(citype, p); \
491 if (cilen != (count + 2) || \
494 for (indx = 0; indx < count; ++indx) {\
495 GETCHAR(cichar, p); \
496 if (cichar != ((u_char *) &val)[indx]) \
503 #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
504 #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen(val))
506 #define ACKCINETWORK(opt, neg, val) \
508 if ((len -= CILEN_NETN) < 0) \
510 GETCHAR(citype, p); \
512 if (cilen != CILEN_NETN || \
515 GETLONG(cilong, p); \
520 #define ACKCIPROTO(opt, neg, val) \
524 GETCHAR(citype, p); \
526 if (cilen != CILEN_PROTOCOL || citype != opt) \
531 GETSHORT(cishort, p); \
532 if (cishort != to_external (val) || cishort == RIP_SAP) \
536 * Process the ACK frame in the order in which the frame was assembled
539 ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
540 ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
541 ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
542 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
543 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
544 ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
546 * This is the end of the record.
552 * The frame is invalid
554 IPXCPDEBUG((LOG_INFO, "ipxcp_ackci: received bad Ack!"));
559 * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
560 * This should not modify any state if the Nak is bad
561 * or if IPXCP is in the OPENED state.
569 ipxcp_nakci(f, p, len)
575 u_char citype, cilen, *next;
578 ipxcp_options no; /* options we've seen Naks for */
579 ipxcp_options try; /* options to request next time */
581 BZERO(&no, sizeof(no));
584 while (len > CILEN_VOID) {
590 next = &p [cilen - CILEN_VOID];
593 case IPX_NETWORK_NUMBER:
594 if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
599 IPXCPDEBUG((LOG_INFO, "local IP address %d", l));
600 if (l && ao->accept_network)
604 case IPX_NODE_NUMBER:
605 if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
609 IPXCPDEBUG((LOG_INFO,
610 "local node number %02X%02X%02X%02X%02X%02X",
613 if (!zero_node (p) && ao->accept_local &&
614 ! compare_node (p, ho->his_node))
615 copy_node (p, try.our_node);
618 /* This has never been sent. Ignore the NAK frame */
619 case IPX_COMPRESSION_PROTOCOL:
622 case IPX_ROUTER_PROTOCOL:
623 if (!go->neg_router || (cilen < CILEN_PROTOCOL))
627 if (s > 15) /* This is just bad, but ignore for now. */
631 if (no.router & s) /* duplicate NAKs are always bad */
634 if (no.router == 0) /* Reset on first NAK only */
641 IPXCPDEBUG((LOG_INFO, "Router protocol number %d", s));
644 /* These, according to the RFC, must never be NAKed. */
645 case IPX_ROUTER_NAME:
649 /* These are for options which we have not seen. */
656 /* If there is still anything left, this packet is bad. */
661 * Do not permit the peer to force a router protocol which we do not
662 * support. However, default to the condition that will accept "NONE".
664 try.router &= (ao->router | BIT(IPX_NONE));
665 if (try.router == 0 && ao->router != 0)
666 try.router = BIT(IPX_NONE);
672 * OK, the Nak is good. Now we can update state.
674 if (f->state != OPENED)
680 IPXCPDEBUG((LOG_INFO, "ipxcp_nakci: received bad Nak!"));
685 * ipxcp_rejci - Reject some of our CIs.
688 ipxcp_rejci(f, p, len)
694 u_short cilen, citype, cishort;
697 ipxcp_options try; /* options to request next time */
699 #define REJCINETWORK(opt, neg, val) \
700 if (neg && p[0] == opt) { \
701 if ((len -= CILEN_NETN) < 0) \
703 GETCHAR(citype, p); \
705 if (cilen != CILEN_NETN || \
708 GETLONG(cilong, p); \
711 IPXCPDEBUG((LOG_INFO,"ipxcp_rejci rejected long opt %d", opt)); \
715 #define REJCICHARS(opt, neg, val, cnt) \
716 if (neg && p[0] == opt) { \
717 int indx, count = cnt; \
718 len -= (count + 2); \
721 GETCHAR(citype, p); \
723 if (cilen != (count + 2) || \
726 for (indx = 0; indx < count; ++indx) {\
727 GETCHAR(cichar, p); \
728 if (cichar != ((u_char *) &val)[indx]) \
733 IPXCPDEBUG((LOG_INFO,"ipxcp_rejci rejected opt %d", opt)); \
737 #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
738 #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
740 #define REJCIVOID(opt, neg) \
741 if (neg && p[0] == opt) { \
742 if ((len -= CILEN_VOID) < 0) \
744 GETCHAR(citype, p); \
746 if (cilen != CILEN_VOID || citype != opt) \
748 IPXCPDEBUG((LOG_INFO, "ipxcp_rejci rejected void opt %d", opt)); \
752 /* a reject for RIP/SAP is invalid since we don't send it and you can't
753 reject something which is not sent. (You can NAK, but you can't REJ.) */
754 #define REJCIPROTO(opt, neg, val, bit) \
755 if (neg && p[0] == opt) { \
756 if ((len -= CILEN_PROTOCOL) < 0) \
758 GETCHAR(citype, p); \
760 if (cilen != CILEN_PROTOCOL) \
762 GETSHORT(cishort, p); \
763 if (cishort != to_external (val) || cishort == RIP_SAP) \
765 IPXCPDEBUG((LOG_INFO, "ipxcp_rejci short opt %d", opt)); \
769 * Any Rejected CIs must be in exactly the same order that we sent.
770 * Check packet length and CI length at each step.
771 * If we find any deviations, then this packet is bad.
776 REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
777 REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
778 REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
779 REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
781 * This is the end of the record.
784 if (f->state != OPENED)
790 * The frame is invalid at this point.
792 IPXCPDEBUG((LOG_INFO, "ipxcp_rejci: received bad Reject!"));
797 * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
799 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
800 * appropriately. If reject_if_disagree is non-zero, doesn't return
801 * CONFNAK; returns CONFREJ if it can't return CONFACK.
804 ipxcp_reqci(f, inp, len, reject_if_disagree)
806 u_char *inp; /* Requested CIs */
807 int *len; /* Length of requested CIs */
808 int reject_if_disagree;
811 u_char *cip, *next; /* Pointer to current and next CIs */
812 u_short cilen, citype; /* Parsed len, type */
813 u_short cishort, ts; /* Parsed short value */
814 u_int32_t tl, cinetwork, outnet;/* Parsed address values */
815 int rc = CONFACK; /* Final packet return code */
816 int orc; /* Individual option return code */
817 u_char *p; /* Pointer to next char to parse */
818 u_char *ucp = inp; /* Pointer to current output char */
819 int l = *len; /* Length left */
820 u_char maxslotindex, cflag;
823 * Reset all his options.
825 BZERO(ho, sizeof(*ho));
828 * Process all his options.
832 orc = CONFACK; /* Assume success */
833 cip = p = next; /* Remember begining of CI */
834 if (l < 2 || /* Not enough data for CI header or */
835 p[1] < 2 || /* CI length too small or */
836 p[1] > l) { /* CI length too big? */
837 IPXCPDEBUG((LOG_INFO, "ipxcp_reqci: bad CI length!"));
838 orc = CONFREJ; /* Reject bad CI */
839 cilen = l; /* Reject till end of packet */
840 l = 0; /* Don't loop again */
843 GETCHAR(citype, p); /* Parse CI type */
844 GETCHAR(cilen, p); /* Parse CI length */
845 l -= cilen; /* Adjust remaining length */
846 next += cilen; /* Step to next CI */
848 switch (citype) { /* Check CI type */
850 * The network number must match. Choose the larger of the two.
852 case IPX_NETWORK_NUMBER:
853 IPXCPDEBUG((LOG_INFO, "ipxcp: received Network Number request"));
855 /* if we wont negotiate the network number or the length is wrong
856 then reject the option */
857 if ( !ao->neg_nn || cilen != CILEN_NETN ) {
861 GETLONG(cinetwork, p);
862 IPXCPDEBUG((LOG_INFO,"Remote proposed IPX network number is %8Lx",tl));
864 /* If the network numbers match then acknowledge them. */
865 if (cinetwork != 0) {
866 ho->his_network = cinetwork;
868 if (wo->our_network == cinetwork)
871 * If the network number is not given or we don't accept their change or
872 * the network number is too small then NAK it.
874 if (! ao->accept_network || cinetwork < wo->our_network) {
875 DECPTR (sizeof (u_int32_t), p);
876 PUTLONG (wo->our_network, p);
882 * The peer sent '0' for the network. Give it ours if we have one.
884 if (go->our_network != 0) {
885 DECPTR (sizeof (u_int32_t), p);
886 PUTLONG (wo->our_network, p);
889 * We don't have one. Reject the value.
896 * The node number is required
898 case IPX_NODE_NUMBER:
899 IPXCPDEBUG((LOG_INFO, "ipxcp: received Node Number request"));
901 /* if we wont negotiate the node number or the length is wrong
902 then reject the option */
903 if ( cilen != CILEN_NODEN ) {
908 copy_node (p, ho->his_node);
911 * If the remote does not have a number and we do then NAK it with the value
912 * which we have for it. (We never have a default value of zero.)
914 if (zero_node (ho->his_node)) {
916 copy_node (wo->his_node, p);
917 INCPTR (sizeof (wo->his_node), p);
921 * If you have given me the expected network node number then I'll accept
924 if (compare_node (wo->his_node, ho->his_node)) {
927 INCPTR (sizeof (wo->his_node), p);
931 * If his node number is the same as ours then ask him to try the next
934 if (compare_node (ho->his_node, go->our_node)) {
935 inc_node (ho->his_node);
937 copy_node (ho->his_node, p);
938 INCPTR (sizeof (wo->his_node), p);
942 * If we don't accept a new value then NAK it.
944 if (! ao->accept_remote) {
945 copy_node (wo->his_node, p);
946 INCPTR (sizeof (wo->his_node), p);
952 INCPTR (sizeof (wo->his_node), p);
955 * Compression is not desired at this time. It is always rejected.
957 case IPX_COMPRESSION_PROTOCOL:
958 IPXCPDEBUG((LOG_INFO, "ipxcp: received Compression Protocol request "));
962 * The routing protocol is a bitmask of various types. Any combination
963 * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
964 * routing protocol must be specified only once.
966 case IPX_ROUTER_PROTOCOL:
967 if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
972 GETSHORT (cishort, p);
973 IPXCPDEBUG((LOG_INFO,
974 "Remote router protocol number 0x%04x",
977 if (wo->neg_router == 0) {
979 wo->router = BIT(IPX_NONE);
982 if ((cishort == IPX_NONE && ho->router != 0) ||
983 (ho->router & BIT(IPX_NONE))) {
988 cishort = BIT(cishort);
989 if (ho->router & cishort) {
994 ho->router |= cishort;
997 /* Finally do not allow a router protocol which we do not
1000 if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1003 if (cishort == BIT(NLSP) &&
1004 (ao->router & BIT(RIP_SAP)) &&
1009 protocol = IPX_NONE;
1011 DECPTR (sizeof (u_int16_t), p);
1012 PUTSHORT (protocol, p);
1017 * The router name is advisorary. Just accept it if it is not too large.
1019 case IPX_ROUTER_NAME:
1020 IPXCPDEBUG((LOG_INFO, "ipxcp: received Router Name request"));
1021 if (cilen >= CILEN_NAME) {
1022 int name_size = cilen - CILEN_NAME;
1023 if (name_size > sizeof (ho->name))
1024 name_size = sizeof (ho->name) - 1;
1025 memset (ho->name, 0, sizeof (ho->name));
1026 memcpy (ho->name, p, name_size);
1027 ho->name [name_size] = '\0';
1035 * This is advisorary.
1038 IPXCPDEBUG((LOG_INFO, "ipxcp: received Complete request"));
1039 if (cilen != CILEN_COMPLETE)
1042 ho->neg_complete = 1;
1047 * All other entries are not known at this time.
1050 IPXCPDEBUG((LOG_INFO, "ipxcp: received Complete request"));
1056 IPXCPDEBUG((LOG_INFO, " (%s)\n", CODENAME(orc)));
1058 if (orc == CONFACK && /* Good CI */
1059 rc != CONFACK) /* but prior CI wasnt? */
1060 continue; /* Don't send this one */
1062 if (orc == CONFNAK) { /* Nak this CI? */
1063 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1064 orc = CONFREJ; /* Get tough if so */
1065 if (rc == CONFREJ) /* Rejecting prior CI? */
1066 continue; /* Don't send this one */
1067 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1068 rc = CONFNAK; /* Not anymore... */
1069 ucp = inp; /* Backup */
1073 if (orc == CONFREJ && /* Reject this CI */
1074 rc != CONFREJ) { /* but no prior ones? */
1076 ucp = inp; /* Backup */
1079 /* Need to move CI? */
1081 BCOPY(cip, ucp, cilen); /* Move it */
1083 /* Update output pointer */
1088 * If we aren't rejecting this packet, and we want to negotiate
1089 * their address, and they didn't send their address, then we
1090 * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1091 * input buffer is long enough that we can append the extra
1095 if (rc != CONFREJ && !ho->neg_node &&
1096 wo->req_nn && !reject_if_disagree) {
1098 if (rc == CONFACK) {
1100 wo->req_nn = 0; /* don't ask again */
1101 ucp = inp; /* reset pointer */
1104 if (zero_node (wo->his_node))
1105 inc_node (wo->his_node);
1107 PUTCHAR (IPX_NODE_NUMBER, ucp);
1108 PUTCHAR (CILEN_NODEN, ucp);
1109 copy_node (wo->his_node, ucp);
1110 INCPTR (sizeof (wo->his_node), ucp);
1113 *len = ucp - inp; /* Compute output length */
1114 IPXCPDEBUG((LOG_INFO, "ipxcp: returning Configure-%s", CODENAME(rc)));
1115 return (rc); /* Return final code */
1119 * ipxcp_up - IPXCP has come UP.
1121 * Configure the IP network interface appropriately and bring it up.
1130 IPXCPDEBUG((LOG_INFO, "ipxcp: up"));
1132 /* The default router protocol is RIP/SAP. */
1133 if (ho->router == 0)
1134 ho->router = BIT(RIP_SAP);
1136 if (go->router == 0)
1137 go->router = BIT(RIP_SAP);
1139 /* Fetch the network number */
1141 ho->his_network = wo->his_network;
1144 copy_node (wo->his_node, ho->his_node);
1146 if (!wo->neg_node && !go->neg_node)
1147 copy_node (wo->our_node, go->our_node);
1149 if (zero_node (go->our_node)) {
1150 static char errmsg[] = "Could not determine local IPX node address";
1151 IPXCPDEBUG((LOG_ERR, errmsg));
1152 ipxcp_close(f->unit, errmsg);
1156 go->network = go->our_network;
1157 if (ho->his_network != 0 && ho->his_network > go->network)
1158 go->network = ho->his_network;
1160 if (go->network == 0) {
1161 static char errmsg[] = "Can not determine network number";
1162 IPXCPDEBUG((LOG_ERR, errmsg));
1163 ipxcp_close (unit, errmsg);
1167 /* bring the interface up */
1169 IPXCPDEBUG((LOG_WARNING, "sifup failed"));
1170 ipxcp_close(unit, "Interface configuration failed");
1174 /* set the network number for IPX */
1175 if (!sipxfaddr(unit, go->network, go->our_node)) {
1176 IPXCPDEBUG((LOG_WARNING, "sipxfaddr failed"));
1177 ipxcp_close(unit, "Interface configuration failed");
1182 * Execute the ipx-up script, like this:
1183 * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1186 ipxcp_script (f, _PATH_IPXUP);
1190 * ipxcp_down - IPXCP has gone DOWN.
1192 * Take the IP network interface down, clear its addresses
1193 * and delete routes through it.
1200 u_int32_t ournn, network;
1202 IPXCPDEBUG((LOG_INFO, "ipxcp: down"));
1204 cipxfaddr (f->unit);
1206 ipxcp_script (f, _PATH_IPXDOWN);
1211 * ipxcp_script - Execute a script with arguments
1212 * interface-name tty-name speed local-IPX remote-IPX networks.
1215 ipxcp_script(f, script)
1220 char strspeed[32], strlocal[32], strremote[32];
1221 char strnetwork[32], strpid[32];
1222 char *argv[14], strproto_lcl[32], strproto_rmt[32];
1224 sprintf (strpid, "%d", getpid());
1225 sprintf (strspeed, "%d", baud_rate);
1227 strproto_lcl[0] = '\0';
1228 if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1229 if (go->router & BIT(RIP_SAP))
1230 strcpy (strproto_lcl, "RIP ");
1231 if (go->router & BIT(NLSP))
1232 strcat (strproto_lcl, "NLSP ");
1235 if (strproto_lcl[0] == '\0')
1236 strcpy (strproto_lcl, "NONE ");
1238 strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1240 strproto_rmt[0] = '\0';
1241 if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1242 if (ho->router & BIT(RIP_SAP))
1243 strcpy (strproto_rmt, "RIP ");
1244 if (ho->router & BIT(NLSP))
1245 strcat (strproto_rmt, "NLSP ");
1248 if (strproto_rmt[0] == '\0')
1249 strcpy (strproto_rmt, "NONE ");
1251 strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1253 strcpy (strnetwork, ipx_ntoa (go->network));
1256 "%02X%02X%02X%02X%02X%02X",
1257 NODE(go->our_node));
1260 "%02X%02X%02X%02X%02X%02X",
1261 NODE(ho->his_node));
1267 argv[4] = strnetwork;
1269 argv[6] = strremote;
1270 argv[7] = strproto_lcl;
1271 argv[8] = strproto_rmt;
1273 argv[10] = ho->name;
1277 run_program(script, argv, 0);
1281 * ipxcp_printpkt - print the contents of an IPXCP packet.
1283 static char *ipxcp_codenames[] = {
1284 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1285 "TermReq", "TermAck", "CodeRej"
1289 ipxcp_printpkt(p, plen, printer, arg)
1292 void (*printer) __P((void *, char *, ...));
1295 int code, id, len, olen;
1296 u_char *pstart, *optend;
1300 if (plen < HEADERLEN)
1306 if (len < HEADERLEN || len > plen)
1309 if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1310 printer(arg, " %s", ipxcp_codenames[code-1]);
1312 printer(arg, " code=0x%x", code);
1313 printer(arg, " id=0x%x", id);
1320 /* print option list */
1325 if (olen < CILEN_VOID || olen > len) {
1332 case IPX_NETWORK_NUMBER:
1333 if (olen == CILEN_NETN) {
1336 printer (arg, "network %s", ipx_ntoa (cilong));
1339 case IPX_NODE_NUMBER:
1340 if (olen == CILEN_NODEN) {
1342 printer (arg, "node ");
1343 while (p < optend) {
1345 printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1349 case IPX_COMPRESSION_PROTOCOL:
1350 if (olen == CILEN_COMPRESS) {
1352 GETSHORT (cishort, p);
1353 printer (arg, "compression %d", (int) cishort);
1356 case IPX_ROUTER_PROTOCOL:
1357 if (olen == CILEN_PROTOCOL) {
1359 GETSHORT (cishort, p);
1360 printer (arg, "router proto %d", (int) cishort);
1363 case IPX_ROUTER_NAME:
1364 if (olen >= CILEN_NAME) {
1366 printer (arg, "router name \"");
1367 while (p < optend) {
1369 if (code >= 0x20 && code <= 0x7E)
1370 printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1372 printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1374 printer (arg, "\"");
1378 if (olen == CILEN_COMPLETE) {
1380 printer (arg, "complete");
1387 while (p < optend) {
1389 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1397 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1399 print_string(p, len, printer, arg);
1406 /* print the rest of the bytes in the packet */
1407 for (; len > 0; --len) {
1409 printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1414 #endif /* ifdef IPX_CHANGE */