-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tunnel/v8 #10597
Tunnel/v8 #10597
Changes from all commits
f4ddeac
029035b
5833d1e
245fc7d
c7544d5
263f442
563a31b
3fb4a73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,6 +407,12 @@ enum PacketDropReason { | |
PKT_DROP_REASON_MAX, | ||
}; | ||
|
||
enum PacketTunnelType { | ||
PacketTunnelNone, | ||
PacketTunnelRoot, | ||
PacketTunnelChild, | ||
}; | ||
|
||
/* forward declaration since Packet struct definition requires this */ | ||
struct PacketQueue_; | ||
|
||
|
@@ -472,6 +478,9 @@ typedef struct Packet_ | |
* hash size still */ | ||
uint32_t flow_hash; | ||
|
||
/* tunnel type: none, root or child */ | ||
enum PacketTunnelType ttype; | ||
|
||
SCTime_t ts; | ||
|
||
union { | ||
|
@@ -618,6 +627,9 @@ typedef struct Packet_ | |
/* enum PacketDropReason::PKT_DROP_REASON_* as uint8_t for compactness */ | ||
uint8_t drop_reason; | ||
|
||
/** has verdict on this tunneled packet been issued? */ | ||
bool tunnel_verdicted; | ||
|
||
/* tunnel/encapsulation handling */ | ||
struct Packet_ *root; /* in case of tunnel this is a ptr | ||
* to the 'real' packet, the one we | ||
|
@@ -646,8 +658,8 @@ typedef struct Packet_ | |
/** lock to protect access to: | ||
* - tunnel_rtv_cnt | ||
* - tunnel_tpr_cnt | ||
* - nfq_v.mark | ||
* - flags | ||
* - tunnel_verdicted | ||
* - nfq_v.mark (if p->ttype != PacketTunnelNone) | ||
*/ | ||
SCSpinlock tunnel_lock; | ||
} persistent; | ||
|
@@ -796,13 +808,14 @@ static inline void TUNNEL_INCR_PKT_TPR(Packet *p) | |
#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) | ||
|
||
#define IS_TUNNEL_PKT(p) (((p)->flags & PKT_TUNNEL)) | ||
#define SET_TUNNEL_PKT(p) ((p)->flags |= PKT_TUNNEL) | ||
#define UNSET_TUNNEL_PKT(p) ((p)->flags &= ~PKT_TUNNEL) | ||
#define IS_TUNNEL_ROOT_PKT(p) (IS_TUNNEL_PKT(p) && (p)->root == NULL) | ||
|
||
#define IS_TUNNEL_PKT_VERDICTED(p) (((p)->flags & PKT_TUNNEL_VERDICTED)) | ||
#define SET_TUNNEL_PKT_VERDICTED(p) ((p)->flags |= PKT_TUNNEL_VERDICTED) | ||
static inline bool PacketTunnelIsVerdicted(const Packet *p) | ||
{ | ||
return p->tunnel_verdicted; | ||
} | ||
static inline void PacketTunnelSetVerdicted(Packet *p) | ||
{ | ||
p->tunnel_verdicted = true; | ||
} | ||
|
||
enum DecodeTunnelProto { | ||
DECODE_TUNNEL_ETHERNET, | ||
|
@@ -1008,14 +1021,14 @@ void DecodeUnregisterCounters(void); | |
/** Packet is modified by the stream engine, we need to recalc the csum and \ | ||
reinject/replace */ | ||
#define PKT_STREAM_MODIFIED BIT_U32(10) | ||
/** Packet mark is modified */ | ||
#define PKT_MARK_MODIFIED BIT_U32(11) | ||
|
||
// vacancy | ||
|
||
/** Exclude packet from pcap logging as it's part of a stream that has reassembly \ | ||
depth reached. */ | ||
#define PKT_STREAM_NOPCAPLOG BIT_U32(12) | ||
|
||
#define PKT_TUNNEL BIT_U32(13) | ||
#define PKT_TUNNEL_VERDICTED BIT_U32(14) | ||
// vacancy 2x | ||
|
||
/** Packet checksum is not computed (TX packet for example) */ | ||
#define PKT_IGNORE_CHECKSUM BIT_U32(15) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't all the defines be shifted by two? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not shifting to keep flags stable. This mostly helps in debugging reported core dumps. |
||
|
@@ -1091,6 +1104,46 @@ static inline void DecodeSetNoPacketInspectionFlag(Packet *p) | |
p->flags |= PKT_NOPACKET_INSPECTION; | ||
} | ||
|
||
static inline bool PacketIsTunnelRoot(const Packet *p) | ||
{ | ||
return (p->ttype == PacketTunnelRoot); | ||
} | ||
|
||
static inline bool PacketIsTunnelChild(const Packet *p) | ||
{ | ||
return (p->ttype == PacketTunnelChild); | ||
} | ||
|
||
static inline bool PacketIsTunnel(const Packet *p) | ||
{ | ||
return (p->ttype != PacketTunnelNone); | ||
} | ||
|
||
static inline bool PacketIsNotTunnel(const Packet *p) | ||
{ | ||
return (p->ttype == PacketTunnelNone); | ||
} | ||
|
||
static inline bool VerdictTunnelPacketInternal(const Packet *p) | ||
{ | ||
const uint16_t outstanding = TUNNEL_PKT_TPR(p) - TUNNEL_PKT_RTV(p); | ||
SCLogDebug("tunnel: outstanding %u", outstanding); | ||
|
||
/* if there are packets outstanding, we won't verdict this one */ | ||
if (PacketIsTunnelRoot(p) && !PacketTunnelIsVerdicted(p) && !outstanding) { | ||
SCLogDebug("root %p: verdict", p); | ||
return true; | ||
|
||
} else if (PacketIsTunnelChild(p) && outstanding == 1 && p->root && | ||
PacketTunnelIsVerdicted(p->root)) { | ||
SCLogDebug("tunnel %p: verdict", p); | ||
return true; | ||
|
||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** \brief return true if *this* packet needs to trigger a verdict. | ||
* | ||
* If we have the root packet, and we have none outstanding, | ||
|
@@ -1103,22 +1156,10 @@ static inline void DecodeSetNoPacketInspectionFlag(Packet *p) | |
*/ | ||
static inline bool VerdictTunnelPacket(Packet *p) | ||
{ | ||
bool verdict = true; | ||
bool verdict; | ||
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); | ||
|
||
/* if there are packets outstanding, we won't verdict this one */ | ||
if (IS_TUNNEL_ROOT_PKT(p) && !IS_TUNNEL_PKT_VERDICTED(p) && !outstanding) { | ||
// verdict | ||
SCLogDebug("root %p: verdict", p); | ||
} else if (!IS_TUNNEL_ROOT_PKT(p) && outstanding == 1 && p->root && IS_TUNNEL_PKT_VERDICTED(p->root)) { | ||
// verdict | ||
SCLogDebug("tunnel %p: verdict", p); | ||
} else { | ||
verdict = false; | ||
} | ||
verdict = VerdictTunnelPacketInternal(p); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declare variable here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I don't like to declare a var inside a lock, then use it outside. It's a matter of style I think, I don't think it has practical effect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, the comment was based on the experience from the previous PRs. |
||
SCSpinUnlock(lock); | ||
return verdict; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shift here as well?