kni: implement header_ops parse method

Message ID 20180927000224.4011-1-iryzhov@nfware.com (mailing list archive)
State Superseded, archived
Headers
Series kni: implement header_ops parse method |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Igor Ryzhov Sept. 27, 2018, 12:02 a.m. UTC
  Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
---
 kernel/linux/kni/kni_net.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

Stephen Hemminger Sept. 29, 2018, 7:21 a.m. UTC | #1
On Thu, 27 Sep 2018 03:02:24 +0300
Igor Ryzhov <iryzhov@nfware.com> wrote:

> +/*
> + *  Extract hardware address from packet
> + */
> +static int
> +kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
> +{
> +	const struct ethhdr *eth = eth_hdr(skb);
> +
> +	memcpy(haddr, eth->h_source, ETH_ALEN);
> +
> +	return ETH_ALEN;
> +}

Kernel has function ether_addr_copy which is marginally faster and
commonly used.
  
Igor Ryzhov Sept. 29, 2018, 7:19 p.m. UTC | #2
It's just exact copy of eth_header_parse function from Linux kernel.

No problem, can do that with ether_addr_copy.

On Sat, Sep 29, 2018 at 10:22 AM Stephen Hemminger <
stephen@networkplumber.org> wrote:

> On Thu, 27 Sep 2018 03:02:24 +0300
> Igor Ryzhov <iryzhov@nfware.com> wrote:
>
> > +/*
> > + *  Extract hardware address from packet
> > + */
> > +static int
> > +kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
> > +{
> > +     const struct ethhdr *eth = eth_hdr(skb);
> > +
> > +     memcpy(haddr, eth->h_source, ETH_ALEN);
> > +
> > +     return ETH_ALEN;
> > +}
>
> Kernel has function ether_addr_copy which is marginally faster and
> commonly used.
>
  
Igor Ryzhov Sept. 30, 2018, 8:22 a.m. UTC | #3
Hello Stephen,

I looked at KNI code again, memcpy is already used everywhere
(kni_net_header, kni_net_rebuild_header) for MAC address copy.
So I propose to accept the patch as it is.

memcpy can be replaced by ether_addr_copy in all functions at once in
separate patch.

Igor

On Sat, Sep 29, 2018 at 10:19 PM Igor Ryzhov <iryzhov@nfware.com> wrote:

> It's just exact copy of eth_header_parse function from Linux kernel.
>
> No problem, can do that with ether_addr_copy.
>
> On Sat, Sep 29, 2018 at 10:22 AM Stephen Hemminger <
> stephen@networkplumber.org> wrote:
>
>> On Thu, 27 Sep 2018 03:02:24 +0300
>> Igor Ryzhov <iryzhov@nfware.com> wrote:
>>
>> > +/*
>> > + *  Extract hardware address from packet
>> > + */
>> > +static int
>> > +kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
>> > +{
>> > +     const struct ethhdr *eth = eth_hdr(skb);
>> > +
>> > +     memcpy(haddr, eth->h_source, ETH_ALEN);
>> > +
>> > +     return ETH_ALEN;
>> > +}
>>
>> Kernel has function ether_addr_copy which is marginally faster and
>> commonly used.
>>
>
  
Ferruh Yigit Oct. 2, 2018, 4:58 p.m. UTC | #4
On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>

Hi Igor,

What is the motivation to add this support? What is enabled by this?


Meanwhile, why we are not using eth_header_ops, which is already set by
ether_setup().
To disable .cache & .cache_update?

If so why not using relevant eth_header_ops (eth_header, eth_header_parse ..)
instead of implementing ours?

