1
2 /*
3 * Copyright (C) 2012 by Darren Reed.
4 *
5 * See the IPFILTER.LICENCE file for details on licencing.
6 *
7 * Added redirect stuff and a variety of bug fixes. (mcn@EnGarde.com)
8 */
9
10 #include "ipf.h"
11
12
13
14 static int proto_opened = 0;
15
16 void
printactivenat(nat_t * nat,int opts,u_long ticks)17 printactivenat(nat_t *nat, int opts, u_long ticks)
18 {
19 struct protoent *pproto;
20
21 if (proto_opened == 0) {
22 proto_opened = 1;
23 setprotoent(1);
24 }
25
26 PRINTF("%s", getnattype(nat));
27
28 if (nat->nat_flags & SI_CLONE)
29 PRINTF(" CLONE");
30 if (nat->nat_phnext[0] == NULL && nat->nat_phnext[1] == NULL)
31 PRINTF(" ORPHAN");
32
33 putchar(' ');
34 if (nat->nat_redir & NAT_REWRITE) {
35 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_osrc6,
36 nat->nat_ifnames[0]);
37
38 if ((nat->nat_flags & IPN_TCPUDP) != 0)
39 PRINTF(" %-5hu", ntohs(nat->nat_osport));
40
41 putchar(' ');
42 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_odst6,
43 nat->nat_ifnames[0]);
44
45 if ((nat->nat_flags & IPN_TCPUDP) != 0)
46 PRINTF(" %-5hu", ntohs(nat->nat_odport));
47
48 PRINTF("<- -> ");
49 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_nsrc6,
50 nat->nat_ifnames[0]);
51
52 if ((nat->nat_flags & IPN_TCPUDP) != 0)
53 PRINTF(" %-5hu", ntohs(nat->nat_nsport));
54
55 putchar(' ');
56 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_ndst6,
57 nat->nat_ifnames[0]);
58 if ((nat->nat_flags & IPN_TCPUDP) != 0)
59 PRINTF(" %-5hu", ntohs(nat->nat_ndport));
60
61 pproto = getprotobynumber(nat->nat_pr[0]);
62 PRINTF(" %s", pproto->p_name);
63
64 } else if (nat->nat_dir == NAT_OUTBOUND) {
65 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_osrc6,
66 nat->nat_ifnames[0]);
67
68 if ((nat->nat_flags & IPN_TCPUDP) != 0)
69 PRINTF(" %-5hu", ntohs(nat->nat_osport));
70
71 PRINTF(" <- -> ");
72 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_nsrc6,
73 nat->nat_ifnames[0]);
74
75 if ((nat->nat_flags & IPN_TCPUDP) != 0)
76 PRINTF(" %-5hu", ntohs(nat->nat_nsport));
77
78 PRINTF(" [");
79 printactiveaddress(nat->nat_v[0], "%s", &nat->nat_odst6,
80 nat->nat_ifnames[0]);
81
82 if ((nat->nat_flags & IPN_TCPUDP) != 0)
83 PRINTF(" %hu", ntohs(nat->nat_odport));
84 PRINTF("]");
85
86 pproto = getprotobynumber(nat->nat_pr[1]);
87 PRINTF(" %s", pproto->p_name);
88 } else {
89 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_ndst6,
90 nat->nat_ifnames[0]);
91
92 if ((nat->nat_flags & IPN_TCPUDP) != 0)
93 PRINTF(" %-5hu", ntohs(nat->nat_ndport));
94
95 PRINTF(" <- -> ");
96 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_odst6,
97 nat->nat_ifnames[0]);
98
99 if ((nat->nat_flags & IPN_TCPUDP) != 0)
100 PRINTF(" %-5hu", ntohs(nat->nat_odport));
101
102 PRINTF(" [");
103 printactiveaddress(nat->nat_v[0], "%s", &nat->nat_osrc6,
104 nat->nat_ifnames[0]);
105
106 if ((nat->nat_flags & IPN_TCPUDP) != 0)
107 PRINTF(" %hu", ntohs(nat->nat_osport));
108 PRINTF("]");
109
110 pproto = getprotobynumber(nat->nat_pr[0]);
111 PRINTF(" %s", pproto->p_name);
112 }
113
114
115 if (opts & OPT_VERBOSE) {
116 PRINTF("\n\tttl %lu use %hu sumd %s/",
117 nat->nat_age - ticks, nat->nat_use,
118 getsumd(nat->nat_sumd[0]));
119 PRINTF("%s pr %u/%u hash %u/%u flags %x\n",
120 getsumd(nat->nat_sumd[1]),
121 nat->nat_pr[0], nat->nat_pr[1],
122 nat->nat_hv[0], nat->nat_hv[1], nat->nat_flags);
123 PRINTF("\tifp %s,%s ", FORMAT_IF(nat->nat_ifnames[0]),
124 FORMAT_IF(nat->nat_ifnames[1]));
125 #ifdef USE_QUAD_T
126 PRINTF("bytes %"PRIu64"/%"PRIu64" pkts %"PRIu64"/%"PRIu64"",
127 (unsigned long long)nat->nat_bytes[0],
128 (unsigned long long)nat->nat_bytes[1],
129 (unsigned long long)nat->nat_pkts[0],
130 (unsigned long long)nat->nat_pkts[1]);
131 #else
132 PRINTF("bytes %lu/%lu pkts %lu/%lu", nat->nat_bytes[0],
133 nat->nat_bytes[1], nat->nat_pkts[0], nat->nat_pkts[1]);
134 #endif
135 PRINTF(" ipsumd %x", nat->nat_ipsumd);
136 }
137
138 if (opts & OPT_DEBUG) {
139 PRINTF("\n\tnat_next %p _pnext %p _hm %p\n",
140 nat->nat_next, nat->nat_pnext, nat->nat_hm);
141 PRINTF("\t_hnext %p/%p _phnext %p/%p\n",
142 nat->nat_hnext[0], nat->nat_hnext[1],
143 nat->nat_phnext[0], nat->nat_phnext[1]);
144 PRINTF("\t_data %p _me %p _state %p _aps %p\n",
145 nat->nat_data, nat->nat_me, nat->nat_state,
146 nat->nat_aps);
147 PRINTF("\tfr %p ptr %p ifps %p/%p sync %p\n",
148 nat->nat_fr, nat->nat_ptr, nat->nat_ifps[0],
149 nat->nat_ifps[1], nat->nat_sync);
150 PRINTF("\ttqe:pnext %p next %p ifq %p parent %p/%p\n",
151 nat->nat_tqe.tqe_pnext, nat->nat_tqe.tqe_next,
152 nat->nat_tqe.tqe_ifq, nat->nat_tqe.tqe_parent, nat);
153 PRINTF("\ttqe:die %d touched %d flags %x state %d/%d\n",
154 nat->nat_tqe.tqe_die, nat->nat_tqe.tqe_touched,
155 nat->nat_tqe.tqe_flags, nat->nat_tqe.tqe_state[0],
156 nat->nat_tqe.tqe_state[1]);
157 }
158 putchar('\n');
159 }
160