summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/ipcp.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-12-13 02:37:33 +0000
committerbrian <brian@FreeBSD.org>1997-12-13 02:37:33 +0000
commitb51dc6a0ad3ce435d5255b72124d2220a345c748 (patch)
tree01ae43c4ae528f7d4f3a9b7aaad7063e4c34bc05 /usr.sbin/ppp/ipcp.c
parent982ed8caa2c928574b4adcc4149fb11f323b0f46 (diff)
downloadFreeBSD-src-b51dc6a0ad3ce435d5255b72124d2220a345c748.zip
FreeBSD-src-b51dc6a0ad3ce435d5255b72124d2220a345c748.tar.gz
Allow random IP number allocation to peer.
Validate the peers suggested IP by attempting to make a routing table entry. Give up IPCP negotiation if the peer NAKs us with an unusable IP. Always SIOCDIFADDR then SIOCAIFADDR when configuring the tun device. Using SIOCSIFDSTADDR allows duplicate dst addresses (which we don't want)!!! Allow up to 200 interface names (was 50) (now that ppp can play server properly). Up the version number (1.5 -> 1.6). Cosmetic: Log unexpected CCP packets in the CCP log rather than the ERROR log. Log unexpected Config Reqs in the appropriate LCP/IPCP/CCP log rather than the ERROR log. Log failed route additions and deletions with WARN, not TCPIP. Log the option id and length for unrecognised IPCP options. Change some .Sq to .Ar in the man page.
Diffstat (limited to 'usr.sbin/ppp/ipcp.c')
-rw-r--r--usr.sbin/ppp/ipcp.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index dc91900..624ea88 100644
--- a/usr.sbin/ppp/ipcp.c
+++ b/usr.sbin/ppp/ipcp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ipcp.c,v 1.40 1997/12/04 18:49:35 brian Exp $
+ * $Id: ipcp.c,v 1.41 1997/12/06 22:43:58 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@@ -44,6 +44,7 @@
#include "fsm.h"
#include "lcpproto.h"
#include "lcp.h"
+#include "iplist.h"
#include "ipcp.h"
#include "slcompress.h"
#include "os.h"
@@ -53,6 +54,7 @@
#include "vjcomp.h"
#include "ip.h"
#include "throughput.h"
+#include "route.h"
#ifndef NOMSEXT
struct in_addr ns_entries[2];
@@ -62,6 +64,7 @@ struct in_addr nbns_entries[2];
struct ipcpstate IpcpInfo;
struct in_range DefMyAddress;
struct in_range DefHisAddress;
+struct iplist DefHisChoice;
struct in_addr TriggerAddress;
int HaveTriggerAddress;
@@ -184,6 +187,8 @@ IpcpDefAddress()
void
IpcpInit()
{
+ if (iplist_isvalid(&DefHisChoice))
+ iplist_setrandpos(&DefHisChoice);
FsmInit(&IpcpFsm);
memset(&IpcpInfo, '\0', sizeof(struct ipcpstate));
if ((mode & MODE_DEDICATED) && !GetLabel()) {
@@ -305,7 +310,7 @@ IpcpLayerUp(struct fsm * fp)
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogLINK, " %s hisaddr = %s\n",
tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
- if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask) < 0) {
+ if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr) < 0) {
if (VarTerm)
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
return;
@@ -366,7 +371,7 @@ IpcpDecodeConfig(u_char * cp, int plen, int mode_type)
else if (type > 128 && type < 128 + NCFTYPES128)
snprintf(tbuff, sizeof(tbuff), " %s[%d] ", cftypes128[type-128], length);
else
- snprintf(tbuff, sizeof(tbuff), " ??? ");
+ snprintf(tbuff, sizeof(tbuff), " <%d>[%d] ", type, length);
switch (type) {
case TY_IPADDR: /* RFC1332 */
@@ -376,13 +381,29 @@ IpcpDecodeConfig(u_char * cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
- if (!AcceptableAddr(&DefHisAddress, ipaddr)) {
+ if (iplist_isvalid(&DefHisChoice)) {
+ if (iplist_ip2pos(&DefHisChoice, ipaddr) < 0 ||
+ OsTrySetIpaddress(DefMyAddress.ipaddr, ipaddr) != 0) {
+ LogPrintf(LogIPCP, "%s: Address invalid or already in use\n",
+ inet_ntoa(ipaddr));
+ IpcpInfo.his_ipaddr = ChooseHisAddr(DefMyAddress.ipaddr);
+ if (IpcpInfo.his_ipaddr.s_addr == INADDR_ANY) {
+ memcpy(rejp, cp, length);
+ rejp += length;
+ } else {
+ memcpy(nakp, cp, 2);
+ memcpy(nakp+2, &IpcpInfo.his_ipaddr.s_addr, length - 2);
+ nakp += length;
+ }
+ break;
+ }
+ } else if (!AcceptableAddr(&DefHisAddress, ipaddr)) {
/*
* If destination address is not acceptable, insist to use what we
* want to use.
*/
memcpy(nakp, cp, 2);
- memcpy(nakp+2, &IpcpInfo.his_ipaddr.s_addr, length);
+ memcpy(nakp+2, &IpcpInfo.his_ipaddr.s_addr, length - 2);
nakp += length;
break;
}
@@ -392,14 +413,14 @@ IpcpDecodeConfig(u_char * cp, int plen, int mode_type)
break;
case MODE_NAK:
if (AcceptableAddr(&DefMyAddress, ipaddr)) {
-
- /*
- * Use address suggested by peer.
- */
+ /* Use address suggested by peer */
snprintf(tbuff2, sizeof(tbuff2), "%s changing address: %s ", tbuff,
inet_ntoa(IpcpInfo.want_ipaddr));
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
IpcpInfo.want_ipaddr = ipaddr;
+ } else {
+ LogPrintf(LogIPCP, "%s: Unacceptable address!\n", inet_ntoa(ipaddr));
+ FsmClose(&IpcpFsm);
}
break;
case MODE_REJ:
OpenPOWER on IntegriCloud