diff mbox

[PING,v2,BZ,#14799] Allow to disable options in RES_OPTIONS

Message ID 20141221165635.GA22503@domone
State New
Headers show

Commit Message

Ondřej Bílka Dec. 21, 2014, 4:56 p.m. UTC
On Sun, Dec 21, 2014 at 05:08:33PM +0100, Andreas Schwab wrote:
> Ondřej Bílka <neleai@seznam.cz> writes:
> 
> > Do you have testcase that shows that?
> 
> I don't need a testcase.  (options[i].clear ^ invert) is obviously
> always nonzero.
> 
Like when you pass inet6 there and options[i].clear == 0 and invert = 0?

But it needs update clear format to match invert.

Comments

Ondřej Bílka Aug. 12, 2015, 8:36 p.m. UTC | #1
On Sun, Dec 21, 2014 at 05:56:35PM +0100, Ondřej Bílka wrote:
> On Sun, Dec 21, 2014 at 05:08:33PM +0100, Andreas Schwab wrote:
> > Ondřej Bílka <neleai@seznam.cz> writes:
> > 
> > > Do you have testcase that shows that?
> > 
> > I don't need a testcase.  (options[i].clear ^ invert) is obviously
> > always nonzero.
> > 
> Like when you pass inet6 there and options[i].clear == 0 and invert = 0?
> 
> But it needs update clear format to match invert.
> 
> diff --git a/resolv/res_init.c b/resolv/res_init.c
> index d492a08..039116a 100644
> --- a/resolv/res_init.c
> +++ b/resolv/res_init.c
> @@ -527,32 +527,38 @@ res_setoptions(res_state statp, const char *options, const char *source) {
>  		  {
>  		    char str[22];
>  		    uint8_t len;
> -		    uint8_t clear;
> +		    unsigned long clear;
>  		    unsigned long int flag;
>  		  } options[] = {
>  #define STRnLEN(str) str, sizeof (str) - 1
>  		    { STRnLEN ("inet6"), 0, RES_USE_INET6 },
>  		    { STRnLEN ("ip6-bytestring"), 0, RES_USEBSTRING },
> -		    { STRnLEN ("no-ip6-dotint"), 0, RES_NOIP6DOTINT },
> -		    { STRnLEN ("ip6-dotint"), 1, ~RES_NOIP6DOTINT },
> +		    { STRnLEN ("ip6-dotint"), ~0, ~RES_NOIP6DOTINT },
>  		    { STRnLEN ("rotate"), 0, RES_ROTATE },
> -		    { STRnLEN ("no-check-names"), 0, RES_NOCHECKNAME },
> +		    { STRnLEN ("check-names"), ~0, ~RES_NOCHECKNAME },
>  		    { STRnLEN ("edns0"), 0, RES_USE_EDNS0 },
>  		    { STRnLEN ("single-request-reopen"), 0, RES_SNGLKUPREOP },
>  		    { STRnLEN ("single-request"), 0, RES_SNGLKUP },
>  		    { STRnLEN ("no_tld_query"), 0, RES_NOTLDQUERY },
> -		    { STRnLEN ("no-tld-query"), 0, RES_NOTLDQUERY },
> +		    { STRnLEN ("tld-query"), ~0, ~RES_NOTLDQUERY },
>  		    { STRnLEN ("use-vc"), 0, RES_USEVC }
>  		  };
>  #define noptions (sizeof (options) / sizeof (options[0]))
>  		  int i;
> +		  unsigned long int invert = 0;
> +		  if (strncmp (cp, "no-", 3) == 0)
> +		    {
> +		      cp += 3;
> +		      invert = ~0;
> +		    }
> +
>  		  for (i = 0; i < noptions; ++i)
>  		    if (strncmp (cp, options[i].str, options[i].len) == 0)
>  		      {
> -			if (options[i].clear)
> -			  statp->options &= options[i].flag;
> +			if (options[i].clear ^ invert)
> +			  statp->options &= options[i].flag ^ invert;
>  			else
> -			  statp->options |= options[i].flag;
> +			  statp->options |= options[i].flag ^ invert;
>  			break;
>  		      }
>  		  if (i == noptions) {
diff mbox

Patch

diff --git a/resolv/res_init.c b/resolv/res_init.c
index d492a08..039116a 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -527,32 +527,38 @@  res_setoptions(res_state statp, const char *options, const char *source) {
 		  {
 		    char str[22];
 		    uint8_t len;
-		    uint8_t clear;
+		    unsigned long clear;
 		    unsigned long int flag;
 		  } options[] = {
 #define STRnLEN(str) str, sizeof (str) - 1
 		    { STRnLEN ("inet6"), 0, RES_USE_INET6 },
 		    { STRnLEN ("ip6-bytestring"), 0, RES_USEBSTRING },
-		    { STRnLEN ("no-ip6-dotint"), 0, RES_NOIP6DOTINT },
-		    { STRnLEN ("ip6-dotint"), 1, ~RES_NOIP6DOTINT },
+		    { STRnLEN ("ip6-dotint"), ~0, ~RES_NOIP6DOTINT },
 		    { STRnLEN ("rotate"), 0, RES_ROTATE },
-		    { STRnLEN ("no-check-names"), 0, RES_NOCHECKNAME },
+		    { STRnLEN ("check-names"), ~0, ~RES_NOCHECKNAME },
 		    { STRnLEN ("edns0"), 0, RES_USE_EDNS0 },
 		    { STRnLEN ("single-request-reopen"), 0, RES_SNGLKUPREOP },
 		    { STRnLEN ("single-request"), 0, RES_SNGLKUP },
 		    { STRnLEN ("no_tld_query"), 0, RES_NOTLDQUERY },
-		    { STRnLEN ("no-tld-query"), 0, RES_NOTLDQUERY },
+		    { STRnLEN ("tld-query"), ~0, ~RES_NOTLDQUERY },
 		    { STRnLEN ("use-vc"), 0, RES_USEVC }
 		  };
 #define noptions (sizeof (options) / sizeof (options[0]))
 		  int i;
+		  unsigned long int invert = 0;
+		  if (strncmp (cp, "no-", 3) == 0)
+		    {
+		      cp += 3;
+		      invert = ~0;
+		    }
+
 		  for (i = 0; i < noptions; ++i)
 		    if (strncmp (cp, options[i].str, options[i].len) == 0)
 		      {
-			if (options[i].clear)
-			  statp->options &= options[i].flag;
+			if (options[i].clear ^ invert)
+			  statp->options &= options[i].flag ^ invert;
 			else
-			  statp->options |= options[i].flag;
+			  statp->options |= options[i].flag ^ invert;
 			break;
 		      }
 		  if (i == noptions) {