2 * Copyright (C) 2000-2005 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: printfr.c,v 1.43.2.12 2005/06/12 07:18:42 darrenr Exp $
8 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
9 * Use is subject to license terms.
12 #pragma ident "%Z%%M% %I% %E% SMI"
17 * print the filter structure in a useful way
19 void printfr(fp
, iocfunc
)
31 type
= fp
->fr_type
& ~FR_T_BUILTIN
;
33 if ((fp
->fr_type
& FR_T_BUILTIN
) != 0)
34 printf("# Builtin: ");
36 if (fp
->fr_collect
!= 0)
37 printf("%u ", fp
->fr_collect
);
39 if (fp
->fr_type
== FR_T_CALLFUNC
) {
41 } else if (fp
->fr_func
!= NULL
) {
43 if ((fp
->fr_flags
& FR_CALLNOW
) != 0)
45 s
= kvatoname(fp
->fr_func
, iocfunc
);
46 printf(" %s/%u", s
? s
: "?", fp
->fr_arg
);
47 } else if (FR_ISPASS(fp
->fr_flags
))
49 else if (FR_ISBLOCK(fp
->fr_flags
)) {
51 if (fp
->fr_flags
& FR_RETICMP
) {
52 if ((fp
->fr_flags
& FR_RETMASK
) == FR_FAKEICMP
)
53 printf(" return-icmp-as-dest");
54 else if ((fp
->fr_flags
& FR_RETMASK
) == FR_RETICMP
)
55 printf(" return-icmp");
57 if (fp
->fr_icode
<= MAX_ICMPCODE
)
59 icmpcodes
[(int)fp
->fr_icode
]);
61 printf("(%d)", fp
->fr_icode
);
63 } else if ((fp
->fr_flags
& FR_RETMASK
) == FR_RETRST
)
64 printf(" return-rst");
65 } else if ((fp
->fr_flags
& FR_LOGMASK
) == FR_LOG
) {
67 } else if (FR_ISACCOUNT(fp
->fr_flags
))
69 else if (FR_ISAUTH(fp
->fr_flags
))
71 else if (FR_ISPREAUTH(fp
->fr_flags
))
73 else if (FR_ISNOMATCH(fp
->fr_flags
))
75 else if (FR_ISSKIP(fp
->fr_flags
))
76 printf("skip %u", fp
->fr_arg
);
78 printf("%x", fp
->fr_flags
);
81 if (fp
->fr_flags
& FR_OUTQUE
)
86 if (((fp
->fr_flags
& FR_LOGB
) == FR_LOGB
) ||
87 ((fp
->fr_flags
& FR_LOGP
) == FR_LOGP
)) {
92 if (fp
->fr_flags
& FR_QUICK
)
96 printifname("on ", fp
->fr_ifname
, fp
->fr_ifa
);
97 if (*fp
->fr_ifnames
[1] && strcmp(fp
->fr_ifnames
[1], "*"))
98 printifname(",", fp
->fr_ifnames
[1], fp
->fr_ifas
[1]);
102 if (*fp
->fr_dif
.fd_ifname
|| (fp
->fr_flags
& FR_DUP
))
103 print_toif("dup-to", &fp
->fr_dif
);
104 if (*fp
->fr_tif
.fd_ifname
)
105 print_toif("to", &fp
->fr_tif
);
106 if (*fp
->fr_rif
.fd_ifname
)
107 print_toif("reply-to", &fp
->fr_rif
);
108 if (fp
->fr_flags
& FR_FASTROUTE
)
109 printf("fastroute ");
111 if ((*fp
->fr_ifnames
[2] && strcmp(fp
->fr_ifnames
[2], "*")) ||
112 (*fp
->fr_ifnames
[3] && strcmp(fp
->fr_ifnames
[3], "*"))) {
113 if (fp
->fr_flags
& FR_OUTQUE
)
118 if (*fp
->fr_ifnames
[2]) {
119 printifname("", fp
->fr_ifnames
[2],
123 if (*fp
->fr_ifnames
[3]) {
124 printifname(",", fp
->fr_ifnames
[3],
130 if (type
== FR_T_IPF
) {
131 if (fp
->fr_mip
.fi_tos
)
132 printf("tos %#x ", fp
->fr_tos
);
133 if (fp
->fr_mip
.fi_ttl
)
134 printf("ttl %d ", fp
->fr_ttl
);
135 if (fp
->fr_flx
& FI_TCPUDP
) {
136 printf("proto tcp/udp ");
138 } else if (fp
->fr_mip
.fi_p
) {
140 p
= getprotobynumber(pr
);
142 printproto(p
, pr
, NULL
);
147 if (type
== FR_T_NONE
) {
149 } else if (type
== FR_T_IPF
) {
150 printf("from %s", fp
->fr_flags
& FR_NOTSRCIP
? "!" : "");
151 printaddr(fp
->fr_v
, fp
->fr_satype
, fp
->fr_ifname
,
152 &fp
->fr_src
.s_addr
, &fp
->fr_smsk
.s_addr
);
154 printportcmp(pr
, &fp
->fr_tuc
.ftu_src
);
156 printf(" to %s", fp
->fr_flags
& FR_NOTDSTIP
? "!" : "");
157 printaddr(fp
->fr_v
, fp
->fr_datype
, fp
->fr_ifname
,
158 &fp
->fr_dst
.s_addr
, &fp
->fr_dmsk
.s_addr
);
160 printportcmp(pr
, &fp
->fr_tuc
.ftu_dst
);
162 if ((fp
->fr_proto
== IPPROTO_ICMP
164 || fp
->fr_proto
== IPPROTO_ICMPV6
167 int type
= fp
->fr_icmp
, code
;
169 type
= ntohs(fp
->fr_icmp
);
172 if (type
< (sizeof(icmptypes
) / sizeof(char *) - 1) &&
173 icmptypes
[type
] && fp
->fr_proto
== IPPROTO_ICMP
)
174 printf(" icmp-type %s", icmptypes
[type
]);
176 printf(" icmp-type %d", type
);
177 if (ntohs(fp
->fr_icmpm
) & 0xff)
178 printf(" code %d", code
);
180 if ((fp
->fr_proto
== IPPROTO_TCP
) &&
181 (fp
->fr_tcpf
|| fp
->fr_tcpfm
)) {
183 if (fp
->fr_tcpf
& ~TCPF_ALL
)
184 printf("0x%x", fp
->fr_tcpf
);
186 for (s
= flagset
, t
= flags
; *s
; s
++, t
++)
187 if (fp
->fr_tcpf
& *t
)
191 if (fp
->fr_tcpfm
& ~TCPF_ALL
)
192 printf("0x%x", fp
->fr_tcpfm
);
194 for (s
= flagset
, t
= flags
; *s
;
196 if (fp
->fr_tcpfm
& *t
)
200 } else if (type
== FR_T_BPFOPC
) {
204 printf("bpf-v%d { \"", fp
->fr_v
);
205 i
= fp
->fr_dsize
/ sizeof(*fb
);
207 for (fb
= fp
->fr_data
, s
= ""; i
; i
--, fb
++, s
= " ")
208 printf("%s%#x %#x %#x %#x", s
, fb
->fb_c
, fb
->fb_t
,
212 } else if (type
== FR_T_COMPIPF
) {
214 } else if (type
== FR_T_CALLFUNC
) {
215 printf("call function at %p", fp
->fr_data
);
217 printf("[unknown filter type %#x]", fp
->fr_type
);
220 if ((type
== FR_T_IPF
) &&
221 ((fp
->fr_flx
& FI_WITH
) || (fp
->fr_mflx
& FI_WITH
) ||
222 fp
->fr_optbits
|| fp
->fr_optmask
||
223 fp
->fr_secbits
|| fp
->fr_secmask
)) {
227 if (fp
->fr_optbits
|| fp
->fr_optmask
||
228 fp
->fr_secbits
|| fp
->fr_secmask
) {
229 sec
[0] = fp
->fr_secmask
;
230 sec
[1] = fp
->fr_secbits
;
232 optprint(sec
, fp
->fr_optmask
, fp
->fr_optbits
);
235 optprintv6(sec
, fp
->fr_optmask
,
238 } else if (fp
->fr_mflx
& FI_OPTIONS
) {
239 fputs(comma
, stdout
);
240 if (!(fp
->fr_flx
& FI_OPTIONS
))
245 if (fp
->fr_mflx
& FI_SHORT
) {
246 fputs(comma
, stdout
);
247 if (!(fp
->fr_flx
& FI_SHORT
))
252 if (fp
->fr_mflx
& FI_FRAG
) {
253 fputs(comma
, stdout
);
254 if (!(fp
->fr_flx
& FI_FRAG
))
259 if (fp
->fr_mflx
& FI_FRAGBODY
) {
260 fputs(comma
, stdout
);
261 if (!(fp
->fr_flx
& FI_FRAGBODY
))
266 if (fp
->fr_mflx
& FI_NATED
) {
267 fputs(comma
, stdout
);
268 if (!(fp
->fr_flx
& FI_NATED
))
273 if (fp
->fr_mflx
& FI_LOWTTL
) {
274 fputs(comma
, stdout
);
275 if (!(fp
->fr_flx
& FI_LOWTTL
))
280 if (fp
->fr_mflx
& FI_BAD
) {
281 fputs(comma
, stdout
);
282 if (!(fp
->fr_flx
& FI_BAD
))
287 if (fp
->fr_mflx
& FI_BADSRC
) {
288 fputs(comma
, stdout
);
289 if (!(fp
->fr_flx
& FI_BADSRC
))
294 if (fp
->fr_mflx
& FI_BADNAT
) {
295 fputs(comma
, stdout
);
296 if (!(fp
->fr_flx
& FI_BADNAT
))
301 if (fp
->fr_mflx
& FI_OOW
) {
302 fputs(comma
, stdout
);
303 if (!(fp
->fr_flx
& FI_OOW
))
307 if (fp
->fr_mflx
& FI_MULTICAST
) {
308 fputs(comma
, stdout
);
309 if (!(fp
->fr_flx
& FI_MULTICAST
))
314 if (fp
->fr_mflx
& FI_BROADCAST
) {
315 fputs(comma
, stdout
);
316 if (!(fp
->fr_flx
& FI_BROADCAST
))
321 if (fp
->fr_mflx
& FI_MBCAST
) {
322 fputs(comma
, stdout
);
323 if (!(fp
->fr_flx
& FI_MBCAST
))
328 if (fp
->fr_mflx
& FI_STATE
) {
329 fputs(comma
, stdout
);
330 if (!(fp
->fr_flx
& FI_STATE
))
337 if (fp
->fr_flags
& FR_KEEPSTATE
) {
338 printf(" keep state");
339 if ((fp
->fr_flags
& (FR_STSTRICT
|FR_NEWISN
|FR_NOICMPERR
|FR_STATESYNC
)) ||
340 (fp
->fr_statemax
!= 0) || (fp
->fr_age
[0] != 0)) {
343 if (fp
->fr_statemax
!= 0) {
344 printf("limit %u", fp
->fr_statemax
);
347 if (fp
->fr_flags
& FR_STSTRICT
) {
348 printf("%sstrict", comma
);
351 if (fp
->fr_flags
& FR_NEWISN
) {
352 printf("%snewisn", comma
);
355 if (fp
->fr_flags
& FR_NOICMPERR
) {
356 printf("%sno-icmp-err", comma
);
359 if (fp
->fr_flags
& FR_STATESYNC
) {
360 printf("%ssync", comma
);
363 if (fp
->fr_age
[0] || fp
->fr_age
[1])
364 printf("%sage %d/%d", comma
, fp
->fr_age
[0],
369 if (fp
->fr_flags
& FR_KEEPFRAG
) {
370 printf(" keep frags");
371 if (fp
->fr_flags
& (FR_FRSTRICT
)) {
373 if (fp
->fr_flags
& FR_FRSTRICT
)
379 if (fp
->fr_isc
!= (struct ipscan
*)-1) {
380 if (fp
->fr_isctag
[0])
381 printf(" scan %s", fp
->fr_isctag
);
385 if (*fp
->fr_grhead
!= '\0')
386 printf(" head %s", fp
->fr_grhead
);
387 if (*fp
->fr_group
!= '\0')
388 printf(" group %s", fp
->fr_group
);
389 if (fp
->fr_logtag
!= FR_NOLOGTAG
|| *fp
->fr_nattag
.ipt_tag
) {
393 if (fp
->fr_logtag
!= FR_NOLOGTAG
) {
394 printf("log=%u", fp
->fr_logtag
);
397 if (*fp
->fr_nattag
.ipt_tag
) {
398 printf("%snat=%-.*s", s
, IPFTAG_LEN
,
399 fp
->fr_nattag
.ipt_tag
);
404 printf(" pps %d", fp
->fr_pps
);