4 * Copyright (C) 2002-2005 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
16 static const char rcsid[] = "@(#)$Id: printnat.c,v 1.22.2.14 2007/09/06 16:40:11 darrenr Exp $";
20 * Print out a NAT rule
22 void printnat(np, opts)
29 pr = getprotobynumber(np->in_p);
46 fprintf(stderr, "unknown value for in_redir: %#x\n",
51 if (!strcmp(np->in_ifnames[0], "-"))
52 printf(" \"%s\"", np->in_ifnames[0]);
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 if (!strcmp(np->in_ifnames[1], "-"))
58 printf(",\"%s\"", np->in_ifnames[1]);
60 printf(",%s", np->in_ifnames[1]);
64 if (np->in_flags & IPN_FILTER) {
65 if (np->in_flags & IPN_NOTSRC)
68 if (np->in_redir == NAT_REDIRECT) {
69 printhostmask(4, (u_32_t *)&np->in_srcip,
70 (u_32_t *)&np->in_srcmsk);
72 printhostmask(4, (u_32_t *)&np->in_inip,
73 (u_32_t *)&np->in_inmsk);
76 printportcmp(np->in_p, &np->in_tuc.ftu_src);
78 if (np->in_flags & IPN_NOTDST)
81 if (np->in_redir == NAT_REDIRECT) {
82 printhostmask(4, (u_32_t *)&np->in_outip,
83 (u_32_t *)&np->in_outmsk);
85 printhostmask(4, (u_32_t *)&np->in_srcip,
86 (u_32_t *)&np->in_srcmsk);
89 printportcmp(np->in_p, &np->in_tuc.ftu_dst);
92 if (np->in_redir == NAT_REDIRECT) {
93 if (!(np->in_flags & IPN_FILTER)) {
94 printf("%s", inet_ntoa(np->in_out[0].in4));
95 bits = count4bits(np->in_outmsk);
99 printf("/%s", inet_ntoa(np->in_out[1].in4));
100 if (np->in_flags & IPN_TCPUDP) {
101 printf(" port %d", ntohs(np->in_pmin));
102 if (np->in_pmax != np->in_pmin)
103 printf("-%d", ntohs(np->in_pmax));
106 printf(" -> %s", inet_ntoa(np->in_in[0].in4));
107 if (np->in_flags & IPN_SPLIT)
108 printf(",%s", inet_ntoa(np->in_in[1].in4));
109 else if (np->in_inmsk == 0 && np->in_inip == 0)
111 if (np->in_flags & IPN_TCPUDP) {
112 if ((np->in_flags & IPN_FIXEDDPORT) != 0)
113 printf(" port = %d", ntohs(np->in_pnext));
115 printf(" port %d", ntohs(np->in_pnext));
118 printproto(pr, np->in_p, np);
119 if (np->in_flags & IPN_ROUNDR)
120 printf(" round-robin");
121 if (np->in_flags & IPN_FRAG)
123 if (np->in_age[0] != 0 || np->in_age[1] != 0) {
124 printf(" age %d/%d", np->in_age[0], np->in_age[1]);
126 if (np->in_flags & IPN_STICKY)
128 if (np->in_mssclamp != 0)
129 printf(" mssclamp %d", np->in_mssclamp);
130 if (*np->in_plabel != '\0')
131 printf(" proxy %.*s", (int)sizeof(np->in_plabel),
133 if (np->in_tag.ipt_tag[0] != '\0')
134 printf(" tag %-.*s", IPFTAG_LEN, np->in_tag.ipt_tag);
136 if (opts & OPT_DEBUG)
137 printf("\tpmax %u\n", np->in_pmax);
139 int protoprinted = 0;
141 if (!(np->in_flags & IPN_FILTER)) {
142 printf("%s/", inet_ntoa(np->in_in[0].in4));
143 bits = count4bits(np->in_inmsk);
147 printf("%s", inet_ntoa(np->in_in[1].in4));
150 if (np->in_flags & IPN_IPRANGE) {
151 printf("range %s-", inet_ntoa(np->in_out[0].in4));
152 printf("%s", inet_ntoa(np->in_out[1].in4));
154 printf("%s/", inet_ntoa(np->in_out[0].in4));
155 bits = count4bits(np->in_outmsk);
159 printf("%s", inet_ntoa(np->in_out[1].in4));
161 if (*np->in_plabel != '\0') {
162 printf(" proxy port ");
163 if (np->in_dcmp != 0)
164 np->in_dport = htons(np->in_dport);
165 if (np->in_dport != 0) {
168 s = portname(np->in_p, ntohs(np->in_dport));
172 fputs("???", stdout);
174 printf(" %.*s/", (int)sizeof(np->in_plabel),
176 printproto(pr, np->in_p, NULL);
178 } else if (np->in_redir == NAT_MAPBLK) {
179 if ((np->in_pmin == 0) &&
180 (np->in_flags & IPN_AUTOPORTMAP))
181 printf(" ports auto");
183 printf(" ports %d", np->in_pmin);
184 if (opts & OPT_DEBUG)
185 printf("\n\tip modulous %d", np->in_pmax);
186 } else if (np->in_pmin || np->in_pmax) {
187 if (np->in_flags & IPN_ICMPQUERY) {
188 printf(" icmpidmap ");
192 printproto(pr, np->in_p, np);
194 if (np->in_flags & IPN_AUTOPORTMAP) {
196 if (opts & OPT_DEBUG)
197 printf(" [%d:%d %d %d]",
200 np->in_ippip, np->in_ppip);
202 printf(" %d:%d", ntohs(np->in_pmin),
207 if (np->in_flags & IPN_FRAG)
209 if (np->in_age[0] != 0 || np->in_age[1] != 0) {
210 printf(" age %d/%d", np->in_age[0], np->in_age[1]);
212 if (np->in_mssclamp != 0)
213 printf(" mssclamp %d", np->in_mssclamp);
214 if (np->in_tag.ipt_tag[0] != '\0')
215 printf(" tag %s", np->in_tag.ipt_tag);
216 if (!protoprinted && (np->in_flags & IPN_TCPUDP || np->in_p)) {
218 printproto(pr, np->in_p, np);
220 if (np->in_flags & IPN_SEQUENTIAL)
221 printf(" sequential");
223 if (opts & OPT_DEBUG) {
226 nip.s_addr = htonl(np->in_nextip.s_addr);
228 printf("\tnextip %s pnext %d\n",
229 inet_ntoa(nip), np->in_pnext);
233 if (opts & OPT_DEBUG) {
234 printf("\tspace %lu use %u hits %lu flags %#x proto %d hv %d\n",
235 np->in_space, np->in_use, np->in_hits,
236 np->in_flags, np->in_p, np->in_hv);
237 printf("\tifp[0] %p ifp[1] %p apr %p\n",
238 np->in_ifps[0], np->in_ifps[1], np->in_apr);
239 printf("\ttqehead %p/%p comment %p\n",
240 np->in_tqehead[0], np->in_tqehead[1], np->in_comment);