All of lore.kernel.org
 help / color / mirror / Atom feed
* What does this code do
@ 2020-03-10 21:42 Andrej Ras
  2020-03-10 22:12 ` Michal Kubecek
  0 siblings, 1 reply; 6+ messages in thread
From: Andrej Ras @ 2020-03-10 21:42 UTC (permalink / raw)
  To: netdev

While browsing the Linux networking code I came across these two lines
in __ip_append_data() which I do not understand.

                /* Check if the remaining data fits into current packet. */
                copy = mtu - skb->len;
                if (copy < length)
                        copy = maxfraglen - skb->len;
                if (copy <= 0) {

Why not just use maxfraglen.

Perhaps someone can explain why this is needed.

Regards

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What does this code do
  2020-03-10 21:42 What does this code do Andrej Ras
@ 2020-03-10 22:12 ` Michal Kubecek
  2020-03-11  4:11   ` Andrej Ras
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Kubecek @ 2020-03-10 22:12 UTC (permalink / raw)
  To: netdev; +Cc: Andrej Ras

On Tue, Mar 10, 2020 at 02:42:11PM -0700, Andrej Ras wrote:
> While browsing the Linux networking code I came across these two lines
> in __ip_append_data() which I do not understand.
> 
>                 /* Check if the remaining data fits into current packet. */
>                 copy = mtu - skb->len;
>                 if (copy < length)
>                         copy = maxfraglen - skb->len;
>                 if (copy <= 0) {
> 
> Why not just use maxfraglen.
> 
> Perhaps someone can explain why this is needed.

This function appends more data to an skb which can already contain some
payload. Therefore you need to take current length (from earlier) into
account, not only newly appended data.

This can be easily enforced e.g. with TCP_CORK or UDP_CORK socket option
or MSG_MORE flag.

Michal Kubecek

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What does this code do
  2020-03-10 22:12 ` Michal Kubecek
@ 2020-03-11  4:11   ` Andrej Ras
  2020-03-11  5:53     ` Michal Kubecek
  0 siblings, 1 reply; 6+ messages in thread
From: Andrej Ras @ 2020-03-11  4:11 UTC (permalink / raw)
  To: Michal Kubecek; +Cc: netdev

I understand that the code is appending data, what I do not understand
is why is it first calculating the remaining space by taking the
difference using the size of mtu and if the difference is <= 0 it
recalculates the difference using maxfraglen. Why not just use
maxfraglen -- All we need to know is how much more data can be added
to the skb.


