[PATCH] libfuse option parsing

2015-08-16 Thread ThiƩbaud Weksteen
Hi @tech,

Two fixes for libfuse and option parsing. According to the official 
implementation, when an option is not recognised, the processing function
should be called with the key FUSE_OPT_KEY_OPT [1]. Additionally, fix the
last argument of a call in fuse_opt_parse.

Thanks,
ThiƩbaud

[1] http://fuse.sourceforge.net/doxygen/fuse__opt_8h.html

Index: lib/libfuse/fuse_opt.c
===
RCS file: /cvs/src/lib/libfuse/fuse_opt.c,v
retrieving revision 1.12
diff -u -p -r1.12 fuse_opt.c
--- lib/libfuse/fuse_opt.c  6 Feb 2015 23:21:58 -   1.12
+++ lib/libfuse/fuse_opt.c  16 Aug 2015 06:08:00 -
@@ -259,8 +259,10 @@ parse_opt(const struct fuse_opt *o, cons
}
 
if (!found) {
-   printf(fuse: unknown option %s\n, val);
-   return (-1);
+   ret = f(data, val, FUSE_OPT_KEY_OPT, arg);
+   if (ret == 1)
+   fuse_opt_add_arg(arg, val);
+   return (ret);
}
 
return (ret);
@@ -293,7 +295,7 @@ fuse_opt_parse(struct fuse_args *args, v
 
/* not - and not -- */
if (arg[0] != '-') {
-   ret = f(data, arg, FUSE_OPT_KEY_NONOPT, 0);
+   ret = f(data, arg, FUSE_OPT_KEY_NONOPT, outargs);
 
if (ret == 1)
fuse_opt_add_arg(outargs, arg);




Re: smtpctl(8) - 'sh s' does not appear to be an unambiguous prefix

2015-08-16 Thread Jason McIntyre
On Sun, Aug 16, 2015 at 11:00:42PM +0100, Larry Hynes wrote:
 From the man page:
The smtpctl program controls smtpd(8). Commands may be abbreviated
to the minimum unambiguous prefix; for example, sh s for show stats.
 
 What I would expect:
# smtpctl sh s
stats output
 
 What actually happens:
# smtpctl sh s
possibilities are:
show mta
show envelope
show hoststats
show message
show queue
show hosts
show relays
show routes
show stats
show status
 
 I'm guessing that 'sh s' became ambiguous with the addition of 'smtpctl
 show status' in Revision 1.47 in Feb 2014. Or I don't understand what the
 man page is trying to convey.
 
 The following patch replaces 'sh s' with 'sh ro' for 'show routes'
 which, as far as I can tell, is unambiguous.
 

fixed, thanks.
jmc

 
 Index: smtpctl.8
 ===
 RCS file: /cvs/src/usr.sbin/smtpd/smtpctl.8,v
 retrieving revision 1.50
 diff -u -p -r1.50 smtpctl.8
 --- smtpctl.8 27 Jul 2015 18:48:05 -  1.50
 +++ smtpctl.8 16 Aug 2015 21:57:48 -
 @@ -33,9 +33,9 @@ The
 program controls
 .Xr smtpd 8 .
 Commands may be abbreviated to the minimum unambiguous prefix; for example,
 -.Cm sh s
 +.Cm sh ro for
 -.Cm show stats .
 +.Cm show routes .
 .Pp
 The
 .Nm mailq



Re: [patch] armv7 option SDHC_DEBUG support

2015-08-16 Thread ian kremlin
My mail client seems to have screwed up the tabs/whitespace, you can
find a working patch here:

http://ce.gl/ommmc.patch.txt

Ian

On Wed, Jul 1, 2015 at 8:50 PM, ian kremlin i...@kremlin.cc wrote:
 Hi

 Compiling an armv7 kernel with option SDHC_DEBUG fails as there is no 
 definition
 of the ommmc_dump_regs function, so add it.

 Tested on real hardware (Beaglebone Black):

 ommmc0 at omap0
 ommmc0: SYSCONFIG: 0x2015 SYSSTATUS: 0x0001  CSRE: 0x
 ommmc0:   SYSTEST: 0x   CON: 0x0600 PWCNT: 0x
 ommmc0:   BLK: 0x   ARG: 0x   CMD: 0x
 ommmc0: RSP10: 0x RSP32: 0x RSP54: 0x
 ommmc0: RSP76: 0x  DATA: 0xPSTATE: 0x01f7
 ommmc0:  HCTL: 0xSYSCTL: 0x  STAT: 0x0040
 ommmc0:IE: 0x   ISE: 0x  AC12: 0x
 ommmc0:  CAPA: 0x06e10080  CUR_CAPA: 0x   REV: 0x3101
 ommmc0: software reset reg=0x100
 sdmmc0 at ommmc0

 This will help figure out why the onboard eMMC flash memory isn't being
 configured properly on later BBB revisions where they bumped it from 2GB - 
 4GB.

 Ian

 Index: ommmc.c
 ===
 RCS file: /cvs/src/sys/arch/armv7/omap/ommmc.c,v
 retrieving revision 1.14
 diff -u -p -r1.14 ommmc.c
 --- ommmc.c 30 May 2015 02:17:36 - 1.14
 +++ ommmc.c 2 Jul 2015 01:48:32 -
 @@ -244,7 +244,41 @@ void ommmc_write_data(struct ommmc_softc
  #ifdef SDHC_DEBUG
  int ommmcdebug = 20;
  #define DPRINTF(n,s) do { if ((n) = ommmcdebug) printf s; } while (0)
 -void ommmc_dump_regs(struct ommmc_softc *);
 +void
 +ommmc_dump_regs(struct ommmc_softc *sc)
 +{
 + DPRINTF(3,(%s: SYSCONFIG: 0x%08x SYSSTATUS: 0x%08x  CSRE: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_SYSCONFIG), HREAD4(sc, 
 MMCHS_SYSSTATUS),
 +HREAD4(sc, MMCHS_CSRE)));
 +
 + DPRINTF(3,(%s:   SYSTEST: 0x%08x   CON: 0x%08x PWCNT: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_SYSTEST), HREAD4(sc, MMCHS_CON),
 +HREAD4(sc, MMCHS_PWCNT)));
 +
 + DPRINTF(3,(%s:   BLK: 0x%08x   ARG: 0x%08x   CMD: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_BLK), HREAD4(sc, MMCHS_ARG),
 +HREAD4(sc, MMCHS_CMD)));
 +
 + DPRINTF(3,(%s: RSP10: 0x%08x RSP32: 0x%08x RSP54: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_RSP10), HREAD4(sc, MMCHS_RSP32),
 +HREAD4(sc, MMCHS_RSP54)));
 +
 + DPRINTF(3,(%s: RSP76: 0x%08x  DATA: 0x%08xPSTATE: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_RSP76), HREAD4(sc, MMCHS_DATA),
 +HREAD4(sc, MMCHS_PSTATE)));
 +
 + DPRINTF(3,(%s:  HCTL: 0x%08xSYSCTL: 0x%08x  STAT: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_HCTL), HREAD4(sc, MMCHS_SYSCTL),
 +HREAD4(sc, MMCHS_STAT)));
 +
 + DPRINTF(3,(%s:IE: 0x%08x   ISE: 0x%08x  AC12: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_IE), HREAD4(sc, MMCHS_ISE),
 +HREAD4(sc, MMCHS_AC12)));
 +
 + DPRINTF(3,(%s:  CAPA: 0x%08x  CUR_CAPA: 0x%08x   REV: 0x%08x\n,
 +DEVNAME(sc), HREAD4(sc, MMCHS_CAPA), HREAD4(sc, MMCHS_CUR_CAPA),
 +HREAD4(sc, MMCHS_REV)));
 +}
  #else
  #define DPRINTF(n,s) do {} while(0)
  #endif



