Reduces Packet size.
Ticket: #6938.
return -1;
}
- p->sctph = (SCTPHdr *)pkt;
-
- SET_SCTP_SRC_PORT(p,&p->sp);
- SET_SCTP_DST_PORT(p,&p->dp);
-
+ SCTPHdr *sctph = PacketSetSCTP(p, pkt);
+ p->sp = SCNtohs(sctph->sh_sport);
+ p->dp = SCNtohs(sctph->sh_dport);
p->payload = (uint8_t *)pkt + sizeof(SCTPHdr);
p->payload_len = len - sizeof(SCTPHdr);
-
p->proto = IPPROTO_SCTP;
-
return 0;
}
StatsIncr(tv, dtv->counter_sctp);
if (unlikely(DecodeSCTPPacket(tv, p,pkt,len) < 0)) {
- CLEAR_SCTP_PACKET(p);
+ PacketClearL4(p);
return TM_ECODE_FAILED;
}
-#ifdef DEBUG
- SCLogDebug("SCTP sp: %" PRIu32 " -> dp: %" PRIu32,
- SCTP_GET_SRC_PORT(p), SCTP_GET_DST_PORT(p));
-#endif
+ SCLogDebug("SCTP sp: %u -> dp: %u", p->sp, p->dp);
FlowSetupPacket(p);
/** size of the packet header without any chunk headers */
#define SCTP_HEADER_LEN 12
-/* XXX RAW* needs to be really 'raw', so no SCNtohs there */
-#define SCTP_GET_RAW_SRC_PORT(sctph) SCNtohs((sctph)->sh_sport)
-#define SCTP_GET_RAW_DST_PORT(sctph) SCNtohs((sctph)->sh_dport)
-
-#define SCTP_GET_SRC_PORT(p) SCTP_GET_RAW_SRC_PORT(p->sctph)
-#define SCTP_GET_DST_PORT(p) SCTP_GET_RAW_DST_PORT(p->sctph)
-
typedef struct SCTPHdr_
{
uint16_t sh_sport; /* source port */
uint32_t sh_sum; /* checksum, computed via crc32 */
} __attribute__((__packed__)) SCTPHdr;
-#define CLEAR_SCTP_PACKET(p) { \
- (p)->sctph = NULL; \
-} while (0)
-
void DecodeSCTPRegisterTests(void);
#endif /* SURICATA_DECODE_SCTP_H */
SET_PORT(UDP_GET_DST_PORT((pkt)), *(prt)); \
} while (0)
-/* Set the SCTP ports into the Ports of the Packet.
- * Make sure p->sctph is initialized and validated. */
-#define SET_SCTP_SRC_PORT(pkt, prt) do { \
- SET_PORT(SCTP_GET_SRC_PORT((pkt)), *(prt)); \
- } while (0)
-
-#define SET_SCTP_DST_PORT(pkt, prt) do { \
- SET_PORT(SCTP_GET_DST_PORT((pkt)), *(prt)); \
- } while (0)
-
-
#define GET_IPV4_SRC_ADDR_U32(p) ((p)->src.addr_data32[0])
#define GET_IPV4_DST_ADDR_U32(p) ((p)->dst.addr_data32[0])
#define GET_IPV4_SRC_ADDR_PTR(p) ((p)->src.addr_data32)
} vars;
};
+enum PacketL4Types {
+ PACKET_L4_UNKNOWN = 0,
+ PACKET_L4_SCTP,
+};
+
struct PacketL4 {
+ enum PacketL4Types type;
bool csum_set;
uint16_t csum;
+ union L4Hdrs {
+ SCTPHdr *sctph;
+ } hdrs;
};
/* sizes of the members:
TCPHdr *tcph;
UDPHdr *udph;
- SCTPHdr *sctph;
ESPHdr *esph;
ICMPV4Hdr *icmpv4h;
ICMPV6Hdr *icmpv6h;
return PKT_IS_ICMPV6(p);
}
+static inline SCTPHdr *PacketSetSCTP(Packet *p, const uint8_t *buf)
+{
+ DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_UNKNOWN);
+ p->l4.type = PACKET_L4_SCTP;
+ p->l4.hdrs.sctph = (SCTPHdr *)buf;
+ return p->l4.hdrs.sctph;
+}
+
+static inline const SCTPHdr *PacketGetSCTP(const Packet *p)
+{
+ DEBUG_VALIDATE_BUG_ON(p->l4.type != PACKET_L4_SCTP);
+ return p->l4.hdrs.sctph;
+}
+
+static inline bool PacketIsSCTP(const Packet *p)
+{
+ return p->l4.type == PACKET_L4_SCTP;
+}
+
/** \brief Structure to hold thread specific data for all decode modules */
typedef struct DecodeThreadVars_
{
f->icmp_s.type = p->icmp_s.type;
f->icmp_s.code = p->icmp_s.code;
FlowSetICMPv6CounterPart(f);
- } else if (p->sctph != NULL) { /* XXX MACRO */
- SET_SCTP_SRC_PORT(p,&f->sp);
- SET_SCTP_DST_PORT(p,&f->dp);
+ } else if (PacketIsSCTP(p)) {
+ f->sp = p->sp;
+ f->dp = p->dp;
} else if (p->esph != NULL) {
f->esp.spi = ESP_GET_SPI(p);
} else {
if (p->udph != NULL) {
CLEAR_UDP_PACKET(p);
}
- if (p->sctph != NULL) {
- CLEAR_SCTP_PACKET(p);
- }
if (p->esph != NULL) {
CLEAR_ESP_PACKET(p);
}
} else if ((p)->proto == IPPROTO_ICMP) { \
BUG_ON((p)->icmpv4h == NULL); \
} else if ((p)->proto == IPPROTO_SCTP) { \
- BUG_ON((p)->sctph == NULL); \
+ BUG_ON(PacketGetSCTP((p)) == NULL); \
} else if ((p)->proto == IPPROTO_ICMPV6) { \
BUG_ON((p)->icmpv6h == NULL); \
} \