Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/libalias/alias_db.c
Show First 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | StartPointOut() -- link table initial search point for | ||||
outgoing packets | outgoing packets | ||||
Miscellaneous: | Miscellaneous: | ||||
SeqDiff() -- difference between two TCP sequences | SeqDiff() -- difference between two TCP sequences | ||||
ShowAliasStats() -- send alias statistics to a monitor file | ShowAliasStats() -- send alias statistics to a monitor file | ||||
*/ | */ | ||||
/* Local prototypes */ | /* Local prototypes */ | ||||
static u_int StartPointIn(struct in_addr, u_short, int); | static struct group_in * | ||||
StartPointIn(struct libalias *, struct in_addr, u_short, int, int); | |||||
static u_int | static u_int | ||||
StartPointOut(struct in_addr, struct in_addr, | StartPointOut(struct in_addr, struct in_addr, u_short, u_short, int); | ||||
u_short, u_short, int); | |||||
static int SeqDiff(u_long, u_long); | static int SeqDiff(u_long, u_long); | ||||
#ifndef NO_FW_PUNCH | #ifndef NO_FW_PUNCH | ||||
/* Firewall control */ | /* Firewall control */ | ||||
static void InitPunchFW(struct libalias *); | static void InitPunchFW(struct libalias *); | ||||
static void UninitPunchFW(struct libalias *); | static void UninitPunchFW(struct libalias *); | ||||
static void ClearFWHole(struct alias_link *); | static void ClearFWHole(struct alias_link *); | ||||
#endif | #endif | ||||
/* Log file control */ | /* Log file control */ | ||||
static void ShowAliasStats(struct libalias *); | static void ShowAliasStats(struct libalias *); | ||||
static int InitPacketAliasLog(struct libalias *); | static int InitPacketAliasLog(struct libalias *); | ||||
static void UninitPacketAliasLog(struct libalias *); | static void UninitPacketAliasLog(struct libalias *); | ||||
void SctpShowAliasStats(struct libalias *la); | void SctpShowAliasStats(struct libalias *la); | ||||
static u_int | #define INGUARD \ | ||||
StartPartialIn(u_short alias_port, int link_type) | if (grp->alias_port != alias_port || \ | ||||
{ | grp->link_type != link_type || \ | ||||
return (link_type == LINK_PPTP) ? 0 | grp->alias_addr.s_addr != alias_addr.s_addr) \ | ||||
: (alias_port % LINK_PARTIAL_SIZE); | continue; | ||||
} | |||||
static u_int | static struct group_in * | ||||
StartPointIn(struct in_addr alias_addr, | StartPointIn(struct libalias *la, | ||||
u_short alias_port, | struct in_addr alias_addr, u_short alias_port, int link_type, | ||||
int link_type) | int create) | ||||
{ | { | ||||
u_int n; | u_int n; | ||||
struct group_in *grp, *tmp; | |||||
n = alias_addr.s_addr; | n = alias_addr.s_addr; | ||||
if (link_type != LINK_PPTP) | if (link_type != LINK_PPTP) | ||||
n += alias_port; | n += alias_port; | ||||
n += link_type; | n += link_type; | ||||
return (n % LINK_TABLE_IN_SIZE); | n %= LINK_TABLE_IN_SIZE; | ||||
LIST_FOREACH_SAFE(grp, &la->groupTableIn[n], group_in, tmp) { | |||||
/* Auto cleanup */ | |||||
if (LIST_EMPTY(&grp->full) && LIST_EMPTY(&grp->partial)) { | |||||
LIST_REMOVE(grp, group_in); | |||||
free(grp); | |||||
} else { | |||||
INGUARD; | |||||
return (grp); | |||||
} | } | ||||
} | |||||
if (!create || (grp = malloc(sizeof(*grp))) == NULL) | |||||
return (grp); | |||||
grp->alias_addr = alias_addr; | |||||
grp->alias_port = alias_port; | |||||
grp->link_type = link_type; | |||||
LIST_INIT(&grp->full); | |||||
LIST_INIT(&grp->partial); | |||||
LIST_INSERT_HEAD(&la->groupTableIn[n], grp, group_in); | |||||
return (grp); | |||||
} | |||||
#undef INGUARD | |||||
static u_int | static u_int | ||||
StartPointOut(struct in_addr src_addr, struct in_addr dst_addr, | StartPointOut(struct in_addr src_addr, struct in_addr dst_addr, | ||||
u_short src_port, u_short dst_port, int link_type) | u_short src_port, u_short dst_port, int link_type) | ||||
{ | { | ||||
u_int n; | u_int n; | ||||
n = src_addr.s_addr; | n = src_addr.s_addr; | ||||
▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
CleanupAliasData(struct libalias *la) | CleanupAliasData(struct libalias *la) | ||||
{ | { | ||||
struct alias_link *lnk, *lnk_tmp; | struct alias_link *lnk, *lnk_tmp; | ||||
struct group_in *grp, *grp_tmp; | |||||
u_int i; | |||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
/* permanent entries may stay */ | /* permanent entries may stay */ | ||||
TAILQ_FOREACH_SAFE(lnk, &la->checkExpire, list_expire, lnk_tmp) | TAILQ_FOREACH_SAFE(lnk, &la->checkExpire, list_expire, lnk_tmp) | ||||
DeleteLink(&lnk); | DeleteLink(&lnk); | ||||
for (i = 0; i < LINK_TABLE_IN_SIZE; i++) | |||||
LIST_FOREACH_SAFE(grp, &la->groupTableIn[i], group_in, grp_tmp) | |||||
if (LIST_EMPTY(&grp->full) && LIST_EMPTY(&grp->partial)) { | |||||
LIST_REMOVE(grp, group_in); | |||||
free(grp); | |||||
} | } | ||||
} | |||||
static void | static void | ||||
CleanupLink(struct libalias *la, struct alias_link **lnk) | CleanupLink(struct libalias *la, struct alias_link **lnk) | ||||
{ | { | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
if (lnk == NULL || *lnk == NULL) | if (lnk == NULL || *lnk == NULL) | ||||
return; | return; | ||||
Show All 38 Lines | #endif | ||||
if (lnk->server != NULL) { | if (lnk->server != NULL) { | ||||
struct server *head, *curr, *next; | struct server *head, *curr, *next; | ||||
head = curr = lnk->server; | head = curr = lnk->server; | ||||
do { | do { | ||||
next = curr->next; | next = curr->next; | ||||
free(curr); | free(curr); | ||||
} while ((curr = next) != head); | } while ((curr = next) != head); | ||||
} | } else { | ||||
/* Adjust output table pointers */ | /* Adjust output table pointers */ | ||||
LIST_REMOVE(lnk, list_out); | LIST_REMOVE(lnk, list_out); | ||||
} | |||||
/* Adjust input table pointers */ | /* Adjust input table pointers */ | ||||
LIST_REMOVE(lnk, list_in); | LIST_REMOVE(lnk, list_in); | ||||
/* remove from housekeeping */ | /* remove from housekeeping */ | ||||
TAILQ_REMOVE(&la->checkExpire, lnk, list_expire); | TAILQ_REMOVE(&la->checkExpire, lnk, list_expire); | ||||
#ifndef NO_USE_SOCKETS | #ifndef NO_USE_SOCKETS | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
struct alias_link * | struct alias_link * | ||||
AddLink(struct libalias *la, struct in_addr src_addr, struct in_addr dst_addr, | AddLink(struct libalias *la, struct in_addr src_addr, struct in_addr dst_addr, | ||||
struct in_addr alias_addr, u_short src_port, u_short dst_port, | struct in_addr alias_addr, u_short src_port, u_short dst_port, | ||||
int alias_port_param, int link_type) | int alias_port_param, int link_type) | ||||
{ | { | ||||
u_int start_point; | u_int start_point; | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
struct group_in *grp_in; | |||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
lnk = malloc(sizeof(struct alias_link)); | lnk = malloc(sizeof(struct alias_link)); | ||||
if (lnk != NULL) { | if (lnk != NULL) { | ||||
/* Basic initialization */ | /* Basic initialization */ | ||||
lnk->la = la; | lnk->la = la; | ||||
lnk->src_addr = src_addr; | lnk->src_addr = src_addr; | ||||
lnk->dst_addr = dst_addr; | lnk->dst_addr = dst_addr; | ||||
lnk->alias_addr = alias_addr; | lnk->alias_addr = alias_addr; | ||||
lnk->proxy_addr.s_addr = INADDR_ANY; | lnk->proxy_addr.s_addr = INADDR_ANY; | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | case LINK_FRAGMENT_PTR: | ||||
break; | break; | ||||
case LINK_ADDR: | case LINK_ADDR: | ||||
break; | break; | ||||
default: | default: | ||||
la->protoLinkCount++; | la->protoLinkCount++; | ||||
break; | break; | ||||
} | } | ||||
grp_in = StartPointIn(la, alias_addr, lnk->alias_port, link_type, 1); | |||||
if (grp_in == NULL) { | |||||
free(lnk); | |||||
return (NULL); | |||||
} | |||||
/* Set up pointers for output lookup table */ | /* Set up pointers for output lookup table */ | ||||
start_point = StartPointOut(src_addr, dst_addr, | start_point = StartPointOut(src_addr, dst_addr, | ||||
src_port, dst_port, link_type); | src_port, dst_port, link_type); | ||||
LIST_INSERT_HEAD(&la->linkTableOut[start_point], lnk, list_out); | LIST_INSERT_HEAD(&la->linkTableOut[start_point], lnk, list_out); | ||||
/* Set up pointers for input lookup table */ | /* Set up pointers for input lookup table */ | ||||
if (lnk->flags & LINK_PARTIALLY_SPECIFIED) { | if (lnk->flags & LINK_PARTIALLY_SPECIFIED) { | ||||
start_point = StartPartialIn(lnk->alias_port, link_type); | LIST_INSERT_HEAD(&grp_in->partial, lnk, list_in); | ||||
LIST_INSERT_HEAD(&la->linkPartialIn[start_point], lnk, list_in); | |||||
} else { | } else { | ||||
start_point = StartPointIn(alias_addr, lnk->alias_port, link_type); | LIST_INSERT_HEAD(&grp_in->full, lnk, list_in); | ||||
LIST_INSERT_HEAD(&la->linkTableIn[start_point], lnk, list_in); | |||||
} | } | ||||
/* Include the element into the housekeeping list */ | /* Include the element into the housekeeping list */ | ||||
TAILQ_INSERT_TAIL(&la->checkExpire, lnk, list_expire); | TAILQ_INSERT_TAIL(&la->checkExpire, lnk, list_expire); | ||||
} else { | } else { | ||||
#ifdef LIBALIAS_DEBUG | #ifdef LIBALIAS_DEBUG | ||||
fprintf(stderr, "PacketAlias/AddLink(): "); | fprintf(stderr, "PacketAlias/AddLink(): "); | ||||
fprintf(stderr, "malloc() call failed.\n"); | fprintf(stderr, "malloc() call failed.\n"); | ||||
Show All 38 Lines | |||||
} | } | ||||
#define OUTGUARD \ | #define OUTGUARD \ | ||||
if (lnk->src_port != src_port || \ | if (lnk->src_port != src_port || \ | ||||
lnk->src_addr.s_addr != src_addr.s_addr || \ | lnk->src_addr.s_addr != src_addr.s_addr || \ | ||||
lnk->dst_addr.s_addr != dst_addr.s_addr || \ | lnk->dst_addr.s_addr != dst_addr.s_addr || \ | ||||
lnk->dst_port != dst_port || \ | lnk->dst_port != dst_port || \ | ||||
lnk->link_type != link_type || \ | lnk->link_type != link_type) \ | ||||
lnk->server != NULL) \ | |||||
continue; | continue; | ||||
static struct alias_link * | static struct alias_link * | ||||
_SearchLinkOut(struct libalias *la, struct in_addr src_addr, | _SearchLinkOut(struct libalias *la, struct in_addr src_addr, | ||||
struct in_addr dst_addr, | struct in_addr dst_addr, | ||||
u_short src_port, | u_short src_port, | ||||
u_short dst_port, | u_short dst_port, | ||||
int link_type) { | int link_type) { | ||||
Show All 18 Lines | _FindLinkOut(struct libalias *la, struct in_addr src_addr, | ||||
u_short dst_port, | u_short dst_port, | ||||
int link_type, | int link_type, | ||||
int replace_partial_links) | int replace_partial_links) | ||||
{ | { | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
lnk = _SearchLinkOut(la, src_addr, dst_addr, src_port, dst_port, link_type); | lnk = _SearchLinkOut(la, src_addr, dst_addr, src_port, dst_port, link_type); | ||||
if (lnk != NULL || !replace_partial_links) | |||||
return (lnk); | |||||
/* Search for partially specified links. */ | /* Search for partially specified links. */ | ||||
if (lnk == NULL && replace_partial_links) { | |||||
if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY) { | if (dst_port != 0 && dst_addr.s_addr != INADDR_ANY) { | ||||
lnk = _SearchLinkOut(la, src_addr, dst_addr, src_port, 0, | lnk = _SearchLinkOut(la, src_addr, dst_addr, src_port, 0, | ||||
link_type); | link_type); | ||||
if (lnk == NULL) | if (lnk == NULL) | ||||
lnk = _SearchLinkOut(la, src_addr, ANY_ADDR, src_port, | lnk = _SearchLinkOut(la, src_addr, ANY_ADDR, src_port, | ||||
dst_port, link_type); | dst_port, link_type); | ||||
} | } | ||||
if (lnk == NULL && | if (lnk == NULL && | ||||
(dst_port != 0 || dst_addr.s_addr != INADDR_ANY)) { | (dst_port != 0 || dst_addr.s_addr != INADDR_ANY)) { | ||||
lnk = _SearchLinkOut(la, src_addr, ANY_ADDR, src_port, 0, | lnk = _SearchLinkOut(la, src_addr, ANY_ADDR, src_port, 0, | ||||
link_type); | link_type); | ||||
} | } | ||||
if (lnk != NULL) { | if (lnk != NULL) { | ||||
lnk = ReLink(lnk, | lnk = ReLink(lnk, | ||||
src_addr, dst_addr, lnk->alias_addr, | src_addr, dst_addr, lnk->alias_addr, | ||||
src_port, dst_port, lnk->alias_port, | src_port, dst_port, lnk->alias_port, | ||||
link_type); | link_type); | ||||
} | } | ||||
} | |||||
return (lnk); | return (lnk); | ||||
} | } | ||||
static struct alias_link * | static struct alias_link * | ||||
FindLinkOut(struct libalias *la, struct in_addr src_addr, | FindLinkOut(struct libalias *la, struct in_addr src_addr, | ||||
struct in_addr dst_addr, | struct in_addr dst_addr, | ||||
u_short src_port, | u_short src_port, | ||||
u_short dst_port, | u_short dst_port, | ||||
Show All 26 Lines | |||||
_FindLinkIn(struct libalias *la, struct in_addr dst_addr, | _FindLinkIn(struct libalias *la, struct in_addr dst_addr, | ||||
struct in_addr alias_addr, | struct in_addr alias_addr, | ||||
u_short dst_port, | u_short dst_port, | ||||
u_short alias_port, | u_short alias_port, | ||||
int link_type, | int link_type, | ||||
int replace_partial_links) | int replace_partial_links) | ||||
{ | { | ||||
int flags_in; | int flags_in; | ||||
u_int start_point; | struct group_in *grp; | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
struct alias_link *lnk_fully_specified; | |||||
struct alias_link *lnk_unknown_all; | struct alias_link *lnk_unknown_all; | ||||
struct alias_link *lnk_unknown_dst_addr; | struct alias_link *lnk_unknown_dst_addr; | ||||
struct alias_link *lnk_unknown_dst_port; | struct alias_link *lnk_unknown_dst_port; | ||||
struct in_addr src_addr; | struct in_addr src_addr; | ||||
u_short src_port; | u_short src_port; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
/* Initialize pointers */ | /* Initialize pointers */ | ||||
lnk_fully_specified = NULL; | |||||
lnk_unknown_all = NULL; | lnk_unknown_all = NULL; | ||||
lnk_unknown_dst_addr = NULL; | lnk_unknown_dst_addr = NULL; | ||||
lnk_unknown_dst_port = NULL; | lnk_unknown_dst_port = NULL; | ||||
/* If either the dest addr or port is unknown, the search | /* If either the dest addr or port is unknown, the search | ||||
* loop will have to know about this. */ | * loop will have to know about this. */ | ||||
flags_in = 0; | flags_in = 0; | ||||
if (dst_addr.s_addr == INADDR_ANY) | if (dst_addr.s_addr == INADDR_ANY) | ||||
flags_in |= LINK_UNKNOWN_DEST_ADDR; | flags_in |= LINK_UNKNOWN_DEST_ADDR; | ||||
if (dst_port == 0) | if (dst_port == 0) | ||||
flags_in |= LINK_UNKNOWN_DEST_PORT; | flags_in |= LINK_UNKNOWN_DEST_PORT; | ||||
#define INGUARD \ | |||||
if (lnk->alias_port != alias_port || \ | |||||
lnk->link_type != link_type || \ | |||||
lnk->alias_addr.s_addr != alias_addr.s_addr) \ | |||||
continue; | |||||
/* Search loop */ | /* Search loop */ | ||||
start_point = StartPointIn(alias_addr, alias_port, link_type); | grp = StartPointIn(la, alias_addr, alias_port, link_type, 0); | ||||
if (!(flags_in & LINK_PARTIALLY_SPECIFIED)) { | if (grp == NULL) | ||||
LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) { | return (NULL); | ||||
INGUARD; | |||||
if (lnk->dst_addr.s_addr == dst_addr.s_addr | switch (flags_in) { | ||||
&& lnk->dst_port == dst_port) | case 0: | ||||
LIST_FOREACH(lnk, &grp->full, list_in) { | |||||
if (lnk->dst_addr.s_addr == dst_addr.s_addr && | |||||
lnk->dst_port == dst_port) | |||||
return (UseLink(la, lnk)); | return (UseLink(la, lnk)); | ||||
} | } | ||||
} else { | break; | ||||
LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) { | case LINK_UNKNOWN_DEST_PORT: | ||||
int flags = flags_in & LINK_PARTIALLY_SPECIFIED; | LIST_FOREACH(lnk, &grp->full, list_in) { | ||||
if(lnk->dst_addr.s_addr == dst_addr.s_addr) { | |||||
INGUARD; | |||||
if (flags == LINK_PARTIALLY_SPECIFIED && | |||||
lnk_unknown_all == NULL) | |||||
lnk_unknown_all = lnk; | |||||
if (flags == LINK_UNKNOWN_DEST_ADDR && | |||||
lnk->dst_port == dst_port && | |||||
lnk_unknown_dst_addr == NULL) | |||||
lnk_unknown_dst_addr = lnk; | |||||
if (flags == LINK_UNKNOWN_DEST_PORT && | |||||
lnk->dst_addr.s_addr == dst_addr.s_addr) { | |||||
lnk_unknown_dst_port = lnk; | lnk_unknown_dst_port = lnk; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
break; | |||||
case LINK_UNKNOWN_DEST_ADDR: | |||||
LIST_FOREACH(lnk, &grp->full, list_in) { | |||||
if(lnk->dst_port == dst_port) { | |||||
lnk_unknown_dst_addr = lnk; | |||||
break; | |||||
} | } | ||||
} | |||||
break; | |||||
case LINK_PARTIALLY_SPECIFIED: | |||||
lnk_unknown_all = LIST_FIRST(&grp->full); | |||||
break; | |||||
} | |||||
start_point = StartPartialIn(alias_port, link_type); | if (lnk_unknown_dst_port == NULL) { | ||||
LIST_FOREACH(lnk, &la->linkPartialIn[start_point], list_in) { | LIST_FOREACH(lnk, &grp->partial, list_in) { | ||||
int flags = (flags_in | lnk->flags) & LINK_PARTIALLY_SPECIFIED; | int flags = (flags_in | lnk->flags) & LINK_PARTIALLY_SPECIFIED; | ||||
INGUARD; | |||||
if (flags == LINK_PARTIALLY_SPECIFIED && | if (flags == LINK_PARTIALLY_SPECIFIED && | ||||
lnk_unknown_all == NULL) | lnk_unknown_all == NULL) | ||||
lnk_unknown_all = lnk; | lnk_unknown_all = lnk; | ||||
if (flags == LINK_UNKNOWN_DEST_ADDR && | if (flags == LINK_UNKNOWN_DEST_ADDR && | ||||
lnk->dst_port == dst_port && | lnk->dst_port == dst_port && | ||||
lnk_unknown_dst_addr == NULL) | lnk_unknown_dst_addr == NULL) | ||||
lnk_unknown_dst_addr = lnk; | lnk_unknown_dst_addr = lnk; | ||||
if (flags == LINK_UNKNOWN_DEST_PORT && | if (flags == LINK_UNKNOWN_DEST_PORT && | ||||
lnk->dst_addr.s_addr == dst_addr.s_addr) { | lnk->dst_addr.s_addr == dst_addr.s_addr) { | ||||
lnk_unknown_dst_port = lnk; | lnk_unknown_dst_port = lnk; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
#undef INGUARD | } | ||||
lnk = (lnk_unknown_dst_port != NULL) ? lnk_unknown_dst_port | lnk = (lnk_unknown_dst_port != NULL) ? lnk_unknown_dst_port | ||||
: (lnk_unknown_dst_addr != NULL) ? lnk_unknown_dst_addr | : (lnk_unknown_dst_addr != NULL) ? lnk_unknown_dst_addr | ||||
: lnk_unknown_all; | : lnk_unknown_all; | ||||
if (lnk == NULL || !replace_partial_links) | if (lnk == NULL || !replace_partial_links) | ||||
return (lnk); | return (lnk); | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | FindPptpOutByPeerCallId(struct libalias *la, struct in_addr src_addr, | ||||
return (UseLink(la, lnk)); | return (UseLink(la, lnk)); | ||||
} | } | ||||
struct alias_link * | struct alias_link * | ||||
FindPptpInByCallId(struct libalias *la, struct in_addr dst_addr, | FindPptpInByCallId(struct libalias *la, struct in_addr dst_addr, | ||||
struct in_addr alias_addr, | struct in_addr alias_addr, | ||||
u_int16_t dst_call_id) | u_int16_t dst_call_id) | ||||
{ | { | ||||
struct group_in *grp; | |||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
LIST_FOREACH(lnk, &la->linkPartialIn[0], list_in) | |||||
if (lnk->link_type == LINK_PPTP && | grp = StartPointIn(la, alias_addr, 0, LINK_PPTP, 0); | ||||
lnk->dst_addr.s_addr == dst_addr.s_addr && | if (grp == NULL) | ||||
lnk->alias_addr.s_addr == alias_addr.s_addr && | return (NULL); | ||||
LIST_FOREACH(lnk, &grp->full, list_in) | |||||
if (lnk->dst_addr.s_addr == dst_addr.s_addr && | |||||
lnk->dst_port == dst_call_id) | lnk->dst_port == dst_call_id) | ||||
break; | break; | ||||
return (UseLink(la, lnk)); | return (UseLink(la, lnk)); | ||||
} | } | ||||
struct alias_link * | struct alias_link * | ||||
FindPptpInByPeerCallId(struct libalias *la, struct in_addr dst_addr, | FindPptpInByPeerCallId(struct libalias *la, struct in_addr dst_addr, | ||||
▲ Show 20 Lines • Show All 634 Lines • ▼ Show 20 Lines | LibAliasAddServer(struct libalias *la, struct alias_link *lnk, struct in_addr addr, u_short port) | ||||
if (server != NULL) { | if (server != NULL) { | ||||
struct server *head; | struct server *head; | ||||
server->addr = addr; | server->addr = addr; | ||||
server->port = port; | server->port = port; | ||||
head = lnk->server; | head = lnk->server; | ||||
if (head == NULL) | if (head == NULL) { | ||||
server->next = server; | server->next = server; | ||||
else { | /* not usable for outgoing connections */ | ||||
LIST_REMOVE(lnk, list_out); | |||||
} else { | |||||
struct server *s; | struct server *s; | ||||
for (s = head; s->next != head; s = s->next) | for (s = head; s->next != head; s = s->next) | ||||
; | ; | ||||
s->next = server; | s->next = server; | ||||
server->next = head; | server->next = head; | ||||
} | } | ||||
lnk->server = server; | lnk->server = server; | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | #ifdef _KERNEL | ||||
LibAliasTime = time_uptime; | LibAliasTime = time_uptime; | ||||
#else | #else | ||||
LibAliasTime = time(NULL); | LibAliasTime = time(NULL); | ||||
#endif | #endif | ||||
for (i = 0; i < LINK_TABLE_OUT_SIZE; i++) | for (i = 0; i < LINK_TABLE_OUT_SIZE; i++) | ||||
LIST_INIT(&la->linkTableOut[i]); | LIST_INIT(&la->linkTableOut[i]); | ||||
for (i = 0; i < LINK_TABLE_IN_SIZE; i++) | for (i = 0; i < LINK_TABLE_IN_SIZE; i++) | ||||
LIST_INIT(&la->linkTableIn[i]); | LIST_INIT(&la->groupTableIn[i]); | ||||
for (i = 0; i < LINK_PARTIAL_SIZE; i++) | |||||
LIST_INIT(&la->linkPartialIn[i]); | |||||
TAILQ_INIT(&la->checkExpire); | TAILQ_INIT(&la->checkExpire); | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
AliasSctpInit(la); | AliasSctpInit(la); | ||||
#endif | #endif | ||||
LIBALIAS_LOCK_INIT(la); | LIBALIAS_LOCK_INIT(la); | ||||
LIBALIAS_LOCK(la); | LIBALIAS_LOCK(la); | ||||
} else { | } else { | ||||
LIBALIAS_LOCK(la); | LIBALIAS_LOCK(la); | ||||
▲ Show 20 Lines • Show All 388 Lines • Show Last 20 Lines |