Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/libalias/alias_db.c
Show First 20 Lines • Show All 529 Lines • ▼ Show 20 Lines | |||||
/* Local prototypes */ | /* Local prototypes */ | ||||
static int GetNewPort(struct libalias *, struct alias_link *, int); | static int GetNewPort(struct libalias *, struct alias_link *, int); | ||||
#ifndef NO_USE_SOCKETS | #ifndef NO_USE_SOCKETS | ||||
static u_short GetSocket(struct libalias *, u_short, int *, int); | static u_short GetSocket(struct libalias *, u_short, int *, int); | ||||
#endif | #endif | ||||
static void CleanupAliasData(struct libalias *); | static void CleanupAliasData(struct libalias *); | ||||
static void CleanupLink(struct libalias *, struct alias_link **); | static void CleanupLink(struct libalias *, struct alias_link **); | ||||
static void DeleteLink(struct alias_link **); | static void DeleteLink(struct alias_link **); | ||||
static struct alias_link * | |||||
UseLink(struct libalias *, struct alias_link *); | |||||
static struct alias_link * | static struct alias_link * | ||||
ReLink(struct alias_link *, | ReLink(struct alias_link *, | ||||
struct in_addr, struct in_addr, struct in_addr, | struct in_addr, struct in_addr, struct in_addr, | ||||
u_short, u_short, int, int); | u_short, u_short, int, int); | ||||
static struct alias_link * | static struct alias_link * | ||||
FindLinkOut(struct libalias *, struct in_addr, struct in_addr, u_short, u_short, int, int); | FindLinkOut(struct libalias *, struct in_addr, struct in_addr, u_short, u_short, int, int); | ||||
▲ Show 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | if ((*lnk) == NULL) | ||||
return; | return; | ||||
} | } | ||||
/* move to end, swap may fail on a single entry list */ | /* move to end, swap may fail on a single entry list */ | ||||
TAILQ_REMOVE(&la->checkExpire, (*lnk), list_expire); | TAILQ_REMOVE(&la->checkExpire, (*lnk), list_expire); | ||||
TAILQ_INSERT_TAIL(&la->checkExpire, (*lnk), list_expire); | TAILQ_INSERT_TAIL(&la->checkExpire, (*lnk), list_expire); | ||||
} | } | ||||
static struct alias_link * | |||||
UseLink(struct libalias *la, struct alias_link *lnk) | |||||
{ | |||||
CleanupLink(la, &lnk); | |||||
if (lnk != NULL) | |||||
lnk->timestamp = LibAliasTime; | |||||
return (lnk); | |||||
} | |||||
static void | static void | ||||
DeleteLink(struct alias_link **plnk) | DeleteLink(struct alias_link **plnk) | ||||
{ | { | ||||
struct alias_link *lnk = *plnk; | struct alias_link *lnk = *plnk; | ||||
struct libalias *la = lnk->la; | struct libalias *la = lnk->la; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
/* Don't do anything if the link is marked permanent */ | /* Don't do anything if the link is marked permanent */ | ||||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | _SearchLinkOut(struct libalias *la, struct in_addr src_addr, | ||||
u_short dst_port, | u_short dst_port, | ||||
int link_type) { | int link_type) { | ||||
u_int i; | u_int i; | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
i = StartPointOut(src_addr, dst_addr, src_port, dst_port, link_type); | i = StartPointOut(src_addr, dst_addr, src_port, dst_port, link_type); | ||||
LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) { | LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) { | ||||
OUTGUARD; | OUTGUARD; | ||||
CleanupLink(la, &lnk); | return (UseLink(la, lnk)); | ||||
if (lnk != NULL) | |||||
lnk->timestamp = LibAliasTime; | |||||
return (lnk); | |||||
} | } | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
#undef OUTGUARD | #undef OUTGUARD | ||||
static struct alias_link * | static struct alias_link * | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | #define INGUARD \ | ||||
continue; | continue; | ||||
/* Search loop */ | /* Search loop */ | ||||
start_point = StartPointIn(alias_addr, alias_port, link_type); | start_point = StartPointIn(alias_addr, alias_port, link_type); | ||||
if (!(flags_in & LINK_PARTIALLY_SPECIFIED)) { | if (!(flags_in & LINK_PARTIALLY_SPECIFIED)) { | ||||
LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) { | LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) { | ||||
INGUARD; | INGUARD; | ||||
if (lnk->dst_addr.s_addr == dst_addr.s_addr | if (lnk->dst_addr.s_addr == dst_addr.s_addr | ||||
&& lnk->dst_port == dst_port) { | && lnk->dst_port == dst_port) | ||||
CleanupLink(la, &lnk); | return (UseLink(la, lnk)); | ||||
if (lnk != NULL) | |||||
lnk->timestamp = LibAliasTime; | |||||
return (lnk); | |||||
} | } | ||||
} | |||||
} else { | } else { | ||||
LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) { | LIST_FOREACH(lnk, &la->linkTableIn[start_point], list_in) { | ||||
int flags = flags_in & LINK_PARTIALLY_SPECIFIED; | int flags = flags_in & LINK_PARTIALLY_SPECIFIED; | ||||
INGUARD; | 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; | ||||
▲ Show 20 Lines • Show All 350 Lines • ▼ Show 20 Lines | FindPptpOutByCallId(struct libalias *la, struct in_addr src_addr, | ||||
i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP); | i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP); | ||||
LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) | LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) | ||||
if (lnk->link_type == LINK_PPTP && | if (lnk->link_type == LINK_PPTP && | ||||
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->src_port == src_call_id) | lnk->src_port == src_call_id) | ||||
break; | break; | ||||
CleanupLink(la, &lnk); | return (UseLink(la, lnk)); | ||||
return (lnk); | |||||
} | } | ||||
struct alias_link * | struct alias_link * | ||||
FindPptpOutByPeerCallId(struct libalias *la, struct in_addr src_addr, | FindPptpOutByPeerCallId(struct libalias *la, struct in_addr src_addr, | ||||
struct in_addr dst_addr, | struct in_addr dst_addr, | ||||
u_int16_t dst_call_id) | u_int16_t dst_call_id) | ||||
{ | { | ||||
u_int i; | u_int i; | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP); | i = StartPointOut(src_addr, dst_addr, 0, 0, LINK_PPTP); | ||||
LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) | LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) | ||||
if (lnk->link_type == LINK_PPTP && | if (lnk->link_type == LINK_PPTP && | ||||
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_call_id) | lnk->dst_port == dst_call_id) | ||||
break; | break; | ||||
CleanupLink(la, &lnk); | return (UseLink(la, lnk)); | ||||
return (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 alias_link *lnk; | struct alias_link *lnk; | ||||
LIBALIAS_LOCK_ASSERT(la); | LIBALIAS_LOCK_ASSERT(la); | ||||
LIST_FOREACH(lnk, &la->linkPartialIn[0], list_in) | LIST_FOREACH(lnk, &la->linkPartialIn[0], list_in) | ||||
if (lnk->link_type == LINK_PPTP && | if (lnk->link_type == LINK_PPTP && | ||||
lnk->dst_addr.s_addr == dst_addr.s_addr && | lnk->dst_addr.s_addr == dst_addr.s_addr && | ||||
lnk->alias_addr.s_addr == alias_addr.s_addr && | lnk->alias_addr.s_addr == alias_addr.s_addr && | ||||
lnk->dst_port == dst_call_id) | lnk->dst_port == dst_call_id) | ||||
break; | break; | ||||
CleanupLink(la, &lnk); | return (UseLink(la, lnk)); | ||||
return (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, | ||||
struct in_addr alias_addr, | struct in_addr alias_addr, | ||||
u_int16_t alias_call_id) | u_int16_t alias_call_id) | ||||
{ | { | ||||
struct alias_link *lnk; | struct alias_link *lnk; | ||||
▲ Show 20 Lines • Show All 1,209 Lines • Show Last 20 Lines |