[Patch] pf refactoring

2015-08-16 Thread Richard Procter
Hi, 

This series of 29 small diffs slims pf.o by 2640 bytes and pf.c by
113 non-comment lines.

pf_translate(), in particular, is now much shorter and clearer[0].

I've tested it by running on my home router (alix, i386, inet4) for a
week or so without issue, and by profiling it under stress. I saw no
significant performance impact, and it's, possibly, even a little more
efficient. See below for the profile details.

The patch's length is due to its conservatism; the cumulative patch 
is much smaller.

At each step, I attempted a correctness argument and some of these follow
the calculational approach of Dijkstra and others. For background, see
e.g. EWD1300 and EWD1123 (for the interested, I've found A.J.M van
Gasteren's 'On the shape of mathematical arguments' a stellar read, and
also recommend EWD1023). I've found it a useful exercise, particularly
as the effort needed to make the argument indicates the effort required
to review the diff, and several times I was led to take smaller bites.


best, 
Richard. 

PS. If you, reading this, like the patch, or even if you don't, 
please drop me a line to let me know. Thanks! 

[0] As pf_translate() is called only on state creation it isn't
terribly performance sensitive, either.

Profiling -

Setup: netcat a 415MB file through the profiled router. 

  [A] -- 192.168.3.2 vr1 -- [router] -- vr0 192.168.1.2 -- [B]

