Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Ben Greear <greearb-my8/4N5VtI7c+919tysfdA@public.gmane.org>
To: Jeff Layton <jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>
Cc: sfrench-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [cifs srcaddr-v4] cifs:  Allow binding to local IP address.
Date: Wed, 01 Sep 2010 14:31:00 -0700	[thread overview]
Message-ID: <4C7EC614.6020505@candelatech.com> (raw)
In-Reply-To: <20100901171418.44685b74-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>

On 09/01/2010 02:14 PM, Jeff Layton wrote:
> On Wed,  1 Sep 2010 12:00:06 -0700
> Ben Greear<greearb-my8/4N5VtI7c+919tysfdA@public.gmane.org>  wrote:

>> +	struct sockaddr *srcaddr;
>> +	srcaddr = (struct sockaddr *)(&tcon->ses->server->srcaddr);
> 					^^^ nit: parens not needed here

Ok, will fix in next patch.

>>
>>   	seq_printf(s, ",unc=%s", tcon->treeName);
>>   	if (tcon->ses->userName)
>> @@ -374,6 +377,19 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
>>   	if (tcon->ses->domainName)
>>   		seq_printf(s, ",domain=%s", tcon->ses->domainName);
>>
>> +	if (srcaddr->sa_family != AF_UNSPEC) {
>> +		struct sockaddr_in *saddr4;
>> +		struct sockaddr_in6 *saddr6;
>> +		saddr4 = (struct sockaddr_in *)srcaddr;
>> +		saddr6 = (struct sockaddr_in6 *)srcaddr;
>> +		if (saddr6->sin6_family == AF_INET6)
>> +			seq_printf(s, ",srcaddr=%pI6c",
>> +				&saddr6->sin6_addr);
>> +		else
>> +			seq_printf(s, ",srcaddr=%pI4",
>> +				&saddr4->sin_addr.s_addr);
> 		^^^ It's unlikely to occur, but maybe better to make
> 		this a switch() and have a default: case that doesn't
> 		prints the address as "(unknown)" or something? It's
> 		usually better to code defensively for this sort of
> 		stuff and printing a garbage address may be confusing
> 		for users.

I'll work on that.

>> +/** Returns true if srcaddr isn't specified and rhs isn't
>> + * specified, or if srcaddr is specified and
>> + * matches the IP address of the rhs argument.
>> + */
>> +static bool
>> +srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs)
>> +{
>> +	switch (srcaddr->sa_family) {
>> +	case AF_UNSPEC:
>> +		return (rhs->sa_family == AF_UNSPEC);
>> +	case AF_INET: {
>> +		struct sockaddr_in *saddr4 = (struct sockaddr_in *)srcaddr;
>> +		struct sockaddr_in *vaddr4 = (struct sockaddr_in *)rhs;
>> +		return (saddr4->sin_addr.s_addr == vaddr4->sin_addr.s_addr);
>> +	}
>> +	case AF_INET6: {
>> +		struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)srcaddr;
>> +		struct sockaddr_in6 *vaddr6 = (struct sockaddr_in6 *)&rhs;
>> +		return ipv6_addr_equal(&saddr6->sin6_addr,&vaddr6->sin6_addr);
>> +	}
> 	^^^^^
> 	These curly braces aren't needed.

It won't compile without them.  I'd have to declare those variables before the
switch to do away with the parens, and I prefer it as I wrote it.  I'll change
it if you all prefer it otherwise, however.

>
>> +	default:
>> +		WARN_ON(1);
>
> Again, I'm not a huge fan of the cERROR and cFYI macros, but they are
> our "standard". This would probably be best as a cERROR macro. You
> should probably also have it print the value of srcaddr->sa_family as
> that may be useful for debugging.
>
>> +		return false; /* don't expect to be here */
>> +	}
>> +}
>
> Does the above generate a compiler warning about reaching end of a
> non-void function? Either way, it's less clear. I'd change the default
> to just fall through and move the "return false" outside the switch.

No warning, it always returns something since the default case catches
all others.  If I did put the return at the end, then the compiler wouldn't
catch a case where I forgot to return from one of the case statements,
but it's not overly complex code, so I don't care so much either way.
Plz let me know if you still want it at the end.

I also think the WARN_ON is valid, because it can only be a coding bug
that hits that state, and I'd like it to be as loud as possible while
still allowing the user to continue.  There are automated tools that
catch WARN_ON output and post to kernel bug trackers, for instance.

If you still want a cERROR, I can do that..but I prefer to not waste
the space.

Thanks,
Ben


-- 
Ben Greear <greearb-my8/4N5VtI7c+919tysfdA@public.gmane.org>
Candela Technologies Inc  http://www.candelatech.com

  parent reply	other threads:[~2010-09-01 21:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-01 19:00 [cifs srcaddr-v4] cifs: Allow binding to local IP address Ben Greear
     [not found] ` <1283367606-14030-1-git-send-email-greearb-my8/4N5VtI7c+919tysfdA@public.gmane.org>
2010-09-01 21:14   ` Jeff Layton
     [not found]     ` <20100901171418.44685b74-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-09-01 21:31       ` Ben Greear [this message]
     [not found]         ` <4C7EC614.6020505-my8/4N5VtI7c+919tysfdA@public.gmane.org>
2010-09-02  0:38           ` Jeff Layton
     [not found]             ` <20100901203836.2628ce57-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-09-02  5:07               ` Ben Greear
     [not found]                 ` <4C7F3111.80808-my8/4N5VtI7c+919tysfdA@public.gmane.org>
2010-09-02 10:56                   ` Jeff Layton
     [not found]                     ` <20100902065602.6a62825c-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2010-09-03  4:02                       ` Steve French
     [not found]                         ` <AANLkTi=ezVf0b1Cu+HBKRb7Sns5+bDeFwpV649Ub_RAs-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-03  4:24                           ` Ben Greear
     [not found]                             ` <AANLkTimo-jibAy-D6j1oVy0d5-VwXrtz=Cnxvv6=g5a_@mail.gmail.com>
     [not found]                               ` <4C81724C.9030702@candelatech.com>
     [not found]                                 ` <AANLkTimGmcSeQEfS_u221RBzR04L_q25kWO31zvouxFM@mail.gmail.com>
     [not found]                                   ` <AANLkTimGmcSeQEfS_u221RBzR04L_q25kWO31zvouxFM-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-03 22:21                                     ` Steve French
     [not found]                                       ` <AANLkTins-m95_tjyxgQGjzDQ+bMehGpAMinAKap_pPF1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-03 22:27                                         ` Ben Greear
2010-09-08 17:27                                     ` smb2 configuration Ben Greear
     [not found]                                       ` <4C87C793.3040800-my8/4N5VtI7c+919tysfdA@public.gmane.org>
2010-09-08 18:35                                         ` Ben Greear

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=4C7EC614.6020505@candelatech.com \
    --to=greearb-my8/4n5vti7c+919tysfda@public.gmane.org \
    --cc=jlayton-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sfrench-eUNUBHrolfbYtjvyW6yDsg@public.gmane.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