1e98d5a30Schristos /* NetBSD */
2f4a68078Schristos
3f447be7aSchristos /*
4f447be7aSchristos * ipxcp.c - PPP IPX Control Protocol.
5f447be7aSchristos *
6f447be7aSchristos * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
7f447be7aSchristos *
8f447be7aSchristos * Redistribution and use in source and binary forms, with or without
9f447be7aSchristos * modification, are permitted provided that the following conditions
10f447be7aSchristos * are met:
11f447be7aSchristos *
12f447be7aSchristos * 1. Redistributions of source code must retain the above copyright
13f447be7aSchristos * notice, this list of conditions and the following disclaimer.
14f447be7aSchristos *
15f447be7aSchristos * 2. Redistributions in binary form must reproduce the above copyright
16f447be7aSchristos * notice, this list of conditions and the following disclaimer in
17f447be7aSchristos * the documentation and/or other materials provided with the
18f447be7aSchristos * distribution.
19f447be7aSchristos *
20f447be7aSchristos * 3. The name "Carnegie Mellon University" must not be used to
21f447be7aSchristos * endorse or promote products derived from this software without
22f447be7aSchristos * prior written permission. For permission or any legal
23f447be7aSchristos * details, please contact
24f447be7aSchristos * Office of Technology Transfer
25f447be7aSchristos * Carnegie Mellon University
26f447be7aSchristos * 5000 Forbes Avenue
27f447be7aSchristos * Pittsburgh, PA 15213-3890
28f447be7aSchristos * (412) 268-4387, fax: (412) 268-7395
29f447be7aSchristos * tech-transfer@andrew.cmu.edu
30f447be7aSchristos *
31f447be7aSchristos * 4. Redistributions of any form whatsoever must retain the following
32f447be7aSchristos * acknowledgment:
33f447be7aSchristos * "This product includes software developed by Computing Services
34f447be7aSchristos * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
35f447be7aSchristos *
36f447be7aSchristos * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
37f447be7aSchristos * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38f447be7aSchristos * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
39f447be7aSchristos * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40f447be7aSchristos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
41f447be7aSchristos * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
42f447be7aSchristos * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43f447be7aSchristos */
44f447be7aSchristos
45f4a68078Schristos #include <sys/cdefs.h>
46f4a68078Schristos #if 0
47f4a68078Schristos #define RCSID "Id: ipxcp.c,v 1.24 2005/08/25 23:59:34 paulus Exp "
48f4a68078Schristos static const char rcsid[] = RCSID;
49f4a68078Schristos #else
50*3dce80e5Schristos __RCSID("$NetBSD: ipxcp.c,v 1.5 2021/01/09 16:39:28 christos Exp $");
51f4a68078Schristos #endif
52f447be7aSchristos #ifdef IPX_CHANGE
53f447be7aSchristos
54f447be7aSchristos /*
55f447be7aSchristos * TODO:
56f447be7aSchristos */
57f447be7aSchristos
58f447be7aSchristos #include <stdio.h>
59f447be7aSchristos #include <string.h>
60f447be7aSchristos #include <unistd.h>
61f447be7aSchristos #include <ctype.h>
62f447be7aSchristos #include <sys/types.h>
63f447be7aSchristos #include <sys/socket.h>
64f447be7aSchristos #include <netinet/in.h>
65f447be7aSchristos
66f447be7aSchristos #include "pppd.h"
67f447be7aSchristos #include "fsm.h"
68f447be7aSchristos #include "ipxcp.h"
69f447be7aSchristos #include "pathnames.h"
70f447be7aSchristos #include "magic.h"
71f447be7aSchristos
72f447be7aSchristos
73f447be7aSchristos /* global vars */
74f447be7aSchristos ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */
75f447be7aSchristos ipxcp_options ipxcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
76f447be7aSchristos ipxcp_options ipxcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
77f447be7aSchristos ipxcp_options ipxcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
78f447be7aSchristos
79f447be7aSchristos #define wo (&ipxcp_wantoptions[0])
80f447be7aSchristos #define ao (&ipxcp_allowoptions[0])
81f447be7aSchristos #define go (&ipxcp_gotoptions[0])
82f447be7aSchristos #define ho (&ipxcp_hisoptions[0])
83f447be7aSchristos
84f447be7aSchristos /*
85f447be7aSchristos * Callbacks for fsm code. (CI = Configuration Information)
86f447be7aSchristos */
87*3dce80e5Schristos static void ipxcp_resetci (fsm *); /* Reset our CI */
88*3dce80e5Schristos static int ipxcp_cilen (fsm *); /* Return length of our CI */
89*3dce80e5Schristos static void ipxcp_addci (fsm *, u_char *, int *); /* Add our CI */
90*3dce80e5Schristos static int ipxcp_ackci (fsm *, u_char *, int); /* Peer ack'd our CI */
91*3dce80e5Schristos static int ipxcp_nakci (fsm *, u_char *, int, int);/* Peer nak'd our CI */
92*3dce80e5Schristos static int ipxcp_rejci (fsm *, u_char *, int); /* Peer rej'd our CI */
93*3dce80e5Schristos static int ipxcp_reqci (fsm *, u_char *, int *, int); /* Rcv CI */
94*3dce80e5Schristos static void ipxcp_up (fsm *); /* We're UP */
95*3dce80e5Schristos static void ipxcp_down (fsm *); /* We're DOWN */
96*3dce80e5Schristos static void ipxcp_finished (fsm *); /* Don't need lower layer */
97*3dce80e5Schristos static void ipxcp_script (fsm *, char *); /* Run an up/down script */
98f447be7aSchristos
99f447be7aSchristos fsm ipxcp_fsm[NUM_PPP]; /* IPXCP fsm structure */
100f447be7aSchristos
101f447be7aSchristos static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */
102f447be7aSchristos ipxcp_resetci, /* Reset our Configuration Information */
103f447be7aSchristos ipxcp_cilen, /* Length of our Configuration Information */
104f447be7aSchristos ipxcp_addci, /* Add our Configuration Information */
105f447be7aSchristos ipxcp_ackci, /* ACK our Configuration Information */
106f447be7aSchristos ipxcp_nakci, /* NAK our Configuration Information */
107f447be7aSchristos ipxcp_rejci, /* Reject our Configuration Information */
108f447be7aSchristos ipxcp_reqci, /* Request peer's Configuration Information */
109f447be7aSchristos ipxcp_up, /* Called when fsm reaches OPENED state */
110f447be7aSchristos ipxcp_down, /* Called when fsm leaves OPENED state */
111f447be7aSchristos NULL, /* Called when we want the lower layer up */
112f447be7aSchristos ipxcp_finished, /* Called when we want the lower layer down */
113f447be7aSchristos NULL, /* Called when Protocol-Reject received */
114f447be7aSchristos NULL, /* Retransmission is necessary */
115f447be7aSchristos NULL, /* Called to handle protocol-specific codes */
116f447be7aSchristos "IPXCP" /* String name of protocol */
117f447be7aSchristos };
118f447be7aSchristos
119f447be7aSchristos /*
120f447be7aSchristos * Command-line options.
121f447be7aSchristos */
122*3dce80e5Schristos static int setipxnode (char **);
123*3dce80e5Schristos static void printipxnode (option_t *,
124*3dce80e5Schristos void (*)(void *, char *, ...), void *);
125*3dce80e5Schristos static int setipxname (char **);
126f447be7aSchristos
127f447be7aSchristos static option_t ipxcp_option_list[] = {
128f447be7aSchristos { "ipx", o_bool, &ipxcp_protent.enabled_flag,
129f447be7aSchristos "Enable IPXCP (and IPX)", OPT_PRIO | 1 },
130f447be7aSchristos { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
131f447be7aSchristos "Enable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS | 1 },
132f447be7aSchristos { "noipx", o_bool, &ipxcp_protent.enabled_flag,
133f447be7aSchristos "Disable IPXCP (and IPX)", OPT_PRIOSUB },
134f447be7aSchristos { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
135f447be7aSchristos "Disable IPXCP (and IPX)", OPT_PRIOSUB | OPT_ALIAS },
136f447be7aSchristos
137f447be7aSchristos { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
138f447be7aSchristos "Set our IPX network number", OPT_PRIO, &ipxcp_wantoptions[0].neg_nn },
139f447be7aSchristos
140f447be7aSchristos { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
141f447be7aSchristos "Accept peer IPX network number", 1,
142f447be7aSchristos &ipxcp_allowoptions[0].accept_network },
143f447be7aSchristos
144f447be7aSchristos { "ipx-node", o_special, (void *)setipxnode,
145f447be7aSchristos "Set IPX node number", OPT_A2PRINTER, (void *)printipxnode },
146f447be7aSchristos
147f447be7aSchristos { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
148f447be7aSchristos "Accept our IPX address", 1,
149f447be7aSchristos &ipxcp_allowoptions[0].accept_local },
150f447be7aSchristos
151f447be7aSchristos { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
152f447be7aSchristos "Accept peer's IPX address", 1,
153f447be7aSchristos &ipxcp_allowoptions[0].accept_remote },
154f447be7aSchristos
155f447be7aSchristos { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
156f447be7aSchristos "Set IPX routing proto number", OPT_PRIO,
157f447be7aSchristos &ipxcp_wantoptions[0].neg_router },
158f447be7aSchristos
159f447be7aSchristos { "ipx-router-name", o_special, setipxname,
160f447be7aSchristos "Set IPX router name", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC,
161f447be7aSchristos &ipxcp_wantoptions[0].name },
162f447be7aSchristos
163f447be7aSchristos { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
164f447be7aSchristos "Set timeout for IPXCP", OPT_PRIO },
165f447be7aSchristos { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
166f447be7aSchristos "Set max #xmits for IPXCP term-reqs", OPT_PRIO },
167f447be7aSchristos { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
168f447be7aSchristos "Set max #xmits for IPXCP conf-reqs", OPT_PRIO },
169f447be7aSchristos { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
170f447be7aSchristos "Set max #conf-naks for IPXCP", OPT_PRIO },
171f447be7aSchristos
172f447be7aSchristos { NULL }
173f447be7aSchristos };
174f447be7aSchristos
175f447be7aSchristos /*
176f447be7aSchristos * Protocol entry points.
177f447be7aSchristos */
178f447be7aSchristos
179*3dce80e5Schristos static void ipxcp_init (int);
180*3dce80e5Schristos static void ipxcp_open (int);
181*3dce80e5Schristos static void ipxcp_close (int, char *);
182*3dce80e5Schristos static void ipxcp_lowerup (int);
183*3dce80e5Schristos static void ipxcp_lowerdown (int);
184*3dce80e5Schristos static void ipxcp_input (int, u_char *, int);
185*3dce80e5Schristos static void ipxcp_protrej (int);
186*3dce80e5Schristos static int ipxcp_printpkt (u_char *, int,
187*3dce80e5Schristos void (*) (void *, char *, ...), void *);
188f447be7aSchristos
189f447be7aSchristos struct protent ipxcp_protent = {
190f447be7aSchristos PPP_IPXCP,
191f447be7aSchristos ipxcp_init,
192f447be7aSchristos ipxcp_input,
193f447be7aSchristos ipxcp_protrej,
194f447be7aSchristos ipxcp_lowerup,
195f447be7aSchristos ipxcp_lowerdown,
196f447be7aSchristos ipxcp_open,
197f447be7aSchristos ipxcp_close,
198f447be7aSchristos ipxcp_printpkt,
199f447be7aSchristos NULL,
200f447be7aSchristos 0,
201f447be7aSchristos "IPXCP",
202f447be7aSchristos "IPX",
203f447be7aSchristos ipxcp_option_list,
204f447be7aSchristos NULL,
205f447be7aSchristos NULL,
206f447be7aSchristos NULL
207f447be7aSchristos };
208f447be7aSchristos
209f447be7aSchristos /*
210f447be7aSchristos * Lengths of configuration options.
211f447be7aSchristos */
212f447be7aSchristos
213f447be7aSchristos #define CILEN_VOID 2
214f447be7aSchristos #define CILEN_COMPLETE 2 /* length of complete option */
215f447be7aSchristos #define CILEN_NETN 6 /* network number length option */
216f447be7aSchristos #define CILEN_NODEN 8 /* node number length option */
217f447be7aSchristos #define CILEN_PROTOCOL 4 /* Minimum length of routing protocol */
218f447be7aSchristos #define CILEN_NAME 3 /* Minimum length of router name */
219f447be7aSchristos #define CILEN_COMPRESS 4 /* Minimum length of compression protocol */
220f447be7aSchristos
221f447be7aSchristos #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
222f447be7aSchristos (x) == CONFNAK ? "NAK" : "REJ")
223f447be7aSchristos
224f447be7aSchristos static int ipxcp_is_up;
225f447be7aSchristos
226*3dce80e5Schristos static char *ipx_ntoa (u_int32_t);
227f447be7aSchristos
228f447be7aSchristos /* Used in printing the node number */
229f447be7aSchristos #define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
230f447be7aSchristos
231f447be7aSchristos /* Used to generate the proper bit mask */
232f447be7aSchristos #define BIT(num) (1 << (num))
233f447be7aSchristos
234f447be7aSchristos /*
235f447be7aSchristos * Convert from internal to external notation
236f447be7aSchristos */
237f447be7aSchristos
238f447be7aSchristos static short int
to_external(short int internal)239*3dce80e5Schristos to_external(short int internal)
240f447be7aSchristos {
241f447be7aSchristos short int external;
242f447be7aSchristos
243f447be7aSchristos if (internal & BIT(IPX_NONE) )
244f447be7aSchristos external = IPX_NONE;
245f447be7aSchristos else
246f447be7aSchristos external = RIP_SAP;
247f447be7aSchristos
248f447be7aSchristos return external;
249f447be7aSchristos }
250f447be7aSchristos
251f447be7aSchristos /*
252f447be7aSchristos * Make a string representation of a network IP address.
253f447be7aSchristos */
254f447be7aSchristos
255f447be7aSchristos static char *
ipx_ntoa(u_int32_t ipxaddr)256*3dce80e5Schristos ipx_ntoa(u_int32_t ipxaddr)
257f447be7aSchristos {
258f447be7aSchristos static char b[64];
259f447be7aSchristos slprintf(b, sizeof(b), "%x", ipxaddr);
260f447be7aSchristos return b;
261f447be7aSchristos }
262f447be7aSchristos
263f447be7aSchristos
264f447be7aSchristos static u_char *
setipxnodevalue(u_char * src,u_char * dst)265*3dce80e5Schristos setipxnodevalue(u_char *src, u_char *dst)
266f447be7aSchristos {
267f447be7aSchristos int indx;
268f447be7aSchristos int item;
269f447be7aSchristos
270f447be7aSchristos for (;;) {
271f447be7aSchristos if (!isxdigit (*src))
272f447be7aSchristos break;
273f447be7aSchristos
274f447be7aSchristos for (indx = 0; indx < 5; ++indx) {
275f447be7aSchristos dst[indx] <<= 4;
276f447be7aSchristos dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
277f447be7aSchristos }
278f447be7aSchristos
279f447be7aSchristos item = toupper (*src) - '0';
280f447be7aSchristos if (item > 9)
281f447be7aSchristos item -= 7;
282f447be7aSchristos
283f447be7aSchristos dst[5] = (dst[5] << 4) | item;
284f447be7aSchristos ++src;
285f447be7aSchristos }
286f447be7aSchristos return src;
287f447be7aSchristos }
288f447be7aSchristos
289f447be7aSchristos static int ipx_prio_our, ipx_prio_his;
290f447be7aSchristos
291f447be7aSchristos static int
setipxnode(char ** argv)292*3dce80e5Schristos setipxnode(char **argv)
293f447be7aSchristos {
294f447be7aSchristos u_char *end;
295f447be7aSchristos int have_his = 0;
296f447be7aSchristos u_char our_node[6];
297f447be7aSchristos u_char his_node[6];
298f447be7aSchristos
299f447be7aSchristos memset (our_node, 0, 6);
300f447be7aSchristos memset (his_node, 0, 6);
301f447be7aSchristos
302*3dce80e5Schristos end = setipxnodevalue ((u_char *)*argv, our_node);
303f447be7aSchristos if (*end == ':') {
304f447be7aSchristos have_his = 1;
305f447be7aSchristos end = setipxnodevalue (++end, his_node);
306f447be7aSchristos }
307f447be7aSchristos
308f447be7aSchristos if (*end == '\0') {
309f447be7aSchristos ipxcp_wantoptions[0].neg_node = 1;
310f447be7aSchristos if (option_priority >= ipx_prio_our) {
311f447be7aSchristos memcpy(&ipxcp_wantoptions[0].our_node[0], our_node, 6);
312f447be7aSchristos ipx_prio_our = option_priority;
313f447be7aSchristos }
314f447be7aSchristos if (have_his && option_priority >= ipx_prio_his) {
315f447be7aSchristos memcpy(&ipxcp_wantoptions[0].his_node[0], his_node, 6);
316f447be7aSchristos ipx_prio_his = option_priority;
317f447be7aSchristos }
318f447be7aSchristos return 1;
319f447be7aSchristos }
320f447be7aSchristos
321f447be7aSchristos option_error("invalid parameter '%s' for ipx-node option", *argv);
322f447be7aSchristos return 0;
323f447be7aSchristos }
324f447be7aSchristos
325f447be7aSchristos static void
printipxnode(option_t * opt,void (* printer)(void *,char *,...),void * arg)326*3dce80e5Schristos printipxnode(option_t *opt, void (*printer) (void *, char *, ...), void *arg)
327f447be7aSchristos {
328f447be7aSchristos unsigned char *p;
329f447be7aSchristos
330f447be7aSchristos p = ipxcp_wantoptions[0].our_node;
331f447be7aSchristos if (ipx_prio_our)
332f447be7aSchristos printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
333f447be7aSchristos p[0], p[1], p[2], p[3], p[4], p[5]);
334f447be7aSchristos printer(arg, ":");
335f447be7aSchristos p = ipxcp_wantoptions[0].his_node;
336f447be7aSchristos if (ipx_prio_his)
337f447be7aSchristos printer(arg, "%.2x%.2x%.2x%.2x%.2x%.2x",
338f447be7aSchristos p[0], p[1], p[2], p[3], p[4], p[5]);
339f447be7aSchristos }
340f447be7aSchristos
341f447be7aSchristos static int
setipxname(char ** argv)342*3dce80e5Schristos setipxname (char **argv)
343f447be7aSchristos {
344f447be7aSchristos u_char *dest = ipxcp_wantoptions[0].name;
345f447be7aSchristos char *src = *argv;
346f447be7aSchristos int count;
347f447be7aSchristos char ch;
348f447be7aSchristos
349f447be7aSchristos ipxcp_wantoptions[0].neg_name = 1;
350f447be7aSchristos ipxcp_allowoptions[0].neg_name = 1;
351f447be7aSchristos memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
352f447be7aSchristos
353f447be7aSchristos count = 0;
354f447be7aSchristos while (*src) {
355f447be7aSchristos ch = *src++;
356f447be7aSchristos if (! isalnum (ch) && ch != '_') {
357f447be7aSchristos option_error("IPX router name must be alphanumeric or _");
358f447be7aSchristos return 0;
359f447be7aSchristos }
360f447be7aSchristos
361f447be7aSchristos if (count >= sizeof (ipxcp_wantoptions[0].name) - 1) {
362f447be7aSchristos option_error("IPX router name is limited to %d characters",
363f447be7aSchristos sizeof (ipxcp_wantoptions[0].name) - 1);
364f447be7aSchristos return 0;
365f447be7aSchristos }
366f447be7aSchristos
367f447be7aSchristos dest[count++] = toupper (ch);
368f447be7aSchristos }
369f447be7aSchristos dest[count] = 0;
370f447be7aSchristos
371f447be7aSchristos return 1;
372f447be7aSchristos }
373f447be7aSchristos
374f447be7aSchristos /*
375f447be7aSchristos * ipxcp_init - Initialize IPXCP.
376f447be7aSchristos */
377f447be7aSchristos static void
ipxcp_init(int unit)378*3dce80e5Schristos ipxcp_init(int unit)
379f447be7aSchristos {
380f447be7aSchristos fsm *f = &ipxcp_fsm[unit];
381f447be7aSchristos
382f447be7aSchristos f->unit = unit;
383f447be7aSchristos f->protocol = PPP_IPXCP;
384f447be7aSchristos f->callbacks = &ipxcp_callbacks;
385f447be7aSchristos fsm_init(&ipxcp_fsm[unit]);
386f447be7aSchristos
387f447be7aSchristos memset (wo->name, 0, sizeof (wo->name));
388f447be7aSchristos memset (wo->our_node, 0, sizeof (wo->our_node));
389f447be7aSchristos memset (wo->his_node, 0, sizeof (wo->his_node));
390f447be7aSchristos
391f447be7aSchristos wo->neg_nn = 1;
392f447be7aSchristos wo->neg_complete = 1;
393f447be7aSchristos wo->network = 0;
394f447be7aSchristos
395f447be7aSchristos ao->neg_node = 1;
396f447be7aSchristos ao->neg_nn = 1;
397f447be7aSchristos ao->neg_name = 1;
398f447be7aSchristos ao->neg_complete = 1;
399f447be7aSchristos ao->neg_router = 1;
400f447be7aSchristos
401f447be7aSchristos ao->accept_local = 0;
402f447be7aSchristos ao->accept_remote = 0;
403f447be7aSchristos ao->accept_network = 0;
404f447be7aSchristos
405f447be7aSchristos wo->tried_rip = 0;
406f447be7aSchristos wo->tried_nlsp = 0;
407f447be7aSchristos }
408f447be7aSchristos
409f447be7aSchristos /*
410f447be7aSchristos * Copy the node number
411f447be7aSchristos */
412f447be7aSchristos
413f447be7aSchristos static void
copy_node(u_char * src,u_char * dst)414*3dce80e5Schristos copy_node (u_char *src, u_char *dst)
415f447be7aSchristos {
416f447be7aSchristos memcpy (dst, src, sizeof (ipxcp_wantoptions[0].our_node));
417f447be7aSchristos }
418f447be7aSchristos
419f447be7aSchristos /*
420f447be7aSchristos * Compare node numbers
421f447be7aSchristos */
422f447be7aSchristos
423f447be7aSchristos static int
compare_node(u_char * src,u_char * dst)424*3dce80e5Schristos compare_node (u_char *src, u_char *dst)
425f447be7aSchristos {
426f447be7aSchristos return memcmp (dst, src, sizeof (ipxcp_wantoptions[0].our_node)) == 0;
427f447be7aSchristos }
428f447be7aSchristos
429f447be7aSchristos /*
430f447be7aSchristos * Is the node number zero?
431f447be7aSchristos */
432f447be7aSchristos
433f447be7aSchristos static int
zero_node(u_char * node)434*3dce80e5Schristos zero_node (u_char *node)
435f447be7aSchristos {
436f447be7aSchristos int indx;
437f447be7aSchristos for (indx = 0; indx < sizeof (ipxcp_wantoptions[0].our_node); ++indx)
438f447be7aSchristos if (node [indx] != 0)
439f447be7aSchristos return 0;
440f447be7aSchristos return 1;
441f447be7aSchristos }
442f447be7aSchristos
443f447be7aSchristos /*
444f447be7aSchristos * Increment the node number
445f447be7aSchristos */
446f447be7aSchristos
447f447be7aSchristos static void
inc_node(u_char * node)448*3dce80e5Schristos inc_node (u_char *node)
449f447be7aSchristos {
450f447be7aSchristos u_char *outp;
451f447be7aSchristos u_int32_t magic_num;
452f447be7aSchristos
453f447be7aSchristos outp = node;
454f447be7aSchristos magic_num = magic();
455f447be7aSchristos *outp++ = '\0';
456f447be7aSchristos *outp++ = '\0';
457f447be7aSchristos PUTLONG (magic_num, outp);
458f447be7aSchristos }
459f447be7aSchristos
460f447be7aSchristos /*
461f447be7aSchristos * ipxcp_open - IPXCP is allowed to come up.
462f447be7aSchristos */
463f447be7aSchristos static void
ipxcp_open(int unit)464*3dce80e5Schristos ipxcp_open(int unit)
465f447be7aSchristos {
466f447be7aSchristos fsm_open(&ipxcp_fsm[unit]);
467f447be7aSchristos }
468f447be7aSchristos
469f447be7aSchristos /*
470f447be7aSchristos * ipxcp_close - Take IPXCP down.
471f447be7aSchristos */
472f447be7aSchristos static void
ipxcp_close(int unit,char * reason)473*3dce80e5Schristos ipxcp_close(int unit, char *reason)
474f447be7aSchristos {
475f447be7aSchristos fsm_close(&ipxcp_fsm[unit], reason);
476f447be7aSchristos }
477f447be7aSchristos
478f447be7aSchristos
479f447be7aSchristos /*
480f447be7aSchristos * ipxcp_lowerup - The lower layer is up.
481f447be7aSchristos */
482f447be7aSchristos static void
ipxcp_lowerup(int unit)483*3dce80e5Schristos ipxcp_lowerup(int unit)
484f447be7aSchristos {
485f447be7aSchristos fsm_lowerup(&ipxcp_fsm[unit]);
486f447be7aSchristos }
487f447be7aSchristos
488f447be7aSchristos
489f447be7aSchristos /*
490f447be7aSchristos * ipxcp_lowerdown - The lower layer is down.
491f447be7aSchristos */
492f447be7aSchristos static void
ipxcp_lowerdown(int unit)493*3dce80e5Schristos ipxcp_lowerdown(int unit)
494f447be7aSchristos {
495f447be7aSchristos fsm_lowerdown(&ipxcp_fsm[unit]);
496f447be7aSchristos }
497f447be7aSchristos
498f447be7aSchristos
499f447be7aSchristos /*
500f447be7aSchristos * ipxcp_input - Input IPXCP packet.
501f447be7aSchristos */
502f447be7aSchristos static void
ipxcp_input(int unit,u_char * p,int len)503*3dce80e5Schristos ipxcp_input(int unit, u_char *p, int len)
504f447be7aSchristos {
505f447be7aSchristos fsm_input(&ipxcp_fsm[unit], p, len);
506f447be7aSchristos }
507f447be7aSchristos
508f447be7aSchristos
509f447be7aSchristos /*
510f447be7aSchristos * ipxcp_protrej - A Protocol-Reject was received for IPXCP.
511f447be7aSchristos *
512f447be7aSchristos * Pretend the lower layer went down, so we shut up.
513f447be7aSchristos */
514f447be7aSchristos static void
ipxcp_protrej(int unit)515*3dce80e5Schristos ipxcp_protrej(int unit)
516f447be7aSchristos {
517f447be7aSchristos fsm_lowerdown(&ipxcp_fsm[unit]);
518f447be7aSchristos }
519f447be7aSchristos
520f447be7aSchristos
521f447be7aSchristos /*
522f447be7aSchristos * ipxcp_resetci - Reset our CI.
523f447be7aSchristos */
524f447be7aSchristos static void
ipxcp_resetci(fsm * f)525*3dce80e5Schristos ipxcp_resetci(fsm *f)
526f447be7aSchristos {
527f447be7aSchristos wo->req_node = wo->neg_node && ao->neg_node;
528f447be7aSchristos wo->req_nn = wo->neg_nn && ao->neg_nn;
529f447be7aSchristos
530f447be7aSchristos if (wo->our_network == 0) {
531f447be7aSchristos wo->neg_node = 1;
532f447be7aSchristos ao->accept_network = 1;
533f447be7aSchristos }
534f447be7aSchristos /*
535f447be7aSchristos * If our node number is zero then change it.
536f447be7aSchristos */
537f447be7aSchristos if (zero_node (wo->our_node)) {
538f447be7aSchristos inc_node (wo->our_node);
539f447be7aSchristos ao->accept_local = 1;
540f447be7aSchristos wo->neg_node = 1;
541f447be7aSchristos }
542f447be7aSchristos /*
543f447be7aSchristos * If his node number is zero then change it.
544f447be7aSchristos */
545f447be7aSchristos if (zero_node (wo->his_node)) {
546f447be7aSchristos inc_node (wo->his_node);
547f447be7aSchristos ao->accept_remote = 1;
548f447be7aSchristos }
549f447be7aSchristos /*
550f447be7aSchristos * If no routing agent was specified then we do RIP/SAP according to the
551f447be7aSchristos * RFC documents. If you have specified something then OK. Otherwise, we
552f447be7aSchristos * do RIP/SAP.
553f447be7aSchristos */
554f447be7aSchristos if (ao->router == 0) {
555f447be7aSchristos ao->router |= BIT(RIP_SAP);
556f447be7aSchristos wo->router |= BIT(RIP_SAP);
557f447be7aSchristos }
558f447be7aSchristos
559f447be7aSchristos /* Always specify a routing protocol unless it was REJected. */
560f447be7aSchristos wo->neg_router = 1;
561f447be7aSchristos /*
562f447be7aSchristos * Start with these default values
563f447be7aSchristos */
564f447be7aSchristos *go = *wo;
565f447be7aSchristos }
566f447be7aSchristos
567f447be7aSchristos /*
568f447be7aSchristos * ipxcp_cilen - Return length of our CI.
569f447be7aSchristos */
570f447be7aSchristos
571f447be7aSchristos static int
ipxcp_cilen(fsm * f)572*3dce80e5Schristos ipxcp_cilen(fsm *f)
573f447be7aSchristos {
574f447be7aSchristos int len;
575f447be7aSchristos
576f447be7aSchristos len = go->neg_nn ? CILEN_NETN : 0;
577f447be7aSchristos len += go->neg_node ? CILEN_NODEN : 0;
578f447be7aSchristos len += go->neg_name ? CILEN_NAME + strlen ((char *)go->name) - 1 : 0;
579f447be7aSchristos
580f447be7aSchristos /* RFC says that defaults should not be included. */
581f447be7aSchristos if (go->neg_router && to_external(go->router) != RIP_SAP)
582f447be7aSchristos len += CILEN_PROTOCOL;
583f447be7aSchristos
584f447be7aSchristos return (len);
585f447be7aSchristos }
586f447be7aSchristos
587f447be7aSchristos
588f447be7aSchristos /*
589f447be7aSchristos * ipxcp_addci - Add our desired CIs to a packet.
590f447be7aSchristos */
591f447be7aSchristos static void
ipxcp_addci(fsm * f,u_char * ucp,int * lenp)592*3dce80e5Schristos ipxcp_addci(fsm *f, u_char *ucp, int *lenp)
593f447be7aSchristos {
594f447be7aSchristos /*
595f447be7aSchristos * Add the options to the record.
596f447be7aSchristos */
597f447be7aSchristos if (go->neg_nn) {
598f447be7aSchristos PUTCHAR (IPX_NETWORK_NUMBER, ucp);
599f447be7aSchristos PUTCHAR (CILEN_NETN, ucp);
600f447be7aSchristos PUTLONG (go->our_network, ucp);
601f447be7aSchristos }
602f447be7aSchristos
603f447be7aSchristos if (go->neg_node) {
604f447be7aSchristos int indx;
605f447be7aSchristos PUTCHAR (IPX_NODE_NUMBER, ucp);
606f447be7aSchristos PUTCHAR (CILEN_NODEN, ucp);
607f447be7aSchristos for (indx = 0; indx < sizeof (go->our_node); ++indx)
608f447be7aSchristos PUTCHAR (go->our_node[indx], ucp);
609f447be7aSchristos }
610f447be7aSchristos
611f447be7aSchristos if (go->neg_name) {
612f447be7aSchristos int cilen = strlen ((char *)go->name);
613f447be7aSchristos int indx;
614f447be7aSchristos PUTCHAR (IPX_ROUTER_NAME, ucp);
615f447be7aSchristos PUTCHAR (CILEN_NAME + cilen - 1, ucp);
616f447be7aSchristos for (indx = 0; indx < cilen; ++indx)
617f447be7aSchristos PUTCHAR (go->name [indx], ucp);
618f447be7aSchristos }
619f447be7aSchristos
620f447be7aSchristos if (go->neg_router) {
621f447be7aSchristos short external = to_external (go->router);
622f447be7aSchristos if (external != RIP_SAP) {
623f447be7aSchristos PUTCHAR (IPX_ROUTER_PROTOCOL, ucp);
624f447be7aSchristos PUTCHAR (CILEN_PROTOCOL, ucp);
625f447be7aSchristos PUTSHORT (external, ucp);
626f447be7aSchristos }
627f447be7aSchristos }
628f447be7aSchristos }
629f447be7aSchristos
630f447be7aSchristos /*
631f447be7aSchristos * ipxcp_ackci - Ack our CIs.
632f447be7aSchristos *
633f447be7aSchristos * Returns:
634f447be7aSchristos * 0 - Ack was bad.
635f447be7aSchristos * 1 - Ack was good.
636f447be7aSchristos */
637f447be7aSchristos static int
ipxcp_ackci(fsm * f,u_char * p,int len)638*3dce80e5Schristos ipxcp_ackci(fsm *f, u_char *p, int len)
639f447be7aSchristos {
640f447be7aSchristos u_short cilen, citype, cishort;
641f447be7aSchristos u_char cichar;
642f447be7aSchristos u_int32_t cilong;
643f447be7aSchristos
644f447be7aSchristos #define ACKCIVOID(opt, neg) \
645f447be7aSchristos if (neg) { \
646f447be7aSchristos if ((len -= CILEN_VOID) < 0) \
647f447be7aSchristos break; \
648f447be7aSchristos GETCHAR(citype, p); \
649f447be7aSchristos GETCHAR(cilen, p); \
650f447be7aSchristos if (cilen != CILEN_VOID || \
651f447be7aSchristos citype != opt) \
652f447be7aSchristos break; \
653f447be7aSchristos }
654f447be7aSchristos
655f447be7aSchristos #define ACKCICOMPLETE(opt,neg) ACKCIVOID(opt, neg)
656f447be7aSchristos
657f447be7aSchristos #define ACKCICHARS(opt, neg, val, cnt) \
658f447be7aSchristos if (neg) { \
659f447be7aSchristos int indx, count = cnt; \
660f447be7aSchristos len -= (count + 2); \
661f447be7aSchristos if (len < 0) \
662f447be7aSchristos break; \
663f447be7aSchristos GETCHAR(citype, p); \
664f447be7aSchristos GETCHAR(cilen, p); \
665f447be7aSchristos if (cilen != (count + 2) || \
666f447be7aSchristos citype != opt) \
667f447be7aSchristos break; \
668f447be7aSchristos for (indx = 0; indx < count; ++indx) {\
669f447be7aSchristos GETCHAR(cichar, p); \
670f447be7aSchristos if (cichar != ((u_char *) &val)[indx]) \
671f447be7aSchristos break; \
672f447be7aSchristos }\
673f447be7aSchristos if (indx != count) \
674f447be7aSchristos break; \
675f447be7aSchristos }
676f447be7aSchristos
677f447be7aSchristos #define ACKCINODE(opt,neg,val) ACKCICHARS(opt,neg,val,sizeof(val))
678f447be7aSchristos #define ACKCINAME(opt,neg,val) ACKCICHARS(opt,neg,val,strlen((char *)val))
679f447be7aSchristos
680f447be7aSchristos #define ACKCINETWORK(opt, neg, val) \
681f447be7aSchristos if (neg) { \
682f447be7aSchristos if ((len -= CILEN_NETN) < 0) \
683f447be7aSchristos break; \
684f447be7aSchristos GETCHAR(citype, p); \
685f447be7aSchristos GETCHAR(cilen, p); \
686f447be7aSchristos if (cilen != CILEN_NETN || \
687f447be7aSchristos citype != opt) \
688f447be7aSchristos break; \
689f447be7aSchristos GETLONG(cilong, p); \
690f447be7aSchristos if (cilong != val) \
691f447be7aSchristos break; \
692f447be7aSchristos }
693f447be7aSchristos
694f447be7aSchristos #define ACKCIPROTO(opt, neg, val) \
695f447be7aSchristos if (neg) { \
696f447be7aSchristos if (len < 2) \
697f447be7aSchristos break; \
698f447be7aSchristos GETCHAR(citype, p); \
699f447be7aSchristos GETCHAR(cilen, p); \
700f447be7aSchristos if (cilen != CILEN_PROTOCOL || citype != opt) \
701f447be7aSchristos break; \
702f447be7aSchristos len -= cilen; \
703f447be7aSchristos if (len < 0) \
704f447be7aSchristos break; \
705f447be7aSchristos GETSHORT(cishort, p); \
706f447be7aSchristos if (cishort != to_external (val) || cishort == RIP_SAP) \
707f447be7aSchristos break; \
708f447be7aSchristos }
709f447be7aSchristos /*
710f447be7aSchristos * Process the ACK frame in the order in which the frame was assembled
711f447be7aSchristos */
712f447be7aSchristos do {
713f447be7aSchristos ACKCINETWORK (IPX_NETWORK_NUMBER, go->neg_nn, go->our_network);
714f447be7aSchristos ACKCINODE (IPX_NODE_NUMBER, go->neg_node, go->our_node);
715f447be7aSchristos ACKCINAME (IPX_ROUTER_NAME, go->neg_name, go->name);
716f447be7aSchristos if (len > 0)
717f447be7aSchristos ACKCIPROTO (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
718f447be7aSchristos /*
719f447be7aSchristos * This is the end of the record.
720f447be7aSchristos */
721f447be7aSchristos if (len == 0)
722f447be7aSchristos return (1);
723f447be7aSchristos } while (0);
724f447be7aSchristos /*
725f447be7aSchristos * The frame is invalid
726f447be7aSchristos */
727f447be7aSchristos IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
728f447be7aSchristos return (0);
729f447be7aSchristos }
730f447be7aSchristos
731f447be7aSchristos /*
732f447be7aSchristos * ipxcp_nakci - Peer has sent a NAK for some of our CIs.
733f447be7aSchristos * This should not modify any state if the Nak is bad
734f447be7aSchristos * or if IPXCP is in the OPENED state.
735f447be7aSchristos *
736f447be7aSchristos * Returns:
737f447be7aSchristos * 0 - Nak was bad.
738f447be7aSchristos * 1 - Nak was good.
739f447be7aSchristos */
740f447be7aSchristos
741f447be7aSchristos static int
ipxcp_nakci(fsm * f,u_char * p,int len,int treat_as_reject)742*3dce80e5Schristos ipxcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject)
743f447be7aSchristos {
744f447be7aSchristos u_char citype, cilen, *next;
745f447be7aSchristos u_short s;
746f447be7aSchristos u_int32_t l;
747f447be7aSchristos ipxcp_options no; /* options we've seen Naks for */
748f447be7aSchristos ipxcp_options try; /* options to request next time */
749f447be7aSchristos
750f447be7aSchristos BZERO(&no, sizeof(no));
751f447be7aSchristos try = *go;
752f447be7aSchristos
753f447be7aSchristos while (len >= CILEN_VOID) {
754f447be7aSchristos GETCHAR (citype, p);
755f447be7aSchristos GETCHAR (cilen, p);
756f447be7aSchristos len -= cilen;
757f447be7aSchristos if (cilen < CILEN_VOID || len < 0)
758f447be7aSchristos goto bad;
759f447be7aSchristos next = &p [cilen - CILEN_VOID];
760f447be7aSchristos
761f447be7aSchristos switch (citype) {
762f447be7aSchristos case IPX_NETWORK_NUMBER:
763f447be7aSchristos if (!go->neg_nn || no.neg_nn || (cilen != CILEN_NETN))
764f447be7aSchristos goto bad;
765f447be7aSchristos no.neg_nn = 1;
766f447be7aSchristos
767f447be7aSchristos GETLONG(l, p);
768f447be7aSchristos if (treat_as_reject)
769f447be7aSchristos try.neg_nn = 0;
770f447be7aSchristos else if (l && ao->accept_network)
771f447be7aSchristos try.our_network = l;
772f447be7aSchristos break;
773f447be7aSchristos
774f447be7aSchristos case IPX_NODE_NUMBER:
775f447be7aSchristos if (!go->neg_node || no.neg_node || (cilen != CILEN_NODEN))
776f447be7aSchristos goto bad;
777f447be7aSchristos no.neg_node = 1;
778f447be7aSchristos
779f447be7aSchristos if (treat_as_reject)
780f447be7aSchristos try.neg_node = 0;
781f447be7aSchristos else if (!zero_node (p) && ao->accept_local &&
782f447be7aSchristos ! compare_node (p, ho->his_node))
783f447be7aSchristos copy_node (p, try.our_node);
784f447be7aSchristos break;
785f447be7aSchristos
786f447be7aSchristos /* This has never been sent. Ignore the NAK frame */
787f447be7aSchristos case IPX_COMPRESSION_PROTOCOL:
788f447be7aSchristos goto bad;
789f447be7aSchristos
790f447be7aSchristos case IPX_ROUTER_PROTOCOL:
791f447be7aSchristos if (!go->neg_router || (cilen < CILEN_PROTOCOL))
792f447be7aSchristos goto bad;
793f447be7aSchristos
794f447be7aSchristos GETSHORT (s, p);
795f447be7aSchristos if (s > 15) /* This is just bad, but ignore for now. */
796f447be7aSchristos break;
797f447be7aSchristos
798f447be7aSchristos s = BIT(s);
799f447be7aSchristos if (no.router & s) /* duplicate NAKs are always bad */
800f447be7aSchristos goto bad;
801f447be7aSchristos
802f447be7aSchristos if (no.router == 0) /* Reset on first NAK only */
803f447be7aSchristos try.router = 0;
804f447be7aSchristos
805f447be7aSchristos no.router |= s;
806f447be7aSchristos try.router |= s;
807f447be7aSchristos try.neg_router = 1;
808f447be7aSchristos break;
809f447be7aSchristos
810f447be7aSchristos /* These, according to the RFC, must never be NAKed. */
811f447be7aSchristos case IPX_ROUTER_NAME:
812f447be7aSchristos case IPX_COMPLETE:
813f447be7aSchristos goto bad;
814f447be7aSchristos
815f447be7aSchristos /* These are for options which we have not seen. */
816f447be7aSchristos default:
817f447be7aSchristos break;
818f447be7aSchristos }
819f447be7aSchristos p = next;
820f447be7aSchristos }
821f447be7aSchristos
822f447be7aSchristos /*
823f447be7aSchristos * Do not permit the peer to force a router protocol which we do not
824f447be7aSchristos * support. However, default to the condition that will accept "NONE".
825f447be7aSchristos */
826f447be7aSchristos try.router &= (ao->router | BIT(IPX_NONE));
827f447be7aSchristos if (try.router == 0 && ao->router != 0)
828f447be7aSchristos try.router = BIT(IPX_NONE);
829f447be7aSchristos
830f447be7aSchristos if (try.router != 0)
831f447be7aSchristos try.neg_router = 1;
832f447be7aSchristos
833f447be7aSchristos /*
834f447be7aSchristos * OK, the Nak is good. Now we can update state.
835f447be7aSchristos * If there are any options left, we ignore them.
836f447be7aSchristos */
837f447be7aSchristos if (f->state != OPENED)
838f447be7aSchristos *go = try;
839f447be7aSchristos
840f447be7aSchristos return 1;
841f447be7aSchristos
842f447be7aSchristos bad:
843f447be7aSchristos IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
844f447be7aSchristos return 0;
845f447be7aSchristos }
846f447be7aSchristos
847f447be7aSchristos /*
848f447be7aSchristos * ipxcp_rejci - Reject some of our CIs.
849f447be7aSchristos */
850f447be7aSchristos static int
ipxcp_rejci(fsm * f,u_char * p,int len)851*3dce80e5Schristos ipxcp_rejci(fsm *f, u_char *p, int len)
852f447be7aSchristos {
853f447be7aSchristos u_short cilen, citype, cishort;
854f447be7aSchristos u_char cichar;
855f447be7aSchristos u_int32_t cilong;
856f447be7aSchristos ipxcp_options try; /* options to request next time */
857f447be7aSchristos
858f447be7aSchristos #define REJCINETWORK(opt, neg, val) \
859f447be7aSchristos if (neg && p[0] == opt) { \
860f447be7aSchristos if ((len -= CILEN_NETN) < 0) \
861f447be7aSchristos break; \
862f447be7aSchristos GETCHAR(citype, p); \
863f447be7aSchristos GETCHAR(cilen, p); \
864f447be7aSchristos if (cilen != CILEN_NETN || \
865f447be7aSchristos citype != opt) \
866f447be7aSchristos break; \
867f447be7aSchristos GETLONG(cilong, p); \
868f447be7aSchristos if (cilong != val) \
869f447be7aSchristos break; \
870f447be7aSchristos neg = 0; \
871f447be7aSchristos }
872f447be7aSchristos
873f447be7aSchristos #define REJCICHARS(opt, neg, val, cnt) \
874f447be7aSchristos if (neg && p[0] == opt) { \
875f447be7aSchristos int indx, count = cnt; \
876f447be7aSchristos len -= (count + 2); \
877f447be7aSchristos if (len < 0) \
878f447be7aSchristos break; \
879f447be7aSchristos GETCHAR(citype, p); \
880f447be7aSchristos GETCHAR(cilen, p); \
881f447be7aSchristos if (cilen != (count + 2) || \
882f447be7aSchristos citype != opt) \
883f447be7aSchristos break; \
884f447be7aSchristos for (indx = 0; indx < count; ++indx) {\
885f447be7aSchristos GETCHAR(cichar, p); \
886f447be7aSchristos if (cichar != ((u_char *) &val)[indx]) \
887f447be7aSchristos break; \
888f447be7aSchristos }\
889f447be7aSchristos if (indx != count) \
890f447be7aSchristos break; \
891f447be7aSchristos neg = 0; \
892f447be7aSchristos }
893f447be7aSchristos
894f447be7aSchristos #define REJCINODE(opt,neg,val) REJCICHARS(opt,neg,val,sizeof(val))
895f447be7aSchristos #define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen((char *)val))
896f447be7aSchristos
897f447be7aSchristos #define REJCIVOID(opt, neg) \
898f447be7aSchristos if (neg && p[0] == opt) { \
899f447be7aSchristos if ((len -= CILEN_VOID) < 0) \
900f447be7aSchristos break; \
901f447be7aSchristos GETCHAR(citype, p); \
902f447be7aSchristos GETCHAR(cilen, p); \
903f447be7aSchristos if (cilen != CILEN_VOID || citype != opt) \
904f447be7aSchristos break; \
905f447be7aSchristos neg = 0; \
906f447be7aSchristos }
907f447be7aSchristos
908f447be7aSchristos /* a reject for RIP/SAP is invalid since we don't send it and you can't
909f447be7aSchristos reject something which is not sent. (You can NAK, but you can't REJ.) */
910f447be7aSchristos #define REJCIPROTO(opt, neg, val, bit) \
911f447be7aSchristos if (neg && p[0] == opt) { \
912f447be7aSchristos if ((len -= CILEN_PROTOCOL) < 0) \
913f447be7aSchristos break; \
914f447be7aSchristos GETCHAR(citype, p); \
915f447be7aSchristos GETCHAR(cilen, p); \
916f447be7aSchristos if (cilen != CILEN_PROTOCOL) \
917f447be7aSchristos break; \
918f447be7aSchristos GETSHORT(cishort, p); \
919f447be7aSchristos if (cishort != to_external (val) || cishort == RIP_SAP) \
920f447be7aSchristos break; \
921f447be7aSchristos neg = 0; \
922f447be7aSchristos }
923f447be7aSchristos /*
924f447be7aSchristos * Any Rejected CIs must be in exactly the same order that we sent.
925f447be7aSchristos * Check packet length and CI length at each step.
926f447be7aSchristos * If we find any deviations, then this packet is bad.
927f447be7aSchristos */
928f447be7aSchristos try = *go;
929f447be7aSchristos
930f447be7aSchristos do {
931f447be7aSchristos REJCINETWORK (IPX_NETWORK_NUMBER, try.neg_nn, try.our_network);
932f447be7aSchristos REJCINODE (IPX_NODE_NUMBER, try.neg_node, try.our_node);
933f447be7aSchristos REJCINAME (IPX_ROUTER_NAME, try.neg_name, try.name);
934f447be7aSchristos REJCIPROTO (IPX_ROUTER_PROTOCOL, try.neg_router, try.router, 0);
935f447be7aSchristos /*
936f447be7aSchristos * This is the end of the record.
937f447be7aSchristos */
938f447be7aSchristos if (len == 0) {
939f447be7aSchristos if (f->state != OPENED)
940f447be7aSchristos *go = try;
941f447be7aSchristos return (1);
942f447be7aSchristos }
943f447be7aSchristos } while (0);
944f447be7aSchristos /*
945f447be7aSchristos * The frame is invalid at this point.
946f447be7aSchristos */
947f447be7aSchristos IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
948f447be7aSchristos return 0;
949f447be7aSchristos }
950f447be7aSchristos
951f447be7aSchristos /*
952f447be7aSchristos * ipxcp_reqci - Check the peer's requested CIs and send appropriate response.
953f447be7aSchristos *
954f447be7aSchristos * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
955f447be7aSchristos * appropriately. If reject_if_disagree is non-zero, doesn't return
956f447be7aSchristos * CONFNAK; returns CONFREJ if it can't return CONFACK.
957f447be7aSchristos */
958f447be7aSchristos static int
ipxcp_reqci(fsm * f,u_char * inp,int * len,int reject_if_disagree)959*3dce80e5Schristos ipxcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree)
960f447be7aSchristos {
961f447be7aSchristos u_char *cip, *next; /* Pointer to current and next CIs */
962f447be7aSchristos u_short cilen, citype; /* Parsed len, type */
963f447be7aSchristos u_short cishort; /* Parsed short value */
964f447be7aSchristos u_int32_t cinetwork; /* Parsed address values */
965f447be7aSchristos int rc = CONFACK; /* Final packet return code */
966f447be7aSchristos int orc; /* Individual option return code */
967f447be7aSchristos u_char *p; /* Pointer to next char to parse */
968f447be7aSchristos u_char *ucp = inp; /* Pointer to current output char */
969f447be7aSchristos int l = *len; /* Length left */
970f447be7aSchristos
971f447be7aSchristos /*
972f447be7aSchristos * Reset all his options.
973f447be7aSchristos */
974f447be7aSchristos BZERO(ho, sizeof(*ho));
975f447be7aSchristos
976f447be7aSchristos /*
977f447be7aSchristos * Process all his options.
978f447be7aSchristos */
979f447be7aSchristos next = inp;
980f447be7aSchristos while (l) {
981f447be7aSchristos orc = CONFACK; /* Assume success */
982f447be7aSchristos cip = p = next; /* Remember begining of CI */
983f447be7aSchristos if (l < 2 || /* Not enough data for CI header or */
984f447be7aSchristos p[1] < 2 || /* CI length too small or */
985f447be7aSchristos p[1] > l) { /* CI length too big? */
986f447be7aSchristos IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
987f447be7aSchristos orc = CONFREJ; /* Reject bad CI */
988f447be7aSchristos cilen = l; /* Reject till end of packet */
989f447be7aSchristos l = 0; /* Don't loop again */
990f447be7aSchristos goto endswitch;
991f447be7aSchristos }
992f447be7aSchristos GETCHAR(citype, p); /* Parse CI type */
993f447be7aSchristos GETCHAR(cilen, p); /* Parse CI length */
994f447be7aSchristos l -= cilen; /* Adjust remaining length */
995f447be7aSchristos next += cilen; /* Step to next CI */
996f447be7aSchristos
997f447be7aSchristos switch (citype) { /* Check CI type */
998f447be7aSchristos /*
999f447be7aSchristos * The network number must match. Choose the larger of the two.
1000f447be7aSchristos */
1001f447be7aSchristos case IPX_NETWORK_NUMBER:
1002f447be7aSchristos /* if we wont negotiate the network number or the length is wrong
1003f447be7aSchristos then reject the option */
1004f447be7aSchristos if ( !ao->neg_nn || cilen != CILEN_NETN ) {
1005f447be7aSchristos orc = CONFREJ;
1006f447be7aSchristos break;
1007f447be7aSchristos }
1008f447be7aSchristos GETLONG(cinetwork, p);
1009f447be7aSchristos
1010f447be7aSchristos /* If the network numbers match then acknowledge them. */
1011f447be7aSchristos if (cinetwork != 0) {
1012f447be7aSchristos ho->his_network = cinetwork;
1013f447be7aSchristos ho->neg_nn = 1;
1014f447be7aSchristos if (wo->our_network == cinetwork)
1015f447be7aSchristos break;
1016f447be7aSchristos /*
1017f447be7aSchristos * If the network number is not given or we don't accept their change or
1018f447be7aSchristos * the network number is too small then NAK it.
1019f447be7aSchristos */
1020f447be7aSchristos if (! ao->accept_network || cinetwork < wo->our_network) {
1021f447be7aSchristos DECPTR (sizeof (u_int32_t), p);
1022f447be7aSchristos PUTLONG (wo->our_network, p);
1023f447be7aSchristos orc = CONFNAK;
1024f447be7aSchristos }
1025f447be7aSchristos break;
1026f447be7aSchristos }
1027f447be7aSchristos /*
1028f447be7aSchristos * The peer sent '0' for the network. Give it ours if we have one.
1029f447be7aSchristos */
1030f447be7aSchristos if (go->our_network != 0) {
1031f447be7aSchristos DECPTR (sizeof (u_int32_t), p);
1032f447be7aSchristos PUTLONG (wo->our_network, p);
1033f447be7aSchristos orc = CONFNAK;
1034f447be7aSchristos /*
1035f447be7aSchristos * We don't have one. Reject the value.
1036f447be7aSchristos */
1037f447be7aSchristos } else
1038f447be7aSchristos orc = CONFREJ;
1039f447be7aSchristos
1040f447be7aSchristos break;
1041f447be7aSchristos /*
1042f447be7aSchristos * The node number is required
1043f447be7aSchristos */
1044f447be7aSchristos case IPX_NODE_NUMBER:
1045f447be7aSchristos /* if we wont negotiate the node number or the length is wrong
1046f447be7aSchristos then reject the option */
1047f447be7aSchristos if ( cilen != CILEN_NODEN ) {
1048f447be7aSchristos orc = CONFREJ;
1049f447be7aSchristos break;
1050f447be7aSchristos }
1051f447be7aSchristos
1052f447be7aSchristos copy_node (p, ho->his_node);
1053f447be7aSchristos ho->neg_node = 1;
1054f447be7aSchristos /*
1055f447be7aSchristos * If the remote does not have a number and we do then NAK it with the value
1056f447be7aSchristos * which we have for it. (We never have a default value of zero.)
1057f447be7aSchristos */
1058f447be7aSchristos if (zero_node (ho->his_node)) {
1059f447be7aSchristos orc = CONFNAK;
1060f447be7aSchristos copy_node (wo->his_node, p);
1061f447be7aSchristos INCPTR (sizeof (wo->his_node), p);
1062f447be7aSchristos break;
1063f447be7aSchristos }
1064f447be7aSchristos /*
1065f447be7aSchristos * If you have given me the expected network node number then I'll accept
1066f447be7aSchristos * it now.
1067f447be7aSchristos */
1068f447be7aSchristos if (compare_node (wo->his_node, ho->his_node)) {
1069f447be7aSchristos orc = CONFACK;
1070f447be7aSchristos ho->neg_node = 1;
1071f447be7aSchristos INCPTR (sizeof (wo->his_node), p);
1072f447be7aSchristos break;
1073f447be7aSchristos }
1074f447be7aSchristos /*
1075f447be7aSchristos * If his node number is the same as ours then ask him to try the next
1076f447be7aSchristos * value.
1077f447be7aSchristos */
1078f447be7aSchristos if (compare_node (ho->his_node, go->our_node)) {
1079f447be7aSchristos inc_node (ho->his_node);
1080f447be7aSchristos orc = CONFNAK;
1081f447be7aSchristos copy_node (ho->his_node, p);
1082f447be7aSchristos INCPTR (sizeof (wo->his_node), p);
1083f447be7aSchristos break;
1084f447be7aSchristos }
1085f447be7aSchristos /*
1086f447be7aSchristos * If we don't accept a new value then NAK it.
1087f447be7aSchristos */
1088f447be7aSchristos if (! ao->accept_remote) {
1089f447be7aSchristos copy_node (wo->his_node, p);
1090f447be7aSchristos INCPTR (sizeof (wo->his_node), p);
1091f447be7aSchristos orc = CONFNAK;
1092f447be7aSchristos break;
1093f447be7aSchristos }
1094f447be7aSchristos orc = CONFACK;
1095f447be7aSchristos ho->neg_node = 1;
1096f447be7aSchristos INCPTR (sizeof (wo->his_node), p);
1097f447be7aSchristos break;
1098f447be7aSchristos /*
1099f447be7aSchristos * Compression is not desired at this time. It is always rejected.
1100f447be7aSchristos */
1101f447be7aSchristos case IPX_COMPRESSION_PROTOCOL:
1102f447be7aSchristos orc = CONFREJ;
1103f447be7aSchristos break;
1104f447be7aSchristos /*
1105f447be7aSchristos * The routing protocol is a bitmask of various types. Any combination
1106f447be7aSchristos * of the values RIP_SAP and NLSP are permissible. 'IPX_NONE' for no
1107f447be7aSchristos * routing protocol must be specified only once.
1108f447be7aSchristos */
1109f447be7aSchristos case IPX_ROUTER_PROTOCOL:
1110f447be7aSchristos if ( !ao->neg_router || cilen < CILEN_PROTOCOL ) {
1111f447be7aSchristos orc = CONFREJ;
1112f447be7aSchristos break;
1113f447be7aSchristos }
1114f447be7aSchristos
1115f447be7aSchristos GETSHORT (cishort, p);
1116f447be7aSchristos
1117f447be7aSchristos if (wo->neg_router == 0) {
1118f447be7aSchristos wo->neg_router = 1;
1119f447be7aSchristos wo->router = BIT(IPX_NONE);
1120f447be7aSchristos }
1121f447be7aSchristos
1122f447be7aSchristos if ((cishort == IPX_NONE && ho->router != 0) ||
1123f447be7aSchristos (ho->router & BIT(IPX_NONE))) {
1124f447be7aSchristos orc = CONFREJ;
1125f447be7aSchristos break;
1126f447be7aSchristos }
1127f447be7aSchristos
1128f447be7aSchristos cishort = BIT(cishort);
1129f447be7aSchristos if (ho->router & cishort) {
1130f447be7aSchristos orc = CONFREJ;
1131f447be7aSchristos break;
1132f447be7aSchristos }
1133f447be7aSchristos
1134f447be7aSchristos ho->router |= cishort;
1135f447be7aSchristos ho->neg_router = 1;
1136f447be7aSchristos
1137f447be7aSchristos /* Finally do not allow a router protocol which we do not
1138f447be7aSchristos support. */
1139f447be7aSchristos
1140f447be7aSchristos if ((cishort & (ao->router | BIT(IPX_NONE))) == 0) {
1141f447be7aSchristos int protocol;
1142f447be7aSchristos
1143f447be7aSchristos if (cishort == BIT(NLSP) &&
1144f447be7aSchristos (ao->router & BIT(RIP_SAP)) &&
1145f447be7aSchristos !wo->tried_rip) {
1146f447be7aSchristos protocol = RIP_SAP;
1147f447be7aSchristos wo->tried_rip = 1;
1148f447be7aSchristos } else
1149f447be7aSchristos protocol = IPX_NONE;
1150f447be7aSchristos
1151f447be7aSchristos DECPTR (sizeof (u_int16_t), p);
1152f447be7aSchristos PUTSHORT (protocol, p);
1153f447be7aSchristos orc = CONFNAK;
1154f447be7aSchristos }
1155f447be7aSchristos break;
1156f447be7aSchristos /*
1157f447be7aSchristos * The router name is advisorary. Just accept it if it is not too large.
1158f447be7aSchristos */
1159f447be7aSchristos case IPX_ROUTER_NAME:
1160f447be7aSchristos if (cilen >= CILEN_NAME) {
1161f447be7aSchristos int name_size = cilen - CILEN_NAME;
1162*3dce80e5Schristos if (name_size >= sizeof (ho->name))
1163f447be7aSchristos name_size = sizeof (ho->name) - 1;
1164f447be7aSchristos memset (ho->name, 0, sizeof (ho->name));
1165f447be7aSchristos memcpy (ho->name, p, name_size);
1166f447be7aSchristos ho->name [name_size] = '\0';
1167f447be7aSchristos ho->neg_name = 1;
1168f447be7aSchristos orc = CONFACK;
1169f447be7aSchristos break;
1170f447be7aSchristos }
1171f447be7aSchristos orc = CONFREJ;
1172f447be7aSchristos break;
1173f447be7aSchristos /*
1174f447be7aSchristos * This is advisorary.
1175f447be7aSchristos */
1176f447be7aSchristos case IPX_COMPLETE:
1177f447be7aSchristos if (cilen != CILEN_COMPLETE)
1178f447be7aSchristos orc = CONFREJ;
1179f447be7aSchristos else {
1180f447be7aSchristos ho->neg_complete = 1;
1181f447be7aSchristos orc = CONFACK;
1182f447be7aSchristos }
1183f447be7aSchristos break;
1184f447be7aSchristos /*
1185f447be7aSchristos * All other entries are not known at this time.
1186f447be7aSchristos */
1187f447be7aSchristos default:
1188f447be7aSchristos orc = CONFREJ;
1189f447be7aSchristos break;
1190f447be7aSchristos }
1191f447be7aSchristos endswitch:
1192f447be7aSchristos if (orc == CONFACK && /* Good CI */
1193f447be7aSchristos rc != CONFACK) /* but prior CI wasnt? */
1194f447be7aSchristos continue; /* Don't send this one */
1195f447be7aSchristos
1196f447be7aSchristos if (orc == CONFNAK) { /* Nak this CI? */
1197f447be7aSchristos if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1198f447be7aSchristos orc = CONFREJ; /* Get tough if so */
1199f447be7aSchristos if (rc == CONFREJ) /* Rejecting prior CI? */
1200f447be7aSchristos continue; /* Don't send this one */
1201f447be7aSchristos if (rc == CONFACK) { /* Ack'd all prior CIs? */
1202f447be7aSchristos rc = CONFNAK; /* Not anymore... */
1203f447be7aSchristos ucp = inp; /* Backup */
1204f447be7aSchristos }
1205f447be7aSchristos }
1206f447be7aSchristos
1207f447be7aSchristos if (orc == CONFREJ && /* Reject this CI */
1208f447be7aSchristos rc != CONFREJ) { /* but no prior ones? */
1209f447be7aSchristos rc = CONFREJ;
1210f447be7aSchristos ucp = inp; /* Backup */
1211f447be7aSchristos }
1212f447be7aSchristos
1213f447be7aSchristos /* Need to move CI? */
1214f447be7aSchristos if (ucp != cip)
1215f447be7aSchristos BCOPY(cip, ucp, cilen); /* Move it */
1216f447be7aSchristos
1217f447be7aSchristos /* Update output pointer */
1218f447be7aSchristos INCPTR(cilen, ucp);
1219f447be7aSchristos }
1220f447be7aSchristos
1221f447be7aSchristos /*
1222f447be7aSchristos * If we aren't rejecting this packet, and we want to negotiate
1223f447be7aSchristos * their address, and they didn't send their address, then we
1224f447be7aSchristos * send a NAK with a IPX_NODE_NUMBER option appended. We assume the
1225f447be7aSchristos * input buffer is long enough that we can append the extra
1226f447be7aSchristos * option safely.
1227f447be7aSchristos */
1228f447be7aSchristos
1229f447be7aSchristos if (rc != CONFREJ && !ho->neg_node &&
1230f447be7aSchristos wo->req_nn && !reject_if_disagree) {
1231f447be7aSchristos if (rc == CONFACK) {
1232f447be7aSchristos rc = CONFNAK;
1233f447be7aSchristos wo->req_nn = 0; /* don't ask again */
1234f447be7aSchristos ucp = inp; /* reset pointer */
1235f447be7aSchristos }
1236f447be7aSchristos
1237f447be7aSchristos if (zero_node (wo->his_node))
1238f447be7aSchristos inc_node (wo->his_node);
1239f447be7aSchristos
1240f447be7aSchristos PUTCHAR (IPX_NODE_NUMBER, ucp);
1241f447be7aSchristos PUTCHAR (CILEN_NODEN, ucp);
1242f447be7aSchristos copy_node (wo->his_node, ucp);
1243f447be7aSchristos INCPTR (sizeof (wo->his_node), ucp);
1244f447be7aSchristos }
1245f447be7aSchristos
1246f447be7aSchristos *len = ucp - inp; /* Compute output length */
1247f447be7aSchristos IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
1248f447be7aSchristos return (rc); /* Return final code */
1249f447be7aSchristos }
1250f447be7aSchristos
1251f447be7aSchristos /*
1252f447be7aSchristos * ipxcp_up - IPXCP has come UP.
1253f447be7aSchristos *
1254f447be7aSchristos * Configure the IP network interface appropriately and bring it up.
1255f447be7aSchristos */
1256f447be7aSchristos
1257f447be7aSchristos static void
ipxcp_up(fsm * f)1258*3dce80e5Schristos ipxcp_up(fsm *f)
1259f447be7aSchristos {
1260f447be7aSchristos int unit = f->unit;
1261f447be7aSchristos
1262f447be7aSchristos IPXCPDEBUG(("ipxcp: up"));
1263f447be7aSchristos
1264f447be7aSchristos /* The default router protocol is RIP/SAP. */
1265f447be7aSchristos if (ho->router == 0)
1266f447be7aSchristos ho->router = BIT(RIP_SAP);
1267f447be7aSchristos
1268f447be7aSchristos if (go->router == 0)
1269f447be7aSchristos go->router = BIT(RIP_SAP);
1270f447be7aSchristos
1271f447be7aSchristos /* Fetch the network number */
1272f447be7aSchristos if (!ho->neg_nn)
1273f447be7aSchristos ho->his_network = wo->his_network;
1274f447be7aSchristos
1275f447be7aSchristos if (!ho->neg_node)
1276f447be7aSchristos copy_node (wo->his_node, ho->his_node);
1277f447be7aSchristos
1278f447be7aSchristos if (!wo->neg_node && !go->neg_node)
1279f447be7aSchristos copy_node (wo->our_node, go->our_node);
1280f447be7aSchristos
1281f447be7aSchristos if (zero_node (go->our_node)) {
1282f447be7aSchristos static char errmsg[] = "Could not determine local IPX node address";
1283f447be7aSchristos if (debug)
1284f447be7aSchristos error(errmsg);
1285f447be7aSchristos ipxcp_close(f->unit, errmsg);
1286f447be7aSchristos return;
1287f447be7aSchristos }
1288f447be7aSchristos
1289f447be7aSchristos go->network = go->our_network;
1290f447be7aSchristos if (ho->his_network != 0 && ho->his_network > go->network)
1291f447be7aSchristos go->network = ho->his_network;
1292f447be7aSchristos
1293f447be7aSchristos if (go->network == 0) {
1294f447be7aSchristos static char errmsg[] = "Can not determine network number";
1295f447be7aSchristos if (debug)
1296f447be7aSchristos error(errmsg);
1297f447be7aSchristos ipxcp_close (unit, errmsg);
1298f447be7aSchristos return;
1299f447be7aSchristos }
1300f447be7aSchristos
1301f447be7aSchristos /* bring the interface up */
1302f447be7aSchristos if (!sifup(unit)) {
1303f447be7aSchristos if (debug)
1304f447be7aSchristos warn("sifup failed (IPX)");
1305f447be7aSchristos ipxcp_close(unit, "Interface configuration failed");
1306f447be7aSchristos return;
1307f447be7aSchristos }
1308f447be7aSchristos ipxcp_is_up = 1;
1309f447be7aSchristos
1310f447be7aSchristos /* set the network number for IPX */
1311f447be7aSchristos if (!sipxfaddr(unit, go->network, go->our_node)) {
1312f447be7aSchristos if (debug)
1313f447be7aSchristos warn("sipxfaddr failed");
1314f447be7aSchristos ipxcp_close(unit, "Interface configuration failed");
1315f447be7aSchristos return;
1316f447be7aSchristos }
1317f447be7aSchristos
1318f447be7aSchristos np_up(f->unit, PPP_IPX);
1319f447be7aSchristos
1320f447be7aSchristos /*
1321f447be7aSchristos * Execute the ipx-up script, like this:
1322f447be7aSchristos * /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
1323f447be7aSchristos */
1324f447be7aSchristos
1325f447be7aSchristos ipxcp_script (f, _PATH_IPXUP);
1326f447be7aSchristos }
1327f447be7aSchristos
1328f447be7aSchristos /*
1329f447be7aSchristos * ipxcp_down - IPXCP has gone DOWN.
1330f447be7aSchristos *
1331f447be7aSchristos * Take the IP network interface down, clear its addresses
1332f447be7aSchristos * and delete routes through it.
1333f447be7aSchristos */
1334f447be7aSchristos
1335f447be7aSchristos static void
ipxcp_down(fsm * f)1336*3dce80e5Schristos ipxcp_down(fsm *f)
1337f447be7aSchristos {
1338f447be7aSchristos IPXCPDEBUG(("ipxcp: down"));
1339f447be7aSchristos
1340f447be7aSchristos if (!ipxcp_is_up)
1341f447be7aSchristos return;
1342f447be7aSchristos ipxcp_is_up = 0;
1343f447be7aSchristos np_down(f->unit, PPP_IPX);
1344f447be7aSchristos cipxfaddr(f->unit);
1345f447be7aSchristos sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
1346f447be7aSchristos sifdown(f->unit);
1347f447be7aSchristos ipxcp_script (f, _PATH_IPXDOWN);
1348f447be7aSchristos }
1349f447be7aSchristos
1350f447be7aSchristos
1351f447be7aSchristos /*
1352f447be7aSchristos * ipxcp_finished - possibly shut down the lower layers.
1353f447be7aSchristos */
1354f447be7aSchristos static void
ipxcp_finished(fsm * f)1355*3dce80e5Schristos ipxcp_finished(fsm *f)
1356f447be7aSchristos {
1357f447be7aSchristos np_finished(f->unit, PPP_IPX);
1358f447be7aSchristos }
1359f447be7aSchristos
1360f447be7aSchristos
1361f447be7aSchristos /*
1362f447be7aSchristos * ipxcp_script - Execute a script with arguments
1363f447be7aSchristos * interface-name tty-name speed local-IPX remote-IPX networks.
1364f447be7aSchristos */
1365f447be7aSchristos static void
ipxcp_script(fsm * f,char * script)1366*3dce80e5Schristos ipxcp_script(fsm *f, char *script)
1367f447be7aSchristos {
1368f447be7aSchristos char strspeed[32], strlocal[32], strremote[32];
1369f447be7aSchristos char strnetwork[32], strpid[32];
1370f447be7aSchristos char *argv[14], strproto_lcl[32], strproto_rmt[32];
1371f447be7aSchristos
1372f447be7aSchristos slprintf(strpid, sizeof(strpid), "%d", getpid());
1373f447be7aSchristos slprintf(strspeed, sizeof(strspeed),"%d", baud_rate);
1374f447be7aSchristos
1375f447be7aSchristos strproto_lcl[0] = '\0';
1376f447be7aSchristos if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
1377f447be7aSchristos if (go->router & BIT(RIP_SAP))
1378f447be7aSchristos strlcpy (strproto_lcl, "RIP ", sizeof(strproto_lcl));
1379f447be7aSchristos if (go->router & BIT(NLSP))
1380f447be7aSchristos strlcat (strproto_lcl, "NLSP ", sizeof(strproto_lcl));
1381f447be7aSchristos }
1382f447be7aSchristos
1383f447be7aSchristos if (strproto_lcl[0] == '\0')
1384f447be7aSchristos strlcpy (strproto_lcl, "NONE ", sizeof(strproto_lcl));
1385f447be7aSchristos
1386f447be7aSchristos strproto_lcl[strlen (strproto_lcl)-1] = '\0';
1387f447be7aSchristos
1388f447be7aSchristos strproto_rmt[0] = '\0';
1389f447be7aSchristos if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
1390f447be7aSchristos if (ho->router & BIT(RIP_SAP))
1391f447be7aSchristos strlcpy (strproto_rmt, "RIP ", sizeof(strproto_rmt));
1392f447be7aSchristos if (ho->router & BIT(NLSP))
1393f447be7aSchristos strlcat (strproto_rmt, "NLSP ", sizeof(strproto_rmt));
1394f447be7aSchristos }
1395f447be7aSchristos
1396f447be7aSchristos if (strproto_rmt[0] == '\0')
1397f447be7aSchristos strlcpy (strproto_rmt, "NONE ", sizeof(strproto_rmt));
1398f447be7aSchristos
1399f447be7aSchristos strproto_rmt[strlen (strproto_rmt)-1] = '\0';
1400f447be7aSchristos
1401f447be7aSchristos strlcpy (strnetwork, ipx_ntoa (go->network), sizeof(strnetwork));
1402f447be7aSchristos
1403f447be7aSchristos slprintf (strlocal, sizeof(strlocal), "%0.6B", go->our_node);
1404f447be7aSchristos
1405f447be7aSchristos slprintf (strremote, sizeof(strremote), "%0.6B", ho->his_node);
1406f447be7aSchristos
1407f447be7aSchristos argv[0] = script;
1408f447be7aSchristos argv[1] = ifname;
1409f447be7aSchristos argv[2] = devnam;
1410f447be7aSchristos argv[3] = strspeed;
1411f447be7aSchristos argv[4] = strnetwork;
1412f447be7aSchristos argv[5] = strlocal;
1413f447be7aSchristos argv[6] = strremote;
1414f447be7aSchristos argv[7] = strproto_lcl;
1415f447be7aSchristos argv[8] = strproto_rmt;
1416f447be7aSchristos argv[9] = (char *)go->name;
1417f447be7aSchristos argv[10] = (char *)ho->name;
1418f447be7aSchristos argv[11] = ipparam;
1419f447be7aSchristos argv[12] = strpid;
1420f447be7aSchristos argv[13] = NULL;
1421f447be7aSchristos run_program(script, argv, 0, NULL, NULL, 0);
1422f447be7aSchristos }
1423f447be7aSchristos
1424f447be7aSchristos /*
1425f447be7aSchristos * ipxcp_printpkt - print the contents of an IPXCP packet.
1426f447be7aSchristos */
1427f447be7aSchristos static char *ipxcp_codenames[] = {
1428f447be7aSchristos "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1429f447be7aSchristos "TermReq", "TermAck", "CodeRej"
1430f447be7aSchristos };
1431f447be7aSchristos
1432f447be7aSchristos static int
ipxcp_printpkt(u_char * p,int plen,void (* printer)(void *,char *,...),void * arg)1433*3dce80e5Schristos ipxcp_printpkt(u_char *p, int plen,
1434*3dce80e5Schristos void (*printer) (void *, char *, ...), void *arg)
1435f447be7aSchristos {
1436f447be7aSchristos int code, id, len, olen;
1437f447be7aSchristos u_char *pstart, *optend;
1438f447be7aSchristos u_short cishort;
1439f447be7aSchristos u_int32_t cilong;
1440f447be7aSchristos
1441f447be7aSchristos if (plen < HEADERLEN)
1442f447be7aSchristos return 0;
1443f447be7aSchristos pstart = p;
1444f447be7aSchristos GETCHAR(code, p);
1445f447be7aSchristos GETCHAR(id, p);
1446f447be7aSchristos GETSHORT(len, p);
1447f447be7aSchristos if (len < HEADERLEN || len > plen)
1448f447be7aSchristos return 0;
1449f447be7aSchristos
1450f447be7aSchristos if (code >= 1 && code <= sizeof(ipxcp_codenames) / sizeof(char *))
1451f447be7aSchristos printer(arg, " %s", ipxcp_codenames[code-1]);
1452f447be7aSchristos else
1453f447be7aSchristos printer(arg, " code=0x%x", code);
1454f447be7aSchristos printer(arg, " id=0x%x", id);
1455f447be7aSchristos len -= HEADERLEN;
1456f447be7aSchristos switch (code) {
1457f447be7aSchristos case CONFREQ:
1458f447be7aSchristos case CONFACK:
1459f447be7aSchristos case CONFNAK:
1460f447be7aSchristos case CONFREJ:
1461f447be7aSchristos /* print option list */
1462f447be7aSchristos while (len >= 2) {
1463f447be7aSchristos GETCHAR(code, p);
1464f447be7aSchristos GETCHAR(olen, p);
1465f447be7aSchristos p -= 2;
1466f447be7aSchristos if (olen < CILEN_VOID || olen > len) {
1467f447be7aSchristos break;
1468f447be7aSchristos }
1469f447be7aSchristos printer(arg, " <");
1470f447be7aSchristos len -= olen;
1471f447be7aSchristos optend = p + olen;
1472f447be7aSchristos switch (code) {
1473f447be7aSchristos case IPX_NETWORK_NUMBER:
1474f447be7aSchristos if (olen == CILEN_NETN) {
1475f447be7aSchristos p += 2;
1476f447be7aSchristos GETLONG(cilong, p);
1477f447be7aSchristos printer (arg, "network %s", ipx_ntoa (cilong));
1478f447be7aSchristos }
1479f447be7aSchristos break;
1480f447be7aSchristos case IPX_NODE_NUMBER:
1481f447be7aSchristos if (olen == CILEN_NODEN) {
1482f447be7aSchristos p += 2;
1483f447be7aSchristos printer (arg, "node ");
1484f447be7aSchristos while (p < optend) {
1485f447be7aSchristos GETCHAR(code, p);
1486f447be7aSchristos printer(arg, "%.2x", (int) (unsigned int) (unsigned char) code);
1487f447be7aSchristos }
1488f447be7aSchristos }
1489f447be7aSchristos break;
1490f447be7aSchristos case IPX_COMPRESSION_PROTOCOL:
1491f447be7aSchristos if (olen == CILEN_COMPRESS) {
1492f447be7aSchristos p += 2;
1493f447be7aSchristos GETSHORT (cishort, p);
1494f447be7aSchristos printer (arg, "compression %d", (int) cishort);
1495f447be7aSchristos }
1496f447be7aSchristos break;
1497f447be7aSchristos case IPX_ROUTER_PROTOCOL:
1498f447be7aSchristos if (olen == CILEN_PROTOCOL) {
1499f447be7aSchristos p += 2;
1500f447be7aSchristos GETSHORT (cishort, p);
1501f447be7aSchristos printer (arg, "router proto %d", (int) cishort);
1502f447be7aSchristos }
1503f447be7aSchristos break;
1504f447be7aSchristos case IPX_ROUTER_NAME:
1505f447be7aSchristos if (olen >= CILEN_NAME) {
1506f447be7aSchristos p += 2;
1507f447be7aSchristos printer (arg, "router name \"");
1508f447be7aSchristos while (p < optend) {
1509f447be7aSchristos GETCHAR(code, p);
1510f447be7aSchristos if (code >= 0x20 && code <= 0x7E)
1511f447be7aSchristos printer (arg, "%c", (int) (unsigned int) (unsigned char) code);
1512f447be7aSchristos else
1513f447be7aSchristos printer (arg, " \\%.2x", (int) (unsigned int) (unsigned char) code);
1514f447be7aSchristos }
1515f447be7aSchristos printer (arg, "\"");
1516f447be7aSchristos }
1517f447be7aSchristos break;
1518f447be7aSchristos case IPX_COMPLETE:
1519f447be7aSchristos if (olen == CILEN_COMPLETE) {
1520f447be7aSchristos p += 2;
1521f447be7aSchristos printer (arg, "complete");
1522f447be7aSchristos }
1523f447be7aSchristos break;
1524f447be7aSchristos default:
1525f447be7aSchristos break;
1526f447be7aSchristos }
1527f447be7aSchristos
1528f447be7aSchristos while (p < optend) {
1529f447be7aSchristos GETCHAR(code, p);
1530f447be7aSchristos printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1531f447be7aSchristos }
1532f447be7aSchristos printer(arg, ">");
1533f447be7aSchristos }
1534f447be7aSchristos break;
1535f447be7aSchristos
1536f447be7aSchristos case TERMACK:
1537f447be7aSchristos case TERMREQ:
1538f447be7aSchristos if (len > 0 && *p >= ' ' && *p < 0x7f) {
1539f447be7aSchristos printer(arg, " ");
1540f447be7aSchristos print_string((char *)p, len, printer, arg);
1541f447be7aSchristos p += len;
1542f447be7aSchristos len = 0;
1543f447be7aSchristos }
1544f447be7aSchristos break;
1545f447be7aSchristos }
1546f447be7aSchristos
1547f447be7aSchristos /* print the rest of the bytes in the packet */
1548f447be7aSchristos for (; len > 0; --len) {
1549f447be7aSchristos GETCHAR(code, p);
1550f447be7aSchristos printer(arg, " %.2x", (int) (unsigned int) (unsigned char) code);
1551f447be7aSchristos }
1552f447be7aSchristos
1553f447be7aSchristos return p - pstart;
1554f447be7aSchristos }
1555f447be7aSchristos #endif /* ifdef IPX_CHANGE */
1556