Lines Matching defs:assoc

105 static void AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction);
106 static int Add_Global_Address_to_List(struct sctp_nat_assoc *assoc, struct sctp_GlobalAddress *G_addr);
107 static void RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction);
112 struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc);
115 struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm);
117 struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm);
119 struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm);
121 struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm);
123 struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm);
125 struct sctp_nat_assoc *assoc, int sndrply, int direction);
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);
142 static void freeGlobalAddressList(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);
154 static void logsctpassoc(struct sctp_nat_assoc *assoc, char *s);
224 #define SN_PARSE_ERROR_AS_MALLOC 2 /**< Packet parsing error - assoc malloc */
280 #define SN_LOCAL_TBL 0x01 /**< assoc in local table */
281 #define SN_GLOBAL_TBL 0x02 /**< assoc in global table */
282 #define SN_BOTH_TBL 0x03 /**< assoc in both tables */
283 #define SN_WAIT_TOLOCAL 0x10 /**< assoc waiting for TOLOCAL asconf ACK*/
284 #define SN_WAIT_TOGLOBAL 0x20 /**< assoc waiting for TOLOCAL asconf ACK*/
285 #define SN_NULL_TBL 0x00 /**< assoc in No table */
289 #define SN_ADD_CLASH 1 /**< Clash when trying to add the assoc. info to the table */
713 struct sctp_nat_assoc *assoc = NULL;
723 rtnval = sctp_PktParser(la, direction, pip, &msg, &assoc); //using *char (change to mbuf when get code from paolo)
746 TxAbortErrorM(la, &msg, assoc, SN_REFLECT_ERROR, direction); /*NB assoc=NULL */
756 logsctpassoc(assoc, "*");
761 rtnval = ProcessSctpMsg(la, direction, &msg, assoc);
764 logsctpassoc(assoc, "-");
775 &(assoc->l_addr), &(msg.ip_hdr->ip_dst), 2);
776 msg.ip_hdr->ip_dst = assoc->l_addr; /* change dst address to local address*/
780 &(assoc->a_addr), &(msg.ip_hdr->ip_src), 2);
781 msg.ip_hdr->ip_src = assoc->a_addr; /* change src to alias addr*/
795 TxAbortErrorM(la, &msg, assoc, rtnval, direction);
800 assoc->state=SN_RM;/* Mark for removal*/
805 if (assoc->state == SN_RM) {
806 if (assoc->TableRegister) {
807 sctp_RmTimeOut(la, assoc);
808 RmSctpAssoc(la, assoc);
811 freeGlobalAddressList(assoc);
812 sn_free(assoc);
858 * @param assoc Pointer to current association details
900 TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int sndrply, int direction)
951 sctp_hdr->v_tag = (direction == SN_TO_LOCAL) ? assoc->g_vtag : assoc->l_vtag ;
963 ip->ip_src = (direction == SN_TO_LOCAL) ? sm->ip_hdr->ip_src : assoc->a_addr;
964 ip->ip_dst = (direction == SN_TO_LOCAL) ? assoc->l_addr : sm->ip_hdr->ip_dst;
1020 //sctp_PktParser(int direction, struct mbuf *ipak, int ip_hdr_len,struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc)
1304 * @param assoc Pointer to the association this SCTP Message belongs to
1309 AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction)
1347 if ((assoc->state == SN_ID) && ((sm->msg == SN_SCTP_INIT) || (bytes_left < SN_MIN_PARAM_SIZE))) {/* add pkt address */
1353 assoc->num_Gaddr = 0; /* don't track any more for this assoc*/
1358 if (!Add_Global_Address_to_List(assoc, G_Addr))
1361 sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction));
1366 if (assoc->num_Gaddr >= sysctl_track_global_addresses) {
1385 assoc->num_Gaddr = 0; /* don't track any more for this assoc*/
1393 if (!Add_Global_Address_to_List(assoc, G_Addr))
1396 sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction));
1400 if (!Add_Global_Address_to_List(assoc, G_Addr))
1403 sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction));
1423 sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction));
1435 * @param assoc Pointer to the association this SCTP Message belongs to
1440 static int Add_Global_Address_to_List(struct sctp_nat_assoc *assoc, struct sctp_GlobalAddress *G_addr)
1443 first_G_Addr = LIST_FIRST(&(assoc->Gaddr));
1445 LIST_INSERT_HEAD(&(assoc->Gaddr), G_addr, list_Gaddr); /* add new address to beginning of list*/
1447 LIST_FOREACH(iter_G_Addr, &(assoc->Gaddr), list_Gaddr) {
1453 assoc->num_Gaddr++;
1466 * @param assoc Pointer to the association this SCTP Message belongs to
1471 RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction)
1503 LIST_FOREACH_SAFE(G_Addr, &(assoc->Gaddr), list_Gaddr, G_Addr_tmp) {
1505 if (assoc->num_Gaddr > 1) { /* only delete if more than one */
1508 assoc->num_Gaddr--;
1512 sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction));
1518 LIST_FOREACH_SAFE(G_Addr, &(assoc->Gaddr), list_Gaddr, G_Addr_tmp) {
1520 if (assoc->num_Gaddr > 1) { /* only delete if more than one */
1523 assoc->num_Gaddr--;
1528 sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction));
1692 * @param assoc Pointer to the association this SCTP Message belongs to
1697 ProcessSctpMsg(struct libalias *la, int direction, struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc)
1701 switch (assoc->state) {
1703 rtnval = ID_process(la, direction, assoc, sm);
1705 assoc->state = SN_RM;/* Mark for removal*/
1709 return (INi_process(la, direction, assoc, sm));
1711 return (INa_process(la, direction, assoc, sm));
1713 return (UP_process(la, direction, assoc, sm));
1715 return (CL_process(la, direction, assoc, sm));
1730 * @param assoc Pointer to the association this SCTP Message belongs to
1735 ID_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1742 if (!GetAsconfVtags(la, sm, &(assoc->l_vtag), &(assoc->g_vtag), direction))
1747 AddGlobalIPAddresses(sm, assoc, direction);
1750 assoc->l_addr = sm->ip_hdr->ip_src;
1751 assoc->a_addr = FindAliasAddress(la, assoc->l_addr);
1752 assoc->l_port = sm->sctp_hdr->src_port;
1753 assoc->g_port = sm->sctp_hdr->dest_port;
1755 assoc->g_vtag = sm->sctpchnk.Init->initiate_tag;
1756 if (AddSctpAssocGlobal(la, assoc)) /* DB clash *///**** need to add dst address
1759 if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_dst)) /* DB clash */
1761 assoc->TableRegister |= SN_WAIT_TOLOCAL; /* wait for tolocal ack */
1765 assoc->l_addr = FindSctpRedirectAddress(la, sm);
1766 assoc->a_addr = sm->ip_hdr->ip_dst;
1767 assoc->l_port = sm->sctp_hdr->dest_port;
1768 assoc->g_port = sm->sctp_hdr->src_port;
1770 assoc->l_vtag = sm->sctpchnk.Init->initiate_tag;
1771 if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_src)) /* DB clash */
1774 if (AddSctpAssocGlobal(la, assoc)) /* DB clash */ //**** need to add src address
1776 assoc->TableRegister |= SN_WAIT_TOGLOBAL; /* wait for toglobal ack */
1780 assoc->state = (sm->msg == SN_SCTP_INIT) ? SN_INi : SN_INa;
1781 assoc->exp = SN_I_T(la);
1782 sctp_AddTimeOut(la,assoc);
1799 * @param assoc Pointer to the association this SCTP Message belongs to
1804 INi_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1808 sctp_ResetTimeOut(la, assoc, SN_I_T(la));
1813 if (assoc->num_Gaddr) /*If tracking global addresses for this association */
1814 AddGlobalIPAddresses(sm, assoc, direction);
1815 assoc->l_vtag = sm->sctpchnk.Init->initiate_tag;
1816 if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_src)) { /* DB clash */
1817 assoc->state = SN_RM;/* Mark for removal*/
1822 assoc->l_addr = sm->ip_hdr->ip_src; // Only if not set in Init! *
1823 assoc->g_vtag = sm->sctpchnk.Init->initiate_tag;
1824 if (AddSctpAssocGlobal(la, assoc)) { /* DB clash */
1825 assoc->state = SN_RM;/* Mark for removal*/
1830 assoc->state = SN_UP;/* association established for NAT */
1831 sctp_ResetTimeOut(la,assoc, SN_U_T(la));
1834 assoc->state = SN_RM;/* Mark for removal*/
1851 * @param assoc Pointer to the association this SCTP Message belongs to
1856 INa_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1860 sctp_ResetTimeOut(la,assoc, SN_I_T(la));
1865 if (!(assoc->TableRegister & SN_WAIT_TOLOCAL)) /* wrong direction */
1869 if (!(assoc->TableRegister & SN_WAIT_TOGLOBAL)) /* wrong direction */
1873 assoc->TableRegister &= SN_BOTH_TBL; /* remove wait flags */
1874 assoc->state = SN_UP; /* association established for NAT */
1875 sctp_ResetTimeOut(la,assoc, SN_U_T(la));
1878 assoc->state = SN_RM;/* Mark for removal*/
1882 assoc->state = SN_RM;/* Mark for removal*/
1899 * @param assoc Pointer to the association this SCTP Message belongs to
1904 UP_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1908 assoc->state = SN_CL;
1909 sctp_ResetTimeOut(la,assoc, SN_C_T(la));
1912 assoc->state = SN_RM;/* Mark for removal*/
1915 if ((direction == SN_TO_LOCAL) && assoc->num_Gaddr) /*If tracking global addresses for this association & from global side */
1918 AddGlobalIPAddresses(sm, assoc, direction);
1921 RmGlobalIPAddresses(sm, assoc, direction);
1925 sctp_ResetTimeOut(la,assoc, SN_U_T(la));
1942 * @param assoc Pointer to the association this SCTP Message belongs to
1947 CL_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm)
1951 assoc->state = SN_CL; /* Stay in Close state until timeout */
1953 sctp_ResetTimeOut(la, assoc, SN_X_T(la));/* allow to stay open for Tbit packets*/
1955 assoc->state = SN_RM;/* Mark for removal*/
1958 assoc->state = SN_CL; /* Stay in Close state until timeout */
1959 sctp_ResetTimeOut(la, assoc, SN_C_T(la));
1962 assoc->state = SN_RM;/* Mark for removal*/
1998 struct sctp_nat_assoc *assoc = NULL;
2003 LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) {
2004 if ((assoc->l_vtag == l_vtag) && (assoc->l_port == l_port) && (assoc->g_port == g_port)\
2005 && (assoc->l_addr.s_addr == l_addr.s_addr)) {
2006 if (assoc->num_Gaddr) {
2007 LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) {
2009 return (assoc);
2012 return (assoc);
2035 struct sctp_nat_assoc *assoc = NULL;
2041 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2042 if ((assoc->g_vtag == Cassoc->g_vtag) && (assoc->g_port == Cassoc->g_port) && (assoc->l_port == Cassoc->l_port)) {
2043 if (assoc->num_Gaddr) {
2045 LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) {
2047 return (assoc);
2051 return (assoc);
2082 struct sctp_nat_assoc *assoc = NULL;
2088 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2089 if ((assoc->g_vtag == g_vtag) && (assoc->g_port == g_port) && (assoc->l_port == l_port)) {
2091 if (assoc->num_Gaddr) {
2092 LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) {
2094 return (assoc);
2097 return (assoc);
2123 struct sctp_nat_assoc *assoc = NULL, *lastmatch = NULL;
2129 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2130 if ((assoc->g_vtag == l_vtag) && (assoc->g_port == g_port) && (assoc->l_port == l_port)) {
2131 if (assoc->num_Gaddr) {
2132 LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) {
2134 return (assoc); /* full match */
2138 lastmatch = assoc;
2165 struct sctp_nat_assoc *assoc = NULL;
2170 LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) {
2171 if ((assoc->l_vtag == g_vtag) && (assoc->l_port == l_port) && (assoc->g_port == g_port)) {
2172 if (assoc->num_Gaddr) {
2173 LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) {
2175 return (assoc);
2178 return (assoc);
2197 * @param assoc pointer to sctp association
2203 AddSctpAssocLocal(struct libalias *la, struct sctp_nat_assoc *assoc, struct in_addr g_addr)
2208 found = FindSctpLocal(la, assoc->l_addr, g_addr, assoc->l_vtag, assoc->l_port, assoc->g_port);
2219 if ((found->TableRegister == SN_LOCAL_TBL) && (found->g_port == assoc->g_port)) { /* resent message */
2228 LIST_INSERT_HEAD(&la->sctpTableLocal[SN_TABLE_HASH(assoc->l_vtag, assoc->l_port, la->sctpNatTableSize)],
2229 assoc, list_L);
2230 assoc->TableRegister |= SN_LOCAL_TBL;
2233 if (assoc->TableRegister == SN_BOTH_TBL) {
2238 SN_LOG(SN_LOG_INFO, logsctpassoc(assoc, "^"));
2255 * @param assoc pointer to sctp association
2260 AddSctpAssocGlobal(struct libalias *la, struct sctp_nat_assoc *assoc)
2265 found = FindSctpGlobalClash(la, assoc);
2268 (found->l_addr.s_addr == assoc->l_addr.s_addr) && (found->l_port == assoc->l_port)) { /* resent message */
2277 LIST_INSERT_HEAD(&la->sctpTableGlobal[SN_TABLE_HASH(assoc->g_vtag, assoc->g_port, la->sctpNatTableSize)],
2278 assoc, list_G);
2279 assoc->TableRegister |= SN_GLOBAL_TBL;
2282 if (assoc->TableRegister == SN_BOTH_TBL) {
2287 SN_LOG(SN_LOG_INFO, logsctpassoc(assoc, "^"));
2305 * @param assoc pointer to sctp association
2308 RmSctpAssoc(struct libalias *la, struct sctp_nat_assoc *assoc)
2311 if (assoc == NULL) {
2318 if (assoc->TableRegister == SN_BOTH_TBL) {
2319 SN_LOG(SN_LOG_INFO, logsctpassoc(assoc, "$"));
2322 if (assoc->TableRegister & SN_LOCAL_TBL) {
2323 assoc->TableRegister ^= SN_LOCAL_TBL;
2325 LIST_REMOVE(assoc, list_L);
2328 if (assoc->TableRegister & SN_GLOBAL_TBL) {
2329 assoc->TableRegister ^= SN_GLOBAL_TBL;
2331 LIST_REMOVE(assoc, list_G);
2333 // sn_free(assoc); //Don't remove now, remove if needed later
2346 * @param assoc
2348 static void freeGlobalAddressList(struct sctp_nat_assoc *assoc)
2352 gaddr1 = LIST_FIRST(&(assoc->Gaddr));
2384 * @param assoc
2387 sctp_AddTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc)
2391 add_loc = assoc->exp - la->sctpNatTimer.loc_time + la->sctpNatTimer.cur_loc;
2394 LIST_INSERT_HEAD(&la->sctpNatTimer.TimerQ[add_loc], assoc, timer_Q);
2395 assoc->exp_loc = add_loc;
2405 * @param assoc pointer to sctp association
2408 sctp_RmTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc)
2411 LIST_REMOVE(assoc, timer_Q);/* Note this is O(1) */
2423 * @param assoc pointer to sctp association
2427 sctp_ResetTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc, int newexp)
2429 if (newexp < assoc->exp) {
2430 sctp_RmTimeOut(la, assoc);
2431 assoc->exp = newexp;
2432 sctp_AddTimeOut(la, assoc);
2434 assoc->exp = newexp;
2457 struct sctp_nat_assoc *assoc;
2462 assoc = LIST_FIRST(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc]);
2464 LIST_REMOVE(assoc, timer_Q);
2465 if (la->timeStamp >= assoc->exp) { /* state expired */
2466 SN_LOG(((assoc->state == SN_CL) ? (SN_LOG_DEBUG) : (SN_LOG_INFO)),
2467 logsctperror("Timer Expired", assoc->g_vtag, assoc->state, SN_TO_NODIR));
2468 RmSctpAssoc(la, assoc);
2469 freeGlobalAddressList(assoc);
2470 sn_free(assoc);
2472 sctp_AddTimeOut(la, assoc);
2573 * @param assoc pointer to sctp association
2576 static void logsctpassoc(struct sctp_nat_assoc *assoc, char* s)
2582 switch (assoc->state) {
2606 s, sp, assoc->exp, inet_ntoa_r(assoc->l_addr, addrbuf),
2607 ntohl(assoc->l_vtag), ntohs(assoc->l_port),
2608 ntohl(assoc->g_vtag), ntohs(assoc->g_port),
2609 assoc->TableRegister);
2611 LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) {
2625 struct sctp_nat_assoc *assoc = NULL;
2629 LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) {
2630 logsctpassoc(assoc, " ");
2643 struct sctp_nat_assoc *assoc = NULL;
2647 LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) {
2648 logsctpassoc(assoc, " ");
2662 struct sctp_nat_assoc *assoc = NULL;
2666 LIST_FOREACH(assoc, &la->sctpNatTimer.TimerQ[i], timer_Q) {
2669 logsctpassoc(assoc, buf);