From owner-freebsd-hackers Fri Dec 19 06:10:12 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id GAA19063 for hackers-outgoing; Fri, 19 Dec 1997 06:10:12 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from cozumel.saidev.com (cozumel.saidev.com [207.67.52.5]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id GAA19012 for ; Fri, 19 Dec 1997 06:09:48 -0800 (PST) (envelope-from derek@cozumel.saidev.com) Received: (from derek@localhost) by cozumel.saidev.com (8.7.1/8.7.1) id IAA05556; Fri, 19 Dec 1997 08:09:14 -0600 (CST) Message-ID: <19971219080913.17939@saidev.com> Date: Fri, 19 Dec 1997 08:09:13 -0600 From: Derek Inksetter To: freebsd-hackers@freebsd.org Subject: ppp multi-device? Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.88 Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk How much interest is there in making user-mode ppp handle multiple devices for dial-out? My company uses ppp with "ip aliasing" and some modifications to deal with multiple modems. basically our ppp.conf has a line that looks like this: set device /dev/cuaa0,/dev/cuaa1,... A setup like this, coupled with setting the box up as a gateway, allows our office to support several customers (accessible only through PPP) with a limited number of dial-out modems. My company's been using this for close to a year, and I can attest to its stability, at least in our case. Let me know what you think. Derek (Here's a patch to the -current ppp. Caveat: This is a re-write for current. My office is running on 2.1.5) diff -c ./command.c ../ppp/command.c *** ./command.c Wed Dec 17 22:47:41 1997 --- ../ppp/command.c Fri Dec 19 07:46:01 1997 *************** *** 1347,1356 **** LogPrintf(LogWARN, "Cannot change device to \"%s\" when \"%s\" is open\n", argp, VarDevice); else { ! strncpy(VarDevice, argp, sizeof(VarDevice) - 1); ! VarDevice[sizeof(VarDevice) - 1] = '\0'; ! VarBaseDevice = strrchr(VarDevice, '/'); ! VarBaseDevice = VarBaseDevice ? VarBaseDevice + 1 : ""; } break; case VAR_ACCMAP: --- 1347,1354 ---- LogPrintf(LogWARN, "Cannot change device to \"%s\" when \"%s\" is open\n", argp, VarDevice); else { ! strncpy(VarDeviceList, argp, sizeof(VarDeviceList) - 1); ! VarDeviceList[sizeof(VarDeviceList) - 1] = '\0'; } break; case VAR_ACCMAP: *************** *** 1421,1427 **** {"ctsrts", NULL, SetCtsRts, LOCAL_AUTH, "Use CTS/RTS modem signalling", "set ctsrts [on|off]"}, {"device", "line", SetVariable, LOCAL_AUTH, "Set modem device name", ! "set device|line device-name", (const void *) VAR_DEVICE}, {"dfilter", NULL, SetDfilter, LOCAL_AUTH, "Set demand filter", "set dfilter ..."}, {"dial", NULL, SetVariable, LOCAL_AUTH, --- 1419,1425 ---- {"ctsrts", NULL, SetCtsRts, LOCAL_AUTH, "Use CTS/RTS modem signalling", "set ctsrts [on|off]"}, {"device", "line", SetVariable, LOCAL_AUTH, "Set modem device name", ! "set device|line device-name[,device-name]", (const void *) VAR_DEVICE}, {"dfilter", NULL, SetDfilter, LOCAL_AUTH, "Set demand filter", "set dfilter ..."}, {"dial", NULL, SetVariable, LOCAL_AUTH, diff -c ./modem.c ../ppp/modem.c *** ./modem.c Wed Dec 17 22:47:42 1997 --- ../ppp/modem.c Thu Dec 18 20:33:24 1997 *************** *** 434,439 **** --- 434,441 ---- int oldflag; char *host, *port; char *cp; + char tmpDeviceList[sizeof(VarDeviceList)]; + char *tmpDevice; if (modem >= 0) LogPrintf(LogDEBUG, "OpenModem: Modem is already open!\n"); *************** *** 464,507 **** return modem = 0; } } else { ! if (strncmp(VarDevice, "/dev/", 5) == 0) { ! if (LockModem() == -1) ! return (-1); ! modem = ID0open(VarDevice, O_RDWR | O_NONBLOCK); ! if (modem < 0) { ! LogPrintf(LogERROR, "OpenModem failed: %s: %s\n", VarDevice, ! strerror(errno)); ! UnlockModem(); ! return (-1); ! } ! HaveModem(); ! LogPrintf(LogDEBUG, "OpenModem: Modem is %s\n", VarDevice); ! } else { ! /* PPP over TCP */ ! cp = strchr(VarDevice, ':'); ! if (cp) { ! *cp = '\0'; ! host = VarDevice; ! port = cp + 1; ! if (*host && *port) { ! modem = OpenConnection(host, port); ! *cp = ':'; /* Don't destroy VarDevice */ ! if (modem < 0) return (-1); ! HaveModem(); ! LogPrintf(LogDEBUG, "OpenModem: Modem is socket %s\n", VarDevice); } else { ! *cp = ':'; /* Don't destroy VarDevice */ ! LogPrintf(LogERROR, "Invalid host:port: \"%s\"\n", VarDevice); return (-1); } - } else { - LogPrintf(LogERROR, - "Device (%s) must be in /dev or be a host:port pair\n", - VarDevice); - return (-1); } } } /* --- 466,527 ---- return modem = 0; } } else { ! strncpy(tmpDeviceList, VarDeviceList, sizeof(tmpDeviceList)); ! tmpDeviceList[sizeof(tmpDeviceList)-1] = '\0'; ! ! for(tmpDevice=strtok(tmpDeviceList, ","); tmpDevice && (modem < 0); ! tmpDevice=strtok(NULL,",")) { ! strncpy(VarDevice, tmpDevice, sizeof(VarDevice)); ! VarDevice[sizeof(VarDevice)-1]= '\0'; ! VarBaseDevice = strrchr(VarDevice, '/'); ! VarBaseDevice = VarBaseDevice ? VarBaseDevice + 1 : ""; ! ! if (strncmp(VarDevice, "/dev/", 5) == 0) { ! if (LockModem() == -1) { ! modem = -1; ! } ! else { ! modem = ID0open(VarDevice, O_RDWR | O_NONBLOCK); ! if (modem < 0) { ! LogPrintf(LogERROR, "OpenModem failed: %s: %s\n", VarDevice, ! strerror(errno)); ! UnlockModem(); ! modem = -1; ! } ! else { ! HaveModem(); ! LogPrintf(LogDEBUG, "OpenModem: Modem is %s\n", VarDevice); ! } ! } ! } else { ! /* PPP over TCP */ ! cp = strchr(VarDevice, ':'); ! if (cp) { ! *cp = '\0'; ! host = VarDevice; ! port = cp + 1; ! if (*host && *port) { ! modem = OpenConnection(host, port); ! *cp = ':'; /* Don't destroy VarDevice */ ! if (modem < 0) ! return (-1); ! HaveModem(); ! LogPrintf(LogDEBUG, "OpenModem: Modem is socket %s\n", VarDevice); ! } else { ! *cp = ':'; /* Don't destroy VarDevice */ ! LogPrintf(LogERROR, "Invalid host:port: \"%s\"\n", VarDevice); return (-1); ! } } else { ! LogPrintf(LogERROR, ! "Device (%s) must be in /dev or be a host:port pair\n", ! VarDevice); return (-1); } } } + + if (modem < 0) return modem; } /* diff -c ./ppp.8 ../ppp/ppp.8 *** ./ppp.8 Wed Dec 17 22:47:42 1997 --- ../ppp/ppp.8 Fri Dec 19 07:45:04 1997 *************** *** 2077,2084 **** .It set ctsrts This sets hardware flow control and is the default. ! .It set device|line value ! This sets the device to which .Nm will talk to the given .Dq value . --- 2077,2084 ---- .It set ctsrts This sets hardware flow control and is the default. ! .It set device|line value[,value...] ! This sets the device(s) to which .Nm will talk to the given .Dq value . *************** *** 2098,2104 **** .Dq port . Refer to the section on .Em PPP OVER TCP ! above for further details. .It set dial chat-script This specifies the chat script that will be used to dial the other --- 2098,2109 ---- .Dq port . Refer to the section on .Em PPP OVER TCP ! above for further details. If multiple ! .Dq values ! are specified, ! .Nm ! will attempt to open each one in turn until it succeeds or runs out of ! devices. .It set dial chat-script This specifies the chat script that will be used to dial the other diff -c ./vars.c ../ppp/vars.c *** ./vars.c Fri Dec 12 18:47:01 1997 --- ../ppp/vars.c Thu Dec 18 22:28:13 1997 *************** *** 73,79 **** struct pppvars pppVars = { DEF_MRU, DEF_MTU, 0, MODEM_SPEED, CS8, MODEM_CTSRTS, 180, 30, 3, RECONNECT_TIMER, RECONNECT_TRIES, REDIAL_PERIOD, ! NEXT_REDIAL_PERIOD, 1, 1, MODEM_DEV, BASE_MODEM_DEV, OPEN_ACTIVE, LOCAL_NO_AUTH, 0 }; --- 73,79 ---- struct pppvars pppVars = { DEF_MRU, DEF_MTU, 0, MODEM_SPEED, CS8, MODEM_CTSRTS, 180, 30, 3, RECONNECT_TIMER, RECONNECT_TRIES, REDIAL_PERIOD, ! NEXT_REDIAL_PERIOD, 1, 1, MODEM_DEV, "", BASE_MODEM_DEV, OPEN_ACTIVE, LOCAL_NO_AUTH, 0 }; diff -c ./vars.h ../ppp/vars.h *** ./vars.h Wed Dec 3 17:28:02 1997 --- ../ppp/vars.h Thu Dec 18 20:49:45 1997 *************** *** 70,75 **** --- 70,76 ---- int redial_next_timeout; /* Redial next timeout value */ int dial_tries; /* Dial attempts before giving up, 0 == inf */ int loopback; /* Turn around packets addressed to me */ + char modem_devlist[500]; /* Comma-separated list of devices */ char modem_dev[40]; /* Name of device / host:port */ const char *base_modem_dev; /* Pointer to base of modem_dev */ int open_mode; /* LCP open mode */ *************** *** 102,107 **** --- 103,109 ---- #define VarMRU pppVars.var_mru #define VarPrefMTU pppVars.pref_mtu #define VarDevice pppVars.modem_dev + #define VarDeviceList pppVars.modem_devlist #define VarBaseDevice pppVars.base_modem_dev #define VarSpeed pppVars.modem_speed #define VarParity pppVars.modem_parity