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 19 void 20 printactivenat(nat_t *nat, int opts, u_long ticks) 21 { 22 23 PRINTF("%s", getnattype(nat)); 24 25 if (nat->nat_flags & SI_CLONE) 26 PRINTF(" CLONE"); 27 if (nat->nat_phnext[0] == NULL && nat->nat_phnext[1] == NULL) 28 PRINTF(" ORPHAN"); 29 30 putchar(' '); 31 if (nat->nat_redir & NAT_REWRITE) { 32 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_osrc6, 33 nat->nat_ifnames[0]); 34 35 if ((nat->nat_flags & IPN_TCPUDP) != 0) 36 PRINTF(" %-5hu", ntohs(nat->nat_osport)); 37 38 putchar(' '); 39 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_odst6, 40 nat->nat_ifnames[0]); 41 42 if ((nat->nat_flags & IPN_TCPUDP) != 0) 43 PRINTF(" %-5hu", ntohs(nat->nat_odport)); 44 45 PRINTF("<- -> "); 46 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_nsrc6, 47 nat->nat_ifnames[0]); 48 49 if ((nat->nat_flags & IPN_TCPUDP) != 0) 50 PRINTF(" %-5hu", ntohs(nat->nat_nsport)); 51 52 putchar(' '); 53 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_ndst6, 54 nat->nat_ifnames[0]); 55 if ((nat->nat_flags & IPN_TCPUDP) != 0) 56 PRINTF(" %-5hu", ntohs(nat->nat_ndport)); 57 58 } else if (nat->nat_dir == NAT_OUTBOUND) { 59 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_osrc6, 60 nat->nat_ifnames[0]); 61 62 if ((nat->nat_flags & IPN_TCPUDP) != 0) 63 PRINTF(" %-5hu", ntohs(nat->nat_osport)); 64 65 PRINTF(" <- -> "); 66 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_nsrc6, 67 nat->nat_ifnames[0]); 68 69 if ((nat->nat_flags & IPN_TCPUDP) != 0) 70 PRINTF(" %-5hu", ntohs(nat->nat_nsport)); 71 72 PRINTF(" ["); 73 printactiveaddress(nat->nat_v[0], "%s", &nat->nat_odst6, 74 nat->nat_ifnames[0]); 75 76 if ((nat->nat_flags & IPN_TCPUDP) != 0) 77 PRINTF(" %hu", ntohs(nat->nat_odport)); 78 PRINTF("]"); 79 } else { 80 printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_ndst6, 81 nat->nat_ifnames[0]); 82 83 if ((nat->nat_flags & IPN_TCPUDP) != 0) 84 PRINTF(" %-5hu", ntohs(nat->nat_ndport)); 85 86 PRINTF(" <- -> "); 87 printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_odst6, 88 nat->nat_ifnames[0]); 89 90 if ((nat->nat_flags & IPN_TCPUDP) != 0) 91 PRINTF(" %-5hu", ntohs(nat->nat_odport)); 92 93 PRINTF(" ["); 94 printactiveaddress(nat->nat_v[0], "%s", &nat->nat_osrc6, 95 nat->nat_ifnames[0]); 96 97 if ((nat->nat_flags & IPN_TCPUDP) != 0) 98 PRINTF(" %hu", ntohs(nat->nat_osport)); 99 PRINTF("]"); 100 } 101 102 if (opts & OPT_VERBOSE) { 103 PRINTF("\n\tttl %lu use %hu sumd %s/", 104 nat->nat_age - ticks, nat->nat_use, 105 getsumd(nat->nat_sumd[0])); 106 PRINTF("%s pr %u/%u hash %u/%u flags %x\n", 107 getsumd(nat->nat_sumd[1]), 108 nat->nat_pr[0], nat->nat_pr[1], 109 nat->nat_hv[0], nat->nat_hv[1], nat->nat_flags); 110 PRINTF("\tifp %s", getifname(nat->nat_ifps[0])); 111 PRINTF(",%s ", getifname(nat->nat_ifps[1])); 112 #ifdef USE_QUAD_T 113 PRINTF("bytes %"PRIu64"/%"PRIu64" pkts %"PRIu64"/%"PRIu64"", 114 (unsigned long long)nat->nat_bytes[0], 115 (unsigned long long)nat->nat_bytes[1], 116 (unsigned long long)nat->nat_pkts[0], 117 (unsigned long long)nat->nat_pkts[1]); 118 #else 119 PRINTF("bytes %lu/%lu pkts %lu/%lu", nat->nat_bytes[0], 120 nat->nat_bytes[1], nat->nat_pkts[0], nat->nat_pkts[1]); 121 #endif 122 PRINTF(" ipsumd %x", nat->nat_ipsumd); 123 } 124 125 if (opts & OPT_DEBUG) { 126 PRINTF("\n\tnat_next %p _pnext %p _hm %p\n", 127 nat->nat_next, nat->nat_pnext, nat->nat_hm); 128 PRINTF("\t_hnext %p/%p _phnext %p/%p\n", 129 nat->nat_hnext[0], nat->nat_hnext[1], 130 nat->nat_phnext[0], nat->nat_phnext[1]); 131 PRINTF("\t_data %p _me %p _state %p _aps %p\n", 132 nat->nat_data, nat->nat_me, nat->nat_state, 133 nat->nat_aps); 134 PRINTF("\tfr %p ptr %p ifps %p/%p sync %p\n", 135 nat->nat_fr, nat->nat_ptr, nat->nat_ifps[0], 136 nat->nat_ifps[1], nat->nat_sync); 137 PRINTF("\ttqe:pnext %p next %p ifq %p parent %p/%p\n", 138 nat->nat_tqe.tqe_pnext, nat->nat_tqe.tqe_next, 139 nat->nat_tqe.tqe_ifq, nat->nat_tqe.tqe_parent, nat); 140 PRINTF("\ttqe:die %d touched %d flags %x state %d/%d\n", 141 nat->nat_tqe.tqe_die, nat->nat_tqe.tqe_touched, 142 nat->nat_tqe.tqe_flags, nat->nat_tqe.tqe_state[0], 143 nat->nat_tqe.tqe_state[1]); 144 } 145 putchar('\n'); 146 } 147