1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP Filter command Interface
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1997-08-31 22:59:49 +00:00
|
|
|
* $Id: filter.c,v 1.13 1997/08/25 00:29:11 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO: Shoud send ICMP error message when we discard packets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
1995-09-17 16:14:49 +00:00
|
|
|
#include <sys/param.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
1995-09-17 16:14:49 +00:00
|
|
|
#include <netdb.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include "command.h"
|
1997-06-09 03:27:43 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "filter.h"
|
1997-06-09 03:27:43 +00:00
|
|
|
#include "loadalias.h"
|
|
|
|
#include "vars.h"
|
1997-06-28 01:34:03 +00:00
|
|
|
#include "ipcp.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static struct filterent filterdata;
|
|
|
|
|
|
|
|
static u_long netmasks[33] = {
|
1997-08-25 00:29:32 +00:00
|
|
|
0x00000000,
|
|
|
|
0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
|
|
|
|
0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
|
|
|
|
0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
|
|
|
|
0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
|
|
|
|
0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
|
|
|
|
0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
|
|
|
|
0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
|
|
|
|
0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF,
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
ParseAddr(int argc,
|
|
|
|
char **argv,
|
|
|
|
struct in_addr * paddr,
|
|
|
|
struct in_addr * pmask,
|
|
|
|
int *pwidth)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int bits;
|
|
|
|
char *cp, *wp;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseAddr: address/mask is expected.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-05-10 01:22:19 +00:00
|
|
|
pmask->s_addr = 0xffffffff; /* Assume 255.255.255.255 as default */
|
1995-01-31 06:29:58 +00:00
|
|
|
cp = index(*argv, '/');
|
1997-08-25 00:29:32 +00:00
|
|
|
if (cp)
|
|
|
|
*cp++ = '\0';
|
1997-06-28 01:34:03 +00:00
|
|
|
if (strcasecmp(*argv, "HISADDR") == 0)
|
|
|
|
*paddr = IpcpInfo.his_ipaddr;
|
|
|
|
else if (strcasecmp(*argv, "MYADDR") == 0)
|
|
|
|
*paddr = IpcpInfo.want_ipaddr;
|
|
|
|
else
|
|
|
|
paddr->s_addr = inet_addr(*argv);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (cp && *cp) {
|
|
|
|
bits = strtol(cp, &wp, 0);
|
|
|
|
if (cp == wp || bits < 0 || bits > 32) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseAddr: bad mask width.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* if width is not given, assume whole 32 bits are meaningfull */
|
|
|
|
bits = 32;
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
*pwidth = bits;
|
|
|
|
pmask->s_addr = htonl(netmasks[bits]);
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
ParseProto(int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int proto;
|
|
|
|
|
|
|
|
if (argc < 1)
|
1997-08-25 00:29:32 +00:00
|
|
|
return (P_NONE);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
if (STREQ(*argv, "tcp"))
|
|
|
|
proto = P_TCP;
|
|
|
|
else if (STREQ(*argv, "udp"))
|
|
|
|
proto = P_UDP;
|
|
|
|
else if (STREQ(*argv, "icmp"))
|
|
|
|
proto = P_ICMP;
|
|
|
|
else
|
|
|
|
proto = P_NONE;
|
1997-08-25 00:29:32 +00:00
|
|
|
return (proto);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1995-09-17 16:14:49 +00:00
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
ParsePort(char *service, int proto)
|
1995-09-17 16:14:49 +00:00
|
|
|
{
|
|
|
|
char *protocol_name, *cp;
|
|
|
|
struct servent *servent;
|
|
|
|
int port;
|
|
|
|
|
|
|
|
switch (proto) {
|
|
|
|
case P_UDP:
|
|
|
|
protocol_name = "udp";
|
|
|
|
break;
|
|
|
|
case P_TCP:
|
|
|
|
protocol_name = "tcp";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
protocol_name = 0;
|
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
servent = getservbyname(service, protocol_name);
|
1995-09-17 16:14:49 +00:00
|
|
|
if (servent != 0)
|
1997-08-25 00:29:32 +00:00
|
|
|
return (ntohs(servent->s_port));
|
1995-09-17 16:14:49 +00:00
|
|
|
|
|
|
|
port = strtol(service, &cp, 0);
|
|
|
|
if (cp == service) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParsePort: %s is not a port name or number.\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
service);
|
|
|
|
return (0);
|
1995-09-17 16:14:49 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
return (port);
|
1995-09-17 16:14:49 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* ICMP Syntax: src eq icmp_message_type
|
|
|
|
*/
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
ParseIcmp(int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 0:
|
|
|
|
/* permit/deny all ICMP types */
|
|
|
|
filterdata.opt.srcop = OP_NONE;
|
|
|
|
break;
|
|
|
|
default:
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseIcmp: bad icmp syntax.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
case 3:
|
|
|
|
if (STREQ(*argv, "src") && STREQ(argv[1], "eq")) {
|
|
|
|
type = strtol(argv[2], &cp, 0);
|
|
|
|
if (cp == argv[2]) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseIcmp: type is expected.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
filterdata.opt.srcop = OP_EQ;
|
|
|
|
filterdata.opt.srcport = type;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
ParseOp(char *cp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int op = OP_NONE;
|
|
|
|
|
|
|
|
if (STREQ(cp, "eq"))
|
|
|
|
op = OP_EQ;
|
|
|
|
else if (STREQ(cp, "gt"))
|
|
|
|
op = OP_GT;
|
|
|
|
else if (STREQ(cp, "lt"))
|
|
|
|
op = OP_LT;
|
1997-08-25 00:29:32 +00:00
|
|
|
return (op);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* UDP Syntax: [src op port] [dst op port]
|
|
|
|
*/
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
ParseUdpOrTcp(int argc, char **argv, int proto)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
if (argc == 0) {
|
|
|
|
/* permit/deny all tcp traffic */
|
|
|
|
filterdata.opt.srcop = filterdata.opt.dstop = A_NONE;
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
if (argc < 3) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseUdpOrTcp: bad udp/tcp syntax.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-09-17 16:14:49 +00:00
|
|
|
if (argc >= 3 && STREQ(*argv, "src")) {
|
1995-01-31 06:29:58 +00:00
|
|
|
filterdata.opt.srcop = ParseOp(argv[1]);
|
|
|
|
if (filterdata.opt.srcop == OP_NONE) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseUdpOrTcp: bad operation\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-09-17 16:14:49 +00:00
|
|
|
filterdata.opt.srcport = ParsePort(argv[2], proto);
|
|
|
|
if (filterdata.opt.srcport == 0)
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
|
|
|
argc -= 3;
|
|
|
|
argv += 3;
|
1995-01-31 06:29:58 +00:00
|
|
|
if (argc == 0)
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
if (argc >= 3 && STREQ(argv[0], "dst")) {
|
|
|
|
filterdata.opt.dstop = ParseOp(argv[1]);
|
|
|
|
if (filterdata.opt.dstop == OP_NONE) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseUdpOrTcp: bad operation\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-09-17 16:14:49 +00:00
|
|
|
filterdata.opt.dstport = ParsePort(argv[2], proto);
|
|
|
|
if (filterdata.opt.dstport == 0)
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
|
|
|
argc -= 3;
|
|
|
|
argv += 3;
|
1995-09-17 16:14:49 +00:00
|
|
|
if (argc == 0)
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-09-17 16:14:49 +00:00
|
|
|
}
|
|
|
|
if (argc == 1) {
|
|
|
|
if (STREQ(*argv, "estab")) {
|
|
|
|
filterdata.opt.estab = 1;
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseUdpOrTcp: estab is expected: %s\n", *argv);
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-09-17 16:14:49 +00:00
|
|
|
}
|
|
|
|
if (argc > 0)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "ParseUdpOrTcp: bad src/dst port syntax: %s\n", *argv);
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
char *opname[] = {"none", "eq", "gt", "lt"};
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
Parse(int argc, char **argv, struct filterent * ofp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int action, proto;
|
|
|
|
int val;
|
|
|
|
char *wp;
|
|
|
|
struct filterent *fp = &filterdata;
|
|
|
|
|
|
|
|
val = strtol(*argv, &wp, 0);
|
|
|
|
if (*argv == wp || val > MAXFILTERS) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Parse: invalid filter number.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
if (val < 0) {
|
|
|
|
for (val = 0; val < MAXFILTERS; val++) {
|
|
|
|
ofp->action = A_NONE;
|
|
|
|
ofp++;
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Parse: filter cleared.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
ofp += val;
|
|
|
|
|
|
|
|
if (--argc == 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Parse: missing action.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
|
|
|
|
proto = P_NONE;
|
|
|
|
bzero(&filterdata, sizeof(filterdata));
|
|
|
|
|
|
|
|
if (STREQ(*argv, "permit")) {
|
|
|
|
action = A_PERMIT;
|
|
|
|
} else if (STREQ(*argv, "deny")) {
|
|
|
|
action = A_DENY;
|
|
|
|
} else if (STREQ(*argv, "clear")) {
|
|
|
|
ofp->action = A_NONE;
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Parse: bad action: %s\n", *argv);
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
fp->action = action;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-07-27 23:26:23 +00:00
|
|
|
if (fp->action == A_DENY) {
|
1995-01-31 06:29:58 +00:00
|
|
|
if (STREQ(*argv, "host")) {
|
|
|
|
fp->action |= A_UHOST;
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else if (STREQ(*argv, "port")) {
|
|
|
|
fp->action |= A_UPORT;
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
1995-02-22 06:44:03 +00:00
|
|
|
proto = ParseProto(argc, argv);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (proto == P_NONE) {
|
|
|
|
if (ParseAddr(argc, argv, &fp->saddr, &fp->smask, &fp->swidth)) {
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
proto = ParseProto(argc, argv);
|
|
|
|
if (proto == P_NONE) {
|
|
|
|
if (ParseAddr(argc, argv, &fp->daddr, &fp->dmask, &fp->dwidth)) {
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
proto = ParseProto(argc, argv);
|
1995-02-26 12:18:08 +00:00
|
|
|
if (proto) {
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
1997-07-27 23:26:23 +00:00
|
|
|
} else {
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Parse: Address/protocol expected.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
1997-08-25 00:29:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val = 1;
|
1995-02-22 06:44:03 +00:00
|
|
|
fp->proto = proto;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (proto) {
|
|
|
|
case P_TCP:
|
1995-09-17 16:14:49 +00:00
|
|
|
val = ParseUdpOrTcp(argc, argv, P_TCP);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case P_UDP:
|
1995-09-17 16:14:49 +00:00
|
|
|
val = ParseUdpOrTcp(argc, argv, P_UDP);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case P_ICMP:
|
|
|
|
val = ParseIcmp(argc, argv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1997-08-31 22:59:49 +00:00
|
|
|
LogPrintf(LogDEBUG, "Parse: Src: %s\n", inet_ntoa(fp->saddr));
|
|
|
|
LogPrintf(LogDEBUG, "Parse: Src mask: %s\n", inet_ntoa(fp->smask));
|
|
|
|
LogPrintf(LogDEBUG, "Parse: Dst: %s\n", inet_ntoa(fp->daddr));
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "Parse: Dst mask: %s\n", inet_ntoa(fp->dmask));
|
|
|
|
LogPrintf(LogDEBUG, "Parse: Proto = %d\n", proto);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "Parse: src: %s (%d)\n", opname[fp->opt.srcop],
|
|
|
|
fp->opt.srcport);
|
|
|
|
LogPrintf(LogDEBUG, "Parse: dst: %s (%d)\n", opname[fp->opt.dstop],
|
|
|
|
fp->opt.dstport);
|
|
|
|
LogPrintf(LogDEBUG, "Parse: estab: %d\n", fp->opt.estab);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
if (val)
|
|
|
|
*ofp = *fp;
|
1997-08-25 00:29:32 +00:00
|
|
|
return (val);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetIfilter(struct cmdtab * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc > 0) {
|
1995-01-31 06:29:58 +00:00
|
|
|
(void) Parse(argc, argv, ifilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetOfilter(struct cmdtab * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc > 0) {
|
1995-01-31 06:29:58 +00:00
|
|
|
(void) Parse(argc, argv, ofilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetDfilter(struct cmdtab * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc > 0) {
|
1995-01-31 06:29:58 +00:00
|
|
|
(void) Parse(argc, argv, dfilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetAfilter(struct cmdtab * list, int argc, char **argv)
|
1995-02-26 12:18:08 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc > 0) {
|
1995-02-26 12:18:08 +00:00
|
|
|
(void) Parse(argc, argv, afilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
static char *protoname[] = {
|
|
|
|
"none", "tcp", "udp", "icmp",
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *actname[] = {
|
|
|
|
"none ", "permit ", "deny ",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
ShowFilter(struct filterent * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
for (n = 0; n < MAXFILTERS; n++, fp++) {
|
|
|
|
if (fp->action != A_NONE) {
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "%2d %s", n, actname[fp->action]);
|
|
|
|
fprintf(VarTerm, "%s/%d ", inet_ntoa(fp->saddr), fp->swidth);
|
|
|
|
fprintf(VarTerm, "%s/%d ", inet_ntoa(fp->daddr), fp->dwidth);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (fp->proto) {
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "%s", protoname[fp->proto]);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
if (fp->opt.srcop)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " src %s %d", opname[fp->opt.srcop],
|
1997-08-25 00:29:32 +00:00
|
|
|
fp->opt.srcport);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (fp->opt.dstop)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " dst %s %d", opname[fp->opt.dstop],
|
1997-08-25 00:29:32 +00:00
|
|
|
fp->opt.dstport);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (fp->opt.estab)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " estab");
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
ShowIfilter(struct cmdtab * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
ShowFilter(ifilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
ShowOfilter(struct cmdtab * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
ShowFilter(ofilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
ShowDfilter(struct cmdtab * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
ShowFilter(dfilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-02-26 12:18:08 +00:00
|
|
|
|
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
ShowAfilter(struct cmdtab * list, int argc, char **argv)
|
1995-02-26 12:18:08 +00:00
|
|
|
{
|
|
|
|
ShowFilter(afilters);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|