From: Cong Wang <amwang@redhat.com>
To: Lorenzo Colitti <lorenzo@google.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [Patch net-next 1/2] ping: some cleanup for net/ipv4/ping.c
Date: Mon, 03 Jun 2013 15:13:06 +0800 [thread overview]
Message-ID: <1370243586.32297.5.camel@cr0> (raw)
In-Reply-To: <CAKD1Yr0zHsM85ZJLwCeE6NkEZnaMqs3ba1PyOa_M09UB6i99=g@mail.gmail.com>
On Mon, 2013-06-03 at 16:02 +0900, Lorenzo Colitti wrote:
> On Mon, Jun 3, 2013 at 2:55 PM, Cong Wang <amwang@redhat.com> wrote:
> > -static inline int ping_supported(int family, int type, int code)
> > +static inline bool ping_supported(int family, int type, int code)
> > {
> > - return (family == AF_INET && type == ICMP_ECHO && code == 0) ||
> > - (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0);
> > + if (family == AF_INET) {
> > + if (type == ICMP_ECHO && code == 0)
> > + return true;
> > +#if IS_ENABLED(CONFIG_IPV6)
> > + } else if (family == AF_INET6) {
> > + if (type == ICMPV6_ECHO_REQUEST && code == 0)
> > + return true;
> > +#endif
> > + }
> > + return false;
> > }
>
> I don't think it's necessary to #ifdef out code here. It's not needed
> to get the code to compile, because AF_INET6 and ICMPV6_ECHO_REQUEST
> are defined even if CONFIG_IPV6=n. It's also not necessary at runtime,
> because if we get here with family = AF_INET6 even though IPv6 is
> disabled, then then there's already a problem. Adding the ifdef also
> makes the function much hard to read.
Remember it is a cleanup, not a bug fix, right? :) I don't think there
is any way to make this 10- line of code hard to read.
>
> >
> > /*
> > @@ -472,11 +480,13 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
> > type = icmp_hdr(skb)->type;
> > code = icmp_hdr(skb)->code;
> > icmph = (struct icmphdr *)(skb->data + offset);
> > +#if IS_ENABLED(CONFIG_IPV6)
> > } else if (skb->protocol == htons(ETH_P_IPV6)) {
> > family = AF_INET6;
> > type = icmp6_hdr(skb)->icmp6_type;
> > code = icmp6_hdr(skb)->icmp6_code;
> > icmph = (struct icmphdr *) (skb->data + offset);
> > +#endif
> > } else {
> > BUG();
> > }
>
> I think this is unnecessary too. ping_err is only called by icmp_err
> and by icmpv6_err, and if icmp_err is calling us on an IPv4 packet, or
> if icmpv6_err is calling us when IPv6 is unloaded, then there are
> bigger problems.
Again, it is just a clean up.
next prev parent reply other threads:[~2013-06-03 7:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-03 5:55 [Patch net-next 1/2] ping: some cleanup for net/ipv4/ping.c Cong Wang
2013-06-03 5:55 ` [Patch net-next 2/2] ping: use ipv6_iface_scope_id() to get scope id Cong Wang
2013-06-03 7:59 ` Lorenzo Colitti
2013-06-03 8:16 ` Cong Wang
2013-06-03 5:59 ` [Patch net-next 1/2] ping: some cleanup for net/ipv4/ping.c Joe Perches
2013-06-03 6:05 ` Cong Wang
2013-06-03 7:02 ` Lorenzo Colitti
2013-06-03 7:13 ` Cong Wang [this message]
2013-06-03 7:17 ` Lorenzo Colitti
2013-06-03 7:24 ` David Miller
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=1370243586.32297.5.camel@cr0 \
--to=amwang@redhat.com \
--cc=davem@davemloft.net \
--cc=lorenzo@google.com \
--cc=netdev@vger.kernel.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).