> ---
>  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> index 7fcfa106c..128a5477c 100644
> --- a/kernel/linux/kni/kni_net.c
> +++ b/kernel/linux/kni/kni_net.c
> @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff *skb, struct net_device *dev,
>  	return dev->hard_header_len;
>  }
>  
> +/*
> + *  Extract hardware address from packet
> + */
> +static int
> +kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
> +{
> +	const struct ethhdr *eth = eth_hdr(skb);
> +
> +	memcpy(haddr, eth->h_source, ETH_ALEN);
> +
> +	return ETH_ALEN;
> +}
> +
>  /*
>   * Re-fill the eth header
>   */
> @@ -739,6 +752,7 @@ kni_net_change_carrier(struct net_device *dev, bool new_carrier)
>  
>  static const struct header_ops kni_net_header_ops = {
>  	.create  = kni_net_header,
> +	.parse   = kni_net_header_parse,
>  #ifdef HAVE_REBUILD_HEADER
>  	.rebuild = kni_net_rebuild_header,
>  #endif /* < 4.1.0  */
>
  
Igor Ryzhov Nov. 30, 2018, 7:07 p.m. UTC | #5
Hi Ferruh,

header_ops.parse method is used by raw-sockets to fill sockaddr_ll
structure.
It is used, for example, in isisd for frrouting.

Regarding your question about eth_header_ops – I, unfortunately, don't know
why .cache and .cache_update are disabled for KNI.
I also think that it will be better to use default eth_header_ops.

Best regards,
Igor

On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
> > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
>
> Hi Igor,
>
> What is the motivation to add this support? What is enabled by this?
>
>
> Meanwhile, why we are not using eth_header_ops, which is already set by
> ether_setup().
> To disable .cache & .cache_update?
>
> If so why not using relevant eth_header_ops (eth_header, eth_header_parse
> ..)
> instead of implementing ours?
>
> > ---
> >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> > index 7fcfa106c..128a5477c 100644
> > --- a/kernel/linux/kni/kni_net.c
> > +++ b/kernel/linux/kni/kni_net.c
> > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff *skb, struct
> net_device *dev,
> >       return dev->hard_header_len;
> >  }
> >
> > +/*
> > + *  Extract hardware address from packet
> > + */
> > +static int
> > +kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
> > +{
> > +     const struct ethhdr *eth = eth_hdr(skb);
> > +
> > +     memcpy(haddr, eth->h_source, ETH_ALEN);
> > +
> > +     return ETH_ALEN;
> > +}
> > +
> >  /*
> >   * Re-fill the eth header
> >   */
> > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct net_device *dev, bool
> new_carrier)
> >
> >  static const struct header_ops kni_net_header_ops = {
> >       .create  = kni_net_header,
> > +     .parse   = kni_net_header_parse,
> >  #ifdef HAVE_REBUILD_HEADER
> >       .rebuild = kni_net_rebuild_header,
> >  #endif /* < 4.1.0  */
> >
>
>
  
Igor Ryzhov Jan. 24, 2019, 9:18 a.m. UTC | #6
Hi Ferruh,

What about this patch?
Can you merge it as-is, or should I change it to use relevant
eth_header_ops functions? Or maybe completely use eth_header_ops?

Best regards,
Igor

On Fri, Nov 30, 2018 at 10:07 PM Igor Ryzhov <iryzhov@nfware.com> wrote:

> Hi Ferruh,
>
> header_ops.parse method is used by raw-sockets to fill sockaddr_ll
> structure.
> It is used, for example, in isisd for frrouting.
>
> Regarding your question about eth_header_ops – I, unfortunately, don't
> know why .cache and .cache_update are disabled for KNI.
> I also think that it will be better to use default eth_header_ops.
>
> Best regards,
> Igor
>
> On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit <ferruh.yigit@intel.com>
> wrote:
>
>> On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
>> > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
>>
>> Hi Igor,
>>
>> What is the motivation to add this support? What is enabled by this?
>>
>>
>> Meanwhile, why we are not using eth_header_ops, which is already set by
>> ether_setup().
>> To disable .cache & .cache_update?
>>
>> If so why not using relevant eth_header_ops (eth_header, eth_header_parse
>> ..)
>> instead of implementing ours?
>>
>> > ---
>> >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
>> >  1 file changed, 14 insertions(+)
>> >
>> > diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
>> > index 7fcfa106c..128a5477c 100644
>> > --- a/kernel/linux/kni/kni_net.c
>> > +++ b/kernel/linux/kni/kni_net.c
>> > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff *skb, struct
>> net_device *dev,
>> >       return dev->hard_header_len;
>> >  }
>> >
>> > +/*
>> > + *  Extract hardware address from packet
>> > + */
>> > +static int
>> > +kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
>> > +{
>> > +     const struct ethhdr *eth = eth_hdr(skb);
>> > +
>> > +     memcpy(haddr, eth->h_source, ETH_ALEN);
>> > +
>> > +     return ETH_ALEN;
>> > +}
>> > +
>> >  /*
>> >   * Re-fill the eth header
>> >   */
>> > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct net_device *dev, bool
>> new_carrier)
>> >
>> >  static const struct header_ops kni_net_header_ops = {
>> >       .create  = kni_net_header,
>> > +     .parse   = kni_net_header_parse,
>> >  #ifdef HAVE_REBUILD_HEADER
>> >       .rebuild = kni_net_rebuild_header,
>> >  #endif /* < 4.1.0  */
>> >
>>
>>
  
Ferruh Yigit Jan. 24, 2019, 2:10 p.m. UTC | #7
On 1/24/2019 9:18 AM, Igor Ryzhov wrote:
> Hi Ferruh,
> 
> What about this patch?
> Can you merge it as-is, or should I change it to use relevant eth_header_ops
> functions? Or maybe completely use eth_header_ops?

Hi Igor,

I am not clear about motivation of the patch, what use case enabled by this
patch? What is not working with current code?
I am for rejecting the patch without need justified.

And if the need is justified, still there is a question that why not use
'eth_header_parse()' directly but implement our copy?


And an extended question/investigation about why not use 'eth_header_ops', which
seems done intentionally but I am missing the reasoning.

> 
> Best regards,
> Igor
> 
> On Fri, Nov 30, 2018 at 10:07 PM Igor Ryzhov <iryzhov@nfware.com
> <mailto:iryzhov@nfware.com>> wrote:
> 
>     Hi Ferruh,
> 
>     header_ops.parse method is used by raw-sockets to fill sockaddr_ll structure.
>     It is used, for example, in isisd for frrouting.
> 
>     Regarding your question about eth_header_ops – I, unfortunately, don't know
>     why .cache and .cache_update are disabled for KNI.
>     I also think that it will be better to use default eth_header_ops.
> 
>     Best regards,
>     Igor
> 
>     On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit <ferruh.yigit@intel.com
>     <mailto:ferruh.yigit@intel.com>> wrote:
> 
>         On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
>         > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com
>         <mailto:iryzhov@nfware.com>>
> 
>         Hi Igor,
> 
>         What is the motivation to add this support? What is enabled by this?
> 
> 
>         Meanwhile, why we are not using eth_header_ops, which is already set by
>         ether_setup().
>         To disable .cache & .cache_update?
> 
>         If so why not using relevant eth_header_ops (eth_header,
>         eth_header_parse ..)
>         instead of implementing ours?
> 
>         > ---
>         >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
>         >  1 file changed, 14 insertions(+)
>         >
>         > diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
>         > index 7fcfa106c..128a5477c 100644
>         > --- a/kernel/linux/kni/kni_net.c
>         > +++ b/kernel/linux/kni/kni_net.c
>         > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff *skb, struct
>         net_device *dev,
>         >       return dev->hard_header_len;
>         >  }
>         > 
>         > +/*
>         > + *  Extract hardware address from packet
>         > + */
>         > +static int
>         > +kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
>         > +{
>         > +     const struct ethhdr *eth = eth_hdr(skb);
>         > +
>         > +     memcpy(haddr, eth->h_source, ETH_ALEN);
>         > +
>         > +     return ETH_ALEN;
>         > +}
>         > +
>         >  /*
>         >   * Re-fill the eth header
>         >   */
>         > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct net_device *dev,
>         bool new_carrier)
>         > 
>         >  static const struct header_ops kni_net_header_ops = {
>         >       .create  = kni_net_header,
>         > +     .parse   = kni_net_header_parse,
>         >  #ifdef HAVE_REBUILD_HEADER
>         >       .rebuild = kni_net_rebuild_header,
>         >  #endif /* < 4.1.0  */
>         >
>
  
Igor Ryzhov Jan. 24, 2019, 4:35 p.m. UTC | #8
Hi Ferruh,

I already answered your question in my previous email, header_ops.parse
method is used by packet(7) interface for packet parsing and filling
sockaddr_ll structure.
Here is the link on the usage –
https://elixir.bootlin.com/linux/latest/source/net/packet/af_packet.c#L2100

Regarding the question about eth_header_ops usage:
Right now both already existing functions, kni_net_header and
kni_net_rebuild_header, are implemented as copies, not using eth_header_ops
functions.
That's why I think my patch should be accepted as is, and the problem of
eth_header_ops usage should be investigated separately, and possibly
resolved by a separate patch.

Best regards,
Igor

On Thu, Jan 24, 2019 at 5:10 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> On 1/24/2019 9:18 AM, Igor Ryzhov wrote:
> > Hi Ferruh,
> >
> > What about this patch?
> > Can you merge it as-is, or should I change it to use relevant
> eth_header_ops
> > functions? Or maybe completely use eth_header_ops?
>
> Hi Igor,
>
> I am not clear about motivation of the patch, what use case enabled by this
> patch? What is not working with current code?
> I am for rejecting the patch without need justified.
>
> And if the need is justified, still there is a question that why not use
> 'eth_header_parse()' directly but implement our copy?
>
>
> And an extended question/investigation about why not use 'eth_header_ops',
> which
> seems done intentionally but I am missing the reasoning.
>
> >
> > Best regards,
> > Igor
> >
> > On Fri, Nov 30, 2018 at 10:07 PM Igor Ryzhov <iryzhov@nfware.com
> > <mailto:iryzhov@nfware.com>> wrote:
> >
> >     Hi Ferruh,
> >
> >     header_ops.parse method is used by raw-sockets to fill sockaddr_ll
> structure.
> >     It is used, for example, in isisd for frrouting.
> >
> >     Regarding your question about eth_header_ops – I, unfortunately,
> don't know
> >     why .cache and .cache_update are disabled for KNI.
> >     I also think that it will be better to use default eth_header_ops.
> >
> >     Best regards,
> >     Igor
> >
> >     On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit <ferruh.yigit@intel.com
> >     <mailto:ferruh.yigit@intel.com>> wrote:
> >
> >         On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
> >         > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com
> >         <mailto:iryzhov@nfware.com>>
> >
> >         Hi Igor,
> >
> >         What is the motivation to add this support? What is enabled by
> this?
> >
> >
> >         Meanwhile, why we are not using eth_header_ops, which is already
> set by
> >         ether_setup().
> >         To disable .cache & .cache_update?
> >
> >         If so why not using relevant eth_header_ops (eth_header,
> >         eth_header_parse ..)
> >         instead of implementing ours?
> >
> >         > ---
> >         >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
> >         >  1 file changed, 14 insertions(+)
> >         >
> >         > diff --git a/kernel/linux/kni/kni_net.c
> b/kernel/linux/kni/kni_net.c
> >         > index 7fcfa106c..128a5477c 100644
> >         > --- a/kernel/linux/kni/kni_net.c
> >         > +++ b/kernel/linux/kni/kni_net.c
> >         > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff *skb, struct
> >         net_device *dev,
> >         >       return dev->hard_header_len;
> >         >  }
> >         >
> >         > +/*
> >         > + *  Extract hardware address from packet
> >         > + */
> >         > +static int
> >         > +kni_net_header_parse(const struct sk_buff *skb, unsigned char
> *haddr)
> >         > +{
> >         > +     const struct ethhdr *eth = eth_hdr(skb);
> >         > +
> >         > +     memcpy(haddr, eth->h_source, ETH_ALEN);
> >         > +
> >         > +     return ETH_ALEN;
> >         > +}
> >         > +
> >         >  /*
> >         >   * Re-fill the eth header
> >         >   */
> >         > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct net_device
> *dev,
> >         bool new_carrier)
> >         >
> >         >  static const struct header_ops kni_net_header_ops = {
> >         >       .create  = kni_net_header,
> >         > +     .parse   = kni_net_header_parse,
> >         >  #ifdef HAVE_REBUILD_HEADER
> >         >       .rebuild = kni_net_rebuild_header,
> >         >  #endif /* < 4.1.0  */
> >         >
> >
>
>
  
Ferruh Yigit Jan. 24, 2019, 5:15 p.m. UTC | #9
On 1/24/2019 4:35 PM, Igor Ryzhov wrote:
> Hi Ferruh,
> 
> I already answered your question in my previous email, header_ops.parse method
> is used by packet(7) interface for packet parsing and filling sockaddr_ll structure.
> Here is the link on the usage –
> https://elixir.bootlin.com/linux/latest/source/net/packet/af_packet.c#L2100

I saw your previous reply. That is why changed the question slightly, from 'what
it does' to 'what is the use case'.
Trying to understand do we need it, please help me understand.

> 
> Regarding the question about eth_header_ops usage:
> Right now both already existing functions, kni_net_header and
> kni_net_rebuild_header, are implemented as copies, not using eth_header_ops
> functions.

OK, I see your reasoning, but if there is an already Linux API that does what we
want, I suggest calling it instead of re-implementing it, unless there is a good
reason to not do so.

> That's why I think my patch should be accepted as is, and the problem of
> eth_header_ops usage should be investigated separately, and possibly resolved by
> a separate patch.

Agreed, eth_header_ops usage should be investigated separately.

> 
> Best regards,
> Igor
> 
> On Thu, Jan 24, 2019 at 5:10 PM Ferruh Yigit <ferruh.yigit@intel.com
> <mailto:ferruh.yigit@intel.com>> wrote:
> 
>     On 1/24/2019 9:18 AM, Igor Ryzhov wrote:
>     > Hi Ferruh,
>     >
>     > What about this patch?
>     > Can you merge it as-is, or should I change it to use relevant eth_header_ops
>     > functions? Or maybe completely use eth_header_ops?
> 
>     Hi Igor,
> 
>     I am not clear about motivation of the patch, what use case enabled by this
>     patch? What is not working with current code?
>     I am for rejecting the patch without need justified.
> 
>     And if the need is justified, still there is a question that why not use
>     'eth_header_parse()' directly but implement our copy?
> 
> 
>     And an extended question/investigation about why not use 'eth_header_ops', which
>     seems done intentionally but I am missing the reasoning.
> 
>     >
>     > Best regards,
>     > Igor
>     >
>     > On Fri, Nov 30, 2018 at 10:07 PM Igor Ryzhov <iryzhov@nfware.com
>     <mailto:iryzhov@nfware.com>
>     > <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>> wrote:
>     >
>     >     Hi Ferruh,
>     >
>     >     header_ops.parse method is used by raw-sockets to fill sockaddr_ll
>     structure.
>     >     It is used, for example, in isisd for frrouting.
>     >
>     >     Regarding your question about eth_header_ops – I, unfortunately, don't
>     know
>     >     why .cache and .cache_update are disabled for KNI.
>     >     I also think that it will be better to use default eth_header_ops.
>     >
>     >     Best regards,
>     >     Igor
>     >
>     >     On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit <ferruh.yigit@intel.com
>     <mailto:ferruh.yigit@intel.com>
>     >     <mailto:ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>>> wrote:
>     >
>     >         On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
>     >         > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com
>     <mailto:iryzhov@nfware.com>
>     >         <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>>
>     >
>     >         Hi Igor,
>     >
>     >         What is the motivation to add this support? What is enabled by this?
>     >
>     >
>     >         Meanwhile, why we are not using eth_header_ops, which is already
>     set by
>     >         ether_setup().
>     >         To disable .cache & .cache_update?
>     >
>     >         If so why not using relevant eth_header_ops (eth_header,
>     >         eth_header_parse ..)
>     >         instead of implementing ours?
>     >
>     >         > ---
>     >         >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
>     >         >  1 file changed, 14 insertions(+)
>     >         >
>     >         > diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
>     >         > index 7fcfa106c..128a5477c 100644
>     >         > --- a/kernel/linux/kni/kni_net.c
>     >         > +++ b/kernel/linux/kni/kni_net.c
>     >         > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff *skb, struct
>     >         net_device *dev,
>     >         >       return dev->hard_header_len;
>     >         >  }
>     >         > 
>     >         > +/*
>     >         > + *  Extract hardware address from packet
>     >         > + */
>     >         > +static int
>     >         > +kni_net_header_parse(const struct sk_buff *skb, unsigned char
>     *haddr)
>     >         > +{
>     >         > +     const struct ethhdr *eth = eth_hdr(skb);
>     >         > +
>     >         > +     memcpy(haddr, eth->h_source, ETH_ALEN);
>     >         > +
>     >         > +     return ETH_ALEN;
>     >         > +}
>     >         > +
>     >         >  /*
>     >         >   * Re-fill the eth header
>     >         >   */
>     >         > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct net_device *dev,
>     >         bool new_carrier)
>     >         > 
>     >         >  static const struct header_ops kni_net_header_ops = {
>     >         >       .create  = kni_net_header,
>     >         > +     .parse   = kni_net_header_parse,
>     >         >  #ifdef HAVE_REBUILD_HEADER
>     >         >       .rebuild = kni_net_rebuild_header,
>     >         >  #endif /* < 4.1.0  */
>     >         >
>     >
>
  
Igor Ryzhov Jan. 24, 2019, 6:05 p.m. UTC | #10
Hi Ferruh,

Ok, no problem. Generally, it is needed for all applications using
packet(7) interface, running over KNI interfaces.
More specifically, one example of such application is FRRouting, I suppose
you are familiar with it.
FRR's ISIS daemon is using AF_PACKET sockets and checking received
sockaddr_ll.
Here is the link on one of the usages –
https://github.com/FRRouting/frr/blob/master/isisd/isis_pfpacket.c#L294

When we are good with motivation, I'll send v2 using eth_header_parse.

Best regards,
Igor

On Thu, Jan 24, 2019 at 8:15 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> On 1/24/2019 4:35 PM, Igor Ryzhov wrote:
> > Hi Ferruh,
> >
> > I already answered your question in my previous email, header_ops.parse
> method
> > is used by packet(7) interface for packet parsing and filling
> sockaddr_ll structure.
> > Here is the link on the usage –
> >
> https://elixir.bootlin.com/linux/latest/source/net/packet/af_packet.c#L2100
>
> I saw your previous reply. That is why changed the question slightly, from
> 'what
> it does' to 'what is the use case'.
> Trying to understand do we need it, please help me understand.
>
> >
> > Regarding the question about eth_header_ops usage:
> > Right now both already existing functions, kni_net_header and
> > kni_net_rebuild_header, are implemented as copies, not using
> eth_header_ops
> > functions.
>
> OK, I see your reasoning, but if there is an already Linux API that does
> what we
> want, I suggest calling it instead of re-implementing it, unless there is
> a good
> reason to not do so.
>
> > That's why I think my patch should be accepted as is, and the problem of
> > eth_header_ops usage should be investigated separately, and possibly
> resolved by
> > a separate patch.
>
> Agreed, eth_header_ops usage should be investigated separately.
>
> >
> > Best regards,
> > Igor
> >
> > On Thu, Jan 24, 2019 at 5:10 PM Ferruh Yigit <ferruh.yigit@intel.com
> > <mailto:ferruh.yigit@intel.com>> wrote:
> >
> >     On 1/24/2019 9:18 AM, Igor Ryzhov wrote:
> >     > Hi Ferruh,
> >     >
> >     > What about this patch?
> >     > Can you merge it as-is, or should I change it to use relevant
> eth_header_ops
> >     > functions? Or maybe completely use eth_header_ops?
> >
> >     Hi Igor,
> >
> >     I am not clear about motivation of the patch, what use case enabled
> by this
> >     patch? What is not working with current code?
> >     I am for rejecting the patch without need justified.
> >
> >     And if the need is justified, still there is a question that why not
> use
> >     'eth_header_parse()' directly but implement our copy?
> >
> >
> >     And an extended question/investigation about why not use
> 'eth_header_ops', which
> >     seems done intentionally but I am missing the reasoning.
> >
> >     >
> >     > Best regards,
> >     > Igor
> >     >
> >     > On Fri, Nov 30, 2018 at 10:07 PM Igor Ryzhov <iryzhov@nfware.com
> >     <mailto:iryzhov@nfware.com>
> >     > <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>> wrote:
> >     >
> >     >     Hi Ferruh,
> >     >
> >     >     header_ops.parse method is used by raw-sockets to
> fill sockaddr_ll
> >     structure.
> >     >     It is used, for example, in isisd for frrouting.
> >     >
> >     >     Regarding your question about eth_header_ops – I,
> unfortunately, don't
> >     know
> >     >     why .cache and .cache_update are disabled for KNI.
> >     >     I also think that it will be better to use default
> eth_header_ops.
> >     >
> >     >     Best regards,
> >     >     Igor
> >     >
> >     >     On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit <
> ferruh.yigit@intel.com
> >     <mailto:ferruh.yigit@intel.com>
> >     >     <mailto:ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>>>
> wrote:
> >     >
> >     >         On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
> >     >         > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com
> >     <mailto:iryzhov@nfware.com>
> >     >         <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>>
> >     >
> >     >         Hi Igor,
> >     >
> >     >         What is the motivation to add this support? What is
> enabled by this?
> >     >
> >     >
> >     >         Meanwhile, why we are not using eth_header_ops, which is
> already
> >     set by
> >     >         ether_setup().
> >     >         To disable .cache & .cache_update?
> >     >
> >     >         If so why not using relevant eth_header_ops (eth_header,
> >     >         eth_header_parse ..)
> >     >         instead of implementing ours?
> >     >
> >     >         > ---
> >     >         >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
> >     >         >  1 file changed, 14 insertions(+)
> >     >         >
> >     >         > diff --git a/kernel/linux/kni/kni_net.c
> b/kernel/linux/kni/kni_net.c
> >     >         > index 7fcfa106c..128a5477c 100644
> >     >         > --- a/kernel/linux/kni/kni_net.c
> >     >         > +++ b/kernel/linux/kni/kni_net.c
> >     >         > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff *skb,
> struct
> >     >         net_device *dev,
> >     >         >       return dev->hard_header_len;
> >     >         >  }
> >     >         >
> >     >         > +/*
> >     >         > + *  Extract hardware address from packet
> >     >         > + */
> >     >         > +static int
> >     >         > +kni_net_header_parse(const struct sk_buff *skb,
> unsigned char
> >     *haddr)
> >     >         > +{
> >     >         > +     const struct ethhdr *eth = eth_hdr(skb);
> >     >         > +
> >     >         > +     memcpy(haddr, eth->h_source, ETH_ALEN);
> >     >         > +
> >     >         > +     return ETH_ALEN;
> >     >         > +}
> >     >         > +
> >     >         >  /*
> >     >         >   * Re-fill the eth header
> >     >         >   */
> >     >         > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct
> net_device *dev,
> >     >         bool new_carrier)
> >     >         >
> >     >         >  static const struct header_ops kni_net_header_ops = {
> >     >         >       .create  = kni_net_header,
> >     >         > +     .parse   = kni_net_header_parse,
> >     >         >  #ifdef HAVE_REBUILD_HEADER
> >     >         >       .rebuild = kni_net_rebuild_header,
> >     >         >  #endif /* < 4.1.0  */
> >     >         >
> >     >
> >
>
>
  
Igor Ryzhov April 8, 2019, 4:59 p.m. UTC | #11
Hi Ferruh,

Can we proceed with this patch?

Igor

On Thu, Jan 24, 2019 at 9:05 PM Igor Ryzhov <iryzhov@nfware.com> wrote:

> Hi Ferruh,
>
> Ok, no problem. Generally, it is needed for all applications using
> packet(7) interface, running over KNI interfaces.
> More specifically, one example of such application is FRRouting, I suppose
> you are familiar with it.
> FRR's ISIS daemon is using AF_PACKET sockets and checking received
> sockaddr_ll.
> Here is the link on one of the usages –
> https://github.com/FRRouting/frr/blob/master/isisd/isis_pfpacket.c#L294
>
> When we are good with motivation, I'll send v2 using eth_header_parse.
>
> Best regards,
> Igor
>
> On Thu, Jan 24, 2019 at 8:15 PM Ferruh Yigit <ferruh.yigit@intel.com>
> wrote:
>
>> On 1/24/2019 4:35 PM, Igor Ryzhov wrote:
>> > Hi Ferruh,
>> >
>> > I already answered your question in my previous email, header_ops.parse
>> method
>> > is used by packet(7) interface for packet parsing and filling
>> sockaddr_ll structure.
>> > Here is the link on the usage –
>> >
>> https://elixir.bootlin.com/linux/latest/source/net/packet/af_packet.c#L2100
>>
>> I saw your previous reply. That is why changed the question slightly,
>> from 'what
>> it does' to 'what is the use case'.
>> Trying to understand do we need it, please help me understand.
>>
>> >
>> > Regarding the question about eth_header_ops usage:
>> > Right now both already existing functions, kni_net_header and
>> > kni_net_rebuild_header, are implemented as copies, not using
>> eth_header_ops
>> > functions.
>>
>> OK, I see your reasoning, but if there is an already Linux API that does
>> what we
>> want, I suggest calling it instead of re-implementing it, unless there is
>> a good
>> reason to not do so.
>>
>> > That's why I think my patch should be accepted as is, and the problem of
>> > eth_header_ops usage should be investigated separately, and possibly
>> resolved by
>> > a separate patch.
>>
>> Agreed, eth_header_ops usage should be investigated separately.
>>
>> >
>> > Best regards,
>> > Igor
>> >
>> > On Thu, Jan 24, 2019 at 5:10 PM Ferruh Yigit <ferruh.yigit@intel.com
>> > <mailto:ferruh.yigit@intel.com>> wrote:
>> >
>> >     On 1/24/2019 9:18 AM, Igor Ryzhov wrote:
>> >     > Hi Ferruh,
>> >     >
>> >     > What about this patch?
>> >     > Can you merge it as-is, or should I change it to use relevant
>> eth_header_ops
>> >     > functions? Or maybe completely use eth_header_ops?
>> >
>> >     Hi Igor,
>> >
>> >     I am not clear about motivation of the patch, what use case enabled
>> by this
>> >     patch? What is not working with current code?
>> >     I am for rejecting the patch without need justified.
>> >
>> >     And if the need is justified, still there is a question that why
>> not use
>> >     'eth_header_parse()' directly but implement our copy?
>> >
>> >
>> >     And an extended question/investigation about why not use
>> 'eth_header_ops', which
>> >     seems done intentionally but I am missing the reasoning.
>> >
>> >     >
>> >     > Best regards,
>> >     > Igor
>> >     >
>> >     > On Fri, Nov 30, 2018 at 10:07 PM Igor Ryzhov <iryzhov@nfware.com
>> >     <mailto:iryzhov@nfware.com>
>> >     > <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>> wrote:
>> >     >
>> >     >     Hi Ferruh,
>> >     >
>> >     >     header_ops.parse method is used by raw-sockets to
>> fill sockaddr_ll
>> >     structure.
>> >     >     It is used, for example, in isisd for frrouting.
>> >     >
>> >     >     Regarding your question about eth_header_ops – I,
>> unfortunately, don't
>> >     know
>> >     >     why .cache and .cache_update are disabled for KNI.
>> >     >     I also think that it will be better to use default
>> eth_header_ops.
>> >     >
>> >     >     Best regards,
>> >     >     Igor
>> >     >
>> >     >     On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit <
>> ferruh.yigit@intel.com
>> >     <mailto:ferruh.yigit@intel.com>
>> >     >     <mailto:ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>>>
>> wrote:
>> >     >
>> >     >         On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
>> >     >         > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com
>> >     <mailto:iryzhov@nfware.com>
>> >     >         <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>>
>> >     >
>> >     >         Hi Igor,
>> >     >
>> >     >         What is the motivation to add this support? What is
>> enabled by this?
>> >     >
>> >     >
>> >     >         Meanwhile, why we are not using eth_header_ops, which is
>> already
>> >     set by
>> >     >         ether_setup().
>> >     >         To disable .cache & .cache_update?
>> >     >
>> >     >         If so why not using relevant eth_header_ops (eth_header,
>> >     >         eth_header_parse ..)
>> >     >         instead of implementing ours?
>> >     >
>> >     >         > ---
>> >     >         >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
>> >     >         >  1 file changed, 14 insertions(+)
>> >     >         >
>> >     >         > diff --git a/kernel/linux/kni/kni_net.c
>> b/kernel/linux/kni/kni_net.c
>> >     >         > index 7fcfa106c..128a5477c 100644
>> >     >         > --- a/kernel/linux/kni/kni_net.c
>> >     >         > +++ b/kernel/linux/kni/kni_net.c
>> >     >         > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff
>> *skb, struct
>> >     >         net_device *dev,
>> >     >         >       return dev->hard_header_len;
>> >     >         >  }
>> >     >         >
>> >     >         > +/*
>> >     >         > + *  Extract hardware address from packet
>> >     >         > + */
>> >     >         > +static int
>> >     >         > +kni_net_header_parse(const struct sk_buff *skb,
>> unsigned char
>> >     *haddr)
>> >     >         > +{
>> >     >         > +     const struct ethhdr *eth = eth_hdr(skb);
>> >     >         > +
>> >     >         > +     memcpy(haddr, eth->h_source, ETH_ALEN);
>> >     >         > +
>> >     >         > +     return ETH_ALEN;
>> >     >         > +}
>> >     >         > +
>> >     >         >  /*
>> >     >         >   * Re-fill the eth header
>> >     >         >   */
>> >     >         > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct
>> net_device *dev,
>> >     >         bool new_carrier)
>> >     >         >
>> >     >         >  static const struct header_ops kni_net_header_ops = {
>> >     >         >       .create  = kni_net_header,
>> >     >         > +     .parse   = kni_net_header_parse,
>> >     >         >  #ifdef HAVE_REBUILD_HEADER
>> >     >         >       .rebuild = kni_net_rebuild_header,
>> >     >         >  #endif /* < 4.1.0  */
>> >     >         >
>> >     >
>> >
>>
>>
  
Ferruh Yigit April 9, 2019, 8:30 p.m. UTC | #12
On 4/8/2019 5:59 PM, Igor Ryzhov wrote:
> Hi Ferruh,
> 
> Can we proceed with this patch?
> 
> Igor
> 
> On Thu, Jan 24, 2019 at 9:05 PM Igor Ryzhov <iryzhov@nfware.com
> <mailto:iryzhov@nfware.com>> wrote:
> 
>     Hi Ferruh,
> 
>     Ok, no problem. Generally, it is needed for all applications using packet(7)
>     interface, running over KNI interfaces.
>     More specifically, one example of such application is FRRouting, I suppose
>     you are familiar with it.
>     FRR's ISIS daemon is using AF_PACKET sockets and checking received sockaddr_ll.
>     Here is the link on one of the usages
>     – https://github.com/FRRouting/frr/blob/master/isisd/isis_pfpacket.c#L294
> 
>     When we are good with motivation, I'll send v2 using eth_header_parse.

Hi Igor,

Sorry for the delay, thanks for the clarification on patch.
Can you please send v2 with 'eth_header_parse'? And please include above
information in commit log.

Thanks,
ferruh

> 
>     Best regards,
>     Igor
> 
>     On Thu, Jan 24, 2019 at 8:15 PM Ferruh Yigit <ferruh.yigit@intel.com
>     <mailto:ferruh.yigit@intel.com>> wrote:
> 
>         On 1/24/2019 4:35 PM, Igor Ryzhov wrote:
>         > Hi Ferruh,
>         >
>         > I already answered your question in my previous email,
>         header_ops.parse method
>         > is used by packet(7) interface for packet parsing and filling
>         sockaddr_ll structure.
>         > Here is the link on the usage –
>         >
>         https://elixir.bootlin.com/linux/latest/source/net/packet/af_packet.c#L2100
> 
>         I saw your previous reply. That is why changed the question slightly,
>         from 'what
>         it does' to 'what is the use case'.
>         Trying to understand do we need it, please help me understand.
> 
>         >
>         > Regarding the question about eth_header_ops usage:
>         > Right now both already existing functions, kni_net_header and
>         > kni_net_rebuild_header, are implemented as copies, not using
>         eth_header_ops
>         > functions.
> 
>         OK, I see your reasoning, but if there is an already Linux API that does
>         what we
>         want, I suggest calling it instead of re-implementing it, unless there
>         is a good
>         reason to not do so.
> 
>         > That's why I think my patch should be accepted as is, and the problem of
>         > eth_header_ops usage should be investigated separately, and possibly
>         resolved by
>         > a separate patch.
> 
>         Agreed, eth_header_ops usage should be investigated separately.
> 
>         >
>         > Best regards,
>         > Igor
>         >
>         > On Thu, Jan 24, 2019 at 5:10 PM Ferruh Yigit <ferruh.yigit@intel.com
>         <mailto:ferruh.yigit@intel.com>
>         > <mailto:ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>>> wrote:
>         >
>         >     On 1/24/2019 9:18 AM, Igor Ryzhov wrote:
>         >     > Hi Ferruh,
>         >     >
>         >     > What about this patch?
>         >     > Can you merge it as-is, or should I change it to use relevant
>         eth_header_ops
>         >     > functions? Or maybe completely use eth_header_ops?
>         >
>         >     Hi Igor,
>         >
>         >     I am not clear about motivation of the patch, what use case
>         enabled by this
>         >     patch? What is not working with current code?
>         >     I am for rejecting the patch without need justified.
>         >
>         >     And if the need is justified, still there is a question that why
>         not use
>         >     'eth_header_parse()' directly but implement our copy?
>         >
>         >
>         >     And an extended question/investigation about why not use
>         'eth_header_ops', which
>         >     seems done intentionally but I am missing the reasoning.
>         >
>         >     >
>         >     > Best regards,
>         >     > Igor
>         >     >
>         >     > On Fri, Nov 30, 2018 at 10:07 PM Igor Ryzhov <iryzhov@nfware.com
>         <mailto:iryzhov@nfware.com>
>         >     <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>
>         >     > <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>
>         <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>>> wrote:
>         >     >
>         >     >     Hi Ferruh,
>         >     >
>         >     >     header_ops.parse method is used by raw-sockets to
>         fill sockaddr_ll
>         >     structure.
>         >     >     It is used, for example, in isisd for frrouting.
>         >     >
>         >     >     Regarding your question about eth_header_ops – I,
>         unfortunately, don't
>         >     know
>         >     >     why .cache and .cache_update are disabled for KNI.
>         >     >     I also think that it will be better to use default
>         eth_header_ops.
>         >     >
>         >     >     Best regards,
>         >     >     Igor
>         >     >
>         >     >     On Tue, Oct 2, 2018 at 7:58 PM Ferruh Yigit
>         <ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>
>         >     <mailto:ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>>
>         >     >     <mailto:ferruh.yigit@intel.com
>         <mailto:ferruh.yigit@intel.com> <mailto:ferruh.yigit@intel.com
>         <mailto:ferruh.yigit@intel.com>>>> wrote:
>         >     >
>         >     >         On 9/27/2018 1:02 AM, Igor Ryzhov wrote:
>         >     >         > Signed-off-by: Igor Ryzhov <iryzhov@nfware.com
>         <mailto:iryzhov@nfware.com>
>         >     <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>
>         >     >         <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>
>         <mailto:iryzhov@nfware.com <mailto:iryzhov@nfware.com>>>>
>         >     >
>         >     >         Hi Igor,
>         >     >
>         >     >         What is the motivation to add this support? What is
>         enabled by this?
>         >     >
>         >     >
>         >     >         Meanwhile, why we are not using eth_header_ops, which is
>         already
>         >     set by
>         >     >         ether_setup().
>         >     >         To disable .cache & .cache_update?
>         >     >
>         >     >         If so why not using relevant eth_header_ops (eth_header,
>         >     >         eth_header_parse ..)
>         >     >         instead of implementing ours?
>         >     >
>         >     >         > ---
>         >     >         >  kernel/linux/kni/kni_net.c | 14 ++++++++++++++
>         >     >         >  1 file changed, 14 insertions(+)
>         >     >         >
>         >     >         > diff --git a/kernel/linux/kni/kni_net.c
>         b/kernel/linux/kni/kni_net.c
>         >     >         > index 7fcfa106c..128a5477c 100644
>         >     >         > --- a/kernel/linux/kni/kni_net.c
>         >     >         > +++ b/kernel/linux/kni/kni_net.c
>         >     >         > @@ -678,6 +678,19 @@ kni_net_header(struct sk_buff
>         *skb, struct
>         >     >         net_device *dev,
>         >     >         >       return dev->hard_header_len;
>         >     >         >  }
>         >     >         > 
>         >     >         > +/*
>         >     >         > + *  Extract hardware address from packet
>         >     >         > + */
>         >     >         > +static int
>         >     >         > +kni_net_header_parse(const struct sk_buff *skb,
>         unsigned char
>         >     *haddr)
>         >     >         > +{
>         >     >         > +     const struct ethhdr *eth = eth_hdr(skb);
>         >     >         > +
>         >     >         > +     memcpy(haddr, eth->h_source, ETH_ALEN);
>         >     >         > +
>         >     >         > +     return ETH_ALEN;
>         >     >         > +}
>         >     >         > +
>         >     >         >  /*
>         >     >         >   * Re-fill the eth header
>         >     >         >   */
>         >     >         > @@ -739,6 +752,7 @@ kni_net_change_carrier(struct
>         net_device *dev,
>         >     >         bool new_carrier)
>         >     >         > 
>         >     >         >  static const struct header_ops kni_net_header_ops = {
>         >     >         >       .create  = kni_net_header,
>         >     >         > +     .parse   = kni_net_header_parse,
>         >     >         >  #ifdef HAVE_REBUILD_HEADER
>         >     >         >       .rebuild = kni_net_rebuild_header,
>         >     >         >  #endif /* < 4.1.0  */
>         >     >         >
>         >     >
>         >
>
  

Patch

diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 7fcfa106c..128a5477c 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -678,6 +678,19 @@  kni_net_header(struct sk_buff *skb, struct net_device *dev,
 	return dev->hard_header_len;
 }
 
+/*
+ *  Extract hardware address from packet
+ */
+static int
+kni_net_header_parse(const struct sk_buff *skb, unsigned char *haddr)
+{
+	const struct ethhdr *eth = eth_hdr(skb);
+
+	memcpy(haddr, eth->h_source, ETH_ALEN);
+
+	return ETH_ALEN;
+}
+
 /*
  * Re-fill the eth header
  */
@@ -739,6 +752,7 @@  kni_net_change_carrier(struct net_device *dev, bool new_carrier)
 
 static const struct header_ops kni_net_header_ops = {
 	.create  = kni_net_header,
+	.parse   = kni_net_header_parse,
 #ifdef HAVE_REBUILD_HEADER
 	.rebuild = kni_net_rebuild_header,
 #endif /* < 4.1.0  */