ipnat_y.y revision 87c3980e28619b2b20d03f92d14b18fd89c183ca
%{
/*
* Copyright (C) 2003 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __FreeBSD__
# ifndef __FreeBSD_cc_version
# include <osreldate.h>
# else
# if __FreeBSD_cc_version < 430000
# include <osreldate.h>
# endif
# endif
#endif
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <strings.h>
#endif
#include <stdlib.h>
#include <stddef.h>
#ifdef IPFILTER_BPF
# include <pcap-int.h>
# include <pcap.h>
#endif
#include <netinet/in_systm.h>
#include <syslog.h>
#if __FreeBSD_version >= 300000
#endif
#include <netdb.h>
#include <resolv.h>
#include "ipf.h"
#if SOLARIS2 >= 10
#include "ipl.h"
#else
#endif
#include "ipnat_l.h"
#define YYDEBUG 1
extern int yydebug;
extern int yylineNum;
static int natfd = -1;
static void newnatrule __P((void));
static void setnatproto __P((int));
%}
%union {
char *str;
struct {
int pc;
} pc;
struct {
struct in_addr a;
struct in_addr m;
} ipp;
};
%%
| assign
;
}
resetlexer();
}
;
resetlexer();
free($1);
free($3);
}
;
;
xx: { newnatrule(); }
;
| mapblock
| redir
;
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
;
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
;
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
nat->in_ifnames[0],
sizeof(nat->in_ifnames[0]));
}
;
yyerror("proxy port numbers not consistant");
}
setnatproto($6);
free($4);
}
setnatproto($6);
free($3);
free($4);
}
;
free($1);
}
;
{ $$.a = $2; $$.m = $4;
dip:
($3 != 0 && $3 != 32))
yyerror("Invalid mask for dip");
;
;
;
;
;
;
;
;
;
;
;
sizeof(nat->in_ifnames[0]));
free($1);
}
;
free($1);
}
;
;
;
} else {
}
}
;
}
;
} else {
}
}
;
;
hostname { $$.a = $1;
$$.m.s_addr = 0xffffffff; }
;
;
;
;
}
;
;
;
"'sticky' for use with round-robin/IP splitting only\n");
} else
}
;
;
}
}
;
free($2);
}
}
}
;
YY_NUMBER { $$ = $1; }
;
| IPNY_TCP { $$ = IPPROTO_TCP; }
| IPNY_UDP { $$ = IPPROTO_UDP; }
;
YY_HEX { $$ = $1; }
;
"Unknown host '%s'\n",
$1);
free($1);
}
;
'=' { $$ = FR_EQUAL; }
| YY_CMP_GT { $$ = FR_GREATERT; }
| YY_CMP_GE { $$ = FR_GREATERTE; }
YY_RANGE_OUT { $$ = FR_OUTRANGE; }
| YY_RANGE_IN { $$ = FR_INRANGE; }
;
{ if ($1 > 255 || $3 > 255 || $5 > 255 || $7 > 255) {
yyerror("Invalid octet string for IP address");
return 0;
}
}
;
%%
{ "age", IPNY_AGE },
{ "any", IPNY_ANY },
{ "auto", IPNY_AUTO },
{ "bimap", IPNY_BIMAP },
{ "frag", IPNY_FRAG },
{ "from", IPNY_FROM },
{ "icmpidmap", IPNY_ICMPIDMAP },
{ "mask", IPNY_MASK },
{ "map", IPNY_MAP },
{ "map-block", IPNY_MAPBLOCK },
{ "mssclamp", IPNY_MSSCLAMP },
{ "port", IPNY_PORT },
{ "portmap", IPNY_PORTMAP },
{ "ports", IPNY_PORTS },
{ "proxy", IPNY_PROXY },
{ "range", IPNY_RANGE },
{ "rdr", IPNY_RDR },
{ "round-robin",IPNY_ROUNDROBIN },
{ "sticky", IPNY_STICKY },
{ "tag", IPNY_TAG },
{ "tcp", IPNY_TCP },
{ "to", IPNY_TO },
{ "udp", IPNY_UDP },
{ "-", '-' },
{ "->", IPNY_TLATE },
{ "eq", YY_CMP_EQ },
{ "ne", YY_CMP_NE },
{ "lt", YY_CMP_LT },
{ "gt", YY_CMP_GT },
{ "le", YY_CMP_LE },
{ "ge", YY_CMP_GE },
{ NULL, 0 }
};
int fd;
char *filename;
{
char *s;
s = getenv("YYDEBUG");
if (s)
else
yydebug = 0;
if (!fp) {
return -1;
}
} else
;
return 0;
}
int fd;
{
char *s;
int i;
yylineNum = 1;
return 0;
if (i == EOF)
return 0;
return 0;
return 0;
s = getenv("YYDEBUG");
if (s)
else
yydebug = 0;
yyparse();
return 1;
}
static void newnatrule()
{
ipnat_t *n;
n = calloc(1, sizeof(*n));
if (n == NULL)
return;
else {
nat = n;
}
}
static void setnatproto(p)
int p;
{
switch (p)
{
case IPPROTO_TCP :
break;
case IPPROTO_UDP :
break;
default :
}
break;
}
}
int fd;
void *ptr;
{
add = 0;
del = 0;
if ((opts & OPT_DONOTHING) != 0)
fd = -1;
if (opts & OPT_ZERORULEST) {
} else if (opts & OPT_INACTIVE) {
} else {
}
if ((opts & OPT_ZERORULEST) != 0) {
if ((opts & OPT_DONOTHING) == 0) {
perror("ioctl(SIOCZRLST)");
}
} 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
}
} else if ((opts & OPT_REMOVE) != 0) {
if ((opts & OPT_DONOTHING) == 0) {
perror("ioctl(delete nat rule)");
}
}
} else {
if ((opts & OPT_DONOTHING) == 0) {
}
}
}
}