4 * Copyright (C) 2001-2006 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
10 #include <sys/ioctl.h>
13 # include "pcap-bpf.h"
17 #include "netinet/ip_pool.h"
18 #include "netinet/ip_htable.h"
19 #include "netinet/ipl.h"
23 #define DOALL(x) for (fr = frc; fr != NULL; fr = fr->fr_next) { x }
24 #define DOREM(x) for (; fr != NULL; fr = fr->fr_next) { x }
26 extern
void yyerror __P
((char *));
27 extern
int yyparse __P
((void));
28 extern
int yylex __P
((void));
33 static void newrule __P
((void));
34 static void setipftype __P
((void));
35 static u_32_t lookuphost __P
((char *));
36 static void dobpf __P
((int, char *));
37 static void resetaddr __P
((void));
38 static struct alist_s
*newalist __P
((struct alist_s
*));
39 static u_int makehash __P
((struct alist_s
*));
40 static int makepool __P
((struct alist_s
*));
41 static frentry_t
*addrule __P
((void));
42 static void setsyslog __P
((void));
43 static void unsetsyslog __P
((void));
44 static void fillgroup __P
((frentry_t
*));
46 frentry_t
*fr
= NULL
, *frc
= NULL
, *frtop
= NULL
, *frold
= NULL
;
48 static int ifpflag
= 0;
49 static int nowith
= 0;
50 static int dynamic
= -1;
51 static int pooled
= 0;
52 static int hashed
= 0;
53 static int nrules
= 0;
54 static int newlist
= 0;
56 static int ipffd
= -1;
57 static int *yycont
= 0;
58 static ioctlfunc_t ipfioctl
[IPL_LOGSIZE
];
59 static addfunc_t ipfaddfunc
= NULL
;
60 static struct wordtab ipfwords
[95];
61 static struct wordtab addrwords
[4];
62 static struct wordtab maskwords
[5];
63 static struct wordtab icmpcodewords
[17];
64 static struct wordtab icmptypewords
[16];
65 static struct wordtab ipv4optwords
[25];
66 static struct wordtab ipv4secwords
[9];
67 static struct wordtab ipv6optwords
[9];
68 static struct wordtab logwords
[33];
77 struct alist_s
*alist
;
96 %type
<num
> facility priority icmpcode seclevel secname icmptype
97 %type
<num
> opt compare range opttype flagset optlist ipv6hdrlist ipv6hdr
98 %type
<num
> portc porteq
99 %type
<ipa
> hostname ipv4 ipv4mask ipv4_16 ipv4_24
101 %type
<ipp
> addr ipaddr
102 %type
<str
> servicename name interfacename
103 %type
<pc
> portrange portcomp
104 %type
<alist
> addrlist poollist
107 %token
<num
> YY_NUMBER YY_HEX
110 %token YY_CMP_EQ YY_CMP_NE YY_CMP_LE YY_CMP_GE YY_CMP_LT YY_CMP_GT
111 %token YY_RANGE_OUT YY_RANGE_IN
114 %token IPFY_PASS IPFY_BLOCK IPFY_COUNT IPFY_CALL IPFY_NOMATCH
115 %token IPFY_RETICMP IPFY_RETRST IPFY_RETICMPASDST
116 %token IPFY_IN IPFY_OUT
117 %token IPFY_QUICK IPFY_ON IPFY_OUTVIA IPFY_INVIA
118 %token IPFY_DUPTO IPFY_TO IPFY_FROUTE IPFY_REPLY_TO IPFY_ROUTETO
119 %token IPFY_TOS IPFY_TTL IPFY_PROTO
120 %token IPFY_HEAD IPFY_GROUP
121 %token IPFY_AUTH IPFY_PREAUTH
122 %token IPFY_LOG IPFY_BODY IPFY_FIRST IPFY_LEVEL IPFY_ORBLOCK
123 %token IPFY_LOGTAG IPFY_MATCHTAG IPFY_SETTAG IPFY_SKIP
124 %token IPFY_FROM IPFY_ALL IPFY_ANY IPFY_BPFV4 IPFY_BPFV6 IPFY_POOL IPFY_HASH
126 %token IPFY_ESP IPFY_AH
127 %token IPFY_WITH IPFY_AND IPFY_NOT IPFY_NO IPFY_OPT
128 %token IPFY_TCPUDP IPFY_TCP IPFY_UDP
129 %token IPFY_FLAGS IPFY_MULTICAST
130 %token IPFY_MASK IPFY_BROADCAST IPFY_NETWORK IPFY_NETMASKED IPFY_PEER
133 %token IPFY_ICMP IPFY_ICMPTYPE IPFY_ICMPCODE
134 %token IPFY_IPOPTS IPFY_SHORT IPFY_NAT IPFY_BADSRC IPFY_LOWTTL IPFY_FRAG
135 %token IPFY_MBCAST IPFY_BAD IPFY_BADNAT IPFY_OOW IPFY_NEWISN IPFY_NOICMPERR
136 %token IPFY_KEEP IPFY_STATE IPFY_FRAGS IPFY_LIMIT IPFY_STRICT IPFY_AGE
137 %token IPFY_SYNC IPFY_FRAGBODY
138 %token IPFY_IPOPT_NOP IPFY_IPOPT_RR IPFY_IPOPT_ZSU IPFY_IPOPT_MTUP
139 %token IPFY_IPOPT_MTUR IPFY_IPOPT_ENCODE IPFY_IPOPT_TS IPFY_IPOPT_TR
140 %token IPFY_IPOPT_SEC IPFY_IPOPT_LSRR IPFY_IPOPT_ESEC IPFY_IPOPT_CIPSO
141 %token IPFY_IPOPT_SATID IPFY_IPOPT_SSRR IPFY_IPOPT_ADDEXT IPFY_IPOPT_VISA
142 %token IPFY_IPOPT_IMITD IPFY_IPOPT_EIP IPFY_IPOPT_FINN IPFY_IPOPT_DPS
143 %token IPFY_IPOPT_SDB IPFY_IPOPT_NSAPA IPFY_IPOPT_RTRALRT IPFY_IPOPT_UMP
144 %token IPFY_SECCLASS IPFY_SEC_UNC IPFY_SEC_CONF IPFY_SEC_RSV1 IPFY_SEC_RSV2
145 %token IPFY_SEC_RSV4 IPFY_SEC_SEC IPFY_SEC_TS IPFY_SEC_RSV3
147 %token IPF6_V6HDRS IPFY_IPV6OPT IPFY_IPV6OPT_DSTOPTS IPFY_IPV6OPT_HOPOPTS
148 %token IPFY_IPV6OPT_IPV6 IPFY_IPV6OPT_NONE IPFY_IPV6OPT_ROUTING
149 %token IPFY_IPV6OPT_MOBILITY IPFY_IPV6OPT_ESP IPFY_IPV6OPT_FRAG
151 %token IPFY_ICMPT_UNR IPFY_ICMPT_ECHO IPFY_ICMPT_ECHOR IPFY_ICMPT_SQUENCH
152 %token IPFY_ICMPT_REDIR IPFY_ICMPT_TIMEX IPFY_ICMPT_PARAMP IPFY_ICMPT_TIMEST
153 %token IPFY_ICMPT_TIMESTREP IPFY_ICMPT_INFOREQ IPFY_ICMPT_INFOREP
154 %token IPFY_ICMPT_MASKREQ IPFY_ICMPT_MASKREP IPFY_ICMPT_ROUTERAD
155 %token IPFY_ICMPT_ROUTERSOL
157 %token IPFY_ICMPC_NETUNR IPFY_ICMPC_HSTUNR IPFY_ICMPC_PROUNR IPFY_ICMPC_PORUNR
158 %token IPFY_ICMPC_NEEDF IPFY_ICMPC_SRCFAIL IPFY_ICMPC_NETUNK IPFY_ICMPC_HSTUNK
159 %token IPFY_ICMPC_ISOLATE IPFY_ICMPC_NETPRO IPFY_ICMPC_HSTPRO
160 %token IPFY_ICMPC_NETTOS IPFY_ICMPC_HSTTOS IPFY_ICMPC_FLTPRO IPFY_ICMPC_HSTPRE
161 %token IPFY_ICMPC_CUTPRE
163 %token IPFY_FAC_KERN IPFY_FAC_USER IPFY_FAC_MAIL IPFY_FAC_DAEMON IPFY_FAC_AUTH
164 %token IPFY_FAC_SYSLOG IPFY_FAC_LPR IPFY_FAC_NEWS IPFY_FAC_UUCP IPFY_FAC_CRON
165 %token IPFY_FAC_LOCAL0 IPFY_FAC_LOCAL1 IPFY_FAC_LOCAL2 IPFY_FAC_LOCAL3
166 %token IPFY_FAC_LOCAL4 IPFY_FAC_LOCAL5 IPFY_FAC_LOCAL6 IPFY_FAC_LOCAL7
167 %token IPFY_FAC_SECURITY IPFY_FAC_FTP IPFY_FAC_AUTHPRIV IPFY_FAC_AUDIT
168 %token IPFY_FAC_LFMT IPFY_FAC_CONSOLE
170 %token IPFY_PRI_EMERG IPFY_PRI_ALERT IPFY_PRI_CRIT IPFY_PRI_ERR IPFY_PRI_WARN
171 %token IPFY_PRI_NOTICE IPFY_PRI_INFO IPFY_PRI_DEBUG
179 line: rule
{ while
((fr
= frtop
) != NULL
) {
182 (*ipfaddfunc
)(ipffd
, ipfioctl
[IPL_LOGIPF
], fr
);
194 assign: YY_STR assigning YY_STR
';' { set_variable
($1, $3);
203 '=' { yyvarnext
= 1; }
214 rulehead markin inopts rulemain ruletail intag ruletail2
218 rulehead markout outopts rulemain ruletail outtag ruletail2
223 | xx insert collection action
226 markin: IPFY_IN
{ fr
->fr_flags |
= FR_INQUE
; }
230 IPFY_OUT
{ fr
->fr_flags |
= FR_OUTQUE
; }
243 IPFY_BPFV4
'{' YY_STR
'}' { dobpf
(4, $3); free
($3); }
244 | IPFY_BPFV6
'{' YY_STR
'}' { dobpf
(6, $3); free
($3); }
255 intag: settagin matchtagin
258 outtag: settagout matchtagout
262 '@' YY_NUMBER
{ fr
->fr_hits
= (U_QUAD_T
)$2 + 1; }
266 | YY_NUMBER
{ fr
->fr_collect
= $1; }
270 | IPFY_PASS
{ fr
->fr_flags |
= FR_PASS
; }
271 | IPFY_NOMATCH
{ fr
->fr_flags |
= FR_NOMATCH
; }
273 | IPFY_COUNT
{ fr
->fr_flags |
= FR_ACCOUNT
; }
275 | IPFY_SKIP YY_NUMBER
{ fr
->fr_flags |
= FR_SKIP
;
278 | IPFY_CALL IPFY_NOW func
{ fr
->fr_flags |
= FR_CALLNOW
; }
282 | blocked blockreturn
286 IPFY_BLOCK
{ fr
->fr_flags
= FR_BLOCK
; }
289 IPFY_RETICMP
{ fr
->fr_flags |
= FR_RETICMP
; }
290 | IPFY_RETICMP returncode
{ fr
->fr_flags |
= FR_RETICMP
; }
291 | IPFY_RETICMPASDST
{ fr
->fr_flags |
= FR_FAKEICMP
; }
292 | IPFY_RETICMPASDST returncode
{ fr
->fr_flags |
= FR_FAKEICMP
; }
293 | IPFY_RETRST
{ fr
->fr_flags |
= FR_RETRST
; }
296 log: IPFY_LOG
{ fr
->fr_flags |
= FR_LOG
; }
297 | IPFY_LOG logoptions
{ fr
->fr_flags |
= FR_LOG
; }
300 auth: IPFY_AUTH
{ fr
->fr_flags |
= FR_AUTH
; }
301 | IPFY_AUTH blockreturn
{ fr
->fr_flags |
= FR_AUTH
;}
302 | IPFY_PREAUTH
{ fr
->fr_flags |
= FR_PREAUTH
; }
305 func: YY_STR
'/' YY_NUMBER
{ fr
->fr_func
= nametokva
($1,
306 ipfioctl
[IPL_LOGIPF
]);
338 tos: | settos YY_NUMBER
{ DOALL
(fr
->fr_tos
= $2; fr
->fr_mtos
= 0xff;) }
339 | settos YY_HEX
{ DOALL
(fr
->fr_tos
= $2; fr
->fr_mtos
= 0xff;) }
340 | settos lstart toslist lend
343 settos: IPFY_TOS
{ setipftype
(); }
347 YY_NUMBER
{ DOALL
(fr
->fr_tos
= $1; fr
->fr_mtos
= 0xff;) }
348 | YY_HEX
{ DOREM
(fr
->fr_tos
= $1; fr
->fr_mtos
= 0xff;) }
349 | toslist lmore YY_NUMBER
350 { DOREM
(fr
->fr_tos
= $3; fr
->fr_mtos
= 0xff;) }
351 | toslist lmore YY_HEX
352 { DOREM
(fr
->fr_tos
= $3; fr
->fr_mtos
= 0xff;) }
355 ttl: | setttl YY_NUMBER
356 { DOALL
(fr
->fr_ttl
= $2; fr
->fr_mttl
= 0xff;) }
357 | setttl lstart ttllist lend
360 lstart: '(' { newlist
= 1; fr
= frc
; added
= 0; }
363 lend: ')' { nrules
+= added
; }
366 lmore: lanother
{ if
(newlist
== 1) {
379 setttl: IPFY_TTL
{ setipftype
(); }
383 YY_NUMBER
{ DOREM
(fr
->fr_ttl
= $1; fr
->fr_mttl
= 0xff;) }
384 | ttllist lmore YY_NUMBER
385 { DOREM
(fr
->fr_ttl
= $3; fr
->fr_mttl
= 0xff;) }
388 proto: | protox protocol
{ yyresetdict
(); }
391 protox: IPFY_PROTO
{ setipftype
();
396 ip: srcdst flags icmp
399 group: | IPFY_GROUP YY_STR
{ DOALL
(strncpy
(fr
->fr_group
, $2, \
403 | IPFY_GROUP YY_NUMBER
{ DOALL
(sprintf
(fr
->fr_group
, "%d", \
408 head: | IPFY_HEAD YY_STR
{ DOALL
(strncpy
(fr
->fr_grhead
, $2, \
411 | IPFY_HEAD YY_NUMBER
{ DOALL
(sprintf
(fr
->fr_grhead
, "%d", \
416 | IPFY_SETTAG
'(' taginlist
')'
421 | taginlist
',' taginspec
428 nattag: IPFY_NAT
'=' YY_STR
{ DOALL
(strncpy
(fr
->fr_nattag.ipt_tag
,\
431 | IPFY_NAT
'=' YY_NUMBER
{ DOALL
(sprintf
(fr
->fr_nattag.ipt_tag
,\
432 "%d", $3 & 0xffffffff);) }
435 logtag: IPFY_LOG
'=' YY_NUMBER
{ DOALL
(fr
->fr_logtag
= $3;) }
439 | IPFY_SETTAG
'(' tagoutlist
')'
444 | tagoutlist
',' tagoutspec
453 | IPFY_MATCHTAG
'(' tagoutlist
')'
457 | IPFY_MATCHTAG
'(' taginlist
')'
460 pps: | IPFY_PPS YY_NUMBER
{ DOALL
(fr
->fr_pps
= $2;) }
463 new: | savegroup file restoregroup
478 IPFY_QUICK
{ fr
->fr_flags |
= FR_QUICK
; }
482 | IPFY_ON lstart onlist lend
483 | IPFY_ON onname IPFY_INVIA vianame
484 | IPFY_ON onname IPFY_OUTVIA vianame
487 onlist: onname
{ DOREM
(strncpy
(fr
->fr_ifnames
[0], $1.if1
, \
488 sizeof
(fr
->fr_ifnames
[0])); \
489 if
($1.if2
!= NULL
) { \
490 strncpy
(fr
->fr_ifnames
[1], \
492 sizeof
(fr
->fr_ifnames
[1]));\
495 | onlist lmore onname
{ DOREM
(strncpy
(fr
->fr_ifnames
[0], $3.if1
, \
496 sizeof
(fr
->fr_ifnames
[0])); \
497 if
($3.if2
!= NULL
) { \
498 strncpy
(fr
->fr_ifnames
[1], \
500 sizeof
(fr
->fr_ifnames
[1]));\
505 onname: interfacename
506 { strncpy
(fr
->fr_ifnames
[0], $1, sizeof
(fr
->fr_ifnames
[0]));
507 $$.if1
= fr
->fr_ifnames
[0];
511 | interfacename
',' interfacename
512 { strncpy
(fr
->fr_ifnames
[0], $1, sizeof
(fr
->fr_ifnames
[0]));
513 $$.if1
= fr
->fr_ifnames
[0];
515 strncpy
(fr
->fr_ifnames
[1], $3, sizeof
(fr
->fr_ifnames
[1]));
516 $$.if1
= fr
->fr_ifnames
[1];
523 { strncpy
(fr
->fr_ifnames
[2], $1, sizeof
(fr
->fr_ifnames
[2]));
527 { strncpy
(fr
->fr_ifnames
[2], $1, sizeof
(fr
->fr_ifnames
[2]));
529 strncpy
(fr
->fr_ifnames
[3], $3, sizeof
(fr
->fr_ifnames
[3]));
535 { strncpy
(fr
->fr_dif.fd_ifname
, $2, sizeof
(fr
->fr_dif.fd_ifname
));
536 fr
->fr_flags |
= FR_DUP
;
539 | IPFY_DUPTO name duptoseparator hostname
540 { strncpy
(fr
->fr_dif.fd_ifname
, $2, sizeof
(fr
->fr_dif.fd_ifname
));
541 fr
->fr_flags |
= FR_DUP
;
542 fr
->fr_dif.fd_ip
= $4;
546 | IPFY_DUPTO name duptoseparator YY_IPV6
547 { strncpy
(fr
->fr_dif.fd_ifname
, $2, sizeof
(fr
->fr_dif.fd_ifname
));
548 bcopy
(&$4, &fr
->fr_dif.fd_ip6
, sizeof
(fr
->fr_dif.fd_ip6
));
549 fr
->fr_flags |
= FR_DUP
;
556 ':' { yyexpectaddr
= 1; yycont
= &yyexpectaddr
; resetaddr
(); }
559 froute: IPFY_FROUTE
{ fr
->fr_flags |
= FR_FASTROUTE
; }
563 { strncpy
(fr
->fr_tif.fd_ifname
, $2, sizeof
(fr
->fr_tif.fd_ifname
));
566 | routeto name duptoseparator hostname
567 { strncpy
(fr
->fr_tif.fd_ifname
, $2, sizeof
(fr
->fr_tif.fd_ifname
));
568 fr
->fr_tif.fd_ip
= $4;
572 | routeto name duptoseparator YY_IPV6
573 { strncpy
(fr
->fr_tif.fd_ifname
, $2, sizeof
(fr
->fr_tif.fd_ifname
));
574 bcopy
(&$4, &fr
->fr_tif.fd_ip6
, sizeof
(fr
->fr_tif.fd_ip6
));
587 { strncpy
(fr
->fr_rif.fd_ifname
, $2, sizeof
(fr
->fr_rif.fd_ifname
));
590 | IPFY_REPLY_TO name duptoseparator hostname
591 { strncpy
(fr
->fr_rif.fd_ifname
, $2, sizeof
(fr
->fr_rif.fd_ifname
));
592 fr
->fr_rif.fd_ip
= $4;
599 | logoptions logoption
603 IPFY_BODY
{ fr
->fr_flags |
= FR_LOGBODY
; }
604 | IPFY_FIRST
{ fr
->fr_flags |
= FR_LOGFIRST
; }
605 | IPFY_ORBLOCK
{ fr
->fr_flags |
= FR_LOGORBLOCK
; }
606 | level loglevel
{ unsetsyslog
(); }
610 starticmpcode icmpcode
')' { fr
->fr_icode
= $2; yyresetdict
(); }
614 '(' { yysetdict
(icmpcodewords
); }
622 YY_NUMBER
{ DOREM
(fr
->fr_proto
= $1; \
623 fr
->fr_mproto
= 0xff;) }
624 | YY_STR
{ if
(!strcmp
($1, "tcp-udp")) {
625 DOREM
(fr
->fr_flx |
= FI_TCPUDP
; \
626 fr
->fr_mflx |
= FI_TCPUDP
;)
628 int p
= getproto
($1);
630 yyerror("protocol unknown");
631 DOREM
(fr
->fr_proto
= p
; \
632 fr
->fr_mproto
= 0xff;)
636 | YY_STR nextstring YY_STR
637 { if
(!strcmp
($1, "tcp") &&
638 !strcmp
($3, "udp")) {
639 DOREM
(fr
->fr_flx |
= FI_TCPUDP
; \
640 fr
->fr_mflx |
= FI_TCPUDP
;)
649 '/' { yysetdict
(NULL
); }
652 fromto: from srcobject to dstobject
{ yyexpectaddr
= 0; yycont
= NULL
; }
653 | to dstobject
{ yyexpectaddr
= 0; yycont
= NULL
; }
654 | from srcobject
{ yyexpectaddr
= 0; yycont
= NULL
; }
657 from: IPFY_FROM
{ setipftype
();
662 printf
("set yyexpectaddr\n");
663 yycont
= &yyexpectaddr
;
664 yysetdict
(addrwords
);
668 to: IPFY_TO
{ if
(fr
== NULL
)
672 printf
("set yyexpectaddr\n");
673 yycont
= &yyexpectaddr
;
674 yysetdict
(addrwords
);
678 with: | andwith withlist
682 IPFY_WITH
{ nowith
= 0; setipftype
(); }
683 | IPFY_AND
{ nowith
= 0; setipftype
(); }
686 flags: | startflags flagset
687 { DOALL
(fr
->fr_tcpf
= $2; fr
->fr_tcpfm
= FR_TCPFMAX
;) }
688 | startflags flagset
'/' flagset
689 { DOALL
(fr
->fr_tcpf
= $2; fr
->fr_tcpfm
= $4;) }
690 | startflags
'/' flagset
691 { DOALL
(fr
->fr_tcpf
= 0; fr
->fr_tcpfm
= $3;) }
692 | startflags YY_NUMBER
693 { DOALL
(fr
->fr_tcpf
= $2; fr
->fr_tcpfm
= FR_TCPFMAX
;) }
694 | startflags
'/' YY_NUMBER
695 { DOALL
(fr
->fr_tcpf
= 0; fr
->fr_tcpfm
= $3;) }
696 | startflags YY_NUMBER
'/' YY_NUMBER
697 { DOALL
(fr
->fr_tcpf
= $2; fr
->fr_tcpfm
= $4;) }
698 | startflags flagset
'/' YY_NUMBER
699 { DOALL
(fr
->fr_tcpf
= $2; fr
->fr_tcpfm
= $4;) }
700 | startflags YY_NUMBER
'/' flagset
701 { DOALL
(fr
->fr_tcpf
= $2; fr
->fr_tcpfm
= $4;) }
705 IPFY_FLAGS
{ if
(frc
->fr_type
!= FR_T_IPF
)
706 yyerror("flags with non-ipf type rule");
707 if
(frc
->fr_proto
!= IPPROTO_TCP
)
708 yyerror("flags with non-TCP rule");
713 YY_STR
{ $$
= tcpflags
($1); free
($1); }
714 | YY_HEX
{ $$
= $1; }
718 { yyresetdict
(); } fromport
720 |
'!' srcaddr srcport
721 { DOALL
(fr
->fr_flags |
= FR_NOTSRCIP
;) }
725 addr
{ DOREM
(bcopy
(&($1.a
), &fr
->fr_ip.fi_src
, sizeof
($1.a
)); \
726 bcopy
(&($1.m
), &fr
->fr_mip.fi_src
, sizeof
($1.m
)); \
727 if
(dynamic
!= -1) { \
728 fr
->fr_satype
= ifpflag
; \
729 fr
->fr_ipf
->fri_sifpidx
= dynamic
; \
730 } else if
(pooled || hashed
) \
731 fr
->fr_satype
= FRI_LOOKUP
;)
733 | lstart srcaddrlist lend
737 addr
{ DOREM
(bcopy
(&($1.a
), &fr
->fr_ip.fi_src
, sizeof
($1.a
)); \
738 bcopy
(&($1.m
), &fr
->fr_mip.fi_src
, sizeof
($1.m
)); \
739 if
(dynamic
!= -1) { \
740 fr
->fr_satype
= ifpflag
; \
741 fr
->fr_ipf
->fri_sifpidx
= dynamic
; \
742 } else if
(pooled || hashed
) \
743 fr
->fr_satype
= FRI_LOOKUP
;)
745 | srcaddrlist lmore addr
746 { DOREM
(bcopy
(&($3.a
), &fr
->fr_ip.fi_src
, sizeof
($3.a
)); \
747 bcopy
(&($3.m
), &fr
->fr_mip.fi_src
, sizeof
($3.m
)); \
748 if
(dynamic
!= -1) { \
749 fr
->fr_satype
= ifpflag
; \
750 fr
->fr_ipf
->fri_sifpidx
= dynamic
; \
751 } else if
(pooled || hashed
) \
752 fr
->fr_satype
= FRI_LOOKUP
;)
758 { DOALL
(fr
->fr_scmp
= $1.pc
; fr
->fr_sport
= $1.p1
;) }
760 { DOALL
(fr
->fr_scmp
= $1.pc
; fr
->fr_sport
= $1.p1
; \
761 fr
->fr_stop
= $1.p2
;) }
762 | porteq lstart srcportlist lend
768 { DOALL
(fr
->fr_scmp
= $1.pc
; fr
->fr_sport
= $1.p1
;) }
770 { DOALL
(fr
->fr_scmp
= $1.pc
; fr
->fr_sport
= $1.p1
; \
771 fr
->fr_stop
= $1.p2
;) }
772 | porteq lstart srcportlist lend
777 portnum
{ DOREM
(fr
->fr_scmp
= FR_EQUAL
; fr
->fr_sport
= $1;) }
778 | portnum
':' portnum
779 { DOREM
(fr
->fr_scmp
= FR_INCRANGE
; fr
->fr_sport
= $1; \
781 | portnum YY_RANGE_IN portnum
782 { DOREM
(fr
->fr_scmp
= FR_INRANGE
; fr
->fr_sport
= $1; \
784 | srcportlist lmore portnum
785 { DOREM
(fr
->fr_scmp
= FR_EQUAL
; fr
->fr_sport
= $3;) }
786 | srcportlist lmore portnum
':' portnum
787 { DOREM
(fr
->fr_scmp
= FR_INCRANGE
; fr
->fr_sport
= $3; \
789 | srcportlist lmore portnum YY_RANGE_IN portnum
790 { DOREM
(fr
->fr_scmp
= FR_INRANGE
; fr
->fr_sport
= $3; \
795 { yyresetdict
(); } toport
797 |
'!' dstaddr dstport
798 { DOALL
(fr
->fr_flags |
= FR_NOTDSTIP
;) }
802 addr
{ DOREM
(bcopy
(&($1.a
), &fr
->fr_ip.fi_dst
, sizeof
($1.a
)); \
803 bcopy
(&($1.m
), &fr
->fr_mip.fi_dst
, sizeof
($1.m
)); \
804 if
(dynamic
!= -1) { \
805 fr
->fr_datype
= ifpflag
; \
806 fr
->fr_ipf
->fri_difpidx
= dynamic
; \
807 } else if
(pooled || hashed
) \
808 fr
->fr_datype
= FRI_LOOKUP
;)
810 | lstart dstaddrlist lend
814 addr
{ DOREM
(bcopy
(&($1.a
), &fr
->fr_ip.fi_dst
, sizeof
($1.a
)); \
815 bcopy
(&($1.m
), &fr
->fr_mip.fi_dst
, sizeof
($1.m
)); \
816 if
(dynamic
!= -1) { \
817 fr
->fr_datype
= ifpflag
; \
818 fr
->fr_ipf
->fri_difpidx
= dynamic
; \
819 } else if
(pooled || hashed
) \
820 fr
->fr_datype
= FRI_LOOKUP
;)
822 | dstaddrlist lmore addr
823 { DOREM
(bcopy
(&($3.a
), &fr
->fr_ip.fi_dst
, sizeof
($3.a
)); \
824 bcopy
(&($3.m
), &fr
->fr_mip.fi_dst
, sizeof
($3.m
)); \
825 if
(dynamic
!= -1) { \
826 fr
->fr_datype
= ifpflag
; \
827 fr
->fr_ipf
->fri_difpidx
= dynamic
; \
828 } else if
(pooled || hashed
) \
829 fr
->fr_datype
= FRI_LOOKUP
;)
836 { DOALL
(fr
->fr_dcmp
= $1.pc
; fr
->fr_dport
= $1.p1
;) }
838 { DOALL
(fr
->fr_dcmp
= $1.pc
; fr
->fr_dport
= $1.p1
; \
839 fr
->fr_dtop
= $1.p2
;) }
840 | porteq lstart dstportlist lend
846 { DOALL
(fr
->fr_dcmp
= $1.pc
; fr
->fr_dport
= $1.p1
;) }
848 { DOALL
(fr
->fr_dcmp
= $1.pc
; fr
->fr_dport
= $1.p1
; \
849 fr
->fr_dtop
= $1.p2
;) }
850 | porteq lstart dstportlist lend
855 portnum
{ DOREM
(fr
->fr_dcmp
= FR_EQUAL
; fr
->fr_dport
= $1;) }
856 | portnum
':' portnum
857 { DOREM
(fr
->fr_dcmp
= FR_INCRANGE
; fr
->fr_dport
= $1; \
859 | portnum YY_RANGE_IN portnum
860 { DOREM
(fr
->fr_dcmp
= FR_INRANGE
; fr
->fr_dport
= $1; \
862 | dstportlist lmore portnum
863 { DOREM
(fr
->fr_dcmp
= FR_EQUAL
; fr
->fr_dport
= $3;) }
864 | dstportlist lmore portnum
':' portnum
865 { DOREM
(fr
->fr_dcmp
= FR_INCRANGE
; fr
->fr_dport
= $3; \
867 | dstportlist lmore portnum YY_RANGE_IN portnum
868 { DOREM
(fr
->fr_dcmp
= FR_INRANGE
; fr
->fr_dport
= $3; \
872 addr: pool
'/' YY_NUMBER
{ pooled
= 1;
873 $$.a.iplookuptype
= IPLT_POOL
;
874 $$.a.iplookupsubtype
= 0;
875 $$.a.iplookupnum
= $3; }
876 | pool
'/' YY_STR
{ pooled
= 1;
877 $$.a.iplookuptype
= IPLT_POOL
;
878 $$.a.iplookupsubtype
= 1;
879 strncpy
($$.a.iplookupname
, $3,
880 sizeof
($$.a.iplookupname
));
882 | pool
'=' '(' poollist
')' { pooled
= 1;
883 $$.a.iplookuptype
= IPLT_POOL
;
884 $$.a.iplookupsubtype
= 0;
885 $$.a.iplookupnum
= makepool
($4); }
886 | hash
'/' YY_NUMBER
{ hashed
= 1;
887 $$.a.iplookuptype
= IPLT_HASH
;
888 $$.a.iplookupsubtype
= 0;
889 $$.a.iplookupnum
= $3; }
890 | hash
'/' YY_STR
{ hashed
= 1;
891 $$.a.iplookuptype
= IPLT_HASH
;
892 $$.a.iplookupsubtype
= 1;
893 strncpy
($$.a.iplookupname
, $3,
894 sizeof
($$.a.iplookupname
));
896 | hash
'=' '(' addrlist
')' { hashed
= 1;
897 $$.a.iplookuptype
= IPLT_HASH
;
898 $$.a.iplookupsubtype
= 0;
899 $$.a.iplookupnum
= makehash
($4); }
900 | ipaddr
{ bcopy
(&$1, &$$
, sizeof
($$
));
904 ipaddr: IPFY_ANY
{ bzero
(&($$
), sizeof
($$
));
907 | hostname
{ $$.a.in4
= $1;
908 $$.m.in4_addr
= 0xffffffff;
910 | hostname
{ yyresetdict
();
911 $$.a.in4_addr
= $1.s_addr
; }
912 maskspace
{ yysetdict
(maskwords
); }
913 ipv4mask
{ $$.m.in4_addr
= $5.s_addr
;
914 $$.a.in4_addr
&= $5.s_addr
;
917 | YY_IPV6
{ bcopy
(&$1, &$$.a
, sizeof
($$.a
));
918 fill6bits
(128, (u_32_t
*)&$$.m
);
921 | YY_IPV6
{ yyresetdict
();
922 bcopy
(&$1, &$$.a
, sizeof
($$.a
)); }
923 maskspace
{ yysetdict
(maskwords
); }
924 ipv6mask
{ bcopy
(&$5, &$$.m
, sizeof
($$.m
));
935 | YY_HEX
{ $$.s_addr
= htonl
($1); }
936 | YY_NUMBER
{ ntomask
(4, $1, (u_32_t
*)&$$
); }
937 | IPFY_BROADCAST
{ if
(ifpflag
== FRI_DYNAMIC
) {
939 ifpflag
= FRI_BROADCAST
;
943 | IPFY_NETWORK
{ if
(ifpflag
== FRI_DYNAMIC
) {
945 ifpflag
= FRI_NETWORK
;
949 | IPFY_NETMASKED
{ if
(ifpflag
== FRI_DYNAMIC
) {
951 ifpflag
= FRI_NETMASKED
;
955 | IPFY_PEER
{ if
(ifpflag
== FRI_DYNAMIC
) {
957 ifpflag
= FRI_PEERADDR
;
964 YY_NUMBER
{ ntomask
(6, $1, $$.i6
); }
965 | IPFY_BROADCAST
{ if
(ifpflag
== FRI_DYNAMIC
) {
966 bzero
(&$$
, sizeof
($$
));
967 ifpflag
= FRI_BROADCAST
;
971 | IPFY_NETWORK
{ if
(ifpflag
== FRI_DYNAMIC
) {
972 bzero
(&$$
, sizeof
($$
));
973 ifpflag
= FRI_BROADCAST
;
977 | IPFY_NETMASKED
{ if
(ifpflag
== FRI_DYNAMIC
) {
978 bzero
(&$$
, sizeof
($$
));
979 ifpflag
= FRI_BROADCAST
;
983 | IPFY_PEER
{ if
(ifpflag
== FRI_DYNAMIC
) {
984 bzero
(&$$
, sizeof
($$
));
985 ifpflag
= FRI_BROADCAST
;
993 | YY_NUMBER
{ $$.s_addr
= $1; }
994 | YY_HEX
{ $$.s_addr
= $1; }
995 | YY_STR
{ $$.s_addr
= lookuphost
($1);
1001 ipaddr
{ $$
= newalist
(NULL
);
1002 bcopy
(&($1.a
), &($$
->al_i6addr
), sizeof
($1.a
));
1003 bcopy
(&($1.m
), &($$
->al_i6mask
), sizeof
($1.m
)); }
1004 | addrlist
',' ipaddr
1005 { $$
= newalist
($1);
1006 bcopy
(&($3.a
), &($$
->al_i6addr
), sizeof
($3.a
));
1007 bcopy
(&($3.m
), &($$
->al_i6mask
), sizeof
($3.m
)); }
1010 pool: IPFY_POOL
{ yyexpectaddr
= 0; yycont
= NULL
; yyresetdict
(); }
1013 hash: IPFY_HASH
{ yyexpectaddr
= 0; yycont
= NULL
; yyresetdict
(); }
1017 ipaddr
{ $$
= newalist
(NULL
);
1018 bcopy
(&($1.a
), &($$
->al_i6addr
), sizeof
($1.a
));
1019 bcopy
(&($1.m
), &($$
->al_i6mask
), sizeof
($1.m
)); }
1020 |
'!' ipaddr
{ $$
= newalist
(NULL
);
1022 bcopy
(&($2.a
), &($$
->al_i6addr
), sizeof
($2.a
));
1023 bcopy
(&($2.m
), &($$
->al_i6mask
), sizeof
($2.m
)); }
1024 | poollist
',' ipaddr
1025 { $$
= newalist
($1);
1026 bcopy
(&($3.a
), &($$
->al_i6addr
), sizeof
($3.a
));
1027 bcopy
(&($3.m
), &($$
->al_i6mask
), sizeof
($3.m
)); }
1028 | poollist
',' '!' ipaddr
1029 { $$
= newalist
($1);
1031 bcopy
(&($4.a
), &($$
->al_i6addr
), sizeof
($4.a
));
1032 bcopy
(&($4.m
), &($$
->al_i6mask
), sizeof
($4.m
)); }
1035 port: IPFY_PORT
{ yyexpectaddr
= 0;
1040 portc: port compare
{ $$
= $2;
1042 | porteq
{ $$
= $1; }
1045 porteq: port
'=' { $$
= FR_EQUAL
;
1049 portr: IPFY_PORT
{ yyexpectaddr
= 0;
1055 portc portnum
{ $$.pc
= $1;
1061 portr portnum range portnum
{ $$.p1
= $2;
1070 itype: seticmptype icmptype
1071 { DOALL
(fr
->fr_icmp
= htons
($2 << 8); fr
->fr_icmpm
= htons
(0xff00););
1074 | seticmptype lstart typelist lend
{ yyresetdict
(); }
1078 IPFY_ICMPTYPE
{ setipftype
();
1079 yysetdict
(icmptypewords
); }
1082 icode: | seticmpcode icmpcode
1083 { DOALL
(fr
->fr_icmp |
= htons
($2); fr
->fr_icmpm |
= htons
(0xff););
1086 | seticmpcode lstart codelist lend
{ yyresetdict
(); }
1090 IPFY_ICMPCODE
{ yysetdict
(icmpcodewords
); }
1095 { DOREM
(fr
->fr_icmp
= htons
($1 << 8); fr
->fr_icmpm
= htons
(0xff00);) }
1096 | typelist lmore icmptype
1097 { DOREM
(fr
->fr_icmp
= htons
($3 << 8); fr
->fr_icmpm
= htons
(0xff00);) }
1102 { DOREM
(fr
->fr_icmp |
= htons
($1); fr
->fr_icmpm |
= htons
(0xff);) }
1103 | codelist lmore icmpcode
1104 { DOREM
(fr
->fr_icmp
&= htons
(0xff00); fr
->fr_icmp |
= htons
($3); \
1105 fr
->fr_icmpm |
= htons
(0xff);) }
1108 age: | IPFY_AGE YY_NUMBER
{ DOALL
(fr
->fr_age
[0] = $2; \
1109 fr
->fr_age
[1] = $2;) }
1110 | IPFY_AGE YY_NUMBER
'/' YY_NUMBER
1111 { DOALL
(fr
->fr_age
[0] = $2; \
1112 fr
->fr_age
[1] = $4;) }
1115 keep: | IPFY_KEEP keepstate keep
1116 | IPFY_KEEP keepfrag keep
1120 IPFY_STATE stateoptlist
{ DOALL
(fr
->fr_flags |
= FR_KEEPSTATE
;)}
1124 IPFY_FRAGS fragoptlist
{ DOALL
(fr
->fr_flags |
= FR_KEEPFRAG
;) }
1125 | IPFY_FRAG fragoptlist
{ DOALL
(fr
->fr_flags |
= FR_KEEPFRAG
;) }
1133 fragopt lanother fragopts
1138 IPFY_STRICT
{ DOALL
(fr
->fr_flags |
= FR_FRSTRICT
;) }
1146 stateopt lanother stateopts
1151 IPFY_LIMIT YY_NUMBER
{ DOALL
(fr
->fr_statemax
= $2;) }
1152 | IPFY_STRICT
{ DOALL
(if
(fr
->fr_proto
!= IPPROTO_TCP
) { \
1155 fr
->fr_flags |
= FR_STSTRICT
;)
1157 | IPFY_NEWISN
{ DOALL
(if
(fr
->fr_proto
!= IPPROTO_TCP
) { \
1160 fr
->fr_flags |
= FR_NEWISN
;)
1162 | IPFY_NOICMPERR
{ DOALL
(fr
->fr_flags |
= FR_NOICMPERR
;) }
1164 | IPFY_SYNC
{ DOALL
(fr
->fr_flags |
= FR_STATESYNC
;) }
1165 | IPFY_AGE YY_NUMBER
{ DOALL
(fr
->fr_age
[0] = $2; \
1166 fr
->fr_age
[1] = $2;) }
1167 | IPFY_AGE YY_NUMBER
'/' YY_NUMBER
1168 { DOALL
(fr
->fr_age
[0] = $2; \
1169 fr
->fr_age
[1] = $4;) }
1173 servicename
{ if
(getport
(frc
, $1, &($$
)) == -1)
1174 yyerror("service unknown");
1178 | YY_NUMBER
{ if
($1 > 65535) /* Unsigned */
1179 yyerror("invalid port number");
1186 withopt
{ nowith
= 0; }
1187 | withlist withopt
{ nowith
= 0; }
1188 | withlist
',' withopt
{ nowith
= 0; }
1192 opttype
{ DOALL
(fr
->fr_flx |
= $1; fr
->fr_mflx |
= $1;) }
1193 | notwith opttype
{ DOALL
(fr
->fr_mflx |
= $2;) }
1194 | ipopt ipopts
{ yyresetdict
(); }
1195 | notwith ipopt ipopts
{ yyresetdict
(); }
1196 | startv6hdrs ipv6hdrs
{ yyresetdict
(); }
1199 ipopt: IPFY_OPT
{ yysetdict
(ipv4optwords
); }
1203 IPF6_V6HDRS
{ if
(use_inet6
== 0)
1204 yyerror("only available with IPv6");
1205 yysetdict
(ipv6optwords
);
1210 IPFY_NOT
{ nowith
= 1; }
1211 | IPFY_NO
{ nowith
= 1; }
1215 IPFY_IPOPTS
{ $$
= FI_OPTIONS
; }
1216 | IPFY_SHORT
{ $$
= FI_SHORT
; }
1217 | IPFY_NAT
{ $$
= FI_NATED
; }
1218 | IPFY_BAD
{ $$
= FI_BAD
; }
1219 | IPFY_BADNAT
{ $$
= FI_BADNAT
; }
1220 | IPFY_BADSRC
{ $$
= FI_BADSRC
; }
1221 | IPFY_LOWTTL
{ $$
= FI_LOWTTL
; }
1222 | IPFY_FRAG
{ $$
= FI_FRAG
; }
1223 | IPFY_FRAGBODY
{ $$
= FI_FRAGBODY
; }
1224 | IPFY_FRAGS
{ $$
= FI_FRAG
; }
1225 | IPFY_MBCAST
{ $$
= FI_MBCAST
; }
1226 | IPFY_MULTICAST
{ $$
= FI_MULTICAST
; }
1227 | IPFY_BROADCAST
{ $$
= FI_BROADCAST
; }
1228 | IPFY_STATE
{ $$
= FI_STATE
; }
1229 | IPFY_OOW
{ $$
= FI_OOW
; }
1232 ipopts: optlist
{ DOALL
(fr
->fr_mip.fi_optmsk |
= $1;
1234 fr
->fr_ip.fi_optmsk |
= $1;)
1240 | optlist
',' opt
{ $$ |
= $1 |
$3; }
1244 ipv6hdrlist
{ DOALL
(fr
->fr_mip.fi_optmsk |
= $1;
1246 fr
->fr_ip.fi_optmsk |
= $1;)
1251 ipv6hdr
{ $$ |
= $1; }
1252 | ipv6hdrlist
',' ipv6hdr
{ $$ |
= $1 |
$3; }
1256 seclevel
{ $$ |
= $1; }
1257 | secname
',' seclevel
{ $$ |
= $1 |
$3; }
1261 IPFY_SEC_UNC
{ $$
= secbit
(IPSO_CLASS_UNCL
); }
1262 | IPFY_SEC_CONF
{ $$
= secbit
(IPSO_CLASS_CONF
); }
1263 | IPFY_SEC_RSV1
{ $$
= secbit
(IPSO_CLASS_RES1
); }
1264 | IPFY_SEC_RSV2
{ $$
= secbit
(IPSO_CLASS_RES2
); }
1265 | IPFY_SEC_RSV3
{ $$
= secbit
(IPSO_CLASS_RES3
); }
1266 | IPFY_SEC_RSV4
{ $$
= secbit
(IPSO_CLASS_RES4
); }
1267 | IPFY_SEC_SEC
{ $$
= secbit
(IPSO_CLASS_SECR
); }
1268 | IPFY_SEC_TS
{ $$
= secbit
(IPSO_CLASS_TOPS
); }
1272 YY_NUMBER
{ $$
= $1; }
1273 | IPFY_ICMPT_UNR
{ $$
= ICMP_UNREACH
; }
1274 | IPFY_ICMPT_ECHO
{ $$
= ICMP_ECHO
; }
1275 | IPFY_ICMPT_ECHOR
{ $$
= ICMP_ECHOREPLY
; }
1276 | IPFY_ICMPT_SQUENCH
{ $$
= ICMP_SOURCEQUENCH
; }
1277 | IPFY_ICMPT_REDIR
{ $$
= ICMP_REDIRECT
; }
1278 | IPFY_ICMPT_TIMEX
{ $$
= ICMP_TIMXCEED
; }
1279 | IPFY_ICMPT_PARAMP
{ $$
= ICMP_PARAMPROB
; }
1280 | IPFY_ICMPT_TIMEST
{ $$
= ICMP_TSTAMP
; }
1281 | IPFY_ICMPT_TIMESTREP
{ $$
= ICMP_TSTAMPREPLY
; }
1282 | IPFY_ICMPT_INFOREQ
{ $$
= ICMP_IREQ
; }
1283 | IPFY_ICMPT_INFOREP
{ $$
= ICMP_IREQREPLY
; }
1284 | IPFY_ICMPT_MASKREQ
{ $$
= ICMP_MASKREQ
; }
1285 | IPFY_ICMPT_MASKREP
{ $$
= ICMP_MASKREPLY
; }
1286 | IPFY_ICMPT_ROUTERAD
{ $$
= ICMP_ROUTERADVERT
; }
1287 | IPFY_ICMPT_ROUTERSOL
{ $$
= ICMP_ROUTERSOLICIT
; }
1291 YY_NUMBER
{ $$
= $1; }
1292 | IPFY_ICMPC_NETUNR
{ $$
= ICMP_UNREACH_NET
; }
1293 | IPFY_ICMPC_HSTUNR
{ $$
= ICMP_UNREACH_HOST
; }
1294 | IPFY_ICMPC_PROUNR
{ $$
= ICMP_UNREACH_PROTOCOL
; }
1295 | IPFY_ICMPC_PORUNR
{ $$
= ICMP_UNREACH_PORT
; }
1296 | IPFY_ICMPC_NEEDF
{ $$
= ICMP_UNREACH_NEEDFRAG
; }
1297 | IPFY_ICMPC_SRCFAIL
{ $$
= ICMP_UNREACH_SRCFAIL
; }
1298 | IPFY_ICMPC_NETUNK
{ $$
= ICMP_UNREACH_NET_UNKNOWN
; }
1299 | IPFY_ICMPC_HSTUNK
{ $$
= ICMP_UNREACH_HOST_UNKNOWN
; }
1300 | IPFY_ICMPC_ISOLATE
{ $$
= ICMP_UNREACH_ISOLATED
; }
1301 | IPFY_ICMPC_NETPRO
{ $$
= ICMP_UNREACH_NET_PROHIB
; }
1302 | IPFY_ICMPC_HSTPRO
{ $$
= ICMP_UNREACH_HOST_PROHIB
; }
1303 | IPFY_ICMPC_NETTOS
{ $$
= ICMP_UNREACH_TOSNET
; }
1304 | IPFY_ICMPC_HSTTOS
{ $$
= ICMP_UNREACH_TOSHOST
; }
1305 | IPFY_ICMPC_FLTPRO
{ $$
= ICMP_UNREACH_ADMIN_PROHIBIT
; }
1306 | IPFY_ICMPC_HSTPRE
{ $$
= 14; }
1307 | IPFY_ICMPC_CUTPRE
{ $$
= 15; }
1311 IPFY_IPOPT_NOP
{ $$
= getoptbyvalue
(IPOPT_NOP
); }
1312 | IPFY_IPOPT_RR
{ $$
= getoptbyvalue
(IPOPT_RR
); }
1313 | IPFY_IPOPT_ZSU
{ $$
= getoptbyvalue
(IPOPT_ZSU
); }
1314 | IPFY_IPOPT_MTUP
{ $$
= getoptbyvalue
(IPOPT_MTUP
); }
1315 | IPFY_IPOPT_MTUR
{ $$
= getoptbyvalue
(IPOPT_MTUR
); }
1316 | IPFY_IPOPT_ENCODE
{ $$
= getoptbyvalue
(IPOPT_ENCODE
); }
1317 | IPFY_IPOPT_TS
{ $$
= getoptbyvalue
(IPOPT_TS
); }
1318 | IPFY_IPOPT_TR
{ $$
= getoptbyvalue
(IPOPT_TR
); }
1319 | IPFY_IPOPT_SEC
{ $$
= getoptbyvalue
(IPOPT_SECURITY
); }
1320 | IPFY_IPOPT_LSRR
{ $$
= getoptbyvalue
(IPOPT_LSRR
); }
1321 | IPFY_IPOPT_ESEC
{ $$
= getoptbyvalue
(IPOPT_E_SEC
); }
1322 | IPFY_IPOPT_CIPSO
{ $$
= getoptbyvalue
(IPOPT_CIPSO
); }
1323 | IPFY_IPOPT_SATID
{ $$
= getoptbyvalue
(IPOPT_SATID
); }
1324 | IPFY_IPOPT_SSRR
{ $$
= getoptbyvalue
(IPOPT_SSRR
); }
1325 | IPFY_IPOPT_ADDEXT
{ $$
= getoptbyvalue
(IPOPT_ADDEXT
); }
1326 | IPFY_IPOPT_VISA
{ $$
= getoptbyvalue
(IPOPT_VISA
); }
1327 | IPFY_IPOPT_IMITD
{ $$
= getoptbyvalue
(IPOPT_IMITD
); }
1328 | IPFY_IPOPT_EIP
{ $$
= getoptbyvalue
(IPOPT_EIP
); }
1329 | IPFY_IPOPT_FINN
{ $$
= getoptbyvalue
(IPOPT_FINN
); }
1330 | IPFY_IPOPT_DPS
{ $$
= getoptbyvalue
(IPOPT_DPS
); }
1331 | IPFY_IPOPT_SDB
{ $$
= getoptbyvalue
(IPOPT_SDB
); }
1332 | IPFY_IPOPT_NSAPA
{ $$
= getoptbyvalue
(IPOPT_NSAPA
); }
1333 | IPFY_IPOPT_RTRALRT
{ $$
= getoptbyvalue
(IPOPT_RTRALRT
); }
1334 | IPFY_IPOPT_UMP
{ $$
= getoptbyvalue
(IPOPT_UMP
); }
1335 | setsecclass secname
1336 { DOALL
(fr
->fr_mip.fi_secmsk |
= $2;
1338 fr
->fr_ip.fi_secmsk |
= $2;)
1345 IPFY_SECCLASS
{ yysetdict
(ipv4secwords
); }
1349 IPFY_AH
{ $$
= getv6optbyvalue
(IPPROTO_AH
); }
1350 | IPFY_IPV6OPT_DSTOPTS
{ $$
= getv6optbyvalue
(IPPROTO_DSTOPTS
); }
1351 | IPFY_IPV6OPT_ESP
{ $$
= getv6optbyvalue
(IPPROTO_ESP
); }
1352 | IPFY_IPV6OPT_HOPOPTS
{ $$
= getv6optbyvalue
(IPPROTO_HOPOPTS
); }
1353 | IPFY_IPV6OPT_IPV6
{ $$
= getv6optbyvalue
(IPPROTO_IPV6
); }
1354 | IPFY_IPV6OPT_NONE
{ $$
= getv6optbyvalue
(IPPROTO_NONE
); }
1355 | IPFY_IPV6OPT_ROUTING
{ $$
= getv6optbyvalue
(IPPROTO_ROUTING
); }
1356 | IPFY_IPV6OPT_FRAG
{ $$
= getv6optbyvalue
(IPPROTO_FRAGMENT
); }
1357 | IPFY_IPV6OPT_MOBILITY
{ $$
= getv6optbyvalue
(IPPROTO_MOBILITY
); }
1360 level: IPFY_LEVEL
{ setsyslog
(); }
1364 priority
{ fr
->fr_loglevel
= LOG_LOCAL0|
$1; }
1365 | facility
'.' priority
{ fr
->fr_loglevel
= $1 |
$3; }
1369 IPFY_FAC_KERN
{ $$
= LOG_KERN
; }
1370 | IPFY_FAC_USER
{ $$
= LOG_USER
; }
1371 | IPFY_FAC_MAIL
{ $$
= LOG_MAIL
; }
1372 | IPFY_FAC_DAEMON
{ $$
= LOG_DAEMON
; }
1373 | IPFY_FAC_AUTH
{ $$
= LOG_AUTH
; }
1374 | IPFY_FAC_SYSLOG
{ $$
= LOG_SYSLOG
; }
1375 | IPFY_FAC_LPR
{ $$
= LOG_LPR
; }
1376 | IPFY_FAC_NEWS
{ $$
= LOG_NEWS
; }
1377 | IPFY_FAC_UUCP
{ $$
= LOG_UUCP
; }
1378 | IPFY_FAC_CRON
{ $$
= LOG_CRON
; }
1379 | IPFY_FAC_FTP
{ $$
= LOG_FTP
; }
1380 | IPFY_FAC_AUTHPRIV
{ $$
= LOG_AUTHPRIV
; }
1381 | IPFY_FAC_AUDIT
{ $$
= LOG_AUDIT
; }
1382 | IPFY_FAC_LFMT
{ $$
= LOG_LFMT
; }
1383 | IPFY_FAC_LOCAL0
{ $$
= LOG_LOCAL0
; }
1384 | IPFY_FAC_LOCAL1
{ $$
= LOG_LOCAL1
; }
1385 | IPFY_FAC_LOCAL2
{ $$
= LOG_LOCAL2
; }
1386 | IPFY_FAC_LOCAL3
{ $$
= LOG_LOCAL3
; }
1387 | IPFY_FAC_LOCAL4
{ $$
= LOG_LOCAL4
; }
1388 | IPFY_FAC_LOCAL5
{ $$
= LOG_LOCAL5
; }
1389 | IPFY_FAC_LOCAL6
{ $$
= LOG_LOCAL6
; }
1390 | IPFY_FAC_LOCAL7
{ $$
= LOG_LOCAL7
; }
1391 | IPFY_FAC_SECURITY
{ $$
= LOG_SECURITY
; }
1395 IPFY_PRI_EMERG
{ $$
= LOG_EMERG
; }
1396 | IPFY_PRI_ALERT
{ $$
= LOG_ALERT
; }
1397 | IPFY_PRI_CRIT
{ $$
= LOG_CRIT
; }
1398 | IPFY_PRI_ERR
{ $$
= LOG_ERR
; }
1399 | IPFY_PRI_WARN
{ $$
= LOG_WARNING
; }
1400 | IPFY_PRI_NOTICE
{ $$
= LOG_NOTICE
; }
1401 | IPFY_PRI_INFO
{ $$
= LOG_INFO
; }
1402 | IPFY_PRI_DEBUG
{ $$
= LOG_DEBUG
; }
1406 YY_CMP_EQ
{ $$
= FR_EQUAL
; }
1407 | YY_CMP_NE
{ $$
= FR_NEQUAL
; }
1408 | YY_CMP_LT
{ $$
= FR_LESST
; }
1409 | YY_CMP_LE
{ $$
= FR_LESSTE
; }
1410 | YY_CMP_GT
{ $$
= FR_GREATERT
; }
1411 | YY_CMP_GE
{ $$
= FR_GREATERTE
; }
1414 range: YY_RANGE_IN
{ $$
= FR_INRANGE
; }
1415 | YY_RANGE_OUT
{ $$
= FR_OUTRANGE
; }
1416 |
':' { $$
= FR_INCRANGE
; }
1423 interfacename: name
{ $$
= $1; }
1424 | name
':' YY_NUMBER
1426 fprintf
(stderr
, "%d: Logical interface %s:%d unsupported, "
1427 "use the physical interface %s instead.\n",
1428 yylineNum
, $1, $3, $1);
1432 name: YY_STR
{ $$
= $1; }
1433 |
'-' { $$
= strdup
("-"); }
1437 YY_NUMBER
'.' YY_NUMBER
1438 { if
($1 > 255 ||
$3 > 255) {
1439 yyerror("Invalid octet string for IP address");
1442 $$.s_addr
= ($1 << 24) |
($3 << 16);
1443 $$.s_addr
= htonl
($$.s_addr
);
1448 ipv4_16
'.' YY_NUMBER
1450 yyerror("Invalid octet string for IP address");
1453 $$.s_addr |
= htonl
($3 << 8);
1457 ipv4: ipv4_24
'.' YY_NUMBER
1459 yyerror("Invalid octet string for IP address");
1462 $$.s_addr |
= htonl
($3);
1471 static struct wordtab ipfwords
[95] = {
1472 { "age", IPFY_AGE
},
1474 { "all", IPFY_ALL
},
1475 { "and", IPFY_AND
},
1476 { "auth", IPFY_AUTH
},
1477 { "bad", IPFY_BAD
},
1478 { "bad-nat", IPFY_BADNAT
},
1479 { "bad-src", IPFY_BADSRC
},
1480 { "bcast", IPFY_BROADCAST
},
1481 { "block", IPFY_BLOCK
},
1482 { "body", IPFY_BODY
},
1483 { "bpf-v4", IPFY_BPFV4
},
1485 { "bpf-v6", IPFY_BPFV6
},
1487 { "call", IPFY_CALL
},
1488 { "code", IPFY_ICMPCODE
},
1489 { "count", IPFY_COUNT
},
1490 { "dup-to", IPFY_DUPTO
},
1491 { "eq", YY_CMP_EQ
},
1492 { "esp", IPFY_ESP
},
1493 { "fastroute", IPFY_FROUTE
},
1494 { "first", IPFY_FIRST
},
1495 { "flags", IPFY_FLAGS
},
1496 { "frag", IPFY_FRAG
},
1497 { "frag-body", IPFY_FRAGBODY
},
1498 { "frags", IPFY_FRAGS
},
1499 { "from", IPFY_FROM
},
1500 { "ge", YY_CMP_GE
},
1501 { "group", IPFY_GROUP
},
1502 { "gt", YY_CMP_GT
},
1503 { "head", IPFY_HEAD
},
1504 { "icmp", IPFY_ICMP
},
1505 { "icmp-type", IPFY_ICMPTYPE
},
1507 { "in-via", IPFY_INVIA
},
1508 { "ipopt", IPFY_IPOPTS
},
1509 { "ipopts", IPFY_IPOPTS
},
1510 { "keep", IPFY_KEEP
},
1511 { "le", YY_CMP_LE
},
1512 { "level", IPFY_LEVEL
},
1513 { "limit", IPFY_LIMIT
},
1514 { "log", IPFY_LOG
},
1515 { "lowttl", IPFY_LOWTTL
},
1516 { "lt", YY_CMP_LT
},
1517 { "mask", IPFY_MASK
},
1518 { "match-tag", IPFY_MATCHTAG
},
1519 { "mbcast", IPFY_MBCAST
},
1520 { "mcast", IPFY_MULTICAST
},
1521 { "multicast", IPFY_MULTICAST
},
1522 { "nat", IPFY_NAT
},
1523 { "ne", YY_CMP_NE
},
1524 { "net", IPFY_NETWORK
},
1525 { "newisn", IPFY_NEWISN
},
1527 { "no-icmp-err", IPFY_NOICMPERR
},
1528 { "nomatch", IPFY_NOMATCH
},
1529 { "now", IPFY_NOW
},
1530 { "not", IPFY_NOT
},
1531 { "oow", IPFY_OOW
},
1533 { "opt", IPFY_OPT
},
1534 { "or-block", IPFY_ORBLOCK
},
1535 { "out", IPFY_OUT
},
1536 { "out-via", IPFY_OUTVIA
},
1537 { "pass", IPFY_PASS
},
1538 { "port", IPFY_PORT
},
1539 { "pps", IPFY_PPS
},
1540 { "preauth", IPFY_PREAUTH
},
1541 { "proto", IPFY_PROTO
},
1542 { "quick", IPFY_QUICK
},
1543 { "reply-to", IPFY_REPLY_TO
},
1544 { "return-icmp", IPFY_RETICMP
},
1545 { "return-icmp-as-dest", IPFY_RETICMPASDST
},
1546 { "return-rst", IPFY_RETRST
},
1547 { "route-to", IPFY_ROUTETO
},
1548 { "sec-class", IPFY_SECCLASS
},
1549 { "set-tag", IPFY_SETTAG
},
1550 { "skip", IPFY_SKIP
},
1551 { "short", IPFY_SHORT
},
1552 { "state", IPFY_STATE
},
1553 { "state-age", IPFY_AGE
},
1554 { "strict", IPFY_STRICT
},
1555 { "sync", IPFY_SYNC
},
1556 { "tcp", IPFY_TCP
},
1557 { "tcp-udp", IPFY_TCPUDP
},
1558 { "tos", IPFY_TOS
},
1560 { "ttl", IPFY_TTL
},
1561 { "udp", IPFY_UDP
},
1562 { "v6hdrs", IPF6_V6HDRS
},
1563 { "with", IPFY_WITH
},
1567 static struct wordtab addrwords
[4] = {
1568 { "any", IPFY_ANY
},
1569 { "hash", IPFY_HASH
},
1570 { "pool", IPFY_POOL
},
1574 static struct wordtab maskwords
[5] = {
1575 { "broadcast", IPFY_BROADCAST
},
1576 { "netmasked", IPFY_NETMASKED
},
1577 { "network", IPFY_NETWORK
},
1578 { "peer", IPFY_PEER
},
1582 static struct wordtab icmptypewords
[16] = {
1583 { "echo", IPFY_ICMPT_ECHO
},
1584 { "echorep", IPFY_ICMPT_ECHOR
},
1585 { "inforeq", IPFY_ICMPT_INFOREQ
},
1586 { "inforep", IPFY_ICMPT_INFOREP
},
1587 { "maskrep", IPFY_ICMPT_MASKREP
},
1588 { "maskreq", IPFY_ICMPT_MASKREQ
},
1589 { "paramprob", IPFY_ICMPT_PARAMP
},
1590 { "redir", IPFY_ICMPT_REDIR
},
1591 { "unreach", IPFY_ICMPT_UNR
},
1592 { "routerad", IPFY_ICMPT_ROUTERAD
},
1593 { "routersol", IPFY_ICMPT_ROUTERSOL
},
1594 { "squench", IPFY_ICMPT_SQUENCH
},
1595 { "timest", IPFY_ICMPT_TIMEST
},
1596 { "timestrep", IPFY_ICMPT_TIMESTREP
},
1597 { "timex", IPFY_ICMPT_TIMEX
},
1601 static struct wordtab icmpcodewords
[17] = {
1602 { "cutoff-preced", IPFY_ICMPC_CUTPRE
},
1603 { "filter-prohib", IPFY_ICMPC_FLTPRO
},
1604 { "isolate", IPFY_ICMPC_ISOLATE
},
1605 { "needfrag", IPFY_ICMPC_NEEDF
},
1606 { "net-prohib", IPFY_ICMPC_NETPRO
},
1607 { "net-tos", IPFY_ICMPC_NETTOS
},
1608 { "host-preced", IPFY_ICMPC_HSTPRE
},
1609 { "host-prohib", IPFY_ICMPC_HSTPRO
},
1610 { "host-tos", IPFY_ICMPC_HSTTOS
},
1611 { "host-unk", IPFY_ICMPC_HSTUNK
},
1612 { "host-unr", IPFY_ICMPC_HSTUNR
},
1613 { "net-unk", IPFY_ICMPC_NETUNK
},
1614 { "net-unr", IPFY_ICMPC_NETUNR
},
1615 { "port-unr", IPFY_ICMPC_PORUNR
},
1616 { "proto-unr", IPFY_ICMPC_PROUNR
},
1617 { "srcfail", IPFY_ICMPC_SRCFAIL
},
1621 static struct wordtab ipv4optwords
[25] = {
1622 { "addext", IPFY_IPOPT_ADDEXT
},
1623 { "cipso", IPFY_IPOPT_CIPSO
},
1624 { "dps", IPFY_IPOPT_DPS
},
1625 { "e-sec", IPFY_IPOPT_ESEC
},
1626 { "eip", IPFY_IPOPT_EIP
},
1627 { "encode", IPFY_IPOPT_ENCODE
},
1628 { "finn", IPFY_IPOPT_FINN
},
1629 { "imitd", IPFY_IPOPT_IMITD
},
1630 { "lsrr", IPFY_IPOPT_LSRR
},
1631 { "mtup", IPFY_IPOPT_MTUP
},
1632 { "mtur", IPFY_IPOPT_MTUR
},
1633 { "nop", IPFY_IPOPT_NOP
},
1634 { "nsapa", IPFY_IPOPT_NSAPA
},
1635 { "rr", IPFY_IPOPT_RR
},
1636 { "rtralrt", IPFY_IPOPT_RTRALRT
},
1637 { "satid", IPFY_IPOPT_SATID
},
1638 { "sdb", IPFY_IPOPT_SDB
},
1639 { "sec", IPFY_IPOPT_SEC
},
1640 { "ssrr", IPFY_IPOPT_SSRR
},
1641 { "tr", IPFY_IPOPT_TR
},
1642 { "ts", IPFY_IPOPT_TS
},
1643 { "ump", IPFY_IPOPT_UMP
},
1644 { "visa", IPFY_IPOPT_VISA
},
1645 { "zsu", IPFY_IPOPT_ZSU
},
1649 static struct wordtab ipv4secwords
[9] = {
1650 { "confid", IPFY_SEC_CONF
},
1651 { "reserv-1", IPFY_SEC_RSV1
},
1652 { "reserv-2", IPFY_SEC_RSV2
},
1653 { "reserv-3", IPFY_SEC_RSV3
},
1654 { "reserv-4", IPFY_SEC_RSV4
},
1655 { "secret", IPFY_SEC_SEC
},
1656 { "topsecret", IPFY_SEC_TS
},
1657 { "unclass", IPFY_SEC_UNC
},
1661 static struct wordtab ipv6optwords
[9] = {
1662 { "dstopts", IPFY_IPV6OPT_DSTOPTS
},
1663 { "esp", IPFY_IPV6OPT_ESP
},
1664 { "frag", IPFY_IPV6OPT_FRAG
},
1665 { "hopopts", IPFY_IPV6OPT_HOPOPTS
},
1666 { "ipv6", IPFY_IPV6OPT_IPV6
},
1667 { "mobility", IPFY_IPV6OPT_MOBILITY
},
1668 { "none", IPFY_IPV6OPT_NONE
},
1669 { "routing", IPFY_IPV6OPT_ROUTING
},
1673 static struct wordtab logwords
[33] = {
1674 { "kern", IPFY_FAC_KERN
},
1675 { "user", IPFY_FAC_USER
},
1676 { "mail", IPFY_FAC_MAIL
},
1677 { "daemon", IPFY_FAC_DAEMON
},
1678 { "auth", IPFY_FAC_AUTH
},
1679 { "syslog", IPFY_FAC_SYSLOG
},
1680 { "lpr", IPFY_FAC_LPR
},
1681 { "news", IPFY_FAC_NEWS
},
1682 { "uucp", IPFY_FAC_UUCP
},
1683 { "cron", IPFY_FAC_CRON
},
1684 { "ftp", IPFY_FAC_FTP
},
1685 { "authpriv", IPFY_FAC_AUTHPRIV
},
1686 { "audit", IPFY_FAC_AUDIT
},
1687 { "logalert", IPFY_FAC_LFMT
},
1688 { "console", IPFY_FAC_CONSOLE
},
1689 { "security", IPFY_FAC_SECURITY
},
1690 { "local0", IPFY_FAC_LOCAL0
},
1691 { "local1", IPFY_FAC_LOCAL1
},
1692 { "local2", IPFY_FAC_LOCAL2
},
1693 { "local3", IPFY_FAC_LOCAL3
},
1694 { "local4", IPFY_FAC_LOCAL4
},
1695 { "local5", IPFY_FAC_LOCAL5
},
1696 { "local6", IPFY_FAC_LOCAL6
},
1697 { "local7", IPFY_FAC_LOCAL7
},
1698 { "emerg", IPFY_PRI_EMERG
},
1699 { "alert", IPFY_PRI_ALERT
},
1700 { "crit", IPFY_PRI_CRIT
},
1701 { "err", IPFY_PRI_ERR
},
1702 { "warn", IPFY_PRI_WARN
},
1703 { "notice", IPFY_PRI_NOTICE
},
1704 { "info", IPFY_PRI_INFO
},
1705 { "debug", IPFY_PRI_DEBUG
},
1712 int ipf_parsefile
(fd
, addfunc
, iocfuncs
, filename
)
1715 ioctlfunc_t
*iocfuncs
;
1724 s
= getenv
("YYDEBUG");
1730 if
(strcmp
(filename
, "-")) {
1731 fp
= fopen
(filename
, "r");
1733 fprintf
(stderr
, "fopen(%s) failed: %s\n", filename
,
1740 while
(ipf_parsesome
(fd
, addfunc
, iocfuncs
, fp
) == 1)
1748 int ipf_parsesome
(fd
, addfunc
, iocfuncs
, fp
)
1751 ioctlfunc_t
*iocfuncs
;
1758 for
(i
= 0; i
<= IPL_LOGMAX
; i
++)
1759 ipfioctl
[i
] = iocfuncs
[i
];
1760 ipfaddfunc
= addfunc
;
1767 if
(ungetc
(i
, fp
) == 0)
1771 s
= getenv
("YYDEBUG");
1783 static void newrule
()
1787 frn
= (frentry_t
*)calloc
(1, sizeof
(frentry_t
));
1788 for
(fr
= frtop
; fr
!= NULL
&& fr
->fr_next
!= NULL
; fr
= fr
->fr_next
)
1796 fr
->fr_loglevel
= 0xffff;
1797 fr
->fr_isc
= (void *)-1;
1798 fr
->fr_logtag
= FR_NOLOGTAG
;
1799 fr
->fr_type
= FR_T_NONE
;
1809 static void setipftype
()
1811 for
(fr
= frc
; fr
!= NULL
; fr
= fr
->fr_next
) {
1812 if
(fr
->fr_type
== FR_T_NONE
) {
1813 fr
->fr_type
= FR_T_IPF
;
1814 fr
->fr_data
= (void *)calloc
(sizeof
(fripf_t
), 1);
1815 fr
->fr_dsize
= sizeof
(fripf_t
);
1816 fr
->fr_ip.fi_v
= frc
->fr_v
;
1817 fr
->fr_mip.fi_v
= 0xf;
1818 fr
->fr_ipf
->fri_sifpidx
= -1;
1819 fr
->fr_ipf
->fri_difpidx
= -1;
1821 if
(fr
->fr_type
!= FR_T_IPF
) {
1822 fprintf
(stderr
, "IPF Type not set\n");
1828 static frentry_t
*addrule
()
1830 frentry_t
*f
, *f1
, *f2
;
1833 for
(f2
= frc
; f2
->fr_next
!= NULL
; f2
= f2
->fr_next
)
1838 for
(f1
= frc
; count
> 0; count
--, f1
= f1
->fr_next
) {
1839 f
->fr_next
= (frentry_t
*)calloc
(sizeof
(*f
), 1);
1842 bcopy
(f1
, f
, sizeof
(*f
));
1844 if
(f
->fr_caddr
!= NULL
) {
1845 f
->fr_caddr
= malloc
(f
->fr_dsize
);
1846 bcopy
(f1
->fr_caddr
, f
->fr_caddr
, f
->fr_dsize
);
1854 static u_32_t lookuphost
(name
)
1864 for
(i
= 0; i
< 4; i
++) {
1865 if
(strncmp
(name
, frc
->fr_ifnames
[i
],
1866 sizeof
(frc
->fr_ifnames
[i
])) == 0) {
1867 ifpflag
= FRI_DYNAMIC
;
1873 if
(gethost
(name
, &addr
) == -1) {
1874 fprintf
(stderr
, "unknown name \"%s\"\n", name
);
1881 static void dobpf
(v
, phrase
)
1886 struct bpf_program bpf
;
1894 for
(fr
= frc
; fr
!= NULL
; fr
= fr
->fr_next
) {
1895 if
(fr
->fr_type
!= FR_T_NONE
) {
1896 fprintf
(stderr
, "cannot mix IPF and BPF matching\n");
1900 fr
->fr_type
= FR_T_BPFOPC
;
1902 if
(!strncmp
(phrase
, "0x", 2)) {
1903 fb
= malloc
(sizeof
(fakebpf_t
));
1905 for
(i
= 0, s
= strtok
(phrase
, " \r\n\t"); s
!= NULL
;
1906 s
= strtok
(NULL
, " \r\n\t"), i
++) {
1907 fb
= realloc
(fb
, (i
/ 4 + 1) * sizeof
(*fb
));
1908 l
= (u_32_t
)strtol
(s
, NULL
, 0);
1912 fb
[i
/ 4].fb_c
= l
& 0xffff;
1915 fb
[i
/ 4].fb_t
= l
& 0xff;
1918 fb
[i
/ 4].fb_f
= l
& 0xff;
1927 "Odd number of bytes in BPF code\n");
1931 fr
->fr_dsize
= (i
/ 4 + 1) * sizeof
(*fb
);
1937 bzero
((char *)&bpf
, sizeof
(bpf
));
1938 p
= pcap_open_dead
(DLT_RAW
, 1);
1940 fprintf
(stderr
, "pcap_open_dead failed\n");
1944 if
(pcap_compile
(p
, &bpf
, phrase
, 1, 0xffffffff)) {
1945 pcap_perror
(p
, "ipf");
1947 fprintf
(stderr
, "pcap parsing failed (%s)\n", phrase
);
1952 fr
->fr_dsize
= bpf.bf_len
* sizeof
(struct bpf_insn
);
1953 fr
->fr_data
= malloc
(fr
->fr_dsize
);
1954 bcopy
((char *)bpf.bf_insns
, fr
->fr_data
, fr
->fr_dsize
);
1955 if
(!bpf_validate
(fr
->fr_data
, bpf.bf_len
)) {
1956 fprintf
(stderr
, "BPF validation failed\n");
1963 if
(opts
& OPT_DEBUG
)
1966 fprintf
(stderr
, "BPF filter expressions not supported\n");
1972 static void resetaddr
()
1980 static alist_t
*newalist
(ptr
)
1985 al
= malloc
(sizeof
(*al
));
1994 static int makepool
(list
)
1997 ip_pool_node_t
*n
, *top
;
2004 top
= calloc
(1, sizeof
(*top
));
2008 for
(n
= top
, a
= list
; (n
!= NULL
) && (a
!= NULL
); a
= a
->al_next
) {
2009 n
->ipn_addr.adf_addr.in4.s_addr
= a
->al_1
;
2010 n
->ipn_mask.adf_addr.in4.s_addr
= a
->al_2
;
2011 n
->ipn_info
= a
->al_not
;
2012 if
(a
->al_next
!= NULL
) {
2013 n
->ipn_next
= calloc
(1, sizeof
(*n
));
2018 bzero
((char *)&pool
, sizeof
(pool
));
2019 pool.ipo_unit
= IPL_LOGIPF
;
2020 pool.ipo_list
= top
;
2021 num
= load_pool
(&pool
, ipfioctl
[IPL_LOGLOOKUP
]);
2023 while
((n
= top
) != NULL
) {
2031 static u_int makehash
(list
)
2041 top
= calloc
(1, sizeof
(*top
));
2045 for
(n
= top
, a
= list
; (n
!= NULL
) && (a
!= NULL
); a
= a
->al_next
) {
2046 n
->ipe_addr.in4_addr
= a
->al_1
;
2047 n
->ipe_mask.in4_addr
= a
->al_2
;
2049 if
(a
->al_next
!= NULL
) {
2050 n
->ipe_next
= calloc
(1, sizeof
(*n
));
2055 bzero
((char *)&iph
, sizeof
(iph
));
2056 iph.iph_unit
= IPL_LOGIPF
;
2057 iph.iph_type
= IPHASH_LOOKUP
;
2058 *iph.iph_name
= '\0';
2060 if
(load_hash
(&iph
, top
, ipfioctl
[IPL_LOGLOOKUP
]) == 0)
2061 sscanf
(iph.iph_name
, "%u", &num
);
2065 while
((n
= top
) != NULL
) {
2073 void ipf_addrule
(fd
, ioctlfunc
, ptr
)
2075 ioctlfunc_t ioctlfunc
;
2078 ioctlcmd_t add
, del
;
2089 bzero
((char *)&obj
, sizeof
(obj
));
2090 obj.ipfo_rev
= IPFILTER_VERSION
;
2091 obj.ipfo_size
= sizeof
(*fr
);
2092 obj.ipfo_type
= IPFOBJ_FRENTRY
;
2095 if
((opts
& OPT_DONOTHING
) != 0)
2098 if
(opts
& OPT_ZERORULEST
) {
2100 } else if
(opts
& OPT_INACTIVE
) {
2101 add
= (u_int
)fr
->fr_hits ? SIOCINIFR
:
2105 add
= (u_int
)fr
->fr_hits ? SIOCINAFR
:
2110 if
((opts
& OPT_OUTQUE
) != 0)
2111 fr
->fr_flags |
= FR_OUTQUE
;
2114 if
((opts
& OPT_VERBOSE
) != 0)
2115 printfr
(fr
, ioctlfunc
);
2117 if
((opts
& OPT_DEBUG
) != 0) {
2118 binprint
(fr
, sizeof
(*fr
));
2119 if
(fr
->fr_data
!= NULL
)
2120 binprint
(fr
->fr_data
, fr
->fr_dsize
);
2123 if
((opts
& OPT_ZERORULEST
) != 0) {
2124 if
((*ioctlfunc
)(fd
, add
, (void *)&obj
) == -1) {
2125 if
((opts
& OPT_DONOTHING
) == 0) {
2126 fprintf
(stderr
, "%d:", yylineNum
);
2127 perror
("ioctl(SIOCZRLST)");
2131 printf
("hits %qd bytes %qd ",
2132 (long long)fr
->fr_hits
,
2133 (long long)fr
->fr_bytes
);
2135 printf
("hits %ld bytes %ld ",
2136 fr
->fr_hits
, fr
->fr_bytes
);
2138 printfr
(fr
, ioctlfunc
);
2140 } else if
((opts
& OPT_REMOVE
) != 0) {
2141 if
((*ioctlfunc
)(fd
, del
, (void *)&obj
) == -1) {
2142 if
((opts
& OPT_DONOTHING
) != 0) {
2143 fprintf
(stderr
, "%d:", yylineNum
);
2144 perror
("ioctl(delete rule)");
2148 if
((*ioctlfunc
)(fd
, add
, (void *)&obj
) == -1) {
2149 if
(!(opts
& OPT_DONOTHING
)) {
2150 fprintf
(stderr
, "%d:", yylineNum
);
2151 perror
("ioctl(add/insert rule)");
2157 static void setsyslog
()
2159 yysetdict
(logwords
);
2164 static void unsetsyslog
()
2171 static void fillgroup
(fr
)
2176 for
(f
= frold
; f
!= NULL
; f
= f
->fr_next
)
2177 if
(strncmp
(f
->fr_grhead
, fr
->fr_group
, FR_GROUPLEN
) == 0)
2183 * Only copy down matching fields if the rules are of the same type
2184 * and are of ipf type. The only fields that are copied are those
2185 * that impact the rule parsing itself, eg. need for knowing what the
2186 * protocol should be for rules with port comparisons in them.
2188 if
(f
->fr_type
!= fr
->fr_type || f
->fr_type
!= FR_T_IPF
)
2191 if
(fr
->fr_v
== 0 && f
->fr_v
!= 0)
2194 if
(fr
->fr_mproto
== 0 && f
->fr_mproto
!= 0)
2195 fr
->fr_mproto
= f
->fr_mproto
;
2196 if
(fr
->fr_proto
== 0 && f
->fr_proto
!= 0)
2197 fr
->fr_proto
= f
->fr_proto
;
2199 if
((fr
->fr_mproto
== 0) && ((fr
->fr_flx
& FI_TCPUDP
) == 0) &&
2200 ((f
->fr_flx
& FI_TCPUDP
) != 0))
2201 fr
->fr_flx |
= FI_TCPUDP
;