alias_db.c (145926) | alias_db.c (145927) |
---|---|
1/*- 2 * Copyright (c) 2001 Charles Mott <cm@linktel.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 Charles Mott <cm@linktel.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_db.c 145926 2005-05-05 20:25:12Z glebius $"); | 28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_db.c 145927 2005-05-05 21:05:38Z glebius $"); |
29 30/* 31 Alias_db.c encapsulates all data structures used for storing 32 packet aliasing data. Other parts of the aliasing software 33 access data through functions provided in this file. 34 35 Data storage is based on the notion of a "link", which is 36 established for ICMP echo/reply packets, UDP datagrams and --- 299 unchanged lines hidden (view full) --- 336 337 union { /* Auxiliary data */ 338 char *frag_ptr; 339 struct in_addr frag_addr; 340 struct tcp_dat *tcp; 341 } data; 342}; 343 | 29 30/* 31 Alias_db.c encapsulates all data structures used for storing 32 packet aliasing data. Other parts of the aliasing software 33 access data through functions provided in this file. 34 35 Data storage is based on the notion of a "link", which is 36 established for ICMP echo/reply packets, UDP datagrams and --- 299 unchanged lines hidden (view full) --- 336 337 union { /* Auxiliary data */ 338 char *frag_ptr; 339 struct in_addr frag_addr; 340 struct tcp_dat *tcp; 341 } data; 342}; 343 |
344/* Clean up procedure. */ 345static void finishoff(void); 346 347/* Kernel module definition. */ 348#ifdef _KERNEL 349MALLOC_DEFINE(M_ALIAS, "libalias", "packet aliasing"); 350 351MODULE_VERSION(libalias, 1); 352 353static int 354alias_mod_handler(module_t mod, int type, void *data) 355{ 356 int error; 357 358 switch (type) { 359 case MOD_LOAD: 360 error = 0; 361 break; 362 case MOD_QUIESCE: 363 case MOD_UNLOAD: 364 finishoff(); 365 error = 0; 366 break; 367 default: 368 error = EINVAL; 369 } 370 371 return (error); 372} 373 374static moduledata_t alias_mod = { 375 "alias", alias_mod_handler, NULL 376}; 377 378DECLARE_MODULE(alias, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND); 379#endif 380 |
|
344/* Internal utility routines (used only in alias_db.c) 345 346Lookup table starting points: 347 StartPointIn() -- link table initial search point for 348 incoming packets 349 StartPointOut() -- link table initial search point for 350 outgoing packets 351 --- 1409 unchanged lines hidden (view full) --- 1761 else 1762 lnk->expire_time = TCP_EXPIRE_SINGLEDEAD; 1763 break; 1764 case ALIAS_TCP_STATE_CONNECTED: 1765 if (lnk->data.tcp->state.out == ALIAS_TCP_STATE_CONNECTED) 1766 lnk->expire_time = TCP_EXPIRE_CONNECTED; 1767 break; 1768 default: | 381/* Internal utility routines (used only in alias_db.c) 382 383Lookup table starting points: 384 StartPointIn() -- link table initial search point for 385 incoming packets 386 StartPointOut() -- link table initial search point for 387 outgoing packets 388 --- 1409 unchanged lines hidden (view full) --- 1798 else 1799 lnk->expire_time = TCP_EXPIRE_SINGLEDEAD; 1800 break; 1801 case ALIAS_TCP_STATE_CONNECTED: 1802 if (lnk->data.tcp->state.out == ALIAS_TCP_STATE_CONNECTED) 1803 lnk->expire_time = TCP_EXPIRE_CONNECTED; 1804 break; 1805 default: |
1806#ifdef _KERNEL 1807 panic("libalias:SetStateIn() unknown state"); 1808#else |
|
1769 abort(); | 1809 abort(); |
1810#endif |
|
1770 } 1771 lnk->data.tcp->state.in = state; 1772} 1773 1774 1775void 1776SetStateOut(struct alias_link *lnk, int state) 1777{ --- 5 unchanged lines hidden (view full) --- 1783 else 1784 lnk->expire_time = TCP_EXPIRE_SINGLEDEAD; 1785 break; 1786 case ALIAS_TCP_STATE_CONNECTED: 1787 if (lnk->data.tcp->state.in == ALIAS_TCP_STATE_CONNECTED) 1788 lnk->expire_time = TCP_EXPIRE_CONNECTED; 1789 break; 1790 default: | 1811 } 1812 lnk->data.tcp->state.in = state; 1813} 1814 1815 1816void 1817SetStateOut(struct alias_link *lnk, int state) 1818{ --- 5 unchanged lines hidden (view full) --- 1824 else 1825 lnk->expire_time = TCP_EXPIRE_SINGLEDEAD; 1826 break; 1827 case ALIAS_TCP_STATE_CONNECTED: 1828 if (lnk->data.tcp->state.in == ALIAS_TCP_STATE_CONNECTED) 1829 lnk->expire_time = TCP_EXPIRE_CONNECTED; 1830 break; 1831 default: |
1832#ifdef _KERNEL 1833 panic("libalias:SetStateOut() unknown state"); 1834#else |
|
1791 abort(); | 1835 abort(); |
1836#endif |
|
1792 } 1793 lnk->data.tcp->state.out = state; 1794} 1795 1796 1797int 1798GetStateIn(struct alias_link *lnk) 1799{ --- 305 unchanged lines hidden (view full) --- 2105 2106 (prototype in alias_local.h) 2107*/ 2108 2109void 2110HouseKeeping(struct libalias *la) 2111{ 2112 int i, n, n100; | 1837 } 1838 lnk->data.tcp->state.out = state; 1839} 1840 1841 1842int 1843GetStateIn(struct alias_link *lnk) 1844{ --- 305 unchanged lines hidden (view full) --- 2150 2151 (prototype in alias_local.h) 2152*/ 2153 2154void 2155HouseKeeping(struct libalias *la) 2156{ 2157 int i, n, n100; |
2158#ifndef _KERNEL |
|
2113 struct timeval tv; 2114 struct timezone tz; | 2159 struct timeval tv; 2160 struct timezone tz; |
2161#endif |
|
2115 2116 /* 2117 * Save system time (seconds) in global variable timeStamp for use 2118 * by other functions. This is done so as not to unnecessarily 2119 * waste timeline by making system calls. 2120 */ | 2162 2163 /* 2164 * Save system time (seconds) in global variable timeStamp for use 2165 * by other functions. This is done so as not to unnecessarily 2166 * waste timeline by making system calls. 2167 */ |
2168#ifdef _KERNEL 2169 la->timeStamp = time_second; 2170#else |
|
2121 gettimeofday(&tv, &tz); 2122 la->timeStamp = tv.tv_sec; | 2171 gettimeofday(&tv, &tz); 2172 la->timeStamp = tv.tv_sec; |
2173#endif |
|
2123 2124 /* Compute number of spokes (output table link chains) to cover */ 2125 n100 = LINK_TABLE_OUT_SIZE * 100 + la->houseKeepingResidual; 2126 n100 *= la->timeStamp - la->lastCleanupTime; 2127 n100 /= ALIAS_CLEANUP_INTERVAL_SECS; 2128 2129 n = n100 / 100; 2130 --- 243 unchanged lines hidden (view full) --- 2374 while (!LIST_EMPTY(&instancehead)) 2375 LibAliasUninit(LIST_FIRST(&instancehead)); 2376} 2377 2378struct libalias * 2379LibAliasInit(struct libalias *la) 2380{ 2381 int i; | 2174 2175 /* Compute number of spokes (output table link chains) to cover */ 2176 n100 = LINK_TABLE_OUT_SIZE * 100 + la->houseKeepingResidual; 2177 n100 *= la->timeStamp - la->lastCleanupTime; 2178 n100 /= ALIAS_CLEANUP_INTERVAL_SECS; 2179 2180 n = n100 / 100; 2181 --- 243 unchanged lines hidden (view full) --- 2425 while (!LIST_EMPTY(&instancehead)) 2426 LibAliasUninit(LIST_FIRST(&instancehead)); 2427} 2428 2429struct libalias * 2430LibAliasInit(struct libalias *la) 2431{ 2432 int i; |
2433#ifndef _KERNEL |
|
2382 struct timeval tv; 2383 struct timezone tz; | 2434 struct timeval tv; 2435 struct timezone tz; |
2436#endif |
|
2384 2385 if (la == NULL) { 2386 la = calloc(sizeof *la, 1); 2387 if (la == NULL) 2388 return (la); | 2437 2438 if (la == NULL) { 2439 la = calloc(sizeof *la, 1); 2440 if (la == NULL) 2441 return (la); |
2442 2443#ifndef _KERNEL /* kernel cleans up on module unload */ |
|
2389 if (LIST_EMPTY(&instancehead)) 2390 atexit(finishoff); | 2444 if (LIST_EMPTY(&instancehead)) 2445 atexit(finishoff); |
2446#endif |
|
2391 LIST_INSERT_HEAD(&instancehead, la, instancelist); 2392 | 2447 LIST_INSERT_HEAD(&instancehead, la, instancelist); 2448 |
2449#ifdef _KERNEL 2450 la->timeStamp = time_second; 2451 la->lastCleanupTime = time_second; 2452#else |
|
2393 gettimeofday(&tv, &tz); 2394 la->timeStamp = tv.tv_sec; 2395 la->lastCleanupTime = tv.tv_sec; | 2453 gettimeofday(&tv, &tz); 2454 la->timeStamp = tv.tv_sec; 2455 la->lastCleanupTime = tv.tv_sec; |
2456#endif |
|
2396 la->houseKeepingResidual = 0; 2397 2398 for (i = 0; i < LINK_TABLE_OUT_SIZE; i++) 2399 LIST_INIT(&la->linkTableOut[i]); 2400 for (i = 0; i < LINK_TABLE_IN_SIZE; i++) 2401 LIST_INIT(&la->linkTableIn[i]); 2402 2403 } else { --- 351 unchanged lines hidden --- | 2457 la->houseKeepingResidual = 0; 2458 2459 for (i = 0; i < LINK_TABLE_OUT_SIZE; i++) 2460 LIST_INIT(&la->linkTableOut[i]); 2461 for (i = 0; i < LINK_TABLE_IN_SIZE; i++) 2462 LIST_INIT(&la->linkTableIn[i]); 2463 2464 } else { --- 351 unchanged lines hidden --- |