* It should always point to the lowest
* packet in a encapsulated packet */
- /** mutex to protect access to:
- * - tunnel_rtv_cnt
- * - tunnel_tpr_cnt
- */
- SCMutex tunnel_mutex;
/* ready to set verdict counter, only set in root */
uint16_t tunnel_rtv_cnt;
/* tunnel packet ref count */
#ifdef PROFILING
PktProfiling *profile;
#endif
+ /* things in the packet that live beyond a reinit */
+ struct {
+ /** lock to protect access to:
+ * - tunnel_rtv_cnt
+ * - tunnel_tpr_cnt
+ * - nfq_v.mark
+ * - flags
+ */
+ SCSpinlock tunnel_lock;
+ } persistent;
} Packet;
/** highest mtu of the interfaces we monitor */
((p)->root ? (p)->root->tunnel_rtv_cnt++ : (p)->tunnel_rtv_cnt++); \
} while (0)
-#define TUNNEL_INCR_PKT_TPR(p) do { \
- SCMutexLock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
- ((p)->root ? (p)->root->tunnel_tpr_cnt++ : (p)->tunnel_tpr_cnt++); \
- SCMutexUnlock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
- } while (0)
+static inline void TUNNEL_INCR_PKT_TPR(Packet *p)
+{
+ Packet *rp = p->root ? p->root : p;
+ SCSpinLock(&rp->persistent.tunnel_lock);
+ rp->tunnel_tpr_cnt++;
+ SCSpinUnlock(&rp->persistent.tunnel_lock);
+}
#define TUNNEL_PKT_RTV(p) ((p)->root ? (p)->root->tunnel_rtv_cnt : (p)->tunnel_rtv_cnt)
#define TUNNEL_PKT_TPR(p) ((p)->root ? (p)->root->tunnel_tpr_cnt : (p)->tunnel_tpr_cnt)
static inline bool VerdictTunnelPacket(Packet *p)
{
bool verdict = true;
- SCMutex *m = p->root ? &p->root->tunnel_mutex : &p->tunnel_mutex;
- SCMutexLock(m);
+ SCSpinlock *lock = p->root ? &p->root->persistent.tunnel_lock : &p->persistent.tunnel_lock;
+ SCSpinLock(lock);
const uint16_t outstanding = TUNNEL_PKT_TPR(p) - TUNNEL_PKT_RTV(p);
SCLogDebug("tunnel: outstanding %u", outstanding);
} else {
verdict = false;
}
- SCMutexUnlock(m);
+ SCSpinUnlock(lock);
return verdict;
}
* are fine. */
if (p->flags & PKT_REBUILT_FRAGMENT) {
Packet *tp = p->root ? p->root : p;
- SCMutexLock(&tp->tunnel_mutex);
+ SCSpinLock(&tp->persistent.tunnel_lock);
tp->nfq_v.mark = (nf_data->mark & nf_data->mask)
| (tp->nfq_v.mark & ~(nf_data->mask));
tp->flags |= PKT_MARK_MODIFIED;
- SCMutexUnlock(&tp->tunnel_mutex);
+ SCSpinUnlock(&tp->persistent.tunnel_lock);
}
}
}
*/
void PacketInit(Packet *p)
{
- SCMutexInit(&p->tunnel_mutex, NULL);
+ SCSpinInit(&p->persistent.tunnel_lock, 0);
p->alerts.alerts = PacketAlertCreate();
PACKET_RESET_CHECKSUMS(p);
p->livedev = NULL;
}
PacketAlertFree(p->alerts.alerts);
PACKET_FREE_EXTDATA(p);
- SCMutexDestroy(&p->tunnel_mutex);
+ SCSpinDestroy(&p->persistent.tunnel_lock);
AppLayerDecoderEventsFreeEvents(&p->app_layer_events);
PACKET_PROFILING_RESET(p);
}
* work for those. Rebuilt packets from IP fragments are fine. */
if (p->flags & PKT_REBUILT_FRAGMENT) {
Packet *tp = p->root ? p->root : p;
- SCMutexLock(&tp->tunnel_mutex);
+ SCSpinLock(&tp->persistent.tunnel_lock);
tp->nfq_v.mark = (nfq_config.bypass_mark & nfq_config.bypass_mask)
| (tp->nfq_v.mark & ~nfq_config.bypass_mask);
tp->flags |= PKT_MARK_MODIFIED;
- SCMutexUnlock(&tp->tunnel_mutex);
+ SCSpinUnlock(&tp->persistent.tunnel_lock);
return 1;
}
return 0;
p,p->root ? "upper layer" : "tunnel root");
/* get a lock to access root packet fields */
- SCMutex *m = p->root ? &p->root->tunnel_mutex : &p->tunnel_mutex;
- SCMutexLock(m);
+ SCSpinlock *lock = p->root ? &p->root->persistent.tunnel_lock : &p->persistent.tunnel_lock;
+ SCSpinLock(lock);
if (IS_TUNNEL_ROOT_PKT(p)) {
SCLogDebug("IS_TUNNEL_ROOT_PKT == TRUE");
SET_TUNNEL_PKT_VERDICTED(p);
PACKET_PROFILING_END(p);
- SCMutexUnlock(m);
+ SCSpinUnlock(lock);
SCReturn;
}
} else {
/* fall through */
}
}
- SCMutexUnlock(m);
+ SCSpinUnlock(lock);
SCLogDebug("tunnel stuff done, move on (proot %d)", proot);
}