alias_db.c (33897) | alias_db.c (35314) |
---|---|
1/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- 2 Alias_db.c encapsulates all data structures used for storing 3 packet aliasing data. Other parts of the aliasing software 4 access data through functions provided in this file. 5 6 Data storage is based on the notion of a "link", which is 7 established for ICMP echo/reply packets, UDP datagrams and 8 TCP stream connections. A link stores the original source --- 326 unchanged lines hidden (view full) --- 335 336static FILE *monitorFile; /* File descriptor for link */ 337 /* statistics monitoring file */ 338 339static int newDefaultLink; /* Indicates if a new aliasing */ 340 /* link has been created after a */ 341 /* call to PacketAliasIn/Out(). */ 342 | 1/* -*- mode: c; tab-width: 8; c-basic-indent: 4; -*- 2 Alias_db.c encapsulates all data structures used for storing 3 packet aliasing data. Other parts of the aliasing software 4 access data through functions provided in this file. 5 6 Data storage is based on the notion of a "link", which is 7 established for ICMP echo/reply packets, UDP datagrams and 8 TCP stream connections. A link stores the original source --- 326 unchanged lines hidden (view full) --- 335 336static FILE *monitorFile; /* File descriptor for link */ 337 /* statistics monitoring file */ 338 339static int newDefaultLink; /* Indicates if a new aliasing */ 340 /* link has been created after a */ 341 /* call to PacketAliasIn/Out(). */ 342 |
343#ifndef NO_FW_PUNCH |
|
343static int fireWallFD = -1; /* File descriptor to be able to */ 344 /* control firewall. Opened by */ 345 /* PacketAliasSetMode on first */ 346 /* setting the PKT_ALIAS_PUNCH_FW */ 347 /* flag. */ | 344static int fireWallFD = -1; /* File descriptor to be able to */ 345 /* control firewall. Opened by */ 346 /* PacketAliasSetMode on first */ 347 /* setting the PKT_ALIAS_PUNCH_FW */ 348 /* flag. */ |
349#endif |
|
348 349 350 351 352 353 354/* Internal utility routines (used only in alias_db.c) 355 --- 14 unchanged lines hidden (view full) --- 370 371static u_int StartPointOut(struct in_addr, struct in_addr, 372 u_short, u_short, int); 373 374static int SeqDiff(u_long, u_long); 375 376static void ShowAliasStats(void); 377 | 350 351 352 353 354 355 356/* Internal utility routines (used only in alias_db.c) 357 --- 14 unchanged lines hidden (view full) --- 372 373static u_int StartPointOut(struct in_addr, struct in_addr, 374 u_short, u_short, int); 375 376static int SeqDiff(u_long, u_long); 377 378static void ShowAliasStats(void); 379 |
380#ifndef NO_FW_PUNCH |
|
378/* Firewall control */ 379static void InitPunchFW(void); 380static void UninitPunchFW(void); 381static void ClearFWHole(struct alias_link *link); | 381/* Firewall control */ 382static void InitPunchFW(void); 383static void UninitPunchFW(void); 384static void ClearFWHole(struct alias_link *link); |
385#endif |
|
382 383/* Log file control */ 384static void InitPacketAliasLog(void); 385static void UninitPacketAliasLog(void); 386 387static u_int 388StartPointIn(struct in_addr alias_addr, 389 u_short alias_port, --- 355 unchanged lines hidden (view full) --- 745{ 746 struct alias_link *link_last; 747 struct alias_link *link_next; 748 749/* Don't do anything if the link is marked permanent */ 750 if (deleteAllLinks == 0 && link->flags & LINK_PERMANENT) 751 return; 752 | 386 387/* Log file control */ 388static void InitPacketAliasLog(void); 389static void UninitPacketAliasLog(void); 390 391static u_int 392StartPointIn(struct in_addr alias_addr, 393 u_short alias_port, --- 355 unchanged lines hidden (view full) --- 749{ 750 struct alias_link *link_last; 751 struct alias_link *link_next; 752 753/* Don't do anything if the link is marked permanent */ 754 if (deleteAllLinks == 0 && link->flags & LINK_PERMANENT) 755 return; 756 |
757#ifndef NO_FW_PUNCH |
|
753/* Delete associatied firewall hole, if any */ 754 ClearFWHole(link); | 758/* Delete associatied firewall hole, if any */ 759 ClearFWHole(link); |
760#endif |
|
755 756/* Adjust output table pointers */ 757 link_last = link->last_out; 758 link_next = link->next_out; 759 760 if (link_last != NULL) 761 link_last->next_out = link_next; 762 else --- 219 unchanged lines hidden (view full) --- 982 int alias_port_param, /* if less than zero, alias */ 983 int link_type) /* port will be automatically */ 984{ /* chosen. If greater than */ 985 struct alias_link *new_link; /* zero, equal to alias port */ 986 987 new_link = AddLink(src_addr, dst_addr, alias_addr, 988 src_port, dst_port, alias_port_param, 989 link_type); | 761 762/* Adjust output table pointers */ 763 link_last = link->last_out; 764 link_next = link->next_out; 765 766 if (link_last != NULL) 767 link_last->next_out = link_next; 768 else --- 219 unchanged lines hidden (view full) --- 988 int alias_port_param, /* if less than zero, alias */ 989 int link_type) /* port will be automatically */ 990{ /* chosen. If greater than */ 991 struct alias_link *new_link; /* zero, equal to alias port */ 992 993 new_link = AddLink(src_addr, dst_addr, alias_addr, 994 src_port, dst_port, alias_port_param, 995 link_type); |
996#ifndef NO_FW_PUNCH |
|
990 if (new_link != NULL && 991 old_link->link_type == LINK_TCP && 992 old_link->data.tcp && 993 old_link->data.tcp->fwhole > 0) { 994 PunchFWHole(new_link); 995 } | 997 if (new_link != NULL && 998 old_link->link_type == LINK_TCP && 999 old_link->data.tcp && 1000 old_link->data.tcp->fwhole > 0) { 1001 PunchFWHole(new_link); 1002 } |
1003#endif |
|
996 DeleteLink(old_link); 997 return new_link; 998} 999 1000static struct alias_link * 1001FindLinkOut(struct in_addr src_addr, 1002 struct in_addr dst_addr, 1003 u_short src_port, --- 996 unchanged lines hidden (view full) --- 2000} 2001 2002void 2003PacketAliasUninit(void) { 2004 deleteAllLinks = 1; 2005 CleanupAliasData(); 2006 deleteAllLinks = 0; 2007 UninitPacketAliasLog(); | 1004 DeleteLink(old_link); 1005 return new_link; 1006} 1007 1008static struct alias_link * 1009FindLinkOut(struct in_addr src_addr, 1010 struct in_addr dst_addr, 1011 u_short src_port, --- 996 unchanged lines hidden (view full) --- 2008} 2009 2010void 2011PacketAliasUninit(void) { 2012 deleteAllLinks = 1; 2013 CleanupAliasData(); 2014 deleteAllLinks = 0; 2015 UninitPacketAliasLog(); |
2016#ifndef NO_FW_PUNCH |
|
2008 UninitPunchFW(); | 2017 UninitPunchFW(); |
2018#endif |
|
2009} 2010 2011 2012/* Change mode for some operations */ 2013unsigned int 2014PacketAliasSetMode( 2015 unsigned int flags, /* Which state to bring flags to */ 2016 unsigned int mask /* Mask of which flags to affect (use 0 to do a --- 5 unchanged lines hidden (view full) --- 2022 { 2023 InitPacketAliasLog(); /* Do the enable */ 2024 } else 2025/* _Disable_ logging? */ 2026 if (~flags & mask & PKT_ALIAS_LOG) { 2027 UninitPacketAliasLog(); 2028 } 2029 | 2019} 2020 2021 2022/* Change mode for some operations */ 2023unsigned int 2024PacketAliasSetMode( 2025 unsigned int flags, /* Which state to bring flags to */ 2026 unsigned int mask /* Mask of which flags to affect (use 0 to do a --- 5 unchanged lines hidden (view full) --- 2032 { 2033 InitPacketAliasLog(); /* Do the enable */ 2034 } else 2035/* _Disable_ logging? */ 2036 if (~flags & mask & PKT_ALIAS_LOG) { 2037 UninitPacketAliasLog(); 2038 } 2039 |
2040#ifndef NO_FW_PUNCH |
|
2030/* Start punching holes in the firewall? */ 2031 if (flags & mask & PKT_ALIAS_PUNCH_FW) { 2032 InitPunchFW(); 2033 } else 2034/* Stop punching holes in the firewall? */ 2035 if (~flags & mask & PKT_ALIAS_PUNCH_FW) { 2036 UninitPunchFW(); 2037 } | 2041/* Start punching holes in the firewall? */ 2042 if (flags & mask & PKT_ALIAS_PUNCH_FW) { 2043 InitPunchFW(); 2044 } else 2045/* Stop punching holes in the firewall? */ 2046 if (~flags & mask & PKT_ALIAS_PUNCH_FW) { 2047 UninitPunchFW(); 2048 } |
2049#endif |
|
2038 2039/* Other flags can be set/cleared without special action */ 2040 packetAliasMode = (flags & mask) | (packetAliasMode & ~mask); 2041 return packetAliasMode; 2042} 2043 2044 2045int 2046PacketAliasCheckNewLink(void) 2047{ 2048 return newDefaultLink; 2049} 2050 2051 | 2050 2051/* Other flags can be set/cleared without special action */ 2052 packetAliasMode = (flags & mask) | (packetAliasMode & ~mask); 2053 return packetAliasMode; 2054} 2055 2056 2057int 2058PacketAliasCheckNewLink(void) 2059{ 2060 return newDefaultLink; 2061} 2062 2063 |
2064#ifndef NO_FW_PUNCH 2065 |
|
2052/***************** 2053 Code to support firewall punching. This shouldn't really be in this 2054 file, but making variables global is evil too. 2055 ****************/ 2056 2057/* Firewall include files */ 2058#include <sys/queue.h> 2059#include <net/if.h> --- 157 unchanged lines hidden (view full) --- 2217 memset(&rule, 0, sizeof rule); 2218 for (i = fireWallBaseNum; i < fireWallBaseNum + fireWallNumNums; i++) { 2219 rule.fw_number = i; 2220 while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL, &rule, sizeof rule)) 2221 ; 2222 } 2223 memset(fireWallField, 0, fireWallNumNums); 2224} | 2066/***************** 2067 Code to support firewall punching. This shouldn't really be in this 2068 file, but making variables global is evil too. 2069 ****************/ 2070 2071/* Firewall include files */ 2072#include <sys/queue.h> 2073#include <net/if.h> --- 157 unchanged lines hidden (view full) --- 2231 memset(&rule, 0, sizeof rule); 2232 for (i = fireWallBaseNum; i < fireWallBaseNum + fireWallNumNums; i++) { 2233 rule.fw_number = i; 2234 while (!setsockopt(fireWallFD, IPPROTO_IP, IP_FW_DEL, &rule, sizeof rule)) 2235 ; 2236 } 2237 memset(fireWallField, 0, fireWallNumNums); 2238} |
2239#endif |
|