diff mbox

[net-next,V5,2/4] net/dst: Utility functions to build dst_metadata without supplying an skb

Message ID 1472986555-14949-3-git-send-email-hadarh@mellanox.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Hadar Hen Zion Sept. 4, 2016, 10:55 a.m. UTC
From: Amir Vadai <amir@vadai.me>

Extract __ip_tun_set_dst() and __ipv6_tun_set_dst() out of
ip_tun_rx_dst() and ipv6_tun_rx_dst(), to be used without supplying an
skb.

Signed-off-by: Amir Vadai <amir@vadai.me>
Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
---
 include/net/dst_metadata.h | 45 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 13 deletions(-)

Comments

Sergei Shtylyov Sept. 4, 2016, 11:14 a.m. UTC | #1
Hello.

On 9/4/2016 1:55 PM, Hadar Hen Zion wrote:

> From: Amir Vadai <amir@vadai.me>
>
> Extract __ip_tun_set_dst() and __ipv6_tun_set_dst() out of
> ip_tun_rx_dst() and ipv6_tun_rx_dst(), to be used without supplying an
> skb.
>
> Signed-off-by: Amir Vadai <amir@vadai.me>
> Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
> Acked-by: Jiri Pirko <jiri@mellanox.com>
> Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
> ---
>  include/net/dst_metadata.h | 45 ++++++++++++++++++++++++++++++++-------------
>  1 file changed, 32 insertions(+), 13 deletions(-)
>
> diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h
> index 5db9f59..49e8847 100644
> --- a/include/net/dst_metadata.h
> +++ b/include/net/dst_metadata.h
> @@ -112,12 +112,10 @@ static inline struct ip_tunnel_info *skb_tunnel_info_unclone(struct sk_buff *skb
>  	return &dst->u.tun_info;
>  }
>
> -static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
> -						 __be16 flags,
> -						 __be64 tunnel_id,
> -						 int md_size)
> +static inline struct metadata_dst *
> +__ip_tun_set_dst(__be32 saddr, __be32 daddr, __u8 tos, __u8 ttl,
> +		 __be16 flags, __be64 tunnel_id, int md_size)

    The continuation lines should start under the 1st '__be32' on the broken 
up line. See how it was before your patch.

>  {
> -	const struct iphdr *iph = ip_hdr(skb);
>  	struct metadata_dst *tun_dst;
>
>  	tun_dst = tun_rx_dst(md_size);
> @@ -125,17 +123,27 @@ static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
[...]
> -static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
> +static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
>  						 __be16 flags,
>  						 __be64 tunnel_id,
>  						 int md_size)
>  {
> -	const struct ipv6hdr *ip6h = ipv6_hdr(skb);
> +	const struct iphdr *iph = ip_hdr(skb);
> +
> +	return __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl,
> +				flags, tunnel_id, md_size);
> +}
> +
> +static inline struct metadata_dst *
> +__ipv6_tun_set_dst(const struct in6_addr *saddr, const struct in6_addr *daddr,
> +		   __u8 tos, __u8 ttl, __be32 label, __be16 flags,
> +		   __be64 tunnel_id, int md_size)

    The continuation lines should start under the 1st *const* on the broken up 
line.

> +{
>  	struct metadata_dst *tun_dst;
>  	struct ip_tunnel_info *info;
>
> @@ -150,14 +158,25 @@ static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
[...]
> +static inline struct metadata_dst *
> +ipv6_tun_rx_dst(struct sk_buff *skb, __be16 flags, __be64 tunnel_id,
> +		int md_size)
> +{
> +	const struct ipv6hdr *ip6h = ipv6_hdr(skb);
> +
> +	return __ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr,
> +				ipv6_get_dsfield(ip6h), ip6h->hop_limit,
> +				ip6_flowlabel(ip6h), flags, tunnel_id,
> +				md_size);

    The continuation lines should start exactly under the 1st & on the broken 
up line.
    That's DaveM's preference, I don't remember if checkpatch.pl reports that 
for the networking code...

[...]

MBR, Sergei
Hadar Hen-Zion Sept. 4, 2016, 12:27 p.m. UTC | #2
On Sun, Sep 4, 2016 at 2:14 PM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
> Hello.
>
>
> On 9/4/2016 1:55 PM, Hadar Hen Zion wrote:
>
>> From: Amir Vadai <amir@vadai.me>
>>
>> Extract __ip_tun_set_dst() and __ipv6_tun_set_dst() out of
>> ip_tun_rx_dst() and ipv6_tun_rx_dst(), to be used without supplying an
>> skb.
>>
>> Signed-off-by: Amir Vadai <amir@vadai.me>
>> Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
>> Acked-by: Jiri Pirko <jiri@mellanox.com>
>> Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
>> ---
>>  include/net/dst_metadata.h | 45
>> ++++++++++++++++++++++++++++++++-------------
>>  1 file changed, 32 insertions(+), 13 deletions(-)
>>
>> diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h
>> index 5db9f59..49e8847 100644
>> --- a/include/net/dst_metadata.h
>> +++ b/include/net/dst_metadata.h
>> @@ -112,12 +112,10 @@ static inline struct ip_tunnel_info
>> *skb_tunnel_info_unclone(struct sk_buff *skb
>>         return &dst->u.tun_info;
>>  }
>>
>> -static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
>> -                                                __be16 flags,
>> -                                                __be64 tunnel_id,
>> -                                                int md_size)
>> +static inline struct metadata_dst *
>> +__ip_tun_set_dst(__be32 saddr, __be32 daddr, __u8 tos, __u8 ttl,
>> +                __be16 flags, __be64 tunnel_id, int md_size)
>
>
>    The continuation lines should start under the 1st '__be32' on the broken
> up line. See how it was before your patch.