On Tue, Mar 10, 2020 at 3:12 PM Michal Kubecek <mkubecek@suse.cz> wrote:
>
> On Tue, Mar 10, 2020 at 02:42:11PM -0700, Andrej Ras wrote:
> > While browsing the Linux networking code I came across these two lines
> > in __ip_append_data() which I do not understand.
> >
> >                 /* Check if the remaining data fits into current packet. */
> >                 copy = mtu - skb->len;
> >                 if (copy < length)
> >                         copy = maxfraglen - skb->len;
> >                 if (copy <= 0) {
> >
> > Why not just use maxfraglen.
> >
> > Perhaps someone can explain why this is needed.
>
> This function appends more data to an skb which can already contain some
> payload. Therefore you need to take current length (from earlier) into
> account, not only newly appended data.
>
> This can be easily enforced e.g. with TCP_CORK or UDP_CORK socket option
> or MSG_MORE flag.
>
> Michal Kubecek

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What does this code do
  2020-03-11  4:11   ` Andrej Ras
@ 2020-03-11  5:53     ` Michal Kubecek
  2020-03-11  6:17       ` Andrej Ras
  2020-03-11  7:21       ` Michal Kubecek
  0 siblings, 2 replies; 6+ messages in thread
From: Michal Kubecek @ 2020-03-11  5:53 UTC (permalink / raw)
  To: netdev; +Cc: Andrej Ras

On Tue, Mar 10, 2020 at 09:11:06PM -0700, Andrej Ras wrote:
> On Tue, Mar 10, 2020 at 3:12 PM Michal Kubecek <mkubecek@suse.cz> wrote:
> >
> > On Tue, Mar 10, 2020 at 02:42:11PM -0700, Andrej Ras wrote:
> > > While browsing the Linux networking code I came across these two lines
> > > in __ip_append_data() which I do not understand.
> > >
> > >                 /* Check if the remaining data fits into current packet. */
> > >                 copy = mtu - skb->len;
> > >                 if (copy < length)
> > >                         copy = maxfraglen - skb->len;
> > >                 if (copy <= 0) {
> > >
> > > Why not just use maxfraglen.
> > >
> > > Perhaps someone can explain why this is needed.
> >
> > This function appends more data to an skb which can already contain some
> > payload. Therefore you need to take current length (from earlier) into
> > account, not only newly appended data.
> >
> > This can be easily enforced e.g. with TCP_CORK or UDP_CORK socket option
> > or MSG_MORE flag.
> >
> I understand that the code is appending data, what I do not understand
> is why is it first calculating the remaining space by taking the
> difference using the size of mtu and if the difference is <= 0 it
> recalculates the difference using maxfraglen. Why not just use
> maxfraglen -- All we need to know is how much more data can be added
> to the skb.

Ah, I see. The first test checks if we can fit into an unfragmented
packet so that we check against mtu. If we don't fit, fragmentation will
be needed so that maxfraglen is the limit (maxfraglen can be shorter
than mtu due to the rounding down to a multiple of 8).

Michal Kubecek

(Please do not top post in developer lists.)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What does this code do
  2020-03-11  5:53     ` Michal Kubecek
@ 2020-03-11  6:17       ` Andrej Ras
  2020-03-11  7:21       ` Michal Kubecek
  1 sibling, 0 replies; 6+ messages in thread
From: Andrej Ras @ 2020-03-11  6:17 UTC (permalink / raw)
  To: Michal Kubecek; +Cc: netdev

Thanks a lot for the explanation.

On Tue, Mar 10, 2020 at 10:53 PM Michal Kubecek <mkubecek@suse.cz> wrote:
>
> On Tue, Mar 10, 2020 at 09:11:06PM -0700, Andrej Ras wrote:
> > On Tue, Mar 10, 2020 at 3:12 PM Michal Kubecek <mkubecek@suse.cz> wrote:
> > >
> > > On Tue, Mar 10, 2020 at 02:42:11PM -0700, Andrej Ras wrote:
> > > > While browsing the Linux networking code I came across these two lines
> > > > in __ip_append_data() which I do not understand.
> > > >
> > > >                 /* Check if the remaining data fits into current packet. */
> > > >                 copy = mtu - skb->len;
> > > >                 if (copy < length)
> > > >                         copy = maxfraglen - skb->len;
> > > >                 if (copy <= 0) {
> > > >
> > > > Why not just use maxfraglen.
> > > >
> > > > Perhaps someone can explain why this is needed.
> > >
> > > This function appends more data to an skb which can already contain some
> > > payload. Therefore you need to take current length (from earlier) into
> > > account, not only newly appended data.
> > >
> > > This can be easily enforced e.g. with TCP_CORK or UDP_CORK socket option
> > > or MSG_MORE flag.
> > >
> > I understand that the code is appending data, what I do not understand
> > is why is it first calculating the remaining space by taking the
> > difference using the size of mtu and if the difference is <= 0 it
> > recalculates the difference using maxfraglen. Why not just use
> > maxfraglen -- All we need to know is how much more data can be added
> > to the skb.
>
> Ah, I see. The first test checks if we can fit into an unfragmented
> packet so that we check against mtu. If we don't fit, fragmentation will
> be needed so that maxfraglen is the limit (maxfraglen can be shorter
> than mtu due to the rounding down to a multiple of 8).
>
> Michal Kubecek
>
> (Please do not top post in developer lists.)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What does this code do
  2020-03-11  5:53     ` Michal Kubecek
  2020-03-11  6:17       ` Andrej Ras
@ 2020-03-11  7:21       ` Michal Kubecek
  1 sibling, 0 replies; 6+ messages in thread
From: Michal Kubecek @ 2020-03-11  7:21 UTC (permalink / raw)
  To: netdev; +Cc: Andrej Ras

On Wed, Mar 11, 2020 at 06:53:43AM +0100, Michal Kubecek wrote:
> On Tue, Mar 10, 2020 at 09:11:06PM -0700, Andrej Ras wrote:
> > On Tue, Mar 10, 2020 at 3:12 PM Michal Kubecek <mkubecek@suse.cz> wrote:
> > >
> > > On Tue, Mar 10, 2020 at 02:42:11PM -0700, Andrej Ras wrote:
> > > > While browsing the Linux networking code I came across these two lines
> > > > in __ip_append_data() which I do not understand.
> > > >
> > > >                 /* Check if the remaining data fits into current packet. */
> > > >                 copy = mtu - skb->len;
> > > >                 if (copy < length)
> > > >                         copy = maxfraglen - skb->len;
> > > >                 if (copy <= 0) {
> > > >
> > > > Why not just use maxfraglen.
> > > >
> > > > Perhaps someone can explain why this is needed.
> > >
> > > This function appends more data to an skb which can already contain some
> > > payload. Therefore you need to take current length (from earlier) into
> > > account, not only newly appended data.
> > >
> > > This can be easily enforced e.g. with TCP_CORK or UDP_CORK socket option
> > > or MSG_MORE flag.
> > >
> > I understand that the code is appending data, what I do not understand
> > is why is it first calculating the remaining space by taking the
> > difference using the size of mtu and if the difference is <= 0 it
> > recalculates the difference using maxfraglen. Why not just use
> > maxfraglen -- All we need to know is how much more data can be added
> > to the skb.
> 
> Ah, I see. The first test checks if we can fit into an unfragmented
> packet so that we check against mtu.

Thinking about it again, it would be more precise to say "unfragmented
packet or last fragment" here as it also covers the case when we already
have some fragments and test if we can send the rest (including current
chunk) as last fragment whose length does not need to be a multiple of 8.

Michal Kubecek

>                                      If we don't fit, fragmentation will
> be needed so that maxfraglen is the limit (maxfraglen can be shorter
> than mtu due to the rounding down to a multiple of 8).



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-11  7:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-10 21:42 What does this code do Andrej Ras
2020-03-10 22:12 ` Michal Kubecek
2020-03-11  4:11   ` Andrej Ras
2020-03-11  5:53     ` Michal Kubecek
2020-03-11  6:17       ` Andrej Ras
2020-03-11  7:21       ` Michal Kubecek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.