Remove MODE_ALIAS and add AliasEnabled() macro.

Remove IsInteractive().
This commit is contained in:
Brian Somers 1998-04-07 23:46:09 +00:00
parent 4a632c808a
commit 85602e5267
10 changed files with 55 additions and 76 deletions

View File

@ -2,7 +2,7 @@
* The code in this file was written by Eivind Eklund <perhaps@yes.no>,
* who places it in the public domain without restriction.
*
* $Id: alias_cmd.c,v 1.12.2.4 1998/04/06 09:12:21 brian Exp $
* $Id: alias_cmd.c,v 1.12.2.5 1998/04/07 00:53:12 brian Exp $
*/
#include <sys/types.h>
@ -15,7 +15,6 @@
#include <string.h>
#include <termios.h>
#include "defs.h"
#include "command.h"
#include "log.h"
#include "loadalias.h"
@ -32,7 +31,7 @@ static int StrToAddrAndPort(const char *, struct in_addr *, u_short *, const cha
int
AliasRedirectPort(struct cmdargs const *arg)
{
if (!(mode & MODE_ALIAS)) {
if (!AliasEnabled()) {
prompt_Printf(arg->prompt, "Alias not enabled\n");
return 1;
} else if (arg->argc == 3) {
@ -93,7 +92,7 @@ AliasRedirectPort(struct cmdargs const *arg)
int
AliasRedirectAddr(struct cmdargs const *arg)
{
if (!(mode & MODE_ALIAS)) {
if (!AliasEnabled()) {
prompt_Printf(arg->prompt, "alias not enabled\n");
return 1;
} else if (arg->argc == 2) {

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.41 1998/04/07 00:53:21 brian Exp $
* $Id: bundle.c,v 1.1.2.42 1998/04/07 01:49:24 brian Exp $
*/
#include <sys/types.h>
@ -553,6 +553,12 @@ bundle_Create(const char *prefix, struct prompt *prompt)
/* Clean out any leftover crud */
bundle_CleanInterface(&bundle);
if (prompt) {
/* Retrospectively introduce ourselves to the prompt */
prompt->bundle = &bundle;
bundle_RegisterDescriptor(&bundle, &prompt->desc);
}
return &bundle;
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.54 1998/04/06 09:12:25 brian Exp $
* $Id: command.c,v 1.131.2.55 1998/04/07 00:53:33 brian Exp $
*
*/
#include <sys/types.h>
@ -144,28 +144,6 @@ HelpCommand(struct cmdargs const *arg)
return 0;
}
int
IsInteractive(struct prompt *prompt)
{
const char *m = NULL;
if (mode & MODE_DDIAL)
m = "direct dial";
else if (mode & MODE_BACKGROUND)
m = "background";
else if (mode & MODE_AUTO)
m = "auto";
else if (mode & MODE_DEDICATED)
m = "dedicated";
else if (mode & MODE_INTER)
m = "interactive";
if (m)
prompt_Printf(prompt, "Working in %s mode\n", m);
return mode & MODE_INTER;
}
static int
CloneCommand(struct cmdargs const *arg)
{
@ -488,7 +466,7 @@ static int
ShowVersion(struct cmdargs const *arg)
{
static char VarVersion[] = "PPP Version 2.0-beta";
static char VarLocalVersion[] = "$Date: 1998/04/06 09:12:38 $";
static char VarLocalVersion[] = "$Date: 1998/04/07 00:53:33 $";
prompt_Printf(arg->prompt, "%s - %s \n", VarVersion, VarLocalVersion);
return 0;
@ -793,9 +771,6 @@ TerminalCommand(struct cmdargs const *arg)
return 1;
}
if (!IsInteractive(arg->prompt))
return (1);
datalink_Up(arg->cx, 0, 0);
prompt_TtyTermMode(arg->prompt, arg->cx);
return 0;
@ -1583,20 +1558,12 @@ AliasEnable(struct cmdargs const *arg)
{
if (arg->argc == 1)
if (strcasecmp(arg->argv[0], "yes") == 0) {
if (!(mode & MODE_ALIAS)) {
if (loadAliasHandlers() == 0) {
mode |= MODE_ALIAS;
return 0;
}
LogPrintf(LogWARN, "Cannot load alias library\n");
return 1;
}
return 0;
if (loadAliasHandlers() == 0)
return 0;
LogPrintf(LogWARN, "Cannot load alias library\n");
return 1;
} else if (strcasecmp(arg->argv[0], "no") == 0) {
if (mode & MODE_ALIAS) {
unloadAliasHandlers();
mode &= ~MODE_ALIAS;
}
unloadAliasHandlers();
return 0;
}
return -1;
@ -1609,13 +1576,13 @@ AliasOption(struct cmdargs const *arg)
unsigned param = (unsigned)arg->cmd->args;
if (arg->argc == 1)
if (strcasecmp(arg->argv[0], "yes") == 0) {
if (mode & MODE_ALIAS) {
if (AliasEnabled()) {
(*PacketAlias.SetMode)(param, param);
return 0;
}
LogPrintf(LogWARN, "alias not enabled\n");
} else if (strcmp(arg->argv[0], "no") == 0) {
if (mode & MODE_ALIAS) {
if (AliasEnabled()) {
(*PacketAlias.SetMode)(0, param);
return 0;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: defs.h,v 1.29.2.9 1998/04/03 19:23:58 brian Exp $
* $Id: defs.h,v 1.29.2.10 1998/04/03 19:25:29 brian Exp $
*
* TODO:
*/
@ -59,8 +59,7 @@
#define MODE_DIRECT 4 /* Direct connection mode */
#define MODE_DEDICATED 8 /* Dedicated line mode */
#define MODE_DDIAL 16 /* Dedicated dialing line mode */
#define MODE_ALIAS 32 /* Packet aliasing (masquerading) */
#define MODE_BACKGROUND 64 /* Background mode. */
#define MODE_BACKGROUND 32 /* Background mode. */
#define MODE_DAEMON (2|4|8|16|64)
#define MODE_OUTGOING_DAEMON (2|8|16|64)

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ip.c,v 1.38.2.19 1998/04/06 09:12:29 brian Exp $
* $Id: ip.c,v 1.38.2.20 1998/04/07 00:53:48 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@ -367,7 +367,7 @@ IpInput(struct bundle *bundle, struct mbuf * bp)
}
#ifndef NOALIAS
if (mode & MODE_ALIAS) {
if (AliasEnabled()) {
struct tun_data *frag;
int iresult;
char *fptr;

View File

@ -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.50.2.32 1998/04/06 09:12:29 brian Exp $
* $Id: ipcp.c,v 1.50.2.33 1998/04/07 00:53:51 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -559,7 +559,7 @@ IpcpLayerUp(struct fsm *fp)
}
#ifndef NOALIAS
if (mode & MODE_ALIAS)
if (AliasEnabled())
(*PacketAlias.SetAddress)(ipcp->my_ip);
#endif

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: loadalias.h,v 1.4 1997/12/21 12:11:06 brian Exp $
* $Id: loadalias.h,v 1.4.2.1 1998/04/07 00:53:59 brian Exp $
*/
struct aliasHandlers {
@ -44,5 +44,6 @@ struct aliasHandlers {
extern struct aliasHandlers PacketAlias;
#define AliasEnabled() (PacketAlias.dl ? 1 : 0)
extern int loadAliasHandlers(void);
extern void unloadAliasHandlers(void);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.45 1998/04/06 09:12:32 brian Exp $
* $Id: main.c,v 1.121.2.46 1998/04/07 00:54:07 brian Exp $
*
* TODO:
*/
@ -36,7 +36,6 @@
#include <termios.h>
#include <unistd.h>
#include "command.h"
#include "mbuf.h"
#include "log.h"
#include "defs.h"
@ -225,9 +224,7 @@ ProcessArgs(int argc, char **argv)
mode &= ~MODE_INTER;
#ifndef NOALIAS
} else if (strcmp(cp, "alias") == 0) {
if (loadAliasHandlers() == 0)
mode |= MODE_ALIAS;
else
if (loadAliasHandlers() != 0)
LogPrintf(LogWARN, "Cannot load alias library\n");
optc--; /* this option isn't exclusive */
#endif
@ -238,12 +235,12 @@ ProcessArgs(int argc, char **argv)
argc--;
}
if (argc > 1) {
fprintf(stderr, "specify only one system label.\n");
fprintf(stderr, "You may specify only one system label.\n");
exit(EX_START);
}
if (optc > 1) {
fprintf(stderr, "specify only one mode.\n");
fprintf(stderr, "You may specify only one mode.\n");
exit(EX_START);
}
@ -296,8 +293,26 @@ main(int argc, char **argv)
/* Allow output for the moment (except in direct mode) */
if (mode & MODE_DIRECT)
prompt = NULL;
else
else {
const char *m;
SignalPrompt = prompt = prompt_Create(NULL, NULL, PROMPT_STD);
if (mode & MODE_DDIAL)
m = "direct dial";
else if (mode & MODE_BACKGROUND)
m = "background";
else if (mode & MODE_AUTO)
m = "auto";
else if (mode & MODE_DEDICATED)
m = "dedicated";
else if (mode & MODE_INTER)
m = "interactive";
else
m = NULL;
if (m)
prompt_Printf(prompt, "Working in %s mode\n", m);
}
ID0init();
if (ID0realuid() != 0) {
@ -330,13 +345,7 @@ main(int argc, char **argv)
LogPrintf(LogWARN, "bundle_Create: %s\n", strerror(errno));
return EX_START;
}
SignalBundle = bundle;
if (prompt) {
prompt->bundle = bundle;
bundle_RegisterDescriptor(bundle, &prompt->desc);
IsInteractive(prompt);
}
if (SelectSystem(bundle, "default", CONFFILE, prompt) < 0)
prompt_Printf(prompt,
@ -563,7 +572,7 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
struct mbuf *bp;
#ifndef NOALIAS
if (mode & MODE_ALIAS) {
if (AliasEnabled()) {
(*PacketAlias.In)(tun.data, sizeof tun.data);
n = ntohs(((struct ip *)tun.data)->ip_len);
}
@ -603,7 +612,7 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
pri = PacketCheck(bundle, tun.data, n, &bundle->filter.out);
if (pri >= 0) {
#ifndef NOALIAS
if (mode & MODE_ALIAS) {
if (AliasEnabled()) {
(*PacketAlias.Out)(tun.data, sizeof tun.data);
n = ntohs(((struct ip *)tun.data)->ip_len);
}

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: prompt.c,v 1.1.2.21 1998/04/05 18:25:33 brian Exp $
* $Id: prompt.c,v 1.1.2.22 1998/04/06 09:12:35 brian Exp $
*/
#include <sys/param.h>
@ -184,7 +184,7 @@ prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
prompt_Required(p);
if (n)
DecodeCommand(bundle, linebuff, n, p,
IsInteractive(NULL) ? NULL : "Client");
(mode & MODE_INTER) ? NULL : "Client");
} else if (n <= 0) {
LogPrintf(LogPHASE, "Client connection closed.\n");
prompt_Destroy(p, 0);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: server.c,v 1.16.2.12 1998/04/06 09:12:36 brian Exp $
* $Id: server.c,v 1.16.2.13 1998/04/07 00:54:17 brian Exp $
*/
#include <sys/types.h>
@ -41,7 +41,6 @@
#include <termios.h>
#include <unistd.h>
#include "command.h"
#include "mbuf.h"
#include "log.h"
#include "defs.h"
@ -143,7 +142,6 @@ server_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
inet_ntoa(sin->sin_addr), sin->sin_port);
break;
}
IsInteractive(p);
prompt_TtyCommandMode(p);
prompt_Required(p);
}