--- alias_db.c.original Fri Apr 15 22:51:23 2003 +++ alias_db.c Fri Apr 15 22:51:54 2003 @@ -359,15 +359,6 @@ linkTableIn[LINK_TABLE_IN_SIZE]; /* into input and output lookup */ /* tables. */ -static int icmpLinkCount; /* Link statistics */ -static int udpLinkCount; -static int tcpLinkCount; -static int pptpLinkCount; -static int protoLinkCount; -static int fragmentIdLinkCount; -static int fragmentPtrLinkCount; -static int sockCount; - static int cleanupIndex; /* Index to chain of link table */ /* being inspected for old links */ @@ -413,7 +404,11 @@ Miscellaneous: SeqDiff() -- difference between two TCP sequences - ShowAliasStats() -- send alias statistics to a monitor file + ShowAliasDetails() -- print major fields of struct link_alias + in text format (for debugging/ + administration purpose) + ShowAddrAndPort() -- call from ShowAliasDetails(). + ShowLinkType() -- ditto. */ @@ -425,7 +420,9 @@ static int SeqDiff(u_long, u_long); -static void ShowAliasStats(void); +static void ShowAddrAndPort(struct in_addr, u_short); +static void ShowLinkType(int); +static void ShowAliasDetails(int, struct alias_link const *); #ifndef NO_FW_PUNCH /* Firewall control */ @@ -485,36 +482,61 @@ } -static void -ShowAliasStats(void) -{ -/* Used for debugging */ - if (monitorFile) - { - fprintf(monitorFile, "icmp=%d, udp=%d, tcp=%d, pptp=%d, proto=%d, frag_id=%d frag_ptr=%d", - icmpLinkCount, - udpLinkCount, - tcpLinkCount, - pptpLinkCount, - protoLinkCount, - fragmentIdLinkCount, - fragmentPtrLinkCount); - - fprintf(monitorFile, " / tot=%d (sock=%d)\n", - icmpLinkCount + udpLinkCount - + tcpLinkCount - + pptpLinkCount - + protoLinkCount - + fragmentIdLinkCount - + fragmentPtrLinkCount, - sockCount); - fflush(monitorFile); - } +static void +ShowAddrAndPort (struct in_addr addr, u_short port) +{ + fprintf(monitorFile, + port == 0 ? " %s:*" : " %s:%u", + addr.s_addr == INADDR_ANY ? "*" : inet_ntoa(addr), + ntohs(port)); } +static void +ShowLinkType (int linktype) +{ + char const *p; + + switch (linktype) { + case LINK_ICMP: p = "icmp"; break; + case LINK_TCP: p = "tcp"; break; + case LINK_UDP: p = "udp"; break; + case LINK_FRAGMENT_ID: p = "[frag_id]"; break; + case LINK_FRAGMENT_PTR: p = "[frag_ptr]"; break; + case LINK_ADDR: p = "[addr]"; break; + case LINK_PPTP: p = "[pptp]"; break; + default: p = "[%d]"; break; + } + fprintf(monitorFile, p, linktype); +} + +/* Show major fields of an alias_link in text format, one per a line, + preceeded by a change indicator. The possible values of the change + indicator are not specified here, but intended to be either '+', + '=', or '-' for "add", "modify", and "remove," respectively. + + BUGS: Under some condition, additon of only one actual link may + cause several (two or three) entries to be logged. It is because + our caller (alias_proxy.c in particular) updates some fields after + allocation. Moreover, the way ReLink() is implemented in this + version causes redundant log entries. This should eventually be + corrected. */ +static void +ShowAliasDetails (int change, struct alias_link const *link) +{ + if (monitorFile && (packetAliasMode & PKT_ALIAS_LOG)) { + fprintf(monitorFile, "%c ", change); + ShowLinkType(link->link_type); + ShowAddrAndPort(link->src_addr, link->src_port); + ShowAddrAndPort(link->dst_addr, link->dst_port); + ShowAddrAndPort(link->alias_addr, link->alias_port); + ShowAddrAndPort(link->proxy_addr, link->proxy_port); + fprintf(monitorFile, " (%p)\n", (void const *) link); + fflush(monitorFile); + } +} @@ -536,8 +558,7 @@ FindLinkIn() - find link for incoming packets Port search: - FindNewPortGroup() - find an available group of ports -*/ + FindNewPortGroup() - find an available group of ports */ /* Local prototypes */ static int GetNewPort(struct alias_link *, int); @@ -732,7 +753,6 @@ sizeof(sock_addr)); if (err == 0) { - sockCount++; *sockfd = sock; return(1); } @@ -943,7 +963,6 @@ /* Close socket, if one has been allocated */ if (link->sockfd != -1) { - sockCount--; close(link->sockfd); } @@ -951,41 +970,32 @@ switch(link->link_type) { case LINK_ICMP: - icmpLinkCount--; break; case LINK_UDP: - udpLinkCount--; break; case LINK_TCP: - tcpLinkCount--; free(link->data.tcp); break; case LINK_PPTP: - pptpLinkCount--; break; case LINK_FRAGMENT_ID: - fragmentIdLinkCount--; break; case LINK_FRAGMENT_PTR: - fragmentPtrLinkCount--; if (link->data.frag_ptr != NULL) free(link->data.frag_ptr); break; case LINK_ADDR: break; default: - protoLinkCount--; break; } +/* Write statistics, if logging enabled */ + ShowAliasDetails('-', link); + /* Free memory */ free(link); -/* Write statistics, if logging enabled */ - if (packetAliasMode & PKT_ALIAS_LOG) - { - ShowAliasStats(); - } } @@ -1065,10 +1075,8 @@ struct tcp_dat *aux_tcp; case LINK_ICMP: - icmpLinkCount++; break; case LINK_UDP: - udpLinkCount++; break; case LINK_TCP: aux_tcp = malloc(sizeof(struct tcp_dat)); @@ -1076,7 +1084,6 @@ { int i; - tcpLinkCount++; aux_tcp->state.in = ALIAS_TCP_STATE_NOT_CONNECTED; aux_tcp->state.out = ALIAS_TCP_STATE_NOT_CONNECTED; aux_tcp->state.index = 0; @@ -1097,18 +1104,14 @@ } break; case LINK_PPTP: - pptpLinkCount++; break; case LINK_FRAGMENT_ID: - fragmentIdLinkCount++; break; case LINK_FRAGMENT_PTR: - fragmentPtrLinkCount++; break; case LINK_ADDR: break; default: - protoLinkCount++; break; } @@ -1120,6 +1123,8 @@ /* Set up pointers for input lookup table */ start_point = StartPointIn(alias_addr, link->alias_port, link_type); LIST_INSERT_HEAD(&linkTableIn[start_point], link, list_in); + + ShowAliasDetails('+', link); } else { @@ -1129,11 +1134,6 @@ #endif } - if (packetAliasMode & PKT_ALIAS_LOG) - { - ShowAliasStats(); - } - return(link); } @@ -2028,6 +2028,7 @@ SetProxyAddress(struct alias_link *link, struct in_addr addr) { link->proxy_addr = addr; + ShowAliasDetails('=', link); } @@ -2042,6 +2043,7 @@ SetProxyPort(struct alias_link *link, u_short port) { link->proxy_port = port; + ShowAliasDetails('=', link); } @@ -2559,15 +2561,6 @@ aliasAddress.s_addr = INADDR_ANY; targetAddress.s_addr = INADDR_ANY; - icmpLinkCount = 0; - udpLinkCount = 0; - tcpLinkCount = 0; - pptpLinkCount = 0; - protoLinkCount = 0; - fragmentIdLinkCount = 0; - fragmentPtrLinkCount = 0; - sockCount = 0; - cleanupIndex =0; packetAliasMode = PKT_ALIAS_SAME_PORTS