MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sctp_PktParser

Function sctp_PktParser

freebsd/netinet/libalias/alias_sctp.c:1035–1240  ·  view source on GitHub ↗

---------------------------------------------------------------------- * PACKET PARSER CODE * ---------------------------------------------------------------------- */ @addtogroup packet_parser * * These functions parse the SCTP packet and fill a sctp_nat_msg structure * with the parsed contents. */ @ingroup packet_parser * @brief Parses SCTP packets for the key S

Source from the content-addressed store, hash-verified

1033 * @return SN_PARSE_OK | SN_PARSE_ERROR_*
1034 */
1035static int
1036sctp_PktParser(struct libalias *la, int direction, struct ip *pip,
1037 struct sctp_nat_msg *sm, struct sctp_nat_assoc **passoc)
1038//sctp_PktParser(int direction, struct mbuf *ipak, int ip_hdr_len,struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc)
1039{
1040 struct sctphdr *sctp_hdr;
1041 struct sctp_chunkhdr *chunk_hdr;
1042 struct sctp_paramhdr *param_hdr;
1043 struct in_addr ipv4addr;
1044 int bytes_left; /* bytes left in ip packet */
1045 int chunk_length;
1046 int chunk_count;
1047 int partial_match = 0;
1048 // mbuf *mp;
1049 // int mlen;
1050
1051 // mlen = SCTP_HEADER_LEN(i_pak);
1052 // mp = SCTP_HEADER_TO_CHAIN(i_pak); /* does nothing in bsd since header and chain not separate */
1053
1054 /*
1055 * Note, that if the VTag is zero, it must be an INIT
1056 * Also, I am only interested in the content of INIT and ADDIP chunks
1057 */
1058
1059 // no mbuf stuff from Paolo yet so ...
1060 sm->ip_hdr = pip;
1061 /* remove ip header length from the bytes_left */
1062 bytes_left = ntohs(pip->ip_len) - (pip->ip_hl << 2);
1063
1064 /* Check SCTP header length and move to first chunk */
1065 if (bytes_left < sizeof(struct sctphdr)) {
1066 sm->sctp_hdr = NULL;
1067 return (SN_PARSE_ERROR_IPSHL); /* packet not long enough*/
1068 }
1069
1070 sm->sctp_hdr = sctp_hdr = (struct sctphdr *) ip_next(pip);
1071 bytes_left -= sizeof(struct sctphdr);
1072
1073 /* Check for valid ports (zero valued ports would find partially initialised associations */
1074 if (sctp_hdr->src_port == 0 || sctp_hdr->dest_port == 0)
1075 return (SN_PARSE_ERROR_PORT);
1076
1077 /* Check length of first chunk */
1078 if (bytes_left < SN_MIN_CHUNK_SIZE) /* malformed chunk - could cause endless loop*/
1079 return (SN_PARSE_ERROR_CHHL); /* packet not long enough for this chunk */
1080
1081 /* First chunk */
1082 chunk_hdr = SN_SCTP_FIRSTCHUNK(sctp_hdr);
1083
1084 chunk_length = SCTP_SIZE32(ntohs(chunk_hdr->chunk_length));
1085 if ((chunk_length < SN_MIN_CHUNK_SIZE) || (chunk_length > bytes_left)) /* malformed chunk - could cause endless loop*/
1086 return (SN_PARSE_ERROR_CHHL);
1087
1088 if ((chunk_hdr->chunk_flags & SCTP_HAD_NO_TCB) &&
1089 ((chunk_hdr->chunk_type == SCTP_ABORT_ASSOCIATION) ||
1090 (chunk_hdr->chunk_type == SCTP_SHUTDOWN_COMPLETE))) {
1091 /* T-Bit set */
1092 if (direction == SN_TO_LOCAL)

Callers 1

SctpAliasFunction · 0.85

Calls 5

ip_nextFunction · 0.85
FindSctpGlobalTFunction · 0.85
FindSctpLocalTFunction · 0.85
FindSctpGlobalFunction · 0.85
FindSctpLocalFunction · 0.85

Tested by

no test coverage detected