Re: another ancient bug in head(1)

2014-10-08 Thread Martin Natano
 Index: head.c
 ===
 RCS file: /cvs/src/usr.bin/head/head.c,v
 retrieving revision 1.17
 diff -u -p -r1.17 head.c
 --- head.c7 Oct 2014 19:38:57 -   1.17
 +++ head.c7 Oct 2014 21:16:43 -
 @@ -48,6 +48,7 @@ static void usage(void);
  int
  main(int argc, char *argv[])
  {
 + FILE*fp;
   longcnt;
   int ch, firsttime;
   longlinecnt = 10;
 @@ -81,13 +82,13 @@ main(int argc, char *argv[])
   errx(1, line count %s: %s, errstr, p);
   }
  
 - /* setlinebuf(stdout); */
   for (firsttime = 1; ; firsttime = 0) {
   if (!*argv) {
   if (!firsttime)
   exit(status);
 + fp = stdin;
   } else {
 - if (!freopen(*argv, r, stdin)) {
 + if ((fp = fopen(*argv, r)) == NULL) {
   warn(%s, *argv++);
   status = 1;
   continue;
 @@ -99,10 +100,11 @@ main(int argc, char *argv[])
   }
   ++argv;
   }
 - for (cnt = linecnt; cnt  !feof(stdin); --cnt)
 - while ((ch = getchar()) != EOF)
 + for (cnt = linecnt; cnt  !feof(fp); --cnt)
 + while ((ch = getc(fp)) != EOF)
   if (putchar(ch) == '\n')
   break;
 + fclose(fp);
   }
   /*NOTREACHED*/
  }
 
Nice fix! Seems correct to me.

cheers,
natano



hibernate button and !HIBERNATE kernels

2014-10-08 Thread David Coppa

Hi!

When running a kernel built without option HIBERNATE, if I press
the hibernate button (Fn+F12) on my ThinkPad T420, the system
abruptly shuts down and I'm welcomed by fsck on the next boot.

What about the following diff?