ack

>
>>  {
>> -       const struct iphdr *iph = ip_hdr(skb);
>>         struct metadata_dst *tun_dst;
>>
>>         tun_dst = tun_rx_dst(md_size);
>> @@ -125,17 +123,27 @@ static inline struct metadata_dst
>> *ip_tun_rx_dst(struct sk_buff *skb,
>
> [...]
>>
>> -static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
>> +static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
>>                                                  __be16 flags,
>>                                                  __be64 tunnel_id,
>>                                                  int md_size)
>>  {
>> -       const struct ipv6hdr *ip6h = ipv6_hdr(skb);
>> +       const struct iphdr *iph = ip_hdr(skb);
>> +
>> +       return __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos,
>> iph->ttl,
>> +                               flags, tunnel_id, md_size);
>> +}
>> +
>> +static inline struct metadata_dst *
>> +__ipv6_tun_set_dst(const struct in6_addr *saddr, const struct in6_addr
>> *daddr,
>> +                  __u8 tos, __u8 ttl, __be32 label, __be16 flags,
>> +                  __be64 tunnel_id, int md_size)
>
>
>    The continuation lines should start under the 1st *const* on the broken
> up line.

ack

>
>> +{
>>         struct metadata_dst *tun_dst;
>>         struct ip_tunnel_info *info;
>>
>> @@ -150,14 +158,25 @@ static inline struct metadata_dst
>> *ipv6_tun_rx_dst(struct sk_buff *skb,
>
> [...]
>>
>> +static inline struct metadata_dst *
>> +ipv6_tun_rx_dst(struct sk_buff *skb, __be16 flags, __be64 tunnel_id,
>> +               int md_size)
>> +{
>> +       const struct ipv6hdr *ip6h = ipv6_hdr(skb);
>> +
>> +       return __ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr,
>> +                               ipv6_get_dsfield(ip6h), ip6h->hop_limit,
>> +                               ip6_flowlabel(ip6h), flags, tunnel_id,
>> +                               md_size);
>
>
>    The continuation lines should start exactly under the 1st & on the broken
> up line.
>    That's DaveM's preference, I don't remember if checkpatch.pl reports that
> for the networking code...

checkpatch doesn't report :(
I'll fix it to the next version.

>
> [...]
>
> MBR, Sergei
>
diff mbox

Patch

diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h
index 5db9f59..49e8847 100644
--- a/include/net/dst_metadata.h
+++ b/include/net/dst_metadata.h
@@ -112,12 +112,10 @@  static inline struct ip_tunnel_info *skb_tunnel_info_unclone(struct sk_buff *skb
 	return &dst->u.tun_info;
 }
 
-static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
-						 __be16 flags,
-						 __be64 tunnel_id,
-						 int md_size)
+static inline struct metadata_dst *
+__ip_tun_set_dst(__be32 saddr, __be32 daddr, __u8 tos, __u8 ttl,
+		 __be16 flags, __be64 tunnel_id, int md_size)
 {
-	const struct iphdr *iph = ip_hdr(skb);
 	struct metadata_dst *tun_dst;
 
 	tun_dst = tun_rx_dst(md_size);
@@ -125,17 +123,27 @@  static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
 		return NULL;
 
 	ip_tunnel_key_init(&tun_dst->u.tun_info.key,
-			   iph->saddr, iph->daddr, iph->tos, iph->ttl,
+			   saddr, daddr, tos, ttl,
 			   0, 0, 0, tunnel_id, flags);
 	return tun_dst;
 }
 
-static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
+static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
 						 __be16 flags,
 						 __be64 tunnel_id,
 						 int md_size)
 {
-	const struct ipv6hdr *ip6h = ipv6_hdr(skb);
+	const struct iphdr *iph = ip_hdr(skb);
+
+	return __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl,
+				flags, tunnel_id, md_size);
+}
+
+static inline struct metadata_dst *
+__ipv6_tun_set_dst(const struct in6_addr *saddr, const struct in6_addr *daddr,
+		   __u8 tos, __u8 ttl, __be32 label, __be16 flags,
+		   __be64 tunnel_id, int md_size)
+{
 	struct metadata_dst *tun_dst;
 	struct ip_tunnel_info *info;
 
@@ -150,14 +158,25 @@  static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
 	info->key.tp_src = 0;
 	info->key.tp_dst = 0;
 
-	info->key.u.ipv6.src = ip6h->saddr;
-	info->key.u.ipv6.dst = ip6h->daddr;
+	info->key.u.ipv6.src = *saddr;
+	info->key.u.ipv6.dst = *daddr;
 
-	info->key.tos = ipv6_get_dsfield(ip6h);
-	info->key.ttl = ip6h->hop_limit;
-	info->key.label = ip6_flowlabel(ip6h);
+	info->key.tos = tos;
+	info->key.ttl = ttl;
+	info->key.label = label;
 
 	return tun_dst;
 }
 
+static inline struct metadata_dst *
+ipv6_tun_rx_dst(struct sk_buff *skb, __be16 flags, __be64 tunnel_id,
+		int md_size)
+{
+	const struct ipv6hdr *ip6h = ipv6_hdr(skb);
+
+	return __ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr,
+				ipv6_get_dsfield(ip6h), ip6h->hop_limit,
+				ip6_flowlabel(ip6h), flags, tunnel_id,
+				md_size);
+}
 #endif /* __NET_DST_METADATA_H */