From: Daniel Axtens <dja@axtens.net>
To: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: netdev@vger.kernel.org, Manish.Chopra@cavium.com,
Jason Wang <jasowang@redhat.com>, Pravin Shelar <pshelar@ovn.org>
Subject: Re: [PATCH v3 1/2] net: create skb_gso_validate_mac_len()
Date: Wed, 31 Jan 2018 00:08:59 +1100 [thread overview]
Message-ID: <877erzbij8.fsf@linkitivity.dja.id.au> (raw)
In-Reply-To: <20180130081702.GJ4000@localhost.localdomain>
Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> writes:
> Hi,
>
> On Tue, Jan 30, 2018 at 12:14:46PM +1100, Daniel Axtens wrote:
>> If you take a GSO skb, and split it into packets, will the MAC
>> length (L2 + L3 + L4 headers + payload) of those packets be small
>> enough to fit within a given length?
>>
>> Move skb_gso_mac_seglen() to skbuff.h with other related functions
>> like skb_gso_network_seglen() so we can use it, and then create
>> skb_gso_validate_mac_len to do the full calculation.
>>
>> Signed-off-by: Daniel Axtens <dja@axtens.net>
>> ---
>> include/linux/skbuff.h | 16 +++++++++++++
>> net/core/skbuff.c | 65 +++++++++++++++++++++++++++++++++++++++-----------
>> net/sched/sch_tbf.c | 10 --------
>> 3 files changed, 67 insertions(+), 24 deletions(-)
>>
>> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
>> index b8e0da6c27d6..242d6773c7c2 100644
>> --- a/include/linux/skbuff.h
>> +++ b/include/linux/skbuff.h
>> @@ -3287,6 +3287,7 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen);
>> void skb_scrub_packet(struct sk_buff *skb, bool xnet);
>> unsigned int skb_gso_transport_seglen(const struct sk_buff *skb);
>> bool skb_gso_validate_mtu(const struct sk_buff *skb, unsigned int mtu);
>> +bool skb_gso_validate_mac_len(const struct sk_buff *skb, unsigned int len);
>> struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features);
>> struct sk_buff *skb_vlan_untag(struct sk_buff *skb);
>> int skb_ensure_writable(struct sk_buff *skb, int write_len);
>> @@ -4120,6 +4121,21 @@ static inline unsigned int skb_gso_network_seglen(const struct sk_buff *skb)
>> return hdr_len + skb_gso_transport_seglen(skb);
>> }
>>
>> +/**
>> + * skb_gso_mac_seglen - Return length of individual segments of a gso packet
>> + *
>> + * @skb: GSO skb
>> + *
>> + * skb_gso_mac_seglen is used to determine the real size of the
>> + * individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4
>> + * headers (TCP/UDP).
>> + */
>> +static inline unsigned int skb_gso_mac_seglen(const struct sk_buff *skb)
>> +{
>> + unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb);
>> + return hdr_len + skb_gso_transport_seglen(skb);
>> +}
>> +
>> /* Local Checksum Offload.
>> * Compute outer checksum based on the assumption that the
>> * inner checksum will be offloaded later.
>> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
>> index 01e8285aea73..55d84ab7d093 100644
>> --- a/net/core/skbuff.c
>> +++ b/net/core/skbuff.c
>> @@ -4914,36 +4914,73 @@ unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
>> EXPORT_SYMBOL_GPL(skb_gso_transport_seglen);
>>
>> /**
>> - * skb_gso_validate_mtu - Return in case such skb fits a given MTU
>> + * skb_gso_size_check - check the skb size, considering GSO_BY_FRAGS
>> *
>> - * @skb: GSO skb
>> - * @mtu: MTU to validate against
>> + * There are a couple of instances where we have a GSO skb, and we
>> + * want to determine what size it would be after it is segmented.
>> *
>> - * skb_gso_validate_mtu validates if a given skb will fit a wanted MTU
>> - * once split.
>> + * We might want to check:
>> + * - L3+L4+payload size (e.g. IP forwarding)
>> + * - L2+L3+L4+payload size (e.g. sanity check before passing to driver)
>> + *
>> + * This is a helper to do that correctly considering GSO_BY_FRAGS.
>> + *
>> + * @seg_len: The segmented length (from skb_gso_*_seglen). In the
>> + * GSO_BY_FRAGS case this will be [header sizes + GSO_BY_FRAGS].
>> + *
>> + * @max_len: The maximum permissible length.
>> + *
>> + * Returns true if the segmented length <= max length.
>> */
>> -bool skb_gso_validate_mtu(const struct sk_buff *skb, unsigned int mtu)
>> -{
>> +static inline bool skb_gso_size_check(const struct sk_buff *skb,
>> + unsigned int seg_len,
>> + unsigned int max_len) {
>> const struct skb_shared_info *shinfo = skb_shinfo(skb);
>> const struct sk_buff *iter;
>> - unsigned int hlen;
>> -
>> - hlen = skb_gso_network_seglen(skb);
>>
>> if (shinfo->gso_size != GSO_BY_FRAGS)
>> - return hlen <= mtu;
>> + return seg_len <= max_len;
>>
>> /* Undo this so we can re-use header sizes */
>> - hlen -= GSO_BY_FRAGS;
>> + seg_len -= GSO_BY_FRAGS;
>>
>> skb_walk_frags(skb, iter) {
>> - if (hlen + skb_headlen(iter) > mtu)
>> + if (seg_len + skb_headlen(iter) > max_len)
>> return false;
>> }
>>
>> return true;
>> }
>> -EXPORT_SYMBOL_GPL(skb_gso_validate_mtu);
>> +
>> +/**
>> + * skb_gso_validate_mtu - Return in case such skb fits a given MTU
>> + *
>> + * @skb: GSO skb
>> + * @mtu: MTU to validate against
>> + *
>> + * skb_gso_validate_mtu validates if a given skb will fit a wanted MTU
>> + * once split.
>> + */
>> +bool skb_gso_validate_mtu(const struct sk_buff *skb, unsigned int mtu)
>> +{
>> + return skb_gso_size_check(skb, skb_gso_network_seglen(skb), mtu);
>> +}
>> +EXPORT_SYMBOL_GPL(skb_gso_validate_network_len);
>
> This export is not matching the function name.
Oh darn it! I fixed this locally and then forgot to run
format-patch. Will fix it in the next spin.
Thanks!
Regards,
Daniel
next prev parent reply other threads:[~2018-01-30 13:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-30 1:14 [PATCH v3 0/2] bnx2x: disable GSO on too-large packets Daniel Axtens
2018-01-30 1:14 ` [PATCH v3 1/2] net: create skb_gso_validate_mac_len() Daniel Axtens
2018-01-30 1:46 ` Eric Dumazet
2018-01-30 1:59 ` Eric Dumazet
2018-01-30 2:42 ` Daniel Axtens
2018-01-30 8:17 ` Marcelo Ricardo Leitner
2018-01-30 13:08 ` Daniel Axtens [this message]
2018-01-30 16:59 ` kbuild test robot
2018-01-30 17:00 ` kbuild test robot
2018-01-30 1:14 ` [PATCH v3 2/2] bnx2x: disable GSO where gso_size is too big for hardware Daniel Axtens
2018-01-30 8:20 ` [PATCH v3 0/2] bnx2x: disable GSO on too-large packets Marcelo Ricardo Leitner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877erzbij8.fsf@linkitivity.dja.id.au \
--to=dja@axtens.net \
--cc=Manish.Chopra@cavium.com \
--cc=jasowang@redhat.com \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pshelar@ovn.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).