diff options
Diffstat (limited to 'sys/netinet/libalias/alias_sctp.c')
-rw-r--r-- | sys/netinet/libalias/alias_sctp.c | 138 |
1 files changed, 78 insertions, 60 deletions
diff --git a/sys/netinet/libalias/alias_sctp.c b/sys/netinet/libalias/alias_sctp.c index 83290148bfa6..719af1512a05 100644 --- a/sys/netinet/libalias/alias_sctp.c +++ b/sys/netinet/libalias/alias_sctp.c @@ -2,7 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2008 - * Swinburne University of Technology, Melbourne, Australia. + * Swinburne University of Technology, Melbourne, Australia. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -128,15 +128,15 @@ static void TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm,\ struct sctp_nat_assoc *assoc, int sndrply, int direction); /* Hash Table Functions */ -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * 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); -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t g_port, uint16_t l_port, int *partial_match); -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc); -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint16_t g_port, uint16_t l_port); -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * FindSctpGlobalT(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t l_port, uint16_t g_port); static int AddSctpAssocLocal(struct libalias *la, struct sctp_nat_assoc *assoc, struct in_addr g_addr); @@ -151,7 +151,7 @@ static void sctp_ResetTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc, void sctp_CheckTimers(struct libalias *la); /* Logging Functions */ -static void logsctperror(char* errormsg, uint32_t vtag, int error, int direction); +static void logsctperror(char *errormsg, uint32_t vtag, int error, int direction); static void logsctpparse(int direction, struct sctp_nat_msg *sm); static void logsctpassoc(struct sctp_nat_assoc *assoc, char *s); static void logTimerQ(struct libalias *la); @@ -181,7 +181,7 @@ static void SctpAliasLog(const char *format, ...); */ void SctpShowAliasStats(struct libalias *la); -#ifdef _KERNEL +#ifdef _KERNEL static MALLOC_DEFINE(M_SCTPNAT, "sctpnat", "sctp nat dbs"); /* Use kernel allocator. */ @@ -438,7 +438,8 @@ int sysctl_chg_loglevel(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &level, 0, req); - if (error) return (error); + if (error) + return (error); level = (level > SN_LOG_DEBUG_MAX) ? (SN_LOG_DEBUG_MAX) : (level); level = (level < SN_LOG_LOW) ? (SN_LOG_LOW) : (level); @@ -459,7 +460,8 @@ int sysctl_chg_timer(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &timer, 0, req); - if (error) return (error); + if (error) + return (error); timer = (timer > SN_MAX_TIMER) ? (SN_MAX_TIMER) : (timer); @@ -487,7 +489,8 @@ int sysctl_chg_hashtable_size(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &size, 0, req); - if (error) return (error); + if (error) + return (error); size = (size < SN_MIN_HASH_SIZE) ? (SN_MIN_HASH_SIZE) : ((size > SN_MAX_HASH_SIZE) ? (SN_MAX_HASH_SIZE) : (size)); @@ -515,7 +518,8 @@ int sysctl_chg_error_on_ootb(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &flag, 0, req); - if (error) return (error); + if (error) + return (error); sysctl_error_on_ootb = (flag > SN_ERROR_ON_OOTB) ? SN_ERROR_ON_OOTB: flag; @@ -534,7 +538,8 @@ int sysctl_chg_accept_global_ootb_addip(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &flag, 0, req); - if (error) return (error); + if (error) + return (error); sysctl_accept_global_ootb_addip = (flag == 1) ? 1: 0; @@ -554,7 +559,8 @@ int sysctl_chg_initialising_chunk_proc_limit(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &proclimit, 0, req); - if (error) return (error); + if (error) + return (error); sysctl_initialising_chunk_proc_limit = (proclimit < 1) ? 1: proclimit; sysctl_chunk_proc_limit = @@ -576,7 +582,8 @@ int sysctl_chg_chunk_proc_limit(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &proclimit, 0, req); - if (error) return (error); + if (error) + return (error); sysctl_chunk_proc_limit = (proclimit < sysctl_initialising_chunk_proc_limit) ? sysctl_initialising_chunk_proc_limit : proclimit; @@ -597,7 +604,8 @@ int sysctl_chg_param_proc_limit(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &proclimit, 0, req); - if (error) return (error); + if (error) + return (error); sysctl_param_proc_limit = (proclimit < 2) ? 2 : proclimit; @@ -618,7 +626,8 @@ int sysctl_chg_track_global_addresses(SYSCTL_HANDLER_ARGS) int error; error = sysctl_handle_int(oidp, &num_to_track, 0, req); - if (error) return (error); + if (error) + return (error); sysctl_track_global_addresses = (num_to_track > SN_MAX_GLOBAL_ADDRESSES) ? SN_MAX_GLOBAL_ADDRESSES : num_to_track; @@ -637,7 +646,8 @@ int sysctl_chg_track_global_addresses(SYSCTL_HANDLER_ARGS) * * @param la Pointer to the relevant libalias instance */ -void AliasSctpInit(struct libalias *la) +void +AliasSctpInit(struct libalias *la) { /* Initialise association tables*/ int i; @@ -677,7 +687,8 @@ void AliasSctpInit(struct libalias *la) * * @param la Pointer to the relevant libalias instance */ -void AliasSctpTerm(struct libalias *la) +void +AliasSctpTerm(struct libalias *la) { struct sctp_nat_assoc *assoc1, *assoc2; int i; @@ -773,7 +784,7 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) SN_LOG(SN_LOG_DETAIL, logsctpassoc(assoc, "*"); logsctpparse(direction, &msg); - ); + ); /* Process the SCTP message */ rtnval = ProcessSctpMsg(la, direction, &msg, assoc); @@ -782,7 +793,7 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) logsctpassoc(assoc, "-"); logSctpLocal(la); logSctpGlobal(la); - ); + ); SN_LOG(SN_LOG_DEBUG, logTimerQ(la)); switch (rtnval) { @@ -815,7 +826,7 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) default: // big error, remove association and go to idle and write log messages SN_LOG(SN_LOG_LOW, logsctperror("SN_PROCESSING_ERROR", msg.sctp_hdr->v_tag, rtnval, direction)); - assoc->state=SN_RM;/* Mark for removal*/ + assoc->state = SN_RM;/* Mark for removal*/ break; } @@ -999,12 +1010,12 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso memcpy(sm->ip_hdr, ip, ip_size); SN_LOG(SN_LOG_EVENT,SctpAliasLog("%s %s 0x%x (->%s:%u vtag=0x%x crc=0x%x)\n", - ((sndrply == SN_SEND_ABORT) ? "Sending" : "Replying"), - ((sndrply & SN_TX_ERROR) ? "ErrorM" : "AbortM"), - (include_error_cause ? ntohs(error_cause->code) : 0), - inet_ntoa_r(ip->ip_dst, INET_NTOA_BUF(addrbuf)), - ntohs(sctp_hdr->dest_port), - ntohl(sctp_hdr->v_tag), ntohl(sctp_hdr->checksum))); + ((sndrply == SN_SEND_ABORT) ? "Sending" : "Replying"), + ((sndrply & SN_TX_ERROR) ? "ErrorM" : "AbortM"), + (include_error_cause ? ntohs(error_cause->code) : 0), + inet_ntoa_r(ip->ip_dst, INET_NTOA_BUF(addrbuf)), + ntohs(sctp_hdr->dest_port), + ntohl(sctp_hdr->v_tag), ntohl(sctp_hdr->checksum))); } /* ---------------------------------------------------------------------- @@ -1265,7 +1276,7 @@ GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, u struct sctp_paramhdr ph;/* type=SCTP_VTAG_PARAM */ uint32_t local_vtag; uint32_t remote_vtag; - } __attribute__((packed)); + } __attribute__((packed)); struct sctp_vtag_param *vtag_param; struct sctp_paramhdr *param; @@ -1298,7 +1309,8 @@ GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, u } bytes_left -= param_size; - if (bytes_left < SN_MIN_PARAM_SIZE) return (0); + if (bytes_left < SN_MIN_PARAM_SIZE) + return (0); param = SN_SCTP_NEXTPARAM(param); param_size = SCTP_SIZE32(ntohs(param->param_length)); @@ -1455,7 +1467,8 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int * * @return 1 - success | 0 - fail */ -static int Add_Global_Address_to_List(struct sctp_nat_assoc *assoc, struct sctp_GlobalAddress *G_addr) +static int +Add_Global_Address_to_List(struct sctp_nat_assoc *assoc, struct sctp_GlobalAddress *G_addr) { struct sctp_GlobalAddress *iter_G_Addr = NULL, *first_G_Addr = NULL; first_G_Addr = LIST_FIRST(&(assoc->Gaddr)); @@ -1550,7 +1563,8 @@ RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int d } } bytes_left -= param_size; - if (bytes_left == 0) return; + if (bytes_left == 0) + return; else if (bytes_left < SN_MIN_PARAM_SIZE) { SN_LOG(SN_LOG_EVENT, logsctperror("RmGlobalIPAddress: truncated packet - may not have removed all IP addresses", @@ -1614,13 +1628,14 @@ IsASCONFack(struct libalias *la, struct sctp_nat_msg *sm, int direction) return (1); /* success - but can't match correlation IDs - should only be one */ /* check others just in case */ bytes_left -= param_size; - if (bytes_left >= SN_MIN_PARAM_SIZE) { + if (bytes_left >= SN_MIN_PARAM_SIZE) param = SN_SCTP_NEXTPARAM(param); - } else { + else return (0); - } + param_size = SCTP_SIZE32(ntohs(param->param_length)); - if (bytes_left < param_size) return (0); + if (bytes_left < param_size) + return (0); if (++param_count > sysctl_param_proc_limit) { SN_LOG(SN_LOG_EVENT, @@ -1667,13 +1682,14 @@ IsADDorDEL(struct libalias *la, struct sctp_nat_msg *sm, int direction) return (SCTP_DEL_IP_ADDRESS); /* check others just in case */ bytes_left -= param_size; - if (bytes_left >= SN_MIN_PARAM_SIZE) { + if (bytes_left >= SN_MIN_PARAM_SIZE) param = SN_SCTP_NEXTPARAM(param); - } else { + else return (0); /*Neither found */ - } + param_size = SCTP_SIZE32(ntohs(param->param_length)); - if (bytes_left < param_size) return (0); + if (bytes_left < param_size) + return (0); if (++param_count > sysctl_param_proc_limit) { SN_LOG(SN_LOG_EVENT, @@ -1771,7 +1787,7 @@ ID_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, str assoc->g_port = sm->sctp_hdr->dest_port; if (sm->msg == SN_SCTP_INIT) assoc->g_vtag = sm->sctpchnk.Init->initiate_tag; - if (AddSctpAssocGlobal(la, assoc)) /* DB clash *///**** need to add dst address + if (AddSctpAssocGlobal(la, assoc)) /* DB clash: need to add dst address */ return ((sm->msg == SN_SCTP_INIT) ? SN_REPLY_ABORT : SN_REPLY_ERROR); if (sm->msg == SN_SCTP_ASCONF) { if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_dst)) /* DB clash */ @@ -1789,10 +1805,10 @@ ID_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, str if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_src)) /* DB clash */ return ((sm->msg == SN_SCTP_INIT) ? SN_REPLY_ABORT : SN_REPLY_ERROR); if (sm->msg == SN_SCTP_ASCONF) { - if (AddSctpAssocGlobal(la, assoc)) /* DB clash */ //**** need to add src address + if (AddSctpAssocGlobal(la, assoc)) /* DB clash: need to add src address */ return (SN_REPLY_ERROR); assoc->TableRegister |= SN_WAIT_TOGLOBAL; /* wait for toglobal ack */ - } + } break; } assoc->state = (sm->msg == SN_SCTP_INIT) ? SN_INi : SN_INa; @@ -1938,7 +1954,8 @@ UP_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, str case SCTP_DEL_IP_ADDRESS: RmGlobalIPAddresses(sm, assoc, direction); break; - } /* fall through to default */ + } + /* fall through to default */ default: sctp_ResetTimeOut(la,assoc, SN_U_T(la)); return (SN_NAT_PKT); /* forward packet */ @@ -2009,7 +2026,7 @@ CL_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, stru * * @return pointer to association or NULL */ -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * 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) { u_int i; @@ -2046,8 +2063,8 @@ FindSctpLocal(struct libalias *la, struct in_addr l_addr, struct in_addr g_addr, * * @return pointer to association or NULL */ -static struct sctp_nat_assoc* -FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc) +static struct sctp_nat_assoc * +FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc) { u_int i; struct sctp_nat_assoc *assoc = NULL; @@ -2093,7 +2110,7 @@ FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc) * * @return pointer to association or NULL */ -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t g_port, uint16_t l_port, int *partial_match) { u_int i; @@ -2134,7 +2151,7 @@ FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint * * @return pointer to association or NULL */ -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint16_t g_port, uint16_t l_port) { u_int i; @@ -2152,7 +2169,8 @@ FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint return (assoc); /* full match */ } } else { - if (++cnt > 1) return (NULL); + if (++cnt > 1) + return (NULL); lastmatch = assoc; } } @@ -2176,7 +2194,7 @@ FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint * * @return pointer to association or NULL */ -static struct sctp_nat_assoc* +static struct sctp_nat_assoc * FindSctpGlobalT(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint16_t l_port, uint16_t g_port) { u_int i; @@ -2282,8 +2300,9 @@ AddSctpAssocGlobal(struct libalias *la, struct sctp_nat_assoc *assoc) LIBALIAS_LOCK_ASSERT(la); found = FindSctpGlobalClash(la, assoc); if (found != NULL) { - if ((found->TableRegister == SN_GLOBAL_TBL) && \ - (found->l_addr.s_addr == assoc->l_addr.s_addr) && (found->l_port == assoc->l_port)) { /* resent message */ + if ((found->TableRegister == SN_GLOBAL_TBL) && + (found->l_addr.s_addr == assoc->l_addr.s_addr) && + (found->l_port == assoc->l_port)) { /* resent message */ RmSctpAssoc(la, found); sctp_RmTimeOut(la, found); freeGlobalAddressList(found); @@ -2515,7 +2534,7 @@ sctp_CheckTimers(struct libalias *la) * @param direction Direction of packet */ static void -logsctperror(char* errormsg, uint32_t vtag, int error, int direction) +logsctperror(char *errormsg, uint32_t vtag, int error, int direction) { char dir; switch (direction) { @@ -2590,7 +2609,7 @@ logsctpparse(int direction, struct sctp_nat_msg *sm) * @param assoc pointer to sctp association * @param s Character that indicates the state of processing for this packet */ -static void logsctpassoc(struct sctp_nat_assoc *assoc, char* s) +static void logsctpassoc(struct sctp_nat_assoc *assoc, char *s) { struct sctp_GlobalAddress *G_Addr = NULL; char *sp; @@ -2642,7 +2661,7 @@ static void logSctpGlobal(struct libalias *la) struct sctp_nat_assoc *assoc = NULL; SctpAliasLog("G->\n"); - for (i=0; i < la->sctpNatTableSize; i++) { + for (i = 0; i < la->sctpNatTableSize; i++) { LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) { logsctpassoc(assoc, " "); } @@ -2660,7 +2679,7 @@ static void logSctpLocal(struct libalias *la) struct sctp_nat_assoc *assoc = NULL; SctpAliasLog("L->\n"); - for (i=0; i < la->sctpNatTableSize; i++) { + for (i = 0; i < la->sctpNatTableSize; i++) { LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) { logsctpassoc(assoc, " "); } @@ -2679,7 +2698,7 @@ static void logTimerQ(struct libalias *la) struct sctp_nat_assoc *assoc = NULL; SctpAliasLog("t->\n"); - for (i=0; i < SN_TIMER_QUEUE_SIZE; i++) { + for (i = 0; i < SN_TIMER_QUEUE_SIZE; i++) { LIST_FOREACH(assoc, &la->sctpNatTimer.TimerQ[i], timer_Q) { snprintf(buf, 50, " l=%u ",i); //SctpAliasLog(la->logDesc," l=%d ",i); @@ -2705,8 +2724,7 @@ SctpAliasLog(const char *format, ...) va_start(ap, format); vsnprintf(buffer, LIBALIAS_BUF_SIZE, format, ap); va_end(ap); - log(LOG_SECURITY | LOG_INFO, - "alias_sctp: %s", buffer); + log(LOG_SECURITY | LOG_INFO, "alias_sctp: %s", buffer); } #else static void |