X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fipxcp.c;h=760106306d406d2249b6fbc5c950093e76762064;hp=9de3462f61d8e2c2ebc270000707ffa9e17481d2;hb=0375e3ce50b9e0bc4e559615039988e7834c7d01;hpb=0f2f62bd2cb9ac4f8757c2ec365cdb62657ef3b8 diff --git a/pppd/ipxcp.c b/pppd/ipxcp.c index 9de3462..7601063 100644 --- a/pppd/ipxcp.c +++ b/pppd/ipxcp.c @@ -19,7 +19,7 @@ #ifdef IPX_CHANGE #ifndef lint -static char rcsid[] = "$Id: ipxcp.c,v 1.5 1997/03/04 03:39:32 paulus Exp $"; +static char rcsid[] = "$Id: ipxcp.c,v 1.9 1999/03/12 06:07:17 paulus Exp $"; #endif /* @@ -29,6 +29,8 @@ static char rcsid[] = "$Id: ipxcp.c,v 1.5 1997/03/04 03:39:32 paulus Exp $"; #include #include #include +#include +#include #include #include #include @@ -37,6 +39,7 @@ static char rcsid[] = "$Id: ipxcp.c,v 1.5 1997/03/04 03:39:32 paulus Exp $"; #include "fsm.h" #include "ipxcp.h" #include "pathnames.h" +#include "magic.h" /* global vars */ ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */ @@ -83,6 +86,50 @@ static fsm_callbacks ipxcp_callbacks = { /* IPXCP callback routines */ "IPXCP" /* String name of protocol */ }; +/* + * Command-line options. + */ +static int setipxnode __P((char **)); +static int setipxname __P((char **)); + +static option_t ipxcp_option_list[] = { + { "ipx", o_bool, &ipxcp_protent.enabled_flag, + "Enable IPXCP (and IPX)", 1 }, + { "+ipx", o_bool, &ipxcp_protent.enabled_flag, + "Enable IPXCP (and IPX)", 1 }, + { "noipx", o_bool, &ipxcp_protent.enabled_flag, + "Disable IPXCP (and IPX)" }, + { "-ipx", o_bool, &ipxcp_protent.enabled_flag, + "Disable IPXCP (and IPX)" } , + { "ipx-network", o_int, &ipxcp_wantoptions[0].our_network, + "Set our IPX network number", 0, &ipxcp_wantoptions[0].neg_nn }, + { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network, + "Accept peer IPX network number", 1, + &ipxcp_allowoptions[0].accept_network }, + { "ipx-node", o_special, setipxnode, + "Set IPX node number" }, + { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local, + "Accept our IPX address", 1, + &ipxcp_allowoptions[0].accept_local }, + { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote, + "Accept peer's IPX address", 1, + &ipxcp_allowoptions[0].accept_remote }, + { "ipx-routing", o_int, &ipxcp_wantoptions[0].router, + "Set IPX routing proto number", 0, + &ipxcp_wantoptions[0].neg_router }, + { "ipx-router-name", o_special, setipxname, + "Set IPX router name" }, + { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime, + "Set timeout for IPXCP" }, + { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits, + "Set max #xmits for IPXCP term-reqs" }, + { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits, + "Set max #xmits for IPXCP conf-reqs" }, + { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops, + "Set max #conf-naks for IPXCP" }, + { NULL } +}; + /* * Protocol entry points. */ @@ -110,6 +157,7 @@ struct protent ipxcp_protent = { NULL, 0, "IPXCP", + ipxcp_option_list, NULL, NULL, NULL @@ -163,11 +211,92 @@ ipx_ntoa(ipxaddr) u_int32_t ipxaddr; { static char b[64]; - sprintf(b, "%lx", ipxaddr); + sprintf(b, "%x", ipxaddr); return b; } +static u_char * +setipxnodevalue(src,dst) +u_char *src, *dst; +{ + int indx; + int item; + + for (;;) { + if (!isxdigit (*src)) + break; + + for (indx = 0; indx < 5; ++indx) { + dst[indx] <<= 4; + dst[indx] |= (dst[indx + 1] >> 4) & 0x0F; + } + + item = toupper (*src) - '0'; + if (item > 9) + item -= 7; + + dst[5] = (dst[5] << 4) | item; + ++src; + } + return src; +} + +static int +setipxnode(argv) + char **argv; +{ + char *end; + + memset (&ipxcp_wantoptions[0].our_node[0], 0, 6); + memset (&ipxcp_wantoptions[0].his_node[0], 0, 6); + + end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]); + if (*end == ':') + end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]); + + if (*end == '\0') { + ipxcp_wantoptions[0].neg_node = 1; + return 1; + } + + option_error("invalid parameter '%s' for ipx-node option", *argv); + return 0; +} + +static int +setipxname (argv) + char **argv; +{ + char *dest = ipxcp_wantoptions[0].name; + char *src = *argv; + int count; + char ch; + + ipxcp_wantoptions[0].neg_name = 1; + ipxcp_allowoptions[0].neg_name = 1; + memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name)); + + count = 0; + while (*src) { + ch = *src++; + if (! isalnum (ch) && ch != '_') { + option_error("IPX router name must be alphanumeric or _"); + return 0; + } + + if (count >= sizeof (ipxcp_wantoptions[0].name)) { + option_error("IPX router name is limited to %d characters", + sizeof (ipxcp_wantoptions[0].name) - 1); + return 0; + } + + dest[count++] = toupper (ch); + } + + return 1; +} + /* * ipxcp_init - Initialize IPXCP. */ @@ -336,9 +465,6 @@ static void ipxcp_resetci(f) fsm *f; { - u_int32_t network; - int unit = f->unit; - wo->req_node = wo->neg_node && ao->neg_node; wo->req_nn = wo->neg_nn && ao->neg_nn; @@ -387,7 +513,6 @@ static int ipxcp_cilen(f) fsm *f; { - int unit = f->unit; int len; len = go->neg_nn ? CILEN_NETN : 0; @@ -411,8 +536,6 @@ ipxcp_addci(f, ucp, lenp) u_char *ucp; int *lenp; { - int len = *lenp; - int unit = f->unit; /* * Add the options to the record. */ @@ -462,7 +585,6 @@ ipxcp_ackci(f, p, len) u_char *p; int len; { - int unit = f->unit; u_short cilen, citype, cishort; u_char cichar; u_int32_t cilong; @@ -571,7 +693,6 @@ ipxcp_nakci(f, p, len) u_char *p; int len; { - int unit = f->unit; u_char citype, cilen, *next; u_short s; u_int32_t l; @@ -690,7 +811,6 @@ ipxcp_rejci(f, p, len) u_char *p; int len; { - int unit = f->unit; u_short cilen, citype, cishort; u_char cichar; u_int32_t cilong; @@ -807,17 +927,15 @@ ipxcp_reqci(f, inp, len, reject_if_disagree) int *len; /* Length of requested CIs */ int reject_if_disagree; { - int unit = f->unit; u_char *cip, *next; /* Pointer to current and next CIs */ u_short cilen, citype; /* Parsed len, type */ - u_short cishort, ts; /* Parsed short value */ - u_int32_t tl, cinetwork, outnet;/* Parsed address values */ + u_short cishort; /* Parsed short value */ + u_int32_t cinetwork; /* Parsed address values */ int rc = CONFACK; /* Final packet return code */ int orc; /* Individual option return code */ u_char *p; /* Pointer to next char to parse */ u_char *ucp = inp; /* Pointer to current output char */ int l = *len; /* Length left */ - u_char maxslotindex, cflag; /* * Reset all his options. @@ -1094,7 +1212,6 @@ endswitch: if (rc != CONFREJ && !ho->neg_node && wo->req_nn && !reject_if_disagree) { - u_char *ps; if (rc == CONFACK) { rc = CONFNAK; wo->req_nn = 0; /* don't ask again */ @@ -1197,8 +1314,6 @@ static void ipxcp_down(f) fsm *f; { - u_int32_t ournn, network; - IPXCPDEBUG((LOG_INFO, "ipxcp: down")); cipxfaddr (f->unit); @@ -1216,7 +1331,6 @@ ipxcp_script(f, script) fsm *f; char *script; { - int unit = f->unit; char strspeed[32], strlocal[32], strremote[32]; char strnetwork[32], strpid[32]; char *argv[14], strproto_lcl[32], strproto_rmt[32]; @@ -1227,38 +1341,38 @@ ipxcp_script(f, script) strproto_lcl[0] = '\0'; if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) { if (go->router & BIT(RIP_SAP)) - strcpy (strproto_lcl, "RIP "); + strlcpy (strproto_lcl, sizeof(strproto_lcl), "RIP "); if (go->router & BIT(NLSP)) - strcat (strproto_lcl, "NLSP "); + strlcat (strproto_lcl, sizeof(strproto_lcl), "NLSP "); } if (strproto_lcl[0] == '\0') - strcpy (strproto_lcl, "NONE "); + strlcpy (strproto_lcl, sizeof(strproto_lcl), "NONE "); strproto_lcl[strlen (strproto_lcl)-1] = '\0'; strproto_rmt[0] = '\0'; if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) { if (ho->router & BIT(RIP_SAP)) - strcpy (strproto_rmt, "RIP "); + strlcpy (strproto_rmt, sizeof(strproto_rmt), "RIP "); if (ho->router & BIT(NLSP)) - strcat (strproto_rmt, "NLSP "); + strlcat (strproto_rmt, sizeof(strproto_rmt), "NLSP "); } if (strproto_rmt[0] == '\0') - strcpy (strproto_rmt, "NONE "); + strlcpy (strproto_rmt, sizeof(strproto_rmt), "NONE "); strproto_rmt[strlen (strproto_rmt)-1] = '\0'; - strcpy (strnetwork, ipx_ntoa (go->network)); + strlcpy (strnetwork, sizeof(strnetwork), ipx_ntoa (go->network)); - sprintf (strlocal, - "%02X%02X%02X%02X%02X%02X", - NODE(go->our_node)); + slprintf (strlocal, sizeof(strlocal), + "%02X%02X%02X%02X%02X%02X", + NODE(go->our_node)); - sprintf (strremote, - "%02X%02X%02X%02X%02X%02X", - NODE(ho->his_node)); + slprintf (strremote, sizeof(strremote), + "%02X%02X%02X%02X%02X%02X", + NODE(ho->his_node)); argv[0] = script; argv[1] = ifname; @@ -1274,7 +1388,7 @@ ipxcp_script(f, script) argv[11] = ipparam; argv[12] = strpid; argv[13] = NULL; - run_program(script, argv, 0); + run_program(script, argv, 0, NULL, NULL); } /*