/*
* Copyright (C) 1993-2005 by Darren Reed.
* See the IPFILTER.LICENCE file for details on licencing.
*/
%{
#include "ipf.h"
#include <syslog.h>
#include "ipmon_l.h"
#include "ipmon.h"
#define YYDEBUG 1
extern int yydebug;
extern int yylineNum;
typedef struct opt {
int o_line;
int o_type;
int o_num;
char *o_str;
} opt_t;
%}
%union {
char *str;
}
%%
| assign
;
;
resetlexer();
free($1);
free($3);
}
;
;
matchopt { $$ = $1; }
;
direction { $$ = $1; }
| dstip { $$ = $1; }
| dstport { $$ = $1; }
| every { $$ = $1; }
| group { $$ = $1; }
| interface { $$ = $1; }
| protocol { $$ = $1; }
| result { $$ = $1; }
| rule { $$ = $1; }
| srcip { $$ = $1; }
| srcport { $$ = $1; }
| logtag { $$ = $1; }
| nattag { $$ = $1; }
| type { $$ = $1; }
;
doopt { $$ = $1; }
;
execute { $$ = $1; }
| save { $$ = $1; }
| syslog { $$ = $1; }
| nothing { $$ = $1; }
;
;
$$->o_ip = $3;
$$->o_num = $5; }
;
$$->o_num = $3; }
$$->o_str = $3; }
;
$$->o_num = 1; }
$$->o_num = $2; }
$$->o_num = 1; }
$$->o_num = $2; }
;
$$->o_num = $3; }
$$->o_str = $3; }
;
$$->o_str = $3; }
;
$$->o_num = $3; }
;
$$->o_str = $3; }
;
$$->o_num = $3; }
free($3);
}
;
$$->o_str = $3; }
;
;
$$->o_ip = $3;
$$->o_num = $5; }
;
$$->o_num = $3; }
$$->o_str = $3; }
;
$$->o_num = $3; }
;
| IPM_NAT { $$ = IPL_MAGIC_NAT; }
| IPM_STATE { $$ = IPL_MAGIC_STATE; }
;
$$->o_str = $2; }
;
$$->o_num = $2;
$$->o_str = $3; }
;
saveopts: { $$ = 0; }
| saveopt { $$ = $1; }
;
IPM_RAW { $$ = IPMDO_SAVERAW; }
;
;
IPM_NOTHING { $$ = 0; }
;
{ if ($1 > 255 || $3 > 255 || $5 > 255 || $7 > 255) {
yyerror("Invalid octet string for IP address");
return 0;
}
}
%%
{ "body", IPM_BODY },
{ "direction", IPM_DIRECTION },
{ "do", IPM_DO },
{ "dstip", IPM_DSTIP },
{ "dstport", IPM_DSTPORT },
{ "every", IPM_EVERY },
{ "execute", IPM_EXECUTE },
{ "group", IPM_GROUP },
{ "in", IPM_IN },
{ "interface", IPM_INTERFACE },
{ "ipf", IPM_IPF },
{ "logtag", IPM_LOGTAG },
{ "match", IPM_MATCH },
{ "nat", IPM_NAT },
{ "nattag", IPM_NATTAG },
{ "no", IPM_NO },
{ "nothing", IPM_NOTHING },
{ "out", IPM_OUT },
{ "packet", IPM_PACKET },
{ "packets", IPM_PACKETS },
{ "protocol", IPM_PROTOCOL },
{ "result", IPM_RESULT },
{ "rule", IPM_RULE },
{ "save", IPM_SAVE },
{ "raw", IPM_RAW },
{ "second", IPM_SECOND },
{ "seconds", IPM_SECONDS },
{ "srcip", IPM_SRCIP },
{ "srcport", IPM_SRCPORT },
{ "state", IPM_STATE },
{ "syslog", IPM_SYSLOG },
{ "with", IPM_WITH },
{ NULL, 0 }
};
{ IPM_DIRECTION, IPMAC_DIRECTION },
{ IPM_DSTIP, IPMAC_DSTIP },
{ IPM_DSTPORT, IPMAC_DSTPORT },
{ IPM_GROUP, IPMAC_GROUP },
{ IPM_INTERFACE, IPMAC_INTERFACE },
{ IPM_LOGTAG, IPMAC_LOGTAG },
{ IPM_NATTAG, IPMAC_NATTAG },
{ IPM_PACKET, IPMAC_EVERY },
{ IPM_PROTOCOL, IPMAC_PROTOCOL },
{ IPM_RESULT, IPMAC_RESULT },
{ IPM_RULE, IPMAC_RULE },
{ IPM_SECOND, IPMAC_EVERY },
{ IPM_SRCIP, IPMAC_SRCIP },
{ IPM_SRCPORT, IPMAC_SRCPORT },
{ IPM_TYPE, IPMAC_TYPE },
{ IPM_WITH, IPMAC_WITH },
{ 0, 0 }
};
int type;
{
opt_t *o;
if (o == NULL)
yyerror("sorry, out of memory");
o->o_num = 0;
o->o_str = (char *)0;
return o;
}
static void build_action(olist)
{
ipmon_action_t *a;
opt_t *o;
char c;
int i;
if (a == NULL)
return;
/*
* Check to see if the same comparator is being used more than
* once per matching statement.
*/
for (i = 0; macflags[i][0]; i++)
break;
free(o);
continue;
}
switch (o->o_type)
{
case IPM_DIRECTION :
a->ac_direction = o->o_num;
break;
case IPM_DSTIP :
break;
case IPM_DSTPORT :
break;
case IPM_EXECUTE :
c = *o->o_str;
if (c== '"'|| c == '\'') {
} else
} else
break;
case IPM_INTERFACE :
break;
case IPM_GROUP :
else
break;
case IPM_LOGTAG :
break;
case IPM_NATTAG :
break;
case IPM_PACKET :
break;
case IPM_PROTOCOL :
break;
case IPM_RULE :
break;
case IPM_RESULT :
a->ac_result = IPMR_BLOCK;
a->ac_result = IPMR_NOMATCH;
break;
case IPM_SECOND :
break;
case IPM_SRCIP :
break;
case IPM_SRCPORT :
break;
case IPM_SAVE :
if (a->ac_savefile != NULL) {
break;
}
break;
case IPM_SYSLOG :
if (a->ac_syslog != 0) {
break;
}
a->ac_syslog = 1;
break;
case IPM_TYPE :
break;
case IPM_WITH :
break;
default :
break;
}
free(o);
}
alist = a;
}
{
ipmon_action_t *a;
int matched;
matched = 0;
if ((a->ac_mflag & IPMAC_DIRECTION) != 0) {
if (a->ac_direction == IPM_IN) {
continue;
} else if (a->ac_direction == IPM_OUT) {
continue;
}
}
continue;
if ((a->ac_mflag & IPMAC_EVERY) != 0) {
t1--;
if (a->ac_second != 0) {
continue;
}
if (a->ac_packet != 0) {
if (a->ac_pktcnt == 0)
a->ac_pktcnt++;
a->ac_pktcnt = 0;
continue;
} else {
a->ac_pktcnt++;
continue;
}
}
}
if ((a->ac_mflag & IPMAC_DSTIP) != 0) {
continue;
}
if ((a->ac_mflag & IPMAC_DSTPORT) != 0) {
continue;
continue;
}
if ((a->ac_mflag & IPMAC_GROUP) != 0) {
FR_GROUPLEN) != 0)
continue;
}
if ((a->ac_mflag & IPMAC_INTERFACE) != 0) {
continue;
}
if ((a->ac_mflag & IPMAC_PROTOCOL) != 0) {
continue;
}
if ((a->ac_mflag & IPMAC_RESULT) != 0) {
if (a->ac_result != IPMR_NOMATCH)
continue;
continue;
if (a->ac_result != IPMR_BLOCK)
continue;
} else { /* Log only */
continue;
}
}
if ((a->ac_mflag & IPMAC_RULE) != 0) {
continue;
}
if ((a->ac_mflag & IPMAC_SRCIP) != 0) {
continue;
}
if ((a->ac_mflag & IPMAC_SRCPORT) != 0) {
continue;
continue;
}
if ((a->ac_mflag & IPMAC_LOGTAG) != 0) {
continue;
}
if ((a->ac_mflag & IPMAC_NATTAG) != 0) {
IPFTAG_LEN) != 0)
continue;
}
matched = 1;
/*
* It matched so now execute the command
*/
if (a->ac_syslog != 0) {
}
if (a->ac_dflag & IPMDO_SAVERAW)
else
}
switch (fork())
{
case 0 :
{
if ((opts & OPT_HEXHDR) != 0) {
sizeof(*ipl) +
sizeof(*ipf));
}
if ((opts & OPT_HEXBODY) != 0) {
}
}
exit(1);
}
case -1 :
break;
default :
break;
}
}
}
return matched;
}
static void free_action(a)
ipmon_action_t *a;
{
if (a->ac_savefile != NULL) {
free(a->ac_savefile);
a->ac_savefile = NULL;
}
}
}
}
}
free(a);
}
int load_config(file)
char *file;
{
ipmon_action_t *a;
char *s;
s = getenv("YYDEBUG");
if (s != NULL)
else
yydebug = 0;
free_action(a);
}
yylineNum = 1;
if (!fp) {
perror("load_config:fopen:");
return -1;
}
yyparse();
return 0;
}