Lines Matching refs:la

99 static int sctp_PktParser(struct libalias *la, int direction, struct ip *pip,
101 static int GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm,
103 static int IsASCONFack(struct libalias *la, struct sctp_nat_msg *sm, int direction);
108 static int IsADDorDEL(struct libalias *la, struct sctp_nat_msg *sm, int direction);
111 static int ProcessSctpMsg(struct libalias *la, int direction, \
114 static int ID_process(struct libalias *la, int direction,\
116 static int INi_process(struct libalias *la, int direction,\
118 static int INa_process(struct libalias *la, int direction,\
120 static int UP_process(struct libalias *la, int direction,\
122 static int CL_process(struct libalias *la, int direction,\
124 static void TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm,\
129 FindSctpLocal(struct libalias *la, struct in_addr l_addr, struct in_addr g_addr, uint32_t l_vtag, uint16_t l_port, uint16_t g_port);
131 FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t g_port, uint16_t l_port, int *partial_match);
133 FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc);
135 FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint16_t g_port, uint16_t l_port);
137 FindSctpGlobalT(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t l_port, uint16_t g_port);
139 static int AddSctpAssocLocal(struct libalias *la, struct sctp_nat_assoc *assoc, struct in_addr g_addr);
140 static int AddSctpAssocGlobal(struct libalias *la, struct sctp_nat_assoc *assoc);
141 static void RmSctpAssoc(struct libalias *la, struct sctp_nat_assoc *assoc);
145 static void sctp_AddTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc);
146 static void sctp_RmTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc);
147 static void sctp_ResetTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc, int newexp);
148 void sctp_CheckTimers(struct libalias *la);
155 static void logTimerQ(struct libalias *la);
156 static void logSctpGlobal(struct libalias *la);
157 static void logSctpLocal(struct libalias *la);
178 * @param la Pointer to the libalias instance
180 void SctpShowAliasStats(struct libalias *la);
303 #define SN_I_T(la) (la->timeStamp + sysctl_init_timer) /**< INIT State expiration time in seconds */
304 #define SN_U_T(la) (la->timeStamp + sysctl_up_timer) /**< UP State expiration time in seconds */
305 #define SN_C_T(la) (la->timeStamp + sysctl_shutdown_timer) /**< CL State expiration time in seconds */
306 #define SN_X_T(la) (la->timeStamp + sysctl_holddown_timer) /**< Wait after a shutdown complete in seconds */
621 * @param la Pointer to the relevant libalias instance
623 void AliasSctpInit(struct libalias *la)
627 la->sctpNatTableSize = sysctl_hashtable_size;
629 SctpAliasLog("Initialising SCTP NAT Instance (hash_table_size:%d)\n", la->sctpNatTableSize));
630 la->sctpTableLocal = sn_calloc(la->sctpNatTableSize, sizeof(struct sctpNatTableL));
631 la->sctpTableGlobal = sn_calloc(la->sctpNatTableSize, sizeof(struct sctpNatTableG));
632 la->sctpNatTimer.TimerQ = sn_calloc(SN_TIMER_QUEUE_SIZE, sizeof(struct sctpTimerQ));
634 for (i = 0; i < la->sctpNatTableSize; i++) {
635 LIST_INIT(&la->sctpTableLocal[i]);
636 LIST_INIT(&la->sctpTableGlobal[i]);
641 LIST_INIT(&la->sctpNatTimer.TimerQ[i]);
643 la->sctpNatTimer.loc_time=time_uptime; /* la->timeStamp is not set yet */
645 la->sctpNatTimer.loc_time=la->timeStamp;
647 la->sctpNatTimer.cur_loc = 0;
648 la->sctpLinkCount = 0;
661 * @param la Pointer to the relevant libalias instance
663 void AliasSctpTerm(struct libalias *la)
668 LIBALIAS_LOCK_ASSERT(la);
672 assoc1 = LIST_FIRST(&la->sctpNatTimer.TimerQ[i]);
681 sn_free(la->sctpTableLocal);
682 sn_free(la->sctpTableGlobal);
683 sn_free(la->sctpNatTimer.TimerQ);
703 * @param la Pointer to the relevant libalias instance
710 SctpAlias(struct libalias *la, struct ip *pip, int direction)
721 sctp_CheckTimers(la); /* Check timers */
724 rtnval = sctp_PktParser(la, direction, pip, &msg, &assoc); //using *char (change to mbuf when get code from paolo)
747 TxAbortErrorM(la, &msg, assoc, SN_REFLECT_ERROR, direction); /*NB assoc=NULL */
762 rtnval = ProcessSctpMsg(la, direction, &msg, assoc);
766 logSctpLocal(la);
767 logSctpGlobal(la);
769 SN_LOG(SN_LOG_DEBUG, logTimerQ(la));
796 TxAbortErrorM(la, &msg, assoc, rtnval, direction);
808 sctp_RmTimeOut(la, assoc);
809 RmSctpAssoc(la, assoc);
811 LIBALIAS_LOCK_ASSERT(la);
857 * @param la Pointer to the relevant libalias instance
901 TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int sndrply, int direction)
1008 * @param la Pointer to the relevant libalias instance
1017 sctp_PktParser(struct libalias *la, int direction, struct ip *pip,
1074 *passoc = FindSctpGlobalT(la, pip->ip_src, sctp_hdr->v_tag, sctp_hdr->dest_port, sctp_hdr->src_port);
1076 *passoc = FindSctpLocalT(la, pip->ip_dst, sctp_hdr->v_tag, sctp_hdr->dest_port, sctp_hdr->src_port);
1080 *passoc = FindSctpGlobal(la, pip->ip_src, sctp_hdr->v_tag, sctp_hdr->src_port, sctp_hdr->dest_port, &partial_match);
1082 *passoc = FindSctpLocal(la, pip->ip_src, pip->ip_dst, sctp_hdr->v_tag, sctp_hdr->src_port, sctp_hdr->dest_port);
1148 *passoc = FindSctpGlobal(la, ipv4addr, sctp_hdr->v_tag, sctp_hdr->src_port, sctp_hdr->dest_port, &partial_match);
1232 * @param la Pointer to the relevant libalias instance
1241 GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, uint32_t *g_vtag, int direction)
1568 * @param la Pointer to the relevant libalias instance
1575 IsASCONFack(struct libalias *la, struct sctp_nat_msg *sm, int direction)
1621 * @param la Pointer to the relevant libalias instance
1628 IsADDorDEL(struct libalias *la, struct sctp_nat_msg *sm, int direction)
1687 * @param la Pointer to the relevant libalias instance
1695 ProcessSctpMsg(struct libalias *la, int direction, struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc)
1701 rtnval = ID_process(la, direction, assoc, sm);
1707 return(INi_process(la, direction, assoc, sm));
1709 return(INa_process(la, direction, assoc, sm));
1711 return(UP_process(la, direction, assoc, sm));
1713 return(CL_process(la, direction, assoc, sm));
1725 * @param la Pointer to the relevant libalias instance
1733 ID_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1740 if (!GetAsconfVtags(la, sm, &(assoc->l_vtag), &(assoc->g_vtag), direction))
1748 assoc->a_addr = FindAliasAddress(la, assoc->l_addr);
1753 if (AddSctpAssocGlobal(la, assoc)) /* DB clash *///**** need to add dst address
1756 if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_dst)) /* DB clash */
1762 assoc->l_addr = FindSctpRedirectAddress(la, sm);
1768 if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_src)) /* DB clash */
1771 if (AddSctpAssocGlobal(la, assoc)) /* DB clash */ //**** need to add src address
1778 assoc->exp = SN_I_T(la);
1779 sctp_AddTimeOut(la,assoc);
1793 * @param la Pointer to the relevant libalias instance
1801 INi_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1805 sctp_ResetTimeOut(la, assoc, SN_I_T(la));
1813 if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_src)) { /* DB clash */
1821 if (AddSctpAssocGlobal(la, assoc)) { /* DB clash */
1828 sctp_ResetTimeOut(la,assoc, SN_U_T(la));
1845 * @param la Pointer to the relevant libalias instance
1853 INa_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1857 sctp_ResetTimeOut(la,assoc, SN_I_T(la));
1869 if (IsASCONFack(la,sm,direction)) {
1872 sctp_ResetTimeOut(la,assoc, SN_U_T(la));
1893 * @param la Pointer to the relevant libalias instance
1901 UP_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1906 sctp_ResetTimeOut(la,assoc, SN_C_T(la));
1913 switch(IsADDorDEL(la,sm,direction)) {
1922 sctp_ResetTimeOut(la,assoc, SN_U_T(la));
1933 * immediately, but leave it up until SN_X_T(la). Only SHUT-COMP, SHUT-ACK, and
1936 * @param la Pointer to the relevant libalias instance
1944 CL_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1950 sctp_ResetTimeOut(la, assoc, SN_X_T(la));/* allow to stay open for Tbit packets*/
1956 sctp_ResetTimeOut(la, assoc, SN_C_T(la));
1982 * @param la Pointer to the relevant libalias instance
1992 FindSctpLocal(struct libalias *la, struct in_addr l_addr, struct in_addr g_addr, uint32_t l_vtag, uint16_t l_port, uint16_t g_port)
1999 i = SN_TABLE_HASH(l_vtag, l_port, la->sctpNatTableSize);
2000 LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) {
2023 * @param la Pointer to the relevant libalias instance
2029 FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc)
2037 i = SN_TABLE_HASH(Cassoc->g_vtag, Cassoc->g_port, la->sctpNatTableSize);
2038 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2067 * @param la Pointer to the relevant libalias instance
2076 FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t g_port, uint16_t l_port, int *partial_match)
2084 i = SN_TABLE_HASH(g_vtag, g_port, la->sctpNatTableSize);
2085 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2108 * @param la Pointer to the relevant libalias instance
2117 FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint16_t g_port, uint16_t l_port)
2125 i = SN_TABLE_HASH(l_vtag, g_port, la->sctpNatTableSize);
2126 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2150 * @param la Pointer to the relevant libalias instance
2159 FindSctpGlobalT(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t l_port, uint16_t g_port)
2166 i = SN_TABLE_HASH(g_vtag, l_port, la->sctpNatTableSize);
2167 LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) {
2193 * @param la Pointer to the relevant libalias instance
2200 AddSctpAssocLocal(struct libalias *la, struct sctp_nat_assoc *assoc, struct in_addr g_addr)
2204 LIBALIAS_LOCK_ASSERT(la);
2205 found = FindSctpLocal(la, assoc->l_addr, g_addr, assoc->l_vtag, assoc->l_port, assoc->g_port);
2217 RmSctpAssoc(la, found);
2218 sctp_RmTimeOut(la, found);
2225 LIST_INSERT_HEAD(&la->sctpTableLocal[SN_TABLE_HASH(assoc->l_vtag, assoc->l_port, la->sctpNatTableSize)],
2228 la->sctpLinkCount++; //increment link count
2232 if (la->packetAliasMode & PKT_ALIAS_LOG)
2233 SctpShowAliasStats(la);
2251 * @param la Pointer to the relevant libalias instance
2257 AddSctpAssocGlobal(struct libalias *la, struct sctp_nat_assoc *assoc)
2261 LIBALIAS_LOCK_ASSERT(la);
2262 found = FindSctpGlobalClash(la, assoc);
2266 RmSctpAssoc(la, found);
2267 sctp_RmTimeOut(la, found);
2274 LIST_INSERT_HEAD(&la->sctpTableGlobal[SN_TABLE_HASH(assoc->g_vtag, assoc->g_port, la->sctpNatTableSize)],
2277 la->sctpLinkCount++; //increment link count
2281 if (la->packetAliasMode & PKT_ALIAS_LOG)
2282 SctpShowAliasStats(la);
2301 * @param la Pointer to the relevant libalias instance
2305 RmSctpAssoc(struct libalias *la, struct sctp_nat_assoc *assoc)
2318 LIBALIAS_LOCK_ASSERT(la);
2321 la->sctpLinkCount--; //decrement link count
2327 la->sctpLinkCount--; //decrement link count
2332 if (la->packetAliasMode & PKT_ALIAS_LOG)
2333 SctpShowAliasStats(la);
2380 * @param la
2384 sctp_AddTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc)
2387 LIBALIAS_LOCK_ASSERT(la);
2388 add_loc = assoc->exp - la->sctpNatTimer.loc_time + la->sctpNatTimer.cur_loc;
2391 LIST_INSERT_HEAD(&la->sctpNatTimer.TimerQ[add_loc], assoc, timer_Q);
2401 * @param la Pointer to the relevant libalias instance
2405 sctp_RmTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc)
2407 LIBALIAS_LOCK_ASSERT(la);
2419 * @param la Pointer to the relevant libalias instance
2424 sctp_ResetTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc, int newexp)
2427 sctp_RmTimeOut(la, assoc);
2429 sctp_AddTimeOut(la, assoc);
2449 * @param la Pointer to the relevant libalias instance
2452 sctp_CheckTimers(struct libalias *la)
2456 LIBALIAS_LOCK_ASSERT(la);
2457 while(la->timeStamp >= la->sctpNatTimer.loc_time) {
2458 while (!LIST_EMPTY(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc])) {
2459 assoc = LIST_FIRST(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc]);
2460 //SLIST_REMOVE_HEAD(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc], timer_Q);
2462 if (la->timeStamp >= assoc->exp) { /* state expired */
2465 RmSctpAssoc(la, assoc);
2469 sctp_AddTimeOut(la, assoc);
2473 ++la->sctpNatTimer.loc_time;
2474 if (++la->sctpNatTimer.cur_loc >= SN_TIMER_QUEUE_SIZE)
2475 la->sctpNatTimer.cur_loc = 0;
2600 SctpAliasLog("%sAssoc: %s exp=%u la=%s lv=%u lp=%u gv=%u gp=%u tbl=%d\n",
2613 * @param la Pointer to the relevant libalias instance
2615 static void logSctpGlobal(struct libalias *la)
2621 for (i=0; i < la->sctpNatTableSize; i++) {
2622 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2631 * @param la Pointer to the relevant libalias instance
2633 static void logSctpLocal(struct libalias *la)
2639 for (i=0; i < la->sctpNatTableSize; i++) {
2640 LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) {
2649 * @param la Pointer to the relevant libalias instance
2651 static void logTimerQ(struct libalias *la)
2659 LIST_FOREACH(assoc, &la->sctpNatTimer.TimerQ[i], timer_Q) {
2661 //SctpAliasLog(la->logDesc," l=%d ",i);