diff mbox

[net-next,fragmentation,icmp,v3,1/4] ipv4: introduce frag_expire_skip_icmp()

Message ID 1431059199-7139-2-git-send-email-azhou@nicira.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Andy Zhou May 8, 2015, 4:26 a.m. UTC
Improve readability of skip ICMP for de-fragmentation expiration logic.
This change will also make the logic easier to maintain when the
following patches in this series are applied.

Signed-off-by: Andy Zhou <azhou@nicira.com>
---
 include/net/ip.h       | 10 ++++++++++
 net/ipv4/ip_fragment.c | 13 +++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

Comments

Sergei Shtylyov May 8, 2015, 12:03 p.m. UTC | #1
Hello.

On 5/8/2015 7:26 AM, Andy Zhou wrote:

> Improve readability of skip ICMP for de-fragmentation expiration logic.
> This change will also make the logic easier to maintain when the
> following patches in this series are applied.

> Signed-off-by: Andy Zhou <azhou@nicira.com>
> ---
>   include/net/ip.h       | 10 ++++++++++
>   net/ipv4/ip_fragment.c | 13 +++++++++----
>   2 files changed, 19 insertions(+), 4 deletions(-)

> diff --git a/include/net/ip.h b/include/net/ip.h
> index d14af7e..f79193a 100644
> --- a/include/net/ip.h
> +++ b/include/net/ip.h
> @@ -478,6 +478,16 @@ enum ip_defrag_users {
>   	IP_DEFRAG_MACVLAN,
>   };
>
> +/* Return true if the value of 'user' is between 'lower_bond'
> + * and 'upper_bond' inclusively.
> + */
> +static inline bool ip_defrag_user_in_between(u32 user,
> +					     enum ip_defrag_users lower_bond,
> +					     enum ip_defrag_users upper_bond)
> +{
> +	return (user >= lower_bond && user <= upper_bond);

    Don't need parens around the *return* expression.

[...]
> diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
> index cc1da6d..429cefa 100644
> --- a/net/ipv4/ip_fragment.c
> +++ b/net/ipv4/ip_fragment.c
> @@ -173,6 +173,13 @@ static void ipq_kill(struct ipq *ipq)
>   	inet_frag_kill(&ipq->q, &ip4_frags);
>   }
>
> +static bool frag_expire_skip_icmp(u32 user)
> +{
> +	return (user == IP_DEFRAG_AF_PACKET ||
> +		ip_defrag_user_in_between(user, IP_DEFRAG_CONNTRACK_IN,
> +					  __IP_DEFRAG_CONNTRACK_IN_END));

    Likewise.

[...]

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Zhou May 12, 2015, 3:13 p.m. UTC | #2
On Fri, May 8, 2015 at 5:03 AM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
> Hello.
>
> On 5/8/2015 7:26 AM, Andy Zhou wrote:
>
>> Improve readability of skip ICMP for de-fragmentation expiration logic.
>> This change will also make the logic easier to maintain when the
>> following patches in this series are applied.
>
>
>> Signed-off-by: Andy Zhou <azhou@nicira.com>
>> ---
>>   include/net/ip.h       | 10 ++++++++++
>>   net/ipv4/ip_fragment.c | 13 +++++++++----
>>   2 files changed, 19 insertions(+), 4 deletions(-)
>
>
>> diff --git a/include/net/ip.h b/include/net/ip.h
>> index d14af7e..f79193a 100644
>> --- a/include/net/ip.h
>> +++ b/include/net/ip.h
>> @@ -478,6 +478,16 @@ enum ip_defrag_users {
>>         IP_DEFRAG_MACVLAN,
>>   };
>>
>> +/* Return true if the value of 'user' is between 'lower_bond'
>> + * and 'upper_bond' inclusively.
>> + */
>> +static inline bool ip_defrag_user_in_between(u32 user,
>> +                                            enum ip_defrag_users
>> lower_bond,
>> +                                            enum ip_defrag_users
>> upper_bond)
>> +{
>> +       return (user >= lower_bond && user <= upper_bond);
>
>
>    Don't need parens around the *return* expression.
Thanks, I will fix this and the following site in the next version.
>
> [...]
>>
>> diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
>> index cc1da6d..429cefa 100644
>> --- a/net/ipv4/ip_fragment.c
>> +++ b/net/ipv4/ip_fragment.c
>> @@ -173,6 +173,13 @@ static void ipq_kill(struct ipq *ipq)
>>         inet_frag_kill(&ipq->q, &ip4_frags);
>>   }
>>
>> +static bool frag_expire_skip_icmp(u32 user)
>> +{
>> +       return (user == IP_DEFRAG_AF_PACKET ||
>> +               ip_defrag_user_in_between(user, IP_DEFRAG_CONNTRACK_IN,
>> +                                         __IP_DEFRAG_CONNTRACK_IN_END));
>
>
>    Likewise.
>
> [...]
>
> WBR, Sergei
>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/net/ip.h b/include/net/ip.h
index d14af7e..f79193a 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -478,6 +478,16 @@  enum ip_defrag_users {
 	IP_DEFRAG_MACVLAN,
 };
 
+/* Return true if the value of 'user' is between 'lower_bond'
+ * and 'upper_bond' inclusively.
+ */
+static inline bool ip_defrag_user_in_between(u32 user,
+					     enum ip_defrag_users lower_bond,
+					     enum ip_defrag_users upper_bond)
+{
+	return (user >= lower_bond && user <= upper_bond);
+}
+
 int ip_defrag(struct sk_buff *skb, u32 user);
 #ifdef CONFIG_INET
 struct sk_buff *ip_check_defrag(struct sk_buff *skb, u32 user);
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index cc1da6d..429cefa 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -173,6 +173,13 @@  static void ipq_kill(struct ipq *ipq)
 	inet_frag_kill(&ipq->q, &ip4_frags);
 }
 
+static bool frag_expire_skip_icmp(u32 user)
+{
+	return (user == IP_DEFRAG_AF_PACKET ||
+		ip_defrag_user_in_between(user, IP_DEFRAG_CONNTRACK_IN,
+					  __IP_DEFRAG_CONNTRACK_IN_END));
+}
+
 /*
  * Oops, a fragment queue timed out.  Kill it and send an ICMP reply.
  */
@@ -217,10 +224,8 @@  static void ip_expire(unsigned long arg)
 		/* Only an end host needs to send an ICMP
 		 * "Fragment Reassembly Timeout" message, per RFC792.
 		 */
-		if (qp->user == IP_DEFRAG_AF_PACKET ||
-		    ((qp->user >= IP_DEFRAG_CONNTRACK_IN) &&
-		     (qp->user <= __IP_DEFRAG_CONNTRACK_IN_END) &&
-		     (skb_rtable(head)->rt_type != RTN_LOCAL)))
+		if (frag_expire_skip_icmp(qp->user) &&
+		    (skb_rtable(head)->rt_type != RTN_LOCAL))
 			goto out_rcu_unlock;
 
 		/* Send an ICMP "Fragment Reassembly Timeout" message. */