Commit c1ddfdbe authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'net-add-debug-checks-to-skb_reset_xxx_header'

Eric Dumazet says:

====================
net: add debug checks to skb_reset_xxx_header()

Add debug checks (only enabled for CONFIG_DEBUG_NET=y builds),
to catch bugs earlier.
====================

Link: https://patch.msgid.link/20241105174403.850330-1-edumazet@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 3545f9b7 3b6167e9
Loading
Loading
Loading
Loading
+35 −12
Original line number Diff line number Diff line
@@ -2909,10 +2909,20 @@ static inline void skb_reset_inner_headers(struct sk_buff *skb)
	skb->inner_transport_header = skb->transport_header;
}

static inline int skb_mac_header_was_set(const struct sk_buff *skb)
{
	return skb->mac_header != (typeof(skb->mac_header))~0U;
}

static inline void skb_reset_mac_len(struct sk_buff *skb)
{
	if (!skb_mac_header_was_set(skb)) {
		DEBUG_NET_WARN_ON_ONCE(1);
		skb->mac_len = 0;
	} else {
		skb->mac_len = skb->network_header - skb->mac_header;
	}
}

static inline unsigned char *skb_inner_transport_header(const struct sk_buff
							*skb)
@@ -2927,7 +2937,10 @@ static inline int skb_inner_transport_offset(const struct sk_buff *skb)

static inline void skb_reset_inner_transport_header(struct sk_buff *skb)
{
	skb->inner_transport_header = skb->data - skb->head;
	long offset = skb->data - skb->head;

	DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->inner_transport_header))offset);
	skb->inner_transport_header = offset;
}

static inline void skb_set_inner_transport_header(struct sk_buff *skb,
@@ -2944,7 +2957,10 @@ static inline unsigned char *skb_inner_network_header(const struct sk_buff *skb)

static inline void skb_reset_inner_network_header(struct sk_buff *skb)
{
	skb->inner_network_header = skb->data - skb->head;
	long offset = skb->data - skb->head;

	DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->inner_network_header))offset);
	skb->inner_network_header = offset;
}

static inline void skb_set_inner_network_header(struct sk_buff *skb,
@@ -2966,7 +2982,10 @@ static inline unsigned char *skb_inner_mac_header(const struct sk_buff *skb)

static inline void skb_reset_inner_mac_header(struct sk_buff *skb)
{
	skb->inner_mac_header = skb->data - skb->head;
	long offset = skb->data - skb->head;

	DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->inner_mac_header))offset);
	skb->inner_mac_header = offset;
}

static inline void skb_set_inner_mac_header(struct sk_buff *skb,
@@ -2988,7 +3007,10 @@ static inline unsigned char *skb_transport_header(const struct sk_buff *skb)

static inline void skb_reset_transport_header(struct sk_buff *skb)
{
	skb->transport_header = skb->data - skb->head;
	long offset = skb->data - skb->head;

	DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->transport_header))offset);
	skb->transport_header = offset;
}

static inline void skb_set_transport_header(struct sk_buff *skb,
@@ -3005,7 +3027,10 @@ static inline unsigned char *skb_network_header(const struct sk_buff *skb)

static inline void skb_reset_network_header(struct sk_buff *skb)
{
	skb->network_header = skb->data - skb->head;
	long offset = skb->data - skb->head;

	DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->network_header))offset);
	skb->network_header = offset;
}

static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
@@ -3014,11 +3039,6 @@ static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
	skb->network_header += offset;
}

static inline int skb_mac_header_was_set(const struct sk_buff *skb)
{
	return skb->mac_header != (typeof(skb->mac_header))~0U;
}

static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
{
	DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb));
@@ -3043,7 +3063,10 @@ static inline void skb_unset_mac_header(struct sk_buff *skb)

static inline void skb_reset_mac_header(struct sk_buff *skb)
{
	skb->mac_header = skb->data - skb->head;
	long offset = skb->data - skb->head;

	DEBUG_NET_WARN_ON_ONCE(offset != (typeof(skb->mac_header))offset);
	skb->mac_header = offset;
}

static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)