(vr0 is part of a bridge.)

pf.conf contains
match on vr1 scrub (random-id, reassemble tcp)
match out on vr0 inet from !vr0:network nat-to $router
pass

before patch: real 1m18.118s 
 after patch: real 1m17.282s, 1m18.150s, 1m17.716s

before patch:

1.044.92 1303400/1303400pf_test [9]
[13] 5.91.044.92 1303400pf_test_state [13]
0.892.10 1301332/1301332pf_tcp_track_full [19]
0.360.69 1303400/1304361pf_find_state [43]
0.290.06 1301273/1951905m_copyback [63]
0.200.00 3257446/5872085pf_addrcpy [74]
0.080.08  650646/650647 pf_change_a [93]
0.100.06  650646/650647 pf_change_ap [95]

after patch:
(note, profiler spent less time in the idle loop before the test began, 
so the time percentages 5.9, 6.9 aren't comparable between these runs.)

0.964.88 1301679/1301679 pf_test [7]
[13] 6.90.964.88 1301679 pf_test_state [13]
0.891.99 1301628/1301628 pf_tcp_track_full [19]
0.390.59 1301679/1301680 pf_find_state [44]
0.190.16 1301580/1301582 pf_change_a [74]
0.280.05 1301576/1952366 m_copyback [64]
0.130.06 1301580/1301582 pf_change_16 [87]
0.150.00 2603358/5857533 pf_addrcpy [75]

Patch 

To apply against HEAD (pf.c:1.935, pfvar.h:1.419):

First apply the checksum patch I posted to tech@ 
Re: [patch] cleaner checksum modification for pf, 
Message-Id: 98bb5cd8-7b74-4a79-a333-70749e3bc...@gmail.com. 
(I'm also happy to regenerate what follows directly against HEAD 
if necessary.)

then, 

# cd /usr/src/sys
# cat - | patch 

- add pf_change_p(), change port, and use instead of pf_change_ap() when
 changing port only.

No functional change: all replaced pf_change_ap() leave address unchanged.

Argument:

(note: afto == (pd-af != nk-af))

All replaced pf_change_ap() executed under afto with arg naf := nk-af   
=   { pf_change_ap() } 
All replaced executions of pf_change_a() executed 
with args af := pd-af, naf := nk-af, under afto which implies af != naf 
=   { afto and pf_change_a() guarded with 'if (af != naf) return;' }
All replaced executions of pf_change_a() are no-op 
=   { pf_change_ap() } 
All replaced pf_change_ap() leave address unchanged

[Context=15]  

Index: net/pf.c
===
--- net.orig/pf.c
+++ net/pf.c
@@ -139,30 +139,31 @@ union pf_headers {

struct pool  pf_src_tree_pl, pf_rule_pl, pf_queue_pl;
struct pool  pf_state_pl, pf_state_key_pl, pf_state_item_pl;
struct pool  pf_rule_item_pl, pf_sn_item_pl;

void pf_init_threshold(struct pf_threshold *, u_int32_t,
u_int32_t);
void pf_add_threshold(struct pf_threshold *);
int  pf_check_threshold(struct pf_threshold *);
void pf_cksum_fixup(u_int16_t *, u_int16_t, u_int16_t,
u_int8_t);
void pf_cksum_fixup_a(u_int16_t *, const struct pf_addr *,
const struct pf_addr *, sa_family_t, u_int8_t);
void pf_change_32(struct pf_pdesc *, u_int32_t *,
 

smtpctl(8) - 'sh s' does not appear to be an unambiguous prefix

2015-08-16 Thread Larry Hynes

From the man page:

   The smtpctl program controls smtpd(8). Commands may be abbreviated
   to the minimum unambiguous prefix; for example, sh s for show stats.

What I would expect:
   # smtpctl sh s
   stats output

What actually happens:
   # smtpctl sh s
   possibilities are:
   show mta
   show envelope
   show hoststats
   show message
   show queue
   show hosts
   show relays
   show routes
   show stats
   show status

I'm guessing that 'sh s' became ambiguous with the addition of 'smtpctl
show status' in Revision 1.47 in Feb 2014. Or I don't understand what the
man page is trying to convey.

The following patch replaces 'sh s' with 'sh ro' for 'show routes'
which, as far as I can tell, is unambiguous.


Index: smtpctl.8
===
RCS file: /cvs/src/usr.sbin/smtpd/smtpctl.8,v
retrieving revision 1.50
diff -u -p -r1.50 smtpctl.8
--- smtpctl.8   27 Jul 2015 18:48:05 -  1.50
+++ smtpctl.8   16 Aug 2015 21:57:48 -
@@ -33,9 +33,9 @@ The
program controls
.Xr smtpd 8 .
Commands may be abbreviated to the minimum unambiguous prefix; for example,
-.Cm sh s
+.Cm sh ro 
for

-.Cm show stats .
+.Cm show routes .
.Pp
The
.Nm mailq
Index: smtpd.conf.5
===
RCS file: /cvs/src/usr.sbin/smtpd/smtpd.conf.5,v
retrieving revision 1.127
diff -u -p -r1.127 smtpd.conf.5
--- smtpd.conf.511 Aug 2015 21:57:24 -  1.127
+++ smtpd.conf.516 Aug 2015 21:57:48 -
@@ -635,7 +635,7 @@ able to establish an SMTP session.
.Ic secure
may be specified to provide both STARTTLS and SMTPS services.
Host certificates may be used for these connections,
-and must be priorly declared using the pki directive.
+and must be declared beforehand using the pki directive.
If
.Ic pki
is specified,



whois(1): fix lookup of XX.network

2015-08-16 Thread Stuart Henderson
When I added code to use whois.nic.XX for new TLDs I forgot to think
about one case, where the TLD is a substring of one of the traditional
TLDs who have to use the old whois-servers.net method. Specifically,
trying to lookup a .network name will incorrectly try to use
network.whois-servers.net - strncasecmp was the wrong decision,
so this diff switches to strcasecmp instead to fix. They're all
null-terminated strings.

before:

$ whois shitty.network|head -5
whois: network.whois-servers.net: no address associated with name

after:

$ whois shitty.network|head -5
Domain Name: shitty.network
Domain ID: d8b5dc3cc4f44139a517c0f66d1c8ad7-D
WHOIS Server: http://whois.rrpproxy.net
Referral URL: http://key-systems.net
Updated Date: 2015-01-02T15:18:22Z

Bonus simplification, use snprintf...%s rather than strlcpy+strlcat.

ok?

Index: whois.c
===
RCS file: /cvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.47
diff -u -p -r1.47 whois.c
--- whois.c 9 Apr 2015 19:29:53 -   1.47
+++ whois.c 16 Aug 2015 20:50:10 -
@@ -310,22 +310,21 @@ choose_server(const char *name, const ch
 * Post-2003 (new) gTLDs are all supposed to have whois.nic.domain
 * (per registry agreement), some older gTLDs also support this...
 */
-   strlcpy(server, whois.nic., len);
-   strlcat(server, qhead, len);
+   snprintf(server, len, whois.nic.%s, qhead);
 
/* most ccTLDs don't do this, but QNICHOST/whois-servers mostly works */
if ((strlen(qhead) == 2 ||
/* and is required for most of the =2003 TLDs/gTLDs */
-   strncasecmp(qhead, org, 3) == 0 ||
-   strncasecmp(qhead, com, 3) == 0 ||
-   strncasecmp(qhead, net, 3) == 0 ||
-   strncasecmp(qhead, cat, 3) == 0 ||
-   strncasecmp(qhead, pro, 3) == 0 ||
-   strncasecmp(qhead, info, 4) == 0 ||
-   strncasecmp(qhead, aero, 4) == 0 ||
-   strncasecmp(qhead, jobs, 4) == 0 ||
-   strncasecmp(qhead, mobi, 4) == 0 ||
-   strncasecmp(qhead, museum, 6) == 0 ||
+   strcasecmp(qhead, org) == 0 ||
+   strcasecmp(qhead, com) == 0 ||
+   strcasecmp(qhead, net) == 0 ||
+   strcasecmp(qhead, cat) == 0 ||
+   strcasecmp(qhead, pro) == 0 ||
+   strcasecmp(qhead, info) == 0 ||
+   strcasecmp(qhead, aero) == 0 ||
+   strcasecmp(qhead, jobs) == 0 ||
+   strcasecmp(qhead, mobi) == 0 ||
+   strcasecmp(qhead, museum) == 0 ||
 /* for others, if whois.nic.TLD doesn't exist, try whois-servers */
getaddrinfo(server, NULL, hints, res) != 0)) {
strlcpy(server, qhead, len);