2005-04-25 18:20:15 +00:00
|
|
|
/* $FreeBSD$ */
|
2005-04-25 17:31:50 +00:00
|
|
|
|
2007-06-04 02:54:36 +00:00
|
|
|
/*
|
2013-08-11 14:28:45 +00:00
|
|
|
* Copyright (C) 2012 by Darren Reed.
|
2007-06-04 02:54:36 +00:00
|
|
|
*
|
|
|
|
* See the IPFILTER.LICENCE file for details on licencing.
|
|
|
|
*/
|
2005-04-25 17:31:50 +00:00
|
|
|
%{
|
|
|
|
#include "ipf.h"
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <syslog.h>
|
2017-04-16 04:36:22 +00:00
|
|
|
#include <err.h>
|
2005-04-25 17:31:50 +00:00
|
|
|
#ifdef IPFILTER_BPF
|
|
|
|
# include <pcap.h>
|
|
|
|
#endif
|
|
|
|
#include "netinet/ip_pool.h"
|
|
|
|
#include "netinet/ip_htable.h"
|
|
|
|
#include "netinet/ipl.h"
|
|
|
|
#include "ipf_l.h"
|
|
|
|
|
|
|
|
#define YYDEBUG 1
|
|
|
|
#define DOALL(x) for (fr = frc; fr != NULL; fr = fr->fr_next) { x }
|
|
|
|
#define DOREM(x) for (; fr != NULL; fr = fr->fr_next) { x }
|
|
|
|
|
2021-01-26 06:24:28 +00:00
|
|
|
extern void yyerror(char *);
|
|
|
|
extern int yyparse(void);
|
|
|
|
extern int yylex(void);
|
2005-04-25 17:31:50 +00:00
|
|
|
extern int yydebug;
|
|
|
|
extern FILE *yyin;
|
|
|
|
extern int yylineNum;
|
|
|
|
|
2021-01-26 06:24:28 +00:00
|
|
|
static int addname(frentry_t **, char *);
|
|
|
|
static frentry_t *addrule(void);
|
|
|
|
static frentry_t *allocfr(void);
|
|
|
|
static void build_dstaddr_af(frentry_t *, void *);
|
|
|
|
static void build_srcaddr_af(frentry_t *, void *);
|
|
|
|
static void dobpf(int, char *);
|
|
|
|
static void doipfexpr(char *);
|
|
|
|
static void do_tuneint(char *, int);
|
|
|
|
static void do_tunestr(char *, char *);
|
|
|
|
static void fillgroup(frentry_t *);
|
|
|
|
static int lookuphost(char *, i6addr_t *);
|
|
|
|
static u_int makehash(struct alist_s *);
|
|
|
|
static int makepool(struct alist_s *);
|
|
|
|
static struct alist_s *newalist(struct alist_s *);
|
|
|
|
static void newrule(void);
|
|
|
|
static void resetaddr(void);
|
|
|
|
static void setgroup(frentry_t **, char *);
|
|
|
|
static void setgrhead(frentry_t **, char *);
|
|
|
|
static void seticmphead(frentry_t **, char *);
|
|
|
|
static void setifname(frentry_t **, int, char *);
|
|
|
|
static void setipftype(void);
|
|
|
|
static void setsyslog(void);
|
|
|
|
static void unsetsyslog(void);
|
2005-04-25 17:31:50 +00:00
|
|
|
|
|
|
|
frentry_t *fr = NULL, *frc = NULL, *frtop = NULL, *frold = NULL;
|
|
|
|
|
|
|
|
static int ifpflag = 0;
|
|
|
|
static int nowith = 0;
|
|
|
|
static int dynamic = -1;
|
|
|
|
static int pooled = 0;
|
|
|
|
static int hashed = 0;
|
|
|
|
static int nrules = 0;
|
|
|
|
static int newlist = 0;
|
|
|
|
static int added = 0;
|
|
|
|
static int ipffd = -1;
|
2013-08-11 14:28:45 +00:00
|
|
|
static int *yycont = NULL;
|
|
|
|
static ioctlfunc_t ipfioctls[IPL_LOGSIZE];
|
2005-04-25 17:31:50 +00:00
|
|
|
static addfunc_t ipfaddfunc = NULL;
|
|
|
|
|
|
|
|
%}
|
|
|
|
%union {
|
|
|
|
char *str;
|
|
|
|
u_32_t num;
|
|
|
|
frentry_t fr;
|
|
|
|
frtuc_t *frt;
|
|
|
|
struct alist_s *alist;
|
|
|
|
u_short port;
|
2013-08-11 14:28:45 +00:00
|
|
|
struct in_addr ip4;
|
2005-04-25 17:31:50 +00:00
|
|
|
struct {
|
|
|
|
u_short p1;
|
|
|
|
u_short p2;
|
|
|
|
int pc;
|
|
|
|
} pc;
|
2013-08-11 14:28:45 +00:00
|
|
|
struct ipp_s {
|
|
|
|
int type;
|
|
|
|
int ifpos;
|
|
|
|
int f;
|
|
|
|
int v;
|
|
|
|
int lif;
|
2005-04-25 17:31:50 +00:00
|
|
|
union i6addr a;
|
|
|
|
union i6addr m;
|
2013-08-11 14:28:45 +00:00
|
|
|
char *name;
|
2005-04-25 17:31:50 +00:00
|
|
|
} ipp;
|
2013-08-11 14:28:45 +00:00
|
|
|
struct {
|
|
|
|
i6addr_t adr;
|
|
|
|
int f;
|
|
|
|
} adr;
|
|
|
|
i6addr_t ip6;
|
2006-08-16 12:23:02 +00:00
|
|
|
struct {
|
|
|
|
char *if1;
|
|
|
|
char *if2;
|
|
|
|
} ifs;
|
2013-08-11 14:28:45 +00:00
|
|
|
char gname[FR_GROUPLEN];
|
2005-04-25 17:31:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
%type <port> portnum
|
|
|
|
%type <num> facility priority icmpcode seclevel secname icmptype
|
|
|
|
%type <num> opt compare range opttype flagset optlist ipv6hdrlist ipv6hdr
|
2013-08-11 14:28:45 +00:00
|
|
|
%type <num> portc porteq ipmask maskopts
|
|
|
|
%type <ip4> ipv4 ipv4_16 ipv4_24
|
|
|
|
%type <adr> hostname
|
2005-04-25 17:31:50 +00:00
|
|
|
%type <ipp> addr ipaddr
|
2013-08-11 14:28:45 +00:00
|
|
|
%type <str> servicename name interfacename groupname
|
2005-04-25 17:31:50 +00:00
|
|
|
%type <pc> portrange portcomp
|
|
|
|
%type <alist> addrlist poollist
|
2006-08-16 12:23:02 +00:00
|
|
|
%type <ifs> onname
|
2005-04-25 17:31:50 +00:00
|
|
|
|
|
|
|
%token <num> YY_NUMBER YY_HEX
|
|
|
|
%token <str> YY_STR
|
|
|
|
%token YY_COMMENT
|
|
|
|
%token YY_CMP_EQ YY_CMP_NE YY_CMP_LE YY_CMP_GE YY_CMP_LT YY_CMP_GT
|
|
|
|
%token YY_RANGE_OUT YY_RANGE_IN
|
|
|
|
%token <ip6> YY_IPV6
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_SET
|
2006-08-16 12:23:02 +00:00
|
|
|
%token IPFY_PASS IPFY_BLOCK IPFY_COUNT IPFY_CALL IPFY_NOMATCH
|
2005-04-25 17:31:50 +00:00
|
|
|
%token IPFY_RETICMP IPFY_RETRST IPFY_RETICMPASDST
|
|
|
|
%token IPFY_IN IPFY_OUT
|
|
|
|
%token IPFY_QUICK IPFY_ON IPFY_OUTVIA IPFY_INVIA
|
|
|
|
%token IPFY_DUPTO IPFY_TO IPFY_FROUTE IPFY_REPLY_TO IPFY_ROUTETO
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_TOS IPFY_TTL IPFY_PROTO IPFY_INET IPFY_INET6
|
2005-04-25 17:31:50 +00:00
|
|
|
%token IPFY_HEAD IPFY_GROUP
|
|
|
|
%token IPFY_AUTH IPFY_PREAUTH
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_LOG IPFY_BODY IPFY_FIRST IPFY_LEVEL IPFY_ORBLOCK IPFY_L5AS
|
|
|
|
%token IPFY_LOGTAG IPFY_MATCHTAG IPFY_SETTAG IPFY_SKIP IPFY_DECAPS
|
2005-04-25 17:31:50 +00:00
|
|
|
%token IPFY_FROM IPFY_ALL IPFY_ANY IPFY_BPFV4 IPFY_BPFV6 IPFY_POOL IPFY_HASH
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_IPFEXPR IPFY_PPS IPFY_FAMILY IPFY_DSTLIST
|
2005-04-25 17:31:50 +00:00
|
|
|
%token IPFY_ESP IPFY_AH
|
|
|
|
%token IPFY_WITH IPFY_AND IPFY_NOT IPFY_NO IPFY_OPT
|
|
|
|
%token IPFY_TCPUDP IPFY_TCP IPFY_UDP
|
|
|
|
%token IPFY_FLAGS IPFY_MULTICAST
|
|
|
|
%token IPFY_MASK IPFY_BROADCAST IPFY_NETWORK IPFY_NETMASKED IPFY_PEER
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_RPC IPFY_PORT
|
|
|
|
%token IPFY_NOW IPFY_COMMENT IPFY_RULETTL
|
2005-04-25 17:31:50 +00:00
|
|
|
%token IPFY_ICMP IPFY_ICMPTYPE IPFY_ICMPCODE
|
|
|
|
%token IPFY_IPOPTS IPFY_SHORT IPFY_NAT IPFY_BADSRC IPFY_LOWTTL IPFY_FRAG
|
|
|
|
%token IPFY_MBCAST IPFY_BAD IPFY_BADNAT IPFY_OOW IPFY_NEWISN IPFY_NOICMPERR
|
|
|
|
%token IPFY_KEEP IPFY_STATE IPFY_FRAGS IPFY_LIMIT IPFY_STRICT IPFY_AGE
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_SYNC IPFY_FRAGBODY IPFY_ICMPHEAD IPFY_NOLOG IPFY_LOOSE
|
|
|
|
%token IPFY_MAX_SRCS IPFY_MAX_PER_SRC
|
2005-04-25 17:31:50 +00:00
|
|
|
%token IPFY_IPOPT_NOP IPFY_IPOPT_RR IPFY_IPOPT_ZSU IPFY_IPOPT_MTUP
|
|
|
|
%token IPFY_IPOPT_MTUR IPFY_IPOPT_ENCODE IPFY_IPOPT_TS IPFY_IPOPT_TR
|
|
|
|
%token IPFY_IPOPT_SEC IPFY_IPOPT_LSRR IPFY_IPOPT_ESEC IPFY_IPOPT_CIPSO
|
|
|
|
%token IPFY_IPOPT_SATID IPFY_IPOPT_SSRR IPFY_IPOPT_ADDEXT IPFY_IPOPT_VISA
|
|
|
|
%token IPFY_IPOPT_IMITD IPFY_IPOPT_EIP IPFY_IPOPT_FINN IPFY_IPOPT_DPS
|
|
|
|
%token IPFY_IPOPT_SDB IPFY_IPOPT_NSAPA IPFY_IPOPT_RTRALRT IPFY_IPOPT_UMP
|
|
|
|
%token IPFY_SECCLASS IPFY_SEC_UNC IPFY_SEC_CONF IPFY_SEC_RSV1 IPFY_SEC_RSV2
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_SEC_RSV4 IPFY_SEC_SEC IPFY_SEC_TS IPFY_SEC_RSV3 IPFY_DOI
|
2005-04-25 17:31:50 +00:00
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
%token IPFY_V6HDRS IPFY_IPV6OPT IPFY_IPV6OPT_DSTOPTS IPFY_IPV6OPT_HOPOPTS
|
|
|
|
%token IPFY_IPV6OPT_IPV6 IPFY_IPV6OPT_NONE IPFY_IPV6OPT_ROUTING IPFY_V6HDR
|
2005-12-30 11:52:26 +00:00
|
|
|
%token IPFY_IPV6OPT_MOBILITY IPFY_IPV6OPT_ESP IPFY_IPV6OPT_FRAG
|
2005-04-25 17:31:50 +00:00
|
|
|
|
|
|
|
%token IPFY_ICMPT_UNR IPFY_ICMPT_ECHO IPFY_ICMPT_ECHOR IPFY_ICMPT_SQUENCH
|
|
|
|
%token IPFY_ICMPT_REDIR IPFY_ICMPT_TIMEX IPFY_ICMPT_PARAMP IPFY_ICMPT_TIMEST
|
|
|
|
%token IPFY_ICMPT_TIMESTREP IPFY_ICMPT_INFOREQ IPFY_ICMPT_INFOREP
|
|
|
|
%token IPFY_ICMPT_MASKREQ IPFY_ICMPT_MASKREP IPFY_ICMPT_ROUTERAD
|
|
|
|
%token IPFY_ICMPT_ROUTERSOL
|
|
|
|
|
|
|
|
%token IPFY_ICMPC_NETUNR IPFY_ICMPC_HSTUNR IPFY_ICMPC_PROUNR IPFY_ICMPC_PORUNR
|
|
|
|
%token IPFY_ICMPC_NEEDF IPFY_ICMPC_SRCFAIL IPFY_ICMPC_NETUNK IPFY_ICMPC_HSTUNK
|
|
|
|
%token IPFY_ICMPC_ISOLATE IPFY_ICMPC_NETPRO IPFY_ICMPC_HSTPRO
|
|
|
|
%token IPFY_ICMPC_NETTOS IPFY_ICMPC_HSTTOS IPFY_ICMPC_FLTPRO IPFY_ICMPC_HSTPRE
|
|
|
|
%token IPFY_ICMPC_CUTPRE
|
|
|
|
|
|
|
|
%token IPFY_FAC_KERN IPFY_FAC_USER IPFY_FAC_MAIL IPFY_FAC_DAEMON IPFY_FAC_AUTH
|
|
|
|
%token IPFY_FAC_SYSLOG IPFY_FAC_LPR IPFY_FAC_NEWS IPFY_FAC_UUCP IPFY_FAC_CRON
|
|
|
|
%token IPFY_FAC_LOCAL0 IPFY_FAC_LOCAL1 IPFY_FAC_LOCAL2 IPFY_FAC_LOCAL3
|
|
|
|
%token IPFY_FAC_LOCAL4 IPFY_FAC_LOCAL5 IPFY_FAC_LOCAL6 IPFY_FAC_LOCAL7
|
|
|
|
%token IPFY_FAC_SECURITY IPFY_FAC_FTP IPFY_FAC_AUTHPRIV IPFY_FAC_AUDIT
|
|
|
|
%token IPFY_FAC_LFMT IPFY_FAC_CONSOLE
|
|
|
|
|
|
|
|
%token IPFY_PRI_EMERG IPFY_PRI_ALERT IPFY_PRI_CRIT IPFY_PRI_ERR IPFY_PRI_WARN
|
|
|
|
%token IPFY_PRI_NOTICE IPFY_PRI_INFO IPFY_PRI_DEBUG
|
|
|
|
%%
|
2013-08-11 14:28:45 +00:00
|
|
|
file: settings rules
|
|
|
|
| rules
|
|
|
|
;
|
|
|
|
|
|
|
|
settings:
|
|
|
|
YY_COMMENT
|
|
|
|
| setting
|
|
|
|
| settings setting
|
|
|
|
;
|
|
|
|
|
|
|
|
rules: line
|
2005-04-25 17:31:50 +00:00
|
|
|
| assign
|
2013-08-11 14:28:45 +00:00
|
|
|
| rules line
|
|
|
|
| rules assign
|
|
|
|
;
|
|
|
|
|
|
|
|
setting:
|
|
|
|
IPFY_SET YY_STR YY_NUMBER ';' { do_tuneint($2, $3); }
|
|
|
|
| IPFY_SET YY_STR YY_HEX ';' { do_tuneint($2, $3); }
|
|
|
|
| IPFY_SET YY_STR YY_STR ';' { do_tunestr($2, $3); }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
2007-06-04 02:54:36 +00:00
|
|
|
line: rule { while ((fr = frtop) != NULL) {
|
2005-04-25 17:31:50 +00:00
|
|
|
frtop = fr->fr_next;
|
|
|
|
fr->fr_next = NULL;
|
2013-08-11 14:28:45 +00:00
|
|
|
if ((fr->fr_type == FR_T_IPF) &&
|
|
|
|
(fr->fr_ip.fi_v == 0))
|
|
|
|
fr->fr_mip.fi_v = 0;
|
|
|
|
/* XXX validate ? */
|
|
|
|
(*ipfaddfunc)(ipffd, ipfioctls[IPL_LOGIPF], fr);
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_next = frold;
|
|
|
|
frold = fr;
|
|
|
|
}
|
|
|
|
resetlexer();
|
|
|
|
}
|
|
|
|
| YY_COMMENT
|
|
|
|
;
|
|
|
|
|
2006-08-16 12:23:02 +00:00
|
|
|
xx: { newrule(); }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
assign: YY_STR assigning YY_STR ';' { set_variable($1, $3);
|
|
|
|
resetlexer();
|
|
|
|
free($1);
|
|
|
|
free($3);
|
2007-06-04 02:54:36 +00:00
|
|
|
yyvarnext = 0;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
assigning:
|
|
|
|
'=' { yyvarnext = 1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
rule: inrule eol
|
|
|
|
| outrule eol
|
|
|
|
;
|
|
|
|
|
|
|
|
eol: | ';'
|
|
|
|
;
|
|
|
|
|
|
|
|
inrule:
|
|
|
|
rulehead markin inopts rulemain ruletail intag ruletail2
|
|
|
|
;
|
|
|
|
|
|
|
|
outrule:
|
|
|
|
rulehead markout outopts rulemain ruletail outtag ruletail2
|
|
|
|
;
|
|
|
|
|
|
|
|
rulehead:
|
2007-06-04 02:54:36 +00:00
|
|
|
xx collection action
|
|
|
|
| xx insert collection action
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
markin: IPFY_IN { fr->fr_flags |= FR_INQUE; }
|
|
|
|
;
|
|
|
|
|
|
|
|
markout:
|
|
|
|
IPFY_OUT { fr->fr_flags |= FR_OUTQUE; }
|
|
|
|
;
|
|
|
|
|
|
|
|
rulemain:
|
|
|
|
ipfrule
|
|
|
|
| bpfrule
|
2013-08-11 14:28:45 +00:00
|
|
|
| exprrule
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
ipfrule:
|
2013-08-11 14:28:45 +00:00
|
|
|
family tos ttl proto ip
|
|
|
|
;
|
|
|
|
|
|
|
|
family: | IPFY_FAMILY IPFY_INET { if (use_inet6 == 1) {
|
|
|
|
YYERROR;
|
|
|
|
} else {
|
|
|
|
frc->fr_family = AF_INET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| IPFY_INET { if (use_inet6 == 1) {
|
|
|
|
YYERROR;
|
|
|
|
} else {
|
|
|
|
frc->fr_family = AF_INET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| IPFY_FAMILY IPFY_INET6 { if (use_inet6 == -1) {
|
|
|
|
YYERROR;
|
|
|
|
} else {
|
|
|
|
frc->fr_family = AF_INET6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| IPFY_INET6 { if (use_inet6 == -1) {
|
|
|
|
YYERROR;
|
|
|
|
} else {
|
|
|
|
frc->fr_family = AF_INET6;
|
|
|
|
}
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
bpfrule:
|
|
|
|
IPFY_BPFV4 '{' YY_STR '}' { dobpf(4, $3); free($3); }
|
|
|
|
| IPFY_BPFV6 '{' YY_STR '}' { dobpf(6, $3); free($3); }
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
exprrule:
|
|
|
|
IPFY_IPFEXPR '{' YY_STR '}' { doipfexpr($3); }
|
|
|
|
;
|
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
ruletail:
|
|
|
|
with keep head group
|
|
|
|
;
|
|
|
|
|
|
|
|
ruletail2:
|
2013-08-11 14:28:45 +00:00
|
|
|
pps age new rulettl comment
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
intag: settagin matchtagin
|
|
|
|
;
|
|
|
|
|
|
|
|
outtag: settagout matchtagout
|
|
|
|
;
|
|
|
|
|
|
|
|
insert:
|
|
|
|
'@' YY_NUMBER { fr->fr_hits = (U_QUAD_T)$2 + 1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
collection:
|
|
|
|
| YY_NUMBER { fr->fr_collect = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
action: block
|
|
|
|
| IPFY_PASS { fr->fr_flags |= FR_PASS; }
|
2006-08-16 12:23:02 +00:00
|
|
|
| IPFY_NOMATCH { fr->fr_flags |= FR_NOMATCH; }
|
2005-04-25 17:31:50 +00:00
|
|
|
| log
|
|
|
|
| IPFY_COUNT { fr->fr_flags |= FR_ACCOUNT; }
|
2013-08-11 14:28:45 +00:00
|
|
|
| decaps { fr->fr_flags |= FR_DECAPSULATE; }
|
2005-04-25 17:31:50 +00:00
|
|
|
| auth
|
|
|
|
| IPFY_SKIP YY_NUMBER { fr->fr_flags |= FR_SKIP;
|
|
|
|
fr->fr_arg = $2; }
|
|
|
|
| IPFY_CALL func
|
|
|
|
| IPFY_CALL IPFY_NOW func { fr->fr_flags |= FR_CALLNOW; }
|
|
|
|
;
|
|
|
|
|
|
|
|
block: blocked
|
|
|
|
| blocked blockreturn
|
|
|
|
;
|
|
|
|
|
|
|
|
blocked:
|
|
|
|
IPFY_BLOCK { fr->fr_flags = FR_BLOCK; }
|
|
|
|
;
|
|
|
|
blockreturn:
|
|
|
|
IPFY_RETICMP { fr->fr_flags |= FR_RETICMP; }
|
|
|
|
| IPFY_RETICMP returncode { fr->fr_flags |= FR_RETICMP; }
|
|
|
|
| IPFY_RETICMPASDST { fr->fr_flags |= FR_FAKEICMP; }
|
|
|
|
| IPFY_RETICMPASDST returncode { fr->fr_flags |= FR_FAKEICMP; }
|
|
|
|
| IPFY_RETRST { fr->fr_flags |= FR_RETRST; }
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
decaps: IPFY_DECAPS
|
|
|
|
| IPFY_DECAPS IPFY_L5AS '(' YY_STR ')'
|
|
|
|
{ fr->fr_icode = atoi($4); }
|
|
|
|
;
|
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
log: IPFY_LOG { fr->fr_flags |= FR_LOG; }
|
|
|
|
| IPFY_LOG logoptions { fr->fr_flags |= FR_LOG; }
|
|
|
|
;
|
|
|
|
|
|
|
|
auth: IPFY_AUTH { fr->fr_flags |= FR_AUTH; }
|
2006-08-16 12:23:02 +00:00
|
|
|
| IPFY_AUTH blockreturn { fr->fr_flags |= FR_AUTH;}
|
2005-04-25 17:31:50 +00:00
|
|
|
| IPFY_PREAUTH { fr->fr_flags |= FR_PREAUTH; }
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
func: YY_STR '/' YY_NUMBER
|
|
|
|
{ fr->fr_func = nametokva($1, ipfioctls[IPL_LOGIPF]);
|
|
|
|
fr->fr_arg = $3;
|
|
|
|
free($1);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
inopts:
|
|
|
|
| inopts inopt
|
|
|
|
;
|
|
|
|
|
|
|
|
inopt:
|
|
|
|
logopt
|
|
|
|
| quick
|
|
|
|
| on
|
|
|
|
| dup
|
|
|
|
| froute
|
|
|
|
| proute
|
|
|
|
| replyto
|
|
|
|
;
|
|
|
|
|
|
|
|
outopts:
|
|
|
|
| outopts outopt
|
|
|
|
;
|
|
|
|
|
|
|
|
outopt:
|
|
|
|
logopt
|
|
|
|
| quick
|
|
|
|
| on
|
|
|
|
| dup
|
|
|
|
| proute
|
2013-08-11 14:28:45 +00:00
|
|
|
| froute
|
2005-04-25 17:31:50 +00:00
|
|
|
| replyto
|
|
|
|
;
|
|
|
|
|
|
|
|
tos: | settos YY_NUMBER { DOALL(fr->fr_tos = $2; fr->fr_mtos = 0xff;) }
|
|
|
|
| settos YY_HEX { DOALL(fr->fr_tos = $2; fr->fr_mtos = 0xff;) }
|
|
|
|
| settos lstart toslist lend
|
|
|
|
;
|
|
|
|
|
|
|
|
settos: IPFY_TOS { setipftype(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
toslist:
|
|
|
|
YY_NUMBER { DOALL(fr->fr_tos = $1; fr->fr_mtos = 0xff;) }
|
|
|
|
| YY_HEX { DOREM(fr->fr_tos = $1; fr->fr_mtos = 0xff;) }
|
|
|
|
| toslist lmore YY_NUMBER
|
|
|
|
{ DOREM(fr->fr_tos = $3; fr->fr_mtos = 0xff;) }
|
2013-08-11 14:28:45 +00:00
|
|
|
| toslist lmore YY_HEX
|
2005-04-25 17:31:50 +00:00
|
|
|
{ DOREM(fr->fr_tos = $3; fr->fr_mtos = 0xff;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
ttl: | setttl YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_ttl = $2; fr->fr_mttl = 0xff;) }
|
|
|
|
| setttl lstart ttllist lend
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
lstart: '{' { newlist = 1; fr = frc; added = 0; }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
lend: '}' { nrules += added; }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
lmore: lanother { if (newlist == 1) {
|
|
|
|
newlist = 0;
|
|
|
|
}
|
|
|
|
fr = addrule();
|
|
|
|
if (yycont != NULL)
|
|
|
|
*yycont = 1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
lanother:
|
|
|
|
| ','
|
|
|
|
;
|
|
|
|
|
|
|
|
setttl: IPFY_TTL { setipftype(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
ttllist:
|
|
|
|
YY_NUMBER { DOREM(fr->fr_ttl = $1; fr->fr_mttl = 0xff;) }
|
|
|
|
| ttllist lmore YY_NUMBER
|
|
|
|
{ DOREM(fr->fr_ttl = $3; fr->fr_mttl = 0xff;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
proto: | protox protocol { yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
protox: IPFY_PROTO { setipftype();
|
|
|
|
fr = frc;
|
|
|
|
yysetdict(NULL); }
|
|
|
|
;
|
|
|
|
|
|
|
|
ip: srcdst flags icmp
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
group: | IPFY_GROUP groupname { DOALL(setgroup(&fr, $2); \
|
|
|
|
fillgroup(fr););
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
head: | IPFY_HEAD groupname { DOALL(setgrhead(&fr, $2););
|
|
|
|
free($2);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
groupname:
|
|
|
|
YY_STR { $$ = $1;
|
|
|
|
if (strlen($$) >= FR_GROUPLEN)
|
|
|
|
$$[FR_GROUPLEN - 1] = '\0';
|
|
|
|
}
|
|
|
|
| YY_NUMBER { $$ = malloc(16);
|
|
|
|
sprintf($$, "%d", $1);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
settagin:
|
|
|
|
| IPFY_SETTAG '(' taginlist ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
taginlist:
|
|
|
|
taginspec
|
|
|
|
| taginlist ',' taginspec
|
|
|
|
;
|
|
|
|
|
|
|
|
taginspec:
|
|
|
|
logtag
|
|
|
|
;
|
|
|
|
|
|
|
|
nattag: IPFY_NAT '=' YY_STR { DOALL(strncpy(fr->fr_nattag.ipt_tag,\
|
|
|
|
$3, IPFTAG_LEN););
|
|
|
|
free($3); }
|
|
|
|
| IPFY_NAT '=' YY_NUMBER { DOALL(sprintf(fr->fr_nattag.ipt_tag,\
|
|
|
|
"%d", $3 & 0xffffffff);) }
|
|
|
|
;
|
|
|
|
|
|
|
|
logtag: IPFY_LOG '=' YY_NUMBER { DOALL(fr->fr_logtag = $3;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
settagout:
|
|
|
|
| IPFY_SETTAG '(' tagoutlist ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
tagoutlist:
|
|
|
|
tagoutspec
|
|
|
|
| tagoutlist ',' tagoutspec
|
|
|
|
;
|
|
|
|
|
|
|
|
tagoutspec:
|
|
|
|
logtag
|
|
|
|
| nattag
|
|
|
|
;
|
|
|
|
|
|
|
|
matchtagin:
|
|
|
|
| IPFY_MATCHTAG '(' tagoutlist ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
matchtagout:
|
|
|
|
| IPFY_MATCHTAG '(' taginlist ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
pps: | IPFY_PPS YY_NUMBER { DOALL(fr->fr_pps = $2;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
new: | savegroup file restoregroup
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
rulettl:
|
|
|
|
| IPFY_RULETTL YY_NUMBER { DOALL(fr->fr_die = $2;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
comment:
|
|
|
|
| IPFY_COMMENT YY_STR { DOALL(fr->fr_comment = addname(&fr, \
|
|
|
|
$2);) }
|
|
|
|
;
|
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
savegroup:
|
|
|
|
'{'
|
|
|
|
;
|
|
|
|
|
|
|
|
restoregroup:
|
|
|
|
'}'
|
|
|
|
;
|
|
|
|
|
|
|
|
logopt: log
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
quick: IPFY_QUICK { fr->fr_flags |= FR_QUICK; }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
on: IPFY_ON onname { setifname(&fr, 0, $2.if1);
|
|
|
|
free($2.if1);
|
|
|
|
if ($2.if2 != NULL) {
|
|
|
|
setifname(&fr, 1,
|
|
|
|
$2.if2);
|
|
|
|
free($2.if2);
|
|
|
|
}
|
|
|
|
}
|
2006-08-16 12:23:02 +00:00
|
|
|
| IPFY_ON lstart onlist lend
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_ON onname IPFY_INVIA vianame { setifname(&fr, 0, $2.if1);
|
|
|
|
free($2.if1);
|
|
|
|
if ($2.if2 != NULL) {
|
|
|
|
setifname(&fr, 1,
|
|
|
|
$2.if2);
|
|
|
|
free($2.if2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| IPFY_ON onname IPFY_OUTVIA vianame { setifname(&fr, 0, $2.if1);
|
|
|
|
free($2.if1);
|
|
|
|
if ($2.if2 != NULL) {
|
|
|
|
setifname(&fr, 1,
|
|
|
|
$2.if2);
|
|
|
|
free($2.if2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
onlist: onname { DOREM(setifname(&fr, 0, $1.if1); \
|
|
|
|
if ($1.if2 != NULL) \
|
|
|
|
setifname(&fr, 1, $1.if2); \
|
|
|
|
)
|
|
|
|
free($1.if1);
|
|
|
|
if ($1.if2 != NULL)
|
|
|
|
free($1.if2);
|
|
|
|
}
|
|
|
|
| onlist lmore onname { DOREM(setifname(&fr, 0, $3.if1); \
|
|
|
|
if ($3.if2 != NULL) \
|
|
|
|
setifname(&fr, 1, $3.if2); \
|
|
|
|
)
|
|
|
|
free($3.if1);
|
|
|
|
if ($3.if2 != NULL)
|
|
|
|
free($3.if2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
onname: interfacename { $$.if1 = $1;
|
|
|
|
$$.if2 = NULL;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| interfacename ',' interfacename
|
2013-08-11 14:28:45 +00:00
|
|
|
{ $$.if1 = $1;
|
|
|
|
$$.if2 = $3;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
vianame:
|
2013-08-11 14:28:45 +00:00
|
|
|
name { setifname(&fr, 2, $1);
|
|
|
|
free($1);
|
|
|
|
}
|
|
|
|
| name ',' name { setifname(&fr, 2, $1);
|
|
|
|
free($1);
|
|
|
|
setifname(&fr, 3, $3);
|
|
|
|
free($3);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
dup: IPFY_DUPTO name
|
2013-08-11 14:28:45 +00:00
|
|
|
{ int idx = addname(&fr, $2);
|
|
|
|
fr->fr_dif.fd_name = idx;
|
2005-04-25 17:31:50 +00:00
|
|
|
free($2);
|
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_DUPTO IPFY_DSTLIST '/' name
|
|
|
|
{ int idx = addname(&fr, $4);
|
|
|
|
fr->fr_dif.fd_name = idx;
|
|
|
|
fr->fr_dif.fd_type = FRD_DSTLIST;
|
|
|
|
free($4);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_DUPTO name duptoseparator hostname
|
|
|
|
{ int idx = addname(&fr, $2);
|
|
|
|
fr->fr_dif.fd_name = idx;
|
|
|
|
fr->fr_dif.fd_ptr = (void *)-1;
|
|
|
|
fr->fr_dif.fd_ip6 = $4.adr;
|
|
|
|
if (fr->fr_family == AF_UNSPEC && $4.f != AF_UNSPEC)
|
|
|
|
fr->fr_family = $4.f;
|
2005-04-25 17:31:50 +00:00
|
|
|
yyexpectaddr = 0;
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
duptoseparator:
|
|
|
|
':' { yyexpectaddr = 1; yycont = &yyexpectaddr; resetaddr(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
froute: IPFY_FROUTE { fr->fr_flags |= FR_FASTROUTE; }
|
|
|
|
;
|
|
|
|
|
|
|
|
proute: routeto name
|
2013-08-11 14:28:45 +00:00
|
|
|
{ int idx = addname(&fr, $2);
|
|
|
|
fr->fr_tif.fd_name = idx;
|
2005-04-25 17:31:50 +00:00
|
|
|
free($2);
|
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
| routeto IPFY_DSTLIST '/' name
|
|
|
|
{ int idx = addname(&fr, $4);
|
|
|
|
fr->fr_tif.fd_name = idx;
|
|
|
|
fr->fr_tif.fd_type = FRD_DSTLIST;
|
|
|
|
free($4);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
| routeto name duptoseparator hostname
|
|
|
|
{ int idx = addname(&fr, $2);
|
|
|
|
fr->fr_tif.fd_name = idx;
|
|
|
|
fr->fr_tif.fd_ptr = (void *)-1;
|
|
|
|
fr->fr_tif.fd_ip6 = $4.adr;
|
|
|
|
if (fr->fr_family == AF_UNSPEC && $4.f != AF_UNSPEC)
|
|
|
|
fr->fr_family = $4.f;
|
2005-04-25 17:31:50 +00:00
|
|
|
yyexpectaddr = 0;
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
routeto:
|
|
|
|
IPFY_TO
|
|
|
|
| IPFY_ROUTETO
|
|
|
|
;
|
|
|
|
|
|
|
|
replyto:
|
|
|
|
IPFY_REPLY_TO name
|
2013-08-11 14:28:45 +00:00
|
|
|
{ int idx = addname(&fr, $2);
|
|
|
|
fr->fr_rif.fd_name = idx;
|
2005-04-25 17:31:50 +00:00
|
|
|
free($2);
|
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_REPLY_TO IPFY_DSTLIST '/' name
|
|
|
|
{ fr->fr_rif.fd_name = addname(&fr, $4);
|
|
|
|
fr->fr_rif.fd_type = FRD_DSTLIST;
|
|
|
|
free($4);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| IPFY_REPLY_TO name duptoseparator hostname
|
2013-08-11 14:28:45 +00:00
|
|
|
{ int idx = addname(&fr, $2);
|
|
|
|
fr->fr_rif.fd_name = idx;
|
|
|
|
fr->fr_rif.fd_ptr = (void *)-1;
|
|
|
|
fr->fr_rif.fd_ip6 = $4.adr;
|
|
|
|
if (fr->fr_family == AF_UNSPEC && $4.f != AF_UNSPEC)
|
|
|
|
fr->fr_family = $4.f;
|
2005-04-25 17:31:50 +00:00
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
logoptions:
|
|
|
|
logoption
|
|
|
|
| logoptions logoption
|
|
|
|
;
|
|
|
|
|
|
|
|
logoption:
|
|
|
|
IPFY_BODY { fr->fr_flags |= FR_LOGBODY; }
|
|
|
|
| IPFY_FIRST { fr->fr_flags |= FR_LOGFIRST; }
|
|
|
|
| IPFY_ORBLOCK { fr->fr_flags |= FR_LOGORBLOCK; }
|
|
|
|
| level loglevel { unsetsyslog(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
returncode:
|
|
|
|
starticmpcode icmpcode ')' { fr->fr_icode = $2; yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
starticmpcode:
|
|
|
|
'(' { yysetdict(icmpcodewords); }
|
|
|
|
;
|
|
|
|
|
|
|
|
srcdst: | IPFY_ALL
|
|
|
|
| fromto
|
|
|
|
;
|
|
|
|
|
|
|
|
protocol:
|
2013-08-11 14:28:45 +00:00
|
|
|
YY_NUMBER { DOALL(fr->fr_proto = $1; \
|
|
|
|
fr->fr_mproto = 0xff;)
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| YY_STR { if (!strcmp($1, "tcp-udp")) {
|
2013-08-11 14:28:45 +00:00
|
|
|
DOALL(fr->fr_flx |= FI_TCPUDP; \
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_mflx |= FI_TCPUDP;)
|
|
|
|
} else {
|
|
|
|
int p = getproto($1);
|
|
|
|
if (p == -1)
|
|
|
|
yyerror("protocol unknown");
|
2013-08-11 14:28:45 +00:00
|
|
|
DOALL(fr->fr_proto = p; \
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_mproto = 0xff;)
|
|
|
|
}
|
|
|
|
free($1);
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| YY_STR nextstring YY_STR
|
|
|
|
{ if (!strcmp($1, "tcp") &&
|
|
|
|
!strcmp($3, "udp")) {
|
|
|
|
DOREM(fr->fr_flx |= FI_TCPUDP; \
|
|
|
|
fr->fr_mflx |= FI_TCPUDP;)
|
2013-08-11 14:28:45 +00:00
|
|
|
} else {
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
free($1);
|
|
|
|
free($3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
nextstring:
|
|
|
|
'/' { yysetdict(NULL); }
|
|
|
|
;
|
|
|
|
|
|
|
|
fromto: from srcobject to dstobject { yyexpectaddr = 0; yycont = NULL; }
|
|
|
|
| to dstobject { yyexpectaddr = 0; yycont = NULL; }
|
|
|
|
| from srcobject { yyexpectaddr = 0; yycont = NULL; }
|
|
|
|
;
|
|
|
|
|
|
|
|
from: IPFY_FROM { setipftype();
|
|
|
|
if (fr == NULL)
|
|
|
|
fr = frc;
|
|
|
|
yyexpectaddr = 1;
|
|
|
|
if (yydebug)
|
|
|
|
printf("set yyexpectaddr\n");
|
|
|
|
yycont = &yyexpectaddr;
|
|
|
|
yysetdict(addrwords);
|
|
|
|
resetaddr(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
to: IPFY_TO { if (fr == NULL)
|
|
|
|
fr = frc;
|
|
|
|
yyexpectaddr = 1;
|
|
|
|
if (yydebug)
|
|
|
|
printf("set yyexpectaddr\n");
|
|
|
|
yycont = &yyexpectaddr;
|
|
|
|
yysetdict(addrwords);
|
2013-08-11 14:28:45 +00:00
|
|
|
resetaddr();
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
with: | andwith withlist
|
|
|
|
;
|
|
|
|
|
|
|
|
andwith:
|
|
|
|
IPFY_WITH { nowith = 0; setipftype(); }
|
|
|
|
| IPFY_AND { nowith = 0; setipftype(); }
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
flags: | startflags flagset
|
2005-04-25 17:31:50 +00:00
|
|
|
{ DOALL(fr->fr_tcpf = $2; fr->fr_tcpfm = FR_TCPFMAX;) }
|
|
|
|
| startflags flagset '/' flagset
|
|
|
|
{ DOALL(fr->fr_tcpf = $2; fr->fr_tcpfm = $4;) }
|
|
|
|
| startflags '/' flagset
|
|
|
|
{ DOALL(fr->fr_tcpf = 0; fr->fr_tcpfm = $3;) }
|
|
|
|
| startflags YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_tcpf = $2; fr->fr_tcpfm = FR_TCPFMAX;) }
|
|
|
|
| startflags '/' YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_tcpf = 0; fr->fr_tcpfm = $3;) }
|
|
|
|
| startflags YY_NUMBER '/' YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_tcpf = $2; fr->fr_tcpfm = $4;) }
|
|
|
|
| startflags flagset '/' YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_tcpf = $2; fr->fr_tcpfm = $4;) }
|
|
|
|
| startflags YY_NUMBER '/' flagset
|
|
|
|
{ DOALL(fr->fr_tcpf = $2; fr->fr_tcpfm = $4;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
startflags:
|
|
|
|
IPFY_FLAGS { if (frc->fr_type != FR_T_IPF)
|
|
|
|
yyerror("flags with non-ipf type rule");
|
|
|
|
if (frc->fr_proto != IPPROTO_TCP)
|
|
|
|
yyerror("flags with non-TCP rule");
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
flagset:
|
|
|
|
YY_STR { $$ = tcpflags($1); free($1); }
|
|
|
|
| YY_HEX { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
srcobject:
|
|
|
|
{ yyresetdict(); } fromport
|
|
|
|
| srcaddr srcport
|
|
|
|
| '!' srcaddr srcport
|
|
|
|
{ DOALL(fr->fr_flags |= FR_NOTSRCIP;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
srcaddr:
|
2013-08-11 14:28:45 +00:00
|
|
|
addr { build_srcaddr_af(fr, &$1); }
|
2005-04-25 17:31:50 +00:00
|
|
|
| lstart srcaddrlist lend
|
|
|
|
;
|
|
|
|
|
|
|
|
srcaddrlist:
|
2013-08-11 14:28:45 +00:00
|
|
|
addr { build_srcaddr_af(fr, &$1); }
|
2005-04-25 17:31:50 +00:00
|
|
|
| srcaddrlist lmore addr
|
2013-08-11 14:28:45 +00:00
|
|
|
{ build_srcaddr_af(fr, &$3); }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
srcport:
|
|
|
|
| portcomp
|
|
|
|
{ DOALL(fr->fr_scmp = $1.pc; fr->fr_sport = $1.p1;) }
|
|
|
|
| portrange
|
|
|
|
{ DOALL(fr->fr_scmp = $1.pc; fr->fr_sport = $1.p1; \
|
|
|
|
fr->fr_stop = $1.p2;) }
|
|
|
|
| porteq lstart srcportlist lend
|
|
|
|
{ yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
fromport:
|
|
|
|
portcomp
|
|
|
|
{ DOALL(fr->fr_scmp = $1.pc; fr->fr_sport = $1.p1;) }
|
|
|
|
| portrange
|
|
|
|
{ DOALL(fr->fr_scmp = $1.pc; fr->fr_sport = $1.p1; \
|
|
|
|
fr->fr_stop = $1.p2;) }
|
|
|
|
| porteq lstart srcportlist lend
|
|
|
|
{ yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
srcportlist:
|
|
|
|
portnum { DOREM(fr->fr_scmp = FR_EQUAL; fr->fr_sport = $1;) }
|
2013-08-11 14:28:45 +00:00
|
|
|
| portnum ':' portnum
|
2007-10-18 21:52:14 +00:00
|
|
|
{ DOREM(fr->fr_scmp = FR_INCRANGE; fr->fr_sport = $1; \
|
|
|
|
fr->fr_stop = $3;) }
|
2013-08-11 14:28:45 +00:00
|
|
|
| portnum YY_RANGE_IN portnum
|
2007-10-18 21:52:14 +00:00
|
|
|
{ DOREM(fr->fr_scmp = FR_INRANGE; fr->fr_sport = $1; \
|
|
|
|
fr->fr_stop = $3;) }
|
2005-04-25 17:31:50 +00:00
|
|
|
| srcportlist lmore portnum
|
|
|
|
{ DOREM(fr->fr_scmp = FR_EQUAL; fr->fr_sport = $3;) }
|
2007-10-18 21:52:14 +00:00
|
|
|
| srcportlist lmore portnum ':' portnum
|
|
|
|
{ DOREM(fr->fr_scmp = FR_INCRANGE; fr->fr_sport = $3; \
|
|
|
|
fr->fr_stop = $5;) }
|
|
|
|
| srcportlist lmore portnum YY_RANGE_IN portnum
|
|
|
|
{ DOREM(fr->fr_scmp = FR_INRANGE; fr->fr_sport = $3; \
|
|
|
|
fr->fr_stop = $5;) }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
dstobject:
|
|
|
|
{ yyresetdict(); } toport
|
|
|
|
| dstaddr dstport
|
|
|
|
| '!' dstaddr dstport
|
|
|
|
{ DOALL(fr->fr_flags |= FR_NOTDSTIP;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
dstaddr:
|
2013-08-11 14:28:45 +00:00
|
|
|
addr { if (($1.f != AF_UNSPEC) && (frc->fr_family != AF_UNSPEC) &&
|
|
|
|
($1.f != frc->fr_family))
|
|
|
|
yyerror("1.src/dst address family mismatch");
|
|
|
|
build_dstaddr_af(fr, &$1);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
| lstart dstaddrlist lend
|
|
|
|
;
|
|
|
|
|
|
|
|
dstaddrlist:
|
2013-08-11 14:28:45 +00:00
|
|
|
addr { if (($1.f != AF_UNSPEC) && (frc->fr_family != AF_UNSPEC) &&
|
|
|
|
($1.f != frc->fr_family))
|
|
|
|
yyerror("2.src/dst address family mismatch");
|
|
|
|
build_dstaddr_af(fr, &$1);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
| dstaddrlist lmore addr
|
2013-08-11 14:28:45 +00:00
|
|
|
{ if (($3.f != AF_UNSPEC) && (frc->fr_family != AF_UNSPEC) &&
|
|
|
|
($3.f != frc->fr_family))
|
|
|
|
yyerror("3.src/dst address family mismatch");
|
|
|
|
build_dstaddr_af(fr, &$3);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
dstport:
|
|
|
|
| portcomp
|
|
|
|
{ DOALL(fr->fr_dcmp = $1.pc; fr->fr_dport = $1.p1;) }
|
|
|
|
| portrange
|
|
|
|
{ DOALL(fr->fr_dcmp = $1.pc; fr->fr_dport = $1.p1; \
|
|
|
|
fr->fr_dtop = $1.p2;) }
|
|
|
|
| porteq lstart dstportlist lend
|
|
|
|
{ yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
toport:
|
|
|
|
portcomp
|
|
|
|
{ DOALL(fr->fr_dcmp = $1.pc; fr->fr_dport = $1.p1;) }
|
|
|
|
| portrange
|
|
|
|
{ DOALL(fr->fr_dcmp = $1.pc; fr->fr_dport = $1.p1; \
|
|
|
|
fr->fr_dtop = $1.p2;) }
|
|
|
|
| porteq lstart dstportlist lend
|
|
|
|
{ yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
dstportlist:
|
|
|
|
portnum { DOREM(fr->fr_dcmp = FR_EQUAL; fr->fr_dport = $1;) }
|
2013-08-11 14:28:45 +00:00
|
|
|
| portnum ':' portnum
|
2007-10-18 21:52:14 +00:00
|
|
|
{ DOREM(fr->fr_dcmp = FR_INCRANGE; fr->fr_dport = $1; \
|
|
|
|
fr->fr_dtop = $3;) }
|
2013-08-11 14:28:45 +00:00
|
|
|
| portnum YY_RANGE_IN portnum
|
2007-10-18 21:52:14 +00:00
|
|
|
{ DOREM(fr->fr_dcmp = FR_INRANGE; fr->fr_dport = $1; \
|
|
|
|
fr->fr_dtop = $3;) }
|
2005-04-25 17:31:50 +00:00
|
|
|
| dstportlist lmore portnum
|
|
|
|
{ DOREM(fr->fr_dcmp = FR_EQUAL; fr->fr_dport = $3;) }
|
2007-10-18 21:52:14 +00:00
|
|
|
| dstportlist lmore portnum ':' portnum
|
|
|
|
{ DOREM(fr->fr_dcmp = FR_INCRANGE; fr->fr_dport = $3; \
|
|
|
|
fr->fr_dtop = $5;) }
|
|
|
|
| dstportlist lmore portnum YY_RANGE_IN portnum
|
|
|
|
{ DOREM(fr->fr_dcmp = FR_INRANGE; fr->fr_dport = $3; \
|
|
|
|
fr->fr_dtop = $5;) }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
addr: pool '/' YY_NUMBER { pooled = 1;
|
2013-08-11 14:28:45 +00:00
|
|
|
yyexpectaddr = 0;
|
|
|
|
$$.type = FRI_LOOKUP;
|
|
|
|
$$.v = 0;
|
|
|
|
$$.ifpos = -1;
|
|
|
|
$$.f = AF_UNSPEC;
|
2005-04-25 17:31:50 +00:00
|
|
|
$$.a.iplookuptype = IPLT_POOL;
|
2007-06-04 02:54:36 +00:00
|
|
|
$$.a.iplookupsubtype = 0;
|
2005-04-25 17:31:50 +00:00
|
|
|
$$.a.iplookupnum = $3; }
|
2007-06-04 02:54:36 +00:00
|
|
|
| pool '/' YY_STR { pooled = 1;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.ifpos = -1;
|
|
|
|
$$.f = AF_UNSPEC;
|
|
|
|
$$.type = FRI_LOOKUP;
|
2007-06-04 02:54:36 +00:00
|
|
|
$$.a.iplookuptype = IPLT_POOL;
|
|
|
|
$$.a.iplookupsubtype = 1;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.a.iplookupname = addname(&fr, $3);
|
|
|
|
}
|
|
|
|
| pool '=' '(' { yyexpectaddr = 1;
|
|
|
|
pooled = 1;
|
2007-06-04 02:54:36 +00:00
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
poollist ')' { yyexpectaddr = 0;
|
|
|
|
$$.v = 0;
|
|
|
|
$$.ifpos = -1;
|
|
|
|
$$.f = AF_UNSPEC;
|
|
|
|
$$.type = FRI_LOOKUP;
|
2005-04-25 17:31:50 +00:00
|
|
|
$$.a.iplookuptype = IPLT_POOL;
|
2007-06-04 02:54:36 +00:00
|
|
|
$$.a.iplookupsubtype = 0;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.a.iplookupnum = makepool($5);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| hash '/' YY_NUMBER { hashed = 1;
|
2013-08-11 14:28:45 +00:00
|
|
|
yyexpectaddr = 0;
|
|
|
|
$$.v = 0;
|
|
|
|
$$.ifpos = -1;
|
|
|
|
$$.f = AF_UNSPEC;
|
|
|
|
$$.type = FRI_LOOKUP;
|
2005-04-25 17:31:50 +00:00
|
|
|
$$.a.iplookuptype = IPLT_HASH;
|
2007-06-04 02:54:36 +00:00
|
|
|
$$.a.iplookupsubtype = 0;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.a.iplookupnum = $3;
|
|
|
|
}
|
|
|
|
| hash '/' YY_STR { hashed = 1;
|
|
|
|
$$.type = FRI_LOOKUP;
|
|
|
|
$$.v = 0;
|
|
|
|
$$.ifpos = -1;
|
|
|
|
$$.f = AF_UNSPEC;
|
2007-06-04 02:54:36 +00:00
|
|
|
$$.a.iplookuptype = IPLT_HASH;
|
|
|
|
$$.a.iplookupsubtype = 1;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.a.iplookupname = addname(&fr, $3);
|
|
|
|
}
|
|
|
|
| hash '=' '(' { hashed = 1;
|
|
|
|
yyexpectaddr = 1;
|
2007-06-04 02:54:36 +00:00
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
addrlist ')' { yyexpectaddr = 0;
|
|
|
|
$$.v = 0;
|
|
|
|
$$.ifpos = -1;
|
|
|
|
$$.f = AF_UNSPEC;
|
|
|
|
$$.type = FRI_LOOKUP;
|
2005-04-25 17:31:50 +00:00
|
|
|
$$.a.iplookuptype = IPLT_HASH;
|
2007-06-04 02:54:36 +00:00
|
|
|
$$.a.iplookupsubtype = 0;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.a.iplookupnum = makehash($5);
|
|
|
|
}
|
|
|
|
| ipaddr { $$ = $1;
|
2005-04-25 17:31:50 +00:00
|
|
|
yyexpectaddr = 0; }
|
|
|
|
;
|
|
|
|
|
2014-09-22 16:13:38 +00:00
|
|
|
ipaddr: IPFY_ANY { memset(&($$), 0, sizeof($$));
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.type = FRI_NORMAL;
|
|
|
|
$$.ifpos = -1;
|
|
|
|
yyexpectaddr = 0;
|
|
|
|
}
|
2014-09-22 16:13:38 +00:00
|
|
|
| hostname { memset(&($$), 0, sizeof($$));
|
|
|
|
$$.a = $1.adr;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.f = $1.f;
|
|
|
|
if ($1.f == AF_INET6)
|
|
|
|
fill6bits(128, $$.m.i6);
|
|
|
|
else if ($1.f == AF_INET)
|
|
|
|
fill6bits(32, $$.m.i6);
|
|
|
|
$$.v = ftov($1.f);
|
|
|
|
$$.ifpos = dynamic;
|
|
|
|
$$.type = FRI_NORMAL;
|
|
|
|
}
|
|
|
|
| hostname { yyresetdict(); }
|
|
|
|
maskspace { yysetdict(maskwords);
|
|
|
|
yyexpectaddr = 2; }
|
2014-09-22 16:13:38 +00:00
|
|
|
ipmask { memset(&($$), 0, sizeof($$));
|
|
|
|
ntomask($1.f, $5, $$.m.i6);
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.a = $1.adr;
|
|
|
|
$$.a.i6[0] &= $$.m.i6[0];
|
|
|
|
$$.a.i6[1] &= $$.m.i6[1];
|
|
|
|
$$.a.i6[2] &= $$.m.i6[2];
|
|
|
|
$$.a.i6[3] &= $$.m.i6[3];
|
|
|
|
$$.f = $1.f;
|
|
|
|
$$.v = ftov($1.f);
|
|
|
|
$$.type = ifpflag;
|
|
|
|
$$.ifpos = dynamic;
|
|
|
|
if (ifpflag != 0 && $$.v == 0) {
|
|
|
|
if (frc->fr_family == AF_INET6){
|
|
|
|
$$.v = 6;
|
|
|
|
$$.f = AF_INET6;
|
|
|
|
} else {
|
|
|
|
$$.v = 4;
|
|
|
|
$$.f = AF_INET;
|
|
|
|
}
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
yyresetdict();
|
2013-08-11 14:28:45 +00:00
|
|
|
yyexpectaddr = 0;
|
|
|
|
}
|
2014-09-22 16:13:38 +00:00
|
|
|
| '(' YY_STR ')' { memset(&($$), 0, sizeof($$));
|
|
|
|
$$.type = FRI_DYNAMIC;
|
2013-08-11 14:28:45 +00:00
|
|
|
ifpflag = FRI_DYNAMIC;
|
|
|
|
$$.ifpos = addname(&fr, $2);
|
|
|
|
$$.lif = 0;
|
|
|
|
}
|
|
|
|
| '(' YY_STR ')' '/'
|
|
|
|
{ ifpflag = FRI_DYNAMIC; yysetdict(maskwords); }
|
|
|
|
maskopts
|
2014-09-22 16:13:38 +00:00
|
|
|
{ memset(&($$), 0, sizeof($$));
|
|
|
|
$$.type = ifpflag;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.ifpos = addname(&fr, $2);
|
|
|
|
$$.lif = 0;
|
|
|
|
if (frc->fr_family == AF_UNSPEC)
|
|
|
|
frc->fr_family = AF_INET;
|
|
|
|
if (ifpflag == FRI_DYNAMIC) {
|
|
|
|
ntomask(frc->fr_family,
|
|
|
|
$6, $$.m.i6);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
yyresetdict();
|
2013-08-11 14:28:45 +00:00
|
|
|
yyexpectaddr = 0;
|
|
|
|
}
|
|
|
|
| '(' YY_STR ':' YY_NUMBER ')' '/'
|
|
|
|
{ ifpflag = FRI_DYNAMIC; yysetdict(maskwords); }
|
|
|
|
maskopts
|
2014-09-22 16:13:38 +00:00
|
|
|
{ memset(&($$), 0, sizeof($$));
|
|
|
|
$$.type = ifpflag;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.ifpos = addname(&fr, $2);
|
|
|
|
$$.lif = $4;
|
|
|
|
if (frc->fr_family == AF_UNSPEC)
|
|
|
|
frc->fr_family = AF_INET;
|
|
|
|
if (ifpflag == FRI_DYNAMIC) {
|
|
|
|
ntomask(frc->fr_family,
|
|
|
|
$8, $$.m.i6);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
yyresetdict();
|
2013-08-11 14:28:45 +00:00
|
|
|
yyexpectaddr = 0;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
2013-08-11 14:28:45 +00:00
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
maskspace:
|
|
|
|
'/'
|
|
|
|
| IPFY_MASK
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
ipmask: ipv4 { $$ = count4bits($1.s_addr); }
|
|
|
|
| YY_HEX { $$ = count4bits(htonl($1)); }
|
|
|
|
| YY_NUMBER { $$ = $1; }
|
|
|
|
| YY_IPV6 { $$ = count6bits($1.i6); }
|
|
|
|
| maskopts { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
maskopts:
|
|
|
|
IPFY_BROADCAST { if (ifpflag == FRI_DYNAMIC) {
|
2005-04-25 17:31:50 +00:00
|
|
|
ifpflag = FRI_BROADCAST;
|
2013-08-11 14:28:45 +00:00
|
|
|
} else {
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
|
|
|
$$ = 0;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
| IPFY_NETWORK { if (ifpflag == FRI_DYNAMIC) {
|
|
|
|
ifpflag = FRI_NETWORK;
|
2013-08-11 14:28:45 +00:00
|
|
|
} else {
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
|
|
|
$$ = 0;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
| IPFY_NETMASKED { if (ifpflag == FRI_DYNAMIC) {
|
|
|
|
ifpflag = FRI_NETMASKED;
|
2013-08-11 14:28:45 +00:00
|
|
|
} else {
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
|
|
|
$$ = 0;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
| IPFY_PEER { if (ifpflag == FRI_DYNAMIC) {
|
|
|
|
ifpflag = FRI_PEERADDR;
|
2013-08-11 14:28:45 +00:00
|
|
|
} else {
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
|
|
|
$$ = 0;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
| YY_NUMBER { $$ = $1; }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
hostname:
|
2014-09-22 16:13:38 +00:00
|
|
|
ipv4 { memset(&($$), 0, sizeof($$));
|
|
|
|
$$.adr.in4 = $1;
|
2013-08-11 14:28:45 +00:00
|
|
|
if (frc->fr_family == AF_INET6)
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.f = AF_INET;
|
|
|
|
yyexpectaddr = 2;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
2014-09-22 16:13:38 +00:00
|
|
|
| YY_NUMBER { memset(&($$), 0, sizeof($$));
|
|
|
|
if (frc->fr_family == AF_INET6)
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.adr.in4_addr = $1;
|
|
|
|
$$.f = AF_INET;
|
|
|
|
yyexpectaddr = 2;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
2014-09-22 16:13:38 +00:00
|
|
|
| YY_HEX { memset(&($$), 0, sizeof($$));
|
|
|
|
if (frc->fr_family == AF_INET6)
|
2005-04-25 17:31:50 +00:00
|
|
|
YYERROR;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.adr.in4_addr = $1;
|
|
|
|
$$.f = AF_INET;
|
|
|
|
yyexpectaddr = 2;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
2014-09-22 16:13:38 +00:00
|
|
|
| YY_STR { memset(&($$), 0, sizeof($$));
|
|
|
|
if (lookuphost($1, &$$.adr) == 0)
|
2013-08-11 14:28:45 +00:00
|
|
|
$$.f = AF_INET;
|
2005-04-25 17:31:50 +00:00
|
|
|
free($1);
|
2013-08-11 14:28:45 +00:00
|
|
|
yyexpectaddr = 2;
|
|
|
|
}
|
2014-09-22 16:13:38 +00:00
|
|
|
| YY_IPV6 { memset(&($$), 0, sizeof($$));
|
|
|
|
if (frc->fr_family == AF_INET)
|
2013-08-11 14:28:45 +00:00
|
|
|
YYERROR;
|
|
|
|
$$.adr = $1;
|
|
|
|
$$.f = AF_INET6;
|
|
|
|
yyexpectaddr = 2;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
addrlist:
|
|
|
|
ipaddr { $$ = newalist(NULL);
|
2013-08-11 14:28:45 +00:00
|
|
|
$$->al_family = $1.f;
|
|
|
|
$$->al_i6addr = $1.a;
|
|
|
|
$$->al_i6mask = $1.m;
|
|
|
|
}
|
|
|
|
| ipaddr ',' { yyexpectaddr = 1; } addrlist
|
|
|
|
{ $$ = newalist($4);
|
|
|
|
$$->al_family = $1.f;
|
|
|
|
$$->al_i6addr = $1.a;
|
|
|
|
$$->al_i6mask = $1.m;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
pool: IPFY_POOL { yyexpectaddr = 0; yycont = NULL; yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
hash: IPFY_HASH { yyexpectaddr = 0; yycont = NULL; yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
poollist:
|
|
|
|
ipaddr { $$ = newalist(NULL);
|
2013-08-11 14:28:45 +00:00
|
|
|
$$->al_family = $1.f;
|
|
|
|
$$->al_i6addr = $1.a;
|
|
|
|
$$->al_i6mask = $1.m;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| '!' ipaddr { $$ = newalist(NULL);
|
|
|
|
$$->al_not = 1;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$->al_family = $2.f;
|
|
|
|
$$->al_i6addr = $2.a;
|
|
|
|
$$->al_i6mask = $2.m;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| poollist ',' ipaddr
|
|
|
|
{ $$ = newalist($1);
|
2013-08-11 14:28:45 +00:00
|
|
|
$$->al_family = $3.f;
|
|
|
|
$$->al_i6addr = $3.a;
|
|
|
|
$$->al_i6mask = $3.m;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| poollist ',' '!' ipaddr
|
|
|
|
{ $$ = newalist($1);
|
|
|
|
$$->al_not = 1;
|
2013-08-11 14:28:45 +00:00
|
|
|
$$->al_family = $4.f;
|
|
|
|
$$->al_i6addr = $4.a;
|
|
|
|
$$->al_i6mask = $4.m;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
port: IPFY_PORT { yyexpectaddr = 0;
|
|
|
|
yycont = NULL;
|
2013-08-11 14:28:45 +00:00
|
|
|
if (frc->fr_proto != 0 &&
|
|
|
|
frc->fr_proto != IPPROTO_UDP &&
|
|
|
|
frc->fr_proto != IPPROTO_TCP)
|
|
|
|
yyerror("port use incorrect");
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
portc: port compare { $$ = $2;
|
2013-08-11 14:28:45 +00:00
|
|
|
yysetdict(NULL);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| porteq { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
porteq: port '=' { $$ = FR_EQUAL;
|
2013-08-11 14:28:45 +00:00
|
|
|
yysetdict(NULL);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
portr: IPFY_PORT { yyexpectaddr = 0;
|
|
|
|
yycont = NULL;
|
2013-08-11 14:28:45 +00:00
|
|
|
yysetdict(NULL);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
portcomp:
|
|
|
|
portc portnum { $$.pc = $1;
|
|
|
|
$$.p1 = $2;
|
2013-08-11 14:28:45 +00:00
|
|
|
yyresetdict();
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
portrange:
|
|
|
|
portr portnum range portnum { $$.p1 = $2;
|
|
|
|
$$.pc = $3;
|
|
|
|
$$.p2 = $4;
|
2013-08-11 14:28:45 +00:00
|
|
|
yyresetdict();
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
icmp: | itype icode
|
|
|
|
;
|
|
|
|
|
|
|
|
itype: seticmptype icmptype
|
|
|
|
{ DOALL(fr->fr_icmp = htons($2 << 8); fr->fr_icmpm = htons(0xff00););
|
|
|
|
yyresetdict();
|
|
|
|
}
|
|
|
|
| seticmptype lstart typelist lend { yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
seticmptype:
|
2013-08-11 14:28:45 +00:00
|
|
|
IPFY_ICMPTYPE { if (frc->fr_family == AF_UNSPEC)
|
|
|
|
frc->fr_family = AF_INET;
|
|
|
|
if (frc->fr_family == AF_INET &&
|
|
|
|
frc->fr_type == FR_T_IPF &&
|
|
|
|
frc->fr_proto != IPPROTO_ICMP) {
|
|
|
|
yyerror("proto not icmp");
|
|
|
|
}
|
|
|
|
if (frc->fr_family == AF_INET6 &&
|
|
|
|
frc->fr_type == FR_T_IPF &&
|
|
|
|
frc->fr_proto != IPPROTO_ICMPV6) {
|
|
|
|
yyerror("proto not ipv6-icmp");
|
|
|
|
}
|
|
|
|
setipftype();
|
|
|
|
DOALL(if (fr->fr_family == AF_INET) { \
|
|
|
|
fr->fr_ip.fi_v = 4; \
|
|
|
|
fr->fr_mip.fi_v = 0xf; \
|
|
|
|
}
|
|
|
|
if (fr->fr_family == AF_INET6) { \
|
|
|
|
fr->fr_ip.fi_v = 6; \
|
|
|
|
fr->fr_mip.fi_v = 0xf; \
|
|
|
|
}
|
|
|
|
)
|
|
|
|
yysetdict(NULL);
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
icode: | seticmpcode icmpcode
|
|
|
|
{ DOALL(fr->fr_icmp |= htons($2); fr->fr_icmpm |= htons(0xff););
|
|
|
|
yyresetdict();
|
|
|
|
}
|
|
|
|
| seticmpcode lstart codelist lend { yyresetdict(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
seticmpcode:
|
|
|
|
IPFY_ICMPCODE { yysetdict(icmpcodewords); }
|
|
|
|
;
|
|
|
|
|
|
|
|
typelist:
|
|
|
|
icmptype
|
|
|
|
{ DOREM(fr->fr_icmp = htons($1 << 8); fr->fr_icmpm = htons(0xff00);) }
|
|
|
|
| typelist lmore icmptype
|
|
|
|
{ DOREM(fr->fr_icmp = htons($3 << 8); fr->fr_icmpm = htons(0xff00);) }
|
|
|
|
;
|
|
|
|
|
|
|
|
codelist:
|
|
|
|
icmpcode
|
|
|
|
{ DOREM(fr->fr_icmp |= htons($1); fr->fr_icmpm |= htons(0xff);) }
|
|
|
|
| codelist lmore icmpcode
|
2006-08-16 12:23:02 +00:00
|
|
|
{ DOREM(fr->fr_icmp &= htons(0xff00); fr->fr_icmp |= htons($3); \
|
|
|
|
fr->fr_icmpm |= htons(0xff);) }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
age: | IPFY_AGE YY_NUMBER { DOALL(fr->fr_age[0] = $2; \
|
|
|
|
fr->fr_age[1] = $2;) }
|
|
|
|
| IPFY_AGE YY_NUMBER '/' YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_age[0] = $2; \
|
|
|
|
fr->fr_age[1] = $4;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
keep: | IPFY_KEEP keepstate keep
|
|
|
|
| IPFY_KEEP keepfrag keep
|
|
|
|
;
|
|
|
|
|
|
|
|
keepstate:
|
|
|
|
IPFY_STATE stateoptlist { DOALL(fr->fr_flags |= FR_KEEPSTATE;)}
|
|
|
|
;
|
|
|
|
|
|
|
|
keepfrag:
|
|
|
|
IPFY_FRAGS fragoptlist { DOALL(fr->fr_flags |= FR_KEEPFRAG;) }
|
|
|
|
| IPFY_FRAG fragoptlist { DOALL(fr->fr_flags |= FR_KEEPFRAG;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
fragoptlist:
|
|
|
|
| '(' fragopts ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
fragopts:
|
|
|
|
fragopt lanother fragopts
|
|
|
|
| fragopt
|
|
|
|
;
|
|
|
|
|
|
|
|
fragopt:
|
|
|
|
IPFY_STRICT { DOALL(fr->fr_flags |= FR_FRSTRICT;) }
|
|
|
|
;
|
|
|
|
|
|
|
|
stateoptlist:
|
|
|
|
| '(' stateopts ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
stateopts:
|
|
|
|
stateopt lanother stateopts
|
|
|
|
| stateopt
|
|
|
|
;
|
|
|
|
|
|
|
|
stateopt:
|
|
|
|
IPFY_LIMIT YY_NUMBER { DOALL(fr->fr_statemax = $2;) }
|
|
|
|
| IPFY_STRICT { DOALL(if (fr->fr_proto != IPPROTO_TCP) { \
|
|
|
|
YYERROR; \
|
2013-08-11 14:28:45 +00:00
|
|
|
} else if (fr->fr_flags & FR_STLOOSE) {\
|
|
|
|
YYERROR; \
|
|
|
|
} else \
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_flags |= FR_STSTRICT;)
|
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_LOOSE { DOALL(if (fr->fr_proto != IPPROTO_TCP) { \
|
|
|
|
YYERROR; \
|
|
|
|
} else if (fr->fr_flags & FR_STSTRICT){\
|
|
|
|
YYERROR; \
|
|
|
|
} else \
|
|
|
|
fr->fr_flags |= FR_STLOOSE;)
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
| IPFY_NEWISN { DOALL(if (fr->fr_proto != IPPROTO_TCP) { \
|
|
|
|
YYERROR; \
|
|
|
|
} else \
|
|
|
|
fr->fr_flags |= FR_NEWISN;)
|
|
|
|
}
|
|
|
|
| IPFY_NOICMPERR { DOALL(fr->fr_flags |= FR_NOICMPERR;) }
|
|
|
|
|
|
|
|
| IPFY_SYNC { DOALL(fr->fr_flags |= FR_STATESYNC;) }
|
2006-08-16 12:23:02 +00:00
|
|
|
| IPFY_AGE YY_NUMBER { DOALL(fr->fr_age[0] = $2; \
|
|
|
|
fr->fr_age[1] = $2;) }
|
|
|
|
| IPFY_AGE YY_NUMBER '/' YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_age[0] = $2; \
|
|
|
|
fr->fr_age[1] = $4;) }
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_ICMPHEAD groupname
|
|
|
|
{ DOALL(seticmphead(&fr, $2);)
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
| IPFY_NOLOG
|
|
|
|
{ DOALL(fr->fr_nostatelog = 1;) }
|
|
|
|
| IPFY_RPC
|
|
|
|
{ DOALL(fr->fr_rpc = 1;) }
|
|
|
|
| IPFY_RPC IPFY_IN YY_STR
|
|
|
|
{ DOALL(fr->fr_rpc = 1;) }
|
|
|
|
| IPFY_MAX_SRCS YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_srctrack.ht_max_nodes = $2;) }
|
|
|
|
| IPFY_MAX_PER_SRC YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_srctrack.ht_max_per_node = $2; \
|
|
|
|
fr->fr_srctrack.ht_netmask = \
|
|
|
|
fr->fr_family == AF_INET ? 32: 128;)
|
|
|
|
}
|
|
|
|
| IPFY_MAX_PER_SRC YY_NUMBER '/' YY_NUMBER
|
|
|
|
{ DOALL(fr->fr_srctrack.ht_max_per_node = $2; \
|
|
|
|
fr->fr_srctrack.ht_netmask = $4;)
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
portnum:
|
2013-08-11 14:28:45 +00:00
|
|
|
servicename { if (getport(frc, $1,
|
|
|
|
&($$), NULL) == -1)
|
2005-04-25 17:31:50 +00:00
|
|
|
yyerror("service unknown");
|
|
|
|
$$ = ntohs($$);
|
|
|
|
free($1);
|
|
|
|
}
|
|
|
|
| YY_NUMBER { if ($1 > 65535) /* Unsigned */
|
|
|
|
yyerror("invalid port number");
|
|
|
|
else
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
withlist:
|
2005-12-30 11:52:26 +00:00
|
|
|
withopt { nowith = 0; }
|
|
|
|
| withlist withopt { nowith = 0; }
|
|
|
|
| withlist ',' withopt { nowith = 0; }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
withopt:
|
|
|
|
opttype { DOALL(fr->fr_flx |= $1; fr->fr_mflx |= $1;) }
|
2005-12-30 11:52:26 +00:00
|
|
|
| notwith opttype { DOALL(fr->fr_mflx |= $2;) }
|
2005-04-25 17:31:50 +00:00
|
|
|
| ipopt ipopts { yyresetdict(); }
|
|
|
|
| notwith ipopt ipopts { yyresetdict(); }
|
2013-08-11 14:28:45 +00:00
|
|
|
| startv6hdr ipv6hdrs { yyresetdict(); }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
ipopt: IPFY_OPT { yysetdict(ipv4optwords); }
|
|
|
|
;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
startv6hdr:
|
|
|
|
IPFY_V6HDR { if (frc->fr_family != AF_INET6)
|
2005-04-25 17:31:50 +00:00
|
|
|
yyerror("only available with IPv6");
|
|
|
|
yysetdict(ipv6optwords);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
notwith:
|
|
|
|
IPFY_NOT { nowith = 1; }
|
|
|
|
| IPFY_NO { nowith = 1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
opttype:
|
|
|
|
IPFY_IPOPTS { $$ = FI_OPTIONS; }
|
|
|
|
| IPFY_SHORT { $$ = FI_SHORT; }
|
|
|
|
| IPFY_NAT { $$ = FI_NATED; }
|
|
|
|
| IPFY_BAD { $$ = FI_BAD; }
|
|
|
|
| IPFY_BADNAT { $$ = FI_BADNAT; }
|
|
|
|
| IPFY_BADSRC { $$ = FI_BADSRC; }
|
|
|
|
| IPFY_LOWTTL { $$ = FI_LOWTTL; }
|
|
|
|
| IPFY_FRAG { $$ = FI_FRAG; }
|
|
|
|
| IPFY_FRAGBODY { $$ = FI_FRAGBODY; }
|
|
|
|
| IPFY_FRAGS { $$ = FI_FRAG; }
|
|
|
|
| IPFY_MBCAST { $$ = FI_MBCAST; }
|
|
|
|
| IPFY_MULTICAST { $$ = FI_MULTICAST; }
|
|
|
|
| IPFY_BROADCAST { $$ = FI_BROADCAST; }
|
|
|
|
| IPFY_STATE { $$ = FI_STATE; }
|
|
|
|
| IPFY_OOW { $$ = FI_OOW; }
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_AH { $$ = FI_AH; }
|
|
|
|
| IPFY_V6HDRS { $$ = FI_V6EXTHDR; }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
ipopts: optlist { DOALL(fr->fr_mip.fi_optmsk |= $1;
|
2013-08-11 14:28:45 +00:00
|
|
|
if (fr->fr_family == AF_UNSPEC) {
|
|
|
|
fr->fr_family = AF_INET;
|
|
|
|
fr->fr_ip.fi_v = 4;
|
|
|
|
fr->fr_mip.fi_v = 0xf;
|
|
|
|
} else if (fr->fr_family != AF_INET) {
|
|
|
|
YYERROR;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
if (!nowith)
|
|
|
|
fr->fr_ip.fi_optmsk |= $1;)
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
optlist:
|
|
|
|
opt { $$ |= $1; }
|
|
|
|
| optlist ',' opt { $$ |= $1 | $3; }
|
|
|
|
;
|
|
|
|
|
|
|
|
ipv6hdrs:
|
|
|
|
ipv6hdrlist { DOALL(fr->fr_mip.fi_optmsk |= $1;
|
|
|
|
if (!nowith)
|
|
|
|
fr->fr_ip.fi_optmsk |= $1;)
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
ipv6hdrlist:
|
|
|
|
ipv6hdr { $$ |= $1; }
|
|
|
|
| ipv6hdrlist ',' ipv6hdr { $$ |= $1 | $3; }
|
|
|
|
;
|
|
|
|
|
|
|
|
secname:
|
|
|
|
seclevel { $$ |= $1; }
|
|
|
|
| secname ',' seclevel { $$ |= $1 | $3; }
|
|
|
|
;
|
|
|
|
|
|
|
|
seclevel:
|
|
|
|
IPFY_SEC_UNC { $$ = secbit(IPSO_CLASS_UNCL); }
|
|
|
|
| IPFY_SEC_CONF { $$ = secbit(IPSO_CLASS_CONF); }
|
|
|
|
| IPFY_SEC_RSV1 { $$ = secbit(IPSO_CLASS_RES1); }
|
|
|
|
| IPFY_SEC_RSV2 { $$ = secbit(IPSO_CLASS_RES2); }
|
|
|
|
| IPFY_SEC_RSV3 { $$ = secbit(IPSO_CLASS_RES3); }
|
|
|
|
| IPFY_SEC_RSV4 { $$ = secbit(IPSO_CLASS_RES4); }
|
|
|
|
| IPFY_SEC_SEC { $$ = secbit(IPSO_CLASS_SECR); }
|
|
|
|
| IPFY_SEC_TS { $$ = secbit(IPSO_CLASS_TOPS); }
|
|
|
|
;
|
|
|
|
|
|
|
|
icmptype:
|
2013-08-11 14:28:45 +00:00
|
|
|
YY_NUMBER { $$ = $1; }
|
|
|
|
| YY_STR { $$ = geticmptype(frc->fr_family, $1);
|
|
|
|
if ($$ == -1)
|
|
|
|
yyerror("unrecognised icmp type");
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
icmpcode:
|
|
|
|
YY_NUMBER { $$ = $1; }
|
|
|
|
| IPFY_ICMPC_NETUNR { $$ = ICMP_UNREACH_NET; }
|
|
|
|
| IPFY_ICMPC_HSTUNR { $$ = ICMP_UNREACH_HOST; }
|
|
|
|
| IPFY_ICMPC_PROUNR { $$ = ICMP_UNREACH_PROTOCOL; }
|
|
|
|
| IPFY_ICMPC_PORUNR { $$ = ICMP_UNREACH_PORT; }
|
|
|
|
| IPFY_ICMPC_NEEDF { $$ = ICMP_UNREACH_NEEDFRAG; }
|
|
|
|
| IPFY_ICMPC_SRCFAIL { $$ = ICMP_UNREACH_SRCFAIL; }
|
|
|
|
| IPFY_ICMPC_NETUNK { $$ = ICMP_UNREACH_NET_UNKNOWN; }
|
|
|
|
| IPFY_ICMPC_HSTUNK { $$ = ICMP_UNREACH_HOST_UNKNOWN; }
|
|
|
|
| IPFY_ICMPC_ISOLATE { $$ = ICMP_UNREACH_ISOLATED; }
|
|
|
|
| IPFY_ICMPC_NETPRO { $$ = ICMP_UNREACH_NET_PROHIB; }
|
|
|
|
| IPFY_ICMPC_HSTPRO { $$ = ICMP_UNREACH_HOST_PROHIB; }
|
|
|
|
| IPFY_ICMPC_NETTOS { $$ = ICMP_UNREACH_TOSNET; }
|
|
|
|
| IPFY_ICMPC_HSTTOS { $$ = ICMP_UNREACH_TOSHOST; }
|
|
|
|
| IPFY_ICMPC_FLTPRO { $$ = ICMP_UNREACH_ADMIN_PROHIBIT; }
|
|
|
|
| IPFY_ICMPC_HSTPRE { $$ = 14; }
|
|
|
|
| IPFY_ICMPC_CUTPRE { $$ = 15; }
|
|
|
|
;
|
|
|
|
|
|
|
|
opt:
|
|
|
|
IPFY_IPOPT_NOP { $$ = getoptbyvalue(IPOPT_NOP); }
|
|
|
|
| IPFY_IPOPT_RR { $$ = getoptbyvalue(IPOPT_RR); }
|
|
|
|
| IPFY_IPOPT_ZSU { $$ = getoptbyvalue(IPOPT_ZSU); }
|
|
|
|
| IPFY_IPOPT_MTUP { $$ = getoptbyvalue(IPOPT_MTUP); }
|
|
|
|
| IPFY_IPOPT_MTUR { $$ = getoptbyvalue(IPOPT_MTUR); }
|
|
|
|
| IPFY_IPOPT_ENCODE { $$ = getoptbyvalue(IPOPT_ENCODE); }
|
|
|
|
| IPFY_IPOPT_TS { $$ = getoptbyvalue(IPOPT_TS); }
|
|
|
|
| IPFY_IPOPT_TR { $$ = getoptbyvalue(IPOPT_TR); }
|
|
|
|
| IPFY_IPOPT_SEC { $$ = getoptbyvalue(IPOPT_SECURITY); }
|
|
|
|
| IPFY_IPOPT_LSRR { $$ = getoptbyvalue(IPOPT_LSRR); }
|
|
|
|
| IPFY_IPOPT_ESEC { $$ = getoptbyvalue(IPOPT_E_SEC); }
|
2013-08-11 14:28:45 +00:00
|
|
|
| IPFY_IPOPT_CIPSO { $$ = getoptbyvalue(IPOPT_CIPSO); }
|
|
|
|
| IPFY_IPOPT_CIPSO doi { $$ = getoptbyvalue(IPOPT_CIPSO); }
|
2005-04-25 17:31:50 +00:00
|
|
|
| IPFY_IPOPT_SATID { $$ = getoptbyvalue(IPOPT_SATID); }
|
|
|
|
| IPFY_IPOPT_SSRR { $$ = getoptbyvalue(IPOPT_SSRR); }
|
|
|
|
| IPFY_IPOPT_ADDEXT { $$ = getoptbyvalue(IPOPT_ADDEXT); }
|
|
|
|
| IPFY_IPOPT_VISA { $$ = getoptbyvalue(IPOPT_VISA); }
|
|
|
|
| IPFY_IPOPT_IMITD { $$ = getoptbyvalue(IPOPT_IMITD); }
|
|
|
|
| IPFY_IPOPT_EIP { $$ = getoptbyvalue(IPOPT_EIP); }
|
|
|
|
| IPFY_IPOPT_FINN { $$ = getoptbyvalue(IPOPT_FINN); }
|
|
|
|
| IPFY_IPOPT_DPS { $$ = getoptbyvalue(IPOPT_DPS); }
|
|
|
|
| IPFY_IPOPT_SDB { $$ = getoptbyvalue(IPOPT_SDB); }
|
|
|
|
| IPFY_IPOPT_NSAPA { $$ = getoptbyvalue(IPOPT_NSAPA); }
|
|
|
|
| IPFY_IPOPT_RTRALRT { $$ = getoptbyvalue(IPOPT_RTRALRT); }
|
|
|
|
| IPFY_IPOPT_UMP { $$ = getoptbyvalue(IPOPT_UMP); }
|
|
|
|
| setsecclass secname
|
|
|
|
{ DOALL(fr->fr_mip.fi_secmsk |= $2;
|
2013-08-11 14:28:45 +00:00
|
|
|
if (fr->fr_family == AF_UNSPEC) {
|
|
|
|
fr->fr_family = AF_INET;
|
|
|
|
fr->fr_ip.fi_v = 4;
|
|
|
|
fr->fr_mip.fi_v = 0xf;
|
|
|
|
} else if (fr->fr_family != AF_INET) {
|
|
|
|
YYERROR;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
if (!nowith)
|
|
|
|
fr->fr_ip.fi_secmsk |= $2;)
|
|
|
|
$$ = 0;
|
|
|
|
yyresetdict();
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
setsecclass:
|
2013-08-11 14:28:45 +00:00
|
|
|
IPFY_SECCLASS { yysetdict(ipv4secwords); }
|
|
|
|
;
|
|
|
|
|
|
|
|
doi: IPFY_DOI YY_NUMBER { DOALL(fr->fr_doimask = 0xffffffff; \
|
|
|
|
if (!nowith) \
|
|
|
|
fr->fr_doi = $2;) }
|
|
|
|
| IPFY_DOI YY_HEX { DOALL(fr->fr_doimask = 0xffffffff; \
|
|
|
|
if (!nowith) \
|
|
|
|
fr->fr_doi = $2;) }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
ipv6hdr:
|
|
|
|
IPFY_AH { $$ = getv6optbyvalue(IPPROTO_AH); }
|
|
|
|
| IPFY_IPV6OPT_DSTOPTS { $$ = getv6optbyvalue(IPPROTO_DSTOPTS); }
|
2005-12-30 11:52:26 +00:00
|
|
|
| IPFY_IPV6OPT_ESP { $$ = getv6optbyvalue(IPPROTO_ESP); }
|
2005-04-25 17:31:50 +00:00
|
|
|
| IPFY_IPV6OPT_HOPOPTS { $$ = getv6optbyvalue(IPPROTO_HOPOPTS); }
|
|
|
|
| IPFY_IPV6OPT_IPV6 { $$ = getv6optbyvalue(IPPROTO_IPV6); }
|
|
|
|
| IPFY_IPV6OPT_NONE { $$ = getv6optbyvalue(IPPROTO_NONE); }
|
|
|
|
| IPFY_IPV6OPT_ROUTING { $$ = getv6optbyvalue(IPPROTO_ROUTING); }
|
2005-12-30 11:52:26 +00:00
|
|
|
| IPFY_IPV6OPT_FRAG { $$ = getv6optbyvalue(IPPROTO_FRAGMENT); }
|
|
|
|
| IPFY_IPV6OPT_MOBILITY { $$ = getv6optbyvalue(IPPROTO_MOBILITY); }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
level: IPFY_LEVEL { setsyslog(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
loglevel:
|
|
|
|
priority { fr->fr_loglevel = LOG_LOCAL0|$1; }
|
|
|
|
| facility '.' priority { fr->fr_loglevel = $1 | $3; }
|
|
|
|
;
|
|
|
|
|
|
|
|
facility:
|
|
|
|
IPFY_FAC_KERN { $$ = LOG_KERN; }
|
|
|
|
| IPFY_FAC_USER { $$ = LOG_USER; }
|
|
|
|
| IPFY_FAC_MAIL { $$ = LOG_MAIL; }
|
|
|
|
| IPFY_FAC_DAEMON { $$ = LOG_DAEMON; }
|
|
|
|
| IPFY_FAC_AUTH { $$ = LOG_AUTH; }
|
|
|
|
| IPFY_FAC_SYSLOG { $$ = LOG_SYSLOG; }
|
|
|
|
| IPFY_FAC_LPR { $$ = LOG_LPR; }
|
|
|
|
| IPFY_FAC_NEWS { $$ = LOG_NEWS; }
|
|
|
|
| IPFY_FAC_UUCP { $$ = LOG_UUCP; }
|
|
|
|
| IPFY_FAC_CRON { $$ = LOG_CRON; }
|
|
|
|
| IPFY_FAC_FTP { $$ = LOG_FTP; }
|
|
|
|
| IPFY_FAC_AUTHPRIV { $$ = LOG_AUTHPRIV; }
|
|
|
|
| IPFY_FAC_AUDIT { $$ = LOG_AUDIT; }
|
|
|
|
| IPFY_FAC_LFMT { $$ = LOG_LFMT; }
|
|
|
|
| IPFY_FAC_LOCAL0 { $$ = LOG_LOCAL0; }
|
|
|
|
| IPFY_FAC_LOCAL1 { $$ = LOG_LOCAL1; }
|
|
|
|
| IPFY_FAC_LOCAL2 { $$ = LOG_LOCAL2; }
|
|
|
|
| IPFY_FAC_LOCAL3 { $$ = LOG_LOCAL3; }
|
|
|
|
| IPFY_FAC_LOCAL4 { $$ = LOG_LOCAL4; }
|
|
|
|
| IPFY_FAC_LOCAL5 { $$ = LOG_LOCAL5; }
|
|
|
|
| IPFY_FAC_LOCAL6 { $$ = LOG_LOCAL6; }
|
|
|
|
| IPFY_FAC_LOCAL7 { $$ = LOG_LOCAL7; }
|
|
|
|
| IPFY_FAC_SECURITY { $$ = LOG_SECURITY; }
|
|
|
|
;
|
|
|
|
|
|
|
|
priority:
|
|
|
|
IPFY_PRI_EMERG { $$ = LOG_EMERG; }
|
|
|
|
| IPFY_PRI_ALERT { $$ = LOG_ALERT; }
|
|
|
|
| IPFY_PRI_CRIT { $$ = LOG_CRIT; }
|
|
|
|
| IPFY_PRI_ERR { $$ = LOG_ERR; }
|
|
|
|
| IPFY_PRI_WARN { $$ = LOG_WARNING; }
|
|
|
|
| IPFY_PRI_NOTICE { $$ = LOG_NOTICE; }
|
|
|
|
| IPFY_PRI_INFO { $$ = LOG_INFO; }
|
|
|
|
| IPFY_PRI_DEBUG { $$ = LOG_DEBUG; }
|
|
|
|
;
|
|
|
|
|
|
|
|
compare:
|
|
|
|
YY_CMP_EQ { $$ = FR_EQUAL; }
|
|
|
|
| YY_CMP_NE { $$ = FR_NEQUAL; }
|
|
|
|
| YY_CMP_LT { $$ = FR_LESST; }
|
|
|
|
| YY_CMP_LE { $$ = FR_LESSTE; }
|
|
|
|
| YY_CMP_GT { $$ = FR_GREATERT; }
|
|
|
|
| YY_CMP_GE { $$ = FR_GREATERTE; }
|
|
|
|
;
|
|
|
|
|
|
|
|
range: YY_RANGE_IN { $$ = FR_INRANGE; }
|
|
|
|
| YY_RANGE_OUT { $$ = FR_OUTRANGE; }
|
|
|
|
| ':' { $$ = FR_INCRANGE; }
|
|
|
|
;
|
|
|
|
|
|
|
|
servicename:
|
|
|
|
YY_STR { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
2007-06-04 02:54:36 +00:00
|
|
|
interfacename: name { $$ = $1; }
|
|
|
|
| name ':' YY_NUMBER
|
2005-04-25 17:31:50 +00:00
|
|
|
{ $$ = $1;
|
|
|
|
fprintf(stderr, "%d: Logical interface %s:%d unsupported, "
|
|
|
|
"use the physical interface %s instead.\n",
|
|
|
|
yylineNum, $1, $3, $1);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
name: YY_STR { $$ = $1; }
|
2007-06-04 02:54:36 +00:00
|
|
|
| '-' { $$ = strdup("-"); }
|
2005-04-25 17:31:50 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
ipv4_16:
|
|
|
|
YY_NUMBER '.' YY_NUMBER
|
|
|
|
{ if ($1 > 255 || $3 > 255) {
|
|
|
|
yyerror("Invalid octet string for IP address");
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
$$.s_addr = ($1 << 24) | ($3 << 16);
|
|
|
|
$$.s_addr = htonl($$.s_addr);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
ipv4_24:
|
|
|
|
ipv4_16 '.' YY_NUMBER
|
|
|
|
{ if ($3 > 255) {
|
|
|
|
yyerror("Invalid octet string for IP address");
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
$$.s_addr |= htonl($3 << 8);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
ipv4: ipv4_24 '.' YY_NUMBER
|
|
|
|
{ if ($3 > 255) {
|
|
|
|
yyerror("Invalid octet string for IP address");
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
$$.s_addr |= htonl($3);
|
|
|
|
}
|
|
|
|
| ipv4_24
|
|
|
|
| ipv4_16
|
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab ipfwords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "age", IPFY_AGE },
|
|
|
|
{ "ah", IPFY_AH },
|
|
|
|
{ "all", IPFY_ALL },
|
|
|
|
{ "and", IPFY_AND },
|
|
|
|
{ "auth", IPFY_AUTH },
|
|
|
|
{ "bad", IPFY_BAD },
|
|
|
|
{ "bad-nat", IPFY_BADNAT },
|
|
|
|
{ "bad-src", IPFY_BADSRC },
|
|
|
|
{ "bcast", IPFY_BROADCAST },
|
|
|
|
{ "block", IPFY_BLOCK },
|
|
|
|
{ "body", IPFY_BODY },
|
|
|
|
{ "bpf-v4", IPFY_BPFV4 },
|
|
|
|
#ifdef USE_INET6
|
|
|
|
{ "bpf-v6", IPFY_BPFV6 },
|
|
|
|
#endif
|
|
|
|
{ "call", IPFY_CALL },
|
|
|
|
{ "code", IPFY_ICMPCODE },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "comment", IPFY_COMMENT },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "count", IPFY_COUNT },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "decapsulate", IPFY_DECAPS },
|
|
|
|
{ "dstlist", IPFY_DSTLIST },
|
|
|
|
{ "doi", IPFY_DOI },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "dup-to", IPFY_DUPTO },
|
|
|
|
{ "eq", YY_CMP_EQ },
|
|
|
|
{ "esp", IPFY_ESP },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "exp", IPFY_IPFEXPR },
|
|
|
|
{ "family", IPFY_FAMILY },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "fastroute", IPFY_FROUTE },
|
|
|
|
{ "first", IPFY_FIRST },
|
|
|
|
{ "flags", IPFY_FLAGS },
|
|
|
|
{ "frag", IPFY_FRAG },
|
|
|
|
{ "frag-body", IPFY_FRAGBODY },
|
|
|
|
{ "frags", IPFY_FRAGS },
|
|
|
|
{ "from", IPFY_FROM },
|
|
|
|
{ "ge", YY_CMP_GE },
|
|
|
|
{ "group", IPFY_GROUP },
|
|
|
|
{ "gt", YY_CMP_GT },
|
|
|
|
{ "head", IPFY_HEAD },
|
|
|
|
{ "icmp", IPFY_ICMP },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "icmp-head", IPFY_ICMPHEAD },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "icmp-type", IPFY_ICMPTYPE },
|
|
|
|
{ "in", IPFY_IN },
|
|
|
|
{ "in-via", IPFY_INVIA },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "inet", IPFY_INET },
|
|
|
|
{ "inet6", IPFY_INET6 },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "ipopt", IPFY_IPOPTS },
|
|
|
|
{ "ipopts", IPFY_IPOPTS },
|
|
|
|
{ "keep", IPFY_KEEP },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "l5-as", IPFY_L5AS },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "le", YY_CMP_LE },
|
|
|
|
{ "level", IPFY_LEVEL },
|
|
|
|
{ "limit", IPFY_LIMIT },
|
|
|
|
{ "log", IPFY_LOG },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "loose", IPFY_LOOSE },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "lowttl", IPFY_LOWTTL },
|
|
|
|
{ "lt", YY_CMP_LT },
|
|
|
|
{ "mask", IPFY_MASK },
|
|
|
|
{ "match-tag", IPFY_MATCHTAG },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "max-per-src", IPFY_MAX_PER_SRC },
|
|
|
|
{ "max-srcs", IPFY_MAX_SRCS },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "mbcast", IPFY_MBCAST },
|
2005-12-30 11:52:26 +00:00
|
|
|
{ "mcast", IPFY_MULTICAST },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "multicast", IPFY_MULTICAST },
|
|
|
|
{ "nat", IPFY_NAT },
|
|
|
|
{ "ne", YY_CMP_NE },
|
|
|
|
{ "net", IPFY_NETWORK },
|
|
|
|
{ "newisn", IPFY_NEWISN },
|
|
|
|
{ "no", IPFY_NO },
|
|
|
|
{ "no-icmp-err", IPFY_NOICMPERR },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "nolog", IPFY_NOLOG },
|
2006-08-16 12:23:02 +00:00
|
|
|
{ "nomatch", IPFY_NOMATCH },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "now", IPFY_NOW },
|
|
|
|
{ "not", IPFY_NOT },
|
|
|
|
{ "oow", IPFY_OOW },
|
|
|
|
{ "on", IPFY_ON },
|
|
|
|
{ "opt", IPFY_OPT },
|
|
|
|
{ "or-block", IPFY_ORBLOCK },
|
|
|
|
{ "out", IPFY_OUT },
|
|
|
|
{ "out-via", IPFY_OUTVIA },
|
|
|
|
{ "pass", IPFY_PASS },
|
|
|
|
{ "port", IPFY_PORT },
|
|
|
|
{ "pps", IPFY_PPS },
|
|
|
|
{ "preauth", IPFY_PREAUTH },
|
|
|
|
{ "proto", IPFY_PROTO },
|
|
|
|
{ "quick", IPFY_QUICK },
|
|
|
|
{ "reply-to", IPFY_REPLY_TO },
|
|
|
|
{ "return-icmp", IPFY_RETICMP },
|
|
|
|
{ "return-icmp-as-dest", IPFY_RETICMPASDST },
|
|
|
|
{ "return-rst", IPFY_RETRST },
|
|
|
|
{ "route-to", IPFY_ROUTETO },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "rule-ttl", IPFY_RULETTL },
|
|
|
|
{ "rpc", IPFY_RPC },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "sec-class", IPFY_SECCLASS },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "set", IPFY_SET },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "set-tag", IPFY_SETTAG },
|
|
|
|
{ "skip", IPFY_SKIP },
|
|
|
|
{ "short", IPFY_SHORT },
|
|
|
|
{ "state", IPFY_STATE },
|
|
|
|
{ "state-age", IPFY_AGE },
|
|
|
|
{ "strict", IPFY_STRICT },
|
|
|
|
{ "sync", IPFY_SYNC },
|
|
|
|
{ "tcp", IPFY_TCP },
|
|
|
|
{ "tcp-udp", IPFY_TCPUDP },
|
|
|
|
{ "tos", IPFY_TOS },
|
|
|
|
{ "to", IPFY_TO },
|
|
|
|
{ "ttl", IPFY_TTL },
|
|
|
|
{ "udp", IPFY_UDP },
|
2013-08-11 14:28:45 +00:00
|
|
|
{ "v6hdr", IPFY_V6HDR },
|
|
|
|
{ "v6hdrs", IPFY_V6HDRS },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "with", IPFY_WITH },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab addrwords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "any", IPFY_ANY },
|
|
|
|
{ "hash", IPFY_HASH },
|
|
|
|
{ "pool", IPFY_POOL },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab maskwords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "broadcast", IPFY_BROADCAST },
|
|
|
|
{ "netmasked", IPFY_NETMASKED },
|
|
|
|
{ "network", IPFY_NETWORK },
|
|
|
|
{ "peer", IPFY_PEER },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab icmpcodewords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "cutoff-preced", IPFY_ICMPC_CUTPRE },
|
|
|
|
{ "filter-prohib", IPFY_ICMPC_FLTPRO },
|
|
|
|
{ "isolate", IPFY_ICMPC_ISOLATE },
|
|
|
|
{ "needfrag", IPFY_ICMPC_NEEDF },
|
|
|
|
{ "net-prohib", IPFY_ICMPC_NETPRO },
|
|
|
|
{ "net-tos", IPFY_ICMPC_NETTOS },
|
|
|
|
{ "host-preced", IPFY_ICMPC_HSTPRE },
|
|
|
|
{ "host-prohib", IPFY_ICMPC_HSTPRO },
|
|
|
|
{ "host-tos", IPFY_ICMPC_HSTTOS },
|
|
|
|
{ "host-unk", IPFY_ICMPC_HSTUNK },
|
|
|
|
{ "host-unr", IPFY_ICMPC_HSTUNR },
|
|
|
|
{ "net-unk", IPFY_ICMPC_NETUNK },
|
|
|
|
{ "net-unr", IPFY_ICMPC_NETUNR },
|
|
|
|
{ "port-unr", IPFY_ICMPC_PORUNR },
|
|
|
|
{ "proto-unr", IPFY_ICMPC_PROUNR },
|
|
|
|
{ "srcfail", IPFY_ICMPC_SRCFAIL },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab ipv4optwords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "addext", IPFY_IPOPT_ADDEXT },
|
|
|
|
{ "cipso", IPFY_IPOPT_CIPSO },
|
|
|
|
{ "dps", IPFY_IPOPT_DPS },
|
|
|
|
{ "e-sec", IPFY_IPOPT_ESEC },
|
|
|
|
{ "eip", IPFY_IPOPT_EIP },
|
|
|
|
{ "encode", IPFY_IPOPT_ENCODE },
|
|
|
|
{ "finn", IPFY_IPOPT_FINN },
|
|
|
|
{ "imitd", IPFY_IPOPT_IMITD },
|
|
|
|
{ "lsrr", IPFY_IPOPT_LSRR },
|
|
|
|
{ "mtup", IPFY_IPOPT_MTUP },
|
|
|
|
{ "mtur", IPFY_IPOPT_MTUR },
|
|
|
|
{ "nop", IPFY_IPOPT_NOP },
|
|
|
|
{ "nsapa", IPFY_IPOPT_NSAPA },
|
|
|
|
{ "rr", IPFY_IPOPT_RR },
|
|
|
|
{ "rtralrt", IPFY_IPOPT_RTRALRT },
|
|
|
|
{ "satid", IPFY_IPOPT_SATID },
|
|
|
|
{ "sdb", IPFY_IPOPT_SDB },
|
|
|
|
{ "sec", IPFY_IPOPT_SEC },
|
|
|
|
{ "ssrr", IPFY_IPOPT_SSRR },
|
|
|
|
{ "tr", IPFY_IPOPT_TR },
|
|
|
|
{ "ts", IPFY_IPOPT_TS },
|
|
|
|
{ "ump", IPFY_IPOPT_UMP },
|
|
|
|
{ "visa", IPFY_IPOPT_VISA },
|
|
|
|
{ "zsu", IPFY_IPOPT_ZSU },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab ipv4secwords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "confid", IPFY_SEC_CONF },
|
|
|
|
{ "reserv-1", IPFY_SEC_RSV1 },
|
|
|
|
{ "reserv-2", IPFY_SEC_RSV2 },
|
|
|
|
{ "reserv-3", IPFY_SEC_RSV3 },
|
|
|
|
{ "reserv-4", IPFY_SEC_RSV4 },
|
|
|
|
{ "secret", IPFY_SEC_SEC },
|
|
|
|
{ "topsecret", IPFY_SEC_TS },
|
|
|
|
{ "unclass", IPFY_SEC_UNC },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab ipv6optwords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "dstopts", IPFY_IPV6OPT_DSTOPTS },
|
2005-12-30 11:52:26 +00:00
|
|
|
{ "esp", IPFY_IPV6OPT_ESP },
|
|
|
|
{ "frag", IPFY_IPV6OPT_FRAG },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "hopopts", IPFY_IPV6OPT_HOPOPTS },
|
|
|
|
{ "ipv6", IPFY_IPV6OPT_IPV6 },
|
2005-12-30 11:52:26 +00:00
|
|
|
{ "mobility", IPFY_IPV6OPT_MOBILITY },
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "none", IPFY_IPV6OPT_NONE },
|
|
|
|
{ "routing", IPFY_IPV6OPT_ROUTING },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static struct wordtab logwords[] = {
|
2005-04-25 17:31:50 +00:00
|
|
|
{ "kern", IPFY_FAC_KERN },
|
|
|
|
{ "user", IPFY_FAC_USER },
|
|
|
|
{ "mail", IPFY_FAC_MAIL },
|
|
|
|
{ "daemon", IPFY_FAC_DAEMON },
|
|
|
|
{ "auth", IPFY_FAC_AUTH },
|
|
|
|
{ "syslog", IPFY_FAC_SYSLOG },
|
|
|
|
{ "lpr", IPFY_FAC_LPR },
|
|
|
|
{ "news", IPFY_FAC_NEWS },
|
|
|
|
{ "uucp", IPFY_FAC_UUCP },
|
|
|
|
{ "cron", IPFY_FAC_CRON },
|
|
|
|
{ "ftp", IPFY_FAC_FTP },
|
|
|
|
{ "authpriv", IPFY_FAC_AUTHPRIV },
|
|
|
|
{ "audit", IPFY_FAC_AUDIT },
|
|
|
|
{ "logalert", IPFY_FAC_LFMT },
|
|
|
|
{ "console", IPFY_FAC_CONSOLE },
|
|
|
|
{ "security", IPFY_FAC_SECURITY },
|
|
|
|
{ "local0", IPFY_FAC_LOCAL0 },
|
|
|
|
{ "local1", IPFY_FAC_LOCAL1 },
|
|
|
|
{ "local2", IPFY_FAC_LOCAL2 },
|
|
|
|
{ "local3", IPFY_FAC_LOCAL3 },
|
|
|
|
{ "local4", IPFY_FAC_LOCAL4 },
|
|
|
|
{ "local5", IPFY_FAC_LOCAL5 },
|
|
|
|
{ "local6", IPFY_FAC_LOCAL6 },
|
|
|
|
{ "local7", IPFY_FAC_LOCAL7 },
|
|
|
|
{ "emerg", IPFY_PRI_EMERG },
|
|
|
|
{ "alert", IPFY_PRI_ALERT },
|
|
|
|
{ "crit", IPFY_PRI_CRIT },
|
|
|
|
{ "err", IPFY_PRI_ERR },
|
|
|
|
{ "warn", IPFY_PRI_WARN },
|
|
|
|
{ "notice", IPFY_PRI_NOTICE },
|
|
|
|
{ "info", IPFY_PRI_INFO },
|
|
|
|
{ "debug", IPFY_PRI_DEBUG },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
int
|
|
|
|
ipf_parsefile(int fd, addfunc_t addfunc, ioctlfunc_t *iocfuncs, char *filename)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
FILE *fp = NULL;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
yylineNum = 1;
|
|
|
|
yysettab(ipfwords);
|
|
|
|
|
|
|
|
s = getenv("YYDEBUG");
|
|
|
|
if (s != NULL)
|
|
|
|
yydebug = atoi(s);
|
|
|
|
else
|
|
|
|
yydebug = 0;
|
|
|
|
|
|
|
|
if (strcmp(filename, "-")) {
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (fp == NULL) {
|
|
|
|
fprintf(stderr, "fopen(%s) failed: %s\n", filename,
|
|
|
|
STRERROR(errno));
|
2021-12-22 02:37:19 +00:00
|
|
|
return(-1);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
fp = stdin;
|
|
|
|
|
|
|
|
while (ipf_parsesome(fd, addfunc, iocfuncs, fp) == 1)
|
|
|
|
;
|
|
|
|
if (fp != NULL)
|
|
|
|
fclose(fp);
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
int
|
|
|
|
ipf_parsesome(int fd, addfunc_t addfunc, ioctlfunc_t *iocfuncs, FILE *fp)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ipffd = fd;
|
|
|
|
for (i = 0; i <= IPL_LOGMAX; i++)
|
2013-08-11 14:28:45 +00:00
|
|
|
ipfioctls[i] = iocfuncs[i];
|
2005-04-25 17:31:50 +00:00
|
|
|
ipfaddfunc = addfunc;
|
|
|
|
|
|
|
|
if (feof(fp))
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
i = fgetc(fp);
|
|
|
|
if (i == EOF)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
if (ungetc(i, fp) == 0)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
if (feof(fp))
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
s = getenv("YYDEBUG");
|
|
|
|
if (s != NULL)
|
|
|
|
yydebug = atoi(s);
|
|
|
|
else
|
|
|
|
yydebug = 0;
|
|
|
|
|
|
|
|
yyin = fp;
|
|
|
|
yyparse();
|
2021-12-22 02:37:19 +00:00
|
|
|
return(1);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
newrule(void)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
frentry_t *frn;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
frn = allocfr();
|
2005-04-25 17:31:50 +00:00
|
|
|
for (fr = frtop; fr != NULL && fr->fr_next != NULL; fr = fr->fr_next)
|
|
|
|
;
|
2013-08-11 14:28:45 +00:00
|
|
|
if (fr != NULL) {
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_next = frn;
|
2013-08-11 14:28:45 +00:00
|
|
|
frn->fr_pnext = &fr->fr_next;
|
|
|
|
}
|
|
|
|
if (frtop == NULL) {
|
2005-04-25 17:31:50 +00:00
|
|
|
frtop = frn;
|
2013-08-11 14:28:45 +00:00
|
|
|
frn->fr_pnext = &frtop;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
fr = frn;
|
|
|
|
frc = frn;
|
|
|
|
fr->fr_loglevel = 0xffff;
|
|
|
|
fr->fr_isc = (void *)-1;
|
|
|
|
fr->fr_logtag = FR_NOLOGTAG;
|
|
|
|
fr->fr_type = FR_T_NONE;
|
2013-08-11 14:28:45 +00:00
|
|
|
fr->fr_flineno = yylineNum;
|
|
|
|
|
|
|
|
if (use_inet6 == 1)
|
|
|
|
fr->fr_family = AF_INET6;
|
|
|
|
else if (use_inet6 == -1)
|
|
|
|
fr->fr_family = AF_INET;
|
2005-04-25 17:31:50 +00:00
|
|
|
|
|
|
|
nrules = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
setipftype(void)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
for (fr = frc; fr != NULL; fr = fr->fr_next) {
|
|
|
|
if (fr->fr_type == FR_T_NONE) {
|
|
|
|
fr->fr_type = FR_T_IPF;
|
|
|
|
fr->fr_data = (void *)calloc(sizeof(fripf_t), 1);
|
|
|
|
fr->fr_dsize = sizeof(fripf_t);
|
2013-08-11 14:28:45 +00:00
|
|
|
fr->fr_family = frc->fr_family;
|
|
|
|
if (fr->fr_family == AF_INET) {
|
|
|
|
fr->fr_ip.fi_v = 4;
|
|
|
|
}
|
|
|
|
else if (fr->fr_family == AF_INET6) {
|
|
|
|
fr->fr_ip.fi_v = 6;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_mip.fi_v = 0xf;
|
|
|
|
fr->fr_ipf->fri_sifpidx = -1;
|
|
|
|
fr->fr_ipf->fri_difpidx = -1;
|
|
|
|
}
|
|
|
|
if (fr->fr_type != FR_T_IPF) {
|
|
|
|
fprintf(stderr, "IPF Type not set\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static frentry_t *
|
|
|
|
addrule(void)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
frentry_t *f, *f1, *f2;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
for (f2 = frc; f2->fr_next != NULL; f2 = f2->fr_next)
|
|
|
|
;
|
|
|
|
|
|
|
|
count = nrules;
|
|
|
|
f = f2;
|
|
|
|
for (f1 = frc; count > 0; count--, f1 = f1->fr_next) {
|
2013-08-11 14:28:45 +00:00
|
|
|
f->fr_next = allocfr();
|
|
|
|
if (f->fr_next == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(NULL);
|
2013-08-11 14:28:45 +00:00
|
|
|
f->fr_next->fr_pnext = &f->fr_next;
|
2005-04-25 17:31:50 +00:00
|
|
|
added++;
|
|
|
|
f = f->fr_next;
|
2013-08-11 14:28:45 +00:00
|
|
|
*f = *f1;
|
2005-04-25 17:31:50 +00:00
|
|
|
f->fr_next = NULL;
|
|
|
|
if (f->fr_caddr != NULL) {
|
|
|
|
f->fr_caddr = malloc(f->fr_dsize);
|
|
|
|
bcopy(f1->fr_caddr, f->fr_caddr, f->fr_dsize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 02:37:19 +00:00
|
|
|
return(f2->fr_next);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static int
|
2021-12-20 17:07:20 +00:00
|
|
|
lookuphost(char *name, i6addr_t *addrp)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hashed = 0;
|
|
|
|
pooled = 0;
|
|
|
|
dynamic = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2013-08-11 14:28:45 +00:00
|
|
|
if (fr->fr_ifnames[i] == -1)
|
|
|
|
continue;
|
|
|
|
if (strcmp(name, fr->fr_names + fr->fr_ifnames[i]) == 0) {
|
2005-04-25 17:31:50 +00:00
|
|
|
ifpflag = FRI_DYNAMIC;
|
2013-08-11 14:28:45 +00:00
|
|
|
dynamic = addname(&fr, name);
|
2021-12-22 02:37:19 +00:00
|
|
|
return(1);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
if (gethost(AF_INET, name, addrp) == -1) {
|
2005-04-25 17:31:50 +00:00
|
|
|
fprintf(stderr, "unknown name \"%s\"\n", name);
|
2021-12-22 02:37:19 +00:00
|
|
|
return(-1);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
dobpf(int v, char *phrase)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
#ifdef IPFILTER_BPF
|
|
|
|
struct bpf_program bpf;
|
|
|
|
struct pcap *p;
|
|
|
|
#endif
|
|
|
|
fakebpf_t *fb;
|
|
|
|
u_32_t l;
|
|
|
|
char *s;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (fr = frc; fr != NULL; fr = fr->fr_next) {
|
|
|
|
if (fr->fr_type != FR_T_NONE) {
|
|
|
|
fprintf(stderr, "cannot mix IPF and BPF matching\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
fr->fr_family = vtof(v);
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_type = FR_T_BPFOPC;
|
|
|
|
|
2005-12-30 11:52:26 +00:00
|
|
|
if (!strncmp(phrase, "0x", 2)) {
|
2005-04-25 17:31:50 +00:00
|
|
|
fb = malloc(sizeof(fakebpf_t));
|
|
|
|
|
|
|
|
for (i = 0, s = strtok(phrase, " \r\n\t"); s != NULL;
|
|
|
|
s = strtok(NULL, " \r\n\t"), i++) {
|
2017-03-16 04:40:07 +00:00
|
|
|
fb = reallocarray(fb, i / 4 + 1, sizeof(*fb));
|
2017-04-16 01:15:37 +00:00
|
|
|
if (fb == NULL) {
|
2017-04-16 04:36:22 +00:00
|
|
|
warnx("memory allocation error at %d in %s in %s", __LINE__, __FUNCTION__, __FILE__);
|
2017-04-16 01:15:37 +00:00
|
|
|
abort();
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
l = (u_32_t)strtol(s, NULL, 0);
|
|
|
|
switch (i & 3)
|
|
|
|
{
|
|
|
|
case 0 :
|
|
|
|
fb[i / 4].fb_c = l & 0xffff;
|
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
fb[i / 4].fb_t = l & 0xff;
|
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
fb[i / 4].fb_f = l & 0xff;
|
|
|
|
break;
|
|
|
|
case 3 :
|
|
|
|
fb[i / 4].fb_k = l;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((i & 3) != 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Odd number of bytes in BPF code\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
fr->fr_dsize = (i / 4 + 1) * sizeof(*fb);
|
|
|
|
fr->fr_data = fb;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IPFILTER_BPF
|
|
|
|
bzero((char *)&bpf, sizeof(bpf));
|
|
|
|
p = pcap_open_dead(DLT_RAW, 1);
|
|
|
|
if (!p) {
|
|
|
|
fprintf(stderr, "pcap_open_dead failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pcap_compile(p, &bpf, phrase, 1, 0xffffffff)) {
|
|
|
|
pcap_perror(p, "ipf");
|
|
|
|
pcap_close(p);
|
|
|
|
fprintf(stderr, "pcap parsing failed (%s)\n", phrase);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pcap_close(p);
|
|
|
|
|
|
|
|
fr->fr_dsize = bpf.bf_len * sizeof(struct bpf_insn);
|
|
|
|
fr->fr_data = malloc(fr->fr_dsize);
|
|
|
|
bcopy((char *)bpf.bf_insns, fr->fr_data, fr->fr_dsize);
|
|
|
|
if (!bpf_validate(fr->fr_data, bpf.bf_len)) {
|
|
|
|
fprintf(stderr, "BPF validation failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IPFILTER_BPF
|
|
|
|
if (opts & OPT_DEBUG)
|
|
|
|
bpf_dump(&bpf, 0);
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "BPF filter expressions not supported\n");
|
|
|
|
exit(1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
resetaddr(void)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
hashed = 0;
|
|
|
|
pooled = 0;
|
|
|
|
dynamic = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static alist_t *
|
|
|
|
newalist(alist_t *ptr)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
alist_t *al;
|
|
|
|
|
|
|
|
al = malloc(sizeof(*al));
|
|
|
|
if (al == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(NULL);
|
2005-04-25 17:31:50 +00:00
|
|
|
al->al_not = 0;
|
|
|
|
al->al_next = ptr;
|
2021-12-22 02:37:19 +00:00
|
|
|
return(al);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
static int
|
2021-12-20 17:07:20 +00:00
|
|
|
makepool(alist_t *list)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
ip_pool_node_t *n, *top;
|
|
|
|
ip_pool_t pool;
|
|
|
|
alist_t *a;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
if (list == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
top = calloc(1, sizeof(*top));
|
|
|
|
if (top == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2013-08-11 14:28:45 +00:00
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
for (n = top, a = list; (n != NULL) && (a != NULL); a = a->al_next) {
|
2013-08-11 14:28:45 +00:00
|
|
|
if (use_inet6 == 1) {
|
2017-06-23 02:42:04 +00:00
|
|
|
#ifdef USE_INET6
|
2013-08-11 14:28:45 +00:00
|
|
|
n->ipn_addr.adf_family = AF_INET6;
|
|
|
|
n->ipn_addr.adf_addr = a->al_i6addr;
|
|
|
|
n->ipn_addr.adf_len = offsetof(addrfamily_t,
|
|
|
|
adf_addr) + 16;
|
|
|
|
n->ipn_mask.adf_family = AF_INET6;
|
|
|
|
n->ipn_mask.adf_addr = a->al_i6mask;
|
|
|
|
n->ipn_mask.adf_len = offsetof(addrfamily_t,
|
|
|
|
adf_addr) + 16;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
n->ipn_addr.adf_family = AF_INET;
|
|
|
|
n->ipn_addr.adf_addr.in4.s_addr = a->al_1;
|
|
|
|
n->ipn_addr.adf_len = offsetof(addrfamily_t,
|
|
|
|
adf_addr) + 4;
|
|
|
|
n->ipn_mask.adf_family = AF_INET;
|
|
|
|
n->ipn_mask.adf_addr.in4.s_addr = a->al_2;
|
|
|
|
n->ipn_mask.adf_len = offsetof(addrfamily_t,
|
|
|
|
adf_addr) + 4;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
n->ipn_info = a->al_not;
|
|
|
|
if (a->al_next != NULL) {
|
|
|
|
n->ipn_next = calloc(1, sizeof(*n));
|
|
|
|
n = n->ipn_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero((char *)&pool, sizeof(pool));
|
|
|
|
pool.ipo_unit = IPL_LOGIPF;
|
|
|
|
pool.ipo_list = top;
|
2013-08-11 14:28:45 +00:00
|
|
|
num = load_pool(&pool, ipfioctls[IPL_LOGLOOKUP]);
|
2005-04-25 17:31:50 +00:00
|
|
|
|
|
|
|
while ((n = top) != NULL) {
|
|
|
|
top = n->ipn_next;
|
|
|
|
free(n);
|
|
|
|
}
|
2021-12-22 02:37:19 +00:00
|
|
|
return(num);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static u_int
|
|
|
|
makehash(alist_t *list)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
iphtent_t *n, *top;
|
|
|
|
iphtable_t iph;
|
|
|
|
alist_t *a;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
if (list == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
top = calloc(1, sizeof(*top));
|
|
|
|
if (top == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2013-08-11 14:28:45 +00:00
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
for (n = top, a = list; (n != NULL) && (a != NULL); a = a->al_next) {
|
2013-08-11 14:28:45 +00:00
|
|
|
if (a->al_family == AF_INET6) {
|
|
|
|
n->ipe_family = AF_INET6;
|
|
|
|
n->ipe_addr = a->al_i6addr;
|
|
|
|
n->ipe_mask = a->al_i6mask;
|
|
|
|
} else {
|
|
|
|
n->ipe_family = AF_INET;
|
|
|
|
n->ipe_addr.in4_addr = a->al_1;
|
|
|
|
n->ipe_mask.in4_addr = a->al_2;
|
|
|
|
}
|
2005-04-25 17:31:50 +00:00
|
|
|
n->ipe_value = 0;
|
|
|
|
if (a->al_next != NULL) {
|
|
|
|
n->ipe_next = calloc(1, sizeof(*n));
|
|
|
|
n = n->ipe_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero((char *)&iph, sizeof(iph));
|
|
|
|
iph.iph_unit = IPL_LOGIPF;
|
|
|
|
iph.iph_type = IPHASH_LOOKUP;
|
|
|
|
*iph.iph_name = '\0';
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
if (load_hash(&iph, top, ipfioctls[IPL_LOGLOOKUP]) == 0)
|
2005-04-25 17:31:50 +00:00
|
|
|
sscanf(iph.iph_name, "%u", &num);
|
|
|
|
else
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
while ((n = top) != NULL) {
|
|
|
|
top = n->ipe_next;
|
|
|
|
free(n);
|
|
|
|
}
|
2021-12-22 02:37:19 +00:00
|
|
|
return(num);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
int
|
|
|
|
ipf_addrule(int fd, ioctlfunc_t ioctlfunc, void *ptr)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
ioctlcmd_t add, del;
|
|
|
|
frentry_t *fr;
|
|
|
|
ipfobj_t obj;
|
|
|
|
|
2007-06-04 02:54:36 +00:00
|
|
|
if (ptr == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2007-06-04 02:54:36 +00:00
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
fr = ptr;
|
|
|
|
add = 0;
|
|
|
|
del = 0;
|
|
|
|
|
|
|
|
bzero((char *)&obj, sizeof(obj));
|
|
|
|
obj.ipfo_rev = IPFILTER_VERSION;
|
2013-08-11 14:28:45 +00:00
|
|
|
obj.ipfo_size = fr->fr_size;
|
2005-04-25 17:31:50 +00:00
|
|
|
obj.ipfo_type = IPFOBJ_FRENTRY;
|
|
|
|
obj.ipfo_ptr = ptr;
|
|
|
|
|
|
|
|
if ((opts & OPT_DONOTHING) != 0)
|
|
|
|
fd = -1;
|
|
|
|
|
|
|
|
if (opts & OPT_ZERORULEST) {
|
|
|
|
add = SIOCZRLST;
|
|
|
|
} else if (opts & OPT_INACTIVE) {
|
|
|
|
add = (u_int)fr->fr_hits ? SIOCINIFR :
|
|
|
|
SIOCADIFR;
|
|
|
|
del = SIOCRMIFR;
|
|
|
|
} else {
|
|
|
|
add = (u_int)fr->fr_hits ? SIOCINAFR :
|
|
|
|
SIOCADAFR;
|
|
|
|
del = SIOCRMAFR;
|
|
|
|
}
|
|
|
|
|
2006-08-16 12:23:02 +00:00
|
|
|
if ((opts & OPT_OUTQUE) != 0)
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_flags |= FR_OUTQUE;
|
|
|
|
if (fr->fr_hits)
|
|
|
|
fr->fr_hits--;
|
2007-06-04 02:54:36 +00:00
|
|
|
if ((opts & OPT_VERBOSE) != 0)
|
2005-04-25 17:31:50 +00:00
|
|
|
printfr(fr, ioctlfunc);
|
|
|
|
|
2007-06-04 02:54:36 +00:00
|
|
|
if ((opts & OPT_DEBUG) != 0) {
|
2005-04-25 17:31:50 +00:00
|
|
|
binprint(fr, sizeof(*fr));
|
|
|
|
if (fr->fr_data != NULL)
|
|
|
|
binprint(fr->fr_data, fr->fr_dsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opts & OPT_ZERORULEST) != 0) {
|
|
|
|
if ((*ioctlfunc)(fd, add, (void *)&obj) == -1) {
|
|
|
|
if ((opts & OPT_DONOTHING) == 0) {
|
2013-08-11 14:28:45 +00:00
|
|
|
char msg[80];
|
|
|
|
|
2021-12-13 22:54:38 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%d:ioctl(zero rule)",
|
2013-08-11 14:28:45 +00:00
|
|
|
fr->fr_flineno);
|
2021-12-22 02:37:19 +00:00
|
|
|
return(ipf_perror_fd(fd, ioctlfunc, msg));
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#ifdef USE_QUAD_T
|
|
|
|
printf("hits %qd bytes %qd ",
|
|
|
|
(long long)fr->fr_hits,
|
|
|
|
(long long)fr->fr_bytes);
|
|
|
|
#else
|
|
|
|
printf("hits %ld bytes %ld ",
|
|
|
|
fr->fr_hits, fr->fr_bytes);
|
|
|
|
#endif
|
|
|
|
printfr(fr, ioctlfunc);
|
|
|
|
}
|
|
|
|
} else if ((opts & OPT_REMOVE) != 0) {
|
|
|
|
if ((*ioctlfunc)(fd, del, (void *)&obj) == -1) {
|
2013-08-11 14:28:45 +00:00
|
|
|
if ((opts & OPT_DONOTHING) == 0) {
|
|
|
|
char msg[80];
|
|
|
|
|
2021-12-13 22:54:38 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%d:ioctl(delete rule)",
|
2013-08-11 14:28:45 +00:00
|
|
|
fr->fr_flineno);
|
2021-12-22 02:37:19 +00:00
|
|
|
return(ipf_perror_fd(fd, ioctlfunc, msg));
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((*ioctlfunc)(fd, add, (void *)&obj) == -1) {
|
2013-08-11 14:28:45 +00:00
|
|
|
if ((opts & OPT_DONOTHING) == 0) {
|
|
|
|
char msg[80];
|
|
|
|
|
2021-12-13 22:54:38 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%d:ioctl(add/insert rule)",
|
2013-08-11 14:28:45 +00:00
|
|
|
fr->fr_flineno);
|
2021-12-22 02:37:19 +00:00
|
|
|
return(ipf_perror_fd(fd, ioctlfunc, msg));
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-22 02:37:19 +00:00
|
|
|
return(0);
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
setsyslog(void)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
yysetdict(logwords);
|
|
|
|
yybreakondot = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
unsetsyslog(void)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
yyresetdict();
|
|
|
|
yybreakondot = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
fillgroup(frentry_t *fr)
|
2005-04-25 17:31:50 +00:00
|
|
|
{
|
|
|
|
frentry_t *f;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
for (f = frold; f != NULL; f = f->fr_next) {
|
|
|
|
if (f->fr_grhead == -1 && fr->fr_group == -1)
|
|
|
|
break;
|
|
|
|
if (f->fr_grhead == -1 || fr->fr_group == -1)
|
|
|
|
continue;
|
|
|
|
if (strcmp(f->fr_names + f->fr_grhead,
|
|
|
|
fr->fr_names + fr->fr_group) == 0)
|
2005-04-25 17:31:50 +00:00
|
|
|
break;
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 17:31:50 +00:00
|
|
|
if (f == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only copy down matching fields if the rules are of the same type
|
|
|
|
* and are of ipf type. The only fields that are copied are those
|
|
|
|
* that impact the rule parsing itself, eg. need for knowing what the
|
|
|
|
* protocol should be for rules with port comparisons in them.
|
|
|
|
*/
|
|
|
|
if (f->fr_type != fr->fr_type || f->fr_type != FR_T_IPF)
|
|
|
|
return;
|
|
|
|
|
2013-08-11 14:28:45 +00:00
|
|
|
if (fr->fr_family == 0 && f->fr_family != 0)
|
|
|
|
fr->fr_family = f->fr_family;
|
2005-04-25 17:31:50 +00:00
|
|
|
|
|
|
|
if (fr->fr_mproto == 0 && f->fr_mproto != 0)
|
|
|
|
fr->fr_mproto = f->fr_mproto;
|
|
|
|
if (fr->fr_proto == 0 && f->fr_proto != 0)
|
|
|
|
fr->fr_proto = f->fr_proto;
|
|
|
|
|
|
|
|
if ((fr->fr_mproto == 0) && ((fr->fr_flx & FI_TCPUDP) == 0) &&
|
2013-08-11 14:28:45 +00:00
|
|
|
((f->fr_flx & FI_TCPUDP) != 0)) {
|
2005-04-25 17:31:50 +00:00
|
|
|
fr->fr_flx |= FI_TCPUDP;
|
2013-08-11 14:28:45 +00:00
|
|
|
fr->fr_mflx |= FI_TCPUDP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
doipfexpr(char *line)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
int *array;
|
|
|
|
char *error;
|
|
|
|
|
|
|
|
array = parseipfexpr(line, &error);
|
|
|
|
if (array == NULL) {
|
|
|
|
fprintf(stderr, "%s:", error);
|
|
|
|
yyerror("error parsing ipf matching expression");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fr->fr_type = FR_T_IPFEXPR;
|
|
|
|
fr->fr_data = array;
|
|
|
|
fr->fr_dsize = array[0] * sizeof(*array);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
do_tuneint(char *varname, int value)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
char buffer[80];
|
|
|
|
|
|
|
|
strncpy(buffer, varname, 60);
|
|
|
|
buffer[59] = '\0';
|
|
|
|
strcat(buffer, "=");
|
2021-12-13 22:54:38 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%u", value);
|
2013-08-11 14:28:45 +00:00
|
|
|
ipf_dotuning(ipffd, buffer, ioctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
do_tunestr(char *varname, char *value)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (!strcasecmp(value, "true")) {
|
|
|
|
do_tuneint(varname, 1);
|
|
|
|
} else if (!strcasecmp(value, "false")) {
|
|
|
|
do_tuneint(varname, 0);
|
|
|
|
} else {
|
|
|
|
yyerror("did not find true/false where expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
setifname(frentry_t **frp, int idx, char *name)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = addname(frp, name);
|
|
|
|
if (pos == -1)
|
|
|
|
return;
|
|
|
|
(*frp)->fr_ifnames[idx] = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static int
|
|
|
|
addname(frentry_t **frp, char *name)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
frentry_t *f;
|
|
|
|
int nlen;
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
nlen = strlen(name) + 1;
|
|
|
|
f = realloc(*frp, (*frp)->fr_size + nlen);
|
|
|
|
if (*frp == frc)
|
|
|
|
frc = f;
|
|
|
|
*frp = f;
|
|
|
|
if (f == NULL)
|
2021-12-22 02:37:19 +00:00
|
|
|
return(-1);
|
2013-08-11 14:28:45 +00:00
|
|
|
if (f->fr_pnext != NULL)
|
|
|
|
*f->fr_pnext = f;
|
|
|
|
f->fr_size += nlen;
|
|
|
|
pos = f->fr_namelen;
|
|
|
|
f->fr_namelen += nlen;
|
|
|
|
strcpy(f->fr_names + pos, name);
|
|
|
|
f->fr_names[f->fr_namelen] = '\0';
|
2021-12-22 02:37:19 +00:00
|
|
|
return(pos);
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static frentry_t *
|
|
|
|
allocfr(void)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
frentry_t *fr;
|
|
|
|
|
|
|
|
fr = calloc(1, sizeof(*fr));
|
|
|
|
if (fr != NULL) {
|
|
|
|
fr->fr_size = sizeof(*fr);
|
|
|
|
fr->fr_comment = -1;
|
|
|
|
fr->fr_group = -1;
|
|
|
|
fr->fr_grhead = -1;
|
|
|
|
fr->fr_icmphead = -1;
|
|
|
|
fr->fr_ifnames[0] = -1;
|
|
|
|
fr->fr_ifnames[1] = -1;
|
|
|
|
fr->fr_ifnames[2] = -1;
|
|
|
|
fr->fr_ifnames[3] = -1;
|
|
|
|
fr->fr_tif.fd_name = -1;
|
|
|
|
fr->fr_rif.fd_name = -1;
|
|
|
|
fr->fr_dif.fd_name = -1;
|
|
|
|
}
|
2021-12-22 02:37:19 +00:00
|
|
|
return(fr);
|
2013-08-11 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
setgroup(frentry_t **frp, char *name)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = addname(frp, name);
|
|
|
|
if (pos == -1)
|
|
|
|
return;
|
|
|
|
(*frp)->fr_group = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
setgrhead(frentry_t **frp, char *name)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = addname(frp, name);
|
|
|
|
if (pos == -1)
|
|
|
|
return;
|
|
|
|
(*frp)->fr_grhead = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-20 17:07:20 +00:00
|
|
|
static void
|
|
|
|
seticmphead(frentry_t **frp, char *name)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = addname(frp, name);
|
|
|
|
if (pos == -1)
|
|
|
|
return;
|
|
|
|
(*frp)->fr_icmphead = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-12-20 17:07:20 +00:00
|
|
|
build_dstaddr_af(frentry_t *fp, void *ptr)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
struct ipp_s *ipp = ptr;
|
|
|
|
frentry_t *f = fp;
|
|
|
|
|
|
|
|
if (f->fr_family != AF_UNSPEC && ipp->f == AF_UNSPEC) {
|
|
|
|
ipp->f = f->fr_family;
|
|
|
|
ipp->v = f->fr_ip.fi_v;
|
|
|
|
}
|
|
|
|
if (ipp->f == AF_INET)
|
|
|
|
ipp->v = 4;
|
|
|
|
else if (ipp->f == AF_INET6)
|
|
|
|
ipp->v = 6;
|
|
|
|
|
|
|
|
for (; f != NULL; f = f->fr_next) {
|
|
|
|
f->fr_ip.fi_dst = ipp->a;
|
|
|
|
f->fr_mip.fi_dst = ipp->m;
|
|
|
|
f->fr_family = ipp->f;
|
|
|
|
f->fr_ip.fi_v = ipp->v;
|
|
|
|
f->fr_mip.fi_v = 0xf;
|
|
|
|
f->fr_datype = ipp->type;
|
|
|
|
if (ipp->ifpos != -1)
|
|
|
|
f->fr_ipf->fri_difpidx = ipp->ifpos;
|
|
|
|
}
|
|
|
|
fr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-12-20 17:07:20 +00:00
|
|
|
build_srcaddr_af(frentry_t *fp, void *ptr)
|
2013-08-11 14:28:45 +00:00
|
|
|
{
|
|
|
|
struct ipp_s *ipp = ptr;
|
|
|
|
frentry_t *f = fp;
|
|
|
|
|
|
|
|
if (f->fr_family != AF_UNSPEC && ipp->f == AF_UNSPEC) {
|
|
|
|
ipp->f = f->fr_family;
|
|
|
|
ipp->v = f->fr_ip.fi_v;
|
|
|
|
}
|
|
|
|
if (ipp->f == AF_INET)
|
|
|
|
ipp->v = 4;
|
|
|
|
else if (ipp->f == AF_INET6)
|
|
|
|
ipp->v = 6;
|
|
|
|
|
|
|
|
for (; f != NULL; f = f->fr_next) {
|
|
|
|
f->fr_ip.fi_src = ipp->a;
|
|
|
|
f->fr_mip.fi_src = ipp->m;
|
|
|
|
f->fr_family = ipp->f;
|
|
|
|
f->fr_ip.fi_v = ipp->v;
|
|
|
|
f->fr_mip.fi_v = 0xf;
|
|
|
|
f->fr_satype = ipp->type;
|
|
|
|
f->fr_ipf->fri_sifpidx = ipp->ifpos;
|
|
|
|
}
|
|
|
|
fr = NULL;
|
2005-04-25 17:31:50 +00:00
|
|
|
}
|