Index: dev/acpi/acpithinkpad.c
===
RCS file: /cvs/src/sys/dev/acpi/acpithinkpad.c,v
retrieving revision 1.40
diff -u -p -u -p -r1.40 acpithinkpad.c
--- dev/acpi/acpithinkpad.c 7 Oct 2014 11:28:59 -   1.40
+++ dev/acpi/acpithinkpad.c 8 Oct 2014 07:14:06 -
@@ -345,7 +345,7 @@ thinkpad_hotkey(struct aml_node *node, i
handled = 1;
break;
case THINKPAD_BUTTON_HIBERNATE:
-#ifndef SMALL_KERNEL
+#if defined(HIBERNATE)  !defined(SMALL_KERNEL)
acpi_addtask(sc-sc_acpi, acpi_sleep_task, 
sc-sc_acpi, ACPI_STATE_S4);
 #endif



Re: pppoe(4), add example for ipv6

2014-10-08 Thread Stefan Sperling
On Tue, Oct 07, 2014 at 11:42:10PM -0400, Brad Smith wrote:
 On 07/10/14 10:03 PM, Stuart Henderson wrote:
 Since it's non-obvious how to setup pppoe for v6 now that link-local
 addresses are no longer configured by default, I think we should have
 something in the manual.
 
 Any comments/objections/suggestions for a better way to do this?
 
 This doesn't make any sense. IPv6CP configures the link local address.

IPv6CP prevents *collisions* of link-local addresses on the same p2p link.

If an existing link-local address doesn't collide with the remote peer's
address we keep using the existing address. The link-local address will
be changed by IPv6CP only if there is a collision (which won't ever happen
under normal conditions).

 Having to do something like this is illogical and counter intuitive. I
 agree it should be documented per se but the current behavior is just
 plain stupid.

A route to fe80:: needs to be configured statically in any case
until autoconf works with ip6 forwarding enabled.

!/sbin/route add default -ifp pppoe0 fe80::

I suppose we can't run this command from hostname.pppoe0 if there is
no IPv6 address yet, so it makes sense to configure one first.



RTFREE - rtfree

2014-10-08 Thread Martin Pieuchot
Diff below kills the macro and use the fonction instead since they are
equivalent.  It also replaces some 0 - NULL where it applies.  It does
not include the manpage bits, I'll deal with that afterward.

I'd appreciate reviews and oks.

Index: net/if_gre.c
===
RCS file: /home/ncvs/src/sys/net/if_gre.c,v
retrieving revision 1.70
diff -u -p -r1.70 if_gre.c
--- net/if_gre.c22 Jul 2014 11:06:09 -  1.70
+++ net/if_gre.c8 Oct 2014 10:20:33 -
@@ -519,8 +519,10 @@ gre_ioctl(struct ifnet *ifp, u_long cmd,
 recompute:
if ((sc-g_src.s_addr != INADDR_ANY) 
(sc-g_dst.s_addr != INADDR_ANY)) {
-   if (sc-route.ro_rt != 0)
-   RTFREE(sc-route.ro_rt);
+   if (sc-route.ro_rt != NULL) {
+   rtfree(sc-route.ro_rt);
+   sc-route.ro_rt = NULL;
+   }
/* ip_output() will do the lookup */
bzero(sc-route, sizeof(sc-route));
ifp-if_flags |= IFF_UP;
Index: net/if_mpe.c
===
RCS file: /home/ncvs/src/sys/net/if_mpe.c,v
retrieving revision 1.36
diff -u -p -r1.36 if_mpe.c
--- net/if_mpe.c7 Oct 2014 08:59:50 -   1.36
+++ net/if_mpe.c8 Oct 2014 10:20:33 -
@@ -186,7 +186,7 @@ mpestart(struct ifnet *ifp)
sa-sa_family = AF_MPLS;
 
mpls_output(rt-rt_ifp, m, sa, rt);
-   RTFREE(rt);
+   rtfree(rt);
}
 }
 
Index: net/pf.c
===
RCS file: /home/ncvs/src/sys/net/pf.c,v
retrieving revision 1.888
diff -u -p -r1.888 pf.c
--- net/pf.c8 Oct 2014 07:37:01 -   1.888
+++ net/pf.c8 Oct 2014 10:20:33 -
@@ -2992,7 +2992,7 @@ pf_calc_mss(struct pf_addr *addr, sa_fam
if (rt  rt-rt_ifp) {
mss = rt-rt_ifp-if_mtu - hlen - sizeof(struct tcphdr);
mss = max(tcp_mssdflt, mss);
-   RTFREE(rt);
+   rtfree(rt);
}
mss = min(mss, offer);
mss = max(mss, 64); /* sanity - at least max opt space */
@@ -5467,7 +5467,7 @@ pf_routable(struct pf_addr *addr, sa_fam
ret = 0;
 out:
if (ro.ro_rt != NULL)
-   RTFREE(ro.ro_rt);
+   rtfree(ro.ro_rt);
return (ret);
 }
 
@@ -5511,7 +5511,7 @@ pf_rtlabel_match(struct pf_addr *addr, s
if (ro.ro_rt != NULL) {
if (ro.ro_rt-rt_labelid == aw-v.rtlabel)
ret = 1;
-   RTFREE(ro.ro_rt);
+   rtfree(ro.ro_rt);
}
 
return (ret);
@@ -5688,7 +5688,7 @@ done:
if (r-rt != PF_DUPTO)
*m = NULL;
if (ro == iproute  ro-ro_rt)
-   RTFREE(ro-ro_rt);
+   rtfree(ro-ro_rt);
return;
 
 bad:
Index: net/pfkeyv2.c
===
RCS file: /home/ncvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.134
diff -u -p -r1.134 pfkeyv2.c
--- net/pfkeyv2.c   27 Sep 2014 12:26:16 -  1.134
+++ net/pfkeyv2.c   8 Oct 2014 10:20:33 -
@@ -1573,7 +1573,7 @@ pfkeyv2_send(struct socket *socket, void
re.re_tableid);
if (re.re_rt != NULL) {
ipo = ((struct sockaddr_encap *) 
re.re_rt-rt_gateway)-sen_ipsp;
-   RTFREE(re.re_rt);
+   rtfree(re.re_rt);
 
/* Verify that the entry is identical */
if (bcmp(ipo-ipo_addr, encapdst,
Index: net/route.c
===
RCS file: /home/ncvs/src/sys/net/route.c,v
retrieving revision 1.186
diff -u -p -r1.186 route.c
--- net/route.c 8 Oct 2014 07:37:02 -   1.186
+++ net/route.c 8 Oct 2014 10:20:33 -
@@ -368,8 +368,7 @@ rtfree(struct rtentry *rt)
 {
struct ifaddr   *ifa;
 
-   if (rt == NULL)
-   panic(rtfree);
+   KASSERT(rt != NULL);
 
rt-rt_refcnt--;
 
@@ -788,8 +787,8 @@ rtrequest1(int req, struct rt_addrinfo *
panic (rtrequest delete);
 
if (rt-rt_gwroute) {
-   rt = rt-rt_gwroute; RTFREE(rt);
-   (rt = (struct rtentry *)rn)-rt_gwroute = NULL;
+   rtfree(rt-rt_gwroute);
+   rt-rt_gwroute = NULL;
}
 
if (rt-rt_parent) {
@@ -971,7 +970,7 @@ rtrequest1(int req, struct rt_addrinfo *
(caddr_t)info-rti_info[RTAX_NETMASK],
rnh, rt-rt_nodes, rt-rt_priority);
}
-   RTFREE(crt);
+   

Re: RTFREE - rtfree

2014-10-08 Thread Mike Belopuhov
On 8 October 2014 12:24, Martin Pieuchot mpieuc...@nolizard.org wrote:
 Diff below kills the macro and use the fonction instead since they are
 equivalent.  It also replaces some 0 - NULL where it applies.  It does
 not include the manpage bits, I'll deal with that afterward.

 I'd appreciate reviews and oks.


although syn_cache_put doesn't really require nullification,
i'm ok with the diff.



A system without interface?

2014-10-08 Thread Martin Pieuchot
I'm looking after the uses of the global list of interface.  These ones
are pointless, you always have at least one interface on your system.

Ok?

Index: netinet/raw_ip.c
===
RCS file: /home/ncvs/src/sys/netinet/raw_ip.c,v
retrieving revision 1.75
diff -u -p -r1.75 raw_ip.c
--- netinet/raw_ip.c14 Aug 2014 08:22:38 -  1.75
+++ netinet/raw_ip.c8 Oct 2014 12:25:31 -
@@ -457,7 +457,7 @@ rip_usrreq(struct socket *so, int req, s
error = EINVAL;
break;
}
-   if (TAILQ_EMPTY(ifnet) || addr-sin_family != AF_INET) {
+   if (addr-sin_family != AF_INET) {
error = EADDRNOTAVAIL;
break;
}
@@ -477,10 +477,6 @@ rip_usrreq(struct socket *so, int req, s
 
if (nam-m_len != sizeof(*addr)) {
error = EINVAL;
-   break;
-   }
-   if (TAILQ_EMPTY(ifnet)) {
-   error = EADDRNOTAVAIL;
break;
}
if (addr-sin_family != AF_INET) {
Index: netinet6/raw_ip6.c
===
RCS file: /home/ncvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.68
diff -u -p -r1.68 raw_ip6.c
--- netinet6/raw_ip6.c  22 Jul 2014 11:06:10 -  1.68
+++ netinet6/raw_ip6.c  8 Oct 2014 12:25:31 -
@@ -665,7 +665,7 @@ rip6_usrreq(struct socket *so, int req, 
error = EINVAL;
break;
}
-   if (TAILQ_EMPTY(ifnet) || (addr-sin6_family != AF_INET6)) {
+   if (addr-sin6_family != AF_INET6) {
error = EADDRNOTAVAIL;
break;
}
@@ -708,10 +708,6 @@ rip6_usrreq(struct socket *so, int req, 
 
if (nam-m_len != sizeof(*addr)) {
error = EINVAL;
-   break;
-   }
-   if (TAILQ_EMPTY(ifnet)) {
-   error = EADDRNOTAVAIL;
break;
}
if (addr-sin6_family != AF_INET6) {



Re: pppoe(4), add example for ipv6

2014-10-08 Thread Stuart Henderson
On 2014/10/08 11:10, Stefan Sperling wrote:
 On Tue, Oct 07, 2014 at 11:42:10PM -0400, Brad Smith wrote:
  On 07/10/14 10:03 PM, Stuart Henderson wrote:
  Since it's non-obvious how to setup pppoe for v6 now that link-local
  addresses are no longer configured by default, I think we should have
  something in the manual.
  
  Any comments/objections/suggestions for a better way to do this?
  
  This doesn't make any sense. IPv6CP configures the link local address.
 
 IPv6CP prevents *collisions* of link-local addresses on the same p2p link.
 
 If an existing link-local address doesn't collide with the remote peer's
 address we keep using the existing address. The link-local address will
 be changed by IPv6CP only if there is a collision (which won't ever happen
 under normal conditions).

pppoe(4) doesn't send an IPV6CP request unless it already has a
link-local address.

With a pre-existing link-local :

We request
They ack
They request
We ack
Done, echoes start

Without :

They request
We ack
They request
We ack
They request
We ack
They request
We ack
They reques.etc etc until they give up waiting for us to send a req.

 A route to fe80:: needs to be configured statically in any case
 until autoconf works with ip6 forwarding enabled.
 
 !/sbin/route add default -ifp pppoe0 fe80::
 
 I suppose we can't run this command from hostname.pppoe0 if there is
 no IPv6 address yet, so it makes sense to configure one first.

With the current behaviour it's more that it's a requirement rather
than just makes sense.

But then... you expect that a pppoe(4) interface *does* pick up addresses
automatically when it's configured/brought up, so perhaps the argument
that triggered the change to NOINET6 by default shouldn't apply in this
case - should pppoe(4) interfaces actually get an IPv6 link-local address
by default like they used to?

Index: if_pppoe.c
===
RCS file: /cvs/src/sys/net/if_pppoe.c,v
retrieving revision 1.41
diff -u -p -w -r1.41 if_pppoe.c
--- if_pppoe.c  13 Aug 2014 12:03:40 -  1.41
+++ if_pppoe.c  8 Oct 2014 12:24:07 -
@@ -245,6 +245,9 @@ pppoe_clone_create(struct if_clone *ifc,
timeout_set(sc-sc_timeout, pppoe_timeout, sc);

if_attach(sc-sc_sppp.pp_if);
+#ifdef INET6
+   sc-sc_sppp.pp_if.if_xflags = ~IFXF_NOINET6;
+#endif
if_alloc_sadl(sc-sc_sppp.pp_if);
sppp_attach(sc-sc_sppp.pp_if);
 #if NBPFILTER  0



Re: improving OpenBSD's gmac.c...

2014-10-08 Thread Mike Belopuhov
On 8 October 2014 00:48, John-Mark Gurney j...@funkthat.com wrote:
 Christian Weisgerber wrote this message on Tue, Oct 07, 2014 at 23:08 +0200:
 John-Mark Gurney:

  So, as I was working on FreeBSD's implementation of gmac.c, I noticed
  that I was able to get a significant speed up by using a mask instead
  of an if branch in ghash_gfmul in gmac.c from OpenBSD...
 
  Add a mask var and replace the code between the comments
  update Z and update V w/:
  mask = !!(x[i  3]  (1  (~i  7)));
  mask = ~(mask - 1);
 
  z[0] ^= v[0]  mask;
  z[1] ^= v[1]  mask;
  z[2] ^= v[2]  mask;
  z[3] ^= v[3]  mask;
 
  And you should see a nice performance increase...

 I tried this on a Soekris net6501-50 and the performance increase
 was around 1.3%.  (I set up an ESP transport association with
 AES-128-GMAC and pushed UDP traffic with tcpbench over it.)

 Yeh, I benchmarked the raw algo in userland, not part of IPsec.  I
 forget the resulting perf increase, but it was well more than 10-20%.

 A look at the generated amd64 assembly code shows that the change
 indeed removes a branch.  What's pretty shocking is that this code

 mul = v[3]  1;
 ...
 v[0] = (v[0]  1) ^ (0xe100 * mul);

 is turned into an actual imul instruction by GCC.  I used the same
 masking approach to get rid of the multiplication, but the improvement
 was minuscule (1%).

 Hmm. interesting...  In my code I switched both to using the and
 operator...

 I also have code which switches the registers to 64bits so that on
 amd64, we make better uses of registers, and on i386, the compilers
 are good at breaking down the 64bit registers to 32bit w/o extra
 work...

  I also have an implementation of ghash that does a 4 bit lookup table
  version with the table split between cache lines in p4 at:
  https://p4db.freebsd.org/fileViewer.cgi?FSPC=//depot/projects/opencrypto/sys/opencrypto/gfmult.cREV=4

 I'll have to look at this, but haven't there been increasing
 misgivings about table implementations for GHASH because of timing
 attacks?

 Well, the code avoids one issue but introduces another issue...  Each
 table lookup accesses all four lines (assuming 64 byte cache lines), so
 there isn't a problem there...  The issue intrroduded is that the first
 64 bits of a cache line are faster to access than the remaining bits...

 For more info, look at the NSS bug:
 https://bugzilla.mozilla.org/show_bug.cgi?id=868948

 Though considering that the AES implementation that FreeBSD is still
 using is the standard table based AES, there are also timing issues
 there too...  Yes, no excuse for opening up additional windows...

 I have thought about introducing an option of slow but secure and
 fast but insecure against local attackers...  Since we are already
 on the fast but insecure against local attackers path, I figured I'll
 take the extra performance...

 As with all things, there is a trade off between speed and security...
 As most IPsec gateways don't have a local user trying to target the
 key, this is less of an issue...  And even if they did, it'd probably
 be easier to use a local root exploit to get the key than try to mount
 a timing attack to extract a key that might change in an hour or a day...

 --
   John-Mark Gurney  Voice: +1 415 225 5579

  All that I will do, has been done, All that I have, has not.


Hi,

I've talked to Theo and it looks like we'll be importing your GF2
multiplication library as is.  I think we should concentrate on
making table version of gmac.c work better.

Cheers,
Mike



Re: hibernate button and !HIBERNATE kernels

2014-10-08 Thread Mike Larkin
On Wed, Oct 08, 2014 at 01:30:38AM -0600, David Coppa wrote:
 
 Hi!
 
 When running a kernel built without option HIBERNATE, if I press
 the hibernate button (Fn+F12) on my ThinkPad T420, the system
 abruptly shuts down and I'm welcomed by fsck on the next boot.
 
 What about the following diff?
 
 Index: dev/acpi/acpithinkpad.c
 ===
 RCS file: /cvs/src/sys/dev/acpi/acpithinkpad.c,v
 retrieving revision 1.40
 diff -u -p -u -p -r1.40 acpithinkpad.c
 --- dev/acpi/acpithinkpad.c   7 Oct 2014 11:28:59 -   1.40
 +++ dev/acpi/acpithinkpad.c   8 Oct 2014 07:14:06 -
 @@ -345,7 +345,7 @@ thinkpad_hotkey(struct aml_node *node, i
   handled = 1;
   break;
   case THINKPAD_BUTTON_HIBERNATE:
 -#ifndef SMALL_KERNEL
 +#if defined(HIBERNATE)  !defined(SMALL_KERNEL)
   acpi_addtask(sc-sc_acpi, acpi_sleep_task, 
   sc-sc_acpi, ACPI_STATE_S4);
  #endif

Funny, I thought to myself yesterday that doesn't look right when 
looking through acpithinkpad.c for something else and saw that very
same line.

Looks fine to me, go ahead.

-ml



Re: improving OpenBSD's gmac.c...

2014-10-08 Thread John-Mark Gurney
Mike Belopuhov wrote this message on Wed, Oct 08, 2014 at 14:32 +0200:
 On 8 October 2014 00:48, John-Mark Gurney j...@funkthat.com wrote:
  Christian Weisgerber wrote this message on Tue, Oct 07, 2014 at 23:08 +0200:
  John-Mark Gurney:
 
   So, as I was working on FreeBSD's implementation of gmac.c, I noticed
   that I was able to get a significant speed up by using a mask instead
   of an if branch in ghash_gfmul in gmac.c from OpenBSD...
  
   Add a mask var and replace the code between the comments
   update Z and update V w/:
   mask = !!(x[i  3]  (1  (~i  7)));
   mask = ~(mask - 1);
  
   z[0] ^= v[0]  mask;
   z[1] ^= v[1]  mask;
   z[2] ^= v[2]  mask;
   z[3] ^= v[3]  mask;
  
   And you should see a nice performance increase...
 
  I tried this on a Soekris net6501-50 and the performance increase
  was around 1.3%.  (I set up an ESP transport association with
  AES-128-GMAC and pushed UDP traffic with tcpbench over it.)
 
  Yeh, I benchmarked the raw algo in userland, not part of IPsec.  I
  forget the resulting perf increase, but it was well more than 10-20%.
 
  A look at the generated amd64 assembly code shows that the change
  indeed removes a branch.  What's pretty shocking is that this code
 
  mul = v[3]  1;
  ...
  v[0] = (v[0]  1) ^ (0xe100 * mul);
 
  is turned into an actual imul instruction by GCC.  I used the same
  masking approach to get rid of the multiplication, but the improvement
  was minuscule (1%).
 
  Hmm. interesting...  In my code I switched both to using the and
  operator...
 
  I also have code which switches the registers to 64bits so that on
  amd64, we make better uses of registers, and on i386, the compilers
  are good at breaking down the 64bit registers to 32bit w/o extra
  work...
 
   I also have an implementation of ghash that does a 4 bit lookup table
   version with the table split between cache lines in p4 at:
   https://p4db.freebsd.org/fileViewer.cgi?FSPC=//depot/projects/opencrypto/sys/opencrypto/gfmult.cREV=4
 
  I'll have to look at this, but haven't there been increasing
  misgivings about table implementations for GHASH because of timing
  attacks?
 
  Well, the code avoids one issue but introduces another issue...  Each
  table lookup accesses all four lines (assuming 64 byte cache lines), so
  there isn't a problem there...  The issue intrroduded is that the first
  64 bits of a cache line are faster to access than the remaining bits...
 
  For more info, look at the NSS bug:
  https://bugzilla.mozilla.org/show_bug.cgi?id=868948
 
  Though considering that the AES implementation that FreeBSD is still
  using is the standard table based AES, there are also timing issues
  there too...  Yes, no excuse for opening up additional windows...
 
  I have thought about introducing an option of slow but secure and
  fast but insecure against local attackers...  Since we are already
  on the fast but insecure against local attackers path, I figured I'll
  take the extra performance...
 
  As with all things, there is a trade off between speed and security...
  As most IPsec gateways don't have a local user trying to target the
  key, this is less of an issue...  And even if they did, it'd probably
  be easier to use a local root exploit to get the key than try to mount
  a timing attack to extract a key that might change in an hour or a day...
 
 I've talked to Theo and it looks like we'll be importing your GF2
 multiplication library as is.  I think we should concentrate on
 making table version of gmac.c work better.

Sounds good... Let me know of any issues you have...  I'll want to try
to keep the source in sync...

As for making the table version work better? do you mean closer to
constant time? or?

Thanks.

-- 
  John-Mark Gurney  Voice: +1 415 225 5579

 All that I will do, has been done, All that I have, has not.



Re: mpe patch: use rt_ifa_{add,del}

2014-10-08 Thread Rafael Zalamena
On Wed, Oct 08, 2014 at 09:22:44AM +0200, Martin Pieuchot wrote:
 On 07/10/14(Tue) 18:44, Rafael Zalamena wrote:
  On Sat, Oct 04, 2014 at 07:39:03PM -0300, Rafael Zalamena wrote:
   On Thu, Oct 02, 2014 at 02:36:12PM +0200, Martin Pieuchot wrote:
On 01/10/14(Wed) 21:54, Rafael Zalamena wrote:
 --- old chat snip ---
   
  
  Code changed:
   * Replaced old function that used to create routes in favor of rt_ifa_*
   * Modified rt_ifa_{add,del} to handle MPLS addresses: when creating an
 route to a MPLS interface it means we want to remove labels. Also MPLS
 only works on rdomain 0
 
 Even if they only work on rdomain 0, I'd prefer not to add code to
 enforce this behavior.  It's like making it harder for people to make it
 work any rdomain.
 
 Other than that, I'm ok with your diff.
 

I removed the code that hardcoded RTF_MPLS to rdomain 0, now we use a
function to handle the rdomain switching to install routes.

Index: sys/net/if_mpe.c
===
RCS file: /home/rzalamena/obsdcvs/src/sys/net/if_mpe.c,v
retrieving revision 1.35
diff -u -p -r1.35 if_mpe.c
--- sys/net/if_mpe.c22 Jul 2014 11:06:09 -  1.35
+++ sys/net/if_mpe.c8 Oct 2014 21:48:15 -
@@ -61,7 +61,7 @@ int   mpeioctl(struct ifnet *, u_long, cad
 void   mpestart(struct ifnet *);
 intmpe_clone_create(struct if_clone *, int);
 intmpe_clone_destroy(struct ifnet *);
-intmpe_newlabel(struct ifnet *, int, struct shim_hdr *);
+intmpe_iflabelroute(struct ifnet *, struct shim_hdr *, int);
 
 LIST_HEAD(, mpe_softc) mpeif_list;
 struct if_clonempe_cloner =
@@ -333,10 +333,10 @@ mpeioctl(struct ifnet *ifp, u_long cmd, 
ifm = ifp-if_softc;
if (ifm-sc_shim.shim_label) {
/* remove old MPLS route */
-   mpe_newlabel(ifp, RTM_DELETE, ifm-sc_shim);
+   mpe_iflabelroute(ifp, ifm-sc_shim, 0);
}
/* add new MPLS route */
-   error = mpe_newlabel(ifp, RTM_ADD, shim);
+   error = mpe_iflabelroute(ifp, shim, 1);
if (error)
break;
ifm-sc_shim.shim_label = shim.shim_label;
@@ -346,8 +346,7 @@ mpeioctl(struct ifnet *ifp, u_long cmd, 
ifm = ifp-if_softc;
if (ifr-ifr_rdomainid != ifp-if_rdomain) {
if (ifm-sc_shim.shim_label) {
-   shim.shim_label = ifm-sc_shim.shim_label;
-   error = mpe_newlabel(ifp, RTM_ADD, shim);
+   mpe_iflabelroute(ifp, ifm-sc_shim, 1);
}
}
/* return with ENOTTY so that the parent handler finishes */
@@ -443,37 +442,29 @@ mpe_input6(struct mbuf *m, struct ifnet 
 }
 #endif /* INET6 */
 
+/*
+ * Install or remove mpe interface label routes using rdomain 0.
+ */
 int
-mpe_newlabel(struct ifnet *ifp, int cmd, struct shim_hdr *shim)
+mpe_iflabelroute(struct ifnet *ifp, struct shim_hdr *shim, int add)
 {
-   struct rtentry *nrt;
-   struct sockaddr_mpls dst;
-   struct rt_addrinfo info;
-   int error;
-
-   bzero(dst, sizeof(dst));
-   dst.smpls_len = sizeof(dst);
-   dst.smpls_family = AF_MPLS;
-   dst.smpls_label = shim-shim_label;
-
-   bzero(info, sizeof(info));
-   info.rti_flags = RTF_UP | RTF_MPLS;
-   info.rti_mpls = MPLS_OP_POP;
-   info.rti_info[RTAX_DST] = smplstosa(dst);
-   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)ifp-if_sadl;
-
-   error = rtrequest1(cmd, info, RTP_CONNECTED, nrt, 0);
-   rt_missmsg(cmd, info, error ? 0 : nrt-rt_flags, ifp, error, 0);
-   if (cmd == RTM_DELETE) {
-   if (error == 0  nrt != NULL) {
-   if (nrt-rt_refcnt = 0) {
-   nrt-rt_refcnt++;
-   rtfree(nrt);
-   }
-   }
-   }
-   if (cmd == RTM_ADD  error == 0  nrt != NULL) {
-   nrt-rt_refcnt--;
-   }
+   int error;
+   struct  sockaddr_mpls smpls;
+   u_short rdomain = ifp-if_rdomain;
+
+   ifp-if_rdomain = 0;
+
+   memset(smpls, 0, sizeof(smpls));
+   smpls.smpls_family = AF_MPLS;
+   smpls.smpls_label = shim-shim_label;
+   smpls.smpls_len = sizeof(smpls);
+   if (add)
+   error = rt_ifa_add(ifp-if_lladdr, RTF_MPLS | RTF_UP,
+   smplstosa(smpls));
+   else
+   error = rt_ifa_del(ifp-if_lladdr, RTF_MPLS | RTF_UP,
+   smplstosa(smpls));
+
+   ifp-if_rdomain = rdomain;
return (error);
 }
Index: sys/net/route.c
===
RCS file: /home/rzalamena/obsdcvs/src/sys/net/route.c,v
retrieving revision 1.185
diff -u -p -r1.185 route.c
--- sys/net/route.c 2 Oct 2014 12:21:20 -   

Re: [patch] rcs: stored values never read

2014-10-08 Thread Nicholas Marriott

seems fine to me


On Mon, Oct 06, 2014 at 09:20:03PM +0200, Fritjof Bornebusch wrote:
 Hi tech,
 
 according to scan-build(1) there are a few never read values.
 
 fritjof
 
 
 
 Index: co.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/co.c,v
 retrieving revision 1.118
 diff -u -p -r1.118 co.c
 --- co.c  2 Oct 2014 06:23:15 -   1.118
 +++ co.c  6 Oct 2014 18:55:54 -
 @@ -56,7 +56,6 @@ checkout_main(int argc, char **argv)
  
   flags = ret = 0;
   kflag = RCS_KWEXP_ERR;
 - rev = RCS_HEAD_REV;
   rev_str = NULL;
   author = date = state = NULL;
  
 @@ -256,7 +255,7 @@ checkout_rev(RCSFILE *file, RCSNUM *frev
   time_t rcsdate, givendate;
   RCSNUM *rev;
  
 - rcsdate = givendate = -1;
 + givendate = -1;
   if (date != NULL  (givendate = date_parse(date)) == -1) {
   warnx(invalid date: %s, date);
   return -1;
 Index: diff.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/diff.c,v
 retrieving revision 1.34
 diff -u -p -r1.34 diff.c
 --- diff.c16 May 2013 12:44:48 -  1.34
 +++ diff.c6 Oct 2014 19:03:31 -
 @@ -1302,7 +1302,7 @@ dump_unified_vec(FILE *f1, FILE *f2, int
   if (context_vec_start  context_vec_ptr)
   return;
  
 - b = d = 0;  /* gcc */
 + d = 0; /* gcc */
   lowa = MAX(1, cvp-a - diff_context);
   upb = MIN(len[0], context_vec_ptr-b + diff_context);
   lowc = MAX(1, cvp-c - diff_context);
 Index: merge.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/merge.c,v
 retrieving revision 1.8
 diff -u -p -r1.8 merge.c
 --- merge.c   2 Oct 2014 06:23:15 -   1.8
 +++ merge.c   6 Oct 2014 19:04:07 -
 @@ -40,7 +40,6 @@ merge_main(int argc, char **argv)
   BUF *bp;
  
   flags = labels = 0;
 - status = D_ERROR;
  
   /*
* Using getopt(3) and not rcs_getopt() because merge(1)
 Index: rcs.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/rcs.c,v
 retrieving revision 1.80
 diff -u -p -r1.80 rcs.c
 --- rcs.c 7 Jan 2014 14:08:16 -   1.80
 +++ rcs.c 6 Oct 2014 19:05:56 -
 @@ -214,7 +214,6 @@ rcs_write(RCSFILE *rfp)
   int fd;
  
   fn = NULL;
 - fd = -1;
  
   if (rfp-rf_flags  RCS_SYNCED)
   return;
 Index: rcsmerge.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/rcsmerge.c,v
 retrieving revision 1.53
 diff -u -p -r1.53 rcsmerge.c
 --- rcsmerge.c2 Oct 2014 06:23:15 -   1.53
 +++ rcsmerge.c6 Oct 2014 19:07:52 -
 @@ -44,7 +44,6 @@ rcsmerge_main(int argc, char **argv)
   BUF *bp;
  
   flags = 0;
 - kflag = RCS_KWEXP_ERR;
   status = D_ERROR;
   rev1 = rev2 = NULL;
   rev_str1 = rev_str2 = NULL;
 Index: rcsparse.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/rcsparse.c,v
 retrieving revision 1.9
 diff -u -p -r1.9 rcsparse.c
 --- rcsparse.c3 Jun 2013 17:04:35 -   1.9
 +++ rcsparse.c6 Oct 2014 19:10:03 -
 @@ -915,7 +915,6 @@ rcsparse_token(RCSFILE *rfp, int allowed
   } while (isspace(c));
  
   pdp-rp_msglineno = pdp-rp_lineno;
 - type = 0;
   switch (c) {
   case '@':
   ret = rcsparse_string(rfp, allowed);
 @@ -1104,7 +1103,6 @@ rcsparse(RCSFILE *rfp, struct rcs_sectio
   int i, token;
  
   pdp = (struct rcs_pdata *)rfp-rf_pdata;
 - i = 0;
  
   token = 0;
   for (i = 0; sec[i].token != 0; i++) {
 Index: rcsutil.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/rcsutil.c,v
 retrieving revision 1.40
 diff -u -p -r1.40 rcsutil.c
 --- rcsutil.c 29 May 2014 16:39:42 -  1.40
 +++ rcsutil.c 6 Oct 2014 19:11:42 -
 @@ -157,8 +157,6 @@ rcs_choosefile(const char *filename, cha
   char *p, *ext, name[MAXPATHLEN], *next, *ptr, rcsdir[MAXPATHLEN],
   *suffixes, rcspath[MAXPATHLEN];
  
 - fd = -1;
 -
   /*
* If `filename' contains a directory, `rcspath' contains that
* directory, including a trailing slash.  Otherwise `rcspath'
 Index: rlog.c
 ===
 RCS file: /cvs/src/usr.bin/rcs/rlog.c,v
 retrieving revision 1.68
 diff -u -p -r1.68 rlog.c
 --- rlog.c2 Oct 2014 06:23:15 -   1.68
 +++ rlog.c6 Oct 2014 19:14:00 -
 @@ -433,7 +433,7 @@ rlog_rev_print(struct rcs_delta *rdp)
   struct rcs_branch *rb;
   struct rcs_delta *nrdp;
  
 - i = found = 0;
 + found = 0;
   author = NULL;
  
   /* -l[lockers] */



no respone on Passphrase after first boot on -current

2014-10-08 Thread Jiri Navratil
Hello,

I bought acer TravelMate notebook TMB115-M-COEA to follow -current and
partitipate on LibreSSL.

I installed system from snapshot and used softraid0 crypto on whole sd0.

After first boot I have Passsphrase prompt and I can't contine. It looks
like keyboard is not working. No response after Enter. I assume, that
I'm providing same password as during install. There is no response at
all.

Can I debug this somehow?

I may install the machine again without crypto and then try to use softraid0 
crypto on external drive, but not sure, if this can be helpfull for debuging 
and reporting.

Is there something next I can experiment with and provide something valuable
here?

Thank you,
Jiri

-- 
Jiri Navratil, http://kouc.navratil.cz, +420 222 767 131



replace select with poll in libc

2014-10-08 Thread David Gwynne
this is the only use of select inside libc i could find. it appears
pretty straightforward to replace with poll.

this compiles, but i have no idea how to test it.

any suggestions? or oks?

Index: net/rcmd.c
===
RCS file: /cvs/src/lib/libc/net/rcmd.c,v
retrieving revision 1.56
diff -u -p -r1.56 rcmd.c
--- net/rcmd.c  18 Nov 2009 07:43:22 -  1.56
+++ net/rcmd.c  9 Oct 2014 04:49:30 -
@@ -46,6 +46,7 @@
 #include string.h
 #include syslog.h
 #include stdlib.h
+#include poll.h
 
 int
 rcmd(char **ahost, int rport, const char *locuser, const char *remuser,
@@ -63,7 +64,6 @@ rcmd_af(char **ahost, int porta, const c
struct addrinfo hints, *res, *r;
int error;
struct sockaddr_storage from;
-   fd_set *readsp = NULL;
sigset_t oldmask, mask;
pid_t pid;
int s, lport, timo;
@@ -188,18 +188,14 @@ rcmd_af(char **ahost, int porta, const c
write(s, , 1);
lport = 0;
} else {
+   struct pollfd pfd[2];
char num[8];
int s2 = rresvport_af(lport, af), s3;
socklen_t len = sizeof(from);
-   int fdssize = howmany(MAX(s, s2)+1, NFDBITS) * sizeof(fd_mask);
 
if (s2  0)
goto bad;
-   readsp = (fd_set *)malloc(fdssize);
-   if (readsp == NULL) {
-   close(s2);
-   goto bad;
-   }
+
listen(s2, 1);
(void)snprintf(num, sizeof(num), %d, lport);
if (write(s, num, strlen(num)+1) != strlen(num)+1) {
@@ -210,12 +206,15 @@ rcmd_af(char **ahost, int porta, const c
goto bad;
}
 again:
-   bzero(readsp, fdssize);
-   FD_SET(s, readsp);
-   FD_SET(s2, readsp);
+   memset(pfd, 0, sizeof(pfd));
+   pfd[0].fd = s;
+   pfd[0].events = POLLIN;
+   pfd[1].fd = s2;
+   pfd[1].events = POLLIN;
+
errno = 0;
-   if (select(MAX(s, s2) + 1, readsp, 0, 0, 0)  1 ||
-   !FD_ISSET(s2, readsp)) {
+   if (poll(pfd, 2, INFTIM)  1 ||
+   (pfd[1].revents  POLLIN) == 0) {
if (errno != 0)
(void)fprintf(stderr,
rcmd: select (setting up stderr): %s\n,
@@ -288,14 +287,11 @@ again:
goto bad2;
}
sigprocmask(SIG_SETMASK, oldmask, NULL);
-   free(readsp);
return (s);
 bad2:
if (lport)
(void)close(*fd2p);
 bad:
-   if (readsp)
-   free(readsp);
(void)close(s);
sigprocmask(SIG_SETMASK, oldmask, NULL);
return (-1);



Re: replace select with poll in libc

2014-10-08 Thread Bryan Steele
On Thu, Oct 09, 2014 at 02:52:50PM +1000, David Gwynne wrote:
 this is the only use of select inside libc i could find. it appears
 pretty straightforward to replace with poll.
 
 this compiles, but i have no idea how to test it.
 
 any suggestions? or oks?

Is rcmd(3) even used by anything anymore? It seems to be specifically
about rsh(1) and even calls getservbyname(shell, tcp).

http://marc.info/?l=openbsd-cvsm=139791954627549w=2



replace select with nanosleep in libc/termios/tcsendbreak.c

2014-10-08 Thread David Gwynne
deraadt points out i suck at grep.

ok?

Index: termios/tcsendbreak.c
===
RCS file: /cvs/src/lib/libc/termios/tcsendbreak.c,v
retrieving revision 1.6
diff -u -p -r1.6 tcsendbreak.c
--- termios/tcsendbreak.c   5 Aug 2005 13:03:00 -   1.6
+++ termios/tcsendbreak.c   9 Oct 2014 05:21:30 -
@@ -43,13 +43,14 @@
 int
 tcsendbreak(int fd, int len)
 {
-   struct timeval sleepytime;
+   struct timespec sleepytime;
 
sleepytime.tv_sec = 0;
-   sleepytime.tv_usec = 40;
+   sleepytime.tv_nsec = 4;
+
if (ioctl(fd, TIOCSBRK, 0) == -1)
return (-1);
-   (void)select(0, 0, 0, 0, sleepytime);
+   (void)nanosleep(sleepytime, NULL);
if (ioctl(fd, TIOCCBRK, 0) == -1)
return (-1);
return (0);



Re: replace select with poll in libc

2014-10-08 Thread David Gwynne

On 9 Oct 2014, at 15:11, Bryan Steele bry...@gmail.com wrote:

 On Thu, Oct 09, 2014 at 02:52:50PM +1000, David Gwynne wrote:
 this is the only use of select inside libc i could find. it appears
 pretty straightforward to replace with poll.
 
 this compiles, but i have no idea how to test it.
 
 any suggestions? or oks?
 
 Is rcmd(3) even used by anything anymore? It seems to be specifically
 about rsh(1) and even calls getservbyname(shell, tcp).
 
 http://marc.info/?l=openbsd-cvsm=139791954627549w=2
 

i believe mt/rmt might still use it.