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