2 * Copyright (C) 2002-2005 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
8 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
9 * Use is subject to license terms.
12 #pragma ident "%Z%%M% %I% %E% SMI"
18 static const char rcsid
[] = "@(#)$Id: printnat.c,v 1.22.2.9 2005/06/12 07:18:43 darrenr Exp $";
21 * Print out a NAT rule
23 void printnat(np
, opts
)
29 char ipbuf
[INET6_ADDRSTRLEN
];
32 pr
= getprotobynumber(np
->in_p
);
49 fprintf(stderr
, "unknown value for in_redir: %#x\n",
54 printf(" %s", np
->in_ifnames
[0]);
55 if ((np
->in_ifnames
[1][0] != '\0') &&
56 (strncmp(np
->in_ifnames
[0], np
->in_ifnames
[1], LIFNAMSIZ
) != 0)) {
57 printf(",%s ", np
->in_ifnames
[1]);
61 if (np
->in_flags
& IPN_FILTER
) {
62 if (np
->in_flags
& IPN_NOTSRC
)
65 if (np
->in_redir
== NAT_REDIRECT
) {
66 printhostmask(np
->in_v
, (u_32_t
*)&np
->in_src
[0],
67 (u_32_t
*)&np
->in_src
[1]);
69 printhostmask(np
->in_v
, (u_32_t
*)&np
->in_in
[0],
70 (u_32_t
*)&np
->in_in
[1]);
73 printportcmp(np
->in_p
, &np
->in_tuc
.ftu_src
);
75 if (np
->in_flags
& IPN_NOTDST
)
78 if (np
->in_redir
== NAT_REDIRECT
) {
79 printhostmask(np
->in_v
, (u_32_t
*)&np
->in_out
[0],
80 (u_32_t
*)&np
->in_out
[1]);
82 printhostmask(np
->in_v
, (u_32_t
*)&np
->in_src
[0],
83 (u_32_t
*)&np
->in_src
[1]);
86 printportcmp(np
->in_p
, &np
->in_tuc
.ftu_dst
);
91 else if (np
->in_v
== 6)
96 if (np
->in_redir
== NAT_REDIRECT
) {
97 if (!(np
->in_flags
& IPN_FILTER
)) {
98 ptr
= (void *)(u_32_t
*)&np
->in_out
[0];
99 printf("%s", inet_ntop(af
, ptr
, ipbuf
, sizeof (ipbuf
)));
100 printmask(np
->in_v
, (u_32_t
*)&np
->in_out
[1]);
101 if (np
->in_flags
& IPN_TCPUDP
) {
102 printf(" port %d", ntohs(np
->in_pmin
));
103 if (np
->in_pmax
!= np
->in_pmin
)
104 printf("-%d", ntohs(np
->in_pmax
));
108 ptr
= (void *)(u_32_t
*)&np
->in_in
[0];
109 printf("%s", inet_ntop(af
, ptr
, ipbuf
, sizeof (ipbuf
)));
110 if (np
->in_flags
& IPN_SPLIT
) {
112 ptr
= (void *)(u_32_t
*)&np
->in_in
[1];
113 printf("%s", inet_ntop(af
, ptr
, ipbuf
, sizeof (ipbuf
)));
115 if (((np
->in_v
== 4) && (np
->in_inip
== 0)) ||
116 ((np
->in_v
== 6) && IP6_ISZERO(&np
->in_in
[0])))
117 printmask(np
->in_v
, (u_32_t
*)&np
->in_in
[1]);
119 if (np
->in_flags
& IPN_TCPUDP
) {
120 if ((np
->in_flags
& IPN_FIXEDDPORT
) != 0)
121 printf(" port = %d", ntohs(np
->in_pnext
));
123 printf(" port %d", ntohs(np
->in_pnext
));
126 printproto(pr
, np
->in_p
, np
);
127 if (np
->in_flags
& IPN_ROUNDR
)
128 printf(" round-robin");
129 if (np
->in_flags
& IPN_FRAG
)
131 if (np
->in_age
[0] != 0 || np
->in_age
[1] != 0) {
132 printf(" age %d/%d", np
->in_age
[0], np
->in_age
[1]);
134 if (np
->in_flags
& IPN_STICKY
)
136 if (np
->in_mssclamp
!= 0)
137 printf(" mssclamp %d", np
->in_mssclamp
);
138 if (*np
->in_plabel
!= '\0')
139 printf(" proxy %.*s", (int)sizeof (np
->in_plabel
),
141 if (np
->in_tag
.ipt_tag
[0] != '\0')
142 printf(" tag %-.*s", IPFTAG_LEN
, np
->in_tag
.ipt_tag
);
144 if (opts
& OPT_DEBUG
)
145 printf("\tpmax %u\n", np
->in_pmax
);
147 if (!(np
->in_flags
& IPN_FILTER
)) {
148 ptr
= (void *)(u_32_t
*)&np
->in_in
[0];
149 printf("%s", inet_ntop(af
, ptr
, ipbuf
, sizeof (ipbuf
)));
150 printmask(np
->in_v
, (u_32_t
*)&np
->in_in
[1]);
153 if (np
->in_flags
& IPN_IPRANGE
) {
155 ptr
= (void *)(u_32_t
*)&np
->in_out
[0];
156 printf("%s", inet_ntop(af
, ptr
, ipbuf
, sizeof (ipbuf
)));
158 ptr
= (void *)(u_32_t
*)&np
->in_out
[1];
159 printf("%s", inet_ntop(af
, ptr
, ipbuf
, sizeof (ipbuf
)));
161 ptr
= (void *)(u_32_t
*)&np
->in_out
[0];
162 printf("%s", inet_ntop(af
, ptr
, ipbuf
, sizeof (ipbuf
)));
163 printmask(np
->in_v
, (u_32_t
*)&np
->in_out
[1]);
165 if (*np
->in_plabel
!= '\0') {
166 printf(" proxy port ");
167 if (np
->in_dcmp
!= 0)
168 np
->in_dport
= htons(np
->in_dport
);
169 if (np
->in_dport
!= 0) {
172 s
= portname(np
->in_p
, ntohs(np
->in_dport
));
176 fputs("???", stdout
);
178 printf(" %.*s/", (int)sizeof (np
->in_plabel
),
180 printproto(pr
, np
->in_p
, NULL
);
181 } else if (np
->in_redir
== NAT_MAPBLK
) {
182 if ((np
->in_pmin
== 0) &&
183 (np
->in_flags
& IPN_AUTOPORTMAP
))
184 printf(" ports auto");
186 printf(" ports %d", np
->in_pmin
);
187 if (opts
& OPT_DEBUG
)
188 printf("\n\tip modulous %d", np
->in_pmax
);
189 } else if (np
->in_pmin
|| np
->in_pmax
) {
190 if (np
->in_flags
& IPN_ICMPQUERY
) {
191 printf(" icmpidmap ");
195 printproto(pr
, np
->in_p
, np
);
196 if (np
->in_flags
& IPN_AUTOPORTMAP
) {
198 if (opts
& OPT_DEBUG
)
199 printf(" [%d:%d %d %d]",
202 np
->in_ippip
, np
->in_ppip
);
204 printf(" %d:%d", ntohs(np
->in_pmin
),
207 } else if (np
->in_flags
& IPN_TCPUDP
|| np
->in_p
) {
209 printproto(pr
, np
->in_p
, np
);
212 if (np
->in_flags
& IPN_FRAG
)
214 if (np
->in_age
[0] != 0 || np
->in_age
[1] != 0) {
215 printf(" age %d/%d", np
->in_age
[0], np
->in_age
[1]);
217 if (np
->in_mssclamp
!= 0)
218 printf(" mssclamp %d", np
->in_mssclamp
);
219 if (np
->in_tag
.ipt_tag
[0] != '\0')
220 printf(" tag %s", np
->in_tag
.ipt_tag
);
221 if (np
->in_flags
& IPN_SEQUENTIAL
)
222 printf(" sequential");
224 if (opts
& OPT_DEBUG
) {
227 nip
.s_addr
= htonl(np
->in_nextip
.s_addr
);
229 printf("\tnextip %s pnext %d\n",
230 inet_ntoa(nip
), np
->in_pnext
);
234 if (opts
& OPT_DEBUG
) {
235 printf("\tspace %lu use %u hits %lu flags %#x proto %d hv %d\n",
236 np
->in_space
, np
->in_use
, np
->in_hits
,
237 np
->in_flags
, np
->in_p
, np
->in_hv
);
238 printf("\tifp[0] %p ifp[1] %p apr %p\n",
239 np
->in_ifps
[0], np
->in_ifps
[1], np
->in_apr
);
240 printf("\ttqehead %p/%p comment %p\n",
241 np
->in_tqehead
[0], np
->in_tqehead
[1], np
->in_comment
);